xref: /dpdk/app/test-pmd/cmdline.c (revision c07b3f046fcb2828e158e9ac4bf74a768f690d3d)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51 
52 #include <sys/queue.h>
53 
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.h>
79 
80 #include <cmdline_rdline.h>
81 #include <cmdline_parse.h>
82 #include <cmdline_parse_num.h>
83 #include <cmdline_parse_string.h>
84 #include <cmdline_parse_ipaddr.h>
85 #include <cmdline_parse_etheraddr.h>
86 #include <cmdline_socket.h>
87 #include <cmdline.h>
88 #ifdef RTE_LIBRTE_PMD_BOND
89 #include <rte_eth_bond.h>
90 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 
103 static struct cmdline *testpmd_cl;
104 
105 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
106 
107 /* *** Help command with introduction. *** */
108 struct cmd_help_brief_result {
109 	cmdline_fixed_string_t help;
110 };
111 
112 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
113                                   struct cmdline *cl,
114                                   __attribute__((unused)) void *data)
115 {
116 	cmdline_printf(
117 		cl,
118 		"\n"
119 		"Help is available for the following sections:\n\n"
120 		"    help control    : Start and stop forwarding.\n"
121 		"    help display    : Displaying port, stats and config "
122 		"information.\n"
123 		"    help config     : Configuration information.\n"
124 		"    help ports      : Configuring ports.\n"
125 		"    help registers  : Reading and setting port registers.\n"
126 		"    help filters    : Filters configuration help.\n"
127 		"    help all        : All of the above sections.\n\n"
128 	);
129 
130 }
131 
132 cmdline_parse_token_string_t cmd_help_brief_help =
133 	TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
134 
135 cmdline_parse_inst_t cmd_help_brief = {
136 	.f = cmd_help_brief_parsed,
137 	.data = NULL,
138 	.help_str = "help: Show help",
139 	.tokens = {
140 		(void *)&cmd_help_brief_help,
141 		NULL,
142 	},
143 };
144 
145 /* *** Help command with help sections. *** */
146 struct cmd_help_long_result {
147 	cmdline_fixed_string_t help;
148 	cmdline_fixed_string_t section;
149 };
150 
151 static void cmd_help_long_parsed(void *parsed_result,
152                                  struct cmdline *cl,
153                                  __attribute__((unused)) void *data)
154 {
155 	int show_all = 0;
156 	struct cmd_help_long_result *res = parsed_result;
157 
158 	if (!strcmp(res->section, "all"))
159 		show_all = 1;
160 
161 	if (show_all || !strcmp(res->section, "control")) {
162 
163 		cmdline_printf(
164 			cl,
165 			"\n"
166 			"Control forwarding:\n"
167 			"-------------------\n\n"
168 
169 			"start\n"
170 			"    Start packet forwarding with current configuration.\n\n"
171 
172 			"start tx_first\n"
173 			"    Start packet forwarding with current config"
174 			" after sending one burst of packets.\n\n"
175 
176 			"stop\n"
177 			"    Stop packet forwarding, and display accumulated"
178 			" statistics.\n\n"
179 
180 			"quit\n"
181 			"    Quit to prompt.\n\n"
182 		);
183 	}
184 
185 	if (show_all || !strcmp(res->section, "display")) {
186 
187 		cmdline_printf(
188 			cl,
189 			"\n"
190 			"Display:\n"
191 			"--------\n\n"
192 
193 			"show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
194 			"    Display information for port_id, or all.\n\n"
195 
196 			"show port X rss reta (size) (mask0,mask1,...)\n"
197 			"    Display the rss redirection table entry indicated"
198 			" by masks on port X. size is used to indicate the"
199 			" hardware supported reta size\n\n"
200 
201 			"show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
202 			"ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
203 			"ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
204 			"    Display the RSS hash functions and RSS hash key"
205 			" of port X\n\n"
206 
207 			"clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
208 			"    Clear information for port_id, or all.\n\n"
209 
210 			"show (rxq|txq) info (port_id) (queue_id)\n"
211 			"    Display information for configured RX/TX queue.\n\n"
212 
213 			"show config (rxtx|cores|fwd|txpkts)\n"
214 			"    Display the given configuration.\n\n"
215 
216 			"read rxd (port_id) (queue_id) (rxd_id)\n"
217 			"    Display an RX descriptor of a port RX queue.\n\n"
218 
219 			"read txd (port_id) (queue_id) (txd_id)\n"
220 			"    Display a TX descriptor of a port TX queue.\n\n"
221 
222 			"ddp get list (port_id)\n"
223 			"    Get ddp profile info list\n\n"
224 
225 			"ddp get info (profile_path)\n"
226 			"    Get ddp profile information.\n\n"
227 
228 			"show vf stats (port_id) (vf_id)\n"
229 			"    Display a VF's statistics.\n\n"
230 
231 			"clear vf stats (port_id) (vf_id)\n"
232 			"    Reset a VF's statistics.\n\n"
233 
234 			"show port (port_id) pctype mapping\n"
235 			"    Get flow ptype to pctype mapping on a port\n\n"
236 
237 		);
238 	}
239 
240 	if (show_all || !strcmp(res->section, "config")) {
241 		cmdline_printf(
242 			cl,
243 			"\n"
244 			"Configuration:\n"
245 			"--------------\n"
246 			"Configuration changes only become active when"
247 			" forwarding is started/restarted.\n\n"
248 
249 			"set default\n"
250 			"    Reset forwarding to the default configuration.\n\n"
251 
252 			"set verbose (level)\n"
253 			"    Set the debug verbosity level X.\n\n"
254 
255 			"set nbport (num)\n"
256 			"    Set number of ports.\n\n"
257 
258 			"set nbcore (num)\n"
259 			"    Set number of cores.\n\n"
260 
261 			"set coremask (mask)\n"
262 			"    Set the forwarding cores hexadecimal mask.\n\n"
263 
264 			"set portmask (mask)\n"
265 			"    Set the forwarding ports hexadecimal mask.\n\n"
266 
267 			"set burst (num)\n"
268 			"    Set number of packets per burst.\n\n"
269 
270 			"set burst tx delay (microseconds) retry (num)\n"
271 			"    Set the transmit delay time and number of retries,"
272 			" effective when retry is enabled.\n\n"
273 
274 			"set txpkts (x[,y]*)\n"
275 			"    Set the length of each segment of TXONLY"
276 			" and optionally CSUM packets.\n\n"
277 
278 			"set txsplit (off|on|rand)\n"
279 			"    Set the split policy for the TX packets."
280 			" Right now only applicable for CSUM and TXONLY"
281 			" modes\n\n"
282 
283 			"set corelist (x[,y]*)\n"
284 			"    Set the list of forwarding cores.\n\n"
285 
286 			"set portlist (x[,y]*)\n"
287 			"    Set the list of forwarding ports.\n\n"
288 
289 			"set tx loopback (port_id) (on|off)\n"
290 			"    Enable or disable tx loopback.\n\n"
291 
292 			"set all queues drop (port_id) (on|off)\n"
293 			"    Set drop enable bit for all queues.\n\n"
294 
295 			"set vf split drop (port_id) (vf_id) (on|off)\n"
296 			"    Set split drop enable bit for a VF from the PF.\n\n"
297 
298 			"set vf mac antispoof (port_id) (vf_id) (on|off).\n"
299 			"    Set MAC antispoof for a VF from the PF.\n\n"
300 
301 			"set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
302 			"    Enable MACsec offload.\n\n"
303 
304 			"set macsec offload (port_id) off\n"
305 			"    Disable MACsec offload.\n\n"
306 
307 			"set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
308 			"    Configure MACsec secure connection (SC).\n\n"
309 
310 			"set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
311 			"    Configure MACsec secure association (SA).\n\n"
312 
313 			"set vf broadcast (port_id) (vf_id) (on|off)\n"
314 			"    Set VF broadcast for a VF from the PF.\n\n"
315 
316 			"vlan set strip (on|off) (port_id)\n"
317 			"    Set the VLAN strip on a port.\n\n"
318 
319 			"vlan set stripq (on|off) (port_id,queue_id)\n"
320 			"    Set the VLAN strip for a queue on a port.\n\n"
321 
322 			"set vf vlan stripq (port_id) (vf_id) (on|off)\n"
323 			"    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
324 
325 			"set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
326 			"    Set VLAN insert for a VF from the PF.\n\n"
327 
328 			"set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
329 			"    Set VLAN antispoof for a VF from the PF.\n\n"
330 
331 			"set vf vlan tag (port_id) (vf_id) (on|off)\n"
332 			"    Set VLAN tag for a VF from the PF.\n\n"
333 
334 			"set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
335 			"    Set a VF's max bandwidth(Mbps).\n\n"
336 
337 			"set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
338 			"    Set all TCs' min bandwidth(%%) on a VF.\n\n"
339 
340 			"set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
341 			"    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
342 
343 			"set tx strict-link-priority (port_id) (tc_bitmap)\n"
344 			"    Set some TCs' strict link priority mode on a physical port.\n\n"
345 
346 			"set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
347 			"    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
348 
349 			"vlan set filter (on|off) (port_id)\n"
350 			"    Set the VLAN filter on a port.\n\n"
351 
352 			"vlan set qinq (on|off) (port_id)\n"
353 			"    Set the VLAN QinQ (extended queue in queue)"
354 			" on a port.\n\n"
355 
356 			"vlan set (inner|outer) tpid (value) (port_id)\n"
357 			"    Set the VLAN TPID for Packet Filtering on"
358 			" a port\n\n"
359 
360 			"rx_vlan add (vlan_id|all) (port_id)\n"
361 			"    Add a vlan_id, or all identifiers, to the set"
362 			" of VLAN identifiers filtered by port_id.\n\n"
363 
364 			"rx_vlan rm (vlan_id|all) (port_id)\n"
365 			"    Remove a vlan_id, or all identifiers, from the set"
366 			" of VLAN identifiers filtered by port_id.\n\n"
367 
368 			"rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
369 			"    Add a vlan_id, to the set of VLAN identifiers"
370 			"filtered for VF(s) from port_id.\n\n"
371 
372 			"rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
373 			"    Remove a vlan_id, to the set of VLAN identifiers"
374 			"filtered for VF(s) from port_id.\n\n"
375 
376 			"tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
377 			"(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
378 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
379 			"   add a tunnel filter of a port.\n\n"
380 
381 			"tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
382 			"(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
383 			"imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
384 			"   remove a tunnel filter of a port.\n\n"
385 
386 			"rx_vxlan_port add (udp_port) (port_id)\n"
387 			"    Add an UDP port for VXLAN packet filter on a port\n\n"
388 
389 			"rx_vxlan_port rm (udp_port) (port_id)\n"
390 			"    Remove an UDP port for VXLAN packet filter on a port\n\n"
391 
392 			"tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
393 			"    Set hardware insertion of VLAN IDs (single or double VLAN "
394 			"depends on the number of VLAN IDs) in packets sent on a port.\n\n"
395 
396 			"tx_vlan set pvid port_id vlan_id (on|off)\n"
397 			"    Set port based TX VLAN insertion.\n\n"
398 
399 			"tx_vlan reset (port_id)\n"
400 			"    Disable hardware insertion of a VLAN header in"
401 			" packets sent on a port.\n\n"
402 
403 			"csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
404 			"    Select hardware or software calculation of the"
405 			" checksum when transmitting a packet using the"
406 			" csum forward engine.\n"
407 			"    ip|udp|tcp|sctp always concern the inner layer.\n"
408 			"    outer-ip concerns the outer IP layer in"
409 			" case the packet is recognized as a tunnel packet by"
410 			" the forward engine (vxlan, gre and ipip are supported)\n"
411 			"    Please check the NIC datasheet for HW limits.\n\n"
412 
413 			"csum parse-tunnel (on|off) (tx_port_id)\n"
414 			"    If disabled, treat tunnel packets as non-tunneled"
415 			" packets (treat inner headers as payload). The port\n"
416 			"    argument is the port used for TX in csum forward"
417 			" engine.\n\n"
418 
419 			"csum show (port_id)\n"
420 			"    Display tx checksum offload configuration\n\n"
421 
422 			"tso set (segsize) (portid)\n"
423 			"    Enable TCP Segmentation Offload in csum forward"
424 			" engine.\n"
425 			"    Please check the NIC datasheet for HW limits.\n\n"
426 
427 			"tso show (portid)"
428 			"    Display the status of TCP Segmentation Offload.\n\n"
429 
430 			"set port (port_id) gro on|off\n"
431 			"    Enable or disable Generic Receive Offload in"
432 			" csum forwarding engine.\n\n"
433 
434 			"show port (port_id) gro\n"
435 			"    Display GRO configuration.\n\n"
436 
437 			"set gro flush (cycles)\n"
438 			"    Set the cycle to flush GROed packets from"
439 			" reassembly tables.\n\n"
440 
441 			"set port (port_id) gso (on|off)"
442 			"    Enable or disable Generic Segmentation Offload in"
443 			" csum forwarding engine.\n\n"
444 
445 			"set gso segsz (length)\n"
446 			"    Set max packet length for output GSO segments,"
447 			" including packet header and payload.\n\n"
448 
449 			"show port (port_id) gso\n"
450 			"    Show GSO configuration.\n\n"
451 
452 			"set fwd (%s)\n"
453 			"    Set packet forwarding mode.\n\n"
454 
455 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
456 			"    Add a MAC address on port_id.\n\n"
457 
458 			"mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
459 			"    Remove a MAC address from port_id.\n\n"
460 
461 			"mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
462 			"    Set the default MAC address for port_id.\n\n"
463 
464 			"mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
465 			"    Add a MAC address for a VF on the port.\n\n"
466 
467 			"set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
468 			"    Set the MAC address for a VF from the PF.\n\n"
469 
470 			"set port (port_id) uta (mac_address|all) (on|off)\n"
471 			"    Add/Remove a or all unicast hash filter(s)"
472 			"from port X.\n\n"
473 
474 			"set promisc (port_id|all) (on|off)\n"
475 			"    Set the promiscuous mode on port_id, or all.\n\n"
476 
477 			"set allmulti (port_id|all) (on|off)\n"
478 			"    Set the allmulti mode on port_id, or all.\n\n"
479 
480 			"set vf promisc (port_id) (vf_id) (on|off)\n"
481 			"    Set unicast promiscuous mode for a VF from the PF.\n\n"
482 
483 			"set vf allmulti (port_id) (vf_id) (on|off)\n"
484 			"    Set multicast promiscuous mode for a VF from the PF.\n\n"
485 
486 			"set flow_ctrl rx (on|off) tx (on|off) (high_water)"
487 			" (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
488 			" (on|off) autoneg (on|off) (port_id)\n"
489 			"set flow_ctrl rx (on|off) (portid)\n"
490 			"set flow_ctrl tx (on|off) (portid)\n"
491 			"set flow_ctrl high_water (high_water) (portid)\n"
492 			"set flow_ctrl low_water (low_water) (portid)\n"
493 			"set flow_ctrl pause_time (pause_time) (portid)\n"
494 			"set flow_ctrl send_xon (send_xon) (portid)\n"
495 			"set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
496 			"set flow_ctrl autoneg (on|off) (port_id)\n"
497 			"    Set the link flow control parameter on a port.\n\n"
498 
499 			"set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
500 			" (low_water) (pause_time) (priority) (port_id)\n"
501 			"    Set the priority flow control parameter on a"
502 			" port.\n\n"
503 
504 			"set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
505 			"    Set statistics mapping (qmapping 0..15) for RX/TX"
506 			" queue on port.\n"
507 			"    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
508 			" on port 0 to mapping 5.\n\n"
509 
510 			"set port (port_id) vf (vf_id) rx|tx on|off\n"
511 			"    Enable/Disable a VF receive/tranmit from a port\n\n"
512 
513 			"set port (port_id) vf (vf_id) (mac_addr)"
514 			" (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
515 			"   Add/Remove unicast or multicast MAC addr filter"
516 			" for a VF.\n\n"
517 
518 			"set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
519 			"|MPE) (on|off)\n"
520 			"    AUPE:accepts untagged VLAN;"
521 			"ROPE:accept unicast hash\n\n"
522 			"    BAM:accepts broadcast packets;"
523 			"MPE:accepts all multicast packets\n\n"
524 			"    Enable/Disable a VF receive mode of a port\n\n"
525 
526 			"set port (port_id) queue (queue_id) rate (rate_num)\n"
527 			"    Set rate limit for a queue of a port\n\n"
528 
529 			"set port (port_id) vf (vf_id) rate (rate_num) "
530 			"queue_mask (queue_mask_value)\n"
531 			"    Set rate limit for queues in VF of a port\n\n"
532 
533 			"set port (port_id) mirror-rule (rule_id)"
534 			" (pool-mirror-up|pool-mirror-down|vlan-mirror)"
535 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
536 			"   Set pool or vlan type mirror rule on a port.\n"
537 			"   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
538 			" dst-pool 0 on' enable mirror traffic with vlan 0,1"
539 			" to pool 0.\n\n"
540 
541 			"set port (port_id) mirror-rule (rule_id)"
542 			" (uplink-mirror|downlink-mirror) dst-pool"
543 			" (pool_id) (on|off)\n"
544 			"   Set uplink or downlink type mirror rule on a port.\n"
545 			"   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
546 			" 0 on' enable mirror income traffic to pool 0.\n\n"
547 
548 			"reset port (port_id) mirror-rule (rule_id)\n"
549 			"   Reset a mirror rule.\n\n"
550 
551 			"set flush_rx (on|off)\n"
552 			"   Flush (default) or don't flush RX streams before"
553 			" forwarding. Mainly used with PCAP drivers.\n\n"
554 
555 			"set bypass mode (normal|bypass|isolate) (port_id)\n"
556 			"   Set the bypass mode for the lowest port on bypass enabled"
557 			" NIC.\n\n"
558 
559 			"set bypass event (timeout|os_on|os_off|power_on|power_off) "
560 			"mode (normal|bypass|isolate) (port_id)\n"
561 			"   Set the event required to initiate specified bypass mode for"
562 			" the lowest port on a bypass enabled NIC where:\n"
563 			"       timeout   = enable bypass after watchdog timeout.\n"
564 			"       os_on     = enable bypass when OS/board is powered on.\n"
565 			"       os_off    = enable bypass when OS/board is powered off.\n"
566 			"       power_on  = enable bypass when power supply is turned on.\n"
567 			"       power_off = enable bypass when power supply is turned off."
568 			"\n\n"
569 
570 			"set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
571 			"   Set the bypass watchdog timeout to 'n' seconds"
572 			" where 0 = instant.\n\n"
573 
574 			"show bypass config (port_id)\n"
575 			"   Show the bypass configuration for a bypass enabled NIC"
576 			" using the lowest port on the NIC.\n\n"
577 
578 #ifdef RTE_LIBRTE_PMD_BOND
579 			"create bonded device (mode) (socket)\n"
580 			"	Create a new bonded device with specific bonding mode and socket.\n\n"
581 
582 			"add bonding slave (slave_id) (port_id)\n"
583 			"	Add a slave device to a bonded device.\n\n"
584 
585 			"remove bonding slave (slave_id) (port_id)\n"
586 			"	Remove a slave device from a bonded device.\n\n"
587 
588 			"set bonding mode (value) (port_id)\n"
589 			"	Set the bonding mode on a bonded device.\n\n"
590 
591 			"set bonding primary (slave_id) (port_id)\n"
592 			"	Set the primary slave for a bonded device.\n\n"
593 
594 			"show bonding config (port_id)\n"
595 			"	Show the bonding config for port_id.\n\n"
596 
597 			"set bonding mac_addr (port_id) (address)\n"
598 			"	Set the MAC address of a bonded device.\n\n"
599 
600 			"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
601 			"	Set Aggregation mode for IEEE802.3AD (mode 4)"
602 
603 			"set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
604 			"	Set the transmit balance policy for bonded device running in balance mode.\n\n"
605 
606 			"set bonding mon_period (port_id) (value)\n"
607 			"	Set the bonding link status monitoring polling period in ms.\n\n"
608 
609 			"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
610 			"	Enable/disable dedicated queues for LACP control traffic.\n\n"
611 
612 #endif
613 			"set link-up port (port_id)\n"
614 			"	Set link up for a port.\n\n"
615 
616 			"set link-down port (port_id)\n"
617 			"	Set link down for a port.\n\n"
618 
619 			"E-tag set insertion on port-tag-id (value)"
620 			" port (port_id) vf (vf_id)\n"
621 			"    Enable E-tag insertion for a VF on a port\n\n"
622 
623 			"E-tag set insertion off port (port_id) vf (vf_id)\n"
624 			"    Disable E-tag insertion for a VF on a port\n\n"
625 
626 			"E-tag set stripping (on|off) port (port_id)\n"
627 			"    Enable/disable E-tag stripping on a port\n\n"
628 
629 			"E-tag set forwarding (on|off) port (port_id)\n"
630 			"    Enable/disable E-tag based forwarding"
631 			" on a port\n\n"
632 
633 			"E-tag set filter add e-tag-id (value) dst-pool"
634 			" (pool_id) port (port_id)\n"
635 			"    Add an E-tag forwarding filter on a port\n\n"
636 
637 			"E-tag set filter del e-tag-id (value) port (port_id)\n"
638 			"    Delete an E-tag forwarding filter on a port\n\n"
639 
640 			"ddp add (port_id) (profile_path[,output_path])\n"
641 			"    Load a profile package on a port\n\n"
642 
643 			"ddp del (port_id) (profile_path)\n"
644 			"    Delete a profile package from a port\n\n"
645 
646 			"ptype mapping get (port_id) (valid_only)\n"
647 			"    Get ptype mapping on a port\n\n"
648 
649 			"ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
650 			"    Replace target with the pkt_type in ptype mapping\n\n"
651 
652 			"ptype mapping reset (port_id)\n"
653 			"    Reset ptype mapping on a port\n\n"
654 
655 			"ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
656 			"    Update a ptype mapping item on a port\n\n"
657 
658 			, list_pkt_forwarding_modes()
659 		);
660 	}
661 
662 	if (show_all || !strcmp(res->section, "ports")) {
663 
664 		cmdline_printf(
665 			cl,
666 			"\n"
667 			"Port Operations:\n"
668 			"----------------\n\n"
669 
670 			"port start (port_id|all)\n"
671 			"    Start all ports or port_id.\n\n"
672 
673 			"port stop (port_id|all)\n"
674 			"    Stop all ports or port_id.\n\n"
675 
676 			"port close (port_id|all)\n"
677 			"    Close all ports or port_id.\n\n"
678 
679 			"port attach (ident)\n"
680 			"    Attach physical or virtual dev by pci address or virtual device name\n\n"
681 
682 			"port detach (port_id)\n"
683 			"    Detach physical or virtual dev by port_id\n\n"
684 
685 			"port config (port_id|all)"
686 			" speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
687 			" duplex (half|full|auto)\n"
688 			"    Set speed and duplex for all ports or port_id\n\n"
689 
690 			"port config all (rxq|txq|rxd|txd) (value)\n"
691 			"    Set number for rxq/txq/rxd/txd.\n\n"
692 
693 			"port config all max-pkt-len (value)\n"
694 			"    Set the max packet length.\n\n"
695 
696 			"port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|"
697 			"hw-vlan-strip|hw-vlan-extend|drop-en)"
698 			" (on|off)\n"
699 			"    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
700 			" for ports.\n\n"
701 
702 			"port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
703 			"geneve|nvgre|none|<flowtype_id>)\n"
704 			"    Set the RSS mode.\n\n"
705 
706 			"port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
707 			"    Set the RSS redirection table.\n\n"
708 
709 			"port config (port_id) dcb vt (on|off) (traffic_class)"
710 			" pfc (on|off)\n"
711 			"    Set the DCB mode.\n\n"
712 
713 			"port config all burst (value)\n"
714 			"    Set the number of packets per burst.\n\n"
715 
716 			"port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
717 			" (value)\n"
718 			"    Set the ring prefetch/host/writeback threshold"
719 			" for tx/rx queue.\n\n"
720 
721 			"port config all (txfreet|txrst|rxfreet) (value)\n"
722 			"    Set free threshold for rx/tx, or set"
723 			" tx rs bit threshold.\n\n"
724 			"port config mtu X value\n"
725 			"    Set the MTU of port X to a given value\n\n"
726 
727 			"port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
728 			"    Start/stop a rx/tx queue of port X. Only take effect"
729 			" when port X is started\n\n"
730 
731 			"port config (port_id|all) l2-tunnel E-tag ether-type"
732 			" (value)\n"
733 			"    Set the value of E-tag ether-type.\n\n"
734 
735 			"port config (port_id|all) l2-tunnel E-tag"
736 			" (enable|disable)\n"
737 			"    Enable/disable the E-tag support.\n\n"
738 
739 			"port config (port_id) pctype mapping reset\n"
740 			"    Reset flow type to pctype mapping on a port\n\n"
741 
742 			"port config (port_id) pctype mapping update"
743 			" (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
744 			"    Update a flow type to pctype mapping item on a port\n\n"
745 		);
746 	}
747 
748 	if (show_all || !strcmp(res->section, "registers")) {
749 
750 		cmdline_printf(
751 			cl,
752 			"\n"
753 			"Registers:\n"
754 			"----------\n\n"
755 
756 			"read reg (port_id) (address)\n"
757 			"    Display value of a port register.\n\n"
758 
759 			"read regfield (port_id) (address) (bit_x) (bit_y)\n"
760 			"    Display a port register bit field.\n\n"
761 
762 			"read regbit (port_id) (address) (bit_x)\n"
763 			"    Display a single port register bit.\n\n"
764 
765 			"write reg (port_id) (address) (value)\n"
766 			"    Set value of a port register.\n\n"
767 
768 			"write regfield (port_id) (address) (bit_x) (bit_y)"
769 			" (value)\n"
770 			"    Set bit field of a port register.\n\n"
771 
772 			"write regbit (port_id) (address) (bit_x) (value)\n"
773 			"    Set single bit value of a port register.\n\n"
774 		);
775 	}
776 	if (show_all || !strcmp(res->section, "filters")) {
777 
778 		cmdline_printf(
779 			cl,
780 			"\n"
781 			"filters:\n"
782 			"--------\n\n"
783 
784 			"ethertype_filter (port_id) (add|del)"
785 			" (mac_addr|mac_ignr) (mac_address) ethertype"
786 			" (ether_type) (drop|fwd) queue (queue_id)\n"
787 			"    Add/Del an ethertype filter.\n\n"
788 
789 			"2tuple_filter (port_id) (add|del)"
790 			" dst_port (dst_port_value) protocol (protocol_value)"
791 			" mask (mask_value) tcp_flags (tcp_flags_value)"
792 			" priority (prio_value) queue (queue_id)\n"
793 			"    Add/Del a 2tuple filter.\n\n"
794 
795 			"5tuple_filter (port_id) (add|del)"
796 			" dst_ip (dst_address) src_ip (src_address)"
797 			" dst_port (dst_port_value) src_port (src_port_value)"
798 			" protocol (protocol_value)"
799 			" mask (mask_value) tcp_flags (tcp_flags_value)"
800 			" priority (prio_value) queue (queue_id)\n"
801 			"    Add/Del a 5tuple filter.\n\n"
802 
803 			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
804 			"    Add/Del syn filter.\n\n"
805 
806 			"flex_filter (port_id) (add|del) len (len_value)"
807 			" bytes (bytes_value) mask (mask_value)"
808 			" priority (prio_value) queue (queue_id)\n"
809 			"    Add/Del a flex filter.\n\n"
810 
811 			"flow_director_filter (port_id) mode IP (add|del|update)"
812 			" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
813 			" src (src_ip_address) dst (dst_ip_address)"
814 			" tos (tos_value) proto (proto_value) ttl (ttl_value)"
815 			" vlan (vlan_value) flexbytes (flexbytes_value)"
816 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
817 			" fd_id (fd_id_value)\n"
818 			"    Add/Del an IP type flow director filter.\n\n"
819 
820 			"flow_director_filter (port_id) mode IP (add|del|update)"
821 			" flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
822 			" src (src_ip_address) (src_port)"
823 			" dst (dst_ip_address) (dst_port)"
824 			" tos (tos_value) ttl (ttl_value)"
825 			" vlan (vlan_value) flexbytes (flexbytes_value)"
826 			" (drop|fwd) pf|vf(vf_id) queue (queue_id)"
827 			" fd_id (fd_id_value)\n"
828 			"    Add/Del an UDP/TCP type flow director filter.\n\n"
829 
830 			"flow_director_filter (port_id) mode IP (add|del|update)"
831 			" flow (ipv4-sctp|ipv6-sctp)"
832 			" src (src_ip_address) (src_port)"
833 			" dst (dst_ip_address) (dst_port)"
834 			" tag (verification_tag) "
835 			" tos (tos_value) ttl (ttl_value)"
836 			" vlan (vlan_value)"
837 			" flexbytes (flexbytes_value) (drop|fwd)"
838 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
839 			"    Add/Del a SCTP type flow director filter.\n\n"
840 
841 			"flow_director_filter (port_id) mode IP (add|del|update)"
842 			" flow l2_payload ether (ethertype)"
843 			" flexbytes (flexbytes_value) (drop|fwd)"
844 			" pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
845 			"    Add/Del a l2 payload type flow director filter.\n\n"
846 
847 			"flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
848 			" mac (mac_address) vlan (vlan_value)"
849 			" flexbytes (flexbytes_value) (drop|fwd)"
850 			" queue (queue_id) fd_id (fd_id_value)\n"
851 			"    Add/Del a MAC-VLAN flow director filter.\n\n"
852 
853 			"flow_director_filter (port_id) mode Tunnel (add|del|update)"
854 			" mac (mac_address) vlan (vlan_value)"
855 			" tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
856 			" flexbytes (flexbytes_value) (drop|fwd)"
857 			" queue (queue_id) fd_id (fd_id_value)\n"
858 			"    Add/Del a Tunnel flow director filter.\n\n"
859 
860 			"flush_flow_director (port_id)\n"
861 			"    Flush all flow director entries of a device.\n\n"
862 
863 			"flow_director_mask (port_id) mode IP vlan (vlan_value)"
864 			" src_mask (ipv4_src) (ipv6_src) (src_port)"
865 			" dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
866 			"    Set flow director IP mask.\n\n"
867 
868 			"flow_director_mask (port_id) mode MAC-VLAN"
869 			" vlan (vlan_value)\n"
870 			"    Set flow director MAC-VLAN mask.\n\n"
871 
872 			"flow_director_mask (port_id) mode Tunnel"
873 			" vlan (vlan_value) mac (mac_value)"
874 			" tunnel-type (tunnel_type_value)"
875 			" tunnel-id (tunnel_id_value)\n"
876 			"    Set flow director Tunnel mask.\n\n"
877 
878 			"flow_director_flex_mask (port_id)"
879 			" flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
880 			"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
881 			" (mask)\n"
882 			"    Configure mask of flex payload.\n\n"
883 
884 			"flow_director_flex_payload (port_id)"
885 			" (raw|l2|l3|l4) (config)\n"
886 			"    Configure flex payload selection.\n\n"
887 
888 			"get_sym_hash_ena_per_port (port_id)\n"
889 			"    get symmetric hash enable configuration per port.\n\n"
890 
891 			"set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
892 			"    set symmetric hash enable configuration per port"
893 			" to enable or disable.\n\n"
894 
895 			"get_hash_global_config (port_id)\n"
896 			"    Get the global configurations of hash filters.\n\n"
897 
898 			"set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
899 			" (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
900 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
901 			" (enable|disable)\n"
902 			"    Set the global configurations of hash filters.\n\n"
903 
904 			"set_hash_input_set (port_id) (ipv4|ipv4-frag|"
905 			"ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
906 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
907 			"l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
908 			"src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
909 			"ipv6-next-header|udp-src-port|udp-dst-port|"
910 			"tcp-src-port|tcp-dst-port|sctp-src-port|"
911 			"sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
912 			"fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
913 			"fld-8th|none) (select|add)\n"
914 			"    Set the input set for hash.\n\n"
915 
916 			"set_fdir_input_set (port_id) "
917 			"(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
918 			"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
919 			"l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
920 			"dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
921 			"ipv6-next-header|ipv6-hop-limits|udp-src-port|"
922 			"udp-dst-port|tcp-src-port|tcp-dst-port|"
923 			"sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
924 			" (select|add)\n"
925 			"    Set the input set for FDir.\n\n"
926 
927 			"flow validate {port_id}"
928 			" [group {group_id}] [priority {level}]"
929 			" [ingress] [egress]"
930 			" pattern {item} [/ {item} [...]] / end"
931 			" actions {action} [/ {action} [...]] / end\n"
932 			"    Check whether a flow rule can be created.\n\n"
933 
934 			"flow create {port_id}"
935 			" [group {group_id}] [priority {level}]"
936 			" [ingress] [egress]"
937 			" pattern {item} [/ {item} [...]] / end"
938 			" actions {action} [/ {action} [...]] / end\n"
939 			"    Create a flow rule.\n\n"
940 
941 			"flow destroy {port_id} rule {rule_id} [...]\n"
942 			"    Destroy specific flow rules.\n\n"
943 
944 			"flow flush {port_id}\n"
945 			"    Destroy all flow rules.\n\n"
946 
947 			"flow query {port_id} {rule_id} {action}\n"
948 			"    Query an existing flow rule.\n\n"
949 
950 			"flow list {port_id} [group {group_id}] [...]\n"
951 			"    List existing flow rules sorted by priority,"
952 			" filtered by group identifiers.\n\n"
953 
954 			"flow isolate {port_id} {boolean}\n"
955 			"    Restrict ingress traffic to the defined"
956 			" flow rules\n\n"
957 		);
958 	}
959 }
960 
961 cmdline_parse_token_string_t cmd_help_long_help =
962 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
963 
964 cmdline_parse_token_string_t cmd_help_long_section =
965 	TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
966 			"all#control#display#config#"
967 			"ports#registers#filters");
968 
969 cmdline_parse_inst_t cmd_help_long = {
970 	.f = cmd_help_long_parsed,
971 	.data = NULL,
972 	.help_str = "help all|control|display|config|ports|register|filters: "
973 		"Show help",
974 	.tokens = {
975 		(void *)&cmd_help_long_help,
976 		(void *)&cmd_help_long_section,
977 		NULL,
978 	},
979 };
980 
981 
982 /* *** start/stop/close all ports *** */
983 struct cmd_operate_port_result {
984 	cmdline_fixed_string_t keyword;
985 	cmdline_fixed_string_t name;
986 	cmdline_fixed_string_t value;
987 };
988 
989 static void cmd_operate_port_parsed(void *parsed_result,
990 				__attribute__((unused)) struct cmdline *cl,
991 				__attribute__((unused)) void *data)
992 {
993 	struct cmd_operate_port_result *res = parsed_result;
994 
995 	if (!strcmp(res->name, "start"))
996 		start_port(RTE_PORT_ALL);
997 	else if (!strcmp(res->name, "stop"))
998 		stop_port(RTE_PORT_ALL);
999 	else if (!strcmp(res->name, "close"))
1000 		close_port(RTE_PORT_ALL);
1001 	else if (!strcmp(res->name, "reset"))
1002 		reset_port(RTE_PORT_ALL);
1003 	else
1004 		printf("Unknown parameter\n");
1005 }
1006 
1007 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1008 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1009 								"port");
1010 cmdline_parse_token_string_t cmd_operate_port_all_port =
1011 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1012 						"start#stop#close#reset");
1013 cmdline_parse_token_string_t cmd_operate_port_all_all =
1014 	TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1015 
1016 cmdline_parse_inst_t cmd_operate_port = {
1017 	.f = cmd_operate_port_parsed,
1018 	.data = NULL,
1019 	.help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1020 	.tokens = {
1021 		(void *)&cmd_operate_port_all_cmd,
1022 		(void *)&cmd_operate_port_all_port,
1023 		(void *)&cmd_operate_port_all_all,
1024 		NULL,
1025 	},
1026 };
1027 
1028 /* *** start/stop/close specific port *** */
1029 struct cmd_operate_specific_port_result {
1030 	cmdline_fixed_string_t keyword;
1031 	cmdline_fixed_string_t name;
1032 	uint8_t value;
1033 };
1034 
1035 static void cmd_operate_specific_port_parsed(void *parsed_result,
1036 			__attribute__((unused)) struct cmdline *cl,
1037 				__attribute__((unused)) void *data)
1038 {
1039 	struct cmd_operate_specific_port_result *res = parsed_result;
1040 
1041 	if (!strcmp(res->name, "start"))
1042 		start_port(res->value);
1043 	else if (!strcmp(res->name, "stop"))
1044 		stop_port(res->value);
1045 	else if (!strcmp(res->name, "close"))
1046 		close_port(res->value);
1047 	else if (!strcmp(res->name, "reset"))
1048 		reset_port(res->value);
1049 	else
1050 		printf("Unknown parameter\n");
1051 }
1052 
1053 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1054 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1055 							keyword, "port");
1056 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1057 	TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1058 						name, "start#stop#close#reset");
1059 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1060 	TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1061 							value, UINT8);
1062 
1063 cmdline_parse_inst_t cmd_operate_specific_port = {
1064 	.f = cmd_operate_specific_port_parsed,
1065 	.data = NULL,
1066 	.help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1067 	.tokens = {
1068 		(void *)&cmd_operate_specific_port_cmd,
1069 		(void *)&cmd_operate_specific_port_port,
1070 		(void *)&cmd_operate_specific_port_id,
1071 		NULL,
1072 	},
1073 };
1074 
1075 /* *** attach a specified port *** */
1076 struct cmd_operate_attach_port_result {
1077 	cmdline_fixed_string_t port;
1078 	cmdline_fixed_string_t keyword;
1079 	cmdline_fixed_string_t identifier;
1080 };
1081 
1082 static void cmd_operate_attach_port_parsed(void *parsed_result,
1083 				__attribute__((unused)) struct cmdline *cl,
1084 				__attribute__((unused)) void *data)
1085 {
1086 	struct cmd_operate_attach_port_result *res = parsed_result;
1087 
1088 	if (!strcmp(res->keyword, "attach"))
1089 		attach_port(res->identifier);
1090 	else
1091 		printf("Unknown parameter\n");
1092 }
1093 
1094 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1095 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1096 			port, "port");
1097 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1098 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1099 			keyword, "attach");
1100 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1101 	TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1102 			identifier, NULL);
1103 
1104 cmdline_parse_inst_t cmd_operate_attach_port = {
1105 	.f = cmd_operate_attach_port_parsed,
1106 	.data = NULL,
1107 	.help_str = "port attach <identifier>: "
1108 		"(identifier: pci address or virtual dev name)",
1109 	.tokens = {
1110 		(void *)&cmd_operate_attach_port_port,
1111 		(void *)&cmd_operate_attach_port_keyword,
1112 		(void *)&cmd_operate_attach_port_identifier,
1113 		NULL,
1114 	},
1115 };
1116 
1117 /* *** detach a specified port *** */
1118 struct cmd_operate_detach_port_result {
1119 	cmdline_fixed_string_t port;
1120 	cmdline_fixed_string_t keyword;
1121 	uint8_t port_id;
1122 };
1123 
1124 static void cmd_operate_detach_port_parsed(void *parsed_result,
1125 				__attribute__((unused)) struct cmdline *cl,
1126 				__attribute__((unused)) void *data)
1127 {
1128 	struct cmd_operate_detach_port_result *res = parsed_result;
1129 
1130 	if (!strcmp(res->keyword, "detach"))
1131 		detach_port(res->port_id);
1132 	else
1133 		printf("Unknown parameter\n");
1134 }
1135 
1136 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1137 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1138 			port, "port");
1139 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1140 	TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1141 			keyword, "detach");
1142 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1143 	TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1144 			port_id, UINT8);
1145 
1146 cmdline_parse_inst_t cmd_operate_detach_port = {
1147 	.f = cmd_operate_detach_port_parsed,
1148 	.data = NULL,
1149 	.help_str = "port detach <port_id>",
1150 	.tokens = {
1151 		(void *)&cmd_operate_detach_port_port,
1152 		(void *)&cmd_operate_detach_port_keyword,
1153 		(void *)&cmd_operate_detach_port_port_id,
1154 		NULL,
1155 	},
1156 };
1157 
1158 /* *** configure speed for all ports *** */
1159 struct cmd_config_speed_all {
1160 	cmdline_fixed_string_t port;
1161 	cmdline_fixed_string_t keyword;
1162 	cmdline_fixed_string_t all;
1163 	cmdline_fixed_string_t item1;
1164 	cmdline_fixed_string_t item2;
1165 	cmdline_fixed_string_t value1;
1166 	cmdline_fixed_string_t value2;
1167 };
1168 
1169 static int
1170 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1171 {
1172 
1173 	int duplex;
1174 
1175 	if (!strcmp(duplexstr, "half")) {
1176 		duplex = ETH_LINK_HALF_DUPLEX;
1177 	} else if (!strcmp(duplexstr, "full")) {
1178 		duplex = ETH_LINK_FULL_DUPLEX;
1179 	} else if (!strcmp(duplexstr, "auto")) {
1180 		duplex = ETH_LINK_FULL_DUPLEX;
1181 	} else {
1182 		printf("Unknown duplex parameter\n");
1183 		return -1;
1184 	}
1185 
1186 	if (!strcmp(speedstr, "10")) {
1187 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1188 				ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1189 	} else if (!strcmp(speedstr, "100")) {
1190 		*speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1191 				ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1192 	} else {
1193 		if (duplex != ETH_LINK_FULL_DUPLEX) {
1194 			printf("Invalid speed/duplex parameters\n");
1195 			return -1;
1196 		}
1197 		if (!strcmp(speedstr, "1000")) {
1198 			*speed = ETH_LINK_SPEED_1G;
1199 		} else if (!strcmp(speedstr, "10000")) {
1200 			*speed = ETH_LINK_SPEED_10G;
1201 		} else if (!strcmp(speedstr, "25000")) {
1202 			*speed = ETH_LINK_SPEED_25G;
1203 		} else if (!strcmp(speedstr, "40000")) {
1204 			*speed = ETH_LINK_SPEED_40G;
1205 		} else if (!strcmp(speedstr, "50000")) {
1206 			*speed = ETH_LINK_SPEED_50G;
1207 		} else if (!strcmp(speedstr, "100000")) {
1208 			*speed = ETH_LINK_SPEED_100G;
1209 		} else if (!strcmp(speedstr, "auto")) {
1210 			*speed = ETH_LINK_SPEED_AUTONEG;
1211 		} else {
1212 			printf("Unknown speed parameter\n");
1213 			return -1;
1214 		}
1215 	}
1216 
1217 	return 0;
1218 }
1219 
1220 static void
1221 cmd_config_speed_all_parsed(void *parsed_result,
1222 			__attribute__((unused)) struct cmdline *cl,
1223 			__attribute__((unused)) void *data)
1224 {
1225 	struct cmd_config_speed_all *res = parsed_result;
1226 	uint32_t link_speed;
1227 	portid_t pid;
1228 
1229 	if (!all_ports_stopped()) {
1230 		printf("Please stop all ports first\n");
1231 		return;
1232 	}
1233 
1234 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1235 			&link_speed) < 0)
1236 		return;
1237 
1238 	RTE_ETH_FOREACH_DEV(pid) {
1239 		ports[pid].dev_conf.link_speeds = link_speed;
1240 	}
1241 
1242 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1243 }
1244 
1245 cmdline_parse_token_string_t cmd_config_speed_all_port =
1246 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1247 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1248 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1249 							"config");
1250 cmdline_parse_token_string_t cmd_config_speed_all_all =
1251 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1252 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1253 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1254 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1255 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1256 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1257 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1258 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1259 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1260 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1261 						"half#full#auto");
1262 
1263 cmdline_parse_inst_t cmd_config_speed_all = {
1264 	.f = cmd_config_speed_all_parsed,
1265 	.data = NULL,
1266 	.help_str = "port config all speed "
1267 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1268 							"half|full|auto",
1269 	.tokens = {
1270 		(void *)&cmd_config_speed_all_port,
1271 		(void *)&cmd_config_speed_all_keyword,
1272 		(void *)&cmd_config_speed_all_all,
1273 		(void *)&cmd_config_speed_all_item1,
1274 		(void *)&cmd_config_speed_all_value1,
1275 		(void *)&cmd_config_speed_all_item2,
1276 		(void *)&cmd_config_speed_all_value2,
1277 		NULL,
1278 	},
1279 };
1280 
1281 /* *** configure speed for specific port *** */
1282 struct cmd_config_speed_specific {
1283 	cmdline_fixed_string_t port;
1284 	cmdline_fixed_string_t keyword;
1285 	uint8_t id;
1286 	cmdline_fixed_string_t item1;
1287 	cmdline_fixed_string_t item2;
1288 	cmdline_fixed_string_t value1;
1289 	cmdline_fixed_string_t value2;
1290 };
1291 
1292 static void
1293 cmd_config_speed_specific_parsed(void *parsed_result,
1294 				__attribute__((unused)) struct cmdline *cl,
1295 				__attribute__((unused)) void *data)
1296 {
1297 	struct cmd_config_speed_specific *res = parsed_result;
1298 	uint32_t link_speed;
1299 
1300 	if (!all_ports_stopped()) {
1301 		printf("Please stop all ports first\n");
1302 		return;
1303 	}
1304 
1305 	if (port_id_is_invalid(res->id, ENABLED_WARN))
1306 		return;
1307 
1308 	if (parse_and_check_speed_duplex(res->value1, res->value2,
1309 			&link_speed) < 0)
1310 		return;
1311 
1312 	ports[res->id].dev_conf.link_speeds = link_speed;
1313 
1314 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1315 }
1316 
1317 
1318 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1319 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1320 								"port");
1321 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1322 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1323 								"config");
1324 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1325 	TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1326 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1327 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1328 								"speed");
1329 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1330 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1331 				"10#100#1000#10000#25000#40000#50000#100000#auto");
1332 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1333 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1334 								"duplex");
1335 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1336 	TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1337 							"half#full#auto");
1338 
1339 cmdline_parse_inst_t cmd_config_speed_specific = {
1340 	.f = cmd_config_speed_specific_parsed,
1341 	.data = NULL,
1342 	.help_str = "port config <port_id> speed "
1343 		"10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1344 							"half|full|auto",
1345 	.tokens = {
1346 		(void *)&cmd_config_speed_specific_port,
1347 		(void *)&cmd_config_speed_specific_keyword,
1348 		(void *)&cmd_config_speed_specific_id,
1349 		(void *)&cmd_config_speed_specific_item1,
1350 		(void *)&cmd_config_speed_specific_value1,
1351 		(void *)&cmd_config_speed_specific_item2,
1352 		(void *)&cmd_config_speed_specific_value2,
1353 		NULL,
1354 	},
1355 };
1356 
1357 /* *** configure txq/rxq, txd/rxd *** */
1358 struct cmd_config_rx_tx {
1359 	cmdline_fixed_string_t port;
1360 	cmdline_fixed_string_t keyword;
1361 	cmdline_fixed_string_t all;
1362 	cmdline_fixed_string_t name;
1363 	uint16_t value;
1364 };
1365 
1366 static void
1367 cmd_config_rx_tx_parsed(void *parsed_result,
1368 			__attribute__((unused)) struct cmdline *cl,
1369 			__attribute__((unused)) void *data)
1370 {
1371 	struct cmd_config_rx_tx *res = parsed_result;
1372 
1373 	if (!all_ports_stopped()) {
1374 		printf("Please stop all ports first\n");
1375 		return;
1376 	}
1377 	if (!strcmp(res->name, "rxq")) {
1378 		if (!res->value && !nb_txq) {
1379 			printf("Warning: Either rx or tx queues should be non zero\n");
1380 			return;
1381 		}
1382 		nb_rxq = res->value;
1383 	}
1384 	else if (!strcmp(res->name, "txq")) {
1385 		if (!res->value && !nb_rxq) {
1386 			printf("Warning: Either rx or tx queues should be non zero\n");
1387 			return;
1388 		}
1389 		nb_txq = res->value;
1390 	}
1391 	else if (!strcmp(res->name, "rxd")) {
1392 		if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1393 			printf("rxd %d invalid - must be > 0 && <= %d\n",
1394 					res->value, RTE_TEST_RX_DESC_MAX);
1395 			return;
1396 		}
1397 		nb_rxd = res->value;
1398 	} else if (!strcmp(res->name, "txd")) {
1399 		if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1400 			printf("txd %d invalid - must be > 0 && <= %d\n",
1401 					res->value, RTE_TEST_TX_DESC_MAX);
1402 			return;
1403 		}
1404 		nb_txd = res->value;
1405 	} else {
1406 		printf("Unknown parameter\n");
1407 		return;
1408 	}
1409 
1410 	fwd_config_setup();
1411 
1412 	init_port_config();
1413 
1414 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1415 }
1416 
1417 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1418 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1419 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1420 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1421 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1422 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1423 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1424 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1425 						"rxq#txq#rxd#txd");
1426 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1427 	TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1428 
1429 cmdline_parse_inst_t cmd_config_rx_tx = {
1430 	.f = cmd_config_rx_tx_parsed,
1431 	.data = NULL,
1432 	.help_str = "port config all rxq|txq|rxd|txd <value>",
1433 	.tokens = {
1434 		(void *)&cmd_config_rx_tx_port,
1435 		(void *)&cmd_config_rx_tx_keyword,
1436 		(void *)&cmd_config_rx_tx_all,
1437 		(void *)&cmd_config_rx_tx_name,
1438 		(void *)&cmd_config_rx_tx_value,
1439 		NULL,
1440 	},
1441 };
1442 
1443 /* *** config max packet length *** */
1444 struct cmd_config_max_pkt_len_result {
1445 	cmdline_fixed_string_t port;
1446 	cmdline_fixed_string_t keyword;
1447 	cmdline_fixed_string_t all;
1448 	cmdline_fixed_string_t name;
1449 	uint32_t value;
1450 };
1451 
1452 static void
1453 cmd_config_max_pkt_len_parsed(void *parsed_result,
1454 				__attribute__((unused)) struct cmdline *cl,
1455 				__attribute__((unused)) void *data)
1456 {
1457 	struct cmd_config_max_pkt_len_result *res = parsed_result;
1458 
1459 	if (!all_ports_stopped()) {
1460 		printf("Please stop all ports first\n");
1461 		return;
1462 	}
1463 
1464 	if (!strcmp(res->name, "max-pkt-len")) {
1465 		if (res->value < ETHER_MIN_LEN) {
1466 			printf("max-pkt-len can not be less than %d\n",
1467 							ETHER_MIN_LEN);
1468 			return;
1469 		}
1470 		if (res->value == rx_mode.max_rx_pkt_len)
1471 			return;
1472 
1473 		rx_mode.max_rx_pkt_len = res->value;
1474 		if (res->value > ETHER_MAX_LEN)
1475 			rx_mode.jumbo_frame = 1;
1476 		else
1477 			rx_mode.jumbo_frame = 0;
1478 	} else {
1479 		printf("Unknown parameter\n");
1480 		return;
1481 	}
1482 
1483 	init_port_config();
1484 
1485 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1486 }
1487 
1488 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1489 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1490 								"port");
1491 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1492 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1493 								"config");
1494 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1495 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1496 								"all");
1497 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1498 	TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1499 								"max-pkt-len");
1500 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1501 	TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1502 								UINT32);
1503 
1504 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1505 	.f = cmd_config_max_pkt_len_parsed,
1506 	.data = NULL,
1507 	.help_str = "port config all max-pkt-len <value>",
1508 	.tokens = {
1509 		(void *)&cmd_config_max_pkt_len_port,
1510 		(void *)&cmd_config_max_pkt_len_keyword,
1511 		(void *)&cmd_config_max_pkt_len_all,
1512 		(void *)&cmd_config_max_pkt_len_name,
1513 		(void *)&cmd_config_max_pkt_len_value,
1514 		NULL,
1515 	},
1516 };
1517 
1518 /* *** configure port MTU *** */
1519 struct cmd_config_mtu_result {
1520 	cmdline_fixed_string_t port;
1521 	cmdline_fixed_string_t keyword;
1522 	cmdline_fixed_string_t mtu;
1523 	uint8_t port_id;
1524 	uint16_t value;
1525 };
1526 
1527 static void
1528 cmd_config_mtu_parsed(void *parsed_result,
1529 		      __attribute__((unused)) struct cmdline *cl,
1530 		      __attribute__((unused)) void *data)
1531 {
1532 	struct cmd_config_mtu_result *res = parsed_result;
1533 
1534 	if (res->value < ETHER_MIN_LEN) {
1535 		printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1536 		return;
1537 	}
1538 	port_mtu_set(res->port_id, res->value);
1539 }
1540 
1541 cmdline_parse_token_string_t cmd_config_mtu_port =
1542 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1543 				 "port");
1544 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1545 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1546 				 "config");
1547 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1548 	TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1549 				 "mtu");
1550 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1551 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1552 cmdline_parse_token_num_t cmd_config_mtu_value =
1553 	TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1554 
1555 cmdline_parse_inst_t cmd_config_mtu = {
1556 	.f = cmd_config_mtu_parsed,
1557 	.data = NULL,
1558 	.help_str = "port config mtu <port_id> <value>",
1559 	.tokens = {
1560 		(void *)&cmd_config_mtu_port,
1561 		(void *)&cmd_config_mtu_keyword,
1562 		(void *)&cmd_config_mtu_mtu,
1563 		(void *)&cmd_config_mtu_port_id,
1564 		(void *)&cmd_config_mtu_value,
1565 		NULL,
1566 	},
1567 };
1568 
1569 /* *** configure rx mode *** */
1570 struct cmd_config_rx_mode_flag {
1571 	cmdline_fixed_string_t port;
1572 	cmdline_fixed_string_t keyword;
1573 	cmdline_fixed_string_t all;
1574 	cmdline_fixed_string_t name;
1575 	cmdline_fixed_string_t value;
1576 };
1577 
1578 static void
1579 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1580 				__attribute__((unused)) struct cmdline *cl,
1581 				__attribute__((unused)) void *data)
1582 {
1583 	struct cmd_config_rx_mode_flag *res = parsed_result;
1584 
1585 	if (!all_ports_stopped()) {
1586 		printf("Please stop all ports first\n");
1587 		return;
1588 	}
1589 
1590 	if (!strcmp(res->name, "crc-strip")) {
1591 		if (!strcmp(res->value, "on"))
1592 			rx_mode.hw_strip_crc = 1;
1593 		else if (!strcmp(res->value, "off"))
1594 			rx_mode.hw_strip_crc = 0;
1595 		else {
1596 			printf("Unknown parameter\n");
1597 			return;
1598 		}
1599 	} else if (!strcmp(res->name, "scatter")) {
1600 		if (!strcmp(res->value, "on"))
1601 			rx_mode.enable_scatter = 1;
1602 		else if (!strcmp(res->value, "off"))
1603 			rx_mode.enable_scatter = 0;
1604 		else {
1605 			printf("Unknown parameter\n");
1606 			return;
1607 		}
1608 	} else if (!strcmp(res->name, "rx-cksum")) {
1609 		if (!strcmp(res->value, "on"))
1610 			rx_mode.hw_ip_checksum = 1;
1611 		else if (!strcmp(res->value, "off"))
1612 			rx_mode.hw_ip_checksum = 0;
1613 		else {
1614 			printf("Unknown parameter\n");
1615 			return;
1616 		}
1617 	} else if (!strcmp(res->name, "hw-vlan")) {
1618 		if (!strcmp(res->value, "on")) {
1619 			rx_mode.hw_vlan_filter = 1;
1620 			rx_mode.hw_vlan_strip  = 1;
1621 		}
1622 		else if (!strcmp(res->value, "off")) {
1623 			rx_mode.hw_vlan_filter = 0;
1624 			rx_mode.hw_vlan_strip  = 0;
1625 		}
1626 		else {
1627 			printf("Unknown parameter\n");
1628 			return;
1629 		}
1630 	} else if (!strcmp(res->name, "hw-vlan-filter")) {
1631 		if (!strcmp(res->value, "on"))
1632 			rx_mode.hw_vlan_filter = 1;
1633 		else if (!strcmp(res->value, "off"))
1634 			rx_mode.hw_vlan_filter = 0;
1635 		else {
1636 			printf("Unknown parameter\n");
1637 			return;
1638 		}
1639 	} else if (!strcmp(res->name, "hw-vlan-strip")) {
1640 		if (!strcmp(res->value, "on"))
1641 			rx_mode.hw_vlan_strip  = 1;
1642 		else if (!strcmp(res->value, "off"))
1643 			rx_mode.hw_vlan_strip  = 0;
1644 		else {
1645 			printf("Unknown parameter\n");
1646 			return;
1647 		}
1648 	} else if (!strcmp(res->name, "hw-vlan-extend")) {
1649 		if (!strcmp(res->value, "on"))
1650 			rx_mode.hw_vlan_extend = 1;
1651 		else if (!strcmp(res->value, "off"))
1652 			rx_mode.hw_vlan_extend = 0;
1653 		else {
1654 			printf("Unknown parameter\n");
1655 			return;
1656 		}
1657 	} else if (!strcmp(res->name, "drop-en")) {
1658 		if (!strcmp(res->value, "on"))
1659 			rx_drop_en = 1;
1660 		else if (!strcmp(res->value, "off"))
1661 			rx_drop_en = 0;
1662 		else {
1663 			printf("Unknown parameter\n");
1664 			return;
1665 		}
1666 	} else {
1667 		printf("Unknown parameter\n");
1668 		return;
1669 	}
1670 
1671 	init_port_config();
1672 
1673 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1674 }
1675 
1676 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1677 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1678 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1679 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1680 								"config");
1681 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1682 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1683 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1684 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1685 					"crc-strip#scatter#rx-cksum#hw-vlan#"
1686 					"hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1687 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1688 	TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1689 							"on#off");
1690 
1691 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1692 	.f = cmd_config_rx_mode_flag_parsed,
1693 	.data = NULL,
1694 	.help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|"
1695 		"hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1696 	.tokens = {
1697 		(void *)&cmd_config_rx_mode_flag_port,
1698 		(void *)&cmd_config_rx_mode_flag_keyword,
1699 		(void *)&cmd_config_rx_mode_flag_all,
1700 		(void *)&cmd_config_rx_mode_flag_name,
1701 		(void *)&cmd_config_rx_mode_flag_value,
1702 		NULL,
1703 	},
1704 };
1705 
1706 /* *** configure rss *** */
1707 struct cmd_config_rss {
1708 	cmdline_fixed_string_t port;
1709 	cmdline_fixed_string_t keyword;
1710 	cmdline_fixed_string_t all;
1711 	cmdline_fixed_string_t name;
1712 	cmdline_fixed_string_t value;
1713 };
1714 
1715 static void
1716 cmd_config_rss_parsed(void *parsed_result,
1717 			__attribute__((unused)) struct cmdline *cl,
1718 			__attribute__((unused)) void *data)
1719 {
1720 	struct cmd_config_rss *res = parsed_result;
1721 	struct rte_eth_rss_conf rss_conf;
1722 	int diag;
1723 	uint8_t i;
1724 
1725 	if (!strcmp(res->value, "all"))
1726 		rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1727 				ETH_RSS_UDP | ETH_RSS_SCTP |
1728 					ETH_RSS_L2_PAYLOAD;
1729 	else if (!strcmp(res->value, "ip"))
1730 		rss_conf.rss_hf = ETH_RSS_IP;
1731 	else if (!strcmp(res->value, "udp"))
1732 		rss_conf.rss_hf = ETH_RSS_UDP;
1733 	else if (!strcmp(res->value, "tcp"))
1734 		rss_conf.rss_hf = ETH_RSS_TCP;
1735 	else if (!strcmp(res->value, "sctp"))
1736 		rss_conf.rss_hf = ETH_RSS_SCTP;
1737 	else if (!strcmp(res->value, "ether"))
1738 		rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1739 	else if (!strcmp(res->value, "port"))
1740 		rss_conf.rss_hf = ETH_RSS_PORT;
1741 	else if (!strcmp(res->value, "vxlan"))
1742 		rss_conf.rss_hf = ETH_RSS_VXLAN;
1743 	else if (!strcmp(res->value, "geneve"))
1744 		rss_conf.rss_hf = ETH_RSS_GENEVE;
1745 	else if (!strcmp(res->value, "nvgre"))
1746 		rss_conf.rss_hf = ETH_RSS_NVGRE;
1747 	else if (!strcmp(res->value, "none"))
1748 		rss_conf.rss_hf = 0;
1749 	else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1750 						atoi(res->value) < 64)
1751 		rss_conf.rss_hf = 1ULL << atoi(res->value);
1752 	else {
1753 		printf("Unknown parameter\n");
1754 		return;
1755 	}
1756 	rss_conf.rss_key = NULL;
1757 	for (i = 0; i < rte_eth_dev_count(); i++) {
1758 		diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1759 		if (diag < 0)
1760 			printf("Configuration of RSS hash at ethernet port %d "
1761 				"failed with error (%d): %s.\n",
1762 				i, -diag, strerror(-diag));
1763 	}
1764 }
1765 
1766 cmdline_parse_token_string_t cmd_config_rss_port =
1767 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1768 cmdline_parse_token_string_t cmd_config_rss_keyword =
1769 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1770 cmdline_parse_token_string_t cmd_config_rss_all =
1771 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1772 cmdline_parse_token_string_t cmd_config_rss_name =
1773 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1774 cmdline_parse_token_string_t cmd_config_rss_value =
1775 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1776 
1777 cmdline_parse_inst_t cmd_config_rss = {
1778 	.f = cmd_config_rss_parsed,
1779 	.data = NULL,
1780 	.help_str = "port config all rss "
1781 		"all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1782 	.tokens = {
1783 		(void *)&cmd_config_rss_port,
1784 		(void *)&cmd_config_rss_keyword,
1785 		(void *)&cmd_config_rss_all,
1786 		(void *)&cmd_config_rss_name,
1787 		(void *)&cmd_config_rss_value,
1788 		NULL,
1789 	},
1790 };
1791 
1792 /* *** configure rss hash key *** */
1793 struct cmd_config_rss_hash_key {
1794 	cmdline_fixed_string_t port;
1795 	cmdline_fixed_string_t config;
1796 	uint8_t port_id;
1797 	cmdline_fixed_string_t rss_hash_key;
1798 	cmdline_fixed_string_t rss_type;
1799 	cmdline_fixed_string_t key;
1800 };
1801 
1802 static uint8_t
1803 hexa_digit_to_value(char hexa_digit)
1804 {
1805 	if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1806 		return (uint8_t) (hexa_digit - '0');
1807 	if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1808 		return (uint8_t) ((hexa_digit - 'a') + 10);
1809 	if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1810 		return (uint8_t) ((hexa_digit - 'A') + 10);
1811 	/* Invalid hexa digit */
1812 	return 0xFF;
1813 }
1814 
1815 static uint8_t
1816 parse_and_check_key_hexa_digit(char *key, int idx)
1817 {
1818 	uint8_t hexa_v;
1819 
1820 	hexa_v = hexa_digit_to_value(key[idx]);
1821 	if (hexa_v == 0xFF)
1822 		printf("invalid key: character %c at position %d is not a "
1823 		       "valid hexa digit\n", key[idx], idx);
1824 	return hexa_v;
1825 }
1826 
1827 static void
1828 cmd_config_rss_hash_key_parsed(void *parsed_result,
1829 			       __attribute__((unused)) struct cmdline *cl,
1830 			       __attribute__((unused)) void *data)
1831 {
1832 	struct cmd_config_rss_hash_key *res = parsed_result;
1833 	uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1834 	uint8_t xdgt0;
1835 	uint8_t xdgt1;
1836 	int i;
1837 	struct rte_eth_dev_info dev_info;
1838 	uint8_t hash_key_size;
1839 	uint32_t key_len;
1840 
1841 	memset(&dev_info, 0, sizeof(dev_info));
1842 	rte_eth_dev_info_get(res->port_id, &dev_info);
1843 	if (dev_info.hash_key_size > 0 &&
1844 			dev_info.hash_key_size <= sizeof(hash_key))
1845 		hash_key_size = dev_info.hash_key_size;
1846 	else {
1847 		printf("dev_info did not provide a valid hash key size\n");
1848 		return;
1849 	}
1850 	/* Check the length of the RSS hash key */
1851 	key_len = strlen(res->key);
1852 	if (key_len != (hash_key_size * 2)) {
1853 		printf("key length: %d invalid - key must be a string of %d"
1854 			   " hexa-decimal numbers\n",
1855 			   (int) key_len, hash_key_size * 2);
1856 		return;
1857 	}
1858 	/* Translate RSS hash key into binary representation */
1859 	for (i = 0; i < hash_key_size; i++) {
1860 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1861 		if (xdgt0 == 0xFF)
1862 			return;
1863 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1864 		if (xdgt1 == 0xFF)
1865 			return;
1866 		hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1867 	}
1868 	port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1869 			hash_key_size);
1870 }
1871 
1872 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1873 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1874 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1875 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1876 				 "config");
1877 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1878 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1879 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1880 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1881 				 rss_hash_key, "rss-hash-key");
1882 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1883 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1884 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1885 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1886 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1887 				 "ipv6-tcp-ex#ipv6-udp-ex");
1888 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1889 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1890 
1891 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1892 	.f = cmd_config_rss_hash_key_parsed,
1893 	.data = NULL,
1894 	.help_str = "port config <port_id> rss-hash-key "
1895 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1896 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1897 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
1898 		"<string of hex digits (variable length, NIC dependent)>",
1899 	.tokens = {
1900 		(void *)&cmd_config_rss_hash_key_port,
1901 		(void *)&cmd_config_rss_hash_key_config,
1902 		(void *)&cmd_config_rss_hash_key_port_id,
1903 		(void *)&cmd_config_rss_hash_key_rss_hash_key,
1904 		(void *)&cmd_config_rss_hash_key_rss_type,
1905 		(void *)&cmd_config_rss_hash_key_value,
1906 		NULL,
1907 	},
1908 };
1909 
1910 /* *** configure port rxq/txq start/stop *** */
1911 struct cmd_config_rxtx_queue {
1912 	cmdline_fixed_string_t port;
1913 	uint8_t portid;
1914 	cmdline_fixed_string_t rxtxq;
1915 	uint16_t qid;
1916 	cmdline_fixed_string_t opname;
1917 };
1918 
1919 static void
1920 cmd_config_rxtx_queue_parsed(void *parsed_result,
1921 			__attribute__((unused)) struct cmdline *cl,
1922 			__attribute__((unused)) void *data)
1923 {
1924 	struct cmd_config_rxtx_queue *res = parsed_result;
1925 	uint8_t isrx;
1926 	uint8_t isstart;
1927 	int ret = 0;
1928 
1929 	if (test_done == 0) {
1930 		printf("Please stop forwarding first\n");
1931 		return;
1932 	}
1933 
1934 	if (port_id_is_invalid(res->portid, ENABLED_WARN))
1935 		return;
1936 
1937 	if (port_is_started(res->portid) != 1) {
1938 		printf("Please start port %u first\n", res->portid);
1939 		return;
1940 	}
1941 
1942 	if (!strcmp(res->rxtxq, "rxq"))
1943 		isrx = 1;
1944 	else if (!strcmp(res->rxtxq, "txq"))
1945 		isrx = 0;
1946 	else {
1947 		printf("Unknown parameter\n");
1948 		return;
1949 	}
1950 
1951 	if (isrx && rx_queue_id_is_invalid(res->qid))
1952 		return;
1953 	else if (!isrx && tx_queue_id_is_invalid(res->qid))
1954 		return;
1955 
1956 	if (!strcmp(res->opname, "start"))
1957 		isstart = 1;
1958 	else if (!strcmp(res->opname, "stop"))
1959 		isstart = 0;
1960 	else {
1961 		printf("Unknown parameter\n");
1962 		return;
1963 	}
1964 
1965 	if (isstart && isrx)
1966 		ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1967 	else if (!isstart && isrx)
1968 		ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1969 	else if (isstart && !isrx)
1970 		ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1971 	else
1972 		ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1973 
1974 	if (ret == -ENOTSUP)
1975 		printf("Function not supported in PMD driver\n");
1976 }
1977 
1978 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1979 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1980 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1981 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1982 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1983 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1984 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1985 	TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1986 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1987 	TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1988 						"start#stop");
1989 
1990 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1991 	.f = cmd_config_rxtx_queue_parsed,
1992 	.data = NULL,
1993 	.help_str = "port <port_id> rxq|txq <queue_id> start|stop",
1994 	.tokens = {
1995 		(void *)&cmd_config_speed_all_port,
1996 		(void *)&cmd_config_rxtx_queue_portid,
1997 		(void *)&cmd_config_rxtx_queue_rxtxq,
1998 		(void *)&cmd_config_rxtx_queue_qid,
1999 		(void *)&cmd_config_rxtx_queue_opname,
2000 		NULL,
2001 	},
2002 };
2003 
2004 /* *** Configure RSS RETA *** */
2005 struct cmd_config_rss_reta {
2006 	cmdline_fixed_string_t port;
2007 	cmdline_fixed_string_t keyword;
2008 	uint8_t port_id;
2009 	cmdline_fixed_string_t name;
2010 	cmdline_fixed_string_t list_name;
2011 	cmdline_fixed_string_t list_of_items;
2012 };
2013 
2014 static int
2015 parse_reta_config(const char *str,
2016 		  struct rte_eth_rss_reta_entry64 *reta_conf,
2017 		  uint16_t nb_entries)
2018 {
2019 	int i;
2020 	unsigned size;
2021 	uint16_t hash_index, idx, shift;
2022 	uint16_t nb_queue;
2023 	char s[256];
2024 	const char *p, *p0 = str;
2025 	char *end;
2026 	enum fieldnames {
2027 		FLD_HASH_INDEX = 0,
2028 		FLD_QUEUE,
2029 		_NUM_FLD
2030 	};
2031 	unsigned long int_fld[_NUM_FLD];
2032 	char *str_fld[_NUM_FLD];
2033 
2034 	while ((p = strchr(p0,'(')) != NULL) {
2035 		++p;
2036 		if((p0 = strchr(p,')')) == NULL)
2037 			return -1;
2038 
2039 		size = p0 - p;
2040 		if(size >= sizeof(s))
2041 			return -1;
2042 
2043 		snprintf(s, sizeof(s), "%.*s", size, p);
2044 		if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2045 			return -1;
2046 		for (i = 0; i < _NUM_FLD; i++) {
2047 			errno = 0;
2048 			int_fld[i] = strtoul(str_fld[i], &end, 0);
2049 			if (errno != 0 || end == str_fld[i] ||
2050 					int_fld[i] > 65535)
2051 				return -1;
2052 		}
2053 
2054 		hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2055 		nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2056 
2057 		if (hash_index >= nb_entries) {
2058 			printf("Invalid RETA hash index=%d\n", hash_index);
2059 			return -1;
2060 		}
2061 
2062 		idx = hash_index / RTE_RETA_GROUP_SIZE;
2063 		shift = hash_index % RTE_RETA_GROUP_SIZE;
2064 		reta_conf[idx].mask |= (1ULL << shift);
2065 		reta_conf[idx].reta[shift] = nb_queue;
2066 	}
2067 
2068 	return 0;
2069 }
2070 
2071 static void
2072 cmd_set_rss_reta_parsed(void *parsed_result,
2073 			__attribute__((unused)) struct cmdline *cl,
2074 			__attribute__((unused)) void *data)
2075 {
2076 	int ret;
2077 	struct rte_eth_dev_info dev_info;
2078 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2079 	struct cmd_config_rss_reta *res = parsed_result;
2080 
2081 	memset(&dev_info, 0, sizeof(dev_info));
2082 	rte_eth_dev_info_get(res->port_id, &dev_info);
2083 	if (dev_info.reta_size == 0) {
2084 		printf("Redirection table size is 0 which is "
2085 					"invalid for RSS\n");
2086 		return;
2087 	} else
2088 		printf("The reta size of port %d is %u\n",
2089 			res->port_id, dev_info.reta_size);
2090 	if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2091 		printf("Currently do not support more than %u entries of "
2092 			"redirection table\n", ETH_RSS_RETA_SIZE_512);
2093 		return;
2094 	}
2095 
2096 	memset(reta_conf, 0, sizeof(reta_conf));
2097 	if (!strcmp(res->list_name, "reta")) {
2098 		if (parse_reta_config(res->list_of_items, reta_conf,
2099 						dev_info.reta_size)) {
2100 			printf("Invalid RSS Redirection Table "
2101 					"config entered\n");
2102 			return;
2103 		}
2104 		ret = rte_eth_dev_rss_reta_update(res->port_id,
2105 				reta_conf, dev_info.reta_size);
2106 		if (ret != 0)
2107 			printf("Bad redirection table parameter, "
2108 					"return code = %d \n", ret);
2109 	}
2110 }
2111 
2112 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2113 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2114 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2115 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2116 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2117 	TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
2118 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2119 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2120 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2121 	TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2122 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2124                                  NULL);
2125 cmdline_parse_inst_t cmd_config_rss_reta = {
2126 	.f = cmd_set_rss_reta_parsed,
2127 	.data = NULL,
2128 	.help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2129 	.tokens = {
2130 		(void *)&cmd_config_rss_reta_port,
2131 		(void *)&cmd_config_rss_reta_keyword,
2132 		(void *)&cmd_config_rss_reta_port_id,
2133 		(void *)&cmd_config_rss_reta_name,
2134 		(void *)&cmd_config_rss_reta_list_name,
2135 		(void *)&cmd_config_rss_reta_list_of_items,
2136 		NULL,
2137 	},
2138 };
2139 
2140 /* *** SHOW PORT RETA INFO *** */
2141 struct cmd_showport_reta {
2142 	cmdline_fixed_string_t show;
2143 	cmdline_fixed_string_t port;
2144 	uint8_t port_id;
2145 	cmdline_fixed_string_t rss;
2146 	cmdline_fixed_string_t reta;
2147 	uint16_t size;
2148 	cmdline_fixed_string_t list_of_items;
2149 };
2150 
2151 static int
2152 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2153 			   uint16_t nb_entries,
2154 			   char *str)
2155 {
2156 	uint32_t size;
2157 	const char *p, *p0 = str;
2158 	char s[256];
2159 	char *end;
2160 	char *str_fld[8];
2161 	uint16_t i;
2162 	uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2163 			RTE_RETA_GROUP_SIZE;
2164 	int ret;
2165 
2166 	p = strchr(p0, '(');
2167 	if (p == NULL)
2168 		return -1;
2169 	p++;
2170 	p0 = strchr(p, ')');
2171 	if (p0 == NULL)
2172 		return -1;
2173 	size = p0 - p;
2174 	if (size >= sizeof(s)) {
2175 		printf("The string size exceeds the internal buffer size\n");
2176 		return -1;
2177 	}
2178 	snprintf(s, sizeof(s), "%.*s", size, p);
2179 	ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2180 	if (ret <= 0 || ret != num) {
2181 		printf("The bits of masks do not match the number of "
2182 					"reta entries: %u\n", num);
2183 		return -1;
2184 	}
2185 	for (i = 0; i < ret; i++)
2186 		conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2187 
2188 	return 0;
2189 }
2190 
2191 static void
2192 cmd_showport_reta_parsed(void *parsed_result,
2193 			 __attribute__((unused)) struct cmdline *cl,
2194 			 __attribute__((unused)) void *data)
2195 {
2196 	struct cmd_showport_reta *res = parsed_result;
2197 	struct rte_eth_rss_reta_entry64 reta_conf[8];
2198 	struct rte_eth_dev_info dev_info;
2199 
2200 	memset(&dev_info, 0, sizeof(dev_info));
2201 	rte_eth_dev_info_get(res->port_id, &dev_info);
2202 	if (dev_info.reta_size == 0 || res->size > dev_info.reta_size ||
2203 				res->size > ETH_RSS_RETA_SIZE_512) {
2204 		printf("Invalid redirection table size: %u\n", res->size);
2205 		return;
2206 	}
2207 
2208 	memset(reta_conf, 0, sizeof(reta_conf));
2209 	if (showport_parse_reta_config(reta_conf, res->size,
2210 				res->list_of_items) < 0) {
2211 		printf("Invalid string: %s for reta masks\n",
2212 					res->list_of_items);
2213 		return;
2214 	}
2215 	port_rss_reta_info(res->port_id, reta_conf, res->size);
2216 }
2217 
2218 cmdline_parse_token_string_t cmd_showport_reta_show =
2219 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2220 cmdline_parse_token_string_t cmd_showport_reta_port =
2221 	TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2222 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2223 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
2224 cmdline_parse_token_string_t cmd_showport_reta_rss =
2225 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2226 cmdline_parse_token_string_t cmd_showport_reta_reta =
2227 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2228 cmdline_parse_token_num_t cmd_showport_reta_size =
2229 	TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2230 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2231 	TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2232 					list_of_items, NULL);
2233 
2234 cmdline_parse_inst_t cmd_showport_reta = {
2235 	.f = cmd_showport_reta_parsed,
2236 	.data = NULL,
2237 	.help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2238 	.tokens = {
2239 		(void *)&cmd_showport_reta_show,
2240 		(void *)&cmd_showport_reta_port,
2241 		(void *)&cmd_showport_reta_port_id,
2242 		(void *)&cmd_showport_reta_rss,
2243 		(void *)&cmd_showport_reta_reta,
2244 		(void *)&cmd_showport_reta_size,
2245 		(void *)&cmd_showport_reta_list_of_items,
2246 		NULL,
2247 	},
2248 };
2249 
2250 /* *** Show RSS hash configuration *** */
2251 struct cmd_showport_rss_hash {
2252 	cmdline_fixed_string_t show;
2253 	cmdline_fixed_string_t port;
2254 	uint8_t port_id;
2255 	cmdline_fixed_string_t rss_hash;
2256 	cmdline_fixed_string_t rss_type;
2257 	cmdline_fixed_string_t key; /* optional argument */
2258 };
2259 
2260 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2261 				__attribute__((unused)) struct cmdline *cl,
2262 				void *show_rss_key)
2263 {
2264 	struct cmd_showport_rss_hash *res = parsed_result;
2265 
2266 	port_rss_hash_conf_show(res->port_id, res->rss_type,
2267 				show_rss_key != NULL);
2268 }
2269 
2270 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2271 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2272 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2273 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2274 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2275 	TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2276 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2277 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2278 				 "rss-hash");
2279 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2280 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2281 				 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2282 				 "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2283 				 "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2284 				 "ipv6-tcp-ex#ipv6-udp-ex");
2285 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2286 	TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2287 
2288 cmdline_parse_inst_t cmd_showport_rss_hash = {
2289 	.f = cmd_showport_rss_hash_parsed,
2290 	.data = NULL,
2291 	.help_str = "show port <port_id> rss-hash "
2292 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2293 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2294 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2295 	.tokens = {
2296 		(void *)&cmd_showport_rss_hash_show,
2297 		(void *)&cmd_showport_rss_hash_port,
2298 		(void *)&cmd_showport_rss_hash_port_id,
2299 		(void *)&cmd_showport_rss_hash_rss_hash,
2300 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2301 		NULL,
2302 	},
2303 };
2304 
2305 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2306 	.f = cmd_showport_rss_hash_parsed,
2307 	.data = (void *)1,
2308 	.help_str = "show port <port_id> rss-hash "
2309 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2310 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2311 		"l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2312 	.tokens = {
2313 		(void *)&cmd_showport_rss_hash_show,
2314 		(void *)&cmd_showport_rss_hash_port,
2315 		(void *)&cmd_showport_rss_hash_port_id,
2316 		(void *)&cmd_showport_rss_hash_rss_hash,
2317 		(void *)&cmd_showport_rss_hash_rss_hash_info,
2318 		(void *)&cmd_showport_rss_hash_rss_key,
2319 		NULL,
2320 	},
2321 };
2322 
2323 /* *** Configure DCB *** */
2324 struct cmd_config_dcb {
2325 	cmdline_fixed_string_t port;
2326 	cmdline_fixed_string_t config;
2327 	uint8_t port_id;
2328 	cmdline_fixed_string_t dcb;
2329 	cmdline_fixed_string_t vt;
2330 	cmdline_fixed_string_t vt_en;
2331 	uint8_t num_tcs;
2332 	cmdline_fixed_string_t pfc;
2333 	cmdline_fixed_string_t pfc_en;
2334 };
2335 
2336 static void
2337 cmd_config_dcb_parsed(void *parsed_result,
2338                         __attribute__((unused)) struct cmdline *cl,
2339                         __attribute__((unused)) void *data)
2340 {
2341 	struct cmd_config_dcb *res = parsed_result;
2342 	portid_t port_id = res->port_id;
2343 	struct rte_port *port;
2344 	uint8_t pfc_en;
2345 	int ret;
2346 
2347 	port = &ports[port_id];
2348 	/** Check if the port is not started **/
2349 	if (port->port_status != RTE_PORT_STOPPED) {
2350 		printf("Please stop port %d first\n", port_id);
2351 		return;
2352 	}
2353 
2354 	if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2355 		printf("The invalid number of traffic class,"
2356 			" only 4 or 8 allowed.\n");
2357 		return;
2358 	}
2359 
2360 	if (nb_fwd_lcores < res->num_tcs) {
2361 		printf("nb_cores shouldn't be less than number of TCs.\n");
2362 		return;
2363 	}
2364 	if (!strncmp(res->pfc_en, "on", 2))
2365 		pfc_en = 1;
2366 	else
2367 		pfc_en = 0;
2368 
2369 	/* DCB in VT mode */
2370 	if (!strncmp(res->vt_en, "on", 2))
2371 		ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2372 				(enum rte_eth_nb_tcs)res->num_tcs,
2373 				pfc_en);
2374 	else
2375 		ret = init_port_dcb_config(port_id, DCB_ENABLED,
2376 				(enum rte_eth_nb_tcs)res->num_tcs,
2377 				pfc_en);
2378 
2379 
2380 	if (ret != 0) {
2381 		printf("Cannot initialize network ports.\n");
2382 		return;
2383 	}
2384 
2385 	cmd_reconfig_device_queue(port_id, 1, 1);
2386 }
2387 
2388 cmdline_parse_token_string_t cmd_config_dcb_port =
2389         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2390 cmdline_parse_token_string_t cmd_config_dcb_config =
2391         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2392 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2393         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2394 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2395         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2396 cmdline_parse_token_string_t cmd_config_dcb_vt =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2398 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2399         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2400 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2401         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2402 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2403         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2404 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2405         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2406 
2407 cmdline_parse_inst_t cmd_config_dcb = {
2408 	.f = cmd_config_dcb_parsed,
2409 	.data = NULL,
2410 	.help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2411 	.tokens = {
2412 		(void *)&cmd_config_dcb_port,
2413 		(void *)&cmd_config_dcb_config,
2414 		(void *)&cmd_config_dcb_port_id,
2415 		(void *)&cmd_config_dcb_dcb,
2416 		(void *)&cmd_config_dcb_vt,
2417 		(void *)&cmd_config_dcb_vt_en,
2418 		(void *)&cmd_config_dcb_num_tcs,
2419 		(void *)&cmd_config_dcb_pfc,
2420 		(void *)&cmd_config_dcb_pfc_en,
2421                 NULL,
2422         },
2423 };
2424 
2425 /* *** configure number of packets per burst *** */
2426 struct cmd_config_burst {
2427 	cmdline_fixed_string_t port;
2428 	cmdline_fixed_string_t keyword;
2429 	cmdline_fixed_string_t all;
2430 	cmdline_fixed_string_t name;
2431 	uint16_t value;
2432 };
2433 
2434 static void
2435 cmd_config_burst_parsed(void *parsed_result,
2436 			__attribute__((unused)) struct cmdline *cl,
2437 			__attribute__((unused)) void *data)
2438 {
2439 	struct cmd_config_burst *res = parsed_result;
2440 
2441 	if (!all_ports_stopped()) {
2442 		printf("Please stop all ports first\n");
2443 		return;
2444 	}
2445 
2446 	if (!strcmp(res->name, "burst")) {
2447 		if (res->value < 1 || res->value > MAX_PKT_BURST) {
2448 			printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2449 			return;
2450 		}
2451 		nb_pkt_per_burst = res->value;
2452 	} else {
2453 		printf("Unknown parameter\n");
2454 		return;
2455 	}
2456 
2457 	init_port_config();
2458 
2459 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2460 }
2461 
2462 cmdline_parse_token_string_t cmd_config_burst_port =
2463 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2464 cmdline_parse_token_string_t cmd_config_burst_keyword =
2465 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2466 cmdline_parse_token_string_t cmd_config_burst_all =
2467 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2468 cmdline_parse_token_string_t cmd_config_burst_name =
2469 	TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2470 cmdline_parse_token_num_t cmd_config_burst_value =
2471 	TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2472 
2473 cmdline_parse_inst_t cmd_config_burst = {
2474 	.f = cmd_config_burst_parsed,
2475 	.data = NULL,
2476 	.help_str = "port config all burst <value>",
2477 	.tokens = {
2478 		(void *)&cmd_config_burst_port,
2479 		(void *)&cmd_config_burst_keyword,
2480 		(void *)&cmd_config_burst_all,
2481 		(void *)&cmd_config_burst_name,
2482 		(void *)&cmd_config_burst_value,
2483 		NULL,
2484 	},
2485 };
2486 
2487 /* *** configure rx/tx queues *** */
2488 struct cmd_config_thresh {
2489 	cmdline_fixed_string_t port;
2490 	cmdline_fixed_string_t keyword;
2491 	cmdline_fixed_string_t all;
2492 	cmdline_fixed_string_t name;
2493 	uint8_t value;
2494 };
2495 
2496 static void
2497 cmd_config_thresh_parsed(void *parsed_result,
2498 			__attribute__((unused)) struct cmdline *cl,
2499 			__attribute__((unused)) void *data)
2500 {
2501 	struct cmd_config_thresh *res = parsed_result;
2502 
2503 	if (!all_ports_stopped()) {
2504 		printf("Please stop all ports first\n");
2505 		return;
2506 	}
2507 
2508 	if (!strcmp(res->name, "txpt"))
2509 		tx_pthresh = res->value;
2510 	else if(!strcmp(res->name, "txht"))
2511 		tx_hthresh = res->value;
2512 	else if(!strcmp(res->name, "txwt"))
2513 		tx_wthresh = res->value;
2514 	else if(!strcmp(res->name, "rxpt"))
2515 		rx_pthresh = res->value;
2516 	else if(!strcmp(res->name, "rxht"))
2517 		rx_hthresh = res->value;
2518 	else if(!strcmp(res->name, "rxwt"))
2519 		rx_wthresh = res->value;
2520 	else {
2521 		printf("Unknown parameter\n");
2522 		return;
2523 	}
2524 
2525 	init_port_config();
2526 
2527 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2528 }
2529 
2530 cmdline_parse_token_string_t cmd_config_thresh_port =
2531 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2532 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2533 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2534 cmdline_parse_token_string_t cmd_config_thresh_all =
2535 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2536 cmdline_parse_token_string_t cmd_config_thresh_name =
2537 	TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2538 				"txpt#txht#txwt#rxpt#rxht#rxwt");
2539 cmdline_parse_token_num_t cmd_config_thresh_value =
2540 	TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2541 
2542 cmdline_parse_inst_t cmd_config_thresh = {
2543 	.f = cmd_config_thresh_parsed,
2544 	.data = NULL,
2545 	.help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2546 	.tokens = {
2547 		(void *)&cmd_config_thresh_port,
2548 		(void *)&cmd_config_thresh_keyword,
2549 		(void *)&cmd_config_thresh_all,
2550 		(void *)&cmd_config_thresh_name,
2551 		(void *)&cmd_config_thresh_value,
2552 		NULL,
2553 	},
2554 };
2555 
2556 /* *** configure free/rs threshold *** */
2557 struct cmd_config_threshold {
2558 	cmdline_fixed_string_t port;
2559 	cmdline_fixed_string_t keyword;
2560 	cmdline_fixed_string_t all;
2561 	cmdline_fixed_string_t name;
2562 	uint16_t value;
2563 };
2564 
2565 static void
2566 cmd_config_threshold_parsed(void *parsed_result,
2567 			__attribute__((unused)) struct cmdline *cl,
2568 			__attribute__((unused)) void *data)
2569 {
2570 	struct cmd_config_threshold *res = parsed_result;
2571 
2572 	if (!all_ports_stopped()) {
2573 		printf("Please stop all ports first\n");
2574 		return;
2575 	}
2576 
2577 	if (!strcmp(res->name, "txfreet"))
2578 		tx_free_thresh = res->value;
2579 	else if (!strcmp(res->name, "txrst"))
2580 		tx_rs_thresh = res->value;
2581 	else if (!strcmp(res->name, "rxfreet"))
2582 		rx_free_thresh = res->value;
2583 	else {
2584 		printf("Unknown parameter\n");
2585 		return;
2586 	}
2587 
2588 	init_port_config();
2589 
2590 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2591 }
2592 
2593 cmdline_parse_token_string_t cmd_config_threshold_port =
2594 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2595 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2596 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2597 								"config");
2598 cmdline_parse_token_string_t cmd_config_threshold_all =
2599 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2600 cmdline_parse_token_string_t cmd_config_threshold_name =
2601 	TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2602 						"txfreet#txrst#rxfreet");
2603 cmdline_parse_token_num_t cmd_config_threshold_value =
2604 	TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2605 
2606 cmdline_parse_inst_t cmd_config_threshold = {
2607 	.f = cmd_config_threshold_parsed,
2608 	.data = NULL,
2609 	.help_str = "port config all txfreet|txrst|rxfreet <value>",
2610 	.tokens = {
2611 		(void *)&cmd_config_threshold_port,
2612 		(void *)&cmd_config_threshold_keyword,
2613 		(void *)&cmd_config_threshold_all,
2614 		(void *)&cmd_config_threshold_name,
2615 		(void *)&cmd_config_threshold_value,
2616 		NULL,
2617 	},
2618 };
2619 
2620 /* *** stop *** */
2621 struct cmd_stop_result {
2622 	cmdline_fixed_string_t stop;
2623 };
2624 
2625 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2626 			    __attribute__((unused)) struct cmdline *cl,
2627 			    __attribute__((unused)) void *data)
2628 {
2629 	stop_packet_forwarding();
2630 }
2631 
2632 cmdline_parse_token_string_t cmd_stop_stop =
2633 	TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2634 
2635 cmdline_parse_inst_t cmd_stop = {
2636 	.f = cmd_stop_parsed,
2637 	.data = NULL,
2638 	.help_str = "stop: Stop packet forwarding",
2639 	.tokens = {
2640 		(void *)&cmd_stop_stop,
2641 		NULL,
2642 	},
2643 };
2644 
2645 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2646 
2647 unsigned int
2648 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2649 		unsigned int *parsed_items, int check_unique_values)
2650 {
2651 	unsigned int nb_item;
2652 	unsigned int value;
2653 	unsigned int i;
2654 	unsigned int j;
2655 	int value_ok;
2656 	char c;
2657 
2658 	/*
2659 	 * First parse all items in the list and store their value.
2660 	 */
2661 	value = 0;
2662 	nb_item = 0;
2663 	value_ok = 0;
2664 	for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2665 		c = str[i];
2666 		if ((c >= '0') && (c <= '9')) {
2667 			value = (unsigned int) (value * 10 + (c - '0'));
2668 			value_ok = 1;
2669 			continue;
2670 		}
2671 		if (c != ',') {
2672 			printf("character %c is not a decimal digit\n", c);
2673 			return 0;
2674 		}
2675 		if (! value_ok) {
2676 			printf("No valid value before comma\n");
2677 			return 0;
2678 		}
2679 		if (nb_item < max_items) {
2680 			parsed_items[nb_item] = value;
2681 			value_ok = 0;
2682 			value = 0;
2683 		}
2684 		nb_item++;
2685 	}
2686 	if (nb_item >= max_items) {
2687 		printf("Number of %s = %u > %u (maximum items)\n",
2688 		       item_name, nb_item + 1, max_items);
2689 		return 0;
2690 	}
2691 	parsed_items[nb_item++] = value;
2692 	if (! check_unique_values)
2693 		return nb_item;
2694 
2695 	/*
2696 	 * Then, check that all values in the list are differents.
2697 	 * No optimization here...
2698 	 */
2699 	for (i = 0; i < nb_item; i++) {
2700 		for (j = i + 1; j < nb_item; j++) {
2701 			if (parsed_items[j] == parsed_items[i]) {
2702 				printf("duplicated %s %u at index %u and %u\n",
2703 				       item_name, parsed_items[i], i, j);
2704 				return 0;
2705 			}
2706 		}
2707 	}
2708 	return nb_item;
2709 }
2710 
2711 struct cmd_set_list_result {
2712 	cmdline_fixed_string_t cmd_keyword;
2713 	cmdline_fixed_string_t list_name;
2714 	cmdline_fixed_string_t list_of_items;
2715 };
2716 
2717 static void cmd_set_list_parsed(void *parsed_result,
2718 				__attribute__((unused)) struct cmdline *cl,
2719 				__attribute__((unused)) void *data)
2720 {
2721 	struct cmd_set_list_result *res;
2722 	union {
2723 		unsigned int lcorelist[RTE_MAX_LCORE];
2724 		unsigned int portlist[RTE_MAX_ETHPORTS];
2725 	} parsed_items;
2726 	unsigned int nb_item;
2727 
2728 	if (test_done == 0) {
2729 		printf("Please stop forwarding first\n");
2730 		return;
2731 	}
2732 
2733 	res = parsed_result;
2734 	if (!strcmp(res->list_name, "corelist")) {
2735 		nb_item = parse_item_list(res->list_of_items, "core",
2736 					  RTE_MAX_LCORE,
2737 					  parsed_items.lcorelist, 1);
2738 		if (nb_item > 0) {
2739 			set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2740 			fwd_config_setup();
2741 		}
2742 		return;
2743 	}
2744 	if (!strcmp(res->list_name, "portlist")) {
2745 		nb_item = parse_item_list(res->list_of_items, "port",
2746 					  RTE_MAX_ETHPORTS,
2747 					  parsed_items.portlist, 1);
2748 		if (nb_item > 0) {
2749 			set_fwd_ports_list(parsed_items.portlist, nb_item);
2750 			fwd_config_setup();
2751 		}
2752 	}
2753 }
2754 
2755 cmdline_parse_token_string_t cmd_set_list_keyword =
2756 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2757 				 "set");
2758 cmdline_parse_token_string_t cmd_set_list_name =
2759 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2760 				 "corelist#portlist");
2761 cmdline_parse_token_string_t cmd_set_list_of_items =
2762 	TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2763 				 NULL);
2764 
2765 cmdline_parse_inst_t cmd_set_fwd_list = {
2766 	.f = cmd_set_list_parsed,
2767 	.data = NULL,
2768 	.help_str = "set corelist|portlist <list0[,list1]*>",
2769 	.tokens = {
2770 		(void *)&cmd_set_list_keyword,
2771 		(void *)&cmd_set_list_name,
2772 		(void *)&cmd_set_list_of_items,
2773 		NULL,
2774 	},
2775 };
2776 
2777 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2778 
2779 struct cmd_setmask_result {
2780 	cmdline_fixed_string_t set;
2781 	cmdline_fixed_string_t mask;
2782 	uint64_t hexavalue;
2783 };
2784 
2785 static void cmd_set_mask_parsed(void *parsed_result,
2786 				__attribute__((unused)) struct cmdline *cl,
2787 				__attribute__((unused)) void *data)
2788 {
2789 	struct cmd_setmask_result *res = parsed_result;
2790 
2791 	if (test_done == 0) {
2792 		printf("Please stop forwarding first\n");
2793 		return;
2794 	}
2795 	if (!strcmp(res->mask, "coremask")) {
2796 		set_fwd_lcores_mask(res->hexavalue);
2797 		fwd_config_setup();
2798 	} else if (!strcmp(res->mask, "portmask")) {
2799 		set_fwd_ports_mask(res->hexavalue);
2800 		fwd_config_setup();
2801 	}
2802 }
2803 
2804 cmdline_parse_token_string_t cmd_setmask_set =
2805 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2806 cmdline_parse_token_string_t cmd_setmask_mask =
2807 	TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2808 				 "coremask#portmask");
2809 cmdline_parse_token_num_t cmd_setmask_value =
2810 	TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2811 
2812 cmdline_parse_inst_t cmd_set_fwd_mask = {
2813 	.f = cmd_set_mask_parsed,
2814 	.data = NULL,
2815 	.help_str = "set coremask|portmask <hexadecimal value>",
2816 	.tokens = {
2817 		(void *)&cmd_setmask_set,
2818 		(void *)&cmd_setmask_mask,
2819 		(void *)&cmd_setmask_value,
2820 		NULL,
2821 	},
2822 };
2823 
2824 /*
2825  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2826  */
2827 struct cmd_set_result {
2828 	cmdline_fixed_string_t set;
2829 	cmdline_fixed_string_t what;
2830 	uint16_t value;
2831 };
2832 
2833 static void cmd_set_parsed(void *parsed_result,
2834 			   __attribute__((unused)) struct cmdline *cl,
2835 			   __attribute__((unused)) void *data)
2836 {
2837 	struct cmd_set_result *res = parsed_result;
2838 	if (!strcmp(res->what, "nbport")) {
2839 		set_fwd_ports_number(res->value);
2840 		fwd_config_setup();
2841 	} else if (!strcmp(res->what, "nbcore")) {
2842 		set_fwd_lcores_number(res->value);
2843 		fwd_config_setup();
2844 	} else if (!strcmp(res->what, "burst"))
2845 		set_nb_pkt_per_burst(res->value);
2846 	else if (!strcmp(res->what, "verbose"))
2847 		set_verbose_level(res->value);
2848 }
2849 
2850 cmdline_parse_token_string_t cmd_set_set =
2851 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2852 cmdline_parse_token_string_t cmd_set_what =
2853 	TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2854 				 "nbport#nbcore#burst#verbose");
2855 cmdline_parse_token_num_t cmd_set_value =
2856 	TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2857 
2858 cmdline_parse_inst_t cmd_set_numbers = {
2859 	.f = cmd_set_parsed,
2860 	.data = NULL,
2861 	.help_str = "set nbport|nbcore|burst|verbose <value>",
2862 	.tokens = {
2863 		(void *)&cmd_set_set,
2864 		(void *)&cmd_set_what,
2865 		(void *)&cmd_set_value,
2866 		NULL,
2867 	},
2868 };
2869 
2870 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2871 
2872 struct cmd_set_txpkts_result {
2873 	cmdline_fixed_string_t cmd_keyword;
2874 	cmdline_fixed_string_t txpkts;
2875 	cmdline_fixed_string_t seg_lengths;
2876 };
2877 
2878 static void
2879 cmd_set_txpkts_parsed(void *parsed_result,
2880 		      __attribute__((unused)) struct cmdline *cl,
2881 		      __attribute__((unused)) void *data)
2882 {
2883 	struct cmd_set_txpkts_result *res;
2884 	unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2885 	unsigned int nb_segs;
2886 
2887 	res = parsed_result;
2888 	nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2889 				  RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2890 	if (nb_segs > 0)
2891 		set_tx_pkt_segments(seg_lengths, nb_segs);
2892 }
2893 
2894 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2895 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2896 				 cmd_keyword, "set");
2897 cmdline_parse_token_string_t cmd_set_txpkts_name =
2898 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2899 				 txpkts, "txpkts");
2900 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2901 	TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2902 				 seg_lengths, NULL);
2903 
2904 cmdline_parse_inst_t cmd_set_txpkts = {
2905 	.f = cmd_set_txpkts_parsed,
2906 	.data = NULL,
2907 	.help_str = "set txpkts <len0[,len1]*>",
2908 	.tokens = {
2909 		(void *)&cmd_set_txpkts_keyword,
2910 		(void *)&cmd_set_txpkts_name,
2911 		(void *)&cmd_set_txpkts_lengths,
2912 		NULL,
2913 	},
2914 };
2915 
2916 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2917 
2918 struct cmd_set_txsplit_result {
2919 	cmdline_fixed_string_t cmd_keyword;
2920 	cmdline_fixed_string_t txsplit;
2921 	cmdline_fixed_string_t mode;
2922 };
2923 
2924 static void
2925 cmd_set_txsplit_parsed(void *parsed_result,
2926 		      __attribute__((unused)) struct cmdline *cl,
2927 		      __attribute__((unused)) void *data)
2928 {
2929 	struct cmd_set_txsplit_result *res;
2930 
2931 	res = parsed_result;
2932 	set_tx_pkt_split(res->mode);
2933 }
2934 
2935 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2936 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2937 				 cmd_keyword, "set");
2938 cmdline_parse_token_string_t cmd_set_txsplit_name =
2939 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2940 				 txsplit, "txsplit");
2941 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2942 	TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2943 				 mode, NULL);
2944 
2945 cmdline_parse_inst_t cmd_set_txsplit = {
2946 	.f = cmd_set_txsplit_parsed,
2947 	.data = NULL,
2948 	.help_str = "set txsplit on|off|rand",
2949 	.tokens = {
2950 		(void *)&cmd_set_txsplit_keyword,
2951 		(void *)&cmd_set_txsplit_name,
2952 		(void *)&cmd_set_txsplit_mode,
2953 		NULL,
2954 	},
2955 };
2956 
2957 /* *** CONFIG TX QUEUE FLAGS *** */
2958 
2959 struct cmd_config_txqflags_result {
2960 	cmdline_fixed_string_t port;
2961 	cmdline_fixed_string_t config;
2962 	cmdline_fixed_string_t all;
2963 	cmdline_fixed_string_t what;
2964 	int32_t hexvalue;
2965 };
2966 
2967 static void cmd_config_txqflags_parsed(void *parsed_result,
2968 				__attribute__((unused)) struct cmdline *cl,
2969 				__attribute__((unused)) void *data)
2970 {
2971 	struct cmd_config_txqflags_result *res = parsed_result;
2972 
2973 	if (!all_ports_stopped()) {
2974 		printf("Please stop all ports first\n");
2975 		return;
2976 	}
2977 
2978 	if (strcmp(res->what, "txqflags")) {
2979 		printf("Unknown parameter\n");
2980 		return;
2981 	}
2982 
2983 	if (res->hexvalue >= 0) {
2984 		txq_flags = res->hexvalue;
2985 	} else {
2986 		printf("txqflags must be >= 0\n");
2987 		return;
2988 	}
2989 
2990 	init_port_config();
2991 
2992 	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2993 }
2994 
2995 cmdline_parse_token_string_t cmd_config_txqflags_port =
2996 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
2997 				 "port");
2998 cmdline_parse_token_string_t cmd_config_txqflags_config =
2999 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3000 				 "config");
3001 cmdline_parse_token_string_t cmd_config_txqflags_all =
3002 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3003 				 "all");
3004 cmdline_parse_token_string_t cmd_config_txqflags_what =
3005 	TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3006 				 "txqflags");
3007 cmdline_parse_token_num_t cmd_config_txqflags_value =
3008 	TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3009 				hexvalue, INT32);
3010 
3011 cmdline_parse_inst_t cmd_config_txqflags = {
3012 	.f = cmd_config_txqflags_parsed,
3013 	.data = NULL,
3014 	.help_str = "port config all txqflags <value>",
3015 	.tokens = {
3016 		(void *)&cmd_config_txqflags_port,
3017 		(void *)&cmd_config_txqflags_config,
3018 		(void *)&cmd_config_txqflags_all,
3019 		(void *)&cmd_config_txqflags_what,
3020 		(void *)&cmd_config_txqflags_value,
3021 		NULL,
3022 	},
3023 };
3024 
3025 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3026 struct cmd_rx_vlan_filter_all_result {
3027 	cmdline_fixed_string_t rx_vlan;
3028 	cmdline_fixed_string_t what;
3029 	cmdline_fixed_string_t all;
3030 	uint8_t port_id;
3031 };
3032 
3033 static void
3034 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3035 			      __attribute__((unused)) struct cmdline *cl,
3036 			      __attribute__((unused)) void *data)
3037 {
3038 	struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3039 
3040 	if (!strcmp(res->what, "add"))
3041 		rx_vlan_all_filter_set(res->port_id, 1);
3042 	else
3043 		rx_vlan_all_filter_set(res->port_id, 0);
3044 }
3045 
3046 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3047 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3048 				 rx_vlan, "rx_vlan");
3049 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3050 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3051 				 what, "add#rm");
3052 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3053 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3054 				 all, "all");
3055 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3056 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3057 			      port_id, UINT8);
3058 
3059 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3060 	.f = cmd_rx_vlan_filter_all_parsed,
3061 	.data = NULL,
3062 	.help_str = "rx_vlan add|rm all <port_id>: "
3063 		"Add/Remove all identifiers to/from the set of VLAN "
3064 		"identifiers filtered by a port",
3065 	.tokens = {
3066 		(void *)&cmd_rx_vlan_filter_all_rx_vlan,
3067 		(void *)&cmd_rx_vlan_filter_all_what,
3068 		(void *)&cmd_rx_vlan_filter_all_all,
3069 		(void *)&cmd_rx_vlan_filter_all_portid,
3070 		NULL,
3071 	},
3072 };
3073 
3074 /* *** VLAN OFFLOAD SET ON A PORT *** */
3075 struct cmd_vlan_offload_result {
3076 	cmdline_fixed_string_t vlan;
3077 	cmdline_fixed_string_t set;
3078 	cmdline_fixed_string_t vlan_type;
3079 	cmdline_fixed_string_t what;
3080 	cmdline_fixed_string_t on;
3081 	cmdline_fixed_string_t port_id;
3082 };
3083 
3084 static void
3085 cmd_vlan_offload_parsed(void *parsed_result,
3086 			  __attribute__((unused)) struct cmdline *cl,
3087 			  __attribute__((unused)) void *data)
3088 {
3089 	int on;
3090 	struct cmd_vlan_offload_result *res = parsed_result;
3091 	char *str;
3092 	int i, len = 0;
3093 	portid_t port_id = 0;
3094 	unsigned int tmp;
3095 
3096 	str = res->port_id;
3097 	len = strnlen(str, STR_TOKEN_SIZE);
3098 	i = 0;
3099 	/* Get port_id first */
3100 	while(i < len){
3101 		if(str[i] == ',')
3102 			break;
3103 
3104 		i++;
3105 	}
3106 	str[i]='\0';
3107 	tmp = strtoul(str, NULL, 0);
3108 	/* If port_id greater that what portid_t can represent, return */
3109 	if(tmp >= RTE_MAX_ETHPORTS)
3110 		return;
3111 	port_id = (portid_t)tmp;
3112 
3113 	if (!strcmp(res->on, "on"))
3114 		on = 1;
3115 	else
3116 		on = 0;
3117 
3118 	if (!strcmp(res->what, "strip"))
3119 		rx_vlan_strip_set(port_id,  on);
3120 	else if(!strcmp(res->what, "stripq")){
3121 		uint16_t queue_id = 0;
3122 
3123 		/* No queue_id, return */
3124 		if(i + 1 >= len) {
3125 			printf("must specify (port,queue_id)\n");
3126 			return;
3127 		}
3128 		tmp = strtoul(str + i + 1, NULL, 0);
3129 		/* If queue_id greater that what 16-bits can represent, return */
3130 		if(tmp > 0xffff)
3131 			return;
3132 
3133 		queue_id = (uint16_t)tmp;
3134 		rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3135 	}
3136 	else if (!strcmp(res->what, "filter"))
3137 		rx_vlan_filter_set(port_id, on);
3138 	else
3139 		vlan_extend_set(port_id, on);
3140 
3141 	return;
3142 }
3143 
3144 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3145 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3146 				 vlan, "vlan");
3147 cmdline_parse_token_string_t cmd_vlan_offload_set =
3148 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3149 				 set, "set");
3150 cmdline_parse_token_string_t cmd_vlan_offload_what =
3151 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3152 				 what, "strip#filter#qinq#stripq");
3153 cmdline_parse_token_string_t cmd_vlan_offload_on =
3154 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3155 			      on, "on#off");
3156 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3157 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3158 			      port_id, NULL);
3159 
3160 cmdline_parse_inst_t cmd_vlan_offload = {
3161 	.f = cmd_vlan_offload_parsed,
3162 	.data = NULL,
3163 	.help_str = "vlan set strip|filter|qinq|stripq on|off "
3164 		"<port_id[,queue_id]>: "
3165 		"Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3166 	.tokens = {
3167 		(void *)&cmd_vlan_offload_vlan,
3168 		(void *)&cmd_vlan_offload_set,
3169 		(void *)&cmd_vlan_offload_what,
3170 		(void *)&cmd_vlan_offload_on,
3171 		(void *)&cmd_vlan_offload_portid,
3172 		NULL,
3173 	},
3174 };
3175 
3176 /* *** VLAN TPID SET ON A PORT *** */
3177 struct cmd_vlan_tpid_result {
3178 	cmdline_fixed_string_t vlan;
3179 	cmdline_fixed_string_t set;
3180 	cmdline_fixed_string_t vlan_type;
3181 	cmdline_fixed_string_t what;
3182 	uint16_t tp_id;
3183 	uint8_t port_id;
3184 };
3185 
3186 static void
3187 cmd_vlan_tpid_parsed(void *parsed_result,
3188 			  __attribute__((unused)) struct cmdline *cl,
3189 			  __attribute__((unused)) void *data)
3190 {
3191 	struct cmd_vlan_tpid_result *res = parsed_result;
3192 	enum rte_vlan_type vlan_type;
3193 
3194 	if (!strcmp(res->vlan_type, "inner"))
3195 		vlan_type = ETH_VLAN_TYPE_INNER;
3196 	else if (!strcmp(res->vlan_type, "outer"))
3197 		vlan_type = ETH_VLAN_TYPE_OUTER;
3198 	else {
3199 		printf("Unknown vlan type\n");
3200 		return;
3201 	}
3202 	vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3203 }
3204 
3205 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3206 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3207 				 vlan, "vlan");
3208 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3209 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3210 				 set, "set");
3211 cmdline_parse_token_string_t cmd_vlan_type =
3212 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3213 				 vlan_type, "inner#outer");
3214 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3215 	TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3216 				 what, "tpid");
3217 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3218 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3219 			      tp_id, UINT16);
3220 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3221 	TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3222 			      port_id, UINT8);
3223 
3224 cmdline_parse_inst_t cmd_vlan_tpid = {
3225 	.f = cmd_vlan_tpid_parsed,
3226 	.data = NULL,
3227 	.help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3228 		"Set the VLAN Ether type",
3229 	.tokens = {
3230 		(void *)&cmd_vlan_tpid_vlan,
3231 		(void *)&cmd_vlan_tpid_set,
3232 		(void *)&cmd_vlan_type,
3233 		(void *)&cmd_vlan_tpid_what,
3234 		(void *)&cmd_vlan_tpid_tpid,
3235 		(void *)&cmd_vlan_tpid_portid,
3236 		NULL,
3237 	},
3238 };
3239 
3240 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3241 struct cmd_rx_vlan_filter_result {
3242 	cmdline_fixed_string_t rx_vlan;
3243 	cmdline_fixed_string_t what;
3244 	uint16_t vlan_id;
3245 	uint8_t port_id;
3246 };
3247 
3248 static void
3249 cmd_rx_vlan_filter_parsed(void *parsed_result,
3250 			  __attribute__((unused)) struct cmdline *cl,
3251 			  __attribute__((unused)) void *data)
3252 {
3253 	struct cmd_rx_vlan_filter_result *res = parsed_result;
3254 
3255 	if (!strcmp(res->what, "add"))
3256 		rx_vft_set(res->port_id, res->vlan_id, 1);
3257 	else
3258 		rx_vft_set(res->port_id, res->vlan_id, 0);
3259 }
3260 
3261 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3262 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3263 				 rx_vlan, "rx_vlan");
3264 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3265 	TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3266 				 what, "add#rm");
3267 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3268 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3269 			      vlan_id, UINT16);
3270 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3271 	TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3272 			      port_id, UINT8);
3273 
3274 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3275 	.f = cmd_rx_vlan_filter_parsed,
3276 	.data = NULL,
3277 	.help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3278 		"Add/Remove a VLAN identifier to/from the set of VLAN "
3279 		"identifiers filtered by a port",
3280 	.tokens = {
3281 		(void *)&cmd_rx_vlan_filter_rx_vlan,
3282 		(void *)&cmd_rx_vlan_filter_what,
3283 		(void *)&cmd_rx_vlan_filter_vlanid,
3284 		(void *)&cmd_rx_vlan_filter_portid,
3285 		NULL,
3286 	},
3287 };
3288 
3289 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3290 struct cmd_tx_vlan_set_result {
3291 	cmdline_fixed_string_t tx_vlan;
3292 	cmdline_fixed_string_t set;
3293 	uint8_t port_id;
3294 	uint16_t vlan_id;
3295 };
3296 
3297 static void
3298 cmd_tx_vlan_set_parsed(void *parsed_result,
3299 		       __attribute__((unused)) struct cmdline *cl,
3300 		       __attribute__((unused)) void *data)
3301 {
3302 	struct cmd_tx_vlan_set_result *res = parsed_result;
3303 
3304 	tx_vlan_set(res->port_id, res->vlan_id);
3305 }
3306 
3307 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3308 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3309 				 tx_vlan, "tx_vlan");
3310 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3311 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3312 				 set, "set");
3313 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3314 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3315 			      port_id, UINT8);
3316 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3317 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3318 			      vlan_id, UINT16);
3319 
3320 cmdline_parse_inst_t cmd_tx_vlan_set = {
3321 	.f = cmd_tx_vlan_set_parsed,
3322 	.data = NULL,
3323 	.help_str = "tx_vlan set <port_id> <vlan_id>: "
3324 		"Enable hardware insertion of a single VLAN header "
3325 		"with a given TAG Identifier in packets sent on a port",
3326 	.tokens = {
3327 		(void *)&cmd_tx_vlan_set_tx_vlan,
3328 		(void *)&cmd_tx_vlan_set_set,
3329 		(void *)&cmd_tx_vlan_set_portid,
3330 		(void *)&cmd_tx_vlan_set_vlanid,
3331 		NULL,
3332 	},
3333 };
3334 
3335 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3336 struct cmd_tx_vlan_set_qinq_result {
3337 	cmdline_fixed_string_t tx_vlan;
3338 	cmdline_fixed_string_t set;
3339 	uint8_t port_id;
3340 	uint16_t vlan_id;
3341 	uint16_t vlan_id_outer;
3342 };
3343 
3344 static void
3345 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3346 			    __attribute__((unused)) struct cmdline *cl,
3347 			    __attribute__((unused)) void *data)
3348 {
3349 	struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3350 
3351 	tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3352 }
3353 
3354 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3355 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3356 		tx_vlan, "tx_vlan");
3357 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3358 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3359 		set, "set");
3360 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3361 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3362 		port_id, UINT8);
3363 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3364 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3365 		vlan_id, UINT16);
3366 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3367 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3368 		vlan_id_outer, UINT16);
3369 
3370 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3371 	.f = cmd_tx_vlan_set_qinq_parsed,
3372 	.data = NULL,
3373 	.help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3374 		"Enable hardware insertion of double VLAN header "
3375 		"with given TAG Identifiers in packets sent on a port",
3376 	.tokens = {
3377 		(void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3378 		(void *)&cmd_tx_vlan_set_qinq_set,
3379 		(void *)&cmd_tx_vlan_set_qinq_portid,
3380 		(void *)&cmd_tx_vlan_set_qinq_vlanid,
3381 		(void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3382 		NULL,
3383 	},
3384 };
3385 
3386 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3387 struct cmd_tx_vlan_set_pvid_result {
3388 	cmdline_fixed_string_t tx_vlan;
3389 	cmdline_fixed_string_t set;
3390 	cmdline_fixed_string_t pvid;
3391 	uint8_t port_id;
3392 	uint16_t vlan_id;
3393 	cmdline_fixed_string_t mode;
3394 };
3395 
3396 static void
3397 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3398 			    __attribute__((unused)) struct cmdline *cl,
3399 			    __attribute__((unused)) void *data)
3400 {
3401 	struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3402 
3403 	if (strcmp(res->mode, "on") == 0)
3404 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3405 	else
3406 		tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3407 }
3408 
3409 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3410 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3411 				 tx_vlan, "tx_vlan");
3412 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3413 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3414 				 set, "set");
3415 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3416 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3417 				 pvid, "pvid");
3418 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3419 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3420 			     port_id, UINT8);
3421 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3422 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3423 			      vlan_id, UINT16);
3424 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3425 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3426 				 mode, "on#off");
3427 
3428 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3429 	.f = cmd_tx_vlan_set_pvid_parsed,
3430 	.data = NULL,
3431 	.help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3432 	.tokens = {
3433 		(void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3434 		(void *)&cmd_tx_vlan_set_pvid_set,
3435 		(void *)&cmd_tx_vlan_set_pvid_pvid,
3436 		(void *)&cmd_tx_vlan_set_pvid_port_id,
3437 		(void *)&cmd_tx_vlan_set_pvid_vlan_id,
3438 		(void *)&cmd_tx_vlan_set_pvid_mode,
3439 		NULL,
3440 	},
3441 };
3442 
3443 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3444 struct cmd_tx_vlan_reset_result {
3445 	cmdline_fixed_string_t tx_vlan;
3446 	cmdline_fixed_string_t reset;
3447 	uint8_t port_id;
3448 };
3449 
3450 static void
3451 cmd_tx_vlan_reset_parsed(void *parsed_result,
3452 			 __attribute__((unused)) struct cmdline *cl,
3453 			 __attribute__((unused)) void *data)
3454 {
3455 	struct cmd_tx_vlan_reset_result *res = parsed_result;
3456 
3457 	tx_vlan_reset(res->port_id);
3458 }
3459 
3460 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3461 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3462 				 tx_vlan, "tx_vlan");
3463 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3464 	TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3465 				 reset, "reset");
3466 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3467 	TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3468 			      port_id, UINT8);
3469 
3470 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3471 	.f = cmd_tx_vlan_reset_parsed,
3472 	.data = NULL,
3473 	.help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3474 		"VLAN header in packets sent on a port",
3475 	.tokens = {
3476 		(void *)&cmd_tx_vlan_reset_tx_vlan,
3477 		(void *)&cmd_tx_vlan_reset_reset,
3478 		(void *)&cmd_tx_vlan_reset_portid,
3479 		NULL,
3480 	},
3481 };
3482 
3483 
3484 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3485 struct cmd_csum_result {
3486 	cmdline_fixed_string_t csum;
3487 	cmdline_fixed_string_t mode;
3488 	cmdline_fixed_string_t proto;
3489 	cmdline_fixed_string_t hwsw;
3490 	uint8_t port_id;
3491 };
3492 
3493 static void
3494 csum_show(int port_id)
3495 {
3496 	struct rte_eth_dev_info dev_info;
3497 	uint16_t ol_flags;
3498 
3499 	ol_flags = ports[port_id].tx_ol_flags;
3500 	printf("Parse tunnel is %s\n",
3501 		(ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3502 	printf("IP checksum offload is %s\n",
3503 		(ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3504 	printf("UDP checksum offload is %s\n",
3505 		(ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3506 	printf("TCP checksum offload is %s\n",
3507 		(ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3508 	printf("SCTP checksum offload is %s\n",
3509 		(ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3510 	printf("Outer-Ip checksum offload is %s\n",
3511 		(ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3512 
3513 	/* display warnings if configuration is not supported by the NIC */
3514 	rte_eth_dev_info_get(port_id, &dev_info);
3515 	if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3516 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3517 		printf("Warning: hardware IP checksum enabled but not "
3518 			"supported by port %d\n", port_id);
3519 	}
3520 	if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3521 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3522 		printf("Warning: hardware UDP checksum enabled but not "
3523 			"supported by port %d\n", port_id);
3524 	}
3525 	if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3526 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3527 		printf("Warning: hardware TCP checksum enabled but not "
3528 			"supported by port %d\n", port_id);
3529 	}
3530 	if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3531 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3532 		printf("Warning: hardware SCTP checksum enabled but not "
3533 			"supported by port %d\n", port_id);
3534 	}
3535 	if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3536 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3537 		printf("Warning: hardware outer IP checksum enabled but not "
3538 			"supported by port %d\n", port_id);
3539 	}
3540 }
3541 
3542 static void
3543 cmd_csum_parsed(void *parsed_result,
3544 		       __attribute__((unused)) struct cmdline *cl,
3545 		       __attribute__((unused)) void *data)
3546 {
3547 	struct cmd_csum_result *res = parsed_result;
3548 	int hw = 0;
3549 	uint16_t mask = 0;
3550 
3551 	if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3552 		printf("invalid port %d\n", res->port_id);
3553 		return;
3554 	}
3555 
3556 	if (!strcmp(res->mode, "set")) {
3557 
3558 		if (!strcmp(res->hwsw, "hw"))
3559 			hw = 1;
3560 
3561 		if (!strcmp(res->proto, "ip")) {
3562 			mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3563 		} else if (!strcmp(res->proto, "udp")) {
3564 			mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3565 		} else if (!strcmp(res->proto, "tcp")) {
3566 			mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3567 		} else if (!strcmp(res->proto, "sctp")) {
3568 			mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3569 		} else if (!strcmp(res->proto, "outer-ip")) {
3570 			mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3571 		}
3572 
3573 		if (hw)
3574 			ports[res->port_id].tx_ol_flags |= mask;
3575 		else
3576 			ports[res->port_id].tx_ol_flags &= (~mask);
3577 	}
3578 	csum_show(res->port_id);
3579 }
3580 
3581 cmdline_parse_token_string_t cmd_csum_csum =
3582 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3583 				csum, "csum");
3584 cmdline_parse_token_string_t cmd_csum_mode =
3585 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3586 				mode, "set");
3587 cmdline_parse_token_string_t cmd_csum_proto =
3588 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3589 				proto, "ip#tcp#udp#sctp#outer-ip");
3590 cmdline_parse_token_string_t cmd_csum_hwsw =
3591 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3592 				hwsw, "hw#sw");
3593 cmdline_parse_token_num_t cmd_csum_portid =
3594 	TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3595 				port_id, UINT8);
3596 
3597 cmdline_parse_inst_t cmd_csum_set = {
3598 	.f = cmd_csum_parsed,
3599 	.data = NULL,
3600 	.help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3601 		"Enable/Disable hardware calculation of L3/L4 checksum when "
3602 		"using csum forward engine",
3603 	.tokens = {
3604 		(void *)&cmd_csum_csum,
3605 		(void *)&cmd_csum_mode,
3606 		(void *)&cmd_csum_proto,
3607 		(void *)&cmd_csum_hwsw,
3608 		(void *)&cmd_csum_portid,
3609 		NULL,
3610 	},
3611 };
3612 
3613 cmdline_parse_token_string_t cmd_csum_mode_show =
3614 	TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3615 				mode, "show");
3616 
3617 cmdline_parse_inst_t cmd_csum_show = {
3618 	.f = cmd_csum_parsed,
3619 	.data = NULL,
3620 	.help_str = "csum show <port_id>: Show checksum offload configuration",
3621 	.tokens = {
3622 		(void *)&cmd_csum_csum,
3623 		(void *)&cmd_csum_mode_show,
3624 		(void *)&cmd_csum_portid,
3625 		NULL,
3626 	},
3627 };
3628 
3629 /* Enable/disable tunnel parsing */
3630 struct cmd_csum_tunnel_result {
3631 	cmdline_fixed_string_t csum;
3632 	cmdline_fixed_string_t parse;
3633 	cmdline_fixed_string_t onoff;
3634 	uint8_t port_id;
3635 };
3636 
3637 static void
3638 cmd_csum_tunnel_parsed(void *parsed_result,
3639 		       __attribute__((unused)) struct cmdline *cl,
3640 		       __attribute__((unused)) void *data)
3641 {
3642 	struct cmd_csum_tunnel_result *res = parsed_result;
3643 
3644 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3645 		return;
3646 
3647 	if (!strcmp(res->onoff, "on"))
3648 		ports[res->port_id].tx_ol_flags |=
3649 			TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3650 	else
3651 		ports[res->port_id].tx_ol_flags &=
3652 			(~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3653 
3654 	csum_show(res->port_id);
3655 }
3656 
3657 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3658 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3659 				csum, "csum");
3660 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3661 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3662 				parse, "parse_tunnel");
3663 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3664 	TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3665 				onoff, "on#off");
3666 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3667 	TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3668 				port_id, UINT8);
3669 
3670 cmdline_parse_inst_t cmd_csum_tunnel = {
3671 	.f = cmd_csum_tunnel_parsed,
3672 	.data = NULL,
3673 	.help_str = "csum parse_tunnel on|off <port_id>: "
3674 		"Enable/Disable parsing of tunnels for csum engine",
3675 	.tokens = {
3676 		(void *)&cmd_csum_tunnel_csum,
3677 		(void *)&cmd_csum_tunnel_parse,
3678 		(void *)&cmd_csum_tunnel_onoff,
3679 		(void *)&cmd_csum_tunnel_portid,
3680 		NULL,
3681 	},
3682 };
3683 
3684 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3685 struct cmd_tso_set_result {
3686 	cmdline_fixed_string_t tso;
3687 	cmdline_fixed_string_t mode;
3688 	uint16_t tso_segsz;
3689 	uint8_t port_id;
3690 };
3691 
3692 static void
3693 cmd_tso_set_parsed(void *parsed_result,
3694 		       __attribute__((unused)) struct cmdline *cl,
3695 		       __attribute__((unused)) void *data)
3696 {
3697 	struct cmd_tso_set_result *res = parsed_result;
3698 	struct rte_eth_dev_info dev_info;
3699 
3700 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3701 		return;
3702 
3703 	if (!strcmp(res->mode, "set"))
3704 		ports[res->port_id].tso_segsz = res->tso_segsz;
3705 
3706 	if (ports[res->port_id].tso_segsz == 0)
3707 		printf("TSO for non-tunneled packets is disabled\n");
3708 	else
3709 		printf("TSO segment size for non-tunneled packets is %d\n",
3710 			ports[res->port_id].tso_segsz);
3711 
3712 	/* display warnings if configuration is not supported by the NIC */
3713 	rte_eth_dev_info_get(res->port_id, &dev_info);
3714 	if ((ports[res->port_id].tso_segsz != 0) &&
3715 		(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3716 		printf("Warning: TSO enabled but not "
3717 			"supported by port %d\n", res->port_id);
3718 	}
3719 }
3720 
3721 cmdline_parse_token_string_t cmd_tso_set_tso =
3722 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3723 				tso, "tso");
3724 cmdline_parse_token_string_t cmd_tso_set_mode =
3725 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3726 				mode, "set");
3727 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3728 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3729 				tso_segsz, UINT16);
3730 cmdline_parse_token_num_t cmd_tso_set_portid =
3731 	TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3732 				port_id, UINT8);
3733 
3734 cmdline_parse_inst_t cmd_tso_set = {
3735 	.f = cmd_tso_set_parsed,
3736 	.data = NULL,
3737 	.help_str = "tso set <tso_segsz> <port_id>: "
3738 		"Set TSO segment size of non-tunneled packets for csum engine "
3739 		"(0 to disable)",
3740 	.tokens = {
3741 		(void *)&cmd_tso_set_tso,
3742 		(void *)&cmd_tso_set_mode,
3743 		(void *)&cmd_tso_set_tso_segsz,
3744 		(void *)&cmd_tso_set_portid,
3745 		NULL,
3746 	},
3747 };
3748 
3749 cmdline_parse_token_string_t cmd_tso_show_mode =
3750 	TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3751 				mode, "show");
3752 
3753 
3754 cmdline_parse_inst_t cmd_tso_show = {
3755 	.f = cmd_tso_set_parsed,
3756 	.data = NULL,
3757 	.help_str = "tso show <port_id>: "
3758 		"Show TSO segment size of non-tunneled packets for csum engine",
3759 	.tokens = {
3760 		(void *)&cmd_tso_set_tso,
3761 		(void *)&cmd_tso_show_mode,
3762 		(void *)&cmd_tso_set_portid,
3763 		NULL,
3764 	},
3765 };
3766 
3767 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3768 struct cmd_tunnel_tso_set_result {
3769 	cmdline_fixed_string_t tso;
3770 	cmdline_fixed_string_t mode;
3771 	uint16_t tso_segsz;
3772 	uint8_t port_id;
3773 };
3774 
3775 static void
3776 check_tunnel_tso_nic_support(uint8_t port_id)
3777 {
3778 	struct rte_eth_dev_info dev_info;
3779 
3780 	rte_eth_dev_info_get(port_id, &dev_info);
3781 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3782 		printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3783 		       "supported by port %d\n", port_id);
3784 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3785 		printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3786 			"supported by port %d\n", port_id);
3787 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3788 		printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3789 		       "supported by port %d\n", port_id);
3790 	if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3791 		printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3792 		       "supported by port %d\n", port_id);
3793 }
3794 
3795 static void
3796 cmd_tunnel_tso_set_parsed(void *parsed_result,
3797 			  __attribute__((unused)) struct cmdline *cl,
3798 			  __attribute__((unused)) void *data)
3799 {
3800 	struct cmd_tunnel_tso_set_result *res = parsed_result;
3801 
3802 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3803 		return;
3804 
3805 	if (!strcmp(res->mode, "set"))
3806 		ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3807 
3808 	if (ports[res->port_id].tunnel_tso_segsz == 0)
3809 		printf("TSO for tunneled packets is disabled\n");
3810 	else {
3811 		printf("TSO segment size for tunneled packets is %d\n",
3812 			ports[res->port_id].tunnel_tso_segsz);
3813 
3814 		/* Below conditions are needed to make it work:
3815 		 * (1) tunnel TSO is supported by the NIC;
3816 		 * (2) "csum parse_tunnel" must be set so that tunneled pkts
3817 		 * are recognized;
3818 		 * (3) for tunneled pkts with outer L3 of IPv4,
3819 		 * "csum set outer-ip" must be set to hw, because after tso,
3820 		 * total_len of outer IP header is changed, and the checksum
3821 		 * of outer IP header calculated by sw should be wrong; that
3822 		 * is not necessary for IPv6 tunneled pkts because there's no
3823 		 * checksum in IP header anymore.
3824 		 */
3825 		check_tunnel_tso_nic_support(res->port_id);
3826 
3827 		if (!(ports[res->port_id].tx_ol_flags &
3828 		      TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3829 			printf("Warning: csum parse_tunnel must be set "
3830 				"so that tunneled packets are recognized\n");
3831 		if (!(ports[res->port_id].tx_ol_flags &
3832 		      TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3833 			printf("Warning: csum set outer-ip must be set to hw "
3834 				"if outer L3 is IPv4; not necessary for IPv6\n");
3835 	}
3836 }
3837 
3838 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3839 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3840 				tso, "tunnel_tso");
3841 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3842 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3843 				mode, "set");
3844 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3845 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3846 				tso_segsz, UINT16);
3847 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3848 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3849 				port_id, UINT8);
3850 
3851 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3852 	.f = cmd_tunnel_tso_set_parsed,
3853 	.data = NULL,
3854 	.help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3855 		"Set TSO segment size of tunneled packets for csum engine "
3856 		"(0 to disable)",
3857 	.tokens = {
3858 		(void *)&cmd_tunnel_tso_set_tso,
3859 		(void *)&cmd_tunnel_tso_set_mode,
3860 		(void *)&cmd_tunnel_tso_set_tso_segsz,
3861 		(void *)&cmd_tunnel_tso_set_portid,
3862 		NULL,
3863 	},
3864 };
3865 
3866 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
3867 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3868 				mode, "show");
3869 
3870 
3871 cmdline_parse_inst_t cmd_tunnel_tso_show = {
3872 	.f = cmd_tunnel_tso_set_parsed,
3873 	.data = NULL,
3874 	.help_str = "tunnel_tso show <port_id> "
3875 		"Show TSO segment size of tunneled packets for csum engine",
3876 	.tokens = {
3877 		(void *)&cmd_tunnel_tso_set_tso,
3878 		(void *)&cmd_tunnel_tso_show_mode,
3879 		(void *)&cmd_tunnel_tso_set_portid,
3880 		NULL,
3881 	},
3882 };
3883 
3884 /* *** SET GRO FOR A PORT *** */
3885 struct cmd_gro_enable_result {
3886 	cmdline_fixed_string_t cmd_set;
3887 	cmdline_fixed_string_t cmd_port;
3888 	cmdline_fixed_string_t cmd_keyword;
3889 	cmdline_fixed_string_t cmd_onoff;
3890 	portid_t cmd_pid;
3891 };
3892 
3893 static void
3894 cmd_gro_enable_parsed(void *parsed_result,
3895 		__attribute__((unused)) struct cmdline *cl,
3896 		__attribute__((unused)) void *data)
3897 {
3898 	struct cmd_gro_enable_result *res;
3899 
3900 	res = parsed_result;
3901 	if (!strcmp(res->cmd_keyword, "gro"))
3902 		setup_gro(res->cmd_onoff, res->cmd_pid);
3903 }
3904 
3905 cmdline_parse_token_string_t cmd_gro_enable_set =
3906 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3907 			cmd_set, "set");
3908 cmdline_parse_token_string_t cmd_gro_enable_port =
3909 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3910 			cmd_keyword, "port");
3911 cmdline_parse_token_num_t cmd_gro_enable_pid =
3912 	TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
3913 			cmd_pid, UINT16);
3914 cmdline_parse_token_string_t cmd_gro_enable_keyword =
3915 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3916 			cmd_keyword, "gro");
3917 cmdline_parse_token_string_t cmd_gro_enable_onoff =
3918 	TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
3919 			cmd_onoff, "on#off");
3920 
3921 cmdline_parse_inst_t cmd_gro_enable = {
3922 	.f = cmd_gro_enable_parsed,
3923 	.data = NULL,
3924 	.help_str = "set port <port_id> gro on|off",
3925 	.tokens = {
3926 		(void *)&cmd_gro_enable_set,
3927 		(void *)&cmd_gro_enable_port,
3928 		(void *)&cmd_gro_enable_pid,
3929 		(void *)&cmd_gro_enable_keyword,
3930 		(void *)&cmd_gro_enable_onoff,
3931 		NULL,
3932 	},
3933 };
3934 
3935 /* *** DISPLAY GRO CONFIGURATION *** */
3936 struct cmd_gro_show_result {
3937 	cmdline_fixed_string_t cmd_show;
3938 	cmdline_fixed_string_t cmd_port;
3939 	cmdline_fixed_string_t cmd_keyword;
3940 	portid_t cmd_pid;
3941 };
3942 
3943 static void
3944 cmd_gro_show_parsed(void *parsed_result,
3945 		__attribute__((unused)) struct cmdline *cl,
3946 		__attribute__((unused)) void *data)
3947 {
3948 	struct cmd_gro_show_result *res;
3949 
3950 	res = parsed_result;
3951 	if (!strcmp(res->cmd_keyword, "gro"))
3952 		show_gro(res->cmd_pid);
3953 }
3954 
3955 cmdline_parse_token_string_t cmd_gro_show_show =
3956 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3957 			cmd_show, "show");
3958 cmdline_parse_token_string_t cmd_gro_show_port =
3959 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3960 			cmd_port, "port");
3961 cmdline_parse_token_num_t cmd_gro_show_pid =
3962 	TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
3963 			cmd_pid, UINT16);
3964 cmdline_parse_token_string_t cmd_gro_show_keyword =
3965 	TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
3966 			cmd_keyword, "gro");
3967 
3968 cmdline_parse_inst_t cmd_gro_show = {
3969 	.f = cmd_gro_show_parsed,
3970 	.data = NULL,
3971 	.help_str = "show port <port_id> gro",
3972 	.tokens = {
3973 		(void *)&cmd_gro_show_show,
3974 		(void *)&cmd_gro_show_port,
3975 		(void *)&cmd_gro_show_pid,
3976 		(void *)&cmd_gro_show_keyword,
3977 		NULL,
3978 	},
3979 };
3980 
3981 /* *** SET FLUSH CYCLES FOR GRO *** */
3982 struct cmd_gro_flush_result {
3983 	cmdline_fixed_string_t cmd_set;
3984 	cmdline_fixed_string_t cmd_keyword;
3985 	cmdline_fixed_string_t cmd_flush;
3986 	uint8_t cmd_cycles;
3987 };
3988 
3989 static void
3990 cmd_gro_flush_parsed(void *parsed_result,
3991 		__attribute__((unused)) struct cmdline *cl,
3992 		__attribute__((unused)) void *data)
3993 {
3994 	struct cmd_gro_flush_result *res;
3995 
3996 	res = parsed_result;
3997 	if ((!strcmp(res->cmd_keyword, "gro")) &&
3998 			(!strcmp(res->cmd_flush, "flush")))
3999 		setup_gro_flush_cycles(res->cmd_cycles);
4000 }
4001 
4002 cmdline_parse_token_string_t cmd_gro_flush_set =
4003 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4004 			cmd_set, "set");
4005 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4006 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4007 			cmd_keyword, "gro");
4008 cmdline_parse_token_string_t cmd_gro_flush_flush =
4009 	TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4010 			cmd_flush, "flush");
4011 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4012 	TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4013 			cmd_cycles, UINT8);
4014 
4015 cmdline_parse_inst_t cmd_gro_flush = {
4016 	.f = cmd_gro_flush_parsed,
4017 	.data = NULL,
4018 	.help_str = "set gro flush <cycles>",
4019 	.tokens = {
4020 		(void *)&cmd_gro_flush_set,
4021 		(void *)&cmd_gro_flush_keyword,
4022 		(void *)&cmd_gro_flush_flush,
4023 		(void *)&cmd_gro_flush_cycles,
4024 		NULL,
4025 	},
4026 };
4027 
4028 /* *** ENABLE/DISABLE GSO *** */
4029 struct cmd_gso_enable_result {
4030 	cmdline_fixed_string_t cmd_set;
4031 	cmdline_fixed_string_t cmd_port;
4032 	cmdline_fixed_string_t cmd_keyword;
4033 	cmdline_fixed_string_t cmd_mode;
4034 	portid_t cmd_pid;
4035 };
4036 
4037 static void
4038 cmd_gso_enable_parsed(void *parsed_result,
4039 		__attribute__((unused)) struct cmdline *cl,
4040 		__attribute__((unused)) void *data)
4041 {
4042 	struct cmd_gso_enable_result *res;
4043 
4044 	res = parsed_result;
4045 	if (!strcmp(res->cmd_keyword, "gso"))
4046 		setup_gso(res->cmd_mode, res->cmd_pid);
4047 }
4048 
4049 cmdline_parse_token_string_t cmd_gso_enable_set =
4050 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4051 			cmd_set, "set");
4052 cmdline_parse_token_string_t cmd_gso_enable_port =
4053 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4054 			cmd_port, "port");
4055 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4056 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4057 			cmd_keyword, "gso");
4058 cmdline_parse_token_string_t cmd_gso_enable_mode =
4059 	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4060 			cmd_mode, "on#off");
4061 cmdline_parse_token_num_t cmd_gso_enable_pid =
4062 	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4063 			cmd_pid, UINT16);
4064 
4065 cmdline_parse_inst_t cmd_gso_enable = {
4066 	.f = cmd_gso_enable_parsed,
4067 	.data = NULL,
4068 	.help_str = "set port <port_id> gso on|off",
4069 	.tokens = {
4070 		(void *)&cmd_gso_enable_set,
4071 		(void *)&cmd_gso_enable_port,
4072 		(void *)&cmd_gso_enable_pid,
4073 		(void *)&cmd_gso_enable_keyword,
4074 		(void *)&cmd_gso_enable_mode,
4075 		NULL,
4076 	},
4077 };
4078 
4079 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4080 struct cmd_gso_size_result {
4081 	cmdline_fixed_string_t cmd_set;
4082 	cmdline_fixed_string_t cmd_keyword;
4083 	cmdline_fixed_string_t cmd_segsz;
4084 	uint16_t cmd_size;
4085 };
4086 
4087 static void
4088 cmd_gso_size_parsed(void *parsed_result,
4089 		       __attribute__((unused)) struct cmdline *cl,
4090 		       __attribute__((unused)) void *data)
4091 {
4092 	struct cmd_gso_size_result *res = parsed_result;
4093 
4094 	if (test_done == 0) {
4095 		printf("Before setting GSO segsz, please first"
4096 				" stop fowarding\n");
4097 		return;
4098 	}
4099 
4100 	if (!strcmp(res->cmd_keyword, "gso") &&
4101 			!strcmp(res->cmd_segsz, "segsz")) {
4102 		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4103 			printf("gso_size should be larger than %zu."
4104 					" Please input a legal value\n",
4105 					RTE_GSO_SEG_SIZE_MIN);
4106 		else
4107 			gso_max_segment_size = res->cmd_size;
4108 	}
4109 }
4110 
4111 cmdline_parse_token_string_t cmd_gso_size_set =
4112 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4113 				cmd_set, "set");
4114 cmdline_parse_token_string_t cmd_gso_size_keyword =
4115 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4116 				cmd_keyword, "gso");
4117 cmdline_parse_token_string_t cmd_gso_size_segsz =
4118 	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4119 				cmd_segsz, "segsz");
4120 cmdline_parse_token_num_t cmd_gso_size_size =
4121 	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4122 				cmd_size, UINT16);
4123 
4124 cmdline_parse_inst_t cmd_gso_size = {
4125 	.f = cmd_gso_size_parsed,
4126 	.data = NULL,
4127 	.help_str = "set gso segsz <length>",
4128 	.tokens = {
4129 		(void *)&cmd_gso_size_set,
4130 		(void *)&cmd_gso_size_keyword,
4131 		(void *)&cmd_gso_size_segsz,
4132 		(void *)&cmd_gso_size_size,
4133 		NULL,
4134 	},
4135 };
4136 
4137 /* *** SHOW GSO CONFIGURATION *** */
4138 struct cmd_gso_show_result {
4139 	cmdline_fixed_string_t cmd_show;
4140 	cmdline_fixed_string_t cmd_port;
4141 	cmdline_fixed_string_t cmd_keyword;
4142 	portid_t cmd_pid;
4143 };
4144 
4145 static void
4146 cmd_gso_show_parsed(void *parsed_result,
4147 		       __attribute__((unused)) struct cmdline *cl,
4148 		       __attribute__((unused)) void *data)
4149 {
4150 	struct cmd_gso_show_result *res = parsed_result;
4151 
4152 	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4153 		printf("invalid port id %u\n", res->cmd_pid);
4154 		return;
4155 	}
4156 	if (!strcmp(res->cmd_keyword, "gso")) {
4157 		if (gso_ports[res->cmd_pid].enable) {
4158 			printf("Max GSO'd packet size: %uB\n"
4159 					"Supported GSO types: TCP/IPv4, "
4160 					"VxLAN with inner TCP/IPv4 packet, "
4161 					"GRE with inner TCP/IPv4  packet\n",
4162 					gso_max_segment_size);
4163 		} else
4164 			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4165 	}
4166 }
4167 
4168 cmdline_parse_token_string_t cmd_gso_show_show =
4169 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4170 		cmd_show, "show");
4171 cmdline_parse_token_string_t cmd_gso_show_port =
4172 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4173 		cmd_port, "port");
4174 cmdline_parse_token_string_t cmd_gso_show_keyword =
4175 	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4176 				cmd_keyword, "gso");
4177 cmdline_parse_token_num_t cmd_gso_show_pid =
4178 	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4179 				cmd_pid, UINT16);
4180 
4181 cmdline_parse_inst_t cmd_gso_show = {
4182 	.f = cmd_gso_show_parsed,
4183 	.data = NULL,
4184 	.help_str = "show port <port_id> gso",
4185 	.tokens = {
4186 		(void *)&cmd_gso_show_show,
4187 		(void *)&cmd_gso_show_port,
4188 		(void *)&cmd_gso_show_pid,
4189 		(void *)&cmd_gso_show_keyword,
4190 		NULL,
4191 	},
4192 };
4193 
4194 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4195 struct cmd_set_flush_rx {
4196 	cmdline_fixed_string_t set;
4197 	cmdline_fixed_string_t flush_rx;
4198 	cmdline_fixed_string_t mode;
4199 };
4200 
4201 static void
4202 cmd_set_flush_rx_parsed(void *parsed_result,
4203 		__attribute__((unused)) struct cmdline *cl,
4204 		__attribute__((unused)) void *data)
4205 {
4206 	struct cmd_set_flush_rx *res = parsed_result;
4207 	no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4208 }
4209 
4210 cmdline_parse_token_string_t cmd_setflushrx_set =
4211 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4212 			set, "set");
4213 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4214 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4215 			flush_rx, "flush_rx");
4216 cmdline_parse_token_string_t cmd_setflushrx_mode =
4217 	TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4218 			mode, "on#off");
4219 
4220 
4221 cmdline_parse_inst_t cmd_set_flush_rx = {
4222 	.f = cmd_set_flush_rx_parsed,
4223 	.help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4224 	.data = NULL,
4225 	.tokens = {
4226 		(void *)&cmd_setflushrx_set,
4227 		(void *)&cmd_setflushrx_flush_rx,
4228 		(void *)&cmd_setflushrx_mode,
4229 		NULL,
4230 	},
4231 };
4232 
4233 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4234 struct cmd_set_link_check {
4235 	cmdline_fixed_string_t set;
4236 	cmdline_fixed_string_t link_check;
4237 	cmdline_fixed_string_t mode;
4238 };
4239 
4240 static void
4241 cmd_set_link_check_parsed(void *parsed_result,
4242 		__attribute__((unused)) struct cmdline *cl,
4243 		__attribute__((unused)) void *data)
4244 {
4245 	struct cmd_set_link_check *res = parsed_result;
4246 	no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4247 }
4248 
4249 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4250 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4251 			set, "set");
4252 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4253 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4254 			link_check, "link_check");
4255 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4256 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4257 			mode, "on#off");
4258 
4259 
4260 cmdline_parse_inst_t cmd_set_link_check = {
4261 	.f = cmd_set_link_check_parsed,
4262 	.help_str = "set link_check on|off: Enable/Disable link status check "
4263 	            "when starting/stopping a port",
4264 	.data = NULL,
4265 	.tokens = {
4266 		(void *)&cmd_setlinkcheck_set,
4267 		(void *)&cmd_setlinkcheck_link_check,
4268 		(void *)&cmd_setlinkcheck_mode,
4269 		NULL,
4270 	},
4271 };
4272 
4273 /* *** SET NIC BYPASS MODE *** */
4274 struct cmd_set_bypass_mode_result {
4275 	cmdline_fixed_string_t set;
4276 	cmdline_fixed_string_t bypass;
4277 	cmdline_fixed_string_t mode;
4278 	cmdline_fixed_string_t value;
4279 	uint8_t port_id;
4280 };
4281 
4282 static void
4283 cmd_set_bypass_mode_parsed(void *parsed_result,
4284 		__attribute__((unused)) struct cmdline *cl,
4285 		__attribute__((unused)) void *data)
4286 {
4287 	struct cmd_set_bypass_mode_result *res = parsed_result;
4288 	portid_t port_id = res->port_id;
4289 	int32_t rc = -EINVAL;
4290 
4291 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4292 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4293 
4294 	if (!strcmp(res->value, "bypass"))
4295 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4296 	else if (!strcmp(res->value, "isolate"))
4297 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4298 	else
4299 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4300 
4301 	/* Set the bypass mode for the relevant port. */
4302 	rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4303 #endif
4304 	if (rc != 0)
4305 		printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4306 }
4307 
4308 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4309 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4310 			set, "set");
4311 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4312 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4313 			bypass, "bypass");
4314 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4315 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4316 			mode, "mode");
4317 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4318 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4319 			value, "normal#bypass#isolate");
4320 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4321 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4322 				port_id, UINT8);
4323 
4324 cmdline_parse_inst_t cmd_set_bypass_mode = {
4325 	.f = cmd_set_bypass_mode_parsed,
4326 	.help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4327 	            "Set the NIC bypass mode for port_id",
4328 	.data = NULL,
4329 	.tokens = {
4330 		(void *)&cmd_setbypass_mode_set,
4331 		(void *)&cmd_setbypass_mode_bypass,
4332 		(void *)&cmd_setbypass_mode_mode,
4333 		(void *)&cmd_setbypass_mode_value,
4334 		(void *)&cmd_setbypass_mode_port,
4335 		NULL,
4336 	},
4337 };
4338 
4339 /* *** SET NIC BYPASS EVENT *** */
4340 struct cmd_set_bypass_event_result {
4341 	cmdline_fixed_string_t set;
4342 	cmdline_fixed_string_t bypass;
4343 	cmdline_fixed_string_t event;
4344 	cmdline_fixed_string_t event_value;
4345 	cmdline_fixed_string_t mode;
4346 	cmdline_fixed_string_t mode_value;
4347 	uint8_t port_id;
4348 };
4349 
4350 static void
4351 cmd_set_bypass_event_parsed(void *parsed_result,
4352 		__attribute__((unused)) struct cmdline *cl,
4353 		__attribute__((unused)) void *data)
4354 {
4355 	int32_t rc = -EINVAL;
4356 	struct cmd_set_bypass_event_result *res = parsed_result;
4357 	portid_t port_id = res->port_id;
4358 
4359 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4360 	uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4361 	uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4362 
4363 	if (!strcmp(res->event_value, "timeout"))
4364 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4365 	else if (!strcmp(res->event_value, "os_on"))
4366 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4367 	else if (!strcmp(res->event_value, "os_off"))
4368 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4369 	else if (!strcmp(res->event_value, "power_on"))
4370 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4371 	else if (!strcmp(res->event_value, "power_off"))
4372 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4373 	else
4374 		bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4375 
4376 	if (!strcmp(res->mode_value, "bypass"))
4377 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4378 	else if (!strcmp(res->mode_value, "isolate"))
4379 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4380 	else
4381 		bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4382 
4383 	/* Set the watchdog timeout. */
4384 	if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4385 
4386 		rc = -EINVAL;
4387 		if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4388 			rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4389 							   bypass_timeout);
4390 		}
4391 		if (rc != 0) {
4392 			printf("Failed to set timeout value %u "
4393 			"for port %d, errto code: %d.\n",
4394 			bypass_timeout, port_id, rc);
4395 		}
4396 	}
4397 
4398 	/* Set the bypass event to transition to bypass mode. */
4399 	rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4400 					      bypass_mode);
4401 #endif
4402 
4403 	if (rc != 0)
4404 		printf("\t Failed to set bypass event for port = %d.\n",
4405 		       port_id);
4406 }
4407 
4408 cmdline_parse_token_string_t cmd_setbypass_event_set =
4409 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4410 			set, "set");
4411 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4412 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4413 			bypass, "bypass");
4414 cmdline_parse_token_string_t cmd_setbypass_event_event =
4415 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4416 			event, "event");
4417 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4418 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4419 			event_value, "none#timeout#os_off#os_on#power_on#power_off");
4420 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4421 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4422 			mode, "mode");
4423 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4424 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4425 			mode_value, "normal#bypass#isolate");
4426 cmdline_parse_token_num_t cmd_setbypass_event_port =
4427 	TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4428 				port_id, UINT8);
4429 
4430 cmdline_parse_inst_t cmd_set_bypass_event = {
4431 	.f = cmd_set_bypass_event_parsed,
4432 	.help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4433 		"power_off mode normal|bypass|isolate <port_id>: "
4434 		"Set the NIC bypass event mode for port_id",
4435 	.data = NULL,
4436 	.tokens = {
4437 		(void *)&cmd_setbypass_event_set,
4438 		(void *)&cmd_setbypass_event_bypass,
4439 		(void *)&cmd_setbypass_event_event,
4440 		(void *)&cmd_setbypass_event_event_value,
4441 		(void *)&cmd_setbypass_event_mode,
4442 		(void *)&cmd_setbypass_event_mode_value,
4443 		(void *)&cmd_setbypass_event_port,
4444 		NULL,
4445 	},
4446 };
4447 
4448 
4449 /* *** SET NIC BYPASS TIMEOUT *** */
4450 struct cmd_set_bypass_timeout_result {
4451 	cmdline_fixed_string_t set;
4452 	cmdline_fixed_string_t bypass;
4453 	cmdline_fixed_string_t timeout;
4454 	cmdline_fixed_string_t value;
4455 };
4456 
4457 static void
4458 cmd_set_bypass_timeout_parsed(void *parsed_result,
4459 		__attribute__((unused)) struct cmdline *cl,
4460 		__attribute__((unused)) void *data)
4461 {
4462 	__rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4463 
4464 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4465 	if (!strcmp(res->value, "1.5"))
4466 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4467 	else if (!strcmp(res->value, "2"))
4468 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4469 	else if (!strcmp(res->value, "3"))
4470 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4471 	else if (!strcmp(res->value, "4"))
4472 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4473 	else if (!strcmp(res->value, "8"))
4474 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4475 	else if (!strcmp(res->value, "16"))
4476 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4477 	else if (!strcmp(res->value, "32"))
4478 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4479 	else
4480 		bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4481 #endif
4482 }
4483 
4484 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4485 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4486 			set, "set");
4487 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4488 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4489 			bypass, "bypass");
4490 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4491 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4492 			timeout, "timeout");
4493 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4494 	TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4495 			value, "0#1.5#2#3#4#8#16#32");
4496 
4497 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4498 	.f = cmd_set_bypass_timeout_parsed,
4499 	.help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4500 		"Set the NIC bypass watchdog timeout in seconds",
4501 	.data = NULL,
4502 	.tokens = {
4503 		(void *)&cmd_setbypass_timeout_set,
4504 		(void *)&cmd_setbypass_timeout_bypass,
4505 		(void *)&cmd_setbypass_timeout_timeout,
4506 		(void *)&cmd_setbypass_timeout_value,
4507 		NULL,
4508 	},
4509 };
4510 
4511 /* *** SHOW NIC BYPASS MODE *** */
4512 struct cmd_show_bypass_config_result {
4513 	cmdline_fixed_string_t show;
4514 	cmdline_fixed_string_t bypass;
4515 	cmdline_fixed_string_t config;
4516 	uint8_t port_id;
4517 };
4518 
4519 static void
4520 cmd_show_bypass_config_parsed(void *parsed_result,
4521 		__attribute__((unused)) struct cmdline *cl,
4522 		__attribute__((unused)) void *data)
4523 {
4524 	struct cmd_show_bypass_config_result *res = parsed_result;
4525 	portid_t port_id = res->port_id;
4526 	int rc = -EINVAL;
4527 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4528 	uint32_t event_mode;
4529 	uint32_t bypass_mode;
4530 	uint32_t timeout = bypass_timeout;
4531 	int i;
4532 
4533 	static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4534 		{"off", "1.5", "2", "3", "4", "8", "16", "32"};
4535 	static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4536 		{"UNKNOWN", "normal", "bypass", "isolate"};
4537 	static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4538 		"NONE",
4539 		"OS/board on",
4540 		"power supply on",
4541 		"OS/board off",
4542 		"power supply off",
4543 		"timeout"};
4544 	int num_events = (sizeof events) / (sizeof events[0]);
4545 
4546 	/* Display the bypass mode.*/
4547 	if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4548 		printf("\tFailed to get bypass mode for port = %d\n", port_id);
4549 		return;
4550 	}
4551 	else {
4552 		if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4553 			bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4554 
4555 		printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4556 	}
4557 
4558 	/* Display the bypass timeout.*/
4559 	if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4560 		timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4561 
4562 	printf("\tbypass timeout = %s\n", timeouts[timeout]);
4563 
4564 	/* Display the bypass events and associated modes. */
4565 	for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4566 
4567 		if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4568 			printf("\tFailed to get bypass mode for event = %s\n",
4569 				events[i]);
4570 		} else {
4571 			if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4572 				event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4573 
4574 			printf("\tbypass event: %-16s = %s\n", events[i],
4575 				modes[event_mode]);
4576 		}
4577 	}
4578 #endif
4579 	if (rc != 0)
4580 		printf("\tFailed to get bypass configuration for port = %d\n",
4581 		       port_id);
4582 }
4583 
4584 cmdline_parse_token_string_t cmd_showbypass_config_show =
4585 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4586 			show, "show");
4587 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4588 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4589 			bypass, "bypass");
4590 cmdline_parse_token_string_t cmd_showbypass_config_config =
4591 	TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4592 			config, "config");
4593 cmdline_parse_token_num_t cmd_showbypass_config_port =
4594 	TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4595 				port_id, UINT8);
4596 
4597 cmdline_parse_inst_t cmd_show_bypass_config = {
4598 	.f = cmd_show_bypass_config_parsed,
4599 	.help_str = "show bypass config <port_id>: "
4600 	            "Show the NIC bypass config for port_id",
4601 	.data = NULL,
4602 	.tokens = {
4603 		(void *)&cmd_showbypass_config_show,
4604 		(void *)&cmd_showbypass_config_bypass,
4605 		(void *)&cmd_showbypass_config_config,
4606 		(void *)&cmd_showbypass_config_port,
4607 		NULL,
4608 	},
4609 };
4610 
4611 #ifdef RTE_LIBRTE_PMD_BOND
4612 /* *** SET BONDING MODE *** */
4613 struct cmd_set_bonding_mode_result {
4614 	cmdline_fixed_string_t set;
4615 	cmdline_fixed_string_t bonding;
4616 	cmdline_fixed_string_t mode;
4617 	uint8_t value;
4618 	uint8_t port_id;
4619 };
4620 
4621 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4622 		__attribute__((unused))  struct cmdline *cl,
4623 		__attribute__((unused)) void *data)
4624 {
4625 	struct cmd_set_bonding_mode_result *res = parsed_result;
4626 	portid_t port_id = res->port_id;
4627 
4628 	/* Set the bonding mode for the relevant port. */
4629 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
4630 		printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4631 }
4632 
4633 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4634 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4635 		set, "set");
4636 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4637 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4638 		bonding, "bonding");
4639 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4640 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4641 		mode, "mode");
4642 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4643 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4644 		value, UINT8);
4645 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4646 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4647 		port_id, UINT8);
4648 
4649 cmdline_parse_inst_t cmd_set_bonding_mode = {
4650 		.f = cmd_set_bonding_mode_parsed,
4651 		.help_str = "set bonding mode <mode_value> <port_id>: "
4652 			"Set the bonding mode for port_id",
4653 		.data = NULL,
4654 		.tokens = {
4655 				(void *) &cmd_setbonding_mode_set,
4656 				(void *) &cmd_setbonding_mode_bonding,
4657 				(void *) &cmd_setbonding_mode_mode,
4658 				(void *) &cmd_setbonding_mode_value,
4659 				(void *) &cmd_setbonding_mode_port,
4660 				NULL
4661 		}
4662 };
4663 
4664 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4665 struct cmd_set_bonding_lacp_dedicated_queues_result {
4666 	cmdline_fixed_string_t set;
4667 	cmdline_fixed_string_t bonding;
4668 	cmdline_fixed_string_t lacp;
4669 	cmdline_fixed_string_t dedicated_queues;
4670 	uint8_t port_id;
4671 	cmdline_fixed_string_t mode;
4672 };
4673 
4674 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4675 		__attribute__((unused))  struct cmdline *cl,
4676 		__attribute__((unused)) void *data)
4677 {
4678 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4679 	portid_t port_id = res->port_id;
4680 	struct rte_port *port;
4681 
4682 	port = &ports[port_id];
4683 
4684 	/** Check if the port is not started **/
4685 	if (port->port_status != RTE_PORT_STOPPED) {
4686 		printf("Please stop port %d first\n", port_id);
4687 		return;
4688 	}
4689 
4690 	if (!strcmp(res->mode, "enable")) {
4691 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4692 			printf("Dedicate queues for LACP control packets"
4693 					" enabled\n");
4694 		else
4695 			printf("Enabling dedicate queues for LACP control "
4696 					"packets on port %d failed\n", port_id);
4697 	} else if (!strcmp(res->mode, "disable")) {
4698 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4699 			printf("Dedicated queues for LACP control packets "
4700 					"disabled\n");
4701 		else
4702 			printf("Disabling dedicated queues for LACP control "
4703 					"traffic on port %d failed\n", port_id);
4704 	}
4705 }
4706 
4707 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4708 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4709 		set, "set");
4710 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4711 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4712 		bonding, "bonding");
4713 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4714 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4715 		lacp, "lacp");
4716 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4717 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4718 		dedicated_queues, "dedicated_queues");
4719 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4720 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4721 		port_id, UINT8);
4722 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4723 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4724 		mode, "enable#disable");
4725 
4726 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4727 		.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4728 		.help_str = "set bonding lacp dedicated_queues <port_id> "
4729 			"enable|disable: "
4730 			"Enable/disable dedicated queues for LACP control traffic for port_id",
4731 		.data = NULL,
4732 		.tokens = {
4733 			(void *)&cmd_setbonding_lacp_dedicated_queues_set,
4734 			(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4735 			(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4736 			(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4737 			(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4738 			(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4739 			NULL
4740 		}
4741 };
4742 
4743 /* *** SET BALANCE XMIT POLICY *** */
4744 struct cmd_set_bonding_balance_xmit_policy_result {
4745 	cmdline_fixed_string_t set;
4746 	cmdline_fixed_string_t bonding;
4747 	cmdline_fixed_string_t balance_xmit_policy;
4748 	uint8_t port_id;
4749 	cmdline_fixed_string_t policy;
4750 };
4751 
4752 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4753 		__attribute__((unused))  struct cmdline *cl,
4754 		__attribute__((unused)) void *data)
4755 {
4756 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4757 	portid_t port_id = res->port_id;
4758 	uint8_t policy;
4759 
4760 	if (!strcmp(res->policy, "l2")) {
4761 		policy = BALANCE_XMIT_POLICY_LAYER2;
4762 	} else if (!strcmp(res->policy, "l23")) {
4763 		policy = BALANCE_XMIT_POLICY_LAYER23;
4764 	} else if (!strcmp(res->policy, "l34")) {
4765 		policy = BALANCE_XMIT_POLICY_LAYER34;
4766 	} else {
4767 		printf("\t Invalid xmit policy selection");
4768 		return;
4769 	}
4770 
4771 	/* Set the bonding mode for the relevant port. */
4772 	if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4773 		printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4774 				port_id);
4775 	}
4776 }
4777 
4778 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4779 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4780 		set, "set");
4781 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4782 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4783 		bonding, "bonding");
4784 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4785 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4786 		balance_xmit_policy, "balance_xmit_policy");
4787 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4788 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4789 		port_id, UINT8);
4790 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4791 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4792 		policy, "l2#l23#l34");
4793 
4794 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4795 		.f = cmd_set_bonding_balance_xmit_policy_parsed,
4796 		.help_str = "set bonding balance_xmit_policy <port_id> "
4797 			"l2|l23|l34: "
4798 			"Set the bonding balance_xmit_policy for port_id",
4799 		.data = NULL,
4800 		.tokens = {
4801 				(void *)&cmd_setbonding_balance_xmit_policy_set,
4802 				(void *)&cmd_setbonding_balance_xmit_policy_bonding,
4803 				(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4804 				(void *)&cmd_setbonding_balance_xmit_policy_port,
4805 				(void *)&cmd_setbonding_balance_xmit_policy_policy,
4806 				NULL
4807 		}
4808 };
4809 
4810 /* *** SHOW NIC BONDING CONFIGURATION *** */
4811 struct cmd_show_bonding_config_result {
4812 	cmdline_fixed_string_t show;
4813 	cmdline_fixed_string_t bonding;
4814 	cmdline_fixed_string_t config;
4815 	portid_t port_id;
4816 };
4817 
4818 static void cmd_show_bonding_config_parsed(void *parsed_result,
4819 		__attribute__((unused))  struct cmdline *cl,
4820 		__attribute__((unused)) void *data)
4821 {
4822 	struct cmd_show_bonding_config_result *res = parsed_result;
4823 	int bonding_mode, agg_mode;
4824 	portid_t slaves[RTE_MAX_ETHPORTS];
4825 	int num_slaves, num_active_slaves;
4826 	int primary_id;
4827 	int i;
4828 	portid_t port_id = res->port_id;
4829 
4830 	/* Display the bonding mode.*/
4831 	bonding_mode = rte_eth_bond_mode_get(port_id);
4832 	if (bonding_mode < 0) {
4833 		printf("\tFailed to get bonding mode for port = %d\n", port_id);
4834 		return;
4835 	} else
4836 		printf("\tBonding mode: %d\n", bonding_mode);
4837 
4838 	if (bonding_mode == BONDING_MODE_BALANCE) {
4839 		int balance_xmit_policy;
4840 
4841 		balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4842 		if (balance_xmit_policy < 0) {
4843 			printf("\tFailed to get balance xmit policy for port = %d\n",
4844 					port_id);
4845 			return;
4846 		} else {
4847 			printf("\tBalance Xmit Policy: ");
4848 
4849 			switch (balance_xmit_policy) {
4850 			case BALANCE_XMIT_POLICY_LAYER2:
4851 				printf("BALANCE_XMIT_POLICY_LAYER2");
4852 				break;
4853 			case BALANCE_XMIT_POLICY_LAYER23:
4854 				printf("BALANCE_XMIT_POLICY_LAYER23");
4855 				break;
4856 			case BALANCE_XMIT_POLICY_LAYER34:
4857 				printf("BALANCE_XMIT_POLICY_LAYER34");
4858 				break;
4859 			}
4860 			printf("\n");
4861 		}
4862 	}
4863 
4864 	if (bonding_mode == BONDING_MODE_8023AD) {
4865 		agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
4866 		printf("\tIEEE802.3AD Aggregator Mode: ");
4867 		switch (agg_mode) {
4868 		case AGG_BANDWIDTH:
4869 			printf("bandwidth");
4870 			break;
4871 		case AGG_STABLE:
4872 			printf("stable");
4873 			break;
4874 		case AGG_COUNT:
4875 			printf("count");
4876 			break;
4877 		}
4878 		printf("\n");
4879 	}
4880 
4881 	num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4882 
4883 	if (num_slaves < 0) {
4884 		printf("\tFailed to get slave list for port = %d\n", port_id);
4885 		return;
4886 	}
4887 	if (num_slaves > 0) {
4888 		printf("\tSlaves (%d): [", num_slaves);
4889 		for (i = 0; i < num_slaves - 1; i++)
4890 			printf("%d ", slaves[i]);
4891 
4892 		printf("%d]\n", slaves[num_slaves - 1]);
4893 	} else {
4894 		printf("\tSlaves: []\n");
4895 
4896 	}
4897 
4898 	num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4899 			RTE_MAX_ETHPORTS);
4900 
4901 	if (num_active_slaves < 0) {
4902 		printf("\tFailed to get active slave list for port = %d\n", port_id);
4903 		return;
4904 	}
4905 	if (num_active_slaves > 0) {
4906 		printf("\tActive Slaves (%d): [", num_active_slaves);
4907 		for (i = 0; i < num_active_slaves - 1; i++)
4908 			printf("%d ", slaves[i]);
4909 
4910 		printf("%d]\n", slaves[num_active_slaves - 1]);
4911 
4912 	} else {
4913 		printf("\tActive Slaves: []\n");
4914 
4915 	}
4916 
4917 	primary_id = rte_eth_bond_primary_get(port_id);
4918 	if (primary_id < 0) {
4919 		printf("\tFailed to get primary slave for port = %d\n", port_id);
4920 		return;
4921 	} else
4922 		printf("\tPrimary: [%d]\n", primary_id);
4923 
4924 }
4925 
4926 cmdline_parse_token_string_t cmd_showbonding_config_show =
4927 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4928 		show, "show");
4929 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4930 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4931 		bonding, "bonding");
4932 cmdline_parse_token_string_t cmd_showbonding_config_config =
4933 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4934 		config, "config");
4935 cmdline_parse_token_num_t cmd_showbonding_config_port =
4936 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4937 		port_id, UINT8);
4938 
4939 cmdline_parse_inst_t cmd_show_bonding_config = {
4940 		.f = cmd_show_bonding_config_parsed,
4941 		.help_str = "show bonding config <port_id>: "
4942 			"Show the bonding config for port_id",
4943 		.data = NULL,
4944 		.tokens = {
4945 				(void *)&cmd_showbonding_config_show,
4946 				(void *)&cmd_showbonding_config_bonding,
4947 				(void *)&cmd_showbonding_config_config,
4948 				(void *)&cmd_showbonding_config_port,
4949 				NULL
4950 		}
4951 };
4952 
4953 /* *** SET BONDING PRIMARY *** */
4954 struct cmd_set_bonding_primary_result {
4955 	cmdline_fixed_string_t set;
4956 	cmdline_fixed_string_t bonding;
4957 	cmdline_fixed_string_t primary;
4958 	uint8_t slave_id;
4959 	uint8_t port_id;
4960 };
4961 
4962 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4963 		__attribute__((unused))  struct cmdline *cl,
4964 		__attribute__((unused)) void *data)
4965 {
4966 	struct cmd_set_bonding_primary_result *res = parsed_result;
4967 	portid_t master_port_id = res->port_id;
4968 	portid_t slave_port_id = res->slave_id;
4969 
4970 	/* Set the primary slave for a bonded device. */
4971 	if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4972 		printf("\t Failed to set primary slave for port = %d.\n",
4973 				master_port_id);
4974 		return;
4975 	}
4976 	init_port_config();
4977 }
4978 
4979 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4980 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4981 		set, "set");
4982 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4983 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4984 		bonding, "bonding");
4985 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4986 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4987 		primary, "primary");
4988 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4989 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4990 		slave_id, UINT8);
4991 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4992 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4993 		port_id, UINT8);
4994 
4995 cmdline_parse_inst_t cmd_set_bonding_primary = {
4996 		.f = cmd_set_bonding_primary_parsed,
4997 		.help_str = "set bonding primary <slave_id> <port_id>: "
4998 			"Set the primary slave for port_id",
4999 		.data = NULL,
5000 		.tokens = {
5001 				(void *)&cmd_setbonding_primary_set,
5002 				(void *)&cmd_setbonding_primary_bonding,
5003 				(void *)&cmd_setbonding_primary_primary,
5004 				(void *)&cmd_setbonding_primary_slave,
5005 				(void *)&cmd_setbonding_primary_port,
5006 				NULL
5007 		}
5008 };
5009 
5010 /* *** ADD SLAVE *** */
5011 struct cmd_add_bonding_slave_result {
5012 	cmdline_fixed_string_t add;
5013 	cmdline_fixed_string_t bonding;
5014 	cmdline_fixed_string_t slave;
5015 	uint8_t slave_id;
5016 	uint8_t port_id;
5017 };
5018 
5019 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5020 		__attribute__((unused))  struct cmdline *cl,
5021 		__attribute__((unused)) void *data)
5022 {
5023 	struct cmd_add_bonding_slave_result *res = parsed_result;
5024 	portid_t master_port_id = res->port_id;
5025 	portid_t slave_port_id = res->slave_id;
5026 
5027 	/* add the slave for a bonded device. */
5028 	if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5029 		printf("\t Failed to add slave %d to master port = %d.\n",
5030 				slave_port_id, master_port_id);
5031 		return;
5032 	}
5033 	init_port_config();
5034 	set_port_slave_flag(slave_port_id);
5035 }
5036 
5037 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5038 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5039 		add, "add");
5040 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5041 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5042 		bonding, "bonding");
5043 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5044 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5045 		slave, "slave");
5046 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5047 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5048 		slave_id, UINT8);
5049 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5050 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5051 		port_id, UINT8);
5052 
5053 cmdline_parse_inst_t cmd_add_bonding_slave = {
5054 		.f = cmd_add_bonding_slave_parsed,
5055 		.help_str = "add bonding slave <slave_id> <port_id>: "
5056 			"Add a slave device to a bonded device",
5057 		.data = NULL,
5058 		.tokens = {
5059 				(void *)&cmd_addbonding_slave_add,
5060 				(void *)&cmd_addbonding_slave_bonding,
5061 				(void *)&cmd_addbonding_slave_slave,
5062 				(void *)&cmd_addbonding_slave_slaveid,
5063 				(void *)&cmd_addbonding_slave_port,
5064 				NULL
5065 		}
5066 };
5067 
5068 /* *** REMOVE SLAVE *** */
5069 struct cmd_remove_bonding_slave_result {
5070 	cmdline_fixed_string_t remove;
5071 	cmdline_fixed_string_t bonding;
5072 	cmdline_fixed_string_t slave;
5073 	uint8_t slave_id;
5074 	uint8_t port_id;
5075 };
5076 
5077 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5078 		__attribute__((unused))  struct cmdline *cl,
5079 		__attribute__((unused)) void *data)
5080 {
5081 	struct cmd_remove_bonding_slave_result *res = parsed_result;
5082 	portid_t master_port_id = res->port_id;
5083 	portid_t slave_port_id = res->slave_id;
5084 
5085 	/* remove the slave from a bonded device. */
5086 	if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5087 		printf("\t Failed to remove slave %d from master port = %d.\n",
5088 				slave_port_id, master_port_id);
5089 		return;
5090 	}
5091 	init_port_config();
5092 	clear_port_slave_flag(slave_port_id);
5093 }
5094 
5095 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5096 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5097 				remove, "remove");
5098 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5099 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5100 				bonding, "bonding");
5101 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5102 		TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5103 				slave, "slave");
5104 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5105 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5106 				slave_id, UINT8);
5107 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5108 		TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5109 				port_id, UINT8);
5110 
5111 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5112 		.f = cmd_remove_bonding_slave_parsed,
5113 		.help_str = "remove bonding slave <slave_id> <port_id>: "
5114 			"Remove a slave device from a bonded device",
5115 		.data = NULL,
5116 		.tokens = {
5117 				(void *)&cmd_removebonding_slave_remove,
5118 				(void *)&cmd_removebonding_slave_bonding,
5119 				(void *)&cmd_removebonding_slave_slave,
5120 				(void *)&cmd_removebonding_slave_slaveid,
5121 				(void *)&cmd_removebonding_slave_port,
5122 				NULL
5123 		}
5124 };
5125 
5126 /* *** CREATE BONDED DEVICE *** */
5127 struct cmd_create_bonded_device_result {
5128 	cmdline_fixed_string_t create;
5129 	cmdline_fixed_string_t bonded;
5130 	cmdline_fixed_string_t device;
5131 	uint8_t mode;
5132 	uint8_t socket;
5133 };
5134 
5135 static int bond_dev_num = 0;
5136 
5137 static void cmd_create_bonded_device_parsed(void *parsed_result,
5138 		__attribute__((unused))  struct cmdline *cl,
5139 		__attribute__((unused)) void *data)
5140 {
5141 	struct cmd_create_bonded_device_result *res = parsed_result;
5142 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5143 	int port_id;
5144 
5145 	if (test_done == 0) {
5146 		printf("Please stop forwarding first\n");
5147 		return;
5148 	}
5149 
5150 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5151 			bond_dev_num++);
5152 
5153 	/* Create a new bonded device. */
5154 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5155 	if (port_id < 0) {
5156 		printf("\t Failed to create bonded device.\n");
5157 		return;
5158 	} else {
5159 		printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5160 				port_id);
5161 
5162 		/* Update number of ports */
5163 		nb_ports = rte_eth_dev_count();
5164 		reconfig(port_id, res->socket);
5165 		rte_eth_promiscuous_enable(port_id);
5166 	}
5167 
5168 }
5169 
5170 cmdline_parse_token_string_t cmd_createbonded_device_create =
5171 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5172 				create, "create");
5173 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5174 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5175 				bonded, "bonded");
5176 cmdline_parse_token_string_t cmd_createbonded_device_device =
5177 		TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5178 				device, "device");
5179 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5180 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5181 				mode, UINT8);
5182 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5183 		TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5184 				socket, UINT8);
5185 
5186 cmdline_parse_inst_t cmd_create_bonded_device = {
5187 		.f = cmd_create_bonded_device_parsed,
5188 		.help_str = "create bonded device <mode> <socket>: "
5189 			"Create a new bonded device with specific bonding mode and socket",
5190 		.data = NULL,
5191 		.tokens = {
5192 				(void *)&cmd_createbonded_device_create,
5193 				(void *)&cmd_createbonded_device_bonded,
5194 				(void *)&cmd_createbonded_device_device,
5195 				(void *)&cmd_createbonded_device_mode,
5196 				(void *)&cmd_createbonded_device_socket,
5197 				NULL
5198 		}
5199 };
5200 
5201 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5202 struct cmd_set_bond_mac_addr_result {
5203 	cmdline_fixed_string_t set;
5204 	cmdline_fixed_string_t bonding;
5205 	cmdline_fixed_string_t mac_addr;
5206 	uint8_t port_num;
5207 	struct ether_addr address;
5208 };
5209 
5210 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5211 		__attribute__((unused))  struct cmdline *cl,
5212 		__attribute__((unused)) void *data)
5213 {
5214 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
5215 	int ret;
5216 
5217 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5218 		return;
5219 
5220 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5221 
5222 	/* check the return value and print it if is < 0 */
5223 	if (ret < 0)
5224 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5225 }
5226 
5227 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5228 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5229 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5230 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5231 				"bonding");
5232 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5233 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5234 				"mac_addr");
5235 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5236 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
5237 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5238 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5239 
5240 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5241 		.f = cmd_set_bond_mac_addr_parsed,
5242 		.data = (void *) 0,
5243 		.help_str = "set bonding mac_addr <port_id> <mac_addr>",
5244 		.tokens = {
5245 				(void *)&cmd_set_bond_mac_addr_set,
5246 				(void *)&cmd_set_bond_mac_addr_bonding,
5247 				(void *)&cmd_set_bond_mac_addr_mac,
5248 				(void *)&cmd_set_bond_mac_addr_portnum,
5249 				(void *)&cmd_set_bond_mac_addr_addr,
5250 				NULL
5251 		}
5252 };
5253 
5254 
5255 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5256 struct cmd_set_bond_mon_period_result {
5257 	cmdline_fixed_string_t set;
5258 	cmdline_fixed_string_t bonding;
5259 	cmdline_fixed_string_t mon_period;
5260 	uint8_t port_num;
5261 	uint32_t period_ms;
5262 };
5263 
5264 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5265 		__attribute__((unused))  struct cmdline *cl,
5266 		__attribute__((unused)) void *data)
5267 {
5268 	struct cmd_set_bond_mon_period_result *res = parsed_result;
5269 	int ret;
5270 
5271 	if (res->port_num >= nb_ports) {
5272 		printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5273 		return;
5274 	}
5275 
5276 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5277 
5278 	/* check the return value and print it if is < 0 */
5279 	if (ret < 0)
5280 		printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5281 }
5282 
5283 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5284 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5285 				set, "set");
5286 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5287 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5288 				bonding, "bonding");
5289 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5290 		TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5291 				mon_period,	"mon_period");
5292 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5293 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5294 				port_num, UINT8);
5295 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5296 		TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5297 				period_ms, UINT32);
5298 
5299 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5300 		.f = cmd_set_bond_mon_period_parsed,
5301 		.data = (void *) 0,
5302 		.help_str = "set bonding mon_period <port_id> <period_ms>",
5303 		.tokens = {
5304 				(void *)&cmd_set_bond_mon_period_set,
5305 				(void *)&cmd_set_bond_mon_period_bonding,
5306 				(void *)&cmd_set_bond_mon_period_mon_period,
5307 				(void *)&cmd_set_bond_mon_period_portnum,
5308 				(void *)&cmd_set_bond_mon_period_period_ms,
5309 				NULL
5310 		}
5311 };
5312 
5313 
5314 
5315 struct cmd_set_bonding_agg_mode_policy_result {
5316 	cmdline_fixed_string_t set;
5317 	cmdline_fixed_string_t bonding;
5318 	cmdline_fixed_string_t agg_mode;
5319 	uint8_t port_num;
5320 	cmdline_fixed_string_t policy;
5321 };
5322 
5323 
5324 static void
5325 cmd_set_bonding_agg_mode(void *parsed_result,
5326 		__attribute__((unused)) struct cmdline *cl,
5327 		__attribute__((unused)) void *data)
5328 {
5329 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5330 	uint8_t policy = AGG_BANDWIDTH;
5331 
5332 	if (res->port_num >= nb_ports) {
5333 		printf("Port id %d must be less than %d\n",
5334 				res->port_num, nb_ports);
5335 		return;
5336 	}
5337 
5338 	if (!strcmp(res->policy, "bandwidth"))
5339 		policy = AGG_BANDWIDTH;
5340 	else if (!strcmp(res->policy, "stable"))
5341 		policy = AGG_STABLE;
5342 	else if (!strcmp(res->policy, "count"))
5343 		policy = AGG_COUNT;
5344 
5345 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5346 }
5347 
5348 
5349 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5350 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5351 				set, "set");
5352 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5353 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5354 				bonding, "bonding");
5355 
5356 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5357 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5358 				agg_mode, "agg_mode");
5359 
5360 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5361 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5362 				port_num, UINT8);
5363 
5364 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5365 	TOKEN_STRING_INITIALIZER(
5366 			struct cmd_set_bonding_balance_xmit_policy_result,
5367 		policy, "stable#bandwidth#count");
5368 
5369 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5370 	.f = cmd_set_bonding_agg_mode,
5371 	.data = (void *) 0,
5372 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5373 	.tokens = {
5374 			(void *)&cmd_set_bonding_agg_mode_set,
5375 			(void *)&cmd_set_bonding_agg_mode_bonding,
5376 			(void *)&cmd_set_bonding_agg_mode_agg_mode,
5377 			(void *)&cmd_set_bonding_agg_mode_portnum,
5378 			(void *)&cmd_set_bonding_agg_mode_policy_string,
5379 			NULL
5380 		}
5381 };
5382 
5383 
5384 #endif /* RTE_LIBRTE_PMD_BOND */
5385 
5386 /* *** SET FORWARDING MODE *** */
5387 struct cmd_set_fwd_mode_result {
5388 	cmdline_fixed_string_t set;
5389 	cmdline_fixed_string_t fwd;
5390 	cmdline_fixed_string_t mode;
5391 };
5392 
5393 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5394 				    __attribute__((unused)) struct cmdline *cl,
5395 				    __attribute__((unused)) void *data)
5396 {
5397 	struct cmd_set_fwd_mode_result *res = parsed_result;
5398 
5399 	retry_enabled = 0;
5400 	set_pkt_forwarding_mode(res->mode);
5401 }
5402 
5403 cmdline_parse_token_string_t cmd_setfwd_set =
5404 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5405 cmdline_parse_token_string_t cmd_setfwd_fwd =
5406 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5407 cmdline_parse_token_string_t cmd_setfwd_mode =
5408 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5409 		"" /* defined at init */);
5410 
5411 cmdline_parse_inst_t cmd_set_fwd_mode = {
5412 	.f = cmd_set_fwd_mode_parsed,
5413 	.data = NULL,
5414 	.help_str = NULL, /* defined at init */
5415 	.tokens = {
5416 		(void *)&cmd_setfwd_set,
5417 		(void *)&cmd_setfwd_fwd,
5418 		(void *)&cmd_setfwd_mode,
5419 		NULL,
5420 	},
5421 };
5422 
5423 static void cmd_set_fwd_mode_init(void)
5424 {
5425 	char *modes, *c;
5426 	static char token[128];
5427 	static char help[256];
5428 	cmdline_parse_token_string_t *token_struct;
5429 
5430 	modes = list_pkt_forwarding_modes();
5431 	snprintf(help, sizeof(help), "set fwd %s: "
5432 		"Set packet forwarding mode", modes);
5433 	cmd_set_fwd_mode.help_str = help;
5434 
5435 	/* string token separator is # */
5436 	for (c = token; *modes != '\0'; modes++)
5437 		if (*modes == '|')
5438 			*c++ = '#';
5439 		else
5440 			*c++ = *modes;
5441 	token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5442 	token_struct->string_data.str = token;
5443 }
5444 
5445 /* *** SET RETRY FORWARDING MODE *** */
5446 struct cmd_set_fwd_retry_mode_result {
5447 	cmdline_fixed_string_t set;
5448 	cmdline_fixed_string_t fwd;
5449 	cmdline_fixed_string_t mode;
5450 	cmdline_fixed_string_t retry;
5451 };
5452 
5453 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5454 			    __attribute__((unused)) struct cmdline *cl,
5455 			    __attribute__((unused)) void *data)
5456 {
5457 	struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5458 
5459 	retry_enabled = 1;
5460 	set_pkt_forwarding_mode(res->mode);
5461 }
5462 
5463 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5464 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5465 			set, "set");
5466 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5467 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5468 			fwd, "fwd");
5469 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5470 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5471 			mode,
5472 		"" /* defined at init */);
5473 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5474 	TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5475 			retry, "retry");
5476 
5477 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5478 	.f = cmd_set_fwd_retry_mode_parsed,
5479 	.data = NULL,
5480 	.help_str = NULL, /* defined at init */
5481 	.tokens = {
5482 		(void *)&cmd_setfwd_retry_set,
5483 		(void *)&cmd_setfwd_retry_fwd,
5484 		(void *)&cmd_setfwd_retry_mode,
5485 		(void *)&cmd_setfwd_retry_retry,
5486 		NULL,
5487 	},
5488 };
5489 
5490 static void cmd_set_fwd_retry_mode_init(void)
5491 {
5492 	char *modes, *c;
5493 	static char token[128];
5494 	static char help[256];
5495 	cmdline_parse_token_string_t *token_struct;
5496 
5497 	modes = list_pkt_forwarding_retry_modes();
5498 	snprintf(help, sizeof(help), "set fwd %s retry: "
5499 		"Set packet forwarding mode with retry", modes);
5500 	cmd_set_fwd_retry_mode.help_str = help;
5501 
5502 	/* string token separator is # */
5503 	for (c = token; *modes != '\0'; modes++)
5504 		if (*modes == '|')
5505 			*c++ = '#';
5506 		else
5507 			*c++ = *modes;
5508 	token_struct = (cmdline_parse_token_string_t *)
5509 		cmd_set_fwd_retry_mode.tokens[2];
5510 	token_struct->string_data.str = token;
5511 }
5512 
5513 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5514 struct cmd_set_burst_tx_retry_result {
5515 	cmdline_fixed_string_t set;
5516 	cmdline_fixed_string_t burst;
5517 	cmdline_fixed_string_t tx;
5518 	cmdline_fixed_string_t delay;
5519 	uint32_t time;
5520 	cmdline_fixed_string_t retry;
5521 	uint32_t retry_num;
5522 };
5523 
5524 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5525 					__attribute__((unused)) struct cmdline *cl,
5526 					__attribute__((unused)) void *data)
5527 {
5528 	struct cmd_set_burst_tx_retry_result *res = parsed_result;
5529 
5530 	if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5531 		&& !strcmp(res->tx, "tx")) {
5532 		if (!strcmp(res->delay, "delay"))
5533 			burst_tx_delay_time = res->time;
5534 		if (!strcmp(res->retry, "retry"))
5535 			burst_tx_retry_num = res->retry_num;
5536 	}
5537 
5538 }
5539 
5540 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5541 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5542 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5543 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5544 				 "burst");
5545 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5546 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5547 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5548 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5549 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5550 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5551 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5552 	TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5553 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5554 	TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5555 
5556 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5557 	.f = cmd_set_burst_tx_retry_parsed,
5558 	.help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5559 	.tokens = {
5560 		(void *)&cmd_set_burst_tx_retry_set,
5561 		(void *)&cmd_set_burst_tx_retry_burst,
5562 		(void *)&cmd_set_burst_tx_retry_tx,
5563 		(void *)&cmd_set_burst_tx_retry_delay,
5564 		(void *)&cmd_set_burst_tx_retry_time,
5565 		(void *)&cmd_set_burst_tx_retry_retry,
5566 		(void *)&cmd_set_burst_tx_retry_retry_num,
5567 		NULL,
5568 	},
5569 };
5570 
5571 /* *** SET PROMISC MODE *** */
5572 struct cmd_set_promisc_mode_result {
5573 	cmdline_fixed_string_t set;
5574 	cmdline_fixed_string_t promisc;
5575 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5576 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5577 	cmdline_fixed_string_t mode;
5578 };
5579 
5580 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5581 					__attribute__((unused)) struct cmdline *cl,
5582 					void *allports)
5583 {
5584 	struct cmd_set_promisc_mode_result *res = parsed_result;
5585 	int enable;
5586 	portid_t i;
5587 
5588 	if (!strcmp(res->mode, "on"))
5589 		enable = 1;
5590 	else
5591 		enable = 0;
5592 
5593 	/* all ports */
5594 	if (allports) {
5595 		RTE_ETH_FOREACH_DEV(i) {
5596 			if (enable)
5597 				rte_eth_promiscuous_enable(i);
5598 			else
5599 				rte_eth_promiscuous_disable(i);
5600 		}
5601 	}
5602 	else {
5603 		if (enable)
5604 			rte_eth_promiscuous_enable(res->port_num);
5605 		else
5606 			rte_eth_promiscuous_disable(res->port_num);
5607 	}
5608 }
5609 
5610 cmdline_parse_token_string_t cmd_setpromisc_set =
5611 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5612 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5613 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5614 				 "promisc");
5615 cmdline_parse_token_string_t cmd_setpromisc_portall =
5616 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5617 				 "all");
5618 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5619 	TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5620 			      UINT8);
5621 cmdline_parse_token_string_t cmd_setpromisc_mode =
5622 	TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5623 				 "on#off");
5624 
5625 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5626 	.f = cmd_set_promisc_mode_parsed,
5627 	.data = (void *)1,
5628 	.help_str = "set promisc all on|off: Set promisc mode for all ports",
5629 	.tokens = {
5630 		(void *)&cmd_setpromisc_set,
5631 		(void *)&cmd_setpromisc_promisc,
5632 		(void *)&cmd_setpromisc_portall,
5633 		(void *)&cmd_setpromisc_mode,
5634 		NULL,
5635 	},
5636 };
5637 
5638 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5639 	.f = cmd_set_promisc_mode_parsed,
5640 	.data = (void *)0,
5641 	.help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5642 	.tokens = {
5643 		(void *)&cmd_setpromisc_set,
5644 		(void *)&cmd_setpromisc_promisc,
5645 		(void *)&cmd_setpromisc_portnum,
5646 		(void *)&cmd_setpromisc_mode,
5647 		NULL,
5648 	},
5649 };
5650 
5651 /* *** SET ALLMULTI MODE *** */
5652 struct cmd_set_allmulti_mode_result {
5653 	cmdline_fixed_string_t set;
5654 	cmdline_fixed_string_t allmulti;
5655 	cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5656 	uint8_t port_num;                /* valid if "allports" argument == 0 */
5657 	cmdline_fixed_string_t mode;
5658 };
5659 
5660 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5661 					__attribute__((unused)) struct cmdline *cl,
5662 					void *allports)
5663 {
5664 	struct cmd_set_allmulti_mode_result *res = parsed_result;
5665 	int enable;
5666 	portid_t i;
5667 
5668 	if (!strcmp(res->mode, "on"))
5669 		enable = 1;
5670 	else
5671 		enable = 0;
5672 
5673 	/* all ports */
5674 	if (allports) {
5675 		RTE_ETH_FOREACH_DEV(i) {
5676 			if (enable)
5677 				rte_eth_allmulticast_enable(i);
5678 			else
5679 				rte_eth_allmulticast_disable(i);
5680 		}
5681 	}
5682 	else {
5683 		if (enable)
5684 			rte_eth_allmulticast_enable(res->port_num);
5685 		else
5686 			rte_eth_allmulticast_disable(res->port_num);
5687 	}
5688 }
5689 
5690 cmdline_parse_token_string_t cmd_setallmulti_set =
5691 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5692 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5693 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5694 				 "allmulti");
5695 cmdline_parse_token_string_t cmd_setallmulti_portall =
5696 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5697 				 "all");
5698 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5699 	TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5700 			      UINT8);
5701 cmdline_parse_token_string_t cmd_setallmulti_mode =
5702 	TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5703 				 "on#off");
5704 
5705 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5706 	.f = cmd_set_allmulti_mode_parsed,
5707 	.data = (void *)1,
5708 	.help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5709 	.tokens = {
5710 		(void *)&cmd_setallmulti_set,
5711 		(void *)&cmd_setallmulti_allmulti,
5712 		(void *)&cmd_setallmulti_portall,
5713 		(void *)&cmd_setallmulti_mode,
5714 		NULL,
5715 	},
5716 };
5717 
5718 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5719 	.f = cmd_set_allmulti_mode_parsed,
5720 	.data = (void *)0,
5721 	.help_str = "set allmulti <port_id> on|off: "
5722 		"Set allmulti mode on port_id",
5723 	.tokens = {
5724 		(void *)&cmd_setallmulti_set,
5725 		(void *)&cmd_setallmulti_allmulti,
5726 		(void *)&cmd_setallmulti_portnum,
5727 		(void *)&cmd_setallmulti_mode,
5728 		NULL,
5729 	},
5730 };
5731 
5732 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5733 struct cmd_link_flow_ctrl_set_result {
5734 	cmdline_fixed_string_t set;
5735 	cmdline_fixed_string_t flow_ctrl;
5736 	cmdline_fixed_string_t rx;
5737 	cmdline_fixed_string_t rx_lfc_mode;
5738 	cmdline_fixed_string_t tx;
5739 	cmdline_fixed_string_t tx_lfc_mode;
5740 	cmdline_fixed_string_t mac_ctrl_frame_fwd;
5741 	cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5742 	cmdline_fixed_string_t autoneg_str;
5743 	cmdline_fixed_string_t autoneg;
5744 	cmdline_fixed_string_t hw_str;
5745 	uint32_t high_water;
5746 	cmdline_fixed_string_t lw_str;
5747 	uint32_t low_water;
5748 	cmdline_fixed_string_t pt_str;
5749 	uint16_t pause_time;
5750 	cmdline_fixed_string_t xon_str;
5751 	uint16_t send_xon;
5752 	uint8_t  port_id;
5753 };
5754 
5755 cmdline_parse_token_string_t cmd_lfc_set_set =
5756 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5757 				set, "set");
5758 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5759 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5760 				flow_ctrl, "flow_ctrl");
5761 cmdline_parse_token_string_t cmd_lfc_set_rx =
5762 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5763 				rx, "rx");
5764 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5765 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5766 				rx_lfc_mode, "on#off");
5767 cmdline_parse_token_string_t cmd_lfc_set_tx =
5768 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5769 				tx, "tx");
5770 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5771 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5772 				tx_lfc_mode, "on#off");
5773 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5774 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5775 				hw_str, "high_water");
5776 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5777 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5778 				high_water, UINT32);
5779 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5780 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5781 				lw_str, "low_water");
5782 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5783 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5784 				low_water, UINT32);
5785 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5786 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5787 				pt_str, "pause_time");
5788 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5789 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5790 				pause_time, UINT16);
5791 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5792 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5793 				xon_str, "send_xon");
5794 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5795 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5796 				send_xon, UINT16);
5797 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5798 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5799 				mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5800 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5801 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5802 				mac_ctrl_frame_fwd_mode, "on#off");
5803 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5804 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5805 				autoneg_str, "autoneg");
5806 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5807 	TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5808 				autoneg, "on#off");
5809 cmdline_parse_token_num_t cmd_lfc_set_portid =
5810 	TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5811 				port_id, UINT8);
5812 
5813 /* forward declaration */
5814 static void
5815 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5816 			      void *data);
5817 
5818 cmdline_parse_inst_t cmd_link_flow_control_set = {
5819 	.f = cmd_link_flow_ctrl_set_parsed,
5820 	.data = NULL,
5821 	.help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5822 		"<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5823 		"autoneg on|off <port_id>: Configure the Ethernet flow control",
5824 	.tokens = {
5825 		(void *)&cmd_lfc_set_set,
5826 		(void *)&cmd_lfc_set_flow_ctrl,
5827 		(void *)&cmd_lfc_set_rx,
5828 		(void *)&cmd_lfc_set_rx_mode,
5829 		(void *)&cmd_lfc_set_tx,
5830 		(void *)&cmd_lfc_set_tx_mode,
5831 		(void *)&cmd_lfc_set_high_water,
5832 		(void *)&cmd_lfc_set_low_water,
5833 		(void *)&cmd_lfc_set_pause_time,
5834 		(void *)&cmd_lfc_set_send_xon,
5835 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5836 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5837 		(void *)&cmd_lfc_set_autoneg_str,
5838 		(void *)&cmd_lfc_set_autoneg,
5839 		(void *)&cmd_lfc_set_portid,
5840 		NULL,
5841 	},
5842 };
5843 
5844 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5845 	.f = cmd_link_flow_ctrl_set_parsed,
5846 	.data = (void *)&cmd_link_flow_control_set_rx,
5847 	.help_str = "set flow_ctrl rx on|off <port_id>: "
5848 		"Change rx flow control parameter",
5849 	.tokens = {
5850 		(void *)&cmd_lfc_set_set,
5851 		(void *)&cmd_lfc_set_flow_ctrl,
5852 		(void *)&cmd_lfc_set_rx,
5853 		(void *)&cmd_lfc_set_rx_mode,
5854 		(void *)&cmd_lfc_set_portid,
5855 		NULL,
5856 	},
5857 };
5858 
5859 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5860 	.f = cmd_link_flow_ctrl_set_parsed,
5861 	.data = (void *)&cmd_link_flow_control_set_tx,
5862 	.help_str = "set flow_ctrl tx on|off <port_id>: "
5863 		"Change tx flow control parameter",
5864 	.tokens = {
5865 		(void *)&cmd_lfc_set_set,
5866 		(void *)&cmd_lfc_set_flow_ctrl,
5867 		(void *)&cmd_lfc_set_tx,
5868 		(void *)&cmd_lfc_set_tx_mode,
5869 		(void *)&cmd_lfc_set_portid,
5870 		NULL,
5871 	},
5872 };
5873 
5874 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
5875 	.f = cmd_link_flow_ctrl_set_parsed,
5876 	.data = (void *)&cmd_link_flow_control_set_hw,
5877 	.help_str = "set flow_ctrl high_water <value> <port_id>: "
5878 		"Change high water flow control parameter",
5879 	.tokens = {
5880 		(void *)&cmd_lfc_set_set,
5881 		(void *)&cmd_lfc_set_flow_ctrl,
5882 		(void *)&cmd_lfc_set_high_water_str,
5883 		(void *)&cmd_lfc_set_high_water,
5884 		(void *)&cmd_lfc_set_portid,
5885 		NULL,
5886 	},
5887 };
5888 
5889 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
5890 	.f = cmd_link_flow_ctrl_set_parsed,
5891 	.data = (void *)&cmd_link_flow_control_set_lw,
5892 	.help_str = "set flow_ctrl low_water <value> <port_id>: "
5893 		"Change low water flow control parameter",
5894 	.tokens = {
5895 		(void *)&cmd_lfc_set_set,
5896 		(void *)&cmd_lfc_set_flow_ctrl,
5897 		(void *)&cmd_lfc_set_low_water_str,
5898 		(void *)&cmd_lfc_set_low_water,
5899 		(void *)&cmd_lfc_set_portid,
5900 		NULL,
5901 	},
5902 };
5903 
5904 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
5905 	.f = cmd_link_flow_ctrl_set_parsed,
5906 	.data = (void *)&cmd_link_flow_control_set_pt,
5907 	.help_str = "set flow_ctrl pause_time <value> <port_id>: "
5908 		"Change pause time flow control parameter",
5909 	.tokens = {
5910 		(void *)&cmd_lfc_set_set,
5911 		(void *)&cmd_lfc_set_flow_ctrl,
5912 		(void *)&cmd_lfc_set_pause_time_str,
5913 		(void *)&cmd_lfc_set_pause_time,
5914 		(void *)&cmd_lfc_set_portid,
5915 		NULL,
5916 	},
5917 };
5918 
5919 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
5920 	.f = cmd_link_flow_ctrl_set_parsed,
5921 	.data = (void *)&cmd_link_flow_control_set_xon,
5922 	.help_str = "set flow_ctrl send_xon <value> <port_id>: "
5923 		"Change send_xon flow control parameter",
5924 	.tokens = {
5925 		(void *)&cmd_lfc_set_set,
5926 		(void *)&cmd_lfc_set_flow_ctrl,
5927 		(void *)&cmd_lfc_set_send_xon_str,
5928 		(void *)&cmd_lfc_set_send_xon,
5929 		(void *)&cmd_lfc_set_portid,
5930 		NULL,
5931 	},
5932 };
5933 
5934 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
5935 	.f = cmd_link_flow_ctrl_set_parsed,
5936 	.data = (void *)&cmd_link_flow_control_set_macfwd,
5937 	.help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
5938 		"Change mac ctrl fwd flow control parameter",
5939 	.tokens = {
5940 		(void *)&cmd_lfc_set_set,
5941 		(void *)&cmd_lfc_set_flow_ctrl,
5942 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5943 		(void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5944 		(void *)&cmd_lfc_set_portid,
5945 		NULL,
5946 	},
5947 };
5948 
5949 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
5950 	.f = cmd_link_flow_ctrl_set_parsed,
5951 	.data = (void *)&cmd_link_flow_control_set_autoneg,
5952 	.help_str = "set flow_ctrl autoneg on|off <port_id>: "
5953 		"Change autoneg flow control parameter",
5954 	.tokens = {
5955 		(void *)&cmd_lfc_set_set,
5956 		(void *)&cmd_lfc_set_flow_ctrl,
5957 		(void *)&cmd_lfc_set_autoneg_str,
5958 		(void *)&cmd_lfc_set_autoneg,
5959 		(void *)&cmd_lfc_set_portid,
5960 		NULL,
5961 	},
5962 };
5963 
5964 static void
5965 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
5966 			      __attribute__((unused)) struct cmdline *cl,
5967 			      void *data)
5968 {
5969 	struct cmd_link_flow_ctrl_set_result *res = parsed_result;
5970 	cmdline_parse_inst_t *cmd = data;
5971 	struct rte_eth_fc_conf fc_conf;
5972 	int rx_fc_en = 0;
5973 	int tx_fc_en = 0;
5974 	int ret;
5975 
5976 	/*
5977 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5978 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5979 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5980 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5981 	 */
5982 	static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
5983 			{RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
5984 	};
5985 
5986 	/* Partial command line, retrieve current configuration */
5987 	if (cmd) {
5988 		ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
5989 		if (ret != 0) {
5990 			printf("cannot get current flow ctrl parameters, return"
5991 			       "code = %d\n", ret);
5992 			return;
5993 		}
5994 
5995 		if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
5996 		    (fc_conf.mode == RTE_FC_FULL))
5997 			rx_fc_en = 1;
5998 		if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
5999 		    (fc_conf.mode == RTE_FC_FULL))
6000 			tx_fc_en = 1;
6001 	}
6002 
6003 	if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6004 		rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6005 
6006 	if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6007 		tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6008 
6009 	fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6010 
6011 	if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6012 		fc_conf.high_water = res->high_water;
6013 
6014 	if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6015 		fc_conf.low_water = res->low_water;
6016 
6017 	if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6018 		fc_conf.pause_time = res->pause_time;
6019 
6020 	if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6021 		fc_conf.send_xon = res->send_xon;
6022 
6023 	if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6024 		if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6025 			fc_conf.mac_ctrl_frame_fwd = 1;
6026 		else
6027 			fc_conf.mac_ctrl_frame_fwd = 0;
6028 	}
6029 
6030 	if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6031 		fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6032 
6033 	ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6034 	if (ret != 0)
6035 		printf("bad flow contrl parameter, return code = %d \n", ret);
6036 }
6037 
6038 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6039 struct cmd_priority_flow_ctrl_set_result {
6040 	cmdline_fixed_string_t set;
6041 	cmdline_fixed_string_t pfc_ctrl;
6042 	cmdline_fixed_string_t rx;
6043 	cmdline_fixed_string_t rx_pfc_mode;
6044 	cmdline_fixed_string_t tx;
6045 	cmdline_fixed_string_t tx_pfc_mode;
6046 	uint32_t high_water;
6047 	uint32_t low_water;
6048 	uint16_t pause_time;
6049 	uint8_t  priority;
6050 	uint8_t  port_id;
6051 };
6052 
6053 static void
6054 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6055 		       __attribute__((unused)) struct cmdline *cl,
6056 		       __attribute__((unused)) void *data)
6057 {
6058 	struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6059 	struct rte_eth_pfc_conf pfc_conf;
6060 	int rx_fc_enable, tx_fc_enable;
6061 	int ret;
6062 
6063 	/*
6064 	 * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6065 	 * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6066 	 * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6067 	 * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6068 	 */
6069 	static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6070 			{RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6071 	};
6072 
6073 	rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6074 	tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6075 	pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6076 	pfc_conf.fc.high_water = res->high_water;
6077 	pfc_conf.fc.low_water  = res->low_water;
6078 	pfc_conf.fc.pause_time = res->pause_time;
6079 	pfc_conf.priority      = res->priority;
6080 
6081 	ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6082 	if (ret != 0)
6083 		printf("bad priority flow contrl parameter, return code = %d \n", ret);
6084 }
6085 
6086 cmdline_parse_token_string_t cmd_pfc_set_set =
6087 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6088 				set, "set");
6089 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6090 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6091 				pfc_ctrl, "pfc_ctrl");
6092 cmdline_parse_token_string_t cmd_pfc_set_rx =
6093 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6094 				rx, "rx");
6095 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6096 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6097 				rx_pfc_mode, "on#off");
6098 cmdline_parse_token_string_t cmd_pfc_set_tx =
6099 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6100 				tx, "tx");
6101 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6102 	TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6103 				tx_pfc_mode, "on#off");
6104 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6105 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6106 				high_water, UINT32);
6107 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6108 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6109 				low_water, UINT32);
6110 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6111 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6112 				pause_time, UINT16);
6113 cmdline_parse_token_num_t cmd_pfc_set_priority =
6114 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6115 				priority, UINT8);
6116 cmdline_parse_token_num_t cmd_pfc_set_portid =
6117 	TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6118 				port_id, UINT8);
6119 
6120 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6121 	.f = cmd_priority_flow_ctrl_set_parsed,
6122 	.data = NULL,
6123 	.help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6124 		"<pause_time> <priority> <port_id>: "
6125 		"Configure the Ethernet priority flow control",
6126 	.tokens = {
6127 		(void *)&cmd_pfc_set_set,
6128 		(void *)&cmd_pfc_set_flow_ctrl,
6129 		(void *)&cmd_pfc_set_rx,
6130 		(void *)&cmd_pfc_set_rx_mode,
6131 		(void *)&cmd_pfc_set_tx,
6132 		(void *)&cmd_pfc_set_tx_mode,
6133 		(void *)&cmd_pfc_set_high_water,
6134 		(void *)&cmd_pfc_set_low_water,
6135 		(void *)&cmd_pfc_set_pause_time,
6136 		(void *)&cmd_pfc_set_priority,
6137 		(void *)&cmd_pfc_set_portid,
6138 		NULL,
6139 	},
6140 };
6141 
6142 /* *** RESET CONFIGURATION *** */
6143 struct cmd_reset_result {
6144 	cmdline_fixed_string_t reset;
6145 	cmdline_fixed_string_t def;
6146 };
6147 
6148 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6149 			     struct cmdline *cl,
6150 			     __attribute__((unused)) void *data)
6151 {
6152 	cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6153 	set_def_fwd_config();
6154 }
6155 
6156 cmdline_parse_token_string_t cmd_reset_set =
6157 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6158 cmdline_parse_token_string_t cmd_reset_def =
6159 	TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6160 				 "default");
6161 
6162 cmdline_parse_inst_t cmd_reset = {
6163 	.f = cmd_reset_parsed,
6164 	.data = NULL,
6165 	.help_str = "set default: Reset default forwarding configuration",
6166 	.tokens = {
6167 		(void *)&cmd_reset_set,
6168 		(void *)&cmd_reset_def,
6169 		NULL,
6170 	},
6171 };
6172 
6173 /* *** START FORWARDING *** */
6174 struct cmd_start_result {
6175 	cmdline_fixed_string_t start;
6176 };
6177 
6178 cmdline_parse_token_string_t cmd_start_start =
6179 	TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6180 
6181 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6182 			     __attribute__((unused)) struct cmdline *cl,
6183 			     __attribute__((unused)) void *data)
6184 {
6185 	start_packet_forwarding(0);
6186 }
6187 
6188 cmdline_parse_inst_t cmd_start = {
6189 	.f = cmd_start_parsed,
6190 	.data = NULL,
6191 	.help_str = "start: Start packet forwarding",
6192 	.tokens = {
6193 		(void *)&cmd_start_start,
6194 		NULL,
6195 	},
6196 };
6197 
6198 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6199 struct cmd_start_tx_first_result {
6200 	cmdline_fixed_string_t start;
6201 	cmdline_fixed_string_t tx_first;
6202 };
6203 
6204 static void
6205 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6206 			  __attribute__((unused)) struct cmdline *cl,
6207 			  __attribute__((unused)) void *data)
6208 {
6209 	start_packet_forwarding(1);
6210 }
6211 
6212 cmdline_parse_token_string_t cmd_start_tx_first_start =
6213 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6214 				 "start");
6215 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6216 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6217 				 tx_first, "tx_first");
6218 
6219 cmdline_parse_inst_t cmd_start_tx_first = {
6220 	.f = cmd_start_tx_first_parsed,
6221 	.data = NULL,
6222 	.help_str = "start tx_first: Start packet forwarding, "
6223 		"after sending 1 burst of packets",
6224 	.tokens = {
6225 		(void *)&cmd_start_tx_first_start,
6226 		(void *)&cmd_start_tx_first_tx_first,
6227 		NULL,
6228 	},
6229 };
6230 
6231 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6232 struct cmd_start_tx_first_n_result {
6233 	cmdline_fixed_string_t start;
6234 	cmdline_fixed_string_t tx_first;
6235 	uint32_t tx_num;
6236 };
6237 
6238 static void
6239 cmd_start_tx_first_n_parsed(void *parsed_result,
6240 			  __attribute__((unused)) struct cmdline *cl,
6241 			  __attribute__((unused)) void *data)
6242 {
6243 	struct cmd_start_tx_first_n_result *res = parsed_result;
6244 
6245 	start_packet_forwarding(res->tx_num);
6246 }
6247 
6248 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6249 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6250 			start, "start");
6251 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6252 	TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6253 			tx_first, "tx_first");
6254 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6255 	TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6256 			tx_num, UINT32);
6257 
6258 cmdline_parse_inst_t cmd_start_tx_first_n = {
6259 	.f = cmd_start_tx_first_n_parsed,
6260 	.data = NULL,
6261 	.help_str = "start tx_first <num>: "
6262 		"packet forwarding, after sending <num> bursts of packets",
6263 	.tokens = {
6264 		(void *)&cmd_start_tx_first_n_start,
6265 		(void *)&cmd_start_tx_first_n_tx_first,
6266 		(void *)&cmd_start_tx_first_n_tx_num,
6267 		NULL,
6268 	},
6269 };
6270 
6271 /* *** SET LINK UP *** */
6272 struct cmd_set_link_up_result {
6273 	cmdline_fixed_string_t set;
6274 	cmdline_fixed_string_t link_up;
6275 	cmdline_fixed_string_t port;
6276 	uint8_t port_id;
6277 };
6278 
6279 cmdline_parse_token_string_t cmd_set_link_up_set =
6280 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6281 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6282 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6283 				"link-up");
6284 cmdline_parse_token_string_t cmd_set_link_up_port =
6285 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6286 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6287 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
6288 
6289 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6290 			     __attribute__((unused)) struct cmdline *cl,
6291 			     __attribute__((unused)) void *data)
6292 {
6293 	struct cmd_set_link_up_result *res = parsed_result;
6294 	dev_set_link_up(res->port_id);
6295 }
6296 
6297 cmdline_parse_inst_t cmd_set_link_up = {
6298 	.f = cmd_set_link_up_parsed,
6299 	.data = NULL,
6300 	.help_str = "set link-up port <port id>",
6301 	.tokens = {
6302 		(void *)&cmd_set_link_up_set,
6303 		(void *)&cmd_set_link_up_link_up,
6304 		(void *)&cmd_set_link_up_port,
6305 		(void *)&cmd_set_link_up_port_id,
6306 		NULL,
6307 	},
6308 };
6309 
6310 /* *** SET LINK DOWN *** */
6311 struct cmd_set_link_down_result {
6312 	cmdline_fixed_string_t set;
6313 	cmdline_fixed_string_t link_down;
6314 	cmdline_fixed_string_t port;
6315 	uint8_t port_id;
6316 };
6317 
6318 cmdline_parse_token_string_t cmd_set_link_down_set =
6319 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6320 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6321 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6322 				"link-down");
6323 cmdline_parse_token_string_t cmd_set_link_down_port =
6324 	TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6325 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6326 	TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
6327 
6328 static void cmd_set_link_down_parsed(
6329 				__attribute__((unused)) void *parsed_result,
6330 				__attribute__((unused)) struct cmdline *cl,
6331 				__attribute__((unused)) void *data)
6332 {
6333 	struct cmd_set_link_down_result *res = parsed_result;
6334 	dev_set_link_down(res->port_id);
6335 }
6336 
6337 cmdline_parse_inst_t cmd_set_link_down = {
6338 	.f = cmd_set_link_down_parsed,
6339 	.data = NULL,
6340 	.help_str = "set link-down port <port id>",
6341 	.tokens = {
6342 		(void *)&cmd_set_link_down_set,
6343 		(void *)&cmd_set_link_down_link_down,
6344 		(void *)&cmd_set_link_down_port,
6345 		(void *)&cmd_set_link_down_port_id,
6346 		NULL,
6347 	},
6348 };
6349 
6350 /* *** SHOW CFG *** */
6351 struct cmd_showcfg_result {
6352 	cmdline_fixed_string_t show;
6353 	cmdline_fixed_string_t cfg;
6354 	cmdline_fixed_string_t what;
6355 };
6356 
6357 static void cmd_showcfg_parsed(void *parsed_result,
6358 			       __attribute__((unused)) struct cmdline *cl,
6359 			       __attribute__((unused)) void *data)
6360 {
6361 	struct cmd_showcfg_result *res = parsed_result;
6362 	if (!strcmp(res->what, "rxtx"))
6363 		rxtx_config_display();
6364 	else if (!strcmp(res->what, "cores"))
6365 		fwd_lcores_config_display();
6366 	else if (!strcmp(res->what, "fwd"))
6367 		pkt_fwd_config_display(&cur_fwd_config);
6368 	else if (!strcmp(res->what, "txpkts"))
6369 		show_tx_pkt_segments();
6370 }
6371 
6372 cmdline_parse_token_string_t cmd_showcfg_show =
6373 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6374 cmdline_parse_token_string_t cmd_showcfg_port =
6375 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6376 cmdline_parse_token_string_t cmd_showcfg_what =
6377 	TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6378 				 "rxtx#cores#fwd#txpkts");
6379 
6380 cmdline_parse_inst_t cmd_showcfg = {
6381 	.f = cmd_showcfg_parsed,
6382 	.data = NULL,
6383 	.help_str = "show config rxtx|cores|fwd|txpkts",
6384 	.tokens = {
6385 		(void *)&cmd_showcfg_show,
6386 		(void *)&cmd_showcfg_port,
6387 		(void *)&cmd_showcfg_what,
6388 		NULL,
6389 	},
6390 };
6391 
6392 /* *** SHOW ALL PORT INFO *** */
6393 struct cmd_showportall_result {
6394 	cmdline_fixed_string_t show;
6395 	cmdline_fixed_string_t port;
6396 	cmdline_fixed_string_t what;
6397 	cmdline_fixed_string_t all;
6398 };
6399 
6400 static void cmd_showportall_parsed(void *parsed_result,
6401 				__attribute__((unused)) struct cmdline *cl,
6402 				__attribute__((unused)) void *data)
6403 {
6404 	portid_t i;
6405 
6406 	struct cmd_showportall_result *res = parsed_result;
6407 	if (!strcmp(res->show, "clear")) {
6408 		if (!strcmp(res->what, "stats"))
6409 			RTE_ETH_FOREACH_DEV(i)
6410 				nic_stats_clear(i);
6411 		else if (!strcmp(res->what, "xstats"))
6412 			RTE_ETH_FOREACH_DEV(i)
6413 				nic_xstats_clear(i);
6414 	} else if (!strcmp(res->what, "info"))
6415 		RTE_ETH_FOREACH_DEV(i)
6416 			port_infos_display(i);
6417 	else if (!strcmp(res->what, "stats"))
6418 		RTE_ETH_FOREACH_DEV(i)
6419 			nic_stats_display(i);
6420 	else if (!strcmp(res->what, "xstats"))
6421 		RTE_ETH_FOREACH_DEV(i)
6422 			nic_xstats_display(i);
6423 	else if (!strcmp(res->what, "fdir"))
6424 		RTE_ETH_FOREACH_DEV(i)
6425 			fdir_get_infos(i);
6426 	else if (!strcmp(res->what, "stat_qmap"))
6427 		RTE_ETH_FOREACH_DEV(i)
6428 			nic_stats_mapping_display(i);
6429 	else if (!strcmp(res->what, "dcb_tc"))
6430 		RTE_ETH_FOREACH_DEV(i)
6431 			port_dcb_info_display(i);
6432 	else if (!strcmp(res->what, "cap"))
6433 		RTE_ETH_FOREACH_DEV(i)
6434 			port_offload_cap_display(i);
6435 }
6436 
6437 cmdline_parse_token_string_t cmd_showportall_show =
6438 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6439 				 "show#clear");
6440 cmdline_parse_token_string_t cmd_showportall_port =
6441 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6442 cmdline_parse_token_string_t cmd_showportall_what =
6443 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6444 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6445 cmdline_parse_token_string_t cmd_showportall_all =
6446 	TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6447 cmdline_parse_inst_t cmd_showportall = {
6448 	.f = cmd_showportall_parsed,
6449 	.data = NULL,
6450 	.help_str = "show|clear port "
6451 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6452 	.tokens = {
6453 		(void *)&cmd_showportall_show,
6454 		(void *)&cmd_showportall_port,
6455 		(void *)&cmd_showportall_what,
6456 		(void *)&cmd_showportall_all,
6457 		NULL,
6458 	},
6459 };
6460 
6461 /* *** SHOW PORT INFO *** */
6462 struct cmd_showport_result {
6463 	cmdline_fixed_string_t show;
6464 	cmdline_fixed_string_t port;
6465 	cmdline_fixed_string_t what;
6466 	uint8_t portnum;
6467 };
6468 
6469 static void cmd_showport_parsed(void *parsed_result,
6470 				__attribute__((unused)) struct cmdline *cl,
6471 				__attribute__((unused)) void *data)
6472 {
6473 	struct cmd_showport_result *res = parsed_result;
6474 	if (!strcmp(res->show, "clear")) {
6475 		if (!strcmp(res->what, "stats"))
6476 			nic_stats_clear(res->portnum);
6477 		else if (!strcmp(res->what, "xstats"))
6478 			nic_xstats_clear(res->portnum);
6479 	} else if (!strcmp(res->what, "info"))
6480 		port_infos_display(res->portnum);
6481 	else if (!strcmp(res->what, "stats"))
6482 		nic_stats_display(res->portnum);
6483 	else if (!strcmp(res->what, "xstats"))
6484 		nic_xstats_display(res->portnum);
6485 	else if (!strcmp(res->what, "fdir"))
6486 		 fdir_get_infos(res->portnum);
6487 	else if (!strcmp(res->what, "stat_qmap"))
6488 		nic_stats_mapping_display(res->portnum);
6489 	else if (!strcmp(res->what, "dcb_tc"))
6490 		port_dcb_info_display(res->portnum);
6491 	else if (!strcmp(res->what, "cap"))
6492 		port_offload_cap_display(res->portnum);
6493 }
6494 
6495 cmdline_parse_token_string_t cmd_showport_show =
6496 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6497 				 "show#clear");
6498 cmdline_parse_token_string_t cmd_showport_port =
6499 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6500 cmdline_parse_token_string_t cmd_showport_what =
6501 	TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6502 				 "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6503 cmdline_parse_token_num_t cmd_showport_portnum =
6504 	TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
6505 
6506 cmdline_parse_inst_t cmd_showport = {
6507 	.f = cmd_showport_parsed,
6508 	.data = NULL,
6509 	.help_str = "show|clear port "
6510 		"info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6511 		"<port_id>",
6512 	.tokens = {
6513 		(void *)&cmd_showport_show,
6514 		(void *)&cmd_showport_port,
6515 		(void *)&cmd_showport_what,
6516 		(void *)&cmd_showport_portnum,
6517 		NULL,
6518 	},
6519 };
6520 
6521 /* *** SHOW QUEUE INFO *** */
6522 struct cmd_showqueue_result {
6523 	cmdline_fixed_string_t show;
6524 	cmdline_fixed_string_t type;
6525 	cmdline_fixed_string_t what;
6526 	uint8_t portnum;
6527 	uint16_t queuenum;
6528 };
6529 
6530 static void
6531 cmd_showqueue_parsed(void *parsed_result,
6532 	__attribute__((unused)) struct cmdline *cl,
6533 	__attribute__((unused)) void *data)
6534 {
6535 	struct cmd_showqueue_result *res = parsed_result;
6536 
6537 	if (!strcmp(res->type, "rxq"))
6538 		rx_queue_infos_display(res->portnum, res->queuenum);
6539 	else if (!strcmp(res->type, "txq"))
6540 		tx_queue_infos_display(res->portnum, res->queuenum);
6541 }
6542 
6543 cmdline_parse_token_string_t cmd_showqueue_show =
6544 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6545 cmdline_parse_token_string_t cmd_showqueue_type =
6546 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6547 cmdline_parse_token_string_t cmd_showqueue_what =
6548 	TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6549 cmdline_parse_token_num_t cmd_showqueue_portnum =
6550 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
6551 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6552 	TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6553 
6554 cmdline_parse_inst_t cmd_showqueue = {
6555 	.f = cmd_showqueue_parsed,
6556 	.data = NULL,
6557 	.help_str = "show rxq|txq info <port_id> <queue_id>",
6558 	.tokens = {
6559 		(void *)&cmd_showqueue_show,
6560 		(void *)&cmd_showqueue_type,
6561 		(void *)&cmd_showqueue_what,
6562 		(void *)&cmd_showqueue_portnum,
6563 		(void *)&cmd_showqueue_queuenum,
6564 		NULL,
6565 	},
6566 };
6567 
6568 /* *** READ PORT REGISTER *** */
6569 struct cmd_read_reg_result {
6570 	cmdline_fixed_string_t read;
6571 	cmdline_fixed_string_t reg;
6572 	uint8_t port_id;
6573 	uint32_t reg_off;
6574 };
6575 
6576 static void
6577 cmd_read_reg_parsed(void *parsed_result,
6578 		    __attribute__((unused)) struct cmdline *cl,
6579 		    __attribute__((unused)) void *data)
6580 {
6581 	struct cmd_read_reg_result *res = parsed_result;
6582 	port_reg_display(res->port_id, res->reg_off);
6583 }
6584 
6585 cmdline_parse_token_string_t cmd_read_reg_read =
6586 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6587 cmdline_parse_token_string_t cmd_read_reg_reg =
6588 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6589 cmdline_parse_token_num_t cmd_read_reg_port_id =
6590 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
6591 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6592 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6593 
6594 cmdline_parse_inst_t cmd_read_reg = {
6595 	.f = cmd_read_reg_parsed,
6596 	.data = NULL,
6597 	.help_str = "read reg <port_id> <reg_off>",
6598 	.tokens = {
6599 		(void *)&cmd_read_reg_read,
6600 		(void *)&cmd_read_reg_reg,
6601 		(void *)&cmd_read_reg_port_id,
6602 		(void *)&cmd_read_reg_reg_off,
6603 		NULL,
6604 	},
6605 };
6606 
6607 /* *** READ PORT REGISTER BIT FIELD *** */
6608 struct cmd_read_reg_bit_field_result {
6609 	cmdline_fixed_string_t read;
6610 	cmdline_fixed_string_t regfield;
6611 	uint8_t port_id;
6612 	uint32_t reg_off;
6613 	uint8_t bit1_pos;
6614 	uint8_t bit2_pos;
6615 };
6616 
6617 static void
6618 cmd_read_reg_bit_field_parsed(void *parsed_result,
6619 			      __attribute__((unused)) struct cmdline *cl,
6620 			      __attribute__((unused)) void *data)
6621 {
6622 	struct cmd_read_reg_bit_field_result *res = parsed_result;
6623 	port_reg_bit_field_display(res->port_id, res->reg_off,
6624 				   res->bit1_pos, res->bit2_pos);
6625 }
6626 
6627 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6628 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6629 				 "read");
6630 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6631 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6632 				 regfield, "regfield");
6633 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6634 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6635 			      UINT8);
6636 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6637 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6638 			      UINT32);
6639 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6640 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6641 			      UINT8);
6642 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6643 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6644 			      UINT8);
6645 
6646 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6647 	.f = cmd_read_reg_bit_field_parsed,
6648 	.data = NULL,
6649 	.help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6650 	"Read register bit field between bit_x and bit_y included",
6651 	.tokens = {
6652 		(void *)&cmd_read_reg_bit_field_read,
6653 		(void *)&cmd_read_reg_bit_field_regfield,
6654 		(void *)&cmd_read_reg_bit_field_port_id,
6655 		(void *)&cmd_read_reg_bit_field_reg_off,
6656 		(void *)&cmd_read_reg_bit_field_bit1_pos,
6657 		(void *)&cmd_read_reg_bit_field_bit2_pos,
6658 		NULL,
6659 	},
6660 };
6661 
6662 /* *** READ PORT REGISTER BIT *** */
6663 struct cmd_read_reg_bit_result {
6664 	cmdline_fixed_string_t read;
6665 	cmdline_fixed_string_t regbit;
6666 	uint8_t port_id;
6667 	uint32_t reg_off;
6668 	uint8_t bit_pos;
6669 };
6670 
6671 static void
6672 cmd_read_reg_bit_parsed(void *parsed_result,
6673 			__attribute__((unused)) struct cmdline *cl,
6674 			__attribute__((unused)) void *data)
6675 {
6676 	struct cmd_read_reg_bit_result *res = parsed_result;
6677 	port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6678 }
6679 
6680 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6681 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6682 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6683 	TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6684 				 regbit, "regbit");
6685 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6686 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
6687 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6688 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6689 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6690 	TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6691 
6692 cmdline_parse_inst_t cmd_read_reg_bit = {
6693 	.f = cmd_read_reg_bit_parsed,
6694 	.data = NULL,
6695 	.help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6696 	.tokens = {
6697 		(void *)&cmd_read_reg_bit_read,
6698 		(void *)&cmd_read_reg_bit_regbit,
6699 		(void *)&cmd_read_reg_bit_port_id,
6700 		(void *)&cmd_read_reg_bit_reg_off,
6701 		(void *)&cmd_read_reg_bit_bit_pos,
6702 		NULL,
6703 	},
6704 };
6705 
6706 /* *** WRITE PORT REGISTER *** */
6707 struct cmd_write_reg_result {
6708 	cmdline_fixed_string_t write;
6709 	cmdline_fixed_string_t reg;
6710 	uint8_t port_id;
6711 	uint32_t reg_off;
6712 	uint32_t value;
6713 };
6714 
6715 static void
6716 cmd_write_reg_parsed(void *parsed_result,
6717 		     __attribute__((unused)) struct cmdline *cl,
6718 		     __attribute__((unused)) void *data)
6719 {
6720 	struct cmd_write_reg_result *res = parsed_result;
6721 	port_reg_set(res->port_id, res->reg_off, res->value);
6722 }
6723 
6724 cmdline_parse_token_string_t cmd_write_reg_write =
6725 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6726 cmdline_parse_token_string_t cmd_write_reg_reg =
6727 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6728 cmdline_parse_token_num_t cmd_write_reg_port_id =
6729 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
6730 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6731 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6732 cmdline_parse_token_num_t cmd_write_reg_value =
6733 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6734 
6735 cmdline_parse_inst_t cmd_write_reg = {
6736 	.f = cmd_write_reg_parsed,
6737 	.data = NULL,
6738 	.help_str = "write reg <port_id> <reg_off> <reg_value>",
6739 	.tokens = {
6740 		(void *)&cmd_write_reg_write,
6741 		(void *)&cmd_write_reg_reg,
6742 		(void *)&cmd_write_reg_port_id,
6743 		(void *)&cmd_write_reg_reg_off,
6744 		(void *)&cmd_write_reg_value,
6745 		NULL,
6746 	},
6747 };
6748 
6749 /* *** WRITE PORT REGISTER BIT FIELD *** */
6750 struct cmd_write_reg_bit_field_result {
6751 	cmdline_fixed_string_t write;
6752 	cmdline_fixed_string_t regfield;
6753 	uint8_t port_id;
6754 	uint32_t reg_off;
6755 	uint8_t bit1_pos;
6756 	uint8_t bit2_pos;
6757 	uint32_t value;
6758 };
6759 
6760 static void
6761 cmd_write_reg_bit_field_parsed(void *parsed_result,
6762 			       __attribute__((unused)) struct cmdline *cl,
6763 			       __attribute__((unused)) void *data)
6764 {
6765 	struct cmd_write_reg_bit_field_result *res = parsed_result;
6766 	port_reg_bit_field_set(res->port_id, res->reg_off,
6767 			  res->bit1_pos, res->bit2_pos, res->value);
6768 }
6769 
6770 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6771 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6772 				 "write");
6773 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6774 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6775 				 regfield, "regfield");
6776 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6777 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6778 			      UINT8);
6779 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6780 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6781 			      UINT32);
6782 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6783 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6784 			      UINT8);
6785 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6786 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6787 			      UINT8);
6788 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6789 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6790 			      UINT32);
6791 
6792 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6793 	.f = cmd_write_reg_bit_field_parsed,
6794 	.data = NULL,
6795 	.help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6796 		"<reg_value>: "
6797 		"Set register bit field between bit_x and bit_y included",
6798 	.tokens = {
6799 		(void *)&cmd_write_reg_bit_field_write,
6800 		(void *)&cmd_write_reg_bit_field_regfield,
6801 		(void *)&cmd_write_reg_bit_field_port_id,
6802 		(void *)&cmd_write_reg_bit_field_reg_off,
6803 		(void *)&cmd_write_reg_bit_field_bit1_pos,
6804 		(void *)&cmd_write_reg_bit_field_bit2_pos,
6805 		(void *)&cmd_write_reg_bit_field_value,
6806 		NULL,
6807 	},
6808 };
6809 
6810 /* *** WRITE PORT REGISTER BIT *** */
6811 struct cmd_write_reg_bit_result {
6812 	cmdline_fixed_string_t write;
6813 	cmdline_fixed_string_t regbit;
6814 	uint8_t port_id;
6815 	uint32_t reg_off;
6816 	uint8_t bit_pos;
6817 	uint8_t value;
6818 };
6819 
6820 static void
6821 cmd_write_reg_bit_parsed(void *parsed_result,
6822 			 __attribute__((unused)) struct cmdline *cl,
6823 			 __attribute__((unused)) void *data)
6824 {
6825 	struct cmd_write_reg_bit_result *res = parsed_result;
6826 	port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6827 }
6828 
6829 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6830 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6831 				 "write");
6832 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6833 	TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6834 				 regbit, "regbit");
6835 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6836 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
6837 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6838 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6839 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6840 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6841 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6842 	TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6843 
6844 cmdline_parse_inst_t cmd_write_reg_bit = {
6845 	.f = cmd_write_reg_bit_parsed,
6846 	.data = NULL,
6847 	.help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6848 		"0 <= bit_x <= 31",
6849 	.tokens = {
6850 		(void *)&cmd_write_reg_bit_write,
6851 		(void *)&cmd_write_reg_bit_regbit,
6852 		(void *)&cmd_write_reg_bit_port_id,
6853 		(void *)&cmd_write_reg_bit_reg_off,
6854 		(void *)&cmd_write_reg_bit_bit_pos,
6855 		(void *)&cmd_write_reg_bit_value,
6856 		NULL,
6857 	},
6858 };
6859 
6860 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6861 struct cmd_read_rxd_txd_result {
6862 	cmdline_fixed_string_t read;
6863 	cmdline_fixed_string_t rxd_txd;
6864 	uint8_t port_id;
6865 	uint16_t queue_id;
6866 	uint16_t desc_id;
6867 };
6868 
6869 static void
6870 cmd_read_rxd_txd_parsed(void *parsed_result,
6871 			__attribute__((unused)) struct cmdline *cl,
6872 			__attribute__((unused)) void *data)
6873 {
6874 	struct cmd_read_rxd_txd_result *res = parsed_result;
6875 
6876 	if (!strcmp(res->rxd_txd, "rxd"))
6877 		rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6878 	else if (!strcmp(res->rxd_txd, "txd"))
6879 		tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
6880 }
6881 
6882 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
6883 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
6884 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
6885 	TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
6886 				 "rxd#txd");
6887 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
6888 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
6889 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
6890 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
6891 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
6892 	TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
6893 
6894 cmdline_parse_inst_t cmd_read_rxd_txd = {
6895 	.f = cmd_read_rxd_txd_parsed,
6896 	.data = NULL,
6897 	.help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
6898 	.tokens = {
6899 		(void *)&cmd_read_rxd_txd_read,
6900 		(void *)&cmd_read_rxd_txd_rxd_txd,
6901 		(void *)&cmd_read_rxd_txd_port_id,
6902 		(void *)&cmd_read_rxd_txd_queue_id,
6903 		(void *)&cmd_read_rxd_txd_desc_id,
6904 		NULL,
6905 	},
6906 };
6907 
6908 /* *** QUIT *** */
6909 struct cmd_quit_result {
6910 	cmdline_fixed_string_t quit;
6911 };
6912 
6913 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
6914 			    struct cmdline *cl,
6915 			    __attribute__((unused)) void *data)
6916 {
6917 	pmd_test_exit();
6918 	cmdline_quit(cl);
6919 }
6920 
6921 cmdline_parse_token_string_t cmd_quit_quit =
6922 	TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
6923 
6924 cmdline_parse_inst_t cmd_quit = {
6925 	.f = cmd_quit_parsed,
6926 	.data = NULL,
6927 	.help_str = "quit: Exit application",
6928 	.tokens = {
6929 		(void *)&cmd_quit_quit,
6930 		NULL,
6931 	},
6932 };
6933 
6934 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
6935 struct cmd_mac_addr_result {
6936 	cmdline_fixed_string_t mac_addr_cmd;
6937 	cmdline_fixed_string_t what;
6938 	uint8_t port_num;
6939 	struct ether_addr address;
6940 };
6941 
6942 static void cmd_mac_addr_parsed(void *parsed_result,
6943 		__attribute__((unused)) struct cmdline *cl,
6944 		__attribute__((unused)) void *data)
6945 {
6946 	struct cmd_mac_addr_result *res = parsed_result;
6947 	int ret;
6948 
6949 	if (strcmp(res->what, "add") == 0)
6950 		ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
6951 	else if (strcmp(res->what, "set") == 0)
6952 		ret = rte_eth_dev_default_mac_addr_set(res->port_num,
6953 						       &res->address);
6954 	else
6955 		ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
6956 
6957 	/* check the return value and print it if is < 0 */
6958 	if(ret < 0)
6959 		printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
6960 
6961 }
6962 
6963 cmdline_parse_token_string_t cmd_mac_addr_cmd =
6964 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
6965 				"mac_addr");
6966 cmdline_parse_token_string_t cmd_mac_addr_what =
6967 	TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
6968 				"add#remove#set");
6969 cmdline_parse_token_num_t cmd_mac_addr_portnum =
6970 		TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
6971 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
6972 		TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
6973 
6974 cmdline_parse_inst_t cmd_mac_addr = {
6975 	.f = cmd_mac_addr_parsed,
6976 	.data = (void *)0,
6977 	.help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
6978 			"Add/Remove/Set MAC address on port_id",
6979 	.tokens = {
6980 		(void *)&cmd_mac_addr_cmd,
6981 		(void *)&cmd_mac_addr_what,
6982 		(void *)&cmd_mac_addr_portnum,
6983 		(void *)&cmd_mac_addr_addr,
6984 		NULL,
6985 	},
6986 };
6987 
6988 
6989 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
6990 struct cmd_set_qmap_result {
6991 	cmdline_fixed_string_t set;
6992 	cmdline_fixed_string_t qmap;
6993 	cmdline_fixed_string_t what;
6994 	uint8_t port_id;
6995 	uint16_t queue_id;
6996 	uint8_t map_value;
6997 };
6998 
6999 static void
7000 cmd_set_qmap_parsed(void *parsed_result,
7001 		       __attribute__((unused)) struct cmdline *cl,
7002 		       __attribute__((unused)) void *data)
7003 {
7004 	struct cmd_set_qmap_result *res = parsed_result;
7005 	int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7006 
7007 	set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7008 }
7009 
7010 cmdline_parse_token_string_t cmd_setqmap_set =
7011 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7012 				 set, "set");
7013 cmdline_parse_token_string_t cmd_setqmap_qmap =
7014 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7015 				 qmap, "stat_qmap");
7016 cmdline_parse_token_string_t cmd_setqmap_what =
7017 	TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7018 				 what, "tx#rx");
7019 cmdline_parse_token_num_t cmd_setqmap_portid =
7020 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7021 			      port_id, UINT8);
7022 cmdline_parse_token_num_t cmd_setqmap_queueid =
7023 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7024 			      queue_id, UINT16);
7025 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7026 	TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7027 			      map_value, UINT8);
7028 
7029 cmdline_parse_inst_t cmd_set_qmap = {
7030 	.f = cmd_set_qmap_parsed,
7031 	.data = NULL,
7032 	.help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7033 		"Set statistics mapping value on tx|rx queue_id of port_id",
7034 	.tokens = {
7035 		(void *)&cmd_setqmap_set,
7036 		(void *)&cmd_setqmap_qmap,
7037 		(void *)&cmd_setqmap_what,
7038 		(void *)&cmd_setqmap_portid,
7039 		(void *)&cmd_setqmap_queueid,
7040 		(void *)&cmd_setqmap_mapvalue,
7041 		NULL,
7042 	},
7043 };
7044 
7045 /* *** CONFIGURE UNICAST HASH TABLE *** */
7046 struct cmd_set_uc_hash_table {
7047 	cmdline_fixed_string_t set;
7048 	cmdline_fixed_string_t port;
7049 	uint8_t port_id;
7050 	cmdline_fixed_string_t what;
7051 	struct ether_addr address;
7052 	cmdline_fixed_string_t mode;
7053 };
7054 
7055 static void
7056 cmd_set_uc_hash_parsed(void *parsed_result,
7057 		       __attribute__((unused)) struct cmdline *cl,
7058 		       __attribute__((unused)) void *data)
7059 {
7060 	int ret=0;
7061 	struct cmd_set_uc_hash_table *res = parsed_result;
7062 
7063 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7064 
7065 	if (strcmp(res->what, "uta") == 0)
7066 		ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7067 						&res->address,(uint8_t)is_on);
7068 	if (ret < 0)
7069 		printf("bad unicast hash table parameter, return code = %d \n", ret);
7070 
7071 }
7072 
7073 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7074 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7075 				 set, "set");
7076 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7077 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7078 				 port, "port");
7079 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7080 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7081 			      port_id, UINT8);
7082 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7083 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7084 				 what, "uta");
7085 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7086 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7087 				address);
7088 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7089 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7090 				 mode, "on#off");
7091 
7092 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7093 	.f = cmd_set_uc_hash_parsed,
7094 	.data = NULL,
7095 	.help_str = "set port <port_id> uta <mac_addr> on|off)",
7096 	.tokens = {
7097 		(void *)&cmd_set_uc_hash_set,
7098 		(void *)&cmd_set_uc_hash_port,
7099 		(void *)&cmd_set_uc_hash_portid,
7100 		(void *)&cmd_set_uc_hash_what,
7101 		(void *)&cmd_set_uc_hash_mac,
7102 		(void *)&cmd_set_uc_hash_mode,
7103 		NULL,
7104 	},
7105 };
7106 
7107 struct cmd_set_uc_all_hash_table {
7108 	cmdline_fixed_string_t set;
7109 	cmdline_fixed_string_t port;
7110 	uint8_t port_id;
7111 	cmdline_fixed_string_t what;
7112 	cmdline_fixed_string_t value;
7113 	cmdline_fixed_string_t mode;
7114 };
7115 
7116 static void
7117 cmd_set_uc_all_hash_parsed(void *parsed_result,
7118 		       __attribute__((unused)) struct cmdline *cl,
7119 		       __attribute__((unused)) void *data)
7120 {
7121 	int ret=0;
7122 	struct cmd_set_uc_all_hash_table *res = parsed_result;
7123 
7124 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7125 
7126 	if ((strcmp(res->what, "uta") == 0) &&
7127 		(strcmp(res->value, "all") == 0))
7128 		ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7129 	if (ret < 0)
7130 		printf("bad unicast hash table parameter,"
7131 			"return code = %d \n", ret);
7132 }
7133 
7134 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7135 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7136 				 set, "set");
7137 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7138 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7139 				 port, "port");
7140 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7141 	TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7142 			      port_id, UINT8);
7143 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7144 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7145 				 what, "uta");
7146 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7147 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7148 				value,"all");
7149 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7150 	TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7151 				 mode, "on#off");
7152 
7153 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7154 	.f = cmd_set_uc_all_hash_parsed,
7155 	.data = NULL,
7156 	.help_str = "set port <port_id> uta all on|off",
7157 	.tokens = {
7158 		(void *)&cmd_set_uc_all_hash_set,
7159 		(void *)&cmd_set_uc_all_hash_port,
7160 		(void *)&cmd_set_uc_all_hash_portid,
7161 		(void *)&cmd_set_uc_all_hash_what,
7162 		(void *)&cmd_set_uc_all_hash_value,
7163 		(void *)&cmd_set_uc_all_hash_mode,
7164 		NULL,
7165 	},
7166 };
7167 
7168 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7169 struct cmd_set_vf_macvlan_filter {
7170 	cmdline_fixed_string_t set;
7171 	cmdline_fixed_string_t port;
7172 	uint8_t port_id;
7173 	cmdline_fixed_string_t vf;
7174 	uint8_t vf_id;
7175 	struct ether_addr address;
7176 	cmdline_fixed_string_t filter_type;
7177 	cmdline_fixed_string_t mode;
7178 };
7179 
7180 static void
7181 cmd_set_vf_macvlan_parsed(void *parsed_result,
7182 		       __attribute__((unused)) struct cmdline *cl,
7183 		       __attribute__((unused)) void *data)
7184 {
7185 	int is_on, ret = 0;
7186 	struct cmd_set_vf_macvlan_filter *res = parsed_result;
7187 	struct rte_eth_mac_filter filter;
7188 
7189 	memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7190 
7191 	rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7192 
7193 	/* set VF MAC filter */
7194 	filter.is_vf = 1;
7195 
7196 	/* set VF ID */
7197 	filter.dst_id = res->vf_id;
7198 
7199 	if (!strcmp(res->filter_type, "exact-mac"))
7200 		filter.filter_type = RTE_MAC_PERFECT_MATCH;
7201 	else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7202 		filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7203 	else if (!strcmp(res->filter_type, "hashmac"))
7204 		filter.filter_type = RTE_MAC_HASH_MATCH;
7205 	else if (!strcmp(res->filter_type, "hashmac-vlan"))
7206 		filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7207 
7208 	is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7209 
7210 	if (is_on)
7211 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7212 					RTE_ETH_FILTER_MACVLAN,
7213 					RTE_ETH_FILTER_ADD,
7214 					 &filter);
7215 	else
7216 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7217 					RTE_ETH_FILTER_MACVLAN,
7218 					RTE_ETH_FILTER_DELETE,
7219 					&filter);
7220 
7221 	if (ret < 0)
7222 		printf("bad set MAC hash parameter, return code = %d\n", ret);
7223 
7224 }
7225 
7226 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7227 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7228 				 set, "set");
7229 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7230 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7231 				 port, "port");
7232 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7233 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7234 			      port_id, UINT8);
7235 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7236 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7237 				 vf, "vf");
7238 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7239 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7240 				vf_id, UINT8);
7241 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7242 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7243 				address);
7244 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7245 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7246 				filter_type, "exact-mac#exact-mac-vlan"
7247 				"#hashmac#hashmac-vlan");
7248 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7249 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7250 				 mode, "on#off");
7251 
7252 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7253 	.f = cmd_set_vf_macvlan_parsed,
7254 	.data = NULL,
7255 	.help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7256 		"exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7257 		"Exact match rule: exact match of MAC or MAC and VLAN; "
7258 		"hash match rule: hash match of MAC and exact match of VLAN",
7259 	.tokens = {
7260 		(void *)&cmd_set_vf_macvlan_set,
7261 		(void *)&cmd_set_vf_macvlan_port,
7262 		(void *)&cmd_set_vf_macvlan_portid,
7263 		(void *)&cmd_set_vf_macvlan_vf,
7264 		(void *)&cmd_set_vf_macvlan_vf_id,
7265 		(void *)&cmd_set_vf_macvlan_mac,
7266 		(void *)&cmd_set_vf_macvlan_filter_type,
7267 		(void *)&cmd_set_vf_macvlan_mode,
7268 		NULL,
7269 	},
7270 };
7271 
7272 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7273 struct cmd_set_vf_traffic {
7274 	cmdline_fixed_string_t set;
7275 	cmdline_fixed_string_t port;
7276 	uint8_t port_id;
7277 	cmdline_fixed_string_t vf;
7278 	uint8_t vf_id;
7279 	cmdline_fixed_string_t what;
7280 	cmdline_fixed_string_t mode;
7281 };
7282 
7283 static void
7284 cmd_set_vf_traffic_parsed(void *parsed_result,
7285 		       __attribute__((unused)) struct cmdline *cl,
7286 		       __attribute__((unused)) void *data)
7287 {
7288 	struct cmd_set_vf_traffic *res = parsed_result;
7289 	int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7290 	int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7291 
7292 	set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7293 }
7294 
7295 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7296 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7297 				 set, "set");
7298 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7299 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7300 				 port, "port");
7301 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7302 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7303 			      port_id, UINT8);
7304 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7305 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7306 				 vf, "vf");
7307 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7308 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7309 			      vf_id, UINT8);
7310 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7311 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7312 				 what, "tx#rx");
7313 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7314 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7315 				 mode, "on#off");
7316 
7317 cmdline_parse_inst_t cmd_set_vf_traffic = {
7318 	.f = cmd_set_vf_traffic_parsed,
7319 	.data = NULL,
7320 	.help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7321 	.tokens = {
7322 		(void *)&cmd_setvf_traffic_set,
7323 		(void *)&cmd_setvf_traffic_port,
7324 		(void *)&cmd_setvf_traffic_portid,
7325 		(void *)&cmd_setvf_traffic_vf,
7326 		(void *)&cmd_setvf_traffic_vfid,
7327 		(void *)&cmd_setvf_traffic_what,
7328 		(void *)&cmd_setvf_traffic_mode,
7329 		NULL,
7330 	},
7331 };
7332 
7333 /* *** CONFIGURE VF RECEIVE MODE *** */
7334 struct cmd_set_vf_rxmode {
7335 	cmdline_fixed_string_t set;
7336 	cmdline_fixed_string_t port;
7337 	uint8_t port_id;
7338 	cmdline_fixed_string_t vf;
7339 	uint8_t vf_id;
7340 	cmdline_fixed_string_t what;
7341 	cmdline_fixed_string_t mode;
7342 	cmdline_fixed_string_t on;
7343 };
7344 
7345 static void
7346 cmd_set_vf_rxmode_parsed(void *parsed_result,
7347 		       __attribute__((unused)) struct cmdline *cl,
7348 		       __attribute__((unused)) void *data)
7349 {
7350 	int ret = -ENOTSUP;
7351 	uint16_t rx_mode = 0;
7352 	struct cmd_set_vf_rxmode *res = parsed_result;
7353 
7354 	int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7355 	if (!strcmp(res->what,"rxmode")) {
7356 		if (!strcmp(res->mode, "AUPE"))
7357 			rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7358 		else if (!strcmp(res->mode, "ROPE"))
7359 			rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7360 		else if (!strcmp(res->mode, "BAM"))
7361 			rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7362 		else if (!strncmp(res->mode, "MPE",3))
7363 			rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7364 	}
7365 
7366 #ifdef RTE_LIBRTE_IXGBE_PMD
7367 	if (ret == -ENOTSUP)
7368 		ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7369 						  rx_mode, (uint8_t)is_on);
7370 #endif
7371 #ifdef RTE_LIBRTE_BNXT_PMD
7372 	if (ret == -ENOTSUP)
7373 		ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7374 						 rx_mode, (uint8_t)is_on);
7375 #endif
7376 	if (ret < 0)
7377 		printf("bad VF receive mode parameter, return code = %d \n",
7378 		ret);
7379 }
7380 
7381 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7382 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7383 				 set, "set");
7384 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7385 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7386 				 port, "port");
7387 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7388 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7389 			      port_id, UINT8);
7390 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7391 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7392 				 vf, "vf");
7393 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7394 	TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7395 			      vf_id, UINT8);
7396 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7397 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7398 				 what, "rxmode");
7399 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7400 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7401 				 mode, "AUPE#ROPE#BAM#MPE");
7402 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7403 	TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7404 				 on, "on#off");
7405 
7406 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7407 	.f = cmd_set_vf_rxmode_parsed,
7408 	.data = NULL,
7409 	.help_str = "set port <port_id> vf <vf_id> rxmode "
7410 		"AUPE|ROPE|BAM|MPE on|off",
7411 	.tokens = {
7412 		(void *)&cmd_set_vf_rxmode_set,
7413 		(void *)&cmd_set_vf_rxmode_port,
7414 		(void *)&cmd_set_vf_rxmode_portid,
7415 		(void *)&cmd_set_vf_rxmode_vf,
7416 		(void *)&cmd_set_vf_rxmode_vfid,
7417 		(void *)&cmd_set_vf_rxmode_what,
7418 		(void *)&cmd_set_vf_rxmode_mode,
7419 		(void *)&cmd_set_vf_rxmode_on,
7420 		NULL,
7421 	},
7422 };
7423 
7424 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7425 struct cmd_vf_mac_addr_result {
7426 	cmdline_fixed_string_t mac_addr_cmd;
7427 	cmdline_fixed_string_t what;
7428 	cmdline_fixed_string_t port;
7429 	uint8_t port_num;
7430 	cmdline_fixed_string_t vf;
7431 	uint8_t vf_num;
7432 	struct ether_addr address;
7433 };
7434 
7435 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7436 		__attribute__((unused)) struct cmdline *cl,
7437 		__attribute__((unused)) void *data)
7438 {
7439 	struct cmd_vf_mac_addr_result *res = parsed_result;
7440 	int ret = -ENOTSUP;
7441 
7442 	if (strcmp(res->what, "add") != 0)
7443 		return;
7444 
7445 #ifdef RTE_LIBRTE_I40E_PMD
7446 	if (ret == -ENOTSUP)
7447 		ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7448 						   &res->address);
7449 #endif
7450 #ifdef RTE_LIBRTE_BNXT_PMD
7451 	if (ret == -ENOTSUP)
7452 		ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7453 						res->vf_num);
7454 #endif
7455 
7456 	if(ret < 0)
7457 		printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7458 
7459 }
7460 
7461 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7462 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7463 				mac_addr_cmd,"mac_addr");
7464 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7465 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7466 				what,"add");
7467 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7468 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7469 				port,"port");
7470 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7471 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7472 				port_num, UINT8);
7473 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7474 	TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7475 				vf,"vf");
7476 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7477 	TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7478 				vf_num, UINT8);
7479 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7480 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7481 				address);
7482 
7483 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7484 	.f = cmd_vf_mac_addr_parsed,
7485 	.data = (void *)0,
7486 	.help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7487 		"Add MAC address filtering for a VF on port_id",
7488 	.tokens = {
7489 		(void *)&cmd_vf_mac_addr_cmd,
7490 		(void *)&cmd_vf_mac_addr_what,
7491 		(void *)&cmd_vf_mac_addr_port,
7492 		(void *)&cmd_vf_mac_addr_portnum,
7493 		(void *)&cmd_vf_mac_addr_vf,
7494 		(void *)&cmd_vf_mac_addr_vfnum,
7495 		(void *)&cmd_vf_mac_addr_addr,
7496 		NULL,
7497 	},
7498 };
7499 
7500 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7501 struct cmd_vf_rx_vlan_filter {
7502 	cmdline_fixed_string_t rx_vlan;
7503 	cmdline_fixed_string_t what;
7504 	uint16_t vlan_id;
7505 	cmdline_fixed_string_t port;
7506 	uint8_t port_id;
7507 	cmdline_fixed_string_t vf;
7508 	uint64_t vf_mask;
7509 };
7510 
7511 static void
7512 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7513 			  __attribute__((unused)) struct cmdline *cl,
7514 			  __attribute__((unused)) void *data)
7515 {
7516 	struct cmd_vf_rx_vlan_filter *res = parsed_result;
7517 	int ret = -ENOTSUP;
7518 
7519 	__rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7520 
7521 #ifdef RTE_LIBRTE_IXGBE_PMD
7522 	if (ret == -ENOTSUP)
7523 		ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7524 				res->vlan_id, res->vf_mask, is_add);
7525 #endif
7526 #ifdef RTE_LIBRTE_I40E_PMD
7527 	if (ret == -ENOTSUP)
7528 		ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7529 				res->vlan_id, res->vf_mask, is_add);
7530 #endif
7531 #ifdef RTE_LIBRTE_BNXT_PMD
7532 	if (ret == -ENOTSUP)
7533 		ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7534 				res->vlan_id, res->vf_mask, is_add);
7535 #endif
7536 
7537 	switch (ret) {
7538 	case 0:
7539 		break;
7540 	case -EINVAL:
7541 		printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7542 				res->vlan_id, res->vf_mask);
7543 		break;
7544 	case -ENODEV:
7545 		printf("invalid port_id %d\n", res->port_id);
7546 		break;
7547 	case -ENOTSUP:
7548 		printf("function not implemented or supported\n");
7549 		break;
7550 	default:
7551 		printf("programming error: (%s)\n", strerror(-ret));
7552 	}
7553 }
7554 
7555 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7556 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7557 				 rx_vlan, "rx_vlan");
7558 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7559 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7560 				 what, "add#rm");
7561 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7562 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7563 			      vlan_id, UINT16);
7564 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7565 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7566 				 port, "port");
7567 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7568 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7569 			      port_id, UINT8);
7570 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7571 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7572 				 vf, "vf");
7573 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7574 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7575 			      vf_mask, UINT64);
7576 
7577 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7578 	.f = cmd_vf_rx_vlan_filter_parsed,
7579 	.data = NULL,
7580 	.help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7581 		"(vf_mask = hexadecimal VF mask)",
7582 	.tokens = {
7583 		(void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7584 		(void *)&cmd_vf_rx_vlan_filter_what,
7585 		(void *)&cmd_vf_rx_vlan_filter_vlanid,
7586 		(void *)&cmd_vf_rx_vlan_filter_port,
7587 		(void *)&cmd_vf_rx_vlan_filter_portid,
7588 		(void *)&cmd_vf_rx_vlan_filter_vf,
7589 		(void *)&cmd_vf_rx_vlan_filter_vf_mask,
7590 		NULL,
7591 	},
7592 };
7593 
7594 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7595 struct cmd_queue_rate_limit_result {
7596 	cmdline_fixed_string_t set;
7597 	cmdline_fixed_string_t port;
7598 	uint8_t port_num;
7599 	cmdline_fixed_string_t queue;
7600 	uint8_t queue_num;
7601 	cmdline_fixed_string_t rate;
7602 	uint16_t rate_num;
7603 };
7604 
7605 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7606 		__attribute__((unused)) struct cmdline *cl,
7607 		__attribute__((unused)) void *data)
7608 {
7609 	struct cmd_queue_rate_limit_result *res = parsed_result;
7610 	int ret = 0;
7611 
7612 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7613 		&& (strcmp(res->queue, "queue") == 0)
7614 		&& (strcmp(res->rate, "rate") == 0))
7615 		ret = set_queue_rate_limit(res->port_num, res->queue_num,
7616 					res->rate_num);
7617 	if (ret < 0)
7618 		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7619 
7620 }
7621 
7622 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7623 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7624 				set, "set");
7625 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7626 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7627 				port, "port");
7628 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7629 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7630 				port_num, UINT8);
7631 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7632 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7633 				queue, "queue");
7634 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7635 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7636 				queue_num, UINT8);
7637 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7638 	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7639 				rate, "rate");
7640 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7641 	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7642 				rate_num, UINT16);
7643 
7644 cmdline_parse_inst_t cmd_queue_rate_limit = {
7645 	.f = cmd_queue_rate_limit_parsed,
7646 	.data = (void *)0,
7647 	.help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7648 		"Set rate limit for a queue on port_id",
7649 	.tokens = {
7650 		(void *)&cmd_queue_rate_limit_set,
7651 		(void *)&cmd_queue_rate_limit_port,
7652 		(void *)&cmd_queue_rate_limit_portnum,
7653 		(void *)&cmd_queue_rate_limit_queue,
7654 		(void *)&cmd_queue_rate_limit_queuenum,
7655 		(void *)&cmd_queue_rate_limit_rate,
7656 		(void *)&cmd_queue_rate_limit_ratenum,
7657 		NULL,
7658 	},
7659 };
7660 
7661 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7662 struct cmd_vf_rate_limit_result {
7663 	cmdline_fixed_string_t set;
7664 	cmdline_fixed_string_t port;
7665 	uint8_t port_num;
7666 	cmdline_fixed_string_t vf;
7667 	uint8_t vf_num;
7668 	cmdline_fixed_string_t rate;
7669 	uint16_t rate_num;
7670 	cmdline_fixed_string_t q_msk;
7671 	uint64_t q_msk_val;
7672 };
7673 
7674 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7675 		__attribute__((unused)) struct cmdline *cl,
7676 		__attribute__((unused)) void *data)
7677 {
7678 	struct cmd_vf_rate_limit_result *res = parsed_result;
7679 	int ret = 0;
7680 
7681 	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7682 		&& (strcmp(res->vf, "vf") == 0)
7683 		&& (strcmp(res->rate, "rate") == 0)
7684 		&& (strcmp(res->q_msk, "queue_mask") == 0))
7685 		ret = set_vf_rate_limit(res->port_num, res->vf_num,
7686 					res->rate_num, res->q_msk_val);
7687 	if (ret < 0)
7688 		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7689 
7690 }
7691 
7692 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7693 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7694 				set, "set");
7695 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7696 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7697 				port, "port");
7698 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7699 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7700 				port_num, UINT8);
7701 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7702 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7703 				vf, "vf");
7704 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7705 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7706 				vf_num, UINT8);
7707 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7708 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7709 				rate, "rate");
7710 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7711 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7712 				rate_num, UINT16);
7713 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7714 	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7715 				q_msk, "queue_mask");
7716 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7717 	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7718 				q_msk_val, UINT64);
7719 
7720 cmdline_parse_inst_t cmd_vf_rate_limit = {
7721 	.f = cmd_vf_rate_limit_parsed,
7722 	.data = (void *)0,
7723 	.help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7724 		"queue_mask <queue_mask_value>: "
7725 		"Set rate limit for queues of VF on port_id",
7726 	.tokens = {
7727 		(void *)&cmd_vf_rate_limit_set,
7728 		(void *)&cmd_vf_rate_limit_port,
7729 		(void *)&cmd_vf_rate_limit_portnum,
7730 		(void *)&cmd_vf_rate_limit_vf,
7731 		(void *)&cmd_vf_rate_limit_vfnum,
7732 		(void *)&cmd_vf_rate_limit_rate,
7733 		(void *)&cmd_vf_rate_limit_ratenum,
7734 		(void *)&cmd_vf_rate_limit_q_msk,
7735 		(void *)&cmd_vf_rate_limit_q_msk_val,
7736 		NULL,
7737 	},
7738 };
7739 
7740 /* *** ADD TUNNEL FILTER OF A PORT *** */
7741 struct cmd_tunnel_filter_result {
7742 	cmdline_fixed_string_t cmd;
7743 	cmdline_fixed_string_t what;
7744 	uint8_t port_id;
7745 	struct ether_addr outer_mac;
7746 	struct ether_addr inner_mac;
7747 	cmdline_ipaddr_t ip_value;
7748 	uint16_t inner_vlan;
7749 	cmdline_fixed_string_t tunnel_type;
7750 	cmdline_fixed_string_t filter_type;
7751 	uint32_t tenant_id;
7752 	uint16_t queue_num;
7753 };
7754 
7755 static void
7756 cmd_tunnel_filter_parsed(void *parsed_result,
7757 			  __attribute__((unused)) struct cmdline *cl,
7758 			  __attribute__((unused)) void *data)
7759 {
7760 	struct cmd_tunnel_filter_result *res = parsed_result;
7761 	struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7762 	int ret = 0;
7763 
7764 	memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7765 
7766 	ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7767 	ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7768 	tunnel_filter_conf.inner_vlan = res->inner_vlan;
7769 
7770 	if (res->ip_value.family == AF_INET) {
7771 		tunnel_filter_conf.ip_addr.ipv4_addr =
7772 			res->ip_value.addr.ipv4.s_addr;
7773 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7774 	} else {
7775 		memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7776 			&(res->ip_value.addr.ipv6),
7777 			sizeof(struct in6_addr));
7778 		tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7779 	}
7780 
7781 	if (!strcmp(res->filter_type, "imac-ivlan"))
7782 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7783 	else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7784 		tunnel_filter_conf.filter_type =
7785 			RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7786 	else if (!strcmp(res->filter_type, "imac-tenid"))
7787 		tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7788 	else if (!strcmp(res->filter_type, "imac"))
7789 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7790 	else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7791 		tunnel_filter_conf.filter_type =
7792 			RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7793 	else if (!strcmp(res->filter_type, "oip"))
7794 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7795 	else if (!strcmp(res->filter_type, "iip"))
7796 		tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7797 	else {
7798 		printf("The filter type is not supported");
7799 		return;
7800 	}
7801 
7802 	if (!strcmp(res->tunnel_type, "vxlan"))
7803 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7804 	else if (!strcmp(res->tunnel_type, "nvgre"))
7805 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7806 	else if (!strcmp(res->tunnel_type, "ipingre"))
7807 		tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7808 	else {
7809 		printf("The tunnel type %s not supported.\n", res->tunnel_type);
7810 		return;
7811 	}
7812 
7813 	tunnel_filter_conf.tenant_id = res->tenant_id;
7814 	tunnel_filter_conf.queue_id = res->queue_num;
7815 	if (!strcmp(res->what, "add"))
7816 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7817 					RTE_ETH_FILTER_TUNNEL,
7818 					RTE_ETH_FILTER_ADD,
7819 					&tunnel_filter_conf);
7820 	else
7821 		ret = rte_eth_dev_filter_ctrl(res->port_id,
7822 					RTE_ETH_FILTER_TUNNEL,
7823 					RTE_ETH_FILTER_DELETE,
7824 					&tunnel_filter_conf);
7825 	if (ret < 0)
7826 		printf("cmd_tunnel_filter_parsed error: (%s)\n",
7827 				strerror(-ret));
7828 
7829 }
7830 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
7831 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7832 	cmd, "tunnel_filter");
7833 cmdline_parse_token_string_t cmd_tunnel_filter_what =
7834 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7835 	what, "add#rm");
7836 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
7837 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7838 	port_id, UINT8);
7839 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
7840 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7841 	outer_mac);
7842 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
7843 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7844 	inner_mac);
7845 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
7846 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7847 	inner_vlan, UINT16);
7848 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
7849 	TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
7850 	ip_value);
7851 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
7852 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7853 	tunnel_type, "vxlan#nvgre#ipingre");
7854 
7855 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
7856 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
7857 	filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
7858 		"imac#omac-imac-tenid");
7859 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
7860 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7861 	tenant_id, UINT32);
7862 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
7863 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
7864 	queue_num, UINT16);
7865 
7866 cmdline_parse_inst_t cmd_tunnel_filter = {
7867 	.f = cmd_tunnel_filter_parsed,
7868 	.data = (void *)0,
7869 	.help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
7870 		"<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
7871 		"imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
7872 		"<queue_id>: Add/Rm tunnel filter of a port",
7873 	.tokens = {
7874 		(void *)&cmd_tunnel_filter_cmd,
7875 		(void *)&cmd_tunnel_filter_what,
7876 		(void *)&cmd_tunnel_filter_port_id,
7877 		(void *)&cmd_tunnel_filter_outer_mac,
7878 		(void *)&cmd_tunnel_filter_inner_mac,
7879 		(void *)&cmd_tunnel_filter_ip_value,
7880 		(void *)&cmd_tunnel_filter_innner_vlan,
7881 		(void *)&cmd_tunnel_filter_tunnel_type,
7882 		(void *)&cmd_tunnel_filter_filter_type,
7883 		(void *)&cmd_tunnel_filter_tenant_id,
7884 		(void *)&cmd_tunnel_filter_queue_num,
7885 		NULL,
7886 	},
7887 };
7888 
7889 /* *** CONFIGURE TUNNEL UDP PORT *** */
7890 struct cmd_tunnel_udp_config {
7891 	cmdline_fixed_string_t cmd;
7892 	cmdline_fixed_string_t what;
7893 	uint16_t udp_port;
7894 	uint8_t port_id;
7895 };
7896 
7897 static void
7898 cmd_tunnel_udp_config_parsed(void *parsed_result,
7899 			  __attribute__((unused)) struct cmdline *cl,
7900 			  __attribute__((unused)) void *data)
7901 {
7902 	struct cmd_tunnel_udp_config *res = parsed_result;
7903 	struct rte_eth_udp_tunnel tunnel_udp;
7904 	int ret;
7905 
7906 	tunnel_udp.udp_port = res->udp_port;
7907 
7908 	if (!strcmp(res->cmd, "rx_vxlan_port"))
7909 		tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
7910 
7911 	if (!strcmp(res->what, "add"))
7912 		ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
7913 						      &tunnel_udp);
7914 	else
7915 		ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
7916 							 &tunnel_udp);
7917 
7918 	if (ret < 0)
7919 		printf("udp tunneling add error: (%s)\n", strerror(-ret));
7920 }
7921 
7922 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
7923 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7924 				cmd, "rx_vxlan_port");
7925 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
7926 	TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
7927 				what, "add#rm");
7928 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
7929 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7930 				udp_port, UINT16);
7931 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
7932 	TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
7933 				port_id, UINT8);
7934 
7935 cmdline_parse_inst_t cmd_tunnel_udp_config = {
7936 	.f = cmd_tunnel_udp_config_parsed,
7937 	.data = (void *)0,
7938 	.help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
7939 		"Add/Remove a tunneling UDP port filter",
7940 	.tokens = {
7941 		(void *)&cmd_tunnel_udp_config_cmd,
7942 		(void *)&cmd_tunnel_udp_config_what,
7943 		(void *)&cmd_tunnel_udp_config_udp_port,
7944 		(void *)&cmd_tunnel_udp_config_port_id,
7945 		NULL,
7946 	},
7947 };
7948 
7949 /* *** GLOBAL CONFIG *** */
7950 struct cmd_global_config_result {
7951 	cmdline_fixed_string_t cmd;
7952 	uint8_t port_id;
7953 	cmdline_fixed_string_t cfg_type;
7954 	uint8_t len;
7955 };
7956 
7957 static void
7958 cmd_global_config_parsed(void *parsed_result,
7959 			 __attribute__((unused)) struct cmdline *cl,
7960 			 __attribute__((unused)) void *data)
7961 {
7962 	struct cmd_global_config_result *res = parsed_result;
7963 	struct rte_eth_global_cfg conf;
7964 	int ret;
7965 
7966 	memset(&conf, 0, sizeof(conf));
7967 	conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
7968 	conf.cfg.gre_key_len = res->len;
7969 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
7970 				      RTE_ETH_FILTER_SET, &conf);
7971 	if (ret != 0)
7972 		printf("Global config error\n");
7973 }
7974 
7975 cmdline_parse_token_string_t cmd_global_config_cmd =
7976 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
7977 		"global_config");
7978 cmdline_parse_token_num_t cmd_global_config_port_id =
7979 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
7980 cmdline_parse_token_string_t cmd_global_config_type =
7981 	TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
7982 		cfg_type, "gre-key-len");
7983 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
7984 	TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
7985 		len, UINT8);
7986 
7987 cmdline_parse_inst_t cmd_global_config = {
7988 	.f = cmd_global_config_parsed,
7989 	.data = (void *)NULL,
7990 	.help_str = "global_config <port_id> gre-key-len <key_len>",
7991 	.tokens = {
7992 		(void *)&cmd_global_config_cmd,
7993 		(void *)&cmd_global_config_port_id,
7994 		(void *)&cmd_global_config_type,
7995 		(void *)&cmd_global_config_gre_key_len,
7996 		NULL,
7997 	},
7998 };
7999 
8000 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8001 struct cmd_set_mirror_mask_result {
8002 	cmdline_fixed_string_t set;
8003 	cmdline_fixed_string_t port;
8004 	uint8_t port_id;
8005 	cmdline_fixed_string_t mirror;
8006 	uint8_t rule_id;
8007 	cmdline_fixed_string_t what;
8008 	cmdline_fixed_string_t value;
8009 	cmdline_fixed_string_t dstpool;
8010 	uint8_t dstpool_id;
8011 	cmdline_fixed_string_t on;
8012 };
8013 
8014 cmdline_parse_token_string_t cmd_mirror_mask_set =
8015 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8016 				set, "set");
8017 cmdline_parse_token_string_t cmd_mirror_mask_port =
8018 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8019 				port, "port");
8020 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8021 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8022 				port_id, UINT8);
8023 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8024 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8025 				mirror, "mirror-rule");
8026 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8027 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8028 				rule_id, UINT8);
8029 cmdline_parse_token_string_t cmd_mirror_mask_what =
8030 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8031 				what, "pool-mirror-up#pool-mirror-down"
8032 				      "#vlan-mirror");
8033 cmdline_parse_token_string_t cmd_mirror_mask_value =
8034 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8035 				value, NULL);
8036 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8037 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8038 				dstpool, "dst-pool");
8039 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8040 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8041 				dstpool_id, UINT8);
8042 cmdline_parse_token_string_t cmd_mirror_mask_on =
8043 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8044 				on, "on#off");
8045 
8046 static void
8047 cmd_set_mirror_mask_parsed(void *parsed_result,
8048 		       __attribute__((unused)) struct cmdline *cl,
8049 		       __attribute__((unused)) void *data)
8050 {
8051 	int ret,nb_item,i;
8052 	struct cmd_set_mirror_mask_result *res = parsed_result;
8053 	struct rte_eth_mirror_conf mr_conf;
8054 
8055 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8056 
8057 	unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8058 
8059 	mr_conf.dst_pool = res->dstpool_id;
8060 
8061 	if (!strcmp(res->what, "pool-mirror-up")) {
8062 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8063 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8064 	} else if (!strcmp(res->what, "pool-mirror-down")) {
8065 		mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8066 		mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8067 	} else if (!strcmp(res->what, "vlan-mirror")) {
8068 		mr_conf.rule_type = ETH_MIRROR_VLAN;
8069 		nb_item = parse_item_list(res->value, "vlan",
8070 				ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8071 		if (nb_item <= 0)
8072 			return;
8073 
8074 		for (i = 0; i < nb_item; i++) {
8075 			if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8076 				printf("Invalid vlan_id: must be < 4096\n");
8077 				return;
8078 			}
8079 
8080 			mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8081 			mr_conf.vlan.vlan_mask |= 1ULL << i;
8082 		}
8083 	}
8084 
8085 	if (!strcmp(res->on, "on"))
8086 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8087 						res->rule_id, 1);
8088 	else
8089 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8090 						res->rule_id, 0);
8091 	if (ret < 0)
8092 		printf("mirror rule add error: (%s)\n", strerror(-ret));
8093 }
8094 
8095 cmdline_parse_inst_t cmd_set_mirror_mask = {
8096 		.f = cmd_set_mirror_mask_parsed,
8097 		.data = NULL,
8098 		.help_str = "set port <port_id> mirror-rule <rule_id> "
8099 			"pool-mirror-up|pool-mirror-down|vlan-mirror "
8100 			"<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8101 		.tokens = {
8102 			(void *)&cmd_mirror_mask_set,
8103 			(void *)&cmd_mirror_mask_port,
8104 			(void *)&cmd_mirror_mask_portid,
8105 			(void *)&cmd_mirror_mask_mirror,
8106 			(void *)&cmd_mirror_mask_ruleid,
8107 			(void *)&cmd_mirror_mask_what,
8108 			(void *)&cmd_mirror_mask_value,
8109 			(void *)&cmd_mirror_mask_dstpool,
8110 			(void *)&cmd_mirror_mask_poolid,
8111 			(void *)&cmd_mirror_mask_on,
8112 			NULL,
8113 		},
8114 };
8115 
8116 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8117 struct cmd_set_mirror_link_result {
8118 	cmdline_fixed_string_t set;
8119 	cmdline_fixed_string_t port;
8120 	uint8_t port_id;
8121 	cmdline_fixed_string_t mirror;
8122 	uint8_t rule_id;
8123 	cmdline_fixed_string_t what;
8124 	cmdline_fixed_string_t dstpool;
8125 	uint8_t dstpool_id;
8126 	cmdline_fixed_string_t on;
8127 };
8128 
8129 cmdline_parse_token_string_t cmd_mirror_link_set =
8130 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8131 				 set, "set");
8132 cmdline_parse_token_string_t cmd_mirror_link_port =
8133 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8134 				port, "port");
8135 cmdline_parse_token_num_t cmd_mirror_link_portid =
8136 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8137 				port_id, UINT8);
8138 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8139 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8140 				mirror, "mirror-rule");
8141 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8142 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8143 			    rule_id, UINT8);
8144 cmdline_parse_token_string_t cmd_mirror_link_what =
8145 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8146 				what, "uplink-mirror#downlink-mirror");
8147 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8148 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8149 				dstpool, "dst-pool");
8150 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8151 	TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8152 				dstpool_id, UINT8);
8153 cmdline_parse_token_string_t cmd_mirror_link_on =
8154 	TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8155 				on, "on#off");
8156 
8157 static void
8158 cmd_set_mirror_link_parsed(void *parsed_result,
8159 		       __attribute__((unused)) struct cmdline *cl,
8160 		       __attribute__((unused)) void *data)
8161 {
8162 	int ret;
8163 	struct cmd_set_mirror_link_result *res = parsed_result;
8164 	struct rte_eth_mirror_conf mr_conf;
8165 
8166 	memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8167 	if (!strcmp(res->what, "uplink-mirror"))
8168 		mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8169 	else
8170 		mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8171 
8172 	mr_conf.dst_pool = res->dstpool_id;
8173 
8174 	if (!strcmp(res->on, "on"))
8175 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8176 						res->rule_id, 1);
8177 	else
8178 		ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8179 						res->rule_id, 0);
8180 
8181 	/* check the return value and print it if is < 0 */
8182 	if (ret < 0)
8183 		printf("mirror rule add error: (%s)\n", strerror(-ret));
8184 
8185 }
8186 
8187 cmdline_parse_inst_t cmd_set_mirror_link = {
8188 		.f = cmd_set_mirror_link_parsed,
8189 		.data = NULL,
8190 		.help_str = "set port <port_id> mirror-rule <rule_id> "
8191 			"uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8192 		.tokens = {
8193 			(void *)&cmd_mirror_link_set,
8194 			(void *)&cmd_mirror_link_port,
8195 			(void *)&cmd_mirror_link_portid,
8196 			(void *)&cmd_mirror_link_mirror,
8197 			(void *)&cmd_mirror_link_ruleid,
8198 			(void *)&cmd_mirror_link_what,
8199 			(void *)&cmd_mirror_link_dstpool,
8200 			(void *)&cmd_mirror_link_poolid,
8201 			(void *)&cmd_mirror_link_on,
8202 			NULL,
8203 		},
8204 };
8205 
8206 /* *** RESET VM MIRROR RULE *** */
8207 struct cmd_rm_mirror_rule_result {
8208 	cmdline_fixed_string_t reset;
8209 	cmdline_fixed_string_t port;
8210 	uint8_t port_id;
8211 	cmdline_fixed_string_t mirror;
8212 	uint8_t rule_id;
8213 };
8214 
8215 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8216 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8217 				 reset, "reset");
8218 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8219 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8220 				port, "port");
8221 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8222 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8223 				port_id, UINT8);
8224 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8225 	TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8226 				mirror, "mirror-rule");
8227 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8228 	TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8229 				rule_id, UINT8);
8230 
8231 static void
8232 cmd_reset_mirror_rule_parsed(void *parsed_result,
8233 		       __attribute__((unused)) struct cmdline *cl,
8234 		       __attribute__((unused)) void *data)
8235 {
8236 	int ret;
8237 	struct cmd_set_mirror_link_result *res = parsed_result;
8238         /* check rule_id */
8239 	ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8240 	if(ret < 0)
8241 		printf("mirror rule remove error: (%s)\n", strerror(-ret));
8242 }
8243 
8244 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8245 		.f = cmd_reset_mirror_rule_parsed,
8246 		.data = NULL,
8247 		.help_str = "reset port <port_id> mirror-rule <rule_id>",
8248 		.tokens = {
8249 			(void *)&cmd_rm_mirror_rule_reset,
8250 			(void *)&cmd_rm_mirror_rule_port,
8251 			(void *)&cmd_rm_mirror_rule_portid,
8252 			(void *)&cmd_rm_mirror_rule_mirror,
8253 			(void *)&cmd_rm_mirror_rule_ruleid,
8254 			NULL,
8255 		},
8256 };
8257 
8258 /* ******************************************************************************** */
8259 
8260 struct cmd_dump_result {
8261 	cmdline_fixed_string_t dump;
8262 };
8263 
8264 static void
8265 dump_struct_sizes(void)
8266 {
8267 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8268 	DUMP_SIZE(struct rte_mbuf);
8269 	DUMP_SIZE(struct rte_mempool);
8270 	DUMP_SIZE(struct rte_ring);
8271 #undef DUMP_SIZE
8272 }
8273 
8274 static void cmd_dump_parsed(void *parsed_result,
8275 			    __attribute__((unused)) struct cmdline *cl,
8276 			    __attribute__((unused)) void *data)
8277 {
8278 	struct cmd_dump_result *res = parsed_result;
8279 
8280 	if (!strcmp(res->dump, "dump_physmem"))
8281 		rte_dump_physmem_layout(stdout);
8282 	else if (!strcmp(res->dump, "dump_memzone"))
8283 		rte_memzone_dump(stdout);
8284 	else if (!strcmp(res->dump, "dump_struct_sizes"))
8285 		dump_struct_sizes();
8286 	else if (!strcmp(res->dump, "dump_ring"))
8287 		rte_ring_list_dump(stdout);
8288 	else if (!strcmp(res->dump, "dump_mempool"))
8289 		rte_mempool_list_dump(stdout);
8290 	else if (!strcmp(res->dump, "dump_devargs"))
8291 		rte_eal_devargs_dump(stdout);
8292 	else if (!strcmp(res->dump, "dump_log_types"))
8293 		rte_log_dump(stdout);
8294 }
8295 
8296 cmdline_parse_token_string_t cmd_dump_dump =
8297 	TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8298 		"dump_physmem#"
8299 		"dump_memzone#"
8300 		"dump_struct_sizes#"
8301 		"dump_ring#"
8302 		"dump_mempool#"
8303 		"dump_devargs#"
8304 		"dump_log_types");
8305 
8306 cmdline_parse_inst_t cmd_dump = {
8307 	.f = cmd_dump_parsed,  /* function to call */
8308 	.data = NULL,      /* 2nd arg of func */
8309 	.help_str = "Dump status",
8310 	.tokens = {        /* token list, NULL terminated */
8311 		(void *)&cmd_dump_dump,
8312 		NULL,
8313 	},
8314 };
8315 
8316 /* ******************************************************************************** */
8317 
8318 struct cmd_dump_one_result {
8319 	cmdline_fixed_string_t dump;
8320 	cmdline_fixed_string_t name;
8321 };
8322 
8323 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8324 				__attribute__((unused)) void *data)
8325 {
8326 	struct cmd_dump_one_result *res = parsed_result;
8327 
8328 	if (!strcmp(res->dump, "dump_ring")) {
8329 		struct rte_ring *r;
8330 		r = rte_ring_lookup(res->name);
8331 		if (r == NULL) {
8332 			cmdline_printf(cl, "Cannot find ring\n");
8333 			return;
8334 		}
8335 		rte_ring_dump(stdout, r);
8336 	} else if (!strcmp(res->dump, "dump_mempool")) {
8337 		struct rte_mempool *mp;
8338 		mp = rte_mempool_lookup(res->name);
8339 		if (mp == NULL) {
8340 			cmdline_printf(cl, "Cannot find mempool\n");
8341 			return;
8342 		}
8343 		rte_mempool_dump(stdout, mp);
8344 	}
8345 }
8346 
8347 cmdline_parse_token_string_t cmd_dump_one_dump =
8348 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8349 				 "dump_ring#dump_mempool");
8350 
8351 cmdline_parse_token_string_t cmd_dump_one_name =
8352 	TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8353 
8354 cmdline_parse_inst_t cmd_dump_one = {
8355 	.f = cmd_dump_one_parsed,  /* function to call */
8356 	.data = NULL,      /* 2nd arg of func */
8357 	.help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8358 	.tokens = {        /* token list, NULL terminated */
8359 		(void *)&cmd_dump_one_dump,
8360 		(void *)&cmd_dump_one_name,
8361 		NULL,
8362 	},
8363 };
8364 
8365 /* *** Add/Del syn filter *** */
8366 struct cmd_syn_filter_result {
8367 	cmdline_fixed_string_t filter;
8368 	uint8_t port_id;
8369 	cmdline_fixed_string_t ops;
8370 	cmdline_fixed_string_t priority;
8371 	cmdline_fixed_string_t high;
8372 	cmdline_fixed_string_t queue;
8373 	uint16_t queue_id;
8374 };
8375 
8376 static void
8377 cmd_syn_filter_parsed(void *parsed_result,
8378 			__attribute__((unused)) struct cmdline *cl,
8379 			__attribute__((unused)) void *data)
8380 {
8381 	struct cmd_syn_filter_result *res = parsed_result;
8382 	struct rte_eth_syn_filter syn_filter;
8383 	int ret = 0;
8384 
8385 	ret = rte_eth_dev_filter_supported(res->port_id,
8386 					RTE_ETH_FILTER_SYN);
8387 	if (ret < 0) {
8388 		printf("syn filter is not supported on port %u.\n",
8389 				res->port_id);
8390 		return;
8391 	}
8392 
8393 	memset(&syn_filter, 0, sizeof(syn_filter));
8394 
8395 	if (!strcmp(res->ops, "add")) {
8396 		if (!strcmp(res->high, "high"))
8397 			syn_filter.hig_pri = 1;
8398 		else
8399 			syn_filter.hig_pri = 0;
8400 
8401 		syn_filter.queue = res->queue_id;
8402 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8403 						RTE_ETH_FILTER_SYN,
8404 						RTE_ETH_FILTER_ADD,
8405 						&syn_filter);
8406 	} else
8407 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8408 						RTE_ETH_FILTER_SYN,
8409 						RTE_ETH_FILTER_DELETE,
8410 						&syn_filter);
8411 
8412 	if (ret < 0)
8413 		printf("syn filter programming error: (%s)\n",
8414 				strerror(-ret));
8415 }
8416 
8417 cmdline_parse_token_string_t cmd_syn_filter_filter =
8418 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8419 	filter, "syn_filter");
8420 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8421 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8422 	port_id, UINT8);
8423 cmdline_parse_token_string_t cmd_syn_filter_ops =
8424 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8425 	ops, "add#del");
8426 cmdline_parse_token_string_t cmd_syn_filter_priority =
8427 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8428 				priority, "priority");
8429 cmdline_parse_token_string_t cmd_syn_filter_high =
8430 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8431 				high, "high#low");
8432 cmdline_parse_token_string_t cmd_syn_filter_queue =
8433 	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8434 				queue, "queue");
8435 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8436 	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8437 				queue_id, UINT16);
8438 
8439 cmdline_parse_inst_t cmd_syn_filter = {
8440 	.f = cmd_syn_filter_parsed,
8441 	.data = NULL,
8442 	.help_str = "syn_filter <port_id> add|del priority high|low queue "
8443 		"<queue_id>: Add/Delete syn filter",
8444 	.tokens = {
8445 		(void *)&cmd_syn_filter_filter,
8446 		(void *)&cmd_syn_filter_port_id,
8447 		(void *)&cmd_syn_filter_ops,
8448 		(void *)&cmd_syn_filter_priority,
8449 		(void *)&cmd_syn_filter_high,
8450 		(void *)&cmd_syn_filter_queue,
8451 		(void *)&cmd_syn_filter_queue_id,
8452 		NULL,
8453 	},
8454 };
8455 
8456 /* *** ADD/REMOVE A 2tuple FILTER *** */
8457 struct cmd_2tuple_filter_result {
8458 	cmdline_fixed_string_t filter;
8459 	uint8_t  port_id;
8460 	cmdline_fixed_string_t ops;
8461 	cmdline_fixed_string_t dst_port;
8462 	uint16_t dst_port_value;
8463 	cmdline_fixed_string_t protocol;
8464 	uint8_t protocol_value;
8465 	cmdline_fixed_string_t mask;
8466 	uint8_t  mask_value;
8467 	cmdline_fixed_string_t tcp_flags;
8468 	uint8_t tcp_flags_value;
8469 	cmdline_fixed_string_t priority;
8470 	uint8_t  priority_value;
8471 	cmdline_fixed_string_t queue;
8472 	uint16_t  queue_id;
8473 };
8474 
8475 static void
8476 cmd_2tuple_filter_parsed(void *parsed_result,
8477 			__attribute__((unused)) struct cmdline *cl,
8478 			__attribute__((unused)) void *data)
8479 {
8480 	struct rte_eth_ntuple_filter filter;
8481 	struct cmd_2tuple_filter_result *res = parsed_result;
8482 	int ret = 0;
8483 
8484 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8485 	if (ret < 0) {
8486 		printf("ntuple filter is not supported on port %u.\n",
8487 			res->port_id);
8488 		return;
8489 	}
8490 
8491 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8492 
8493 	filter.flags = RTE_2TUPLE_FLAGS;
8494 	filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8495 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8496 	filter.proto = res->protocol_value;
8497 	filter.priority = res->priority_value;
8498 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8499 		printf("nonzero tcp_flags is only meaningful"
8500 			" when protocol is TCP.\n");
8501 		return;
8502 	}
8503 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8504 		printf("invalid TCP flags.\n");
8505 		return;
8506 	}
8507 
8508 	if (res->tcp_flags_value != 0) {
8509 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8510 		filter.tcp_flags = res->tcp_flags_value;
8511 	}
8512 
8513 	/* need convert to big endian. */
8514 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8515 	filter.queue = res->queue_id;
8516 
8517 	if (!strcmp(res->ops, "add"))
8518 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8519 				RTE_ETH_FILTER_NTUPLE,
8520 				RTE_ETH_FILTER_ADD,
8521 				&filter);
8522 	else
8523 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8524 				RTE_ETH_FILTER_NTUPLE,
8525 				RTE_ETH_FILTER_DELETE,
8526 				&filter);
8527 	if (ret < 0)
8528 		printf("2tuple filter programming error: (%s)\n",
8529 			strerror(-ret));
8530 
8531 }
8532 
8533 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
8534 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8535 				 filter, "2tuple_filter");
8536 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
8537 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8538 				port_id, UINT8);
8539 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
8540 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8541 				 ops, "add#del");
8542 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
8543 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8544 				dst_port, "dst_port");
8545 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
8546 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8547 				dst_port_value, UINT16);
8548 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
8549 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8550 				protocol, "protocol");
8551 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
8552 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8553 				protocol_value, UINT8);
8554 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
8555 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8556 				mask, "mask");
8557 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
8558 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8559 				mask_value, INT8);
8560 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
8561 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8562 				tcp_flags, "tcp_flags");
8563 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
8564 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8565 				tcp_flags_value, UINT8);
8566 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
8567 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8568 				priority, "priority");
8569 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
8570 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8571 				priority_value, UINT8);
8572 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
8573 	TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
8574 				queue, "queue");
8575 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
8576 	TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
8577 				queue_id, UINT16);
8578 
8579 cmdline_parse_inst_t cmd_2tuple_filter = {
8580 	.f = cmd_2tuple_filter_parsed,
8581 	.data = NULL,
8582 	.help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
8583 		"<value> mask <value> tcp_flags <value> priority <value> queue "
8584 		"<queue_id>: Add a 2tuple filter",
8585 	.tokens = {
8586 		(void *)&cmd_2tuple_filter_filter,
8587 		(void *)&cmd_2tuple_filter_port_id,
8588 		(void *)&cmd_2tuple_filter_ops,
8589 		(void *)&cmd_2tuple_filter_dst_port,
8590 		(void *)&cmd_2tuple_filter_dst_port_value,
8591 		(void *)&cmd_2tuple_filter_protocol,
8592 		(void *)&cmd_2tuple_filter_protocol_value,
8593 		(void *)&cmd_2tuple_filter_mask,
8594 		(void *)&cmd_2tuple_filter_mask_value,
8595 		(void *)&cmd_2tuple_filter_tcp_flags,
8596 		(void *)&cmd_2tuple_filter_tcp_flags_value,
8597 		(void *)&cmd_2tuple_filter_priority,
8598 		(void *)&cmd_2tuple_filter_priority_value,
8599 		(void *)&cmd_2tuple_filter_queue,
8600 		(void *)&cmd_2tuple_filter_queue_id,
8601 		NULL,
8602 	},
8603 };
8604 
8605 /* *** ADD/REMOVE A 5tuple FILTER *** */
8606 struct cmd_5tuple_filter_result {
8607 	cmdline_fixed_string_t filter;
8608 	uint8_t  port_id;
8609 	cmdline_fixed_string_t ops;
8610 	cmdline_fixed_string_t dst_ip;
8611 	cmdline_ipaddr_t dst_ip_value;
8612 	cmdline_fixed_string_t src_ip;
8613 	cmdline_ipaddr_t src_ip_value;
8614 	cmdline_fixed_string_t dst_port;
8615 	uint16_t dst_port_value;
8616 	cmdline_fixed_string_t src_port;
8617 	uint16_t src_port_value;
8618 	cmdline_fixed_string_t protocol;
8619 	uint8_t protocol_value;
8620 	cmdline_fixed_string_t mask;
8621 	uint8_t  mask_value;
8622 	cmdline_fixed_string_t tcp_flags;
8623 	uint8_t tcp_flags_value;
8624 	cmdline_fixed_string_t priority;
8625 	uint8_t  priority_value;
8626 	cmdline_fixed_string_t queue;
8627 	uint16_t  queue_id;
8628 };
8629 
8630 static void
8631 cmd_5tuple_filter_parsed(void *parsed_result,
8632 			__attribute__((unused)) struct cmdline *cl,
8633 			__attribute__((unused)) void *data)
8634 {
8635 	struct rte_eth_ntuple_filter filter;
8636 	struct cmd_5tuple_filter_result *res = parsed_result;
8637 	int ret = 0;
8638 
8639 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
8640 	if (ret < 0) {
8641 		printf("ntuple filter is not supported on port %u.\n",
8642 			res->port_id);
8643 		return;
8644 	}
8645 
8646 	memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
8647 
8648 	filter.flags = RTE_5TUPLE_FLAGS;
8649 	filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
8650 	filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
8651 	filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
8652 	filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
8653 	filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
8654 	filter.proto = res->protocol_value;
8655 	filter.priority = res->priority_value;
8656 	if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
8657 		printf("nonzero tcp_flags is only meaningful"
8658 			" when protocol is TCP.\n");
8659 		return;
8660 	}
8661 	if (res->tcp_flags_value > TCP_FLAG_ALL) {
8662 		printf("invalid TCP flags.\n");
8663 		return;
8664 	}
8665 
8666 	if (res->tcp_flags_value != 0) {
8667 		filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
8668 		filter.tcp_flags = res->tcp_flags_value;
8669 	}
8670 
8671 	if (res->dst_ip_value.family == AF_INET)
8672 		/* no need to convert, already big endian. */
8673 		filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
8674 	else {
8675 		if (filter.dst_ip_mask == 0) {
8676 			printf("can not support ipv6 involved compare.\n");
8677 			return;
8678 		}
8679 		filter.dst_ip = 0;
8680 	}
8681 
8682 	if (res->src_ip_value.family == AF_INET)
8683 		/* no need to convert, already big endian. */
8684 		filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
8685 	else {
8686 		if (filter.src_ip_mask == 0) {
8687 			printf("can not support ipv6 involved compare.\n");
8688 			return;
8689 		}
8690 		filter.src_ip = 0;
8691 	}
8692 	/* need convert to big endian. */
8693 	filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
8694 	filter.src_port = rte_cpu_to_be_16(res->src_port_value);
8695 	filter.queue = res->queue_id;
8696 
8697 	if (!strcmp(res->ops, "add"))
8698 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8699 				RTE_ETH_FILTER_NTUPLE,
8700 				RTE_ETH_FILTER_ADD,
8701 				&filter);
8702 	else
8703 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8704 				RTE_ETH_FILTER_NTUPLE,
8705 				RTE_ETH_FILTER_DELETE,
8706 				&filter);
8707 	if (ret < 0)
8708 		printf("5tuple filter programming error: (%s)\n",
8709 			strerror(-ret));
8710 }
8711 
8712 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
8713 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8714 				 filter, "5tuple_filter");
8715 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
8716 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8717 				port_id, UINT8);
8718 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
8719 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8720 				 ops, "add#del");
8721 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
8722 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8723 				dst_ip, "dst_ip");
8724 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
8725 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8726 				dst_ip_value);
8727 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
8728 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8729 				src_ip, "src_ip");
8730 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
8731 	TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
8732 				src_ip_value);
8733 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
8734 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8735 				dst_port, "dst_port");
8736 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
8737 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8738 				dst_port_value, UINT16);
8739 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
8740 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8741 				src_port, "src_port");
8742 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
8743 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8744 				src_port_value, UINT16);
8745 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
8746 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8747 				protocol, "protocol");
8748 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
8749 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8750 				protocol_value, UINT8);
8751 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
8752 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8753 				mask, "mask");
8754 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
8755 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8756 				mask_value, INT8);
8757 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
8758 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8759 				tcp_flags, "tcp_flags");
8760 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
8761 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8762 				tcp_flags_value, UINT8);
8763 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
8764 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8765 				priority, "priority");
8766 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
8767 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8768 				priority_value, UINT8);
8769 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
8770 	TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
8771 				queue, "queue");
8772 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
8773 	TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
8774 				queue_id, UINT16);
8775 
8776 cmdline_parse_inst_t cmd_5tuple_filter = {
8777 	.f = cmd_5tuple_filter_parsed,
8778 	.data = NULL,
8779 	.help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
8780 		"src_ip <value> dst_port <value> src_port <value> "
8781 		"protocol <value>  mask <value> tcp_flags <value> "
8782 		"priority <value> queue <queue_id>: Add/Del a 5tuple filter",
8783 	.tokens = {
8784 		(void *)&cmd_5tuple_filter_filter,
8785 		(void *)&cmd_5tuple_filter_port_id,
8786 		(void *)&cmd_5tuple_filter_ops,
8787 		(void *)&cmd_5tuple_filter_dst_ip,
8788 		(void *)&cmd_5tuple_filter_dst_ip_value,
8789 		(void *)&cmd_5tuple_filter_src_ip,
8790 		(void *)&cmd_5tuple_filter_src_ip_value,
8791 		(void *)&cmd_5tuple_filter_dst_port,
8792 		(void *)&cmd_5tuple_filter_dst_port_value,
8793 		(void *)&cmd_5tuple_filter_src_port,
8794 		(void *)&cmd_5tuple_filter_src_port_value,
8795 		(void *)&cmd_5tuple_filter_protocol,
8796 		(void *)&cmd_5tuple_filter_protocol_value,
8797 		(void *)&cmd_5tuple_filter_mask,
8798 		(void *)&cmd_5tuple_filter_mask_value,
8799 		(void *)&cmd_5tuple_filter_tcp_flags,
8800 		(void *)&cmd_5tuple_filter_tcp_flags_value,
8801 		(void *)&cmd_5tuple_filter_priority,
8802 		(void *)&cmd_5tuple_filter_priority_value,
8803 		(void *)&cmd_5tuple_filter_queue,
8804 		(void *)&cmd_5tuple_filter_queue_id,
8805 		NULL,
8806 	},
8807 };
8808 
8809 /* *** ADD/REMOVE A flex FILTER *** */
8810 struct cmd_flex_filter_result {
8811 	cmdline_fixed_string_t filter;
8812 	cmdline_fixed_string_t ops;
8813 	uint8_t port_id;
8814 	cmdline_fixed_string_t len;
8815 	uint8_t len_value;
8816 	cmdline_fixed_string_t bytes;
8817 	cmdline_fixed_string_t bytes_value;
8818 	cmdline_fixed_string_t mask;
8819 	cmdline_fixed_string_t mask_value;
8820 	cmdline_fixed_string_t priority;
8821 	uint8_t priority_value;
8822 	cmdline_fixed_string_t queue;
8823 	uint16_t queue_id;
8824 };
8825 
8826 static int xdigit2val(unsigned char c)
8827 {
8828 	int val;
8829 	if (isdigit(c))
8830 		val = c - '0';
8831 	else if (isupper(c))
8832 		val = c - 'A' + 10;
8833 	else
8834 		val = c - 'a' + 10;
8835 	return val;
8836 }
8837 
8838 static void
8839 cmd_flex_filter_parsed(void *parsed_result,
8840 			  __attribute__((unused)) struct cmdline *cl,
8841 			  __attribute__((unused)) void *data)
8842 {
8843 	int ret = 0;
8844 	struct rte_eth_flex_filter filter;
8845 	struct cmd_flex_filter_result *res = parsed_result;
8846 	char *bytes_ptr, *mask_ptr;
8847 	uint16_t len, i, j = 0;
8848 	char c;
8849 	int val;
8850 	uint8_t byte = 0;
8851 
8852 	if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
8853 		printf("the len exceed the max length 128\n");
8854 		return;
8855 	}
8856 	memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
8857 	filter.len = res->len_value;
8858 	filter.priority = res->priority_value;
8859 	filter.queue = res->queue_id;
8860 	bytes_ptr = res->bytes_value;
8861 	mask_ptr = res->mask_value;
8862 
8863 	 /* translate bytes string to array. */
8864 	if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
8865 		(bytes_ptr[1] == 'X')))
8866 		bytes_ptr += 2;
8867 	len = strnlen(bytes_ptr, res->len_value * 2);
8868 	if (len == 0 || (len % 8 != 0)) {
8869 		printf("please check len and bytes input\n");
8870 		return;
8871 	}
8872 	for (i = 0; i < len; i++) {
8873 		c = bytes_ptr[i];
8874 		if (isxdigit(c) == 0) {
8875 			/* invalid characters. */
8876 			printf("invalid input\n");
8877 			return;
8878 		}
8879 		val = xdigit2val(c);
8880 		if (i % 2) {
8881 			byte |= val;
8882 			filter.bytes[j] = byte;
8883 			printf("bytes[%d]:%02x ", j, filter.bytes[j]);
8884 			j++;
8885 			byte = 0;
8886 		} else
8887 			byte |= val << 4;
8888 	}
8889 	printf("\n");
8890 	 /* translate mask string to uint8_t array. */
8891 	if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
8892 		(mask_ptr[1] == 'X')))
8893 		mask_ptr += 2;
8894 	len = strnlen(mask_ptr, (res->len_value + 3) / 4);
8895 	if (len == 0) {
8896 		printf("invalid input\n");
8897 		return;
8898 	}
8899 	j = 0;
8900 	byte = 0;
8901 	for (i = 0; i < len; i++) {
8902 		c = mask_ptr[i];
8903 		if (isxdigit(c) == 0) {
8904 			/* invalid characters. */
8905 			printf("invalid input\n");
8906 			return;
8907 		}
8908 		val = xdigit2val(c);
8909 		if (i % 2) {
8910 			byte |= val;
8911 			filter.mask[j] = byte;
8912 			printf("mask[%d]:%02x ", j, filter.mask[j]);
8913 			j++;
8914 			byte = 0;
8915 		} else
8916 			byte |= val << 4;
8917 	}
8918 	printf("\n");
8919 
8920 	if (!strcmp(res->ops, "add"))
8921 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8922 				RTE_ETH_FILTER_FLEXIBLE,
8923 				RTE_ETH_FILTER_ADD,
8924 				&filter);
8925 	else
8926 		ret = rte_eth_dev_filter_ctrl(res->port_id,
8927 				RTE_ETH_FILTER_FLEXIBLE,
8928 				RTE_ETH_FILTER_DELETE,
8929 				&filter);
8930 
8931 	if (ret < 0)
8932 		printf("flex filter setting error: (%s)\n", strerror(-ret));
8933 }
8934 
8935 cmdline_parse_token_string_t cmd_flex_filter_filter =
8936 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8937 				filter, "flex_filter");
8938 cmdline_parse_token_num_t cmd_flex_filter_port_id =
8939 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8940 				port_id, UINT8);
8941 cmdline_parse_token_string_t cmd_flex_filter_ops =
8942 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8943 				ops, "add#del");
8944 cmdline_parse_token_string_t cmd_flex_filter_len =
8945 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8946 				len, "len");
8947 cmdline_parse_token_num_t cmd_flex_filter_len_value =
8948 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8949 				len_value, UINT8);
8950 cmdline_parse_token_string_t cmd_flex_filter_bytes =
8951 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8952 				bytes, "bytes");
8953 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
8954 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8955 				bytes_value, NULL);
8956 cmdline_parse_token_string_t cmd_flex_filter_mask =
8957 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8958 				mask, "mask");
8959 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
8960 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8961 				mask_value, NULL);
8962 cmdline_parse_token_string_t cmd_flex_filter_priority =
8963 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8964 				priority, "priority");
8965 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
8966 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8967 				priority_value, UINT8);
8968 cmdline_parse_token_string_t cmd_flex_filter_queue =
8969 	TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
8970 				queue, "queue");
8971 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
8972 	TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
8973 				queue_id, UINT16);
8974 cmdline_parse_inst_t cmd_flex_filter = {
8975 	.f = cmd_flex_filter_parsed,
8976 	.data = NULL,
8977 	.help_str = "flex_filter <port_id> add|del len <value> bytes "
8978 		"<value> mask <value> priority <value> queue <queue_id>: "
8979 		"Add/Del a flex filter",
8980 	.tokens = {
8981 		(void *)&cmd_flex_filter_filter,
8982 		(void *)&cmd_flex_filter_port_id,
8983 		(void *)&cmd_flex_filter_ops,
8984 		(void *)&cmd_flex_filter_len,
8985 		(void *)&cmd_flex_filter_len_value,
8986 		(void *)&cmd_flex_filter_bytes,
8987 		(void *)&cmd_flex_filter_bytes_value,
8988 		(void *)&cmd_flex_filter_mask,
8989 		(void *)&cmd_flex_filter_mask_value,
8990 		(void *)&cmd_flex_filter_priority,
8991 		(void *)&cmd_flex_filter_priority_value,
8992 		(void *)&cmd_flex_filter_queue,
8993 		(void *)&cmd_flex_filter_queue_id,
8994 		NULL,
8995 	},
8996 };
8997 
8998 /* *** Filters Control *** */
8999 
9000 /* *** deal with ethertype filter *** */
9001 struct cmd_ethertype_filter_result {
9002 	cmdline_fixed_string_t filter;
9003 	uint8_t port_id;
9004 	cmdline_fixed_string_t ops;
9005 	cmdline_fixed_string_t mac;
9006 	struct ether_addr mac_addr;
9007 	cmdline_fixed_string_t ethertype;
9008 	uint16_t ethertype_value;
9009 	cmdline_fixed_string_t drop;
9010 	cmdline_fixed_string_t queue;
9011 	uint16_t  queue_id;
9012 };
9013 
9014 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9015 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9016 				 filter, "ethertype_filter");
9017 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9018 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9019 			      port_id, UINT8);
9020 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9021 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9022 				 ops, "add#del");
9023 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9024 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9025 				 mac, "mac_addr#mac_ignr");
9026 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9027 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9028 				     mac_addr);
9029 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9030 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9031 				 ethertype, "ethertype");
9032 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9033 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9034 			      ethertype_value, UINT16);
9035 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9036 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9037 				 drop, "drop#fwd");
9038 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9039 	TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9040 				 queue, "queue");
9041 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9042 	TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9043 			      queue_id, UINT16);
9044 
9045 static void
9046 cmd_ethertype_filter_parsed(void *parsed_result,
9047 			  __attribute__((unused)) struct cmdline *cl,
9048 			  __attribute__((unused)) void *data)
9049 {
9050 	struct cmd_ethertype_filter_result *res = parsed_result;
9051 	struct rte_eth_ethertype_filter filter;
9052 	int ret = 0;
9053 
9054 	ret = rte_eth_dev_filter_supported(res->port_id,
9055 			RTE_ETH_FILTER_ETHERTYPE);
9056 	if (ret < 0) {
9057 		printf("ethertype filter is not supported on port %u.\n",
9058 			res->port_id);
9059 		return;
9060 	}
9061 
9062 	memset(&filter, 0, sizeof(filter));
9063 	if (!strcmp(res->mac, "mac_addr")) {
9064 		filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9065 		rte_memcpy(&filter.mac_addr, &res->mac_addr,
9066 			sizeof(struct ether_addr));
9067 	}
9068 	if (!strcmp(res->drop, "drop"))
9069 		filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9070 	filter.ether_type = res->ethertype_value;
9071 	filter.queue = res->queue_id;
9072 
9073 	if (!strcmp(res->ops, "add"))
9074 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9075 				RTE_ETH_FILTER_ETHERTYPE,
9076 				RTE_ETH_FILTER_ADD,
9077 				&filter);
9078 	else
9079 		ret = rte_eth_dev_filter_ctrl(res->port_id,
9080 				RTE_ETH_FILTER_ETHERTYPE,
9081 				RTE_ETH_FILTER_DELETE,
9082 				&filter);
9083 	if (ret < 0)
9084 		printf("ethertype filter programming error: (%s)\n",
9085 			strerror(-ret));
9086 }
9087 
9088 cmdline_parse_inst_t cmd_ethertype_filter = {
9089 	.f = cmd_ethertype_filter_parsed,
9090 	.data = NULL,
9091 	.help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9092 		"<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9093 		"Add or delete an ethertype filter entry",
9094 	.tokens = {
9095 		(void *)&cmd_ethertype_filter_filter,
9096 		(void *)&cmd_ethertype_filter_port_id,
9097 		(void *)&cmd_ethertype_filter_ops,
9098 		(void *)&cmd_ethertype_filter_mac,
9099 		(void *)&cmd_ethertype_filter_mac_addr,
9100 		(void *)&cmd_ethertype_filter_ethertype,
9101 		(void *)&cmd_ethertype_filter_ethertype_value,
9102 		(void *)&cmd_ethertype_filter_drop,
9103 		(void *)&cmd_ethertype_filter_queue,
9104 		(void *)&cmd_ethertype_filter_queue_id,
9105 		NULL,
9106 	},
9107 };
9108 
9109 /* *** deal with flow director filter *** */
9110 struct cmd_flow_director_result {
9111 	cmdline_fixed_string_t flow_director_filter;
9112 	uint8_t port_id;
9113 	cmdline_fixed_string_t mode;
9114 	cmdline_fixed_string_t mode_value;
9115 	cmdline_fixed_string_t ops;
9116 	cmdline_fixed_string_t flow;
9117 	cmdline_fixed_string_t flow_type;
9118 	cmdline_fixed_string_t ether;
9119 	uint16_t ether_type;
9120 	cmdline_fixed_string_t src;
9121 	cmdline_ipaddr_t ip_src;
9122 	uint16_t port_src;
9123 	cmdline_fixed_string_t dst;
9124 	cmdline_ipaddr_t ip_dst;
9125 	uint16_t port_dst;
9126 	cmdline_fixed_string_t verify_tag;
9127 	uint32_t verify_tag_value;
9128 	cmdline_ipaddr_t tos;
9129 	uint8_t tos_value;
9130 	cmdline_ipaddr_t proto;
9131 	uint8_t proto_value;
9132 	cmdline_ipaddr_t ttl;
9133 	uint8_t ttl_value;
9134 	cmdline_fixed_string_t vlan;
9135 	uint16_t vlan_value;
9136 	cmdline_fixed_string_t flexbytes;
9137 	cmdline_fixed_string_t flexbytes_value;
9138 	cmdline_fixed_string_t pf_vf;
9139 	cmdline_fixed_string_t drop;
9140 	cmdline_fixed_string_t queue;
9141 	uint16_t  queue_id;
9142 	cmdline_fixed_string_t fd_id;
9143 	uint32_t  fd_id_value;
9144 	cmdline_fixed_string_t mac;
9145 	struct ether_addr mac_addr;
9146 	cmdline_fixed_string_t tunnel;
9147 	cmdline_fixed_string_t tunnel_type;
9148 	cmdline_fixed_string_t tunnel_id;
9149 	uint32_t tunnel_id_value;
9150 };
9151 
9152 static inline int
9153 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9154 {
9155 	char s[256];
9156 	const char *p, *p0 = q_arg;
9157 	char *end;
9158 	unsigned long int_fld;
9159 	char *str_fld[max_num];
9160 	int i;
9161 	unsigned size;
9162 	int ret = -1;
9163 
9164 	p = strchr(p0, '(');
9165 	if (p == NULL)
9166 		return -1;
9167 	++p;
9168 	p0 = strchr(p, ')');
9169 	if (p0 == NULL)
9170 		return -1;
9171 
9172 	size = p0 - p;
9173 	if (size >= sizeof(s))
9174 		return -1;
9175 
9176 	snprintf(s, sizeof(s), "%.*s", size, p);
9177 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9178 	if (ret < 0 || ret > max_num)
9179 		return -1;
9180 	for (i = 0; i < ret; i++) {
9181 		errno = 0;
9182 		int_fld = strtoul(str_fld[i], &end, 0);
9183 		if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9184 			return -1;
9185 		flexbytes[i] = (uint8_t)int_fld;
9186 	}
9187 	return ret;
9188 }
9189 
9190 static uint16_t
9191 str2flowtype(char *string)
9192 {
9193 	uint8_t i = 0;
9194 	static const struct {
9195 		char str[32];
9196 		uint16_t type;
9197 	} flowtype_str[] = {
9198 		{"raw", RTE_ETH_FLOW_RAW},
9199 		{"ipv4", RTE_ETH_FLOW_IPV4},
9200 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9201 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9202 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9203 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9204 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9205 		{"ipv6", RTE_ETH_FLOW_IPV6},
9206 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9207 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9208 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9209 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9210 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9211 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9212 	};
9213 
9214 	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9215 		if (!strcmp(flowtype_str[i].str, string))
9216 			return flowtype_str[i].type;
9217 	}
9218 
9219 	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9220 		return (uint16_t)atoi(string);
9221 
9222 	return RTE_ETH_FLOW_UNKNOWN;
9223 }
9224 
9225 static enum rte_eth_fdir_tunnel_type
9226 str2fdir_tunneltype(char *string)
9227 {
9228 	uint8_t i = 0;
9229 
9230 	static const struct {
9231 		char str[32];
9232 		enum rte_eth_fdir_tunnel_type type;
9233 	} tunneltype_str[] = {
9234 		{"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9235 		{"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9236 	};
9237 
9238 	for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9239 		if (!strcmp(tunneltype_str[i].str, string))
9240 			return tunneltype_str[i].type;
9241 	}
9242 	return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9243 }
9244 
9245 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9246 do { \
9247 	if ((ip_addr).family == AF_INET) \
9248 		(ip) = (ip_addr).addr.ipv4.s_addr; \
9249 	else { \
9250 		printf("invalid parameter.\n"); \
9251 		return; \
9252 	} \
9253 } while (0)
9254 
9255 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9256 do { \
9257 	if ((ip_addr).family == AF_INET6) \
9258 		rte_memcpy(&(ip), \
9259 				 &((ip_addr).addr.ipv6), \
9260 				 sizeof(struct in6_addr)); \
9261 	else { \
9262 		printf("invalid parameter.\n"); \
9263 		return; \
9264 	} \
9265 } while (0)
9266 
9267 static void
9268 cmd_flow_director_filter_parsed(void *parsed_result,
9269 			  __attribute__((unused)) struct cmdline *cl,
9270 			  __attribute__((unused)) void *data)
9271 {
9272 	struct cmd_flow_director_result *res = parsed_result;
9273 	struct rte_eth_fdir_filter entry;
9274 	uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9275 	char *end;
9276 	unsigned long vf_id;
9277 	int ret = 0;
9278 
9279 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9280 	if (ret < 0) {
9281 		printf("flow director is not supported on port %u.\n",
9282 			res->port_id);
9283 		return;
9284 	}
9285 	memset(flexbytes, 0, sizeof(flexbytes));
9286 	memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9287 
9288 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9289 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9290 			printf("Please set mode to MAC-VLAN.\n");
9291 			return;
9292 		}
9293 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9294 		if (strcmp(res->mode_value, "Tunnel")) {
9295 			printf("Please set mode to Tunnel.\n");
9296 			return;
9297 		}
9298 	} else {
9299 		if (strcmp(res->mode_value, "IP")) {
9300 			printf("Please set mode to IP.\n");
9301 			return;
9302 		}
9303 		entry.input.flow_type = str2flowtype(res->flow_type);
9304 	}
9305 
9306 	ret = parse_flexbytes(res->flexbytes_value,
9307 					flexbytes,
9308 					RTE_ETH_FDIR_MAX_FLEXLEN);
9309 	if (ret < 0) {
9310 		printf("error: Cannot parse flexbytes input.\n");
9311 		return;
9312 	}
9313 
9314 	switch (entry.input.flow_type) {
9315 	case RTE_ETH_FLOW_FRAG_IPV4:
9316 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9317 		entry.input.flow.ip4_flow.proto = res->proto_value;
9318 		/* fall-through */
9319 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9320 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9321 		IPV4_ADDR_TO_UINT(res->ip_dst,
9322 			entry.input.flow.ip4_flow.dst_ip);
9323 		IPV4_ADDR_TO_UINT(res->ip_src,
9324 			entry.input.flow.ip4_flow.src_ip);
9325 		entry.input.flow.ip4_flow.tos = res->tos_value;
9326 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
9327 		/* need convert to big endian. */
9328 		entry.input.flow.udp4_flow.dst_port =
9329 				rte_cpu_to_be_16(res->port_dst);
9330 		entry.input.flow.udp4_flow.src_port =
9331 				rte_cpu_to_be_16(res->port_src);
9332 		break;
9333 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9334 		IPV4_ADDR_TO_UINT(res->ip_dst,
9335 			entry.input.flow.sctp4_flow.ip.dst_ip);
9336 		IPV4_ADDR_TO_UINT(res->ip_src,
9337 			entry.input.flow.sctp4_flow.ip.src_ip);
9338 		entry.input.flow.ip4_flow.tos = res->tos_value;
9339 		entry.input.flow.ip4_flow.ttl = res->ttl_value;
9340 		/* need convert to big endian. */
9341 		entry.input.flow.sctp4_flow.dst_port =
9342 				rte_cpu_to_be_16(res->port_dst);
9343 		entry.input.flow.sctp4_flow.src_port =
9344 				rte_cpu_to_be_16(res->port_src);
9345 		entry.input.flow.sctp4_flow.verify_tag =
9346 				rte_cpu_to_be_32(res->verify_tag_value);
9347 		break;
9348 	case RTE_ETH_FLOW_FRAG_IPV6:
9349 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9350 		entry.input.flow.ipv6_flow.proto = res->proto_value;
9351 		/* fall-through */
9352 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9353 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9354 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
9355 			entry.input.flow.ipv6_flow.dst_ip);
9356 		IPV6_ADDR_TO_ARRAY(res->ip_src,
9357 			entry.input.flow.ipv6_flow.src_ip);
9358 		entry.input.flow.ipv6_flow.tc = res->tos_value;
9359 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9360 		/* need convert to big endian. */
9361 		entry.input.flow.udp6_flow.dst_port =
9362 				rte_cpu_to_be_16(res->port_dst);
9363 		entry.input.flow.udp6_flow.src_port =
9364 				rte_cpu_to_be_16(res->port_src);
9365 		break;
9366 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9367 		IPV6_ADDR_TO_ARRAY(res->ip_dst,
9368 			entry.input.flow.sctp6_flow.ip.dst_ip);
9369 		IPV6_ADDR_TO_ARRAY(res->ip_src,
9370 			entry.input.flow.sctp6_flow.ip.src_ip);
9371 		entry.input.flow.ipv6_flow.tc = res->tos_value;
9372 		entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9373 		/* need convert to big endian. */
9374 		entry.input.flow.sctp6_flow.dst_port =
9375 				rte_cpu_to_be_16(res->port_dst);
9376 		entry.input.flow.sctp6_flow.src_port =
9377 				rte_cpu_to_be_16(res->port_src);
9378 		entry.input.flow.sctp6_flow.verify_tag =
9379 				rte_cpu_to_be_32(res->verify_tag_value);
9380 		break;
9381 	case RTE_ETH_FLOW_L2_PAYLOAD:
9382 		entry.input.flow.l2_flow.ether_type =
9383 			rte_cpu_to_be_16(res->ether_type);
9384 		break;
9385 	default:
9386 		break;
9387 	}
9388 
9389 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
9390 		rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
9391 				 &res->mac_addr,
9392 				 sizeof(struct ether_addr));
9393 
9394 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9395 		rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
9396 				 &res->mac_addr,
9397 				 sizeof(struct ether_addr));
9398 		entry.input.flow.tunnel_flow.tunnel_type =
9399 			str2fdir_tunneltype(res->tunnel_type);
9400 		entry.input.flow.tunnel_flow.tunnel_id =
9401 			rte_cpu_to_be_32(res->tunnel_id_value);
9402 	}
9403 
9404 	rte_memcpy(entry.input.flow_ext.flexbytes,
9405 		   flexbytes,
9406 		   RTE_ETH_FDIR_MAX_FLEXLEN);
9407 
9408 	entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
9409 
9410 	entry.action.flex_off = 0;  /*use 0 by default */
9411 	if (!strcmp(res->drop, "drop"))
9412 		entry.action.behavior = RTE_ETH_FDIR_REJECT;
9413 	else
9414 		entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
9415 
9416 	if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
9417 	    fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9418 		if (!strcmp(res->pf_vf, "pf"))
9419 			entry.input.flow_ext.is_vf = 0;
9420 		else if (!strncmp(res->pf_vf, "vf", 2)) {
9421 			struct rte_eth_dev_info dev_info;
9422 
9423 			memset(&dev_info, 0, sizeof(dev_info));
9424 			rte_eth_dev_info_get(res->port_id, &dev_info);
9425 			errno = 0;
9426 			vf_id = strtoul(res->pf_vf + 2, &end, 10);
9427 			if (errno != 0 || *end != '\0' ||
9428 			    vf_id >= dev_info.max_vfs) {
9429 				printf("invalid parameter %s.\n", res->pf_vf);
9430 				return;
9431 			}
9432 			entry.input.flow_ext.is_vf = 1;
9433 			entry.input.flow_ext.dst_id = (uint16_t)vf_id;
9434 		} else {
9435 			printf("invalid parameter %s.\n", res->pf_vf);
9436 			return;
9437 		}
9438 	}
9439 
9440 	/* set to report FD ID by default */
9441 	entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
9442 	entry.action.rx_queue = res->queue_id;
9443 	entry.soft_id = res->fd_id_value;
9444 	if (!strcmp(res->ops, "add"))
9445 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9446 					     RTE_ETH_FILTER_ADD, &entry);
9447 	else if (!strcmp(res->ops, "del"))
9448 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9449 					     RTE_ETH_FILTER_DELETE, &entry);
9450 	else
9451 		ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9452 					     RTE_ETH_FILTER_UPDATE, &entry);
9453 	if (ret < 0)
9454 		printf("flow director programming error: (%s)\n",
9455 			strerror(-ret));
9456 }
9457 
9458 cmdline_parse_token_string_t cmd_flow_director_filter =
9459 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9460 				 flow_director_filter, "flow_director_filter");
9461 cmdline_parse_token_num_t cmd_flow_director_port_id =
9462 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9463 			      port_id, UINT8);
9464 cmdline_parse_token_string_t cmd_flow_director_ops =
9465 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9466 				 ops, "add#del#update");
9467 cmdline_parse_token_string_t cmd_flow_director_flow =
9468 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9469 				 flow, "flow");
9470 cmdline_parse_token_string_t cmd_flow_director_flow_type =
9471 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9472 		flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
9473 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
9474 cmdline_parse_token_string_t cmd_flow_director_ether =
9475 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9476 				 ether, "ether");
9477 cmdline_parse_token_num_t cmd_flow_director_ether_type =
9478 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9479 			      ether_type, UINT16);
9480 cmdline_parse_token_string_t cmd_flow_director_src =
9481 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9482 				 src, "src");
9483 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
9484 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9485 				 ip_src);
9486 cmdline_parse_token_num_t cmd_flow_director_port_src =
9487 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9488 			      port_src, UINT16);
9489 cmdline_parse_token_string_t cmd_flow_director_dst =
9490 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9491 				 dst, "dst");
9492 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
9493 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
9494 				 ip_dst);
9495 cmdline_parse_token_num_t cmd_flow_director_port_dst =
9496 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9497 			      port_dst, UINT16);
9498 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
9499 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9500 				  verify_tag, "verify_tag");
9501 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
9502 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9503 			      verify_tag_value, UINT32);
9504 cmdline_parse_token_string_t cmd_flow_director_tos =
9505 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9506 				 tos, "tos");
9507 cmdline_parse_token_num_t cmd_flow_director_tos_value =
9508 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9509 			      tos_value, UINT8);
9510 cmdline_parse_token_string_t cmd_flow_director_proto =
9511 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9512 				 proto, "proto");
9513 cmdline_parse_token_num_t cmd_flow_director_proto_value =
9514 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9515 			      proto_value, UINT8);
9516 cmdline_parse_token_string_t cmd_flow_director_ttl =
9517 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9518 				 ttl, "ttl");
9519 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
9520 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9521 			      ttl_value, UINT8);
9522 cmdline_parse_token_string_t cmd_flow_director_vlan =
9523 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9524 				 vlan, "vlan");
9525 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
9526 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9527 			      vlan_value, UINT16);
9528 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
9529 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9530 				 flexbytes, "flexbytes");
9531 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
9532 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9533 			      flexbytes_value, NULL);
9534 cmdline_parse_token_string_t cmd_flow_director_drop =
9535 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9536 				 drop, "drop#fwd");
9537 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
9538 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9539 			      pf_vf, NULL);
9540 cmdline_parse_token_string_t cmd_flow_director_queue =
9541 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9542 				 queue, "queue");
9543 cmdline_parse_token_num_t cmd_flow_director_queue_id =
9544 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9545 			      queue_id, UINT16);
9546 cmdline_parse_token_string_t cmd_flow_director_fd_id =
9547 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9548 				 fd_id, "fd_id");
9549 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
9550 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9551 			      fd_id_value, UINT32);
9552 
9553 cmdline_parse_token_string_t cmd_flow_director_mode =
9554 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9555 				 mode, "mode");
9556 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
9557 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9558 				 mode_value, "IP");
9559 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
9560 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9561 				 mode_value, "MAC-VLAN");
9562 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
9563 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9564 				 mode_value, "Tunnel");
9565 cmdline_parse_token_string_t cmd_flow_director_mac =
9566 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9567 				 mac, "mac");
9568 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
9569 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
9570 				    mac_addr);
9571 cmdline_parse_token_string_t cmd_flow_director_tunnel =
9572 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9573 				 tunnel, "tunnel");
9574 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
9575 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9576 				 tunnel_type, "NVGRE#VxLAN");
9577 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
9578 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
9579 				 tunnel_id, "tunnel-id");
9580 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
9581 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
9582 			      tunnel_id_value, UINT32);
9583 
9584 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
9585 	.f = cmd_flow_director_filter_parsed,
9586 	.data = NULL,
9587 	.help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
9588 		" ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
9589 		"ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
9590 		"l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
9591 		"proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
9592 		"flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> "
9593 		"fd_id <fd_id_value>: "
9594 		"Add or delete an ip flow director entry on NIC",
9595 	.tokens = {
9596 		(void *)&cmd_flow_director_filter,
9597 		(void *)&cmd_flow_director_port_id,
9598 		(void *)&cmd_flow_director_mode,
9599 		(void *)&cmd_flow_director_mode_ip,
9600 		(void *)&cmd_flow_director_ops,
9601 		(void *)&cmd_flow_director_flow,
9602 		(void *)&cmd_flow_director_flow_type,
9603 		(void *)&cmd_flow_director_src,
9604 		(void *)&cmd_flow_director_ip_src,
9605 		(void *)&cmd_flow_director_dst,
9606 		(void *)&cmd_flow_director_ip_dst,
9607 		(void *)&cmd_flow_director_tos,
9608 		(void *)&cmd_flow_director_tos_value,
9609 		(void *)&cmd_flow_director_proto,
9610 		(void *)&cmd_flow_director_proto_value,
9611 		(void *)&cmd_flow_director_ttl,
9612 		(void *)&cmd_flow_director_ttl_value,
9613 		(void *)&cmd_flow_director_vlan,
9614 		(void *)&cmd_flow_director_vlan_value,
9615 		(void *)&cmd_flow_director_flexbytes,
9616 		(void *)&cmd_flow_director_flexbytes_value,
9617 		(void *)&cmd_flow_director_drop,
9618 		(void *)&cmd_flow_director_pf_vf,
9619 		(void *)&cmd_flow_director_queue,
9620 		(void *)&cmd_flow_director_queue_id,
9621 		(void *)&cmd_flow_director_fd_id,
9622 		(void *)&cmd_flow_director_fd_id_value,
9623 		NULL,
9624 	},
9625 };
9626 
9627 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
9628 	.f = cmd_flow_director_filter_parsed,
9629 	.data = NULL,
9630 	.help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
9631 		"director entry on NIC",
9632 	.tokens = {
9633 		(void *)&cmd_flow_director_filter,
9634 		(void *)&cmd_flow_director_port_id,
9635 		(void *)&cmd_flow_director_mode,
9636 		(void *)&cmd_flow_director_mode_ip,
9637 		(void *)&cmd_flow_director_ops,
9638 		(void *)&cmd_flow_director_flow,
9639 		(void *)&cmd_flow_director_flow_type,
9640 		(void *)&cmd_flow_director_src,
9641 		(void *)&cmd_flow_director_ip_src,
9642 		(void *)&cmd_flow_director_port_src,
9643 		(void *)&cmd_flow_director_dst,
9644 		(void *)&cmd_flow_director_ip_dst,
9645 		(void *)&cmd_flow_director_port_dst,
9646 		(void *)&cmd_flow_director_tos,
9647 		(void *)&cmd_flow_director_tos_value,
9648 		(void *)&cmd_flow_director_ttl,
9649 		(void *)&cmd_flow_director_ttl_value,
9650 		(void *)&cmd_flow_director_vlan,
9651 		(void *)&cmd_flow_director_vlan_value,
9652 		(void *)&cmd_flow_director_flexbytes,
9653 		(void *)&cmd_flow_director_flexbytes_value,
9654 		(void *)&cmd_flow_director_drop,
9655 		(void *)&cmd_flow_director_pf_vf,
9656 		(void *)&cmd_flow_director_queue,
9657 		(void *)&cmd_flow_director_queue_id,
9658 		(void *)&cmd_flow_director_fd_id,
9659 		(void *)&cmd_flow_director_fd_id_value,
9660 		NULL,
9661 	},
9662 };
9663 
9664 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
9665 	.f = cmd_flow_director_filter_parsed,
9666 	.data = NULL,
9667 	.help_str = "flow_director_filter ... : Add or delete a sctp flow "
9668 		"director entry on NIC",
9669 	.tokens = {
9670 		(void *)&cmd_flow_director_filter,
9671 		(void *)&cmd_flow_director_port_id,
9672 		(void *)&cmd_flow_director_mode,
9673 		(void *)&cmd_flow_director_mode_ip,
9674 		(void *)&cmd_flow_director_ops,
9675 		(void *)&cmd_flow_director_flow,
9676 		(void *)&cmd_flow_director_flow_type,
9677 		(void *)&cmd_flow_director_src,
9678 		(void *)&cmd_flow_director_ip_src,
9679 		(void *)&cmd_flow_director_port_dst,
9680 		(void *)&cmd_flow_director_dst,
9681 		(void *)&cmd_flow_director_ip_dst,
9682 		(void *)&cmd_flow_director_port_dst,
9683 		(void *)&cmd_flow_director_verify_tag,
9684 		(void *)&cmd_flow_director_verify_tag_value,
9685 		(void *)&cmd_flow_director_tos,
9686 		(void *)&cmd_flow_director_tos_value,
9687 		(void *)&cmd_flow_director_ttl,
9688 		(void *)&cmd_flow_director_ttl_value,
9689 		(void *)&cmd_flow_director_vlan,
9690 		(void *)&cmd_flow_director_vlan_value,
9691 		(void *)&cmd_flow_director_flexbytes,
9692 		(void *)&cmd_flow_director_flexbytes_value,
9693 		(void *)&cmd_flow_director_drop,
9694 		(void *)&cmd_flow_director_pf_vf,
9695 		(void *)&cmd_flow_director_queue,
9696 		(void *)&cmd_flow_director_queue_id,
9697 		(void *)&cmd_flow_director_fd_id,
9698 		(void *)&cmd_flow_director_fd_id_value,
9699 		NULL,
9700 	},
9701 };
9702 
9703 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
9704 	.f = cmd_flow_director_filter_parsed,
9705 	.data = NULL,
9706 	.help_str = "flow_director_filter ... : Add or delete a L2 flow "
9707 		"director entry on NIC",
9708 	.tokens = {
9709 		(void *)&cmd_flow_director_filter,
9710 		(void *)&cmd_flow_director_port_id,
9711 		(void *)&cmd_flow_director_mode,
9712 		(void *)&cmd_flow_director_mode_ip,
9713 		(void *)&cmd_flow_director_ops,
9714 		(void *)&cmd_flow_director_flow,
9715 		(void *)&cmd_flow_director_flow_type,
9716 		(void *)&cmd_flow_director_ether,
9717 		(void *)&cmd_flow_director_ether_type,
9718 		(void *)&cmd_flow_director_flexbytes,
9719 		(void *)&cmd_flow_director_flexbytes_value,
9720 		(void *)&cmd_flow_director_drop,
9721 		(void *)&cmd_flow_director_pf_vf,
9722 		(void *)&cmd_flow_director_queue,
9723 		(void *)&cmd_flow_director_queue_id,
9724 		(void *)&cmd_flow_director_fd_id,
9725 		(void *)&cmd_flow_director_fd_id_value,
9726 		NULL,
9727 	},
9728 };
9729 
9730 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
9731 	.f = cmd_flow_director_filter_parsed,
9732 	.data = NULL,
9733 	.help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
9734 		"director entry on NIC",
9735 	.tokens = {
9736 		(void *)&cmd_flow_director_filter,
9737 		(void *)&cmd_flow_director_port_id,
9738 		(void *)&cmd_flow_director_mode,
9739 		(void *)&cmd_flow_director_mode_mac_vlan,
9740 		(void *)&cmd_flow_director_ops,
9741 		(void *)&cmd_flow_director_mac,
9742 		(void *)&cmd_flow_director_mac_addr,
9743 		(void *)&cmd_flow_director_vlan,
9744 		(void *)&cmd_flow_director_vlan_value,
9745 		(void *)&cmd_flow_director_flexbytes,
9746 		(void *)&cmd_flow_director_flexbytes_value,
9747 		(void *)&cmd_flow_director_drop,
9748 		(void *)&cmd_flow_director_queue,
9749 		(void *)&cmd_flow_director_queue_id,
9750 		(void *)&cmd_flow_director_fd_id,
9751 		(void *)&cmd_flow_director_fd_id_value,
9752 		NULL,
9753 	},
9754 };
9755 
9756 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
9757 	.f = cmd_flow_director_filter_parsed,
9758 	.data = NULL,
9759 	.help_str = "flow_director_filter ... : Add or delete a tunnel flow "
9760 		"director entry on NIC",
9761 	.tokens = {
9762 		(void *)&cmd_flow_director_filter,
9763 		(void *)&cmd_flow_director_port_id,
9764 		(void *)&cmd_flow_director_mode,
9765 		(void *)&cmd_flow_director_mode_tunnel,
9766 		(void *)&cmd_flow_director_ops,
9767 		(void *)&cmd_flow_director_mac,
9768 		(void *)&cmd_flow_director_mac_addr,
9769 		(void *)&cmd_flow_director_vlan,
9770 		(void *)&cmd_flow_director_vlan_value,
9771 		(void *)&cmd_flow_director_tunnel,
9772 		(void *)&cmd_flow_director_tunnel_type,
9773 		(void *)&cmd_flow_director_tunnel_id,
9774 		(void *)&cmd_flow_director_tunnel_id_value,
9775 		(void *)&cmd_flow_director_flexbytes,
9776 		(void *)&cmd_flow_director_flexbytes_value,
9777 		(void *)&cmd_flow_director_drop,
9778 		(void *)&cmd_flow_director_queue,
9779 		(void *)&cmd_flow_director_queue_id,
9780 		(void *)&cmd_flow_director_fd_id,
9781 		(void *)&cmd_flow_director_fd_id_value,
9782 		NULL,
9783 	},
9784 };
9785 
9786 struct cmd_flush_flow_director_result {
9787 	cmdline_fixed_string_t flush_flow_director;
9788 	uint8_t port_id;
9789 };
9790 
9791 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
9792 	TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
9793 				 flush_flow_director, "flush_flow_director");
9794 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
9795 	TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
9796 			      port_id, UINT8);
9797 
9798 static void
9799 cmd_flush_flow_director_parsed(void *parsed_result,
9800 			  __attribute__((unused)) struct cmdline *cl,
9801 			  __attribute__((unused)) void *data)
9802 {
9803 	struct cmd_flow_director_result *res = parsed_result;
9804 	int ret = 0;
9805 
9806 	ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9807 	if (ret < 0) {
9808 		printf("flow director is not supported on port %u.\n",
9809 			res->port_id);
9810 		return;
9811 	}
9812 
9813 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9814 			RTE_ETH_FILTER_FLUSH, NULL);
9815 	if (ret < 0)
9816 		printf("flow director table flushing error: (%s)\n",
9817 			strerror(-ret));
9818 }
9819 
9820 cmdline_parse_inst_t cmd_flush_flow_director = {
9821 	.f = cmd_flush_flow_director_parsed,
9822 	.data = NULL,
9823 	.help_str = "flush_flow_director <port_id>: "
9824 		"Flush all flow director entries of a device on NIC",
9825 	.tokens = {
9826 		(void *)&cmd_flush_flow_director_flush,
9827 		(void *)&cmd_flush_flow_director_port_id,
9828 		NULL,
9829 	},
9830 };
9831 
9832 /* *** deal with flow director mask *** */
9833 struct cmd_flow_director_mask_result {
9834 	cmdline_fixed_string_t flow_director_mask;
9835 	uint8_t port_id;
9836 	cmdline_fixed_string_t mode;
9837 	cmdline_fixed_string_t mode_value;
9838 	cmdline_fixed_string_t vlan;
9839 	uint16_t vlan_mask;
9840 	cmdline_fixed_string_t src_mask;
9841 	cmdline_ipaddr_t ipv4_src;
9842 	cmdline_ipaddr_t ipv6_src;
9843 	uint16_t port_src;
9844 	cmdline_fixed_string_t dst_mask;
9845 	cmdline_ipaddr_t ipv4_dst;
9846 	cmdline_ipaddr_t ipv6_dst;
9847 	uint16_t port_dst;
9848 	cmdline_fixed_string_t mac;
9849 	uint8_t mac_addr_byte_mask;
9850 	cmdline_fixed_string_t tunnel_id;
9851 	uint32_t tunnel_id_mask;
9852 	cmdline_fixed_string_t tunnel_type;
9853 	uint8_t tunnel_type_mask;
9854 };
9855 
9856 static void
9857 cmd_flow_director_mask_parsed(void *parsed_result,
9858 			  __attribute__((unused)) struct cmdline *cl,
9859 			  __attribute__((unused)) void *data)
9860 {
9861 	struct cmd_flow_director_mask_result *res = parsed_result;
9862 	struct rte_eth_fdir_masks *mask;
9863 	struct rte_port *port;
9864 
9865 	if (res->port_id > nb_ports) {
9866 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9867 		return;
9868 	}
9869 
9870 	port = &ports[res->port_id];
9871 	/** Check if the port is not started **/
9872 	if (port->port_status != RTE_PORT_STOPPED) {
9873 		printf("Please stop port %d first\n", res->port_id);
9874 		return;
9875 	}
9876 
9877 	mask = &port->dev_conf.fdir_conf.mask;
9878 
9879 	if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9880 		if (strcmp(res->mode_value, "MAC-VLAN")) {
9881 			printf("Please set mode to MAC-VLAN.\n");
9882 			return;
9883 		}
9884 
9885 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9886 	} else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9887 		if (strcmp(res->mode_value, "Tunnel")) {
9888 			printf("Please set mode to Tunnel.\n");
9889 			return;
9890 		}
9891 
9892 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9893 		mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
9894 		mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
9895 		mask->tunnel_type_mask = res->tunnel_type_mask;
9896 	} else {
9897 		if (strcmp(res->mode_value, "IP")) {
9898 			printf("Please set mode to IP.\n");
9899 			return;
9900 		}
9901 
9902 		mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
9903 		IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
9904 		IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
9905 		IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
9906 		IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
9907 		mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
9908 		mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
9909 	}
9910 
9911 	cmd_reconfig_device_queue(res->port_id, 1, 1);
9912 }
9913 
9914 cmdline_parse_token_string_t cmd_flow_director_mask =
9915 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9916 				 flow_director_mask, "flow_director_mask");
9917 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
9918 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9919 			      port_id, UINT8);
9920 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
9921 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9922 				 vlan, "vlan");
9923 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
9924 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9925 			      vlan_mask, UINT16);
9926 cmdline_parse_token_string_t cmd_flow_director_mask_src =
9927 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9928 				 src_mask, "src_mask");
9929 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
9930 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9931 				 ipv4_src);
9932 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
9933 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9934 				 ipv6_src);
9935 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
9936 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9937 			      port_src, UINT16);
9938 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
9939 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9940 				 dst_mask, "dst_mask");
9941 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
9942 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9943 				 ipv4_dst);
9944 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
9945 	TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
9946 				 ipv6_dst);
9947 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
9948 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9949 			      port_dst, UINT16);
9950 
9951 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
9952 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9953 				 mode, "mode");
9954 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
9955 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9956 				 mode_value, "IP");
9957 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
9958 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9959 				 mode_value, "MAC-VLAN");
9960 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
9961 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9962 				 mode_value, "Tunnel");
9963 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
9964 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9965 				 mac, "mac");
9966 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
9967 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9968 			      mac_addr_byte_mask, UINT8);
9969 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
9970 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9971 				 tunnel_type, "tunnel-type");
9972 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
9973 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9974 			      tunnel_type_mask, UINT8);
9975 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
9976 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
9977 				 tunnel_id, "tunnel-id");
9978 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
9979 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
9980 			      tunnel_id_mask, UINT32);
9981 
9982 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
9983 	.f = cmd_flow_director_mask_parsed,
9984 	.data = NULL,
9985 	.help_str = "flow_director_mask ... : "
9986 		"Set IP mode flow director's mask on NIC",
9987 	.tokens = {
9988 		(void *)&cmd_flow_director_mask,
9989 		(void *)&cmd_flow_director_mask_port_id,
9990 		(void *)&cmd_flow_director_mask_mode,
9991 		(void *)&cmd_flow_director_mask_mode_ip,
9992 		(void *)&cmd_flow_director_mask_vlan,
9993 		(void *)&cmd_flow_director_mask_vlan_value,
9994 		(void *)&cmd_flow_director_mask_src,
9995 		(void *)&cmd_flow_director_mask_ipv4_src,
9996 		(void *)&cmd_flow_director_mask_ipv6_src,
9997 		(void *)&cmd_flow_director_mask_port_src,
9998 		(void *)&cmd_flow_director_mask_dst,
9999 		(void *)&cmd_flow_director_mask_ipv4_dst,
10000 		(void *)&cmd_flow_director_mask_ipv6_dst,
10001 		(void *)&cmd_flow_director_mask_port_dst,
10002 		NULL,
10003 	},
10004 };
10005 
10006 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10007 	.f = cmd_flow_director_mask_parsed,
10008 	.data = NULL,
10009 	.help_str = "flow_director_mask ... : Set MAC VLAN mode "
10010 		"flow director's mask on NIC",
10011 	.tokens = {
10012 		(void *)&cmd_flow_director_mask,
10013 		(void *)&cmd_flow_director_mask_port_id,
10014 		(void *)&cmd_flow_director_mask_mode,
10015 		(void *)&cmd_flow_director_mask_mode_mac_vlan,
10016 		(void *)&cmd_flow_director_mask_vlan,
10017 		(void *)&cmd_flow_director_mask_vlan_value,
10018 		NULL,
10019 	},
10020 };
10021 
10022 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10023 	.f = cmd_flow_director_mask_parsed,
10024 	.data = NULL,
10025 	.help_str = "flow_director_mask ... : Set tunnel mode "
10026 		"flow director's mask on NIC",
10027 	.tokens = {
10028 		(void *)&cmd_flow_director_mask,
10029 		(void *)&cmd_flow_director_mask_port_id,
10030 		(void *)&cmd_flow_director_mask_mode,
10031 		(void *)&cmd_flow_director_mask_mode_tunnel,
10032 		(void *)&cmd_flow_director_mask_vlan,
10033 		(void *)&cmd_flow_director_mask_vlan_value,
10034 		(void *)&cmd_flow_director_mask_mac,
10035 		(void *)&cmd_flow_director_mask_mac_value,
10036 		(void *)&cmd_flow_director_mask_tunnel_type,
10037 		(void *)&cmd_flow_director_mask_tunnel_type_value,
10038 		(void *)&cmd_flow_director_mask_tunnel_id,
10039 		(void *)&cmd_flow_director_mask_tunnel_id_value,
10040 		NULL,
10041 	},
10042 };
10043 
10044 /* *** deal with flow director mask on flexible payload *** */
10045 struct cmd_flow_director_flex_mask_result {
10046 	cmdline_fixed_string_t flow_director_flexmask;
10047 	uint8_t port_id;
10048 	cmdline_fixed_string_t flow;
10049 	cmdline_fixed_string_t flow_type;
10050 	cmdline_fixed_string_t mask;
10051 };
10052 
10053 static void
10054 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10055 			  __attribute__((unused)) struct cmdline *cl,
10056 			  __attribute__((unused)) void *data)
10057 {
10058 	struct cmd_flow_director_flex_mask_result *res = parsed_result;
10059 	struct rte_eth_fdir_info fdir_info;
10060 	struct rte_eth_fdir_flex_mask flex_mask;
10061 	struct rte_port *port;
10062 	uint32_t flow_type_mask;
10063 	uint16_t i;
10064 	int ret;
10065 
10066 	if (res->port_id > nb_ports) {
10067 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10068 		return;
10069 	}
10070 
10071 	port = &ports[res->port_id];
10072 	/** Check if the port is not started **/
10073 	if (port->port_status != RTE_PORT_STOPPED) {
10074 		printf("Please stop port %d first\n", res->port_id);
10075 		return;
10076 	}
10077 
10078 	memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10079 	ret = parse_flexbytes(res->mask,
10080 			flex_mask.mask,
10081 			RTE_ETH_FDIR_MAX_FLEXLEN);
10082 	if (ret < 0) {
10083 		printf("error: Cannot parse mask input.\n");
10084 		return;
10085 	}
10086 
10087 	memset(&fdir_info, 0, sizeof(fdir_info));
10088 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10089 				RTE_ETH_FILTER_INFO, &fdir_info);
10090 	if (ret < 0) {
10091 		printf("Cannot get FDir filter info\n");
10092 		return;
10093 	}
10094 
10095 	if (!strcmp(res->flow_type, "none")) {
10096 		/* means don't specify the flow type */
10097 		flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10098 		for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10099 			memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10100 			       0, sizeof(struct rte_eth_fdir_flex_mask));
10101 		port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10102 		rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10103 				 &flex_mask,
10104 				 sizeof(struct rte_eth_fdir_flex_mask));
10105 		cmd_reconfig_device_queue(res->port_id, 1, 1);
10106 		return;
10107 	}
10108 	flow_type_mask = fdir_info.flow_types_mask[0];
10109 	if (!strcmp(res->flow_type, "all")) {
10110 		if (!flow_type_mask) {
10111 			printf("No flow type supported\n");
10112 			return;
10113 		}
10114 		for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10115 			if (flow_type_mask & (1 << i)) {
10116 				flex_mask.flow_type = i;
10117 				fdir_set_flex_mask(res->port_id, &flex_mask);
10118 			}
10119 		}
10120 		cmd_reconfig_device_queue(res->port_id, 1, 1);
10121 		return;
10122 	}
10123 	flex_mask.flow_type = str2flowtype(res->flow_type);
10124 	if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10125 		printf("Flow type %s not supported on port %d\n",
10126 				res->flow_type, res->port_id);
10127 		return;
10128 	}
10129 	fdir_set_flex_mask(res->port_id, &flex_mask);
10130 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10131 }
10132 
10133 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10134 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10135 				 flow_director_flexmask,
10136 				 "flow_director_flex_mask");
10137 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10138 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10139 			      port_id, UINT8);
10140 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10141 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10142 				 flow, "flow");
10143 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10144 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10145 		flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10146 		"ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10147 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10148 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10149 				 mask, NULL);
10150 
10151 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10152 	.f = cmd_flow_director_flex_mask_parsed,
10153 	.data = NULL,
10154 	.help_str = "flow_director_flex_mask ... : "
10155 		"Set flow director's flex mask on NIC",
10156 	.tokens = {
10157 		(void *)&cmd_flow_director_flexmask,
10158 		(void *)&cmd_flow_director_flexmask_port_id,
10159 		(void *)&cmd_flow_director_flexmask_flow,
10160 		(void *)&cmd_flow_director_flexmask_flow_type,
10161 		(void *)&cmd_flow_director_flexmask_mask,
10162 		NULL,
10163 	},
10164 };
10165 
10166 /* *** deal with flow director flexible payload configuration *** */
10167 struct cmd_flow_director_flexpayload_result {
10168 	cmdline_fixed_string_t flow_director_flexpayload;
10169 	uint8_t port_id;
10170 	cmdline_fixed_string_t payload_layer;
10171 	cmdline_fixed_string_t payload_cfg;
10172 };
10173 
10174 static inline int
10175 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10176 {
10177 	char s[256];
10178 	const char *p, *p0 = q_arg;
10179 	char *end;
10180 	unsigned long int_fld;
10181 	char *str_fld[max_num];
10182 	int i;
10183 	unsigned size;
10184 	int ret = -1;
10185 
10186 	p = strchr(p0, '(');
10187 	if (p == NULL)
10188 		return -1;
10189 	++p;
10190 	p0 = strchr(p, ')');
10191 	if (p0 == NULL)
10192 		return -1;
10193 
10194 	size = p0 - p;
10195 	if (size >= sizeof(s))
10196 		return -1;
10197 
10198 	snprintf(s, sizeof(s), "%.*s", size, p);
10199 	ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10200 	if (ret < 0 || ret > max_num)
10201 		return -1;
10202 	for (i = 0; i < ret; i++) {
10203 		errno = 0;
10204 		int_fld = strtoul(str_fld[i], &end, 0);
10205 		if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10206 			return -1;
10207 		offsets[i] = (uint16_t)int_fld;
10208 	}
10209 	return ret;
10210 }
10211 
10212 static void
10213 cmd_flow_director_flxpld_parsed(void *parsed_result,
10214 			  __attribute__((unused)) struct cmdline *cl,
10215 			  __attribute__((unused)) void *data)
10216 {
10217 	struct cmd_flow_director_flexpayload_result *res = parsed_result;
10218 	struct rte_eth_flex_payload_cfg flex_cfg;
10219 	struct rte_port *port;
10220 	int ret = 0;
10221 
10222 	if (res->port_id > nb_ports) {
10223 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10224 		return;
10225 	}
10226 
10227 	port = &ports[res->port_id];
10228 	/** Check if the port is not started **/
10229 	if (port->port_status != RTE_PORT_STOPPED) {
10230 		printf("Please stop port %d first\n", res->port_id);
10231 		return;
10232 	}
10233 
10234 	memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10235 
10236 	if (!strcmp(res->payload_layer, "raw"))
10237 		flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10238 	else if (!strcmp(res->payload_layer, "l2"))
10239 		flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10240 	else if (!strcmp(res->payload_layer, "l3"))
10241 		flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10242 	else if (!strcmp(res->payload_layer, "l4"))
10243 		flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10244 
10245 	ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10246 			    RTE_ETH_FDIR_MAX_FLEXLEN);
10247 	if (ret < 0) {
10248 		printf("error: Cannot parse flex payload input.\n");
10249 		return;
10250 	}
10251 
10252 	fdir_set_flex_payload(res->port_id, &flex_cfg);
10253 	cmd_reconfig_device_queue(res->port_id, 1, 1);
10254 }
10255 
10256 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10257 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10258 				 flow_director_flexpayload,
10259 				 "flow_director_flex_payload");
10260 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10261 	TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10262 			      port_id, UINT8);
10263 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10264 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10265 				 payload_layer, "raw#l2#l3#l4");
10266 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10267 	TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10268 				 payload_cfg, NULL);
10269 
10270 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10271 	.f = cmd_flow_director_flxpld_parsed,
10272 	.data = NULL,
10273 	.help_str = "flow_director_flexpayload ... : "
10274 		"Set flow director's flex payload on NIC",
10275 	.tokens = {
10276 		(void *)&cmd_flow_director_flexpayload,
10277 		(void *)&cmd_flow_director_flexpayload_port_id,
10278 		(void *)&cmd_flow_director_flexpayload_payload_layer,
10279 		(void *)&cmd_flow_director_flexpayload_payload_cfg,
10280 		NULL,
10281 	},
10282 };
10283 
10284 /* Generic flow interface command. */
10285 extern cmdline_parse_inst_t cmd_flow;
10286 
10287 /* *** Classification Filters Control *** */
10288 /* *** Get symmetric hash enable per port *** */
10289 struct cmd_get_sym_hash_ena_per_port_result {
10290 	cmdline_fixed_string_t get_sym_hash_ena_per_port;
10291 	uint8_t port_id;
10292 };
10293 
10294 static void
10295 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10296 				 __rte_unused struct cmdline *cl,
10297 				 __rte_unused void *data)
10298 {
10299 	struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10300 	struct rte_eth_hash_filter_info info;
10301 	int ret;
10302 
10303 	if (rte_eth_dev_filter_supported(res->port_id,
10304 				RTE_ETH_FILTER_HASH) < 0) {
10305 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10306 							res->port_id);
10307 		return;
10308 	}
10309 
10310 	memset(&info, 0, sizeof(info));
10311 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10312 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10313 						RTE_ETH_FILTER_GET, &info);
10314 
10315 	if (ret < 0) {
10316 		printf("Cannot get symmetric hash enable per port "
10317 					"on port %u\n", res->port_id);
10318 		return;
10319 	}
10320 
10321 	printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10322 				"enabled" : "disabled", res->port_id);
10323 }
10324 
10325 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10326 	TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10327 		get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10328 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10329 	TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10330 		port_id, UINT8);
10331 
10332 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10333 	.f = cmd_get_sym_hash_per_port_parsed,
10334 	.data = NULL,
10335 	.help_str = "get_sym_hash_ena_per_port <port_id>",
10336 	.tokens = {
10337 		(void *)&cmd_get_sym_hash_ena_per_port_all,
10338 		(void *)&cmd_get_sym_hash_ena_per_port_port_id,
10339 		NULL,
10340 	},
10341 };
10342 
10343 /* *** Set symmetric hash enable per port *** */
10344 struct cmd_set_sym_hash_ena_per_port_result {
10345 	cmdline_fixed_string_t set_sym_hash_ena_per_port;
10346 	cmdline_fixed_string_t enable;
10347 	uint8_t port_id;
10348 };
10349 
10350 static void
10351 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10352 				 __rte_unused struct cmdline *cl,
10353 				 __rte_unused void *data)
10354 {
10355 	struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10356 	struct rte_eth_hash_filter_info info;
10357 	int ret;
10358 
10359 	if (rte_eth_dev_filter_supported(res->port_id,
10360 				RTE_ETH_FILTER_HASH) < 0) {
10361 		printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10362 							res->port_id);
10363 		return;
10364 	}
10365 
10366 	memset(&info, 0, sizeof(info));
10367 	info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10368 	if (!strcmp(res->enable, "enable"))
10369 		info.info.enable = 1;
10370 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10371 					RTE_ETH_FILTER_SET, &info);
10372 	if (ret < 0) {
10373 		printf("Cannot set symmetric hash enable per port on "
10374 					"port %u\n", res->port_id);
10375 		return;
10376 	}
10377 	printf("Symmetric hash has been set to %s on port %u\n",
10378 					res->enable, res->port_id);
10379 }
10380 
10381 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
10382 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10383 		set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
10384 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
10385 	TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10386 		port_id, UINT8);
10387 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
10388 	TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
10389 		enable, "enable#disable");
10390 
10391 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
10392 	.f = cmd_set_sym_hash_per_port_parsed,
10393 	.data = NULL,
10394 	.help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
10395 	.tokens = {
10396 		(void *)&cmd_set_sym_hash_ena_per_port_all,
10397 		(void *)&cmd_set_sym_hash_ena_per_port_port_id,
10398 		(void *)&cmd_set_sym_hash_ena_per_port_enable,
10399 		NULL,
10400 	},
10401 };
10402 
10403 /* Get global config of hash function */
10404 struct cmd_get_hash_global_config_result {
10405 	cmdline_fixed_string_t get_hash_global_config;
10406 	uint8_t port_id;
10407 };
10408 
10409 static char *
10410 flowtype_to_str(uint16_t ftype)
10411 {
10412 	uint16_t i;
10413 	static struct {
10414 		char str[16];
10415 		uint16_t ftype;
10416 	} ftype_table[] = {
10417 		{"ipv4", RTE_ETH_FLOW_IPV4},
10418 		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10419 		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10420 		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10421 		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10422 		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10423 		{"ipv6", RTE_ETH_FLOW_IPV6},
10424 		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10425 		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10426 		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10427 		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10428 		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10429 		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10430 		{"port", RTE_ETH_FLOW_PORT},
10431 		{"vxlan", RTE_ETH_FLOW_VXLAN},
10432 		{"geneve", RTE_ETH_FLOW_GENEVE},
10433 		{"nvgre", RTE_ETH_FLOW_NVGRE},
10434 	};
10435 
10436 	for (i = 0; i < RTE_DIM(ftype_table); i++) {
10437 		if (ftype_table[i].ftype == ftype)
10438 			return ftype_table[i].str;
10439 	}
10440 
10441 	return NULL;
10442 }
10443 
10444 static void
10445 cmd_get_hash_global_config_parsed(void *parsed_result,
10446 				  __rte_unused struct cmdline *cl,
10447 				  __rte_unused void *data)
10448 {
10449 	struct cmd_get_hash_global_config_result *res = parsed_result;
10450 	struct rte_eth_hash_filter_info info;
10451 	uint32_t idx, offset;
10452 	uint16_t i;
10453 	char *str;
10454 	int ret;
10455 
10456 	if (rte_eth_dev_filter_supported(res->port_id,
10457 			RTE_ETH_FILTER_HASH) < 0) {
10458 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10459 							res->port_id);
10460 		return;
10461 	}
10462 
10463 	memset(&info, 0, sizeof(info));
10464 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10465 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10466 					RTE_ETH_FILTER_GET, &info);
10467 	if (ret < 0) {
10468 		printf("Cannot get hash global configurations by port %d\n",
10469 							res->port_id);
10470 		return;
10471 	}
10472 
10473 	switch (info.info.global_conf.hash_func) {
10474 	case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
10475 		printf("Hash function is Toeplitz\n");
10476 		break;
10477 	case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
10478 		printf("Hash function is Simple XOR\n");
10479 		break;
10480 	default:
10481 		printf("Unknown hash function\n");
10482 		break;
10483 	}
10484 
10485 	for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
10486 		idx = i / UINT32_BIT;
10487 		offset = i % UINT32_BIT;
10488 		if (!(info.info.global_conf.valid_bit_mask[idx] &
10489 						(1UL << offset)))
10490 			continue;
10491 		str = flowtype_to_str(i);
10492 		if (!str)
10493 			continue;
10494 		printf("Symmetric hash is %s globally for flow type %s "
10495 							"by port %d\n",
10496 			((info.info.global_conf.sym_hash_enable_mask[idx] &
10497 			(1UL << offset)) ? "enabled" : "disabled"), str,
10498 							res->port_id);
10499 	}
10500 }
10501 
10502 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
10503 	TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
10504 		get_hash_global_config, "get_hash_global_config");
10505 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
10506 	TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
10507 		port_id, UINT8);
10508 
10509 cmdline_parse_inst_t cmd_get_hash_global_config = {
10510 	.f = cmd_get_hash_global_config_parsed,
10511 	.data = NULL,
10512 	.help_str = "get_hash_global_config <port_id>",
10513 	.tokens = {
10514 		(void *)&cmd_get_hash_global_config_all,
10515 		(void *)&cmd_get_hash_global_config_port_id,
10516 		NULL,
10517 	},
10518 };
10519 
10520 /* Set global config of hash function */
10521 struct cmd_set_hash_global_config_result {
10522 	cmdline_fixed_string_t set_hash_global_config;
10523 	uint8_t port_id;
10524 	cmdline_fixed_string_t hash_func;
10525 	cmdline_fixed_string_t flow_type;
10526 	cmdline_fixed_string_t enable;
10527 };
10528 
10529 static void
10530 cmd_set_hash_global_config_parsed(void *parsed_result,
10531 				  __rte_unused struct cmdline *cl,
10532 				  __rte_unused void *data)
10533 {
10534 	struct cmd_set_hash_global_config_result *res = parsed_result;
10535 	struct rte_eth_hash_filter_info info;
10536 	uint32_t ftype, idx, offset;
10537 	int ret;
10538 
10539 	if (rte_eth_dev_filter_supported(res->port_id,
10540 				RTE_ETH_FILTER_HASH) < 0) {
10541 		printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
10542 							res->port_id);
10543 		return;
10544 	}
10545 	memset(&info, 0, sizeof(info));
10546 	info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
10547 	if (!strcmp(res->hash_func, "toeplitz"))
10548 		info.info.global_conf.hash_func =
10549 			RTE_ETH_HASH_FUNCTION_TOEPLITZ;
10550 	else if (!strcmp(res->hash_func, "simple_xor"))
10551 		info.info.global_conf.hash_func =
10552 			RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
10553 	else if (!strcmp(res->hash_func, "default"))
10554 		info.info.global_conf.hash_func =
10555 			RTE_ETH_HASH_FUNCTION_DEFAULT;
10556 
10557 	ftype = str2flowtype(res->flow_type);
10558 	idx = ftype / (CHAR_BIT * sizeof(uint32_t));
10559 	offset = ftype % (CHAR_BIT * sizeof(uint32_t));
10560 	info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
10561 	if (!strcmp(res->enable, "enable"))
10562 		info.info.global_conf.sym_hash_enable_mask[idx] |=
10563 						(1UL << offset);
10564 	ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10565 					RTE_ETH_FILTER_SET, &info);
10566 	if (ret < 0)
10567 		printf("Cannot set global hash configurations by port %d\n",
10568 							res->port_id);
10569 	else
10570 		printf("Global hash configurations have been set "
10571 			"succcessfully by port %d\n", res->port_id);
10572 }
10573 
10574 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
10575 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10576 		set_hash_global_config, "set_hash_global_config");
10577 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
10578 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
10579 		port_id, UINT8);
10580 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
10581 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10582 		hash_func, "toeplitz#simple_xor#default");
10583 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
10584 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10585 		flow_type,
10586 		"ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
10587 		"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10588 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
10589 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
10590 		enable, "enable#disable");
10591 
10592 cmdline_parse_inst_t cmd_set_hash_global_config = {
10593 	.f = cmd_set_hash_global_config_parsed,
10594 	.data = NULL,
10595 	.help_str = "set_hash_global_config <port_id> "
10596 		"toeplitz|simple_xor|default "
10597 		"ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10598 		"ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
10599 		"l2_payload enable|disable",
10600 	.tokens = {
10601 		(void *)&cmd_set_hash_global_config_all,
10602 		(void *)&cmd_set_hash_global_config_port_id,
10603 		(void *)&cmd_set_hash_global_config_hash_func,
10604 		(void *)&cmd_set_hash_global_config_flow_type,
10605 		(void *)&cmd_set_hash_global_config_enable,
10606 		NULL,
10607 	},
10608 };
10609 
10610 /* Set hash input set */
10611 struct cmd_set_hash_input_set_result {
10612 	cmdline_fixed_string_t set_hash_input_set;
10613 	uint8_t port_id;
10614 	cmdline_fixed_string_t flow_type;
10615 	cmdline_fixed_string_t inset_field;
10616 	cmdline_fixed_string_t select;
10617 };
10618 
10619 static enum rte_eth_input_set_field
10620 str2inset(char *string)
10621 {
10622 	uint16_t i;
10623 
10624 	static const struct {
10625 		char str[32];
10626 		enum rte_eth_input_set_field inset;
10627 	} inset_table[] = {
10628 		{"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
10629 		{"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
10630 		{"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
10631 		{"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
10632 		{"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
10633 		{"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
10634 		{"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
10635 		{"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
10636 		{"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
10637 		{"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
10638 		{"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
10639 		{"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
10640 		{"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
10641 		{"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
10642 		{"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
10643 		{"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
10644 		{"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
10645 		{"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
10646 		{"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
10647 		{"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
10648 		{"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
10649 		{"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
10650 		{"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
10651 		{"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
10652 		{"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
10653 		{"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
10654 		{"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
10655 		{"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
10656 		{"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
10657 		{"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
10658 		{"none", RTE_ETH_INPUT_SET_NONE},
10659 	};
10660 
10661 	for (i = 0; i < RTE_DIM(inset_table); i++) {
10662 		if (!strcmp(string, inset_table[i].str))
10663 			return inset_table[i].inset;
10664 	}
10665 
10666 	return RTE_ETH_INPUT_SET_UNKNOWN;
10667 }
10668 
10669 static void
10670 cmd_set_hash_input_set_parsed(void *parsed_result,
10671 			      __rte_unused struct cmdline *cl,
10672 			      __rte_unused void *data)
10673 {
10674 	struct cmd_set_hash_input_set_result *res = parsed_result;
10675 	struct rte_eth_hash_filter_info info;
10676 
10677 	memset(&info, 0, sizeof(info));
10678 	info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
10679 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10680 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10681 	info.info.input_set_conf.inset_size = 1;
10682 	if (!strcmp(res->select, "select"))
10683 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10684 	else if (!strcmp(res->select, "add"))
10685 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10686 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10687 				RTE_ETH_FILTER_SET, &info);
10688 }
10689 
10690 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
10691 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10692 		set_hash_input_set, "set_hash_input_set");
10693 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
10694 	TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
10695 		port_id, UINT8);
10696 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
10697 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10698 		flow_type, NULL);
10699 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
10700 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10701 		inset_field,
10702 		"ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10703 		"ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
10704 		"udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
10705 		"sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
10706 		"fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
10707 		"fld-8th#none");
10708 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
10709 	TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
10710 		select, "select#add");
10711 
10712 cmdline_parse_inst_t cmd_set_hash_input_set = {
10713 	.f = cmd_set_hash_input_set_parsed,
10714 	.data = NULL,
10715 	.help_str = "set_hash_input_set <port_id> "
10716 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10717 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
10718 	"ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
10719 	"ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
10720 	"tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
10721 	"gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
10722 	"fld-7th|fld-8th|none select|add",
10723 	.tokens = {
10724 		(void *)&cmd_set_hash_input_set_cmd,
10725 		(void *)&cmd_set_hash_input_set_port_id,
10726 		(void *)&cmd_set_hash_input_set_flow_type,
10727 		(void *)&cmd_set_hash_input_set_field,
10728 		(void *)&cmd_set_hash_input_set_select,
10729 		NULL,
10730 	},
10731 };
10732 
10733 /* Set flow director input set */
10734 struct cmd_set_fdir_input_set_result {
10735 	cmdline_fixed_string_t set_fdir_input_set;
10736 	uint8_t port_id;
10737 	cmdline_fixed_string_t flow_type;
10738 	cmdline_fixed_string_t inset_field;
10739 	cmdline_fixed_string_t select;
10740 };
10741 
10742 static void
10743 cmd_set_fdir_input_set_parsed(void *parsed_result,
10744 	__rte_unused struct cmdline *cl,
10745 	__rte_unused void *data)
10746 {
10747 	struct cmd_set_fdir_input_set_result *res = parsed_result;
10748 	struct rte_eth_fdir_filter_info info;
10749 
10750 	memset(&info, 0, sizeof(info));
10751 	info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
10752 	info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
10753 	info.info.input_set_conf.field[0] = str2inset(res->inset_field);
10754 	info.info.input_set_conf.inset_size = 1;
10755 	if (!strcmp(res->select, "select"))
10756 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
10757 	else if (!strcmp(res->select, "add"))
10758 		info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
10759 	rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10760 		RTE_ETH_FILTER_SET, &info);
10761 }
10762 
10763 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
10764 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10765 	set_fdir_input_set, "set_fdir_input_set");
10766 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
10767 	TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
10768 	port_id, UINT8);
10769 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
10770 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10771 	flow_type,
10772 	"ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
10773 	"ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
10774 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
10775 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10776 	inset_field,
10777 	"ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
10778 	"ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
10779 	"ipv6-hop-limits#udp-src-port#udp-dst-port#"
10780 	"tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
10781 	"sctp-veri-tag#none");
10782 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
10783 	TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
10784 	select, "select#add");
10785 
10786 cmdline_parse_inst_t cmd_set_fdir_input_set = {
10787 	.f = cmd_set_fdir_input_set_parsed,
10788 	.data = NULL,
10789 	.help_str = "set_fdir_input_set <port_id> "
10790 	"ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
10791 	"ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
10792 	"ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
10793 	"ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
10794 	"ipv6-hop-limits|udp-src-port|udp-dst-port|"
10795 	"tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
10796 	"sctp-veri-tag|none select|add",
10797 	.tokens = {
10798 		(void *)&cmd_set_fdir_input_set_cmd,
10799 		(void *)&cmd_set_fdir_input_set_port_id,
10800 		(void *)&cmd_set_fdir_input_set_flow_type,
10801 		(void *)&cmd_set_fdir_input_set_field,
10802 		(void *)&cmd_set_fdir_input_set_select,
10803 		NULL,
10804 	},
10805 };
10806 
10807 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10808 struct cmd_mcast_addr_result {
10809 	cmdline_fixed_string_t mcast_addr_cmd;
10810 	cmdline_fixed_string_t what;
10811 	uint8_t port_num;
10812 	struct ether_addr mc_addr;
10813 };
10814 
10815 static void cmd_mcast_addr_parsed(void *parsed_result,
10816 		__attribute__((unused)) struct cmdline *cl,
10817 		__attribute__((unused)) void *data)
10818 {
10819 	struct cmd_mcast_addr_result *res = parsed_result;
10820 
10821 	if (!is_multicast_ether_addr(&res->mc_addr)) {
10822 		printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10823 		       res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10824 		       res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10825 		       res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10826 		return;
10827 	}
10828 	if (strcmp(res->what, "add") == 0)
10829 		mcast_addr_add(res->port_num, &res->mc_addr);
10830 	else
10831 		mcast_addr_remove(res->port_num, &res->mc_addr);
10832 }
10833 
10834 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10835 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10836 				 mcast_addr_cmd, "mcast_addr");
10837 cmdline_parse_token_string_t cmd_mcast_addr_what =
10838 	TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10839 				 "add#remove");
10840 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10841 	TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
10842 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10843 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10844 
10845 cmdline_parse_inst_t cmd_mcast_addr = {
10846 	.f = cmd_mcast_addr_parsed,
10847 	.data = (void *)0,
10848 	.help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10849 		"Add/Remove multicast MAC address on port_id",
10850 	.tokens = {
10851 		(void *)&cmd_mcast_addr_cmd,
10852 		(void *)&cmd_mcast_addr_what,
10853 		(void *)&cmd_mcast_addr_portnum,
10854 		(void *)&cmd_mcast_addr_addr,
10855 		NULL,
10856 	},
10857 };
10858 
10859 /* l2 tunnel config
10860  * only support E-tag now.
10861  */
10862 
10863 /* Ether type config */
10864 struct cmd_config_l2_tunnel_eth_type_result {
10865 	cmdline_fixed_string_t port;
10866 	cmdline_fixed_string_t config;
10867 	cmdline_fixed_string_t all;
10868 	uint8_t id;
10869 	cmdline_fixed_string_t l2_tunnel;
10870 	cmdline_fixed_string_t l2_tunnel_type;
10871 	cmdline_fixed_string_t eth_type;
10872 	uint16_t eth_type_val;
10873 };
10874 
10875 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
10876 	TOKEN_STRING_INITIALIZER
10877 		(struct cmd_config_l2_tunnel_eth_type_result,
10878 		 port, "port");
10879 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
10880 	TOKEN_STRING_INITIALIZER
10881 		(struct cmd_config_l2_tunnel_eth_type_result,
10882 		 config, "config");
10883 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
10884 	TOKEN_STRING_INITIALIZER
10885 		(struct cmd_config_l2_tunnel_eth_type_result,
10886 		 all, "all");
10887 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
10888 	TOKEN_NUM_INITIALIZER
10889 		(struct cmd_config_l2_tunnel_eth_type_result,
10890 		 id, UINT8);
10891 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
10892 	TOKEN_STRING_INITIALIZER
10893 		(struct cmd_config_l2_tunnel_eth_type_result,
10894 		 l2_tunnel, "l2-tunnel");
10895 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
10896 	TOKEN_STRING_INITIALIZER
10897 		(struct cmd_config_l2_tunnel_eth_type_result,
10898 		 l2_tunnel_type, "E-tag");
10899 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
10900 	TOKEN_STRING_INITIALIZER
10901 		(struct cmd_config_l2_tunnel_eth_type_result,
10902 		 eth_type, "ether-type");
10903 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
10904 	TOKEN_NUM_INITIALIZER
10905 		(struct cmd_config_l2_tunnel_eth_type_result,
10906 		 eth_type_val, UINT16);
10907 
10908 static enum rte_eth_tunnel_type
10909 str2fdir_l2_tunnel_type(char *string)
10910 {
10911 	uint32_t i = 0;
10912 
10913 	static const struct {
10914 		char str[32];
10915 		enum rte_eth_tunnel_type type;
10916 	} l2_tunnel_type_str[] = {
10917 		{"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
10918 	};
10919 
10920 	for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
10921 		if (!strcmp(l2_tunnel_type_str[i].str, string))
10922 			return l2_tunnel_type_str[i].type;
10923 	}
10924 	return RTE_TUNNEL_TYPE_NONE;
10925 }
10926 
10927 /* ether type config for all ports */
10928 static void
10929 cmd_config_l2_tunnel_eth_type_all_parsed
10930 	(void *parsed_result,
10931 	 __attribute__((unused)) struct cmdline *cl,
10932 	 __attribute__((unused)) void *data)
10933 {
10934 	struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
10935 	struct rte_eth_l2_tunnel_conf entry;
10936 	portid_t pid;
10937 
10938 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10939 	entry.ether_type = res->eth_type_val;
10940 
10941 	RTE_ETH_FOREACH_DEV(pid) {
10942 		rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
10943 	}
10944 }
10945 
10946 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
10947 	.f = cmd_config_l2_tunnel_eth_type_all_parsed,
10948 	.data = NULL,
10949 	.help_str = "port config all l2-tunnel E-tag ether-type <value>",
10950 	.tokens = {
10951 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10952 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10953 		(void *)&cmd_config_l2_tunnel_eth_type_all_str,
10954 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10955 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10956 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10957 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10958 		NULL,
10959 	},
10960 };
10961 
10962 /* ether type config for a specific port */
10963 static void
10964 cmd_config_l2_tunnel_eth_type_specific_parsed(
10965 	void *parsed_result,
10966 	__attribute__((unused)) struct cmdline *cl,
10967 	__attribute__((unused)) void *data)
10968 {
10969 	struct cmd_config_l2_tunnel_eth_type_result *res =
10970 		 parsed_result;
10971 	struct rte_eth_l2_tunnel_conf entry;
10972 
10973 	if (port_id_is_invalid(res->id, ENABLED_WARN))
10974 		return;
10975 
10976 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
10977 	entry.ether_type = res->eth_type_val;
10978 
10979 	rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
10980 }
10981 
10982 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
10983 	.f = cmd_config_l2_tunnel_eth_type_specific_parsed,
10984 	.data = NULL,
10985 	.help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
10986 	.tokens = {
10987 		(void *)&cmd_config_l2_tunnel_eth_type_port,
10988 		(void *)&cmd_config_l2_tunnel_eth_type_config,
10989 		(void *)&cmd_config_l2_tunnel_eth_type_id,
10990 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
10991 		(void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
10992 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type,
10993 		(void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
10994 		NULL,
10995 	},
10996 };
10997 
10998 /* Enable/disable l2 tunnel */
10999 struct cmd_config_l2_tunnel_en_dis_result {
11000 	cmdline_fixed_string_t port;
11001 	cmdline_fixed_string_t config;
11002 	cmdline_fixed_string_t all;
11003 	uint8_t id;
11004 	cmdline_fixed_string_t l2_tunnel;
11005 	cmdline_fixed_string_t l2_tunnel_type;
11006 	cmdline_fixed_string_t en_dis;
11007 };
11008 
11009 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11010 	TOKEN_STRING_INITIALIZER
11011 		(struct cmd_config_l2_tunnel_en_dis_result,
11012 		 port, "port");
11013 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11014 	TOKEN_STRING_INITIALIZER
11015 		(struct cmd_config_l2_tunnel_en_dis_result,
11016 		 config, "config");
11017 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11018 	TOKEN_STRING_INITIALIZER
11019 		(struct cmd_config_l2_tunnel_en_dis_result,
11020 		 all, "all");
11021 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11022 	TOKEN_NUM_INITIALIZER
11023 		(struct cmd_config_l2_tunnel_en_dis_result,
11024 		 id, UINT8);
11025 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11026 	TOKEN_STRING_INITIALIZER
11027 		(struct cmd_config_l2_tunnel_en_dis_result,
11028 		 l2_tunnel, "l2-tunnel");
11029 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11030 	TOKEN_STRING_INITIALIZER
11031 		(struct cmd_config_l2_tunnel_en_dis_result,
11032 		 l2_tunnel_type, "E-tag");
11033 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11034 	TOKEN_STRING_INITIALIZER
11035 		(struct cmd_config_l2_tunnel_en_dis_result,
11036 		 en_dis, "enable#disable");
11037 
11038 /* enable/disable l2 tunnel for all ports */
11039 static void
11040 cmd_config_l2_tunnel_en_dis_all_parsed(
11041 	void *parsed_result,
11042 	__attribute__((unused)) struct cmdline *cl,
11043 	__attribute__((unused)) void *data)
11044 {
11045 	struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11046 	struct rte_eth_l2_tunnel_conf entry;
11047 	portid_t pid;
11048 	uint8_t en;
11049 
11050 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11051 
11052 	if (!strcmp("enable", res->en_dis))
11053 		en = 1;
11054 	else
11055 		en = 0;
11056 
11057 	RTE_ETH_FOREACH_DEV(pid) {
11058 		rte_eth_dev_l2_tunnel_offload_set(pid,
11059 						  &entry,
11060 						  ETH_L2_TUNNEL_ENABLE_MASK,
11061 						  en);
11062 	}
11063 }
11064 
11065 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11066 	.f = cmd_config_l2_tunnel_en_dis_all_parsed,
11067 	.data = NULL,
11068 	.help_str = "port config all l2-tunnel E-tag enable|disable",
11069 	.tokens = {
11070 		(void *)&cmd_config_l2_tunnel_en_dis_port,
11071 		(void *)&cmd_config_l2_tunnel_en_dis_config,
11072 		(void *)&cmd_config_l2_tunnel_en_dis_all_str,
11073 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11074 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11075 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11076 		NULL,
11077 	},
11078 };
11079 
11080 /* enable/disable l2 tunnel for a port */
11081 static void
11082 cmd_config_l2_tunnel_en_dis_specific_parsed(
11083 	void *parsed_result,
11084 	__attribute__((unused)) struct cmdline *cl,
11085 	__attribute__((unused)) void *data)
11086 {
11087 	struct cmd_config_l2_tunnel_en_dis_result *res =
11088 		parsed_result;
11089 	struct rte_eth_l2_tunnel_conf entry;
11090 
11091 	if (port_id_is_invalid(res->id, ENABLED_WARN))
11092 		return;
11093 
11094 	entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11095 
11096 	if (!strcmp("enable", res->en_dis))
11097 		rte_eth_dev_l2_tunnel_offload_set(res->id,
11098 						  &entry,
11099 						  ETH_L2_TUNNEL_ENABLE_MASK,
11100 						  1);
11101 	else
11102 		rte_eth_dev_l2_tunnel_offload_set(res->id,
11103 						  &entry,
11104 						  ETH_L2_TUNNEL_ENABLE_MASK,
11105 						  0);
11106 }
11107 
11108 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11109 	.f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11110 	.data = NULL,
11111 	.help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11112 	.tokens = {
11113 		(void *)&cmd_config_l2_tunnel_en_dis_port,
11114 		(void *)&cmd_config_l2_tunnel_en_dis_config,
11115 		(void *)&cmd_config_l2_tunnel_en_dis_id,
11116 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11117 		(void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11118 		(void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11119 		NULL,
11120 	},
11121 };
11122 
11123 /* E-tag configuration */
11124 
11125 /* Common result structure for all E-tag configuration */
11126 struct cmd_config_e_tag_result {
11127 	cmdline_fixed_string_t e_tag;
11128 	cmdline_fixed_string_t set;
11129 	cmdline_fixed_string_t insertion;
11130 	cmdline_fixed_string_t stripping;
11131 	cmdline_fixed_string_t forwarding;
11132 	cmdline_fixed_string_t filter;
11133 	cmdline_fixed_string_t add;
11134 	cmdline_fixed_string_t del;
11135 	cmdline_fixed_string_t on;
11136 	cmdline_fixed_string_t off;
11137 	cmdline_fixed_string_t on_off;
11138 	cmdline_fixed_string_t port_tag_id;
11139 	uint32_t port_tag_id_val;
11140 	cmdline_fixed_string_t e_tag_id;
11141 	uint16_t e_tag_id_val;
11142 	cmdline_fixed_string_t dst_pool;
11143 	uint8_t dst_pool_val;
11144 	cmdline_fixed_string_t port;
11145 	uint8_t port_id;
11146 	cmdline_fixed_string_t vf;
11147 	uint8_t vf_id;
11148 };
11149 
11150 /* Common CLI fields for all E-tag configuration */
11151 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11152 	TOKEN_STRING_INITIALIZER
11153 		(struct cmd_config_e_tag_result,
11154 		 e_tag, "E-tag");
11155 cmdline_parse_token_string_t cmd_config_e_tag_set =
11156 	TOKEN_STRING_INITIALIZER
11157 		(struct cmd_config_e_tag_result,
11158 		 set, "set");
11159 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11160 	TOKEN_STRING_INITIALIZER
11161 		(struct cmd_config_e_tag_result,
11162 		 insertion, "insertion");
11163 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11164 	TOKEN_STRING_INITIALIZER
11165 		(struct cmd_config_e_tag_result,
11166 		 stripping, "stripping");
11167 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11168 	TOKEN_STRING_INITIALIZER
11169 		(struct cmd_config_e_tag_result,
11170 		 forwarding, "forwarding");
11171 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11172 	TOKEN_STRING_INITIALIZER
11173 		(struct cmd_config_e_tag_result,
11174 		 filter, "filter");
11175 cmdline_parse_token_string_t cmd_config_e_tag_add =
11176 	TOKEN_STRING_INITIALIZER
11177 		(struct cmd_config_e_tag_result,
11178 		 add, "add");
11179 cmdline_parse_token_string_t cmd_config_e_tag_del =
11180 	TOKEN_STRING_INITIALIZER
11181 		(struct cmd_config_e_tag_result,
11182 		 del, "del");
11183 cmdline_parse_token_string_t cmd_config_e_tag_on =
11184 	TOKEN_STRING_INITIALIZER
11185 		(struct cmd_config_e_tag_result,
11186 		 on, "on");
11187 cmdline_parse_token_string_t cmd_config_e_tag_off =
11188 	TOKEN_STRING_INITIALIZER
11189 		(struct cmd_config_e_tag_result,
11190 		 off, "off");
11191 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11192 	TOKEN_STRING_INITIALIZER
11193 		(struct cmd_config_e_tag_result,
11194 		 on_off, "on#off");
11195 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11196 	TOKEN_STRING_INITIALIZER
11197 		(struct cmd_config_e_tag_result,
11198 		 port_tag_id, "port-tag-id");
11199 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11200 	TOKEN_NUM_INITIALIZER
11201 		(struct cmd_config_e_tag_result,
11202 		 port_tag_id_val, UINT32);
11203 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11204 	TOKEN_STRING_INITIALIZER
11205 		(struct cmd_config_e_tag_result,
11206 		 e_tag_id, "e-tag-id");
11207 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11208 	TOKEN_NUM_INITIALIZER
11209 		(struct cmd_config_e_tag_result,
11210 		 e_tag_id_val, UINT16);
11211 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11212 	TOKEN_STRING_INITIALIZER
11213 		(struct cmd_config_e_tag_result,
11214 		 dst_pool, "dst-pool");
11215 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11216 	TOKEN_NUM_INITIALIZER
11217 		(struct cmd_config_e_tag_result,
11218 		 dst_pool_val, UINT8);
11219 cmdline_parse_token_string_t cmd_config_e_tag_port =
11220 	TOKEN_STRING_INITIALIZER
11221 		(struct cmd_config_e_tag_result,
11222 		 port, "port");
11223 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11224 	TOKEN_NUM_INITIALIZER
11225 		(struct cmd_config_e_tag_result,
11226 		 port_id, UINT8);
11227 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11228 	TOKEN_STRING_INITIALIZER
11229 		(struct cmd_config_e_tag_result,
11230 		 vf, "vf");
11231 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11232 	TOKEN_NUM_INITIALIZER
11233 		(struct cmd_config_e_tag_result,
11234 		 vf_id, UINT8);
11235 
11236 /* E-tag insertion configuration */
11237 static void
11238 cmd_config_e_tag_insertion_en_parsed(
11239 	void *parsed_result,
11240 	__attribute__((unused)) struct cmdline *cl,
11241 	__attribute__((unused)) void *data)
11242 {
11243 	struct cmd_config_e_tag_result *res =
11244 		parsed_result;
11245 	struct rte_eth_l2_tunnel_conf entry;
11246 
11247 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11248 		return;
11249 
11250 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11251 	entry.tunnel_id = res->port_tag_id_val;
11252 	entry.vf_id = res->vf_id;
11253 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11254 					  &entry,
11255 					  ETH_L2_TUNNEL_INSERTION_MASK,
11256 					  1);
11257 }
11258 
11259 static void
11260 cmd_config_e_tag_insertion_dis_parsed(
11261 	void *parsed_result,
11262 	__attribute__((unused)) struct cmdline *cl,
11263 	__attribute__((unused)) void *data)
11264 {
11265 	struct cmd_config_e_tag_result *res =
11266 		parsed_result;
11267 	struct rte_eth_l2_tunnel_conf entry;
11268 
11269 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11270 		return;
11271 
11272 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11273 	entry.vf_id = res->vf_id;
11274 
11275 	rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11276 					  &entry,
11277 					  ETH_L2_TUNNEL_INSERTION_MASK,
11278 					  0);
11279 }
11280 
11281 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11282 	.f = cmd_config_e_tag_insertion_en_parsed,
11283 	.data = NULL,
11284 	.help_str = "E-tag ... : E-tag insertion enable",
11285 	.tokens = {
11286 		(void *)&cmd_config_e_tag_e_tag,
11287 		(void *)&cmd_config_e_tag_set,
11288 		(void *)&cmd_config_e_tag_insertion,
11289 		(void *)&cmd_config_e_tag_on,
11290 		(void *)&cmd_config_e_tag_port_tag_id,
11291 		(void *)&cmd_config_e_tag_port_tag_id_val,
11292 		(void *)&cmd_config_e_tag_port,
11293 		(void *)&cmd_config_e_tag_port_id,
11294 		(void *)&cmd_config_e_tag_vf,
11295 		(void *)&cmd_config_e_tag_vf_id,
11296 		NULL,
11297 	},
11298 };
11299 
11300 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11301 	.f = cmd_config_e_tag_insertion_dis_parsed,
11302 	.data = NULL,
11303 	.help_str = "E-tag ... : E-tag insertion disable",
11304 	.tokens = {
11305 		(void *)&cmd_config_e_tag_e_tag,
11306 		(void *)&cmd_config_e_tag_set,
11307 		(void *)&cmd_config_e_tag_insertion,
11308 		(void *)&cmd_config_e_tag_off,
11309 		(void *)&cmd_config_e_tag_port,
11310 		(void *)&cmd_config_e_tag_port_id,
11311 		(void *)&cmd_config_e_tag_vf,
11312 		(void *)&cmd_config_e_tag_vf_id,
11313 		NULL,
11314 	},
11315 };
11316 
11317 /* E-tag stripping configuration */
11318 static void
11319 cmd_config_e_tag_stripping_parsed(
11320 	void *parsed_result,
11321 	__attribute__((unused)) struct cmdline *cl,
11322 	__attribute__((unused)) void *data)
11323 {
11324 	struct cmd_config_e_tag_result *res =
11325 		parsed_result;
11326 	struct rte_eth_l2_tunnel_conf entry;
11327 
11328 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11329 		return;
11330 
11331 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11332 
11333 	if (!strcmp(res->on_off, "on"))
11334 		rte_eth_dev_l2_tunnel_offload_set
11335 			(res->port_id,
11336 			 &entry,
11337 			 ETH_L2_TUNNEL_STRIPPING_MASK,
11338 			 1);
11339 	else
11340 		rte_eth_dev_l2_tunnel_offload_set
11341 			(res->port_id,
11342 			 &entry,
11343 			 ETH_L2_TUNNEL_STRIPPING_MASK,
11344 			 0);
11345 }
11346 
11347 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11348 	.f = cmd_config_e_tag_stripping_parsed,
11349 	.data = NULL,
11350 	.help_str = "E-tag ... : E-tag stripping enable/disable",
11351 	.tokens = {
11352 		(void *)&cmd_config_e_tag_e_tag,
11353 		(void *)&cmd_config_e_tag_set,
11354 		(void *)&cmd_config_e_tag_stripping,
11355 		(void *)&cmd_config_e_tag_on_off,
11356 		(void *)&cmd_config_e_tag_port,
11357 		(void *)&cmd_config_e_tag_port_id,
11358 		NULL,
11359 	},
11360 };
11361 
11362 /* E-tag forwarding configuration */
11363 static void
11364 cmd_config_e_tag_forwarding_parsed(
11365 	void *parsed_result,
11366 	__attribute__((unused)) struct cmdline *cl,
11367 	__attribute__((unused)) void *data)
11368 {
11369 	struct cmd_config_e_tag_result *res = parsed_result;
11370 	struct rte_eth_l2_tunnel_conf entry;
11371 
11372 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11373 		return;
11374 
11375 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11376 
11377 	if (!strcmp(res->on_off, "on"))
11378 		rte_eth_dev_l2_tunnel_offload_set
11379 			(res->port_id,
11380 			 &entry,
11381 			 ETH_L2_TUNNEL_FORWARDING_MASK,
11382 			 1);
11383 	else
11384 		rte_eth_dev_l2_tunnel_offload_set
11385 			(res->port_id,
11386 			 &entry,
11387 			 ETH_L2_TUNNEL_FORWARDING_MASK,
11388 			 0);
11389 }
11390 
11391 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
11392 	.f = cmd_config_e_tag_forwarding_parsed,
11393 	.data = NULL,
11394 	.help_str = "E-tag ... : E-tag forwarding enable/disable",
11395 	.tokens = {
11396 		(void *)&cmd_config_e_tag_e_tag,
11397 		(void *)&cmd_config_e_tag_set,
11398 		(void *)&cmd_config_e_tag_forwarding,
11399 		(void *)&cmd_config_e_tag_on_off,
11400 		(void *)&cmd_config_e_tag_port,
11401 		(void *)&cmd_config_e_tag_port_id,
11402 		NULL,
11403 	},
11404 };
11405 
11406 /* E-tag filter configuration */
11407 static void
11408 cmd_config_e_tag_filter_add_parsed(
11409 	void *parsed_result,
11410 	__attribute__((unused)) struct cmdline *cl,
11411 	__attribute__((unused)) void *data)
11412 {
11413 	struct cmd_config_e_tag_result *res = parsed_result;
11414 	struct rte_eth_l2_tunnel_conf entry;
11415 	int ret = 0;
11416 
11417 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11418 		return;
11419 
11420 	if (res->e_tag_id_val > 0x3fff) {
11421 		printf("e-tag-id must be equal or less than 0x3fff.\n");
11422 		return;
11423 	}
11424 
11425 	ret = rte_eth_dev_filter_supported(res->port_id,
11426 					   RTE_ETH_FILTER_L2_TUNNEL);
11427 	if (ret < 0) {
11428 		printf("E-tag filter is not supported on port %u.\n",
11429 		       res->port_id);
11430 		return;
11431 	}
11432 
11433 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11434 	entry.tunnel_id = res->e_tag_id_val;
11435 	entry.pool = res->dst_pool_val;
11436 
11437 	ret = rte_eth_dev_filter_ctrl(res->port_id,
11438 				      RTE_ETH_FILTER_L2_TUNNEL,
11439 				      RTE_ETH_FILTER_ADD,
11440 				      &entry);
11441 	if (ret < 0)
11442 		printf("E-tag filter programming error: (%s)\n",
11443 		       strerror(-ret));
11444 }
11445 
11446 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
11447 	.f = cmd_config_e_tag_filter_add_parsed,
11448 	.data = NULL,
11449 	.help_str = "E-tag ... : E-tag filter add",
11450 	.tokens = {
11451 		(void *)&cmd_config_e_tag_e_tag,
11452 		(void *)&cmd_config_e_tag_set,
11453 		(void *)&cmd_config_e_tag_filter,
11454 		(void *)&cmd_config_e_tag_add,
11455 		(void *)&cmd_config_e_tag_e_tag_id,
11456 		(void *)&cmd_config_e_tag_e_tag_id_val,
11457 		(void *)&cmd_config_e_tag_dst_pool,
11458 		(void *)&cmd_config_e_tag_dst_pool_val,
11459 		(void *)&cmd_config_e_tag_port,
11460 		(void *)&cmd_config_e_tag_port_id,
11461 		NULL,
11462 	},
11463 };
11464 
11465 static void
11466 cmd_config_e_tag_filter_del_parsed(
11467 	void *parsed_result,
11468 	__attribute__((unused)) struct cmdline *cl,
11469 	__attribute__((unused)) void *data)
11470 {
11471 	struct cmd_config_e_tag_result *res = parsed_result;
11472 	struct rte_eth_l2_tunnel_conf entry;
11473 	int ret = 0;
11474 
11475 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11476 		return;
11477 
11478 	if (res->e_tag_id_val > 0x3fff) {
11479 		printf("e-tag-id must be less than 0x3fff.\n");
11480 		return;
11481 	}
11482 
11483 	ret = rte_eth_dev_filter_supported(res->port_id,
11484 					   RTE_ETH_FILTER_L2_TUNNEL);
11485 	if (ret < 0) {
11486 		printf("E-tag filter is not supported on port %u.\n",
11487 		       res->port_id);
11488 		return;
11489 	}
11490 
11491 	entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11492 	entry.tunnel_id = res->e_tag_id_val;
11493 
11494 	ret = rte_eth_dev_filter_ctrl(res->port_id,
11495 				      RTE_ETH_FILTER_L2_TUNNEL,
11496 				      RTE_ETH_FILTER_DELETE,
11497 				      &entry);
11498 	if (ret < 0)
11499 		printf("E-tag filter programming error: (%s)\n",
11500 		       strerror(-ret));
11501 }
11502 
11503 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
11504 	.f = cmd_config_e_tag_filter_del_parsed,
11505 	.data = NULL,
11506 	.help_str = "E-tag ... : E-tag filter delete",
11507 	.tokens = {
11508 		(void *)&cmd_config_e_tag_e_tag,
11509 		(void *)&cmd_config_e_tag_set,
11510 		(void *)&cmd_config_e_tag_filter,
11511 		(void *)&cmd_config_e_tag_del,
11512 		(void *)&cmd_config_e_tag_e_tag_id,
11513 		(void *)&cmd_config_e_tag_e_tag_id_val,
11514 		(void *)&cmd_config_e_tag_port,
11515 		(void *)&cmd_config_e_tag_port_id,
11516 		NULL,
11517 	},
11518 };
11519 
11520 /* vf vlan anti spoof configuration */
11521 
11522 /* Common result structure for vf vlan anti spoof */
11523 struct cmd_vf_vlan_anti_spoof_result {
11524 	cmdline_fixed_string_t set;
11525 	cmdline_fixed_string_t vf;
11526 	cmdline_fixed_string_t vlan;
11527 	cmdline_fixed_string_t antispoof;
11528 	uint8_t port_id;
11529 	uint32_t vf_id;
11530 	cmdline_fixed_string_t on_off;
11531 };
11532 
11533 /* Common CLI fields for vf vlan anti spoof enable disable */
11534 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11535 	TOKEN_STRING_INITIALIZER
11536 		(struct cmd_vf_vlan_anti_spoof_result,
11537 		 set, "set");
11538 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11539 	TOKEN_STRING_INITIALIZER
11540 		(struct cmd_vf_vlan_anti_spoof_result,
11541 		 vf, "vf");
11542 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11543 	TOKEN_STRING_INITIALIZER
11544 		(struct cmd_vf_vlan_anti_spoof_result,
11545 		 vlan, "vlan");
11546 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11547 	TOKEN_STRING_INITIALIZER
11548 		(struct cmd_vf_vlan_anti_spoof_result,
11549 		 antispoof, "antispoof");
11550 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11551 	TOKEN_NUM_INITIALIZER
11552 		(struct cmd_vf_vlan_anti_spoof_result,
11553 		 port_id, UINT8);
11554 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11555 	TOKEN_NUM_INITIALIZER
11556 		(struct cmd_vf_vlan_anti_spoof_result,
11557 		 vf_id, UINT32);
11558 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11559 	TOKEN_STRING_INITIALIZER
11560 		(struct cmd_vf_vlan_anti_spoof_result,
11561 		 on_off, "on#off");
11562 
11563 static void
11564 cmd_set_vf_vlan_anti_spoof_parsed(
11565 	void *parsed_result,
11566 	__attribute__((unused)) struct cmdline *cl,
11567 	__attribute__((unused)) void *data)
11568 {
11569 	struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11570 	int ret = -ENOTSUP;
11571 
11572 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11573 
11574 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11575 		return;
11576 
11577 #ifdef RTE_LIBRTE_IXGBE_PMD
11578 	if (ret == -ENOTSUP)
11579 		ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11580 				res->vf_id, is_on);
11581 #endif
11582 #ifdef RTE_LIBRTE_I40E_PMD
11583 	if (ret == -ENOTSUP)
11584 		ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11585 				res->vf_id, is_on);
11586 #endif
11587 #ifdef RTE_LIBRTE_BNXT_PMD
11588 	if (ret == -ENOTSUP)
11589 		ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11590 				res->vf_id, is_on);
11591 #endif
11592 
11593 	switch (ret) {
11594 	case 0:
11595 		break;
11596 	case -EINVAL:
11597 		printf("invalid vf_id %d\n", res->vf_id);
11598 		break;
11599 	case -ENODEV:
11600 		printf("invalid port_id %d\n", res->port_id);
11601 		break;
11602 	case -ENOTSUP:
11603 		printf("function not implemented\n");
11604 		break;
11605 	default:
11606 		printf("programming error: (%s)\n", strerror(-ret));
11607 	}
11608 }
11609 
11610 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11611 	.f = cmd_set_vf_vlan_anti_spoof_parsed,
11612 	.data = NULL,
11613 	.help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11614 	.tokens = {
11615 		(void *)&cmd_vf_vlan_anti_spoof_set,
11616 		(void *)&cmd_vf_vlan_anti_spoof_vf,
11617 		(void *)&cmd_vf_vlan_anti_spoof_vlan,
11618 		(void *)&cmd_vf_vlan_anti_spoof_antispoof,
11619 		(void *)&cmd_vf_vlan_anti_spoof_port_id,
11620 		(void *)&cmd_vf_vlan_anti_spoof_vf_id,
11621 		(void *)&cmd_vf_vlan_anti_spoof_on_off,
11622 		NULL,
11623 	},
11624 };
11625 
11626 /* vf mac anti spoof configuration */
11627 
11628 /* Common result structure for vf mac anti spoof */
11629 struct cmd_vf_mac_anti_spoof_result {
11630 	cmdline_fixed_string_t set;
11631 	cmdline_fixed_string_t vf;
11632 	cmdline_fixed_string_t mac;
11633 	cmdline_fixed_string_t antispoof;
11634 	uint8_t port_id;
11635 	uint32_t vf_id;
11636 	cmdline_fixed_string_t on_off;
11637 };
11638 
11639 /* Common CLI fields for vf mac anti spoof enable disable */
11640 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11641 	TOKEN_STRING_INITIALIZER
11642 		(struct cmd_vf_mac_anti_spoof_result,
11643 		 set, "set");
11644 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11645 	TOKEN_STRING_INITIALIZER
11646 		(struct cmd_vf_mac_anti_spoof_result,
11647 		 vf, "vf");
11648 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11649 	TOKEN_STRING_INITIALIZER
11650 		(struct cmd_vf_mac_anti_spoof_result,
11651 		 mac, "mac");
11652 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11653 	TOKEN_STRING_INITIALIZER
11654 		(struct cmd_vf_mac_anti_spoof_result,
11655 		 antispoof, "antispoof");
11656 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11657 	TOKEN_NUM_INITIALIZER
11658 		(struct cmd_vf_mac_anti_spoof_result,
11659 		 port_id, UINT8);
11660 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11661 	TOKEN_NUM_INITIALIZER
11662 		(struct cmd_vf_mac_anti_spoof_result,
11663 		 vf_id, UINT32);
11664 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11665 	TOKEN_STRING_INITIALIZER
11666 		(struct cmd_vf_mac_anti_spoof_result,
11667 		 on_off, "on#off");
11668 
11669 static void
11670 cmd_set_vf_mac_anti_spoof_parsed(
11671 	void *parsed_result,
11672 	__attribute__((unused)) struct cmdline *cl,
11673 	__attribute__((unused)) void *data)
11674 {
11675 	struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11676 	int ret = -ENOTSUP;
11677 
11678 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11679 
11680 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11681 		return;
11682 
11683 #ifdef RTE_LIBRTE_IXGBE_PMD
11684 	if (ret == -ENOTSUP)
11685 		ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11686 			res->vf_id, is_on);
11687 #endif
11688 #ifdef RTE_LIBRTE_I40E_PMD
11689 	if (ret == -ENOTSUP)
11690 		ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11691 			res->vf_id, is_on);
11692 #endif
11693 #ifdef RTE_LIBRTE_BNXT_PMD
11694 	if (ret == -ENOTSUP)
11695 		ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11696 			res->vf_id, is_on);
11697 #endif
11698 
11699 	switch (ret) {
11700 	case 0:
11701 		break;
11702 	case -EINVAL:
11703 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11704 		break;
11705 	case -ENODEV:
11706 		printf("invalid port_id %d\n", res->port_id);
11707 		break;
11708 	case -ENOTSUP:
11709 		printf("function not implemented\n");
11710 		break;
11711 	default:
11712 		printf("programming error: (%s)\n", strerror(-ret));
11713 	}
11714 }
11715 
11716 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11717 	.f = cmd_set_vf_mac_anti_spoof_parsed,
11718 	.data = NULL,
11719 	.help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11720 	.tokens = {
11721 		(void *)&cmd_vf_mac_anti_spoof_set,
11722 		(void *)&cmd_vf_mac_anti_spoof_vf,
11723 		(void *)&cmd_vf_mac_anti_spoof_mac,
11724 		(void *)&cmd_vf_mac_anti_spoof_antispoof,
11725 		(void *)&cmd_vf_mac_anti_spoof_port_id,
11726 		(void *)&cmd_vf_mac_anti_spoof_vf_id,
11727 		(void *)&cmd_vf_mac_anti_spoof_on_off,
11728 		NULL,
11729 	},
11730 };
11731 
11732 /* vf vlan strip queue configuration */
11733 
11734 /* Common result structure for vf mac anti spoof */
11735 struct cmd_vf_vlan_stripq_result {
11736 	cmdline_fixed_string_t set;
11737 	cmdline_fixed_string_t vf;
11738 	cmdline_fixed_string_t vlan;
11739 	cmdline_fixed_string_t stripq;
11740 	portid_t port_id;
11741 	uint16_t vf_id;
11742 	cmdline_fixed_string_t on_off;
11743 };
11744 
11745 /* Common CLI fields for vf vlan strip enable disable */
11746 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11747 	TOKEN_STRING_INITIALIZER
11748 		(struct cmd_vf_vlan_stripq_result,
11749 		 set, "set");
11750 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11751 	TOKEN_STRING_INITIALIZER
11752 		(struct cmd_vf_vlan_stripq_result,
11753 		 vf, "vf");
11754 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11755 	TOKEN_STRING_INITIALIZER
11756 		(struct cmd_vf_vlan_stripq_result,
11757 		 vlan, "vlan");
11758 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11759 	TOKEN_STRING_INITIALIZER
11760 		(struct cmd_vf_vlan_stripq_result,
11761 		 stripq, "stripq");
11762 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11763 	TOKEN_NUM_INITIALIZER
11764 		(struct cmd_vf_vlan_stripq_result,
11765 		 port_id, UINT8);
11766 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11767 	TOKEN_NUM_INITIALIZER
11768 		(struct cmd_vf_vlan_stripq_result,
11769 		 vf_id, UINT16);
11770 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11771 	TOKEN_STRING_INITIALIZER
11772 		(struct cmd_vf_vlan_stripq_result,
11773 		 on_off, "on#off");
11774 
11775 static void
11776 cmd_set_vf_vlan_stripq_parsed(
11777 	void *parsed_result,
11778 	__attribute__((unused)) struct cmdline *cl,
11779 	__attribute__((unused)) void *data)
11780 {
11781 	struct cmd_vf_vlan_stripq_result *res = parsed_result;
11782 	int ret = -ENOTSUP;
11783 
11784 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11785 
11786 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11787 		return;
11788 
11789 #ifdef RTE_LIBRTE_IXGBE_PMD
11790 	if (ret == -ENOTSUP)
11791 		ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11792 			res->vf_id, is_on);
11793 #endif
11794 #ifdef RTE_LIBRTE_I40E_PMD
11795 	if (ret == -ENOTSUP)
11796 		ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11797 			res->vf_id, is_on);
11798 #endif
11799 #ifdef RTE_LIBRTE_BNXT_PMD
11800 	if (ret == -ENOTSUP)
11801 		ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11802 			res->vf_id, is_on);
11803 #endif
11804 
11805 	switch (ret) {
11806 	case 0:
11807 		break;
11808 	case -EINVAL:
11809 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11810 		break;
11811 	case -ENODEV:
11812 		printf("invalid port_id %d\n", res->port_id);
11813 		break;
11814 	case -ENOTSUP:
11815 		printf("function not implemented\n");
11816 		break;
11817 	default:
11818 		printf("programming error: (%s)\n", strerror(-ret));
11819 	}
11820 }
11821 
11822 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11823 	.f = cmd_set_vf_vlan_stripq_parsed,
11824 	.data = NULL,
11825 	.help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11826 	.tokens = {
11827 		(void *)&cmd_vf_vlan_stripq_set,
11828 		(void *)&cmd_vf_vlan_stripq_vf,
11829 		(void *)&cmd_vf_vlan_stripq_vlan,
11830 		(void *)&cmd_vf_vlan_stripq_stripq,
11831 		(void *)&cmd_vf_vlan_stripq_port_id,
11832 		(void *)&cmd_vf_vlan_stripq_vf_id,
11833 		(void *)&cmd_vf_vlan_stripq_on_off,
11834 		NULL,
11835 	},
11836 };
11837 
11838 /* vf vlan insert configuration */
11839 
11840 /* Common result structure for vf vlan insert */
11841 struct cmd_vf_vlan_insert_result {
11842 	cmdline_fixed_string_t set;
11843 	cmdline_fixed_string_t vf;
11844 	cmdline_fixed_string_t vlan;
11845 	cmdline_fixed_string_t insert;
11846 	uint8_t port_id;
11847 	uint16_t vf_id;
11848 	uint16_t vlan_id;
11849 };
11850 
11851 /* Common CLI fields for vf vlan insert enable disable */
11852 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11853 	TOKEN_STRING_INITIALIZER
11854 		(struct cmd_vf_vlan_insert_result,
11855 		 set, "set");
11856 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11857 	TOKEN_STRING_INITIALIZER
11858 		(struct cmd_vf_vlan_insert_result,
11859 		 vf, "vf");
11860 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11861 	TOKEN_STRING_INITIALIZER
11862 		(struct cmd_vf_vlan_insert_result,
11863 		 vlan, "vlan");
11864 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11865 	TOKEN_STRING_INITIALIZER
11866 		(struct cmd_vf_vlan_insert_result,
11867 		 insert, "insert");
11868 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11869 	TOKEN_NUM_INITIALIZER
11870 		(struct cmd_vf_vlan_insert_result,
11871 		 port_id, UINT8);
11872 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11873 	TOKEN_NUM_INITIALIZER
11874 		(struct cmd_vf_vlan_insert_result,
11875 		 vf_id, UINT16);
11876 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11877 	TOKEN_NUM_INITIALIZER
11878 		(struct cmd_vf_vlan_insert_result,
11879 		 vlan_id, UINT16);
11880 
11881 static void
11882 cmd_set_vf_vlan_insert_parsed(
11883 	void *parsed_result,
11884 	__attribute__((unused)) struct cmdline *cl,
11885 	__attribute__((unused)) void *data)
11886 {
11887 	struct cmd_vf_vlan_insert_result *res = parsed_result;
11888 	int ret = -ENOTSUP;
11889 
11890 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11891 		return;
11892 
11893 #ifdef RTE_LIBRTE_IXGBE_PMD
11894 	if (ret == -ENOTSUP)
11895 		ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11896 			res->vlan_id);
11897 #endif
11898 #ifdef RTE_LIBRTE_I40E_PMD
11899 	if (ret == -ENOTSUP)
11900 		ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11901 			res->vlan_id);
11902 #endif
11903 #ifdef RTE_LIBRTE_BNXT_PMD
11904 	if (ret == -ENOTSUP)
11905 		ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11906 			res->vlan_id);
11907 #endif
11908 
11909 	switch (ret) {
11910 	case 0:
11911 		break;
11912 	case -EINVAL:
11913 		printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11914 		break;
11915 	case -ENODEV:
11916 		printf("invalid port_id %d\n", res->port_id);
11917 		break;
11918 	case -ENOTSUP:
11919 		printf("function not implemented\n");
11920 		break;
11921 	default:
11922 		printf("programming error: (%s)\n", strerror(-ret));
11923 	}
11924 }
11925 
11926 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11927 	.f = cmd_set_vf_vlan_insert_parsed,
11928 	.data = NULL,
11929 	.help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11930 	.tokens = {
11931 		(void *)&cmd_vf_vlan_insert_set,
11932 		(void *)&cmd_vf_vlan_insert_vf,
11933 		(void *)&cmd_vf_vlan_insert_vlan,
11934 		(void *)&cmd_vf_vlan_insert_insert,
11935 		(void *)&cmd_vf_vlan_insert_port_id,
11936 		(void *)&cmd_vf_vlan_insert_vf_id,
11937 		(void *)&cmd_vf_vlan_insert_vlan_id,
11938 		NULL,
11939 	},
11940 };
11941 
11942 /* tx loopback configuration */
11943 
11944 /* Common result structure for tx loopback */
11945 struct cmd_tx_loopback_result {
11946 	cmdline_fixed_string_t set;
11947 	cmdline_fixed_string_t tx;
11948 	cmdline_fixed_string_t loopback;
11949 	uint8_t port_id;
11950 	cmdline_fixed_string_t on_off;
11951 };
11952 
11953 /* Common CLI fields for tx loopback enable disable */
11954 cmdline_parse_token_string_t cmd_tx_loopback_set =
11955 	TOKEN_STRING_INITIALIZER
11956 		(struct cmd_tx_loopback_result,
11957 		 set, "set");
11958 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11959 	TOKEN_STRING_INITIALIZER
11960 		(struct cmd_tx_loopback_result,
11961 		 tx, "tx");
11962 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11963 	TOKEN_STRING_INITIALIZER
11964 		(struct cmd_tx_loopback_result,
11965 		 loopback, "loopback");
11966 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11967 	TOKEN_NUM_INITIALIZER
11968 		(struct cmd_tx_loopback_result,
11969 		 port_id, UINT8);
11970 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11971 	TOKEN_STRING_INITIALIZER
11972 		(struct cmd_tx_loopback_result,
11973 		 on_off, "on#off");
11974 
11975 static void
11976 cmd_set_tx_loopback_parsed(
11977 	void *parsed_result,
11978 	__attribute__((unused)) struct cmdline *cl,
11979 	__attribute__((unused)) void *data)
11980 {
11981 	struct cmd_tx_loopback_result *res = parsed_result;
11982 	int ret = -ENOTSUP;
11983 
11984 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11985 
11986 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11987 		return;
11988 
11989 #ifdef RTE_LIBRTE_IXGBE_PMD
11990 	if (ret == -ENOTSUP)
11991 		ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11992 #endif
11993 #ifdef RTE_LIBRTE_I40E_PMD
11994 	if (ret == -ENOTSUP)
11995 		ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11996 #endif
11997 #ifdef RTE_LIBRTE_BNXT_PMD
11998 	if (ret == -ENOTSUP)
11999 		ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12000 #endif
12001 
12002 	switch (ret) {
12003 	case 0:
12004 		break;
12005 	case -EINVAL:
12006 		printf("invalid is_on %d\n", is_on);
12007 		break;
12008 	case -ENODEV:
12009 		printf("invalid port_id %d\n", res->port_id);
12010 		break;
12011 	case -ENOTSUP:
12012 		printf("function not implemented\n");
12013 		break;
12014 	default:
12015 		printf("programming error: (%s)\n", strerror(-ret));
12016 	}
12017 }
12018 
12019 cmdline_parse_inst_t cmd_set_tx_loopback = {
12020 	.f = cmd_set_tx_loopback_parsed,
12021 	.data = NULL,
12022 	.help_str = "set tx loopback <port_id> on|off",
12023 	.tokens = {
12024 		(void *)&cmd_tx_loopback_set,
12025 		(void *)&cmd_tx_loopback_tx,
12026 		(void *)&cmd_tx_loopback_loopback,
12027 		(void *)&cmd_tx_loopback_port_id,
12028 		(void *)&cmd_tx_loopback_on_off,
12029 		NULL,
12030 	},
12031 };
12032 
12033 /* all queues drop enable configuration */
12034 
12035 /* Common result structure for all queues drop enable */
12036 struct cmd_all_queues_drop_en_result {
12037 	cmdline_fixed_string_t set;
12038 	cmdline_fixed_string_t all;
12039 	cmdline_fixed_string_t queues;
12040 	cmdline_fixed_string_t drop;
12041 	uint8_t port_id;
12042 	cmdline_fixed_string_t on_off;
12043 };
12044 
12045 /* Common CLI fields for tx loopback enable disable */
12046 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12047 	TOKEN_STRING_INITIALIZER
12048 		(struct cmd_all_queues_drop_en_result,
12049 		 set, "set");
12050 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12051 	TOKEN_STRING_INITIALIZER
12052 		(struct cmd_all_queues_drop_en_result,
12053 		 all, "all");
12054 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12055 	TOKEN_STRING_INITIALIZER
12056 		(struct cmd_all_queues_drop_en_result,
12057 		 queues, "queues");
12058 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12059 	TOKEN_STRING_INITIALIZER
12060 		(struct cmd_all_queues_drop_en_result,
12061 		 drop, "drop");
12062 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12063 	TOKEN_NUM_INITIALIZER
12064 		(struct cmd_all_queues_drop_en_result,
12065 		 port_id, UINT8);
12066 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12067 	TOKEN_STRING_INITIALIZER
12068 		(struct cmd_all_queues_drop_en_result,
12069 		 on_off, "on#off");
12070 
12071 static void
12072 cmd_set_all_queues_drop_en_parsed(
12073 	void *parsed_result,
12074 	__attribute__((unused)) struct cmdline *cl,
12075 	__attribute__((unused)) void *data)
12076 {
12077 	struct cmd_all_queues_drop_en_result *res = parsed_result;
12078 	int ret = -ENOTSUP;
12079 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12080 
12081 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12082 		return;
12083 
12084 #ifdef RTE_LIBRTE_IXGBE_PMD
12085 	if (ret == -ENOTSUP)
12086 		ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12087 #endif
12088 #ifdef RTE_LIBRTE_BNXT_PMD
12089 	if (ret == -ENOTSUP)
12090 		ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12091 #endif
12092 	switch (ret) {
12093 	case 0:
12094 		break;
12095 	case -EINVAL:
12096 		printf("invalid is_on %d\n", is_on);
12097 		break;
12098 	case -ENODEV:
12099 		printf("invalid port_id %d\n", res->port_id);
12100 		break;
12101 	case -ENOTSUP:
12102 		printf("function not implemented\n");
12103 		break;
12104 	default:
12105 		printf("programming error: (%s)\n", strerror(-ret));
12106 	}
12107 }
12108 
12109 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12110 	.f = cmd_set_all_queues_drop_en_parsed,
12111 	.data = NULL,
12112 	.help_str = "set all queues drop <port_id> on|off",
12113 	.tokens = {
12114 		(void *)&cmd_all_queues_drop_en_set,
12115 		(void *)&cmd_all_queues_drop_en_all,
12116 		(void *)&cmd_all_queues_drop_en_queues,
12117 		(void *)&cmd_all_queues_drop_en_drop,
12118 		(void *)&cmd_all_queues_drop_en_port_id,
12119 		(void *)&cmd_all_queues_drop_en_on_off,
12120 		NULL,
12121 	},
12122 };
12123 
12124 /* vf split drop enable configuration */
12125 
12126 /* Common result structure for vf split drop enable */
12127 struct cmd_vf_split_drop_en_result {
12128 	cmdline_fixed_string_t set;
12129 	cmdline_fixed_string_t vf;
12130 	cmdline_fixed_string_t split;
12131 	cmdline_fixed_string_t drop;
12132 	uint8_t port_id;
12133 	uint16_t vf_id;
12134 	cmdline_fixed_string_t on_off;
12135 };
12136 
12137 /* Common CLI fields for vf split drop enable disable */
12138 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12139 	TOKEN_STRING_INITIALIZER
12140 		(struct cmd_vf_split_drop_en_result,
12141 		 set, "set");
12142 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12143 	TOKEN_STRING_INITIALIZER
12144 		(struct cmd_vf_split_drop_en_result,
12145 		 vf, "vf");
12146 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12147 	TOKEN_STRING_INITIALIZER
12148 		(struct cmd_vf_split_drop_en_result,
12149 		 split, "split");
12150 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12151 	TOKEN_STRING_INITIALIZER
12152 		(struct cmd_vf_split_drop_en_result,
12153 		 drop, "drop");
12154 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12155 	TOKEN_NUM_INITIALIZER
12156 		(struct cmd_vf_split_drop_en_result,
12157 		 port_id, UINT8);
12158 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12159 	TOKEN_NUM_INITIALIZER
12160 		(struct cmd_vf_split_drop_en_result,
12161 		 vf_id, UINT16);
12162 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12163 	TOKEN_STRING_INITIALIZER
12164 		(struct cmd_vf_split_drop_en_result,
12165 		 on_off, "on#off");
12166 
12167 static void
12168 cmd_set_vf_split_drop_en_parsed(
12169 	void *parsed_result,
12170 	__attribute__((unused)) struct cmdline *cl,
12171 	__attribute__((unused)) void *data)
12172 {
12173 	struct cmd_vf_split_drop_en_result *res = parsed_result;
12174 	int ret = -ENOTSUP;
12175 	int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12176 
12177 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12178 		return;
12179 
12180 #ifdef RTE_LIBRTE_IXGBE_PMD
12181 	ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12182 			is_on);
12183 #endif
12184 	switch (ret) {
12185 	case 0:
12186 		break;
12187 	case -EINVAL:
12188 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12189 		break;
12190 	case -ENODEV:
12191 		printf("invalid port_id %d\n", res->port_id);
12192 		break;
12193 	case -ENOTSUP:
12194 		printf("not supported on port %d\n", res->port_id);
12195 		break;
12196 	default:
12197 		printf("programming error: (%s)\n", strerror(-ret));
12198 	}
12199 }
12200 
12201 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12202 	.f = cmd_set_vf_split_drop_en_parsed,
12203 	.data = NULL,
12204 	.help_str = "set vf split drop <port_id> <vf_id> on|off",
12205 	.tokens = {
12206 		(void *)&cmd_vf_split_drop_en_set,
12207 		(void *)&cmd_vf_split_drop_en_vf,
12208 		(void *)&cmd_vf_split_drop_en_split,
12209 		(void *)&cmd_vf_split_drop_en_drop,
12210 		(void *)&cmd_vf_split_drop_en_port_id,
12211 		(void *)&cmd_vf_split_drop_en_vf_id,
12212 		(void *)&cmd_vf_split_drop_en_on_off,
12213 		NULL,
12214 	},
12215 };
12216 
12217 /* vf mac address configuration */
12218 
12219 /* Common result structure for vf mac address */
12220 struct cmd_set_vf_mac_addr_result {
12221 	cmdline_fixed_string_t set;
12222 	cmdline_fixed_string_t vf;
12223 	cmdline_fixed_string_t mac;
12224 	cmdline_fixed_string_t addr;
12225 	uint8_t port_id;
12226 	uint16_t vf_id;
12227 	struct ether_addr mac_addr;
12228 
12229 };
12230 
12231 /* Common CLI fields for vf split drop enable disable */
12232 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12233 	TOKEN_STRING_INITIALIZER
12234 		(struct cmd_set_vf_mac_addr_result,
12235 		 set, "set");
12236 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12237 	TOKEN_STRING_INITIALIZER
12238 		(struct cmd_set_vf_mac_addr_result,
12239 		 vf, "vf");
12240 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12241 	TOKEN_STRING_INITIALIZER
12242 		(struct cmd_set_vf_mac_addr_result,
12243 		 mac, "mac");
12244 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12245 	TOKEN_STRING_INITIALIZER
12246 		(struct cmd_set_vf_mac_addr_result,
12247 		 addr, "addr");
12248 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12249 	TOKEN_NUM_INITIALIZER
12250 		(struct cmd_set_vf_mac_addr_result,
12251 		 port_id, UINT8);
12252 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12253 	TOKEN_NUM_INITIALIZER
12254 		(struct cmd_set_vf_mac_addr_result,
12255 		 vf_id, UINT16);
12256 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12257 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12258 		 mac_addr);
12259 
12260 static void
12261 cmd_set_vf_mac_addr_parsed(
12262 	void *parsed_result,
12263 	__attribute__((unused)) struct cmdline *cl,
12264 	__attribute__((unused)) void *data)
12265 {
12266 	struct cmd_set_vf_mac_addr_result *res = parsed_result;
12267 	int ret = -ENOTSUP;
12268 
12269 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12270 		return;
12271 
12272 #ifdef RTE_LIBRTE_IXGBE_PMD
12273 	if (ret == -ENOTSUP)
12274 		ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12275 				&res->mac_addr);
12276 #endif
12277 #ifdef RTE_LIBRTE_I40E_PMD
12278 	if (ret == -ENOTSUP)
12279 		ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12280 				&res->mac_addr);
12281 #endif
12282 #ifdef RTE_LIBRTE_BNXT_PMD
12283 	if (ret == -ENOTSUP)
12284 		ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12285 				&res->mac_addr);
12286 #endif
12287 
12288 	switch (ret) {
12289 	case 0:
12290 		break;
12291 	case -EINVAL:
12292 		printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12293 		break;
12294 	case -ENODEV:
12295 		printf("invalid port_id %d\n", res->port_id);
12296 		break;
12297 	case -ENOTSUP:
12298 		printf("function not implemented\n");
12299 		break;
12300 	default:
12301 		printf("programming error: (%s)\n", strerror(-ret));
12302 	}
12303 }
12304 
12305 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12306 	.f = cmd_set_vf_mac_addr_parsed,
12307 	.data = NULL,
12308 	.help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12309 	.tokens = {
12310 		(void *)&cmd_set_vf_mac_addr_set,
12311 		(void *)&cmd_set_vf_mac_addr_vf,
12312 		(void *)&cmd_set_vf_mac_addr_mac,
12313 		(void *)&cmd_set_vf_mac_addr_addr,
12314 		(void *)&cmd_set_vf_mac_addr_port_id,
12315 		(void *)&cmd_set_vf_mac_addr_vf_id,
12316 		(void *)&cmd_set_vf_mac_addr_mac_addr,
12317 		NULL,
12318 	},
12319 };
12320 
12321 /* MACsec configuration */
12322 
12323 /* Common result structure for MACsec offload enable */
12324 struct cmd_macsec_offload_on_result {
12325 	cmdline_fixed_string_t set;
12326 	cmdline_fixed_string_t macsec;
12327 	cmdline_fixed_string_t offload;
12328 	uint8_t port_id;
12329 	cmdline_fixed_string_t on;
12330 	cmdline_fixed_string_t encrypt;
12331 	cmdline_fixed_string_t en_on_off;
12332 	cmdline_fixed_string_t replay_protect;
12333 	cmdline_fixed_string_t rp_on_off;
12334 };
12335 
12336 /* Common CLI fields for MACsec offload disable */
12337 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12338 	TOKEN_STRING_INITIALIZER
12339 		(struct cmd_macsec_offload_on_result,
12340 		 set, "set");
12341 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12342 	TOKEN_STRING_INITIALIZER
12343 		(struct cmd_macsec_offload_on_result,
12344 		 macsec, "macsec");
12345 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12346 	TOKEN_STRING_INITIALIZER
12347 		(struct cmd_macsec_offload_on_result,
12348 		 offload, "offload");
12349 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12350 	TOKEN_NUM_INITIALIZER
12351 		(struct cmd_macsec_offload_on_result,
12352 		 port_id, UINT8);
12353 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12354 	TOKEN_STRING_INITIALIZER
12355 		(struct cmd_macsec_offload_on_result,
12356 		 on, "on");
12357 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12358 	TOKEN_STRING_INITIALIZER
12359 		(struct cmd_macsec_offload_on_result,
12360 		 encrypt, "encrypt");
12361 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12362 	TOKEN_STRING_INITIALIZER
12363 		(struct cmd_macsec_offload_on_result,
12364 		 en_on_off, "on#off");
12365 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12366 	TOKEN_STRING_INITIALIZER
12367 		(struct cmd_macsec_offload_on_result,
12368 		 replay_protect, "replay-protect");
12369 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12370 	TOKEN_STRING_INITIALIZER
12371 		(struct cmd_macsec_offload_on_result,
12372 		 rp_on_off, "on#off");
12373 
12374 static void
12375 cmd_set_macsec_offload_on_parsed(
12376 	void *parsed_result,
12377 	__attribute__((unused)) struct cmdline *cl,
12378 	__attribute__((unused)) void *data)
12379 {
12380 	struct cmd_macsec_offload_on_result *res = parsed_result;
12381 	int ret = -ENOTSUP;
12382 	portid_t port_id = res->port_id;
12383 	int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12384 	int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12385 
12386 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12387 		return;
12388 
12389 	ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
12390 #ifdef RTE_LIBRTE_IXGBE_PMD
12391 	ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12392 #endif
12393 	RTE_SET_USED(en);
12394 	RTE_SET_USED(rp);
12395 
12396 	switch (ret) {
12397 	case 0:
12398 		break;
12399 	case -ENODEV:
12400 		printf("invalid port_id %d\n", port_id);
12401 		break;
12402 	case -ENOTSUP:
12403 		printf("not supported on port %d\n", port_id);
12404 		break;
12405 	default:
12406 		printf("programming error: (%s)\n", strerror(-ret));
12407 	}
12408 }
12409 
12410 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12411 	.f = cmd_set_macsec_offload_on_parsed,
12412 	.data = NULL,
12413 	.help_str = "set macsec offload <port_id> on "
12414 		"encrypt on|off replay-protect on|off",
12415 	.tokens = {
12416 		(void *)&cmd_macsec_offload_on_set,
12417 		(void *)&cmd_macsec_offload_on_macsec,
12418 		(void *)&cmd_macsec_offload_on_offload,
12419 		(void *)&cmd_macsec_offload_on_port_id,
12420 		(void *)&cmd_macsec_offload_on_on,
12421 		(void *)&cmd_macsec_offload_on_encrypt,
12422 		(void *)&cmd_macsec_offload_on_en_on_off,
12423 		(void *)&cmd_macsec_offload_on_replay_protect,
12424 		(void *)&cmd_macsec_offload_on_rp_on_off,
12425 		NULL,
12426 	},
12427 };
12428 
12429 /* Common result structure for MACsec offload disable */
12430 struct cmd_macsec_offload_off_result {
12431 	cmdline_fixed_string_t set;
12432 	cmdline_fixed_string_t macsec;
12433 	cmdline_fixed_string_t offload;
12434 	uint8_t port_id;
12435 	cmdline_fixed_string_t off;
12436 };
12437 
12438 /* Common CLI fields for MACsec offload disable */
12439 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12440 	TOKEN_STRING_INITIALIZER
12441 		(struct cmd_macsec_offload_off_result,
12442 		 set, "set");
12443 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12444 	TOKEN_STRING_INITIALIZER
12445 		(struct cmd_macsec_offload_off_result,
12446 		 macsec, "macsec");
12447 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12448 	TOKEN_STRING_INITIALIZER
12449 		(struct cmd_macsec_offload_off_result,
12450 		 offload, "offload");
12451 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12452 	TOKEN_NUM_INITIALIZER
12453 		(struct cmd_macsec_offload_off_result,
12454 		 port_id, UINT8);
12455 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12456 	TOKEN_STRING_INITIALIZER
12457 		(struct cmd_macsec_offload_off_result,
12458 		 off, "off");
12459 
12460 static void
12461 cmd_set_macsec_offload_off_parsed(
12462 	void *parsed_result,
12463 	__attribute__((unused)) struct cmdline *cl,
12464 	__attribute__((unused)) void *data)
12465 {
12466 	struct cmd_macsec_offload_off_result *res = parsed_result;
12467 	int ret = -ENOTSUP;
12468 	portid_t port_id = res->port_id;
12469 
12470 	if (port_id_is_invalid(port_id, ENABLED_WARN))
12471 		return;
12472 
12473 	ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
12474 #ifdef RTE_LIBRTE_IXGBE_PMD
12475 	ret = rte_pmd_ixgbe_macsec_disable(port_id);
12476 #endif
12477 
12478 	switch (ret) {
12479 	case 0:
12480 		break;
12481 	case -ENODEV:
12482 		printf("invalid port_id %d\n", port_id);
12483 		break;
12484 	case -ENOTSUP:
12485 		printf("not supported on port %d\n", port_id);
12486 		break;
12487 	default:
12488 		printf("programming error: (%s)\n", strerror(-ret));
12489 	}
12490 }
12491 
12492 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12493 	.f = cmd_set_macsec_offload_off_parsed,
12494 	.data = NULL,
12495 	.help_str = "set macsec offload <port_id> off",
12496 	.tokens = {
12497 		(void *)&cmd_macsec_offload_off_set,
12498 		(void *)&cmd_macsec_offload_off_macsec,
12499 		(void *)&cmd_macsec_offload_off_offload,
12500 		(void *)&cmd_macsec_offload_off_port_id,
12501 		(void *)&cmd_macsec_offload_off_off,
12502 		NULL,
12503 	},
12504 };
12505 
12506 /* Common result structure for MACsec secure connection configure */
12507 struct cmd_macsec_sc_result {
12508 	cmdline_fixed_string_t set;
12509 	cmdline_fixed_string_t macsec;
12510 	cmdline_fixed_string_t sc;
12511 	cmdline_fixed_string_t tx_rx;
12512 	uint8_t port_id;
12513 	struct ether_addr mac;
12514 	uint16_t pi;
12515 };
12516 
12517 /* Common CLI fields for MACsec secure connection configure */
12518 cmdline_parse_token_string_t cmd_macsec_sc_set =
12519 	TOKEN_STRING_INITIALIZER
12520 		(struct cmd_macsec_sc_result,
12521 		 set, "set");
12522 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12523 	TOKEN_STRING_INITIALIZER
12524 		(struct cmd_macsec_sc_result,
12525 		 macsec, "macsec");
12526 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12527 	TOKEN_STRING_INITIALIZER
12528 		(struct cmd_macsec_sc_result,
12529 		 sc, "sc");
12530 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12531 	TOKEN_STRING_INITIALIZER
12532 		(struct cmd_macsec_sc_result,
12533 		 tx_rx, "tx#rx");
12534 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12535 	TOKEN_NUM_INITIALIZER
12536 		(struct cmd_macsec_sc_result,
12537 		 port_id, UINT8);
12538 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12539 	TOKEN_ETHERADDR_INITIALIZER
12540 		(struct cmd_macsec_sc_result,
12541 		 mac);
12542 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12543 	TOKEN_NUM_INITIALIZER
12544 		(struct cmd_macsec_sc_result,
12545 		 pi, UINT16);
12546 
12547 static void
12548 cmd_set_macsec_sc_parsed(
12549 	void *parsed_result,
12550 	__attribute__((unused)) struct cmdline *cl,
12551 	__attribute__((unused)) void *data)
12552 {
12553 	struct cmd_macsec_sc_result *res = parsed_result;
12554 	int ret = -ENOTSUP;
12555 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12556 
12557 #ifdef RTE_LIBRTE_IXGBE_PMD
12558 	ret = is_tx ?
12559 		rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12560 				res->mac.addr_bytes) :
12561 		rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12562 				res->mac.addr_bytes, res->pi);
12563 #endif
12564 	RTE_SET_USED(is_tx);
12565 
12566 	switch (ret) {
12567 	case 0:
12568 		break;
12569 	case -ENODEV:
12570 		printf("invalid port_id %d\n", res->port_id);
12571 		break;
12572 	case -ENOTSUP:
12573 		printf("not supported on port %d\n", res->port_id);
12574 		break;
12575 	default:
12576 		printf("programming error: (%s)\n", strerror(-ret));
12577 	}
12578 }
12579 
12580 cmdline_parse_inst_t cmd_set_macsec_sc = {
12581 	.f = cmd_set_macsec_sc_parsed,
12582 	.data = NULL,
12583 	.help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12584 	.tokens = {
12585 		(void *)&cmd_macsec_sc_set,
12586 		(void *)&cmd_macsec_sc_macsec,
12587 		(void *)&cmd_macsec_sc_sc,
12588 		(void *)&cmd_macsec_sc_tx_rx,
12589 		(void *)&cmd_macsec_sc_port_id,
12590 		(void *)&cmd_macsec_sc_mac,
12591 		(void *)&cmd_macsec_sc_pi,
12592 		NULL,
12593 	},
12594 };
12595 
12596 /* Common result structure for MACsec secure connection configure */
12597 struct cmd_macsec_sa_result {
12598 	cmdline_fixed_string_t set;
12599 	cmdline_fixed_string_t macsec;
12600 	cmdline_fixed_string_t sa;
12601 	cmdline_fixed_string_t tx_rx;
12602 	uint8_t port_id;
12603 	uint8_t idx;
12604 	uint8_t an;
12605 	uint32_t pn;
12606 	cmdline_fixed_string_t key;
12607 };
12608 
12609 /* Common CLI fields for MACsec secure connection configure */
12610 cmdline_parse_token_string_t cmd_macsec_sa_set =
12611 	TOKEN_STRING_INITIALIZER
12612 		(struct cmd_macsec_sa_result,
12613 		 set, "set");
12614 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12615 	TOKEN_STRING_INITIALIZER
12616 		(struct cmd_macsec_sa_result,
12617 		 macsec, "macsec");
12618 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12619 	TOKEN_STRING_INITIALIZER
12620 		(struct cmd_macsec_sa_result,
12621 		 sa, "sa");
12622 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12623 	TOKEN_STRING_INITIALIZER
12624 		(struct cmd_macsec_sa_result,
12625 		 tx_rx, "tx#rx");
12626 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12627 	TOKEN_NUM_INITIALIZER
12628 		(struct cmd_macsec_sa_result,
12629 		 port_id, UINT8);
12630 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12631 	TOKEN_NUM_INITIALIZER
12632 		(struct cmd_macsec_sa_result,
12633 		 idx, UINT8);
12634 cmdline_parse_token_num_t cmd_macsec_sa_an =
12635 	TOKEN_NUM_INITIALIZER
12636 		(struct cmd_macsec_sa_result,
12637 		 an, UINT8);
12638 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12639 	TOKEN_NUM_INITIALIZER
12640 		(struct cmd_macsec_sa_result,
12641 		 pn, UINT32);
12642 cmdline_parse_token_string_t cmd_macsec_sa_key =
12643 	TOKEN_STRING_INITIALIZER
12644 		(struct cmd_macsec_sa_result,
12645 		 key, NULL);
12646 
12647 static void
12648 cmd_set_macsec_sa_parsed(
12649 	void *parsed_result,
12650 	__attribute__((unused)) struct cmdline *cl,
12651 	__attribute__((unused)) void *data)
12652 {
12653 	struct cmd_macsec_sa_result *res = parsed_result;
12654 	int ret = -ENOTSUP;
12655 	int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12656 	uint8_t key[16] = { 0 };
12657 	uint8_t xdgt0;
12658 	uint8_t xdgt1;
12659 	int key_len;
12660 	int i;
12661 
12662 	key_len = strlen(res->key) / 2;
12663 	if (key_len > 16)
12664 		key_len = 16;
12665 
12666 	for (i = 0; i < key_len; i++) {
12667 		xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12668 		if (xdgt0 == 0xFF)
12669 			return;
12670 		xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12671 		if (xdgt1 == 0xFF)
12672 			return;
12673 		key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12674 	}
12675 
12676 #ifdef RTE_LIBRTE_IXGBE_PMD
12677 	ret = is_tx ?
12678 		rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12679 			res->idx, res->an, res->pn, key) :
12680 		rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12681 			res->idx, res->an, res->pn, key);
12682 #endif
12683 	RTE_SET_USED(is_tx);
12684 	RTE_SET_USED(key);
12685 
12686 	switch (ret) {
12687 	case 0:
12688 		break;
12689 	case -EINVAL:
12690 		printf("invalid idx %d or an %d\n", res->idx, res->an);
12691 		break;
12692 	case -ENODEV:
12693 		printf("invalid port_id %d\n", res->port_id);
12694 		break;
12695 	case -ENOTSUP:
12696 		printf("not supported on port %d\n", res->port_id);
12697 		break;
12698 	default:
12699 		printf("programming error: (%s)\n", strerror(-ret));
12700 	}
12701 }
12702 
12703 cmdline_parse_inst_t cmd_set_macsec_sa = {
12704 	.f = cmd_set_macsec_sa_parsed,
12705 	.data = NULL,
12706 	.help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12707 	.tokens = {
12708 		(void *)&cmd_macsec_sa_set,
12709 		(void *)&cmd_macsec_sa_macsec,
12710 		(void *)&cmd_macsec_sa_sa,
12711 		(void *)&cmd_macsec_sa_tx_rx,
12712 		(void *)&cmd_macsec_sa_port_id,
12713 		(void *)&cmd_macsec_sa_idx,
12714 		(void *)&cmd_macsec_sa_an,
12715 		(void *)&cmd_macsec_sa_pn,
12716 		(void *)&cmd_macsec_sa_key,
12717 		NULL,
12718 	},
12719 };
12720 
12721 /* VF unicast promiscuous mode configuration */
12722 
12723 /* Common result structure for VF unicast promiscuous mode */
12724 struct cmd_vf_promisc_result {
12725 	cmdline_fixed_string_t set;
12726 	cmdline_fixed_string_t vf;
12727 	cmdline_fixed_string_t promisc;
12728 	uint8_t port_id;
12729 	uint32_t vf_id;
12730 	cmdline_fixed_string_t on_off;
12731 };
12732 
12733 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12734 cmdline_parse_token_string_t cmd_vf_promisc_set =
12735 	TOKEN_STRING_INITIALIZER
12736 		(struct cmd_vf_promisc_result,
12737 		 set, "set");
12738 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12739 	TOKEN_STRING_INITIALIZER
12740 		(struct cmd_vf_promisc_result,
12741 		 vf, "vf");
12742 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12743 	TOKEN_STRING_INITIALIZER
12744 		(struct cmd_vf_promisc_result,
12745 		 promisc, "promisc");
12746 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12747 	TOKEN_NUM_INITIALIZER
12748 		(struct cmd_vf_promisc_result,
12749 		 port_id, UINT8);
12750 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12751 	TOKEN_NUM_INITIALIZER
12752 		(struct cmd_vf_promisc_result,
12753 		 vf_id, UINT32);
12754 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12755 	TOKEN_STRING_INITIALIZER
12756 		(struct cmd_vf_promisc_result,
12757 		 on_off, "on#off");
12758 
12759 static void
12760 cmd_set_vf_promisc_parsed(
12761 	void *parsed_result,
12762 	__attribute__((unused)) struct cmdline *cl,
12763 	__attribute__((unused)) void *data)
12764 {
12765 	struct cmd_vf_promisc_result *res = parsed_result;
12766 	int ret = -ENOTSUP;
12767 
12768 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12769 
12770 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12771 		return;
12772 
12773 #ifdef RTE_LIBRTE_I40E_PMD
12774 	ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12775 						  res->vf_id, is_on);
12776 #endif
12777 
12778 	switch (ret) {
12779 	case 0:
12780 		break;
12781 	case -EINVAL:
12782 		printf("invalid vf_id %d\n", res->vf_id);
12783 		break;
12784 	case -ENODEV:
12785 		printf("invalid port_id %d\n", res->port_id);
12786 		break;
12787 	case -ENOTSUP:
12788 		printf("function not implemented\n");
12789 		break;
12790 	default:
12791 		printf("programming error: (%s)\n", strerror(-ret));
12792 	}
12793 }
12794 
12795 cmdline_parse_inst_t cmd_set_vf_promisc = {
12796 	.f = cmd_set_vf_promisc_parsed,
12797 	.data = NULL,
12798 	.help_str = "set vf promisc <port_id> <vf_id> on|off: "
12799 		"Set unicast promiscuous mode for a VF from the PF",
12800 	.tokens = {
12801 		(void *)&cmd_vf_promisc_set,
12802 		(void *)&cmd_vf_promisc_vf,
12803 		(void *)&cmd_vf_promisc_promisc,
12804 		(void *)&cmd_vf_promisc_port_id,
12805 		(void *)&cmd_vf_promisc_vf_id,
12806 		(void *)&cmd_vf_promisc_on_off,
12807 		NULL,
12808 	},
12809 };
12810 
12811 /* VF multicast promiscuous mode configuration */
12812 
12813 /* Common result structure for VF multicast promiscuous mode */
12814 struct cmd_vf_allmulti_result {
12815 	cmdline_fixed_string_t set;
12816 	cmdline_fixed_string_t vf;
12817 	cmdline_fixed_string_t allmulti;
12818 	uint8_t port_id;
12819 	uint32_t vf_id;
12820 	cmdline_fixed_string_t on_off;
12821 };
12822 
12823 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12824 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12825 	TOKEN_STRING_INITIALIZER
12826 		(struct cmd_vf_allmulti_result,
12827 		 set, "set");
12828 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12829 	TOKEN_STRING_INITIALIZER
12830 		(struct cmd_vf_allmulti_result,
12831 		 vf, "vf");
12832 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12833 	TOKEN_STRING_INITIALIZER
12834 		(struct cmd_vf_allmulti_result,
12835 		 allmulti, "allmulti");
12836 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12837 	TOKEN_NUM_INITIALIZER
12838 		(struct cmd_vf_allmulti_result,
12839 		 port_id, UINT8);
12840 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12841 	TOKEN_NUM_INITIALIZER
12842 		(struct cmd_vf_allmulti_result,
12843 		 vf_id, UINT32);
12844 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12845 	TOKEN_STRING_INITIALIZER
12846 		(struct cmd_vf_allmulti_result,
12847 		 on_off, "on#off");
12848 
12849 static void
12850 cmd_set_vf_allmulti_parsed(
12851 	void *parsed_result,
12852 	__attribute__((unused)) struct cmdline *cl,
12853 	__attribute__((unused)) void *data)
12854 {
12855 	struct cmd_vf_allmulti_result *res = parsed_result;
12856 	int ret = -ENOTSUP;
12857 
12858 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12859 
12860 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12861 		return;
12862 
12863 #ifdef RTE_LIBRTE_I40E_PMD
12864 	ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12865 						    res->vf_id, is_on);
12866 #endif
12867 
12868 	switch (ret) {
12869 	case 0:
12870 		break;
12871 	case -EINVAL:
12872 		printf("invalid vf_id %d\n", res->vf_id);
12873 		break;
12874 	case -ENODEV:
12875 		printf("invalid port_id %d\n", res->port_id);
12876 		break;
12877 	case -ENOTSUP:
12878 		printf("function not implemented\n");
12879 		break;
12880 	default:
12881 		printf("programming error: (%s)\n", strerror(-ret));
12882 	}
12883 }
12884 
12885 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12886 	.f = cmd_set_vf_allmulti_parsed,
12887 	.data = NULL,
12888 	.help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12889 		"Set multicast promiscuous mode for a VF from the PF",
12890 	.tokens = {
12891 		(void *)&cmd_vf_allmulti_set,
12892 		(void *)&cmd_vf_allmulti_vf,
12893 		(void *)&cmd_vf_allmulti_allmulti,
12894 		(void *)&cmd_vf_allmulti_port_id,
12895 		(void *)&cmd_vf_allmulti_vf_id,
12896 		(void *)&cmd_vf_allmulti_on_off,
12897 		NULL,
12898 	},
12899 };
12900 
12901 /* vf broadcast mode configuration */
12902 
12903 /* Common result structure for vf broadcast */
12904 struct cmd_set_vf_broadcast_result {
12905 	cmdline_fixed_string_t set;
12906 	cmdline_fixed_string_t vf;
12907 	cmdline_fixed_string_t broadcast;
12908 	uint8_t port_id;
12909 	uint16_t vf_id;
12910 	cmdline_fixed_string_t on_off;
12911 };
12912 
12913 /* Common CLI fields for vf broadcast enable disable */
12914 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12915 	TOKEN_STRING_INITIALIZER
12916 		(struct cmd_set_vf_broadcast_result,
12917 		 set, "set");
12918 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12919 	TOKEN_STRING_INITIALIZER
12920 		(struct cmd_set_vf_broadcast_result,
12921 		 vf, "vf");
12922 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12923 	TOKEN_STRING_INITIALIZER
12924 		(struct cmd_set_vf_broadcast_result,
12925 		 broadcast, "broadcast");
12926 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12927 	TOKEN_NUM_INITIALIZER
12928 		(struct cmd_set_vf_broadcast_result,
12929 		 port_id, UINT8);
12930 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12931 	TOKEN_NUM_INITIALIZER
12932 		(struct cmd_set_vf_broadcast_result,
12933 		 vf_id, UINT16);
12934 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12935 	TOKEN_STRING_INITIALIZER
12936 		(struct cmd_set_vf_broadcast_result,
12937 		 on_off, "on#off");
12938 
12939 static void
12940 cmd_set_vf_broadcast_parsed(
12941 	void *parsed_result,
12942 	__attribute__((unused)) struct cmdline *cl,
12943 	__attribute__((unused)) void *data)
12944 {
12945 	struct cmd_set_vf_broadcast_result *res = parsed_result;
12946 	int ret = -ENOTSUP;
12947 
12948 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12949 
12950 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12951 		return;
12952 
12953 #ifdef RTE_LIBRTE_I40E_PMD
12954 	ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12955 					    res->vf_id, is_on);
12956 #endif
12957 
12958 	switch (ret) {
12959 	case 0:
12960 		break;
12961 	case -EINVAL:
12962 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12963 		break;
12964 	case -ENODEV:
12965 		printf("invalid port_id %d\n", res->port_id);
12966 		break;
12967 	case -ENOTSUP:
12968 		printf("function not implemented\n");
12969 		break;
12970 	default:
12971 		printf("programming error: (%s)\n", strerror(-ret));
12972 	}
12973 }
12974 
12975 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12976 	.f = cmd_set_vf_broadcast_parsed,
12977 	.data = NULL,
12978 	.help_str = "set vf broadcast <port_id> <vf_id> on|off",
12979 	.tokens = {
12980 		(void *)&cmd_set_vf_broadcast_set,
12981 		(void *)&cmd_set_vf_broadcast_vf,
12982 		(void *)&cmd_set_vf_broadcast_broadcast,
12983 		(void *)&cmd_set_vf_broadcast_port_id,
12984 		(void *)&cmd_set_vf_broadcast_vf_id,
12985 		(void *)&cmd_set_vf_broadcast_on_off,
12986 		NULL,
12987 	},
12988 };
12989 
12990 /* vf vlan tag configuration */
12991 
12992 /* Common result structure for vf vlan tag */
12993 struct cmd_set_vf_vlan_tag_result {
12994 	cmdline_fixed_string_t set;
12995 	cmdline_fixed_string_t vf;
12996 	cmdline_fixed_string_t vlan;
12997 	cmdline_fixed_string_t tag;
12998 	uint8_t port_id;
12999 	uint16_t vf_id;
13000 	cmdline_fixed_string_t on_off;
13001 };
13002 
13003 /* Common CLI fields for vf vlan tag enable disable */
13004 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13005 	TOKEN_STRING_INITIALIZER
13006 		(struct cmd_set_vf_vlan_tag_result,
13007 		 set, "set");
13008 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13009 	TOKEN_STRING_INITIALIZER
13010 		(struct cmd_set_vf_vlan_tag_result,
13011 		 vf, "vf");
13012 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13013 	TOKEN_STRING_INITIALIZER
13014 		(struct cmd_set_vf_vlan_tag_result,
13015 		 vlan, "vlan");
13016 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13017 	TOKEN_STRING_INITIALIZER
13018 		(struct cmd_set_vf_vlan_tag_result,
13019 		 tag, "tag");
13020 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13021 	TOKEN_NUM_INITIALIZER
13022 		(struct cmd_set_vf_vlan_tag_result,
13023 		 port_id, UINT8);
13024 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13025 	TOKEN_NUM_INITIALIZER
13026 		(struct cmd_set_vf_vlan_tag_result,
13027 		 vf_id, UINT16);
13028 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13029 	TOKEN_STRING_INITIALIZER
13030 		(struct cmd_set_vf_vlan_tag_result,
13031 		 on_off, "on#off");
13032 
13033 static void
13034 cmd_set_vf_vlan_tag_parsed(
13035 	void *parsed_result,
13036 	__attribute__((unused)) struct cmdline *cl,
13037 	__attribute__((unused)) void *data)
13038 {
13039 	struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13040 	int ret = -ENOTSUP;
13041 
13042 	__rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13043 
13044 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13045 		return;
13046 
13047 #ifdef RTE_LIBRTE_I40E_PMD
13048 	ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13049 					   res->vf_id, is_on);
13050 #endif
13051 
13052 	switch (ret) {
13053 	case 0:
13054 		break;
13055 	case -EINVAL:
13056 		printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13057 		break;
13058 	case -ENODEV:
13059 		printf("invalid port_id %d\n", res->port_id);
13060 		break;
13061 	case -ENOTSUP:
13062 		printf("function not implemented\n");
13063 		break;
13064 	default:
13065 		printf("programming error: (%s)\n", strerror(-ret));
13066 	}
13067 }
13068 
13069 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13070 	.f = cmd_set_vf_vlan_tag_parsed,
13071 	.data = NULL,
13072 	.help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13073 	.tokens = {
13074 		(void *)&cmd_set_vf_vlan_tag_set,
13075 		(void *)&cmd_set_vf_vlan_tag_vf,
13076 		(void *)&cmd_set_vf_vlan_tag_vlan,
13077 		(void *)&cmd_set_vf_vlan_tag_tag,
13078 		(void *)&cmd_set_vf_vlan_tag_port_id,
13079 		(void *)&cmd_set_vf_vlan_tag_vf_id,
13080 		(void *)&cmd_set_vf_vlan_tag_on_off,
13081 		NULL,
13082 	},
13083 };
13084 
13085 /* Common definition of VF and TC TX bandwidth configuration */
13086 struct cmd_vf_tc_bw_result {
13087 	cmdline_fixed_string_t set;
13088 	cmdline_fixed_string_t vf;
13089 	cmdline_fixed_string_t tc;
13090 	cmdline_fixed_string_t tx;
13091 	cmdline_fixed_string_t min_bw;
13092 	cmdline_fixed_string_t max_bw;
13093 	cmdline_fixed_string_t strict_link_prio;
13094 	uint8_t port_id;
13095 	uint16_t vf_id;
13096 	uint8_t tc_no;
13097 	uint32_t bw;
13098 	cmdline_fixed_string_t bw_list;
13099 	uint8_t tc_map;
13100 };
13101 
13102 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13103 	TOKEN_STRING_INITIALIZER
13104 		(struct cmd_vf_tc_bw_result,
13105 		 set, "set");
13106 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13107 	TOKEN_STRING_INITIALIZER
13108 		(struct cmd_vf_tc_bw_result,
13109 		 vf, "vf");
13110 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13111 	TOKEN_STRING_INITIALIZER
13112 		(struct cmd_vf_tc_bw_result,
13113 		 tc, "tc");
13114 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13115 	TOKEN_STRING_INITIALIZER
13116 		(struct cmd_vf_tc_bw_result,
13117 		 tx, "tx");
13118 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13119 	TOKEN_STRING_INITIALIZER
13120 		(struct cmd_vf_tc_bw_result,
13121 		 strict_link_prio, "strict-link-priority");
13122 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13123 	TOKEN_STRING_INITIALIZER
13124 		(struct cmd_vf_tc_bw_result,
13125 		 min_bw, "min-bandwidth");
13126 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13127 	TOKEN_STRING_INITIALIZER
13128 		(struct cmd_vf_tc_bw_result,
13129 		 max_bw, "max-bandwidth");
13130 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13131 	TOKEN_NUM_INITIALIZER
13132 		(struct cmd_vf_tc_bw_result,
13133 		 port_id, UINT8);
13134 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13135 	TOKEN_NUM_INITIALIZER
13136 		(struct cmd_vf_tc_bw_result,
13137 		 vf_id, UINT16);
13138 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13139 	TOKEN_NUM_INITIALIZER
13140 		(struct cmd_vf_tc_bw_result,
13141 		 tc_no, UINT8);
13142 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13143 	TOKEN_NUM_INITIALIZER
13144 		(struct cmd_vf_tc_bw_result,
13145 		 bw, UINT32);
13146 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13147 	TOKEN_STRING_INITIALIZER
13148 		(struct cmd_vf_tc_bw_result,
13149 		 bw_list, NULL);
13150 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13151 	TOKEN_NUM_INITIALIZER
13152 		(struct cmd_vf_tc_bw_result,
13153 		 tc_map, UINT8);
13154 
13155 /* VF max bandwidth setting */
13156 static void
13157 cmd_vf_max_bw_parsed(
13158 	void *parsed_result,
13159 	__attribute__((unused)) struct cmdline *cl,
13160 	__attribute__((unused)) void *data)
13161 {
13162 	struct cmd_vf_tc_bw_result *res = parsed_result;
13163 	int ret = -ENOTSUP;
13164 
13165 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13166 		return;
13167 
13168 #ifdef RTE_LIBRTE_I40E_PMD
13169 	ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13170 					 res->vf_id, res->bw);
13171 #endif
13172 
13173 	switch (ret) {
13174 	case 0:
13175 		break;
13176 	case -EINVAL:
13177 		printf("invalid vf_id %d or bandwidth %d\n",
13178 		       res->vf_id, res->bw);
13179 		break;
13180 	case -ENODEV:
13181 		printf("invalid port_id %d\n", res->port_id);
13182 		break;
13183 	case -ENOTSUP:
13184 		printf("function not implemented\n");
13185 		break;
13186 	default:
13187 		printf("programming error: (%s)\n", strerror(-ret));
13188 	}
13189 }
13190 
13191 cmdline_parse_inst_t cmd_vf_max_bw = {
13192 	.f = cmd_vf_max_bw_parsed,
13193 	.data = NULL,
13194 	.help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13195 	.tokens = {
13196 		(void *)&cmd_vf_tc_bw_set,
13197 		(void *)&cmd_vf_tc_bw_vf,
13198 		(void *)&cmd_vf_tc_bw_tx,
13199 		(void *)&cmd_vf_tc_bw_max_bw,
13200 		(void *)&cmd_vf_tc_bw_port_id,
13201 		(void *)&cmd_vf_tc_bw_vf_id,
13202 		(void *)&cmd_vf_tc_bw_bw,
13203 		NULL,
13204 	},
13205 };
13206 
13207 static int
13208 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13209 			   uint8_t *tc_num,
13210 			   char *str)
13211 {
13212 	uint32_t size;
13213 	const char *p, *p0 = str;
13214 	char s[256];
13215 	char *end;
13216 	char *str_fld[16];
13217 	uint16_t i;
13218 	int ret;
13219 
13220 	p = strchr(p0, '(');
13221 	if (p == NULL) {
13222 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13223 		return -1;
13224 	}
13225 	p++;
13226 	p0 = strchr(p, ')');
13227 	if (p0 == NULL) {
13228 		printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13229 		return -1;
13230 	}
13231 	size = p0 - p;
13232 	if (size >= sizeof(s)) {
13233 		printf("The string size exceeds the internal buffer size\n");
13234 		return -1;
13235 	}
13236 	snprintf(s, sizeof(s), "%.*s", size, p);
13237 	ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13238 	if (ret <= 0) {
13239 		printf("Failed to get the bandwidth list. ");
13240 		return -1;
13241 	}
13242 	*tc_num = ret;
13243 	for (i = 0; i < ret; i++)
13244 		bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13245 
13246 	return 0;
13247 }
13248 
13249 /* TC min bandwidth setting */
13250 static void
13251 cmd_vf_tc_min_bw_parsed(
13252 	void *parsed_result,
13253 	__attribute__((unused)) struct cmdline *cl,
13254 	__attribute__((unused)) void *data)
13255 {
13256 	struct cmd_vf_tc_bw_result *res = parsed_result;
13257 	uint8_t tc_num;
13258 	uint8_t bw[16];
13259 	int ret = -ENOTSUP;
13260 
13261 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13262 		return;
13263 
13264 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13265 	if (ret)
13266 		return;
13267 
13268 #ifdef RTE_LIBRTE_I40E_PMD
13269 	ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13270 					      tc_num, bw);
13271 #endif
13272 
13273 	switch (ret) {
13274 	case 0:
13275 		break;
13276 	case -EINVAL:
13277 		printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13278 		break;
13279 	case -ENODEV:
13280 		printf("invalid port_id %d\n", res->port_id);
13281 		break;
13282 	case -ENOTSUP:
13283 		printf("function not implemented\n");
13284 		break;
13285 	default:
13286 		printf("programming error: (%s)\n", strerror(-ret));
13287 	}
13288 }
13289 
13290 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13291 	.f = cmd_vf_tc_min_bw_parsed,
13292 	.data = NULL,
13293 	.help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13294 		    " <bw1, bw2, ...>",
13295 	.tokens = {
13296 		(void *)&cmd_vf_tc_bw_set,
13297 		(void *)&cmd_vf_tc_bw_vf,
13298 		(void *)&cmd_vf_tc_bw_tc,
13299 		(void *)&cmd_vf_tc_bw_tx,
13300 		(void *)&cmd_vf_tc_bw_min_bw,
13301 		(void *)&cmd_vf_tc_bw_port_id,
13302 		(void *)&cmd_vf_tc_bw_vf_id,
13303 		(void *)&cmd_vf_tc_bw_bw_list,
13304 		NULL,
13305 	},
13306 };
13307 
13308 static void
13309 cmd_tc_min_bw_parsed(
13310 	void *parsed_result,
13311 	__attribute__((unused)) struct cmdline *cl,
13312 	__attribute__((unused)) void *data)
13313 {
13314 	struct cmd_vf_tc_bw_result *res = parsed_result;
13315 	struct rte_port *port;
13316 	uint8_t tc_num;
13317 	uint8_t bw[16];
13318 	int ret = -ENOTSUP;
13319 
13320 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13321 		return;
13322 
13323 	port = &ports[res->port_id];
13324 	/** Check if the port is not started **/
13325 	if (port->port_status != RTE_PORT_STOPPED) {
13326 		printf("Please stop port %d first\n", res->port_id);
13327 		return;
13328 	}
13329 
13330 	ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13331 	if (ret)
13332 		return;
13333 
13334 #ifdef RTE_LIBRTE_IXGBE_PMD
13335 	ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13336 #endif
13337 
13338 	switch (ret) {
13339 	case 0:
13340 		break;
13341 	case -EINVAL:
13342 		printf("invalid bandwidth\n");
13343 		break;
13344 	case -ENODEV:
13345 		printf("invalid port_id %d\n", res->port_id);
13346 		break;
13347 	case -ENOTSUP:
13348 		printf("function not implemented\n");
13349 		break;
13350 	default:
13351 		printf("programming error: (%s)\n", strerror(-ret));
13352 	}
13353 }
13354 
13355 cmdline_parse_inst_t cmd_tc_min_bw = {
13356 	.f = cmd_tc_min_bw_parsed,
13357 	.data = NULL,
13358 	.help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13359 	.tokens = {
13360 		(void *)&cmd_vf_tc_bw_set,
13361 		(void *)&cmd_vf_tc_bw_tc,
13362 		(void *)&cmd_vf_tc_bw_tx,
13363 		(void *)&cmd_vf_tc_bw_min_bw,
13364 		(void *)&cmd_vf_tc_bw_port_id,
13365 		(void *)&cmd_vf_tc_bw_bw_list,
13366 		NULL,
13367 	},
13368 };
13369 
13370 /* TC max bandwidth setting */
13371 static void
13372 cmd_vf_tc_max_bw_parsed(
13373 	void *parsed_result,
13374 	__attribute__((unused)) struct cmdline *cl,
13375 	__attribute__((unused)) void *data)
13376 {
13377 	struct cmd_vf_tc_bw_result *res = parsed_result;
13378 	int ret = -ENOTSUP;
13379 
13380 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13381 		return;
13382 
13383 #ifdef RTE_LIBRTE_I40E_PMD
13384 	ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13385 					    res->tc_no, res->bw);
13386 #endif
13387 
13388 	switch (ret) {
13389 	case 0:
13390 		break;
13391 	case -EINVAL:
13392 		printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
13393 		       res->vf_id, res->tc_no, res->bw);
13394 		break;
13395 	case -ENODEV:
13396 		printf("invalid port_id %d\n", res->port_id);
13397 		break;
13398 	case -ENOTSUP:
13399 		printf("function not implemented\n");
13400 		break;
13401 	default:
13402 		printf("programming error: (%s)\n", strerror(-ret));
13403 	}
13404 }
13405 
13406 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13407 	.f = cmd_vf_tc_max_bw_parsed,
13408 	.data = NULL,
13409 	.help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13410 		    " <bandwidth>",
13411 	.tokens = {
13412 		(void *)&cmd_vf_tc_bw_set,
13413 		(void *)&cmd_vf_tc_bw_vf,
13414 		(void *)&cmd_vf_tc_bw_tc,
13415 		(void *)&cmd_vf_tc_bw_tx,
13416 		(void *)&cmd_vf_tc_bw_max_bw,
13417 		(void *)&cmd_vf_tc_bw_port_id,
13418 		(void *)&cmd_vf_tc_bw_vf_id,
13419 		(void *)&cmd_vf_tc_bw_tc_no,
13420 		(void *)&cmd_vf_tc_bw_bw,
13421 		NULL,
13422 	},
13423 };
13424 
13425 /* Strict link priority scheduling mode setting */
13426 static void
13427 cmd_strict_link_prio_parsed(
13428 	void *parsed_result,
13429 	__attribute__((unused)) struct cmdline *cl,
13430 	__attribute__((unused)) void *data)
13431 {
13432 	struct cmd_vf_tc_bw_result *res = parsed_result;
13433 	int ret = -ENOTSUP;
13434 
13435 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13436 		return;
13437 
13438 #ifdef RTE_LIBRTE_I40E_PMD
13439 	ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
13440 #endif
13441 
13442 	switch (ret) {
13443 	case 0:
13444 		break;
13445 	case -EINVAL:
13446 		printf("invalid tc_bitmap 0x%x\n", res->tc_map);
13447 		break;
13448 	case -ENODEV:
13449 		printf("invalid port_id %d\n", res->port_id);
13450 		break;
13451 	case -ENOTSUP:
13452 		printf("function not implemented\n");
13453 		break;
13454 	default:
13455 		printf("programming error: (%s)\n", strerror(-ret));
13456 	}
13457 }
13458 
13459 cmdline_parse_inst_t cmd_strict_link_prio = {
13460 	.f = cmd_strict_link_prio_parsed,
13461 	.data = NULL,
13462 	.help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
13463 	.tokens = {
13464 		(void *)&cmd_vf_tc_bw_set,
13465 		(void *)&cmd_vf_tc_bw_tx,
13466 		(void *)&cmd_vf_tc_bw_strict_link_prio,
13467 		(void *)&cmd_vf_tc_bw_port_id,
13468 		(void *)&cmd_vf_tc_bw_tc_map,
13469 		NULL,
13470 	},
13471 };
13472 
13473 /* Load dynamic device personalization*/
13474 struct cmd_ddp_add_result {
13475 	cmdline_fixed_string_t ddp;
13476 	cmdline_fixed_string_t add;
13477 	uint8_t port_id;
13478 	char filepath[];
13479 };
13480 
13481 cmdline_parse_token_string_t cmd_ddp_add_ddp =
13482 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
13483 cmdline_parse_token_string_t cmd_ddp_add_add =
13484 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
13485 cmdline_parse_token_num_t cmd_ddp_add_port_id =
13486 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8);
13487 cmdline_parse_token_string_t cmd_ddp_add_filepath =
13488 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
13489 
13490 static void
13491 cmd_ddp_add_parsed(
13492 	void *parsed_result,
13493 	__attribute__((unused)) struct cmdline *cl,
13494 	__attribute__((unused)) void *data)
13495 {
13496 	struct cmd_ddp_add_result *res = parsed_result;
13497 	uint8_t *buff;
13498 	uint32_t size;
13499 	char *filepath;
13500 	char *file_fld[2];
13501 	int file_num;
13502 	int ret = -ENOTSUP;
13503 
13504 	if (res->port_id > nb_ports) {
13505 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13506 		return;
13507 	}
13508 
13509 	if (!all_ports_stopped()) {
13510 		printf("Please stop all ports first\n");
13511 		return;
13512 	}
13513 
13514 	filepath = strdup(res->filepath);
13515 	if (filepath == NULL) {
13516 		printf("Failed to allocate memory\n");
13517 		return;
13518 	}
13519 	file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
13520 
13521 	buff = open_ddp_package_file(file_fld[0], &size);
13522 	if (!buff) {
13523 		free((void *)filepath);
13524 		return;
13525 	}
13526 
13527 #ifdef RTE_LIBRTE_I40E_PMD
13528 	if (ret == -ENOTSUP)
13529 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13530 					       buff, size,
13531 					       RTE_PMD_I40E_PKG_OP_WR_ADD);
13532 #endif
13533 
13534 	if (ret == -EEXIST)
13535 		printf("Profile has already existed.\n");
13536 	else if (ret < 0)
13537 		printf("Failed to load profile.\n");
13538 	else if (file_num == 2)
13539 		save_ddp_package_file(file_fld[1], buff, size);
13540 
13541 	close_ddp_package_file(buff);
13542 	free((void *)filepath);
13543 }
13544 
13545 cmdline_parse_inst_t cmd_ddp_add = {
13546 	.f = cmd_ddp_add_parsed,
13547 	.data = NULL,
13548 	.help_str = "ddp add <port_id> <profile_path[,output_path]>",
13549 	.tokens = {
13550 		(void *)&cmd_ddp_add_ddp,
13551 		(void *)&cmd_ddp_add_add,
13552 		(void *)&cmd_ddp_add_port_id,
13553 		(void *)&cmd_ddp_add_filepath,
13554 		NULL,
13555 	},
13556 };
13557 
13558 /* Delete dynamic device personalization*/
13559 struct cmd_ddp_del_result {
13560 	cmdline_fixed_string_t ddp;
13561 	cmdline_fixed_string_t del;
13562 	uint8_t port_id;
13563 	char filepath[];
13564 };
13565 
13566 cmdline_parse_token_string_t cmd_ddp_del_ddp =
13567 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
13568 cmdline_parse_token_string_t cmd_ddp_del_del =
13569 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
13570 cmdline_parse_token_num_t cmd_ddp_del_port_id =
13571 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8);
13572 cmdline_parse_token_string_t cmd_ddp_del_filepath =
13573 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
13574 
13575 static void
13576 cmd_ddp_del_parsed(
13577 	void *parsed_result,
13578 	__attribute__((unused)) struct cmdline *cl,
13579 	__attribute__((unused)) void *data)
13580 {
13581 	struct cmd_ddp_del_result *res = parsed_result;
13582 	uint8_t *buff;
13583 	uint32_t size;
13584 	int ret = -ENOTSUP;
13585 
13586 	if (res->port_id > nb_ports) {
13587 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13588 		return;
13589 	}
13590 
13591 	if (!all_ports_stopped()) {
13592 		printf("Please stop all ports first\n");
13593 		return;
13594 	}
13595 
13596 	buff = open_ddp_package_file(res->filepath, &size);
13597 	if (!buff)
13598 		return;
13599 
13600 #ifdef RTE_LIBRTE_I40E_PMD
13601 	if (ret == -ENOTSUP)
13602 		ret = rte_pmd_i40e_process_ddp_package(res->port_id,
13603 					       buff, size,
13604 					       RTE_PMD_I40E_PKG_OP_WR_DEL);
13605 #endif
13606 
13607 	if (ret == -EACCES)
13608 		printf("Profile does not exist.\n");
13609 	else if (ret < 0)
13610 		printf("Failed to delete profile.\n");
13611 
13612 	close_ddp_package_file(buff);
13613 }
13614 
13615 cmdline_parse_inst_t cmd_ddp_del = {
13616 	.f = cmd_ddp_del_parsed,
13617 	.data = NULL,
13618 	.help_str = "ddp del <port_id> <profile_path>",
13619 	.tokens = {
13620 		(void *)&cmd_ddp_del_ddp,
13621 		(void *)&cmd_ddp_del_del,
13622 		(void *)&cmd_ddp_del_port_id,
13623 		(void *)&cmd_ddp_del_filepath,
13624 		NULL,
13625 	},
13626 };
13627 
13628 /* Get dynamic device personalization profile info */
13629 struct cmd_ddp_info_result {
13630 	cmdline_fixed_string_t ddp;
13631 	cmdline_fixed_string_t get;
13632 	cmdline_fixed_string_t info;
13633 	char filepath[];
13634 };
13635 
13636 cmdline_parse_token_string_t cmd_ddp_info_ddp =
13637 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
13638 cmdline_parse_token_string_t cmd_ddp_info_get =
13639 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
13640 cmdline_parse_token_string_t cmd_ddp_info_info =
13641 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
13642 cmdline_parse_token_string_t cmd_ddp_info_filepath =
13643 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
13644 
13645 static void
13646 cmd_ddp_info_parsed(
13647 	void *parsed_result,
13648 	__attribute__((unused)) struct cmdline *cl,
13649 	__attribute__((unused)) void *data)
13650 {
13651 	struct cmd_ddp_info_result *res = parsed_result;
13652 	uint8_t *pkg;
13653 	uint32_t pkg_size;
13654 	int ret = -ENOTSUP;
13655 #ifdef RTE_LIBRTE_I40E_PMD
13656 	uint32_t i, j, n;
13657 	uint8_t *buff;
13658 	uint32_t buff_size = 0;
13659 	struct rte_pmd_i40e_profile_info info;
13660 	uint32_t dev_num = 0;
13661 	struct rte_pmd_i40e_ddp_device_id *devs;
13662 	uint32_t proto_num = 0;
13663 	struct rte_pmd_i40e_proto_info *proto;
13664 	uint32_t pctype_num = 0;
13665 	struct rte_pmd_i40e_ptype_info *pctype;
13666 	uint32_t ptype_num = 0;
13667 	struct rte_pmd_i40e_ptype_info *ptype;
13668 	uint8_t proto_id;
13669 
13670 #endif
13671 
13672 	pkg = open_ddp_package_file(res->filepath, &pkg_size);
13673 	if (!pkg)
13674 		return;
13675 
13676 #ifdef RTE_LIBRTE_I40E_PMD
13677 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13678 				(uint8_t *)&info, sizeof(info),
13679 				RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
13680 	if (!ret) {
13681 		printf("Global Track id:       0x%x\n", info.track_id);
13682 		printf("Global Version:        %d.%d.%d.%d\n",
13683 			info.version.major,
13684 			info.version.minor,
13685 			info.version.update,
13686 			info.version.draft);
13687 		printf("Global Package name:   %s\n\n", info.name);
13688 	}
13689 
13690 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13691 				(uint8_t *)&info, sizeof(info),
13692 				RTE_PMD_I40E_PKG_INFO_HEADER);
13693 	if (!ret) {
13694 		printf("i40e Profile Track id: 0x%x\n", info.track_id);
13695 		printf("i40e Profile Version:  %d.%d.%d.%d\n",
13696 			info.version.major,
13697 			info.version.minor,
13698 			info.version.update,
13699 			info.version.draft);
13700 		printf("i40e Profile name:     %s\n\n", info.name);
13701 	}
13702 
13703 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13704 				(uint8_t *)&buff_size, sizeof(buff_size),
13705 				RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
13706 	if (!ret && buff_size) {
13707 		buff = (uint8_t *)malloc(buff_size);
13708 		if (buff) {
13709 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13710 						buff, buff_size,
13711 						RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
13712 			if (!ret)
13713 				printf("Package Notes:\n%s\n\n", buff);
13714 			free(buff);
13715 		}
13716 	}
13717 
13718 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13719 				(uint8_t *)&dev_num, sizeof(dev_num),
13720 				RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
13721 	if (!ret && dev_num) {
13722 		buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
13723 		devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
13724 		if (devs) {
13725 			ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13726 						(uint8_t *)devs, buff_size,
13727 						RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
13728 			if (!ret) {
13729 				printf("List of supported devices:\n");
13730 				for (i = 0; i < dev_num; i++) {
13731 					printf("  %04X:%04X %04X:%04X\n",
13732 						devs[i].vendor_dev_id >> 16,
13733 						devs[i].vendor_dev_id & 0xFFFF,
13734 						devs[i].sub_vendor_dev_id >> 16,
13735 						devs[i].sub_vendor_dev_id & 0xFFFF);
13736 				}
13737 				printf("\n");
13738 			}
13739 			free(devs);
13740 		}
13741 	}
13742 
13743 	/* get information about protocols and packet types */
13744 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13745 		(uint8_t *)&proto_num, sizeof(proto_num),
13746 		RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
13747 	if (ret || !proto_num)
13748 		goto no_print_return;
13749 
13750 	buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
13751 	proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
13752 	if (!proto)
13753 		goto no_print_return;
13754 
13755 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
13756 					buff_size,
13757 					RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
13758 	if (!ret) {
13759 		printf("List of used protocols:\n");
13760 		for (i = 0; i < proto_num; i++)
13761 			printf("  %2u: %s\n", proto[i].proto_id,
13762 			       proto[i].name);
13763 		printf("\n");
13764 	}
13765 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
13766 		(uint8_t *)&pctype_num, sizeof(pctype_num),
13767 		RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
13768 	if (ret || !pctype_num)
13769 		goto no_print_pctypes;
13770 
13771 	buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13772 	pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13773 	if (!pctype)
13774 		goto no_print_pctypes;
13775 
13776 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
13777 					buff_size,
13778 					RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
13779 	if (ret) {
13780 		free(pctype);
13781 		goto no_print_pctypes;
13782 	}
13783 
13784 	printf("List of defined packet classification types:\n");
13785 	for (i = 0; i < pctype_num; i++) {
13786 		printf("  %2u:", pctype[i].ptype_id);
13787 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13788 			proto_id = pctype[i].protocols[j];
13789 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13790 				for (n = 0; n < proto_num; n++) {
13791 					if (proto[n].proto_id == proto_id) {
13792 						printf(" %s", proto[n].name);
13793 						break;
13794 					}
13795 				}
13796 			}
13797 		}
13798 		printf("\n");
13799 	}
13800 	printf("\n");
13801 	free(pctype);
13802 
13803 no_print_pctypes:
13804 
13805 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
13806 					sizeof(ptype_num),
13807 					RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
13808 	if (ret || !ptype_num)
13809 		goto no_print_return;
13810 
13811 	buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
13812 	ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
13813 	if (!ptype)
13814 		goto no_print_return;
13815 
13816 	ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
13817 					buff_size,
13818 					RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
13819 	if (ret) {
13820 		free(ptype);
13821 		goto no_print_return;
13822 	}
13823 	printf("List of defined packet types:\n");
13824 	for (i = 0; i < ptype_num; i++) {
13825 		printf("  %2u:", ptype[i].ptype_id);
13826 		for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
13827 			proto_id = ptype[i].protocols[j];
13828 			if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
13829 				for (n = 0; n < proto_num; n++) {
13830 					if (proto[n].proto_id == proto_id) {
13831 						printf(" %s", proto[n].name);
13832 						break;
13833 					}
13834 				}
13835 			}
13836 		}
13837 		printf("\n");
13838 	}
13839 	free(ptype);
13840 	printf("\n");
13841 
13842 	free(proto);
13843 	ret = 0;
13844 #endif
13845 no_print_return:
13846 	if (ret == -ENOTSUP)
13847 		printf("Function not supported in PMD driver\n");
13848 	close_ddp_package_file(pkg);
13849 }
13850 
13851 cmdline_parse_inst_t cmd_ddp_get_info = {
13852 	.f = cmd_ddp_info_parsed,
13853 	.data = NULL,
13854 	.help_str = "ddp get info <profile_path>",
13855 	.tokens = {
13856 		(void *)&cmd_ddp_info_ddp,
13857 		(void *)&cmd_ddp_info_get,
13858 		(void *)&cmd_ddp_info_info,
13859 		(void *)&cmd_ddp_info_filepath,
13860 		NULL,
13861 	},
13862 };
13863 
13864 /* Get dynamic device personalization profile info list*/
13865 #define PROFILE_INFO_SIZE 48
13866 #define MAX_PROFILE_NUM 16
13867 
13868 struct cmd_ddp_get_list_result {
13869 	cmdline_fixed_string_t ddp;
13870 	cmdline_fixed_string_t get;
13871 	cmdline_fixed_string_t list;
13872 	uint8_t port_id;
13873 };
13874 
13875 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
13876 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
13877 cmdline_parse_token_string_t cmd_ddp_get_list_get =
13878 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
13879 cmdline_parse_token_string_t cmd_ddp_get_list_list =
13880 	TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
13881 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
13882 	TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8);
13883 
13884 static void
13885 cmd_ddp_get_list_parsed(
13886 	void *parsed_result,
13887 	__attribute__((unused)) struct cmdline *cl,
13888 	__attribute__((unused)) void *data)
13889 {
13890 	struct cmd_ddp_get_list_result *res = parsed_result;
13891 #ifdef RTE_LIBRTE_I40E_PMD
13892 	struct rte_pmd_i40e_profile_list *p_list;
13893 	struct rte_pmd_i40e_profile_info *p_info;
13894 	uint32_t p_num;
13895 	uint32_t size;
13896 	uint32_t i;
13897 #endif
13898 	int ret = -ENOTSUP;
13899 
13900 	if (res->port_id > nb_ports) {
13901 		printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
13902 		return;
13903 	}
13904 
13905 #ifdef RTE_LIBRTE_I40E_PMD
13906 	size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
13907 	p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
13908 	if (!p_list)
13909 		printf("%s: Failed to malloc buffer\n", __func__);
13910 
13911 	if (ret == -ENOTSUP)
13912 		ret = rte_pmd_i40e_get_ddp_list(res->port_id,
13913 						(uint8_t *)p_list, size);
13914 
13915 	if (!ret) {
13916 		p_num = p_list->p_count;
13917 		printf("Profile number is: %d\n\n", p_num);
13918 
13919 		for (i = 0; i < p_num; i++) {
13920 			p_info = &p_list->p_info[i];
13921 			printf("Profile %d:\n", i);
13922 			printf("Track id:     0x%x\n", p_info->track_id);
13923 			printf("Version:      %d.%d.%d.%d\n",
13924 			       p_info->version.major,
13925 			       p_info->version.minor,
13926 			       p_info->version.update,
13927 			       p_info->version.draft);
13928 			printf("Profile name: %s\n\n", p_info->name);
13929 		}
13930 	}
13931 
13932 	free(p_list);
13933 #endif
13934 
13935 	if (ret < 0)
13936 		printf("Failed to get ddp list\n");
13937 }
13938 
13939 cmdline_parse_inst_t cmd_ddp_get_list = {
13940 	.f = cmd_ddp_get_list_parsed,
13941 	.data = NULL,
13942 	.help_str = "ddp get list <port_id>",
13943 	.tokens = {
13944 		(void *)&cmd_ddp_get_list_ddp,
13945 		(void *)&cmd_ddp_get_list_get,
13946 		(void *)&cmd_ddp_get_list_list,
13947 		(void *)&cmd_ddp_get_list_port_id,
13948 		NULL,
13949 	},
13950 };
13951 
13952 /* show vf stats */
13953 
13954 /* Common result structure for show vf stats */
13955 struct cmd_show_vf_stats_result {
13956 	cmdline_fixed_string_t show;
13957 	cmdline_fixed_string_t vf;
13958 	cmdline_fixed_string_t stats;
13959 	uint8_t port_id;
13960 	uint16_t vf_id;
13961 };
13962 
13963 /* Common CLI fields show vf stats*/
13964 cmdline_parse_token_string_t cmd_show_vf_stats_show =
13965 	TOKEN_STRING_INITIALIZER
13966 		(struct cmd_show_vf_stats_result,
13967 		 show, "show");
13968 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
13969 	TOKEN_STRING_INITIALIZER
13970 		(struct cmd_show_vf_stats_result,
13971 		 vf, "vf");
13972 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
13973 	TOKEN_STRING_INITIALIZER
13974 		(struct cmd_show_vf_stats_result,
13975 		 stats, "stats");
13976 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
13977 	TOKEN_NUM_INITIALIZER
13978 		(struct cmd_show_vf_stats_result,
13979 		 port_id, UINT8);
13980 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
13981 	TOKEN_NUM_INITIALIZER
13982 		(struct cmd_show_vf_stats_result,
13983 		 vf_id, UINT16);
13984 
13985 static void
13986 cmd_show_vf_stats_parsed(
13987 	void *parsed_result,
13988 	__attribute__((unused)) struct cmdline *cl,
13989 	__attribute__((unused)) void *data)
13990 {
13991 	struct cmd_show_vf_stats_result *res = parsed_result;
13992 	struct rte_eth_stats stats;
13993 	int ret = -ENOTSUP;
13994 	static const char *nic_stats_border = "########################";
13995 
13996 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13997 		return;
13998 
13999 	memset(&stats, 0, sizeof(stats));
14000 
14001 #ifdef RTE_LIBRTE_I40E_PMD
14002 	if (ret == -ENOTSUP)
14003 		ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14004 						res->vf_id,
14005 						&stats);
14006 #endif
14007 #ifdef RTE_LIBRTE_BNXT_PMD
14008 	if (ret == -ENOTSUP)
14009 		ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14010 						res->vf_id,
14011 						&stats);
14012 #endif
14013 
14014 	switch (ret) {
14015 	case 0:
14016 		break;
14017 	case -EINVAL:
14018 		printf("invalid vf_id %d\n", res->vf_id);
14019 		break;
14020 	case -ENODEV:
14021 		printf("invalid port_id %d\n", res->port_id);
14022 		break;
14023 	case -ENOTSUP:
14024 		printf("function not implemented\n");
14025 		break;
14026 	default:
14027 		printf("programming error: (%s)\n", strerror(-ret));
14028 	}
14029 
14030 	printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14031 		nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14032 
14033 	printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14034 	       "%-"PRIu64"\n",
14035 	       stats.ipackets, stats.imissed, stats.ibytes);
14036 	printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14037 	printf("  RX-nombuf:  %-10"PRIu64"\n",
14038 	       stats.rx_nombuf);
14039 	printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14040 	       "%-"PRIu64"\n",
14041 	       stats.opackets, stats.oerrors, stats.obytes);
14042 
14043 	printf("  %s############################%s\n",
14044 			       nic_stats_border, nic_stats_border);
14045 }
14046 
14047 cmdline_parse_inst_t cmd_show_vf_stats = {
14048 	.f = cmd_show_vf_stats_parsed,
14049 	.data = NULL,
14050 	.help_str = "show vf stats <port_id> <vf_id>",
14051 	.tokens = {
14052 		(void *)&cmd_show_vf_stats_show,
14053 		(void *)&cmd_show_vf_stats_vf,
14054 		(void *)&cmd_show_vf_stats_stats,
14055 		(void *)&cmd_show_vf_stats_port_id,
14056 		(void *)&cmd_show_vf_stats_vf_id,
14057 		NULL,
14058 	},
14059 };
14060 
14061 /* clear vf stats */
14062 
14063 /* Common result structure for clear vf stats */
14064 struct cmd_clear_vf_stats_result {
14065 	cmdline_fixed_string_t clear;
14066 	cmdline_fixed_string_t vf;
14067 	cmdline_fixed_string_t stats;
14068 	uint8_t port_id;
14069 	uint16_t vf_id;
14070 };
14071 
14072 /* Common CLI fields clear vf stats*/
14073 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14074 	TOKEN_STRING_INITIALIZER
14075 		(struct cmd_clear_vf_stats_result,
14076 		 clear, "clear");
14077 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14078 	TOKEN_STRING_INITIALIZER
14079 		(struct cmd_clear_vf_stats_result,
14080 		 vf, "vf");
14081 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14082 	TOKEN_STRING_INITIALIZER
14083 		(struct cmd_clear_vf_stats_result,
14084 		 stats, "stats");
14085 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14086 	TOKEN_NUM_INITIALIZER
14087 		(struct cmd_clear_vf_stats_result,
14088 		 port_id, UINT8);
14089 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14090 	TOKEN_NUM_INITIALIZER
14091 		(struct cmd_clear_vf_stats_result,
14092 		 vf_id, UINT16);
14093 
14094 static void
14095 cmd_clear_vf_stats_parsed(
14096 	void *parsed_result,
14097 	__attribute__((unused)) struct cmdline *cl,
14098 	__attribute__((unused)) void *data)
14099 {
14100 	struct cmd_clear_vf_stats_result *res = parsed_result;
14101 	int ret = -ENOTSUP;
14102 
14103 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14104 		return;
14105 
14106 #ifdef RTE_LIBRTE_I40E_PMD
14107 	if (ret == -ENOTSUP)
14108 		ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14109 						  res->vf_id);
14110 #endif
14111 #ifdef RTE_LIBRTE_BNXT_PMD
14112 	if (ret == -ENOTSUP)
14113 		ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14114 						  res->vf_id);
14115 #endif
14116 
14117 	switch (ret) {
14118 	case 0:
14119 		break;
14120 	case -EINVAL:
14121 		printf("invalid vf_id %d\n", res->vf_id);
14122 		break;
14123 	case -ENODEV:
14124 		printf("invalid port_id %d\n", res->port_id);
14125 		break;
14126 	case -ENOTSUP:
14127 		printf("function not implemented\n");
14128 		break;
14129 	default:
14130 		printf("programming error: (%s)\n", strerror(-ret));
14131 	}
14132 }
14133 
14134 cmdline_parse_inst_t cmd_clear_vf_stats = {
14135 	.f = cmd_clear_vf_stats_parsed,
14136 	.data = NULL,
14137 	.help_str = "clear vf stats <port_id> <vf_id>",
14138 	.tokens = {
14139 		(void *)&cmd_clear_vf_stats_clear,
14140 		(void *)&cmd_clear_vf_stats_vf,
14141 		(void *)&cmd_clear_vf_stats_stats,
14142 		(void *)&cmd_clear_vf_stats_port_id,
14143 		(void *)&cmd_clear_vf_stats_vf_id,
14144 		NULL,
14145 	},
14146 };
14147 
14148 /* port config pctype mapping reset */
14149 
14150 /* Common result structure for port config pctype mapping reset */
14151 struct cmd_pctype_mapping_reset_result {
14152 	cmdline_fixed_string_t port;
14153 	cmdline_fixed_string_t config;
14154 	uint8_t port_id;
14155 	cmdline_fixed_string_t pctype;
14156 	cmdline_fixed_string_t mapping;
14157 	cmdline_fixed_string_t reset;
14158 };
14159 
14160 /* Common CLI fields for port config pctype mapping reset*/
14161 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14162 	TOKEN_STRING_INITIALIZER
14163 		(struct cmd_pctype_mapping_reset_result,
14164 		 port, "port");
14165 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14166 	TOKEN_STRING_INITIALIZER
14167 		(struct cmd_pctype_mapping_reset_result,
14168 		 config, "config");
14169 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14170 	TOKEN_NUM_INITIALIZER
14171 		(struct cmd_pctype_mapping_reset_result,
14172 		 port_id, UINT8);
14173 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14174 	TOKEN_STRING_INITIALIZER
14175 		(struct cmd_pctype_mapping_reset_result,
14176 		 pctype, "pctype");
14177 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14178 	TOKEN_STRING_INITIALIZER
14179 		(struct cmd_pctype_mapping_reset_result,
14180 		 mapping, "mapping");
14181 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14182 	TOKEN_STRING_INITIALIZER
14183 		(struct cmd_pctype_mapping_reset_result,
14184 		 reset, "reset");
14185 
14186 static void
14187 cmd_pctype_mapping_reset_parsed(
14188 	void *parsed_result,
14189 	__attribute__((unused)) struct cmdline *cl,
14190 	__attribute__((unused)) void *data)
14191 {
14192 	struct cmd_pctype_mapping_reset_result *res = parsed_result;
14193 	int ret = -ENOTSUP;
14194 
14195 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14196 		return;
14197 
14198 #ifdef RTE_LIBRTE_I40E_PMD
14199 	ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14200 #endif
14201 
14202 	switch (ret) {
14203 	case 0:
14204 		break;
14205 	case -ENODEV:
14206 		printf("invalid port_id %d\n", res->port_id);
14207 		break;
14208 	case -ENOTSUP:
14209 		printf("function not implemented\n");
14210 		break;
14211 	default:
14212 		printf("programming error: (%s)\n", strerror(-ret));
14213 	}
14214 }
14215 
14216 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14217 	.f = cmd_pctype_mapping_reset_parsed,
14218 	.data = NULL,
14219 	.help_str = "port config <port_id> pctype mapping reset",
14220 	.tokens = {
14221 		(void *)&cmd_pctype_mapping_reset_port,
14222 		(void *)&cmd_pctype_mapping_reset_config,
14223 		(void *)&cmd_pctype_mapping_reset_port_id,
14224 		(void *)&cmd_pctype_mapping_reset_pctype,
14225 		(void *)&cmd_pctype_mapping_reset_mapping,
14226 		(void *)&cmd_pctype_mapping_reset_reset,
14227 		NULL,
14228 	},
14229 };
14230 
14231 /* show port pctype mapping */
14232 
14233 /* Common result structure for show port pctype mapping */
14234 struct cmd_pctype_mapping_get_result {
14235 	cmdline_fixed_string_t show;
14236 	cmdline_fixed_string_t port;
14237 	uint8_t port_id;
14238 	cmdline_fixed_string_t pctype;
14239 	cmdline_fixed_string_t mapping;
14240 };
14241 
14242 /* Common CLI fields for pctype mapping get */
14243 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14244 	TOKEN_STRING_INITIALIZER
14245 		(struct cmd_pctype_mapping_get_result,
14246 		 show, "show");
14247 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14248 	TOKEN_STRING_INITIALIZER
14249 		(struct cmd_pctype_mapping_get_result,
14250 		 port, "port");
14251 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14252 	TOKEN_NUM_INITIALIZER
14253 		(struct cmd_pctype_mapping_get_result,
14254 		 port_id, UINT8);
14255 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14256 	TOKEN_STRING_INITIALIZER
14257 		(struct cmd_pctype_mapping_get_result,
14258 		 pctype, "pctype");
14259 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14260 	TOKEN_STRING_INITIALIZER
14261 		(struct cmd_pctype_mapping_get_result,
14262 		 mapping, "mapping");
14263 
14264 static void
14265 cmd_pctype_mapping_get_parsed(
14266 	void *parsed_result,
14267 	__attribute__((unused)) struct cmdline *cl,
14268 	__attribute__((unused)) void *data)
14269 {
14270 	struct cmd_pctype_mapping_get_result *res = parsed_result;
14271 	int ret = -ENOTSUP;
14272 #ifdef RTE_LIBRTE_I40E_PMD
14273 	struct rte_pmd_i40e_flow_type_mapping
14274 				mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14275 	int i, j, first_pctype;
14276 #endif
14277 
14278 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14279 		return;
14280 
14281 #ifdef RTE_LIBRTE_I40E_PMD
14282 	ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14283 #endif
14284 
14285 	switch (ret) {
14286 	case 0:
14287 		break;
14288 	case -ENODEV:
14289 		printf("invalid port_id %d\n", res->port_id);
14290 		return;
14291 	case -ENOTSUP:
14292 		printf("function not implemented\n");
14293 		return;
14294 	default:
14295 		printf("programming error: (%s)\n", strerror(-ret));
14296 		return;
14297 	}
14298 
14299 #ifdef RTE_LIBRTE_I40E_PMD
14300 	for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
14301 		if (mapping[i].pctype != 0ULL) {
14302 			first_pctype = 1;
14303 
14304 			printf("pctype: ");
14305 			for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
14306 				if (mapping[i].pctype & (1ULL << j)) {
14307 					printf(first_pctype ?
14308 					       "%02d" : ",%02d", j);
14309 					first_pctype = 0;
14310 				}
14311 			}
14312 			printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
14313 		}
14314 	}
14315 #endif
14316 }
14317 
14318 cmdline_parse_inst_t cmd_pctype_mapping_get = {
14319 	.f = cmd_pctype_mapping_get_parsed,
14320 	.data = NULL,
14321 	.help_str = "show port <port_id> pctype mapping",
14322 	.tokens = {
14323 		(void *)&cmd_pctype_mapping_get_show,
14324 		(void *)&cmd_pctype_mapping_get_port,
14325 		(void *)&cmd_pctype_mapping_get_port_id,
14326 		(void *)&cmd_pctype_mapping_get_pctype,
14327 		(void *)&cmd_pctype_mapping_get_mapping,
14328 		NULL,
14329 	},
14330 };
14331 
14332 /* port config pctype mapping update */
14333 
14334 /* Common result structure for port config pctype mapping update */
14335 struct cmd_pctype_mapping_update_result {
14336 	cmdline_fixed_string_t port;
14337 	cmdline_fixed_string_t config;
14338 	uint8_t port_id;
14339 	cmdline_fixed_string_t pctype;
14340 	cmdline_fixed_string_t mapping;
14341 	cmdline_fixed_string_t update;
14342 	cmdline_fixed_string_t pctype_list;
14343 	uint16_t flow_type;
14344 };
14345 
14346 /* Common CLI fields for pctype mapping update*/
14347 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
14348 	TOKEN_STRING_INITIALIZER
14349 		(struct cmd_pctype_mapping_update_result,
14350 		 port, "port");
14351 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
14352 	TOKEN_STRING_INITIALIZER
14353 		(struct cmd_pctype_mapping_update_result,
14354 		 config, "config");
14355 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
14356 	TOKEN_NUM_INITIALIZER
14357 		(struct cmd_pctype_mapping_update_result,
14358 		 port_id, UINT8);
14359 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
14360 	TOKEN_STRING_INITIALIZER
14361 		(struct cmd_pctype_mapping_update_result,
14362 		 pctype, "pctype");
14363 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
14364 	TOKEN_STRING_INITIALIZER
14365 		(struct cmd_pctype_mapping_update_result,
14366 		 mapping, "mapping");
14367 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
14368 	TOKEN_STRING_INITIALIZER
14369 		(struct cmd_pctype_mapping_update_result,
14370 		 update, "update");
14371 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
14372 	TOKEN_STRING_INITIALIZER
14373 		(struct cmd_pctype_mapping_update_result,
14374 		 pctype_list, NULL);
14375 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
14376 	TOKEN_NUM_INITIALIZER
14377 		(struct cmd_pctype_mapping_update_result,
14378 		 flow_type, UINT16);
14379 
14380 static void
14381 cmd_pctype_mapping_update_parsed(
14382 	void *parsed_result,
14383 	__attribute__((unused)) struct cmdline *cl,
14384 	__attribute__((unused)) void *data)
14385 {
14386 	struct cmd_pctype_mapping_update_result *res = parsed_result;
14387 	int ret = -ENOTSUP;
14388 #ifdef RTE_LIBRTE_I40E_PMD
14389 	struct rte_pmd_i40e_flow_type_mapping mapping;
14390 	unsigned int i;
14391 #endif
14392 	unsigned int nb_item;
14393 	unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
14394 
14395 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14396 		return;
14397 
14398 	nb_item = parse_item_list(res->pctype_list, "pctypes",
14399 				  RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
14400 
14401 #ifdef RTE_LIBRTE_I40E_PMD
14402 	mapping.flow_type = res->flow_type;
14403 	for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
14404 		mapping.pctype |= (1ULL << pctype_list[i]);
14405 	ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
14406 						&mapping,
14407 						1,
14408 						0);
14409 #endif
14410 
14411 	switch (ret) {
14412 	case 0:
14413 		break;
14414 	case -EINVAL:
14415 		printf("invalid pctype or flow type\n");
14416 		break;
14417 	case -ENODEV:
14418 		printf("invalid port_id %d\n", res->port_id);
14419 		break;
14420 	case -ENOTSUP:
14421 		printf("function not implemented\n");
14422 		break;
14423 	default:
14424 		printf("programming error: (%s)\n", strerror(-ret));
14425 	}
14426 }
14427 
14428 cmdline_parse_inst_t cmd_pctype_mapping_update = {
14429 	.f = cmd_pctype_mapping_update_parsed,
14430 	.data = NULL,
14431 	.help_str = "port config <port_id> pctype mapping update"
14432 	" <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
14433 	.tokens = {
14434 		(void *)&cmd_pctype_mapping_update_port,
14435 		(void *)&cmd_pctype_mapping_update_config,
14436 		(void *)&cmd_pctype_mapping_update_port_id,
14437 		(void *)&cmd_pctype_mapping_update_pctype,
14438 		(void *)&cmd_pctype_mapping_update_mapping,
14439 		(void *)&cmd_pctype_mapping_update_update,
14440 		(void *)&cmd_pctype_mapping_update_pc_type,
14441 		(void *)&cmd_pctype_mapping_update_flow_type,
14442 		NULL,
14443 	},
14444 };
14445 
14446 /* ptype mapping get */
14447 
14448 /* Common result structure for ptype mapping get */
14449 struct cmd_ptype_mapping_get_result {
14450 	cmdline_fixed_string_t ptype;
14451 	cmdline_fixed_string_t mapping;
14452 	cmdline_fixed_string_t get;
14453 	uint8_t port_id;
14454 	uint8_t valid_only;
14455 };
14456 
14457 /* Common CLI fields for ptype mapping get */
14458 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
14459 	TOKEN_STRING_INITIALIZER
14460 		(struct cmd_ptype_mapping_get_result,
14461 		 ptype, "ptype");
14462 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
14463 	TOKEN_STRING_INITIALIZER
14464 		(struct cmd_ptype_mapping_get_result,
14465 		 mapping, "mapping");
14466 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
14467 	TOKEN_STRING_INITIALIZER
14468 		(struct cmd_ptype_mapping_get_result,
14469 		 get, "get");
14470 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
14471 	TOKEN_NUM_INITIALIZER
14472 		(struct cmd_ptype_mapping_get_result,
14473 		 port_id, UINT8);
14474 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
14475 	TOKEN_NUM_INITIALIZER
14476 		(struct cmd_ptype_mapping_get_result,
14477 		 valid_only, UINT8);
14478 
14479 static void
14480 cmd_ptype_mapping_get_parsed(
14481 	void *parsed_result,
14482 	__attribute__((unused)) struct cmdline *cl,
14483 	__attribute__((unused)) void *data)
14484 {
14485 	struct cmd_ptype_mapping_get_result *res = parsed_result;
14486 	int ret = -ENOTSUP;
14487 #ifdef RTE_LIBRTE_I40E_PMD
14488 	int max_ptype_num = 256;
14489 	struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
14490 	uint16_t count;
14491 	int i;
14492 #endif
14493 
14494 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14495 		return;
14496 
14497 #ifdef RTE_LIBRTE_I40E_PMD
14498 	ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
14499 					mapping,
14500 					max_ptype_num,
14501 					&count,
14502 					res->valid_only);
14503 #endif
14504 
14505 	switch (ret) {
14506 	case 0:
14507 		break;
14508 	case -ENODEV:
14509 		printf("invalid port_id %d\n", res->port_id);
14510 		break;
14511 	case -ENOTSUP:
14512 		printf("function not implemented\n");
14513 		break;
14514 	default:
14515 		printf("programming error: (%s)\n", strerror(-ret));
14516 	}
14517 
14518 #ifdef RTE_LIBRTE_I40E_PMD
14519 	if (!ret) {
14520 		for (i = 0; i < count; i++)
14521 			printf("%3d\t0x%08x\n",
14522 				mapping[i].hw_ptype, mapping[i].sw_ptype);
14523 	}
14524 #endif
14525 }
14526 
14527 cmdline_parse_inst_t cmd_ptype_mapping_get = {
14528 	.f = cmd_ptype_mapping_get_parsed,
14529 	.data = NULL,
14530 	.help_str = "ptype mapping get <port_id> <valid_only>",
14531 	.tokens = {
14532 		(void *)&cmd_ptype_mapping_get_ptype,
14533 		(void *)&cmd_ptype_mapping_get_mapping,
14534 		(void *)&cmd_ptype_mapping_get_get,
14535 		(void *)&cmd_ptype_mapping_get_port_id,
14536 		(void *)&cmd_ptype_mapping_get_valid_only,
14537 		NULL,
14538 	},
14539 };
14540 
14541 /* ptype mapping replace */
14542 
14543 /* Common result structure for ptype mapping replace */
14544 struct cmd_ptype_mapping_replace_result {
14545 	cmdline_fixed_string_t ptype;
14546 	cmdline_fixed_string_t mapping;
14547 	cmdline_fixed_string_t replace;
14548 	uint8_t port_id;
14549 	uint32_t target;
14550 	uint8_t mask;
14551 	uint32_t pkt_type;
14552 };
14553 
14554 /* Common CLI fields for ptype mapping replace */
14555 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
14556 	TOKEN_STRING_INITIALIZER
14557 		(struct cmd_ptype_mapping_replace_result,
14558 		 ptype, "ptype");
14559 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
14560 	TOKEN_STRING_INITIALIZER
14561 		(struct cmd_ptype_mapping_replace_result,
14562 		 mapping, "mapping");
14563 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
14564 	TOKEN_STRING_INITIALIZER
14565 		(struct cmd_ptype_mapping_replace_result,
14566 		 replace, "replace");
14567 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
14568 	TOKEN_NUM_INITIALIZER
14569 		(struct cmd_ptype_mapping_replace_result,
14570 		 port_id, UINT8);
14571 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
14572 	TOKEN_NUM_INITIALIZER
14573 		(struct cmd_ptype_mapping_replace_result,
14574 		 target, UINT32);
14575 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
14576 	TOKEN_NUM_INITIALIZER
14577 		(struct cmd_ptype_mapping_replace_result,
14578 		 mask, UINT8);
14579 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
14580 	TOKEN_NUM_INITIALIZER
14581 		(struct cmd_ptype_mapping_replace_result,
14582 		 pkt_type, UINT32);
14583 
14584 static void
14585 cmd_ptype_mapping_replace_parsed(
14586 	void *parsed_result,
14587 	__attribute__((unused)) struct cmdline *cl,
14588 	__attribute__((unused)) void *data)
14589 {
14590 	struct cmd_ptype_mapping_replace_result *res = parsed_result;
14591 	int ret = -ENOTSUP;
14592 
14593 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14594 		return;
14595 
14596 #ifdef RTE_LIBRTE_I40E_PMD
14597 	ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
14598 					res->target,
14599 					res->mask,
14600 					res->pkt_type);
14601 #endif
14602 
14603 	switch (ret) {
14604 	case 0:
14605 		break;
14606 	case -EINVAL:
14607 		printf("invalid ptype 0x%8x or 0x%8x\n",
14608 				res->target, res->pkt_type);
14609 		break;
14610 	case -ENODEV:
14611 		printf("invalid port_id %d\n", res->port_id);
14612 		break;
14613 	case -ENOTSUP:
14614 		printf("function not implemented\n");
14615 		break;
14616 	default:
14617 		printf("programming error: (%s)\n", strerror(-ret));
14618 	}
14619 }
14620 
14621 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
14622 	.f = cmd_ptype_mapping_replace_parsed,
14623 	.data = NULL,
14624 	.help_str =
14625 		"ptype mapping replace <port_id> <target> <mask> <pkt_type>",
14626 	.tokens = {
14627 		(void *)&cmd_ptype_mapping_replace_ptype,
14628 		(void *)&cmd_ptype_mapping_replace_mapping,
14629 		(void *)&cmd_ptype_mapping_replace_replace,
14630 		(void *)&cmd_ptype_mapping_replace_port_id,
14631 		(void *)&cmd_ptype_mapping_replace_target,
14632 		(void *)&cmd_ptype_mapping_replace_mask,
14633 		(void *)&cmd_ptype_mapping_replace_pkt_type,
14634 		NULL,
14635 	},
14636 };
14637 
14638 /* ptype mapping reset */
14639 
14640 /* Common result structure for ptype mapping reset */
14641 struct cmd_ptype_mapping_reset_result {
14642 	cmdline_fixed_string_t ptype;
14643 	cmdline_fixed_string_t mapping;
14644 	cmdline_fixed_string_t reset;
14645 	uint8_t port_id;
14646 };
14647 
14648 /* Common CLI fields for ptype mapping reset*/
14649 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
14650 	TOKEN_STRING_INITIALIZER
14651 		(struct cmd_ptype_mapping_reset_result,
14652 		 ptype, "ptype");
14653 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
14654 	TOKEN_STRING_INITIALIZER
14655 		(struct cmd_ptype_mapping_reset_result,
14656 		 mapping, "mapping");
14657 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
14658 	TOKEN_STRING_INITIALIZER
14659 		(struct cmd_ptype_mapping_reset_result,
14660 		 reset, "reset");
14661 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
14662 	TOKEN_NUM_INITIALIZER
14663 		(struct cmd_ptype_mapping_reset_result,
14664 		 port_id, UINT8);
14665 
14666 static void
14667 cmd_ptype_mapping_reset_parsed(
14668 	void *parsed_result,
14669 	__attribute__((unused)) struct cmdline *cl,
14670 	__attribute__((unused)) void *data)
14671 {
14672 	struct cmd_ptype_mapping_reset_result *res = parsed_result;
14673 	int ret = -ENOTSUP;
14674 
14675 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14676 		return;
14677 
14678 #ifdef RTE_LIBRTE_I40E_PMD
14679 	ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
14680 #endif
14681 
14682 	switch (ret) {
14683 	case 0:
14684 		break;
14685 	case -ENODEV:
14686 		printf("invalid port_id %d\n", res->port_id);
14687 		break;
14688 	case -ENOTSUP:
14689 		printf("function not implemented\n");
14690 		break;
14691 	default:
14692 		printf("programming error: (%s)\n", strerror(-ret));
14693 	}
14694 }
14695 
14696 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
14697 	.f = cmd_ptype_mapping_reset_parsed,
14698 	.data = NULL,
14699 	.help_str = "ptype mapping reset <port_id>",
14700 	.tokens = {
14701 		(void *)&cmd_ptype_mapping_reset_ptype,
14702 		(void *)&cmd_ptype_mapping_reset_mapping,
14703 		(void *)&cmd_ptype_mapping_reset_reset,
14704 		(void *)&cmd_ptype_mapping_reset_port_id,
14705 		NULL,
14706 	},
14707 };
14708 
14709 /* ptype mapping update */
14710 
14711 /* Common result structure for ptype mapping update */
14712 struct cmd_ptype_mapping_update_result {
14713 	cmdline_fixed_string_t ptype;
14714 	cmdline_fixed_string_t mapping;
14715 	cmdline_fixed_string_t reset;
14716 	uint8_t port_id;
14717 	uint8_t hw_ptype;
14718 	uint32_t sw_ptype;
14719 };
14720 
14721 /* Common CLI fields for ptype mapping update*/
14722 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
14723 	TOKEN_STRING_INITIALIZER
14724 		(struct cmd_ptype_mapping_update_result,
14725 		 ptype, "ptype");
14726 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
14727 	TOKEN_STRING_INITIALIZER
14728 		(struct cmd_ptype_mapping_update_result,
14729 		 mapping, "mapping");
14730 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
14731 	TOKEN_STRING_INITIALIZER
14732 		(struct cmd_ptype_mapping_update_result,
14733 		 reset, "update");
14734 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
14735 	TOKEN_NUM_INITIALIZER
14736 		(struct cmd_ptype_mapping_update_result,
14737 		 port_id, UINT8);
14738 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
14739 	TOKEN_NUM_INITIALIZER
14740 		(struct cmd_ptype_mapping_update_result,
14741 		 hw_ptype, UINT8);
14742 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
14743 	TOKEN_NUM_INITIALIZER
14744 		(struct cmd_ptype_mapping_update_result,
14745 		 sw_ptype, UINT32);
14746 
14747 static void
14748 cmd_ptype_mapping_update_parsed(
14749 	void *parsed_result,
14750 	__attribute__((unused)) struct cmdline *cl,
14751 	__attribute__((unused)) void *data)
14752 {
14753 	struct cmd_ptype_mapping_update_result *res = parsed_result;
14754 	int ret = -ENOTSUP;
14755 #ifdef RTE_LIBRTE_I40E_PMD
14756 	struct rte_pmd_i40e_ptype_mapping mapping;
14757 #endif
14758 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14759 		return;
14760 
14761 #ifdef RTE_LIBRTE_I40E_PMD
14762 	mapping.hw_ptype = res->hw_ptype;
14763 	mapping.sw_ptype = res->sw_ptype;
14764 	ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
14765 						&mapping,
14766 						1,
14767 						0);
14768 #endif
14769 
14770 	switch (ret) {
14771 	case 0:
14772 		break;
14773 	case -EINVAL:
14774 		printf("invalid ptype 0x%8x\n", res->sw_ptype);
14775 		break;
14776 	case -ENODEV:
14777 		printf("invalid port_id %d\n", res->port_id);
14778 		break;
14779 	case -ENOTSUP:
14780 		printf("function not implemented\n");
14781 		break;
14782 	default:
14783 		printf("programming error: (%s)\n", strerror(-ret));
14784 	}
14785 }
14786 
14787 cmdline_parse_inst_t cmd_ptype_mapping_update = {
14788 	.f = cmd_ptype_mapping_update_parsed,
14789 	.data = NULL,
14790 	.help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
14791 	.tokens = {
14792 		(void *)&cmd_ptype_mapping_update_ptype,
14793 		(void *)&cmd_ptype_mapping_update_mapping,
14794 		(void *)&cmd_ptype_mapping_update_update,
14795 		(void *)&cmd_ptype_mapping_update_port_id,
14796 		(void *)&cmd_ptype_mapping_update_hw_ptype,
14797 		(void *)&cmd_ptype_mapping_update_sw_ptype,
14798 		NULL,
14799 	},
14800 };
14801 
14802 /* Common result structure for file commands */
14803 struct cmd_cmdfile_result {
14804 	cmdline_fixed_string_t load;
14805 	cmdline_fixed_string_t filename;
14806 };
14807 
14808 /* Common CLI fields for file commands */
14809 cmdline_parse_token_string_t cmd_load_cmdfile =
14810 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
14811 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
14812 	TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
14813 
14814 static void
14815 cmd_load_from_file_parsed(
14816 	void *parsed_result,
14817 	__attribute__((unused)) struct cmdline *cl,
14818 	__attribute__((unused)) void *data)
14819 {
14820 	struct cmd_cmdfile_result *res = parsed_result;
14821 
14822 	cmdline_read_from_file(res->filename);
14823 }
14824 
14825 cmdline_parse_inst_t cmd_load_from_file = {
14826 	.f = cmd_load_from_file_parsed,
14827 	.data = NULL,
14828 	.help_str = "load <filename>",
14829 	.tokens = {
14830 		(void *)&cmd_load_cmdfile,
14831 		(void *)&cmd_load_cmdfile_filename,
14832 		NULL,
14833 	},
14834 };
14835 
14836 /* ******************************************************************************** */
14837 
14838 /* list of instructions */
14839 cmdline_parse_ctx_t main_ctx[] = {
14840 	(cmdline_parse_inst_t *)&cmd_help_brief,
14841 	(cmdline_parse_inst_t *)&cmd_help_long,
14842 	(cmdline_parse_inst_t *)&cmd_quit,
14843 	(cmdline_parse_inst_t *)&cmd_load_from_file,
14844 	(cmdline_parse_inst_t *)&cmd_showport,
14845 	(cmdline_parse_inst_t *)&cmd_showqueue,
14846 	(cmdline_parse_inst_t *)&cmd_showportall,
14847 	(cmdline_parse_inst_t *)&cmd_showcfg,
14848 	(cmdline_parse_inst_t *)&cmd_start,
14849 	(cmdline_parse_inst_t *)&cmd_start_tx_first,
14850 	(cmdline_parse_inst_t *)&cmd_start_tx_first_n,
14851 	(cmdline_parse_inst_t *)&cmd_set_link_up,
14852 	(cmdline_parse_inst_t *)&cmd_set_link_down,
14853 	(cmdline_parse_inst_t *)&cmd_reset,
14854 	(cmdline_parse_inst_t *)&cmd_set_numbers,
14855 	(cmdline_parse_inst_t *)&cmd_set_txpkts,
14856 	(cmdline_parse_inst_t *)&cmd_set_txsplit,
14857 	(cmdline_parse_inst_t *)&cmd_set_fwd_list,
14858 	(cmdline_parse_inst_t *)&cmd_set_fwd_mask,
14859 	(cmdline_parse_inst_t *)&cmd_set_fwd_mode,
14860 	(cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
14861 	(cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
14862 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
14863 	(cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
14864 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
14865 	(cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
14866 	(cmdline_parse_inst_t *)&cmd_set_flush_rx,
14867 	(cmdline_parse_inst_t *)&cmd_set_link_check,
14868 	(cmdline_parse_inst_t *)&cmd_set_bypass_mode,
14869 	(cmdline_parse_inst_t *)&cmd_set_bypass_event,
14870 	(cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
14871 	(cmdline_parse_inst_t *)&cmd_show_bypass_config,
14872 #ifdef RTE_LIBRTE_PMD_BOND
14873 	(cmdline_parse_inst_t *) &cmd_set_bonding_mode,
14874 	(cmdline_parse_inst_t *) &cmd_show_bonding_config,
14875 	(cmdline_parse_inst_t *) &cmd_set_bonding_primary,
14876 	(cmdline_parse_inst_t *) &cmd_add_bonding_slave,
14877 	(cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
14878 	(cmdline_parse_inst_t *) &cmd_create_bonded_device,
14879 	(cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
14880 	(cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
14881 	(cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
14882 	(cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
14883 	(cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
14884 #endif
14885 	(cmdline_parse_inst_t *)&cmd_vlan_offload,
14886 	(cmdline_parse_inst_t *)&cmd_vlan_tpid,
14887 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
14888 	(cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
14889 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set,
14890 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
14891 	(cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
14892 	(cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
14893 	(cmdline_parse_inst_t *)&cmd_csum_set,
14894 	(cmdline_parse_inst_t *)&cmd_csum_show,
14895 	(cmdline_parse_inst_t *)&cmd_csum_tunnel,
14896 	(cmdline_parse_inst_t *)&cmd_tso_set,
14897 	(cmdline_parse_inst_t *)&cmd_tso_show,
14898 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
14899 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
14900 	(cmdline_parse_inst_t *)&cmd_gro_enable,
14901 	(cmdline_parse_inst_t *)&cmd_gro_flush,
14902 	(cmdline_parse_inst_t *)&cmd_gro_show,
14903 	(cmdline_parse_inst_t *)&cmd_gso_enable,
14904 	(cmdline_parse_inst_t *)&cmd_gso_size,
14905 	(cmdline_parse_inst_t *)&cmd_gso_show,
14906 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
14907 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
14908 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
14909 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
14910 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
14911 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
14912 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
14913 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
14914 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
14915 	(cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
14916 	(cmdline_parse_inst_t *)&cmd_config_dcb,
14917 	(cmdline_parse_inst_t *)&cmd_read_reg,
14918 	(cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
14919 	(cmdline_parse_inst_t *)&cmd_read_reg_bit,
14920 	(cmdline_parse_inst_t *)&cmd_write_reg,
14921 	(cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
14922 	(cmdline_parse_inst_t *)&cmd_write_reg_bit,
14923 	(cmdline_parse_inst_t *)&cmd_read_rxd_txd,
14924 	(cmdline_parse_inst_t *)&cmd_stop,
14925 	(cmdline_parse_inst_t *)&cmd_mac_addr,
14926 	(cmdline_parse_inst_t *)&cmd_set_qmap,
14927 	(cmdline_parse_inst_t *)&cmd_operate_port,
14928 	(cmdline_parse_inst_t *)&cmd_operate_specific_port,
14929 	(cmdline_parse_inst_t *)&cmd_operate_attach_port,
14930 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
14931 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
14932 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
14933 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
14934 	(cmdline_parse_inst_t *)&cmd_config_mtu,
14935 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
14936 	(cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
14937 	(cmdline_parse_inst_t *)&cmd_config_rss,
14938 	(cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
14939 	(cmdline_parse_inst_t *)&cmd_config_txqflags,
14940 	(cmdline_parse_inst_t *)&cmd_config_rss_reta,
14941 	(cmdline_parse_inst_t *)&cmd_showport_reta,
14942 	(cmdline_parse_inst_t *)&cmd_config_burst,
14943 	(cmdline_parse_inst_t *)&cmd_config_thresh,
14944 	(cmdline_parse_inst_t *)&cmd_config_threshold,
14945 	(cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
14946 	(cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
14947 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
14948 	(cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
14949 	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
14950 	(cmdline_parse_inst_t *)&cmd_tunnel_filter,
14951 	(cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
14952 	(cmdline_parse_inst_t *)&cmd_global_config,
14953 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
14954 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
14955 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
14956 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash,
14957 	(cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
14958 	(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
14959 	(cmdline_parse_inst_t *)&cmd_dump,
14960 	(cmdline_parse_inst_t *)&cmd_dump_one,
14961 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
14962 	(cmdline_parse_inst_t *)&cmd_syn_filter,
14963 	(cmdline_parse_inst_t *)&cmd_2tuple_filter,
14964 	(cmdline_parse_inst_t *)&cmd_5tuple_filter,
14965 	(cmdline_parse_inst_t *)&cmd_flex_filter,
14966 	(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
14967 	(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
14968 	(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
14969 	(cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
14970 	(cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
14971 	(cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
14972 	(cmdline_parse_inst_t *)&cmd_flush_flow_director,
14973 	(cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
14974 	(cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
14975 	(cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
14976 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
14977 	(cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
14978 	(cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
14979 	(cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
14980 	(cmdline_parse_inst_t *)&cmd_get_hash_global_config,
14981 	(cmdline_parse_inst_t *)&cmd_set_hash_global_config,
14982 	(cmdline_parse_inst_t *)&cmd_set_hash_input_set,
14983 	(cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
14984 	(cmdline_parse_inst_t *)&cmd_flow,
14985 	(cmdline_parse_inst_t *)&cmd_mcast_addr,
14986 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
14987 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
14988 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
14989 	(cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
14990 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
14991 	(cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
14992 	(cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
14993 	(cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
14994 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
14995 	(cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
14996 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
14997 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
14998 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
14999 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15000 	(cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15001 	(cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15002 	(cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15003 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15004 	(cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15005 	(cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15006 	(cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15007 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15008 	(cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15009 	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15010 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15011 	(cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15012 	(cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15013 	(cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15014 	(cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15015 	(cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15016 	(cmdline_parse_inst_t *)&cmd_vf_max_bw,
15017 	(cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15018 	(cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15019 	(cmdline_parse_inst_t *)&cmd_strict_link_prio,
15020 	(cmdline_parse_inst_t *)&cmd_tc_min_bw,
15021 	(cmdline_parse_inst_t *)&cmd_ddp_add,
15022 	(cmdline_parse_inst_t *)&cmd_ddp_del,
15023 	(cmdline_parse_inst_t *)&cmd_ddp_get_list,
15024 	(cmdline_parse_inst_t *)&cmd_ddp_get_info,
15025 	(cmdline_parse_inst_t *)&cmd_show_vf_stats,
15026 	(cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15027 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15028 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15029 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15030 	(cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15031 
15032 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15033 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15034 	(cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15035 	NULL,
15036 };
15037 
15038 /* read cmdline commands from file */
15039 void
15040 cmdline_read_from_file(const char *filename)
15041 {
15042 	struct cmdline *cl;
15043 
15044 	cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15045 	if (cl == NULL) {
15046 		printf("Failed to create file based cmdline context: %s\n",
15047 		       filename);
15048 		return;
15049 	}
15050 
15051 	cmdline_interact(cl);
15052 	cmdline_quit(cl);
15053 
15054 	cmdline_free(cl);
15055 
15056 	printf("Read CLI commands from %s\n", filename);
15057 }
15058 
15059 /* prompt function, called from main on MASTER lcore */
15060 void
15061 prompt(void)
15062 {
15063 	/* initialize non-constant commands */
15064 	cmd_set_fwd_mode_init();
15065 	cmd_set_fwd_retry_mode_init();
15066 
15067 	testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15068 	if (testpmd_cl == NULL)
15069 		return;
15070 	cmdline_interact(testpmd_cl);
15071 	cmdline_stdin_exit(testpmd_cl);
15072 }
15073 
15074 void
15075 prompt_exit(void)
15076 {
15077 	if (testpmd_cl != NULL)
15078 		cmdline_quit(testpmd_cl);
15079 }
15080 
15081 static void
15082 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15083 {
15084 	if (id == (portid_t)RTE_PORT_ALL) {
15085 		portid_t pid;
15086 
15087 		RTE_ETH_FOREACH_DEV(pid) {
15088 			/* check if need_reconfig has been set to 1 */
15089 			if (ports[pid].need_reconfig == 0)
15090 				ports[pid].need_reconfig = dev;
15091 			/* check if need_reconfig_queues has been set to 1 */
15092 			if (ports[pid].need_reconfig_queues == 0)
15093 				ports[pid].need_reconfig_queues = queue;
15094 		}
15095 	} else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15096 		/* check if need_reconfig has been set to 1 */
15097 		if (ports[id].need_reconfig == 0)
15098 			ports[id].need_reconfig = dev;
15099 		/* check if need_reconfig_queues has been set to 1 */
15100 		if (ports[id].need_reconfig_queues == 0)
15101 			ports[id].need_reconfig_queues = queue;
15102 	}
15103 }
15104