app/testpmd: fix bonding slave devices not released
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <inttypes.h>
13 #include <sys/queue.h>
14
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_debug.h>
19 #include <rte_cycles.h>
20 #include <rte_memory.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_ring.h>
29 #include <rte_mempool.h>
30 #include <rte_interrupts.h>
31 #include <rte_pci.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_string_fns.h>
35 #include <rte_devargs.h>
36 #include <rte_flow.h>
37 #ifdef RTE_LIB_GRO
38 #include <rte_gro.h>
39 #endif
40 #include <rte_mbuf_dyn.h>
41
42 #include <cmdline_rdline.h>
43 #include <cmdline_parse.h>
44 #include <cmdline_parse_num.h>
45 #include <cmdline_parse_string.h>
46 #include <cmdline_parse_ipaddr.h>
47 #include <cmdline_parse_etheraddr.h>
48 #include <cmdline_socket.h>
49 #include <cmdline.h>
50 #ifdef RTE_NET_BOND
51 #include <rte_eth_bond.h>
52 #include <rte_eth_bond_8023ad.h>
53 #endif
54 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
55 #include <rte_pmd_dpaa.h>
56 #endif
57 #ifdef RTE_NET_IXGBE
58 #include <rte_pmd_ixgbe.h>
59 #endif
60 #ifdef RTE_NET_I40E
61 #include <rte_pmd_i40e.h>
62 #endif
63 #ifdef RTE_NET_BNXT
64 #include <rte_pmd_bnxt.h>
65 #endif
66 #include "testpmd.h"
67 #include "cmdline_mtr.h"
68 #include "cmdline_tm.h"
69 #include "bpf_cmd.h"
70
71 static struct cmdline *testpmd_cl;
72 static cmdline_parse_ctx_t *main_ctx;
73 static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head =
74         TAILQ_HEAD_INITIALIZER(driver_commands_head);
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related commands.\n"
100                 "    help drivers                    : Driver specific commands.\n"
101                 "    help all                        : All of the above sections.\n\n"
102         );
103
104 }
105
106 static cmdline_parse_token_string_t cmd_help_brief_help =
107         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
108
109 static cmdline_parse_inst_t cmd_help_brief = {
110         .f = cmd_help_brief_parsed,
111         .data = NULL,
112         .help_str = "help: Show help",
113         .tokens = {
114                 (void *)&cmd_help_brief_help,
115                 NULL,
116         },
117 };
118
119 /* *** Help command with help sections. *** */
120 struct cmd_help_long_result {
121         cmdline_fixed_string_t help;
122         cmdline_fixed_string_t section;
123 };
124
125 static void cmd_help_long_parsed(void *parsed_result,
126                                  struct cmdline *cl,
127                                  __rte_unused void *data)
128 {
129         int show_all = 0;
130         struct cmd_help_long_result *res = parsed_result;
131
132         if (!strcmp(res->section, "all"))
133                 show_all = 1;
134
135         if (show_all || !strcmp(res->section, "control")) {
136
137                 cmdline_printf(
138                         cl,
139                         "\n"
140                         "Control forwarding:\n"
141                         "-------------------\n\n"
142
143                         "start\n"
144                         "    Start packet forwarding with current configuration.\n\n"
145
146                         "start tx_first\n"
147                         "    Start packet forwarding with current config"
148                         " after sending one burst of packets.\n\n"
149
150                         "stop\n"
151                         "    Stop packet forwarding, and display accumulated"
152                         " statistics.\n\n"
153
154                         "quit\n"
155                         "    Quit to prompt.\n\n"
156                 );
157         }
158
159         if (show_all || !strcmp(res->section, "display")) {
160
161                 cmdline_printf(
162                         cl,
163                         "\n"
164                         "Display:\n"
165                         "--------\n\n"
166
167                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
168                         "    Display information for port_id, or all.\n\n"
169
170                         "show port info (port_id) representor\n"
171                         "    Show supported representors for a specific port\n\n"
172
173                         "show port port_id (module_eeprom|eeprom)\n"
174                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
175
176                         "show port X rss reta (size) (mask0,mask1,...)\n"
177                         "    Display the rss redirection table entry indicated"
178                         " by masks on port X. size is used to indicate the"
179                         " hardware supported reta size\n\n"
180
181                         "show port (port_id) rss-hash [key]\n"
182                         "    Display the RSS hash functions and RSS hash key of port\n\n"
183
184                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
185                         "    Clear information for port_id, or all.\n\n"
186
187                         "show (rxq|txq) info (port_id) (queue_id)\n"
188                         "    Display information for configured RX/TX queue.\n\n"
189
190                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
191                         "    Display the given configuration.\n\n"
192
193                         "read rxd (port_id) (queue_id) (rxd_id)\n"
194                         "    Display an RX descriptor of a port RX queue.\n\n"
195
196                         "read txd (port_id) (queue_id) (txd_id)\n"
197                         "    Display a TX descriptor of a port TX queue.\n\n"
198
199                         "ddp get list (port_id)\n"
200                         "    Get ddp profile info list\n\n"
201
202                         "ddp get info (profile_path)\n"
203                         "    Get ddp profile information.\n\n"
204
205                         "show vf stats (port_id) (vf_id)\n"
206                         "    Display a VF's statistics.\n\n"
207
208                         "clear vf stats (port_id) (vf_id)\n"
209                         "    Reset a VF's statistics.\n\n"
210
211                         "show port (port_id) pctype mapping\n"
212                         "    Get flow ptype to pctype mapping on a port\n\n"
213
214                         "show port meter stats (port_id) (meter_id) (clear)\n"
215                         "    Get meter stats on a port\n\n"
216
217                         "show fwd stats all\n"
218                         "    Display statistics for all fwd engines.\n\n"
219
220                         "clear fwd stats all\n"
221                         "    Clear statistics for all fwd engines.\n\n"
222
223                         "show port (port_id) rx_offload capabilities\n"
224                         "    List all per queue and per port Rx offloading"
225                         " capabilities of a port\n\n"
226
227                         "show port (port_id) rx_offload configuration\n"
228                         "    List port level and all queue level"
229                         " Rx offloading configuration\n\n"
230
231                         "show port (port_id) tx_offload capabilities\n"
232                         "    List all per queue and per port"
233                         " Tx offloading capabilities of a port\n\n"
234
235                         "show port (port_id) tx_offload configuration\n"
236                         "    List port level and all queue level"
237                         " Tx offloading configuration\n\n"
238
239                         "show port (port_id) tx_metadata\n"
240                         "    Show Tx metadata value set"
241                         " for a specific port\n\n"
242
243                         "show port (port_id) ptypes\n"
244                         "    Show port supported ptypes"
245                         " for a specific port\n\n"
246
247                         "show device info (<identifier>|all)"
248                         "       Show general information about devices probed.\n\n"
249
250                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
251                         "       Show status of rx|tx descriptor.\n\n"
252
253                         "show port (port_id) rxq (queue_id) desc used count\n"
254                         "    Show current number of filled receive"
255                         " packet descriptors.\n\n"
256
257                         "show port (port_id) macs|mcast_macs"
258                         "       Display list of mac addresses added to port.\n\n"
259
260                         "show port (port_id) flow transfer proxy\n"
261                         "       Display proxy port to manage transfer flows\n\n"
262
263                         "show port (port_id) fec capabilities"
264                         "       Show fec capabilities of a port.\n\n"
265
266                         "show port (port_id) fec_mode"
267                         "       Show fec mode of a port.\n\n"
268
269                         "show port (port_id) flow_ctrl"
270                         "       Show flow control info of a port.\n\n"
271                 );
272         }
273
274         if (show_all || !strcmp(res->section, "config")) {
275                 cmdline_printf(
276                         cl,
277                         "\n"
278                         "Configuration:\n"
279                         "--------------\n"
280                         "Configuration changes only become active when"
281                         " forwarding is started/restarted.\n\n"
282
283                         "set default\n"
284                         "    Reset forwarding to the default configuration.\n\n"
285
286                         "set verbose (level)\n"
287                         "    Set the debug verbosity level X.\n\n"
288
289                         "set log global|(type) (level)\n"
290                         "    Set the log level.\n\n"
291
292                         "set nbport (num)\n"
293                         "    Set number of ports.\n\n"
294
295                         "set nbcore (num)\n"
296                         "    Set number of cores.\n\n"
297
298                         "set coremask (mask)\n"
299                         "    Set the forwarding cores hexadecimal mask.\n\n"
300
301                         "set portmask (mask)\n"
302                         "    Set the forwarding ports hexadecimal mask.\n\n"
303
304                         "set burst (num)\n"
305                         "    Set number of packets per burst.\n\n"
306
307                         "set burst tx delay (microseconds) retry (num)\n"
308                         "    Set the transmit delay time and number of retries,"
309                         " effective when retry is enabled.\n\n"
310
311                         "set rxoffs (x[,y]*)\n"
312                         "    Set the offset of each packet segment on"
313                         " receiving if split feature is engaged."
314                         " Affects only the queues configured with split"
315                         " offloads.\n\n"
316
317                         "set rxpkts (x[,y]*)\n"
318                         "    Set the length of each segment to scatter"
319                         " packets on receiving if split feature is engaged."
320                         " Affects only the queues configured with split"
321                         " offloads.\n\n"
322
323                         "set txpkts (x[,y]*)\n"
324                         "    Set the length of each segment of TXONLY"
325                         " and optionally CSUM packets.\n\n"
326
327                         "set txsplit (off|on|rand)\n"
328                         "    Set the split policy for the TX packets."
329                         " Right now only applicable for CSUM and TXONLY"
330                         " modes\n\n"
331
332                         "set txtimes (x, y)\n"
333                         "    Set the scheduling on timestamps"
334                         " timings for the TXONLY mode\n\n"
335
336                         "set corelist (x[,y]*)\n"
337                         "    Set the list of forwarding cores.\n\n"
338
339                         "set portlist (x[,y]*)\n"
340                         "    Set the list of forwarding ports.\n\n"
341
342                         "set port setup on (iterator|event)\n"
343                         "    Select how attached port is retrieved for setup.\n\n"
344
345                         "set tx loopback (port_id) (on|off)\n"
346                         "    Enable or disable tx loopback.\n\n"
347
348                         "set all queues drop (port_id) (on|off)\n"
349                         "    Set drop enable bit for all queues.\n\n"
350
351                         "set vf split drop (port_id) (vf_id) (on|off)\n"
352                         "    Set split drop enable bit for a VF from the PF.\n\n"
353
354                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
355                         "    Set MAC antispoof for a VF from the PF.\n\n"
356
357                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
358                         "    Enable MACsec offload.\n\n"
359
360                         "set macsec offload (port_id) off\n"
361                         "    Disable MACsec offload.\n\n"
362
363                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
364                         "    Configure MACsec secure connection (SC).\n\n"
365
366                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
367                         "    Configure MACsec secure association (SA).\n\n"
368
369                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
370                         "    Set VF broadcast for a VF from the PF.\n\n"
371
372                         "vlan set stripq (on|off) (port_id,queue_id)\n"
373                         "    Set the VLAN strip for a queue on a port.\n\n"
374
375                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
376                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
377
378                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
379                         "    Set VLAN insert for a VF from the PF.\n\n"
380
381                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
382                         "    Set VLAN antispoof for a VF from the PF.\n\n"
383
384                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
385                         "    Set VLAN tag for a VF from the PF.\n\n"
386
387                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
388                         "    Set a VF's max bandwidth(Mbps).\n\n"
389
390                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
391                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
392
393                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
394                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
395
396                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
397                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
398
399                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
400                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
401
402                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
403                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
404
405                         "vlan set (inner|outer) tpid (value) (port_id)\n"
406                         "    Set the VLAN TPID for Packet Filtering on"
407                         " a port\n\n"
408
409                         "rx_vlan add (vlan_id|all) (port_id)\n"
410                         "    Add a vlan_id, or all identifiers, to the set"
411                         " of VLAN identifiers filtered by port_id.\n\n"
412
413                         "rx_vlan rm (vlan_id|all) (port_id)\n"
414                         "    Remove a vlan_id, or all identifiers, from the set"
415                         " of VLAN identifiers filtered by port_id.\n\n"
416
417                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
418                         "    Add a vlan_id, to the set of VLAN identifiers"
419                         "filtered for VF(s) from port_id.\n\n"
420
421                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
422                         "    Remove a vlan_id, to the set of VLAN identifiers"
423                         "filtered for VF(s) from port_id.\n\n"
424
425                         "rx_vxlan_port add (udp_port) (port_id)\n"
426                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
427
428                         "rx_vxlan_port rm (udp_port) (port_id)\n"
429                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
430
431                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
432                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
433                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
434
435                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
436                         "    Set port based TX VLAN insertion.\n\n"
437
438                         "tx_vlan reset (port_id)\n"
439                         "    Disable hardware insertion of a VLAN header in"
440                         " packets sent on a port.\n\n"
441
442                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
443                         "    Select hardware or software calculation of the"
444                         " checksum when transmitting a packet using the"
445                         " csum forward engine.\n"
446                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
447                         "    outer-ip concerns the outer IP layer in"
448                         "    outer-udp concerns the outer UDP layer in"
449                         " case the packet is recognized as a tunnel packet by"
450                         " the forward engine (vxlan, gre and ipip are supported)\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "csum parse-tunnel (on|off) (tx_port_id)\n"
454                         "    If disabled, treat tunnel packets as non-tunneled"
455                         " packets (treat inner headers as payload). The port\n"
456                         "    argument is the port used for TX in csum forward"
457                         " engine.\n\n"
458
459                         "csum show (port_id)\n"
460                         "    Display tx checksum offload configuration\n\n"
461
462                         "tso set (segsize) (portid)\n"
463                         "    Enable TCP Segmentation Offload in csum forward"
464                         " engine.\n"
465                         "    Please check the NIC datasheet for HW limits.\n\n"
466
467                         "tso show (portid)"
468                         "    Display the status of TCP Segmentation Offload.\n\n"
469
470 #ifdef RTE_LIB_GRO
471                         "set port (port_id) gro on|off\n"
472                         "    Enable or disable Generic Receive Offload in"
473                         " csum forwarding engine.\n\n"
474
475                         "show port (port_id) gro\n"
476                         "    Display GRO configuration.\n\n"
477
478                         "set gro flush (cycles)\n"
479                         "    Set the cycle to flush GROed packets from"
480                         " reassembly tables.\n\n"
481 #endif
482
483 #ifdef RTE_LIB_GSO
484                         "set port (port_id) gso (on|off)"
485                         "    Enable or disable Generic Segmentation Offload in"
486                         " csum forwarding engine.\n\n"
487
488                         "set gso segsz (length)\n"
489                         "    Set max packet length for output GSO segments,"
490                         " including packet header and payload.\n\n"
491
492                         "show port (port_id) gso\n"
493                         "    Show GSO configuration.\n\n"
494 #endif
495
496                         "set fwd (%s)\n"
497                         "    Set packet forwarding mode.\n\n"
498
499                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
500                         "    Add a MAC address on port_id.\n\n"
501
502                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
503                         "    Remove a MAC address from port_id.\n\n"
504
505                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
506                         "    Set the default MAC address for port_id.\n\n"
507
508                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
509                         "    Add a MAC address for a VF on the port.\n\n"
510
511                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
512                         "    Set the MAC address for a VF from the PF.\n\n"
513
514                         "set eth-peer (port_id) (peer_addr)\n"
515                         "    set the peer address for certain port.\n\n"
516
517                         "set port (port_id) uta (mac_address|all) (on|off)\n"
518                         "    Add/Remove a or all unicast hash filter(s)"
519                         "from port X.\n\n"
520
521                         "set promisc (port_id|all) (on|off)\n"
522                         "    Set the promiscuous mode on port_id, or all.\n\n"
523
524                         "set allmulti (port_id|all) (on|off)\n"
525                         "    Set the allmulti mode on port_id, or all.\n\n"
526
527                         "set vf promisc (port_id) (vf_id) (on|off)\n"
528                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
529
530                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
531                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
532
533                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
534                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
535                         " (on|off) autoneg (on|off) (port_id)\n"
536                         "set flow_ctrl rx (on|off) (portid)\n"
537                         "set flow_ctrl tx (on|off) (portid)\n"
538                         "set flow_ctrl high_water (high_water) (portid)\n"
539                         "set flow_ctrl low_water (low_water) (portid)\n"
540                         "set flow_ctrl pause_time (pause_time) (portid)\n"
541                         "set flow_ctrl send_xon (send_xon) (portid)\n"
542                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
543                         "set flow_ctrl autoneg (on|off) (port_id)\n"
544                         "    Set the link flow control parameter on a port.\n\n"
545
546                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
547                         " (low_water) (pause_time) (priority) (port_id)\n"
548                         "    Set the priority flow control parameter on a"
549                         " port.\n\n"
550
551                         "set pfc_queue_ctrl (port_id) rx (on|off) (tx_qid)"
552                         " (tx_tc) tx (on|off) (rx_qid) (rx_tc) (pause_time)\n"
553                         "    Set the queue priority flow control parameter on a"
554                         " given Rx and Tx queues of a port.\n\n"
555
556                         "set port (port_id) rxq (queue_id) avail_thresh (0..99)>\n "
557                         "    set available descriptors threshold for Rx queue\n\n"
558
559                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
560                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
561                         " queue on port.\n"
562                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
563                         " on port 0 to mapping 5.\n\n"
564
565                         "set xstats-hide-zero on|off\n"
566                         "    Set the option to hide the zero values"
567                         " for xstats display.\n"
568
569                         "set record-core-cycles on|off\n"
570                         "    Set the option to enable measurement of CPU cycles.\n"
571
572                         "set record-burst-stats on|off\n"
573                         "    Set the option to enable display of RX and TX bursts.\n"
574
575                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
576                         "    Enable/Disable a VF receive/transmit from a port\n\n"
577
578                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
579                         "|MPE) (on|off)\n"
580                         "    AUPE:accepts untagged VLAN;"
581                         "ROPE:accept unicast hash\n\n"
582                         "    BAM:accepts broadcast packets;"
583                         "MPE:accepts all multicast packets\n\n"
584                         "    Enable/Disable a VF receive mode of a port\n\n"
585
586                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
587                         "    Set rate limit for a queue of a port\n\n"
588
589                         "set port (port_id) vf (vf_id) rate (rate_num) "
590                         "queue_mask (queue_mask_value)\n"
591                         "    Set rate limit for queues in VF of a port\n\n"
592
593                         "set flush_rx (on|off)\n"
594                         "   Flush (default) or don't flush RX streams before"
595                         " forwarding. Mainly used with PCAP drivers.\n\n"
596
597                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
598                         "   Set the bypass mode for the lowest port on bypass enabled"
599                         " NIC.\n\n"
600
601                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
602                         "mode (normal|bypass|isolate) (port_id)\n"
603                         "   Set the event required to initiate specified bypass mode for"
604                         " the lowest port on a bypass enabled NIC where:\n"
605                         "       timeout   = enable bypass after watchdog timeout.\n"
606                         "       os_on     = enable bypass when OS/board is powered on.\n"
607                         "       os_off    = enable bypass when OS/board is powered off.\n"
608                         "       power_on  = enable bypass when power supply is turned on.\n"
609                         "       power_off = enable bypass when power supply is turned off."
610                         "\n\n"
611
612                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
613                         "   Set the bypass watchdog timeout to 'n' seconds"
614                         " where 0 = instant.\n\n"
615
616                         "show bypass config (port_id)\n"
617                         "   Show the bypass configuration for a bypass enabled NIC"
618                         " using the lowest port on the NIC.\n\n"
619
620 #ifdef RTE_NET_BOND
621                         "create bonded device (mode) (socket)\n"
622                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
623
624                         "add bonding slave (slave_id) (port_id)\n"
625                         "       Add a slave device to a bonded device.\n\n"
626
627                         "remove bonding slave (slave_id) (port_id)\n"
628                         "       Remove a slave device from a bonded device.\n\n"
629
630                         "set bonding mode (value) (port_id)\n"
631                         "       Set the bonding mode on a bonded device.\n\n"
632
633                         "set bonding primary (slave_id) (port_id)\n"
634                         "       Set the primary slave for a bonded device.\n\n"
635
636                         "show bonding config (port_id)\n"
637                         "       Show the bonding config for port_id.\n\n"
638
639                         "show bonding lacp info (port_id)\n"
640                         "       Show the bonding lacp information for port_id.\n\n"
641
642                         "set bonding mac_addr (port_id) (address)\n"
643                         "       Set the MAC address of a bonded device.\n\n"
644
645                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
646                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
647
648                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
649                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
650
651                         "set bonding mon_period (port_id) (value)\n"
652                         "       Set the bonding link status monitoring polling period in ms.\n\n"
653
654                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
655                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
656
657 #endif
658                         "set link-up port (port_id)\n"
659                         "       Set link up for a port.\n\n"
660
661                         "set link-down port (port_id)\n"
662                         "       Set link down for a port.\n\n"
663
664                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
665                         "    Load a profile package on a port\n\n"
666
667                         "ddp del (port_id) (backup_profile_path)\n"
668                         "    Delete a profile package from a port\n\n"
669
670                         "ptype mapping get (port_id) (valid_only)\n"
671                         "    Get ptype mapping on a port\n\n"
672
673                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
674                         "    Replace target with the pkt_type in ptype mapping\n\n"
675
676                         "ptype mapping reset (port_id)\n"
677                         "    Reset ptype mapping on a port\n\n"
678
679                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
680                         "    Update a ptype mapping item on a port\n\n"
681
682                         "set port (port_id) ptype_mask (ptype_mask)\n"
683                         "    set packet types classification for a specific port\n\n"
684
685                         "set port (port_id) queue-region region_id (value) "
686                         "queue_start_index (value) queue_num (value)\n"
687                         "    Set a queue region on a port\n\n"
688
689                         "set port (port_id) queue-region region_id (value) "
690                         "flowtype (value)\n"
691                         "    Set a flowtype region index on a port\n\n"
692
693                         "set port (port_id) queue-region UP (value) region_id (value)\n"
694                         "    Set the mapping of User Priority to "
695                         "queue region on a port\n\n"
696
697                         "set port (port_id) queue-region flush (on|off)\n"
698                         "    flush all queue region related configuration\n\n"
699
700                         "show port meter cap (port_id)\n"
701                         "    Show port meter capability information\n\n"
702
703                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
704                         "    meter profile add - srtcm rfc 2697\n\n"
705
706                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
707                         "    meter profile add - trtcm rfc 2698\n\n"
708
709                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
710                         "    meter profile add - trtcm rfc 4115\n\n"
711
712                         "del port meter profile (port_id) (profile_id)\n"
713                         "    meter profile delete\n\n"
714
715                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
716                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
717                         "(dscp_tbl_entry63)]\n"
718                         "    meter create\n\n"
719
720                         "enable port meter (port_id) (mtr_id)\n"
721                         "    meter enable\n\n"
722
723                         "disable port meter (port_id) (mtr_id)\n"
724                         "    meter disable\n\n"
725
726                         "del port meter (port_id) (mtr_id)\n"
727                         "    meter delete\n\n"
728
729                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
730                         "y_actions (actions) r_actions (actions)\n"
731                         "    meter policy add\n\n"
732
733                         "del port meter policy (port_id) (policy_id)\n"
734                         "    meter policy delete\n\n"
735
736                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
737                         "    meter update meter profile\n\n"
738
739                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
740                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
741                         "    update meter dscp table entries\n\n"
742
743                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
744                         "(action0) [(action1) (action2)]\n"
745                         "    meter update policer action\n\n"
746
747                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
748                         "    meter update stats\n\n"
749
750                         "show port (port_id) queue-region\n"
751                         "    show all queue region related configuration info\n\n"
752
753                         "set port (port_id) fec_mode auto|off|rs|baser\n"
754                         "    set fec mode for a specific port\n\n"
755
756                         , list_pkt_forwarding_modes()
757                 );
758         }
759
760         if (show_all || !strcmp(res->section, "ports")) {
761
762                 cmdline_printf(
763                         cl,
764                         "\n"
765                         "Port Operations:\n"
766                         "----------------\n\n"
767
768                         "port start (port_id|all)\n"
769                         "    Start all ports or port_id.\n\n"
770
771                         "port stop (port_id|all)\n"
772                         "    Stop all ports or port_id.\n\n"
773
774                         "port close (port_id|all)\n"
775                         "    Close all ports or port_id.\n\n"
776
777                         "port reset (port_id|all)\n"
778                         "    Reset all ports or port_id.\n\n"
779
780                         "port attach (ident)\n"
781                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
782
783                         "port detach (port_id)\n"
784                         "    Detach physical or virtual dev by port_id\n\n"
785
786                         "port config (port_id|all)"
787                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
788                         " duplex (half|full|auto)\n"
789                         "    Set speed and duplex for all ports or port_id\n\n"
790
791                         "port config (port_id|all) loopback (mode)\n"
792                         "    Set loopback mode for all ports or port_id\n\n"
793
794                         "port config all (rxq|txq|rxd|txd) (value)\n"
795                         "    Set number for rxq/txq/rxd/txd.\n\n"
796
797                         "port config all max-pkt-len (value)\n"
798                         "    Set the max packet length.\n\n"
799
800                         "port config all max-lro-pkt-size (value)\n"
801                         "    Set the max LRO aggregated packet size.\n\n"
802
803                         "port config all drop-en (on|off)\n"
804                         "    Enable or disable packet drop on all RX queues of all ports when no "
805                         "receive buffers available.\n\n"
806
807                         "port config all rss (all|default|ip|tcp|udp|sctp|"
808                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|"
809                         "none|level-default|level-outer|level-inner|<flowtype_id>)\n"
810                         "    Set the RSS mode.\n\n"
811
812                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
813                         "    Set the RSS redirection table.\n\n"
814
815                         "port config (port_id) dcb vt (on|off) (traffic_class)"
816                         " pfc (on|off)\n"
817                         "    Set the DCB mode.\n\n"
818
819                         "port config all burst (value)\n"
820                         "    Set the number of packets per burst.\n\n"
821
822                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
823                         " (value)\n"
824                         "    Set the ring prefetch/host/writeback threshold"
825                         " for tx/rx queue.\n\n"
826
827                         "port config all (txfreet|txrst|rxfreet) (value)\n"
828                         "    Set free threshold for rx/tx, or set"
829                         " tx rs bit threshold.\n\n"
830                         "port config mtu X value\n"
831                         "    Set the MTU of port X to a given value\n\n"
832
833                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
834                         "    Set a rx/tx queue's ring size configuration, the new"
835                         " value will take effect after command that (re-)start the port"
836                         " or command that setup the specific queue\n\n"
837
838                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
839                         "    Start/stop a rx/tx queue of port X. Only take effect"
840                         " when port X is started\n\n"
841
842                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
843                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
844                         " take effect when port X is stopped.\n\n"
845
846                         "port (port_id) (rxq|txq) (queue_id) setup\n"
847                         "    Setup a rx/tx queue of port X.\n\n"
848
849                         "port config (port_id) pctype mapping reset\n"
850                         "    Reset flow type to pctype mapping on a port\n\n"
851
852                         "port config (port_id) pctype mapping update"
853                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
854                         "    Update a flow type to pctype mapping item on a port\n\n"
855
856                         "port config (port_id) pctype (pctype_id) hash_inset|"
857                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
858                         " (field_idx)\n"
859                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
860
861                         "port config (port_id) pctype (pctype_id) hash_inset|"
862                         "fdir_inset|fdir_flx_inset clear all"
863                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
864
865                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
866                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
867
868                         "port config <port_id> rx_offload vlan_strip|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870                         "outer_ipv4_cksum|macsec_strip|header_split|"
871                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
872                         "buffer_split|timestamp|security|keep_crc on|off\n"
873                         "     Enable or disable a per port Rx offloading"
874                         " on all Rx queues of a port\n\n"
875
876                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
878                         "outer_ipv4_cksum|macsec_strip|header_split|"
879                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
880                         "buffer_split|timestamp|security|keep_crc on|off\n"
881                         "    Enable or disable a per queue Rx offloading"
882                         " only on a specific Rx queue\n\n"
883
884                         "port config (port_id) tx_offload vlan_insert|"
885                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
886                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
887                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
888                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
889                         "security on|off\n"
890                         "    Enable or disable a per port Tx offloading"
891                         " on all Tx queues of a port\n\n"
892
893                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
894                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
895                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
896                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
897                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
898                         " on|off\n"
899                         "    Enable or disable a per queue Tx offloading"
900                         " only on a specific Tx queue\n\n"
901
902                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
903                         "    Load an eBPF program as a callback"
904                         " for particular RX/TX queue\n\n"
905
906                         "bpf-unload rx|tx (port) (queue)\n"
907                         "    Unload previously loaded eBPF program"
908                         " for particular RX/TX queue\n\n"
909
910                         "port config (port_id) tx_metadata (value)\n"
911                         "    Set Tx metadata value per port. Testpmd will add this value"
912                         " to any Tx packet sent from this port\n\n"
913
914                         "port config (port_id) dynf (name) set|clear\n"
915                         "    Register a dynf and Set/clear this flag on Tx. "
916                         "Testpmd will set this value to any Tx packet "
917                         "sent from this port\n\n"
918
919                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
920                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
921                 );
922         }
923
924         if (show_all || !strcmp(res->section, "registers")) {
925
926                 cmdline_printf(
927                         cl,
928                         "\n"
929                         "Registers:\n"
930                         "----------\n\n"
931
932                         "read reg (port_id) (address)\n"
933                         "    Display value of a port register.\n\n"
934
935                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
936                         "    Display a port register bit field.\n\n"
937
938                         "read regbit (port_id) (address) (bit_x)\n"
939                         "    Display a single port register bit.\n\n"
940
941                         "write reg (port_id) (address) (value)\n"
942                         "    Set value of a port register.\n\n"
943
944                         "write regfield (port_id) (address) (bit_x) (bit_y)"
945                         " (value)\n"
946                         "    Set bit field of a port register.\n\n"
947
948                         "write regbit (port_id) (address) (bit_x) (value)\n"
949                         "    Set single bit value of a port register.\n\n"
950                 );
951         }
952         if (show_all || !strcmp(res->section, "filters")) {
953
954                 cmdline_printf(
955                         cl,
956                         "\n"
957                         "filters:\n"
958                         "--------\n\n"
959
960 #ifdef RTE_NET_I40E
961                         "flow_director_filter (port_id) mode raw (add|del|update)"
962                         " flow (flow_id) (drop|fwd) queue (queue_id)"
963                         " fd_id (fd_id_value) packet (packet file name)\n"
964                         "    Add/Del a raw type flow director filter.\n\n"
965 #endif
966
967                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
968                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
969                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
970                         "    Set flow director IP mask.\n\n"
971
972                         "flow_director_mask (port_id) mode MAC-VLAN"
973                         " vlan (vlan_value)\n"
974                         "    Set flow director MAC-VLAN mask.\n\n"
975
976                         "flow_director_mask (port_id) mode Tunnel"
977                         " vlan (vlan_value) mac (mac_value)"
978                         " tunnel-type (tunnel_type_value)"
979                         " tunnel-id (tunnel_id_value)\n"
980                         "    Set flow director Tunnel mask.\n\n"
981
982                         "flow_director_flex_payload (port_id)"
983                         " (raw|l2|l3|l4) (config)\n"
984                         "    Configure flex payload selection.\n\n"
985
986                         "flow validate {port_id}"
987                         " [group {group_id}] [priority {level}]"
988                         " [ingress] [egress]"
989                         " pattern {item} [/ {item} [...]] / end"
990                         " actions {action} [/ {action} [...]] / end\n"
991                         "    Check whether a flow rule can be created.\n\n"
992
993                         "flow create {port_id}"
994                         " [group {group_id}] [priority {level}]"
995                         " [ingress] [egress]"
996                         " pattern {item} [/ {item} [...]] / end"
997                         " actions {action} [/ {action} [...]] / end\n"
998                         "    Create a flow rule.\n\n"
999
1000                         "flow destroy {port_id} rule {rule_id} [...]\n"
1001                         "    Destroy specific flow rules.\n\n"
1002
1003                         "flow flush {port_id}\n"
1004                         "    Destroy all flow rules.\n\n"
1005
1006                         "flow query {port_id} {rule_id} {action}\n"
1007                         "    Query an existing flow rule.\n\n"
1008
1009                         "flow list {port_id} [group {group_id}] [...]\n"
1010                         "    List existing flow rules sorted by priority,"
1011                         " filtered by group identifiers.\n\n"
1012
1013                         "flow isolate {port_id} {boolean}\n"
1014                         "    Restrict ingress traffic to the defined"
1015                         " flow rules\n\n"
1016
1017                         "flow aged {port_id} [destroy]\n"
1018                         "    List and destroy aged flows"
1019                         " flow rules\n\n"
1020
1021                         "flow indirect_action {port_id} create"
1022                         " [action_id {indirect_action_id}]"
1023                         " [ingress] [egress]"
1024                         " action {action} / end\n"
1025                         "    Create indirect action.\n\n"
1026
1027                         "flow indirect_action {port_id} update"
1028                         " {indirect_action_id} action {action} / end\n"
1029                         "    Update indirect action.\n\n"
1030
1031                         "flow indirect_action {port_id} destroy"
1032                         " action_id {indirect_action_id} [...]\n"
1033                         "    Destroy specific indirect actions.\n\n"
1034
1035                         "flow indirect_action {port_id} query"
1036                         " {indirect_action_id}\n"
1037                         "    Query an existing indirect action.\n\n"
1038
1039                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1040                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1041                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1042                         "       Configure the VXLAN encapsulation for flows.\n\n"
1043
1044                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1045                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1046                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1047                         " eth-dst (eth-dst)\n"
1048                         "       Configure the VXLAN encapsulation for flows.\n\n"
1049
1050                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1051                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1052                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1053                         " eth-dst (eth-dst)\n"
1054                         "       Configure the VXLAN encapsulation for flows.\n\n"
1055
1056                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1057                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1058                         " (eth-dst)\n"
1059                         "       Configure the NVGRE encapsulation for flows.\n\n"
1060
1061                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1062                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1063                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1064                         "       Configure the NVGRE encapsulation for flows.\n\n"
1065
1066                         "set raw_encap {flow items}\n"
1067                         "       Configure the encapsulation with raw data.\n\n"
1068
1069                         "set raw_decap {flow items}\n"
1070                         "       Configure the decapsulation with raw data.\n\n"
1071
1072                 );
1073         }
1074
1075         if (show_all || !strcmp(res->section, "traffic_management")) {
1076                 cmdline_printf(
1077                         cl,
1078                         "\n"
1079                         "Traffic Management:\n"
1080                         "--------------\n"
1081                         "show port tm cap (port_id)\n"
1082                         "       Display the port TM capability.\n\n"
1083
1084                         "show port tm level cap (port_id) (level_id)\n"
1085                         "       Display the port TM hierarchical level capability.\n\n"
1086
1087                         "show port tm node cap (port_id) (node_id)\n"
1088                         "       Display the port TM node capability.\n\n"
1089
1090                         "show port tm node type (port_id) (node_id)\n"
1091                         "       Display the port TM node type.\n\n"
1092
1093                         "show port tm node stats (port_id) (node_id) (clear)\n"
1094                         "       Display the port TM node stats.\n\n"
1095
1096                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1097                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1098                         " (packet_length_adjust) (packet_mode)\n"
1099                         "       Add port tm node private shaper profile.\n\n"
1100
1101                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1102                         "       Delete port tm node private shaper profile.\n\n"
1103
1104                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1105                         " (shaper_profile_id)\n"
1106                         "       Add/update port tm node shared shaper.\n\n"
1107
1108                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1109                         "       Delete port tm node shared shaper.\n\n"
1110
1111                         "set port tm node shaper profile (port_id) (node_id)"
1112                         " (shaper_profile_id)\n"
1113                         "       Set port tm node shaper profile.\n\n"
1114
1115                         "add port tm node wred profile (port_id) (wred_profile_id)"
1116                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1117                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1118                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1119                         "       Add port tm node wred profile.\n\n"
1120
1121                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1122                         "       Delete port tm node wred profile.\n\n"
1123
1124                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1125                         " (priority) (weight) (level_id) (shaper_profile_id)"
1126                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1127                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1128                         "       Add port tm nonleaf node.\n\n"
1129
1130                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1131                         " (priority) (weight) (level_id) (shaper_profile_id)"
1132                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1133                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1134                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1135
1136                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1137                         " (priority) (weight) (level_id) (shaper_profile_id)"
1138                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1139                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1140                         "       Add port tm leaf node.\n\n"
1141
1142                         "del port tm node (port_id) (node_id)\n"
1143                         "       Delete port tm node.\n\n"
1144
1145                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1146                         " (priority) (weight)\n"
1147                         "       Set port tm node parent.\n\n"
1148
1149                         "suspend port tm node (port_id) (node_id)"
1150                         "       Suspend tm node.\n\n"
1151
1152                         "resume port tm node (port_id) (node_id)"
1153                         "       Resume tm node.\n\n"
1154
1155                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1156                         "       Commit tm hierarchy.\n\n"
1157
1158                         "set port tm mark ip_ecn (port) (green) (yellow)"
1159                         " (red)\n"
1160                         "    Enables/Disables the traffic management marking"
1161                         " for IP ECN (Explicit Congestion Notification)"
1162                         " packets on a given port\n\n"
1163
1164                         "set port tm mark ip_dscp (port) (green) (yellow)"
1165                         " (red)\n"
1166                         "    Enables/Disables the traffic management marking"
1167                         " on the port for IP dscp packets\n\n"
1168
1169                         "set port tm mark vlan_dei (port) (green) (yellow)"
1170                         " (red)\n"
1171                         "    Enables/Disables the traffic management marking"
1172                         " on the port for VLAN packets with DEI enabled\n\n"
1173                 );
1174         }
1175
1176         if (show_all || !strcmp(res->section, "devices")) {
1177                 cmdline_printf(
1178                         cl,
1179                         "\n"
1180                         "Device Operations:\n"
1181                         "--------------\n"
1182                         "device detach (identifier)\n"
1183                         "       Detach device by identifier.\n\n"
1184                 );
1185         }
1186
1187         if (show_all || !strcmp(res->section, "drivers")) {
1188                 struct testpmd_driver_commands *c;
1189                 unsigned int i;
1190
1191                 cmdline_printf(
1192                         cl,
1193                         "\n"
1194                         "Driver specific:\n"
1195                         "----------------\n"
1196                 );
1197                 TAILQ_FOREACH(c, &driver_commands_head, next) {
1198                         for (i = 0; c->commands[i].ctx != NULL; i++)
1199                                 cmdline_printf(cl, "%s\n", c->commands[i].help);
1200                 }
1201         }
1202 }
1203
1204 static cmdline_parse_token_string_t cmd_help_long_help =
1205         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1206
1207 static cmdline_parse_token_string_t cmd_help_long_section =
1208         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1209                 "all#control#display#config#ports#registers#"
1210                 "filters#traffic_management#devices#drivers");
1211
1212 static cmdline_parse_inst_t cmd_help_long = {
1213         .f = cmd_help_long_parsed,
1214         .data = NULL,
1215         .help_str = "help all|control|display|config|ports|register|"
1216                 "filters|traffic_management|devices|drivers: "
1217                 "Show help",
1218         .tokens = {
1219                 (void *)&cmd_help_long_help,
1220                 (void *)&cmd_help_long_section,
1221                 NULL,
1222         },
1223 };
1224
1225
1226 /* *** start/stop/close all ports *** */
1227 struct cmd_operate_port_result {
1228         cmdline_fixed_string_t keyword;
1229         cmdline_fixed_string_t name;
1230         cmdline_fixed_string_t value;
1231 };
1232
1233 static void cmd_operate_port_parsed(void *parsed_result,
1234                                 __rte_unused struct cmdline *cl,
1235                                 __rte_unused void *data)
1236 {
1237         struct cmd_operate_port_result *res = parsed_result;
1238
1239         if (!strcmp(res->name, "start"))
1240                 start_port(RTE_PORT_ALL);
1241         else if (!strcmp(res->name, "stop"))
1242                 stop_port(RTE_PORT_ALL);
1243         else if (!strcmp(res->name, "close"))
1244                 close_port(RTE_PORT_ALL);
1245         else if (!strcmp(res->name, "reset"))
1246                 reset_port(RTE_PORT_ALL);
1247         else
1248                 fprintf(stderr, "Unknown parameter\n");
1249 }
1250
1251 static cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1252         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1253                                                                 "port");
1254 static cmdline_parse_token_string_t cmd_operate_port_all_port =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1256                                                 "start#stop#close#reset");
1257 static cmdline_parse_token_string_t cmd_operate_port_all_all =
1258         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1259
1260 static cmdline_parse_inst_t cmd_operate_port = {
1261         .f = cmd_operate_port_parsed,
1262         .data = NULL,
1263         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1264         .tokens = {
1265                 (void *)&cmd_operate_port_all_cmd,
1266                 (void *)&cmd_operate_port_all_port,
1267                 (void *)&cmd_operate_port_all_all,
1268                 NULL,
1269         },
1270 };
1271
1272 /* *** start/stop/close specific port *** */
1273 struct cmd_operate_specific_port_result {
1274         cmdline_fixed_string_t keyword;
1275         cmdline_fixed_string_t name;
1276         uint8_t value;
1277 };
1278
1279 static void cmd_operate_specific_port_parsed(void *parsed_result,
1280                         __rte_unused struct cmdline *cl,
1281                                 __rte_unused void *data)
1282 {
1283         struct cmd_operate_specific_port_result *res = parsed_result;
1284
1285         if (!strcmp(res->name, "start"))
1286                 start_port(res->value);
1287         else if (!strcmp(res->name, "stop"))
1288                 stop_port(res->value);
1289         else if (!strcmp(res->name, "close"))
1290                 close_port(res->value);
1291         else if (!strcmp(res->name, "reset"))
1292                 reset_port(res->value);
1293         else
1294                 fprintf(stderr, "Unknown parameter\n");
1295 }
1296
1297 static cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1298         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1299                                                         keyword, "port");
1300 static cmdline_parse_token_string_t cmd_operate_specific_port_port =
1301         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1302                                                 name, "start#stop#close#reset");
1303 static cmdline_parse_token_num_t cmd_operate_specific_port_id =
1304         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1305                                                         value, RTE_UINT8);
1306
1307 static cmdline_parse_inst_t cmd_operate_specific_port = {
1308         .f = cmd_operate_specific_port_parsed,
1309         .data = NULL,
1310         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1311         .tokens = {
1312                 (void *)&cmd_operate_specific_port_cmd,
1313                 (void *)&cmd_operate_specific_port_port,
1314                 (void *)&cmd_operate_specific_port_id,
1315                 NULL,
1316         },
1317 };
1318
1319 /* *** enable port setup (after attach) via iterator or event *** */
1320 struct cmd_set_port_setup_on_result {
1321         cmdline_fixed_string_t set;
1322         cmdline_fixed_string_t port;
1323         cmdline_fixed_string_t setup;
1324         cmdline_fixed_string_t on;
1325         cmdline_fixed_string_t mode;
1326 };
1327
1328 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1329                                 __rte_unused struct cmdline *cl,
1330                                 __rte_unused void *data)
1331 {
1332         struct cmd_set_port_setup_on_result *res = parsed_result;
1333
1334         if (strcmp(res->mode, "event") == 0)
1335                 setup_on_probe_event = true;
1336         else if (strcmp(res->mode, "iterator") == 0)
1337                 setup_on_probe_event = false;
1338         else
1339                 fprintf(stderr, "Unknown mode\n");
1340 }
1341
1342 static cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1343         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1344                         set, "set");
1345 static cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1346         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1347                         port, "port");
1348 static cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1349         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1350                         setup, "setup");
1351 static cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1352         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1353                         on, "on");
1354 static cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1355         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1356                         mode, "iterator#event");
1357
1358 static cmdline_parse_inst_t cmd_set_port_setup_on = {
1359         .f = cmd_set_port_setup_on_parsed,
1360         .data = NULL,
1361         .help_str = "set port setup on iterator|event",
1362         .tokens = {
1363                 (void *)&cmd_set_port_setup_on_set,
1364                 (void *)&cmd_set_port_setup_on_port,
1365                 (void *)&cmd_set_port_setup_on_setup,
1366                 (void *)&cmd_set_port_setup_on_on,
1367                 (void *)&cmd_set_port_setup_on_mode,
1368                 NULL,
1369         },
1370 };
1371
1372 /* *** attach a specified port *** */
1373 struct cmd_operate_attach_port_result {
1374         cmdline_fixed_string_t port;
1375         cmdline_fixed_string_t keyword;
1376         cmdline_multi_string_t identifier;
1377 };
1378
1379 static void cmd_operate_attach_port_parsed(void *parsed_result,
1380                                 __rte_unused struct cmdline *cl,
1381                                 __rte_unused void *data)
1382 {
1383         struct cmd_operate_attach_port_result *res = parsed_result;
1384
1385         if (!strcmp(res->keyword, "attach"))
1386                 attach_port(res->identifier);
1387         else
1388                 fprintf(stderr, "Unknown parameter\n");
1389 }
1390
1391 static cmdline_parse_token_string_t cmd_operate_attach_port_port =
1392         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1393                         port, "port");
1394 static cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1395         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1396                         keyword, "attach");
1397 static cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1398         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1399                         identifier, TOKEN_STRING_MULTI);
1400
1401 static cmdline_parse_inst_t cmd_operate_attach_port = {
1402         .f = cmd_operate_attach_port_parsed,
1403         .data = NULL,
1404         .help_str = "port attach <identifier>: "
1405                 "(identifier: pci address or virtual dev name)",
1406         .tokens = {
1407                 (void *)&cmd_operate_attach_port_port,
1408                 (void *)&cmd_operate_attach_port_keyword,
1409                 (void *)&cmd_operate_attach_port_identifier,
1410                 NULL,
1411         },
1412 };
1413
1414 /* *** detach a specified port *** */
1415 struct cmd_operate_detach_port_result {
1416         cmdline_fixed_string_t port;
1417         cmdline_fixed_string_t keyword;
1418         portid_t port_id;
1419 };
1420
1421 static void cmd_operate_detach_port_parsed(void *parsed_result,
1422                                 __rte_unused struct cmdline *cl,
1423                                 __rte_unused void *data)
1424 {
1425         struct cmd_operate_detach_port_result *res = parsed_result;
1426
1427         if (!strcmp(res->keyword, "detach")) {
1428                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1429                 detach_port_device(res->port_id);
1430         } else {
1431                 fprintf(stderr, "Unknown parameter\n");
1432         }
1433 }
1434
1435 static cmdline_parse_token_string_t cmd_operate_detach_port_port =
1436         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1437                         port, "port");
1438 static cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1439         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1440                         keyword, "detach");
1441 static cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1442         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1443                         port_id, RTE_UINT16);
1444
1445 static cmdline_parse_inst_t cmd_operate_detach_port = {
1446         .f = cmd_operate_detach_port_parsed,
1447         .data = NULL,
1448         .help_str = "port detach <port_id>",
1449         .tokens = {
1450                 (void *)&cmd_operate_detach_port_port,
1451                 (void *)&cmd_operate_detach_port_keyword,
1452                 (void *)&cmd_operate_detach_port_port_id,
1453                 NULL,
1454         },
1455 };
1456
1457 /* *** detach device by identifier *** */
1458 struct cmd_operate_detach_device_result {
1459         cmdline_fixed_string_t device;
1460         cmdline_fixed_string_t keyword;
1461         cmdline_fixed_string_t identifier;
1462 };
1463
1464 static void cmd_operate_detach_device_parsed(void *parsed_result,
1465                                 __rte_unused struct cmdline *cl,
1466                                 __rte_unused void *data)
1467 {
1468         struct cmd_operate_detach_device_result *res = parsed_result;
1469
1470         if (!strcmp(res->keyword, "detach"))
1471                 detach_devargs(res->identifier);
1472         else
1473                 fprintf(stderr, "Unknown parameter\n");
1474 }
1475
1476 static cmdline_parse_token_string_t cmd_operate_detach_device_device =
1477         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1478                         device, "device");
1479 static cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1480         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1481                         keyword, "detach");
1482 static cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1483         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1484                         identifier, NULL);
1485
1486 static cmdline_parse_inst_t cmd_operate_detach_device = {
1487         .f = cmd_operate_detach_device_parsed,
1488         .data = NULL,
1489         .help_str = "device detach <identifier>:"
1490                 "(identifier: pci address or virtual dev name)",
1491         .tokens = {
1492                 (void *)&cmd_operate_detach_device_device,
1493                 (void *)&cmd_operate_detach_device_keyword,
1494                 (void *)&cmd_operate_detach_device_identifier,
1495                 NULL,
1496         },
1497 };
1498 /* *** configure speed for all ports *** */
1499 struct cmd_config_speed_all {
1500         cmdline_fixed_string_t port;
1501         cmdline_fixed_string_t keyword;
1502         cmdline_fixed_string_t all;
1503         cmdline_fixed_string_t item1;
1504         cmdline_fixed_string_t item2;
1505         cmdline_fixed_string_t value1;
1506         cmdline_fixed_string_t value2;
1507 };
1508
1509 static int
1510 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1511 {
1512
1513         int duplex;
1514
1515         if (!strcmp(duplexstr, "half")) {
1516                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
1517         } else if (!strcmp(duplexstr, "full")) {
1518                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1519         } else if (!strcmp(duplexstr, "auto")) {
1520                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1521         } else {
1522                 fprintf(stderr, "Unknown duplex parameter\n");
1523                 return -1;
1524         }
1525
1526         if (!strcmp(speedstr, "10")) {
1527                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1528                                 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1529         } else if (!strcmp(speedstr, "100")) {
1530                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1531                                 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1532         } else {
1533                 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1534                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1535                         return -1;
1536                 }
1537                 if (!strcmp(speedstr, "1000")) {
1538                         *speed = RTE_ETH_LINK_SPEED_1G;
1539                 } else if (!strcmp(speedstr, "10000")) {
1540                         *speed = RTE_ETH_LINK_SPEED_10G;
1541                 } else if (!strcmp(speedstr, "25000")) {
1542                         *speed = RTE_ETH_LINK_SPEED_25G;
1543                 } else if (!strcmp(speedstr, "40000")) {
1544                         *speed = RTE_ETH_LINK_SPEED_40G;
1545                 } else if (!strcmp(speedstr, "50000")) {
1546                         *speed = RTE_ETH_LINK_SPEED_50G;
1547                 } else if (!strcmp(speedstr, "100000")) {
1548                         *speed = RTE_ETH_LINK_SPEED_100G;
1549                 } else if (!strcmp(speedstr, "200000")) {
1550                         *speed = RTE_ETH_LINK_SPEED_200G;
1551                 } else if (!strcmp(speedstr, "auto")) {
1552                         *speed = RTE_ETH_LINK_SPEED_AUTONEG;
1553                 } else {
1554                         fprintf(stderr, "Unknown speed parameter\n");
1555                         return -1;
1556                 }
1557         }
1558
1559         if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1560                 *speed |= RTE_ETH_LINK_SPEED_FIXED;
1561
1562         return 0;
1563 }
1564
1565 static void
1566 cmd_config_speed_all_parsed(void *parsed_result,
1567                         __rte_unused struct cmdline *cl,
1568                         __rte_unused void *data)
1569 {
1570         struct cmd_config_speed_all *res = parsed_result;
1571         uint32_t link_speed;
1572         portid_t pid;
1573
1574         if (!all_ports_stopped()) {
1575                 fprintf(stderr, "Please stop all ports first\n");
1576                 return;
1577         }
1578
1579         if (parse_and_check_speed_duplex(res->value1, res->value2,
1580                         &link_speed) < 0)
1581                 return;
1582
1583         RTE_ETH_FOREACH_DEV(pid) {
1584                 ports[pid].dev_conf.link_speeds = link_speed;
1585         }
1586
1587         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1588 }
1589
1590 static cmdline_parse_token_string_t cmd_config_speed_all_port =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1592 static cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1593         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1594                                                         "config");
1595 static cmdline_parse_token_string_t cmd_config_speed_all_all =
1596         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1597 static cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1599 static cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1600         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1601                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1602 static cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1603         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1604 static cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1605         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1606                                                 "half#full#auto");
1607
1608 static cmdline_parse_inst_t cmd_config_speed_all = {
1609         .f = cmd_config_speed_all_parsed,
1610         .data = NULL,
1611         .help_str = "port config all speed "
1612                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1613                                                         "half|full|auto",
1614         .tokens = {
1615                 (void *)&cmd_config_speed_all_port,
1616                 (void *)&cmd_config_speed_all_keyword,
1617                 (void *)&cmd_config_speed_all_all,
1618                 (void *)&cmd_config_speed_all_item1,
1619                 (void *)&cmd_config_speed_all_value1,
1620                 (void *)&cmd_config_speed_all_item2,
1621                 (void *)&cmd_config_speed_all_value2,
1622                 NULL,
1623         },
1624 };
1625
1626 /* *** configure speed for specific port *** */
1627 struct cmd_config_speed_specific {
1628         cmdline_fixed_string_t port;
1629         cmdline_fixed_string_t keyword;
1630         portid_t id;
1631         cmdline_fixed_string_t item1;
1632         cmdline_fixed_string_t item2;
1633         cmdline_fixed_string_t value1;
1634         cmdline_fixed_string_t value2;
1635 };
1636
1637 static void
1638 cmd_config_speed_specific_parsed(void *parsed_result,
1639                                 __rte_unused struct cmdline *cl,
1640                                 __rte_unused void *data)
1641 {
1642         struct cmd_config_speed_specific *res = parsed_result;
1643         uint32_t link_speed;
1644
1645         if (port_id_is_invalid(res->id, ENABLED_WARN))
1646                 return;
1647
1648         if (!port_is_stopped(res->id)) {
1649                 fprintf(stderr, "Please stop port %d first\n", res->id);
1650                 return;
1651         }
1652
1653         if (parse_and_check_speed_duplex(res->value1, res->value2,
1654                         &link_speed) < 0)
1655                 return;
1656
1657         ports[res->id].dev_conf.link_speeds = link_speed;
1658
1659         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1660 }
1661
1662
1663 static cmdline_parse_token_string_t cmd_config_speed_specific_port =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1665                                                                 "port");
1666 static cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1668                                                                 "config");
1669 static cmdline_parse_token_num_t cmd_config_speed_specific_id =
1670         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1671 static cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1673                                                                 "speed");
1674 static cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1675         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1676                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1677 static cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1679                                                                 "duplex");
1680 static cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1682                                                         "half#full#auto");
1683
1684 static cmdline_parse_inst_t cmd_config_speed_specific = {
1685         .f = cmd_config_speed_specific_parsed,
1686         .data = NULL,
1687         .help_str = "port config <port_id> speed "
1688                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1689                                                         "half|full|auto",
1690         .tokens = {
1691                 (void *)&cmd_config_speed_specific_port,
1692                 (void *)&cmd_config_speed_specific_keyword,
1693                 (void *)&cmd_config_speed_specific_id,
1694                 (void *)&cmd_config_speed_specific_item1,
1695                 (void *)&cmd_config_speed_specific_value1,
1696                 (void *)&cmd_config_speed_specific_item2,
1697                 (void *)&cmd_config_speed_specific_value2,
1698                 NULL,
1699         },
1700 };
1701
1702 /* *** configure loopback for all ports *** */
1703 struct cmd_config_loopback_all {
1704         cmdline_fixed_string_t port;
1705         cmdline_fixed_string_t keyword;
1706         cmdline_fixed_string_t all;
1707         cmdline_fixed_string_t item;
1708         uint32_t mode;
1709 };
1710
1711 static void
1712 cmd_config_loopback_all_parsed(void *parsed_result,
1713                         __rte_unused struct cmdline *cl,
1714                         __rte_unused void *data)
1715 {
1716         struct cmd_config_loopback_all *res = parsed_result;
1717         portid_t pid;
1718
1719         if (!all_ports_stopped()) {
1720                 fprintf(stderr, "Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         RTE_ETH_FOREACH_DEV(pid) {
1725                 ports[pid].dev_conf.lpbk_mode = res->mode;
1726         }
1727
1728         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1729 }
1730
1731 static cmdline_parse_token_string_t cmd_config_loopback_all_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1733 static cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1735                                                         "config");
1736 static cmdline_parse_token_string_t cmd_config_loopback_all_all =
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1738 static cmdline_parse_token_string_t cmd_config_loopback_all_item =
1739         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1740                                                         "loopback");
1741 static cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1742         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1743
1744 static cmdline_parse_inst_t cmd_config_loopback_all = {
1745         .f = cmd_config_loopback_all_parsed,
1746         .data = NULL,
1747         .help_str = "port config all loopback <mode>",
1748         .tokens = {
1749                 (void *)&cmd_config_loopback_all_port,
1750                 (void *)&cmd_config_loopback_all_keyword,
1751                 (void *)&cmd_config_loopback_all_all,
1752                 (void *)&cmd_config_loopback_all_item,
1753                 (void *)&cmd_config_loopback_all_mode,
1754                 NULL,
1755         },
1756 };
1757
1758 /* *** configure loopback for specific port *** */
1759 struct cmd_config_loopback_specific {
1760         cmdline_fixed_string_t port;
1761         cmdline_fixed_string_t keyword;
1762         uint16_t port_id;
1763         cmdline_fixed_string_t item;
1764         uint32_t mode;
1765 };
1766
1767 static void
1768 cmd_config_loopback_specific_parsed(void *parsed_result,
1769                                 __rte_unused struct cmdline *cl,
1770                                 __rte_unused void *data)
1771 {
1772         struct cmd_config_loopback_specific *res = parsed_result;
1773
1774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1775                 return;
1776
1777         if (!port_is_stopped(res->port_id)) {
1778                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1779                 return;
1780         }
1781
1782         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1783
1784         cmd_reconfig_device_queue(res->port_id, 1, 1);
1785 }
1786
1787
1788 static cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1790                                                                 "port");
1791 static cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1793                                                                 "config");
1794 static cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1795         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1796                                                                 RTE_UINT16);
1797 static cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1798         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1799                                                                 "loopback");
1800 static cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1801         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1802                               RTE_UINT32);
1803
1804 static cmdline_parse_inst_t cmd_config_loopback_specific = {
1805         .f = cmd_config_loopback_specific_parsed,
1806         .data = NULL,
1807         .help_str = "port config <port_id> loopback <mode>",
1808         .tokens = {
1809                 (void *)&cmd_config_loopback_specific_port,
1810                 (void *)&cmd_config_loopback_specific_keyword,
1811                 (void *)&cmd_config_loopback_specific_id,
1812                 (void *)&cmd_config_loopback_specific_item,
1813                 (void *)&cmd_config_loopback_specific_mode,
1814                 NULL,
1815         },
1816 };
1817
1818 /* *** configure txq/rxq, txd/rxd *** */
1819 struct cmd_config_rx_tx {
1820         cmdline_fixed_string_t port;
1821         cmdline_fixed_string_t keyword;
1822         cmdline_fixed_string_t all;
1823         cmdline_fixed_string_t name;
1824         uint16_t value;
1825 };
1826
1827 static void
1828 cmd_config_rx_tx_parsed(void *parsed_result,
1829                         __rte_unused struct cmdline *cl,
1830                         __rte_unused void *data)
1831 {
1832         struct cmd_config_rx_tx *res = parsed_result;
1833
1834         if (!all_ports_stopped()) {
1835                 fprintf(stderr, "Please stop all ports first\n");
1836                 return;
1837         }
1838         if (!strcmp(res->name, "rxq")) {
1839                 if (!res->value && !nb_txq) {
1840                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1841                         return;
1842                 }
1843                 if (check_nb_rxq(res->value) != 0)
1844                         return;
1845                 nb_rxq = res->value;
1846         }
1847         else if (!strcmp(res->name, "txq")) {
1848                 if (!res->value && !nb_rxq) {
1849                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1850                         return;
1851                 }
1852                 if (check_nb_txq(res->value) != 0)
1853                         return;
1854                 nb_txq = res->value;
1855         }
1856         else if (!strcmp(res->name, "rxd")) {
1857                 if (check_nb_rxd(res->value) != 0)
1858                         return;
1859                 nb_rxd = res->value;
1860         } else if (!strcmp(res->name, "txd")) {
1861                 if (check_nb_txd(res->value) != 0)
1862                         return;
1863
1864                 nb_txd = res->value;
1865         } else {
1866                 fprintf(stderr, "Unknown parameter\n");
1867                 return;
1868         }
1869
1870         fwd_config_setup();
1871
1872         init_port_config();
1873
1874         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1875 }
1876
1877 static cmdline_parse_token_string_t cmd_config_rx_tx_port =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1879 static cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1881 static cmdline_parse_token_string_t cmd_config_rx_tx_all =
1882         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1883 static cmdline_parse_token_string_t cmd_config_rx_tx_name =
1884         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1885                                                 "rxq#txq#rxd#txd");
1886 static cmdline_parse_token_num_t cmd_config_rx_tx_value =
1887         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1888
1889 static cmdline_parse_inst_t cmd_config_rx_tx = {
1890         .f = cmd_config_rx_tx_parsed,
1891         .data = NULL,
1892         .help_str = "port config all rxq|txq|rxd|txd <value>",
1893         .tokens = {
1894                 (void *)&cmd_config_rx_tx_port,
1895                 (void *)&cmd_config_rx_tx_keyword,
1896                 (void *)&cmd_config_rx_tx_all,
1897                 (void *)&cmd_config_rx_tx_name,
1898                 (void *)&cmd_config_rx_tx_value,
1899                 NULL,
1900         },
1901 };
1902
1903 /* *** config max packet length *** */
1904 struct cmd_config_max_pkt_len_result {
1905         cmdline_fixed_string_t port;
1906         cmdline_fixed_string_t keyword;
1907         cmdline_fixed_string_t all;
1908         cmdline_fixed_string_t name;
1909         uint32_t value;
1910 };
1911
1912 static void
1913 cmd_config_max_pkt_len_parsed(void *parsed_result,
1914                                 __rte_unused struct cmdline *cl,
1915                                 __rte_unused void *data)
1916 {
1917         struct cmd_config_max_pkt_len_result *res = parsed_result;
1918         portid_t port_id;
1919         int ret;
1920
1921         if (strcmp(res->name, "max-pkt-len") != 0) {
1922                 printf("Unknown parameter\n");
1923                 return;
1924         }
1925
1926         if (!all_ports_stopped()) {
1927                 fprintf(stderr, "Please stop all ports first\n");
1928                 return;
1929         }
1930
1931         RTE_ETH_FOREACH_DEV(port_id) {
1932                 struct rte_port *port = &ports[port_id];
1933
1934                 if (res->value < RTE_ETHER_MIN_LEN) {
1935                         fprintf(stderr,
1936                                 "max-pkt-len can not be less than %d\n",
1937                                 RTE_ETHER_MIN_LEN);
1938                         return;
1939                 }
1940
1941                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1942                 if (ret != 0) {
1943                         fprintf(stderr,
1944                                 "rte_eth_dev_info_get() failed for port %u\n",
1945                                 port_id);
1946                         return;
1947                 }
1948
1949                 update_mtu_from_frame_size(port_id, res->value);
1950         }
1951
1952         init_port_config();
1953
1954         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1955 }
1956
1957 static cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1959                                                                 "port");
1960 static cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1962                                                                 "config");
1963 static cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1965                                                                 "all");
1966 static cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1968                                                                 "max-pkt-len");
1969 static cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1970         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1971                                                                 RTE_UINT32);
1972
1973 static cmdline_parse_inst_t cmd_config_max_pkt_len = {
1974         .f = cmd_config_max_pkt_len_parsed,
1975         .data = NULL,
1976         .help_str = "port config all max-pkt-len <value>",
1977         .tokens = {
1978                 (void *)&cmd_config_max_pkt_len_port,
1979                 (void *)&cmd_config_max_pkt_len_keyword,
1980                 (void *)&cmd_config_max_pkt_len_all,
1981                 (void *)&cmd_config_max_pkt_len_name,
1982                 (void *)&cmd_config_max_pkt_len_value,
1983                 NULL,
1984         },
1985 };
1986
1987 /* *** config max LRO aggregated packet size *** */
1988 struct cmd_config_max_lro_pkt_size_result {
1989         cmdline_fixed_string_t port;
1990         cmdline_fixed_string_t keyword;
1991         cmdline_fixed_string_t all;
1992         cmdline_fixed_string_t name;
1993         uint32_t value;
1994 };
1995
1996 static void
1997 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1998                                 __rte_unused struct cmdline *cl,
1999                                 __rte_unused void *data)
2000 {
2001         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2002         portid_t pid;
2003
2004         if (!all_ports_stopped()) {
2005                 fprintf(stderr, "Please stop all ports first\n");
2006                 return;
2007         }
2008
2009         RTE_ETH_FOREACH_DEV(pid) {
2010                 struct rte_port *port = &ports[pid];
2011
2012                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2013                         if (res->value ==
2014                                         port->dev_conf.rxmode.max_lro_pkt_size)
2015                                 return;
2016
2017                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2018                 } else {
2019                         fprintf(stderr, "Unknown parameter\n");
2020                         return;
2021                 }
2022         }
2023
2024         init_port_config();
2025
2026         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2027 }
2028
2029 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2031                                  port, "port");
2032 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2034                                  keyword, "config");
2035 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2037                                  all, "all");
2038 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2039         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2040                                  name, "max-lro-pkt-size");
2041 static cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2042         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2043                               value, RTE_UINT32);
2044
2045 static cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2046         .f = cmd_config_max_lro_pkt_size_parsed,
2047         .data = NULL,
2048         .help_str = "port config all max-lro-pkt-size <value>",
2049         .tokens = {
2050                 (void *)&cmd_config_max_lro_pkt_size_port,
2051                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2052                 (void *)&cmd_config_max_lro_pkt_size_all,
2053                 (void *)&cmd_config_max_lro_pkt_size_name,
2054                 (void *)&cmd_config_max_lro_pkt_size_value,
2055                 NULL,
2056         },
2057 };
2058
2059 /* *** configure port MTU *** */
2060 struct cmd_config_mtu_result {
2061         cmdline_fixed_string_t port;
2062         cmdline_fixed_string_t keyword;
2063         cmdline_fixed_string_t mtu;
2064         portid_t port_id;
2065         uint16_t value;
2066 };
2067
2068 static void
2069 cmd_config_mtu_parsed(void *parsed_result,
2070                       __rte_unused struct cmdline *cl,
2071                       __rte_unused void *data)
2072 {
2073         struct cmd_config_mtu_result *res = parsed_result;
2074
2075         port_mtu_set(res->port_id, res->value);
2076 }
2077
2078 static cmdline_parse_token_string_t cmd_config_mtu_port =
2079         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2080                                  "port");
2081 static cmdline_parse_token_string_t cmd_config_mtu_keyword =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2083                                  "config");
2084 static cmdline_parse_token_string_t cmd_config_mtu_mtu =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2086                                  "mtu");
2087 static cmdline_parse_token_num_t cmd_config_mtu_port_id =
2088         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2089                                  RTE_UINT16);
2090 static cmdline_parse_token_num_t cmd_config_mtu_value =
2091         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2092                                  RTE_UINT16);
2093
2094 static cmdline_parse_inst_t cmd_config_mtu = {
2095         .f = cmd_config_mtu_parsed,
2096         .data = NULL,
2097         .help_str = "port config mtu <port_id> <value>",
2098         .tokens = {
2099                 (void *)&cmd_config_mtu_port,
2100                 (void *)&cmd_config_mtu_keyword,
2101                 (void *)&cmd_config_mtu_mtu,
2102                 (void *)&cmd_config_mtu_port_id,
2103                 (void *)&cmd_config_mtu_value,
2104                 NULL,
2105         },
2106 };
2107
2108 /* *** configure rx mode *** */
2109 struct cmd_config_rx_mode_flag {
2110         cmdline_fixed_string_t port;
2111         cmdline_fixed_string_t keyword;
2112         cmdline_fixed_string_t all;
2113         cmdline_fixed_string_t name;
2114         cmdline_fixed_string_t value;
2115 };
2116
2117 static void
2118 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2119                                 __rte_unused struct cmdline *cl,
2120                                 __rte_unused void *data)
2121 {
2122         struct cmd_config_rx_mode_flag *res = parsed_result;
2123
2124         if (!all_ports_stopped()) {
2125                 fprintf(stderr, "Please stop all ports first\n");
2126                 return;
2127         }
2128
2129         if (!strcmp(res->name, "drop-en")) {
2130                 if (!strcmp(res->value, "on"))
2131                         rx_drop_en = 1;
2132                 else if (!strcmp(res->value, "off"))
2133                         rx_drop_en = 0;
2134                 else {
2135                         fprintf(stderr, "Unknown parameter\n");
2136                         return;
2137                 }
2138         } else {
2139                 fprintf(stderr, "Unknown parameter\n");
2140                 return;
2141         }
2142
2143         init_port_config();
2144
2145         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2146 }
2147
2148 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2150 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2151         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2152                                                                 "config");
2153 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2155 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2157                                         "drop-en");
2158 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2160                                                         "on#off");
2161
2162 static cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2163         .f = cmd_config_rx_mode_flag_parsed,
2164         .data = NULL,
2165         .help_str = "port config all drop-en on|off",
2166         .tokens = {
2167                 (void *)&cmd_config_rx_mode_flag_port,
2168                 (void *)&cmd_config_rx_mode_flag_keyword,
2169                 (void *)&cmd_config_rx_mode_flag_all,
2170                 (void *)&cmd_config_rx_mode_flag_name,
2171                 (void *)&cmd_config_rx_mode_flag_value,
2172                 NULL,
2173         },
2174 };
2175
2176 /* *** configure rss *** */
2177 struct cmd_config_rss {
2178         cmdline_fixed_string_t port;
2179         cmdline_fixed_string_t keyword;
2180         cmdline_fixed_string_t all;
2181         cmdline_fixed_string_t name;
2182         cmdline_fixed_string_t value;
2183 };
2184
2185 static void
2186 cmd_config_rss_parsed(void *parsed_result,
2187                         __rte_unused struct cmdline *cl,
2188                         __rte_unused void *data)
2189 {
2190         struct cmd_config_rss *res = parsed_result;
2191         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2192         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2193         int use_default = 0;
2194         int all_updated = 1;
2195         int diag;
2196         uint16_t i;
2197         int ret;
2198
2199         if (!strcmp(res->value, "all"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2201                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2202                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2203                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2204                         RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
2205         else if (!strcmp(res->value, "eth"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2207         else if (!strcmp(res->value, "vlan"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2209         else if (!strcmp(res->value, "ip"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2211         else if (!strcmp(res->value, "udp"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2213         else if (!strcmp(res->value, "tcp"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2215         else if (!strcmp(res->value, "sctp"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2217         else if (!strcmp(res->value, "ether"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2219         else if (!strcmp(res->value, "port"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2221         else if (!strcmp(res->value, "vxlan"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2223         else if (!strcmp(res->value, "geneve"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2225         else if (!strcmp(res->value, "nvgre"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2227         else if (!strcmp(res->value, "l3-pre32"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2229         else if (!strcmp(res->value, "l3-pre40"))
2230                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2231         else if (!strcmp(res->value, "l3-pre48"))
2232                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2233         else if (!strcmp(res->value, "l3-pre56"))
2234                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2235         else if (!strcmp(res->value, "l3-pre64"))
2236                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2237         else if (!strcmp(res->value, "l3-pre96"))
2238                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2239         else if (!strcmp(res->value, "l3-src-only"))
2240                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2241         else if (!strcmp(res->value, "l3-dst-only"))
2242                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2243         else if (!strcmp(res->value, "l4-src-only"))
2244                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2245         else if (!strcmp(res->value, "l4-dst-only"))
2246                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2247         else if (!strcmp(res->value, "l2-src-only"))
2248                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2249         else if (!strcmp(res->value, "l2-dst-only"))
2250                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2251         else if (!strcmp(res->value, "l2tpv3"))
2252                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2253         else if (!strcmp(res->value, "esp"))
2254                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2255         else if (!strcmp(res->value, "ah"))
2256                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2257         else if (!strcmp(res->value, "pfcp"))
2258                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2259         else if (!strcmp(res->value, "pppoe"))
2260                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2261         else if (!strcmp(res->value, "gtpu"))
2262                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2263         else if (!strcmp(res->value, "ecpri"))
2264                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2265         else if (!strcmp(res->value, "mpls"))
2266                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2267         else if (!strcmp(res->value, "ipv4-chksum"))
2268                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2269         else if (!strcmp(res->value, "l2tpv2"))
2270                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
2271         else if (!strcmp(res->value, "none"))
2272                 rss_conf.rss_hf = 0;
2273         else if (!strcmp(res->value, "level-default")) {
2274                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2275                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2276         } else if (!strcmp(res->value, "level-outer")) {
2277                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2278                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2279         } else if (!strcmp(res->value, "level-inner")) {
2280                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2281                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2282         } else if (!strcmp(res->value, "default"))
2283                 use_default = 1;
2284         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2285                                                 atoi(res->value) < 64)
2286                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2287         else {
2288                 fprintf(stderr, "Unknown parameter\n");
2289                 return;
2290         }
2291         rss_conf.rss_key = NULL;
2292         /* Update global configuration for RSS types. */
2293         RTE_ETH_FOREACH_DEV(i) {
2294                 struct rte_eth_rss_conf local_rss_conf;
2295
2296                 ret = eth_dev_info_get_print_err(i, &dev_info);
2297                 if (ret != 0)
2298                         return;
2299
2300                 if (use_default)
2301                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2302
2303                 local_rss_conf = rss_conf;
2304                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2305                         dev_info.flow_type_rss_offloads;
2306                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2307                         printf("Port %u modified RSS hash function based on hardware support,"
2308                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2309                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2310                 }
2311                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2312                 if (diag < 0) {
2313                         all_updated = 0;
2314                         fprintf(stderr,
2315                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2316                                 i, -diag, strerror(-diag));
2317                 }
2318         }
2319         if (all_updated && !use_default) {
2320                 rss_hf = rss_conf.rss_hf;
2321                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2322         }
2323 }
2324
2325 static cmdline_parse_token_string_t cmd_config_rss_port =
2326         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2327 static cmdline_parse_token_string_t cmd_config_rss_keyword =
2328         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2329 static cmdline_parse_token_string_t cmd_config_rss_all =
2330         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2331 static cmdline_parse_token_string_t cmd_config_rss_name =
2332         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2333 static cmdline_parse_token_string_t cmd_config_rss_value =
2334         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2335
2336 static cmdline_parse_inst_t cmd_config_rss = {
2337         .f = cmd_config_rss_parsed,
2338         .data = NULL,
2339         .help_str = "port config all rss "
2340                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2341                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
2342                 "none|level-default|level-outer|level-inner|<flowtype_id>",
2343         .tokens = {
2344                 (void *)&cmd_config_rss_port,
2345                 (void *)&cmd_config_rss_keyword,
2346                 (void *)&cmd_config_rss_all,
2347                 (void *)&cmd_config_rss_name,
2348                 (void *)&cmd_config_rss_value,
2349                 NULL,
2350         },
2351 };
2352
2353 /* *** configure rss hash key *** */
2354 struct cmd_config_rss_hash_key {
2355         cmdline_fixed_string_t port;
2356         cmdline_fixed_string_t config;
2357         portid_t port_id;
2358         cmdline_fixed_string_t rss_hash_key;
2359         cmdline_fixed_string_t rss_type;
2360         cmdline_fixed_string_t key;
2361 };
2362
2363 static uint8_t
2364 hexa_digit_to_value(char hexa_digit)
2365 {
2366         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2367                 return (uint8_t) (hexa_digit - '0');
2368         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2369                 return (uint8_t) ((hexa_digit - 'a') + 10);
2370         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2371                 return (uint8_t) ((hexa_digit - 'A') + 10);
2372         /* Invalid hexa digit */
2373         return 0xFF;
2374 }
2375
2376 static uint8_t
2377 parse_and_check_key_hexa_digit(char *key, int idx)
2378 {
2379         uint8_t hexa_v;
2380
2381         hexa_v = hexa_digit_to_value(key[idx]);
2382         if (hexa_v == 0xFF)
2383                 fprintf(stderr,
2384                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2385                         key[idx], idx);
2386         return hexa_v;
2387 }
2388
2389 static void
2390 cmd_config_rss_hash_key_parsed(void *parsed_result,
2391                                __rte_unused struct cmdline *cl,
2392                                __rte_unused void *data)
2393 {
2394         struct cmd_config_rss_hash_key *res = parsed_result;
2395         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2396         uint8_t xdgt0;
2397         uint8_t xdgt1;
2398         int i;
2399         struct rte_eth_dev_info dev_info;
2400         uint8_t hash_key_size;
2401         uint32_t key_len;
2402         int ret;
2403
2404         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2405         if (ret != 0)
2406                 return;
2407
2408         if (dev_info.hash_key_size > 0 &&
2409                         dev_info.hash_key_size <= sizeof(hash_key))
2410                 hash_key_size = dev_info.hash_key_size;
2411         else {
2412                 fprintf(stderr,
2413                         "dev_info did not provide a valid hash key size\n");
2414                 return;
2415         }
2416         /* Check the length of the RSS hash key */
2417         key_len = strlen(res->key);
2418         if (key_len != (hash_key_size * 2)) {
2419                 fprintf(stderr,
2420                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2421                         (int)key_len, hash_key_size * 2);
2422                 return;
2423         }
2424         /* Translate RSS hash key into binary representation */
2425         for (i = 0; i < hash_key_size; i++) {
2426                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2427                 if (xdgt0 == 0xFF)
2428                         return;
2429                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2430                 if (xdgt1 == 0xFF)
2431                         return;
2432                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2433         }
2434         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2435                         hash_key_size);
2436 }
2437
2438 static cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2440 static cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2442                                  "config");
2443 static cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2444         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2445                                  RTE_UINT16);
2446 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2447         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2448                                  rss_hash_key, "rss-hash-key");
2449 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2450         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2451                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2452                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2453                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2454                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2455                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2456                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2457                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2458 static cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2459         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2460
2461 static cmdline_parse_inst_t cmd_config_rss_hash_key = {
2462         .f = cmd_config_rss_hash_key_parsed,
2463         .data = NULL,
2464         .help_str = "port config <port_id> rss-hash-key "
2465                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2466                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2467                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2468                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2469                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2470                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2471                 "<string of hex digits (variable length, NIC dependent)>",
2472         .tokens = {
2473                 (void *)&cmd_config_rss_hash_key_port,
2474                 (void *)&cmd_config_rss_hash_key_config,
2475                 (void *)&cmd_config_rss_hash_key_port_id,
2476                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2477                 (void *)&cmd_config_rss_hash_key_rss_type,
2478                 (void *)&cmd_config_rss_hash_key_value,
2479                 NULL,
2480         },
2481 };
2482
2483 /* *** cleanup txq mbufs *** */
2484 struct cmd_cleanup_txq_mbufs_result {
2485         cmdline_fixed_string_t port;
2486         cmdline_fixed_string_t keyword;
2487         cmdline_fixed_string_t name;
2488         uint16_t port_id;
2489         uint16_t queue_id;
2490         uint32_t free_cnt;
2491 };
2492
2493 static void
2494 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2495                              __rte_unused struct cmdline *cl,
2496                              __rte_unused void *data)
2497 {
2498         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2499         uint16_t port_id = res->port_id;
2500         uint16_t queue_id = res->queue_id;
2501         uint32_t free_cnt = res->free_cnt;
2502         struct rte_eth_txq_info qinfo;
2503         int ret;
2504
2505         if (test_done == 0) {
2506                 fprintf(stderr, "Please stop forwarding first\n");
2507                 return;
2508         }
2509
2510         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2511                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2512                         port_id, queue_id);
2513                 return;
2514         }
2515
2516         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2517                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2518                 return;
2519         }
2520
2521         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2522         if (ret < 0) {
2523                 fprintf(stderr,
2524                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2525                         port_id, queue_id, strerror(-ret), ret);
2526                 return;
2527         }
2528
2529         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2530                port_id, queue_id, ret);
2531 }
2532
2533 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2534         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2535                                  "port");
2536 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2537         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2538                                  "cleanup");
2539 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2540         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2541                               RTE_UINT16);
2542 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2543         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2544                                  "txq");
2545 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2546         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2547                               RTE_UINT16);
2548 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2549         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2550                               RTE_UINT32);
2551
2552 static cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2553         .f = cmd_cleanup_txq_mbufs_parsed,
2554         .data = NULL,
2555         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2556         .tokens = {
2557                 (void *)&cmd_cleanup_txq_mbufs_port,
2558                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2559                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2560                 (void *)&cmd_cleanup_txq_mbufs_txq,
2561                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2562                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2563                 NULL,
2564         },
2565 };
2566
2567 /* *** configure port rxq/txq ring size *** */
2568 struct cmd_config_rxtx_ring_size {
2569         cmdline_fixed_string_t port;
2570         cmdline_fixed_string_t config;
2571         portid_t portid;
2572         cmdline_fixed_string_t rxtxq;
2573         uint16_t qid;
2574         cmdline_fixed_string_t rsize;
2575         uint16_t size;
2576 };
2577
2578 static void
2579 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2580                                  __rte_unused struct cmdline *cl,
2581                                  __rte_unused void *data)
2582 {
2583         struct cmd_config_rxtx_ring_size *res = parsed_result;
2584         struct rte_port *port;
2585         uint8_t isrx;
2586
2587         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2588                 return;
2589
2590         if (res->portid == (portid_t)RTE_PORT_ALL) {
2591                 fprintf(stderr, "Invalid port id\n");
2592                 return;
2593         }
2594
2595         port = &ports[res->portid];
2596
2597         if (!strcmp(res->rxtxq, "rxq"))
2598                 isrx = 1;
2599         else if (!strcmp(res->rxtxq, "txq"))
2600                 isrx = 0;
2601         else {
2602                 fprintf(stderr, "Unknown parameter\n");
2603                 return;
2604         }
2605
2606         if (isrx && rx_queue_id_is_invalid(res->qid))
2607                 return;
2608         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2609                 return;
2610
2611         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2612                 fprintf(stderr,
2613                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2614                         rx_free_thresh);
2615                 return;
2616         }
2617
2618         if (isrx)
2619                 port->nb_rx_desc[res->qid] = res->size;
2620         else
2621                 port->nb_tx_desc[res->qid] = res->size;
2622
2623         cmd_reconfig_device_queue(res->portid, 0, 1);
2624 }
2625
2626 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2627         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2628                                  port, "port");
2629 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2630         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2631                                  config, "config");
2632 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2633         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2634                                  portid, RTE_UINT16);
2635 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2636         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2637                                  rxtxq, "rxq#txq");
2638 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2639         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2640                               qid, RTE_UINT16);
2641 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2642         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2643                                  rsize, "ring_size");
2644 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2645         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2646                               size, RTE_UINT16);
2647
2648 static cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2649         .f = cmd_config_rxtx_ring_size_parsed,
2650         .data = NULL,
2651         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2652         .tokens = {
2653                 (void *)&cmd_config_rxtx_ring_size_port,
2654                 (void *)&cmd_config_rxtx_ring_size_config,
2655                 (void *)&cmd_config_rxtx_ring_size_portid,
2656                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2657                 (void *)&cmd_config_rxtx_ring_size_qid,
2658                 (void *)&cmd_config_rxtx_ring_size_rsize,
2659                 (void *)&cmd_config_rxtx_ring_size_size,
2660                 NULL,
2661         },
2662 };
2663
2664 /* *** configure port rxq/txq start/stop *** */
2665 struct cmd_config_rxtx_queue {
2666         cmdline_fixed_string_t port;
2667         portid_t portid;
2668         cmdline_fixed_string_t rxtxq;
2669         uint16_t qid;
2670         cmdline_fixed_string_t opname;
2671 };
2672
2673 static void
2674 cmd_config_rxtx_queue_parsed(void *parsed_result,
2675                         __rte_unused struct cmdline *cl,
2676                         __rte_unused void *data)
2677 {
2678         struct cmd_config_rxtx_queue *res = parsed_result;
2679         struct rte_port *port;
2680         uint8_t isrx;
2681         uint8_t isstart;
2682         uint8_t *state;
2683         int ret = 0;
2684
2685         if (test_done == 0) {
2686                 fprintf(stderr, "Please stop forwarding first\n");
2687                 return;
2688         }
2689
2690         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2691                 return;
2692
2693         if (port_is_started(res->portid) != 1) {
2694                 fprintf(stderr, "Please start port %u first\n", res->portid);
2695                 return;
2696         }
2697
2698         if (!strcmp(res->rxtxq, "rxq"))
2699                 isrx = 1;
2700         else if (!strcmp(res->rxtxq, "txq"))
2701                 isrx = 0;
2702         else {
2703                 fprintf(stderr, "Unknown parameter\n");
2704                 return;
2705         }
2706
2707         if (isrx && rx_queue_id_is_invalid(res->qid))
2708                 return;
2709         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2710                 return;
2711
2712         if (!strcmp(res->opname, "start"))
2713                 isstart = 1;
2714         else if (!strcmp(res->opname, "stop"))
2715                 isstart = 0;
2716         else {
2717                 fprintf(stderr, "Unknown parameter\n");
2718                 return;
2719         }
2720
2721         if (isstart && isrx)
2722                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2723         else if (!isstart && isrx)
2724                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2725         else if (isstart && !isrx)
2726                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2727         else
2728                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2729
2730         if (ret == -ENOTSUP) {
2731                 fprintf(stderr, "Function not supported in PMD\n");
2732                 return;
2733         }
2734
2735         port = &ports[res->portid];
2736         state = isrx ? &port->rxq[res->qid].state : &port->txq[res->qid].state;
2737         *state = isstart ? RTE_ETH_QUEUE_STATE_STARTED :
2738                            RTE_ETH_QUEUE_STATE_STOPPED;
2739 }
2740
2741 static cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2742         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2743 static cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2744         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2745 static cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2746         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2747 static cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2748         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2749 static cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2750         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2751                                                 "start#stop");
2752
2753 static cmdline_parse_inst_t cmd_config_rxtx_queue = {
2754         .f = cmd_config_rxtx_queue_parsed,
2755         .data = NULL,
2756         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2757         .tokens = {
2758                 (void *)&cmd_config_rxtx_queue_port,
2759                 (void *)&cmd_config_rxtx_queue_portid,
2760                 (void *)&cmd_config_rxtx_queue_rxtxq,
2761                 (void *)&cmd_config_rxtx_queue_qid,
2762                 (void *)&cmd_config_rxtx_queue_opname,
2763                 NULL,
2764         },
2765 };
2766
2767 /* *** configure port rxq/txq deferred start on/off *** */
2768 struct cmd_config_deferred_start_rxtx_queue {
2769         cmdline_fixed_string_t port;
2770         portid_t port_id;
2771         cmdline_fixed_string_t rxtxq;
2772         uint16_t qid;
2773         cmdline_fixed_string_t opname;
2774         cmdline_fixed_string_t state;
2775 };
2776
2777 static void
2778 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2779                         __rte_unused struct cmdline *cl,
2780                         __rte_unused void *data)
2781 {
2782         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2783         struct rte_port *port;
2784         uint8_t isrx;
2785         uint8_t ison;
2786         uint8_t needreconfig = 0;
2787
2788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2789                 return;
2790
2791         if (port_is_started(res->port_id) != 0) {
2792                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2793                 return;
2794         }
2795
2796         port = &ports[res->port_id];
2797
2798         isrx = !strcmp(res->rxtxq, "rxq");
2799
2800         if (isrx && rx_queue_id_is_invalid(res->qid))
2801                 return;
2802         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2803                 return;
2804
2805         ison = !strcmp(res->state, "on");
2806
2807         if (isrx && port->rxq[res->qid].conf.rx_deferred_start != ison) {
2808                 port->rxq[res->qid].conf.rx_deferred_start = ison;
2809                 needreconfig = 1;
2810         } else if (!isrx && port->txq[res->qid].conf.tx_deferred_start != ison) {
2811                 port->txq[res->qid].conf.tx_deferred_start = ison;
2812                 needreconfig = 1;
2813         }
2814
2815         if (needreconfig)
2816                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2817 }
2818
2819 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2820         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2821                                                 port, "port");
2822 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2823         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2824                                                 port_id, RTE_UINT16);
2825 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2826         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2827                                                 rxtxq, "rxq#txq");
2828 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2829         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2830                                                 qid, RTE_UINT16);
2831 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2832         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2833                                                 opname, "deferred_start");
2834 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2835         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2836                                                 state, "on#off");
2837
2838 static cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2839         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2840         .data = NULL,
2841         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2842         .tokens = {
2843                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2844                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2845                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2846                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2847                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2848                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2849                 NULL,
2850         },
2851 };
2852
2853 /* *** configure port rxq/txq setup *** */
2854 struct cmd_setup_rxtx_queue {
2855         cmdline_fixed_string_t port;
2856         portid_t portid;
2857         cmdline_fixed_string_t rxtxq;
2858         uint16_t qid;
2859         cmdline_fixed_string_t setup;
2860 };
2861
2862 /* Common CLI fields for queue setup */
2863 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2864         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2865 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2866         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2867 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2868         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2869 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2870         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2871 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2872         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2873
2874 static void
2875 cmd_setup_rxtx_queue_parsed(
2876         void *parsed_result,
2877         __rte_unused struct cmdline *cl,
2878         __rte_unused void *data)
2879 {
2880         struct cmd_setup_rxtx_queue *res = parsed_result;
2881         struct rte_port *port;
2882         struct rte_mempool *mp;
2883         unsigned int socket_id;
2884         uint8_t isrx = 0;
2885         int ret;
2886
2887         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2888                 return;
2889
2890         if (res->portid == (portid_t)RTE_PORT_ALL) {
2891                 fprintf(stderr, "Invalid port id\n");
2892                 return;
2893         }
2894
2895         if (!strcmp(res->rxtxq, "rxq"))
2896                 isrx = 1;
2897         else if (!strcmp(res->rxtxq, "txq"))
2898                 isrx = 0;
2899         else {
2900                 fprintf(stderr, "Unknown parameter\n");
2901                 return;
2902         }
2903
2904         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2905                 fprintf(stderr, "Invalid rx queue\n");
2906                 return;
2907         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2908                 fprintf(stderr, "Invalid tx queue\n");
2909                 return;
2910         }
2911
2912         port = &ports[res->portid];
2913         if (isrx) {
2914                 socket_id = rxring_numa[res->portid];
2915                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2916                         socket_id = port->socket_id;
2917
2918                 mp = mbuf_pool_find(socket_id, 0);
2919                 if (mp == NULL) {
2920                         fprintf(stderr,
2921                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2922                                 rxring_numa[res->portid]);
2923                         return;
2924                 }
2925                 ret = rx_queue_setup(res->portid,
2926                                      res->qid,
2927                                      port->nb_rx_desc[res->qid],
2928                                      socket_id,
2929                                      &port->rxq[res->qid].conf,
2930                                      mp);
2931                 if (ret)
2932                         fprintf(stderr, "Failed to setup RX queue\n");
2933         } else {
2934                 socket_id = txring_numa[res->portid];
2935                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2936                         socket_id = port->socket_id;
2937
2938                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2939                         fprintf(stderr,
2940                                 "Failed to setup TX queue: not enough descriptors\n");
2941                         return;
2942                 }
2943                 ret = rte_eth_tx_queue_setup(res->portid,
2944                                              res->qid,
2945                                              port->nb_tx_desc[res->qid],
2946                                              socket_id,
2947                                              &port->txq[res->qid].conf);
2948                 if (ret)
2949                         fprintf(stderr, "Failed to setup TX queue\n");
2950         }
2951 }
2952
2953 static cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2954         .f = cmd_setup_rxtx_queue_parsed,
2955         .data = NULL,
2956         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2957         .tokens = {
2958                 (void *)&cmd_setup_rxtx_queue_port,
2959                 (void *)&cmd_setup_rxtx_queue_portid,
2960                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2961                 (void *)&cmd_setup_rxtx_queue_qid,
2962                 (void *)&cmd_setup_rxtx_queue_setup,
2963                 NULL,
2964         },
2965 };
2966
2967
2968 /* *** Configure RSS RETA *** */
2969 struct cmd_config_rss_reta {
2970         cmdline_fixed_string_t port;
2971         cmdline_fixed_string_t keyword;
2972         portid_t port_id;
2973         cmdline_fixed_string_t name;
2974         cmdline_fixed_string_t list_name;
2975         cmdline_fixed_string_t list_of_items;
2976 };
2977
2978 static int
2979 parse_reta_config(const char *str,
2980                   struct rte_eth_rss_reta_entry64 *reta_conf,
2981                   uint16_t nb_entries)
2982 {
2983         int i;
2984         unsigned size;
2985         uint16_t hash_index, idx, shift;
2986         uint16_t nb_queue;
2987         char s[256];
2988         const char *p, *p0 = str;
2989         char *end;
2990         enum fieldnames {
2991                 FLD_HASH_INDEX = 0,
2992                 FLD_QUEUE,
2993                 _NUM_FLD
2994         };
2995         unsigned long int_fld[_NUM_FLD];
2996         char *str_fld[_NUM_FLD];
2997
2998         while ((p = strchr(p0,'(')) != NULL) {
2999                 ++p;
3000                 if((p0 = strchr(p,')')) == NULL)
3001                         return -1;
3002
3003                 size = p0 - p;
3004                 if(size >= sizeof(s))
3005                         return -1;
3006
3007                 snprintf(s, sizeof(s), "%.*s", size, p);
3008                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3009                         return -1;
3010                 for (i = 0; i < _NUM_FLD; i++) {
3011                         errno = 0;
3012                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3013                         if (errno != 0 || end == str_fld[i] ||
3014                                         int_fld[i] > 65535)
3015                                 return -1;
3016                 }
3017
3018                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3019                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3020
3021                 if (hash_index >= nb_entries) {
3022                         fprintf(stderr, "Invalid RETA hash index=%d\n",
3023                                 hash_index);
3024                         return -1;
3025                 }
3026
3027                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
3028                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
3029                 reta_conf[idx].mask |= (1ULL << shift);
3030                 reta_conf[idx].reta[shift] = nb_queue;
3031         }
3032
3033         return 0;
3034 }
3035
3036 static void
3037 cmd_set_rss_reta_parsed(void *parsed_result,
3038                         __rte_unused struct cmdline *cl,
3039                         __rte_unused void *data)
3040 {
3041         int ret;
3042         struct rte_eth_dev_info dev_info;
3043         struct rte_eth_rss_reta_entry64 reta_conf[8];
3044         struct cmd_config_rss_reta *res = parsed_result;
3045
3046         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3047         if (ret != 0)
3048                 return;
3049
3050         if (dev_info.reta_size == 0) {
3051                 fprintf(stderr,
3052                         "Redirection table size is 0 which is invalid for RSS\n");
3053                 return;
3054         } else
3055                 printf("The reta size of port %d is %u\n",
3056                         res->port_id, dev_info.reta_size);
3057         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3058                 fprintf(stderr,
3059                         "Currently do not support more than %u entries of redirection table\n",
3060                         RTE_ETH_RSS_RETA_SIZE_512);
3061                 return;
3062         }
3063
3064         memset(reta_conf, 0, sizeof(reta_conf));
3065         if (!strcmp(res->list_name, "reta")) {
3066                 if (parse_reta_config(res->list_of_items, reta_conf,
3067                                                 dev_info.reta_size)) {
3068                         fprintf(stderr,
3069                                 "Invalid RSS Redirection Table config entered\n");
3070                         return;
3071                 }
3072                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3073                                 reta_conf, dev_info.reta_size);
3074                 if (ret != 0)
3075                         fprintf(stderr,
3076                                 "Bad redirection table parameter, return code = %d\n",
3077                                 ret);
3078         }
3079 }
3080
3081 static cmdline_parse_token_string_t cmd_config_rss_reta_port =
3082         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3083 static cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3084         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3085 static cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3086         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3087 static cmdline_parse_token_string_t cmd_config_rss_reta_name =
3088         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3089 static cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3090         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3091 static cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3092         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3093                                  NULL);
3094 static cmdline_parse_inst_t cmd_config_rss_reta = {
3095         .f = cmd_set_rss_reta_parsed,
3096         .data = NULL,
3097         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3098         .tokens = {
3099                 (void *)&cmd_config_rss_reta_port,
3100                 (void *)&cmd_config_rss_reta_keyword,
3101                 (void *)&cmd_config_rss_reta_port_id,
3102                 (void *)&cmd_config_rss_reta_name,
3103                 (void *)&cmd_config_rss_reta_list_name,
3104                 (void *)&cmd_config_rss_reta_list_of_items,
3105                 NULL,
3106         },
3107 };
3108
3109 /* *** SHOW PORT RETA INFO *** */
3110 struct cmd_showport_reta {
3111         cmdline_fixed_string_t show;
3112         cmdline_fixed_string_t port;
3113         portid_t port_id;
3114         cmdline_fixed_string_t rss;
3115         cmdline_fixed_string_t reta;
3116         uint16_t size;
3117         cmdline_fixed_string_t list_of_items;
3118 };
3119
3120 static int
3121 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3122                            uint16_t nb_entries,
3123                            char *str)
3124 {
3125         uint32_t size;
3126         const char *p, *p0 = str;
3127         char s[256];
3128         char *end;
3129         char *str_fld[8];
3130         uint16_t i;
3131         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3132                         RTE_ETH_RETA_GROUP_SIZE;
3133         int ret;
3134
3135         p = strchr(p0, '(');
3136         if (p == NULL)
3137                 return -1;
3138         p++;
3139         p0 = strchr(p, ')');
3140         if (p0 == NULL)
3141                 return -1;
3142         size = p0 - p;
3143         if (size >= sizeof(s)) {
3144                 fprintf(stderr,
3145                         "The string size exceeds the internal buffer size\n");
3146                 return -1;
3147         }
3148         snprintf(s, sizeof(s), "%.*s", size, p);
3149         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3150         if (ret <= 0 || ret != num) {
3151                 fprintf(stderr,
3152                         "The bits of masks do not match the number of reta entries: %u\n",
3153                         num);
3154                 return -1;
3155         }
3156         for (i = 0; i < ret; i++)
3157                 conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
3158
3159         return 0;
3160 }
3161
3162 static void
3163 cmd_showport_reta_parsed(void *parsed_result,
3164                          __rte_unused struct cmdline *cl,
3165                          __rte_unused void *data)
3166 {
3167         struct cmd_showport_reta *res = parsed_result;
3168         struct rte_eth_rss_reta_entry64 reta_conf[8];
3169         struct rte_eth_dev_info dev_info;
3170         uint16_t max_reta_size;
3171         int ret;
3172
3173         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3174         if (ret != 0)
3175                 return;
3176
3177         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3178         if (res->size == 0 || res->size > max_reta_size) {
3179                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3180                         res->size, max_reta_size);
3181                 return;
3182         }
3183
3184         memset(reta_conf, 0, sizeof(reta_conf));
3185         if (showport_parse_reta_config(reta_conf, res->size,
3186                                 res->list_of_items) < 0) {
3187                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3188                         res->list_of_items);
3189                 return;
3190         }
3191         port_rss_reta_info(res->port_id, reta_conf, res->size);
3192 }
3193
3194 static cmdline_parse_token_string_t cmd_showport_reta_show =
3195         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3196 static cmdline_parse_token_string_t cmd_showport_reta_port =
3197         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3198 static cmdline_parse_token_num_t cmd_showport_reta_port_id =
3199         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3200 static cmdline_parse_token_string_t cmd_showport_reta_rss =
3201         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3202 static cmdline_parse_token_string_t cmd_showport_reta_reta =
3203         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3204 static cmdline_parse_token_num_t cmd_showport_reta_size =
3205         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3206 static cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3207         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3208                                         list_of_items, NULL);
3209
3210 static cmdline_parse_inst_t cmd_showport_reta = {
3211         .f = cmd_showport_reta_parsed,
3212         .data = NULL,
3213         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3214         .tokens = {
3215                 (void *)&cmd_showport_reta_show,
3216                 (void *)&cmd_showport_reta_port,
3217                 (void *)&cmd_showport_reta_port_id,
3218                 (void *)&cmd_showport_reta_rss,
3219                 (void *)&cmd_showport_reta_reta,
3220                 (void *)&cmd_showport_reta_size,
3221                 (void *)&cmd_showport_reta_list_of_items,
3222                 NULL,
3223         },
3224 };
3225
3226 /* *** Show RSS hash configuration *** */
3227 struct cmd_showport_rss_hash {
3228         cmdline_fixed_string_t show;
3229         cmdline_fixed_string_t port;
3230         portid_t port_id;
3231         cmdline_fixed_string_t rss_hash;
3232         cmdline_fixed_string_t rss_type;
3233         cmdline_fixed_string_t key; /* optional argument */
3234 };
3235
3236 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3237                                 __rte_unused struct cmdline *cl,
3238                                 void *show_rss_key)
3239 {
3240         struct cmd_showport_rss_hash *res = parsed_result;
3241
3242         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3243 }
3244
3245 static cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3246         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3247 static cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3248         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3249 static cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3250         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3251                                  RTE_UINT16);
3252 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3253         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3254                                  "rss-hash");
3255 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3256         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3257
3258 static cmdline_parse_inst_t cmd_showport_rss_hash = {
3259         .f = cmd_showport_rss_hash_parsed,
3260         .data = NULL,
3261         .help_str = "show port <port_id> rss-hash",
3262         .tokens = {
3263                 (void *)&cmd_showport_rss_hash_show,
3264                 (void *)&cmd_showport_rss_hash_port,
3265                 (void *)&cmd_showport_rss_hash_port_id,
3266                 (void *)&cmd_showport_rss_hash_rss_hash,
3267                 NULL,
3268         },
3269 };
3270
3271 static cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3272         .f = cmd_showport_rss_hash_parsed,
3273         .data = (void *)1,
3274         .help_str = "show port <port_id> rss-hash key",
3275         .tokens = {
3276                 (void *)&cmd_showport_rss_hash_show,
3277                 (void *)&cmd_showport_rss_hash_port,
3278                 (void *)&cmd_showport_rss_hash_port_id,
3279                 (void *)&cmd_showport_rss_hash_rss_hash,
3280                 (void *)&cmd_showport_rss_hash_rss_key,
3281                 NULL,
3282         },
3283 };
3284
3285 /* *** Configure DCB *** */
3286 struct cmd_config_dcb {
3287         cmdline_fixed_string_t port;
3288         cmdline_fixed_string_t config;
3289         portid_t port_id;
3290         cmdline_fixed_string_t dcb;
3291         cmdline_fixed_string_t vt;
3292         cmdline_fixed_string_t vt_en;
3293         uint8_t num_tcs;
3294         cmdline_fixed_string_t pfc;
3295         cmdline_fixed_string_t pfc_en;
3296 };
3297
3298 static void
3299 cmd_config_dcb_parsed(void *parsed_result,
3300                         __rte_unused struct cmdline *cl,
3301                         __rte_unused void *data)
3302 {
3303         struct cmd_config_dcb *res = parsed_result;
3304         struct rte_eth_dcb_info dcb_info;
3305         portid_t port_id = res->port_id;
3306         struct rte_port *port;
3307         uint8_t pfc_en;
3308         int ret;
3309
3310         port = &ports[port_id];
3311         /** Check if the port is not started **/
3312         if (port->port_status != RTE_PORT_STOPPED) {
3313                 fprintf(stderr, "Please stop port %d first\n", port_id);
3314                 return;
3315         }
3316
3317         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3318                 fprintf(stderr,
3319                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3320                 return;
3321         }
3322
3323         if (nb_fwd_lcores < res->num_tcs) {
3324                 fprintf(stderr,
3325                         "nb_cores shouldn't be less than number of TCs.\n");
3326                 return;
3327         }
3328
3329         /* Check whether the port supports the report of DCB info. */
3330         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3331         if (ret == -ENOTSUP) {
3332                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3333                 return;
3334         }
3335
3336         if (!strncmp(res->pfc_en, "on", 2))
3337                 pfc_en = 1;
3338         else
3339                 pfc_en = 0;
3340
3341         /* DCB in VT mode */
3342         if (!strncmp(res->vt_en, "on", 2))
3343                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3344                                 (enum rte_eth_nb_tcs)res->num_tcs,
3345                                 pfc_en);
3346         else
3347                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3348                                 (enum rte_eth_nb_tcs)res->num_tcs,
3349                                 pfc_en);
3350         if (ret != 0) {
3351                 fprintf(stderr, "Cannot initialize network ports.\n");
3352                 return;
3353         }
3354
3355         fwd_config_setup();
3356
3357         cmd_reconfig_device_queue(port_id, 1, 1);
3358 }
3359
3360 static cmdline_parse_token_string_t cmd_config_dcb_port =
3361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3362 static cmdline_parse_token_string_t cmd_config_dcb_config =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3364 static cmdline_parse_token_num_t cmd_config_dcb_port_id =
3365         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3366 static cmdline_parse_token_string_t cmd_config_dcb_dcb =
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3368 static cmdline_parse_token_string_t cmd_config_dcb_vt =
3369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3370 static cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3372 static cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3373         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3374 static cmdline_parse_token_string_t cmd_config_dcb_pfc =
3375         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3376 static cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3377         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3378
3379 static cmdline_parse_inst_t cmd_config_dcb = {
3380         .f = cmd_config_dcb_parsed,
3381         .data = NULL,
3382         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3383         .tokens = {
3384                 (void *)&cmd_config_dcb_port,
3385                 (void *)&cmd_config_dcb_config,
3386                 (void *)&cmd_config_dcb_port_id,
3387                 (void *)&cmd_config_dcb_dcb,
3388                 (void *)&cmd_config_dcb_vt,
3389                 (void *)&cmd_config_dcb_vt_en,
3390                 (void *)&cmd_config_dcb_num_tcs,
3391                 (void *)&cmd_config_dcb_pfc,
3392                 (void *)&cmd_config_dcb_pfc_en,
3393                 NULL,
3394         },
3395 };
3396
3397 /* *** configure number of packets per burst *** */
3398 struct cmd_config_burst {
3399         cmdline_fixed_string_t port;
3400         cmdline_fixed_string_t keyword;
3401         cmdline_fixed_string_t all;
3402         cmdline_fixed_string_t name;
3403         uint16_t value;
3404 };
3405
3406 static void
3407 cmd_config_burst_parsed(void *parsed_result,
3408                         __rte_unused struct cmdline *cl,
3409                         __rte_unused void *data)
3410 {
3411         struct cmd_config_burst *res = parsed_result;
3412         struct rte_eth_dev_info dev_info;
3413         uint16_t rec_nb_pkts;
3414         int ret;
3415
3416         if (!all_ports_stopped()) {
3417                 fprintf(stderr, "Please stop all ports first\n");
3418                 return;
3419         }
3420
3421         if (!strcmp(res->name, "burst")) {
3422                 if (res->value == 0) {
3423                         /* If user gives a value of zero, query the PMD for
3424                          * its recommended Rx burst size. Testpmd uses a single
3425                          * size for all ports, so assume all ports are the same
3426                          * NIC model and use the values from Port 0.
3427                          */
3428                         ret = eth_dev_info_get_print_err(0, &dev_info);
3429                         if (ret != 0)
3430                                 return;
3431
3432                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3433
3434                         if (rec_nb_pkts == 0) {
3435                                 printf("PMD does not recommend a burst size.\n"
3436                                         "User provided value must be between"
3437                                         " 1 and %d\n", MAX_PKT_BURST);
3438                                 return;
3439                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3440                                 printf("PMD recommended burst size of %d"
3441                                         " exceeds maximum value of %d\n",
3442                                         rec_nb_pkts, MAX_PKT_BURST);
3443                                 return;
3444                         }
3445                         printf("Using PMD-provided burst value of %d\n",
3446                                 rec_nb_pkts);
3447                         nb_pkt_per_burst = rec_nb_pkts;
3448                 } else if (res->value > MAX_PKT_BURST) {
3449                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3450                                 MAX_PKT_BURST);
3451                         return;
3452                 } else
3453                         nb_pkt_per_burst = res->value;
3454         } else {
3455                 fprintf(stderr, "Unknown parameter\n");
3456                 return;
3457         }
3458
3459         init_port_config();
3460
3461         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3462 }
3463
3464 static cmdline_parse_token_string_t cmd_config_burst_port =
3465         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3466 static cmdline_parse_token_string_t cmd_config_burst_keyword =
3467         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3468 static cmdline_parse_token_string_t cmd_config_burst_all =
3469         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3470 static cmdline_parse_token_string_t cmd_config_burst_name =
3471         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3472 static cmdline_parse_token_num_t cmd_config_burst_value =
3473         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3474
3475 static cmdline_parse_inst_t cmd_config_burst = {
3476         .f = cmd_config_burst_parsed,
3477         .data = NULL,
3478         .help_str = "port config all burst <value>",
3479         .tokens = {
3480                 (void *)&cmd_config_burst_port,
3481                 (void *)&cmd_config_burst_keyword,
3482                 (void *)&cmd_config_burst_all,
3483                 (void *)&cmd_config_burst_name,
3484                 (void *)&cmd_config_burst_value,
3485                 NULL,
3486         },
3487 };
3488
3489 /* *** configure rx/tx queues *** */
3490 struct cmd_config_thresh {
3491         cmdline_fixed_string_t port;
3492         cmdline_fixed_string_t keyword;
3493         cmdline_fixed_string_t all;
3494         cmdline_fixed_string_t name;
3495         uint8_t value;
3496 };
3497
3498 static void
3499 cmd_config_thresh_parsed(void *parsed_result,
3500                         __rte_unused struct cmdline *cl,
3501                         __rte_unused void *data)
3502 {
3503         struct cmd_config_thresh *res = parsed_result;
3504
3505         if (!all_ports_stopped()) {
3506                 fprintf(stderr, "Please stop all ports first\n");
3507                 return;
3508         }
3509
3510         if (!strcmp(res->name, "txpt"))
3511                 tx_pthresh = res->value;
3512         else if(!strcmp(res->name, "txht"))
3513                 tx_hthresh = res->value;
3514         else if(!strcmp(res->name, "txwt"))
3515                 tx_wthresh = res->value;
3516         else if(!strcmp(res->name, "rxpt"))
3517                 rx_pthresh = res->value;
3518         else if(!strcmp(res->name, "rxht"))
3519                 rx_hthresh = res->value;
3520         else if(!strcmp(res->name, "rxwt"))
3521                 rx_wthresh = res->value;
3522         else {
3523                 fprintf(stderr, "Unknown parameter\n");
3524                 return;
3525         }
3526
3527         init_port_config();
3528
3529         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3530 }
3531
3532 static cmdline_parse_token_string_t cmd_config_thresh_port =
3533         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3534 static cmdline_parse_token_string_t cmd_config_thresh_keyword =
3535         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3536 static cmdline_parse_token_string_t cmd_config_thresh_all =
3537         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3538 static cmdline_parse_token_string_t cmd_config_thresh_name =
3539         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3540                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3541 static cmdline_parse_token_num_t cmd_config_thresh_value =
3542         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3543
3544 static cmdline_parse_inst_t cmd_config_thresh = {
3545         .f = cmd_config_thresh_parsed,
3546         .data = NULL,
3547         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3548         .tokens = {
3549                 (void *)&cmd_config_thresh_port,
3550                 (void *)&cmd_config_thresh_keyword,
3551                 (void *)&cmd_config_thresh_all,
3552                 (void *)&cmd_config_thresh_name,
3553                 (void *)&cmd_config_thresh_value,
3554                 NULL,
3555         },
3556 };
3557
3558 /* *** configure free/rs threshold *** */
3559 struct cmd_config_threshold {
3560         cmdline_fixed_string_t port;
3561         cmdline_fixed_string_t keyword;
3562         cmdline_fixed_string_t all;
3563         cmdline_fixed_string_t name;
3564         uint16_t value;
3565 };
3566
3567 static void
3568 cmd_config_threshold_parsed(void *parsed_result,
3569                         __rte_unused struct cmdline *cl,
3570                         __rte_unused void *data)
3571 {
3572         struct cmd_config_threshold *res = parsed_result;
3573
3574         if (!all_ports_stopped()) {
3575                 fprintf(stderr, "Please stop all ports first\n");
3576                 return;
3577         }
3578
3579         if (!strcmp(res->name, "txfreet"))
3580                 tx_free_thresh = res->value;
3581         else if (!strcmp(res->name, "txrst"))
3582                 tx_rs_thresh = res->value;
3583         else if (!strcmp(res->name, "rxfreet"))
3584                 rx_free_thresh = res->value;
3585         else {
3586                 fprintf(stderr, "Unknown parameter\n");
3587                 return;
3588         }
3589
3590         init_port_config();
3591
3592         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3593 }
3594
3595 static cmdline_parse_token_string_t cmd_config_threshold_port =
3596         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3597 static cmdline_parse_token_string_t cmd_config_threshold_keyword =
3598         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3599                                                                 "config");
3600 static cmdline_parse_token_string_t cmd_config_threshold_all =
3601         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3602 static cmdline_parse_token_string_t cmd_config_threshold_name =
3603         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3604                                                 "txfreet#txrst#rxfreet");
3605 static cmdline_parse_token_num_t cmd_config_threshold_value =
3606         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3607
3608 static cmdline_parse_inst_t cmd_config_threshold = {
3609         .f = cmd_config_threshold_parsed,
3610         .data = NULL,
3611         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3612         .tokens = {
3613                 (void *)&cmd_config_threshold_port,
3614                 (void *)&cmd_config_threshold_keyword,
3615                 (void *)&cmd_config_threshold_all,
3616                 (void *)&cmd_config_threshold_name,
3617                 (void *)&cmd_config_threshold_value,
3618                 NULL,
3619         },
3620 };
3621
3622 /* *** stop *** */
3623 struct cmd_stop_result {
3624         cmdline_fixed_string_t stop;
3625 };
3626
3627 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3628                             __rte_unused struct cmdline *cl,
3629                             __rte_unused void *data)
3630 {
3631         stop_packet_forwarding();
3632 }
3633
3634 static cmdline_parse_token_string_t cmd_stop_stop =
3635         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3636
3637 static cmdline_parse_inst_t cmd_stop = {
3638         .f = cmd_stop_parsed,
3639         .data = NULL,
3640         .help_str = "stop: Stop packet forwarding",
3641         .tokens = {
3642                 (void *)&cmd_stop_stop,
3643                 NULL,
3644         },
3645 };
3646
3647 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3648
3649 unsigned int
3650 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3651                 unsigned int *parsed_items, int check_unique_values)
3652 {
3653         unsigned int nb_item;
3654         unsigned int value;
3655         unsigned int i;
3656         unsigned int j;
3657         int value_ok;
3658         char c;
3659
3660         /*
3661          * First parse all items in the list and store their value.
3662          */
3663         value = 0;
3664         nb_item = 0;
3665         value_ok = 0;
3666         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3667                 c = str[i];
3668                 if ((c >= '0') && (c <= '9')) {
3669                         value = (unsigned int) (value * 10 + (c - '0'));
3670                         value_ok = 1;
3671                         continue;
3672                 }
3673                 if (c != ',') {
3674                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3675                         return 0;
3676                 }
3677                 if (! value_ok) {
3678                         fprintf(stderr, "No valid value before comma\n");
3679                         return 0;
3680                 }
3681                 if (nb_item < max_items) {
3682                         parsed_items[nb_item] = value;
3683                         value_ok = 0;
3684                         value = 0;
3685                 }
3686                 nb_item++;
3687         }
3688         if (nb_item >= max_items) {
3689                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3690                         item_name, nb_item + 1, max_items);
3691                 return 0;
3692         }
3693         parsed_items[nb_item++] = value;
3694         if (! check_unique_values)
3695                 return nb_item;
3696
3697         /*
3698          * Then, check that all values in the list are different.
3699          * No optimization here...
3700          */
3701         for (i = 0; i < nb_item; i++) {
3702                 for (j = i + 1; j < nb_item; j++) {
3703                         if (parsed_items[j] == parsed_items[i]) {
3704                                 fprintf(stderr,
3705                                         "duplicated %s %u at index %u and %u\n",
3706                                         item_name, parsed_items[i], i, j);
3707                                 return 0;
3708                         }
3709                 }
3710         }
3711         return nb_item;
3712 }
3713
3714 struct cmd_set_list_result {
3715         cmdline_fixed_string_t cmd_keyword;
3716         cmdline_fixed_string_t list_name;
3717         cmdline_fixed_string_t list_of_items;
3718 };
3719
3720 static void cmd_set_list_parsed(void *parsed_result,
3721                                 __rte_unused struct cmdline *cl,
3722                                 __rte_unused void *data)
3723 {
3724         struct cmd_set_list_result *res;
3725         union {
3726                 unsigned int lcorelist[RTE_MAX_LCORE];
3727                 unsigned int portlist[RTE_MAX_ETHPORTS];
3728         } parsed_items;
3729         unsigned int nb_item;
3730
3731         if (test_done == 0) {
3732                 fprintf(stderr, "Please stop forwarding first\n");
3733                 return;
3734         }
3735
3736         res = parsed_result;
3737         if (!strcmp(res->list_name, "corelist")) {
3738                 nb_item = parse_item_list(res->list_of_items, "core",
3739                                           RTE_MAX_LCORE,
3740                                           parsed_items.lcorelist, 1);
3741                 if (nb_item > 0) {
3742                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3743                         fwd_config_setup();
3744                 }
3745                 return;
3746         }
3747         if (!strcmp(res->list_name, "portlist")) {
3748                 nb_item = parse_item_list(res->list_of_items, "port",
3749                                           RTE_MAX_ETHPORTS,
3750                                           parsed_items.portlist, 1);
3751                 if (nb_item > 0) {
3752                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3753                         fwd_config_setup();
3754                 }
3755         }
3756 }
3757
3758 static cmdline_parse_token_string_t cmd_set_list_keyword =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3760                                  "set");
3761 static cmdline_parse_token_string_t cmd_set_list_name =
3762         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3763                                  "corelist#portlist");
3764 static cmdline_parse_token_string_t cmd_set_list_of_items =
3765         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3766                                  NULL);
3767
3768 static cmdline_parse_inst_t cmd_set_fwd_list = {
3769         .f = cmd_set_list_parsed,
3770         .data = NULL,
3771         .help_str = "set corelist|portlist <list0[,list1]*>",
3772         .tokens = {
3773                 (void *)&cmd_set_list_keyword,
3774                 (void *)&cmd_set_list_name,
3775                 (void *)&cmd_set_list_of_items,
3776                 NULL,
3777         },
3778 };
3779
3780 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3781
3782 struct cmd_setmask_result {
3783         cmdline_fixed_string_t set;
3784         cmdline_fixed_string_t mask;
3785         uint64_t hexavalue;
3786 };
3787
3788 static void cmd_set_mask_parsed(void *parsed_result,
3789                                 __rte_unused struct cmdline *cl,
3790                                 __rte_unused void *data)
3791 {
3792         struct cmd_setmask_result *res = parsed_result;
3793
3794         if (test_done == 0) {
3795                 fprintf(stderr, "Please stop forwarding first\n");
3796                 return;
3797         }
3798         if (!strcmp(res->mask, "coremask")) {
3799                 set_fwd_lcores_mask(res->hexavalue);
3800                 fwd_config_setup();
3801         } else if (!strcmp(res->mask, "portmask")) {
3802                 set_fwd_ports_mask(res->hexavalue);
3803                 fwd_config_setup();
3804         }
3805 }
3806
3807 static cmdline_parse_token_string_t cmd_setmask_set =
3808         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3809 static cmdline_parse_token_string_t cmd_setmask_mask =
3810         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3811                                  "coremask#portmask");
3812 static cmdline_parse_token_num_t cmd_setmask_value =
3813         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3814
3815 static cmdline_parse_inst_t cmd_set_fwd_mask = {
3816         .f = cmd_set_mask_parsed,
3817         .data = NULL,
3818         .help_str = "set coremask|portmask <hexadecimal value>",
3819         .tokens = {
3820                 (void *)&cmd_setmask_set,
3821                 (void *)&cmd_setmask_mask,
3822                 (void *)&cmd_setmask_value,
3823                 NULL,
3824         },
3825 };
3826
3827 /*
3828  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3829  */
3830 struct cmd_set_result {
3831         cmdline_fixed_string_t set;
3832         cmdline_fixed_string_t what;
3833         uint16_t value;
3834 };
3835
3836 static void cmd_set_parsed(void *parsed_result,
3837                            __rte_unused struct cmdline *cl,
3838                            __rte_unused void *data)
3839 {
3840         struct cmd_set_result *res = parsed_result;
3841         if (!strcmp(res->what, "nbport")) {
3842                 set_fwd_ports_number(res->value);
3843                 fwd_config_setup();
3844         } else if (!strcmp(res->what, "nbcore")) {
3845                 set_fwd_lcores_number(res->value);
3846                 fwd_config_setup();
3847         } else if (!strcmp(res->what, "burst"))
3848                 set_nb_pkt_per_burst(res->value);
3849         else if (!strcmp(res->what, "verbose"))
3850                 set_verbose_level(res->value);
3851 }
3852
3853 static cmdline_parse_token_string_t cmd_set_set =
3854         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3855 static cmdline_parse_token_string_t cmd_set_what =
3856         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3857                                  "nbport#nbcore#burst#verbose");
3858 static cmdline_parse_token_num_t cmd_set_value =
3859         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3860
3861 static cmdline_parse_inst_t cmd_set_numbers = {
3862         .f = cmd_set_parsed,
3863         .data = NULL,
3864         .help_str = "set nbport|nbcore|burst|verbose <value>",
3865         .tokens = {
3866                 (void *)&cmd_set_set,
3867                 (void *)&cmd_set_what,
3868                 (void *)&cmd_set_value,
3869                 NULL,
3870         },
3871 };
3872
3873 /* *** SET LOG LEVEL CONFIGURATION *** */
3874
3875 struct cmd_set_log_result {
3876         cmdline_fixed_string_t set;
3877         cmdline_fixed_string_t log;
3878         cmdline_fixed_string_t type;
3879         uint32_t level;
3880 };
3881
3882 static void
3883 cmd_set_log_parsed(void *parsed_result,
3884                    __rte_unused struct cmdline *cl,
3885                    __rte_unused void *data)
3886 {
3887         struct cmd_set_log_result *res;
3888         int ret;
3889
3890         res = parsed_result;
3891         if (!strcmp(res->type, "global"))
3892                 rte_log_set_global_level(res->level);
3893         else {
3894                 ret = rte_log_set_level_regexp(res->type, res->level);
3895                 if (ret < 0)
3896                         fprintf(stderr, "Unable to set log level\n");
3897         }
3898 }
3899
3900 static cmdline_parse_token_string_t cmd_set_log_set =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3902 static cmdline_parse_token_string_t cmd_set_log_log =
3903         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3904 static cmdline_parse_token_string_t cmd_set_log_type =
3905         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3906 static cmdline_parse_token_num_t cmd_set_log_level =
3907         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3908
3909 static cmdline_parse_inst_t cmd_set_log = {
3910         .f = cmd_set_log_parsed,
3911         .data = NULL,
3912         .help_str = "set log global|<type> <level>",
3913         .tokens = {
3914                 (void *)&cmd_set_log_set,
3915                 (void *)&cmd_set_log_log,
3916                 (void *)&cmd_set_log_type,
3917                 (void *)&cmd_set_log_level,
3918                 NULL,
3919         },
3920 };
3921
3922 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3923
3924 struct cmd_set_rxoffs_result {
3925         cmdline_fixed_string_t cmd_keyword;
3926         cmdline_fixed_string_t rxoffs;
3927         cmdline_fixed_string_t seg_offsets;
3928 };
3929
3930 static void
3931 cmd_set_rxoffs_parsed(void *parsed_result,
3932                       __rte_unused struct cmdline *cl,
3933                       __rte_unused void *data)
3934 {
3935         struct cmd_set_rxoffs_result *res;
3936         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3937         unsigned int nb_segs;
3938
3939         res = parsed_result;
3940         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3941                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3942         if (nb_segs > 0)
3943                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3944         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3945 }
3946
3947 static cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3948         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3949                                  cmd_keyword, "set");
3950 static cmdline_parse_token_string_t cmd_set_rxoffs_name =
3951         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3952                                  rxoffs, "rxoffs");
3953 static cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3954         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3955                                  seg_offsets, NULL);
3956
3957 static cmdline_parse_inst_t cmd_set_rxoffs = {
3958         .f = cmd_set_rxoffs_parsed,
3959         .data = NULL,
3960         .help_str = "set rxoffs <len0[,len1]*>",
3961         .tokens = {
3962                 (void *)&cmd_set_rxoffs_keyword,
3963                 (void *)&cmd_set_rxoffs_name,
3964                 (void *)&cmd_set_rxoffs_offsets,
3965                 NULL,
3966         },
3967 };
3968
3969 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3970
3971 struct cmd_set_rxpkts_result {
3972         cmdline_fixed_string_t cmd_keyword;
3973         cmdline_fixed_string_t rxpkts;
3974         cmdline_fixed_string_t seg_lengths;
3975 };
3976
3977 static void
3978 cmd_set_rxpkts_parsed(void *parsed_result,
3979                       __rte_unused struct cmdline *cl,
3980                       __rte_unused void *data)
3981 {
3982         struct cmd_set_rxpkts_result *res;
3983         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3984         unsigned int nb_segs;
3985
3986         res = parsed_result;
3987         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3988                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3989         if (nb_segs > 0)
3990                 set_rx_pkt_segments(seg_lengths, nb_segs);
3991         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3992 }
3993
3994 static cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3995         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3996                                  cmd_keyword, "set");
3997 static cmdline_parse_token_string_t cmd_set_rxpkts_name =
3998         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3999                                  rxpkts, "rxpkts");
4000 static cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
4001         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
4002                                  seg_lengths, NULL);
4003
4004 static cmdline_parse_inst_t cmd_set_rxpkts = {
4005         .f = cmd_set_rxpkts_parsed,
4006         .data = NULL,
4007         .help_str = "set rxpkts <len0[,len1]*>",
4008         .tokens = {
4009                 (void *)&cmd_set_rxpkts_keyword,
4010                 (void *)&cmd_set_rxpkts_name,
4011                 (void *)&cmd_set_rxpkts_lengths,
4012                 NULL,
4013         },
4014 };
4015
4016 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4017
4018 struct cmd_set_txpkts_result {
4019         cmdline_fixed_string_t cmd_keyword;
4020         cmdline_fixed_string_t txpkts;
4021         cmdline_fixed_string_t seg_lengths;
4022 };
4023
4024 static void
4025 cmd_set_txpkts_parsed(void *parsed_result,
4026                       __rte_unused struct cmdline *cl,
4027                       __rte_unused void *data)
4028 {
4029         struct cmd_set_txpkts_result *res;
4030         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4031         unsigned int nb_segs;
4032
4033         res = parsed_result;
4034         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4035                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4036         if (nb_segs > 0)
4037                 set_tx_pkt_segments(seg_lengths, nb_segs);
4038 }
4039
4040 static cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4041         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4042                                  cmd_keyword, "set");
4043 static cmdline_parse_token_string_t cmd_set_txpkts_name =
4044         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4045                                  txpkts, "txpkts");
4046 static cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4047         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4048                                  seg_lengths, NULL);
4049
4050 static cmdline_parse_inst_t cmd_set_txpkts = {
4051         .f = cmd_set_txpkts_parsed,
4052         .data = NULL,
4053         .help_str = "set txpkts <len0[,len1]*>",
4054         .tokens = {
4055                 (void *)&cmd_set_txpkts_keyword,
4056                 (void *)&cmd_set_txpkts_name,
4057                 (void *)&cmd_set_txpkts_lengths,
4058                 NULL,
4059         },
4060 };
4061
4062 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4063
4064 struct cmd_set_txsplit_result {
4065         cmdline_fixed_string_t cmd_keyword;
4066         cmdline_fixed_string_t txsplit;
4067         cmdline_fixed_string_t mode;
4068 };
4069
4070 static void
4071 cmd_set_txsplit_parsed(void *parsed_result,
4072                       __rte_unused struct cmdline *cl,
4073                       __rte_unused void *data)
4074 {
4075         struct cmd_set_txsplit_result *res;
4076
4077         res = parsed_result;
4078         set_tx_pkt_split(res->mode);
4079 }
4080
4081 static cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4082         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4083                                  cmd_keyword, "set");
4084 static cmdline_parse_token_string_t cmd_set_txsplit_name =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4086                                  txsplit, "txsplit");
4087 static cmdline_parse_token_string_t cmd_set_txsplit_mode =
4088         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4089                                  mode, NULL);
4090
4091 static cmdline_parse_inst_t cmd_set_txsplit = {
4092         .f = cmd_set_txsplit_parsed,
4093         .data = NULL,
4094         .help_str = "set txsplit on|off|rand",
4095         .tokens = {
4096                 (void *)&cmd_set_txsplit_keyword,
4097                 (void *)&cmd_set_txsplit_name,
4098                 (void *)&cmd_set_txsplit_mode,
4099                 NULL,
4100         },
4101 };
4102
4103 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4104
4105 struct cmd_set_txtimes_result {
4106         cmdline_fixed_string_t cmd_keyword;
4107         cmdline_fixed_string_t txtimes;
4108         cmdline_fixed_string_t tx_times;
4109 };
4110
4111 static void
4112 cmd_set_txtimes_parsed(void *parsed_result,
4113                        __rte_unused struct cmdline *cl,
4114                        __rte_unused void *data)
4115 {
4116         struct cmd_set_txtimes_result *res;
4117         unsigned int tx_times[2] = {0, 0};
4118         unsigned int n_times;
4119
4120         res = parsed_result;
4121         n_times = parse_item_list(res->tx_times, "tx times",
4122                                   2, tx_times, 0);
4123         if (n_times == 2)
4124                 set_tx_pkt_times(tx_times);
4125 }
4126
4127 static cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4128         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4129                                  cmd_keyword, "set");
4130 static cmdline_parse_token_string_t cmd_set_txtimes_name =
4131         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4132                                  txtimes, "txtimes");
4133 static cmdline_parse_token_string_t cmd_set_txtimes_value =
4134         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4135                                  tx_times, NULL);
4136
4137 static cmdline_parse_inst_t cmd_set_txtimes = {
4138         .f = cmd_set_txtimes_parsed,
4139         .data = NULL,
4140         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4141         .tokens = {
4142                 (void *)&cmd_set_txtimes_keyword,
4143                 (void *)&cmd_set_txtimes_name,
4144                 (void *)&cmd_set_txtimes_value,
4145                 NULL,
4146         },
4147 };
4148
4149 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4150 struct cmd_rx_vlan_filter_all_result {
4151         cmdline_fixed_string_t rx_vlan;
4152         cmdline_fixed_string_t what;
4153         cmdline_fixed_string_t all;
4154         portid_t port_id;
4155 };
4156
4157 static void
4158 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4159                               __rte_unused struct cmdline *cl,
4160                               __rte_unused void *data)
4161 {
4162         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4163
4164         if (!strcmp(res->what, "add"))
4165                 rx_vlan_all_filter_set(res->port_id, 1);
4166         else
4167                 rx_vlan_all_filter_set(res->port_id, 0);
4168 }
4169
4170 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4171         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4172                                  rx_vlan, "rx_vlan");
4173 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4174         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4175                                  what, "add#rm");
4176 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4177         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4178                                  all, "all");
4179 static cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4180         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4181                               port_id, RTE_UINT16);
4182
4183 static cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4184         .f = cmd_rx_vlan_filter_all_parsed,
4185         .data = NULL,
4186         .help_str = "rx_vlan add|rm all <port_id>: "
4187                 "Add/Remove all identifiers to/from the set of VLAN "
4188                 "identifiers filtered by a port",
4189         .tokens = {
4190                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4191                 (void *)&cmd_rx_vlan_filter_all_what,
4192                 (void *)&cmd_rx_vlan_filter_all_all,
4193                 (void *)&cmd_rx_vlan_filter_all_portid,
4194                 NULL,
4195         },
4196 };
4197
4198 /* *** VLAN OFFLOAD SET ON A PORT *** */
4199 struct cmd_vlan_offload_result {
4200         cmdline_fixed_string_t vlan;
4201         cmdline_fixed_string_t set;
4202         cmdline_fixed_string_t vlan_type;
4203         cmdline_fixed_string_t what;
4204         cmdline_fixed_string_t on;
4205         cmdline_fixed_string_t port_id;
4206 };
4207
4208 static void
4209 cmd_vlan_offload_parsed(void *parsed_result,
4210                           __rte_unused struct cmdline *cl,
4211                           __rte_unused void *data)
4212 {
4213         int on;
4214         struct cmd_vlan_offload_result *res = parsed_result;
4215         char *str;
4216         int i, len = 0;
4217         portid_t port_id = 0;
4218         unsigned int tmp;
4219
4220         str = res->port_id;
4221         len = strnlen(str, STR_TOKEN_SIZE);
4222         i = 0;
4223         /* Get port_id first */
4224         while(i < len){
4225                 if(str[i] == ',')
4226                         break;
4227
4228                 i++;
4229         }
4230         str[i]='\0';
4231         tmp = strtoul(str, NULL, 0);
4232         /* If port_id greater that what portid_t can represent, return */
4233         if(tmp >= RTE_MAX_ETHPORTS)
4234                 return;
4235         port_id = (portid_t)tmp;
4236
4237         if (!strcmp(res->on, "on"))
4238                 on = 1;
4239         else
4240                 on = 0;
4241
4242         if (!strcmp(res->what, "strip"))
4243                 rx_vlan_strip_set(port_id,  on);
4244         else if(!strcmp(res->what, "stripq")){
4245                 uint16_t queue_id = 0;
4246
4247                 /* No queue_id, return */
4248                 if(i + 1 >= len) {
4249                         fprintf(stderr, "must specify (port,queue_id)\n");
4250                         return;
4251                 }
4252                 tmp = strtoul(str + i + 1, NULL, 0);
4253                 /* If queue_id greater that what 16-bits can represent, return */
4254                 if(tmp > 0xffff)
4255                         return;
4256
4257                 queue_id = (uint16_t)tmp;
4258                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4259         }
4260         else if (!strcmp(res->what, "filter"))
4261                 rx_vlan_filter_set(port_id, on);
4262         else if (!strcmp(res->what, "qinq_strip"))
4263                 rx_vlan_qinq_strip_set(port_id, on);
4264         else
4265                 vlan_extend_set(port_id, on);
4266
4267         return;
4268 }
4269
4270 static cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4271         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4272                                  vlan, "vlan");
4273 static cmdline_parse_token_string_t cmd_vlan_offload_set =
4274         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4275                                  set, "set");
4276 static cmdline_parse_token_string_t cmd_vlan_offload_what =
4277         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4278                                 what, "strip#filter#qinq_strip#extend#stripq");
4279 static cmdline_parse_token_string_t cmd_vlan_offload_on =
4280         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4281                               on, "on#off");
4282 static cmdline_parse_token_string_t cmd_vlan_offload_portid =
4283         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4284                               port_id, NULL);
4285
4286 static cmdline_parse_inst_t cmd_vlan_offload = {
4287         .f = cmd_vlan_offload_parsed,
4288         .data = NULL,
4289         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4290                 "<port_id[,queue_id]>: "
4291                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4292         .tokens = {
4293                 (void *)&cmd_vlan_offload_vlan,
4294                 (void *)&cmd_vlan_offload_set,
4295                 (void *)&cmd_vlan_offload_what,
4296                 (void *)&cmd_vlan_offload_on,
4297                 (void *)&cmd_vlan_offload_portid,
4298                 NULL,
4299         },
4300 };
4301
4302 /* *** VLAN TPID SET ON A PORT *** */
4303 struct cmd_vlan_tpid_result {
4304         cmdline_fixed_string_t vlan;
4305         cmdline_fixed_string_t set;
4306         cmdline_fixed_string_t vlan_type;
4307         cmdline_fixed_string_t what;
4308         uint16_t tp_id;
4309         portid_t port_id;
4310 };
4311
4312 static void
4313 cmd_vlan_tpid_parsed(void *parsed_result,
4314                           __rte_unused struct cmdline *cl,
4315                           __rte_unused void *data)
4316 {
4317         struct cmd_vlan_tpid_result *res = parsed_result;
4318         enum rte_vlan_type vlan_type;
4319
4320         if (!strcmp(res->vlan_type, "inner"))
4321                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4322         else if (!strcmp(res->vlan_type, "outer"))
4323                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4324         else {
4325                 fprintf(stderr, "Unknown vlan type\n");
4326                 return;
4327         }
4328         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4329 }
4330
4331 static cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4332         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4333                                  vlan, "vlan");
4334 static cmdline_parse_token_string_t cmd_vlan_tpid_set =
4335         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4336                                  set, "set");
4337 static cmdline_parse_token_string_t cmd_vlan_type =
4338         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4339                                  vlan_type, "inner#outer");
4340 static cmdline_parse_token_string_t cmd_vlan_tpid_what =
4341         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4342                                  what, "tpid");
4343 static cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4344         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4345                               tp_id, RTE_UINT16);
4346 static cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4347         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4348                               port_id, RTE_UINT16);
4349
4350 static cmdline_parse_inst_t cmd_vlan_tpid = {
4351         .f = cmd_vlan_tpid_parsed,
4352         .data = NULL,
4353         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4354                 "Set the VLAN Ether type",
4355         .tokens = {
4356                 (void *)&cmd_vlan_tpid_vlan,
4357                 (void *)&cmd_vlan_tpid_set,
4358                 (void *)&cmd_vlan_type,
4359                 (void *)&cmd_vlan_tpid_what,
4360                 (void *)&cmd_vlan_tpid_tpid,
4361                 (void *)&cmd_vlan_tpid_portid,
4362                 NULL,
4363         },
4364 };
4365
4366 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4367 struct cmd_rx_vlan_filter_result {
4368         cmdline_fixed_string_t rx_vlan;
4369         cmdline_fixed_string_t what;
4370         uint16_t vlan_id;
4371         portid_t port_id;
4372 };
4373
4374 static void
4375 cmd_rx_vlan_filter_parsed(void *parsed_result,
4376                           __rte_unused struct cmdline *cl,
4377                           __rte_unused void *data)
4378 {
4379         struct cmd_rx_vlan_filter_result *res = parsed_result;
4380
4381         if (!strcmp(res->what, "add"))
4382                 rx_vft_set(res->port_id, res->vlan_id, 1);
4383         else
4384                 rx_vft_set(res->port_id, res->vlan_id, 0);
4385 }
4386
4387 static cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4388         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4389                                  rx_vlan, "rx_vlan");
4390 static cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4391         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4392                                  what, "add#rm");
4393 static cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4394         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4395                               vlan_id, RTE_UINT16);
4396 static cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4397         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4398                               port_id, RTE_UINT16);
4399
4400 static cmdline_parse_inst_t cmd_rx_vlan_filter = {
4401         .f = cmd_rx_vlan_filter_parsed,
4402         .data = NULL,
4403         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4404                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4405                 "identifiers filtered by a port",
4406         .tokens = {
4407                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4408                 (void *)&cmd_rx_vlan_filter_what,
4409                 (void *)&cmd_rx_vlan_filter_vlanid,
4410                 (void *)&cmd_rx_vlan_filter_portid,
4411                 NULL,
4412         },
4413 };
4414
4415 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4416 struct cmd_tx_vlan_set_result {
4417         cmdline_fixed_string_t tx_vlan;
4418         cmdline_fixed_string_t set;
4419         portid_t port_id;
4420         uint16_t vlan_id;
4421 };
4422
4423 static void
4424 cmd_tx_vlan_set_parsed(void *parsed_result,
4425                        __rte_unused struct cmdline *cl,
4426                        __rte_unused void *data)
4427 {
4428         struct cmd_tx_vlan_set_result *res = parsed_result;
4429
4430         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4431                 return;
4432
4433         if (!port_is_stopped(res->port_id)) {
4434                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4435                 return;
4436         }
4437
4438         tx_vlan_set(res->port_id, res->vlan_id);
4439
4440         cmd_reconfig_device_queue(res->port_id, 1, 1);
4441 }
4442
4443 static cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4444         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4445                                  tx_vlan, "tx_vlan");
4446 static cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4447         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4448                                  set, "set");
4449 static cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4450         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4451                               port_id, RTE_UINT16);
4452 static cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4453         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4454                               vlan_id, RTE_UINT16);
4455
4456 static cmdline_parse_inst_t cmd_tx_vlan_set = {
4457         .f = cmd_tx_vlan_set_parsed,
4458         .data = NULL,
4459         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4460                 "Enable hardware insertion of a single VLAN header "
4461                 "with a given TAG Identifier in packets sent on a port",
4462         .tokens = {
4463                 (void *)&cmd_tx_vlan_set_tx_vlan,
4464                 (void *)&cmd_tx_vlan_set_set,
4465                 (void *)&cmd_tx_vlan_set_portid,
4466                 (void *)&cmd_tx_vlan_set_vlanid,
4467                 NULL,
4468         },
4469 };
4470
4471 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4472 struct cmd_tx_vlan_set_qinq_result {
4473         cmdline_fixed_string_t tx_vlan;
4474         cmdline_fixed_string_t set;
4475         portid_t port_id;
4476         uint16_t vlan_id;
4477         uint16_t vlan_id_outer;
4478 };
4479
4480 static void
4481 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4482                             __rte_unused struct cmdline *cl,
4483                             __rte_unused void *data)
4484 {
4485         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4486
4487         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4488                 return;
4489
4490         if (!port_is_stopped(res->port_id)) {
4491                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4492                 return;
4493         }
4494
4495         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4496
4497         cmd_reconfig_device_queue(res->port_id, 1, 1);
4498 }
4499
4500 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4501         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4502                 tx_vlan, "tx_vlan");
4503 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4504         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4505                 set, "set");
4506 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4507         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4508                 port_id, RTE_UINT16);
4509 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4510         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4511                 vlan_id, RTE_UINT16);
4512 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4513         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4514                 vlan_id_outer, RTE_UINT16);
4515
4516 static cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4517         .f = cmd_tx_vlan_set_qinq_parsed,
4518         .data = NULL,
4519         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4520                 "Enable hardware insertion of double VLAN header "
4521                 "with given TAG Identifiers in packets sent on a port",
4522         .tokens = {
4523                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4524                 (void *)&cmd_tx_vlan_set_qinq_set,
4525                 (void *)&cmd_tx_vlan_set_qinq_portid,
4526                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4527                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4528                 NULL,
4529         },
4530 };
4531
4532 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4533 struct cmd_tx_vlan_set_pvid_result {
4534         cmdline_fixed_string_t tx_vlan;
4535         cmdline_fixed_string_t set;
4536         cmdline_fixed_string_t pvid;
4537         portid_t port_id;
4538         uint16_t vlan_id;
4539         cmdline_fixed_string_t mode;
4540 };
4541
4542 static void
4543 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4544                             __rte_unused struct cmdline *cl,
4545                             __rte_unused void *data)
4546 {
4547         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4548
4549         if (strcmp(res->mode, "on") == 0)
4550                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4551         else
4552                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4553 }
4554
4555 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4556         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4557                                  tx_vlan, "tx_vlan");
4558 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4559         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4560                                  set, "set");
4561 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4562         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4563                                  pvid, "pvid");
4564 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4565         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4566                              port_id, RTE_UINT16);
4567 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4568         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4569                               vlan_id, RTE_UINT16);
4570 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4571         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4572                                  mode, "on#off");
4573
4574 static cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4575         .f = cmd_tx_vlan_set_pvid_parsed,
4576         .data = NULL,
4577         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4578         .tokens = {
4579                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4580                 (void *)&cmd_tx_vlan_set_pvid_set,
4581                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4582                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4583                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4584                 (void *)&cmd_tx_vlan_set_pvid_mode,
4585                 NULL,
4586         },
4587 };
4588
4589 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4590 struct cmd_tx_vlan_reset_result {
4591         cmdline_fixed_string_t tx_vlan;
4592         cmdline_fixed_string_t reset;
4593         portid_t port_id;
4594 };
4595
4596 static void
4597 cmd_tx_vlan_reset_parsed(void *parsed_result,
4598                          __rte_unused struct cmdline *cl,
4599                          __rte_unused void *data)
4600 {
4601         struct cmd_tx_vlan_reset_result *res = parsed_result;
4602
4603         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4604                 return;
4605
4606         if (!port_is_stopped(res->port_id)) {
4607                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4608                 return;
4609         }
4610
4611         tx_vlan_reset(res->port_id);
4612
4613         cmd_reconfig_device_queue(res->port_id, 1, 1);
4614 }
4615
4616 static cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4617         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4618                                  tx_vlan, "tx_vlan");
4619 static cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4620         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4621                                  reset, "reset");
4622 static cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4623         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4624                               port_id, RTE_UINT16);
4625
4626 static cmdline_parse_inst_t cmd_tx_vlan_reset = {
4627         .f = cmd_tx_vlan_reset_parsed,
4628         .data = NULL,
4629         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4630                 "VLAN header in packets sent on a port",
4631         .tokens = {
4632                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4633                 (void *)&cmd_tx_vlan_reset_reset,
4634                 (void *)&cmd_tx_vlan_reset_portid,
4635                 NULL,
4636         },
4637 };
4638
4639
4640 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4641 struct cmd_csum_result {
4642         cmdline_fixed_string_t csum;
4643         cmdline_fixed_string_t mode;
4644         cmdline_fixed_string_t proto;
4645         cmdline_fixed_string_t hwsw;
4646         portid_t port_id;
4647 };
4648
4649 static void
4650 csum_show(int port_id)
4651 {
4652         struct rte_eth_dev_info dev_info;
4653         uint64_t tx_offloads;
4654         int ret;
4655
4656         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4657         printf("Parse tunnel is %s\n",
4658                 (ports[port_id].parse_tunnel) ? "on" : "off");
4659         printf("IP checksum offload is %s\n",
4660                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4661         printf("UDP checksum offload is %s\n",
4662                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4663         printf("TCP checksum offload is %s\n",
4664                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4665         printf("SCTP checksum offload is %s\n",
4666                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4667         printf("Outer-Ip checksum offload is %s\n",
4668                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4669         printf("Outer-Udp checksum offload is %s\n",
4670                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4671
4672         /* display warnings if configuration is not supported by the NIC */
4673         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4674         if (ret != 0)
4675                 return;
4676
4677         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4678                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4679                 fprintf(stderr,
4680                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4681                         port_id);
4682         }
4683         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4684                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4685                 fprintf(stderr,
4686                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4687                         port_id);
4688         }
4689         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4690                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4691                 fprintf(stderr,
4692                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4693                         port_id);
4694         }
4695         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4696                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4697                 fprintf(stderr,
4698                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4699                         port_id);
4700         }
4701         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4702                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4703                 fprintf(stderr,
4704                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4705                         port_id);
4706         }
4707         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4708                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4709                         == 0) {
4710                 fprintf(stderr,
4711                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4712                         port_id);
4713         }
4714 }
4715
4716 static void
4717 cmd_config_queue_tx_offloads(struct rte_port *port)
4718 {
4719         int k;
4720
4721         /* Apply queue tx offloads configuration */
4722         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4723                 port->txq[k].conf.offloads =
4724                         port->dev_conf.txmode.offloads;
4725 }
4726
4727 static void
4728 cmd_csum_parsed(void *parsed_result,
4729                        __rte_unused struct cmdline *cl,
4730                        __rte_unused void *data)
4731 {
4732         struct cmd_csum_result *res = parsed_result;
4733         int hw = 0;
4734         uint64_t csum_offloads = 0;
4735         struct rte_eth_dev_info dev_info;
4736         int ret;
4737
4738         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4739                 fprintf(stderr, "invalid port %d\n", res->port_id);
4740                 return;
4741         }
4742         if (!port_is_stopped(res->port_id)) {
4743                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4744                 return;
4745         }
4746
4747         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4748         if (ret != 0)
4749                 return;
4750
4751         if (!strcmp(res->mode, "set")) {
4752
4753                 if (!strcmp(res->hwsw, "hw"))
4754                         hw = 1;
4755
4756                 if (!strcmp(res->proto, "ip")) {
4757                         if (hw == 0 || (dev_info.tx_offload_capa &
4758                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4759                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4760                         } else {
4761                                 fprintf(stderr,
4762                                         "IP checksum offload is not supported by port %u\n",
4763                                         res->port_id);
4764                         }
4765                 } else if (!strcmp(res->proto, "udp")) {
4766                         if (hw == 0 || (dev_info.tx_offload_capa &
4767                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4768                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4769                         } else {
4770                                 fprintf(stderr,
4771                                         "UDP checksum offload is not supported by port %u\n",
4772                                         res->port_id);
4773                         }
4774                 } else if (!strcmp(res->proto, "tcp")) {
4775                         if (hw == 0 || (dev_info.tx_offload_capa &
4776                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4777                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4778                         } else {
4779                                 fprintf(stderr,
4780                                         "TCP checksum offload is not supported by port %u\n",
4781                                         res->port_id);
4782                         }
4783                 } else if (!strcmp(res->proto, "sctp")) {
4784                         if (hw == 0 || (dev_info.tx_offload_capa &
4785                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4786                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4787                         } else {
4788                                 fprintf(stderr,
4789                                         "SCTP checksum offload is not supported by port %u\n",
4790                                         res->port_id);
4791                         }
4792                 } else if (!strcmp(res->proto, "outer-ip")) {
4793                         if (hw == 0 || (dev_info.tx_offload_capa &
4794                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4795                                 csum_offloads |=
4796                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4797                         } else {
4798                                 fprintf(stderr,
4799                                         "Outer IP checksum offload is not supported by port %u\n",
4800                                         res->port_id);
4801                         }
4802                 } else if (!strcmp(res->proto, "outer-udp")) {
4803                         if (hw == 0 || (dev_info.tx_offload_capa &
4804                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4805                                 csum_offloads |=
4806                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4807                         } else {
4808                                 fprintf(stderr,
4809                                         "Outer UDP checksum offload is not supported by port %u\n",
4810                                         res->port_id);
4811                         }
4812                 }
4813
4814                 if (hw) {
4815                         ports[res->port_id].dev_conf.txmode.offloads |=
4816                                                         csum_offloads;
4817                 } else {
4818                         ports[res->port_id].dev_conf.txmode.offloads &=
4819                                                         (~csum_offloads);
4820                 }
4821                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4822         }
4823         csum_show(res->port_id);
4824
4825         cmd_reconfig_device_queue(res->port_id, 1, 1);
4826 }
4827
4828 static cmdline_parse_token_string_t cmd_csum_csum =
4829         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4830                                 csum, "csum");
4831 static cmdline_parse_token_string_t cmd_csum_mode =
4832         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4833                                 mode, "set");
4834 static cmdline_parse_token_string_t cmd_csum_proto =
4835         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4836                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4837 static cmdline_parse_token_string_t cmd_csum_hwsw =
4838         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4839                                 hwsw, "hw#sw");
4840 static cmdline_parse_token_num_t cmd_csum_portid =
4841         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4842                                 port_id, RTE_UINT16);
4843
4844 static cmdline_parse_inst_t cmd_csum_set = {
4845         .f = cmd_csum_parsed,
4846         .data = NULL,
4847         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4848                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4849                 "using csum forward engine",
4850         .tokens = {
4851                 (void *)&cmd_csum_csum,
4852                 (void *)&cmd_csum_mode,
4853                 (void *)&cmd_csum_proto,
4854                 (void *)&cmd_csum_hwsw,
4855                 (void *)&cmd_csum_portid,
4856                 NULL,
4857         },
4858 };
4859
4860 static cmdline_parse_token_string_t cmd_csum_mode_show =
4861         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4862                                 mode, "show");
4863
4864 static cmdline_parse_inst_t cmd_csum_show = {
4865         .f = cmd_csum_parsed,
4866         .data = NULL,
4867         .help_str = "csum show <port_id>: Show checksum offload configuration",
4868         .tokens = {
4869                 (void *)&cmd_csum_csum,
4870                 (void *)&cmd_csum_mode_show,
4871                 (void *)&cmd_csum_portid,
4872                 NULL,
4873         },
4874 };
4875
4876 /* Enable/disable tunnel parsing */
4877 struct cmd_csum_tunnel_result {
4878         cmdline_fixed_string_t csum;
4879         cmdline_fixed_string_t parse;
4880         cmdline_fixed_string_t onoff;
4881         portid_t port_id;
4882 };
4883
4884 static void
4885 cmd_csum_tunnel_parsed(void *parsed_result,
4886                        __rte_unused struct cmdline *cl,
4887                        __rte_unused void *data)
4888 {
4889         struct cmd_csum_tunnel_result *res = parsed_result;
4890
4891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4892                 return;
4893
4894         if (!strcmp(res->onoff, "on"))
4895                 ports[res->port_id].parse_tunnel = 1;
4896         else
4897                 ports[res->port_id].parse_tunnel = 0;
4898
4899         csum_show(res->port_id);
4900 }
4901
4902 static cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4903         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4904                                 csum, "csum");
4905 static cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4906         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4907                                 parse, "parse-tunnel");
4908 static cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4909         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4910                                 onoff, "on#off");
4911 static cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4912         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4913                                 port_id, RTE_UINT16);
4914
4915 static cmdline_parse_inst_t cmd_csum_tunnel = {
4916         .f = cmd_csum_tunnel_parsed,
4917         .data = NULL,
4918         .help_str = "csum parse-tunnel on|off <port_id>: "
4919                 "Enable/Disable parsing of tunnels for csum engine",
4920         .tokens = {
4921                 (void *)&cmd_csum_tunnel_csum,
4922                 (void *)&cmd_csum_tunnel_parse,
4923                 (void *)&cmd_csum_tunnel_onoff,
4924                 (void *)&cmd_csum_tunnel_portid,
4925                 NULL,
4926         },
4927 };
4928
4929 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4930 struct cmd_tso_set_result {
4931         cmdline_fixed_string_t tso;
4932         cmdline_fixed_string_t mode;
4933         uint16_t tso_segsz;
4934         portid_t port_id;
4935 };
4936
4937 static void
4938 cmd_tso_set_parsed(void *parsed_result,
4939                        __rte_unused struct cmdline *cl,
4940                        __rte_unused void *data)
4941 {
4942         struct cmd_tso_set_result *res = parsed_result;
4943         struct rte_eth_dev_info dev_info;
4944         int ret;
4945
4946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4947                 return;
4948         if (!port_is_stopped(res->port_id)) {
4949                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4950                 return;
4951         }
4952
4953         if (!strcmp(res->mode, "set"))
4954                 ports[res->port_id].tso_segsz = res->tso_segsz;
4955
4956         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4957         if (ret != 0)
4958                 return;
4959
4960         if ((ports[res->port_id].tso_segsz != 0) &&
4961                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4962                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4963                         res->port_id);
4964                 return;
4965         }
4966
4967         if (ports[res->port_id].tso_segsz == 0) {
4968                 ports[res->port_id].dev_conf.txmode.offloads &=
4969                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4970                 printf("TSO for non-tunneled packets is disabled\n");
4971         } else {
4972                 ports[res->port_id].dev_conf.txmode.offloads |=
4973                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4974                 printf("TSO segment size for non-tunneled packets is %d\n",
4975                         ports[res->port_id].tso_segsz);
4976         }
4977         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4978
4979         /* display warnings if configuration is not supported by the NIC */
4980         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4981         if (ret != 0)
4982                 return;
4983
4984         if ((ports[res->port_id].tso_segsz != 0) &&
4985                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4986                 fprintf(stderr,
4987                         "Warning: TSO enabled but not supported by port %d\n",
4988                         res->port_id);
4989         }
4990
4991         cmd_reconfig_device_queue(res->port_id, 1, 1);
4992 }
4993
4994 static cmdline_parse_token_string_t cmd_tso_set_tso =
4995         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4996                                 tso, "tso");
4997 static cmdline_parse_token_string_t cmd_tso_set_mode =
4998         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4999                                 mode, "set");
5000 static cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
5001         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
5002                                 tso_segsz, RTE_UINT16);
5003 static cmdline_parse_token_num_t cmd_tso_set_portid =
5004         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
5005                                 port_id, RTE_UINT16);
5006
5007 static cmdline_parse_inst_t cmd_tso_set = {
5008         .f = cmd_tso_set_parsed,
5009         .data = NULL,
5010         .help_str = "tso set <tso_segsz> <port_id>: "
5011                 "Set TSO segment size of non-tunneled packets for csum engine "
5012                 "(0 to disable)",
5013         .tokens = {
5014                 (void *)&cmd_tso_set_tso,
5015                 (void *)&cmd_tso_set_mode,
5016                 (void *)&cmd_tso_set_tso_segsz,
5017                 (void *)&cmd_tso_set_portid,
5018                 NULL,
5019         },
5020 };
5021
5022 static cmdline_parse_token_string_t cmd_tso_show_mode =
5023         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
5024                                 mode, "show");
5025
5026
5027 static cmdline_parse_inst_t cmd_tso_show = {
5028         .f = cmd_tso_set_parsed,
5029         .data = NULL,
5030         .help_str = "tso show <port_id>: "
5031                 "Show TSO segment size of non-tunneled packets for csum engine",
5032         .tokens = {
5033                 (void *)&cmd_tso_set_tso,
5034                 (void *)&cmd_tso_show_mode,
5035                 (void *)&cmd_tso_set_portid,
5036                 NULL,
5037         },
5038 };
5039
5040 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5041 struct cmd_tunnel_tso_set_result {
5042         cmdline_fixed_string_t tso;
5043         cmdline_fixed_string_t mode;
5044         uint16_t tso_segsz;
5045         portid_t port_id;
5046 };
5047
5048 static struct rte_eth_dev_info
5049 check_tunnel_tso_nic_support(portid_t port_id)
5050 {
5051         struct rte_eth_dev_info dev_info;
5052
5053         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5054                 return dev_info;
5055
5056         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5057                 fprintf(stderr,
5058                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5059                         port_id);
5060         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5061                 fprintf(stderr,
5062                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5063                         port_id);
5064         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5065                 fprintf(stderr,
5066                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5067                         port_id);
5068         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5069                 fprintf(stderr,
5070                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5071                         port_id);
5072         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5073                 fprintf(stderr,
5074                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5075                         port_id);
5076         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5077                 fprintf(stderr,
5078                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5079                         port_id);
5080         return dev_info;
5081 }
5082
5083 static void
5084 cmd_tunnel_tso_set_parsed(void *parsed_result,
5085                           __rte_unused struct cmdline *cl,
5086                           __rte_unused void *data)
5087 {
5088         struct cmd_tunnel_tso_set_result *res = parsed_result;
5089         struct rte_eth_dev_info dev_info;
5090
5091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5092                 return;
5093         if (!port_is_stopped(res->port_id)) {
5094                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5095                 return;
5096         }
5097
5098         if (!strcmp(res->mode, "set"))
5099                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5100
5101         dev_info = check_tunnel_tso_nic_support(res->port_id);
5102         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5103                 ports[res->port_id].dev_conf.txmode.offloads &=
5104                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5105                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5106                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5107                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5108                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5109                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5110                 printf("TSO for tunneled packets is disabled\n");
5111         } else {
5112                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5113                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5114                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5115                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5116                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5117                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5118
5119                 ports[res->port_id].dev_conf.txmode.offloads |=
5120                         (tso_offloads & dev_info.tx_offload_capa);
5121                 printf("TSO segment size for tunneled packets is %d\n",
5122                         ports[res->port_id].tunnel_tso_segsz);
5123
5124                 /* Below conditions are needed to make it work:
5125                  * (1) tunnel TSO is supported by the NIC;
5126                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5127                  * are recognized;
5128                  * (3) for tunneled pkts with outer L3 of IPv4,
5129                  * "csum set outer-ip" must be set to hw, because after tso,
5130                  * total_len of outer IP header is changed, and the checksum
5131                  * of outer IP header calculated by sw should be wrong; that
5132                  * is not necessary for IPv6 tunneled pkts because there's no
5133                  * checksum in IP header anymore.
5134                  */
5135
5136                 if (!ports[res->port_id].parse_tunnel)
5137                         fprintf(stderr,
5138                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5139                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5140                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5141                         fprintf(stderr,
5142                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5143         }
5144
5145         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5146         cmd_reconfig_device_queue(res->port_id, 1, 1);
5147 }
5148
5149 static cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5150         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5151                                 tso, "tunnel_tso");
5152 static cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5153         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5154                                 mode, "set");
5155 static cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5156         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5157                                 tso_segsz, RTE_UINT16);
5158 static cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5159         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5160                                 port_id, RTE_UINT16);
5161
5162 static cmdline_parse_inst_t cmd_tunnel_tso_set = {
5163         .f = cmd_tunnel_tso_set_parsed,
5164         .data = NULL,
5165         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5166                 "Set TSO segment size of tunneled packets for csum engine "
5167                 "(0 to disable)",
5168         .tokens = {
5169                 (void *)&cmd_tunnel_tso_set_tso,
5170                 (void *)&cmd_tunnel_tso_set_mode,
5171                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5172                 (void *)&cmd_tunnel_tso_set_portid,
5173                 NULL,
5174         },
5175 };
5176
5177 static cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5178         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5179                                 mode, "show");
5180
5181
5182 static cmdline_parse_inst_t cmd_tunnel_tso_show = {
5183         .f = cmd_tunnel_tso_set_parsed,
5184         .data = NULL,
5185         .help_str = "tunnel_tso show <port_id> "
5186                 "Show TSO segment size of tunneled packets for csum engine",
5187         .tokens = {
5188                 (void *)&cmd_tunnel_tso_set_tso,
5189                 (void *)&cmd_tunnel_tso_show_mode,
5190                 (void *)&cmd_tunnel_tso_set_portid,
5191                 NULL,
5192         },
5193 };
5194
5195 #ifdef RTE_LIB_GRO
5196 /* *** SET GRO FOR A PORT *** */
5197 struct cmd_gro_enable_result {
5198         cmdline_fixed_string_t cmd_set;
5199         cmdline_fixed_string_t cmd_port;
5200         cmdline_fixed_string_t cmd_keyword;
5201         cmdline_fixed_string_t cmd_onoff;
5202         portid_t cmd_pid;
5203 };
5204
5205 static void
5206 cmd_gro_enable_parsed(void *parsed_result,
5207                 __rte_unused struct cmdline *cl,
5208                 __rte_unused void *data)
5209 {
5210         struct cmd_gro_enable_result *res;
5211
5212         res = parsed_result;
5213         if (!strcmp(res->cmd_keyword, "gro"))
5214                 setup_gro(res->cmd_onoff, res->cmd_pid);
5215 }
5216
5217 static cmdline_parse_token_string_t cmd_gro_enable_set =
5218         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5219                         cmd_set, "set");
5220 static cmdline_parse_token_string_t cmd_gro_enable_port =
5221         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5222                         cmd_keyword, "port");
5223 static cmdline_parse_token_num_t cmd_gro_enable_pid =
5224         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5225                         cmd_pid, RTE_UINT16);
5226 static cmdline_parse_token_string_t cmd_gro_enable_keyword =
5227         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5228                         cmd_keyword, "gro");
5229 static cmdline_parse_token_string_t cmd_gro_enable_onoff =
5230         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5231                         cmd_onoff, "on#off");
5232
5233 static cmdline_parse_inst_t cmd_gro_enable = {
5234         .f = cmd_gro_enable_parsed,
5235         .data = NULL,
5236         .help_str = "set port <port_id> gro on|off",
5237         .tokens = {
5238                 (void *)&cmd_gro_enable_set,
5239                 (void *)&cmd_gro_enable_port,
5240                 (void *)&cmd_gro_enable_pid,
5241                 (void *)&cmd_gro_enable_keyword,
5242                 (void *)&cmd_gro_enable_onoff,
5243                 NULL,
5244         },
5245 };
5246
5247 /* *** DISPLAY GRO CONFIGURATION *** */
5248 struct cmd_gro_show_result {
5249         cmdline_fixed_string_t cmd_show;
5250         cmdline_fixed_string_t cmd_port;
5251         cmdline_fixed_string_t cmd_keyword;
5252         portid_t cmd_pid;
5253 };
5254
5255 static void
5256 cmd_gro_show_parsed(void *parsed_result,
5257                 __rte_unused struct cmdline *cl,
5258                 __rte_unused void *data)
5259 {
5260         struct cmd_gro_show_result *res;
5261
5262         res = parsed_result;
5263         if (!strcmp(res->cmd_keyword, "gro"))
5264                 show_gro(res->cmd_pid);
5265 }
5266
5267 static cmdline_parse_token_string_t cmd_gro_show_show =
5268         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5269                         cmd_show, "show");
5270 static cmdline_parse_token_string_t cmd_gro_show_port =
5271         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5272                         cmd_port, "port");
5273 static cmdline_parse_token_num_t cmd_gro_show_pid =
5274         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5275                         cmd_pid, RTE_UINT16);
5276 static cmdline_parse_token_string_t cmd_gro_show_keyword =
5277         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5278                         cmd_keyword, "gro");
5279
5280 static cmdline_parse_inst_t cmd_gro_show = {
5281         .f = cmd_gro_show_parsed,
5282         .data = NULL,
5283         .help_str = "show port <port_id> gro",
5284         .tokens = {
5285                 (void *)&cmd_gro_show_show,
5286                 (void *)&cmd_gro_show_port,
5287                 (void *)&cmd_gro_show_pid,
5288                 (void *)&cmd_gro_show_keyword,
5289                 NULL,
5290         },
5291 };
5292
5293 /* *** SET FLUSH CYCLES FOR GRO *** */
5294 struct cmd_gro_flush_result {
5295         cmdline_fixed_string_t cmd_set;
5296         cmdline_fixed_string_t cmd_keyword;
5297         cmdline_fixed_string_t cmd_flush;
5298         uint8_t cmd_cycles;
5299 };
5300
5301 static void
5302 cmd_gro_flush_parsed(void *parsed_result,
5303                 __rte_unused struct cmdline *cl,
5304                 __rte_unused void *data)
5305 {
5306         struct cmd_gro_flush_result *res;
5307
5308         res = parsed_result;
5309         if ((!strcmp(res->cmd_keyword, "gro")) &&
5310                         (!strcmp(res->cmd_flush, "flush")))
5311                 setup_gro_flush_cycles(res->cmd_cycles);
5312 }
5313
5314 static cmdline_parse_token_string_t cmd_gro_flush_set =
5315         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5316                         cmd_set, "set");
5317 static cmdline_parse_token_string_t cmd_gro_flush_keyword =
5318         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5319                         cmd_keyword, "gro");
5320 static cmdline_parse_token_string_t cmd_gro_flush_flush =
5321         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5322                         cmd_flush, "flush");
5323 static cmdline_parse_token_num_t cmd_gro_flush_cycles =
5324         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5325                         cmd_cycles, RTE_UINT8);
5326
5327 static cmdline_parse_inst_t cmd_gro_flush = {
5328         .f = cmd_gro_flush_parsed,
5329         .data = NULL,
5330         .help_str = "set gro flush <cycles>",
5331         .tokens = {
5332                 (void *)&cmd_gro_flush_set,
5333                 (void *)&cmd_gro_flush_keyword,
5334                 (void *)&cmd_gro_flush_flush,
5335                 (void *)&cmd_gro_flush_cycles,
5336                 NULL,
5337         },
5338 };
5339 #endif /* RTE_LIB_GRO */
5340
5341 #ifdef RTE_LIB_GSO
5342 /* *** ENABLE/DISABLE GSO *** */
5343 struct cmd_gso_enable_result {
5344         cmdline_fixed_string_t cmd_set;
5345         cmdline_fixed_string_t cmd_port;
5346         cmdline_fixed_string_t cmd_keyword;
5347         cmdline_fixed_string_t cmd_mode;
5348         portid_t cmd_pid;
5349 };
5350
5351 static void
5352 cmd_gso_enable_parsed(void *parsed_result,
5353                 __rte_unused struct cmdline *cl,
5354                 __rte_unused void *data)
5355 {
5356         struct cmd_gso_enable_result *res;
5357
5358         res = parsed_result;
5359         if (!strcmp(res->cmd_keyword, "gso"))
5360                 setup_gso(res->cmd_mode, res->cmd_pid);
5361 }
5362
5363 static cmdline_parse_token_string_t cmd_gso_enable_set =
5364         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5365                         cmd_set, "set");
5366 static cmdline_parse_token_string_t cmd_gso_enable_port =
5367         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5368                         cmd_port, "port");
5369 static cmdline_parse_token_string_t cmd_gso_enable_keyword =
5370         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5371                         cmd_keyword, "gso");
5372 static cmdline_parse_token_string_t cmd_gso_enable_mode =
5373         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5374                         cmd_mode, "on#off");
5375 static cmdline_parse_token_num_t cmd_gso_enable_pid =
5376         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5377                         cmd_pid, RTE_UINT16);
5378
5379 static cmdline_parse_inst_t cmd_gso_enable = {
5380         .f = cmd_gso_enable_parsed,
5381         .data = NULL,
5382         .help_str = "set port <port_id> gso on|off",
5383         .tokens = {
5384                 (void *)&cmd_gso_enable_set,
5385                 (void *)&cmd_gso_enable_port,
5386                 (void *)&cmd_gso_enable_pid,
5387                 (void *)&cmd_gso_enable_keyword,
5388                 (void *)&cmd_gso_enable_mode,
5389                 NULL,
5390         },
5391 };
5392
5393 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5394 struct cmd_gso_size_result {
5395         cmdline_fixed_string_t cmd_set;
5396         cmdline_fixed_string_t cmd_keyword;
5397         cmdline_fixed_string_t cmd_segsz;
5398         uint16_t cmd_size;
5399 };
5400
5401 static void
5402 cmd_gso_size_parsed(void *parsed_result,
5403                        __rte_unused struct cmdline *cl,
5404                        __rte_unused void *data)
5405 {
5406         struct cmd_gso_size_result *res = parsed_result;
5407
5408         if (test_done == 0) {
5409                 fprintf(stderr,
5410                         "Before setting GSO segsz, please first stop forwarding\n");
5411                 return;
5412         }
5413
5414         if (!strcmp(res->cmd_keyword, "gso") &&
5415                         !strcmp(res->cmd_segsz, "segsz")) {
5416                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5417                         fprintf(stderr,
5418                                 "gso_size should be larger than %zu. Please input a legal value\n",
5419                                 RTE_GSO_SEG_SIZE_MIN);
5420                 else
5421                         gso_max_segment_size = res->cmd_size;
5422         }
5423 }
5424
5425 static cmdline_parse_token_string_t cmd_gso_size_set =
5426         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5427                                 cmd_set, "set");
5428 static cmdline_parse_token_string_t cmd_gso_size_keyword =
5429         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5430                                 cmd_keyword, "gso");
5431 static cmdline_parse_token_string_t cmd_gso_size_segsz =
5432         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5433                                 cmd_segsz, "segsz");
5434 static cmdline_parse_token_num_t cmd_gso_size_size =
5435         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5436                                 cmd_size, RTE_UINT16);
5437
5438 static cmdline_parse_inst_t cmd_gso_size = {
5439         .f = cmd_gso_size_parsed,
5440         .data = NULL,
5441         .help_str = "set gso segsz <length>",
5442         .tokens = {
5443                 (void *)&cmd_gso_size_set,
5444                 (void *)&cmd_gso_size_keyword,
5445                 (void *)&cmd_gso_size_segsz,
5446                 (void *)&cmd_gso_size_size,
5447                 NULL,
5448         },
5449 };
5450
5451 /* *** SHOW GSO CONFIGURATION *** */
5452 struct cmd_gso_show_result {
5453         cmdline_fixed_string_t cmd_show;
5454         cmdline_fixed_string_t cmd_port;
5455         cmdline_fixed_string_t cmd_keyword;
5456         portid_t cmd_pid;
5457 };
5458
5459 static void
5460 cmd_gso_show_parsed(void *parsed_result,
5461                        __rte_unused struct cmdline *cl,
5462                        __rte_unused void *data)
5463 {
5464         struct cmd_gso_show_result *res = parsed_result;
5465
5466         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5467                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5468                 return;
5469         }
5470         if (!strcmp(res->cmd_keyword, "gso")) {
5471                 if (gso_ports[res->cmd_pid].enable) {
5472                         printf("Max GSO'd packet size: %uB\n"
5473                                         "Supported GSO types: TCP/IPv4, "
5474                                         "UDP/IPv4, VxLAN with inner "
5475                                         "TCP/IPv4 packet, GRE with inner "
5476                                         "TCP/IPv4 packet\n",
5477                                         gso_max_segment_size);
5478                 } else
5479                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5480         }
5481 }
5482
5483 static cmdline_parse_token_string_t cmd_gso_show_show =
5484 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5485                 cmd_show, "show");
5486 static cmdline_parse_token_string_t cmd_gso_show_port =
5487 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5488                 cmd_port, "port");
5489 static cmdline_parse_token_string_t cmd_gso_show_keyword =
5490         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5491                                 cmd_keyword, "gso");
5492 static cmdline_parse_token_num_t cmd_gso_show_pid =
5493         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5494                                 cmd_pid, RTE_UINT16);
5495
5496 static cmdline_parse_inst_t cmd_gso_show = {
5497         .f = cmd_gso_show_parsed,
5498         .data = NULL,
5499         .help_str = "show port <port_id> gso",
5500         .tokens = {
5501                 (void *)&cmd_gso_show_show,
5502                 (void *)&cmd_gso_show_port,
5503                 (void *)&cmd_gso_show_pid,
5504                 (void *)&cmd_gso_show_keyword,
5505                 NULL,
5506         },
5507 };
5508 #endif /* RTE_LIB_GSO */
5509
5510 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5511 struct cmd_set_flush_rx {
5512         cmdline_fixed_string_t set;
5513         cmdline_fixed_string_t flush_rx;
5514         cmdline_fixed_string_t mode;
5515 };
5516
5517 static void
5518 cmd_set_flush_rx_parsed(void *parsed_result,
5519                 __rte_unused struct cmdline *cl,
5520                 __rte_unused void *data)
5521 {
5522         struct cmd_set_flush_rx *res = parsed_result;
5523
5524         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5525                 printf("multi-process doesn't support to flush Rx queues.\n");
5526                 return;
5527         }
5528
5529         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5530 }
5531
5532 static cmdline_parse_token_string_t cmd_setflushrx_set =
5533         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5534                         set, "set");
5535 static cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5537                         flush_rx, "flush_rx");
5538 static cmdline_parse_token_string_t cmd_setflushrx_mode =
5539         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5540                         mode, "on#off");
5541
5542
5543 static cmdline_parse_inst_t cmd_set_flush_rx = {
5544         .f = cmd_set_flush_rx_parsed,
5545         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5546         .data = NULL,
5547         .tokens = {
5548                 (void *)&cmd_setflushrx_set,
5549                 (void *)&cmd_setflushrx_flush_rx,
5550                 (void *)&cmd_setflushrx_mode,
5551                 NULL,
5552         },
5553 };
5554
5555 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5556 struct cmd_set_link_check {
5557         cmdline_fixed_string_t set;
5558         cmdline_fixed_string_t link_check;
5559         cmdline_fixed_string_t mode;
5560 };
5561
5562 static void
5563 cmd_set_link_check_parsed(void *parsed_result,
5564                 __rte_unused struct cmdline *cl,
5565                 __rte_unused void *data)
5566 {
5567         struct cmd_set_link_check *res = parsed_result;
5568         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5569 }
5570
5571 static cmdline_parse_token_string_t cmd_setlinkcheck_set =
5572         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5573                         set, "set");
5574 static cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5575         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5576                         link_check, "link_check");
5577 static cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5578         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5579                         mode, "on#off");
5580
5581
5582 static cmdline_parse_inst_t cmd_set_link_check = {
5583         .f = cmd_set_link_check_parsed,
5584         .help_str = "set link_check on|off: Enable/Disable link status check "
5585                     "when starting/stopping a port",
5586         .data = NULL,
5587         .tokens = {
5588                 (void *)&cmd_setlinkcheck_set,
5589                 (void *)&cmd_setlinkcheck_link_check,
5590                 (void *)&cmd_setlinkcheck_mode,
5591                 NULL,
5592         },
5593 };
5594
5595 /* *** SET NIC BYPASS MODE *** */
5596 struct cmd_set_bypass_mode_result {
5597         cmdline_fixed_string_t set;
5598         cmdline_fixed_string_t bypass;
5599         cmdline_fixed_string_t mode;
5600         cmdline_fixed_string_t value;
5601         portid_t port_id;
5602 };
5603
5604 static void
5605 cmd_set_bypass_mode_parsed(void *parsed_result,
5606                 __rte_unused struct cmdline *cl,
5607                 __rte_unused void *data)
5608 {
5609         struct cmd_set_bypass_mode_result *res = parsed_result;
5610         portid_t port_id = res->port_id;
5611         int32_t rc = -EINVAL;
5612
5613 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5614         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5615
5616         if (!strcmp(res->value, "bypass"))
5617                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5618         else if (!strcmp(res->value, "isolate"))
5619                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5620         else
5621                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5622
5623         /* Set the bypass mode for the relevant port. */
5624         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5625 #endif
5626         if (rc != 0)
5627                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5628                         port_id);
5629 }
5630
5631 static cmdline_parse_token_string_t cmd_setbypass_mode_set =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5633                         set, "set");
5634 static cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5636                         bypass, "bypass");
5637 static cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5639                         mode, "mode");
5640 static cmdline_parse_token_string_t cmd_setbypass_mode_value =
5641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5642                         value, "normal#bypass#isolate");
5643 static cmdline_parse_token_num_t cmd_setbypass_mode_port =
5644         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5645                                 port_id, RTE_UINT16);
5646
5647 static cmdline_parse_inst_t cmd_set_bypass_mode = {
5648         .f = cmd_set_bypass_mode_parsed,
5649         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5650                     "Set the NIC bypass mode for port_id",
5651         .data = NULL,
5652         .tokens = {
5653                 (void *)&cmd_setbypass_mode_set,
5654                 (void *)&cmd_setbypass_mode_bypass,
5655                 (void *)&cmd_setbypass_mode_mode,
5656                 (void *)&cmd_setbypass_mode_value,
5657                 (void *)&cmd_setbypass_mode_port,
5658                 NULL,
5659         },
5660 };
5661
5662 /* *** SET NIC BYPASS EVENT *** */
5663 struct cmd_set_bypass_event_result {
5664         cmdline_fixed_string_t set;
5665         cmdline_fixed_string_t bypass;
5666         cmdline_fixed_string_t event;
5667         cmdline_fixed_string_t event_value;
5668         cmdline_fixed_string_t mode;
5669         cmdline_fixed_string_t mode_value;
5670         portid_t port_id;
5671 };
5672
5673 static void
5674 cmd_set_bypass_event_parsed(void *parsed_result,
5675                 __rte_unused struct cmdline *cl,
5676                 __rte_unused void *data)
5677 {
5678         int32_t rc = -EINVAL;
5679         struct cmd_set_bypass_event_result *res = parsed_result;
5680         portid_t port_id = res->port_id;
5681
5682 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5683         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5684         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5685
5686         if (!strcmp(res->event_value, "timeout"))
5687                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5688         else if (!strcmp(res->event_value, "os_on"))
5689                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5690         else if (!strcmp(res->event_value, "os_off"))
5691                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5692         else if (!strcmp(res->event_value, "power_on"))
5693                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5694         else if (!strcmp(res->event_value, "power_off"))
5695                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5696         else
5697                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5698
5699         if (!strcmp(res->mode_value, "bypass"))
5700                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5701         else if (!strcmp(res->mode_value, "isolate"))
5702                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5703         else
5704                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5705
5706         /* Set the watchdog timeout. */
5707         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5708
5709                 rc = -EINVAL;
5710                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5711                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5712                                                            bypass_timeout);
5713                 }
5714                 if (rc != 0) {
5715                         fprintf(stderr,
5716                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5717                                 bypass_timeout, port_id, rc);
5718                 }
5719         }
5720
5721         /* Set the bypass event to transition to bypass mode. */
5722         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5723                                               bypass_mode);
5724 #endif
5725
5726         if (rc != 0)
5727                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5728                         port_id);
5729 }
5730
5731 static cmdline_parse_token_string_t cmd_setbypass_event_set =
5732         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5733                         set, "set");
5734 static cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5735         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5736                         bypass, "bypass");
5737 static cmdline_parse_token_string_t cmd_setbypass_event_event =
5738         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5739                         event, "event");
5740 static cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5741         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5742                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5743 static cmdline_parse_token_string_t cmd_setbypass_event_mode =
5744         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5745                         mode, "mode");
5746 static cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5747         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5748                         mode_value, "normal#bypass#isolate");
5749 static cmdline_parse_token_num_t cmd_setbypass_event_port =
5750         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5751                                 port_id, RTE_UINT16);
5752
5753 static cmdline_parse_inst_t cmd_set_bypass_event = {
5754         .f = cmd_set_bypass_event_parsed,
5755         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5756                 "power_off mode normal|bypass|isolate <port_id>: "
5757                 "Set the NIC bypass event mode for port_id",
5758         .data = NULL,
5759         .tokens = {
5760                 (void *)&cmd_setbypass_event_set,
5761                 (void *)&cmd_setbypass_event_bypass,
5762                 (void *)&cmd_setbypass_event_event,
5763                 (void *)&cmd_setbypass_event_event_value,
5764                 (void *)&cmd_setbypass_event_mode,
5765                 (void *)&cmd_setbypass_event_mode_value,
5766                 (void *)&cmd_setbypass_event_port,
5767                 NULL,
5768         },
5769 };
5770
5771
5772 /* *** SET NIC BYPASS TIMEOUT *** */
5773 struct cmd_set_bypass_timeout_result {
5774         cmdline_fixed_string_t set;
5775         cmdline_fixed_string_t bypass;
5776         cmdline_fixed_string_t timeout;
5777         cmdline_fixed_string_t value;
5778 };
5779
5780 static void
5781 cmd_set_bypass_timeout_parsed(void *parsed_result,
5782                 __rte_unused struct cmdline *cl,
5783                 __rte_unused void *data)
5784 {
5785         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5786
5787 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5788         if (!strcmp(res->value, "1.5"))
5789                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5790         else if (!strcmp(res->value, "2"))
5791                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5792         else if (!strcmp(res->value, "3"))
5793                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5794         else if (!strcmp(res->value, "4"))
5795                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5796         else if (!strcmp(res->value, "8"))
5797                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5798         else if (!strcmp(res->value, "16"))
5799                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5800         else if (!strcmp(res->value, "32"))
5801                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5802         else
5803                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5804 #endif
5805 }
5806
5807 static cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5808         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5809                         set, "set");
5810 static cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5811         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5812                         bypass, "bypass");
5813 static cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5814         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5815                         timeout, "timeout");
5816 static cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5817         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5818                         value, "0#1.5#2#3#4#8#16#32");
5819
5820 static cmdline_parse_inst_t cmd_set_bypass_timeout = {
5821         .f = cmd_set_bypass_timeout_parsed,
5822         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5823                 "Set the NIC bypass watchdog timeout in seconds",
5824         .data = NULL,
5825         .tokens = {
5826                 (void *)&cmd_setbypass_timeout_set,
5827                 (void *)&cmd_setbypass_timeout_bypass,
5828                 (void *)&cmd_setbypass_timeout_timeout,
5829                 (void *)&cmd_setbypass_timeout_value,
5830                 NULL,
5831         },
5832 };
5833
5834 /* *** SHOW NIC BYPASS MODE *** */
5835 struct cmd_show_bypass_config_result {
5836         cmdline_fixed_string_t show;
5837         cmdline_fixed_string_t bypass;
5838         cmdline_fixed_string_t config;
5839         portid_t port_id;
5840 };
5841
5842 static void
5843 cmd_show_bypass_config_parsed(void *parsed_result,
5844                 __rte_unused struct cmdline *cl,
5845                 __rte_unused void *data)
5846 {
5847         struct cmd_show_bypass_config_result *res = parsed_result;
5848         portid_t port_id = res->port_id;
5849         int rc = -EINVAL;
5850 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5851         uint32_t event_mode;
5852         uint32_t bypass_mode;
5853         uint32_t timeout = bypass_timeout;
5854         unsigned int i;
5855
5856         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5857                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5858         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5859                 {"UNKNOWN", "normal", "bypass", "isolate"};
5860         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5861                 "NONE",
5862                 "OS/board on",
5863                 "power supply on",
5864                 "OS/board off",
5865                 "power supply off",
5866                 "timeout"};
5867
5868         /* Display the bypass mode.*/
5869         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5870                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5871                         port_id);
5872                 return;
5873         }
5874         else {
5875                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5876                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5877
5878                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5879         }
5880
5881         /* Display the bypass timeout.*/
5882         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5883                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5884
5885         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5886
5887         /* Display the bypass events and associated modes. */
5888         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5889
5890                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5891                         fprintf(stderr,
5892                                 "\tFailed to get bypass mode for event = %s\n",
5893                                 events[i]);
5894                 } else {
5895                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5896                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5897
5898                         printf("\tbypass event: %-16s = %s\n", events[i],
5899                                 modes[event_mode]);
5900                 }
5901         }
5902 #endif
5903         if (rc != 0)
5904                 fprintf(stderr,
5905                         "\tFailed to get bypass configuration for port = %d\n",
5906                        port_id);
5907 }
5908
5909 static cmdline_parse_token_string_t cmd_showbypass_config_show =
5910         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5911                         show, "show");
5912 static cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5913         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5914                         bypass, "bypass");
5915 static cmdline_parse_token_string_t cmd_showbypass_config_config =
5916         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5917                         config, "config");
5918 static cmdline_parse_token_num_t cmd_showbypass_config_port =
5919         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5920                                 port_id, RTE_UINT16);
5921
5922 static cmdline_parse_inst_t cmd_show_bypass_config = {
5923         .f = cmd_show_bypass_config_parsed,
5924         .help_str = "show bypass config <port_id>: "
5925                     "Show the NIC bypass config for port_id",
5926         .data = NULL,
5927         .tokens = {
5928                 (void *)&cmd_showbypass_config_show,
5929                 (void *)&cmd_showbypass_config_bypass,
5930                 (void *)&cmd_showbypass_config_config,
5931                 (void *)&cmd_showbypass_config_port,
5932                 NULL,
5933         },
5934 };
5935
5936 #ifdef RTE_NET_BOND
5937 /* *** SET BONDING MODE *** */
5938 struct cmd_set_bonding_mode_result {
5939         cmdline_fixed_string_t set;
5940         cmdline_fixed_string_t bonding;
5941         cmdline_fixed_string_t mode;
5942         uint8_t value;
5943         portid_t port_id;
5944 };
5945
5946 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5947                 __rte_unused  struct cmdline *cl,
5948                 __rte_unused void *data)
5949 {
5950         struct cmd_set_bonding_mode_result *res = parsed_result;
5951         portid_t port_id = res->port_id;
5952         struct rte_port *port = &ports[port_id];
5953
5954         /*
5955          * Bonding mode changed means resources of device changed, like whether
5956          * started rte timer or not. Device should be restarted when resources
5957          * of device changed.
5958          */
5959         if (port->port_status != RTE_PORT_STOPPED) {
5960                 fprintf(stderr,
5961                         "\t Error: Can't set bonding mode when port %d is not stopped\n",
5962                         port_id);
5963                 return;
5964         }
5965
5966         /* Set the bonding mode for the relevant port. */
5967         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5968                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5969                         port_id);
5970 }
5971
5972 static cmdline_parse_token_string_t cmd_setbonding_mode_set =
5973 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5974                 set, "set");
5975 static cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5976 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5977                 bonding, "bonding");
5978 static cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5979 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5980                 mode, "mode");
5981 static cmdline_parse_token_num_t cmd_setbonding_mode_value =
5982 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5983                 value, RTE_UINT8);
5984 static cmdline_parse_token_num_t cmd_setbonding_mode_port =
5985 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5986                 port_id, RTE_UINT16);
5987
5988 static cmdline_parse_inst_t cmd_set_bonding_mode = {
5989                 .f = cmd_set_bonding_mode_parsed,
5990                 .help_str = "set bonding mode <mode_value> <port_id>: "
5991                         "Set the bonding mode for port_id",
5992                 .data = NULL,
5993                 .tokens = {
5994                                 (void *) &cmd_setbonding_mode_set,
5995                                 (void *) &cmd_setbonding_mode_bonding,
5996                                 (void *) &cmd_setbonding_mode_mode,
5997                                 (void *) &cmd_setbonding_mode_value,
5998                                 (void *) &cmd_setbonding_mode_port,
5999                                 NULL
6000                 }
6001 };
6002
6003 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
6004 struct cmd_set_bonding_lacp_dedicated_queues_result {
6005         cmdline_fixed_string_t set;
6006         cmdline_fixed_string_t bonding;
6007         cmdline_fixed_string_t lacp;
6008         cmdline_fixed_string_t dedicated_queues;
6009         portid_t port_id;
6010         cmdline_fixed_string_t mode;
6011 };
6012
6013 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
6014                 __rte_unused  struct cmdline *cl,
6015                 __rte_unused void *data)
6016 {
6017         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
6018         portid_t port_id = res->port_id;
6019         struct rte_port *port;
6020
6021         port = &ports[port_id];
6022
6023         /** Check if the port is not started **/
6024         if (port->port_status != RTE_PORT_STOPPED) {
6025                 fprintf(stderr, "Please stop port %d first\n", port_id);
6026                 return;
6027         }
6028
6029         if (!strcmp(res->mode, "enable")) {
6030                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6031                         printf("Dedicate queues for LACP control packets"
6032                                         " enabled\n");
6033                 else
6034                         printf("Enabling dedicate queues for LACP control "
6035                                         "packets on port %d failed\n", port_id);
6036         } else if (!strcmp(res->mode, "disable")) {
6037                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6038                         printf("Dedicated queues for LACP control packets "
6039                                         "disabled\n");
6040                 else
6041                         printf("Disabling dedicated queues for LACP control "
6042                                         "traffic on port %d failed\n", port_id);
6043         }
6044 }
6045
6046 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6047 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6048                 set, "set");
6049 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6051                 bonding, "bonding");
6052 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6053 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6054                 lacp, "lacp");
6055 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6056 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6057                 dedicated_queues, "dedicated_queues");
6058 static cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6059 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6060                 port_id, RTE_UINT16);
6061 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6062 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6063                 mode, "enable#disable");
6064
6065 static cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6066                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6067                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6068                         "enable|disable: "
6069                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6070                 .data = NULL,
6071                 .tokens = {
6072                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6073                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6074                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6075                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6076                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6077                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6078                         NULL
6079                 }
6080 };
6081
6082 /* *** SET BALANCE XMIT POLICY *** */
6083 struct cmd_set_bonding_balance_xmit_policy_result {
6084         cmdline_fixed_string_t set;
6085         cmdline_fixed_string_t bonding;
6086         cmdline_fixed_string_t balance_xmit_policy;
6087         portid_t port_id;
6088         cmdline_fixed_string_t policy;
6089 };
6090
6091 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6092                 __rte_unused  struct cmdline *cl,
6093                 __rte_unused void *data)
6094 {
6095         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6096         portid_t port_id = res->port_id;
6097         uint8_t policy;
6098
6099         if (!strcmp(res->policy, "l2")) {
6100                 policy = BALANCE_XMIT_POLICY_LAYER2;
6101         } else if (!strcmp(res->policy, "l23")) {
6102                 policy = BALANCE_XMIT_POLICY_LAYER23;
6103         } else if (!strcmp(res->policy, "l34")) {
6104                 policy = BALANCE_XMIT_POLICY_LAYER34;
6105         } else {
6106                 fprintf(stderr, "\t Invalid xmit policy selection");
6107                 return;
6108         }
6109
6110         /* Set the bonding mode for the relevant port. */
6111         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6112                 fprintf(stderr,
6113                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6114                         port_id);
6115         }
6116 }
6117
6118 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6119 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6120                 set, "set");
6121 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6123                 bonding, "bonding");
6124 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6125 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6126                 balance_xmit_policy, "balance_xmit_policy");
6127 static cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6128 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6129                 port_id, RTE_UINT16);
6130 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6131 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6132                 policy, "l2#l23#l34");
6133
6134 static cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6135                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6136                 .help_str = "set bonding balance_xmit_policy <port_id> "
6137                         "l2|l23|l34: "
6138                         "Set the bonding balance_xmit_policy for port_id",
6139                 .data = NULL,
6140                 .tokens = {
6141                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6142                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6143                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6144                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6145                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6146                                 NULL
6147                 }
6148 };
6149
6150 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6151 struct cmd_show_bonding_lacp_info_result {
6152         cmdline_fixed_string_t show;
6153         cmdline_fixed_string_t bonding;
6154         cmdline_fixed_string_t lacp;
6155         cmdline_fixed_string_t info;
6156         portid_t port_id;
6157 };
6158
6159 static void port_param_show(struct port_params *params)
6160 {
6161         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6162
6163         printf("\t\tsystem priority: %u\n", params->system_priority);
6164         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6165         printf("\t\tsystem mac address: %s\n", buf);
6166         printf("\t\tport key: %u\n", params->key);
6167         printf("\t\tport priority: %u\n", params->port_priority);
6168         printf("\t\tport number: %u\n", params->port_number);
6169 }
6170
6171 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6172 {
6173         char a_state[256] = { 0 };
6174         char p_state[256] = { 0 };
6175         int a_len = 0;
6176         int p_len = 0;
6177         uint32_t i;
6178
6179         static const char * const state[] = {
6180                 "ACTIVE",
6181                 "TIMEOUT",
6182                 "AGGREGATION",
6183                 "SYNCHRONIZATION",
6184                 "COLLECTING",
6185                 "DISTRIBUTING",
6186                 "DEFAULTED",
6187                 "EXPIRED"
6188         };
6189         static const char * const selection[] = {
6190                 "UNSELECTED",
6191                 "STANDBY",
6192                 "SELECTED"
6193         };
6194
6195         for (i = 0; i < RTE_DIM(state); i++) {
6196                 if ((info->actor_state >> i) & 1)
6197                         a_len += snprintf(&a_state[a_len],
6198                                                 RTE_DIM(a_state) - a_len, "%s ",
6199                                                 state[i]);
6200
6201                 if ((info->partner_state >> i) & 1)
6202                         p_len += snprintf(&p_state[p_len],
6203                                                 RTE_DIM(p_state) - p_len, "%s ",
6204                                                 state[i]);
6205         }
6206         printf("\tAggregator port id: %u\n", info->agg_port_id);
6207         printf("\tselection: %s\n", selection[info->selected]);
6208         printf("\tActor detail info:\n");
6209         port_param_show(&info->actor);
6210         printf("\t\tport state: %s\n", a_state);
6211         printf("\tPartner detail info:\n");
6212         port_param_show(&info->partner);
6213         printf("\t\tport state: %s\n", p_state);
6214         printf("\n");
6215 }
6216
6217 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6218 {
6219         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6220         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6221         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6222         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6223         printf("\taggregate wait timeout: %u ms\n",
6224                         conf->aggregate_wait_timeout_ms);
6225         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6226         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6227         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6228         switch (conf->agg_selection) {
6229         case AGG_BANDWIDTH:
6230                 printf("\taggregation mode: bandwidth\n");
6231                 break;
6232         case AGG_STABLE:
6233                 printf("\taggregation mode: stable\n");
6234                 break;
6235         case AGG_COUNT:
6236                 printf("\taggregation mode: count\n");
6237                 break;
6238         default:
6239                 printf("\taggregation mode: invalid\n");
6240                 break;
6241         }
6242
6243         printf("\n");
6244 }
6245
6246 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6247                 __rte_unused  struct cmdline *cl,
6248                 __rte_unused void *data)
6249 {
6250         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6251         struct rte_eth_bond_8023ad_slave_info slave_info;
6252         struct rte_eth_bond_8023ad_conf port_conf;
6253         portid_t slaves[RTE_MAX_ETHPORTS];
6254         portid_t port_id = res->port_id;
6255         int num_active_slaves;
6256         int bonding_mode;
6257         int i;
6258         int ret;
6259
6260         bonding_mode = rte_eth_bond_mode_get(port_id);
6261         if (bonding_mode != BONDING_MODE_8023AD) {
6262                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6263                 return;
6264         }
6265
6266         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6267                         RTE_MAX_ETHPORTS);
6268         if (num_active_slaves < 0) {
6269                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6270                                 port_id);
6271                 return;
6272         }
6273         if (num_active_slaves == 0)
6274                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6275                         port_id);
6276
6277         printf("\tIEEE802.3 port: %u\n", port_id);
6278         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6279         if (ret) {
6280                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6281                         port_id);
6282                 return;
6283         }
6284         lacp_conf_show(&port_conf);
6285
6286         for (i = 0; i < num_active_slaves; i++) {
6287                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6288                                 &slave_info);
6289                 if (ret) {
6290                         fprintf(stderr, "\tGet slave device %u info failed\n",
6291                                 slaves[i]);
6292                         return;
6293                 }
6294                 printf("\tSlave Port: %u\n", slaves[i]);
6295                 lacp_slave_info_show(&slave_info);
6296         }
6297 }
6298
6299 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6300 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6301                 show, "show");
6302 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6303 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6304                 bonding, "bonding");
6305 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6306 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6307                 bonding, "lacp");
6308 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6309 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6310                 info, "info");
6311 static cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6312 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6313                 port_id, RTE_UINT16);
6314
6315 static cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6316                 .f = cmd_show_bonding_lacp_info_parsed,
6317                 .help_str = "show bonding lacp info <port_id> : "
6318                         "Show bonding IEEE802.3 information for port_id",
6319                 .data = NULL,
6320                 .tokens = {
6321                         (void *)&cmd_show_bonding_lacp_info_show,
6322                         (void *)&cmd_show_bonding_lacp_info_bonding,
6323                         (void *)&cmd_show_bonding_lacp_info_lacp,
6324                         (void *)&cmd_show_bonding_lacp_info_info,
6325                         (void *)&cmd_show_bonding_lacp_info_port_id,
6326                         NULL
6327                 }
6328 };
6329
6330 /* *** SHOW NIC BONDING CONFIGURATION *** */
6331 struct cmd_show_bonding_config_result {
6332         cmdline_fixed_string_t show;
6333         cmdline_fixed_string_t bonding;
6334         cmdline_fixed_string_t config;
6335         portid_t port_id;
6336 };
6337
6338 static void cmd_show_bonding_config_parsed(void *parsed_result,
6339                 __rte_unused  struct cmdline *cl,
6340                 __rte_unused void *data)
6341 {
6342         struct cmd_show_bonding_config_result *res = parsed_result;
6343         int bonding_mode, agg_mode;
6344         portid_t slaves[RTE_MAX_ETHPORTS];
6345         int num_slaves, num_active_slaves;
6346         int primary_id;
6347         int i;
6348         portid_t port_id = res->port_id;
6349
6350         /* Display the bonding mode.*/
6351         bonding_mode = rte_eth_bond_mode_get(port_id);
6352         if (bonding_mode < 0) {
6353                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6354                         port_id);
6355                 return;
6356         } else
6357                 printf("\tBonding mode: %d\n", bonding_mode);
6358
6359         if (bonding_mode == BONDING_MODE_BALANCE ||
6360                 bonding_mode == BONDING_MODE_8023AD) {
6361                 int balance_xmit_policy;
6362
6363                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6364                 if (balance_xmit_policy < 0) {
6365                         fprintf(stderr,
6366                                 "\tFailed to get balance xmit policy for port = %d\n",
6367                                 port_id);
6368                         return;
6369                 } else {
6370                         printf("\tBalance Xmit Policy: ");
6371
6372                         switch (balance_xmit_policy) {
6373                         case BALANCE_XMIT_POLICY_LAYER2:
6374                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6375                                 break;
6376                         case BALANCE_XMIT_POLICY_LAYER23:
6377                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6378                                 break;
6379                         case BALANCE_XMIT_POLICY_LAYER34:
6380                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6381                                 break;
6382                         }
6383                         printf("\n");
6384                 }
6385         }
6386
6387         if (bonding_mode == BONDING_MODE_8023AD) {
6388                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6389                 printf("\tIEEE802.3AD Aggregator Mode: ");
6390                 switch (agg_mode) {
6391                 case AGG_BANDWIDTH:
6392                         printf("bandwidth");
6393                         break;
6394                 case AGG_STABLE:
6395                         printf("stable");
6396                         break;
6397                 case AGG_COUNT:
6398                         printf("count");
6399                         break;
6400                 }
6401                 printf("\n");
6402         }
6403
6404         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6405
6406         if (num_slaves < 0) {
6407                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6408                         port_id);
6409                 return;
6410         }
6411         if (num_slaves > 0) {
6412                 printf("\tSlaves (%d): [", num_slaves);
6413                 for (i = 0; i < num_slaves - 1; i++)
6414                         printf("%d ", slaves[i]);
6415
6416                 printf("%d]\n", slaves[num_slaves - 1]);
6417         } else {
6418                 printf("\tSlaves: []\n");
6419
6420         }
6421
6422         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6423                         RTE_MAX_ETHPORTS);
6424
6425         if (num_active_slaves < 0) {
6426                 fprintf(stderr,
6427                         "\tFailed to get active slave list for port = %d\n",
6428                         port_id);
6429                 return;
6430         }
6431         if (num_active_slaves > 0) {
6432                 printf("\tActive Slaves (%d): [", num_active_slaves);
6433                 for (i = 0; i < num_active_slaves - 1; i++)
6434                         printf("%d ", slaves[i]);
6435
6436                 printf("%d]\n", slaves[num_active_slaves - 1]);
6437
6438         } else {
6439                 printf("\tActive Slaves: []\n");
6440
6441         }
6442
6443         primary_id = rte_eth_bond_primary_get(port_id);
6444         if (primary_id < 0) {
6445                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6446                         port_id);
6447                 return;
6448         } else
6449                 printf("\tPrimary: [%d]\n", primary_id);
6450
6451 }
6452
6453 static cmdline_parse_token_string_t cmd_showbonding_config_show =
6454 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6455                 show, "show");
6456 static cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6457 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6458                 bonding, "bonding");
6459 static cmdline_parse_token_string_t cmd_showbonding_config_config =
6460 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6461                 config, "config");
6462 static cmdline_parse_token_num_t cmd_showbonding_config_port =
6463 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6464                 port_id, RTE_UINT16);
6465
6466 static cmdline_parse_inst_t cmd_show_bonding_config = {
6467                 .f = cmd_show_bonding_config_parsed,
6468                 .help_str = "show bonding config <port_id>: "
6469                         "Show the bonding config for port_id",
6470                 .data = NULL,
6471                 .tokens = {
6472                                 (void *)&cmd_showbonding_config_show,
6473                                 (void *)&cmd_showbonding_config_bonding,
6474                                 (void *)&cmd_showbonding_config_config,
6475                                 (void *)&cmd_showbonding_config_port,
6476                                 NULL
6477                 }
6478 };
6479
6480 /* *** SET BONDING PRIMARY *** */
6481 struct cmd_set_bonding_primary_result {
6482         cmdline_fixed_string_t set;
6483         cmdline_fixed_string_t bonding;
6484         cmdline_fixed_string_t primary;
6485         portid_t slave_id;
6486         portid_t port_id;
6487 };
6488
6489 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6490                 __rte_unused  struct cmdline *cl,
6491                 __rte_unused void *data)
6492 {
6493         struct cmd_set_bonding_primary_result *res = parsed_result;
6494         portid_t master_port_id = res->port_id;
6495         portid_t slave_port_id = res->slave_id;
6496
6497         /* Set the primary slave for a bonded device. */
6498         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6499                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6500                         master_port_id);
6501                 return;
6502         }
6503         init_port_config();
6504 }
6505
6506 static cmdline_parse_token_string_t cmd_setbonding_primary_set =
6507 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6508                 set, "set");
6509 static cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6510 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6511                 bonding, "bonding");
6512 static cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6513 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6514                 primary, "primary");
6515 static cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6516 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6517                 slave_id, RTE_UINT16);
6518 static cmdline_parse_token_num_t cmd_setbonding_primary_port =
6519 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6520                 port_id, RTE_UINT16);
6521
6522 static cmdline_parse_inst_t cmd_set_bonding_primary = {
6523                 .f = cmd_set_bonding_primary_parsed,
6524                 .help_str = "set bonding primary <slave_id> <port_id>: "
6525                         "Set the primary slave for port_id",
6526                 .data = NULL,
6527                 .tokens = {
6528                                 (void *)&cmd_setbonding_primary_set,
6529                                 (void *)&cmd_setbonding_primary_bonding,
6530                                 (void *)&cmd_setbonding_primary_primary,
6531                                 (void *)&cmd_setbonding_primary_slave,
6532                                 (void *)&cmd_setbonding_primary_port,
6533                                 NULL
6534                 }
6535 };
6536
6537 /* *** ADD SLAVE *** */
6538 struct cmd_add_bonding_slave_result {
6539         cmdline_fixed_string_t add;
6540         cmdline_fixed_string_t bonding;
6541         cmdline_fixed_string_t slave;
6542         portid_t slave_id;
6543         portid_t port_id;
6544 };
6545
6546 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6547                 __rte_unused  struct cmdline *cl,
6548                 __rte_unused void *data)
6549 {
6550         struct cmd_add_bonding_slave_result *res = parsed_result;
6551         portid_t master_port_id = res->port_id;
6552         portid_t slave_port_id = res->slave_id;
6553
6554         /* add the slave for a bonded device. */
6555         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6556                 fprintf(stderr,
6557                         "\t Failed to add slave %d to master port = %d.\n",
6558                         slave_port_id, master_port_id);
6559                 return;
6560         }
6561         init_port_config();
6562         set_port_slave_flag(slave_port_id);
6563 }
6564
6565 static cmdline_parse_token_string_t cmd_addbonding_slave_add =
6566 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6567                 add, "add");
6568 static cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6569 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6570                 bonding, "bonding");
6571 static cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6572 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6573                 slave, "slave");
6574 static cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6575 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6576                 slave_id, RTE_UINT16);
6577 static cmdline_parse_token_num_t cmd_addbonding_slave_port =
6578 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6579                 port_id, RTE_UINT16);
6580
6581 static cmdline_parse_inst_t cmd_add_bonding_slave = {
6582                 .f = cmd_add_bonding_slave_parsed,
6583                 .help_str = "add bonding slave <slave_id> <port_id>: "
6584                         "Add a slave device to a bonded device",
6585                 .data = NULL,
6586                 .tokens = {
6587                                 (void *)&cmd_addbonding_slave_add,
6588                                 (void *)&cmd_addbonding_slave_bonding,
6589                                 (void *)&cmd_addbonding_slave_slave,
6590                                 (void *)&cmd_addbonding_slave_slaveid,
6591                                 (void *)&cmd_addbonding_slave_port,
6592                                 NULL
6593                 }
6594 };
6595
6596 /* *** REMOVE SLAVE *** */
6597 struct cmd_remove_bonding_slave_result {
6598         cmdline_fixed_string_t remove;
6599         cmdline_fixed_string_t bonding;
6600         cmdline_fixed_string_t slave;
6601         portid_t slave_id;
6602         portid_t port_id;
6603 };
6604
6605 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6606                 __rte_unused  struct cmdline *cl,
6607                 __rte_unused void *data)
6608 {
6609         struct cmd_remove_bonding_slave_result *res = parsed_result;
6610         portid_t master_port_id = res->port_id;
6611         portid_t slave_port_id = res->slave_id;
6612
6613         /* remove the slave from a bonded device. */
6614         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6615                 fprintf(stderr,
6616                         "\t Failed to remove slave %d from master port = %d.\n",
6617                         slave_port_id, master_port_id);
6618                 return;
6619         }
6620         init_port_config();
6621         clear_port_slave_flag(slave_port_id);
6622 }
6623
6624 static cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6625                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6626                                 remove, "remove");
6627 static cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6628                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6629                                 bonding, "bonding");
6630 static cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6631                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6632                                 slave, "slave");
6633 static cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6634                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6635                                 slave_id, RTE_UINT16);
6636 static cmdline_parse_token_num_t cmd_removebonding_slave_port =
6637                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6638                                 port_id, RTE_UINT16);
6639
6640 static cmdline_parse_inst_t cmd_remove_bonding_slave = {
6641                 .f = cmd_remove_bonding_slave_parsed,
6642                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6643                         "Remove a slave device from a bonded device",
6644                 .data = NULL,
6645                 .tokens = {
6646                                 (void *)&cmd_removebonding_slave_remove,
6647                                 (void *)&cmd_removebonding_slave_bonding,
6648                                 (void *)&cmd_removebonding_slave_slave,
6649                                 (void *)&cmd_removebonding_slave_slaveid,
6650                                 (void *)&cmd_removebonding_slave_port,
6651                                 NULL
6652                 }
6653 };
6654
6655 /* *** CREATE BONDED DEVICE *** */
6656 struct cmd_create_bonded_device_result {
6657         cmdline_fixed_string_t create;
6658         cmdline_fixed_string_t bonded;
6659         cmdline_fixed_string_t device;
6660         uint8_t mode;
6661         uint8_t socket;
6662 };
6663
6664 static int bond_dev_num = 0;
6665
6666 static void cmd_create_bonded_device_parsed(void *parsed_result,
6667                 __rte_unused  struct cmdline *cl,
6668                 __rte_unused void *data)
6669 {
6670         struct cmd_create_bonded_device_result *res = parsed_result;
6671         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6672         int port_id;
6673         int ret;
6674
6675         if (test_done == 0) {
6676                 fprintf(stderr, "Please stop forwarding first\n");
6677                 return;
6678         }
6679
6680         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6681                         bond_dev_num++);
6682
6683         /* Create a new bonded device. */
6684         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6685         if (port_id < 0) {
6686                 fprintf(stderr, "\t Failed to create bonded device.\n");
6687                 return;
6688         } else {
6689                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6690                                 port_id);
6691
6692                 /* Update number of ports */
6693                 nb_ports = rte_eth_dev_count_avail();
6694                 reconfig(port_id, res->socket);
6695                 ret = rte_eth_promiscuous_enable(port_id);
6696                 if (ret != 0)
6697                         fprintf(stderr,
6698                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6699                                 port_id, rte_strerror(-ret));
6700
6701                 ports[port_id].bond_flag = 1;
6702                 ports[port_id].need_setup = 0;
6703                 ports[port_id].port_status = RTE_PORT_STOPPED;
6704         }
6705
6706 }
6707
6708 static cmdline_parse_token_string_t cmd_createbonded_device_create =
6709                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6710                                 create, "create");
6711 static cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6712                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6713                                 bonded, "bonded");
6714 static cmdline_parse_token_string_t cmd_createbonded_device_device =
6715                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6716                                 device, "device");
6717 static cmdline_parse_token_num_t cmd_createbonded_device_mode =
6718                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6719                                 mode, RTE_UINT8);
6720 static cmdline_parse_token_num_t cmd_createbonded_device_socket =
6721                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6722                                 socket, RTE_UINT8);
6723
6724 static cmdline_parse_inst_t cmd_create_bonded_device = {
6725                 .f = cmd_create_bonded_device_parsed,
6726                 .help_str = "create bonded device <mode> <socket>: "
6727                         "Create a new bonded device with specific bonding mode and socket",
6728                 .data = NULL,
6729                 .tokens = {
6730                                 (void *)&cmd_createbonded_device_create,
6731                                 (void *)&cmd_createbonded_device_bonded,
6732                                 (void *)&cmd_createbonded_device_device,
6733                                 (void *)&cmd_createbonded_device_mode,
6734                                 (void *)&cmd_createbonded_device_socket,
6735                                 NULL
6736                 }
6737 };
6738
6739 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6740 struct cmd_set_bond_mac_addr_result {
6741         cmdline_fixed_string_t set;
6742         cmdline_fixed_string_t bonding;
6743         cmdline_fixed_string_t mac_addr;
6744         uint16_t port_num;
6745         struct rte_ether_addr address;
6746 };
6747
6748 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6749                 __rte_unused  struct cmdline *cl,
6750                 __rte_unused void *data)
6751 {
6752         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6753         int ret;
6754
6755         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6756                 return;
6757
6758         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6759
6760         /* check the return value and print it if is < 0 */
6761         if (ret < 0)
6762                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6763                         strerror(-ret));
6764 }
6765
6766 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6767                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6768 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6769                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6770                                 "bonding");
6771 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6772                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6773                                 "mac_addr");
6774 static cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6775                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6776                                 port_num, RTE_UINT16);
6777 static cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6778                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6779
6780 static cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6781                 .f = cmd_set_bond_mac_addr_parsed,
6782                 .data = (void *) 0,
6783                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6784                 .tokens = {
6785                                 (void *)&cmd_set_bond_mac_addr_set,
6786                                 (void *)&cmd_set_bond_mac_addr_bonding,
6787                                 (void *)&cmd_set_bond_mac_addr_mac,
6788                                 (void *)&cmd_set_bond_mac_addr_portnum,
6789                                 (void *)&cmd_set_bond_mac_addr_addr,
6790                                 NULL
6791                 }
6792 };
6793
6794
6795 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6796 struct cmd_set_bond_mon_period_result {
6797         cmdline_fixed_string_t set;
6798         cmdline_fixed_string_t bonding;
6799         cmdline_fixed_string_t mon_period;
6800         uint16_t port_num;
6801         uint32_t period_ms;
6802 };
6803
6804 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6805                 __rte_unused  struct cmdline *cl,
6806                 __rte_unused void *data)
6807 {
6808         struct cmd_set_bond_mon_period_result *res = parsed_result;
6809         int ret;
6810
6811         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6812
6813         /* check the return value and print it if is < 0 */
6814         if (ret < 0)
6815                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6816                         strerror(-ret));
6817 }
6818
6819 static cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6820                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6821                                 set, "set");
6822 static cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6823                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6824                                 bonding, "bonding");
6825 static cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6826                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6827                                 mon_period,     "mon_period");
6828 static cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6829                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6830                                 port_num, RTE_UINT16);
6831 static cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6832                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6833                                 period_ms, RTE_UINT32);
6834
6835 static cmdline_parse_inst_t cmd_set_bond_mon_period = {
6836                 .f = cmd_set_bond_mon_period_parsed,
6837                 .data = (void *) 0,
6838                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6839                 .tokens = {
6840                                 (void *)&cmd_set_bond_mon_period_set,
6841                                 (void *)&cmd_set_bond_mon_period_bonding,
6842                                 (void *)&cmd_set_bond_mon_period_mon_period,
6843                                 (void *)&cmd_set_bond_mon_period_portnum,
6844                                 (void *)&cmd_set_bond_mon_period_period_ms,
6845                                 NULL
6846                 }
6847 };
6848
6849
6850
6851 struct cmd_set_bonding_agg_mode_policy_result {
6852         cmdline_fixed_string_t set;
6853         cmdline_fixed_string_t bonding;
6854         cmdline_fixed_string_t agg_mode;
6855         uint16_t port_num;
6856         cmdline_fixed_string_t policy;
6857 };
6858
6859
6860 static void
6861 cmd_set_bonding_agg_mode(void *parsed_result,
6862                 __rte_unused struct cmdline *cl,
6863                 __rte_unused void *data)
6864 {
6865         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6866         uint8_t policy = AGG_BANDWIDTH;
6867
6868         if (!strcmp(res->policy, "bandwidth"))
6869                 policy = AGG_BANDWIDTH;
6870         else if (!strcmp(res->policy, "stable"))
6871                 policy = AGG_STABLE;
6872         else if (!strcmp(res->policy, "count"))
6873                 policy = AGG_COUNT;
6874
6875         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6876 }
6877
6878
6879 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6880         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6881                                 set, "set");
6882 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6883         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6884                                 bonding, "bonding");
6885
6886 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6887         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6888                                 agg_mode, "agg_mode");
6889
6890 static cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6891         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6892                                 port_num, RTE_UINT16);
6893
6894 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6895         TOKEN_STRING_INITIALIZER(
6896                         struct cmd_set_bonding_balance_xmit_policy_result,
6897                 policy, "stable#bandwidth#count");
6898
6899 static cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6900         .f = cmd_set_bonding_agg_mode,
6901         .data = (void *) 0,
6902         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6903         .tokens = {
6904                         (void *)&cmd_set_bonding_agg_mode_set,
6905                         (void *)&cmd_set_bonding_agg_mode_bonding,
6906                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6907                         (void *)&cmd_set_bonding_agg_mode_portnum,
6908                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6909                         NULL
6910                 }
6911 };
6912
6913
6914 #endif /* RTE_NET_BOND */
6915
6916 /* *** SET FORWARDING MODE *** */
6917 struct cmd_set_fwd_mode_result {
6918         cmdline_fixed_string_t set;
6919         cmdline_fixed_string_t fwd;
6920         cmdline_fixed_string_t mode;
6921 };
6922
6923 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6924                                     __rte_unused struct cmdline *cl,
6925                                     __rte_unused void *data)
6926 {
6927         struct cmd_set_fwd_mode_result *res = parsed_result;
6928
6929         retry_enabled = 0;
6930         set_pkt_forwarding_mode(res->mode);
6931 }
6932
6933 static cmdline_parse_token_string_t cmd_setfwd_set =
6934         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6935 static cmdline_parse_token_string_t cmd_setfwd_fwd =
6936         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6937 static cmdline_parse_token_string_t cmd_setfwd_mode =
6938         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6939                 "" /* defined at init */);
6940
6941 static cmdline_parse_inst_t cmd_set_fwd_mode = {
6942         .f = cmd_set_fwd_mode_parsed,
6943         .data = NULL,
6944         .help_str = NULL, /* defined at init */
6945         .tokens = {
6946                 (void *)&cmd_setfwd_set,
6947                 (void *)&cmd_setfwd_fwd,
6948                 (void *)&cmd_setfwd_mode,
6949                 NULL,
6950         },
6951 };
6952
6953 static void cmd_set_fwd_mode_init(void)
6954 {
6955         char *modes, *c;
6956         static char token[128];
6957         static char help[256];
6958         cmdline_parse_token_string_t *token_struct;
6959
6960         modes = list_pkt_forwarding_modes();
6961         snprintf(help, sizeof(help), "set fwd %s: "
6962                 "Set packet forwarding mode", modes);
6963         cmd_set_fwd_mode.help_str = help;
6964
6965         /* string token separator is # */
6966         for (c = token; *modes != '\0'; modes++)
6967                 if (*modes == '|')
6968                         *c++ = '#';
6969                 else
6970                         *c++ = *modes;
6971         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6972         token_struct->string_data.str = token;
6973 }
6974
6975 /* *** SET RETRY FORWARDING MODE *** */
6976 struct cmd_set_fwd_retry_mode_result {
6977         cmdline_fixed_string_t set;
6978         cmdline_fixed_string_t fwd;
6979         cmdline_fixed_string_t mode;
6980         cmdline_fixed_string_t retry;
6981 };
6982
6983 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6984                             __rte_unused struct cmdline *cl,
6985                             __rte_unused void *data)
6986 {
6987         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6988
6989         retry_enabled = 1;
6990         set_pkt_forwarding_mode(res->mode);
6991 }
6992
6993 static cmdline_parse_token_string_t cmd_setfwd_retry_set =
6994         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6995                         set, "set");
6996 static cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6997         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6998                         fwd, "fwd");
6999 static cmdline_parse_token_string_t cmd_setfwd_retry_mode =
7000         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
7001                         mode,
7002                 "" /* defined at init */);
7003 static cmdline_parse_token_string_t cmd_setfwd_retry_retry =
7004         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
7005                         retry, "retry");
7006
7007 static cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
7008         .f = cmd_set_fwd_retry_mode_parsed,
7009         .data = NULL,
7010         .help_str = NULL, /* defined at init */
7011         .tokens = {
7012                 (void *)&cmd_setfwd_retry_set,
7013                 (void *)&cmd_setfwd_retry_fwd,
7014                 (void *)&cmd_setfwd_retry_mode,
7015                 (void *)&cmd_setfwd_retry_retry,
7016                 NULL,
7017         },
7018 };
7019
7020 static void cmd_set_fwd_retry_mode_init(void)
7021 {
7022         char *modes, *c;
7023         static char token[128];
7024         static char help[256];
7025         cmdline_parse_token_string_t *token_struct;
7026
7027         modes = list_pkt_forwarding_retry_modes();
7028         snprintf(help, sizeof(help), "set fwd %s retry: "
7029                 "Set packet forwarding mode with retry", modes);
7030         cmd_set_fwd_retry_mode.help_str = help;
7031
7032         /* string token separator is # */
7033         for (c = token; *modes != '\0'; modes++)
7034                 if (*modes == '|')
7035                         *c++ = '#';
7036                 else
7037                         *c++ = *modes;
7038         token_struct = (cmdline_parse_token_string_t *)
7039                 cmd_set_fwd_retry_mode.tokens[2];
7040         token_struct->string_data.str = token;
7041 }
7042
7043 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7044 struct cmd_set_burst_tx_retry_result {
7045         cmdline_fixed_string_t set;
7046         cmdline_fixed_string_t burst;
7047         cmdline_fixed_string_t tx;
7048         cmdline_fixed_string_t delay;
7049         uint32_t time;
7050         cmdline_fixed_string_t retry;
7051         uint32_t retry_num;
7052 };
7053
7054 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7055                                         __rte_unused struct cmdline *cl,
7056                                         __rte_unused void *data)
7057 {
7058         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7059
7060         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7061                 && !strcmp(res->tx, "tx")) {
7062                 if (!strcmp(res->delay, "delay"))
7063                         burst_tx_delay_time = res->time;
7064                 if (!strcmp(res->retry, "retry"))
7065                         burst_tx_retry_num = res->retry_num;
7066         }
7067
7068 }
7069
7070 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7071         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7072 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7073         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7074                                  "burst");
7075 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7076         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7077 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7078         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7079 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7080         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7081                                  RTE_UINT32);
7082 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7083         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7084 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7085         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7086                                  RTE_UINT32);
7087
7088 static cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7089         .f = cmd_set_burst_tx_retry_parsed,
7090         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7091         .tokens = {
7092                 (void *)&cmd_set_burst_tx_retry_set,
7093                 (void *)&cmd_set_burst_tx_retry_burst,
7094                 (void *)&cmd_set_burst_tx_retry_tx,
7095                 (void *)&cmd_set_burst_tx_retry_delay,
7096                 (void *)&cmd_set_burst_tx_retry_time,
7097                 (void *)&cmd_set_burst_tx_retry_retry,
7098                 (void *)&cmd_set_burst_tx_retry_retry_num,
7099                 NULL,
7100         },
7101 };
7102
7103 /* *** SET PROMISC MODE *** */
7104 struct cmd_set_promisc_mode_result {
7105         cmdline_fixed_string_t set;
7106         cmdline_fixed_string_t promisc;
7107         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7108         uint16_t port_num;               /* valid if "allports" argument == 0 */
7109         cmdline_fixed_string_t mode;
7110 };
7111
7112 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7113                                         __rte_unused struct cmdline *cl,
7114                                         void *allports)
7115 {
7116         struct cmd_set_promisc_mode_result *res = parsed_result;
7117         int enable;
7118         portid_t i;
7119
7120         if (!strcmp(res->mode, "on"))
7121                 enable = 1;
7122         else
7123                 enable = 0;
7124
7125         /* all ports */
7126         if (allports) {
7127                 RTE_ETH_FOREACH_DEV(i)
7128                         eth_set_promisc_mode(i, enable);
7129         } else {
7130                 eth_set_promisc_mode(res->port_num, enable);
7131         }
7132 }
7133
7134 static cmdline_parse_token_string_t cmd_setpromisc_set =
7135         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7136 static cmdline_parse_token_string_t cmd_setpromisc_promisc =
7137         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7138                                  "promisc");
7139 static cmdline_parse_token_string_t cmd_setpromisc_portall =
7140         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7141                                  "all");
7142 static cmdline_parse_token_num_t cmd_setpromisc_portnum =
7143         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7144                               RTE_UINT16);
7145 static cmdline_parse_token_string_t cmd_setpromisc_mode =
7146         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7147                                  "on#off");
7148
7149 static cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7150         .f = cmd_set_promisc_mode_parsed,
7151         .data = (void *)1,
7152         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7153         .tokens = {
7154                 (void *)&cmd_setpromisc_set,
7155                 (void *)&cmd_setpromisc_promisc,
7156                 (void *)&cmd_setpromisc_portall,
7157                 (void *)&cmd_setpromisc_mode,
7158                 NULL,
7159         },
7160 };
7161
7162 static cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7163         .f = cmd_set_promisc_mode_parsed,
7164         .data = (void *)0,
7165         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7166         .tokens = {
7167                 (void *)&cmd_setpromisc_set,
7168                 (void *)&cmd_setpromisc_promisc,
7169                 (void *)&cmd_setpromisc_portnum,
7170                 (void *)&cmd_setpromisc_mode,
7171                 NULL,
7172         },
7173 };
7174
7175 /* *** SET ALLMULTI MODE *** */
7176 struct cmd_set_allmulti_mode_result {
7177         cmdline_fixed_string_t set;
7178         cmdline_fixed_string_t allmulti;
7179         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7180         uint16_t port_num;               /* valid if "allports" argument == 0 */
7181         cmdline_fixed_string_t mode;
7182 };
7183
7184 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7185                                         __rte_unused struct cmdline *cl,
7186                                         void *allports)
7187 {
7188         struct cmd_set_allmulti_mode_result *res = parsed_result;
7189         int enable;
7190         portid_t i;
7191
7192         if (!strcmp(res->mode, "on"))
7193                 enable = 1;
7194         else
7195                 enable = 0;
7196
7197         /* all ports */
7198         if (allports) {
7199                 RTE_ETH_FOREACH_DEV(i) {
7200                         eth_set_allmulticast_mode(i, enable);
7201                 }
7202         }
7203         else {
7204                 eth_set_allmulticast_mode(res->port_num, enable);
7205         }
7206 }
7207
7208 static cmdline_parse_token_string_t cmd_setallmulti_set =
7209         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7210 static cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7211         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7212                                  "allmulti");
7213 static cmdline_parse_token_string_t cmd_setallmulti_portall =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7215                                  "all");
7216 static cmdline_parse_token_num_t cmd_setallmulti_portnum =
7217         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7218                               RTE_UINT16);
7219 static cmdline_parse_token_string_t cmd_setallmulti_mode =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7221                                  "on#off");
7222
7223 static cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7224         .f = cmd_set_allmulti_mode_parsed,
7225         .data = (void *)1,
7226         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7227         .tokens = {
7228                 (void *)&cmd_setallmulti_set,
7229                 (void *)&cmd_setallmulti_allmulti,
7230                 (void *)&cmd_setallmulti_portall,
7231                 (void *)&cmd_setallmulti_mode,
7232                 NULL,
7233         },
7234 };
7235
7236 static cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7237         .f = cmd_set_allmulti_mode_parsed,
7238         .data = (void *)0,
7239         .help_str = "set allmulti <port_id> on|off: "
7240                 "Set allmulti mode on port_id",
7241         .tokens = {
7242                 (void *)&cmd_setallmulti_set,
7243                 (void *)&cmd_setallmulti_allmulti,
7244                 (void *)&cmd_setallmulti_portnum,
7245                 (void *)&cmd_setallmulti_mode,
7246                 NULL,
7247         },
7248 };
7249
7250 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7251 struct cmd_link_flow_ctrl_show {
7252         cmdline_fixed_string_t show;
7253         cmdline_fixed_string_t port;
7254         portid_t port_id;
7255         cmdline_fixed_string_t flow_ctrl;
7256 };
7257
7258 static cmdline_parse_token_string_t cmd_lfc_show_show =
7259         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7260                                 show, "show");
7261 static cmdline_parse_token_string_t cmd_lfc_show_port =
7262         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7263                                 port, "port");
7264 static cmdline_parse_token_num_t cmd_lfc_show_portid =
7265         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7266                                 port_id, RTE_UINT16);
7267 static cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7268         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7269                                 flow_ctrl, "flow_ctrl");
7270
7271 static void
7272 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7273                               __rte_unused struct cmdline *cl,
7274                               __rte_unused void *data)
7275 {
7276         struct cmd_link_flow_ctrl_show *res = parsed_result;
7277         static const char *info_border = "*********************";
7278         struct rte_eth_fc_conf fc_conf;
7279         bool rx_fc_en = false;
7280         bool tx_fc_en = false;
7281         int ret;
7282
7283         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7284         if (ret != 0) {
7285                 fprintf(stderr,
7286                         "Failed to get current flow ctrl information: err = %d\n",
7287                         ret);
7288                 return;
7289         }
7290
7291         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7292                 rx_fc_en = true;
7293         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7294                 tx_fc_en = true;
7295
7296         printf("\n%s Flow control infos for port %-2d %s\n",
7297                 info_border, res->port_id, info_border);
7298         printf("FC mode:\n");
7299         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7300         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7301         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7302         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7303         printf("High waterline: 0x%x\n", fc_conf.high_water);
7304         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7305         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7306         printf("Forward MAC control frames: %s\n",
7307                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7308         printf("\n%s**************   End  ***********%s\n",
7309                 info_border, info_border);
7310 }
7311
7312 static cmdline_parse_inst_t cmd_link_flow_control_show = {
7313         .f = cmd_link_flow_ctrl_show_parsed,
7314         .data = NULL,
7315         .help_str = "show port <port_id> flow_ctrl",
7316         .tokens = {
7317                 (void *)&cmd_lfc_show_show,
7318                 (void *)&cmd_lfc_show_port,
7319                 (void *)&cmd_lfc_show_portid,
7320                 (void *)&cmd_lfc_show_flow_ctrl,
7321                 NULL,
7322         },
7323 };
7324
7325 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7326 struct cmd_link_flow_ctrl_set_result {
7327         cmdline_fixed_string_t set;
7328         cmdline_fixed_string_t flow_ctrl;
7329         cmdline_fixed_string_t rx;
7330         cmdline_fixed_string_t rx_lfc_mode;
7331         cmdline_fixed_string_t tx;
7332         cmdline_fixed_string_t tx_lfc_mode;
7333         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7334         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7335         cmdline_fixed_string_t autoneg_str;
7336         cmdline_fixed_string_t autoneg;
7337         cmdline_fixed_string_t hw_str;
7338         uint32_t high_water;
7339         cmdline_fixed_string_t lw_str;
7340         uint32_t low_water;
7341         cmdline_fixed_string_t pt_str;
7342         uint16_t pause_time;
7343         cmdline_fixed_string_t xon_str;
7344         uint16_t send_xon;
7345         portid_t port_id;
7346 };
7347
7348 static cmdline_parse_token_string_t cmd_lfc_set_set =
7349         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7350                                 set, "set");
7351 static cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7352         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7353                                 flow_ctrl, "flow_ctrl");
7354 static cmdline_parse_token_string_t cmd_lfc_set_rx =
7355         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7356                                 rx, "rx");
7357 static cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7358         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7359                                 rx_lfc_mode, "on#off");
7360 static cmdline_parse_token_string_t cmd_lfc_set_tx =
7361         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7362                                 tx, "tx");
7363 static cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7364         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7365                                 tx_lfc_mode, "on#off");
7366 static cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7367         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7368                                 hw_str, "high_water");
7369 static cmdline_parse_token_num_t cmd_lfc_set_high_water =
7370         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7371                                 high_water, RTE_UINT32);
7372 static cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7373         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7374                                 lw_str, "low_water");
7375 static cmdline_parse_token_num_t cmd_lfc_set_low_water =
7376         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7377                                 low_water, RTE_UINT32);
7378 static cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7379         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7380                                 pt_str, "pause_time");
7381 static cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7382         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7383                                 pause_time, RTE_UINT16);
7384 static cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7385         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7386                                 xon_str, "send_xon");
7387 static cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7388         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7389                                 send_xon, RTE_UINT16);
7390 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7391         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7392                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7393 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7394         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7395                                 mac_ctrl_frame_fwd_mode, "on#off");
7396 static cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7397         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7398                                 autoneg_str, "autoneg");
7399 static cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7400         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7401                                 autoneg, "on#off");
7402 static cmdline_parse_token_num_t cmd_lfc_set_portid =
7403         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7404                                 port_id, RTE_UINT16);
7405
7406 /* forward declaration */
7407 static void
7408 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7409                               void *data);
7410
7411 static cmdline_parse_inst_t cmd_link_flow_control_set = {
7412         .f = cmd_link_flow_ctrl_set_parsed,
7413         .data = NULL,
7414         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7415                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7416                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7417         .tokens = {
7418                 (void *)&cmd_lfc_set_set,
7419                 (void *)&cmd_lfc_set_flow_ctrl,
7420                 (void *)&cmd_lfc_set_rx,
7421                 (void *)&cmd_lfc_set_rx_mode,
7422                 (void *)&cmd_lfc_set_tx,
7423                 (void *)&cmd_lfc_set_tx_mode,
7424                 (void *)&cmd_lfc_set_high_water,
7425                 (void *)&cmd_lfc_set_low_water,
7426                 (void *)&cmd_lfc_set_pause_time,
7427                 (void *)&cmd_lfc_set_send_xon,
7428                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7429                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7430                 (void *)&cmd_lfc_set_autoneg_str,
7431                 (void *)&cmd_lfc_set_autoneg,
7432                 (void *)&cmd_lfc_set_portid,
7433                 NULL,
7434         },
7435 };
7436
7437 static cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7438         .f = cmd_link_flow_ctrl_set_parsed,
7439         .data = (void *)&cmd_link_flow_control_set_rx,
7440         .help_str = "set flow_ctrl rx on|off <port_id>: "
7441                 "Change rx flow control parameter",
7442         .tokens = {
7443                 (void *)&cmd_lfc_set_set,
7444                 (void *)&cmd_lfc_set_flow_ctrl,
7445                 (void *)&cmd_lfc_set_rx,
7446                 (void *)&cmd_lfc_set_rx_mode,
7447                 (void *)&cmd_lfc_set_portid,
7448                 NULL,
7449         },
7450 };
7451
7452 static cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7453         .f = cmd_link_flow_ctrl_set_parsed,
7454         .data = (void *)&cmd_link_flow_control_set_tx,
7455         .help_str = "set flow_ctrl tx on|off <port_id>: "
7456                 "Change tx flow control parameter",
7457         .tokens = {
7458                 (void *)&cmd_lfc_set_set,
7459                 (void *)&cmd_lfc_set_flow_ctrl,
7460                 (void *)&cmd_lfc_set_tx,
7461                 (void *)&cmd_lfc_set_tx_mode,
7462                 (void *)&cmd_lfc_set_portid,
7463                 NULL,
7464         },
7465 };
7466
7467 static cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7468         .f = cmd_link_flow_ctrl_set_parsed,
7469         .data = (void *)&cmd_link_flow_control_set_hw,
7470         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7471                 "Change high water flow control parameter",
7472         .tokens = {
7473                 (void *)&cmd_lfc_set_set,
7474                 (void *)&cmd_lfc_set_flow_ctrl,
7475                 (void *)&cmd_lfc_set_high_water_str,
7476                 (void *)&cmd_lfc_set_high_water,
7477                 (void *)&cmd_lfc_set_portid,
7478                 NULL,
7479         },
7480 };
7481
7482 static cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7483         .f = cmd_link_flow_ctrl_set_parsed,
7484         .data = (void *)&cmd_link_flow_control_set_lw,
7485         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7486                 "Change low water flow control parameter",
7487         .tokens = {
7488                 (void *)&cmd_lfc_set_set,
7489                 (void *)&cmd_lfc_set_flow_ctrl,
7490                 (void *)&cmd_lfc_set_low_water_str,
7491                 (void *)&cmd_lfc_set_low_water,
7492                 (void *)&cmd_lfc_set_portid,
7493                 NULL,
7494         },
7495 };
7496
7497 static cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7498         .f = cmd_link_flow_ctrl_set_parsed,
7499         .data = (void *)&cmd_link_flow_control_set_pt,
7500         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7501                 "Change pause time flow control parameter",
7502         .tokens = {
7503                 (void *)&cmd_lfc_set_set,
7504                 (void *)&cmd_lfc_set_flow_ctrl,
7505                 (void *)&cmd_lfc_set_pause_time_str,
7506                 (void *)&cmd_lfc_set_pause_time,
7507                 (void *)&cmd_lfc_set_portid,
7508                 NULL,
7509         },
7510 };
7511
7512 static cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7513         .f = cmd_link_flow_ctrl_set_parsed,
7514         .data = (void *)&cmd_link_flow_control_set_xon,
7515         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7516                 "Change send_xon flow control parameter",
7517         .tokens = {
7518                 (void *)&cmd_lfc_set_set,
7519                 (void *)&cmd_lfc_set_flow_ctrl,
7520                 (void *)&cmd_lfc_set_send_xon_str,
7521                 (void *)&cmd_lfc_set_send_xon,
7522                 (void *)&cmd_lfc_set_portid,
7523                 NULL,
7524         },
7525 };
7526
7527 static cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7528         .f = cmd_link_flow_ctrl_set_parsed,
7529         .data = (void *)&cmd_link_flow_control_set_macfwd,
7530         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7531                 "Change mac ctrl fwd flow control parameter",
7532         .tokens = {
7533                 (void *)&cmd_lfc_set_set,
7534                 (void *)&cmd_lfc_set_flow_ctrl,
7535                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7536                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7537                 (void *)&cmd_lfc_set_portid,
7538                 NULL,
7539         },
7540 };
7541
7542 static cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7543         .f = cmd_link_flow_ctrl_set_parsed,
7544         .data = (void *)&cmd_link_flow_control_set_autoneg,
7545         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7546                 "Change autoneg flow control parameter",
7547         .tokens = {
7548                 (void *)&cmd_lfc_set_set,
7549                 (void *)&cmd_lfc_set_flow_ctrl,
7550                 (void *)&cmd_lfc_set_autoneg_str,
7551                 (void *)&cmd_lfc_set_autoneg,
7552                 (void *)&cmd_lfc_set_portid,
7553                 NULL,
7554         },
7555 };
7556
7557 static void
7558 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7559                               __rte_unused struct cmdline *cl,
7560                               void *data)
7561 {
7562         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7563         cmdline_parse_inst_t *cmd = data;
7564         struct rte_eth_fc_conf fc_conf;
7565         int rx_fc_en = 0;
7566         int tx_fc_en = 0;
7567         int ret;
7568
7569         /*
7570          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7571          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7572          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7573          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7574          */
7575         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7576                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7577         };
7578
7579         /* Partial command line, retrieve current configuration */
7580         if (cmd) {
7581                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7582                 if (ret != 0) {
7583                         fprintf(stderr,
7584                                 "cannot get current flow ctrl parameters, return code = %d\n",
7585                                 ret);
7586                         return;
7587                 }
7588
7589                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7590                     (fc_conf.mode == RTE_ETH_FC_FULL))
7591                         rx_fc_en = 1;
7592                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7593                     (fc_conf.mode == RTE_ETH_FC_FULL))
7594                         tx_fc_en = 1;
7595         }
7596
7597         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7598                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7599
7600         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7601                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7602
7603         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7604
7605         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7606                 fc_conf.high_water = res->high_water;
7607
7608         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7609                 fc_conf.low_water = res->low_water;
7610
7611         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7612                 fc_conf.pause_time = res->pause_time;
7613
7614         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7615                 fc_conf.send_xon = res->send_xon;
7616
7617         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7618                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7619                         fc_conf.mac_ctrl_frame_fwd = 1;
7620                 else
7621                         fc_conf.mac_ctrl_frame_fwd = 0;
7622         }
7623
7624         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7625                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7626
7627         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7628         if (ret != 0)
7629                 fprintf(stderr,
7630                         "bad flow control parameter, return code = %d\n",
7631                         ret);
7632 }
7633
7634 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7635 struct cmd_priority_flow_ctrl_set_result {
7636         cmdline_fixed_string_t set;
7637         cmdline_fixed_string_t pfc_ctrl;
7638         cmdline_fixed_string_t rx;
7639         cmdline_fixed_string_t rx_pfc_mode;
7640         cmdline_fixed_string_t tx;
7641         cmdline_fixed_string_t tx_pfc_mode;
7642         uint32_t high_water;
7643         uint32_t low_water;
7644         uint16_t pause_time;
7645         uint8_t  priority;
7646         portid_t port_id;
7647 };
7648
7649 static void
7650 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7651                        __rte_unused struct cmdline *cl,
7652                        __rte_unused void *data)
7653 {
7654         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7655         struct rte_eth_pfc_conf pfc_conf;
7656         int rx_fc_enable, tx_fc_enable;
7657         int ret;
7658
7659         /*
7660          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7661          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7662          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7663          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7664          */
7665         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7666                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7667         };
7668
7669         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7670         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7671         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7672         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7673         pfc_conf.fc.high_water = res->high_water;
7674         pfc_conf.fc.low_water  = res->low_water;
7675         pfc_conf.fc.pause_time = res->pause_time;
7676         pfc_conf.priority      = res->priority;
7677
7678         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7679         if (ret != 0)
7680                 fprintf(stderr,
7681                         "bad priority flow control parameter, return code = %d\n",
7682                         ret);
7683 }
7684
7685 static cmdline_parse_token_string_t cmd_pfc_set_set =
7686         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7687                                 set, "set");
7688 static cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7689         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7690                                 pfc_ctrl, "pfc_ctrl");
7691 static cmdline_parse_token_string_t cmd_pfc_set_rx =
7692         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7693                                 rx, "rx");
7694 static cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7695         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7696                                 rx_pfc_mode, "on#off");
7697 static cmdline_parse_token_string_t cmd_pfc_set_tx =
7698         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7699                                 tx, "tx");
7700 static cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7701         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7702                                 tx_pfc_mode, "on#off");
7703 static cmdline_parse_token_num_t cmd_pfc_set_high_water =
7704         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7705                                 high_water, RTE_UINT32);
7706 static cmdline_parse_token_num_t cmd_pfc_set_low_water =
7707         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7708                                 low_water, RTE_UINT32);
7709 static cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7710         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7711                                 pause_time, RTE_UINT16);
7712 static cmdline_parse_token_num_t cmd_pfc_set_priority =
7713         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7714                                 priority, RTE_UINT8);
7715 static cmdline_parse_token_num_t cmd_pfc_set_portid =
7716         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7717                                 port_id, RTE_UINT16);
7718
7719 static cmdline_parse_inst_t cmd_priority_flow_control_set = {
7720         .f = cmd_priority_flow_ctrl_set_parsed,
7721         .data = NULL,
7722         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7723                 "<pause_time> <priority> <port_id>: "
7724                 "Configure the Ethernet priority flow control",
7725         .tokens = {
7726                 (void *)&cmd_pfc_set_set,
7727                 (void *)&cmd_pfc_set_flow_ctrl,
7728                 (void *)&cmd_pfc_set_rx,
7729                 (void *)&cmd_pfc_set_rx_mode,
7730                 (void *)&cmd_pfc_set_tx,
7731                 (void *)&cmd_pfc_set_tx_mode,
7732                 (void *)&cmd_pfc_set_high_water,
7733                 (void *)&cmd_pfc_set_low_water,
7734                 (void *)&cmd_pfc_set_pause_time,
7735                 (void *)&cmd_pfc_set_priority,
7736                 (void *)&cmd_pfc_set_portid,
7737                 NULL,
7738         },
7739 };
7740
7741 struct cmd_queue_priority_flow_ctrl_set_result {
7742         cmdline_fixed_string_t set;
7743         cmdline_fixed_string_t pfc_queue_ctrl;
7744         portid_t port_id;
7745         cmdline_fixed_string_t rx;
7746         cmdline_fixed_string_t rx_pfc_mode;
7747         uint16_t tx_qid;
7748         uint8_t  tx_tc;
7749         cmdline_fixed_string_t tx;
7750         cmdline_fixed_string_t tx_pfc_mode;
7751         uint16_t rx_qid;
7752         uint8_t  rx_tc;
7753         uint16_t pause_time;
7754 };
7755
7756 static void
7757 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7758                                         __rte_unused struct cmdline *cl,
7759                                         __rte_unused void *data)
7760 {
7761         struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7762         struct rte_eth_pfc_queue_conf pfc_queue_conf;
7763         int rx_fc_enable, tx_fc_enable;
7764         int ret;
7765
7766         /*
7767          * Rx on/off, flow control is enabled/disabled on RX side. This can
7768          * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7769          * side. Tx on/off, flow control is enabled/disabled on TX side. This
7770          * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7771          * the Tx side.
7772          */
7773         static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7774                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7775                 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7776         };
7777
7778         memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7779         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7780         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7781         pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7782         pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7783         pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7784         pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7785         pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7786         pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7787
7788         ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7789                                                              &pfc_queue_conf);
7790         if (ret != 0) {
7791                 fprintf(stderr,
7792                         "bad queue priority flow control parameter, rc = %d\n",
7793                         ret);
7794         }
7795 }
7796
7797 static cmdline_parse_token_string_t cmd_q_pfc_set_set =
7798         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7799                                 set, "set");
7800 static cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7801         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7802                                 pfc_queue_ctrl, "pfc_queue_ctrl");
7803 static cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7804         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7805                                 port_id, RTE_UINT16);
7806 static cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7807         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7808                                 rx, "rx");
7809 static cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7810         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7811                                 rx_pfc_mode, "on#off");
7812 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7813         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7814                                 tx_qid, RTE_UINT16);
7815 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7816         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7817                                 tx_tc, RTE_UINT8);
7818 static cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7819         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7820                                 tx, "tx");
7821 static cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7822         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7823                                 tx_pfc_mode, "on#off");
7824 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7825         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7826                                 rx_qid, RTE_UINT16);
7827 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7828         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7829                                 rx_tc, RTE_UINT8);
7830 static cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7831         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7832                                 pause_time, RTE_UINT16);
7833
7834 static cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7835         .f = cmd_queue_priority_flow_ctrl_set_parsed,
7836         .data = NULL,
7837         .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7838                 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7839                 "Configure the Ethernet queue priority flow control",
7840         .tokens = {
7841                 (void *)&cmd_q_pfc_set_set,
7842                 (void *)&cmd_q_pfc_set_flow_ctrl,
7843                 (void *)&cmd_q_pfc_set_portid,
7844                 (void *)&cmd_q_pfc_set_rx,
7845                 (void *)&cmd_q_pfc_set_rx_mode,
7846                 (void *)&cmd_q_pfc_set_tx_qid,
7847                 (void *)&cmd_q_pfc_set_tx_tc,
7848                 (void *)&cmd_q_pfc_set_tx,
7849                 (void *)&cmd_q_pfc_set_tx_mode,
7850                 (void *)&cmd_q_pfc_set_rx_qid,
7851                 (void *)&cmd_q_pfc_set_rx_tc,
7852                 (void *)&cmd_q_pfc_set_pause_time,
7853                 NULL,
7854         },
7855 };
7856
7857 /* *** RESET CONFIGURATION *** */
7858 struct cmd_reset_result {
7859         cmdline_fixed_string_t reset;
7860         cmdline_fixed_string_t def;
7861 };
7862
7863 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7864                              struct cmdline *cl,
7865                              __rte_unused void *data)
7866 {
7867         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7868         set_def_fwd_config();
7869 }
7870
7871 static cmdline_parse_token_string_t cmd_reset_set =
7872         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7873 static cmdline_parse_token_string_t cmd_reset_def =
7874         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7875                                  "default");
7876
7877 static cmdline_parse_inst_t cmd_reset = {
7878         .f = cmd_reset_parsed,
7879         .data = NULL,
7880         .help_str = "set default: Reset default forwarding configuration",
7881         .tokens = {
7882                 (void *)&cmd_reset_set,
7883                 (void *)&cmd_reset_def,
7884                 NULL,
7885         },
7886 };
7887
7888 /* *** START FORWARDING *** */
7889 struct cmd_start_result {
7890         cmdline_fixed_string_t start;
7891 };
7892
7893 static cmdline_parse_token_string_t cmd_start_start =
7894         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7895
7896 static void cmd_start_parsed(__rte_unused void *parsed_result,
7897                              __rte_unused struct cmdline *cl,
7898                              __rte_unused void *data)
7899 {
7900         start_packet_forwarding(0);
7901 }
7902
7903 static cmdline_parse_inst_t cmd_start = {
7904         .f = cmd_start_parsed,
7905         .data = NULL,
7906         .help_str = "start: Start packet forwarding",
7907         .tokens = {
7908                 (void *)&cmd_start_start,
7909                 NULL,
7910         },
7911 };
7912
7913 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7914 struct cmd_start_tx_first_result {
7915         cmdline_fixed_string_t start;
7916         cmdline_fixed_string_t tx_first;
7917 };
7918
7919 static void
7920 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7921                           __rte_unused struct cmdline *cl,
7922                           __rte_unused void *data)
7923 {
7924         start_packet_forwarding(1);
7925 }
7926
7927 static cmdline_parse_token_string_t cmd_start_tx_first_start =
7928         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7929                                  "start");
7930 static cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7931         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7932                                  tx_first, "tx_first");
7933
7934 static cmdline_parse_inst_t cmd_start_tx_first = {
7935         .f = cmd_start_tx_first_parsed,
7936         .data = NULL,
7937         .help_str = "start tx_first: Start packet forwarding, "
7938                 "after sending 1 burst of packets",
7939         .tokens = {
7940                 (void *)&cmd_start_tx_first_start,
7941                 (void *)&cmd_start_tx_first_tx_first,
7942                 NULL,
7943         },
7944 };
7945
7946 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7947 struct cmd_start_tx_first_n_result {
7948         cmdline_fixed_string_t start;
7949         cmdline_fixed_string_t tx_first;
7950         uint32_t tx_num;
7951 };
7952
7953 static void
7954 cmd_start_tx_first_n_parsed(void *parsed_result,
7955                           __rte_unused struct cmdline *cl,
7956                           __rte_unused void *data)
7957 {
7958         struct cmd_start_tx_first_n_result *res = parsed_result;
7959
7960         start_packet_forwarding(res->tx_num);
7961 }
7962
7963 static cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7964         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7965                         start, "start");
7966 static cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7967         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7968                         tx_first, "tx_first");
7969 static cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7970         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7971                         tx_num, RTE_UINT32);
7972
7973 static cmdline_parse_inst_t cmd_start_tx_first_n = {
7974         .f = cmd_start_tx_first_n_parsed,
7975         .data = NULL,
7976         .help_str = "start tx_first <num>: "
7977                 "packet forwarding, after sending <num> bursts of packets",
7978         .tokens = {
7979                 (void *)&cmd_start_tx_first_n_start,
7980                 (void *)&cmd_start_tx_first_n_tx_first,
7981                 (void *)&cmd_start_tx_first_n_tx_num,
7982                 NULL,
7983         },
7984 };
7985
7986 /* *** SET LINK UP *** */
7987 struct cmd_set_link_up_result {
7988         cmdline_fixed_string_t set;
7989         cmdline_fixed_string_t link_up;
7990         cmdline_fixed_string_t port;
7991         portid_t port_id;
7992 };
7993
7994 static cmdline_parse_token_string_t cmd_set_link_up_set =
7995         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7996 static cmdline_parse_token_string_t cmd_set_link_up_link_up =
7997         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7998                                 "link-up");
7999 static cmdline_parse_token_string_t cmd_set_link_up_port =
8000         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
8001 static cmdline_parse_token_num_t cmd_set_link_up_port_id =
8002         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
8003                                 RTE_UINT16);
8004
8005 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
8006                              __rte_unused struct cmdline *cl,
8007                              __rte_unused void *data)
8008 {
8009         struct cmd_set_link_up_result *res = parsed_result;
8010         dev_set_link_up(res->port_id);
8011 }
8012
8013 static cmdline_parse_inst_t cmd_set_link_up = {
8014         .f = cmd_set_link_up_parsed,
8015         .data = NULL,
8016         .help_str = "set link-up port <port id>",
8017         .tokens = {
8018                 (void *)&cmd_set_link_up_set,
8019                 (void *)&cmd_set_link_up_link_up,
8020                 (void *)&cmd_set_link_up_port,
8021                 (void *)&cmd_set_link_up_port_id,
8022                 NULL,
8023         },
8024 };
8025
8026 /* *** SET LINK DOWN *** */
8027 struct cmd_set_link_down_result {
8028         cmdline_fixed_string_t set;
8029         cmdline_fixed_string_t link_down;
8030         cmdline_fixed_string_t port;
8031         portid_t port_id;
8032 };
8033
8034 static cmdline_parse_token_string_t cmd_set_link_down_set =
8035         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8036 static cmdline_parse_token_string_t cmd_set_link_down_link_down =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8038                                 "link-down");
8039 static cmdline_parse_token_string_t cmd_set_link_down_port =
8040         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8041 static cmdline_parse_token_num_t cmd_set_link_down_port_id =
8042         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8043                                 RTE_UINT16);
8044
8045 static void cmd_set_link_down_parsed(
8046                                 __rte_unused void *parsed_result,
8047                                 __rte_unused struct cmdline *cl,
8048                                 __rte_unused void *data)
8049 {
8050         struct cmd_set_link_down_result *res = parsed_result;
8051         dev_set_link_down(res->port_id);
8052 }
8053
8054 static cmdline_parse_inst_t cmd_set_link_down = {
8055         .f = cmd_set_link_down_parsed,
8056         .data = NULL,
8057         .help_str = "set link-down port <port id>",
8058         .tokens = {
8059                 (void *)&cmd_set_link_down_set,
8060                 (void *)&cmd_set_link_down_link_down,
8061                 (void *)&cmd_set_link_down_port,
8062                 (void *)&cmd_set_link_down_port_id,
8063                 NULL,
8064         },
8065 };
8066
8067 /* *** SHOW CFG *** */
8068 struct cmd_showcfg_result {
8069         cmdline_fixed_string_t show;
8070         cmdline_fixed_string_t cfg;
8071         cmdline_fixed_string_t what;
8072 };
8073
8074 static void cmd_showcfg_parsed(void *parsed_result,
8075                                __rte_unused struct cmdline *cl,
8076                                __rte_unused void *data)
8077 {
8078         struct cmd_showcfg_result *res = parsed_result;
8079         if (!strcmp(res->what, "rxtx"))
8080                 rxtx_config_display();
8081         else if (!strcmp(res->what, "cores"))
8082                 fwd_lcores_config_display();
8083         else if (!strcmp(res->what, "fwd"))
8084                 pkt_fwd_config_display(&cur_fwd_config);
8085         else if (!strcmp(res->what, "rxoffs"))
8086                 show_rx_pkt_offsets();
8087         else if (!strcmp(res->what, "rxpkts"))
8088                 show_rx_pkt_segments();
8089         else if (!strcmp(res->what, "txpkts"))
8090                 show_tx_pkt_segments();
8091         else if (!strcmp(res->what, "txtimes"))
8092                 show_tx_pkt_times();
8093 }
8094
8095 static cmdline_parse_token_string_t cmd_showcfg_show =
8096         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8097 static cmdline_parse_token_string_t cmd_showcfg_port =
8098         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8099 static cmdline_parse_token_string_t cmd_showcfg_what =
8100         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8101                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8102
8103 static cmdline_parse_inst_t cmd_showcfg = {
8104         .f = cmd_showcfg_parsed,
8105         .data = NULL,
8106         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8107         .tokens = {
8108                 (void *)&cmd_showcfg_show,
8109                 (void *)&cmd_showcfg_port,
8110                 (void *)&cmd_showcfg_what,
8111                 NULL,
8112         },
8113 };
8114
8115 /* *** SHOW ALL PORT INFO *** */
8116 struct cmd_showportall_result {
8117         cmdline_fixed_string_t show;
8118         cmdline_fixed_string_t port;
8119         cmdline_fixed_string_t what;
8120         cmdline_fixed_string_t all;
8121 };
8122
8123 static void cmd_showportall_parsed(void *parsed_result,
8124                                 __rte_unused struct cmdline *cl,
8125                                 __rte_unused void *data)
8126 {
8127         portid_t i;
8128
8129         struct cmd_showportall_result *res = parsed_result;
8130         if (!strcmp(res->show, "clear")) {
8131                 if (!strcmp(res->what, "stats"))
8132                         RTE_ETH_FOREACH_DEV(i)
8133                                 nic_stats_clear(i);
8134                 else if (!strcmp(res->what, "xstats"))
8135                         RTE_ETH_FOREACH_DEV(i)
8136                                 nic_xstats_clear(i);
8137         } else if (!strcmp(res->what, "info"))
8138                 RTE_ETH_FOREACH_DEV(i)
8139                         port_infos_display(i);
8140         else if (!strcmp(res->what, "summary")) {
8141                 port_summary_header_display();
8142                 RTE_ETH_FOREACH_DEV(i)
8143                         port_summary_display(i);
8144         }
8145         else if (!strcmp(res->what, "stats"))
8146                 RTE_ETH_FOREACH_DEV(i)
8147                         nic_stats_display(i);
8148         else if (!strcmp(res->what, "xstats"))
8149                 RTE_ETH_FOREACH_DEV(i)
8150                         nic_xstats_display(i);
8151 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8152         else if (!strcmp(res->what, "fdir"))
8153                 RTE_ETH_FOREACH_DEV(i)
8154                         fdir_get_infos(i);
8155 #endif
8156         else if (!strcmp(res->what, "dcb_tc"))
8157                 RTE_ETH_FOREACH_DEV(i)
8158                         port_dcb_info_display(i);
8159 }
8160
8161 static cmdline_parse_token_string_t cmd_showportall_show =
8162         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8163                                  "show#clear");
8164 static cmdline_parse_token_string_t cmd_showportall_port =
8165         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8166 static cmdline_parse_token_string_t cmd_showportall_what =
8167         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8168                                  "info#summary#stats#xstats#fdir#dcb_tc");
8169 static cmdline_parse_token_string_t cmd_showportall_all =
8170         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8171 static cmdline_parse_inst_t cmd_showportall = {
8172         .f = cmd_showportall_parsed,
8173         .data = NULL,
8174         .help_str = "show|clear port "
8175                 "info|summary|stats|xstats|fdir|dcb_tc all",
8176         .tokens = {
8177                 (void *)&cmd_showportall_show,
8178                 (void *)&cmd_showportall_port,
8179                 (void *)&cmd_showportall_what,
8180                 (void *)&cmd_showportall_all,
8181                 NULL,
8182         },
8183 };
8184
8185 /* *** SHOW PORT INFO *** */
8186 struct cmd_showport_result {
8187         cmdline_fixed_string_t show;
8188         cmdline_fixed_string_t port;
8189         cmdline_fixed_string_t what;
8190         uint16_t portnum;
8191 };
8192
8193 static void cmd_showport_parsed(void *parsed_result,
8194                                 __rte_unused struct cmdline *cl,
8195                                 __rte_unused void *data)
8196 {
8197         struct cmd_showport_result *res = parsed_result;
8198         if (!strcmp(res->show, "clear")) {
8199                 if (!strcmp(res->what, "stats"))
8200                         nic_stats_clear(res->portnum);
8201                 else if (!strcmp(res->what, "xstats"))
8202                         nic_xstats_clear(res->portnum);
8203         } else if (!strcmp(res->what, "info"))
8204                 port_infos_display(res->portnum);
8205         else if (!strcmp(res->what, "summary")) {
8206                 port_summary_header_display();
8207                 port_summary_display(res->portnum);
8208         }
8209         else if (!strcmp(res->what, "stats"))
8210                 nic_stats_display(res->portnum);
8211         else if (!strcmp(res->what, "xstats"))
8212                 nic_xstats_display(res->portnum);
8213 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8214         else if (!strcmp(res->what, "fdir"))
8215                  fdir_get_infos(res->portnum);
8216 #endif
8217         else if (!strcmp(res->what, "dcb_tc"))
8218                 port_dcb_info_display(res->portnum);
8219 }
8220
8221 static cmdline_parse_token_string_t cmd_showport_show =
8222         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8223                                  "show#clear");
8224 static cmdline_parse_token_string_t cmd_showport_port =
8225         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8226 static cmdline_parse_token_string_t cmd_showport_what =
8227         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8228                                  "info#summary#stats#xstats#fdir#dcb_tc");
8229 static cmdline_parse_token_num_t cmd_showport_portnum =
8230         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8231
8232 static cmdline_parse_inst_t cmd_showport = {
8233         .f = cmd_showport_parsed,
8234         .data = NULL,
8235         .help_str = "show|clear port "
8236                 "info|summary|stats|xstats|fdir|dcb_tc "
8237                 "<port_id>",
8238         .tokens = {
8239                 (void *)&cmd_showport_show,
8240                 (void *)&cmd_showport_port,
8241                 (void *)&cmd_showport_what,
8242                 (void *)&cmd_showport_portnum,
8243                 NULL,
8244         },
8245 };
8246
8247 /* *** show port representors information *** */
8248 struct cmd_representor_info_result {
8249         cmdline_fixed_string_t cmd_show;
8250         cmdline_fixed_string_t cmd_port;
8251         cmdline_fixed_string_t cmd_info;
8252         cmdline_fixed_string_t cmd_keyword;
8253         portid_t cmd_pid;
8254 };
8255
8256 static void
8257 cmd_representor_info_parsed(void *parsed_result,
8258                 __rte_unused struct cmdline *cl,
8259                 __rte_unused void *data)
8260 {
8261         struct cmd_representor_info_result *res = parsed_result;
8262         struct rte_eth_representor_info *info;
8263         struct rte_eth_representor_range *range;
8264         uint32_t range_diff;
8265         uint32_t i;
8266         int ret;
8267         int num;
8268
8269         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8270                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8271                 return;
8272         }
8273
8274         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8275         if (ret < 0) {
8276                 fprintf(stderr,
8277                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8278                         res->cmd_pid, rte_strerror(-ret));
8279                 return;
8280         }
8281         num = ret;
8282
8283         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8284         if (info == NULL) {
8285                 fprintf(stderr,
8286                         "Failed to allocate memory for representor info for port %hu\n",
8287                         res->cmd_pid);
8288                 return;
8289         }
8290         info->nb_ranges_alloc = num;
8291
8292         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8293         if (ret < 0) {
8294                 fprintf(stderr,
8295                         "Failed to get the representor info for port %hu: %s\n",
8296                         res->cmd_pid, rte_strerror(-ret));
8297                 free(info);
8298                 return;
8299         }
8300
8301         printf("Port controller: %hu\n", info->controller);
8302         printf("Port PF: %hu\n", info->pf);
8303
8304         printf("Ranges: %u\n", info->nb_ranges);
8305         for (i = 0; i < info->nb_ranges; i++) {
8306                 range = &info->ranges[i];
8307                 range_diff = range->id_end - range->id_base;
8308
8309                 printf("%u. ", i + 1);
8310                 printf("'%s' ", range->name);
8311                 if (range_diff > 0)
8312                         printf("[%u-%u]: ", range->id_base, range->id_end);
8313                 else
8314                         printf("[%u]: ", range->id_base);
8315
8316                 printf("Controller %d, PF %d", range->controller, range->pf);
8317
8318                 switch (range->type) {
8319                 case RTE_ETH_REPRESENTOR_NONE:
8320                         printf(", NONE\n");
8321                         break;
8322                 case RTE_ETH_REPRESENTOR_VF:
8323                         if (range_diff > 0)
8324                                 printf(", VF %d..%d\n", range->vf,
8325                                        range->vf + range_diff);
8326                         else
8327                                 printf(", VF %d\n", range->vf);
8328                         break;
8329                 case RTE_ETH_REPRESENTOR_SF:
8330                         printf(", SF %d\n", range->sf);
8331                         break;
8332                 case RTE_ETH_REPRESENTOR_PF:
8333                         if (range_diff > 0)
8334                                 printf("..%d\n", range->pf + range_diff);
8335                         else
8336                                 printf("\n");
8337                         break;
8338                 default:
8339                         printf(", UNKNOWN TYPE %d\n", range->type);
8340                         break;
8341                 }
8342         }
8343
8344         free(info);
8345 }
8346
8347 static cmdline_parse_token_string_t cmd_representor_info_show =
8348         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8349                         cmd_show, "show");
8350 static cmdline_parse_token_string_t cmd_representor_info_port =
8351         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8352                         cmd_port, "port");
8353 static cmdline_parse_token_string_t cmd_representor_info_info =
8354         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8355                         cmd_info, "info");
8356 static cmdline_parse_token_num_t cmd_representor_info_pid =
8357         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8358                         cmd_pid, RTE_UINT16);
8359 static cmdline_parse_token_string_t cmd_representor_info_keyword =
8360         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8361                         cmd_keyword, "representor");
8362
8363 static cmdline_parse_inst_t cmd_representor_info = {
8364         .f = cmd_representor_info_parsed,
8365         .data = NULL,
8366         .help_str = "show port info <port_id> representor",
8367         .tokens = {
8368                 (void *)&cmd_representor_info_show,
8369                 (void *)&cmd_representor_info_port,
8370                 (void *)&cmd_representor_info_info,
8371                 (void *)&cmd_representor_info_pid,
8372                 (void *)&cmd_representor_info_keyword,
8373                 NULL,
8374         },
8375 };
8376
8377
8378 /* *** SHOW DEVICE INFO *** */
8379 struct cmd_showdevice_result {
8380         cmdline_fixed_string_t show;
8381         cmdline_fixed_string_t device;
8382         cmdline_fixed_string_t what;
8383         cmdline_fixed_string_t identifier;
8384 };
8385
8386 static void cmd_showdevice_parsed(void *parsed_result,
8387                                 __rte_unused struct cmdline *cl,
8388                                 __rte_unused void *data)
8389 {
8390         struct cmd_showdevice_result *res = parsed_result;
8391         if (!strcmp(res->what, "info")) {
8392                 if (!strcmp(res->identifier, "all"))
8393                         device_infos_display(NULL);
8394                 else
8395                         device_infos_display(res->identifier);
8396         }
8397 }
8398
8399 static cmdline_parse_token_string_t cmd_showdevice_show =
8400         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8401                                  "show");
8402 static cmdline_parse_token_string_t cmd_showdevice_device =
8403         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8404 static cmdline_parse_token_string_t cmd_showdevice_what =
8405         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8406                                  "info");
8407 static cmdline_parse_token_string_t cmd_showdevice_identifier =
8408         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8409                         identifier, NULL);
8410
8411 static cmdline_parse_inst_t cmd_showdevice = {
8412         .f = cmd_showdevice_parsed,
8413         .data = NULL,
8414         .help_str = "show device info <identifier>|all",
8415         .tokens = {
8416                 (void *)&cmd_showdevice_show,
8417                 (void *)&cmd_showdevice_device,
8418                 (void *)&cmd_showdevice_what,
8419                 (void *)&cmd_showdevice_identifier,
8420                 NULL,
8421         },
8422 };
8423
8424 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8425 struct cmd_showeeprom_result {
8426         cmdline_fixed_string_t show;
8427         cmdline_fixed_string_t port;
8428         uint16_t portnum;
8429         cmdline_fixed_string_t type;
8430 };
8431
8432 static void cmd_showeeprom_parsed(void *parsed_result,
8433                 __rte_unused struct cmdline *cl,
8434                 __rte_unused void *data)
8435 {
8436         struct cmd_showeeprom_result *res = parsed_result;
8437
8438         if (!strcmp(res->type, "eeprom"))
8439                 port_eeprom_display(res->portnum);
8440         else if (!strcmp(res->type, "module_eeprom"))
8441                 port_module_eeprom_display(res->portnum);
8442         else
8443                 fprintf(stderr, "Unknown argument\n");
8444 }
8445
8446 static cmdline_parse_token_string_t cmd_showeeprom_show =
8447         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8448 static cmdline_parse_token_string_t cmd_showeeprom_port =
8449         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8450 static cmdline_parse_token_num_t cmd_showeeprom_portnum =
8451         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8452                         RTE_UINT16);
8453 static cmdline_parse_token_string_t cmd_showeeprom_type =
8454         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8455
8456 static cmdline_parse_inst_t cmd_showeeprom = {
8457         .f = cmd_showeeprom_parsed,
8458         .data = NULL,
8459         .help_str = "show port <port_id> module_eeprom|eeprom",
8460         .tokens = {
8461                 (void *)&cmd_showeeprom_show,
8462                 (void *)&cmd_showeeprom_port,
8463                 (void *)&cmd_showeeprom_portnum,
8464                 (void *)&cmd_showeeprom_type,
8465                 NULL,
8466         },
8467 };
8468
8469 /* *** SHOW QUEUE INFO *** */
8470 struct cmd_showqueue_result {
8471         cmdline_fixed_string_t show;
8472         cmdline_fixed_string_t type;
8473         cmdline_fixed_string_t what;
8474         uint16_t portnum;
8475         uint16_t queuenum;
8476 };
8477
8478 static void
8479 cmd_showqueue_parsed(void *parsed_result,
8480         __rte_unused struct cmdline *cl,
8481         __rte_unused void *data)
8482 {
8483         struct cmd_showqueue_result *res = parsed_result;
8484
8485         if (!strcmp(res->type, "rxq"))
8486                 rx_queue_infos_display(res->portnum, res->queuenum);
8487         else if (!strcmp(res->type, "txq"))
8488                 tx_queue_infos_display(res->portnum, res->queuenum);
8489 }
8490
8491 static cmdline_parse_token_string_t cmd_showqueue_show =
8492         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8493 static cmdline_parse_token_string_t cmd_showqueue_type =
8494         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8495 static cmdline_parse_token_string_t cmd_showqueue_what =
8496         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8497 static cmdline_parse_token_num_t cmd_showqueue_portnum =
8498         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8499                 RTE_UINT16);
8500 static cmdline_parse_token_num_t cmd_showqueue_queuenum =
8501         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8502                 RTE_UINT16);
8503
8504 static cmdline_parse_inst_t cmd_showqueue = {
8505         .f = cmd_showqueue_parsed,
8506         .data = NULL,
8507         .help_str = "show rxq|txq info <port_id> <queue_id>",
8508         .tokens = {
8509                 (void *)&cmd_showqueue_show,
8510                 (void *)&cmd_showqueue_type,
8511                 (void *)&cmd_showqueue_what,
8512                 (void *)&cmd_showqueue_portnum,
8513                 (void *)&cmd_showqueue_queuenum,
8514                 NULL,
8515         },
8516 };
8517
8518 /* show/clear fwd engine statistics */
8519 struct fwd_result {
8520         cmdline_fixed_string_t action;
8521         cmdline_fixed_string_t fwd;
8522         cmdline_fixed_string_t stats;
8523         cmdline_fixed_string_t all;
8524 };
8525
8526 static cmdline_parse_token_string_t cmd_fwd_action =
8527         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8528 static cmdline_parse_token_string_t cmd_fwd_fwd =
8529         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8530 static cmdline_parse_token_string_t cmd_fwd_stats =
8531         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8532 static cmdline_parse_token_string_t cmd_fwd_all =
8533         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8534
8535 static void
8536 cmd_showfwdall_parsed(void *parsed_result,
8537                       __rte_unused struct cmdline *cl,
8538                       __rte_unused void *data)
8539 {
8540         struct fwd_result *res = parsed_result;
8541
8542         if (!strcmp(res->action, "show"))
8543                 fwd_stats_display();
8544         else
8545                 fwd_stats_reset();
8546 }
8547
8548 static cmdline_parse_inst_t cmd_showfwdall = {
8549         .f = cmd_showfwdall_parsed,
8550         .data = NULL,
8551         .help_str = "show|clear fwd stats all",
8552         .tokens = {
8553                 (void *)&cmd_fwd_action,
8554                 (void *)&cmd_fwd_fwd,
8555                 (void *)&cmd_fwd_stats,
8556                 (void *)&cmd_fwd_all,
8557                 NULL,
8558         },
8559 };
8560
8561 /* *** READ PORT REGISTER *** */
8562 struct cmd_read_reg_result {
8563         cmdline_fixed_string_t read;
8564         cmdline_fixed_string_t reg;
8565         portid_t port_id;
8566         uint32_t reg_off;
8567 };
8568
8569 static void
8570 cmd_read_reg_parsed(void *parsed_result,
8571                     __rte_unused struct cmdline *cl,
8572                     __rte_unused void *data)
8573 {
8574         struct cmd_read_reg_result *res = parsed_result;
8575         port_reg_display(res->port_id, res->reg_off);
8576 }
8577
8578 static cmdline_parse_token_string_t cmd_read_reg_read =
8579         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8580 static cmdline_parse_token_string_t cmd_read_reg_reg =
8581         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8582 static cmdline_parse_token_num_t cmd_read_reg_port_id =
8583         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8584 static cmdline_parse_token_num_t cmd_read_reg_reg_off =
8585         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8586
8587 static cmdline_parse_inst_t cmd_read_reg = {
8588         .f = cmd_read_reg_parsed,
8589         .data = NULL,
8590         .help_str = "read reg <port_id> <reg_off>",
8591         .tokens = {
8592                 (void *)&cmd_read_reg_read,
8593                 (void *)&cmd_read_reg_reg,
8594                 (void *)&cmd_read_reg_port_id,
8595                 (void *)&cmd_read_reg_reg_off,
8596                 NULL,
8597         },
8598 };
8599
8600 /* *** READ PORT REGISTER BIT FIELD *** */
8601 struct cmd_read_reg_bit_field_result {
8602         cmdline_fixed_string_t read;
8603         cmdline_fixed_string_t regfield;
8604         portid_t port_id;
8605         uint32_t reg_off;
8606         uint8_t bit1_pos;
8607         uint8_t bit2_pos;
8608 };
8609
8610 static void
8611 cmd_read_reg_bit_field_parsed(void *parsed_result,
8612                               __rte_unused struct cmdline *cl,
8613                               __rte_unused void *data)
8614 {
8615         struct cmd_read_reg_bit_field_result *res = parsed_result;
8616         port_reg_bit_field_display(res->port_id, res->reg_off,
8617                                    res->bit1_pos, res->bit2_pos);
8618 }
8619
8620 static cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8621         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8622                                  "read");
8623 static cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8624         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8625                                  regfield, "regfield");
8626 static cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8627         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8628                               RTE_UINT16);
8629 static cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8630         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8631                               RTE_UINT32);
8632 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8633         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8634                               RTE_UINT8);
8635 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8636         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8637                               RTE_UINT8);
8638
8639 static cmdline_parse_inst_t cmd_read_reg_bit_field = {
8640         .f = cmd_read_reg_bit_field_parsed,
8641         .data = NULL,
8642         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8643         "Read register bit field between bit_x and bit_y included",
8644         .tokens = {
8645                 (void *)&cmd_read_reg_bit_field_read,
8646                 (void *)&cmd_read_reg_bit_field_regfield,
8647                 (void *)&cmd_read_reg_bit_field_port_id,
8648                 (void *)&cmd_read_reg_bit_field_reg_off,
8649                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8650                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8651                 NULL,
8652         },
8653 };
8654
8655 /* *** READ PORT REGISTER BIT *** */
8656 struct cmd_read_reg_bit_result {
8657         cmdline_fixed_string_t read;
8658         cmdline_fixed_string_t regbit;
8659         portid_t port_id;
8660         uint32_t reg_off;
8661         uint8_t bit_pos;
8662 };
8663
8664 static void
8665 cmd_read_reg_bit_parsed(void *parsed_result,
8666                         __rte_unused struct cmdline *cl,
8667                         __rte_unused void *data)
8668 {
8669         struct cmd_read_reg_bit_result *res = parsed_result;
8670         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8671 }
8672
8673 static cmdline_parse_token_string_t cmd_read_reg_bit_read =
8674         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8675 static cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8676         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8677                                  regbit, "regbit");
8678 static cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8679         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8680                                  RTE_UINT16);
8681 static cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8682         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8683                                  RTE_UINT32);
8684 static cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8685         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8686                                  RTE_UINT8);
8687
8688 static cmdline_parse_inst_t cmd_read_reg_bit = {
8689         .f = cmd_read_reg_bit_parsed,
8690         .data = NULL,
8691         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8692         .tokens = {
8693                 (void *)&cmd_read_reg_bit_read,
8694                 (void *)&cmd_read_reg_bit_regbit,
8695                 (void *)&cmd_read_reg_bit_port_id,
8696                 (void *)&cmd_read_reg_bit_reg_off,
8697                 (void *)&cmd_read_reg_bit_bit_pos,
8698                 NULL,
8699         },
8700 };
8701
8702 /* *** WRITE PORT REGISTER *** */
8703 struct cmd_write_reg_result {
8704         cmdline_fixed_string_t write;
8705         cmdline_fixed_string_t reg;
8706         portid_t port_id;
8707         uint32_t reg_off;
8708         uint32_t value;
8709 };
8710
8711 static void
8712 cmd_write_reg_parsed(void *parsed_result,
8713                      __rte_unused struct cmdline *cl,
8714                      __rte_unused void *data)
8715 {
8716         struct cmd_write_reg_result *res = parsed_result;
8717         port_reg_set(res->port_id, res->reg_off, res->value);
8718 }
8719
8720 static cmdline_parse_token_string_t cmd_write_reg_write =
8721         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8722 static cmdline_parse_token_string_t cmd_write_reg_reg =
8723         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8724 static cmdline_parse_token_num_t cmd_write_reg_port_id =
8725         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8726 static cmdline_parse_token_num_t cmd_write_reg_reg_off =
8727         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8728 static cmdline_parse_token_num_t cmd_write_reg_value =
8729         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8730
8731 static cmdline_parse_inst_t cmd_write_reg = {
8732         .f = cmd_write_reg_parsed,
8733         .data = NULL,
8734         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8735         .tokens = {
8736                 (void *)&cmd_write_reg_write,
8737                 (void *)&cmd_write_reg_reg,
8738                 (void *)&cmd_write_reg_port_id,
8739                 (void *)&cmd_write_reg_reg_off,
8740                 (void *)&cmd_write_reg_value,
8741                 NULL,
8742         },
8743 };
8744
8745 /* *** WRITE PORT REGISTER BIT FIELD *** */
8746 struct cmd_write_reg_bit_field_result {
8747         cmdline_fixed_string_t write;
8748         cmdline_fixed_string_t regfield;
8749         portid_t port_id;
8750         uint32_t reg_off;
8751         uint8_t bit1_pos;
8752         uint8_t bit2_pos;
8753         uint32_t value;
8754 };
8755
8756 static void
8757 cmd_write_reg_bit_field_parsed(void *parsed_result,
8758                                __rte_unused struct cmdline *cl,
8759                                __rte_unused void *data)
8760 {
8761         struct cmd_write_reg_bit_field_result *res = parsed_result;
8762         port_reg_bit_field_set(res->port_id, res->reg_off,
8763                           res->bit1_pos, res->bit2_pos, res->value);
8764 }
8765
8766 static cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8767         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8768                                  "write");
8769 static cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8770         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8771                                  regfield, "regfield");
8772 static cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8773         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8774                               RTE_UINT16);
8775 static cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8776         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8777                               RTE_UINT32);
8778 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8779         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8780                               RTE_UINT8);
8781 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8782         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8783                               RTE_UINT8);
8784 static cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8785         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8786                               RTE_UINT32);
8787
8788 static cmdline_parse_inst_t cmd_write_reg_bit_field = {
8789         .f = cmd_write_reg_bit_field_parsed,
8790         .data = NULL,
8791         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8792                 "<reg_value>: "
8793                 "Set register bit field between bit_x and bit_y included",
8794         .tokens = {
8795                 (void *)&cmd_write_reg_bit_field_write,
8796                 (void *)&cmd_write_reg_bit_field_regfield,
8797                 (void *)&cmd_write_reg_bit_field_port_id,
8798                 (void *)&cmd_write_reg_bit_field_reg_off,
8799                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8800                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8801                 (void *)&cmd_write_reg_bit_field_value,
8802                 NULL,
8803         },
8804 };
8805
8806 /* *** WRITE PORT REGISTER BIT *** */
8807 struct cmd_write_reg_bit_result {
8808         cmdline_fixed_string_t write;
8809         cmdline_fixed_string_t regbit;
8810         portid_t port_id;
8811         uint32_t reg_off;
8812         uint8_t bit_pos;
8813         uint8_t value;
8814 };
8815
8816 static void
8817 cmd_write_reg_bit_parsed(void *parsed_result,
8818                          __rte_unused struct cmdline *cl,
8819                          __rte_unused void *data)
8820 {
8821         struct cmd_write_reg_bit_result *res = parsed_result;
8822         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8823 }
8824
8825 static cmdline_parse_token_string_t cmd_write_reg_bit_write =
8826         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8827                                  "write");
8828 static cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8829         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8830                                  regbit, "regbit");
8831 static cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8832         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8833                                  RTE_UINT16);
8834 static cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8835         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8836                                  RTE_UINT32);
8837 static cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8838         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8839                                  RTE_UINT8);
8840 static cmdline_parse_token_num_t cmd_write_reg_bit_value =
8841         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8842                                  RTE_UINT8);
8843
8844 static cmdline_parse_inst_t cmd_write_reg_bit = {
8845         .f = cmd_write_reg_bit_parsed,
8846         .data = NULL,
8847         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8848                 "0 <= bit_x <= 31",
8849         .tokens = {
8850                 (void *)&cmd_write_reg_bit_write,
8851                 (void *)&cmd_write_reg_bit_regbit,
8852                 (void *)&cmd_write_reg_bit_port_id,
8853                 (void *)&cmd_write_reg_bit_reg_off,
8854                 (void *)&cmd_write_reg_bit_bit_pos,
8855                 (void *)&cmd_write_reg_bit_value,
8856                 NULL,
8857         },
8858 };
8859
8860 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8861 struct cmd_read_rxd_txd_result {
8862         cmdline_fixed_string_t read;
8863         cmdline_fixed_string_t rxd_txd;
8864         portid_t port_id;
8865         uint16_t queue_id;
8866         uint16_t desc_id;
8867 };
8868
8869 static void
8870 cmd_read_rxd_txd_parsed(void *parsed_result,
8871                         __rte_unused struct cmdline *cl,
8872                         __rte_unused void *data)
8873 {
8874         struct cmd_read_rxd_txd_result *res = parsed_result;
8875
8876         if (!strcmp(res->rxd_txd, "rxd"))
8877                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8878         else if (!strcmp(res->rxd_txd, "txd"))
8879                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8880 }
8881
8882 static cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8883         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8884 static cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8885         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8886                                  "rxd#txd");
8887 static cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8888         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8889                                  RTE_UINT16);
8890 static cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8891         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8892                                  RTE_UINT16);
8893 static cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8894         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8895                                  RTE_UINT16);
8896
8897 static cmdline_parse_inst_t cmd_read_rxd_txd = {
8898         .f = cmd_read_rxd_txd_parsed,
8899         .data = NULL,
8900         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8901         .tokens = {
8902                 (void *)&cmd_read_rxd_txd_read,
8903                 (void *)&cmd_read_rxd_txd_rxd_txd,
8904                 (void *)&cmd_read_rxd_txd_port_id,
8905                 (void *)&cmd_read_rxd_txd_queue_id,
8906                 (void *)&cmd_read_rxd_txd_desc_id,
8907                 NULL,
8908         },
8909 };
8910
8911 /* *** QUIT *** */
8912 struct cmd_quit_result {
8913         cmdline_fixed_string_t quit;
8914 };
8915
8916 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8917                             struct cmdline *cl,
8918                             __rte_unused void *data)
8919 {
8920         cmdline_quit(cl);
8921         cl_quit = 1;
8922 }
8923
8924 static cmdline_parse_token_string_t cmd_quit_quit =
8925         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8926
8927 static cmdline_parse_inst_t cmd_quit = {
8928         .f = cmd_quit_parsed,
8929         .data = NULL,
8930         .help_str = "quit: Exit application",
8931         .tokens = {
8932                 (void *)&cmd_quit_quit,
8933                 NULL,
8934         },
8935 };
8936
8937 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8938 struct cmd_mac_addr_result {
8939         cmdline_fixed_string_t mac_addr_cmd;
8940         cmdline_fixed_string_t what;
8941         uint16_t port_num;
8942         struct rte_ether_addr address;
8943 };
8944
8945 static void cmd_mac_addr_parsed(void *parsed_result,
8946                 __rte_unused struct cmdline *cl,
8947                 __rte_unused void *data)
8948 {
8949         struct cmd_mac_addr_result *res = parsed_result;
8950         int ret;
8951
8952         if (strcmp(res->what, "add") == 0)
8953                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8954         else if (strcmp(res->what, "set") == 0)
8955                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8956                                                        &res->address);
8957         else
8958                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8959
8960         /* check the return value and print it if is < 0 */
8961         if(ret < 0)
8962                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8963
8964 }
8965
8966 static cmdline_parse_token_string_t cmd_mac_addr_cmd =
8967         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8968                                 "mac_addr");
8969 static cmdline_parse_token_string_t cmd_mac_addr_what =
8970         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8971                                 "add#remove#set");
8972 static cmdline_parse_token_num_t cmd_mac_addr_portnum =
8973                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8974                                         RTE_UINT16);
8975 static cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8976                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8977
8978 static cmdline_parse_inst_t cmd_mac_addr = {
8979         .f = cmd_mac_addr_parsed,
8980         .data = (void *)0,
8981         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8982                         "Add/Remove/Set MAC address on port_id",
8983         .tokens = {
8984                 (void *)&cmd_mac_addr_cmd,
8985                 (void *)&cmd_mac_addr_what,
8986                 (void *)&cmd_mac_addr_portnum,
8987                 (void *)&cmd_mac_addr_addr,
8988                 NULL,
8989         },
8990 };
8991
8992 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8993 struct cmd_eth_peer_result {
8994         cmdline_fixed_string_t set;
8995         cmdline_fixed_string_t eth_peer;
8996         portid_t port_id;
8997         cmdline_fixed_string_t peer_addr;
8998 };
8999
9000 static void cmd_set_eth_peer_parsed(void *parsed_result,
9001                         __rte_unused struct cmdline *cl,
9002                         __rte_unused void *data)
9003 {
9004                 struct cmd_eth_peer_result *res = parsed_result;
9005
9006                 if (test_done == 0) {
9007                         fprintf(stderr, "Please stop forwarding first\n");
9008                         return;
9009                 }
9010                 if (!strcmp(res->eth_peer, "eth-peer")) {
9011                         set_fwd_eth_peer(res->port_id, res->peer_addr);
9012                         fwd_config_setup();
9013                 }
9014 }
9015 static cmdline_parse_token_string_t cmd_eth_peer_set =
9016         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
9017 static cmdline_parse_token_string_t cmd_eth_peer =
9018         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
9019 static cmdline_parse_token_num_t cmd_eth_peer_port_id =
9020         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
9021                 RTE_UINT16);
9022 static cmdline_parse_token_string_t cmd_eth_peer_addr =
9023         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
9024
9025 static cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
9026         .f = cmd_set_eth_peer_parsed,
9027         .data = NULL,
9028         .help_str = "set eth-peer <port_id> <peer_mac>",
9029         .tokens = {
9030                 (void *)&cmd_eth_peer_set,
9031                 (void *)&cmd_eth_peer,
9032                 (void *)&cmd_eth_peer_port_id,
9033                 (void *)&cmd_eth_peer_addr,
9034                 NULL,
9035         },
9036 };
9037
9038 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9039 struct cmd_set_qmap_result {
9040         cmdline_fixed_string_t set;
9041         cmdline_fixed_string_t qmap;
9042         cmdline_fixed_string_t what;
9043         portid_t port_id;
9044         uint16_t queue_id;
9045         uint8_t map_value;
9046 };
9047
9048 static void
9049 cmd_set_qmap_parsed(void *parsed_result,
9050                        __rte_unused struct cmdline *cl,
9051                        __rte_unused void *data)
9052 {
9053         struct cmd_set_qmap_result *res = parsed_result;
9054         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9055
9056         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9057 }
9058
9059 static cmdline_parse_token_string_t cmd_setqmap_set =
9060         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9061                                  set, "set");
9062 static cmdline_parse_token_string_t cmd_setqmap_qmap =
9063         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9064                                  qmap, "stat_qmap");
9065 static cmdline_parse_token_string_t cmd_setqmap_what =
9066         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9067                                  what, "tx#rx");
9068 static cmdline_parse_token_num_t cmd_setqmap_portid =
9069         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9070                               port_id, RTE_UINT16);
9071 static cmdline_parse_token_num_t cmd_setqmap_queueid =
9072         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9073                               queue_id, RTE_UINT16);
9074 static cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9075         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9076                               map_value, RTE_UINT8);
9077
9078 static cmdline_parse_inst_t cmd_set_qmap = {
9079         .f = cmd_set_qmap_parsed,
9080         .data = NULL,
9081         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9082                 "Set statistics mapping value on tx|rx queue_id of port_id",
9083         .tokens = {
9084                 (void *)&cmd_setqmap_set,
9085                 (void *)&cmd_setqmap_qmap,
9086                 (void *)&cmd_setqmap_what,
9087                 (void *)&cmd_setqmap_portid,
9088                 (void *)&cmd_setqmap_queueid,
9089                 (void *)&cmd_setqmap_mapvalue,
9090                 NULL,
9091         },
9092 };
9093
9094 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9095 struct cmd_set_xstats_hide_zero_result {
9096         cmdline_fixed_string_t keyword;
9097         cmdline_fixed_string_t name;
9098         cmdline_fixed_string_t on_off;
9099 };
9100
9101 static void
9102 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9103                         __rte_unused struct cmdline *cl,
9104                         __rte_unused void *data)
9105 {
9106         struct cmd_set_xstats_hide_zero_result *res;
9107         uint16_t on_off = 0;
9108
9109         res = parsed_result;
9110         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9111         set_xstats_hide_zero(on_off);
9112 }
9113
9114 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9115         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9116                                  keyword, "set");
9117 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9118         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9119                                  name, "xstats-hide-zero");
9120 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9121         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9122                                  on_off, "on#off");
9123
9124 static cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9125         .f = cmd_set_xstats_hide_zero_parsed,
9126         .data = NULL,
9127         .help_str = "set xstats-hide-zero on|off",
9128         .tokens = {
9129                 (void *)&cmd_set_xstats_hide_zero_keyword,
9130                 (void *)&cmd_set_xstats_hide_zero_name,
9131                 (void *)&cmd_set_xstats_hide_zero_on_off,
9132                 NULL,
9133         },
9134 };
9135
9136 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9137 struct cmd_set_record_core_cycles_result {
9138         cmdline_fixed_string_t keyword;
9139         cmdline_fixed_string_t name;
9140         cmdline_fixed_string_t on_off;
9141 };
9142
9143 static void
9144 cmd_set_record_core_cycles_parsed(void *parsed_result,
9145                         __rte_unused struct cmdline *cl,
9146                         __rte_unused void *data)
9147 {
9148         struct cmd_set_record_core_cycles_result *res;
9149         uint16_t on_off = 0;
9150
9151         res = parsed_result;
9152         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9153         set_record_core_cycles(on_off);
9154 }
9155
9156 static cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9157         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9158                                  keyword, "set");
9159 static cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9160         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9161                                  name, "record-core-cycles");
9162 static cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9163         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9164                                  on_off, "on#off");
9165
9166 static cmdline_parse_inst_t cmd_set_record_core_cycles = {
9167         .f = cmd_set_record_core_cycles_parsed,
9168         .data = NULL,
9169         .help_str = "set record-core-cycles on|off",
9170         .tokens = {
9171                 (void *)&cmd_set_record_core_cycles_keyword,
9172                 (void *)&cmd_set_record_core_cycles_name,
9173                 (void *)&cmd_set_record_core_cycles_on_off,
9174                 NULL,
9175         },
9176 };
9177
9178 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9179 struct cmd_set_record_burst_stats_result {
9180         cmdline_fixed_string_t keyword;
9181         cmdline_fixed_string_t name;
9182         cmdline_fixed_string_t on_off;
9183 };
9184
9185 static void
9186 cmd_set_record_burst_stats_parsed(void *parsed_result,
9187                         __rte_unused struct cmdline *cl,
9188                         __rte_unused void *data)
9189 {
9190         struct cmd_set_record_burst_stats_result *res;
9191         uint16_t on_off = 0;
9192
9193         res = parsed_result;
9194         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9195         set_record_burst_stats(on_off);
9196 }
9197
9198 static cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9199         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9200                                  keyword, "set");
9201 static cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9202         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9203                                  name, "record-burst-stats");
9204 static cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9205         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9206                                  on_off, "on#off");
9207
9208 static cmdline_parse_inst_t cmd_set_record_burst_stats = {
9209         .f = cmd_set_record_burst_stats_parsed,
9210         .data = NULL,
9211         .help_str = "set record-burst-stats on|off",
9212         .tokens = {
9213                 (void *)&cmd_set_record_burst_stats_keyword,
9214                 (void *)&cmd_set_record_burst_stats_name,
9215                 (void *)&cmd_set_record_burst_stats_on_off,
9216                 NULL,
9217         },
9218 };
9219
9220 /* *** CONFIGURE UNICAST HASH TABLE *** */
9221 struct cmd_set_uc_hash_table {
9222         cmdline_fixed_string_t set;
9223         cmdline_fixed_string_t port;
9224         portid_t port_id;
9225         cmdline_fixed_string_t what;
9226         struct rte_ether_addr address;
9227         cmdline_fixed_string_t mode;
9228 };
9229
9230 static void
9231 cmd_set_uc_hash_parsed(void *parsed_result,
9232                        __rte_unused struct cmdline *cl,
9233                        __rte_unused void *data)
9234 {
9235         int ret=0;
9236         struct cmd_set_uc_hash_table *res = parsed_result;
9237
9238         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9239
9240         if (strcmp(res->what, "uta") == 0)
9241                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9242                                                 &res->address,(uint8_t)is_on);
9243         if (ret < 0)
9244                 fprintf(stderr,
9245                         "bad unicast hash table parameter, return code = %d\n",
9246                         ret);
9247
9248 }
9249
9250 static cmdline_parse_token_string_t cmd_set_uc_hash_set =
9251         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9252                                  set, "set");
9253 static cmdline_parse_token_string_t cmd_set_uc_hash_port =
9254         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9255                                  port, "port");
9256 static cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9257         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9258                               port_id, RTE_UINT16);
9259 static cmdline_parse_token_string_t cmd_set_uc_hash_what =
9260         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9261                                  what, "uta");
9262 static cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9263         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9264                                 address);
9265 static cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9266         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9267                                  mode, "on#off");
9268
9269 static cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9270         .f = cmd_set_uc_hash_parsed,
9271         .data = NULL,
9272         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9273         .tokens = {
9274                 (void *)&cmd_set_uc_hash_set,
9275                 (void *)&cmd_set_uc_hash_port,
9276                 (void *)&cmd_set_uc_hash_portid,
9277                 (void *)&cmd_set_uc_hash_what,
9278                 (void *)&cmd_set_uc_hash_mac,
9279                 (void *)&cmd_set_uc_hash_mode,
9280                 NULL,
9281         },
9282 };
9283
9284 struct cmd_set_uc_all_hash_table {
9285         cmdline_fixed_string_t set;
9286         cmdline_fixed_string_t port;
9287         portid_t port_id;
9288         cmdline_fixed_string_t what;
9289         cmdline_fixed_string_t value;
9290         cmdline_fixed_string_t mode;
9291 };
9292
9293 static void
9294 cmd_set_uc_all_hash_parsed(void *parsed_result,
9295                        __rte_unused struct cmdline *cl,
9296                        __rte_unused void *data)
9297 {
9298         int ret=0;
9299         struct cmd_set_uc_all_hash_table *res = parsed_result;
9300
9301         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9302
9303         if ((strcmp(res->what, "uta") == 0) &&
9304                 (strcmp(res->value, "all") == 0))
9305                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9306         if (ret < 0)
9307                 fprintf(stderr,
9308                         "bad unicast hash table parameter, return code = %d\n",
9309                         ret);
9310 }
9311
9312 static cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9313         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9314                                  set, "set");
9315 static cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9316         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9317                                  port, "port");
9318 static cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9319         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9320                               port_id, RTE_UINT16);
9321 static cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9322         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9323                                  what, "uta");
9324 static cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9325         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9326                                 value,"all");
9327 static cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9328         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9329                                  mode, "on#off");
9330
9331 static cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9332         .f = cmd_set_uc_all_hash_parsed,
9333         .data = NULL,
9334         .help_str = "set port <port_id> uta all on|off",
9335         .tokens = {
9336                 (void *)&cmd_set_uc_all_hash_set,
9337                 (void *)&cmd_set_uc_all_hash_port,
9338                 (void *)&cmd_set_uc_all_hash_portid,
9339                 (void *)&cmd_set_uc_all_hash_what,
9340                 (void *)&cmd_set_uc_all_hash_value,
9341                 (void *)&cmd_set_uc_all_hash_mode,
9342                 NULL,
9343         },
9344 };
9345
9346 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9347 struct cmd_set_vf_traffic {
9348         cmdline_fixed_string_t set;
9349         cmdline_fixed_string_t port;
9350         portid_t port_id;
9351         cmdline_fixed_string_t vf;
9352         uint8_t vf_id;
9353         cmdline_fixed_string_t what;
9354         cmdline_fixed_string_t mode;
9355 };
9356
9357 static void
9358 cmd_set_vf_traffic_parsed(void *parsed_result,
9359                        __rte_unused struct cmdline *cl,
9360                        __rte_unused void *data)
9361 {
9362         struct cmd_set_vf_traffic *res = parsed_result;
9363         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9364         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9365
9366         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9367 }
9368
9369 static cmdline_parse_token_string_t cmd_setvf_traffic_set =
9370         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9371                                  set, "set");
9372 static cmdline_parse_token_string_t cmd_setvf_traffic_port =
9373         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9374                                  port, "port");
9375 static cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9376         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9377                               port_id, RTE_UINT16);
9378 static cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9379         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9380                                  vf, "vf");
9381 static cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9382         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9383                               vf_id, RTE_UINT8);
9384 static cmdline_parse_token_string_t cmd_setvf_traffic_what =
9385         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9386                                  what, "tx#rx");
9387 static cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9388         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9389                                  mode, "on#off");
9390
9391 static cmdline_parse_inst_t cmd_set_vf_traffic = {
9392         .f = cmd_set_vf_traffic_parsed,
9393         .data = NULL,
9394         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9395         .tokens = {
9396                 (void *)&cmd_setvf_traffic_set,
9397                 (void *)&cmd_setvf_traffic_port,
9398                 (void *)&cmd_setvf_traffic_portid,
9399                 (void *)&cmd_setvf_traffic_vf,
9400                 (void *)&cmd_setvf_traffic_vfid,
9401                 (void *)&cmd_setvf_traffic_what,
9402                 (void *)&cmd_setvf_traffic_mode,
9403                 NULL,
9404         },
9405 };
9406
9407 /* *** CONFIGURE VF RECEIVE MODE *** */
9408 struct cmd_set_vf_rxmode {
9409         cmdline_fixed_string_t set;
9410         cmdline_fixed_string_t port;
9411         portid_t port_id;
9412         cmdline_fixed_string_t vf;
9413         uint8_t vf_id;
9414         cmdline_fixed_string_t what;
9415         cmdline_fixed_string_t mode;
9416         cmdline_fixed_string_t on;
9417 };
9418
9419 static void
9420 cmd_set_vf_rxmode_parsed(void *parsed_result,
9421                        __rte_unused struct cmdline *cl,
9422                        __rte_unused void *data)
9423 {
9424         int ret = -ENOTSUP;
9425         uint16_t vf_rxmode = 0;
9426         struct cmd_set_vf_rxmode *res = parsed_result;
9427
9428         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9429         if (!strcmp(res->what,"rxmode")) {
9430                 if (!strcmp(res->mode, "AUPE"))
9431                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9432                 else if (!strcmp(res->mode, "ROPE"))
9433                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9434                 else if (!strcmp(res->mode, "BAM"))
9435                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9436                 else if (!strncmp(res->mode, "MPE",3))
9437                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9438         }
9439
9440         RTE_SET_USED(is_on);
9441         RTE_SET_USED(vf_rxmode);
9442
9443 #ifdef RTE_NET_IXGBE
9444         if (ret == -ENOTSUP)
9445                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9446                                                   vf_rxmode, (uint8_t)is_on);
9447 #endif
9448 #ifdef RTE_NET_BNXT
9449         if (ret == -ENOTSUP)
9450                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9451                                                  vf_rxmode, (uint8_t)is_on);
9452 #endif
9453         if (ret < 0)
9454                 fprintf(stderr,
9455                         "bad VF receive mode parameter, return code = %d\n",
9456                         ret);
9457 }
9458
9459 static cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9460         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9461                                  set, "set");
9462 static cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9463         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9464                                  port, "port");
9465 static cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9466         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9467                               port_id, RTE_UINT16);
9468 static cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9469         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9470                                  vf, "vf");
9471 static cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9472         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9473                               vf_id, RTE_UINT8);
9474 static cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9475         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9476                                  what, "rxmode");
9477 static cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9478         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9479                                  mode, "AUPE#ROPE#BAM#MPE");
9480 static cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9481         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9482                                  on, "on#off");
9483
9484 static cmdline_parse_inst_t cmd_set_vf_rxmode = {
9485         .f = cmd_set_vf_rxmode_parsed,
9486         .data = NULL,
9487         .help_str = "set port <port_id> vf <vf_id> rxmode "
9488                 "AUPE|ROPE|BAM|MPE on|off",
9489         .tokens = {
9490                 (void *)&cmd_set_vf_rxmode_set,
9491                 (void *)&cmd_set_vf_rxmode_port,
9492                 (void *)&cmd_set_vf_rxmode_portid,
9493                 (void *)&cmd_set_vf_rxmode_vf,
9494                 (void *)&cmd_set_vf_rxmode_vfid,
9495                 (void *)&cmd_set_vf_rxmode_what,
9496                 (void *)&cmd_set_vf_rxmode_mode,
9497                 (void *)&cmd_set_vf_rxmode_on,
9498                 NULL,
9499         },
9500 };
9501
9502 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9503 struct cmd_vf_mac_addr_result {
9504         cmdline_fixed_string_t mac_addr_cmd;
9505         cmdline_fixed_string_t what;
9506         cmdline_fixed_string_t port;
9507         uint16_t port_num;
9508         cmdline_fixed_string_t vf;
9509         uint8_t vf_num;
9510         struct rte_ether_addr address;
9511 };
9512
9513 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9514                 __rte_unused struct cmdline *cl,
9515                 __rte_unused void *data)
9516 {
9517         struct cmd_vf_mac_addr_result *res = parsed_result;
9518         int ret = -ENOTSUP;
9519
9520         if (strcmp(res->what, "add") != 0)
9521                 return;
9522
9523 #ifdef RTE_NET_I40E
9524         if (ret == -ENOTSUP)
9525                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9526                                                    &res->address);
9527 #endif
9528 #ifdef RTE_NET_BNXT
9529         if (ret == -ENOTSUP)
9530                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9531                                                 res->vf_num);
9532 #endif
9533
9534         if(ret < 0)
9535                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9536
9537 }
9538
9539 static cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9540         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9541                                 mac_addr_cmd,"mac_addr");
9542 static cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9543         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9544                                 what,"add");
9545 static cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9546         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9547                                 port,"port");
9548 static cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9549         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9550                                 port_num, RTE_UINT16);
9551 static cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9552         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9553                                 vf,"vf");
9554 static cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9555         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9556                                 vf_num, RTE_UINT8);
9557 static cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9558         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9559                                 address);
9560
9561 static cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9562         .f = cmd_vf_mac_addr_parsed,
9563         .data = (void *)0,
9564         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9565                 "Add MAC address filtering for a VF on port_id",
9566         .tokens = {
9567                 (void *)&cmd_vf_mac_addr_cmd,
9568                 (void *)&cmd_vf_mac_addr_what,
9569                 (void *)&cmd_vf_mac_addr_port,
9570                 (void *)&cmd_vf_mac_addr_portnum,
9571                 (void *)&cmd_vf_mac_addr_vf,
9572                 (void *)&cmd_vf_mac_addr_vfnum,
9573                 (void *)&cmd_vf_mac_addr_addr,
9574                 NULL,
9575         },
9576 };
9577
9578 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9579 struct cmd_vf_rx_vlan_filter {
9580         cmdline_fixed_string_t rx_vlan;
9581         cmdline_fixed_string_t what;
9582         uint16_t vlan_id;
9583         cmdline_fixed_string_t port;
9584         portid_t port_id;
9585         cmdline_fixed_string_t vf;
9586         uint64_t vf_mask;
9587 };
9588
9589 static void
9590 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9591                           __rte_unused struct cmdline *cl,
9592                           __rte_unused void *data)
9593 {
9594         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9595         int ret = -ENOTSUP;
9596
9597         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9598
9599 #ifdef RTE_NET_IXGBE
9600         if (ret == -ENOTSUP)
9601                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9602                                 res->vlan_id, res->vf_mask, is_add);
9603 #endif
9604 #ifdef RTE_NET_I40E
9605         if (ret == -ENOTSUP)
9606                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9607                                 res->vlan_id, res->vf_mask, is_add);
9608 #endif
9609 #ifdef RTE_NET_BNXT
9610         if (ret == -ENOTSUP)
9611                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9612                                 res->vlan_id, res->vf_mask, is_add);
9613 #endif
9614
9615         switch (ret) {
9616         case 0:
9617                 break;
9618         case -EINVAL:
9619                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9620                         res->vlan_id, res->vf_mask);
9621                 break;
9622         case -ENODEV:
9623                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9624                 break;
9625         case -ENOTSUP:
9626                 fprintf(stderr, "function not implemented or supported\n");
9627                 break;
9628         default:
9629                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9630         }
9631 }
9632
9633 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9634         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9635                                  rx_vlan, "rx_vlan");
9636 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9637         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9638                                  what, "add#rm");
9639 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9640         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9641                               vlan_id, RTE_UINT16);
9642 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9643         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9644                                  port, "port");
9645 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9646         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9647                               port_id, RTE_UINT16);
9648 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9649         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9650                                  vf, "vf");
9651 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9652         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9653                               vf_mask, RTE_UINT64);
9654
9655 static cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9656         .f = cmd_vf_rx_vlan_filter_parsed,
9657         .data = NULL,
9658         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9659                 "(vf_mask = hexadecimal VF mask)",
9660         .tokens = {
9661                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9662                 (void *)&cmd_vf_rx_vlan_filter_what,
9663                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9664                 (void *)&cmd_vf_rx_vlan_filter_port,
9665                 (void *)&cmd_vf_rx_vlan_filter_portid,
9666                 (void *)&cmd_vf_rx_vlan_filter_vf,
9667                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9668                 NULL,
9669         },
9670 };
9671
9672 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9673 struct cmd_queue_rate_limit_result {
9674         cmdline_fixed_string_t set;
9675         cmdline_fixed_string_t port;
9676         uint16_t port_num;
9677         cmdline_fixed_string_t queue;
9678         uint8_t queue_num;
9679         cmdline_fixed_string_t rate;
9680         uint16_t rate_num;
9681 };
9682
9683 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9684                 __rte_unused struct cmdline *cl,
9685                 __rte_unused void *data)
9686 {
9687         struct cmd_queue_rate_limit_result *res = parsed_result;
9688         int ret = 0;
9689
9690         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9691                 && (strcmp(res->queue, "queue") == 0)
9692                 && (strcmp(res->rate, "rate") == 0))
9693                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9694                                         res->rate_num);
9695         if (ret < 0)
9696                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9697                         strerror(-ret));
9698
9699 }
9700
9701 static cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9702         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9703                                 set, "set");
9704 static cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9705         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9706                                 port, "port");
9707 static cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9708         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9709                                 port_num, RTE_UINT16);
9710 static cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9711         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9712                                 queue, "queue");
9713 static cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9714         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9715                                 queue_num, RTE_UINT8);
9716 static cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9717         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9718                                 rate, "rate");
9719 static cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9720         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9721                                 rate_num, RTE_UINT16);
9722
9723 static cmdline_parse_inst_t cmd_queue_rate_limit = {
9724         .f = cmd_queue_rate_limit_parsed,
9725         .data = (void *)0,
9726         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9727                 "Set rate limit for a queue on port_id",
9728         .tokens = {
9729                 (void *)&cmd_queue_rate_limit_set,
9730                 (void *)&cmd_queue_rate_limit_port,
9731                 (void *)&cmd_queue_rate_limit_portnum,
9732                 (void *)&cmd_queue_rate_limit_queue,
9733                 (void *)&cmd_queue_rate_limit_queuenum,
9734                 (void *)&cmd_queue_rate_limit_rate,
9735                 (void *)&cmd_queue_rate_limit_ratenum,
9736                 NULL,
9737         },
9738 };
9739
9740 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9741 struct cmd_vf_rate_limit_result {
9742         cmdline_fixed_string_t set;
9743         cmdline_fixed_string_t port;
9744         uint16_t port_num;
9745         cmdline_fixed_string_t vf;
9746         uint8_t vf_num;
9747         cmdline_fixed_string_t rate;
9748         uint16_t rate_num;
9749         cmdline_fixed_string_t q_msk;
9750         uint64_t q_msk_val;
9751 };
9752
9753 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9754                 __rte_unused struct cmdline *cl,
9755                 __rte_unused void *data)
9756 {
9757         struct cmd_vf_rate_limit_result *res = parsed_result;
9758         int ret = 0;
9759
9760         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9761                 && (strcmp(res->vf, "vf") == 0)
9762                 && (strcmp(res->rate, "rate") == 0)
9763                 && (strcmp(res->q_msk, "queue_mask") == 0))
9764                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9765                                         res->rate_num, res->q_msk_val);
9766         if (ret < 0)
9767                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9768                         strerror(-ret));
9769
9770 }
9771
9772 static cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9773         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9774                                 set, "set");
9775 static cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9776         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9777                                 port, "port");
9778 static cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9779         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9780                                 port_num, RTE_UINT16);
9781 static cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9782         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9783                                 vf, "vf");
9784 static cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9785         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9786                                 vf_num, RTE_UINT8);
9787 static cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9788         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9789                                 rate, "rate");
9790 static cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9791         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9792                                 rate_num, RTE_UINT16);
9793 static cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9794         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9795                                 q_msk, "queue_mask");
9796 static cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9797         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9798                                 q_msk_val, RTE_UINT64);
9799
9800 static cmdline_parse_inst_t cmd_vf_rate_limit = {
9801         .f = cmd_vf_rate_limit_parsed,
9802         .data = (void *)0,
9803         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9804                 "queue_mask <queue_mask_value>: "
9805                 "Set rate limit for queues of VF on port_id",
9806         .tokens = {
9807                 (void *)&cmd_vf_rate_limit_set,
9808                 (void *)&cmd_vf_rate_limit_port,
9809                 (void *)&cmd_vf_rate_limit_portnum,
9810                 (void *)&cmd_vf_rate_limit_vf,
9811                 (void *)&cmd_vf_rate_limit_vfnum,
9812                 (void *)&cmd_vf_rate_limit_rate,
9813                 (void *)&cmd_vf_rate_limit_ratenum,
9814                 (void *)&cmd_vf_rate_limit_q_msk,
9815                 (void *)&cmd_vf_rate_limit_q_msk_val,
9816                 NULL,
9817         },
9818 };
9819
9820 /* *** CONFIGURE TUNNEL UDP PORT *** */
9821 struct cmd_tunnel_udp_config {
9822         cmdline_fixed_string_t rx_vxlan_port;
9823         cmdline_fixed_string_t what;
9824         uint16_t udp_port;
9825         portid_t port_id;
9826 };
9827
9828 static void
9829 cmd_tunnel_udp_config_parsed(void *parsed_result,
9830                           __rte_unused struct cmdline *cl,
9831                           __rte_unused void *data)
9832 {
9833         struct cmd_tunnel_udp_config *res = parsed_result;
9834         struct rte_eth_udp_tunnel tunnel_udp;
9835         int ret;
9836
9837         tunnel_udp.udp_port = res->udp_port;
9838         tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9839
9840         if (!strcmp(res->what, "add"))
9841                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9842                                                       &tunnel_udp);
9843         else
9844                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9845                                                          &tunnel_udp);
9846
9847         if (ret < 0)
9848                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9849                         strerror(-ret));
9850 }
9851
9852 static cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9853         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9854                                 rx_vxlan_port, "rx_vxlan_port");
9855 static cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9856         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9857                                 what, "add#rm");
9858 static cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9859         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9860                                 udp_port, RTE_UINT16);
9861 static cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9862         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9863                                 port_id, RTE_UINT16);
9864
9865 static cmdline_parse_inst_t cmd_tunnel_udp_config = {
9866         .f = cmd_tunnel_udp_config_parsed,
9867         .data = (void *)0,
9868         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9869                 "Add/Remove a tunneling UDP port filter",
9870         .tokens = {
9871                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9872                 (void *)&cmd_tunnel_udp_config_what,
9873                 (void *)&cmd_tunnel_udp_config_udp_port,
9874                 (void *)&cmd_tunnel_udp_config_port_id,
9875                 NULL,
9876         },
9877 };
9878
9879 struct cmd_config_tunnel_udp_port {
9880         cmdline_fixed_string_t port;
9881         cmdline_fixed_string_t config;
9882         portid_t port_id;
9883         cmdline_fixed_string_t udp_tunnel_port;
9884         cmdline_fixed_string_t action;
9885         cmdline_fixed_string_t tunnel_type;
9886         uint16_t udp_port;
9887 };
9888
9889 static void
9890 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9891                                __rte_unused struct cmdline *cl,
9892                                __rte_unused void *data)
9893 {
9894         struct cmd_config_tunnel_udp_port *res = parsed_result;
9895         struct rte_eth_udp_tunnel tunnel_udp;
9896         int ret = 0;
9897
9898         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9899                 return;
9900
9901         tunnel_udp.udp_port = res->udp_port;
9902
9903         if (!strcmp(res->tunnel_type, "vxlan")) {
9904                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9905         } else if (!strcmp(res->tunnel_type, "geneve")) {
9906                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9907         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9908                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9909         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9910                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9911         } else {
9912                 fprintf(stderr, "Invalid tunnel type\n");
9913                 return;
9914         }
9915
9916         if (!strcmp(res->action, "add"))
9917                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9918                                                       &tunnel_udp);
9919         else
9920                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9921                                                          &tunnel_udp);
9922
9923         if (ret < 0)
9924                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9925                         strerror(-ret));
9926 }
9927
9928 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9929         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9930                                  "port");
9931 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9932         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9933                                  "config");
9934 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9935         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9936                               RTE_UINT16);
9937 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9938         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9939                                  udp_tunnel_port,
9940                                  "udp_tunnel_port");
9941 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9942         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9943                                  "add#rm");
9944 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9945         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9946                                  "vxlan#geneve#vxlan-gpe#ecpri");
9947 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9948         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9949                               RTE_UINT16);
9950
9951 static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9952         .f = cmd_cfg_tunnel_udp_port_parsed,
9953         .data = NULL,
9954         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9955                 "geneve|vxlan-gpe|ecpri <udp_port>",
9956         .tokens = {
9957                 (void *)&cmd_config_tunnel_udp_port_port,
9958                 (void *)&cmd_config_tunnel_udp_port_config,
9959                 (void *)&cmd_config_tunnel_udp_port_port_id,
9960                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9961                 (void *)&cmd_config_tunnel_udp_port_action,
9962                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9963                 (void *)&cmd_config_tunnel_udp_port_value,
9964                 NULL,
9965         },
9966 };
9967
9968 /* ******************************************************************************** */
9969
9970 struct cmd_dump_result {
9971         cmdline_fixed_string_t dump;
9972 };
9973
9974 static void
9975 dump_struct_sizes(void)
9976 {
9977 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9978         DUMP_SIZE(struct rte_mbuf);
9979         DUMP_SIZE(struct rte_mempool);
9980         DUMP_SIZE(struct rte_ring);
9981 #undef DUMP_SIZE
9982 }
9983
9984
9985 /* Dump the socket memory statistics on console */
9986 static void
9987 dump_socket_mem(FILE *f)
9988 {
9989         struct rte_malloc_socket_stats socket_stats;
9990         unsigned int i;
9991         size_t total = 0;
9992         size_t alloc = 0;
9993         size_t free = 0;
9994         unsigned int n_alloc = 0;
9995         unsigned int n_free = 0;
9996         static size_t last_allocs;
9997         static size_t last_total;
9998
9999
10000         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
10001                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
10002                     !socket_stats.heap_totalsz_bytes)
10003                         continue;
10004                 total += socket_stats.heap_totalsz_bytes;
10005                 alloc += socket_stats.heap_allocsz_bytes;
10006                 free += socket_stats.heap_freesz_bytes;
10007                 n_alloc += socket_stats.alloc_count;
10008                 n_free += socket_stats.free_count;
10009                 fprintf(f,
10010                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
10011                         i,
10012                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
10013                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
10014                         (double)socket_stats.heap_allocsz_bytes * 100 /
10015                         (double)socket_stats.heap_totalsz_bytes,
10016                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
10017                         socket_stats.alloc_count,
10018                         socket_stats.free_count);
10019         }
10020         fprintf(f,
10021                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
10022                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
10023                 total ? ((double)alloc * 100 / (double)total) : 0,
10024                 (double)free / (1024 * 1024),
10025                 n_alloc, n_free);
10026         if (last_allocs)
10027                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
10028                         ((double)total - (double)last_total) / (1024 * 1024),
10029                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
10030         last_allocs = alloc;
10031         last_total = total;
10032 }
10033
10034 static void cmd_dump_parsed(void *parsed_result,
10035                             __rte_unused struct cmdline *cl,
10036                             __rte_unused void *data)
10037 {
10038         struct cmd_dump_result *res = parsed_result;
10039
10040         if (!strcmp(res->dump, "dump_physmem"))
10041                 rte_dump_physmem_layout(stdout);
10042         else if (!strcmp(res->dump, "dump_socket_mem"))
10043                 dump_socket_mem(stdout);
10044         else if (!strcmp(res->dump, "dump_memzone"))
10045                 rte_memzone_dump(stdout);
10046         else if (!strcmp(res->dump, "dump_struct_sizes"))
10047                 dump_struct_sizes();
10048         else if (!strcmp(res->dump, "dump_ring"))
10049                 rte_ring_list_dump(stdout);
10050         else if (!strcmp(res->dump, "dump_mempool"))
10051                 rte_mempool_list_dump(stdout);
10052         else if (!strcmp(res->dump, "dump_devargs"))
10053                 rte_devargs_dump(stdout);
10054         else if (!strcmp(res->dump, "dump_log_types"))
10055                 rte_log_dump(stdout);
10056 }
10057
10058 static cmdline_parse_token_string_t cmd_dump_dump =
10059         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10060                 "dump_physmem#"
10061                 "dump_memzone#"
10062                 "dump_socket_mem#"
10063                 "dump_struct_sizes#"
10064                 "dump_ring#"
10065                 "dump_mempool#"
10066                 "dump_devargs#"
10067                 "dump_log_types");
10068
10069 static cmdline_parse_inst_t cmd_dump = {
10070         .f = cmd_dump_parsed,  /* function to call */
10071         .data = NULL,      /* 2nd arg of func */
10072         .help_str = "Dump status",
10073         .tokens = {        /* token list, NULL terminated */
10074                 (void *)&cmd_dump_dump,
10075                 NULL,
10076         },
10077 };
10078
10079 /* ******************************************************************************** */
10080
10081 struct cmd_dump_one_result {
10082         cmdline_fixed_string_t dump;
10083         cmdline_fixed_string_t name;
10084 };
10085
10086 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10087                                 __rte_unused void *data)
10088 {
10089         struct cmd_dump_one_result *res = parsed_result;
10090
10091         if (!strcmp(res->dump, "dump_ring")) {
10092                 struct rte_ring *r;
10093                 r = rte_ring_lookup(res->name);
10094                 if (r == NULL) {
10095                         cmdline_printf(cl, "Cannot find ring\n");
10096                         return;
10097                 }
10098                 rte_ring_dump(stdout, r);
10099         } else if (!strcmp(res->dump, "dump_mempool")) {
10100                 struct rte_mempool *mp;
10101                 mp = rte_mempool_lookup(res->name);
10102                 if (mp == NULL) {
10103                         cmdline_printf(cl, "Cannot find mempool\n");
10104                         return;
10105                 }
10106                 rte_mempool_dump(stdout, mp);
10107         }
10108 }
10109
10110 static cmdline_parse_token_string_t cmd_dump_one_dump =
10111         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10112                                  "dump_ring#dump_mempool");
10113
10114 static cmdline_parse_token_string_t cmd_dump_one_name =
10115         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10116
10117 static cmdline_parse_inst_t cmd_dump_one = {
10118         .f = cmd_dump_one_parsed,  /* function to call */
10119         .data = NULL,      /* 2nd arg of func */
10120         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10121         .tokens = {        /* token list, NULL terminated */
10122                 (void *)&cmd_dump_one_dump,
10123                 (void *)&cmd_dump_one_name,
10124                 NULL,
10125         },
10126 };
10127
10128 /* *** queue region set *** */
10129 struct cmd_queue_region_result {
10130         cmdline_fixed_string_t set;
10131         cmdline_fixed_string_t port;
10132         portid_t port_id;
10133         cmdline_fixed_string_t cmd;
10134         cmdline_fixed_string_t region;
10135         uint8_t  region_id;
10136         cmdline_fixed_string_t queue_start_index;
10137         uint8_t  queue_id;
10138         cmdline_fixed_string_t queue_num;
10139         uint8_t  queue_num_value;
10140 };
10141
10142 static void
10143 cmd_queue_region_parsed(void *parsed_result,
10144                         __rte_unused struct cmdline *cl,
10145                         __rte_unused void *data)
10146 {
10147         struct cmd_queue_region_result *res = parsed_result;
10148         int ret = -ENOTSUP;
10149 #ifdef RTE_NET_I40E
10150         struct rte_pmd_i40e_queue_region_conf region_conf;
10151         enum rte_pmd_i40e_queue_region_op op_type;
10152 #endif
10153
10154         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10155                 return;
10156
10157 #ifdef RTE_NET_I40E
10158         memset(&region_conf, 0, sizeof(region_conf));
10159         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10160         region_conf.region_id = res->region_id;
10161         region_conf.queue_num = res->queue_num_value;
10162         region_conf.queue_start_index = res->queue_id;
10163
10164         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10165                                 op_type, &region_conf);
10166 #endif
10167
10168         switch (ret) {
10169         case 0:
10170                 break;
10171         case -ENOTSUP:
10172                 fprintf(stderr, "function not implemented or supported\n");
10173                 break;
10174         default:
10175                 fprintf(stderr, "queue region config error: (%s)\n",
10176                         strerror(-ret));
10177         }
10178 }
10179
10180 static cmdline_parse_token_string_t cmd_queue_region_set =
10181 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10182                 set, "set");
10183 static cmdline_parse_token_string_t cmd_queue_region_port =
10184         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10185 static cmdline_parse_token_num_t cmd_queue_region_port_id =
10186         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10187                                 port_id, RTE_UINT16);
10188 static cmdline_parse_token_string_t cmd_queue_region_cmd =
10189         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10190                                  cmd, "queue-region");
10191 static cmdline_parse_token_string_t cmd_queue_region_id =
10192         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10193                                 region, "region_id");
10194 static cmdline_parse_token_num_t cmd_queue_region_index =
10195         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10196                                 region_id, RTE_UINT8);
10197 static cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10198         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10199                                 queue_start_index, "queue_start_index");
10200 static cmdline_parse_token_num_t cmd_queue_region_queue_id =
10201         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10202                                 queue_id, RTE_UINT8);
10203 static cmdline_parse_token_string_t cmd_queue_region_queue_num =
10204         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10205                                 queue_num, "queue_num");
10206 static cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10207         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10208                                 queue_num_value, RTE_UINT8);
10209
10210 static cmdline_parse_inst_t cmd_queue_region = {
10211         .f = cmd_queue_region_parsed,
10212         .data = NULL,
10213         .help_str = "set port <port_id> queue-region region_id <value> "
10214                 "queue_start_index <value> queue_num <value>: Set a queue region",
10215         .tokens = {
10216                 (void *)&cmd_queue_region_set,
10217                 (void *)&cmd_queue_region_port,
10218                 (void *)&cmd_queue_region_port_id,
10219                 (void *)&cmd_queue_region_cmd,
10220                 (void *)&cmd_queue_region_id,
10221                 (void *)&cmd_queue_region_index,
10222                 (void *)&cmd_queue_region_queue_start_index,
10223                 (void *)&cmd_queue_region_queue_id,
10224                 (void *)&cmd_queue_region_queue_num,
10225                 (void *)&cmd_queue_region_queue_num_value,
10226                 NULL,
10227         },
10228 };
10229
10230 /* *** queue region and flowtype set *** */
10231 struct cmd_region_flowtype_result {
10232         cmdline_fixed_string_t set;
10233         cmdline_fixed_string_t port;
10234         portid_t port_id;
10235         cmdline_fixed_string_t cmd;
10236         cmdline_fixed_string_t region;
10237         uint8_t  region_id;
10238         cmdline_fixed_string_t flowtype;
10239         uint8_t  flowtype_id;
10240 };
10241
10242 static void
10243 cmd_region_flowtype_parsed(void *parsed_result,
10244                         __rte_unused struct cmdline *cl,
10245                         __rte_unused void *data)
10246 {
10247         struct cmd_region_flowtype_result *res = parsed_result;
10248         int ret = -ENOTSUP;
10249 #ifdef RTE_NET_I40E
10250         struct rte_pmd_i40e_queue_region_conf region_conf;
10251         enum rte_pmd_i40e_queue_region_op op_type;
10252 #endif
10253
10254         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10255                 return;
10256
10257 #ifdef RTE_NET_I40E
10258         memset(&region_conf, 0, sizeof(region_conf));
10259
10260         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10261         region_conf.region_id = res->region_id;
10262         region_conf.hw_flowtype = res->flowtype_id;
10263
10264         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10265                         op_type, &region_conf);
10266 #endif
10267
10268         switch (ret) {
10269         case 0:
10270                 break;
10271         case -ENOTSUP:
10272                 fprintf(stderr, "function not implemented or supported\n");
10273                 break;
10274         default:
10275                 fprintf(stderr, "region flowtype config error: (%s)\n",
10276                         strerror(-ret));
10277         }
10278 }
10279
10280 static cmdline_parse_token_string_t cmd_region_flowtype_set =
10281 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10282                                 set, "set");
10283 static cmdline_parse_token_string_t cmd_region_flowtype_port =
10284         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10285                                 port, "port");
10286 static cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10287         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10288                                 port_id, RTE_UINT16);
10289 static cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10290         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10291                                 cmd, "queue-region");
10292 static cmdline_parse_token_string_t cmd_region_flowtype_index =
10293         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10294                                 region, "region_id");
10295 static cmdline_parse_token_num_t cmd_region_flowtype_id =
10296         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10297                                 region_id, RTE_UINT8);
10298 static cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10299         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10300                                 flowtype, "flowtype");
10301 static cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10302         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10303                                 flowtype_id, RTE_UINT8);
10304 static cmdline_parse_inst_t cmd_region_flowtype = {
10305         .f = cmd_region_flowtype_parsed,
10306         .data = NULL,
10307         .help_str = "set port <port_id> queue-region region_id <value> "
10308                 "flowtype <value>: Set a flowtype region index",
10309         .tokens = {
10310                 (void *)&cmd_region_flowtype_set,
10311                 (void *)&cmd_region_flowtype_port,
10312                 (void *)&cmd_region_flowtype_port_index,
10313                 (void *)&cmd_region_flowtype_cmd,
10314                 (void *)&cmd_region_flowtype_index,
10315                 (void *)&cmd_region_flowtype_id,
10316                 (void *)&cmd_region_flowtype_flow_index,
10317                 (void *)&cmd_region_flowtype_flow_id,
10318                 NULL,
10319         },
10320 };
10321
10322 /* *** User Priority (UP) to queue region (region_id) set *** */
10323 struct cmd_user_priority_region_result {
10324         cmdline_fixed_string_t set;
10325         cmdline_fixed_string_t port;
10326         portid_t port_id;
10327         cmdline_fixed_string_t cmd;
10328         cmdline_fixed_string_t user_priority;
10329         uint8_t  user_priority_id;
10330         cmdline_fixed_string_t region;
10331         uint8_t  region_id;
10332 };
10333
10334 static void
10335 cmd_user_priority_region_parsed(void *parsed_result,
10336                         __rte_unused struct cmdline *cl,
10337                         __rte_unused void *data)
10338 {
10339         struct cmd_user_priority_region_result *res = parsed_result;
10340         int ret = -ENOTSUP;
10341 #ifdef RTE_NET_I40E
10342         struct rte_pmd_i40e_queue_region_conf region_conf;
10343         enum rte_pmd_i40e_queue_region_op op_type;
10344 #endif
10345
10346         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10347                 return;
10348
10349 #ifdef RTE_NET_I40E
10350         memset(&region_conf, 0, sizeof(region_conf));
10351         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10352         region_conf.user_priority = res->user_priority_id;
10353         region_conf.region_id = res->region_id;
10354
10355         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10356                                 op_type, &region_conf);
10357 #endif
10358
10359         switch (ret) {
10360         case 0:
10361                 break;
10362         case -ENOTSUP:
10363                 fprintf(stderr, "function not implemented or supported\n");
10364                 break;
10365         default:
10366                 fprintf(stderr, "user_priority region config error: (%s)\n",
10367                         strerror(-ret));
10368         }
10369 }
10370
10371 static cmdline_parse_token_string_t cmd_user_priority_region_set =
10372         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10373                                 set, "set");
10374 static cmdline_parse_token_string_t cmd_user_priority_region_port =
10375         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10376                                 port, "port");
10377 static cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10378         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10379                                 port_id, RTE_UINT16);
10380 static cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10381         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10382                                 cmd, "queue-region");
10383 static cmdline_parse_token_string_t cmd_user_priority_region_UP =
10384         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10385                                 user_priority, "UP");
10386 static cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10387         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10388                                 user_priority_id, RTE_UINT8);
10389 static cmdline_parse_token_string_t cmd_user_priority_region_region =
10390         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10391                                 region, "region_id");
10392 static cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10393         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10394                                 region_id, RTE_UINT8);
10395
10396 static cmdline_parse_inst_t cmd_user_priority_region = {
10397         .f = cmd_user_priority_region_parsed,
10398         .data = NULL,
10399         .help_str = "set port <port_id> queue-region UP <value> "
10400                 "region_id <value>: Set the mapping of User Priority (UP) "
10401                 "to queue region (region_id) ",
10402         .tokens = {
10403                 (void *)&cmd_user_priority_region_set,
10404                 (void *)&cmd_user_priority_region_port,
10405                 (void *)&cmd_user_priority_region_port_index,
10406                 (void *)&cmd_user_priority_region_cmd,
10407                 (void *)&cmd_user_priority_region_UP,
10408                 (void *)&cmd_user_priority_region_UP_id,
10409                 (void *)&cmd_user_priority_region_region,
10410                 (void *)&cmd_user_priority_region_region_id,
10411                 NULL,
10412         },
10413 };
10414
10415 /* *** flush all queue region related configuration *** */
10416 struct cmd_flush_queue_region_result {
10417         cmdline_fixed_string_t set;
10418         cmdline_fixed_string_t port;
10419         portid_t port_id;
10420         cmdline_fixed_string_t cmd;
10421         cmdline_fixed_string_t flush;
10422         cmdline_fixed_string_t what;
10423 };
10424
10425 static void
10426 cmd_flush_queue_region_parsed(void *parsed_result,
10427                         __rte_unused struct cmdline *cl,
10428                         __rte_unused void *data)
10429 {
10430         struct cmd_flush_queue_region_result *res = parsed_result;
10431         int ret = -ENOTSUP;
10432 #ifdef RTE_NET_I40E
10433         struct rte_pmd_i40e_queue_region_conf region_conf;
10434         enum rte_pmd_i40e_queue_region_op op_type;
10435 #endif
10436
10437         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10438                 return;
10439
10440 #ifdef RTE_NET_I40E
10441         memset(&region_conf, 0, sizeof(region_conf));
10442
10443         if (strcmp(res->what, "on") == 0)
10444                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10445         else
10446                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10447
10448         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10449                                 op_type, &region_conf);
10450 #endif
10451
10452         switch (ret) {
10453         case 0:
10454                 break;
10455         case -ENOTSUP:
10456                 fprintf(stderr, "function not implemented or supported\n");
10457                 break;
10458         default:
10459                 fprintf(stderr, "queue region config flush error: (%s)\n",
10460                         strerror(-ret));
10461         }
10462 }
10463
10464 static cmdline_parse_token_string_t cmd_flush_queue_region_set =
10465         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10466                                 set, "set");
10467 static cmdline_parse_token_string_t cmd_flush_queue_region_port =
10468         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10469                                 port, "port");
10470 static cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10471         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10472                                 port_id, RTE_UINT16);
10473 static cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10474         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10475                                 cmd, "queue-region");
10476 static cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10477         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10478                                 flush, "flush");
10479 static cmdline_parse_token_string_t cmd_flush_queue_region_what =
10480         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10481                                 what, "on#off");
10482
10483 static cmdline_parse_inst_t cmd_flush_queue_region = {
10484         .f = cmd_flush_queue_region_parsed,
10485         .data = NULL,
10486         .help_str = "set port <port_id> queue-region flush on|off"
10487                 ": flush all queue region related configuration",
10488         .tokens = {
10489                 (void *)&cmd_flush_queue_region_set,
10490                 (void *)&cmd_flush_queue_region_port,
10491                 (void *)&cmd_flush_queue_region_port_index,
10492                 (void *)&cmd_flush_queue_region_cmd,
10493                 (void *)&cmd_flush_queue_region_flush,
10494                 (void *)&cmd_flush_queue_region_what,
10495                 NULL,
10496         },
10497 };
10498
10499 /* *** get all queue region related configuration info *** */
10500 struct cmd_show_queue_region_info {
10501         cmdline_fixed_string_t show;
10502         cmdline_fixed_string_t port;
10503         portid_t port_id;
10504         cmdline_fixed_string_t cmd;
10505 };
10506
10507 static void
10508 cmd_show_queue_region_info_parsed(void *parsed_result,
10509                         __rte_unused struct cmdline *cl,
10510                         __rte_unused void *data)
10511 {
10512         struct cmd_show_queue_region_info *res = parsed_result;
10513         int ret = -ENOTSUP;
10514 #ifdef RTE_NET_I40E
10515         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10516         enum rte_pmd_i40e_queue_region_op op_type;
10517 #endif
10518
10519         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10520                 return;
10521
10522 #ifdef RTE_NET_I40E
10523         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10524
10525         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10526
10527         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10528                                         op_type, &rte_pmd_regions);
10529
10530         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10531 #endif
10532
10533         switch (ret) {
10534         case 0:
10535                 break;
10536         case -ENOTSUP:
10537                 fprintf(stderr, "function not implemented or supported\n");
10538                 break;
10539         default:
10540                 fprintf(stderr, "queue region config info show error: (%s)\n",
10541                         strerror(-ret));
10542         }
10543 }
10544
10545 static cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10546 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10547                                 show, "show");
10548 static cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10549         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10550                                 port, "port");
10551 static cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10552         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10553                                 port_id, RTE_UINT16);
10554 static cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10555         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10556                                 cmd, "queue-region");
10557
10558 static cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10559         .f = cmd_show_queue_region_info_parsed,
10560         .data = NULL,
10561         .help_str = "show port <port_id> queue-region"
10562                 ": show all queue region related configuration info",
10563         .tokens = {
10564                 (void *)&cmd_show_queue_region_info_get,
10565                 (void *)&cmd_show_queue_region_info_port,
10566                 (void *)&cmd_show_queue_region_info_port_index,
10567                 (void *)&cmd_show_queue_region_info_cmd,
10568                 NULL,
10569         },
10570 };
10571
10572 /* *** Filters Control *** */
10573
10574 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10575 do { \
10576         if ((ip_addr).family == AF_INET) \
10577                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10578         else { \
10579                 fprintf(stderr, "invalid parameter.\n"); \
10580                 return; \
10581         } \
10582 } while (0)
10583
10584 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10585 do { \
10586         if ((ip_addr).family == AF_INET6) \
10587                 rte_memcpy(&(ip), \
10588                                  &((ip_addr).addr.ipv6), \
10589                                  sizeof(struct in6_addr)); \
10590         else { \
10591                 fprintf(stderr, "invalid parameter.\n"); \
10592                 return; \
10593         } \
10594 } while (0)
10595
10596 #ifdef RTE_NET_I40E
10597
10598 static uint16_t
10599 str2flowtype(char *string)
10600 {
10601         uint8_t i = 0;
10602         static const struct {
10603                 char str[32];
10604                 uint16_t type;
10605         } flowtype_str[] = {
10606                 {"raw", RTE_ETH_FLOW_RAW},
10607                 {"ipv4", RTE_ETH_FLOW_IPV4},
10608                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10609                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10610                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10611                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10612                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10613                 {"ipv6", RTE_ETH_FLOW_IPV6},
10614                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10615                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10616                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10617                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10618                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10619                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10620                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10621                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10622                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10623                 {"gtpu", RTE_ETH_FLOW_GTPU},
10624         };
10625
10626         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10627                 if (!strcmp(flowtype_str[i].str, string))
10628                         return flowtype_str[i].type;
10629         }
10630
10631         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10632                 return (uint16_t)atoi(string);
10633
10634         return RTE_ETH_FLOW_UNKNOWN;
10635 }
10636
10637 /* *** deal with flow director filter *** */
10638 struct cmd_flow_director_result {
10639         cmdline_fixed_string_t flow_director_filter;
10640         portid_t port_id;
10641         cmdline_fixed_string_t mode;
10642         cmdline_fixed_string_t mode_value;
10643         cmdline_fixed_string_t ops;
10644         cmdline_fixed_string_t flow;
10645         cmdline_fixed_string_t flow_type;
10646         cmdline_fixed_string_t drop;
10647         cmdline_fixed_string_t queue;
10648         uint16_t  queue_id;
10649         cmdline_fixed_string_t fd_id;
10650         uint32_t  fd_id_value;
10651         cmdline_fixed_string_t packet;
10652         char filepath[];
10653 };
10654
10655 static void
10656 cmd_flow_director_filter_parsed(void *parsed_result,
10657                           __rte_unused struct cmdline *cl,
10658                           __rte_unused void *data)
10659 {
10660         struct cmd_flow_director_result *res = parsed_result;
10661         int ret = 0;
10662         struct rte_pmd_i40e_flow_type_mapping
10663                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10664         struct rte_pmd_i40e_pkt_template_conf conf;
10665         uint16_t flow_type = str2flowtype(res->flow_type);
10666         uint16_t i, port = res->port_id;
10667         uint8_t add;
10668
10669         memset(&conf, 0, sizeof(conf));
10670
10671         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10672                 fprintf(stderr, "Invalid flow type specified.\n");
10673                 return;
10674         }
10675         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10676                                                  mapping);
10677         if (ret)
10678                 return;
10679         if (mapping[flow_type].pctype == 0ULL) {
10680                 fprintf(stderr, "Invalid flow type specified.\n");
10681                 return;
10682         }
10683         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10684                 if (mapping[flow_type].pctype & (1ULL << i)) {
10685                         conf.input.pctype = i;
10686                         break;
10687                 }
10688         }
10689
10690         conf.input.packet = open_file(res->filepath,
10691                                 &conf.input.length);
10692         if (!conf.input.packet)
10693                 return;
10694         if (!strcmp(res->drop, "drop"))
10695                 conf.action.behavior =
10696                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10697         else
10698                 conf.action.behavior =
10699                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10700         conf.action.report_status =
10701                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10702         conf.action.rx_queue = res->queue_id;
10703         conf.soft_id = res->fd_id_value;
10704         add  = strcmp(res->ops, "del") ? 1 : 0;
10705         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10706                                                         &conf,
10707                                                         add);
10708         if (ret < 0)
10709                 fprintf(stderr, "flow director config error: (%s)\n",
10710                         strerror(-ret));
10711         close_file(conf.input.packet);
10712 }
10713
10714 static cmdline_parse_token_string_t cmd_flow_director_filter =
10715         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10716                                  flow_director_filter, "flow_director_filter");
10717 static cmdline_parse_token_num_t cmd_flow_director_port_id =
10718         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10719                               port_id, RTE_UINT16);
10720 static cmdline_parse_token_string_t cmd_flow_director_ops =
10721         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10722                                  ops, "add#del#update");
10723 static cmdline_parse_token_string_t cmd_flow_director_flow =
10724         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10725                                  flow, "flow");
10726 static cmdline_parse_token_string_t cmd_flow_director_flow_type =
10727         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10728                 flow_type, NULL);
10729 static cmdline_parse_token_string_t cmd_flow_director_drop =
10730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10731                                  drop, "drop#fwd");
10732 static cmdline_parse_token_string_t cmd_flow_director_queue =
10733         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10734                                  queue, "queue");
10735 static cmdline_parse_token_num_t cmd_flow_director_queue_id =
10736         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10737                               queue_id, RTE_UINT16);
10738 static cmdline_parse_token_string_t cmd_flow_director_fd_id =
10739         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10740                                  fd_id, "fd_id");
10741 static cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10742         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10743                               fd_id_value, RTE_UINT32);
10744
10745 static cmdline_parse_token_string_t cmd_flow_director_mode =
10746         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10747                                  mode, "mode");
10748 static cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10749         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10750                                  mode_value, "raw");
10751 static cmdline_parse_token_string_t cmd_flow_director_packet =
10752         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10753                                  packet, "packet");
10754 static cmdline_parse_token_string_t cmd_flow_director_filepath =
10755         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10756                                  filepath, NULL);
10757
10758 static cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10759         .f = cmd_flow_director_filter_parsed,
10760         .data = NULL,
10761         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10762                 "director entry on NIC",
10763         .tokens = {
10764                 (void *)&cmd_flow_director_filter,
10765                 (void *)&cmd_flow_director_port_id,
10766                 (void *)&cmd_flow_director_mode,
10767                 (void *)&cmd_flow_director_mode_raw,
10768                 (void *)&cmd_flow_director_ops,
10769                 (void *)&cmd_flow_director_flow,
10770                 (void *)&cmd_flow_director_flow_type,
10771                 (void *)&cmd_flow_director_drop,
10772                 (void *)&cmd_flow_director_queue,
10773                 (void *)&cmd_flow_director_queue_id,
10774                 (void *)&cmd_flow_director_fd_id,
10775                 (void *)&cmd_flow_director_fd_id_value,
10776                 (void *)&cmd_flow_director_packet,
10777                 (void *)&cmd_flow_director_filepath,
10778                 NULL,
10779         },
10780 };
10781
10782 #endif /* RTE_NET_I40E */
10783
10784 /* *** deal with flow director mask *** */
10785 struct cmd_flow_director_mask_result {
10786         cmdline_fixed_string_t flow_director_mask;
10787         portid_t port_id;
10788         cmdline_fixed_string_t mode;
10789         cmdline_fixed_string_t mode_value;
10790         cmdline_fixed_string_t vlan;
10791         uint16_t vlan_mask;
10792         cmdline_fixed_string_t src_mask;
10793         cmdline_ipaddr_t ipv4_src;
10794         cmdline_ipaddr_t ipv6_src;
10795         uint16_t port_src;
10796         cmdline_fixed_string_t dst_mask;
10797         cmdline_ipaddr_t ipv4_dst;
10798         cmdline_ipaddr_t ipv6_dst;
10799         uint16_t port_dst;
10800         cmdline_fixed_string_t mac;
10801         uint8_t mac_addr_byte_mask;
10802         cmdline_fixed_string_t tunnel_id;
10803         uint32_t tunnel_id_mask;
10804         cmdline_fixed_string_t tunnel_type;
10805         uint8_t tunnel_type_mask;
10806 };
10807
10808 static void
10809 cmd_flow_director_mask_parsed(void *parsed_result,
10810                           __rte_unused struct cmdline *cl,
10811                           __rte_unused void *data)
10812 {
10813         struct cmd_flow_director_mask_result *res = parsed_result;
10814         struct rte_eth_fdir_masks *mask;
10815         struct rte_port *port;
10816
10817         port = &ports[res->port_id];
10818         /** Check if the port is not started **/
10819         if (port->port_status != RTE_PORT_STOPPED) {
10820                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10821                 return;
10822         }
10823
10824         mask = &port->dev_conf.fdir_conf.mask;
10825
10826         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10827                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10828                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10829                         return;
10830                 }
10831
10832                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10833         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10834                 if (strcmp(res->mode_value, "Tunnel")) {
10835                         fprintf(stderr, "Please set mode to Tunnel.\n");
10836                         return;
10837                 }
10838
10839                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10840                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10841                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10842                 mask->tunnel_type_mask = res->tunnel_type_mask;
10843         } else {
10844                 if (strcmp(res->mode_value, "IP")) {
10845                         fprintf(stderr, "Please set mode to IP.\n");
10846                         return;
10847                 }
10848
10849                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10850                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10851                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10852                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10853                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10854                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10855                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10856         }
10857
10858         cmd_reconfig_device_queue(res->port_id, 1, 1);
10859 }
10860
10861 static cmdline_parse_token_string_t cmd_flow_director_mask =
10862         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10863                                  flow_director_mask, "flow_director_mask");
10864 static cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10865         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10866                               port_id, RTE_UINT16);
10867 static cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10869                                  vlan, "vlan");
10870 static cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10871         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10872                               vlan_mask, RTE_UINT16);
10873 static cmdline_parse_token_string_t cmd_flow_director_mask_src =
10874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10875                                  src_mask, "src_mask");
10876 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10877         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10878                                  ipv4_src);
10879 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10880         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10881                                  ipv6_src);
10882 static cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10883         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10884                               port_src, RTE_UINT16);
10885 static cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10886         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10887                                  dst_mask, "dst_mask");
10888 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10889         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10890                                  ipv4_dst);
10891 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10892         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10893                                  ipv6_dst);
10894 static cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10895         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10896                               port_dst, RTE_UINT16);
10897
10898 static cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10899         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10900                                  mode, "mode");
10901 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10902         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10903                                  mode_value, "IP");
10904 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10905         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10906                                  mode_value, "MAC-VLAN");
10907 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10909                                  mode_value, "Tunnel");
10910 static cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10911         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10912                                  mac, "mac");
10913 static cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10914         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10915                               mac_addr_byte_mask, RTE_UINT8);
10916 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10917         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10918                                  tunnel_type, "tunnel-type");
10919 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10920         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10921                               tunnel_type_mask, RTE_UINT8);
10922 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10923         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10924                                  tunnel_id, "tunnel-id");
10925 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10926         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10927                               tunnel_id_mask, RTE_UINT32);
10928
10929 static cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10930         .f = cmd_flow_director_mask_parsed,
10931         .data = NULL,
10932         .help_str = "flow_director_mask ... : "
10933                 "Set IP mode flow director's mask on NIC",
10934         .tokens = {
10935                 (void *)&cmd_flow_director_mask,
10936                 (void *)&cmd_flow_director_mask_port_id,
10937                 (void *)&cmd_flow_director_mask_mode,
10938                 (void *)&cmd_flow_director_mask_mode_ip,
10939                 (void *)&cmd_flow_director_mask_vlan,
10940                 (void *)&cmd_flow_director_mask_vlan_value,
10941                 (void *)&cmd_flow_director_mask_src,
10942                 (void *)&cmd_flow_director_mask_ipv4_src,
10943                 (void *)&cmd_flow_director_mask_ipv6_src,
10944                 (void *)&cmd_flow_director_mask_port_src,
10945                 (void *)&cmd_flow_director_mask_dst,
10946                 (void *)&cmd_flow_director_mask_ipv4_dst,
10947                 (void *)&cmd_flow_director_mask_ipv6_dst,
10948                 (void *)&cmd_flow_director_mask_port_dst,
10949                 NULL,
10950         },
10951 };
10952
10953 static cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10954         .f = cmd_flow_director_mask_parsed,
10955         .data = NULL,
10956         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10957                 "flow director's mask on NIC",
10958         .tokens = {
10959                 (void *)&cmd_flow_director_mask,
10960                 (void *)&cmd_flow_director_mask_port_id,
10961                 (void *)&cmd_flow_director_mask_mode,
10962                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10963                 (void *)&cmd_flow_director_mask_vlan,
10964                 (void *)&cmd_flow_director_mask_vlan_value,
10965                 NULL,
10966         },
10967 };
10968
10969 static cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10970         .f = cmd_flow_director_mask_parsed,
10971         .data = NULL,
10972         .help_str = "flow_director_mask ... : Set tunnel mode "
10973                 "flow director's mask on NIC",
10974         .tokens = {
10975                 (void *)&cmd_flow_director_mask,
10976                 (void *)&cmd_flow_director_mask_port_id,
10977                 (void *)&cmd_flow_director_mask_mode,
10978                 (void *)&cmd_flow_director_mask_mode_tunnel,
10979                 (void *)&cmd_flow_director_mask_vlan,
10980                 (void *)&cmd_flow_director_mask_vlan_value,
10981                 (void *)&cmd_flow_director_mask_mac,
10982                 (void *)&cmd_flow_director_mask_mac_value,
10983                 (void *)&cmd_flow_director_mask_tunnel_type,
10984                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10985                 (void *)&cmd_flow_director_mask_tunnel_id,
10986                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10987                 NULL,
10988         },
10989 };
10990
10991 /* *** deal with flow director flexible payload configuration *** */
10992 struct cmd_flow_director_flexpayload_result {
10993         cmdline_fixed_string_t flow_director_flexpayload;
10994         portid_t port_id;
10995         cmdline_fixed_string_t payload_layer;
10996         cmdline_fixed_string_t payload_cfg;
10997 };
10998
10999 static inline int
11000 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11001 {
11002         char s[256];
11003         const char *p, *p0 = q_arg;
11004         char *end;
11005         unsigned long int_fld;
11006         char *str_fld[max_num];
11007         int i;
11008         unsigned size;
11009         int ret = -1;
11010
11011         p = strchr(p0, '(');
11012         if (p == NULL)
11013                 return -1;
11014         ++p;
11015         p0 = strchr(p, ')');
11016         if (p0 == NULL)
11017                 return -1;
11018
11019         size = p0 - p;
11020         if (size >= sizeof(s))
11021                 return -1;
11022
11023         snprintf(s, sizeof(s), "%.*s", size, p);
11024         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11025         if (ret < 0 || ret > max_num)
11026                 return -1;
11027         for (i = 0; i < ret; i++) {
11028                 errno = 0;
11029                 int_fld = strtoul(str_fld[i], &end, 0);
11030                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11031                         return -1;
11032                 offsets[i] = (uint16_t)int_fld;
11033         }
11034         return ret;
11035 }
11036
11037 static void
11038 cmd_flow_director_flxpld_parsed(void *parsed_result,
11039                           __rte_unused struct cmdline *cl,
11040                           __rte_unused void *data)
11041 {
11042         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11043         struct rte_eth_flex_payload_cfg flex_cfg;
11044         struct rte_port *port;
11045         int ret = 0;
11046
11047         port = &ports[res->port_id];
11048         /** Check if the port is not started **/
11049         if (port->port_status != RTE_PORT_STOPPED) {
11050                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
11051                 return;
11052         }
11053
11054         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11055
11056         if (!strcmp(res->payload_layer, "raw"))
11057                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11058         else if (!strcmp(res->payload_layer, "l2"))
11059                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11060         else if (!strcmp(res->payload_layer, "l3"))
11061                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11062         else if (!strcmp(res->payload_layer, "l4"))
11063                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11064
11065         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11066                             RTE_ETH_FDIR_MAX_FLEXLEN);
11067         if (ret < 0) {
11068                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
11069                 return;
11070         }
11071
11072         fdir_set_flex_payload(res->port_id, &flex_cfg);
11073         cmd_reconfig_device_queue(res->port_id, 1, 1);
11074 }
11075
11076 static cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11077         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11078                                  flow_director_flexpayload,
11079                                  "flow_director_flex_payload");
11080 static cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11081         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11082                               port_id, RTE_UINT16);
11083 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11084         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11085                                  payload_layer, "raw#l2#l3#l4");
11086 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11087         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11088                                  payload_cfg, NULL);
11089
11090 static cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11091         .f = cmd_flow_director_flxpld_parsed,
11092         .data = NULL,
11093         .help_str = "flow_director_flexpayload ... : "
11094                 "Set flow director's flex payload on NIC",
11095         .tokens = {
11096                 (void *)&cmd_flow_director_flexpayload,
11097                 (void *)&cmd_flow_director_flexpayload_port_id,
11098                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11099                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11100                 NULL,
11101         },
11102 };
11103
11104 /* Generic flow interface command. */
11105 extern cmdline_parse_inst_t cmd_flow;
11106
11107 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11108 struct cmd_mcast_addr_result {
11109         cmdline_fixed_string_t mcast_addr_cmd;
11110         cmdline_fixed_string_t what;
11111         uint16_t port_num;
11112         struct rte_ether_addr mc_addr;
11113 };
11114
11115 static void cmd_mcast_addr_parsed(void *parsed_result,
11116                 __rte_unused struct cmdline *cl,
11117                 __rte_unused void *data)
11118 {
11119         struct cmd_mcast_addr_result *res = parsed_result;
11120
11121         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11122                 fprintf(stderr,
11123                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11124                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11125                 return;
11126         }
11127         if (strcmp(res->what, "add") == 0)
11128                 mcast_addr_add(res->port_num, &res->mc_addr);
11129         else
11130                 mcast_addr_remove(res->port_num, &res->mc_addr);
11131 }
11132
11133 static cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11134         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11135                                  mcast_addr_cmd, "mcast_addr");
11136 static cmdline_parse_token_string_t cmd_mcast_addr_what =
11137         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11138                                  "add#remove");
11139 static cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11140         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11141                                  RTE_UINT16);
11142 static cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11143         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11144
11145 static cmdline_parse_inst_t cmd_mcast_addr = {
11146         .f = cmd_mcast_addr_parsed,
11147         .data = (void *)0,
11148         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11149                 "Add/Remove multicast MAC address on port_id",
11150         .tokens = {
11151                 (void *)&cmd_mcast_addr_cmd,
11152                 (void *)&cmd_mcast_addr_what,
11153                 (void *)&cmd_mcast_addr_portnum,
11154                 (void *)&cmd_mcast_addr_addr,
11155                 NULL,
11156         },
11157 };
11158
11159 /* vf vlan anti spoof configuration */
11160
11161 /* Common result structure for vf vlan anti spoof */
11162 struct cmd_vf_vlan_anti_spoof_result {
11163         cmdline_fixed_string_t set;
11164         cmdline_fixed_string_t vf;
11165         cmdline_fixed_string_t vlan;
11166         cmdline_fixed_string_t antispoof;
11167         portid_t port_id;
11168         uint32_t vf_id;
11169         cmdline_fixed_string_t on_off;
11170 };
11171
11172 /* Common CLI fields for vf vlan anti spoof enable disable */
11173 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11174         TOKEN_STRING_INITIALIZER
11175                 (struct cmd_vf_vlan_anti_spoof_result,
11176                  set, "set");
11177 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11178         TOKEN_STRING_INITIALIZER
11179                 (struct cmd_vf_vlan_anti_spoof_result,
11180                  vf, "vf");
11181 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11182         TOKEN_STRING_INITIALIZER
11183                 (struct cmd_vf_vlan_anti_spoof_result,
11184                  vlan, "vlan");
11185 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11186         TOKEN_STRING_INITIALIZER
11187                 (struct cmd_vf_vlan_anti_spoof_result,
11188                  antispoof, "antispoof");
11189 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11190         TOKEN_NUM_INITIALIZER
11191                 (struct cmd_vf_vlan_anti_spoof_result,
11192                  port_id, RTE_UINT16);
11193 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11194         TOKEN_NUM_INITIALIZER
11195                 (struct cmd_vf_vlan_anti_spoof_result,
11196                  vf_id, RTE_UINT32);
11197 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11198         TOKEN_STRING_INITIALIZER
11199                 (struct cmd_vf_vlan_anti_spoof_result,
11200                  on_off, "on#off");
11201
11202 static void
11203 cmd_set_vf_vlan_anti_spoof_parsed(
11204         void *parsed_result,
11205         __rte_unused struct cmdline *cl,
11206         __rte_unused void *data)
11207 {
11208         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11209         int ret = -ENOTSUP;
11210
11211         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11212
11213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11214                 return;
11215
11216 #ifdef RTE_NET_IXGBE
11217         if (ret == -ENOTSUP)
11218                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11219                                 res->vf_id, is_on);
11220 #endif
11221 #ifdef RTE_NET_I40E
11222         if (ret == -ENOTSUP)
11223                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11224                                 res->vf_id, is_on);
11225 #endif
11226 #ifdef RTE_NET_BNXT
11227         if (ret == -ENOTSUP)
11228                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11229                                 res->vf_id, is_on);
11230 #endif
11231
11232         switch (ret) {
11233         case 0:
11234                 break;
11235         case -EINVAL:
11236                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11237                 break;
11238         case -ENODEV:
11239                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11240                 break;
11241         case -ENOTSUP:
11242                 fprintf(stderr, "function not implemented\n");
11243                 break;
11244         default:
11245                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11246         }
11247 }
11248
11249 static cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11250         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11251         .data = NULL,
11252         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11253         .tokens = {
11254                 (void *)&cmd_vf_vlan_anti_spoof_set,
11255                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11256                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11257                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11258                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11259                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11260                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11261                 NULL,
11262         },
11263 };
11264
11265 /* vf mac anti spoof configuration */
11266
11267 /* Common result structure for vf mac anti spoof */
11268 struct cmd_vf_mac_anti_spoof_result {
11269         cmdline_fixed_string_t set;
11270         cmdline_fixed_string_t vf;
11271         cmdline_fixed_string_t mac;
11272         cmdline_fixed_string_t antispoof;
11273         portid_t port_id;
11274         uint32_t vf_id;
11275         cmdline_fixed_string_t on_off;
11276 };
11277
11278 /* Common CLI fields for vf mac anti spoof enable disable */
11279 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11280         TOKEN_STRING_INITIALIZER
11281                 (struct cmd_vf_mac_anti_spoof_result,
11282                  set, "set");
11283 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11284         TOKEN_STRING_INITIALIZER
11285                 (struct cmd_vf_mac_anti_spoof_result,
11286                  vf, "vf");
11287 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11288         TOKEN_STRING_INITIALIZER
11289                 (struct cmd_vf_mac_anti_spoof_result,
11290                  mac, "mac");
11291 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11292         TOKEN_STRING_INITIALIZER
11293                 (struct cmd_vf_mac_anti_spoof_result,
11294                  antispoof, "antispoof");
11295 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11296         TOKEN_NUM_INITIALIZER
11297                 (struct cmd_vf_mac_anti_spoof_result,
11298                  port_id, RTE_UINT16);
11299 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11300         TOKEN_NUM_INITIALIZER
11301                 (struct cmd_vf_mac_anti_spoof_result,
11302                  vf_id, RTE_UINT32);
11303 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11304         TOKEN_STRING_INITIALIZER
11305                 (struct cmd_vf_mac_anti_spoof_result,
11306                  on_off, "on#off");
11307
11308 static void
11309 cmd_set_vf_mac_anti_spoof_parsed(
11310         void *parsed_result,
11311         __rte_unused struct cmdline *cl,
11312         __rte_unused void *data)
11313 {
11314         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11315         int ret = -ENOTSUP;
11316
11317         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11318
11319         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11320                 return;
11321
11322 #ifdef RTE_NET_IXGBE
11323         if (ret == -ENOTSUP)
11324                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11325                         res->vf_id, is_on);
11326 #endif
11327 #ifdef RTE_NET_I40E
11328         if (ret == -ENOTSUP)
11329                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11330                         res->vf_id, is_on);
11331 #endif
11332 #ifdef RTE_NET_BNXT
11333         if (ret == -ENOTSUP)
11334                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11335                         res->vf_id, is_on);
11336 #endif
11337
11338         switch (ret) {
11339         case 0:
11340                 break;
11341         case -EINVAL:
11342                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11343                         res->vf_id, is_on);
11344                 break;
11345         case -ENODEV:
11346                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11347                 break;
11348         case -ENOTSUP:
11349                 fprintf(stderr, "function not implemented\n");
11350                 break;
11351         default:
11352                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11353         }
11354 }
11355
11356 static cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11357         .f = cmd_set_vf_mac_anti_spoof_parsed,
11358         .data = NULL,
11359         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11360         .tokens = {
11361                 (void *)&cmd_vf_mac_anti_spoof_set,
11362                 (void *)&cmd_vf_mac_anti_spoof_vf,
11363                 (void *)&cmd_vf_mac_anti_spoof_mac,
11364                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11365                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11366                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11367                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11368                 NULL,
11369         },
11370 };
11371
11372 /* vf vlan strip queue configuration */
11373
11374 /* Common result structure for vf mac anti spoof */
11375 struct cmd_vf_vlan_stripq_result {
11376         cmdline_fixed_string_t set;
11377         cmdline_fixed_string_t vf;
11378         cmdline_fixed_string_t vlan;
11379         cmdline_fixed_string_t stripq;
11380         portid_t port_id;
11381         uint16_t vf_id;
11382         cmdline_fixed_string_t on_off;
11383 };
11384
11385 /* Common CLI fields for vf vlan strip enable disable */
11386 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11387         TOKEN_STRING_INITIALIZER
11388                 (struct cmd_vf_vlan_stripq_result,
11389                  set, "set");
11390 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11391         TOKEN_STRING_INITIALIZER
11392                 (struct cmd_vf_vlan_stripq_result,
11393                  vf, "vf");
11394 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11395         TOKEN_STRING_INITIALIZER
11396                 (struct cmd_vf_vlan_stripq_result,
11397                  vlan, "vlan");
11398 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11399         TOKEN_STRING_INITIALIZER
11400                 (struct cmd_vf_vlan_stripq_result,
11401                  stripq, "stripq");
11402 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11403         TOKEN_NUM_INITIALIZER
11404                 (struct cmd_vf_vlan_stripq_result,
11405                  port_id, RTE_UINT16);
11406 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11407         TOKEN_NUM_INITIALIZER
11408                 (struct cmd_vf_vlan_stripq_result,
11409                  vf_id, RTE_UINT16);
11410 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11411         TOKEN_STRING_INITIALIZER
11412                 (struct cmd_vf_vlan_stripq_result,
11413                  on_off, "on#off");
11414
11415 static void
11416 cmd_set_vf_vlan_stripq_parsed(
11417         void *parsed_result,
11418         __rte_unused struct cmdline *cl,
11419         __rte_unused void *data)
11420 {
11421         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11422         int ret = -ENOTSUP;
11423
11424         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11425
11426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11427                 return;
11428
11429 #ifdef RTE_NET_IXGBE
11430         if (ret == -ENOTSUP)
11431                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11432                         res->vf_id, is_on);
11433 #endif
11434 #ifdef RTE_NET_I40E
11435         if (ret == -ENOTSUP)
11436                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11437                         res->vf_id, is_on);
11438 #endif
11439 #ifdef RTE_NET_BNXT
11440         if (ret == -ENOTSUP)
11441                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11442                         res->vf_id, is_on);
11443 #endif
11444
11445         switch (ret) {
11446         case 0:
11447                 break;
11448         case -EINVAL:
11449                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11450                         res->vf_id, is_on);
11451                 break;
11452         case -ENODEV:
11453                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11454                 break;
11455         case -ENOTSUP:
11456                 fprintf(stderr, "function not implemented\n");
11457                 break;
11458         default:
11459                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11460         }
11461 }
11462
11463 static cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11464         .f = cmd_set_vf_vlan_stripq_parsed,
11465         .data = NULL,
11466         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11467         .tokens = {
11468                 (void *)&cmd_vf_vlan_stripq_set,
11469                 (void *)&cmd_vf_vlan_stripq_vf,
11470                 (void *)&cmd_vf_vlan_stripq_vlan,
11471                 (void *)&cmd_vf_vlan_stripq_stripq,
11472                 (void *)&cmd_vf_vlan_stripq_port_id,
11473                 (void *)&cmd_vf_vlan_stripq_vf_id,
11474                 (void *)&cmd_vf_vlan_stripq_on_off,
11475                 NULL,
11476         },
11477 };
11478
11479 /* vf vlan insert configuration */
11480
11481 /* Common result structure for vf vlan insert */
11482 struct cmd_vf_vlan_insert_result {
11483         cmdline_fixed_string_t set;
11484         cmdline_fixed_string_t vf;
11485         cmdline_fixed_string_t vlan;
11486         cmdline_fixed_string_t insert;
11487         portid_t port_id;
11488         uint16_t vf_id;
11489         uint16_t vlan_id;
11490 };
11491
11492 /* Common CLI fields for vf vlan insert enable disable */
11493 static cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11494         TOKEN_STRING_INITIALIZER
11495                 (struct cmd_vf_vlan_insert_result,
11496                  set, "set");
11497 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11498         TOKEN_STRING_INITIALIZER
11499                 (struct cmd_vf_vlan_insert_result,
11500                  vf, "vf");
11501 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11502         TOKEN_STRING_INITIALIZER
11503                 (struct cmd_vf_vlan_insert_result,
11504                  vlan, "vlan");
11505 static cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11506         TOKEN_STRING_INITIALIZER
11507                 (struct cmd_vf_vlan_insert_result,
11508                  insert, "insert");
11509 static cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11510         TOKEN_NUM_INITIALIZER
11511                 (struct cmd_vf_vlan_insert_result,
11512                  port_id, RTE_UINT16);
11513 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11514         TOKEN_NUM_INITIALIZER
11515                 (struct cmd_vf_vlan_insert_result,
11516                  vf_id, RTE_UINT16);
11517 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11518         TOKEN_NUM_INITIALIZER
11519                 (struct cmd_vf_vlan_insert_result,
11520                  vlan_id, RTE_UINT16);
11521
11522 static void
11523 cmd_set_vf_vlan_insert_parsed(
11524         void *parsed_result,
11525         __rte_unused struct cmdline *cl,
11526         __rte_unused void *data)
11527 {
11528         struct cmd_vf_vlan_insert_result *res = parsed_result;
11529         int ret = -ENOTSUP;
11530
11531         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11532                 return;
11533
11534 #ifdef RTE_NET_IXGBE
11535         if (ret == -ENOTSUP)
11536                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11537                         res->vlan_id);
11538 #endif
11539 #ifdef RTE_NET_I40E
11540         if (ret == -ENOTSUP)
11541                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11542                         res->vlan_id);
11543 #endif
11544 #ifdef RTE_NET_BNXT
11545         if (ret == -ENOTSUP)
11546                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11547                         res->vlan_id);
11548 #endif
11549
11550         switch (ret) {
11551         case 0:
11552                 break;
11553         case -EINVAL:
11554                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11555                         res->vf_id, res->vlan_id);
11556                 break;
11557         case -ENODEV:
11558                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11559                 break;
11560         case -ENOTSUP:
11561                 fprintf(stderr, "function not implemented\n");
11562                 break;
11563         default:
11564                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11565         }
11566 }
11567
11568 static cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11569         .f = cmd_set_vf_vlan_insert_parsed,
11570         .data = NULL,
11571         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11572         .tokens = {
11573                 (void *)&cmd_vf_vlan_insert_set,
11574                 (void *)&cmd_vf_vlan_insert_vf,
11575                 (void *)&cmd_vf_vlan_insert_vlan,
11576                 (void *)&cmd_vf_vlan_insert_insert,
11577                 (void *)&cmd_vf_vlan_insert_port_id,
11578                 (void *)&cmd_vf_vlan_insert_vf_id,
11579                 (void *)&cmd_vf_vlan_insert_vlan_id,
11580                 NULL,
11581         },
11582 };
11583
11584 /* tx loopback configuration */
11585
11586 /* Common result structure for tx loopback */
11587 struct cmd_tx_loopback_result {
11588         cmdline_fixed_string_t set;
11589         cmdline_fixed_string_t tx;
11590         cmdline_fixed_string_t loopback;
11591         portid_t port_id;
11592         cmdline_fixed_string_t on_off;
11593 };
11594
11595 /* Common CLI fields for tx loopback enable disable */
11596 static cmdline_parse_token_string_t cmd_tx_loopback_set =
11597         TOKEN_STRING_INITIALIZER
11598                 (struct cmd_tx_loopback_result,
11599                  set, "set");
11600 static cmdline_parse_token_string_t cmd_tx_loopback_tx =
11601         TOKEN_STRING_INITIALIZER
11602                 (struct cmd_tx_loopback_result,
11603                  tx, "tx");
11604 static cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11605         TOKEN_STRING_INITIALIZER
11606                 (struct cmd_tx_loopback_result,
11607                  loopback, "loopback");
11608 static cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11609         TOKEN_NUM_INITIALIZER
11610                 (struct cmd_tx_loopback_result,
11611                  port_id, RTE_UINT16);
11612 static cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11613         TOKEN_STRING_INITIALIZER
11614                 (struct cmd_tx_loopback_result,
11615                  on_off, "on#off");
11616
11617 static void
11618 cmd_set_tx_loopback_parsed(
11619         void *parsed_result,
11620         __rte_unused struct cmdline *cl,
11621         __rte_unused void *data)
11622 {
11623         struct cmd_tx_loopback_result *res = parsed_result;
11624         int ret = -ENOTSUP;
11625
11626         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11627
11628         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11629                 return;
11630
11631 #ifdef RTE_NET_IXGBE
11632         if (ret == -ENOTSUP)
11633                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11634 #endif
11635 #ifdef RTE_NET_I40E
11636         if (ret == -ENOTSUP)
11637                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11638 #endif
11639 #ifdef RTE_NET_BNXT
11640         if (ret == -ENOTSUP)
11641                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11642 #endif
11643 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11644         if (ret == -ENOTSUP)
11645                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11646 #endif
11647
11648         switch (ret) {
11649         case 0:
11650                 break;
11651         case -EINVAL:
11652                 fprintf(stderr, "invalid is_on %d\n", is_on);
11653                 break;
11654         case -ENODEV:
11655                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11656                 break;
11657         case -ENOTSUP:
11658                 fprintf(stderr, "function not implemented\n");
11659                 break;
11660         default:
11661                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11662         }
11663 }
11664
11665 static cmdline_parse_inst_t cmd_set_tx_loopback = {
11666         .f = cmd_set_tx_loopback_parsed,
11667         .data = NULL,
11668         .help_str = "set tx loopback <port_id> on|off",
11669         .tokens = {
11670                 (void *)&cmd_tx_loopback_set,
11671                 (void *)&cmd_tx_loopback_tx,
11672                 (void *)&cmd_tx_loopback_loopback,
11673                 (void *)&cmd_tx_loopback_port_id,
11674                 (void *)&cmd_tx_loopback_on_off,
11675                 NULL,
11676         },
11677 };
11678
11679 /* all queues drop enable configuration */
11680
11681 /* Common result structure for all queues drop enable */
11682 struct cmd_all_queues_drop_en_result {
11683         cmdline_fixed_string_t set;
11684         cmdline_fixed_string_t all;
11685         cmdline_fixed_string_t queues;
11686         cmdline_fixed_string_t drop;
11687         portid_t port_id;
11688         cmdline_fixed_string_t on_off;
11689 };
11690
11691 /* Common CLI fields for tx loopback enable disable */
11692 static cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11693         TOKEN_STRING_INITIALIZER
11694                 (struct cmd_all_queues_drop_en_result,
11695                  set, "set");
11696 static cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11697         TOKEN_STRING_INITIALIZER
11698                 (struct cmd_all_queues_drop_en_result,
11699                  all, "all");
11700 static cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_all_queues_drop_en_result,
11703                  queues, "queues");
11704 static cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11705         TOKEN_STRING_INITIALIZER
11706                 (struct cmd_all_queues_drop_en_result,
11707                  drop, "drop");
11708 static cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11709         TOKEN_NUM_INITIALIZER
11710                 (struct cmd_all_queues_drop_en_result,
11711                  port_id, RTE_UINT16);
11712 static cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11713         TOKEN_STRING_INITIALIZER
11714                 (struct cmd_all_queues_drop_en_result,
11715                  on_off, "on#off");
11716
11717 static void
11718 cmd_set_all_queues_drop_en_parsed(
11719         void *parsed_result,
11720         __rte_unused struct cmdline *cl,
11721         __rte_unused void *data)
11722 {
11723         struct cmd_all_queues_drop_en_result *res = parsed_result;
11724         int ret = -ENOTSUP;
11725         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11726
11727         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11728                 return;
11729
11730 #ifdef RTE_NET_IXGBE
11731         if (ret == -ENOTSUP)
11732                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11733 #endif
11734 #ifdef RTE_NET_BNXT
11735         if (ret == -ENOTSUP)
11736                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11737 #endif
11738         switch (ret) {
11739         case 0:
11740                 break;
11741         case -EINVAL:
11742                 fprintf(stderr, "invalid is_on %d\n", is_on);
11743                 break;
11744         case -ENODEV:
11745                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11746                 break;
11747         case -ENOTSUP:
11748                 fprintf(stderr, "function not implemented\n");
11749                 break;
11750         default:
11751                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11752         }
11753 }
11754
11755 static cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11756         .f = cmd_set_all_queues_drop_en_parsed,
11757         .data = NULL,
11758         .help_str = "set all queues drop <port_id> on|off",
11759         .tokens = {
11760                 (void *)&cmd_all_queues_drop_en_set,
11761                 (void *)&cmd_all_queues_drop_en_all,
11762                 (void *)&cmd_all_queues_drop_en_queues,
11763                 (void *)&cmd_all_queues_drop_en_drop,
11764                 (void *)&cmd_all_queues_drop_en_port_id,
11765                 (void *)&cmd_all_queues_drop_en_on_off,
11766                 NULL,
11767         },
11768 };
11769
11770 /* vf split drop enable configuration */
11771
11772 /* Common result structure for vf split drop enable */
11773 struct cmd_vf_split_drop_en_result {
11774         cmdline_fixed_string_t set;
11775         cmdline_fixed_string_t vf;
11776         cmdline_fixed_string_t split;
11777         cmdline_fixed_string_t drop;
11778         portid_t port_id;
11779         uint16_t vf_id;
11780         cmdline_fixed_string_t on_off;
11781 };
11782
11783 /* Common CLI fields for vf split drop enable disable */
11784 static cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11785         TOKEN_STRING_INITIALIZER
11786                 (struct cmd_vf_split_drop_en_result,
11787                  set, "set");
11788 static cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11789         TOKEN_STRING_INITIALIZER
11790                 (struct cmd_vf_split_drop_en_result,
11791                  vf, "vf");
11792 static cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11793         TOKEN_STRING_INITIALIZER
11794                 (struct cmd_vf_split_drop_en_result,
11795                  split, "split");
11796 static cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11797         TOKEN_STRING_INITIALIZER
11798                 (struct cmd_vf_split_drop_en_result,
11799                  drop, "drop");
11800 static cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11801         TOKEN_NUM_INITIALIZER
11802                 (struct cmd_vf_split_drop_en_result,
11803                  port_id, RTE_UINT16);
11804 static cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11805         TOKEN_NUM_INITIALIZER
11806                 (struct cmd_vf_split_drop_en_result,
11807                  vf_id, RTE_UINT16);
11808 static cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11809         TOKEN_STRING_INITIALIZER
11810                 (struct cmd_vf_split_drop_en_result,
11811                  on_off, "on#off");
11812
11813 static void
11814 cmd_set_vf_split_drop_en_parsed(
11815         void *parsed_result,
11816         __rte_unused struct cmdline *cl,
11817         __rte_unused void *data)
11818 {
11819         struct cmd_vf_split_drop_en_result *res = parsed_result;
11820         int ret = -ENOTSUP;
11821         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11822
11823         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11824                 return;
11825
11826 #ifdef RTE_NET_IXGBE
11827         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11828                         is_on);
11829 #endif
11830         switch (ret) {
11831         case 0:
11832                 break;
11833         case -EINVAL:
11834                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11835                         res->vf_id, is_on);
11836                 break;
11837         case -ENODEV:
11838                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11839                 break;
11840         case -ENOTSUP:
11841                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11842                 break;
11843         default:
11844                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11845         }
11846 }
11847
11848 static cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11849         .f = cmd_set_vf_split_drop_en_parsed,
11850         .data = NULL,
11851         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11852         .tokens = {
11853                 (void *)&cmd_vf_split_drop_en_set,
11854                 (void *)&cmd_vf_split_drop_en_vf,
11855                 (void *)&cmd_vf_split_drop_en_split,
11856                 (void *)&cmd_vf_split_drop_en_drop,
11857                 (void *)&cmd_vf_split_drop_en_port_id,
11858                 (void *)&cmd_vf_split_drop_en_vf_id,
11859                 (void *)&cmd_vf_split_drop_en_on_off,
11860                 NULL,
11861         },
11862 };
11863
11864 /* vf mac address configuration */
11865
11866 /* Common result structure for vf mac address */
11867 struct cmd_set_vf_mac_addr_result {
11868         cmdline_fixed_string_t set;
11869         cmdline_fixed_string_t vf;
11870         cmdline_fixed_string_t mac;
11871         cmdline_fixed_string_t addr;
11872         portid_t port_id;
11873         uint16_t vf_id;
11874         struct rte_ether_addr mac_addr;
11875
11876 };
11877
11878 /* Common CLI fields for vf split drop enable disable */
11879 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11880         TOKEN_STRING_INITIALIZER
11881                 (struct cmd_set_vf_mac_addr_result,
11882                  set, "set");
11883 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11884         TOKEN_STRING_INITIALIZER
11885                 (struct cmd_set_vf_mac_addr_result,
11886                  vf, "vf");
11887 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11888         TOKEN_STRING_INITIALIZER
11889                 (struct cmd_set_vf_mac_addr_result,
11890                  mac, "mac");
11891 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11892         TOKEN_STRING_INITIALIZER
11893                 (struct cmd_set_vf_mac_addr_result,
11894                  addr, "addr");
11895 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11896         TOKEN_NUM_INITIALIZER
11897                 (struct cmd_set_vf_mac_addr_result,
11898                  port_id, RTE_UINT16);
11899 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11900         TOKEN_NUM_INITIALIZER
11901                 (struct cmd_set_vf_mac_addr_result,
11902                  vf_id, RTE_UINT16);
11903 static cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11904         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11905                  mac_addr);
11906
11907 static void
11908 cmd_set_vf_mac_addr_parsed(
11909         void *parsed_result,
11910         __rte_unused struct cmdline *cl,
11911         __rte_unused void *data)
11912 {
11913         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11914         int ret = -ENOTSUP;
11915
11916         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11917                 return;
11918
11919 #ifdef RTE_NET_IXGBE
11920         if (ret == -ENOTSUP)
11921                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11922                                 &res->mac_addr);
11923 #endif
11924 #ifdef RTE_NET_I40E
11925         if (ret == -ENOTSUP)
11926                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11927                                 &res->mac_addr);
11928 #endif
11929 #ifdef RTE_NET_BNXT
11930         if (ret == -ENOTSUP)
11931                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11932                                 &res->mac_addr);
11933 #endif
11934
11935         switch (ret) {
11936         case 0:
11937                 break;
11938         case -EINVAL:
11939                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11940                 break;
11941         case -ENODEV:
11942                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11943                 break;
11944         case -ENOTSUP:
11945                 fprintf(stderr, "function not implemented\n");
11946                 break;
11947         default:
11948                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11949         }
11950 }
11951
11952 static cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11953         .f = cmd_set_vf_mac_addr_parsed,
11954         .data = NULL,
11955         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11956         .tokens = {
11957                 (void *)&cmd_set_vf_mac_addr_set,
11958                 (void *)&cmd_set_vf_mac_addr_vf,
11959                 (void *)&cmd_set_vf_mac_addr_mac,
11960                 (void *)&cmd_set_vf_mac_addr_addr,
11961                 (void *)&cmd_set_vf_mac_addr_port_id,
11962                 (void *)&cmd_set_vf_mac_addr_vf_id,
11963                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11964                 NULL,
11965         },
11966 };
11967
11968 /* MACsec configuration */
11969
11970 /* Common result structure for MACsec offload enable */
11971 struct cmd_macsec_offload_on_result {
11972         cmdline_fixed_string_t set;
11973         cmdline_fixed_string_t macsec;
11974         cmdline_fixed_string_t offload;
11975         portid_t port_id;
11976         cmdline_fixed_string_t on;
11977         cmdline_fixed_string_t encrypt;
11978         cmdline_fixed_string_t en_on_off;
11979         cmdline_fixed_string_t replay_protect;
11980         cmdline_fixed_string_t rp_on_off;
11981 };
11982
11983 /* Common CLI fields for MACsec offload disable */
11984 static cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11985         TOKEN_STRING_INITIALIZER
11986                 (struct cmd_macsec_offload_on_result,
11987                  set, "set");
11988 static cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11989         TOKEN_STRING_INITIALIZER
11990                 (struct cmd_macsec_offload_on_result,
11991                  macsec, "macsec");
11992 static cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11993         TOKEN_STRING_INITIALIZER
11994                 (struct cmd_macsec_offload_on_result,
11995                  offload, "offload");
11996 static cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11997         TOKEN_NUM_INITIALIZER
11998                 (struct cmd_macsec_offload_on_result,
11999                  port_id, RTE_UINT16);
12000 static cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12001         TOKEN_STRING_INITIALIZER
12002                 (struct cmd_macsec_offload_on_result,
12003                  on, "on");
12004 static cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12005         TOKEN_STRING_INITIALIZER
12006                 (struct cmd_macsec_offload_on_result,
12007                  encrypt, "encrypt");
12008 static cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12009         TOKEN_STRING_INITIALIZER
12010                 (struct cmd_macsec_offload_on_result,
12011                  en_on_off, "on#off");
12012 static cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12013         TOKEN_STRING_INITIALIZER
12014                 (struct cmd_macsec_offload_on_result,
12015                  replay_protect, "replay-protect");
12016 static cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12017         TOKEN_STRING_INITIALIZER
12018                 (struct cmd_macsec_offload_on_result,
12019                  rp_on_off, "on#off");
12020
12021 static void
12022 cmd_set_macsec_offload_on_parsed(
12023         void *parsed_result,
12024         __rte_unused struct cmdline *cl,
12025         __rte_unused void *data)
12026 {
12027         struct cmd_macsec_offload_on_result *res = parsed_result;
12028         int ret = -ENOTSUP;
12029         portid_t port_id = res->port_id;
12030         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12031         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12032         struct rte_eth_dev_info dev_info;
12033
12034         if (port_id_is_invalid(port_id, ENABLED_WARN))
12035                 return;
12036         if (!port_is_stopped(port_id)) {
12037                 fprintf(stderr, "Please stop port %d first\n", port_id);
12038                 return;
12039         }
12040
12041         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12042         if (ret != 0)
12043                 return;
12044
12045         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12046 #ifdef RTE_NET_IXGBE
12047                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12048 #endif
12049         }
12050         RTE_SET_USED(en);
12051         RTE_SET_USED(rp);
12052
12053         switch (ret) {
12054         case 0:
12055                 ports[port_id].dev_conf.txmode.offloads |=
12056                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12057                 cmd_reconfig_device_queue(port_id, 1, 1);
12058                 break;
12059         case -ENODEV:
12060                 fprintf(stderr, "invalid port_id %d\n", port_id);
12061                 break;
12062         case -ENOTSUP:
12063                 fprintf(stderr, "not supported on port %d\n", port_id);
12064                 break;
12065         default:
12066                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12067         }
12068 }
12069
12070 static cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12071         .f = cmd_set_macsec_offload_on_parsed,
12072         .data = NULL,
12073         .help_str = "set macsec offload <port_id> on "
12074                 "encrypt on|off replay-protect on|off",
12075         .tokens = {
12076                 (void *)&cmd_macsec_offload_on_set,
12077                 (void *)&cmd_macsec_offload_on_macsec,
12078                 (void *)&cmd_macsec_offload_on_offload,
12079                 (void *)&cmd_macsec_offload_on_port_id,
12080                 (void *)&cmd_macsec_offload_on_on,
12081                 (void *)&cmd_macsec_offload_on_encrypt,
12082                 (void *)&cmd_macsec_offload_on_en_on_off,
12083                 (void *)&cmd_macsec_offload_on_replay_protect,
12084                 (void *)&cmd_macsec_offload_on_rp_on_off,
12085                 NULL,
12086         },
12087 };
12088
12089 /* Common result structure for MACsec offload disable */
12090 struct cmd_macsec_offload_off_result {
12091         cmdline_fixed_string_t set;
12092         cmdline_fixed_string_t macsec;
12093         cmdline_fixed_string_t offload;
12094         portid_t port_id;
12095         cmdline_fixed_string_t off;
12096 };
12097
12098 /* Common CLI fields for MACsec offload disable */
12099 static cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12100         TOKEN_STRING_INITIALIZER
12101                 (struct cmd_macsec_offload_off_result,
12102                  set, "set");
12103 static cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12104         TOKEN_STRING_INITIALIZER
12105                 (struct cmd_macsec_offload_off_result,
12106                  macsec, "macsec");
12107 static cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12108         TOKEN_STRING_INITIALIZER
12109                 (struct cmd_macsec_offload_off_result,
12110                  offload, "offload");
12111 static cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12112         TOKEN_NUM_INITIALIZER
12113                 (struct cmd_macsec_offload_off_result,
12114                  port_id, RTE_UINT16);
12115 static cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12116         TOKEN_STRING_INITIALIZER
12117                 (struct cmd_macsec_offload_off_result,
12118                  off, "off");
12119
12120 static void
12121 cmd_set_macsec_offload_off_parsed(
12122         void *parsed_result,
12123         __rte_unused struct cmdline *cl,
12124         __rte_unused void *data)
12125 {
12126         struct cmd_macsec_offload_off_result *res = parsed_result;
12127         int ret = -ENOTSUP;
12128         struct rte_eth_dev_info dev_info;
12129         portid_t port_id = res->port_id;
12130
12131         if (port_id_is_invalid(port_id, ENABLED_WARN))
12132                 return;
12133         if (!port_is_stopped(port_id)) {
12134                 fprintf(stderr, "Please stop port %d first\n", port_id);
12135                 return;
12136         }
12137
12138         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12139         if (ret != 0)
12140                 return;
12141
12142         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12143 #ifdef RTE_NET_IXGBE
12144                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12145 #endif
12146         }
12147         switch (ret) {
12148         case 0:
12149                 ports[port_id].dev_conf.txmode.offloads &=
12150                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12151                 cmd_reconfig_device_queue(port_id, 1, 1);
12152                 break;
12153         case -ENODEV:
12154                 fprintf(stderr, "invalid port_id %d\n", port_id);
12155                 break;
12156         case -ENOTSUP:
12157                 fprintf(stderr, "not supported on port %d\n", port_id);
12158                 break;
12159         default:
12160                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12161         }
12162 }
12163
12164 static cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12165         .f = cmd_set_macsec_offload_off_parsed,
12166         .data = NULL,
12167         .help_str = "set macsec offload <port_id> off",
12168         .tokens = {
12169                 (void *)&cmd_macsec_offload_off_set,
12170                 (void *)&cmd_macsec_offload_off_macsec,
12171                 (void *)&cmd_macsec_offload_off_offload,
12172                 (void *)&cmd_macsec_offload_off_port_id,
12173                 (void *)&cmd_macsec_offload_off_off,
12174                 NULL,
12175         },
12176 };
12177
12178 /* Common result structure for MACsec secure connection configure */
12179 struct cmd_macsec_sc_result {
12180         cmdline_fixed_string_t set;
12181         cmdline_fixed_string_t macsec;
12182         cmdline_fixed_string_t sc;
12183         cmdline_fixed_string_t tx_rx;
12184         portid_t port_id;
12185         struct rte_ether_addr mac;
12186         uint16_t pi;
12187 };
12188
12189 /* Common CLI fields for MACsec secure connection configure */
12190 static cmdline_parse_token_string_t cmd_macsec_sc_set =
12191         TOKEN_STRING_INITIALIZER
12192                 (struct cmd_macsec_sc_result,
12193                  set, "set");
12194 static cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_macsec_sc_result,
12197                  macsec, "macsec");
12198 static cmdline_parse_token_string_t cmd_macsec_sc_sc =
12199         TOKEN_STRING_INITIALIZER
12200                 (struct cmd_macsec_sc_result,
12201                  sc, "sc");
12202 static cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_macsec_sc_result,
12205                  tx_rx, "tx#rx");
12206 static cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12207         TOKEN_NUM_INITIALIZER
12208                 (struct cmd_macsec_sc_result,
12209                  port_id, RTE_UINT16);
12210 static cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12211         TOKEN_ETHERADDR_INITIALIZER
12212                 (struct cmd_macsec_sc_result,
12213                  mac);
12214 static cmdline_parse_token_num_t cmd_macsec_sc_pi =
12215         TOKEN_NUM_INITIALIZER
12216                 (struct cmd_macsec_sc_result,
12217                  pi, RTE_UINT16);
12218
12219 static void
12220 cmd_set_macsec_sc_parsed(
12221         void *parsed_result,
12222         __rte_unused struct cmdline *cl,
12223         __rte_unused void *data)
12224 {
12225         struct cmd_macsec_sc_result *res = parsed_result;
12226         int ret = -ENOTSUP;
12227         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12228
12229 #ifdef RTE_NET_IXGBE
12230         ret = is_tx ?
12231                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12232                                 res->mac.addr_bytes) :
12233                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12234                                 res->mac.addr_bytes, res->pi);
12235 #endif
12236         RTE_SET_USED(is_tx);
12237
12238         switch (ret) {
12239         case 0:
12240                 break;
12241         case -ENODEV:
12242                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12243                 break;
12244         case -ENOTSUP:
12245                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12246                 break;
12247         default:
12248                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12249         }
12250 }
12251
12252 static cmdline_parse_inst_t cmd_set_macsec_sc = {
12253         .f = cmd_set_macsec_sc_parsed,
12254         .data = NULL,
12255         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12256         .tokens = {
12257                 (void *)&cmd_macsec_sc_set,
12258                 (void *)&cmd_macsec_sc_macsec,
12259                 (void *)&cmd_macsec_sc_sc,
12260                 (void *)&cmd_macsec_sc_tx_rx,
12261                 (void *)&cmd_macsec_sc_port_id,
12262                 (void *)&cmd_macsec_sc_mac,
12263                 (void *)&cmd_macsec_sc_pi,
12264                 NULL,
12265         },
12266 };
12267
12268 /* Common result structure for MACsec secure connection configure */
12269 struct cmd_macsec_sa_result {
12270         cmdline_fixed_string_t set;
12271         cmdline_fixed_string_t macsec;
12272         cmdline_fixed_string_t sa;
12273         cmdline_fixed_string_t tx_rx;
12274         portid_t port_id;
12275         uint8_t idx;
12276         uint8_t an;
12277         uint32_t pn;
12278         cmdline_fixed_string_t key;
12279 };
12280
12281 /* Common CLI fields for MACsec secure connection configure */
12282 static cmdline_parse_token_string_t cmd_macsec_sa_set =
12283         TOKEN_STRING_INITIALIZER
12284                 (struct cmd_macsec_sa_result,
12285                  set, "set");
12286 static cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12287         TOKEN_STRING_INITIALIZER
12288                 (struct cmd_macsec_sa_result,
12289                  macsec, "macsec");
12290 static cmdline_parse_token_string_t cmd_macsec_sa_sa =
12291         TOKEN_STRING_INITIALIZER
12292                 (struct cmd_macsec_sa_result,
12293                  sa, "sa");
12294 static cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12295         TOKEN_STRING_INITIALIZER
12296                 (struct cmd_macsec_sa_result,
12297                  tx_rx, "tx#rx");
12298 static cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12299         TOKEN_NUM_INITIALIZER
12300                 (struct cmd_macsec_sa_result,
12301                  port_id, RTE_UINT16);
12302 static cmdline_parse_token_num_t cmd_macsec_sa_idx =
12303         TOKEN_NUM_INITIALIZER
12304                 (struct cmd_macsec_sa_result,
12305                  idx, RTE_UINT8);
12306 static cmdline_parse_token_num_t cmd_macsec_sa_an =
12307         TOKEN_NUM_INITIALIZER
12308                 (struct cmd_macsec_sa_result,
12309                  an, RTE_UINT8);
12310 static cmdline_parse_token_num_t cmd_macsec_sa_pn =
12311         TOKEN_NUM_INITIALIZER
12312                 (struct cmd_macsec_sa_result,
12313                  pn, RTE_UINT32);
12314 static cmdline_parse_token_string_t cmd_macsec_sa_key =
12315         TOKEN_STRING_INITIALIZER
12316                 (struct cmd_macsec_sa_result,
12317                  key, NULL);
12318
12319 static void
12320 cmd_set_macsec_sa_parsed(
12321         void *parsed_result,
12322         __rte_unused struct cmdline *cl,
12323         __rte_unused void *data)
12324 {
12325         struct cmd_macsec_sa_result *res = parsed_result;
12326         int ret = -ENOTSUP;
12327         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12328         uint8_t key[16] = { 0 };
12329         uint8_t xdgt0;
12330         uint8_t xdgt1;
12331         int key_len;
12332         int i;
12333
12334         key_len = strlen(res->key) / 2;
12335         if (key_len > 16)
12336                 key_len = 16;
12337
12338         for (i = 0; i < key_len; i++) {
12339                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12340                 if (xdgt0 == 0xFF)
12341                         return;
12342                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12343                 if (xdgt1 == 0xFF)
12344                         return;
12345                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12346         }
12347
12348 #ifdef RTE_NET_IXGBE
12349         ret = is_tx ?
12350                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12351                         res->idx, res->an, res->pn, key) :
12352                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12353                         res->idx, res->an, res->pn, key);
12354 #endif
12355         RTE_SET_USED(is_tx);
12356         RTE_SET_USED(key);
12357
12358         switch (ret) {
12359         case 0:
12360                 break;
12361         case -EINVAL:
12362                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12363                 break;
12364         case -ENODEV:
12365                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12366                 break;
12367         case -ENOTSUP:
12368                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12369                 break;
12370         default:
12371                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12372         }
12373 }
12374
12375 static cmdline_parse_inst_t cmd_set_macsec_sa = {
12376         .f = cmd_set_macsec_sa_parsed,
12377         .data = NULL,
12378         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12379         .tokens = {
12380                 (void *)&cmd_macsec_sa_set,
12381                 (void *)&cmd_macsec_sa_macsec,
12382                 (void *)&cmd_macsec_sa_sa,
12383                 (void *)&cmd_macsec_sa_tx_rx,
12384                 (void *)&cmd_macsec_sa_port_id,
12385                 (void *)&cmd_macsec_sa_idx,
12386                 (void *)&cmd_macsec_sa_an,
12387                 (void *)&cmd_macsec_sa_pn,
12388                 (void *)&cmd_macsec_sa_key,
12389                 NULL,
12390         },
12391 };
12392
12393 /* VF unicast promiscuous mode configuration */
12394
12395 /* Common result structure for VF unicast promiscuous mode */
12396 struct cmd_vf_promisc_result {
12397         cmdline_fixed_string_t set;
12398         cmdline_fixed_string_t vf;
12399         cmdline_fixed_string_t promisc;
12400         portid_t port_id;
12401         uint32_t vf_id;
12402         cmdline_fixed_string_t on_off;
12403 };
12404
12405 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12406 static cmdline_parse_token_string_t cmd_vf_promisc_set =
12407         TOKEN_STRING_INITIALIZER
12408                 (struct cmd_vf_promisc_result,
12409                  set, "set");
12410 static cmdline_parse_token_string_t cmd_vf_promisc_vf =
12411         TOKEN_STRING_INITIALIZER
12412                 (struct cmd_vf_promisc_result,
12413                  vf, "vf");
12414 static cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12415         TOKEN_STRING_INITIALIZER
12416                 (struct cmd_vf_promisc_result,
12417                  promisc, "promisc");
12418 static cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12419         TOKEN_NUM_INITIALIZER
12420                 (struct cmd_vf_promisc_result,
12421                  port_id, RTE_UINT16);
12422 static cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12423         TOKEN_NUM_INITIALIZER
12424                 (struct cmd_vf_promisc_result,
12425                  vf_id, RTE_UINT32);
12426 static cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12427         TOKEN_STRING_INITIALIZER
12428                 (struct cmd_vf_promisc_result,
12429                  on_off, "on#off");
12430
12431 static void
12432 cmd_set_vf_promisc_parsed(
12433         void *parsed_result,
12434         __rte_unused struct cmdline *cl,
12435         __rte_unused void *data)
12436 {
12437         struct cmd_vf_promisc_result *res = parsed_result;
12438         int ret = -ENOTSUP;
12439
12440         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12441
12442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12443                 return;
12444
12445 #ifdef RTE_NET_I40E
12446         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12447                                                   res->vf_id, is_on);
12448 #endif
12449
12450         switch (ret) {
12451         case 0:
12452                 break;
12453         case -EINVAL:
12454                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12455                 break;
12456         case -ENODEV:
12457                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12458                 break;
12459         case -ENOTSUP:
12460                 fprintf(stderr, "function not implemented\n");
12461                 break;
12462         default:
12463                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12464         }
12465 }
12466
12467 static cmdline_parse_inst_t cmd_set_vf_promisc = {
12468         .f = cmd_set_vf_promisc_parsed,
12469         .data = NULL,
12470         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12471                 "Set unicast promiscuous mode for a VF from the PF",
12472         .tokens = {
12473                 (void *)&cmd_vf_promisc_set,
12474                 (void *)&cmd_vf_promisc_vf,
12475                 (void *)&cmd_vf_promisc_promisc,
12476                 (void *)&cmd_vf_promisc_port_id,
12477                 (void *)&cmd_vf_promisc_vf_id,
12478                 (void *)&cmd_vf_promisc_on_off,
12479                 NULL,
12480         },
12481 };
12482
12483 /* VF multicast promiscuous mode configuration */
12484
12485 /* Common result structure for VF multicast promiscuous mode */
12486 struct cmd_vf_allmulti_result {
12487         cmdline_fixed_string_t set;
12488         cmdline_fixed_string_t vf;
12489         cmdline_fixed_string_t allmulti;
12490         portid_t port_id;
12491         uint32_t vf_id;
12492         cmdline_fixed_string_t on_off;
12493 };
12494
12495 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12496 static cmdline_parse_token_string_t cmd_vf_allmulti_set =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_vf_allmulti_result,
12499                  set, "set");
12500 static cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_vf_allmulti_result,
12503                  vf, "vf");
12504 static cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12505         TOKEN_STRING_INITIALIZER
12506                 (struct cmd_vf_allmulti_result,
12507                  allmulti, "allmulti");
12508 static cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12509         TOKEN_NUM_INITIALIZER
12510                 (struct cmd_vf_allmulti_result,
12511                  port_id, RTE_UINT16);
12512 static cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12513         TOKEN_NUM_INITIALIZER
12514                 (struct cmd_vf_allmulti_result,
12515                  vf_id, RTE_UINT32);
12516 static cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_vf_allmulti_result,
12519                  on_off, "on#off");
12520
12521 static void
12522 cmd_set_vf_allmulti_parsed(
12523         void *parsed_result,
12524         __rte_unused struct cmdline *cl,
12525         __rte_unused void *data)
12526 {
12527         struct cmd_vf_allmulti_result *res = parsed_result;
12528         int ret = -ENOTSUP;
12529
12530         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12531
12532         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12533                 return;
12534
12535 #ifdef RTE_NET_I40E
12536         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12537                                                     res->vf_id, is_on);
12538 #endif
12539
12540         switch (ret) {
12541         case 0:
12542                 break;
12543         case -EINVAL:
12544                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12545                 break;
12546         case -ENODEV:
12547                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12548                 break;
12549         case -ENOTSUP:
12550                 fprintf(stderr, "function not implemented\n");
12551                 break;
12552         default:
12553                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12554         }
12555 }
12556
12557 static cmdline_parse_inst_t cmd_set_vf_allmulti = {
12558         .f = cmd_set_vf_allmulti_parsed,
12559         .data = NULL,
12560         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12561                 "Set multicast promiscuous mode for a VF from the PF",
12562         .tokens = {
12563                 (void *)&cmd_vf_allmulti_set,
12564                 (void *)&cmd_vf_allmulti_vf,
12565                 (void *)&cmd_vf_allmulti_allmulti,
12566                 (void *)&cmd_vf_allmulti_port_id,
12567                 (void *)&cmd_vf_allmulti_vf_id,
12568                 (void *)&cmd_vf_allmulti_on_off,
12569                 NULL,
12570         },
12571 };
12572
12573 /* vf broadcast mode configuration */
12574
12575 /* Common result structure for vf broadcast */
12576 struct cmd_set_vf_broadcast_result {
12577         cmdline_fixed_string_t set;
12578         cmdline_fixed_string_t vf;
12579         cmdline_fixed_string_t broadcast;
12580         portid_t port_id;
12581         uint16_t vf_id;
12582         cmdline_fixed_string_t on_off;
12583 };
12584
12585 /* Common CLI fields for vf broadcast enable disable */
12586 static cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12587         TOKEN_STRING_INITIALIZER
12588                 (struct cmd_set_vf_broadcast_result,
12589                  set, "set");
12590 static cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12591         TOKEN_STRING_INITIALIZER
12592                 (struct cmd_set_vf_broadcast_result,
12593                  vf, "vf");
12594 static cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12595         TOKEN_STRING_INITIALIZER
12596                 (struct cmd_set_vf_broadcast_result,
12597                  broadcast, "broadcast");
12598 static cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12599         TOKEN_NUM_INITIALIZER
12600                 (struct cmd_set_vf_broadcast_result,
12601                  port_id, RTE_UINT16);
12602 static cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12603         TOKEN_NUM_INITIALIZER
12604                 (struct cmd_set_vf_broadcast_result,
12605                  vf_id, RTE_UINT16);
12606 static cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12607         TOKEN_STRING_INITIALIZER
12608                 (struct cmd_set_vf_broadcast_result,
12609                  on_off, "on#off");
12610
12611 static void
12612 cmd_set_vf_broadcast_parsed(
12613         void *parsed_result,
12614         __rte_unused struct cmdline *cl,
12615         __rte_unused void *data)
12616 {
12617         struct cmd_set_vf_broadcast_result *res = parsed_result;
12618         int ret = -ENOTSUP;
12619
12620         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12621
12622         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12623                 return;
12624
12625 #ifdef RTE_NET_I40E
12626         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12627                                             res->vf_id, is_on);
12628 #endif
12629
12630         switch (ret) {
12631         case 0:
12632                 break;
12633         case -EINVAL:
12634                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12635                         res->vf_id, is_on);
12636                 break;
12637         case -ENODEV:
12638                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12639                 break;
12640         case -ENOTSUP:
12641                 fprintf(stderr, "function not implemented\n");
12642                 break;
12643         default:
12644                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12645         }
12646 }
12647
12648 static cmdline_parse_inst_t cmd_set_vf_broadcast = {
12649         .f = cmd_set_vf_broadcast_parsed,
12650         .data = NULL,
12651         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12652         .tokens = {
12653                 (void *)&cmd_set_vf_broadcast_set,
12654                 (void *)&cmd_set_vf_broadcast_vf,
12655                 (void *)&cmd_set_vf_broadcast_broadcast,
12656                 (void *)&cmd_set_vf_broadcast_port_id,
12657                 (void *)&cmd_set_vf_broadcast_vf_id,
12658                 (void *)&cmd_set_vf_broadcast_on_off,
12659                 NULL,
12660         },
12661 };
12662
12663 /* vf vlan tag configuration */
12664
12665 /* Common result structure for vf vlan tag */
12666 struct cmd_set_vf_vlan_tag_result {
12667         cmdline_fixed_string_t set;
12668         cmdline_fixed_string_t vf;
12669         cmdline_fixed_string_t vlan;
12670         cmdline_fixed_string_t tag;
12671         portid_t port_id;
12672         uint16_t vf_id;
12673         cmdline_fixed_string_t on_off;
12674 };
12675
12676 /* Common CLI fields for vf vlan tag enable disable */
12677 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12678         TOKEN_STRING_INITIALIZER
12679                 (struct cmd_set_vf_vlan_tag_result,
12680                  set, "set");
12681 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12682         TOKEN_STRING_INITIALIZER
12683                 (struct cmd_set_vf_vlan_tag_result,
12684                  vf, "vf");
12685 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_set_vf_vlan_tag_result,
12688                  vlan, "vlan");
12689 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12690         TOKEN_STRING_INITIALIZER
12691                 (struct cmd_set_vf_vlan_tag_result,
12692                  tag, "tag");
12693 static cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12694         TOKEN_NUM_INITIALIZER
12695                 (struct cmd_set_vf_vlan_tag_result,
12696                  port_id, RTE_UINT16);
12697 static cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12698         TOKEN_NUM_INITIALIZER
12699                 (struct cmd_set_vf_vlan_tag_result,
12700                  vf_id, RTE_UINT16);
12701 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12702         TOKEN_STRING_INITIALIZER
12703                 (struct cmd_set_vf_vlan_tag_result,
12704                  on_off, "on#off");
12705
12706 static void
12707 cmd_set_vf_vlan_tag_parsed(
12708         void *parsed_result,
12709         __rte_unused struct cmdline *cl,
12710         __rte_unused void *data)
12711 {
12712         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12713         int ret = -ENOTSUP;
12714
12715         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12716
12717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12718                 return;
12719
12720 #ifdef RTE_NET_I40E
12721         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12722                                            res->vf_id, is_on);
12723 #endif
12724
12725         switch (ret) {
12726         case 0:
12727                 break;
12728         case -EINVAL:
12729                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12730                         res->vf_id, is_on);
12731                 break;
12732         case -ENODEV:
12733                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12734                 break;
12735         case -ENOTSUP:
12736                 fprintf(stderr, "function not implemented\n");
12737                 break;
12738         default:
12739                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12740         }
12741 }
12742
12743 static cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12744         .f = cmd_set_vf_vlan_tag_parsed,
12745         .data = NULL,
12746         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12747         .tokens = {
12748                 (void *)&cmd_set_vf_vlan_tag_set,
12749                 (void *)&cmd_set_vf_vlan_tag_vf,
12750                 (void *)&cmd_set_vf_vlan_tag_vlan,
12751                 (void *)&cmd_set_vf_vlan_tag_tag,
12752                 (void *)&cmd_set_vf_vlan_tag_port_id,
12753                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12754                 (void *)&cmd_set_vf_vlan_tag_on_off,
12755                 NULL,
12756         },
12757 };
12758
12759 /* Common definition of VF and TC TX bandwidth configuration */
12760 struct cmd_vf_tc_bw_result {
12761         cmdline_fixed_string_t set;
12762         cmdline_fixed_string_t vf;
12763         cmdline_fixed_string_t tc;
12764         cmdline_fixed_string_t tx;
12765         cmdline_fixed_string_t min_bw;
12766         cmdline_fixed_string_t max_bw;
12767         cmdline_fixed_string_t strict_link_prio;
12768         portid_t port_id;
12769         uint16_t vf_id;
12770         uint8_t tc_no;
12771         uint32_t bw;
12772         cmdline_fixed_string_t bw_list;
12773         uint8_t tc_map;
12774 };
12775
12776 static cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12777         TOKEN_STRING_INITIALIZER
12778                 (struct cmd_vf_tc_bw_result,
12779                  set, "set");
12780 static cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12781         TOKEN_STRING_INITIALIZER
12782                 (struct cmd_vf_tc_bw_result,
12783                  vf, "vf");
12784 static cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12785         TOKEN_STRING_INITIALIZER
12786                 (struct cmd_vf_tc_bw_result,
12787                  tc, "tc");
12788 static cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_vf_tc_bw_result,
12791                  tx, "tx");
12792 static cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_vf_tc_bw_result,
12795                  strict_link_prio, "strict-link-priority");
12796 static cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12797         TOKEN_STRING_INITIALIZER
12798                 (struct cmd_vf_tc_bw_result,
12799                  min_bw, "min-bandwidth");
12800 static cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12801         TOKEN_STRING_INITIALIZER
12802                 (struct cmd_vf_tc_bw_result,
12803                  max_bw, "max-bandwidth");
12804 static cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12805         TOKEN_NUM_INITIALIZER
12806                 (struct cmd_vf_tc_bw_result,
12807                  port_id, RTE_UINT16);
12808 static cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12809         TOKEN_NUM_INITIALIZER
12810                 (struct cmd_vf_tc_bw_result,
12811                  vf_id, RTE_UINT16);
12812 static cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12813         TOKEN_NUM_INITIALIZER
12814                 (struct cmd_vf_tc_bw_result,
12815                  tc_no, RTE_UINT8);
12816 static cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12817         TOKEN_NUM_INITIALIZER
12818                 (struct cmd_vf_tc_bw_result,
12819                  bw, RTE_UINT32);
12820 static cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12821         TOKEN_STRING_INITIALIZER
12822                 (struct cmd_vf_tc_bw_result,
12823                  bw_list, NULL);
12824 static cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12825         TOKEN_NUM_INITIALIZER
12826                 (struct cmd_vf_tc_bw_result,
12827                  tc_map, RTE_UINT8);
12828
12829 /* VF max bandwidth setting */
12830 static void
12831 cmd_vf_max_bw_parsed(
12832         void *parsed_result,
12833         __rte_unused struct cmdline *cl,
12834         __rte_unused void *data)
12835 {
12836         struct cmd_vf_tc_bw_result *res = parsed_result;
12837         int ret = -ENOTSUP;
12838
12839         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12840                 return;
12841
12842 #ifdef RTE_NET_I40E
12843         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12844                                          res->vf_id, res->bw);
12845 #endif
12846
12847         switch (ret) {
12848         case 0:
12849                 break;
12850         case -EINVAL:
12851                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12852                         res->vf_id, res->bw);
12853                 break;
12854         case -ENODEV:
12855                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12856                 break;
12857         case -ENOTSUP:
12858                 fprintf(stderr, "function not implemented\n");
12859                 break;
12860         default:
12861                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12862         }
12863 }
12864
12865 static cmdline_parse_inst_t cmd_vf_max_bw = {
12866         .f = cmd_vf_max_bw_parsed,
12867         .data = NULL,
12868         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12869         .tokens = {
12870                 (void *)&cmd_vf_tc_bw_set,
12871                 (void *)&cmd_vf_tc_bw_vf,
12872                 (void *)&cmd_vf_tc_bw_tx,
12873                 (void *)&cmd_vf_tc_bw_max_bw,
12874                 (void *)&cmd_vf_tc_bw_port_id,
12875                 (void *)&cmd_vf_tc_bw_vf_id,
12876                 (void *)&cmd_vf_tc_bw_bw,
12877                 NULL,
12878         },
12879 };
12880
12881 static int
12882 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12883                            uint8_t *tc_num,
12884                            char *str)
12885 {
12886         uint32_t size;
12887         const char *p, *p0 = str;
12888         char s[256];
12889         char *end;
12890         char *str_fld[16];
12891         uint16_t i;
12892         int ret;
12893
12894         p = strchr(p0, '(');
12895         if (p == NULL) {
12896                 fprintf(stderr,
12897                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12898                 return -1;
12899         }
12900         p++;
12901         p0 = strchr(p, ')');
12902         if (p0 == NULL) {
12903                 fprintf(stderr,
12904                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12905                 return -1;
12906         }
12907         size = p0 - p;
12908         if (size >= sizeof(s)) {
12909                 fprintf(stderr,
12910                         "The string size exceeds the internal buffer size\n");
12911                 return -1;
12912         }
12913         snprintf(s, sizeof(s), "%.*s", size, p);
12914         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12915         if (ret <= 0) {
12916                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12917                 return -1;
12918         }
12919         *tc_num = ret;
12920         for (i = 0; i < ret; i++)
12921                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12922
12923         return 0;
12924 }
12925
12926 /* TC min bandwidth setting */
12927 static void
12928 cmd_vf_tc_min_bw_parsed(
12929         void *parsed_result,
12930         __rte_unused struct cmdline *cl,
12931         __rte_unused void *data)
12932 {
12933         struct cmd_vf_tc_bw_result *res = parsed_result;
12934         uint8_t tc_num;
12935         uint8_t bw[16];
12936         int ret = -ENOTSUP;
12937
12938         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12939                 return;
12940
12941         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12942         if (ret)
12943                 return;
12944
12945 #ifdef RTE_NET_I40E
12946         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12947                                               tc_num, bw);
12948 #endif
12949
12950         switch (ret) {
12951         case 0:
12952                 break;
12953         case -EINVAL:
12954                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12955                 break;
12956         case -ENODEV:
12957                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12958                 break;
12959         case -ENOTSUP:
12960                 fprintf(stderr, "function not implemented\n");
12961                 break;
12962         default:
12963                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12964         }
12965 }
12966
12967 static cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12968         .f = cmd_vf_tc_min_bw_parsed,
12969         .data = NULL,
12970         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12971                     " <bw1, bw2, ...>",
12972         .tokens = {
12973                 (void *)&cmd_vf_tc_bw_set,
12974                 (void *)&cmd_vf_tc_bw_vf,
12975                 (void *)&cmd_vf_tc_bw_tc,
12976                 (void *)&cmd_vf_tc_bw_tx,
12977                 (void *)&cmd_vf_tc_bw_min_bw,
12978                 (void *)&cmd_vf_tc_bw_port_id,
12979                 (void *)&cmd_vf_tc_bw_vf_id,
12980                 (void *)&cmd_vf_tc_bw_bw_list,
12981                 NULL,
12982         },
12983 };
12984
12985 static void
12986 cmd_tc_min_bw_parsed(
12987         void *parsed_result,
12988         __rte_unused struct cmdline *cl,
12989         __rte_unused void *data)
12990 {
12991         struct cmd_vf_tc_bw_result *res = parsed_result;
12992         struct rte_port *port;
12993         uint8_t tc_num;
12994         uint8_t bw[16];
12995         int ret = -ENOTSUP;
12996
12997         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12998                 return;
12999
13000         port = &ports[res->port_id];
13001         /** Check if the port is not started **/
13002         if (port->port_status != RTE_PORT_STOPPED) {
13003                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
13004                 return;
13005         }
13006
13007         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13008         if (ret)
13009                 return;
13010
13011 #ifdef RTE_NET_IXGBE
13012         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13013 #endif
13014
13015         switch (ret) {
13016         case 0:
13017                 break;
13018         case -EINVAL:
13019                 fprintf(stderr, "invalid bandwidth\n");
13020                 break;
13021         case -ENODEV:
13022                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13023                 break;
13024         case -ENOTSUP:
13025                 fprintf(stderr, "function not implemented\n");
13026                 break;
13027         default:
13028                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13029         }
13030 }
13031
13032 static cmdline_parse_inst_t cmd_tc_min_bw = {
13033         .f = cmd_tc_min_bw_parsed,
13034         .data = NULL,
13035         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13036         .tokens = {
13037                 (void *)&cmd_vf_tc_bw_set,
13038                 (void *)&cmd_vf_tc_bw_tc,
13039                 (void *)&cmd_vf_tc_bw_tx,
13040                 (void *)&cmd_vf_tc_bw_min_bw,
13041                 (void *)&cmd_vf_tc_bw_port_id,
13042                 (void *)&cmd_vf_tc_bw_bw_list,
13043                 NULL,
13044         },
13045 };
13046
13047 /* TC max bandwidth setting */
13048 static void
13049 cmd_vf_tc_max_bw_parsed(
13050         void *parsed_result,
13051         __rte_unused struct cmdline *cl,
13052         __rte_unused void *data)
13053 {
13054         struct cmd_vf_tc_bw_result *res = parsed_result;
13055         int ret = -ENOTSUP;
13056
13057         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13058                 return;
13059
13060 #ifdef RTE_NET_I40E
13061         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13062                                             res->tc_no, res->bw);
13063 #endif
13064
13065         switch (ret) {
13066         case 0:
13067                 break;
13068         case -EINVAL:
13069                 fprintf(stderr,
13070                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
13071                         res->vf_id, res->tc_no, res->bw);
13072                 break;
13073         case -ENODEV:
13074                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13075                 break;
13076         case -ENOTSUP:
13077                 fprintf(stderr, "function not implemented\n");
13078                 break;
13079         default:
13080                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13081         }
13082 }
13083
13084 static cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13085         .f = cmd_vf_tc_max_bw_parsed,
13086         .data = NULL,
13087         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13088                     " <bandwidth>",
13089         .tokens = {
13090                 (void *)&cmd_vf_tc_bw_set,
13091                 (void *)&cmd_vf_tc_bw_vf,
13092                 (void *)&cmd_vf_tc_bw_tc,
13093                 (void *)&cmd_vf_tc_bw_tx,
13094                 (void *)&cmd_vf_tc_bw_max_bw,
13095                 (void *)&cmd_vf_tc_bw_port_id,
13096                 (void *)&cmd_vf_tc_bw_vf_id,
13097                 (void *)&cmd_vf_tc_bw_tc_no,
13098                 (void *)&cmd_vf_tc_bw_bw,
13099                 NULL,
13100         },
13101 };
13102
13103 /** Set VXLAN encapsulation details */
13104 struct cmd_set_vxlan_result {
13105         cmdline_fixed_string_t set;
13106         cmdline_fixed_string_t vxlan;
13107         cmdline_fixed_string_t pos_token;
13108         cmdline_fixed_string_t ip_version;
13109         uint32_t vlan_present:1;
13110         uint32_t vni;
13111         uint16_t udp_src;
13112         uint16_t udp_dst;
13113         cmdline_ipaddr_t ip_src;
13114         cmdline_ipaddr_t ip_dst;
13115         uint16_t tci;
13116         uint8_t tos;
13117         uint8_t ttl;
13118         struct rte_ether_addr eth_src;
13119         struct rte_ether_addr eth_dst;
13120 };
13121
13122 static cmdline_parse_token_string_t cmd_set_vxlan_set =
13123         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13124 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13125         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13126 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13127         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13128                                  "vxlan-tos-ttl");
13129 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13130         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13131                                  "vxlan-with-vlan");
13132 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13133         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13134                                  "ip-version");
13135 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13136         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13137                                  "ipv4#ipv6");
13138 static cmdline_parse_token_string_t cmd_set_vxlan_vni =
13139         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13140                                  "vni");
13141 static cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13142         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13143 static cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13144         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13145                                  "udp-src");
13146 static cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13147         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13148 static cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13149         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13150                                  "udp-dst");
13151 static cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13152         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13153 static cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13154         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13155                                  "ip-tos");
13156 static cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13157         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13158 static cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13159         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13160                                  "ip-ttl");
13161 static cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13162         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13163 static cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13164         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13165                                  "ip-src");
13166 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13167         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13168 static cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13169         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13170                                  "ip-dst");
13171 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13172         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13173 static cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13174         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13175                                  "vlan-tci");
13176 static cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13177         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13178 static cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13179         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13180                                  "eth-src");
13181 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13182         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13183 static cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13184         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13185                                  "eth-dst");
13186 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13187         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13188
13189 static void cmd_set_vxlan_parsed(void *parsed_result,
13190         __rte_unused struct cmdline *cl,
13191         __rte_unused void *data)
13192 {
13193         struct cmd_set_vxlan_result *res = parsed_result;
13194         union {
13195                 uint32_t vxlan_id;
13196                 uint8_t vni[4];
13197         } id = {
13198                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13199         };
13200
13201         vxlan_encap_conf.select_tos_ttl = 0;
13202         if (strcmp(res->vxlan, "vxlan") == 0)
13203                 vxlan_encap_conf.select_vlan = 0;
13204         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13205                 vxlan_encap_conf.select_vlan = 1;
13206         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13207                 vxlan_encap_conf.select_vlan = 0;
13208                 vxlan_encap_conf.select_tos_ttl = 1;
13209         }
13210         if (strcmp(res->ip_version, "ipv4") == 0)
13211                 vxlan_encap_conf.select_ipv4 = 1;
13212         else if (strcmp(res->ip_version, "ipv6") == 0)
13213                 vxlan_encap_conf.select_ipv4 = 0;
13214         else
13215                 return;
13216         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13217         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13218         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13219         vxlan_encap_conf.ip_tos = res->tos;
13220         vxlan_encap_conf.ip_ttl = res->ttl;
13221         if (vxlan_encap_conf.select_ipv4) {
13222                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13223                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13224         } else {
13225                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13226                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13227         }
13228         if (vxlan_encap_conf.select_vlan)
13229                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13230         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13231                    RTE_ETHER_ADDR_LEN);
13232         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13233                    RTE_ETHER_ADDR_LEN);
13234 }
13235
13236 static cmdline_parse_inst_t cmd_set_vxlan = {
13237         .f = cmd_set_vxlan_parsed,
13238         .data = NULL,
13239         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13240                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13241                 " eth-src <eth-src> eth-dst <eth-dst>",
13242         .tokens = {
13243                 (void *)&cmd_set_vxlan_set,
13244                 (void *)&cmd_set_vxlan_vxlan,
13245                 (void *)&cmd_set_vxlan_ip_version,
13246                 (void *)&cmd_set_vxlan_ip_version_value,
13247                 (void *)&cmd_set_vxlan_vni,
13248                 (void *)&cmd_set_vxlan_vni_value,
13249                 (void *)&cmd_set_vxlan_udp_src,
13250                 (void *)&cmd_set_vxlan_udp_src_value,
13251                 (void *)&cmd_set_vxlan_udp_dst,
13252                 (void *)&cmd_set_vxlan_udp_dst_value,
13253                 (void *)&cmd_set_vxlan_ip_src,
13254                 (void *)&cmd_set_vxlan_ip_src_value,
13255                 (void *)&cmd_set_vxlan_ip_dst,
13256                 (void *)&cmd_set_vxlan_ip_dst_value,
13257                 (void *)&cmd_set_vxlan_eth_src,
13258                 (void *)&cmd_set_vxlan_eth_src_value,
13259                 (void *)&cmd_set_vxlan_eth_dst,
13260                 (void *)&cmd_set_vxlan_eth_dst_value,
13261                 NULL,
13262         },
13263 };
13264
13265 static cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13266         .f = cmd_set_vxlan_parsed,
13267         .data = NULL,
13268         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13269                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13270                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13271                 " eth-dst <eth-dst>",
13272         .tokens = {
13273                 (void *)&cmd_set_vxlan_set,
13274                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13275                 (void *)&cmd_set_vxlan_ip_version,
13276                 (void *)&cmd_set_vxlan_ip_version_value,
13277                 (void *)&cmd_set_vxlan_vni,
13278                 (void *)&cmd_set_vxlan_vni_value,
13279                 (void *)&cmd_set_vxlan_udp_src,
13280                 (void *)&cmd_set_vxlan_udp_src_value,
13281                 (void *)&cmd_set_vxlan_udp_dst,
13282                 (void *)&cmd_set_vxlan_udp_dst_value,
13283                 (void *)&cmd_set_vxlan_ip_tos,
13284                 (void *)&cmd_set_vxlan_ip_tos_value,
13285                 (void *)&cmd_set_vxlan_ip_ttl,
13286                 (void *)&cmd_set_vxlan_ip_ttl_value,
13287                 (void *)&cmd_set_vxlan_ip_src,
13288                 (void *)&cmd_set_vxlan_ip_src_value,
13289                 (void *)&cmd_set_vxlan_ip_dst,
13290                 (void *)&cmd_set_vxlan_ip_dst_value,
13291                 (void *)&cmd_set_vxlan_eth_src,
13292                 (void *)&cmd_set_vxlan_eth_src_value,
13293                 (void *)&cmd_set_vxlan_eth_dst,
13294                 (void *)&cmd_set_vxlan_eth_dst_value,
13295                 NULL,
13296         },
13297 };
13298
13299 static cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13300         .f = cmd_set_vxlan_parsed,
13301         .data = NULL,
13302         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13303                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13304                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13305                 " <eth-dst>",
13306         .tokens = {
13307                 (void *)&cmd_set_vxlan_set,
13308                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13309                 (void *)&cmd_set_vxlan_ip_version,
13310                 (void *)&cmd_set_vxlan_ip_version_value,
13311                 (void *)&cmd_set_vxlan_vni,
13312                 (void *)&cmd_set_vxlan_vni_value,
13313                 (void *)&cmd_set_vxlan_udp_src,
13314                 (void *)&cmd_set_vxlan_udp_src_value,
13315                 (void *)&cmd_set_vxlan_udp_dst,
13316                 (void *)&cmd_set_vxlan_udp_dst_value,
13317                 (void *)&cmd_set_vxlan_ip_src,
13318                 (void *)&cmd_set_vxlan_ip_src_value,
13319                 (void *)&cmd_set_vxlan_ip_dst,
13320                 (void *)&cmd_set_vxlan_ip_dst_value,
13321                 (void *)&cmd_set_vxlan_vlan,
13322                 (void *)&cmd_set_vxlan_vlan_value,
13323                 (void *)&cmd_set_vxlan_eth_src,
13324                 (void *)&cmd_set_vxlan_eth_src_value,
13325                 (void *)&cmd_set_vxlan_eth_dst,
13326                 (void *)&cmd_set_vxlan_eth_dst_value,
13327                 NULL,
13328         },
13329 };
13330
13331 /** Set NVGRE encapsulation details */
13332 struct cmd_set_nvgre_result {
13333         cmdline_fixed_string_t set;
13334         cmdline_fixed_string_t nvgre;
13335         cmdline_fixed_string_t pos_token;
13336         cmdline_fixed_string_t ip_version;
13337         uint32_t tni;
13338         cmdline_ipaddr_t ip_src;
13339         cmdline_ipaddr_t ip_dst;
13340         uint16_t tci;
13341         struct rte_ether_addr eth_src;
13342         struct rte_ether_addr eth_dst;
13343 };
13344
13345 static cmdline_parse_token_string_t cmd_set_nvgre_set =
13346         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13347 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13348         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13349 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13350         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13351                                  "nvgre-with-vlan");
13352 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13353         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13354                                  "ip-version");
13355 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13356         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13357                                  "ipv4#ipv6");
13358 static cmdline_parse_token_string_t cmd_set_nvgre_tni =
13359         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13360                                  "tni");
13361 static cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13362         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13363 static cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13364         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13365                                  "ip-src");
13366 static cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13367         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13368 static cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13369         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13370                                  "ip-dst");
13371 static cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13372         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13373 static cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13374         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13375                                  "vlan-tci");
13376 static cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13377         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13378 static cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13379         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13380                                  "eth-src");
13381 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13382         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13383 static cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13384         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13385                                  "eth-dst");
13386 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13387         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13388
13389 static void cmd_set_nvgre_parsed(void *parsed_result,
13390         __rte_unused struct cmdline *cl,
13391         __rte_unused void *data)
13392 {
13393         struct cmd_set_nvgre_result *res = parsed_result;
13394         union {
13395                 uint32_t nvgre_tni;
13396                 uint8_t tni[4];
13397         } id = {
13398                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13399         };
13400
13401         if (strcmp(res->nvgre, "nvgre") == 0)
13402                 nvgre_encap_conf.select_vlan = 0;
13403         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13404                 nvgre_encap_conf.select_vlan = 1;
13405         if (strcmp(res->ip_version, "ipv4") == 0)
13406                 nvgre_encap_conf.select_ipv4 = 1;
13407         else if (strcmp(res->ip_version, "ipv6") == 0)
13408                 nvgre_encap_conf.select_ipv4 = 0;
13409         else
13410                 return;
13411         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13412         if (nvgre_encap_conf.select_ipv4) {
13413                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13414                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13415         } else {
13416                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13417                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13418         }
13419         if (nvgre_encap_conf.select_vlan)
13420                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13421         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13422                    RTE_ETHER_ADDR_LEN);
13423         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13424                    RTE_ETHER_ADDR_LEN);
13425 }
13426
13427 static cmdline_parse_inst_t cmd_set_nvgre = {
13428         .f = cmd_set_nvgre_parsed,
13429         .data = NULL,
13430         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13431                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13432                 " eth-dst <eth-dst>",
13433         .tokens = {
13434                 (void *)&cmd_set_nvgre_set,
13435                 (void *)&cmd_set_nvgre_nvgre,
13436                 (void *)&cmd_set_nvgre_ip_version,
13437                 (void *)&cmd_set_nvgre_ip_version_value,
13438                 (void *)&cmd_set_nvgre_tni,
13439                 (void *)&cmd_set_nvgre_tni_value,
13440                 (void *)&cmd_set_nvgre_ip_src,
13441                 (void *)&cmd_set_nvgre_ip_src_value,
13442                 (void *)&cmd_set_nvgre_ip_dst,
13443                 (void *)&cmd_set_nvgre_ip_dst_value,
13444                 (void *)&cmd_set_nvgre_eth_src,
13445                 (void *)&cmd_set_nvgre_eth_src_value,
13446                 (void *)&cmd_set_nvgre_eth_dst,
13447                 (void *)&cmd_set_nvgre_eth_dst_value,
13448                 NULL,
13449         },
13450 };
13451
13452 static cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13453         .f = cmd_set_nvgre_parsed,
13454         .data = NULL,
13455         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13456                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13457                 " eth-src <eth-src> eth-dst <eth-dst>",
13458         .tokens = {
13459                 (void *)&cmd_set_nvgre_set,
13460                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13461                 (void *)&cmd_set_nvgre_ip_version,
13462                 (void *)&cmd_set_nvgre_ip_version_value,
13463                 (void *)&cmd_set_nvgre_tni,
13464                 (void *)&cmd_set_nvgre_tni_value,
13465                 (void *)&cmd_set_nvgre_ip_src,
13466                 (void *)&cmd_set_nvgre_ip_src_value,
13467                 (void *)&cmd_set_nvgre_ip_dst,
13468                 (void *)&cmd_set_nvgre_ip_dst_value,
13469                 (void *)&cmd_set_nvgre_vlan,
13470                 (void *)&cmd_set_nvgre_vlan_value,
13471                 (void *)&cmd_set_nvgre_eth_src,
13472                 (void *)&cmd_set_nvgre_eth_src_value,
13473                 (void *)&cmd_set_nvgre_eth_dst,
13474                 (void *)&cmd_set_nvgre_eth_dst_value,
13475                 NULL,
13476         },
13477 };
13478
13479 /** Set L2 encapsulation details */
13480 struct cmd_set_l2_encap_result {
13481         cmdline_fixed_string_t set;
13482         cmdline_fixed_string_t l2_encap;
13483         cmdline_fixed_string_t pos_token;
13484         cmdline_fixed_string_t ip_version;
13485         uint32_t vlan_present:1;
13486         uint16_t tci;
13487         struct rte_ether_addr eth_src;
13488         struct rte_ether_addr eth_dst;
13489 };
13490
13491 static cmdline_parse_token_string_t cmd_set_l2_encap_set =
13492         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13493 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13494         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13495 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13496         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13497                                  "l2_encap-with-vlan");
13498 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13499         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13500                                  "ip-version");
13501 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13502         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13503                                  "ipv4#ipv6");
13504 static cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13505         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13506                                  "vlan-tci");
13507 static cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13508         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13509 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13510         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13511                                  "eth-src");
13512 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13513         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13514 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13515         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13516                                  "eth-dst");
13517 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13518         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13519
13520 static void cmd_set_l2_encap_parsed(void *parsed_result,
13521         __rte_unused struct cmdline *cl,
13522         __rte_unused void *data)
13523 {
13524         struct cmd_set_l2_encap_result *res = parsed_result;
13525
13526         if (strcmp(res->l2_encap, "l2_encap") == 0)
13527                 l2_encap_conf.select_vlan = 0;
13528         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13529                 l2_encap_conf.select_vlan = 1;
13530         if (strcmp(res->ip_version, "ipv4") == 0)
13531                 l2_encap_conf.select_ipv4 = 1;
13532         else if (strcmp(res->ip_version, "ipv6") == 0)
13533                 l2_encap_conf.select_ipv4 = 0;
13534         else
13535                 return;
13536         if (l2_encap_conf.select_vlan)
13537                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13538         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13539                    RTE_ETHER_ADDR_LEN);
13540         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13541                    RTE_ETHER_ADDR_LEN);
13542 }
13543
13544 static cmdline_parse_inst_t cmd_set_l2_encap = {
13545         .f = cmd_set_l2_encap_parsed,
13546         .data = NULL,
13547         .help_str = "set l2_encap ip-version ipv4|ipv6"
13548                 " eth-src <eth-src> eth-dst <eth-dst>",
13549         .tokens = {
13550                 (void *)&cmd_set_l2_encap_set,
13551                 (void *)&cmd_set_l2_encap_l2_encap,
13552                 (void *)&cmd_set_l2_encap_ip_version,
13553                 (void *)&cmd_set_l2_encap_ip_version_value,
13554                 (void *)&cmd_set_l2_encap_eth_src,
13555                 (void *)&cmd_set_l2_encap_eth_src_value,
13556                 (void *)&cmd_set_l2_encap_eth_dst,
13557                 (void *)&cmd_set_l2_encap_eth_dst_value,
13558                 NULL,
13559         },
13560 };
13561
13562 static cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13563         .f = cmd_set_l2_encap_parsed,
13564         .data = NULL,
13565         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13566                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13567         .tokens = {
13568                 (void *)&cmd_set_l2_encap_set,
13569                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13570                 (void *)&cmd_set_l2_encap_ip_version,
13571                 (void *)&cmd_set_l2_encap_ip_version_value,
13572                 (void *)&cmd_set_l2_encap_vlan,
13573                 (void *)&cmd_set_l2_encap_vlan_value,
13574                 (void *)&cmd_set_l2_encap_eth_src,
13575                 (void *)&cmd_set_l2_encap_eth_src_value,
13576                 (void *)&cmd_set_l2_encap_eth_dst,
13577                 (void *)&cmd_set_l2_encap_eth_dst_value,
13578                 NULL,
13579         },
13580 };
13581
13582 /** Set L2 decapsulation details */
13583 struct cmd_set_l2_decap_result {
13584         cmdline_fixed_string_t set;
13585         cmdline_fixed_string_t l2_decap;
13586         cmdline_fixed_string_t pos_token;
13587         uint32_t vlan_present:1;
13588 };
13589
13590 static cmdline_parse_token_string_t cmd_set_l2_decap_set =
13591         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13592 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13593         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13594                                  "l2_decap");
13595 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13596         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13597                                  "l2_decap-with-vlan");
13598
13599 static void cmd_set_l2_decap_parsed(void *parsed_result,
13600         __rte_unused struct cmdline *cl,
13601         __rte_unused void *data)
13602 {
13603         struct cmd_set_l2_decap_result *res = parsed_result;
13604
13605         if (strcmp(res->l2_decap, "l2_decap") == 0)
13606                 l2_decap_conf.select_vlan = 0;
13607         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13608                 l2_decap_conf.select_vlan = 1;
13609 }
13610
13611 static cmdline_parse_inst_t cmd_set_l2_decap = {
13612         .f = cmd_set_l2_decap_parsed,
13613         .data = NULL,
13614         .help_str = "set l2_decap",
13615         .tokens = {
13616                 (void *)&cmd_set_l2_decap_set,
13617                 (void *)&cmd_set_l2_decap_l2_decap,
13618                 NULL,
13619         },
13620 };
13621
13622 static cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13623         .f = cmd_set_l2_decap_parsed,
13624         .data = NULL,
13625         .help_str = "set l2_decap-with-vlan",
13626         .tokens = {
13627                 (void *)&cmd_set_l2_decap_set,
13628                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13629                 NULL,
13630         },
13631 };
13632
13633 /** Set MPLSoGRE encapsulation details */
13634 struct cmd_set_mplsogre_encap_result {
13635         cmdline_fixed_string_t set;
13636         cmdline_fixed_string_t mplsogre;
13637         cmdline_fixed_string_t pos_token;
13638         cmdline_fixed_string_t ip_version;
13639         uint32_t vlan_present:1;
13640         uint32_t label;
13641         cmdline_ipaddr_t ip_src;
13642         cmdline_ipaddr_t ip_dst;
13643         uint16_t tci;
13644         struct rte_ether_addr eth_src;
13645         struct rte_ether_addr eth_dst;
13646 };
13647
13648 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13649         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13650                                  "set");
13651 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13652         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13653                                  "mplsogre_encap");
13654 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13655         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13656                                  mplsogre, "mplsogre_encap-with-vlan");
13657 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13658         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13659                                  pos_token, "ip-version");
13660 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13661         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13662                                  ip_version, "ipv4#ipv6");
13663 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13664         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13665                                  pos_token, "label");
13666 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13667         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13668                               RTE_UINT32);
13669 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13670         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13671                                  pos_token, "ip-src");
13672 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13673         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13674 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13675         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13676                                  pos_token, "ip-dst");
13677 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13678         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13679 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13680         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13681                                  pos_token, "vlan-tci");
13682 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13683         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13684                               RTE_UINT16);
13685 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13686         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13687                                  pos_token, "eth-src");
13688 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13689         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13690                                     eth_src);
13691 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13692         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13693                                  pos_token, "eth-dst");
13694 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13695         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13696                                     eth_dst);
13697
13698 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13699         __rte_unused struct cmdline *cl,
13700         __rte_unused void *data)
13701 {
13702         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13703         union {
13704                 uint32_t mplsogre_label;
13705                 uint8_t label[4];
13706         } id = {
13707                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13708         };
13709
13710         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13711                 mplsogre_encap_conf.select_vlan = 0;
13712         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13713                 mplsogre_encap_conf.select_vlan = 1;
13714         if (strcmp(res->ip_version, "ipv4") == 0)
13715                 mplsogre_encap_conf.select_ipv4 = 1;
13716         else if (strcmp(res->ip_version, "ipv6") == 0)
13717                 mplsogre_encap_conf.select_ipv4 = 0;
13718         else
13719                 return;
13720         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13721         if (mplsogre_encap_conf.select_ipv4) {
13722                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13723                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13724         } else {
13725                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13726                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13727         }
13728         if (mplsogre_encap_conf.select_vlan)
13729                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13730         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13731                    RTE_ETHER_ADDR_LEN);
13732         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13733                    RTE_ETHER_ADDR_LEN);
13734 }
13735
13736 static cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13737         .f = cmd_set_mplsogre_encap_parsed,
13738         .data = NULL,
13739         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13740                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13741                 " eth-dst <eth-dst>",
13742         .tokens = {
13743                 (void *)&cmd_set_mplsogre_encap_set,
13744                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13745                 (void *)&cmd_set_mplsogre_encap_ip_version,
13746                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13747                 (void *)&cmd_set_mplsogre_encap_label,
13748                 (void *)&cmd_set_mplsogre_encap_label_value,
13749                 (void *)&cmd_set_mplsogre_encap_ip_src,
13750                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13751                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13752                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13753                 (void *)&cmd_set_mplsogre_encap_eth_src,
13754                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13755                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13756                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13757                 NULL,
13758         },
13759 };
13760
13761 static cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13762         .f = cmd_set_mplsogre_encap_parsed,
13763         .data = NULL,
13764         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13765                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13766                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13767         .tokens = {
13768                 (void *)&cmd_set_mplsogre_encap_set,
13769                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13770                 (void *)&cmd_set_mplsogre_encap_ip_version,
13771                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13772                 (void *)&cmd_set_mplsogre_encap_label,
13773                 (void *)&cmd_set_mplsogre_encap_label_value,
13774                 (void *)&cmd_set_mplsogre_encap_ip_src,
13775                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13776                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13777                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13778                 (void *)&cmd_set_mplsogre_encap_vlan,
13779                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13780                 (void *)&cmd_set_mplsogre_encap_eth_src,
13781                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13782                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13783                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13784                 NULL,
13785         },
13786 };
13787
13788 /** Set MPLSoGRE decapsulation details */
13789 struct cmd_set_mplsogre_decap_result {
13790         cmdline_fixed_string_t set;
13791         cmdline_fixed_string_t mplsogre;
13792         cmdline_fixed_string_t pos_token;
13793         cmdline_fixed_string_t ip_version;
13794         uint32_t vlan_present:1;
13795 };
13796
13797 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13798         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13799                                  "set");
13800 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13801         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13802                                  "mplsogre_decap");
13803 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13804         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13805                                  mplsogre, "mplsogre_decap-with-vlan");
13806 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13807         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13808                                  pos_token, "ip-version");
13809 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13810         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13811                                  ip_version, "ipv4#ipv6");
13812
13813 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13814         __rte_unused struct cmdline *cl,
13815         __rte_unused void *data)
13816 {
13817         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13818
13819         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13820                 mplsogre_decap_conf.select_vlan = 0;
13821         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13822                 mplsogre_decap_conf.select_vlan = 1;
13823         if (strcmp(res->ip_version, "ipv4") == 0)
13824                 mplsogre_decap_conf.select_ipv4 = 1;
13825         else if (strcmp(res->ip_version, "ipv6") == 0)
13826                 mplsogre_decap_conf.select_ipv4 = 0;
13827 }
13828
13829 static cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13830         .f = cmd_set_mplsogre_decap_parsed,
13831         .data = NULL,
13832         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13833         .tokens = {
13834                 (void *)&cmd_set_mplsogre_decap_set,
13835                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13836                 (void *)&cmd_set_mplsogre_decap_ip_version,
13837                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13838                 NULL,
13839         },
13840 };
13841
13842 static cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13843         .f = cmd_set_mplsogre_decap_parsed,
13844         .data = NULL,
13845         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13846         .tokens = {
13847                 (void *)&cmd_set_mplsogre_decap_set,
13848                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13849                 (void *)&cmd_set_mplsogre_decap_ip_version,
13850                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13851                 NULL,
13852         },
13853 };
13854
13855 /** Set MPLSoUDP encapsulation details */
13856 struct cmd_set_mplsoudp_encap_result {
13857         cmdline_fixed_string_t set;
13858         cmdline_fixed_string_t mplsoudp;
13859         cmdline_fixed_string_t pos_token;
13860         cmdline_fixed_string_t ip_version;
13861         uint32_t vlan_present:1;
13862         uint32_t label;
13863         uint16_t udp_src;
13864         uint16_t udp_dst;
13865         cmdline_ipaddr_t ip_src;
13866         cmdline_ipaddr_t ip_dst;
13867         uint16_t tci;
13868         struct rte_ether_addr eth_src;
13869         struct rte_ether_addr eth_dst;
13870 };
13871
13872 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13873         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13874                                  "set");
13875 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13876         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13877                                  "mplsoudp_encap");
13878 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13879         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13880                                  mplsoudp, "mplsoudp_encap-with-vlan");
13881 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13882         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13883                                  pos_token, "ip-version");
13884 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13885         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13886                                  ip_version, "ipv4#ipv6");
13887 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13888         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13889                                  pos_token, "label");
13890 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13891         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13892                               RTE_UINT32);
13893 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13894         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13895                                  pos_token, "udp-src");
13896 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13897         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13898                               RTE_UINT16);
13899 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13900         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13901                                  pos_token, "udp-dst");
13902 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13903         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13904                               RTE_UINT16);
13905 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13906         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13907                                  pos_token, "ip-src");
13908 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13909         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13910 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13911         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13912                                  pos_token, "ip-dst");
13913 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13914         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13915 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13916         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13917                                  pos_token, "vlan-tci");
13918 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13919         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13920                               RTE_UINT16);
13921 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13922         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13923                                  pos_token, "eth-src");
13924 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13925         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13926                                     eth_src);
13927 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13928         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13929                                  pos_token, "eth-dst");
13930 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13931         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13932                                     eth_dst);
13933
13934 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13935         __rte_unused struct cmdline *cl,
13936         __rte_unused void *data)
13937 {
13938         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13939         union {
13940                 uint32_t mplsoudp_label;
13941                 uint8_t label[4];
13942         } id = {
13943                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13944         };
13945
13946         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13947                 mplsoudp_encap_conf.select_vlan = 0;
13948         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13949                 mplsoudp_encap_conf.select_vlan = 1;
13950         if (strcmp(res->ip_version, "ipv4") == 0)
13951                 mplsoudp_encap_conf.select_ipv4 = 1;
13952         else if (strcmp(res->ip_version, "ipv6") == 0)
13953                 mplsoudp_encap_conf.select_ipv4 = 0;
13954         else
13955                 return;
13956         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13957         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13958         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13959         if (mplsoudp_encap_conf.select_ipv4) {
13960                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13961                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13962         } else {
13963                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13964                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13965         }
13966         if (mplsoudp_encap_conf.select_vlan)
13967                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13968         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13969                    RTE_ETHER_ADDR_LEN);
13970         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13971                    RTE_ETHER_ADDR_LEN);
13972 }
13973
13974 static cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13975         .f = cmd_set_mplsoudp_encap_parsed,
13976         .data = NULL,
13977         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13978                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13979                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13980         .tokens = {
13981                 (void *)&cmd_set_mplsoudp_encap_set,
13982                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13983                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13984                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13985                 (void *)&cmd_set_mplsoudp_encap_label,
13986                 (void *)&cmd_set_mplsoudp_encap_label_value,
13987                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13988                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13989                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13990                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13991                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13992                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13993                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13994                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13995                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13996                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13997                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13998                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13999                 NULL,
14000         },
14001 };
14002
14003 static cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
14004         .f = cmd_set_mplsoudp_encap_parsed,
14005         .data = NULL,
14006         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
14007                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
14008                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14009                 " eth-src <eth-src> eth-dst <eth-dst>",
14010         .tokens = {
14011                 (void *)&cmd_set_mplsoudp_encap_set,
14012                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
14013                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14014                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14015                 (void *)&cmd_set_mplsoudp_encap_label,
14016                 (void *)&cmd_set_mplsoudp_encap_label_value,
14017                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14018                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14019                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14020                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14021                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14022                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14023                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14024                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14025                 (void *)&cmd_set_mplsoudp_encap_vlan,
14026                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
14027                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14028                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14029                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14030                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14031                 NULL,
14032         },
14033 };
14034
14035 /** Set MPLSoUDP decapsulation details */
14036 struct cmd_set_mplsoudp_decap_result {
14037         cmdline_fixed_string_t set;
14038         cmdline_fixed_string_t mplsoudp;
14039         cmdline_fixed_string_t pos_token;
14040         cmdline_fixed_string_t ip_version;
14041         uint32_t vlan_present:1;
14042 };
14043
14044 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14045         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14046                                  "set");
14047 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14048         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14049                                  "mplsoudp_decap");
14050 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14051         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14052                                  mplsoudp, "mplsoudp_decap-with-vlan");
14053 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14054         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14055                                  pos_token, "ip-version");
14056 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14057         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14058                                  ip_version, "ipv4#ipv6");
14059
14060 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14061         __rte_unused struct cmdline *cl,
14062         __rte_unused void *data)
14063 {
14064         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14065
14066         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14067                 mplsoudp_decap_conf.select_vlan = 0;
14068         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14069                 mplsoudp_decap_conf.select_vlan = 1;
14070         if (strcmp(res->ip_version, "ipv4") == 0)
14071                 mplsoudp_decap_conf.select_ipv4 = 1;
14072         else if (strcmp(res->ip_version, "ipv6") == 0)
14073                 mplsoudp_decap_conf.select_ipv4 = 0;
14074 }
14075
14076 static cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14077         .f = cmd_set_mplsoudp_decap_parsed,
14078         .data = NULL,
14079         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14080         .tokens = {
14081                 (void *)&cmd_set_mplsoudp_decap_set,
14082                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14083                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14084                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14085                 NULL,
14086         },
14087 };
14088
14089 static cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14090         .f = cmd_set_mplsoudp_decap_parsed,
14091         .data = NULL,
14092         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14093         .tokens = {
14094                 (void *)&cmd_set_mplsoudp_decap_set,
14095                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14096                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14097                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14098                 NULL,
14099         },
14100 };
14101
14102 /** Set connection tracking object common details */
14103 struct cmd_set_conntrack_common_result {
14104         cmdline_fixed_string_t set;
14105         cmdline_fixed_string_t conntrack;
14106         cmdline_fixed_string_t common;
14107         cmdline_fixed_string_t peer;
14108         cmdline_fixed_string_t is_orig;
14109         cmdline_fixed_string_t enable;
14110         cmdline_fixed_string_t live;
14111         cmdline_fixed_string_t sack;
14112         cmdline_fixed_string_t cack;
14113         cmdline_fixed_string_t last_dir;
14114         cmdline_fixed_string_t liberal;
14115         cmdline_fixed_string_t state;
14116         cmdline_fixed_string_t max_ack_win;
14117         cmdline_fixed_string_t retrans;
14118         cmdline_fixed_string_t last_win;
14119         cmdline_fixed_string_t last_seq;
14120         cmdline_fixed_string_t last_ack;
14121         cmdline_fixed_string_t last_end;
14122         cmdline_fixed_string_t last_index;
14123         uint8_t stat;
14124         uint8_t factor;
14125         uint16_t peer_port;
14126         uint32_t is_original;
14127         uint32_t en;
14128         uint32_t is_live;
14129         uint32_t s_ack;
14130         uint32_t c_ack;
14131         uint32_t ld;
14132         uint32_t lb;
14133         uint8_t re_num;
14134         uint8_t li;
14135         uint16_t lw;
14136         uint32_t ls;
14137         uint32_t la;
14138         uint32_t le;
14139 };
14140
14141 static cmdline_parse_token_string_t cmd_set_conntrack_set =
14142         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14143                                  set, "set");
14144 static cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14145         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14146                                  conntrack, "conntrack");
14147 static cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14148         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14149                                  common, "com");
14150 static cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14151         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14152                                  peer, "peer");
14153 static cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14154         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14155                               peer_port, RTE_UINT16);
14156 static cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14157         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14158                                  is_orig, "is_orig");
14159 static cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14160         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14161                               is_original, RTE_UINT32);
14162 static cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14163         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14164                                  enable, "enable");
14165 static cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14166         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14167                               en, RTE_UINT32);
14168 static cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14169         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14170                                  live, "live");
14171 static cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14172         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14173                               is_live, RTE_UINT32);
14174 static cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14175         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14176                                  sack, "sack");
14177 static cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14178         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14179                               s_ack, RTE_UINT32);
14180 static cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14181         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14182                                  cack, "cack");
14183 static cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14184         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14185                               c_ack, RTE_UINT32);
14186 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14187         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14188                                  last_dir, "last_dir");
14189 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14190         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14191                               ld, RTE_UINT32);
14192 static cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14193         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14194                                  liberal, "liberal");
14195 static cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14196         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14197                               lb, RTE_UINT32);
14198 static cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14199         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14200                                  state, "state");
14201 static cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14202         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14203                               stat, RTE_UINT8);
14204 static cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14205         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14206                                  max_ack_win, "max_ack_win");
14207 static cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14208         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14209                               factor, RTE_UINT8);
14210 static cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14211         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14212                                  retrans, "r_lim");
14213 static cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14214         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14215                               re_num, RTE_UINT8);
14216 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14217         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14218                                  last_win, "last_win");
14219 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14220         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14221                               lw, RTE_UINT16);
14222 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14223         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14224                                  last_seq, "last_seq");
14225 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14226         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14227                               ls, RTE_UINT32);
14228 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14229         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14230                                  last_ack, "last_ack");
14231 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14232         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14233                               la, RTE_UINT32);
14234 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14235         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14236                                  last_end, "last_end");
14237 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14238         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14239                               le, RTE_UINT32);
14240 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14241         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14242                                  last_index, "last_index");
14243 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14244         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14245                               li, RTE_UINT8);
14246
14247 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14248         __rte_unused struct cmdline *cl,
14249         __rte_unused void *data)
14250 {
14251         struct cmd_set_conntrack_common_result *res = parsed_result;
14252
14253         /* No need to swap to big endian. */
14254         conntrack_context.peer_port = res->peer_port;
14255         conntrack_context.is_original_dir = res->is_original;
14256         conntrack_context.enable = res->en;
14257         conntrack_context.live_connection = res->is_live;
14258         conntrack_context.selective_ack = res->s_ack;
14259         conntrack_context.challenge_ack_passed = res->c_ack;
14260         conntrack_context.last_direction = res->ld;
14261         conntrack_context.liberal_mode = res->lb;
14262         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14263         conntrack_context.max_ack_window = res->factor;
14264         conntrack_context.retransmission_limit = res->re_num;
14265         conntrack_context.last_window = res->lw;
14266         conntrack_context.last_index =
14267                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14268         conntrack_context.last_seq = res->ls;
14269         conntrack_context.last_ack = res->la;
14270         conntrack_context.last_end = res->le;
14271 }
14272
14273 static cmdline_parse_inst_t cmd_set_conntrack_common = {
14274         .f = cmd_set_conntrack_common_parsed,
14275         .data = NULL,
14276         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14277                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14278                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14279                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14280                 " last_index <flag>",
14281         .tokens = {
14282                 (void *)&cmd_set_conntrack_set,
14283                 (void *)&cmd_set_conntrack_conntrack,
14284                 (void *)&cmd_set_conntrack_common_com,
14285                 (void *)&cmd_set_conntrack_common_peer,
14286                 (void *)&cmd_set_conntrack_common_peer_value,
14287                 (void *)&cmd_set_conntrack_common_is_orig,
14288                 (void *)&cmd_set_conntrack_common_is_orig_value,
14289                 (void *)&cmd_set_conntrack_common_enable,
14290                 (void *)&cmd_set_conntrack_common_enable_value,
14291                 (void *)&cmd_set_conntrack_common_live,
14292                 (void *)&cmd_set_conntrack_common_live_value,
14293                 (void *)&cmd_set_conntrack_common_sack,
14294                 (void *)&cmd_set_conntrack_common_sack_value,
14295                 (void *)&cmd_set_conntrack_common_cack,
14296                 (void *)&cmd_set_conntrack_common_cack_value,
14297                 (void *)&cmd_set_conntrack_common_last_dir,
14298                 (void *)&cmd_set_conntrack_common_last_dir_value,
14299                 (void *)&cmd_set_conntrack_common_liberal,
14300                 (void *)&cmd_set_conntrack_common_liberal_value,
14301                 (void *)&cmd_set_conntrack_common_state,
14302                 (void *)&cmd_set_conntrack_common_state_value,
14303                 (void *)&cmd_set_conntrack_common_max_ackwin,
14304                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14305                 (void *)&cmd_set_conntrack_common_retrans,
14306                 (void *)&cmd_set_conntrack_common_retrans_value,
14307                 (void *)&cmd_set_conntrack_common_last_win,
14308                 (void *)&cmd_set_conntrack_common_last_win_value,
14309                 (void *)&cmd_set_conntrack_common_last_seq,
14310                 (void *)&cmd_set_conntrack_common_last_seq_value,
14311                 (void *)&cmd_set_conntrack_common_last_ack,
14312                 (void *)&cmd_set_conntrack_common_last_ack_value,
14313                 (void *)&cmd_set_conntrack_common_last_end,
14314                 (void *)&cmd_set_conntrack_common_last_end_value,
14315                 (void *)&cmd_set_conntrack_common_last_index,
14316                 (void *)&cmd_set_conntrack_common_last_index_value,
14317                 NULL,
14318         },
14319 };
14320
14321 /** Set connection tracking object both directions' details */
14322 struct cmd_set_conntrack_dir_result {
14323         cmdline_fixed_string_t set;
14324         cmdline_fixed_string_t conntrack;
14325         cmdline_fixed_string_t dir;
14326         cmdline_fixed_string_t scale;
14327         cmdline_fixed_string_t fin;
14328         cmdline_fixed_string_t ack_seen;
14329         cmdline_fixed_string_t unack;
14330         cmdline_fixed_string_t sent_end;
14331         cmdline_fixed_string_t reply_end;
14332         cmdline_fixed_string_t max_win;
14333         cmdline_fixed_string_t max_ack;
14334         uint32_t factor;
14335         uint32_t f;
14336         uint32_t as;
14337         uint32_t un;
14338         uint32_t se;
14339         uint32_t re;
14340         uint32_t mw;
14341         uint32_t ma;
14342 };
14343
14344 static cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14345         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14346                                  dir, "orig#rply");
14347 static cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14348         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14349                                  scale, "scale");
14350 static cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14351         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14352                               factor, RTE_UINT32);
14353 static cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14354         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14355                                  fin, "fin");
14356 static cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14357         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14358                               f, RTE_UINT32);
14359 static cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14360         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14361                                  ack_seen, "acked");
14362 static cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14363         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14364                               as, RTE_UINT32);
14365 static cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14366         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14367                                  unack, "unack_data");
14368 static cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14369         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14370                               un, RTE_UINT32);
14371 static cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14372         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14373                                  sent_end, "sent_end");
14374 static cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14375         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14376                               se, RTE_UINT32);
14377 static cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14378         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14379                                  reply_end, "reply_end");
14380 static cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14381         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14382                               re, RTE_UINT32);
14383 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14384         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14385                                  max_win, "max_win");
14386 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14387         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14388                               mw, RTE_UINT32);
14389 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14390         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14391                                  max_ack, "max_ack");
14392 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14393         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14394                               ma, RTE_UINT32);
14395
14396 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14397         __rte_unused struct cmdline *cl,
14398         __rte_unused void *data)
14399 {
14400         struct cmd_set_conntrack_dir_result *res = parsed_result;
14401         struct rte_flow_tcp_dir_param *dir = NULL;
14402
14403         if (strcmp(res->dir, "orig") == 0)
14404                 dir = &conntrack_context.original_dir;
14405         else if (strcmp(res->dir, "rply") == 0)
14406                 dir = &conntrack_context.reply_dir;
14407         else
14408                 return;
14409         dir->scale = res->factor;
14410         dir->close_initiated = res->f;
14411         dir->last_ack_seen = res->as;
14412         dir->data_unacked = res->un;
14413         dir->sent_end = res->se;
14414         dir->reply_end = res->re;
14415         dir->max_ack = res->ma;
14416         dir->max_win = res->mw;
14417 }
14418
14419 static cmdline_parse_inst_t cmd_set_conntrack_dir = {
14420         .f = cmd_set_conntrack_dir_parsed,
14421         .data = NULL,
14422         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14423                     " acked <seen> unack_data <unack> sent_end <sent>"
14424                     " reply_end <reply> max_win <win> max_ack <ack>",
14425         .tokens = {
14426                 (void *)&cmd_set_conntrack_set,
14427                 (void *)&cmd_set_conntrack_conntrack,
14428                 (void *)&cmd_set_conntrack_dir_dir,
14429                 (void *)&cmd_set_conntrack_dir_scale,
14430                 (void *)&cmd_set_conntrack_dir_scale_value,
14431                 (void *)&cmd_set_conntrack_dir_fin,
14432                 (void *)&cmd_set_conntrack_dir_fin_value,
14433                 (void *)&cmd_set_conntrack_dir_ack,
14434                 (void *)&cmd_set_conntrack_dir_ack_value,
14435                 (void *)&cmd_set_conntrack_dir_unack_data,
14436                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14437                 (void *)&cmd_set_conntrack_dir_sent_end,
14438                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14439                 (void *)&cmd_set_conntrack_dir_reply_end,
14440                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14441                 (void *)&cmd_set_conntrack_dir_max_win,
14442                 (void *)&cmd_set_conntrack_dir_max_win_value,
14443                 (void *)&cmd_set_conntrack_dir_max_ack,
14444                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14445                 NULL,
14446         },
14447 };
14448
14449 /* Strict link priority scheduling mode setting */
14450 static void
14451 cmd_strict_link_prio_parsed(
14452         void *parsed_result,
14453         __rte_unused struct cmdline *cl,
14454         __rte_unused void *data)
14455 {
14456         struct cmd_vf_tc_bw_result *res = parsed_result;
14457         int ret = -ENOTSUP;
14458
14459         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14460                 return;
14461
14462 #ifdef RTE_NET_I40E
14463         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14464 #endif
14465
14466         switch (ret) {
14467         case 0:
14468                 break;
14469         case -EINVAL:
14470                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14471                 break;
14472         case -ENODEV:
14473                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14474                 break;
14475         case -ENOTSUP:
14476                 fprintf(stderr, "function not implemented\n");
14477                 break;
14478         default:
14479                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14480         }
14481 }
14482
14483 static cmdline_parse_inst_t cmd_strict_link_prio = {
14484         .f = cmd_strict_link_prio_parsed,
14485         .data = NULL,
14486         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14487         .tokens = {
14488                 (void *)&cmd_vf_tc_bw_set,
14489                 (void *)&cmd_vf_tc_bw_tx,
14490                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14491                 (void *)&cmd_vf_tc_bw_port_id,
14492                 (void *)&cmd_vf_tc_bw_tc_map,
14493                 NULL,
14494         },
14495 };
14496
14497 /* Load dynamic device personalization*/
14498 struct cmd_ddp_add_result {
14499         cmdline_fixed_string_t ddp;
14500         cmdline_fixed_string_t add;
14501         portid_t port_id;
14502         char filepath[];
14503 };
14504
14505 static cmdline_parse_token_string_t cmd_ddp_add_ddp =
14506         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14507 static cmdline_parse_token_string_t cmd_ddp_add_add =
14508         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14509 static cmdline_parse_token_num_t cmd_ddp_add_port_id =
14510         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14511                 RTE_UINT16);
14512 static cmdline_parse_token_string_t cmd_ddp_add_filepath =
14513         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14514
14515 static void
14516 cmd_ddp_add_parsed(
14517         void *parsed_result,
14518         __rte_unused struct cmdline *cl,
14519         __rte_unused void *data)
14520 {
14521         struct cmd_ddp_add_result *res = parsed_result;
14522         uint8_t *buff;
14523         uint32_t size;
14524         char *filepath;
14525         char *file_fld[2];
14526         int file_num;
14527         int ret = -ENOTSUP;
14528
14529         if (!all_ports_stopped()) {
14530                 fprintf(stderr, "Please stop all ports first\n");
14531                 return;
14532         }
14533
14534         filepath = strdup(res->filepath);
14535         if (filepath == NULL) {
14536                 fprintf(stderr, "Failed to allocate memory\n");
14537                 return;
14538         }
14539         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14540
14541         buff = open_file(file_fld[0], &size);
14542         if (!buff) {
14543                 free((void *)filepath);
14544                 return;
14545         }
14546
14547 #ifdef RTE_NET_I40E
14548         if (ret == -ENOTSUP)
14549                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14550                                                buff, size,
14551                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14552 #endif
14553
14554         if (ret == -EEXIST)
14555                 fprintf(stderr, "Profile has already existed.\n");
14556         else if (ret < 0)
14557                 fprintf(stderr, "Failed to load profile.\n");
14558         else if (file_num == 2)
14559                 save_file(file_fld[1], buff, size);
14560
14561         close_file(buff);
14562         free((void *)filepath);
14563 }
14564
14565 static cmdline_parse_inst_t cmd_ddp_add = {
14566         .f = cmd_ddp_add_parsed,
14567         .data = NULL,
14568         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14569         .tokens = {
14570                 (void *)&cmd_ddp_add_ddp,
14571                 (void *)&cmd_ddp_add_add,
14572                 (void *)&cmd_ddp_add_port_id,
14573                 (void *)&cmd_ddp_add_filepath,
14574                 NULL,
14575         },
14576 };
14577
14578 /* Delete dynamic device personalization*/
14579 struct cmd_ddp_del_result {
14580         cmdline_fixed_string_t ddp;
14581         cmdline_fixed_string_t del;
14582         portid_t port_id;
14583         char filepath[];
14584 };
14585
14586 static cmdline_parse_token_string_t cmd_ddp_del_ddp =
14587         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14588 static cmdline_parse_token_string_t cmd_ddp_del_del =
14589         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14590 static cmdline_parse_token_num_t cmd_ddp_del_port_id =
14591         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14592 static cmdline_parse_token_string_t cmd_ddp_del_filepath =
14593         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14594
14595 static void
14596 cmd_ddp_del_parsed(
14597         void *parsed_result,
14598         __rte_unused struct cmdline *cl,
14599         __rte_unused void *data)
14600 {
14601         struct cmd_ddp_del_result *res = parsed_result;
14602         uint8_t *buff;
14603         uint32_t size;
14604         int ret = -ENOTSUP;
14605
14606         if (!all_ports_stopped()) {
14607                 fprintf(stderr, "Please stop all ports first\n");
14608                 return;
14609         }
14610
14611         buff = open_file(res->filepath, &size);
14612         if (!buff)
14613                 return;
14614
14615 #ifdef RTE_NET_I40E
14616         if (ret == -ENOTSUP)
14617                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14618                                                buff, size,
14619                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14620 #endif
14621
14622         if (ret == -EACCES)
14623                 fprintf(stderr, "Profile does not exist.\n");
14624         else if (ret < 0)
14625                 fprintf(stderr, "Failed to delete profile.\n");
14626
14627         close_file(buff);
14628 }
14629
14630 static cmdline_parse_inst_t cmd_ddp_del = {
14631         .f = cmd_ddp_del_parsed,
14632         .data = NULL,
14633         .help_str = "ddp del <port_id> <backup_profile_path>",
14634         .tokens = {
14635                 (void *)&cmd_ddp_del_ddp,
14636                 (void *)&cmd_ddp_del_del,
14637                 (void *)&cmd_ddp_del_port_id,
14638                 (void *)&cmd_ddp_del_filepath,
14639                 NULL,
14640         },
14641 };
14642
14643 /* Get dynamic device personalization profile info */
14644 struct cmd_ddp_info_result {
14645         cmdline_fixed_string_t ddp;
14646         cmdline_fixed_string_t get;
14647         cmdline_fixed_string_t info;
14648         char filepath[];
14649 };
14650
14651 static cmdline_parse_token_string_t cmd_ddp_info_ddp =
14652         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14653 static cmdline_parse_token_string_t cmd_ddp_info_get =
14654         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14655 static cmdline_parse_token_string_t cmd_ddp_info_info =
14656         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14657 static cmdline_parse_token_string_t cmd_ddp_info_filepath =
14658         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14659
14660 static void
14661 cmd_ddp_info_parsed(
14662         void *parsed_result,
14663         __rte_unused struct cmdline *cl,
14664         __rte_unused void *data)
14665 {
14666         struct cmd_ddp_info_result *res = parsed_result;
14667         uint8_t *pkg;
14668         uint32_t pkg_size;
14669         int ret = -ENOTSUP;
14670 #ifdef RTE_NET_I40E
14671         uint32_t i, j, n;
14672         uint8_t *buff;
14673         uint32_t buff_size = 0;
14674         struct rte_pmd_i40e_profile_info info;
14675         uint32_t dev_num = 0;
14676         struct rte_pmd_i40e_ddp_device_id *devs;
14677         uint32_t proto_num = 0;
14678         struct rte_pmd_i40e_proto_info *proto = NULL;
14679         uint32_t pctype_num = 0;
14680         struct rte_pmd_i40e_ptype_info *pctype;
14681         uint32_t ptype_num = 0;
14682         struct rte_pmd_i40e_ptype_info *ptype;
14683         uint8_t proto_id;
14684
14685 #endif
14686
14687         pkg = open_file(res->filepath, &pkg_size);
14688         if (!pkg)
14689                 return;
14690
14691 #ifdef RTE_NET_I40E
14692         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14693                                 (uint8_t *)&info, sizeof(info),
14694                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14695         if (!ret) {
14696                 printf("Global Track id:       0x%x\n", info.track_id);
14697                 printf("Global Version:        %d.%d.%d.%d\n",
14698                         info.version.major,
14699                         info.version.minor,
14700                         info.version.update,
14701                         info.version.draft);
14702                 printf("Global Package name:   %s\n\n", info.name);
14703         }
14704
14705         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14706                                 (uint8_t *)&info, sizeof(info),
14707                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14708         if (!ret) {
14709                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14710                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14711                         info.version.major,
14712                         info.version.minor,
14713                         info.version.update,
14714                         info.version.draft);
14715                 printf("i40e Profile name:     %s\n\n", info.name);
14716         }
14717
14718         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14719                                 (uint8_t *)&buff_size, sizeof(buff_size),
14720                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14721         if (!ret && buff_size) {
14722                 buff = (uint8_t *)malloc(buff_size);
14723                 if (buff) {
14724                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14725                                                 buff, buff_size,
14726                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14727                         if (!ret)
14728                                 printf("Package Notes:\n%s\n\n", buff);
14729                         free(buff);
14730                 }
14731         }
14732
14733         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14734                                 (uint8_t *)&dev_num, sizeof(dev_num),
14735                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14736         if (!ret && dev_num) {
14737                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14738                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14739                 if (devs) {
14740                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14741                                                 (uint8_t *)devs, buff_size,
14742                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14743                         if (!ret) {
14744                                 printf("List of supported devices:\n");
14745                                 for (i = 0; i < dev_num; i++) {
14746                                         printf("  %04X:%04X %04X:%04X\n",
14747                                                 devs[i].vendor_dev_id >> 16,
14748                                                 devs[i].vendor_dev_id & 0xFFFF,
14749                                                 devs[i].sub_vendor_dev_id >> 16,
14750                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14751                                 }
14752                                 printf("\n");
14753                         }
14754                         free(devs);
14755                 }
14756         }
14757
14758         /* get information about protocols and packet types */
14759         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14760                 (uint8_t *)&proto_num, sizeof(proto_num),
14761                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14762         if (ret || !proto_num)
14763                 goto no_print_return;
14764
14765         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14766         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14767         if (!proto)
14768                 goto no_print_return;
14769
14770         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14771                                         buff_size,
14772                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14773         if (!ret) {
14774                 printf("List of used protocols:\n");
14775                 for (i = 0; i < proto_num; i++)
14776                         printf("  %2u: %s\n", proto[i].proto_id,
14777                                proto[i].name);
14778                 printf("\n");
14779         }
14780         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14781                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14782                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14783         if (ret || !pctype_num)
14784                 goto no_print_pctypes;
14785
14786         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14787         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14788         if (!pctype)
14789                 goto no_print_pctypes;
14790
14791         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14792                                         buff_size,
14793                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14794         if (ret) {
14795                 free(pctype);
14796                 goto no_print_pctypes;
14797         }
14798
14799         printf("List of defined packet classification types:\n");
14800         for (i = 0; i < pctype_num; i++) {
14801                 printf("  %2u:", pctype[i].ptype_id);
14802                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14803                         proto_id = pctype[i].protocols[j];
14804                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14805                                 for (n = 0; n < proto_num; n++) {
14806                                         if (proto[n].proto_id == proto_id) {
14807                                                 printf(" %s", proto[n].name);
14808                                                 break;
14809                                         }
14810                                 }
14811                         }
14812                 }
14813                 printf("\n");
14814         }
14815         printf("\n");
14816         free(pctype);
14817
14818 no_print_pctypes:
14819
14820         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14821                                         sizeof(ptype_num),
14822                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14823         if (ret || !ptype_num)
14824                 goto no_print_return;
14825
14826         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14827         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14828         if (!ptype)
14829                 goto no_print_return;
14830
14831         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14832                                         buff_size,
14833                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14834         if (ret) {
14835                 free(ptype);
14836                 goto no_print_return;
14837         }
14838         printf("List of defined packet types:\n");
14839         for (i = 0; i < ptype_num; i++) {
14840                 printf("  %2u:", ptype[i].ptype_id);
14841                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14842                         proto_id = ptype[i].protocols[j];
14843                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14844                                 for (n = 0; n < proto_num; n++) {
14845                                         if (proto[n].proto_id == proto_id) {
14846                                                 printf(" %s", proto[n].name);
14847                                                 break;
14848                                         }
14849                                 }
14850                         }
14851                 }
14852                 printf("\n");
14853         }
14854         free(ptype);
14855         printf("\n");
14856
14857         ret = 0;
14858 no_print_return:
14859         free(proto);
14860 #endif
14861         if (ret == -ENOTSUP)
14862                 fprintf(stderr, "Function not supported in PMD\n");
14863         close_file(pkg);
14864 }
14865
14866 static cmdline_parse_inst_t cmd_ddp_get_info = {
14867         .f = cmd_ddp_info_parsed,
14868         .data = NULL,
14869         .help_str = "ddp get info <profile_path>",
14870         .tokens = {
14871                 (void *)&cmd_ddp_info_ddp,
14872                 (void *)&cmd_ddp_info_get,
14873                 (void *)&cmd_ddp_info_info,
14874                 (void *)&cmd_ddp_info_filepath,
14875                 NULL,
14876         },
14877 };
14878
14879 /* Get dynamic device personalization profile info list*/
14880 #define PROFILE_INFO_SIZE 48
14881 #define MAX_PROFILE_NUM 16
14882
14883 struct cmd_ddp_get_list_result {
14884         cmdline_fixed_string_t ddp;
14885         cmdline_fixed_string_t get;
14886         cmdline_fixed_string_t list;
14887         portid_t port_id;
14888 };
14889
14890 static cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14891         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14892 static cmdline_parse_token_string_t cmd_ddp_get_list_get =
14893         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14894 static cmdline_parse_token_string_t cmd_ddp_get_list_list =
14895         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14896 static cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14897         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14898                 RTE_UINT16);
14899
14900 static void
14901 cmd_ddp_get_list_parsed(
14902         __rte_unused void *parsed_result,
14903         __rte_unused struct cmdline *cl,
14904         __rte_unused void *data)
14905 {
14906 #ifdef RTE_NET_I40E
14907         struct cmd_ddp_get_list_result *res = parsed_result;
14908         struct rte_pmd_i40e_profile_list *p_list;
14909         struct rte_pmd_i40e_profile_info *p_info;
14910         uint32_t p_num;
14911         uint32_t size;
14912         uint32_t i;
14913 #endif
14914         int ret = -ENOTSUP;
14915
14916 #ifdef RTE_NET_I40E
14917         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14918         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14919         if (!p_list) {
14920                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14921                 return;
14922         }
14923
14924         if (ret == -ENOTSUP)
14925                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14926                                                 (uint8_t *)p_list, size);
14927
14928         if (!ret) {
14929                 p_num = p_list->p_count;
14930                 printf("Profile number is: %d\n\n", p_num);
14931
14932                 for (i = 0; i < p_num; i++) {
14933                         p_info = &p_list->p_info[i];
14934                         printf("Profile %d:\n", i);
14935                         printf("Track id:     0x%x\n", p_info->track_id);
14936                         printf("Version:      %d.%d.%d.%d\n",
14937                                p_info->version.major,
14938                                p_info->version.minor,
14939                                p_info->version.update,
14940                                p_info->version.draft);
14941                         printf("Profile name: %s\n\n", p_info->name);
14942                 }
14943         }
14944
14945         free(p_list);
14946 #endif
14947
14948         if (ret < 0)
14949                 fprintf(stderr, "Failed to get ddp list\n");
14950 }
14951
14952 static cmdline_parse_inst_t cmd_ddp_get_list = {
14953         .f = cmd_ddp_get_list_parsed,
14954         .data = NULL,
14955         .help_str = "ddp get list <port_id>",
14956         .tokens = {
14957                 (void *)&cmd_ddp_get_list_ddp,
14958                 (void *)&cmd_ddp_get_list_get,
14959                 (void *)&cmd_ddp_get_list_list,
14960                 (void *)&cmd_ddp_get_list_port_id,
14961                 NULL,
14962         },
14963 };
14964
14965 /* Configure input set */
14966 struct cmd_cfg_input_set_result {
14967         cmdline_fixed_string_t port;
14968         cmdline_fixed_string_t cfg;
14969         portid_t port_id;
14970         cmdline_fixed_string_t pctype;
14971         uint8_t pctype_id;
14972         cmdline_fixed_string_t inset_type;
14973         cmdline_fixed_string_t opt;
14974         cmdline_fixed_string_t field;
14975         uint8_t field_idx;
14976 };
14977
14978 static void
14979 cmd_cfg_input_set_parsed(
14980         __rte_unused void *parsed_result,
14981         __rte_unused struct cmdline *cl,
14982         __rte_unused void *data)
14983 {
14984 #ifdef RTE_NET_I40E
14985         struct cmd_cfg_input_set_result *res = parsed_result;
14986         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14987         struct rte_pmd_i40e_inset inset;
14988 #endif
14989         int ret = -ENOTSUP;
14990
14991         if (!all_ports_stopped()) {
14992                 fprintf(stderr, "Please stop all ports first\n");
14993                 return;
14994         }
14995
14996 #ifdef RTE_NET_I40E
14997         if (!strcmp(res->inset_type, "hash_inset"))
14998                 inset_type = INSET_HASH;
14999         else if (!strcmp(res->inset_type, "fdir_inset"))
15000                 inset_type = INSET_FDIR;
15001         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15002                 inset_type = INSET_FDIR_FLX;
15003         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15004                                      &inset, inset_type);
15005         if (ret) {
15006                 fprintf(stderr, "Failed to get input set.\n");
15007                 return;
15008         }
15009
15010         if (!strcmp(res->opt, "get")) {
15011                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15012                                                    res->field_idx);
15013                 if (ret)
15014                         printf("Field index %d is enabled.\n", res->field_idx);
15015                 else
15016                         printf("Field index %d is disabled.\n", res->field_idx);
15017                 return;
15018         } else if (!strcmp(res->opt, "set"))
15019                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15020                                                    res->field_idx);
15021         else if (!strcmp(res->opt, "clear"))
15022                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15023                                                      res->field_idx);
15024         if (ret) {
15025                 fprintf(stderr, "Failed to configure input set field.\n");
15026                 return;
15027         }
15028
15029         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15030                                      &inset, inset_type);
15031         if (ret) {
15032                 fprintf(stderr, "Failed to set input set.\n");
15033                 return;
15034         }
15035 #endif
15036
15037         if (ret == -ENOTSUP)
15038                 fprintf(stderr, "Function not supported\n");
15039 }
15040
15041 static cmdline_parse_token_string_t cmd_cfg_input_set_port =
15042         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15043                                  port, "port");
15044 static cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15045         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15046                                  cfg, "config");
15047 static cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15048         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15049                               port_id, RTE_UINT16);
15050 static cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15051         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15052                                  pctype, "pctype");
15053 static cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15054         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15055                               pctype_id, RTE_UINT8);
15056 static cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15057         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15058                                  inset_type,
15059                                  "hash_inset#fdir_inset#fdir_flx_inset");
15060 static cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15061         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15062                                  opt, "get#set#clear");
15063 static cmdline_parse_token_string_t cmd_cfg_input_set_field =
15064         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15065                                  field, "field");
15066 static cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15067         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15068                               field_idx, RTE_UINT8);
15069
15070 static cmdline_parse_inst_t cmd_cfg_input_set = {
15071         .f = cmd_cfg_input_set_parsed,
15072         .data = NULL,
15073         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15074                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15075         .tokens = {
15076                 (void *)&cmd_cfg_input_set_port,
15077                 (void *)&cmd_cfg_input_set_cfg,
15078                 (void *)&cmd_cfg_input_set_port_id,
15079                 (void *)&cmd_cfg_input_set_pctype,
15080                 (void *)&cmd_cfg_input_set_pctype_id,
15081                 (void *)&cmd_cfg_input_set_inset_type,
15082                 (void *)&cmd_cfg_input_set_opt,
15083                 (void *)&cmd_cfg_input_set_field,
15084                 (void *)&cmd_cfg_input_set_field_idx,
15085                 NULL,
15086         },
15087 };
15088
15089 /* Clear input set */
15090 struct cmd_clear_input_set_result {
15091         cmdline_fixed_string_t port;
15092         cmdline_fixed_string_t cfg;
15093         portid_t port_id;
15094         cmdline_fixed_string_t pctype;
15095         uint8_t pctype_id;
15096         cmdline_fixed_string_t inset_type;
15097         cmdline_fixed_string_t clear;
15098         cmdline_fixed_string_t all;
15099 };
15100
15101 static void
15102 cmd_clear_input_set_parsed(
15103         __rte_unused void *parsed_result,
15104         __rte_unused struct cmdline *cl,
15105         __rte_unused void *data)
15106 {
15107 #ifdef RTE_NET_I40E
15108         struct cmd_clear_input_set_result *res = parsed_result;
15109         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15110         struct rte_pmd_i40e_inset inset;
15111 #endif
15112         int ret = -ENOTSUP;
15113
15114         if (!all_ports_stopped()) {
15115                 fprintf(stderr, "Please stop all ports first\n");
15116                 return;
15117         }
15118
15119 #ifdef RTE_NET_I40E
15120         if (!strcmp(res->inset_type, "hash_inset"))
15121                 inset_type = INSET_HASH;
15122         else if (!strcmp(res->inset_type, "fdir_inset"))
15123                 inset_type = INSET_FDIR;
15124         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15125                 inset_type = INSET_FDIR_FLX;
15126
15127         memset(&inset, 0, sizeof(inset));
15128
15129         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15130                                      &inset, inset_type);
15131         if (ret) {
15132                 fprintf(stderr, "Failed to clear input set.\n");
15133                 return;
15134         }
15135
15136 #endif
15137
15138         if (ret == -ENOTSUP)
15139                 fprintf(stderr, "Function not supported\n");
15140 }
15141
15142 static cmdline_parse_token_string_t cmd_clear_input_set_port =
15143         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15144                                  port, "port");
15145 static cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15146         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15147                                  cfg, "config");
15148 static cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15149         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15150                               port_id, RTE_UINT16);
15151 static cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15152         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15153                                  pctype, "pctype");
15154 static cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15155         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15156                               pctype_id, RTE_UINT8);
15157 static cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15158         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15159                                  inset_type,
15160                                  "hash_inset#fdir_inset#fdir_flx_inset");
15161 static cmdline_parse_token_string_t cmd_clear_input_set_clear =
15162         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15163                                  clear, "clear");
15164 static cmdline_parse_token_string_t cmd_clear_input_set_all =
15165         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15166                                  all, "all");
15167
15168 static cmdline_parse_inst_t cmd_clear_input_set = {
15169         .f = cmd_clear_input_set_parsed,
15170         .data = NULL,
15171         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15172                     "fdir_inset|fdir_flx_inset clear all",
15173         .tokens = {
15174                 (void *)&cmd_clear_input_set_port,
15175                 (void *)&cmd_clear_input_set_cfg,
15176                 (void *)&cmd_clear_input_set_port_id,
15177                 (void *)&cmd_clear_input_set_pctype,
15178                 (void *)&cmd_clear_input_set_pctype_id,
15179                 (void *)&cmd_clear_input_set_inset_type,
15180                 (void *)&cmd_clear_input_set_clear,
15181                 (void *)&cmd_clear_input_set_all,
15182                 NULL,
15183         },
15184 };
15185
15186 /* show vf stats */
15187
15188 /* Common result structure for show vf stats */
15189 struct cmd_show_vf_stats_result {
15190         cmdline_fixed_string_t show;
15191         cmdline_fixed_string_t vf;
15192         cmdline_fixed_string_t stats;
15193         portid_t port_id;
15194         uint16_t vf_id;
15195 };
15196
15197 /* Common CLI fields show vf stats*/
15198 static cmdline_parse_token_string_t cmd_show_vf_stats_show =
15199         TOKEN_STRING_INITIALIZER
15200                 (struct cmd_show_vf_stats_result,
15201                  show, "show");
15202 static cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15203         TOKEN_STRING_INITIALIZER
15204                 (struct cmd_show_vf_stats_result,
15205                  vf, "vf");
15206 static cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15207         TOKEN_STRING_INITIALIZER
15208                 (struct cmd_show_vf_stats_result,
15209                  stats, "stats");
15210 static cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15211         TOKEN_NUM_INITIALIZER
15212                 (struct cmd_show_vf_stats_result,
15213                  port_id, RTE_UINT16);
15214 static cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15215         TOKEN_NUM_INITIALIZER
15216                 (struct cmd_show_vf_stats_result,
15217                  vf_id, RTE_UINT16);
15218
15219 static void
15220 cmd_show_vf_stats_parsed(
15221         void *parsed_result,
15222         __rte_unused struct cmdline *cl,
15223         __rte_unused void *data)
15224 {
15225         struct cmd_show_vf_stats_result *res = parsed_result;
15226         struct rte_eth_stats stats;
15227         int ret = -ENOTSUP;
15228         static const char *nic_stats_border = "########################";
15229
15230         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15231                 return;
15232
15233         memset(&stats, 0, sizeof(stats));
15234
15235 #ifdef RTE_NET_I40E
15236         if (ret == -ENOTSUP)
15237                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15238                                                 res->vf_id,
15239                                                 &stats);
15240 #endif
15241 #ifdef RTE_NET_BNXT
15242         if (ret == -ENOTSUP)
15243                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15244                                                 res->vf_id,
15245                                                 &stats);
15246 #endif
15247
15248         switch (ret) {
15249         case 0:
15250                 break;
15251         case -EINVAL:
15252                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15253                 break;
15254         case -ENODEV:
15255                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15256                 break;
15257         case -ENOTSUP:
15258                 fprintf(stderr, "function not implemented\n");
15259                 break;
15260         default:
15261                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15262         }
15263
15264         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15265                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15266
15267         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15268                "%-"PRIu64"\n",
15269                stats.ipackets, stats.imissed, stats.ibytes);
15270         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15271         printf("  RX-nombuf:  %-10"PRIu64"\n",
15272                stats.rx_nombuf);
15273         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15274                "%-"PRIu64"\n",
15275                stats.opackets, stats.oerrors, stats.obytes);
15276
15277         printf("  %s############################%s\n",
15278                                nic_stats_border, nic_stats_border);
15279 }
15280
15281 static cmdline_parse_inst_t cmd_show_vf_stats = {
15282         .f = cmd_show_vf_stats_parsed,
15283         .data = NULL,
15284         .help_str = "show vf stats <port_id> <vf_id>",
15285         .tokens = {
15286                 (void *)&cmd_show_vf_stats_show,
15287                 (void *)&cmd_show_vf_stats_vf,
15288                 (void *)&cmd_show_vf_stats_stats,
15289                 (void *)&cmd_show_vf_stats_port_id,
15290                 (void *)&cmd_show_vf_stats_vf_id,
15291                 NULL,
15292         },
15293 };
15294
15295 /* clear vf stats */
15296
15297 /* Common result structure for clear vf stats */
15298 struct cmd_clear_vf_stats_result {
15299         cmdline_fixed_string_t clear;
15300         cmdline_fixed_string_t vf;
15301         cmdline_fixed_string_t stats;
15302         portid_t port_id;
15303         uint16_t vf_id;
15304 };
15305
15306 /* Common CLI fields clear vf stats*/
15307 static cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15308         TOKEN_STRING_INITIALIZER
15309                 (struct cmd_clear_vf_stats_result,
15310                  clear, "clear");
15311 static cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15312         TOKEN_STRING_INITIALIZER
15313                 (struct cmd_clear_vf_stats_result,
15314                  vf, "vf");
15315 static cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15316         TOKEN_STRING_INITIALIZER
15317                 (struct cmd_clear_vf_stats_result,
15318                  stats, "stats");
15319 static cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15320         TOKEN_NUM_INITIALIZER
15321                 (struct cmd_clear_vf_stats_result,
15322                  port_id, RTE_UINT16);
15323 static cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15324         TOKEN_NUM_INITIALIZER
15325                 (struct cmd_clear_vf_stats_result,
15326                  vf_id, RTE_UINT16);
15327
15328 static void
15329 cmd_clear_vf_stats_parsed(
15330         void *parsed_result,
15331         __rte_unused struct cmdline *cl,
15332         __rte_unused void *data)
15333 {
15334         struct cmd_clear_vf_stats_result *res = parsed_result;
15335         int ret = -ENOTSUP;
15336
15337         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15338                 return;
15339
15340 #ifdef RTE_NET_I40E
15341         if (ret == -ENOTSUP)
15342                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15343                                                   res->vf_id);
15344 #endif
15345 #ifdef RTE_NET_BNXT
15346         if (ret == -ENOTSUP)
15347                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15348                                                   res->vf_id);
15349 #endif
15350
15351         switch (ret) {
15352         case 0:
15353                 break;
15354         case -EINVAL:
15355                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15356                 break;
15357         case -ENODEV:
15358                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15359                 break;
15360         case -ENOTSUP:
15361                 fprintf(stderr, "function not implemented\n");
15362                 break;
15363         default:
15364                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15365         }
15366 }
15367
15368 static cmdline_parse_inst_t cmd_clear_vf_stats = {
15369         .f = cmd_clear_vf_stats_parsed,
15370         .data = NULL,
15371         .help_str = "clear vf stats <port_id> <vf_id>",
15372         .tokens = {
15373                 (void *)&cmd_clear_vf_stats_clear,
15374                 (void *)&cmd_clear_vf_stats_vf,
15375                 (void *)&cmd_clear_vf_stats_stats,
15376                 (void *)&cmd_clear_vf_stats_port_id,
15377                 (void *)&cmd_clear_vf_stats_vf_id,
15378                 NULL,
15379         },
15380 };
15381
15382 /* port config pctype mapping reset */
15383
15384 /* Common result structure for port config pctype mapping reset */
15385 struct cmd_pctype_mapping_reset_result {
15386         cmdline_fixed_string_t port;
15387         cmdline_fixed_string_t config;
15388         portid_t port_id;
15389         cmdline_fixed_string_t pctype;
15390         cmdline_fixed_string_t mapping;
15391         cmdline_fixed_string_t reset;
15392 };
15393
15394 /* Common CLI fields for port config pctype mapping reset*/
15395 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15396         TOKEN_STRING_INITIALIZER
15397                 (struct cmd_pctype_mapping_reset_result,
15398                  port, "port");
15399 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15400         TOKEN_STRING_INITIALIZER
15401                 (struct cmd_pctype_mapping_reset_result,
15402                  config, "config");
15403 static cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15404         TOKEN_NUM_INITIALIZER
15405                 (struct cmd_pctype_mapping_reset_result,
15406                  port_id, RTE_UINT16);
15407 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15408         TOKEN_STRING_INITIALIZER
15409                 (struct cmd_pctype_mapping_reset_result,
15410                  pctype, "pctype");
15411 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15412         TOKEN_STRING_INITIALIZER
15413                 (struct cmd_pctype_mapping_reset_result,
15414                  mapping, "mapping");
15415 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15416         TOKEN_STRING_INITIALIZER
15417                 (struct cmd_pctype_mapping_reset_result,
15418                  reset, "reset");
15419
15420 static void
15421 cmd_pctype_mapping_reset_parsed(
15422         void *parsed_result,
15423         __rte_unused struct cmdline *cl,
15424         __rte_unused void *data)
15425 {
15426         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15427         int ret = -ENOTSUP;
15428
15429         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15430                 return;
15431
15432 #ifdef RTE_NET_I40E
15433         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15434 #endif
15435
15436         switch (ret) {
15437         case 0:
15438                 break;
15439         case -ENODEV:
15440                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15441                 break;
15442         case -ENOTSUP:
15443                 fprintf(stderr, "function not implemented\n");
15444                 break;
15445         default:
15446                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15447         }
15448 }
15449
15450 static cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15451         .f = cmd_pctype_mapping_reset_parsed,
15452         .data = NULL,
15453         .help_str = "port config <port_id> pctype mapping reset",
15454         .tokens = {
15455                 (void *)&cmd_pctype_mapping_reset_port,
15456                 (void *)&cmd_pctype_mapping_reset_config,
15457                 (void *)&cmd_pctype_mapping_reset_port_id,
15458                 (void *)&cmd_pctype_mapping_reset_pctype,
15459                 (void *)&cmd_pctype_mapping_reset_mapping,
15460                 (void *)&cmd_pctype_mapping_reset_reset,
15461                 NULL,
15462         },
15463 };
15464
15465 /* show port pctype mapping */
15466
15467 /* Common result structure for show port pctype mapping */
15468 struct cmd_pctype_mapping_get_result {
15469         cmdline_fixed_string_t show;
15470         cmdline_fixed_string_t port;
15471         portid_t port_id;
15472         cmdline_fixed_string_t pctype;
15473         cmdline_fixed_string_t mapping;
15474 };
15475
15476 /* Common CLI fields for pctype mapping get */
15477 static cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15478         TOKEN_STRING_INITIALIZER
15479                 (struct cmd_pctype_mapping_get_result,
15480                  show, "show");
15481 static cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15482         TOKEN_STRING_INITIALIZER
15483                 (struct cmd_pctype_mapping_get_result,
15484                  port, "port");
15485 static cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15486         TOKEN_NUM_INITIALIZER
15487                 (struct cmd_pctype_mapping_get_result,
15488                  port_id, RTE_UINT16);
15489 static cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15490         TOKEN_STRING_INITIALIZER
15491                 (struct cmd_pctype_mapping_get_result,
15492                  pctype, "pctype");
15493 static cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15494         TOKEN_STRING_INITIALIZER
15495                 (struct cmd_pctype_mapping_get_result,
15496                  mapping, "mapping");
15497
15498 static void
15499 cmd_pctype_mapping_get_parsed(
15500         void *parsed_result,
15501         __rte_unused struct cmdline *cl,
15502         __rte_unused void *data)
15503 {
15504         struct cmd_pctype_mapping_get_result *res = parsed_result;
15505         int ret = -ENOTSUP;
15506 #ifdef RTE_NET_I40E
15507         struct rte_pmd_i40e_flow_type_mapping
15508                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15509         int i, j, first_pctype;
15510 #endif
15511
15512         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15513                 return;
15514
15515 #ifdef RTE_NET_I40E
15516         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15517 #endif
15518
15519         switch (ret) {
15520         case 0:
15521                 break;
15522         case -ENODEV:
15523                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15524                 return;
15525         case -ENOTSUP:
15526                 fprintf(stderr, "function not implemented\n");
15527                 return;
15528         default:
15529                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15530                 return;
15531         }
15532
15533 #ifdef RTE_NET_I40E
15534         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15535                 if (mapping[i].pctype != 0ULL) {
15536                         first_pctype = 1;
15537
15538                         printf("pctype: ");
15539                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15540                                 if (mapping[i].pctype & (1ULL << j)) {
15541                                         printf(first_pctype ?
15542                                                "%02d" : ",%02d", j);
15543                                         first_pctype = 0;
15544                                 }
15545                         }
15546                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15547                 }
15548         }
15549 #endif
15550 }
15551
15552 static cmdline_parse_inst_t cmd_pctype_mapping_get = {
15553         .f = cmd_pctype_mapping_get_parsed,
15554         .data = NULL,
15555         .help_str = "show port <port_id> pctype mapping",
15556         .tokens = {
15557                 (void *)&cmd_pctype_mapping_get_show,
15558                 (void *)&cmd_pctype_mapping_get_port,
15559                 (void *)&cmd_pctype_mapping_get_port_id,
15560                 (void *)&cmd_pctype_mapping_get_pctype,
15561                 (void *)&cmd_pctype_mapping_get_mapping,
15562                 NULL,
15563         },
15564 };
15565
15566 /* port config pctype mapping update */
15567
15568 /* Common result structure for port config pctype mapping update */
15569 struct cmd_pctype_mapping_update_result {
15570         cmdline_fixed_string_t port;
15571         cmdline_fixed_string_t config;
15572         portid_t port_id;
15573         cmdline_fixed_string_t pctype;
15574         cmdline_fixed_string_t mapping;
15575         cmdline_fixed_string_t update;
15576         cmdline_fixed_string_t pctype_list;
15577         uint16_t flow_type;
15578 };
15579
15580 /* Common CLI fields for pctype mapping update*/
15581 static cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15582         TOKEN_STRING_INITIALIZER
15583                 (struct cmd_pctype_mapping_update_result,
15584                  port, "port");
15585 static cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15586         TOKEN_STRING_INITIALIZER
15587                 (struct cmd_pctype_mapping_update_result,
15588                  config, "config");
15589 static cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15590         TOKEN_NUM_INITIALIZER
15591                 (struct cmd_pctype_mapping_update_result,
15592                  port_id, RTE_UINT16);
15593 static cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15594         TOKEN_STRING_INITIALIZER
15595                 (struct cmd_pctype_mapping_update_result,
15596                  pctype, "pctype");
15597 static cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15598         TOKEN_STRING_INITIALIZER
15599                 (struct cmd_pctype_mapping_update_result,
15600                  mapping, "mapping");
15601 static cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15602         TOKEN_STRING_INITIALIZER
15603                 (struct cmd_pctype_mapping_update_result,
15604                  update, "update");
15605 static cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15606         TOKEN_STRING_INITIALIZER
15607                 (struct cmd_pctype_mapping_update_result,
15608                  pctype_list, NULL);
15609 static cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15610         TOKEN_NUM_INITIALIZER
15611                 (struct cmd_pctype_mapping_update_result,
15612                  flow_type, RTE_UINT16);
15613
15614 static void
15615 cmd_pctype_mapping_update_parsed(
15616         void *parsed_result,
15617         __rte_unused struct cmdline *cl,
15618         __rte_unused void *data)
15619 {
15620         struct cmd_pctype_mapping_update_result *res = parsed_result;
15621         int ret = -ENOTSUP;
15622 #ifdef RTE_NET_I40E
15623         struct rte_pmd_i40e_flow_type_mapping mapping;
15624         unsigned int i;
15625         unsigned int nb_item;
15626         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15627 #endif
15628
15629         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15630                 return;
15631
15632 #ifdef RTE_NET_I40E
15633         nb_item = parse_item_list(res->pctype_list, "pctypes",
15634                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15635         mapping.flow_type = res->flow_type;
15636         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15637                 mapping.pctype |= (1ULL << pctype_list[i]);
15638         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15639                                                 &mapping,
15640                                                 1,
15641                                                 0);
15642 #endif
15643
15644         switch (ret) {
15645         case 0:
15646                 break;
15647         case -EINVAL:
15648                 fprintf(stderr, "invalid pctype or flow type\n");
15649                 break;
15650         case -ENODEV:
15651                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15652                 break;
15653         case -ENOTSUP:
15654                 fprintf(stderr, "function not implemented\n");
15655                 break;
15656         default:
15657                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15658         }
15659 }
15660
15661 static cmdline_parse_inst_t cmd_pctype_mapping_update = {
15662         .f = cmd_pctype_mapping_update_parsed,
15663         .data = NULL,
15664         .help_str = "port config <port_id> pctype mapping update"
15665         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15666         .tokens = {
15667                 (void *)&cmd_pctype_mapping_update_port,
15668                 (void *)&cmd_pctype_mapping_update_config,
15669                 (void *)&cmd_pctype_mapping_update_port_id,
15670                 (void *)&cmd_pctype_mapping_update_pctype,
15671                 (void *)&cmd_pctype_mapping_update_mapping,
15672                 (void *)&cmd_pctype_mapping_update_update,
15673                 (void *)&cmd_pctype_mapping_update_pc_type,
15674                 (void *)&cmd_pctype_mapping_update_flow_type,
15675                 NULL,
15676         },
15677 };
15678
15679 /* ptype mapping get */
15680
15681 /* Common result structure for ptype mapping get */
15682 struct cmd_ptype_mapping_get_result {
15683         cmdline_fixed_string_t ptype;
15684         cmdline_fixed_string_t mapping;
15685         cmdline_fixed_string_t get;
15686         portid_t port_id;
15687         uint8_t valid_only;
15688 };
15689
15690 /* Common CLI fields for ptype mapping get */
15691 static cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15692         TOKEN_STRING_INITIALIZER
15693                 (struct cmd_ptype_mapping_get_result,
15694                  ptype, "ptype");
15695 static cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15696         TOKEN_STRING_INITIALIZER
15697                 (struct cmd_ptype_mapping_get_result,
15698                  mapping, "mapping");
15699 static cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15700         TOKEN_STRING_INITIALIZER
15701                 (struct cmd_ptype_mapping_get_result,
15702                  get, "get");
15703 static cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15704         TOKEN_NUM_INITIALIZER
15705                 (struct cmd_ptype_mapping_get_result,
15706                  port_id, RTE_UINT16);
15707 static cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15708         TOKEN_NUM_INITIALIZER
15709                 (struct cmd_ptype_mapping_get_result,
15710                  valid_only, RTE_UINT8);
15711
15712 static void
15713 cmd_ptype_mapping_get_parsed(
15714         void *parsed_result,
15715         __rte_unused struct cmdline *cl,
15716         __rte_unused void *data)
15717 {
15718         struct cmd_ptype_mapping_get_result *res = parsed_result;
15719         int ret = -ENOTSUP;
15720 #ifdef RTE_NET_I40E
15721         int max_ptype_num = 256;
15722         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15723         uint16_t count;
15724         int i;
15725 #endif
15726
15727         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15728                 return;
15729
15730 #ifdef RTE_NET_I40E
15731         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15732                                         mapping,
15733                                         max_ptype_num,
15734                                         &count,
15735                                         res->valid_only);
15736 #endif
15737
15738         switch (ret) {
15739         case 0:
15740                 break;
15741         case -ENODEV:
15742                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15743                 break;
15744         case -ENOTSUP:
15745                 fprintf(stderr, "function not implemented\n");
15746                 break;
15747         default:
15748                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15749         }
15750
15751 #ifdef RTE_NET_I40E
15752         if (!ret) {
15753                 for (i = 0; i < count; i++)
15754                         printf("%3d\t0x%08x\n",
15755                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15756         }
15757 #endif
15758 }
15759
15760 static cmdline_parse_inst_t cmd_ptype_mapping_get = {
15761         .f = cmd_ptype_mapping_get_parsed,
15762         .data = NULL,
15763         .help_str = "ptype mapping get <port_id> <valid_only>",
15764         .tokens = {
15765                 (void *)&cmd_ptype_mapping_get_ptype,
15766                 (void *)&cmd_ptype_mapping_get_mapping,
15767                 (void *)&cmd_ptype_mapping_get_get,
15768                 (void *)&cmd_ptype_mapping_get_port_id,
15769                 (void *)&cmd_ptype_mapping_get_valid_only,
15770                 NULL,
15771         },
15772 };
15773
15774 /* ptype mapping replace */
15775
15776 /* Common result structure for ptype mapping replace */
15777 struct cmd_ptype_mapping_replace_result {
15778         cmdline_fixed_string_t ptype;
15779         cmdline_fixed_string_t mapping;
15780         cmdline_fixed_string_t replace;
15781         portid_t port_id;
15782         uint32_t target;
15783         uint8_t mask;
15784         uint32_t pkt_type;
15785 };
15786
15787 /* Common CLI fields for ptype mapping replace */
15788 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15789         TOKEN_STRING_INITIALIZER
15790                 (struct cmd_ptype_mapping_replace_result,
15791                  ptype, "ptype");
15792 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15793         TOKEN_STRING_INITIALIZER
15794                 (struct cmd_ptype_mapping_replace_result,
15795                  mapping, "mapping");
15796 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15797         TOKEN_STRING_INITIALIZER
15798                 (struct cmd_ptype_mapping_replace_result,
15799                  replace, "replace");
15800 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15801         TOKEN_NUM_INITIALIZER
15802                 (struct cmd_ptype_mapping_replace_result,
15803                  port_id, RTE_UINT16);
15804 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15805         TOKEN_NUM_INITIALIZER
15806                 (struct cmd_ptype_mapping_replace_result,
15807                  target, RTE_UINT32);
15808 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15809         TOKEN_NUM_INITIALIZER
15810                 (struct cmd_ptype_mapping_replace_result,
15811                  mask, RTE_UINT8);
15812 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15813         TOKEN_NUM_INITIALIZER
15814                 (struct cmd_ptype_mapping_replace_result,
15815                  pkt_type, RTE_UINT32);
15816
15817 static void
15818 cmd_ptype_mapping_replace_parsed(
15819         void *parsed_result,
15820         __rte_unused struct cmdline *cl,
15821         __rte_unused void *data)
15822 {
15823         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15824         int ret = -ENOTSUP;
15825
15826         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15827                 return;
15828
15829 #ifdef RTE_NET_I40E
15830         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15831                                         res->target,
15832                                         res->mask,
15833                                         res->pkt_type);
15834 #endif
15835
15836         switch (ret) {
15837         case 0:
15838                 break;
15839         case -EINVAL:
15840                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15841                         res->target, res->pkt_type);
15842                 break;
15843         case -ENODEV:
15844                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15845                 break;
15846         case -ENOTSUP:
15847                 fprintf(stderr, "function not implemented\n");
15848                 break;
15849         default:
15850                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15851         }
15852 }
15853
15854 static cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15855         .f = cmd_ptype_mapping_replace_parsed,
15856         .data = NULL,
15857         .help_str =
15858                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15859         .tokens = {
15860                 (void *)&cmd_ptype_mapping_replace_ptype,
15861                 (void *)&cmd_ptype_mapping_replace_mapping,
15862                 (void *)&cmd_ptype_mapping_replace_replace,
15863                 (void *)&cmd_ptype_mapping_replace_port_id,
15864                 (void *)&cmd_ptype_mapping_replace_target,
15865                 (void *)&cmd_ptype_mapping_replace_mask,
15866                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15867                 NULL,
15868         },
15869 };
15870
15871 /* ptype mapping reset */
15872
15873 /* Common result structure for ptype mapping reset */
15874 struct cmd_ptype_mapping_reset_result {
15875         cmdline_fixed_string_t ptype;
15876         cmdline_fixed_string_t mapping;
15877         cmdline_fixed_string_t reset;
15878         portid_t port_id;
15879 };
15880
15881 /* Common CLI fields for ptype mapping reset*/
15882 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15883         TOKEN_STRING_INITIALIZER
15884                 (struct cmd_ptype_mapping_reset_result,
15885                  ptype, "ptype");
15886 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15887         TOKEN_STRING_INITIALIZER
15888                 (struct cmd_ptype_mapping_reset_result,
15889                  mapping, "mapping");
15890 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15891         TOKEN_STRING_INITIALIZER
15892                 (struct cmd_ptype_mapping_reset_result,
15893                  reset, "reset");
15894 static cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15895         TOKEN_NUM_INITIALIZER
15896                 (struct cmd_ptype_mapping_reset_result,
15897                  port_id, RTE_UINT16);
15898
15899 static void
15900 cmd_ptype_mapping_reset_parsed(
15901         void *parsed_result,
15902         __rte_unused struct cmdline *cl,
15903         __rte_unused void *data)
15904 {
15905         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15906         int ret = -ENOTSUP;
15907
15908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15909                 return;
15910
15911 #ifdef RTE_NET_I40E
15912         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15913 #endif
15914
15915         switch (ret) {
15916         case 0:
15917                 break;
15918         case -ENODEV:
15919                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15920                 break;
15921         case -ENOTSUP:
15922                 fprintf(stderr, "function not implemented\n");
15923                 break;
15924         default:
15925                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15926         }
15927 }
15928
15929 static cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15930         .f = cmd_ptype_mapping_reset_parsed,
15931         .data = NULL,
15932         .help_str = "ptype mapping reset <port_id>",
15933         .tokens = {
15934                 (void *)&cmd_ptype_mapping_reset_ptype,
15935                 (void *)&cmd_ptype_mapping_reset_mapping,
15936                 (void *)&cmd_ptype_mapping_reset_reset,
15937                 (void *)&cmd_ptype_mapping_reset_port_id,
15938                 NULL,
15939         },
15940 };
15941
15942 /* ptype mapping update */
15943
15944 /* Common result structure for ptype mapping update */
15945 struct cmd_ptype_mapping_update_result {
15946         cmdline_fixed_string_t ptype;
15947         cmdline_fixed_string_t mapping;
15948         cmdline_fixed_string_t reset;
15949         portid_t port_id;
15950         uint8_t hw_ptype;
15951         uint32_t sw_ptype;
15952 };
15953
15954 /* Common CLI fields for ptype mapping update*/
15955 static cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15956         TOKEN_STRING_INITIALIZER
15957                 (struct cmd_ptype_mapping_update_result,
15958                  ptype, "ptype");
15959 static cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15960         TOKEN_STRING_INITIALIZER
15961                 (struct cmd_ptype_mapping_update_result,
15962                  mapping, "mapping");
15963 static cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15964         TOKEN_STRING_INITIALIZER
15965                 (struct cmd_ptype_mapping_update_result,
15966                  reset, "update");
15967 static cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15968         TOKEN_NUM_INITIALIZER
15969                 (struct cmd_ptype_mapping_update_result,
15970                  port_id, RTE_UINT16);
15971 static cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15972         TOKEN_NUM_INITIALIZER
15973                 (struct cmd_ptype_mapping_update_result,
15974                  hw_ptype, RTE_UINT8);
15975 static cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15976         TOKEN_NUM_INITIALIZER
15977                 (struct cmd_ptype_mapping_update_result,
15978                  sw_ptype, RTE_UINT32);
15979
15980 static void
15981 cmd_ptype_mapping_update_parsed(
15982         void *parsed_result,
15983         __rte_unused struct cmdline *cl,
15984         __rte_unused void *data)
15985 {
15986         struct cmd_ptype_mapping_update_result *res = parsed_result;
15987         int ret = -ENOTSUP;
15988 #ifdef RTE_NET_I40E
15989         struct rte_pmd_i40e_ptype_mapping mapping;
15990 #endif
15991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15992                 return;
15993
15994 #ifdef RTE_NET_I40E
15995         mapping.hw_ptype = res->hw_ptype;
15996         mapping.sw_ptype = res->sw_ptype;
15997         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15998                                                 &mapping,
15999                                                 1,
16000                                                 0);
16001 #endif
16002
16003         switch (ret) {
16004         case 0:
16005                 break;
16006         case -EINVAL:
16007                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
16008                 break;
16009         case -ENODEV:
16010                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
16011                 break;
16012         case -ENOTSUP:
16013                 fprintf(stderr, "function not implemented\n");
16014                 break;
16015         default:
16016                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
16017         }
16018 }
16019
16020 static cmdline_parse_inst_t cmd_ptype_mapping_update = {
16021         .f = cmd_ptype_mapping_update_parsed,
16022         .data = NULL,
16023         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16024         .tokens = {
16025                 (void *)&cmd_ptype_mapping_update_ptype,
16026                 (void *)&cmd_ptype_mapping_update_mapping,
16027                 (void *)&cmd_ptype_mapping_update_update,
16028                 (void *)&cmd_ptype_mapping_update_port_id,
16029                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16030                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16031                 NULL,
16032         },
16033 };
16034
16035 /* Common result structure for file commands */
16036 struct cmd_cmdfile_result {
16037         cmdline_fixed_string_t load;
16038         cmdline_fixed_string_t filename;
16039 };
16040
16041 /* Common CLI fields for file commands */
16042 static cmdline_parse_token_string_t cmd_load_cmdfile =
16043         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16044 static cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16045         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16046
16047 static void
16048 cmd_load_from_file_parsed(
16049         void *parsed_result,
16050         __rte_unused struct cmdline *cl,
16051         __rte_unused void *data)
16052 {
16053         struct cmd_cmdfile_result *res = parsed_result;
16054
16055         cmdline_read_from_file(res->filename);
16056 }
16057
16058 static cmdline_parse_inst_t cmd_load_from_file = {
16059         .f = cmd_load_from_file_parsed,
16060         .data = NULL,
16061         .help_str = "load <filename>",
16062         .tokens = {
16063                 (void *)&cmd_load_cmdfile,
16064                 (void *)&cmd_load_cmdfile_filename,
16065                 NULL,
16066         },
16067 };
16068
16069 /* Get Rx offloads capabilities */
16070 struct cmd_rx_offload_get_capa_result {
16071         cmdline_fixed_string_t show;
16072         cmdline_fixed_string_t port;
16073         portid_t port_id;
16074         cmdline_fixed_string_t rx_offload;
16075         cmdline_fixed_string_t capabilities;
16076 };
16077
16078 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16079         TOKEN_STRING_INITIALIZER
16080                 (struct cmd_rx_offload_get_capa_result,
16081                  show, "show");
16082 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16083         TOKEN_STRING_INITIALIZER
16084                 (struct cmd_rx_offload_get_capa_result,
16085                  port, "port");
16086 static cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16087         TOKEN_NUM_INITIALIZER
16088                 (struct cmd_rx_offload_get_capa_result,
16089                  port_id, RTE_UINT16);
16090 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16091         TOKEN_STRING_INITIALIZER
16092                 (struct cmd_rx_offload_get_capa_result,
16093                  rx_offload, "rx_offload");
16094 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16095         TOKEN_STRING_INITIALIZER
16096                 (struct cmd_rx_offload_get_capa_result,
16097                  capabilities, "capabilities");
16098
16099 static void
16100 print_rx_offloads(uint64_t offloads)
16101 {
16102         uint64_t single_offload;
16103         int begin;
16104         int end;
16105         int bit;
16106
16107         if (offloads == 0)
16108                 return;
16109
16110         begin = __builtin_ctzll(offloads);
16111         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16112
16113         single_offload = 1ULL << begin;
16114         for (bit = begin; bit < end; bit++) {
16115                 if (offloads & single_offload)
16116                         printf(" %s",
16117                                rte_eth_dev_rx_offload_name(single_offload));
16118                 single_offload <<= 1;
16119         }
16120 }
16121
16122 static void
16123 cmd_rx_offload_get_capa_parsed(
16124         void *parsed_result,
16125         __rte_unused struct cmdline *cl,
16126         __rte_unused void *data)
16127 {
16128         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16129         struct rte_eth_dev_info dev_info;
16130         portid_t port_id = res->port_id;
16131         uint64_t queue_offloads;
16132         uint64_t port_offloads;
16133         int ret;
16134
16135         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16136         if (ret != 0)
16137                 return;
16138
16139         queue_offloads = dev_info.rx_queue_offload_capa;
16140         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16141
16142         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16143         printf("  Per Queue :");
16144         print_rx_offloads(queue_offloads);
16145
16146         printf("\n");
16147         printf("  Per Port  :");
16148         print_rx_offloads(port_offloads);
16149         printf("\n\n");
16150 }
16151
16152 static cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16153         .f = cmd_rx_offload_get_capa_parsed,
16154         .data = NULL,
16155         .help_str = "show port <port_id> rx_offload capabilities",
16156         .tokens = {
16157                 (void *)&cmd_rx_offload_get_capa_show,
16158                 (void *)&cmd_rx_offload_get_capa_port,
16159                 (void *)&cmd_rx_offload_get_capa_port_id,
16160                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16161                 (void *)&cmd_rx_offload_get_capa_capabilities,
16162                 NULL,
16163         }
16164 };
16165
16166 /* Get Rx offloads configuration */
16167 struct cmd_rx_offload_get_configuration_result {
16168         cmdline_fixed_string_t show;
16169         cmdline_fixed_string_t port;
16170         portid_t port_id;
16171         cmdline_fixed_string_t rx_offload;
16172         cmdline_fixed_string_t configuration;
16173 };
16174
16175 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16176         TOKEN_STRING_INITIALIZER
16177                 (struct cmd_rx_offload_get_configuration_result,
16178                  show, "show");
16179 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16180         TOKEN_STRING_INITIALIZER
16181                 (struct cmd_rx_offload_get_configuration_result,
16182                  port, "port");
16183 static cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16184         TOKEN_NUM_INITIALIZER
16185                 (struct cmd_rx_offload_get_configuration_result,
16186                  port_id, RTE_UINT16);
16187 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16188         TOKEN_STRING_INITIALIZER
16189                 (struct cmd_rx_offload_get_configuration_result,
16190                  rx_offload, "rx_offload");
16191 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16192         TOKEN_STRING_INITIALIZER
16193                 (struct cmd_rx_offload_get_configuration_result,
16194                  configuration, "configuration");
16195
16196 static void
16197 cmd_rx_offload_get_configuration_parsed(
16198         void *parsed_result,
16199         __rte_unused struct cmdline *cl,
16200         __rte_unused void *data)
16201 {
16202         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16203         struct rte_eth_dev_info dev_info;
16204         portid_t port_id = res->port_id;
16205         struct rte_port *port = &ports[port_id];
16206         struct rte_eth_conf dev_conf;
16207         uint64_t port_offloads;
16208         uint64_t queue_offloads;
16209         uint16_t nb_rx_queues;
16210         int q;
16211         int ret;
16212
16213         printf("Rx Offloading Configuration of port %d :\n", port_id);
16214
16215         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16216         if (ret != 0)
16217                 return;
16218
16219         port_offloads = dev_conf.rxmode.offloads;
16220         printf("  Port :");
16221         print_rx_offloads(port_offloads);
16222         printf("\n");
16223
16224         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16225         if (ret != 0)
16226                 return;
16227
16228         nb_rx_queues = dev_info.nb_rx_queues;
16229         for (q = 0; q < nb_rx_queues; q++) {
16230                 queue_offloads = port->rxq[q].conf.offloads;
16231                 printf("  Queue[%2d] :", q);
16232                 print_rx_offloads(queue_offloads);
16233                 printf("\n");
16234         }
16235         printf("\n");
16236 }
16237
16238 static cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16239         .f = cmd_rx_offload_get_configuration_parsed,
16240         .data = NULL,
16241         .help_str = "show port <port_id> rx_offload configuration",
16242         .tokens = {
16243                 (void *)&cmd_rx_offload_get_configuration_show,
16244                 (void *)&cmd_rx_offload_get_configuration_port,
16245                 (void *)&cmd_rx_offload_get_configuration_port_id,
16246                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16247                 (void *)&cmd_rx_offload_get_configuration_configuration,
16248                 NULL,
16249         }
16250 };
16251
16252 /* Enable/Disable a per port offloading */
16253 struct cmd_config_per_port_rx_offload_result {
16254         cmdline_fixed_string_t port;
16255         cmdline_fixed_string_t config;
16256         portid_t port_id;
16257         cmdline_fixed_string_t rx_offload;
16258         cmdline_fixed_string_t offload;
16259         cmdline_fixed_string_t on_off;
16260 };
16261
16262 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16263         TOKEN_STRING_INITIALIZER
16264                 (struct cmd_config_per_port_rx_offload_result,
16265                  port, "port");
16266 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16267         TOKEN_STRING_INITIALIZER
16268                 (struct cmd_config_per_port_rx_offload_result,
16269                  config, "config");
16270 static cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16271         TOKEN_NUM_INITIALIZER
16272                 (struct cmd_config_per_port_rx_offload_result,
16273                  port_id, RTE_UINT16);
16274 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16275         TOKEN_STRING_INITIALIZER
16276                 (struct cmd_config_per_port_rx_offload_result,
16277                  rx_offload, "rx_offload");
16278 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16279         TOKEN_STRING_INITIALIZER
16280                 (struct cmd_config_per_port_rx_offload_result,
16281                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16282                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16283                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16284                            "scatter#buffer_split#timestamp#security#"
16285                            "keep_crc#rss_hash");
16286 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16287         TOKEN_STRING_INITIALIZER
16288                 (struct cmd_config_per_port_rx_offload_result,
16289                  on_off, "on#off");
16290
16291 static uint64_t
16292 search_rx_offload(const char *name)
16293 {
16294         uint64_t single_offload;
16295         const char *single_name;
16296         int found = 0;
16297         unsigned int bit;
16298
16299         single_offload = 1;
16300         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16301                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16302                 if (!strcasecmp(single_name, name)) {
16303                         found = 1;
16304                         break;
16305                 }
16306                 single_offload <<= 1;
16307         }
16308
16309         if (found)
16310                 return single_offload;
16311
16312         return 0;
16313 }
16314
16315 static void
16316 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16317                                 __rte_unused struct cmdline *cl,
16318                                 __rte_unused void *data)
16319 {
16320         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16321         portid_t port_id = res->port_id;
16322         struct rte_eth_dev_info dev_info;
16323         struct rte_port *port = &ports[port_id];
16324         uint64_t single_offload;
16325         uint16_t nb_rx_queues;
16326         int q;
16327         int ret;
16328
16329         if (port->port_status != RTE_PORT_STOPPED) {
16330                 fprintf(stderr,
16331                         "Error: Can't config offload when Port %d is not stopped\n",
16332                         port_id);
16333                 return;
16334         }
16335
16336         single_offload = search_rx_offload(res->offload);
16337         if (single_offload == 0) {
16338                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16339                 return;
16340         }
16341
16342         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16343         if (ret != 0)
16344                 return;
16345
16346         nb_rx_queues = dev_info.nb_rx_queues;
16347         if (!strcmp(res->on_off, "on")) {
16348                 port->dev_conf.rxmode.offloads |= single_offload;
16349                 for (q = 0; q < nb_rx_queues; q++)
16350                         port->rxq[q].conf.offloads |= single_offload;
16351         } else {
16352                 port->dev_conf.rxmode.offloads &= ~single_offload;
16353                 for (q = 0; q < nb_rx_queues; q++)
16354                         port->rxq[q].conf.offloads &= ~single_offload;
16355         }
16356
16357         cmd_reconfig_device_queue(port_id, 1, 1);
16358 }
16359
16360 static cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16361         .f = cmd_config_per_port_rx_offload_parsed,
16362         .data = NULL,
16363         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16364                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16365                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16366                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16367                     "keep_crc|rss_hash on|off",
16368         .tokens = {
16369                 (void *)&cmd_config_per_port_rx_offload_result_port,
16370                 (void *)&cmd_config_per_port_rx_offload_result_config,
16371                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16372                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16373                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16374                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16375                 NULL,
16376         }
16377 };
16378
16379 /* Enable/Disable a per queue offloading */
16380 struct cmd_config_per_queue_rx_offload_result {
16381         cmdline_fixed_string_t port;
16382         portid_t port_id;
16383         cmdline_fixed_string_t rxq;
16384         uint16_t queue_id;
16385         cmdline_fixed_string_t rx_offload;
16386         cmdline_fixed_string_t offload;
16387         cmdline_fixed_string_t on_off;
16388 };
16389
16390 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16391         TOKEN_STRING_INITIALIZER
16392                 (struct cmd_config_per_queue_rx_offload_result,
16393                  port, "port");
16394 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16395         TOKEN_NUM_INITIALIZER
16396                 (struct cmd_config_per_queue_rx_offload_result,
16397                  port_id, RTE_UINT16);
16398 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16399         TOKEN_STRING_INITIALIZER
16400                 (struct cmd_config_per_queue_rx_offload_result,
16401                  rxq, "rxq");
16402 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16403         TOKEN_NUM_INITIALIZER
16404                 (struct cmd_config_per_queue_rx_offload_result,
16405                  queue_id, RTE_UINT16);
16406 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16407         TOKEN_STRING_INITIALIZER
16408                 (struct cmd_config_per_queue_rx_offload_result,
16409                  rx_offload, "rx_offload");
16410 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16411         TOKEN_STRING_INITIALIZER
16412                 (struct cmd_config_per_queue_rx_offload_result,
16413                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16414                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16415                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16416                            "scatter#buffer_split#timestamp#security#keep_crc");
16417 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16418         TOKEN_STRING_INITIALIZER
16419                 (struct cmd_config_per_queue_rx_offload_result,
16420                  on_off, "on#off");
16421
16422 static void
16423 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16424                                 __rte_unused struct cmdline *cl,
16425                                 __rte_unused void *data)
16426 {
16427         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16428         struct rte_eth_dev_info dev_info;
16429         portid_t port_id = res->port_id;
16430         uint16_t queue_id = res->queue_id;
16431         struct rte_port *port = &ports[port_id];
16432         uint64_t single_offload;
16433         int ret;
16434
16435         if (port->port_status != RTE_PORT_STOPPED) {
16436                 fprintf(stderr,
16437                         "Error: Can't config offload when Port %d is not stopped\n",
16438                         port_id);
16439                 return;
16440         }
16441
16442         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16443         if (ret != 0)
16444                 return;
16445
16446         if (queue_id >= dev_info.nb_rx_queues) {
16447                 fprintf(stderr,
16448                         "Error: input queue_id should be 0 ... %d\n",
16449                         dev_info.nb_rx_queues - 1);
16450                 return;
16451         }
16452
16453         single_offload = search_rx_offload(res->offload);
16454         if (single_offload == 0) {
16455                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16456                 return;
16457         }
16458
16459         if (!strcmp(res->on_off, "on"))
16460                 port->rxq[queue_id].conf.offloads |= single_offload;
16461         else
16462                 port->rxq[queue_id].conf.offloads &= ~single_offload;
16463
16464         cmd_reconfig_device_queue(port_id, 1, 1);
16465 }
16466
16467 static cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16468         .f = cmd_config_per_queue_rx_offload_parsed,
16469         .data = NULL,
16470         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16471                     "vlan_strip|ipv4_cksum|"
16472                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16473                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16474                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16475                     "keep_crc on|off",
16476         .tokens = {
16477                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16478                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16479                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16480                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16481                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16482                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16483                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16484                 NULL,
16485         }
16486 };
16487
16488 /* Get Tx offloads capabilities */
16489 struct cmd_tx_offload_get_capa_result {
16490         cmdline_fixed_string_t show;
16491         cmdline_fixed_string_t port;
16492         portid_t port_id;
16493         cmdline_fixed_string_t tx_offload;
16494         cmdline_fixed_string_t capabilities;
16495 };
16496
16497 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16498         TOKEN_STRING_INITIALIZER
16499                 (struct cmd_tx_offload_get_capa_result,
16500                  show, "show");
16501 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16502         TOKEN_STRING_INITIALIZER
16503                 (struct cmd_tx_offload_get_capa_result,
16504                  port, "port");
16505 static cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16506         TOKEN_NUM_INITIALIZER
16507                 (struct cmd_tx_offload_get_capa_result,
16508                  port_id, RTE_UINT16);
16509 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16510         TOKEN_STRING_INITIALIZER
16511                 (struct cmd_tx_offload_get_capa_result,
16512                  tx_offload, "tx_offload");
16513 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16514         TOKEN_STRING_INITIALIZER
16515                 (struct cmd_tx_offload_get_capa_result,
16516                  capabilities, "capabilities");
16517
16518 static void
16519 print_tx_offloads(uint64_t offloads)
16520 {
16521         uint64_t single_offload;
16522         int begin;
16523         int end;
16524         int bit;
16525
16526         if (offloads == 0)
16527                 return;
16528
16529         begin = __builtin_ctzll(offloads);
16530         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16531
16532         single_offload = 1ULL << begin;
16533         for (bit = begin; bit < end; bit++) {
16534                 if (offloads & single_offload)
16535                         printf(" %s",
16536                                rte_eth_dev_tx_offload_name(single_offload));
16537                 single_offload <<= 1;
16538         }
16539 }
16540
16541 static void
16542 cmd_tx_offload_get_capa_parsed(
16543         void *parsed_result,
16544         __rte_unused struct cmdline *cl,
16545         __rte_unused void *data)
16546 {
16547         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16548         struct rte_eth_dev_info dev_info;
16549         portid_t port_id = res->port_id;
16550         uint64_t queue_offloads;
16551         uint64_t port_offloads;
16552         int ret;
16553
16554         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16555         if (ret != 0)
16556                 return;
16557
16558         queue_offloads = dev_info.tx_queue_offload_capa;
16559         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16560
16561         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16562         printf("  Per Queue :");
16563         print_tx_offloads(queue_offloads);
16564
16565         printf("\n");
16566         printf("  Per Port  :");
16567         print_tx_offloads(port_offloads);
16568         printf("\n\n");
16569 }
16570
16571 static cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16572         .f = cmd_tx_offload_get_capa_parsed,
16573         .data = NULL,
16574         .help_str = "show port <port_id> tx_offload capabilities",
16575         .tokens = {
16576                 (void *)&cmd_tx_offload_get_capa_show,
16577                 (void *)&cmd_tx_offload_get_capa_port,
16578                 (void *)&cmd_tx_offload_get_capa_port_id,
16579                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16580                 (void *)&cmd_tx_offload_get_capa_capabilities,
16581                 NULL,
16582         }
16583 };
16584
16585 /* Get Tx offloads configuration */
16586 struct cmd_tx_offload_get_configuration_result {
16587         cmdline_fixed_string_t show;
16588         cmdline_fixed_string_t port;
16589         portid_t port_id;
16590         cmdline_fixed_string_t tx_offload;
16591         cmdline_fixed_string_t configuration;
16592 };
16593
16594 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16595         TOKEN_STRING_INITIALIZER
16596                 (struct cmd_tx_offload_get_configuration_result,
16597                  show, "show");
16598 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16599         TOKEN_STRING_INITIALIZER
16600                 (struct cmd_tx_offload_get_configuration_result,
16601                  port, "port");
16602 static cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16603         TOKEN_NUM_INITIALIZER
16604                 (struct cmd_tx_offload_get_configuration_result,
16605                  port_id, RTE_UINT16);
16606 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16607         TOKEN_STRING_INITIALIZER
16608                 (struct cmd_tx_offload_get_configuration_result,
16609                  tx_offload, "tx_offload");
16610 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16611         TOKEN_STRING_INITIALIZER
16612                 (struct cmd_tx_offload_get_configuration_result,
16613                  configuration, "configuration");
16614
16615 static void
16616 cmd_tx_offload_get_configuration_parsed(
16617         void *parsed_result,
16618         __rte_unused struct cmdline *cl,
16619         __rte_unused void *data)
16620 {
16621         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16622         struct rte_eth_dev_info dev_info;
16623         portid_t port_id = res->port_id;
16624         struct rte_port *port = &ports[port_id];
16625         struct rte_eth_conf dev_conf;
16626         uint64_t port_offloads;
16627         uint64_t queue_offloads;
16628         uint16_t nb_tx_queues;
16629         int q;
16630         int ret;
16631
16632         printf("Tx Offloading Configuration of port %d :\n", port_id);
16633
16634         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16635         if (ret != 0)
16636                 return;
16637
16638         port_offloads = dev_conf.txmode.offloads;
16639         printf("  Port :");
16640         print_tx_offloads(port_offloads);
16641         printf("\n");
16642
16643         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16644         if (ret != 0)
16645                 return;
16646
16647         nb_tx_queues = dev_info.nb_tx_queues;
16648         for (q = 0; q < nb_tx_queues; q++) {
16649                 queue_offloads = port->txq[q].conf.offloads;
16650                 printf("  Queue[%2d] :", q);
16651                 print_tx_offloads(queue_offloads);
16652                 printf("\n");
16653         }
16654         printf("\n");
16655 }
16656
16657 static cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16658         .f = cmd_tx_offload_get_configuration_parsed,
16659         .data = NULL,
16660         .help_str = "show port <port_id> tx_offload configuration",
16661         .tokens = {
16662                 (void *)&cmd_tx_offload_get_configuration_show,
16663                 (void *)&cmd_tx_offload_get_configuration_port,
16664                 (void *)&cmd_tx_offload_get_configuration_port_id,
16665                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16666                 (void *)&cmd_tx_offload_get_configuration_configuration,
16667                 NULL,
16668         }
16669 };
16670
16671 /* Enable/Disable a per port offloading */
16672 struct cmd_config_per_port_tx_offload_result {
16673         cmdline_fixed_string_t port;
16674         cmdline_fixed_string_t config;
16675         portid_t port_id;
16676         cmdline_fixed_string_t tx_offload;
16677         cmdline_fixed_string_t offload;
16678         cmdline_fixed_string_t on_off;
16679 };
16680
16681 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16682         TOKEN_STRING_INITIALIZER
16683                 (struct cmd_config_per_port_tx_offload_result,
16684                  port, "port");
16685 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16686         TOKEN_STRING_INITIALIZER
16687                 (struct cmd_config_per_port_tx_offload_result,
16688                  config, "config");
16689 static cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16690         TOKEN_NUM_INITIALIZER
16691                 (struct cmd_config_per_port_tx_offload_result,
16692                  port_id, RTE_UINT16);
16693 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16694         TOKEN_STRING_INITIALIZER
16695                 (struct cmd_config_per_port_tx_offload_result,
16696                  tx_offload, "tx_offload");
16697 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16698         TOKEN_STRING_INITIALIZER
16699                 (struct cmd_config_per_port_tx_offload_result,
16700                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16701                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16702                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16703                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16704                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16705                           "send_on_timestamp");
16706 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16707         TOKEN_STRING_INITIALIZER
16708                 (struct cmd_config_per_port_tx_offload_result,
16709                  on_off, "on#off");
16710
16711 static uint64_t
16712 search_tx_offload(const char *name)
16713 {
16714         uint64_t single_offload;
16715         const char *single_name;
16716         int found = 0;
16717         unsigned int bit;
16718
16719         single_offload = 1;
16720         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16721                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16722                 if (single_name == NULL)
16723                         break;
16724                 if (!strcasecmp(single_name, name)) {
16725                         found = 1;
16726                         break;
16727                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16728                         break;
16729                 single_offload <<= 1;
16730         }
16731
16732         if (found)
16733                 return single_offload;
16734
16735         return 0;
16736 }
16737
16738 static void
16739 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16740                                 __rte_unused struct cmdline *cl,
16741                                 __rte_unused void *data)
16742 {
16743         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16744         portid_t port_id = res->port_id;
16745         struct rte_eth_dev_info dev_info;
16746         struct rte_port *port = &ports[port_id];
16747         uint64_t single_offload;
16748         uint16_t nb_tx_queues;
16749         int q;
16750         int ret;
16751
16752         if (port->port_status != RTE_PORT_STOPPED) {
16753                 fprintf(stderr,
16754                         "Error: Can't config offload when Port %d is not stopped\n",
16755                         port_id);
16756                 return;
16757         }
16758
16759         single_offload = search_tx_offload(res->offload);
16760         if (single_offload == 0) {
16761                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16762                 return;
16763         }
16764
16765         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16766         if (ret != 0)
16767                 return;
16768
16769         nb_tx_queues = dev_info.nb_tx_queues;
16770         if (!strcmp(res->on_off, "on")) {
16771                 port->dev_conf.txmode.offloads |= single_offload;
16772                 for (q = 0; q < nb_tx_queues; q++)
16773                         port->txq[q].conf.offloads |= single_offload;
16774         } else {
16775                 port->dev_conf.txmode.offloads &= ~single_offload;
16776                 for (q = 0; q < nb_tx_queues; q++)
16777                         port->txq[q].conf.offloads &= ~single_offload;
16778         }
16779
16780         cmd_reconfig_device_queue(port_id, 1, 1);
16781 }
16782
16783 static cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16784         .f = cmd_config_per_port_tx_offload_parsed,
16785         .data = NULL,
16786         .help_str = "port config <port_id> tx_offload "
16787                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16788                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16789                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16790                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16791                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16792                     "send_on_timestamp on|off",
16793         .tokens = {
16794                 (void *)&cmd_config_per_port_tx_offload_result_port,
16795                 (void *)&cmd_config_per_port_tx_offload_result_config,
16796                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16797                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16798                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16799                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16800                 NULL,
16801         }
16802 };
16803
16804 /* Enable/Disable a per queue offloading */
16805 struct cmd_config_per_queue_tx_offload_result {
16806         cmdline_fixed_string_t port;
16807         portid_t port_id;
16808         cmdline_fixed_string_t txq;
16809         uint16_t queue_id;
16810         cmdline_fixed_string_t tx_offload;
16811         cmdline_fixed_string_t offload;
16812         cmdline_fixed_string_t on_off;
16813 };
16814
16815 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16816         TOKEN_STRING_INITIALIZER
16817                 (struct cmd_config_per_queue_tx_offload_result,
16818                  port, "port");
16819 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16820         TOKEN_NUM_INITIALIZER
16821                 (struct cmd_config_per_queue_tx_offload_result,
16822                  port_id, RTE_UINT16);
16823 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16824         TOKEN_STRING_INITIALIZER
16825                 (struct cmd_config_per_queue_tx_offload_result,
16826                  txq, "txq");
16827 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16828         TOKEN_NUM_INITIALIZER
16829                 (struct cmd_config_per_queue_tx_offload_result,
16830                  queue_id, RTE_UINT16);
16831 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16832         TOKEN_STRING_INITIALIZER
16833                 (struct cmd_config_per_queue_tx_offload_result,
16834                  tx_offload, "tx_offload");
16835 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16836         TOKEN_STRING_INITIALIZER
16837                 (struct cmd_config_per_queue_tx_offload_result,
16838                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16839                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16840                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16841                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16842                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16843 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16844         TOKEN_STRING_INITIALIZER
16845                 (struct cmd_config_per_queue_tx_offload_result,
16846                  on_off, "on#off");
16847
16848 static void
16849 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16850                                 __rte_unused struct cmdline *cl,
16851                                 __rte_unused void *data)
16852 {
16853         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16854         struct rte_eth_dev_info dev_info;
16855         portid_t port_id = res->port_id;
16856         uint16_t queue_id = res->queue_id;
16857         struct rte_port *port = &ports[port_id];
16858         uint64_t single_offload;
16859         int ret;
16860
16861         if (port->port_status != RTE_PORT_STOPPED) {
16862                 fprintf(stderr,
16863                         "Error: Can't config offload when Port %d is not stopped\n",
16864                         port_id);
16865                 return;
16866         }
16867
16868         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16869         if (ret != 0)
16870                 return;
16871
16872         if (queue_id >= dev_info.nb_tx_queues) {
16873                 fprintf(stderr,
16874                         "Error: input queue_id should be 0 ... %d\n",
16875                         dev_info.nb_tx_queues - 1);
16876                 return;
16877         }
16878
16879         single_offload = search_tx_offload(res->offload);
16880         if (single_offload == 0) {
16881                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16882                 return;
16883         }
16884
16885         if (!strcmp(res->on_off, "on"))
16886                 port->txq[queue_id].conf.offloads |= single_offload;
16887         else
16888                 port->txq[queue_id].conf.offloads &= ~single_offload;
16889
16890         cmd_reconfig_device_queue(port_id, 1, 1);
16891 }
16892
16893 static cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16894         .f = cmd_config_per_queue_tx_offload_parsed,
16895         .data = NULL,
16896         .help_str = "port <port_id> txq <queue_id> tx_offload "
16897                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16898                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16899                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16900                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16901                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16902                     "on|off",
16903         .tokens = {
16904                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16905                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16906                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16907                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16908                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16909                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16910                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16911                 NULL,
16912         }
16913 };
16914
16915 /* *** configure tx_metadata for specific port *** */
16916 struct cmd_config_tx_metadata_specific_result {
16917         cmdline_fixed_string_t port;
16918         cmdline_fixed_string_t keyword;
16919         uint16_t port_id;
16920         cmdline_fixed_string_t item;
16921         uint32_t value;
16922 };
16923
16924 static void
16925 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16926                                 __rte_unused struct cmdline *cl,
16927                                 __rte_unused void *data)
16928 {
16929         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16930
16931         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16932                 return;
16933         ports[res->port_id].tx_metadata = res->value;
16934         /* Add/remove callback to insert valid metadata in every Tx packet. */
16935         if (ports[res->port_id].tx_metadata)
16936                 add_tx_md_callback(res->port_id);
16937         else
16938                 remove_tx_md_callback(res->port_id);
16939         rte_flow_dynf_metadata_register();
16940 }
16941
16942 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16943         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16944                         port, "port");
16945 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16946         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16947                         keyword, "config");
16948 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16949         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16950                         port_id, RTE_UINT16);
16951 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16952         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16953                         item, "tx_metadata");
16954 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16955         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16956                         value, RTE_UINT32);
16957
16958 static cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16959         .f = cmd_config_tx_metadata_specific_parsed,
16960         .data = NULL,
16961         .help_str = "port config <port_id> tx_metadata <value>",
16962         .tokens = {
16963                 (void *)&cmd_config_tx_metadata_specific_port,
16964                 (void *)&cmd_config_tx_metadata_specific_keyword,
16965                 (void *)&cmd_config_tx_metadata_specific_id,
16966                 (void *)&cmd_config_tx_metadata_specific_item,
16967                 (void *)&cmd_config_tx_metadata_specific_value,
16968                 NULL,
16969         },
16970 };
16971
16972 /* *** set dynf *** */
16973 struct cmd_config_tx_dynf_specific_result {
16974         cmdline_fixed_string_t port;
16975         cmdline_fixed_string_t keyword;
16976         uint16_t port_id;
16977         cmdline_fixed_string_t item;
16978         cmdline_fixed_string_t name;
16979         cmdline_fixed_string_t value;
16980 };
16981
16982 static void
16983 cmd_config_dynf_specific_parsed(void *parsed_result,
16984                                 __rte_unused struct cmdline *cl,
16985                                 __rte_unused void *data)
16986 {
16987         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16988         struct rte_mbuf_dynflag desc_flag;
16989         int flag;
16990         uint64_t old_port_flags;
16991
16992         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16993                 return;
16994         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16995         if (flag <= 0) {
16996                 if (strlcpy(desc_flag.name, res->name,
16997                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16998                         fprintf(stderr, "Flag name too long\n");
16999                         return;
17000                 }
17001                 desc_flag.flags = 0;
17002                 flag = rte_mbuf_dynflag_register(&desc_flag);
17003                 if (flag < 0) {
17004                         fprintf(stderr, "Can't register flag\n");
17005                         return;
17006                 }
17007                 strcpy(dynf_names[flag], desc_flag.name);
17008         }
17009         old_port_flags = ports[res->port_id].mbuf_dynf;
17010         if (!strcmp(res->value, "set")) {
17011                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
17012                 if (old_port_flags == 0)
17013                         add_tx_dynf_callback(res->port_id);
17014         } else {
17015                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
17016                 if (ports[res->port_id].mbuf_dynf == 0)
17017                         remove_tx_dynf_callback(res->port_id);
17018         }
17019 }
17020
17021 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17022         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17023                         keyword, "port");
17024 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17025         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17026                         keyword, "config");
17027 static cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17028         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17029                         port_id, RTE_UINT16);
17030 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17031         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17032                         item, "dynf");
17033 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17034         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17035                         name, NULL);
17036 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17037         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17038                         value, "set#clear");
17039
17040 static cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17041         .f = cmd_config_dynf_specific_parsed,
17042         .data = NULL,
17043         .help_str = "port config <port id> dynf <name> set|clear",
17044         .tokens = {
17045                 (void *)&cmd_config_tx_dynf_specific_port,
17046                 (void *)&cmd_config_tx_dynf_specific_keyword,
17047                 (void *)&cmd_config_tx_dynf_specific_port_id,
17048                 (void *)&cmd_config_tx_dynf_specific_item,
17049                 (void *)&cmd_config_tx_dynf_specific_name,
17050                 (void *)&cmd_config_tx_dynf_specific_value,
17051                 NULL,
17052         },
17053 };
17054
17055 /* *** display tx_metadata per port configuration *** */
17056 struct cmd_show_tx_metadata_result {
17057         cmdline_fixed_string_t cmd_show;
17058         cmdline_fixed_string_t cmd_port;
17059         cmdline_fixed_string_t cmd_keyword;
17060         portid_t cmd_pid;
17061 };
17062
17063 static void
17064 cmd_show_tx_metadata_parsed(void *parsed_result,
17065                 __rte_unused struct cmdline *cl,
17066                 __rte_unused void *data)
17067 {
17068         struct cmd_show_tx_metadata_result *res = parsed_result;
17069
17070         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17071                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17072                 return;
17073         }
17074         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17075                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17076                        ports[res->cmd_pid].tx_metadata);
17077         }
17078 }
17079
17080 static cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17081         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17082                         cmd_show, "show");
17083 static cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17084         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17085                         cmd_port, "port");
17086 static cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17087         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17088                         cmd_pid, RTE_UINT16);
17089 static cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17090         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17091                         cmd_keyword, "tx_metadata");
17092
17093 static cmdline_parse_inst_t cmd_show_tx_metadata = {
17094         .f = cmd_show_tx_metadata_parsed,
17095         .data = NULL,
17096         .help_str = "show port <port_id> tx_metadata",
17097         .tokens = {
17098                 (void *)&cmd_show_tx_metadata_show,
17099                 (void *)&cmd_show_tx_metadata_port,
17100                 (void *)&cmd_show_tx_metadata_pid,
17101                 (void *)&cmd_show_tx_metadata_keyword,
17102                 NULL,
17103         },
17104 };
17105
17106 /* *** show fec capability per port configuration *** */
17107 struct cmd_show_fec_capability_result {
17108         cmdline_fixed_string_t cmd_show;
17109         cmdline_fixed_string_t cmd_port;
17110         cmdline_fixed_string_t cmd_fec;
17111         cmdline_fixed_string_t cmd_keyword;
17112         portid_t cmd_pid;
17113 };
17114
17115 static void
17116 cmd_show_fec_capability_parsed(void *parsed_result,
17117                 __rte_unused struct cmdline *cl,
17118                 __rte_unused void *data)
17119 {
17120         struct cmd_show_fec_capability_result *res = parsed_result;
17121         struct rte_eth_fec_capa *speed_fec_capa;
17122         unsigned int num;
17123         int ret;
17124
17125         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17126                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17127                 return;
17128         }
17129
17130         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17131         if (ret == -ENOTSUP) {
17132                 fprintf(stderr, "Function not implemented\n");
17133                 return;
17134         } else if (ret < 0) {
17135                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17136                 return;
17137         }
17138
17139         num = (unsigned int)ret;
17140         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17141         if (speed_fec_capa == NULL) {
17142                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17143                 return;
17144         }
17145
17146         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17147         if (ret < 0) {
17148                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17149                 goto out;
17150         }
17151
17152         show_fec_capability(num, speed_fec_capa);
17153 out:
17154         free(speed_fec_capa);
17155 }
17156
17157 static cmdline_parse_token_string_t cmd_show_fec_capability_show =
17158         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17159                         cmd_show, "show");
17160 static cmdline_parse_token_string_t cmd_show_fec_capability_port =
17161         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17162                         cmd_port, "port");
17163 static cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17164         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17165                         cmd_pid, RTE_UINT16);
17166 static cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17167         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17168                         cmd_fec, "fec");
17169 static cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17170         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17171                         cmd_keyword, "capabilities");
17172
17173 static cmdline_parse_inst_t cmd_show_capability = {
17174         .f = cmd_show_fec_capability_parsed,
17175         .data = NULL,
17176         .help_str = "show port <port_id> fec capabilities",
17177         .tokens = {
17178                 (void *)&cmd_show_fec_capability_show,
17179                 (void *)&cmd_show_fec_capability_port,
17180                 (void *)&cmd_show_fec_capability_pid,
17181                 (void *)&cmd_show_fec_capability_fec,
17182                 (void *)&cmd_show_fec_capability_keyword,
17183                 NULL,
17184         },
17185 };
17186
17187 /* *** show fec mode per port configuration *** */
17188 struct cmd_show_fec_metadata_result {
17189         cmdline_fixed_string_t cmd_show;
17190         cmdline_fixed_string_t cmd_port;
17191         cmdline_fixed_string_t cmd_keyword;
17192         portid_t cmd_pid;
17193 };
17194
17195 static void
17196 cmd_show_fec_mode_parsed(void *parsed_result,
17197                 __rte_unused struct cmdline *cl,
17198                 __rte_unused void *data)
17199 {
17200 #define FEC_NAME_SIZE 16
17201         struct cmd_show_fec_metadata_result *res = parsed_result;
17202         uint32_t mode;
17203         char buf[FEC_NAME_SIZE];
17204         int ret;
17205
17206         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17207                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17208                 return;
17209         }
17210         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17211         if (ret == -ENOTSUP) {
17212                 fprintf(stderr, "Function not implemented\n");
17213                 return;
17214         } else if (ret < 0) {
17215                 fprintf(stderr, "Get FEC mode failed\n");
17216                 return;
17217         }
17218
17219         switch (mode) {
17220         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17221                 strlcpy(buf, "off", sizeof(buf));
17222                 break;
17223         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17224                 strlcpy(buf, "auto", sizeof(buf));
17225                 break;
17226         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17227                 strlcpy(buf, "baser", sizeof(buf));
17228                 break;
17229         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17230                 strlcpy(buf, "rs", sizeof(buf));
17231                 break;
17232         default:
17233                 return;
17234         }
17235
17236         printf("%s\n", buf);
17237 }
17238
17239 static cmdline_parse_token_string_t cmd_show_fec_mode_show =
17240         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17241                         cmd_show, "show");
17242 static cmdline_parse_token_string_t cmd_show_fec_mode_port =
17243         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17244                         cmd_port, "port");
17245 static cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17246         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17247                         cmd_pid, RTE_UINT16);
17248 static cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17249         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17250                         cmd_keyword, "fec_mode");
17251
17252 static cmdline_parse_inst_t cmd_show_fec_mode = {
17253         .f = cmd_show_fec_mode_parsed,
17254         .data = NULL,
17255         .help_str = "show port <port_id> fec_mode",
17256         .tokens = {
17257                 (void *)&cmd_show_fec_mode_show,
17258                 (void *)&cmd_show_fec_mode_port,
17259                 (void *)&cmd_show_fec_mode_pid,
17260                 (void *)&cmd_show_fec_mode_keyword,
17261                 NULL,
17262         },
17263 };
17264
17265 /* *** set fec mode per port configuration *** */
17266 struct cmd_set_port_fec_mode {
17267         cmdline_fixed_string_t set;
17268         cmdline_fixed_string_t port;
17269         portid_t port_id;
17270         cmdline_fixed_string_t fec_mode;
17271         cmdline_fixed_string_t fec_value;
17272 };
17273
17274 /* Common CLI fields for set fec mode */
17275 static cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17276         TOKEN_STRING_INITIALIZER
17277                 (struct cmd_set_port_fec_mode,
17278                  set, "set");
17279 static cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17280         TOKEN_STRING_INITIALIZER
17281                 (struct cmd_set_port_fec_mode,
17282                  port, "port");
17283 static cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17284         TOKEN_NUM_INITIALIZER
17285                 (struct cmd_set_port_fec_mode,
17286                  port_id, RTE_UINT16);
17287 static cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17288         TOKEN_STRING_INITIALIZER
17289                 (struct cmd_set_port_fec_mode,
17290                  fec_mode, "fec_mode");
17291 static cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17292         TOKEN_STRING_INITIALIZER
17293                 (struct cmd_set_port_fec_mode,
17294                  fec_value, NULL);
17295
17296 static void
17297 cmd_set_port_fec_mode_parsed(
17298         void *parsed_result,
17299         __rte_unused struct cmdline *cl,
17300         __rte_unused void *data)
17301 {
17302         struct cmd_set_port_fec_mode *res = parsed_result;
17303         uint16_t port_id = res->port_id;
17304         uint32_t fec_capa;
17305         int ret;
17306
17307         ret = parse_fec_mode(res->fec_value, &fec_capa);
17308         if (ret < 0) {
17309                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17310                                 res->fec_value, port_id);
17311                 return;
17312         }
17313
17314         ret = rte_eth_fec_set(port_id, fec_capa);
17315         if (ret == -ENOTSUP) {
17316                 fprintf(stderr, "Function not implemented\n");
17317                 return;
17318         } else if (ret < 0) {
17319                 fprintf(stderr, "Set FEC mode failed\n");
17320                 return;
17321         }
17322 }
17323
17324 static cmdline_parse_inst_t cmd_set_fec_mode = {
17325         .f = cmd_set_port_fec_mode_parsed,
17326         .data = NULL,
17327         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17328         .tokens = {
17329                 (void *)&cmd_set_port_fec_mode_set,
17330                 (void *)&cmd_set_port_fec_mode_port,
17331                 (void *)&cmd_set_port_fec_mode_port_id,
17332                 (void *)&cmd_set_port_fec_mode_str,
17333                 (void *)&cmd_set_port_fec_mode_value,
17334                 NULL,
17335         },
17336 };
17337
17338 /* *** set available descriptors threshold for an RxQ of a port *** */
17339 struct cmd_set_rxq_avail_thresh_result {
17340         cmdline_fixed_string_t set;
17341         cmdline_fixed_string_t port;
17342         uint16_t port_num;
17343         cmdline_fixed_string_t rxq;
17344         uint16_t rxq_num;
17345         cmdline_fixed_string_t avail_thresh;
17346         uint8_t avail_thresh_num;
17347 };
17348
17349 static void cmd_set_rxq_avail_thresh_parsed(void *parsed_result,
17350                 __rte_unused struct cmdline *cl,
17351                 __rte_unused void *data)
17352 {
17353         struct cmd_set_rxq_avail_thresh_result *res = parsed_result;
17354         int ret = 0;
17355
17356         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
17357             && (strcmp(res->rxq, "rxq") == 0)
17358             && (strcmp(res->avail_thresh, "avail_thresh") == 0))
17359                 ret = set_rxq_avail_thresh(res->port_num, res->rxq_num,
17360                                   res->avail_thresh_num);
17361         if (ret < 0)
17362                 printf("rxq_avail_thresh_cmd error: (%s)\n", strerror(-ret));
17363
17364 }
17365
17366 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_set =
17367         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17368                                 set, "set");
17369 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_port =
17370         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17371                                 port, "port");
17372 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_portnum =
17373         TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17374                                 port_num, RTE_UINT16);
17375 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_rxq =
17376         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17377                                 rxq, "rxq");
17378 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_rxqnum =
17379         TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17380                                 rxq_num, RTE_UINT16);
17381 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_avail_thresh =
17382         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17383                                 avail_thresh, "avail_thresh");
17384 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_avail_threshnum =
17385         TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17386                                 avail_thresh_num, RTE_UINT8);
17387
17388 static cmdline_parse_inst_t cmd_set_rxq_avail_thresh = {
17389         .f = cmd_set_rxq_avail_thresh_parsed,
17390         .data = (void *)0,
17391         .help_str =
17392                 "set port <port_id> rxq <queue_id> avail_thresh <0..99>: "
17393                 "Set available descriptors threshold for Rx queue",
17394         .tokens = {
17395                 (void *)&cmd_set_rxq_avail_thresh_set,
17396                 (void *)&cmd_set_rxq_avail_thresh_port,
17397                 (void *)&cmd_set_rxq_avail_thresh_portnum,
17398                 (void *)&cmd_set_rxq_avail_thresh_rxq,
17399                 (void *)&cmd_set_rxq_avail_thresh_rxqnum,
17400                 (void *)&cmd_set_rxq_avail_thresh_avail_thresh,
17401                 (void *)&cmd_set_rxq_avail_thresh_avail_threshnum,
17402                 NULL,
17403         },
17404 };
17405
17406 /* show port supported ptypes */
17407
17408 /* Common result structure for show port ptypes */
17409 struct cmd_show_port_supported_ptypes_result {
17410         cmdline_fixed_string_t show;
17411         cmdline_fixed_string_t port;
17412         portid_t port_id;
17413         cmdline_fixed_string_t ptypes;
17414 };
17415
17416 /* Common CLI fields for show port ptypes */
17417 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17418         TOKEN_STRING_INITIALIZER
17419                 (struct cmd_show_port_supported_ptypes_result,
17420                  show, "show");
17421 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17422         TOKEN_STRING_INITIALIZER
17423                 (struct cmd_show_port_supported_ptypes_result,
17424                  port, "port");
17425 static cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17426         TOKEN_NUM_INITIALIZER
17427                 (struct cmd_show_port_supported_ptypes_result,
17428                  port_id, RTE_UINT16);
17429 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17430         TOKEN_STRING_INITIALIZER
17431                 (struct cmd_show_port_supported_ptypes_result,
17432                  ptypes, "ptypes");
17433
17434 static void
17435 cmd_show_port_supported_ptypes_parsed(
17436         void *parsed_result,
17437         __rte_unused struct cmdline *cl,
17438         __rte_unused void *data)
17439 {
17440 #define RSVD_PTYPE_MASK       0xf0000000
17441 #define MAX_PTYPES_PER_LAYER  16
17442 #define LTYPE_NAMESIZE        32
17443 #define PTYPE_NAMESIZE        256
17444         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17445         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17446         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17447         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17448         uint16_t port_id = res->port_id;
17449         int ret, i;
17450
17451         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17452         if (ret < 0)
17453                 return;
17454
17455         while (ptype_mask != RSVD_PTYPE_MASK) {
17456
17457                 switch (ptype_mask) {
17458                 case RTE_PTYPE_L2_MASK:
17459                         strlcpy(ltype, "L2", sizeof(ltype));
17460                         break;
17461                 case RTE_PTYPE_L3_MASK:
17462                         strlcpy(ltype, "L3", sizeof(ltype));
17463                         break;
17464                 case RTE_PTYPE_L4_MASK:
17465                         strlcpy(ltype, "L4", sizeof(ltype));
17466                         break;
17467                 case RTE_PTYPE_TUNNEL_MASK:
17468                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17469                         break;
17470                 case RTE_PTYPE_INNER_L2_MASK:
17471                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17472                         break;
17473                 case RTE_PTYPE_INNER_L3_MASK:
17474                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17475                         break;
17476                 case RTE_PTYPE_INNER_L4_MASK:
17477                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17478                         break;
17479                 default:
17480                         return;
17481                 }
17482
17483                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17484                                                        ptype_mask, ptypes,
17485                                                        MAX_PTYPES_PER_LAYER);
17486
17487                 if (ret > 0)
17488                         printf("Supported %s ptypes:\n", ltype);
17489                 else
17490                         printf("%s ptypes unsupported\n", ltype);
17491
17492                 for (i = 0; i < ret; ++i) {
17493                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17494                         printf("%s\n", buf);
17495                 }
17496
17497                 ptype_mask <<= 4;
17498         }
17499 }
17500
17501 static cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17502         .f = cmd_show_port_supported_ptypes_parsed,
17503         .data = NULL,
17504         .help_str = "show port <port_id> ptypes",
17505         .tokens = {
17506                 (void *)&cmd_show_port_supported_ptypes_show,
17507                 (void *)&cmd_show_port_supported_ptypes_port,
17508                 (void *)&cmd_show_port_supported_ptypes_port_id,
17509                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17510                 NULL,
17511         },
17512 };
17513
17514 /* *** display rx/tx descriptor status *** */
17515 struct cmd_show_rx_tx_desc_status_result {
17516         cmdline_fixed_string_t cmd_show;
17517         cmdline_fixed_string_t cmd_port;
17518         cmdline_fixed_string_t cmd_keyword;
17519         cmdline_fixed_string_t cmd_desc;
17520         cmdline_fixed_string_t cmd_status;
17521         portid_t cmd_pid;
17522         portid_t cmd_qid;
17523         portid_t cmd_did;
17524 };
17525
17526 static void
17527 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17528                 __rte_unused struct cmdline *cl,
17529                 __rte_unused void *data)
17530 {
17531         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17532         int rc;
17533
17534         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17535                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17536                 return;
17537         }
17538
17539         if (!strcmp(res->cmd_keyword, "rxq")) {
17540                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17541                                              res->cmd_did);
17542                 if (rc < 0) {
17543                         fprintf(stderr,
17544                                 "Invalid input: queue id = %d, desc id = %d\n",
17545                                 res->cmd_qid, res->cmd_did);
17546                         return;
17547                 }
17548                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17549                         printf("Desc status = AVAILABLE\n");
17550                 else if (rc == RTE_ETH_RX_DESC_DONE)
17551                         printf("Desc status = DONE\n");
17552                 else
17553                         printf("Desc status = UNAVAILABLE\n");
17554         } else if (!strcmp(res->cmd_keyword, "txq")) {
17555                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17556                                              res->cmd_did);
17557                 if (rc < 0) {
17558                         fprintf(stderr,
17559                                 "Invalid input: queue id = %d, desc id = %d\n",
17560                                 res->cmd_qid, res->cmd_did);
17561                         return;
17562                 }
17563                 if (rc == RTE_ETH_TX_DESC_FULL)
17564                         printf("Desc status = FULL\n");
17565                 else if (rc == RTE_ETH_TX_DESC_DONE)
17566                         printf("Desc status = DONE\n");
17567                 else
17568                         printf("Desc status = UNAVAILABLE\n");
17569         }
17570 }
17571
17572 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17573         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17574                         cmd_show, "show");
17575 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17576         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17577                         cmd_port, "port");
17578 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17579         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17580                         cmd_pid, RTE_UINT16);
17581 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17582         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17583                         cmd_keyword, "rxq#txq");
17584 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17585         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17586                         cmd_qid, RTE_UINT16);
17587 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17588         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17589                         cmd_desc, "desc");
17590 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17591         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17592                         cmd_did, RTE_UINT16);
17593 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17594         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17595                         cmd_status, "status");
17596 static cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17597         .f = cmd_show_rx_tx_desc_status_parsed,
17598         .data = NULL,
17599         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17600                 "status",
17601         .tokens = {
17602                 (void *)&cmd_show_rx_tx_desc_status_show,
17603                 (void *)&cmd_show_rx_tx_desc_status_port,
17604                 (void *)&cmd_show_rx_tx_desc_status_pid,
17605                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17606                 (void *)&cmd_show_rx_tx_desc_status_qid,
17607                 (void *)&cmd_show_rx_tx_desc_status_desc,
17608                 (void *)&cmd_show_rx_tx_desc_status_did,
17609                 (void *)&cmd_show_rx_tx_desc_status_status,
17610                 NULL,
17611         },
17612 };
17613
17614 /* *** display rx queue desc used count *** */
17615 struct cmd_show_rx_queue_desc_used_count_result {
17616         cmdline_fixed_string_t cmd_show;
17617         cmdline_fixed_string_t cmd_port;
17618         cmdline_fixed_string_t cmd_rxq;
17619         cmdline_fixed_string_t cmd_desc;
17620         cmdline_fixed_string_t cmd_used;
17621         cmdline_fixed_string_t cmd_count;
17622         portid_t cmd_pid;
17623         portid_t cmd_qid;
17624 };
17625
17626 static void
17627 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17628                 __rte_unused struct cmdline *cl,
17629                 __rte_unused void *data)
17630 {
17631         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17632         int rc;
17633
17634         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17635                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17636                 return;
17637         }
17638
17639         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17640         if (rc < 0) {
17641                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17642                 return;
17643         }
17644         printf("Used desc count = %d\n", rc);
17645 }
17646
17647 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17648         TOKEN_STRING_INITIALIZER
17649                 (struct cmd_show_rx_queue_desc_used_count_result,
17650                  cmd_show, "show");
17651 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17652         TOKEN_STRING_INITIALIZER
17653                 (struct cmd_show_rx_queue_desc_used_count_result,
17654                  cmd_port, "port");
17655 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17656         TOKEN_NUM_INITIALIZER
17657                 (struct cmd_show_rx_queue_desc_used_count_result,
17658                  cmd_pid, RTE_UINT16);
17659 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17660         TOKEN_STRING_INITIALIZER
17661                 (struct cmd_show_rx_queue_desc_used_count_result,
17662                  cmd_rxq, "rxq");
17663 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17664         TOKEN_NUM_INITIALIZER
17665                 (struct cmd_show_rx_queue_desc_used_count_result,
17666                  cmd_qid, RTE_UINT16);
17667 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17668         TOKEN_STRING_INITIALIZER
17669                 (struct cmd_show_rx_queue_desc_used_count_result,
17670                  cmd_count, "desc");
17671 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17672         TOKEN_STRING_INITIALIZER
17673                 (struct cmd_show_rx_queue_desc_used_count_result,
17674                  cmd_count, "used");
17675 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17676         TOKEN_STRING_INITIALIZER
17677                 (struct cmd_show_rx_queue_desc_used_count_result,
17678                  cmd_count, "count");
17679 static cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17680         .f = cmd_show_rx_queue_desc_used_count_parsed,
17681         .data = NULL,
17682         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17683         .tokens = {
17684                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17685                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17686                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17687                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17688                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17689                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17690                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17691                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17692                 NULL,
17693         },
17694 };
17695
17696 /* Common result structure for set port ptypes */
17697 struct cmd_set_port_ptypes_result {
17698         cmdline_fixed_string_t set;
17699         cmdline_fixed_string_t port;
17700         portid_t port_id;
17701         cmdline_fixed_string_t ptype_mask;
17702         uint32_t mask;
17703 };
17704
17705 /* Common CLI fields for set port ptypes */
17706 static cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17707         TOKEN_STRING_INITIALIZER
17708                 (struct cmd_set_port_ptypes_result,
17709                  set, "set");
17710 static cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17711         TOKEN_STRING_INITIALIZER
17712                 (struct cmd_set_port_ptypes_result,
17713                  port, "port");
17714 static cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17715         TOKEN_NUM_INITIALIZER
17716                 (struct cmd_set_port_ptypes_result,
17717                  port_id, RTE_UINT16);
17718 static cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17719         TOKEN_STRING_INITIALIZER
17720                 (struct cmd_set_port_ptypes_result,
17721                  ptype_mask, "ptype_mask");
17722 static cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17723         TOKEN_NUM_INITIALIZER
17724                 (struct cmd_set_port_ptypes_result,
17725                  mask, RTE_UINT32);
17726
17727 static void
17728 cmd_set_port_ptypes_parsed(
17729         void *parsed_result,
17730         __rte_unused struct cmdline *cl,
17731         __rte_unused void *data)
17732 {
17733         struct cmd_set_port_ptypes_result *res = parsed_result;
17734 #define PTYPE_NAMESIZE        256
17735         char ptype_name[PTYPE_NAMESIZE];
17736         uint16_t port_id = res->port_id;
17737         uint32_t ptype_mask = res->mask;
17738         int ret, i;
17739
17740         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17741                                                NULL, 0);
17742         if (ret <= 0) {
17743                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17744                         port_id);
17745                 return;
17746         }
17747
17748         uint32_t ptypes[ret];
17749
17750         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17751         if (ret < 0) {
17752                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17753                         port_id);
17754                 return;
17755         }
17756
17757         printf("Successfully set following ptypes for Port %d\n", port_id);
17758         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17759                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17760                 printf("%s\n", ptype_name);
17761         }
17762
17763         clear_ptypes = false;
17764 }
17765
17766 static cmdline_parse_inst_t cmd_set_port_ptypes = {
17767         .f = cmd_set_port_ptypes_parsed,
17768         .data = NULL,
17769         .help_str = "set port <port_id> ptype_mask <mask>",
17770         .tokens = {
17771                 (void *)&cmd_set_port_ptypes_set,
17772                 (void *)&cmd_set_port_ptypes_port,
17773                 (void *)&cmd_set_port_ptypes_port_id,
17774                 (void *)&cmd_set_port_ptypes_mask_str,
17775                 (void *)&cmd_set_port_ptypes_mask_u32,
17776                 NULL,
17777         },
17778 };
17779
17780 /* *** display mac addresses added to a port *** */
17781 struct cmd_showport_macs_result {
17782         cmdline_fixed_string_t cmd_show;
17783         cmdline_fixed_string_t cmd_port;
17784         cmdline_fixed_string_t cmd_keyword;
17785         portid_t cmd_pid;
17786 };
17787
17788 static void
17789 cmd_showport_macs_parsed(void *parsed_result,
17790                 __rte_unused struct cmdline *cl,
17791                 __rte_unused void *data)
17792 {
17793         struct cmd_showport_macs_result *res = parsed_result;
17794
17795         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17796                 return;
17797
17798         if (!strcmp(res->cmd_keyword, "macs"))
17799                 show_macs(res->cmd_pid);
17800         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17801                 show_mcast_macs(res->cmd_pid);
17802 }
17803
17804 static cmdline_parse_token_string_t cmd_showport_macs_show =
17805         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17806                         cmd_show, "show");
17807 static cmdline_parse_token_string_t cmd_showport_macs_port =
17808         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17809                         cmd_port, "port");
17810 static cmdline_parse_token_num_t cmd_showport_macs_pid =
17811         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17812                         cmd_pid, RTE_UINT16);
17813 static cmdline_parse_token_string_t cmd_showport_macs_keyword =
17814         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17815                         cmd_keyword, "macs#mcast_macs");
17816
17817 static cmdline_parse_inst_t cmd_showport_macs = {
17818         .f = cmd_showport_macs_parsed,
17819         .data = NULL,
17820         .help_str = "show port <port_id> macs|mcast_macs",
17821         .tokens = {
17822                 (void *)&cmd_showport_macs_show,
17823                 (void *)&cmd_showport_macs_port,
17824                 (void *)&cmd_showport_macs_pid,
17825                 (void *)&cmd_showport_macs_keyword,
17826                 NULL,
17827         },
17828 };
17829
17830 /* *** show flow transfer proxy port ID for the given port *** */
17831 struct cmd_show_port_flow_transfer_proxy_result {
17832         cmdline_fixed_string_t show;
17833         cmdline_fixed_string_t port;
17834         portid_t port_id;
17835         cmdline_fixed_string_t flow;
17836         cmdline_fixed_string_t transfer;
17837         cmdline_fixed_string_t proxy;
17838 };
17839
17840 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17841         TOKEN_STRING_INITIALIZER
17842                 (struct cmd_show_port_flow_transfer_proxy_result,
17843                  show, "show");
17844 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17845         TOKEN_STRING_INITIALIZER
17846                 (struct cmd_show_port_flow_transfer_proxy_result,
17847                  port, "port");
17848 static cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17849         TOKEN_NUM_INITIALIZER
17850                 (struct cmd_show_port_flow_transfer_proxy_result,
17851                  port_id, RTE_UINT16);
17852 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17853         TOKEN_STRING_INITIALIZER
17854                 (struct cmd_show_port_flow_transfer_proxy_result,
17855                  flow, "flow");
17856 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17857         TOKEN_STRING_INITIALIZER
17858                 (struct cmd_show_port_flow_transfer_proxy_result,
17859                  transfer, "transfer");
17860 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17861         TOKEN_STRING_INITIALIZER
17862                 (struct cmd_show_port_flow_transfer_proxy_result,
17863                  proxy, "proxy");
17864
17865 static void
17866 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17867                                          __rte_unused struct cmdline *cl,
17868                                          __rte_unused void *data)
17869 {
17870         struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17871         portid_t proxy_port_id;
17872         int ret;
17873
17874         printf("\n");
17875
17876         ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17877         if (ret != 0) {
17878                 fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17879                         rte_strerror(-ret));
17880                 return;
17881         }
17882
17883         printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17884 }
17885
17886 static cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17887         .f = cmd_show_port_flow_transfer_proxy_parsed,
17888         .data = NULL,
17889         .help_str = "show port <port_id> flow transfer proxy",
17890         .tokens = {
17891                 (void *)&cmd_show_port_flow_transfer_proxy_show,
17892                 (void *)&cmd_show_port_flow_transfer_proxy_port,
17893                 (void *)&cmd_show_port_flow_transfer_proxy_port_id,
17894                 (void *)&cmd_show_port_flow_transfer_proxy_flow,
17895                 (void *)&cmd_show_port_flow_transfer_proxy_transfer,
17896                 (void *)&cmd_show_port_flow_transfer_proxy_proxy,
17897                 NULL,
17898         }
17899 };
17900
17901 /* ******************************************************************************** */
17902
17903 /* list of instructions */
17904 static cmdline_parse_ctx_t builtin_ctx[] = {
17905         (cmdline_parse_inst_t *)&cmd_help_brief,
17906         (cmdline_parse_inst_t *)&cmd_help_long,
17907         (cmdline_parse_inst_t *)&cmd_quit,
17908         (cmdline_parse_inst_t *)&cmd_load_from_file,
17909         (cmdline_parse_inst_t *)&cmd_showport,
17910         (cmdline_parse_inst_t *)&cmd_showqueue,
17911         (cmdline_parse_inst_t *)&cmd_showeeprom,
17912         (cmdline_parse_inst_t *)&cmd_showportall,
17913         (cmdline_parse_inst_t *)&cmd_representor_info,
17914         (cmdline_parse_inst_t *)&cmd_showdevice,
17915         (cmdline_parse_inst_t *)&cmd_showcfg,
17916         (cmdline_parse_inst_t *)&cmd_showfwdall,
17917         (cmdline_parse_inst_t *)&cmd_start,
17918         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17919         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17920         (cmdline_parse_inst_t *)&cmd_set_link_up,
17921         (cmdline_parse_inst_t *)&cmd_set_link_down,
17922         (cmdline_parse_inst_t *)&cmd_reset,
17923         (cmdline_parse_inst_t *)&cmd_set_numbers,
17924         (cmdline_parse_inst_t *)&cmd_set_log,
17925         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17926         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17927         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17928         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17929         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17930         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17931         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17932         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17933         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17934         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17935         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17936         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17937         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17938         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17939         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17940         (cmdline_parse_inst_t *)&cmd_set_link_check,
17941         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17942         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17943         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17944         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17945 #ifdef RTE_NET_BOND
17946         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17947         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17948         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17949         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17950         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17951         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17952         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17953         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17954         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17955         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17956         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17957         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17958 #endif
17959         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17960         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17961         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17962         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17963         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17964         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17965         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17966         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17967         (cmdline_parse_inst_t *)&cmd_csum_set,
17968         (cmdline_parse_inst_t *)&cmd_csum_show,
17969         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17970         (cmdline_parse_inst_t *)&cmd_tso_set,
17971         (cmdline_parse_inst_t *)&cmd_tso_show,
17972         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17973         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17974 #ifdef RTE_LIB_GRO
17975         (cmdline_parse_inst_t *)&cmd_gro_enable,
17976         (cmdline_parse_inst_t *)&cmd_gro_flush,
17977         (cmdline_parse_inst_t *)&cmd_gro_show,
17978 #endif
17979 #ifdef RTE_LIB_GSO
17980         (cmdline_parse_inst_t *)&cmd_gso_enable,
17981         (cmdline_parse_inst_t *)&cmd_gso_size,
17982         (cmdline_parse_inst_t *)&cmd_gso_show,
17983 #endif
17984         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17985         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17986         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17987         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17988         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17989         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17990         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17991         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17992         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17993         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17994         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17995         (cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17996         (cmdline_parse_inst_t *)&cmd_config_dcb,
17997         (cmdline_parse_inst_t *)&cmd_read_reg,
17998         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17999         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18000         (cmdline_parse_inst_t *)&cmd_write_reg,
18001         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18002         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18003         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18004         (cmdline_parse_inst_t *)&cmd_stop,
18005         (cmdline_parse_inst_t *)&cmd_mac_addr,
18006         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18007         (cmdline_parse_inst_t *)&cmd_set_qmap,
18008         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18009         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
18010         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
18011         (cmdline_parse_inst_t *)&cmd_operate_port,
18012         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18013         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18014         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18015         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18016         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18017         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18018         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18019         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18020         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18021         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18022         (cmdline_parse_inst_t *)&cmd_config_mtu,
18023         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18024         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
18025         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18026         (cmdline_parse_inst_t *)&cmd_config_rss,
18027         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18028         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18029         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18030         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18031         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18032         (cmdline_parse_inst_t *)&cmd_showport_reta,
18033         (cmdline_parse_inst_t *)&cmd_showport_macs,
18034         (cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
18035         (cmdline_parse_inst_t *)&cmd_config_burst,
18036         (cmdline_parse_inst_t *)&cmd_config_thresh,
18037         (cmdline_parse_inst_t *)&cmd_config_threshold,
18038         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18039         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18040         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18041         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18042         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18043         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18044         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18045         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18046         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
18047         (cmdline_parse_inst_t *)&cmd_dump,
18048         (cmdline_parse_inst_t *)&cmd_dump_one,
18049 #ifdef RTE_NET_I40E
18050         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18051 #endif
18052         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18053         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18054         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18055         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18056         (cmdline_parse_inst_t *)&cmd_flow,
18057         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18058         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18059         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18060         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm_rfc4115,
18061         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18062         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18063         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18064         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18065         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18066         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
18067         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18068         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18069         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18070         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18071         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18072         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18073         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18074         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18075         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18076         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18077         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18078         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18079         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18080         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18081         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18082         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18083         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18084         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18085         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18086         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18087         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18088         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18089         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18090         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18091         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18092         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18093         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18094         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18095         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18096         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18097         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18098         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18099         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18100         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18101         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18102         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18103         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18104         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18105         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18106         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18107         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18108         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18109         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18110         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18111         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18112         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18113         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18114         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18115         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18116         (cmdline_parse_inst_t *)&cmd_ddp_add,
18117         (cmdline_parse_inst_t *)&cmd_ddp_del,
18118         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18119         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18120         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18121         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18122         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18123         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18124         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18125         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18126         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18127         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18128         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18129         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18130
18131         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18132         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18133         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18134         (cmdline_parse_inst_t *)&cmd_queue_region,
18135         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18136         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18137         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18138         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18139         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18140         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18141         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18142         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18143         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18144         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18145         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18146         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18147         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18148         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18149         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18150         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18151         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18152         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18153         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18154         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18155         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18156         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18157         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18158         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18159         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18160         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18161         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18162         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18163         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18164         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18165         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18166         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18167         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18168         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18169         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18170         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18171 #ifdef RTE_LIB_BPF
18172         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18173         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18174 #endif
18175         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18176         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18177         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18178         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18179         (cmdline_parse_inst_t *)&cmd_set_raw,
18180         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18181         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18182         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18183         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18184         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18185         (cmdline_parse_inst_t *)&cmd_set_rxq_avail_thresh,
18186         (cmdline_parse_inst_t *)&cmd_show_capability,
18187         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18188         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18189         NULL,
18190 };
18191
18192 void
18193 testpmd_add_driver_commands(struct testpmd_driver_commands *c)
18194 {
18195         TAILQ_INSERT_TAIL(&driver_commands_head, c, next);
18196 }
18197
18198 int
18199 init_cmdline(void)
18200 {
18201         struct testpmd_driver_commands *c;
18202         unsigned int count;
18203         unsigned int i;
18204
18205         /* initialize non-constant commands */
18206         cmd_set_fwd_mode_init();
18207         cmd_set_fwd_retry_mode_init();
18208
18209         count = 0;
18210         for (i = 0; builtin_ctx[i] != NULL; i++)
18211                 count++;
18212         TAILQ_FOREACH(c, &driver_commands_head, next) {
18213                 for (i = 0; c->commands[i].ctx != NULL; i++)
18214                         count++;
18215         }
18216
18217         /* cmdline expects a NULL terminated array */
18218         main_ctx = calloc(count + 1, sizeof(main_ctx[0]));
18219         if (main_ctx == NULL)
18220                 return -1;
18221
18222         count = 0;
18223         for (i = 0; builtin_ctx[i] != NULL; i++, count++)
18224                 main_ctx[count] = builtin_ctx[i];
18225         TAILQ_FOREACH(c, &driver_commands_head, next) {
18226                 for (i = 0; c->commands[i].ctx != NULL; i++, count++)
18227                         main_ctx[count] = c->commands[i].ctx;
18228         }
18229
18230         return 0;
18231 }
18232
18233 /* read cmdline commands from file */
18234 void
18235 cmdline_read_from_file(const char *filename)
18236 {
18237         struct cmdline *cl;
18238
18239         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18240         if (cl == NULL) {
18241                 fprintf(stderr,
18242                         "Failed to create file based cmdline context: %s\n",
18243                         filename);
18244                 return;
18245         }
18246
18247         cmdline_interact(cl);
18248         cmdline_quit(cl);
18249
18250         cmdline_free(cl);
18251
18252         printf("Read CLI commands from %s\n", filename);
18253 }
18254
18255 /* prompt function, called from main on MAIN lcore */
18256 void
18257 prompt(void)
18258 {
18259         int ret;
18260
18261         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18262         if (testpmd_cl == NULL)
18263                 return;
18264
18265         ret = atexit(prompt_exit);
18266         if (ret != 0)
18267                 fprintf(stderr, "Cannot set exit function for cmdline\n");
18268
18269         cmdline_interact(testpmd_cl);
18270         if (ret != 0)
18271                 cmdline_stdin_exit(testpmd_cl);
18272 }
18273
18274 void
18275 prompt_exit(void)
18276 {
18277         if (testpmd_cl != NULL) {
18278                 cmdline_quit(testpmd_cl);
18279                 cmdline_stdin_exit(testpmd_cl);
18280         }
18281 }
18282
18283 static void
18284 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18285 {
18286         if (id == (portid_t)RTE_PORT_ALL) {
18287                 portid_t pid;
18288
18289                 RTE_ETH_FOREACH_DEV(pid) {
18290                         /* check if need_reconfig has been set to 1 */
18291                         if (ports[pid].need_reconfig == 0)
18292                                 ports[pid].need_reconfig = dev;
18293                         /* check if need_reconfig_queues has been set to 1 */
18294                         if (ports[pid].need_reconfig_queues == 0)
18295                                 ports[pid].need_reconfig_queues = queue;
18296                 }
18297         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18298                 /* check if need_reconfig has been set to 1 */
18299                 if (ports[id].need_reconfig == 0)
18300                         ports[id].need_reconfig = dev;
18301                 /* check if need_reconfig_queues has been set to 1 */
18302                 if (ports[id].need_reconfig_queues == 0)
18303                         ports[id].need_reconfig_queues = queue;
18304         }
18305 }