net/vhost: move to vhost library statistics API
[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 stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
557                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
558                         " queue on port.\n"
559                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
560                         " on port 0 to mapping 5.\n\n"
561
562                         "set xstats-hide-zero on|off\n"
563                         "    Set the option to hide the zero values"
564                         " for xstats display.\n"
565
566                         "set record-core-cycles on|off\n"
567                         "    Set the option to enable measurement of CPU cycles.\n"
568
569                         "set record-burst-stats on|off\n"
570                         "    Set the option to enable display of RX and TX bursts.\n"
571
572                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
573                         "    Enable/Disable a VF receive/transmit from a port\n\n"
574
575                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
576                         "|MPE) (on|off)\n"
577                         "    AUPE:accepts untagged VLAN;"
578                         "ROPE:accept unicast hash\n\n"
579                         "    BAM:accepts broadcast packets;"
580                         "MPE:accepts all multicast packets\n\n"
581                         "    Enable/Disable a VF receive mode of a port\n\n"
582
583                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
584                         "    Set rate limit for a queue of a port\n\n"
585
586                         "set port (port_id) vf (vf_id) rate (rate_num) "
587                         "queue_mask (queue_mask_value)\n"
588                         "    Set rate limit for queues in VF of a port\n\n"
589
590                         "set flush_rx (on|off)\n"
591                         "   Flush (default) or don't flush RX streams before"
592                         " forwarding. Mainly used with PCAP drivers.\n\n"
593
594                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
595                         "   Set the bypass mode for the lowest port on bypass enabled"
596                         " NIC.\n\n"
597
598                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
599                         "mode (normal|bypass|isolate) (port_id)\n"
600                         "   Set the event required to initiate specified bypass mode for"
601                         " the lowest port on a bypass enabled NIC where:\n"
602                         "       timeout   = enable bypass after watchdog timeout.\n"
603                         "       os_on     = enable bypass when OS/board is powered on.\n"
604                         "       os_off    = enable bypass when OS/board is powered off.\n"
605                         "       power_on  = enable bypass when power supply is turned on.\n"
606                         "       power_off = enable bypass when power supply is turned off."
607                         "\n\n"
608
609                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
610                         "   Set the bypass watchdog timeout to 'n' seconds"
611                         " where 0 = instant.\n\n"
612
613                         "show bypass config (port_id)\n"
614                         "   Show the bypass configuration for a bypass enabled NIC"
615                         " using the lowest port on the NIC.\n\n"
616
617 #ifdef RTE_NET_BOND
618                         "create bonded device (mode) (socket)\n"
619                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
620
621                         "add bonding slave (slave_id) (port_id)\n"
622                         "       Add a slave device to a bonded device.\n\n"
623
624                         "remove bonding slave (slave_id) (port_id)\n"
625                         "       Remove a slave device from a bonded device.\n\n"
626
627                         "set bonding mode (value) (port_id)\n"
628                         "       Set the bonding mode on a bonded device.\n\n"
629
630                         "set bonding primary (slave_id) (port_id)\n"
631                         "       Set the primary slave for a bonded device.\n\n"
632
633                         "show bonding config (port_id)\n"
634                         "       Show the bonding config for port_id.\n\n"
635
636                         "show bonding lacp info (port_id)\n"
637                         "       Show the bonding lacp information for port_id.\n\n"
638
639                         "set bonding mac_addr (port_id) (address)\n"
640                         "       Set the MAC address of a bonded device.\n\n"
641
642                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
643                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
644
645                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
646                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
647
648                         "set bonding mon_period (port_id) (value)\n"
649                         "       Set the bonding link status monitoring polling period in ms.\n\n"
650
651                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
652                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
653
654 #endif
655                         "set link-up port (port_id)\n"
656                         "       Set link up for a port.\n\n"
657
658                         "set link-down port (port_id)\n"
659                         "       Set link down for a port.\n\n"
660
661                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
662                         "    Load a profile package on a port\n\n"
663
664                         "ddp del (port_id) (backup_profile_path)\n"
665                         "    Delete a profile package from a port\n\n"
666
667                         "ptype mapping get (port_id) (valid_only)\n"
668                         "    Get ptype mapping on a port\n\n"
669
670                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
671                         "    Replace target with the pkt_type in ptype mapping\n\n"
672
673                         "ptype mapping reset (port_id)\n"
674                         "    Reset ptype mapping on a port\n\n"
675
676                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
677                         "    Update a ptype mapping item on a port\n\n"
678
679                         "set port (port_id) ptype_mask (ptype_mask)\n"
680                         "    set packet types classification for a specific port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "queue_start_index (value) queue_num (value)\n"
684                         "    Set a queue region on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "flowtype (value)\n"
688                         "    Set a flowtype region index on a port\n\n"
689
690                         "set port (port_id) queue-region UP (value) region_id (value)\n"
691                         "    Set the mapping of User Priority to "
692                         "queue region on a port\n\n"
693
694                         "set port (port_id) queue-region flush (on|off)\n"
695                         "    flush all queue region related configuration\n\n"
696
697                         "show port meter cap (port_id)\n"
698                         "    Show port meter capability information\n\n"
699
700                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
701                         "    meter profile add - srtcm rfc 2697\n\n"
702
703                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
704                         "    meter profile add - trtcm rfc 2698\n\n"
705
706                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
707                         "    meter profile add - trtcm rfc 4115\n\n"
708
709                         "del port meter profile (port_id) (profile_id)\n"
710                         "    meter profile delete\n\n"
711
712                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
713                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
714                         "(dscp_tbl_entry63)]\n"
715                         "    meter create\n\n"
716
717                         "enable port meter (port_id) (mtr_id)\n"
718                         "    meter enable\n\n"
719
720                         "disable port meter (port_id) (mtr_id)\n"
721                         "    meter disable\n\n"
722
723                         "del port meter (port_id) (mtr_id)\n"
724                         "    meter delete\n\n"
725
726                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
727                         "y_actions (actions) r_actions (actions)\n"
728                         "    meter policy add\n\n"
729
730                         "del port meter policy (port_id) (policy_id)\n"
731                         "    meter policy delete\n\n"
732
733                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
734                         "    meter update meter profile\n\n"
735
736                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
737                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
738                         "    update meter dscp table entries\n\n"
739
740                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
741                         "(action0) [(action1) (action2)]\n"
742                         "    meter update policer action\n\n"
743
744                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
745                         "    meter update stats\n\n"
746
747                         "show port (port_id) queue-region\n"
748                         "    show all queue region related configuration info\n\n"
749
750                         "set port (port_id) fec_mode auto|off|rs|baser\n"
751                         "    set fec mode for a specific port\n\n"
752
753                         , list_pkt_forwarding_modes()
754                 );
755         }
756
757         if (show_all || !strcmp(res->section, "ports")) {
758
759                 cmdline_printf(
760                         cl,
761                         "\n"
762                         "Port Operations:\n"
763                         "----------------\n\n"
764
765                         "port start (port_id|all)\n"
766                         "    Start all ports or port_id.\n\n"
767
768                         "port stop (port_id|all)\n"
769                         "    Stop all ports or port_id.\n\n"
770
771                         "port close (port_id|all)\n"
772                         "    Close all ports or port_id.\n\n"
773
774                         "port reset (port_id|all)\n"
775                         "    Reset all ports or port_id.\n\n"
776
777                         "port attach (ident)\n"
778                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
779
780                         "port detach (port_id)\n"
781                         "    Detach physical or virtual dev by port_id\n\n"
782
783                         "port config (port_id|all)"
784                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
785                         " duplex (half|full|auto)\n"
786                         "    Set speed and duplex for all ports or port_id\n\n"
787
788                         "port config (port_id|all) loopback (mode)\n"
789                         "    Set loopback mode for all ports or port_id\n\n"
790
791                         "port config all (rxq|txq|rxd|txd) (value)\n"
792                         "    Set number for rxq/txq/rxd/txd.\n\n"
793
794                         "port config all max-pkt-len (value)\n"
795                         "    Set the max packet length.\n\n"
796
797                         "port config all max-lro-pkt-size (value)\n"
798                         "    Set the max LRO aggregated packet size.\n\n"
799
800                         "port config all drop-en (on|off)\n"
801                         "    Enable or disable packet drop on all RX queues of all ports when no "
802                         "receive buffers available.\n\n"
803
804                         "port config all rss (all|default|ip|tcp|udp|sctp|"
805                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|"
806                         "none|level-default|level-outer|level-inner|<flowtype_id>)\n"
807                         "    Set the RSS mode.\n\n"
808
809                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
810                         "    Set the RSS redirection table.\n\n"
811
812                         "port config (port_id) dcb vt (on|off) (traffic_class)"
813                         " pfc (on|off)\n"
814                         "    Set the DCB mode.\n\n"
815
816                         "port config all burst (value)\n"
817                         "    Set the number of packets per burst.\n\n"
818
819                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
820                         " (value)\n"
821                         "    Set the ring prefetch/host/writeback threshold"
822                         " for tx/rx queue.\n\n"
823
824                         "port config all (txfreet|txrst|rxfreet) (value)\n"
825                         "    Set free threshold for rx/tx, or set"
826                         " tx rs bit threshold.\n\n"
827                         "port config mtu X value\n"
828                         "    Set the MTU of port X to a given value\n\n"
829
830                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
831                         "    Set a rx/tx queue's ring size configuration, the new"
832                         " value will take effect after command that (re-)start the port"
833                         " or command that setup the specific queue\n\n"
834
835                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
836                         "    Start/stop a rx/tx queue of port X. Only take effect"
837                         " when port X is started\n\n"
838
839                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
840                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
841                         " take effect when port X is stopped.\n\n"
842
843                         "port (port_id) (rxq|txq) (queue_id) setup\n"
844                         "    Setup a rx/tx queue of port X.\n\n"
845
846                         "port config (port_id) pctype mapping reset\n"
847                         "    Reset flow type to pctype mapping on a port\n\n"
848
849                         "port config (port_id) pctype mapping update"
850                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
851                         "    Update a flow type to pctype mapping item on a port\n\n"
852
853                         "port config (port_id) pctype (pctype_id) hash_inset|"
854                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
855                         " (field_idx)\n"
856                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
857
858                         "port config (port_id) pctype (pctype_id) hash_inset|"
859                         "fdir_inset|fdir_flx_inset clear all"
860                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
861
862                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
863                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
864
865                         "port config <port_id> rx_offload vlan_strip|"
866                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
867                         "outer_ipv4_cksum|macsec_strip|header_split|"
868                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
869                         "buffer_split|timestamp|security|keep_crc on|off\n"
870                         "     Enable or disable a per port Rx offloading"
871                         " on all Rx queues of a port\n\n"
872
873                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
874                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
875                         "outer_ipv4_cksum|macsec_strip|header_split|"
876                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
877                         "buffer_split|timestamp|security|keep_crc on|off\n"
878                         "    Enable or disable a per queue Rx offloading"
879                         " only on a specific Rx queue\n\n"
880
881                         "port config (port_id) tx_offload vlan_insert|"
882                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
883                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
884                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
885                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
886                         "security on|off\n"
887                         "    Enable or disable a per port Tx offloading"
888                         " on all Tx queues of a port\n\n"
889
890                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
891                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
892                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
893                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
894                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
895                         " on|off\n"
896                         "    Enable or disable a per queue Tx offloading"
897                         " only on a specific Tx queue\n\n"
898
899                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
900                         "    Load an eBPF program as a callback"
901                         " for particular RX/TX queue\n\n"
902
903                         "bpf-unload rx|tx (port) (queue)\n"
904                         "    Unload previously loaded eBPF program"
905                         " for particular RX/TX queue\n\n"
906
907                         "port config (port_id) tx_metadata (value)\n"
908                         "    Set Tx metadata value per port. Testpmd will add this value"
909                         " to any Tx packet sent from this port\n\n"
910
911                         "port config (port_id) dynf (name) set|clear\n"
912                         "    Register a dynf and Set/clear this flag on Tx. "
913                         "Testpmd will set this value to any Tx packet "
914                         "sent from this port\n\n"
915
916                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
917                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
918                 );
919         }
920
921         if (show_all || !strcmp(res->section, "registers")) {
922
923                 cmdline_printf(
924                         cl,
925                         "\n"
926                         "Registers:\n"
927                         "----------\n\n"
928
929                         "read reg (port_id) (address)\n"
930                         "    Display value of a port register.\n\n"
931
932                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
933                         "    Display a port register bit field.\n\n"
934
935                         "read regbit (port_id) (address) (bit_x)\n"
936                         "    Display a single port register bit.\n\n"
937
938                         "write reg (port_id) (address) (value)\n"
939                         "    Set value of a port register.\n\n"
940
941                         "write regfield (port_id) (address) (bit_x) (bit_y)"
942                         " (value)\n"
943                         "    Set bit field of a port register.\n\n"
944
945                         "write regbit (port_id) (address) (bit_x) (value)\n"
946                         "    Set single bit value of a port register.\n\n"
947                 );
948         }
949         if (show_all || !strcmp(res->section, "filters")) {
950
951                 cmdline_printf(
952                         cl,
953                         "\n"
954                         "filters:\n"
955                         "--------\n\n"
956
957 #ifdef RTE_NET_I40E
958                         "flow_director_filter (port_id) mode raw (add|del|update)"
959                         " flow (flow_id) (drop|fwd) queue (queue_id)"
960                         " fd_id (fd_id_value) packet (packet file name)\n"
961                         "    Add/Del a raw type flow director filter.\n\n"
962 #endif
963
964                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
965                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
966                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
967                         "    Set flow director IP mask.\n\n"
968
969                         "flow_director_mask (port_id) mode MAC-VLAN"
970                         " vlan (vlan_value)\n"
971                         "    Set flow director MAC-VLAN mask.\n\n"
972
973                         "flow_director_mask (port_id) mode Tunnel"
974                         " vlan (vlan_value) mac (mac_value)"
975                         " tunnel-type (tunnel_type_value)"
976                         " tunnel-id (tunnel_id_value)\n"
977                         "    Set flow director Tunnel mask.\n\n"
978
979                         "flow_director_flex_payload (port_id)"
980                         " (raw|l2|l3|l4) (config)\n"
981                         "    Configure flex payload selection.\n\n"
982
983                         "flow validate {port_id}"
984                         " [group {group_id}] [priority {level}]"
985                         " [ingress] [egress]"
986                         " pattern {item} [/ {item} [...]] / end"
987                         " actions {action} [/ {action} [...]] / end\n"
988                         "    Check whether a flow rule can be created.\n\n"
989
990                         "flow create {port_id}"
991                         " [group {group_id}] [priority {level}]"
992                         " [ingress] [egress]"
993                         " pattern {item} [/ {item} [...]] / end"
994                         " actions {action} [/ {action} [...]] / end\n"
995                         "    Create a flow rule.\n\n"
996
997                         "flow destroy {port_id} rule {rule_id} [...]\n"
998                         "    Destroy specific flow rules.\n\n"
999
1000                         "flow flush {port_id}\n"
1001                         "    Destroy all flow rules.\n\n"
1002
1003                         "flow query {port_id} {rule_id} {action}\n"
1004                         "    Query an existing flow rule.\n\n"
1005
1006                         "flow list {port_id} [group {group_id}] [...]\n"
1007                         "    List existing flow rules sorted by priority,"
1008                         " filtered by group identifiers.\n\n"
1009
1010                         "flow isolate {port_id} {boolean}\n"
1011                         "    Restrict ingress traffic to the defined"
1012                         " flow rules\n\n"
1013
1014                         "flow aged {port_id} [destroy]\n"
1015                         "    List and destroy aged flows"
1016                         " flow rules\n\n"
1017
1018                         "flow indirect_action {port_id} create"
1019                         " [action_id {indirect_action_id}]"
1020                         " [ingress] [egress]"
1021                         " action {action} / end\n"
1022                         "    Create indirect action.\n\n"
1023
1024                         "flow indirect_action {port_id} update"
1025                         " {indirect_action_id} action {action} / end\n"
1026                         "    Update indirect action.\n\n"
1027
1028                         "flow indirect_action {port_id} destroy"
1029                         " action_id {indirect_action_id} [...]\n"
1030                         "    Destroy specific indirect actions.\n\n"
1031
1032                         "flow indirect_action {port_id} query"
1033                         " {indirect_action_id}\n"
1034                         "    Query an existing indirect action.\n\n"
1035
1036                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1037                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1038                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1039                         "       Configure the VXLAN encapsulation for flows.\n\n"
1040
1041                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1042                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1043                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1044                         " eth-dst (eth-dst)\n"
1045                         "       Configure the VXLAN encapsulation for flows.\n\n"
1046
1047                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1048                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1049                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1050                         " eth-dst (eth-dst)\n"
1051                         "       Configure the VXLAN encapsulation for flows.\n\n"
1052
1053                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1054                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1055                         " (eth-dst)\n"
1056                         "       Configure the NVGRE encapsulation for flows.\n\n"
1057
1058                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1059                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1060                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1061                         "       Configure the NVGRE encapsulation for flows.\n\n"
1062
1063                         "set raw_encap {flow items}\n"
1064                         "       Configure the encapsulation with raw data.\n\n"
1065
1066                         "set raw_decap {flow items}\n"
1067                         "       Configure the decapsulation with raw data.\n\n"
1068
1069                 );
1070         }
1071
1072         if (show_all || !strcmp(res->section, "traffic_management")) {
1073                 cmdline_printf(
1074                         cl,
1075                         "\n"
1076                         "Traffic Management:\n"
1077                         "--------------\n"
1078                         "show port tm cap (port_id)\n"
1079                         "       Display the port TM capability.\n\n"
1080
1081                         "show port tm level cap (port_id) (level_id)\n"
1082                         "       Display the port TM hierarchical level capability.\n\n"
1083
1084                         "show port tm node cap (port_id) (node_id)\n"
1085                         "       Display the port TM node capability.\n\n"
1086
1087                         "show port tm node type (port_id) (node_id)\n"
1088                         "       Display the port TM node type.\n\n"
1089
1090                         "show port tm node stats (port_id) (node_id) (clear)\n"
1091                         "       Display the port TM node stats.\n\n"
1092
1093                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1094                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1095                         " (packet_length_adjust) (packet_mode)\n"
1096                         "       Add port tm node private shaper profile.\n\n"
1097
1098                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1099                         "       Delete port tm node private shaper profile.\n\n"
1100
1101                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1102                         " (shaper_profile_id)\n"
1103                         "       Add/update port tm node shared shaper.\n\n"
1104
1105                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1106                         "       Delete port tm node shared shaper.\n\n"
1107
1108                         "set port tm node shaper profile (port_id) (node_id)"
1109                         " (shaper_profile_id)\n"
1110                         "       Set port tm node shaper profile.\n\n"
1111
1112                         "add port tm node wred profile (port_id) (wred_profile_id)"
1113                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1114                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1115                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1116                         "       Add port tm node wred profile.\n\n"
1117
1118                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1119                         "       Delete port tm node wred profile.\n\n"
1120
1121                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1122                         " (priority) (weight) (level_id) (shaper_profile_id)"
1123                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1124                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1125                         "       Add port tm nonleaf node.\n\n"
1126
1127                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1128                         " (priority) (weight) (level_id) (shaper_profile_id)"
1129                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1130                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1131                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1132
1133                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1134                         " (priority) (weight) (level_id) (shaper_profile_id)"
1135                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1136                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1137                         "       Add port tm leaf node.\n\n"
1138
1139                         "del port tm node (port_id) (node_id)\n"
1140                         "       Delete port tm node.\n\n"
1141
1142                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1143                         " (priority) (weight)\n"
1144                         "       Set port tm node parent.\n\n"
1145
1146                         "suspend port tm node (port_id) (node_id)"
1147                         "       Suspend tm node.\n\n"
1148
1149                         "resume port tm node (port_id) (node_id)"
1150                         "       Resume tm node.\n\n"
1151
1152                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1153                         "       Commit tm hierarchy.\n\n"
1154
1155                         "set port tm mark ip_ecn (port) (green) (yellow)"
1156                         " (red)\n"
1157                         "    Enables/Disables the traffic management marking"
1158                         " for IP ECN (Explicit Congestion Notification)"
1159                         " packets on a given port\n\n"
1160
1161                         "set port tm mark ip_dscp (port) (green) (yellow)"
1162                         " (red)\n"
1163                         "    Enables/Disables the traffic management marking"
1164                         " on the port for IP dscp packets\n\n"
1165
1166                         "set port tm mark vlan_dei (port) (green) (yellow)"
1167                         " (red)\n"
1168                         "    Enables/Disables the traffic management marking"
1169                         " on the port for VLAN packets with DEI enabled\n\n"
1170                 );
1171         }
1172
1173         if (show_all || !strcmp(res->section, "devices")) {
1174                 cmdline_printf(
1175                         cl,
1176                         "\n"
1177                         "Device Operations:\n"
1178                         "--------------\n"
1179                         "device detach (identifier)\n"
1180                         "       Detach device by identifier.\n\n"
1181                 );
1182         }
1183
1184         if (show_all || !strcmp(res->section, "drivers")) {
1185                 struct testpmd_driver_commands *c;
1186                 unsigned int i;
1187
1188                 cmdline_printf(
1189                         cl,
1190                         "\n"
1191                         "Driver specific:\n"
1192                         "----------------\n"
1193                 );
1194                 TAILQ_FOREACH(c, &driver_commands_head, next) {
1195                         for (i = 0; c->commands[i].ctx != NULL; i++)
1196                                 cmdline_printf(cl, "%s\n", c->commands[i].help);
1197                 }
1198         }
1199 }
1200
1201 static cmdline_parse_token_string_t cmd_help_long_help =
1202         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1203
1204 static cmdline_parse_token_string_t cmd_help_long_section =
1205         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1206                 "all#control#display#config#ports#registers#"
1207                 "filters#traffic_management#devices#drivers");
1208
1209 static cmdline_parse_inst_t cmd_help_long = {
1210         .f = cmd_help_long_parsed,
1211         .data = NULL,
1212         .help_str = "help all|control|display|config|ports|register|"
1213                 "filters|traffic_management|devices|drivers: "
1214                 "Show help",
1215         .tokens = {
1216                 (void *)&cmd_help_long_help,
1217                 (void *)&cmd_help_long_section,
1218                 NULL,
1219         },
1220 };
1221
1222
1223 /* *** start/stop/close all ports *** */
1224 struct cmd_operate_port_result {
1225         cmdline_fixed_string_t keyword;
1226         cmdline_fixed_string_t name;
1227         cmdline_fixed_string_t value;
1228 };
1229
1230 static void cmd_operate_port_parsed(void *parsed_result,
1231                                 __rte_unused struct cmdline *cl,
1232                                 __rte_unused void *data)
1233 {
1234         struct cmd_operate_port_result *res = parsed_result;
1235
1236         if (!strcmp(res->name, "start"))
1237                 start_port(RTE_PORT_ALL);
1238         else if (!strcmp(res->name, "stop"))
1239                 stop_port(RTE_PORT_ALL);
1240         else if (!strcmp(res->name, "close"))
1241                 close_port(RTE_PORT_ALL);
1242         else if (!strcmp(res->name, "reset"))
1243                 reset_port(RTE_PORT_ALL);
1244         else
1245                 fprintf(stderr, "Unknown parameter\n");
1246 }
1247
1248 static cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1249         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1250                                                                 "port");
1251 static cmdline_parse_token_string_t cmd_operate_port_all_port =
1252         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1253                                                 "start#stop#close#reset");
1254 static cmdline_parse_token_string_t cmd_operate_port_all_all =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1256
1257 static cmdline_parse_inst_t cmd_operate_port = {
1258         .f = cmd_operate_port_parsed,
1259         .data = NULL,
1260         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1261         .tokens = {
1262                 (void *)&cmd_operate_port_all_cmd,
1263                 (void *)&cmd_operate_port_all_port,
1264                 (void *)&cmd_operate_port_all_all,
1265                 NULL,
1266         },
1267 };
1268
1269 /* *** start/stop/close specific port *** */
1270 struct cmd_operate_specific_port_result {
1271         cmdline_fixed_string_t keyword;
1272         cmdline_fixed_string_t name;
1273         uint8_t value;
1274 };
1275
1276 static void cmd_operate_specific_port_parsed(void *parsed_result,
1277                         __rte_unused struct cmdline *cl,
1278                                 __rte_unused void *data)
1279 {
1280         struct cmd_operate_specific_port_result *res = parsed_result;
1281
1282         if (!strcmp(res->name, "start"))
1283                 start_port(res->value);
1284         else if (!strcmp(res->name, "stop"))
1285                 stop_port(res->value);
1286         else if (!strcmp(res->name, "close"))
1287                 close_port(res->value);
1288         else if (!strcmp(res->name, "reset"))
1289                 reset_port(res->value);
1290         else
1291                 fprintf(stderr, "Unknown parameter\n");
1292 }
1293
1294 static cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1295         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1296                                                         keyword, "port");
1297 static cmdline_parse_token_string_t cmd_operate_specific_port_port =
1298         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1299                                                 name, "start#stop#close#reset");
1300 static cmdline_parse_token_num_t cmd_operate_specific_port_id =
1301         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1302                                                         value, RTE_UINT8);
1303
1304 static cmdline_parse_inst_t cmd_operate_specific_port = {
1305         .f = cmd_operate_specific_port_parsed,
1306         .data = NULL,
1307         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1308         .tokens = {
1309                 (void *)&cmd_operate_specific_port_cmd,
1310                 (void *)&cmd_operate_specific_port_port,
1311                 (void *)&cmd_operate_specific_port_id,
1312                 NULL,
1313         },
1314 };
1315
1316 /* *** enable port setup (after attach) via iterator or event *** */
1317 struct cmd_set_port_setup_on_result {
1318         cmdline_fixed_string_t set;
1319         cmdline_fixed_string_t port;
1320         cmdline_fixed_string_t setup;
1321         cmdline_fixed_string_t on;
1322         cmdline_fixed_string_t mode;
1323 };
1324
1325 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1326                                 __rte_unused struct cmdline *cl,
1327                                 __rte_unused void *data)
1328 {
1329         struct cmd_set_port_setup_on_result *res = parsed_result;
1330
1331         if (strcmp(res->mode, "event") == 0)
1332                 setup_on_probe_event = true;
1333         else if (strcmp(res->mode, "iterator") == 0)
1334                 setup_on_probe_event = false;
1335         else
1336                 fprintf(stderr, "Unknown mode\n");
1337 }
1338
1339 static cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1340         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1341                         set, "set");
1342 static cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1343         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1344                         port, "port");
1345 static cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1346         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1347                         setup, "setup");
1348 static cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1349         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1350                         on, "on");
1351 static cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1352         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1353                         mode, "iterator#event");
1354
1355 static cmdline_parse_inst_t cmd_set_port_setup_on = {
1356         .f = cmd_set_port_setup_on_parsed,
1357         .data = NULL,
1358         .help_str = "set port setup on iterator|event",
1359         .tokens = {
1360                 (void *)&cmd_set_port_setup_on_set,
1361                 (void *)&cmd_set_port_setup_on_port,
1362                 (void *)&cmd_set_port_setup_on_setup,
1363                 (void *)&cmd_set_port_setup_on_on,
1364                 (void *)&cmd_set_port_setup_on_mode,
1365                 NULL,
1366         },
1367 };
1368
1369 /* *** attach a specified port *** */
1370 struct cmd_operate_attach_port_result {
1371         cmdline_fixed_string_t port;
1372         cmdline_fixed_string_t keyword;
1373         cmdline_multi_string_t identifier;
1374 };
1375
1376 static void cmd_operate_attach_port_parsed(void *parsed_result,
1377                                 __rte_unused struct cmdline *cl,
1378                                 __rte_unused void *data)
1379 {
1380         struct cmd_operate_attach_port_result *res = parsed_result;
1381
1382         if (!strcmp(res->keyword, "attach"))
1383                 attach_port(res->identifier);
1384         else
1385                 fprintf(stderr, "Unknown parameter\n");
1386 }
1387
1388 static cmdline_parse_token_string_t cmd_operate_attach_port_port =
1389         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1390                         port, "port");
1391 static cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1392         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1393                         keyword, "attach");
1394 static cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1395         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1396                         identifier, TOKEN_STRING_MULTI);
1397
1398 static cmdline_parse_inst_t cmd_operate_attach_port = {
1399         .f = cmd_operate_attach_port_parsed,
1400         .data = NULL,
1401         .help_str = "port attach <identifier>: "
1402                 "(identifier: pci address or virtual dev name)",
1403         .tokens = {
1404                 (void *)&cmd_operate_attach_port_port,
1405                 (void *)&cmd_operate_attach_port_keyword,
1406                 (void *)&cmd_operate_attach_port_identifier,
1407                 NULL,
1408         },
1409 };
1410
1411 /* *** detach a specified port *** */
1412 struct cmd_operate_detach_port_result {
1413         cmdline_fixed_string_t port;
1414         cmdline_fixed_string_t keyword;
1415         portid_t port_id;
1416 };
1417
1418 static void cmd_operate_detach_port_parsed(void *parsed_result,
1419                                 __rte_unused struct cmdline *cl,
1420                                 __rte_unused void *data)
1421 {
1422         struct cmd_operate_detach_port_result *res = parsed_result;
1423
1424         if (!strcmp(res->keyword, "detach")) {
1425                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1426                 detach_port_device(res->port_id);
1427         } else {
1428                 fprintf(stderr, "Unknown parameter\n");
1429         }
1430 }
1431
1432 static cmdline_parse_token_string_t cmd_operate_detach_port_port =
1433         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1434                         port, "port");
1435 static cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1436         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1437                         keyword, "detach");
1438 static cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1439         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1440                         port_id, RTE_UINT16);
1441
1442 static cmdline_parse_inst_t cmd_operate_detach_port = {
1443         .f = cmd_operate_detach_port_parsed,
1444         .data = NULL,
1445         .help_str = "port detach <port_id>",
1446         .tokens = {
1447                 (void *)&cmd_operate_detach_port_port,
1448                 (void *)&cmd_operate_detach_port_keyword,
1449                 (void *)&cmd_operate_detach_port_port_id,
1450                 NULL,
1451         },
1452 };
1453
1454 /* *** detach device by identifier *** */
1455 struct cmd_operate_detach_device_result {
1456         cmdline_fixed_string_t device;
1457         cmdline_fixed_string_t keyword;
1458         cmdline_fixed_string_t identifier;
1459 };
1460
1461 static void cmd_operate_detach_device_parsed(void *parsed_result,
1462                                 __rte_unused struct cmdline *cl,
1463                                 __rte_unused void *data)
1464 {
1465         struct cmd_operate_detach_device_result *res = parsed_result;
1466
1467         if (!strcmp(res->keyword, "detach"))
1468                 detach_devargs(res->identifier);
1469         else
1470                 fprintf(stderr, "Unknown parameter\n");
1471 }
1472
1473 static cmdline_parse_token_string_t cmd_operate_detach_device_device =
1474         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1475                         device, "device");
1476 static cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1477         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1478                         keyword, "detach");
1479 static cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1480         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1481                         identifier, NULL);
1482
1483 static cmdline_parse_inst_t cmd_operate_detach_device = {
1484         .f = cmd_operate_detach_device_parsed,
1485         .data = NULL,
1486         .help_str = "device detach <identifier>:"
1487                 "(identifier: pci address or virtual dev name)",
1488         .tokens = {
1489                 (void *)&cmd_operate_detach_device_device,
1490                 (void *)&cmd_operate_detach_device_keyword,
1491                 (void *)&cmd_operate_detach_device_identifier,
1492                 NULL,
1493         },
1494 };
1495 /* *** configure speed for all ports *** */
1496 struct cmd_config_speed_all {
1497         cmdline_fixed_string_t port;
1498         cmdline_fixed_string_t keyword;
1499         cmdline_fixed_string_t all;
1500         cmdline_fixed_string_t item1;
1501         cmdline_fixed_string_t item2;
1502         cmdline_fixed_string_t value1;
1503         cmdline_fixed_string_t value2;
1504 };
1505
1506 static int
1507 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1508 {
1509
1510         int duplex;
1511
1512         if (!strcmp(duplexstr, "half")) {
1513                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
1514         } else if (!strcmp(duplexstr, "full")) {
1515                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1516         } else if (!strcmp(duplexstr, "auto")) {
1517                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1518         } else {
1519                 fprintf(stderr, "Unknown duplex parameter\n");
1520                 return -1;
1521         }
1522
1523         if (!strcmp(speedstr, "10")) {
1524                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1525                                 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1526         } else if (!strcmp(speedstr, "100")) {
1527                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1528                                 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1529         } else {
1530                 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1531                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1532                         return -1;
1533                 }
1534                 if (!strcmp(speedstr, "1000")) {
1535                         *speed = RTE_ETH_LINK_SPEED_1G;
1536                 } else if (!strcmp(speedstr, "10000")) {
1537                         *speed = RTE_ETH_LINK_SPEED_10G;
1538                 } else if (!strcmp(speedstr, "25000")) {
1539                         *speed = RTE_ETH_LINK_SPEED_25G;
1540                 } else if (!strcmp(speedstr, "40000")) {
1541                         *speed = RTE_ETH_LINK_SPEED_40G;
1542                 } else if (!strcmp(speedstr, "50000")) {
1543                         *speed = RTE_ETH_LINK_SPEED_50G;
1544                 } else if (!strcmp(speedstr, "100000")) {
1545                         *speed = RTE_ETH_LINK_SPEED_100G;
1546                 } else if (!strcmp(speedstr, "200000")) {
1547                         *speed = RTE_ETH_LINK_SPEED_200G;
1548                 } else if (!strcmp(speedstr, "auto")) {
1549                         *speed = RTE_ETH_LINK_SPEED_AUTONEG;
1550                 } else {
1551                         fprintf(stderr, "Unknown speed parameter\n");
1552                         return -1;
1553                 }
1554         }
1555
1556         if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1557                 *speed |= RTE_ETH_LINK_SPEED_FIXED;
1558
1559         return 0;
1560 }
1561
1562 static void
1563 cmd_config_speed_all_parsed(void *parsed_result,
1564                         __rte_unused struct cmdline *cl,
1565                         __rte_unused void *data)
1566 {
1567         struct cmd_config_speed_all *res = parsed_result;
1568         uint32_t link_speed;
1569         portid_t pid;
1570
1571         if (!all_ports_stopped()) {
1572                 fprintf(stderr, "Please stop all ports first\n");
1573                 return;
1574         }
1575
1576         if (parse_and_check_speed_duplex(res->value1, res->value2,
1577                         &link_speed) < 0)
1578                 return;
1579
1580         RTE_ETH_FOREACH_DEV(pid) {
1581                 ports[pid].dev_conf.link_speeds = link_speed;
1582         }
1583
1584         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1585 }
1586
1587 static cmdline_parse_token_string_t cmd_config_speed_all_port =
1588         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1589 static cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1590         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1591                                                         "config");
1592 static cmdline_parse_token_string_t cmd_config_speed_all_all =
1593         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1594 static cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1595         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1596 static cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1597         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1598                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1599 static cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1600         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1601 static cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1602         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1603                                                 "half#full#auto");
1604
1605 static cmdline_parse_inst_t cmd_config_speed_all = {
1606         .f = cmd_config_speed_all_parsed,
1607         .data = NULL,
1608         .help_str = "port config all speed "
1609                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1610                                                         "half|full|auto",
1611         .tokens = {
1612                 (void *)&cmd_config_speed_all_port,
1613                 (void *)&cmd_config_speed_all_keyword,
1614                 (void *)&cmd_config_speed_all_all,
1615                 (void *)&cmd_config_speed_all_item1,
1616                 (void *)&cmd_config_speed_all_value1,
1617                 (void *)&cmd_config_speed_all_item2,
1618                 (void *)&cmd_config_speed_all_value2,
1619                 NULL,
1620         },
1621 };
1622
1623 /* *** configure speed for specific port *** */
1624 struct cmd_config_speed_specific {
1625         cmdline_fixed_string_t port;
1626         cmdline_fixed_string_t keyword;
1627         portid_t id;
1628         cmdline_fixed_string_t item1;
1629         cmdline_fixed_string_t item2;
1630         cmdline_fixed_string_t value1;
1631         cmdline_fixed_string_t value2;
1632 };
1633
1634 static void
1635 cmd_config_speed_specific_parsed(void *parsed_result,
1636                                 __rte_unused struct cmdline *cl,
1637                                 __rte_unused void *data)
1638 {
1639         struct cmd_config_speed_specific *res = parsed_result;
1640         uint32_t link_speed;
1641
1642         if (port_id_is_invalid(res->id, ENABLED_WARN))
1643                 return;
1644
1645         if (!port_is_stopped(res->id)) {
1646                 fprintf(stderr, "Please stop port %d first\n", res->id);
1647                 return;
1648         }
1649
1650         if (parse_and_check_speed_duplex(res->value1, res->value2,
1651                         &link_speed) < 0)
1652                 return;
1653
1654         ports[res->id].dev_conf.link_speeds = link_speed;
1655
1656         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1657 }
1658
1659
1660 static cmdline_parse_token_string_t cmd_config_speed_specific_port =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1662                                                                 "port");
1663 static cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1665                                                                 "config");
1666 static cmdline_parse_token_num_t cmd_config_speed_specific_id =
1667         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1668 static cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1669         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1670                                                                 "speed");
1671 static cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1673                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1674 static cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1675         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1676                                                                 "duplex");
1677 static cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1679                                                         "half#full#auto");
1680
1681 static cmdline_parse_inst_t cmd_config_speed_specific = {
1682         .f = cmd_config_speed_specific_parsed,
1683         .data = NULL,
1684         .help_str = "port config <port_id> speed "
1685                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1686                                                         "half|full|auto",
1687         .tokens = {
1688                 (void *)&cmd_config_speed_specific_port,
1689                 (void *)&cmd_config_speed_specific_keyword,
1690                 (void *)&cmd_config_speed_specific_id,
1691                 (void *)&cmd_config_speed_specific_item1,
1692                 (void *)&cmd_config_speed_specific_value1,
1693                 (void *)&cmd_config_speed_specific_item2,
1694                 (void *)&cmd_config_speed_specific_value2,
1695                 NULL,
1696         },
1697 };
1698
1699 /* *** configure loopback for all ports *** */
1700 struct cmd_config_loopback_all {
1701         cmdline_fixed_string_t port;
1702         cmdline_fixed_string_t keyword;
1703         cmdline_fixed_string_t all;
1704         cmdline_fixed_string_t item;
1705         uint32_t mode;
1706 };
1707
1708 static void
1709 cmd_config_loopback_all_parsed(void *parsed_result,
1710                         __rte_unused struct cmdline *cl,
1711                         __rte_unused void *data)
1712 {
1713         struct cmd_config_loopback_all *res = parsed_result;
1714         portid_t pid;
1715
1716         if (!all_ports_stopped()) {
1717                 fprintf(stderr, "Please stop all ports first\n");
1718                 return;
1719         }
1720
1721         RTE_ETH_FOREACH_DEV(pid) {
1722                 ports[pid].dev_conf.lpbk_mode = res->mode;
1723         }
1724
1725         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1726 }
1727
1728 static cmdline_parse_token_string_t cmd_config_loopback_all_port =
1729         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1730 static cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1732                                                         "config");
1733 static cmdline_parse_token_string_t cmd_config_loopback_all_all =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1735 static cmdline_parse_token_string_t cmd_config_loopback_all_item =
1736         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1737                                                         "loopback");
1738 static cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1739         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1740
1741 static cmdline_parse_inst_t cmd_config_loopback_all = {
1742         .f = cmd_config_loopback_all_parsed,
1743         .data = NULL,
1744         .help_str = "port config all loopback <mode>",
1745         .tokens = {
1746                 (void *)&cmd_config_loopback_all_port,
1747                 (void *)&cmd_config_loopback_all_keyword,
1748                 (void *)&cmd_config_loopback_all_all,
1749                 (void *)&cmd_config_loopback_all_item,
1750                 (void *)&cmd_config_loopback_all_mode,
1751                 NULL,
1752         },
1753 };
1754
1755 /* *** configure loopback for specific port *** */
1756 struct cmd_config_loopback_specific {
1757         cmdline_fixed_string_t port;
1758         cmdline_fixed_string_t keyword;
1759         uint16_t port_id;
1760         cmdline_fixed_string_t item;
1761         uint32_t mode;
1762 };
1763
1764 static void
1765 cmd_config_loopback_specific_parsed(void *parsed_result,
1766                                 __rte_unused struct cmdline *cl,
1767                                 __rte_unused void *data)
1768 {
1769         struct cmd_config_loopback_specific *res = parsed_result;
1770
1771         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1772                 return;
1773
1774         if (!port_is_stopped(res->port_id)) {
1775                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1776                 return;
1777         }
1778
1779         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1780
1781         cmd_reconfig_device_queue(res->port_id, 1, 1);
1782 }
1783
1784
1785 static cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1787                                                                 "port");
1788 static cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1790                                                                 "config");
1791 static cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1792         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1793                                                                 RTE_UINT16);
1794 static cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1795         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1796                                                                 "loopback");
1797 static cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1798         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1799                               RTE_UINT32);
1800
1801 static cmdline_parse_inst_t cmd_config_loopback_specific = {
1802         .f = cmd_config_loopback_specific_parsed,
1803         .data = NULL,
1804         .help_str = "port config <port_id> loopback <mode>",
1805         .tokens = {
1806                 (void *)&cmd_config_loopback_specific_port,
1807                 (void *)&cmd_config_loopback_specific_keyword,
1808                 (void *)&cmd_config_loopback_specific_id,
1809                 (void *)&cmd_config_loopback_specific_item,
1810                 (void *)&cmd_config_loopback_specific_mode,
1811                 NULL,
1812         },
1813 };
1814
1815 /* *** configure txq/rxq, txd/rxd *** */
1816 struct cmd_config_rx_tx {
1817         cmdline_fixed_string_t port;
1818         cmdline_fixed_string_t keyword;
1819         cmdline_fixed_string_t all;
1820         cmdline_fixed_string_t name;
1821         uint16_t value;
1822 };
1823
1824 static void
1825 cmd_config_rx_tx_parsed(void *parsed_result,
1826                         __rte_unused struct cmdline *cl,
1827                         __rte_unused void *data)
1828 {
1829         struct cmd_config_rx_tx *res = parsed_result;
1830
1831         if (!all_ports_stopped()) {
1832                 fprintf(stderr, "Please stop all ports first\n");
1833                 return;
1834         }
1835         if (!strcmp(res->name, "rxq")) {
1836                 if (!res->value && !nb_txq) {
1837                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1838                         return;
1839                 }
1840                 if (check_nb_rxq(res->value) != 0)
1841                         return;
1842                 nb_rxq = res->value;
1843         }
1844         else if (!strcmp(res->name, "txq")) {
1845                 if (!res->value && !nb_rxq) {
1846                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1847                         return;
1848                 }
1849                 if (check_nb_txq(res->value) != 0)
1850                         return;
1851                 nb_txq = res->value;
1852         }
1853         else if (!strcmp(res->name, "rxd")) {
1854                 if (check_nb_rxd(res->value) != 0)
1855                         return;
1856                 nb_rxd = res->value;
1857         } else if (!strcmp(res->name, "txd")) {
1858                 if (check_nb_txd(res->value) != 0)
1859                         return;
1860
1861                 nb_txd = res->value;
1862         } else {
1863                 fprintf(stderr, "Unknown parameter\n");
1864                 return;
1865         }
1866
1867         fwd_config_setup();
1868
1869         init_port_config();
1870
1871         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1872 }
1873
1874 static cmdline_parse_token_string_t cmd_config_rx_tx_port =
1875         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1876 static cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1877         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1878 static cmdline_parse_token_string_t cmd_config_rx_tx_all =
1879         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1880 static cmdline_parse_token_string_t cmd_config_rx_tx_name =
1881         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1882                                                 "rxq#txq#rxd#txd");
1883 static cmdline_parse_token_num_t cmd_config_rx_tx_value =
1884         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1885
1886 static cmdline_parse_inst_t cmd_config_rx_tx = {
1887         .f = cmd_config_rx_tx_parsed,
1888         .data = NULL,
1889         .help_str = "port config all rxq|txq|rxd|txd <value>",
1890         .tokens = {
1891                 (void *)&cmd_config_rx_tx_port,
1892                 (void *)&cmd_config_rx_tx_keyword,
1893                 (void *)&cmd_config_rx_tx_all,
1894                 (void *)&cmd_config_rx_tx_name,
1895                 (void *)&cmd_config_rx_tx_value,
1896                 NULL,
1897         },
1898 };
1899
1900 /* *** config max packet length *** */
1901 struct cmd_config_max_pkt_len_result {
1902         cmdline_fixed_string_t port;
1903         cmdline_fixed_string_t keyword;
1904         cmdline_fixed_string_t all;
1905         cmdline_fixed_string_t name;
1906         uint32_t value;
1907 };
1908
1909 static void
1910 cmd_config_max_pkt_len_parsed(void *parsed_result,
1911                                 __rte_unused struct cmdline *cl,
1912                                 __rte_unused void *data)
1913 {
1914         struct cmd_config_max_pkt_len_result *res = parsed_result;
1915         portid_t port_id;
1916         int ret;
1917
1918         if (strcmp(res->name, "max-pkt-len") != 0) {
1919                 printf("Unknown parameter\n");
1920                 return;
1921         }
1922
1923         if (!all_ports_stopped()) {
1924                 fprintf(stderr, "Please stop all ports first\n");
1925                 return;
1926         }
1927
1928         RTE_ETH_FOREACH_DEV(port_id) {
1929                 struct rte_port *port = &ports[port_id];
1930
1931                 if (res->value < RTE_ETHER_MIN_LEN) {
1932                         fprintf(stderr,
1933                                 "max-pkt-len can not be less than %d\n",
1934                                 RTE_ETHER_MIN_LEN);
1935                         return;
1936                 }
1937
1938                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1939                 if (ret != 0) {
1940                         fprintf(stderr,
1941                                 "rte_eth_dev_info_get() failed for port %u\n",
1942                                 port_id);
1943                         return;
1944                 }
1945
1946                 update_mtu_from_frame_size(port_id, res->value);
1947         }
1948
1949         init_port_config();
1950
1951         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1952 }
1953
1954 static cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1956                                                                 "port");
1957 static cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1959                                                                 "config");
1960 static cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1962                                                                 "all");
1963 static cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1965                                                                 "max-pkt-len");
1966 static cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1967         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1968                                                                 RTE_UINT32);
1969
1970 static cmdline_parse_inst_t cmd_config_max_pkt_len = {
1971         .f = cmd_config_max_pkt_len_parsed,
1972         .data = NULL,
1973         .help_str = "port config all max-pkt-len <value>",
1974         .tokens = {
1975                 (void *)&cmd_config_max_pkt_len_port,
1976                 (void *)&cmd_config_max_pkt_len_keyword,
1977                 (void *)&cmd_config_max_pkt_len_all,
1978                 (void *)&cmd_config_max_pkt_len_name,
1979                 (void *)&cmd_config_max_pkt_len_value,
1980                 NULL,
1981         },
1982 };
1983
1984 /* *** config max LRO aggregated packet size *** */
1985 struct cmd_config_max_lro_pkt_size_result {
1986         cmdline_fixed_string_t port;
1987         cmdline_fixed_string_t keyword;
1988         cmdline_fixed_string_t all;
1989         cmdline_fixed_string_t name;
1990         uint32_t value;
1991 };
1992
1993 static void
1994 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1995                                 __rte_unused struct cmdline *cl,
1996                                 __rte_unused void *data)
1997 {
1998         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1999         portid_t pid;
2000
2001         if (!all_ports_stopped()) {
2002                 fprintf(stderr, "Please stop all ports first\n");
2003                 return;
2004         }
2005
2006         RTE_ETH_FOREACH_DEV(pid) {
2007                 struct rte_port *port = &ports[pid];
2008
2009                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2010                         if (res->value ==
2011                                         port->dev_conf.rxmode.max_lro_pkt_size)
2012                                 return;
2013
2014                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2015                 } else {
2016                         fprintf(stderr, "Unknown parameter\n");
2017                         return;
2018                 }
2019         }
2020
2021         init_port_config();
2022
2023         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2024 }
2025
2026 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2027         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2028                                  port, "port");
2029 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2031                                  keyword, "config");
2032 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2034                                  all, "all");
2035 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2037                                  name, "max-lro-pkt-size");
2038 static cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2039         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2040                               value, RTE_UINT32);
2041
2042 static cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2043         .f = cmd_config_max_lro_pkt_size_parsed,
2044         .data = NULL,
2045         .help_str = "port config all max-lro-pkt-size <value>",
2046         .tokens = {
2047                 (void *)&cmd_config_max_lro_pkt_size_port,
2048                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2049                 (void *)&cmd_config_max_lro_pkt_size_all,
2050                 (void *)&cmd_config_max_lro_pkt_size_name,
2051                 (void *)&cmd_config_max_lro_pkt_size_value,
2052                 NULL,
2053         },
2054 };
2055
2056 /* *** configure port MTU *** */
2057 struct cmd_config_mtu_result {
2058         cmdline_fixed_string_t port;
2059         cmdline_fixed_string_t keyword;
2060         cmdline_fixed_string_t mtu;
2061         portid_t port_id;
2062         uint16_t value;
2063 };
2064
2065 static void
2066 cmd_config_mtu_parsed(void *parsed_result,
2067                       __rte_unused struct cmdline *cl,
2068                       __rte_unused void *data)
2069 {
2070         struct cmd_config_mtu_result *res = parsed_result;
2071
2072         port_mtu_set(res->port_id, res->value);
2073 }
2074
2075 static cmdline_parse_token_string_t cmd_config_mtu_port =
2076         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2077                                  "port");
2078 static cmdline_parse_token_string_t cmd_config_mtu_keyword =
2079         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2080                                  "config");
2081 static cmdline_parse_token_string_t cmd_config_mtu_mtu =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2083                                  "mtu");
2084 static cmdline_parse_token_num_t cmd_config_mtu_port_id =
2085         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2086                                  RTE_UINT16);
2087 static cmdline_parse_token_num_t cmd_config_mtu_value =
2088         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2089                                  RTE_UINT16);
2090
2091 static cmdline_parse_inst_t cmd_config_mtu = {
2092         .f = cmd_config_mtu_parsed,
2093         .data = NULL,
2094         .help_str = "port config mtu <port_id> <value>",
2095         .tokens = {
2096                 (void *)&cmd_config_mtu_port,
2097                 (void *)&cmd_config_mtu_keyword,
2098                 (void *)&cmd_config_mtu_mtu,
2099                 (void *)&cmd_config_mtu_port_id,
2100                 (void *)&cmd_config_mtu_value,
2101                 NULL,
2102         },
2103 };
2104
2105 /* *** configure rx mode *** */
2106 struct cmd_config_rx_mode_flag {
2107         cmdline_fixed_string_t port;
2108         cmdline_fixed_string_t keyword;
2109         cmdline_fixed_string_t all;
2110         cmdline_fixed_string_t name;
2111         cmdline_fixed_string_t value;
2112 };
2113
2114 static void
2115 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2116                                 __rte_unused struct cmdline *cl,
2117                                 __rte_unused void *data)
2118 {
2119         struct cmd_config_rx_mode_flag *res = parsed_result;
2120
2121         if (!all_ports_stopped()) {
2122                 fprintf(stderr, "Please stop all ports first\n");
2123                 return;
2124         }
2125
2126         if (!strcmp(res->name, "drop-en")) {
2127                 if (!strcmp(res->value, "on"))
2128                         rx_drop_en = 1;
2129                 else if (!strcmp(res->value, "off"))
2130                         rx_drop_en = 0;
2131                 else {
2132                         fprintf(stderr, "Unknown parameter\n");
2133                         return;
2134                 }
2135         } else {
2136                 fprintf(stderr, "Unknown parameter\n");
2137                 return;
2138         }
2139
2140         init_port_config();
2141
2142         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2143 }
2144
2145 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2147 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2148         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2149                                                                 "config");
2150 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2151         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2152 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2154                                         "drop-en");
2155 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2157                                                         "on#off");
2158
2159 static cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2160         .f = cmd_config_rx_mode_flag_parsed,
2161         .data = NULL,
2162         .help_str = "port config all drop-en on|off",
2163         .tokens = {
2164                 (void *)&cmd_config_rx_mode_flag_port,
2165                 (void *)&cmd_config_rx_mode_flag_keyword,
2166                 (void *)&cmd_config_rx_mode_flag_all,
2167                 (void *)&cmd_config_rx_mode_flag_name,
2168                 (void *)&cmd_config_rx_mode_flag_value,
2169                 NULL,
2170         },
2171 };
2172
2173 /* *** configure rss *** */
2174 struct cmd_config_rss {
2175         cmdline_fixed_string_t port;
2176         cmdline_fixed_string_t keyword;
2177         cmdline_fixed_string_t all;
2178         cmdline_fixed_string_t name;
2179         cmdline_fixed_string_t value;
2180 };
2181
2182 static void
2183 cmd_config_rss_parsed(void *parsed_result,
2184                         __rte_unused struct cmdline *cl,
2185                         __rte_unused void *data)
2186 {
2187         struct cmd_config_rss *res = parsed_result;
2188         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2189         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2190         int use_default = 0;
2191         int all_updated = 1;
2192         int diag;
2193         uint16_t i;
2194         int ret;
2195
2196         if (!strcmp(res->value, "all"))
2197                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2198                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2199                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2200                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2201                         RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
2202         else if (!strcmp(res->value, "eth"))
2203                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2204         else if (!strcmp(res->value, "vlan"))
2205                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2206         else if (!strcmp(res->value, "ip"))
2207                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2208         else if (!strcmp(res->value, "udp"))
2209                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2210         else if (!strcmp(res->value, "tcp"))
2211                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2212         else if (!strcmp(res->value, "sctp"))
2213                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2214         else if (!strcmp(res->value, "ether"))
2215                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2216         else if (!strcmp(res->value, "port"))
2217                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2218         else if (!strcmp(res->value, "vxlan"))
2219                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2220         else if (!strcmp(res->value, "geneve"))
2221                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2222         else if (!strcmp(res->value, "nvgre"))
2223                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2224         else if (!strcmp(res->value, "l3-pre32"))
2225                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2226         else if (!strcmp(res->value, "l3-pre40"))
2227                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2228         else if (!strcmp(res->value, "l3-pre48"))
2229                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2230         else if (!strcmp(res->value, "l3-pre56"))
2231                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2232         else if (!strcmp(res->value, "l3-pre64"))
2233                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2234         else if (!strcmp(res->value, "l3-pre96"))
2235                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2236         else if (!strcmp(res->value, "l3-src-only"))
2237                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2238         else if (!strcmp(res->value, "l3-dst-only"))
2239                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2240         else if (!strcmp(res->value, "l4-src-only"))
2241                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2242         else if (!strcmp(res->value, "l4-dst-only"))
2243                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2244         else if (!strcmp(res->value, "l2-src-only"))
2245                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2246         else if (!strcmp(res->value, "l2-dst-only"))
2247                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2248         else if (!strcmp(res->value, "l2tpv3"))
2249                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2250         else if (!strcmp(res->value, "esp"))
2251                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2252         else if (!strcmp(res->value, "ah"))
2253                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2254         else if (!strcmp(res->value, "pfcp"))
2255                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2256         else if (!strcmp(res->value, "pppoe"))
2257                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2258         else if (!strcmp(res->value, "gtpu"))
2259                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2260         else if (!strcmp(res->value, "ecpri"))
2261                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2262         else if (!strcmp(res->value, "mpls"))
2263                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2264         else if (!strcmp(res->value, "ipv4-chksum"))
2265                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2266         else if (!strcmp(res->value, "l2tpv2"))
2267                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
2268         else if (!strcmp(res->value, "none"))
2269                 rss_conf.rss_hf = 0;
2270         else if (!strcmp(res->value, "level-default")) {
2271                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2272                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2273         } else if (!strcmp(res->value, "level-outer")) {
2274                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2275                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2276         } else if (!strcmp(res->value, "level-inner")) {
2277                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2278                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2279         } else if (!strcmp(res->value, "default"))
2280                 use_default = 1;
2281         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2282                                                 atoi(res->value) < 64)
2283                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2284         else {
2285                 fprintf(stderr, "Unknown parameter\n");
2286                 return;
2287         }
2288         rss_conf.rss_key = NULL;
2289         /* Update global configuration for RSS types. */
2290         RTE_ETH_FOREACH_DEV(i) {
2291                 struct rte_eth_rss_conf local_rss_conf;
2292
2293                 ret = eth_dev_info_get_print_err(i, &dev_info);
2294                 if (ret != 0)
2295                         return;
2296
2297                 if (use_default)
2298                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2299
2300                 local_rss_conf = rss_conf;
2301                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2302                         dev_info.flow_type_rss_offloads;
2303                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2304                         printf("Port %u modified RSS hash function based on hardware support,"
2305                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2306                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2307                 }
2308                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2309                 if (diag < 0) {
2310                         all_updated = 0;
2311                         fprintf(stderr,
2312                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2313                                 i, -diag, strerror(-diag));
2314                 }
2315         }
2316         if (all_updated && !use_default) {
2317                 rss_hf = rss_conf.rss_hf;
2318                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2319         }
2320 }
2321
2322 static cmdline_parse_token_string_t cmd_config_rss_port =
2323         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2324 static cmdline_parse_token_string_t cmd_config_rss_keyword =
2325         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2326 static cmdline_parse_token_string_t cmd_config_rss_all =
2327         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2328 static cmdline_parse_token_string_t cmd_config_rss_name =
2329         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2330 static cmdline_parse_token_string_t cmd_config_rss_value =
2331         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2332
2333 static cmdline_parse_inst_t cmd_config_rss = {
2334         .f = cmd_config_rss_parsed,
2335         .data = NULL,
2336         .help_str = "port config all rss "
2337                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2338                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
2339                 "none|level-default|level-outer|level-inner|<flowtype_id>",
2340         .tokens = {
2341                 (void *)&cmd_config_rss_port,
2342                 (void *)&cmd_config_rss_keyword,
2343                 (void *)&cmd_config_rss_all,
2344                 (void *)&cmd_config_rss_name,
2345                 (void *)&cmd_config_rss_value,
2346                 NULL,
2347         },
2348 };
2349
2350 /* *** configure rss hash key *** */
2351 struct cmd_config_rss_hash_key {
2352         cmdline_fixed_string_t port;
2353         cmdline_fixed_string_t config;
2354         portid_t port_id;
2355         cmdline_fixed_string_t rss_hash_key;
2356         cmdline_fixed_string_t rss_type;
2357         cmdline_fixed_string_t key;
2358 };
2359
2360 static uint8_t
2361 hexa_digit_to_value(char hexa_digit)
2362 {
2363         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2364                 return (uint8_t) (hexa_digit - '0');
2365         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2366                 return (uint8_t) ((hexa_digit - 'a') + 10);
2367         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2368                 return (uint8_t) ((hexa_digit - 'A') + 10);
2369         /* Invalid hexa digit */
2370         return 0xFF;
2371 }
2372
2373 static uint8_t
2374 parse_and_check_key_hexa_digit(char *key, int idx)
2375 {
2376         uint8_t hexa_v;
2377
2378         hexa_v = hexa_digit_to_value(key[idx]);
2379         if (hexa_v == 0xFF)
2380                 fprintf(stderr,
2381                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2382                         key[idx], idx);
2383         return hexa_v;
2384 }
2385
2386 static void
2387 cmd_config_rss_hash_key_parsed(void *parsed_result,
2388                                __rte_unused struct cmdline *cl,
2389                                __rte_unused void *data)
2390 {
2391         struct cmd_config_rss_hash_key *res = parsed_result;
2392         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2393         uint8_t xdgt0;
2394         uint8_t xdgt1;
2395         int i;
2396         struct rte_eth_dev_info dev_info;
2397         uint8_t hash_key_size;
2398         uint32_t key_len;
2399         int ret;
2400
2401         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2402         if (ret != 0)
2403                 return;
2404
2405         if (dev_info.hash_key_size > 0 &&
2406                         dev_info.hash_key_size <= sizeof(hash_key))
2407                 hash_key_size = dev_info.hash_key_size;
2408         else {
2409                 fprintf(stderr,
2410                         "dev_info did not provide a valid hash key size\n");
2411                 return;
2412         }
2413         /* Check the length of the RSS hash key */
2414         key_len = strlen(res->key);
2415         if (key_len != (hash_key_size * 2)) {
2416                 fprintf(stderr,
2417                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2418                         (int)key_len, hash_key_size * 2);
2419                 return;
2420         }
2421         /* Translate RSS hash key into binary representation */
2422         for (i = 0; i < hash_key_size; i++) {
2423                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2424                 if (xdgt0 == 0xFF)
2425                         return;
2426                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2427                 if (xdgt1 == 0xFF)
2428                         return;
2429                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2430         }
2431         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2432                         hash_key_size);
2433 }
2434
2435 static cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2436         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2437 static cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2438         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2439                                  "config");
2440 static cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2441         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2442                                  RTE_UINT16);
2443 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2444         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2445                                  rss_hash_key, "rss-hash-key");
2446 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2447         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2448                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2449                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2450                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2451                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2452                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2453                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2454                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2455 static cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2456         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2457
2458 static cmdline_parse_inst_t cmd_config_rss_hash_key = {
2459         .f = cmd_config_rss_hash_key_parsed,
2460         .data = NULL,
2461         .help_str = "port config <port_id> rss-hash-key "
2462                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2463                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2464                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2465                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2466                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2467                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2468                 "<string of hex digits (variable length, NIC dependent)>",
2469         .tokens = {
2470                 (void *)&cmd_config_rss_hash_key_port,
2471                 (void *)&cmd_config_rss_hash_key_config,
2472                 (void *)&cmd_config_rss_hash_key_port_id,
2473                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2474                 (void *)&cmd_config_rss_hash_key_rss_type,
2475                 (void *)&cmd_config_rss_hash_key_value,
2476                 NULL,
2477         },
2478 };
2479
2480 /* *** cleanup txq mbufs *** */
2481 struct cmd_cleanup_txq_mbufs_result {
2482         cmdline_fixed_string_t port;
2483         cmdline_fixed_string_t keyword;
2484         cmdline_fixed_string_t name;
2485         uint16_t port_id;
2486         uint16_t queue_id;
2487         uint32_t free_cnt;
2488 };
2489
2490 static void
2491 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2492                              __rte_unused struct cmdline *cl,
2493                              __rte_unused void *data)
2494 {
2495         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2496         uint16_t port_id = res->port_id;
2497         uint16_t queue_id = res->queue_id;
2498         uint32_t free_cnt = res->free_cnt;
2499         struct rte_eth_txq_info qinfo;
2500         int ret;
2501
2502         if (test_done == 0) {
2503                 fprintf(stderr, "Please stop forwarding first\n");
2504                 return;
2505         }
2506
2507         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2508                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2509                         port_id, queue_id);
2510                 return;
2511         }
2512
2513         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2514                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2515                 return;
2516         }
2517
2518         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2519         if (ret < 0) {
2520                 fprintf(stderr,
2521                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2522                         port_id, queue_id, strerror(-ret), ret);
2523                 return;
2524         }
2525
2526         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2527                port_id, queue_id, ret);
2528 }
2529
2530 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2531         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2532                                  "port");
2533 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2534         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2535                                  "cleanup");
2536 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2537         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2538                               RTE_UINT16);
2539 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2540         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2541                                  "txq");
2542 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2543         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2544                               RTE_UINT16);
2545 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2546         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2547                               RTE_UINT32);
2548
2549 static cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2550         .f = cmd_cleanup_txq_mbufs_parsed,
2551         .data = NULL,
2552         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2553         .tokens = {
2554                 (void *)&cmd_cleanup_txq_mbufs_port,
2555                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2556                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2557                 (void *)&cmd_cleanup_txq_mbufs_txq,
2558                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2559                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2560                 NULL,
2561         },
2562 };
2563
2564 /* *** configure port rxq/txq ring size *** */
2565 struct cmd_config_rxtx_ring_size {
2566         cmdline_fixed_string_t port;
2567         cmdline_fixed_string_t config;
2568         portid_t portid;
2569         cmdline_fixed_string_t rxtxq;
2570         uint16_t qid;
2571         cmdline_fixed_string_t rsize;
2572         uint16_t size;
2573 };
2574
2575 static void
2576 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2577                                  __rte_unused struct cmdline *cl,
2578                                  __rte_unused void *data)
2579 {
2580         struct cmd_config_rxtx_ring_size *res = parsed_result;
2581         struct rte_port *port;
2582         uint8_t isrx;
2583
2584         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2585                 return;
2586
2587         if (res->portid == (portid_t)RTE_PORT_ALL) {
2588                 fprintf(stderr, "Invalid port id\n");
2589                 return;
2590         }
2591
2592         port = &ports[res->portid];
2593
2594         if (!strcmp(res->rxtxq, "rxq"))
2595                 isrx = 1;
2596         else if (!strcmp(res->rxtxq, "txq"))
2597                 isrx = 0;
2598         else {
2599                 fprintf(stderr, "Unknown parameter\n");
2600                 return;
2601         }
2602
2603         if (isrx && rx_queue_id_is_invalid(res->qid))
2604                 return;
2605         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2606                 return;
2607
2608         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2609                 fprintf(stderr,
2610                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2611                         rx_free_thresh);
2612                 return;
2613         }
2614
2615         if (isrx)
2616                 port->nb_rx_desc[res->qid] = res->size;
2617         else
2618                 port->nb_tx_desc[res->qid] = res->size;
2619
2620         cmd_reconfig_device_queue(res->portid, 0, 1);
2621 }
2622
2623 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2624         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2625                                  port, "port");
2626 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2627         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2628                                  config, "config");
2629 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2630         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2631                                  portid, RTE_UINT16);
2632 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2633         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2634                                  rxtxq, "rxq#txq");
2635 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2636         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2637                               qid, RTE_UINT16);
2638 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2639         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2640                                  rsize, "ring_size");
2641 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2642         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2643                               size, RTE_UINT16);
2644
2645 static cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2646         .f = cmd_config_rxtx_ring_size_parsed,
2647         .data = NULL,
2648         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2649         .tokens = {
2650                 (void *)&cmd_config_rxtx_ring_size_port,
2651                 (void *)&cmd_config_rxtx_ring_size_config,
2652                 (void *)&cmd_config_rxtx_ring_size_portid,
2653                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2654                 (void *)&cmd_config_rxtx_ring_size_qid,
2655                 (void *)&cmd_config_rxtx_ring_size_rsize,
2656                 (void *)&cmd_config_rxtx_ring_size_size,
2657                 NULL,
2658         },
2659 };
2660
2661 /* *** configure port rxq/txq start/stop *** */
2662 struct cmd_config_rxtx_queue {
2663         cmdline_fixed_string_t port;
2664         portid_t portid;
2665         cmdline_fixed_string_t rxtxq;
2666         uint16_t qid;
2667         cmdline_fixed_string_t opname;
2668 };
2669
2670 static void
2671 cmd_config_rxtx_queue_parsed(void *parsed_result,
2672                         __rte_unused struct cmdline *cl,
2673                         __rte_unused void *data)
2674 {
2675         struct cmd_config_rxtx_queue *res = parsed_result;
2676         struct rte_port *port;
2677         uint8_t isrx;
2678         uint8_t isstart;
2679         uint8_t *state;
2680         int ret = 0;
2681
2682         if (test_done == 0) {
2683                 fprintf(stderr, "Please stop forwarding first\n");
2684                 return;
2685         }
2686
2687         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2688                 return;
2689
2690         if (port_is_started(res->portid) != 1) {
2691                 fprintf(stderr, "Please start port %u first\n", res->portid);
2692                 return;
2693         }
2694
2695         if (!strcmp(res->rxtxq, "rxq"))
2696                 isrx = 1;
2697         else if (!strcmp(res->rxtxq, "txq"))
2698                 isrx = 0;
2699         else {
2700                 fprintf(stderr, "Unknown parameter\n");
2701                 return;
2702         }
2703
2704         if (isrx && rx_queue_id_is_invalid(res->qid))
2705                 return;
2706         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2707                 return;
2708
2709         if (!strcmp(res->opname, "start"))
2710                 isstart = 1;
2711         else if (!strcmp(res->opname, "stop"))
2712                 isstart = 0;
2713         else {
2714                 fprintf(stderr, "Unknown parameter\n");
2715                 return;
2716         }
2717
2718         if (isstart && isrx)
2719                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2720         else if (!isstart && isrx)
2721                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2722         else if (isstart && !isrx)
2723                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2724         else
2725                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2726
2727         if (ret == -ENOTSUP) {
2728                 fprintf(stderr, "Function not supported in PMD\n");
2729                 return;
2730         }
2731
2732         port = &ports[res->portid];
2733         state = isrx ? &port->rxq[res->qid].state : &port->txq[res->qid].state;
2734         *state = isstart ? RTE_ETH_QUEUE_STATE_STARTED :
2735                            RTE_ETH_QUEUE_STATE_STOPPED;
2736 }
2737
2738 static cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2739         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2740 static cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2741         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2742 static cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2743         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2744 static cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2745         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2746 static cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2747         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2748                                                 "start#stop");
2749
2750 static cmdline_parse_inst_t cmd_config_rxtx_queue = {
2751         .f = cmd_config_rxtx_queue_parsed,
2752         .data = NULL,
2753         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2754         .tokens = {
2755                 (void *)&cmd_config_rxtx_queue_port,
2756                 (void *)&cmd_config_rxtx_queue_portid,
2757                 (void *)&cmd_config_rxtx_queue_rxtxq,
2758                 (void *)&cmd_config_rxtx_queue_qid,
2759                 (void *)&cmd_config_rxtx_queue_opname,
2760                 NULL,
2761         },
2762 };
2763
2764 /* *** configure port rxq/txq deferred start on/off *** */
2765 struct cmd_config_deferred_start_rxtx_queue {
2766         cmdline_fixed_string_t port;
2767         portid_t port_id;
2768         cmdline_fixed_string_t rxtxq;
2769         uint16_t qid;
2770         cmdline_fixed_string_t opname;
2771         cmdline_fixed_string_t state;
2772 };
2773
2774 static void
2775 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2776                         __rte_unused struct cmdline *cl,
2777                         __rte_unused void *data)
2778 {
2779         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2780         struct rte_port *port;
2781         uint8_t isrx;
2782         uint8_t ison;
2783         uint8_t needreconfig = 0;
2784
2785         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2786                 return;
2787
2788         if (port_is_started(res->port_id) != 0) {
2789                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2790                 return;
2791         }
2792
2793         port = &ports[res->port_id];
2794
2795         isrx = !strcmp(res->rxtxq, "rxq");
2796
2797         if (isrx && rx_queue_id_is_invalid(res->qid))
2798                 return;
2799         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2800                 return;
2801
2802         ison = !strcmp(res->state, "on");
2803
2804         if (isrx && port->rxq[res->qid].conf.rx_deferred_start != ison) {
2805                 port->rxq[res->qid].conf.rx_deferred_start = ison;
2806                 needreconfig = 1;
2807         } else if (!isrx && port->txq[res->qid].conf.tx_deferred_start != ison) {
2808                 port->txq[res->qid].conf.tx_deferred_start = ison;
2809                 needreconfig = 1;
2810         }
2811
2812         if (needreconfig)
2813                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2814 }
2815
2816 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2817         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2818                                                 port, "port");
2819 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2820         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2821                                                 port_id, RTE_UINT16);
2822 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2823         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2824                                                 rxtxq, "rxq#txq");
2825 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2826         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2827                                                 qid, RTE_UINT16);
2828 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2829         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2830                                                 opname, "deferred_start");
2831 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2832         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2833                                                 state, "on#off");
2834
2835 static cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2836         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2837         .data = NULL,
2838         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2839         .tokens = {
2840                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2841                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2842                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2843                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2844                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2845                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2846                 NULL,
2847         },
2848 };
2849
2850 /* *** configure port rxq/txq setup *** */
2851 struct cmd_setup_rxtx_queue {
2852         cmdline_fixed_string_t port;
2853         portid_t portid;
2854         cmdline_fixed_string_t rxtxq;
2855         uint16_t qid;
2856         cmdline_fixed_string_t setup;
2857 };
2858
2859 /* Common CLI fields for queue setup */
2860 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2861         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2862 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2863         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2864 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2865         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2866 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2867         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2868 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2869         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2870
2871 static void
2872 cmd_setup_rxtx_queue_parsed(
2873         void *parsed_result,
2874         __rte_unused struct cmdline *cl,
2875         __rte_unused void *data)
2876 {
2877         struct cmd_setup_rxtx_queue *res = parsed_result;
2878         struct rte_port *port;
2879         struct rte_mempool *mp;
2880         unsigned int socket_id;
2881         uint8_t isrx = 0;
2882         int ret;
2883
2884         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2885                 return;
2886
2887         if (res->portid == (portid_t)RTE_PORT_ALL) {
2888                 fprintf(stderr, "Invalid port id\n");
2889                 return;
2890         }
2891
2892         if (!strcmp(res->rxtxq, "rxq"))
2893                 isrx = 1;
2894         else if (!strcmp(res->rxtxq, "txq"))
2895                 isrx = 0;
2896         else {
2897                 fprintf(stderr, "Unknown parameter\n");
2898                 return;
2899         }
2900
2901         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2902                 fprintf(stderr, "Invalid rx queue\n");
2903                 return;
2904         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2905                 fprintf(stderr, "Invalid tx queue\n");
2906                 return;
2907         }
2908
2909         port = &ports[res->portid];
2910         if (isrx) {
2911                 socket_id = rxring_numa[res->portid];
2912                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2913                         socket_id = port->socket_id;
2914
2915                 mp = mbuf_pool_find(socket_id, 0);
2916                 if (mp == NULL) {
2917                         fprintf(stderr,
2918                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2919                                 rxring_numa[res->portid]);
2920                         return;
2921                 }
2922                 ret = rx_queue_setup(res->portid,
2923                                      res->qid,
2924                                      port->nb_rx_desc[res->qid],
2925                                      socket_id,
2926                                      &port->rxq[res->qid].conf,
2927                                      mp);
2928                 if (ret)
2929                         fprintf(stderr, "Failed to setup RX queue\n");
2930         } else {
2931                 socket_id = txring_numa[res->portid];
2932                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2933                         socket_id = port->socket_id;
2934
2935                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2936                         fprintf(stderr,
2937                                 "Failed to setup TX queue: not enough descriptors\n");
2938                         return;
2939                 }
2940                 ret = rte_eth_tx_queue_setup(res->portid,
2941                                              res->qid,
2942                                              port->nb_tx_desc[res->qid],
2943                                              socket_id,
2944                                              &port->txq[res->qid].conf);
2945                 if (ret)
2946                         fprintf(stderr, "Failed to setup TX queue\n");
2947         }
2948 }
2949
2950 static cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2951         .f = cmd_setup_rxtx_queue_parsed,
2952         .data = NULL,
2953         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2954         .tokens = {
2955                 (void *)&cmd_setup_rxtx_queue_port,
2956                 (void *)&cmd_setup_rxtx_queue_portid,
2957                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2958                 (void *)&cmd_setup_rxtx_queue_qid,
2959                 (void *)&cmd_setup_rxtx_queue_setup,
2960                 NULL,
2961         },
2962 };
2963
2964
2965 /* *** Configure RSS RETA *** */
2966 struct cmd_config_rss_reta {
2967         cmdline_fixed_string_t port;
2968         cmdline_fixed_string_t keyword;
2969         portid_t port_id;
2970         cmdline_fixed_string_t name;
2971         cmdline_fixed_string_t list_name;
2972         cmdline_fixed_string_t list_of_items;
2973 };
2974
2975 static int
2976 parse_reta_config(const char *str,
2977                   struct rte_eth_rss_reta_entry64 *reta_conf,
2978                   uint16_t nb_entries)
2979 {
2980         int i;
2981         unsigned size;
2982         uint16_t hash_index, idx, shift;
2983         uint16_t nb_queue;
2984         char s[256];
2985         const char *p, *p0 = str;
2986         char *end;
2987         enum fieldnames {
2988                 FLD_HASH_INDEX = 0,
2989                 FLD_QUEUE,
2990                 _NUM_FLD
2991         };
2992         unsigned long int_fld[_NUM_FLD];
2993         char *str_fld[_NUM_FLD];
2994
2995         while ((p = strchr(p0,'(')) != NULL) {
2996                 ++p;
2997                 if((p0 = strchr(p,')')) == NULL)
2998                         return -1;
2999
3000                 size = p0 - p;
3001                 if(size >= sizeof(s))
3002                         return -1;
3003
3004                 snprintf(s, sizeof(s), "%.*s", size, p);
3005                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3006                         return -1;
3007                 for (i = 0; i < _NUM_FLD; i++) {
3008                         errno = 0;
3009                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3010                         if (errno != 0 || end == str_fld[i] ||
3011                                         int_fld[i] > 65535)
3012                                 return -1;
3013                 }
3014
3015                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3016                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3017
3018                 if (hash_index >= nb_entries) {
3019                         fprintf(stderr, "Invalid RETA hash index=%d\n",
3020                                 hash_index);
3021                         return -1;
3022                 }
3023
3024                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
3025                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
3026                 reta_conf[idx].mask |= (1ULL << shift);
3027                 reta_conf[idx].reta[shift] = nb_queue;
3028         }
3029
3030         return 0;
3031 }
3032
3033 static void
3034 cmd_set_rss_reta_parsed(void *parsed_result,
3035                         __rte_unused struct cmdline *cl,
3036                         __rte_unused void *data)
3037 {
3038         int ret;
3039         struct rte_eth_dev_info dev_info;
3040         struct rte_eth_rss_reta_entry64 reta_conf[8];
3041         struct cmd_config_rss_reta *res = parsed_result;
3042
3043         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3044         if (ret != 0)
3045                 return;
3046
3047         if (dev_info.reta_size == 0) {
3048                 fprintf(stderr,
3049                         "Redirection table size is 0 which is invalid for RSS\n");
3050                 return;
3051         } else
3052                 printf("The reta size of port %d is %u\n",
3053                         res->port_id, dev_info.reta_size);
3054         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3055                 fprintf(stderr,
3056                         "Currently do not support more than %u entries of redirection table\n",
3057                         RTE_ETH_RSS_RETA_SIZE_512);
3058                 return;
3059         }
3060
3061         memset(reta_conf, 0, sizeof(reta_conf));
3062         if (!strcmp(res->list_name, "reta")) {
3063                 if (parse_reta_config(res->list_of_items, reta_conf,
3064                                                 dev_info.reta_size)) {
3065                         fprintf(stderr,
3066                                 "Invalid RSS Redirection Table config entered\n");
3067                         return;
3068                 }
3069                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3070                                 reta_conf, dev_info.reta_size);
3071                 if (ret != 0)
3072                         fprintf(stderr,
3073                                 "Bad redirection table parameter, return code = %d\n",
3074                                 ret);
3075         }
3076 }
3077
3078 static cmdline_parse_token_string_t cmd_config_rss_reta_port =
3079         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3080 static cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3081         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3082 static cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3083         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3084 static cmdline_parse_token_string_t cmd_config_rss_reta_name =
3085         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3086 static cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3088 static cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3089         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3090                                  NULL);
3091 static cmdline_parse_inst_t cmd_config_rss_reta = {
3092         .f = cmd_set_rss_reta_parsed,
3093         .data = NULL,
3094         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3095         .tokens = {
3096                 (void *)&cmd_config_rss_reta_port,
3097                 (void *)&cmd_config_rss_reta_keyword,
3098                 (void *)&cmd_config_rss_reta_port_id,
3099                 (void *)&cmd_config_rss_reta_name,
3100                 (void *)&cmd_config_rss_reta_list_name,
3101                 (void *)&cmd_config_rss_reta_list_of_items,
3102                 NULL,
3103         },
3104 };
3105
3106 /* *** SHOW PORT RETA INFO *** */
3107 struct cmd_showport_reta {
3108         cmdline_fixed_string_t show;
3109         cmdline_fixed_string_t port;
3110         portid_t port_id;
3111         cmdline_fixed_string_t rss;
3112         cmdline_fixed_string_t reta;
3113         uint16_t size;
3114         cmdline_fixed_string_t list_of_items;
3115 };
3116
3117 static int
3118 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3119                            uint16_t nb_entries,
3120                            char *str)
3121 {
3122         uint32_t size;
3123         const char *p, *p0 = str;
3124         char s[256];
3125         char *end;
3126         char *str_fld[8];
3127         uint16_t i;
3128         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3129                         RTE_ETH_RETA_GROUP_SIZE;
3130         int ret;
3131
3132         p = strchr(p0, '(');
3133         if (p == NULL)
3134                 return -1;
3135         p++;
3136         p0 = strchr(p, ')');
3137         if (p0 == NULL)
3138                 return -1;
3139         size = p0 - p;
3140         if (size >= sizeof(s)) {
3141                 fprintf(stderr,
3142                         "The string size exceeds the internal buffer size\n");
3143                 return -1;
3144         }
3145         snprintf(s, sizeof(s), "%.*s", size, p);
3146         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3147         if (ret <= 0 || ret != num) {
3148                 fprintf(stderr,
3149                         "The bits of masks do not match the number of reta entries: %u\n",
3150                         num);
3151                 return -1;
3152         }
3153         for (i = 0; i < ret; i++)
3154                 conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
3155
3156         return 0;
3157 }
3158
3159 static void
3160 cmd_showport_reta_parsed(void *parsed_result,
3161                          __rte_unused struct cmdline *cl,
3162                          __rte_unused void *data)
3163 {
3164         struct cmd_showport_reta *res = parsed_result;
3165         struct rte_eth_rss_reta_entry64 reta_conf[8];
3166         struct rte_eth_dev_info dev_info;
3167         uint16_t max_reta_size;
3168         int ret;
3169
3170         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3171         if (ret != 0)
3172                 return;
3173
3174         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3175         if (res->size == 0 || res->size > max_reta_size) {
3176                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3177                         res->size, max_reta_size);
3178                 return;
3179         }
3180
3181         memset(reta_conf, 0, sizeof(reta_conf));
3182         if (showport_parse_reta_config(reta_conf, res->size,
3183                                 res->list_of_items) < 0) {
3184                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3185                         res->list_of_items);
3186                 return;
3187         }
3188         port_rss_reta_info(res->port_id, reta_conf, res->size);
3189 }
3190
3191 static cmdline_parse_token_string_t cmd_showport_reta_show =
3192         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3193 static cmdline_parse_token_string_t cmd_showport_reta_port =
3194         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3195 static cmdline_parse_token_num_t cmd_showport_reta_port_id =
3196         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3197 static cmdline_parse_token_string_t cmd_showport_reta_rss =
3198         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3199 static cmdline_parse_token_string_t cmd_showport_reta_reta =
3200         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3201 static cmdline_parse_token_num_t cmd_showport_reta_size =
3202         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3203 static cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3204         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3205                                         list_of_items, NULL);
3206
3207 static cmdline_parse_inst_t cmd_showport_reta = {
3208         .f = cmd_showport_reta_parsed,
3209         .data = NULL,
3210         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3211         .tokens = {
3212                 (void *)&cmd_showport_reta_show,
3213                 (void *)&cmd_showport_reta_port,
3214                 (void *)&cmd_showport_reta_port_id,
3215                 (void *)&cmd_showport_reta_rss,
3216                 (void *)&cmd_showport_reta_reta,
3217                 (void *)&cmd_showport_reta_size,
3218                 (void *)&cmd_showport_reta_list_of_items,
3219                 NULL,
3220         },
3221 };
3222
3223 /* *** Show RSS hash configuration *** */
3224 struct cmd_showport_rss_hash {
3225         cmdline_fixed_string_t show;
3226         cmdline_fixed_string_t port;
3227         portid_t port_id;
3228         cmdline_fixed_string_t rss_hash;
3229         cmdline_fixed_string_t rss_type;
3230         cmdline_fixed_string_t key; /* optional argument */
3231 };
3232
3233 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3234                                 __rte_unused struct cmdline *cl,
3235                                 void *show_rss_key)
3236 {
3237         struct cmd_showport_rss_hash *res = parsed_result;
3238
3239         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3240 }
3241
3242 static cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3243         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3244 static cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3245         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3246 static cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3247         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3248                                  RTE_UINT16);
3249 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3250         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3251                                  "rss-hash");
3252 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3253         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3254
3255 static cmdline_parse_inst_t cmd_showport_rss_hash = {
3256         .f = cmd_showport_rss_hash_parsed,
3257         .data = NULL,
3258         .help_str = "show port <port_id> rss-hash",
3259         .tokens = {
3260                 (void *)&cmd_showport_rss_hash_show,
3261                 (void *)&cmd_showport_rss_hash_port,
3262                 (void *)&cmd_showport_rss_hash_port_id,
3263                 (void *)&cmd_showport_rss_hash_rss_hash,
3264                 NULL,
3265         },
3266 };
3267
3268 static cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3269         .f = cmd_showport_rss_hash_parsed,
3270         .data = (void *)1,
3271         .help_str = "show port <port_id> rss-hash key",
3272         .tokens = {
3273                 (void *)&cmd_showport_rss_hash_show,
3274                 (void *)&cmd_showport_rss_hash_port,
3275                 (void *)&cmd_showport_rss_hash_port_id,
3276                 (void *)&cmd_showport_rss_hash_rss_hash,
3277                 (void *)&cmd_showport_rss_hash_rss_key,
3278                 NULL,
3279         },
3280 };
3281
3282 /* *** Configure DCB *** */
3283 struct cmd_config_dcb {
3284         cmdline_fixed_string_t port;
3285         cmdline_fixed_string_t config;
3286         portid_t port_id;
3287         cmdline_fixed_string_t dcb;
3288         cmdline_fixed_string_t vt;
3289         cmdline_fixed_string_t vt_en;
3290         uint8_t num_tcs;
3291         cmdline_fixed_string_t pfc;
3292         cmdline_fixed_string_t pfc_en;
3293 };
3294
3295 static void
3296 cmd_config_dcb_parsed(void *parsed_result,
3297                         __rte_unused struct cmdline *cl,
3298                         __rte_unused void *data)
3299 {
3300         struct cmd_config_dcb *res = parsed_result;
3301         struct rte_eth_dcb_info dcb_info;
3302         portid_t port_id = res->port_id;
3303         struct rte_port *port;
3304         uint8_t pfc_en;
3305         int ret;
3306
3307         port = &ports[port_id];
3308         /** Check if the port is not started **/
3309         if (port->port_status != RTE_PORT_STOPPED) {
3310                 fprintf(stderr, "Please stop port %d first\n", port_id);
3311                 return;
3312         }
3313
3314         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3315                 fprintf(stderr,
3316                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3317                 return;
3318         }
3319
3320         if (nb_fwd_lcores < res->num_tcs) {
3321                 fprintf(stderr,
3322                         "nb_cores shouldn't be less than number of TCs.\n");
3323                 return;
3324         }
3325
3326         /* Check whether the port supports the report of DCB info. */
3327         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3328         if (ret == -ENOTSUP) {
3329                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3330                 return;
3331         }
3332
3333         if (!strncmp(res->pfc_en, "on", 2))
3334                 pfc_en = 1;
3335         else
3336                 pfc_en = 0;
3337
3338         /* DCB in VT mode */
3339         if (!strncmp(res->vt_en, "on", 2))
3340                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3341                                 (enum rte_eth_nb_tcs)res->num_tcs,
3342                                 pfc_en);
3343         else
3344                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3345                                 (enum rte_eth_nb_tcs)res->num_tcs,
3346                                 pfc_en);
3347         if (ret != 0) {
3348                 fprintf(stderr, "Cannot initialize network ports.\n");
3349                 return;
3350         }
3351
3352         fwd_config_setup();
3353
3354         cmd_reconfig_device_queue(port_id, 1, 1);
3355 }
3356
3357 static cmdline_parse_token_string_t cmd_config_dcb_port =
3358         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3359 static cmdline_parse_token_string_t cmd_config_dcb_config =
3360         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3361 static cmdline_parse_token_num_t cmd_config_dcb_port_id =
3362         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3363 static cmdline_parse_token_string_t cmd_config_dcb_dcb =
3364         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3365 static cmdline_parse_token_string_t cmd_config_dcb_vt =
3366         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3367 static cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3368         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3369 static cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3370         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3371 static cmdline_parse_token_string_t cmd_config_dcb_pfc =
3372         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3373 static cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3374         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3375
3376 static cmdline_parse_inst_t cmd_config_dcb = {
3377         .f = cmd_config_dcb_parsed,
3378         .data = NULL,
3379         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3380         .tokens = {
3381                 (void *)&cmd_config_dcb_port,
3382                 (void *)&cmd_config_dcb_config,
3383                 (void *)&cmd_config_dcb_port_id,
3384                 (void *)&cmd_config_dcb_dcb,
3385                 (void *)&cmd_config_dcb_vt,
3386                 (void *)&cmd_config_dcb_vt_en,
3387                 (void *)&cmd_config_dcb_num_tcs,
3388                 (void *)&cmd_config_dcb_pfc,
3389                 (void *)&cmd_config_dcb_pfc_en,
3390                 NULL,
3391         },
3392 };
3393
3394 /* *** configure number of packets per burst *** */
3395 struct cmd_config_burst {
3396         cmdline_fixed_string_t port;
3397         cmdline_fixed_string_t keyword;
3398         cmdline_fixed_string_t all;
3399         cmdline_fixed_string_t name;
3400         uint16_t value;
3401 };
3402
3403 static void
3404 cmd_config_burst_parsed(void *parsed_result,
3405                         __rte_unused struct cmdline *cl,
3406                         __rte_unused void *data)
3407 {
3408         struct cmd_config_burst *res = parsed_result;
3409         struct rte_eth_dev_info dev_info;
3410         uint16_t rec_nb_pkts;
3411         int ret;
3412
3413         if (!all_ports_stopped()) {
3414                 fprintf(stderr, "Please stop all ports first\n");
3415                 return;
3416         }
3417
3418         if (!strcmp(res->name, "burst")) {
3419                 if (res->value == 0) {
3420                         /* If user gives a value of zero, query the PMD for
3421                          * its recommended Rx burst size. Testpmd uses a single
3422                          * size for all ports, so assume all ports are the same
3423                          * NIC model and use the values from Port 0.
3424                          */
3425                         ret = eth_dev_info_get_print_err(0, &dev_info);
3426                         if (ret != 0)
3427                                 return;
3428
3429                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3430
3431                         if (rec_nb_pkts == 0) {
3432                                 printf("PMD does not recommend a burst size.\n"
3433                                         "User provided value must be between"
3434                                         " 1 and %d\n", MAX_PKT_BURST);
3435                                 return;
3436                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3437                                 printf("PMD recommended burst size of %d"
3438                                         " exceeds maximum value of %d\n",
3439                                         rec_nb_pkts, MAX_PKT_BURST);
3440                                 return;
3441                         }
3442                         printf("Using PMD-provided burst value of %d\n",
3443                                 rec_nb_pkts);
3444                         nb_pkt_per_burst = rec_nb_pkts;
3445                 } else if (res->value > MAX_PKT_BURST) {
3446                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3447                                 MAX_PKT_BURST);
3448                         return;
3449                 } else
3450                         nb_pkt_per_burst = res->value;
3451         } else {
3452                 fprintf(stderr, "Unknown parameter\n");
3453                 return;
3454         }
3455
3456         init_port_config();
3457
3458         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3459 }
3460
3461 static cmdline_parse_token_string_t cmd_config_burst_port =
3462         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3463 static cmdline_parse_token_string_t cmd_config_burst_keyword =
3464         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3465 static cmdline_parse_token_string_t cmd_config_burst_all =
3466         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3467 static cmdline_parse_token_string_t cmd_config_burst_name =
3468         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3469 static cmdline_parse_token_num_t cmd_config_burst_value =
3470         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3471
3472 static cmdline_parse_inst_t cmd_config_burst = {
3473         .f = cmd_config_burst_parsed,
3474         .data = NULL,
3475         .help_str = "port config all burst <value>",
3476         .tokens = {
3477                 (void *)&cmd_config_burst_port,
3478                 (void *)&cmd_config_burst_keyword,
3479                 (void *)&cmd_config_burst_all,
3480                 (void *)&cmd_config_burst_name,
3481                 (void *)&cmd_config_burst_value,
3482                 NULL,
3483         },
3484 };
3485
3486 /* *** configure rx/tx queues *** */
3487 struct cmd_config_thresh {
3488         cmdline_fixed_string_t port;
3489         cmdline_fixed_string_t keyword;
3490         cmdline_fixed_string_t all;
3491         cmdline_fixed_string_t name;
3492         uint8_t value;
3493 };
3494
3495 static void
3496 cmd_config_thresh_parsed(void *parsed_result,
3497                         __rte_unused struct cmdline *cl,
3498                         __rte_unused void *data)
3499 {
3500         struct cmd_config_thresh *res = parsed_result;
3501
3502         if (!all_ports_stopped()) {
3503                 fprintf(stderr, "Please stop all ports first\n");
3504                 return;
3505         }
3506
3507         if (!strcmp(res->name, "txpt"))
3508                 tx_pthresh = res->value;
3509         else if(!strcmp(res->name, "txht"))
3510                 tx_hthresh = res->value;
3511         else if(!strcmp(res->name, "txwt"))
3512                 tx_wthresh = res->value;
3513         else if(!strcmp(res->name, "rxpt"))
3514                 rx_pthresh = res->value;
3515         else if(!strcmp(res->name, "rxht"))
3516                 rx_hthresh = res->value;
3517         else if(!strcmp(res->name, "rxwt"))
3518                 rx_wthresh = res->value;
3519         else {
3520                 fprintf(stderr, "Unknown parameter\n");
3521                 return;
3522         }
3523
3524         init_port_config();
3525
3526         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3527 }
3528
3529 static cmdline_parse_token_string_t cmd_config_thresh_port =
3530         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3531 static cmdline_parse_token_string_t cmd_config_thresh_keyword =
3532         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3533 static cmdline_parse_token_string_t cmd_config_thresh_all =
3534         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3535 static cmdline_parse_token_string_t cmd_config_thresh_name =
3536         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3537                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3538 static cmdline_parse_token_num_t cmd_config_thresh_value =
3539         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3540
3541 static cmdline_parse_inst_t cmd_config_thresh = {
3542         .f = cmd_config_thresh_parsed,
3543         .data = NULL,
3544         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3545         .tokens = {
3546                 (void *)&cmd_config_thresh_port,
3547                 (void *)&cmd_config_thresh_keyword,
3548                 (void *)&cmd_config_thresh_all,
3549                 (void *)&cmd_config_thresh_name,
3550                 (void *)&cmd_config_thresh_value,
3551                 NULL,
3552         },
3553 };
3554
3555 /* *** configure free/rs threshold *** */
3556 struct cmd_config_threshold {
3557         cmdline_fixed_string_t port;
3558         cmdline_fixed_string_t keyword;
3559         cmdline_fixed_string_t all;
3560         cmdline_fixed_string_t name;
3561         uint16_t value;
3562 };
3563
3564 static void
3565 cmd_config_threshold_parsed(void *parsed_result,
3566                         __rte_unused struct cmdline *cl,
3567                         __rte_unused void *data)
3568 {
3569         struct cmd_config_threshold *res = parsed_result;
3570
3571         if (!all_ports_stopped()) {
3572                 fprintf(stderr, "Please stop all ports first\n");
3573                 return;
3574         }
3575
3576         if (!strcmp(res->name, "txfreet"))
3577                 tx_free_thresh = res->value;
3578         else if (!strcmp(res->name, "txrst"))
3579                 tx_rs_thresh = res->value;
3580         else if (!strcmp(res->name, "rxfreet"))
3581                 rx_free_thresh = res->value;
3582         else {
3583                 fprintf(stderr, "Unknown parameter\n");
3584                 return;
3585         }
3586
3587         init_port_config();
3588
3589         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3590 }
3591
3592 static cmdline_parse_token_string_t cmd_config_threshold_port =
3593         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3594 static cmdline_parse_token_string_t cmd_config_threshold_keyword =
3595         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3596                                                                 "config");
3597 static cmdline_parse_token_string_t cmd_config_threshold_all =
3598         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3599 static cmdline_parse_token_string_t cmd_config_threshold_name =
3600         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3601                                                 "txfreet#txrst#rxfreet");
3602 static cmdline_parse_token_num_t cmd_config_threshold_value =
3603         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3604
3605 static cmdline_parse_inst_t cmd_config_threshold = {
3606         .f = cmd_config_threshold_parsed,
3607         .data = NULL,
3608         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3609         .tokens = {
3610                 (void *)&cmd_config_threshold_port,
3611                 (void *)&cmd_config_threshold_keyword,
3612                 (void *)&cmd_config_threshold_all,
3613                 (void *)&cmd_config_threshold_name,
3614                 (void *)&cmd_config_threshold_value,
3615                 NULL,
3616         },
3617 };
3618
3619 /* *** stop *** */
3620 struct cmd_stop_result {
3621         cmdline_fixed_string_t stop;
3622 };
3623
3624 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3625                             __rte_unused struct cmdline *cl,
3626                             __rte_unused void *data)
3627 {
3628         stop_packet_forwarding();
3629 }
3630
3631 static cmdline_parse_token_string_t cmd_stop_stop =
3632         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3633
3634 static cmdline_parse_inst_t cmd_stop = {
3635         .f = cmd_stop_parsed,
3636         .data = NULL,
3637         .help_str = "stop: Stop packet forwarding",
3638         .tokens = {
3639                 (void *)&cmd_stop_stop,
3640                 NULL,
3641         },
3642 };
3643
3644 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3645
3646 unsigned int
3647 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3648                 unsigned int *parsed_items, int check_unique_values)
3649 {
3650         unsigned int nb_item;
3651         unsigned int value;
3652         unsigned int i;
3653         unsigned int j;
3654         int value_ok;
3655         char c;
3656
3657         /*
3658          * First parse all items in the list and store their value.
3659          */
3660         value = 0;
3661         nb_item = 0;
3662         value_ok = 0;
3663         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3664                 c = str[i];
3665                 if ((c >= '0') && (c <= '9')) {
3666                         value = (unsigned int) (value * 10 + (c - '0'));
3667                         value_ok = 1;
3668                         continue;
3669                 }
3670                 if (c != ',') {
3671                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3672                         return 0;
3673                 }
3674                 if (! value_ok) {
3675                         fprintf(stderr, "No valid value before comma\n");
3676                         return 0;
3677                 }
3678                 if (nb_item < max_items) {
3679                         parsed_items[nb_item] = value;
3680                         value_ok = 0;
3681                         value = 0;
3682                 }
3683                 nb_item++;
3684         }
3685         if (nb_item >= max_items) {
3686                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3687                         item_name, nb_item + 1, max_items);
3688                 return 0;
3689         }
3690         parsed_items[nb_item++] = value;
3691         if (! check_unique_values)
3692                 return nb_item;
3693
3694         /*
3695          * Then, check that all values in the list are different.
3696          * No optimization here...
3697          */
3698         for (i = 0; i < nb_item; i++) {
3699                 for (j = i + 1; j < nb_item; j++) {
3700                         if (parsed_items[j] == parsed_items[i]) {
3701                                 fprintf(stderr,
3702                                         "duplicated %s %u at index %u and %u\n",
3703                                         item_name, parsed_items[i], i, j);
3704                                 return 0;
3705                         }
3706                 }
3707         }
3708         return nb_item;
3709 }
3710
3711 struct cmd_set_list_result {
3712         cmdline_fixed_string_t cmd_keyword;
3713         cmdline_fixed_string_t list_name;
3714         cmdline_fixed_string_t list_of_items;
3715 };
3716
3717 static void cmd_set_list_parsed(void *parsed_result,
3718                                 __rte_unused struct cmdline *cl,
3719                                 __rte_unused void *data)
3720 {
3721         struct cmd_set_list_result *res;
3722         union {
3723                 unsigned int lcorelist[RTE_MAX_LCORE];
3724                 unsigned int portlist[RTE_MAX_ETHPORTS];
3725         } parsed_items;
3726         unsigned int nb_item;
3727
3728         if (test_done == 0) {
3729                 fprintf(stderr, "Please stop forwarding first\n");
3730                 return;
3731         }
3732
3733         res = parsed_result;
3734         if (!strcmp(res->list_name, "corelist")) {
3735                 nb_item = parse_item_list(res->list_of_items, "core",
3736                                           RTE_MAX_LCORE,
3737                                           parsed_items.lcorelist, 1);
3738                 if (nb_item > 0) {
3739                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3740                         fwd_config_setup();
3741                 }
3742                 return;
3743         }
3744         if (!strcmp(res->list_name, "portlist")) {
3745                 nb_item = parse_item_list(res->list_of_items, "port",
3746                                           RTE_MAX_ETHPORTS,
3747                                           parsed_items.portlist, 1);
3748                 if (nb_item > 0) {
3749                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3750                         fwd_config_setup();
3751                 }
3752         }
3753 }
3754
3755 static cmdline_parse_token_string_t cmd_set_list_keyword =
3756         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3757                                  "set");
3758 static cmdline_parse_token_string_t cmd_set_list_name =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3760                                  "corelist#portlist");
3761 static cmdline_parse_token_string_t cmd_set_list_of_items =
3762         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3763                                  NULL);
3764
3765 static cmdline_parse_inst_t cmd_set_fwd_list = {
3766         .f = cmd_set_list_parsed,
3767         .data = NULL,
3768         .help_str = "set corelist|portlist <list0[,list1]*>",
3769         .tokens = {
3770                 (void *)&cmd_set_list_keyword,
3771                 (void *)&cmd_set_list_name,
3772                 (void *)&cmd_set_list_of_items,
3773                 NULL,
3774         },
3775 };
3776
3777 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3778
3779 struct cmd_setmask_result {
3780         cmdline_fixed_string_t set;
3781         cmdline_fixed_string_t mask;
3782         uint64_t hexavalue;
3783 };
3784
3785 static void cmd_set_mask_parsed(void *parsed_result,
3786                                 __rte_unused struct cmdline *cl,
3787                                 __rte_unused void *data)
3788 {
3789         struct cmd_setmask_result *res = parsed_result;
3790
3791         if (test_done == 0) {
3792                 fprintf(stderr, "Please stop forwarding first\n");
3793                 return;
3794         }
3795         if (!strcmp(res->mask, "coremask")) {
3796                 set_fwd_lcores_mask(res->hexavalue);
3797                 fwd_config_setup();
3798         } else if (!strcmp(res->mask, "portmask")) {
3799                 set_fwd_ports_mask(res->hexavalue);
3800                 fwd_config_setup();
3801         }
3802 }
3803
3804 static cmdline_parse_token_string_t cmd_setmask_set =
3805         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3806 static cmdline_parse_token_string_t cmd_setmask_mask =
3807         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3808                                  "coremask#portmask");
3809 static cmdline_parse_token_num_t cmd_setmask_value =
3810         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3811
3812 static cmdline_parse_inst_t cmd_set_fwd_mask = {
3813         .f = cmd_set_mask_parsed,
3814         .data = NULL,
3815         .help_str = "set coremask|portmask <hexadecimal value>",
3816         .tokens = {
3817                 (void *)&cmd_setmask_set,
3818                 (void *)&cmd_setmask_mask,
3819                 (void *)&cmd_setmask_value,
3820                 NULL,
3821         },
3822 };
3823
3824 /*
3825  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3826  */
3827 struct cmd_set_result {
3828         cmdline_fixed_string_t set;
3829         cmdline_fixed_string_t what;
3830         uint16_t value;
3831 };
3832
3833 static void cmd_set_parsed(void *parsed_result,
3834                            __rte_unused struct cmdline *cl,
3835                            __rte_unused void *data)
3836 {
3837         struct cmd_set_result *res = parsed_result;
3838         if (!strcmp(res->what, "nbport")) {
3839                 set_fwd_ports_number(res->value);
3840                 fwd_config_setup();
3841         } else if (!strcmp(res->what, "nbcore")) {
3842                 set_fwd_lcores_number(res->value);
3843                 fwd_config_setup();
3844         } else if (!strcmp(res->what, "burst"))
3845                 set_nb_pkt_per_burst(res->value);
3846         else if (!strcmp(res->what, "verbose"))
3847                 set_verbose_level(res->value);
3848 }
3849
3850 static cmdline_parse_token_string_t cmd_set_set =
3851         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3852 static cmdline_parse_token_string_t cmd_set_what =
3853         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3854                                  "nbport#nbcore#burst#verbose");
3855 static cmdline_parse_token_num_t cmd_set_value =
3856         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3857
3858 static cmdline_parse_inst_t cmd_set_numbers = {
3859         .f = cmd_set_parsed,
3860         .data = NULL,
3861         .help_str = "set nbport|nbcore|burst|verbose <value>",
3862         .tokens = {
3863                 (void *)&cmd_set_set,
3864                 (void *)&cmd_set_what,
3865                 (void *)&cmd_set_value,
3866                 NULL,
3867         },
3868 };
3869
3870 /* *** SET LOG LEVEL CONFIGURATION *** */
3871
3872 struct cmd_set_log_result {
3873         cmdline_fixed_string_t set;
3874         cmdline_fixed_string_t log;
3875         cmdline_fixed_string_t type;
3876         uint32_t level;
3877 };
3878
3879 static void
3880 cmd_set_log_parsed(void *parsed_result,
3881                    __rte_unused struct cmdline *cl,
3882                    __rte_unused void *data)
3883 {
3884         struct cmd_set_log_result *res;
3885         int ret;
3886
3887         res = parsed_result;
3888         if (!strcmp(res->type, "global"))
3889                 rte_log_set_global_level(res->level);
3890         else {
3891                 ret = rte_log_set_level_regexp(res->type, res->level);
3892                 if (ret < 0)
3893                         fprintf(stderr, "Unable to set log level\n");
3894         }
3895 }
3896
3897 static cmdline_parse_token_string_t cmd_set_log_set =
3898         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3899 static cmdline_parse_token_string_t cmd_set_log_log =
3900         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3901 static cmdline_parse_token_string_t cmd_set_log_type =
3902         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3903 static cmdline_parse_token_num_t cmd_set_log_level =
3904         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3905
3906 static cmdline_parse_inst_t cmd_set_log = {
3907         .f = cmd_set_log_parsed,
3908         .data = NULL,
3909         .help_str = "set log global|<type> <level>",
3910         .tokens = {
3911                 (void *)&cmd_set_log_set,
3912                 (void *)&cmd_set_log_log,
3913                 (void *)&cmd_set_log_type,
3914                 (void *)&cmd_set_log_level,
3915                 NULL,
3916         },
3917 };
3918
3919 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3920
3921 struct cmd_set_rxoffs_result {
3922         cmdline_fixed_string_t cmd_keyword;
3923         cmdline_fixed_string_t rxoffs;
3924         cmdline_fixed_string_t seg_offsets;
3925 };
3926
3927 static void
3928 cmd_set_rxoffs_parsed(void *parsed_result,
3929                       __rte_unused struct cmdline *cl,
3930                       __rte_unused void *data)
3931 {
3932         struct cmd_set_rxoffs_result *res;
3933         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3934         unsigned int nb_segs;
3935
3936         res = parsed_result;
3937         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3938                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3939         if (nb_segs > 0)
3940                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3941         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3942 }
3943
3944 static cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3945         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3946                                  cmd_keyword, "set");
3947 static cmdline_parse_token_string_t cmd_set_rxoffs_name =
3948         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3949                                  rxoffs, "rxoffs");
3950 static cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3951         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3952                                  seg_offsets, NULL);
3953
3954 static cmdline_parse_inst_t cmd_set_rxoffs = {
3955         .f = cmd_set_rxoffs_parsed,
3956         .data = NULL,
3957         .help_str = "set rxoffs <len0[,len1]*>",
3958         .tokens = {
3959                 (void *)&cmd_set_rxoffs_keyword,
3960                 (void *)&cmd_set_rxoffs_name,
3961                 (void *)&cmd_set_rxoffs_offsets,
3962                 NULL,
3963         },
3964 };
3965
3966 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3967
3968 struct cmd_set_rxpkts_result {
3969         cmdline_fixed_string_t cmd_keyword;
3970         cmdline_fixed_string_t rxpkts;
3971         cmdline_fixed_string_t seg_lengths;
3972 };
3973
3974 static void
3975 cmd_set_rxpkts_parsed(void *parsed_result,
3976                       __rte_unused struct cmdline *cl,
3977                       __rte_unused void *data)
3978 {
3979         struct cmd_set_rxpkts_result *res;
3980         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3981         unsigned int nb_segs;
3982
3983         res = parsed_result;
3984         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3985                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3986         if (nb_segs > 0)
3987                 set_rx_pkt_segments(seg_lengths, nb_segs);
3988         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3989 }
3990
3991 static cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3992         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3993                                  cmd_keyword, "set");
3994 static cmdline_parse_token_string_t cmd_set_rxpkts_name =
3995         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3996                                  rxpkts, "rxpkts");
3997 static cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3998         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3999                                  seg_lengths, NULL);
4000
4001 static cmdline_parse_inst_t cmd_set_rxpkts = {
4002         .f = cmd_set_rxpkts_parsed,
4003         .data = NULL,
4004         .help_str = "set rxpkts <len0[,len1]*>",
4005         .tokens = {
4006                 (void *)&cmd_set_rxpkts_keyword,
4007                 (void *)&cmd_set_rxpkts_name,
4008                 (void *)&cmd_set_rxpkts_lengths,
4009                 NULL,
4010         },
4011 };
4012
4013 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4014
4015 struct cmd_set_txpkts_result {
4016         cmdline_fixed_string_t cmd_keyword;
4017         cmdline_fixed_string_t txpkts;
4018         cmdline_fixed_string_t seg_lengths;
4019 };
4020
4021 static void
4022 cmd_set_txpkts_parsed(void *parsed_result,
4023                       __rte_unused struct cmdline *cl,
4024                       __rte_unused void *data)
4025 {
4026         struct cmd_set_txpkts_result *res;
4027         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4028         unsigned int nb_segs;
4029
4030         res = parsed_result;
4031         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4032                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4033         if (nb_segs > 0)
4034                 set_tx_pkt_segments(seg_lengths, nb_segs);
4035 }
4036
4037 static cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4038         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4039                                  cmd_keyword, "set");
4040 static cmdline_parse_token_string_t cmd_set_txpkts_name =
4041         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4042                                  txpkts, "txpkts");
4043 static cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4044         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4045                                  seg_lengths, NULL);
4046
4047 static cmdline_parse_inst_t cmd_set_txpkts = {
4048         .f = cmd_set_txpkts_parsed,
4049         .data = NULL,
4050         .help_str = "set txpkts <len0[,len1]*>",
4051         .tokens = {
4052                 (void *)&cmd_set_txpkts_keyword,
4053                 (void *)&cmd_set_txpkts_name,
4054                 (void *)&cmd_set_txpkts_lengths,
4055                 NULL,
4056         },
4057 };
4058
4059 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4060
4061 struct cmd_set_txsplit_result {
4062         cmdline_fixed_string_t cmd_keyword;
4063         cmdline_fixed_string_t txsplit;
4064         cmdline_fixed_string_t mode;
4065 };
4066
4067 static void
4068 cmd_set_txsplit_parsed(void *parsed_result,
4069                       __rte_unused struct cmdline *cl,
4070                       __rte_unused void *data)
4071 {
4072         struct cmd_set_txsplit_result *res;
4073
4074         res = parsed_result;
4075         set_tx_pkt_split(res->mode);
4076 }
4077
4078 static cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4079         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4080                                  cmd_keyword, "set");
4081 static cmdline_parse_token_string_t cmd_set_txsplit_name =
4082         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4083                                  txsplit, "txsplit");
4084 static cmdline_parse_token_string_t cmd_set_txsplit_mode =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4086                                  mode, NULL);
4087
4088 static cmdline_parse_inst_t cmd_set_txsplit = {
4089         .f = cmd_set_txsplit_parsed,
4090         .data = NULL,
4091         .help_str = "set txsplit on|off|rand",
4092         .tokens = {
4093                 (void *)&cmd_set_txsplit_keyword,
4094                 (void *)&cmd_set_txsplit_name,
4095                 (void *)&cmd_set_txsplit_mode,
4096                 NULL,
4097         },
4098 };
4099
4100 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4101
4102 struct cmd_set_txtimes_result {
4103         cmdline_fixed_string_t cmd_keyword;
4104         cmdline_fixed_string_t txtimes;
4105         cmdline_fixed_string_t tx_times;
4106 };
4107
4108 static void
4109 cmd_set_txtimes_parsed(void *parsed_result,
4110                        __rte_unused struct cmdline *cl,
4111                        __rte_unused void *data)
4112 {
4113         struct cmd_set_txtimes_result *res;
4114         unsigned int tx_times[2] = {0, 0};
4115         unsigned int n_times;
4116
4117         res = parsed_result;
4118         n_times = parse_item_list(res->tx_times, "tx times",
4119                                   2, tx_times, 0);
4120         if (n_times == 2)
4121                 set_tx_pkt_times(tx_times);
4122 }
4123
4124 static cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4125         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4126                                  cmd_keyword, "set");
4127 static cmdline_parse_token_string_t cmd_set_txtimes_name =
4128         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4129                                  txtimes, "txtimes");
4130 static cmdline_parse_token_string_t cmd_set_txtimes_value =
4131         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4132                                  tx_times, NULL);
4133
4134 static cmdline_parse_inst_t cmd_set_txtimes = {
4135         .f = cmd_set_txtimes_parsed,
4136         .data = NULL,
4137         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4138         .tokens = {
4139                 (void *)&cmd_set_txtimes_keyword,
4140                 (void *)&cmd_set_txtimes_name,
4141                 (void *)&cmd_set_txtimes_value,
4142                 NULL,
4143         },
4144 };
4145
4146 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4147 struct cmd_rx_vlan_filter_all_result {
4148         cmdline_fixed_string_t rx_vlan;
4149         cmdline_fixed_string_t what;
4150         cmdline_fixed_string_t all;
4151         portid_t port_id;
4152 };
4153
4154 static void
4155 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4156                               __rte_unused struct cmdline *cl,
4157                               __rte_unused void *data)
4158 {
4159         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4160
4161         if (!strcmp(res->what, "add"))
4162                 rx_vlan_all_filter_set(res->port_id, 1);
4163         else
4164                 rx_vlan_all_filter_set(res->port_id, 0);
4165 }
4166
4167 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4168         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4169                                  rx_vlan, "rx_vlan");
4170 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4171         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4172                                  what, "add#rm");
4173 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4174         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4175                                  all, "all");
4176 static cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4177         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4178                               port_id, RTE_UINT16);
4179
4180 static cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4181         .f = cmd_rx_vlan_filter_all_parsed,
4182         .data = NULL,
4183         .help_str = "rx_vlan add|rm all <port_id>: "
4184                 "Add/Remove all identifiers to/from the set of VLAN "
4185                 "identifiers filtered by a port",
4186         .tokens = {
4187                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4188                 (void *)&cmd_rx_vlan_filter_all_what,
4189                 (void *)&cmd_rx_vlan_filter_all_all,
4190                 (void *)&cmd_rx_vlan_filter_all_portid,
4191                 NULL,
4192         },
4193 };
4194
4195 /* *** VLAN OFFLOAD SET ON A PORT *** */
4196 struct cmd_vlan_offload_result {
4197         cmdline_fixed_string_t vlan;
4198         cmdline_fixed_string_t set;
4199         cmdline_fixed_string_t vlan_type;
4200         cmdline_fixed_string_t what;
4201         cmdline_fixed_string_t on;
4202         cmdline_fixed_string_t port_id;
4203 };
4204
4205 static void
4206 cmd_vlan_offload_parsed(void *parsed_result,
4207                           __rte_unused struct cmdline *cl,
4208                           __rte_unused void *data)
4209 {
4210         int on;
4211         struct cmd_vlan_offload_result *res = parsed_result;
4212         char *str;
4213         int i, len = 0;
4214         portid_t port_id = 0;
4215         unsigned int tmp;
4216
4217         str = res->port_id;
4218         len = strnlen(str, STR_TOKEN_SIZE);
4219         i = 0;
4220         /* Get port_id first */
4221         while(i < len){
4222                 if(str[i] == ',')
4223                         break;
4224
4225                 i++;
4226         }
4227         str[i]='\0';
4228         tmp = strtoul(str, NULL, 0);
4229         /* If port_id greater that what portid_t can represent, return */
4230         if(tmp >= RTE_MAX_ETHPORTS)
4231                 return;
4232         port_id = (portid_t)tmp;
4233
4234         if (!strcmp(res->on, "on"))
4235                 on = 1;
4236         else
4237                 on = 0;
4238
4239         if (!strcmp(res->what, "strip"))
4240                 rx_vlan_strip_set(port_id,  on);
4241         else if(!strcmp(res->what, "stripq")){
4242                 uint16_t queue_id = 0;
4243
4244                 /* No queue_id, return */
4245                 if(i + 1 >= len) {
4246                         fprintf(stderr, "must specify (port,queue_id)\n");
4247                         return;
4248                 }
4249                 tmp = strtoul(str + i + 1, NULL, 0);
4250                 /* If queue_id greater that what 16-bits can represent, return */
4251                 if(tmp > 0xffff)
4252                         return;
4253
4254                 queue_id = (uint16_t)tmp;
4255                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4256         }
4257         else if (!strcmp(res->what, "filter"))
4258                 rx_vlan_filter_set(port_id, on);
4259         else if (!strcmp(res->what, "qinq_strip"))
4260                 rx_vlan_qinq_strip_set(port_id, on);
4261         else
4262                 vlan_extend_set(port_id, on);
4263
4264         return;
4265 }
4266
4267 static cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4268         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4269                                  vlan, "vlan");
4270 static cmdline_parse_token_string_t cmd_vlan_offload_set =
4271         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4272                                  set, "set");
4273 static cmdline_parse_token_string_t cmd_vlan_offload_what =
4274         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4275                                 what, "strip#filter#qinq_strip#extend#stripq");
4276 static cmdline_parse_token_string_t cmd_vlan_offload_on =
4277         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4278                               on, "on#off");
4279 static cmdline_parse_token_string_t cmd_vlan_offload_portid =
4280         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4281                               port_id, NULL);
4282
4283 static cmdline_parse_inst_t cmd_vlan_offload = {
4284         .f = cmd_vlan_offload_parsed,
4285         .data = NULL,
4286         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4287                 "<port_id[,queue_id]>: "
4288                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4289         .tokens = {
4290                 (void *)&cmd_vlan_offload_vlan,
4291                 (void *)&cmd_vlan_offload_set,
4292                 (void *)&cmd_vlan_offload_what,
4293                 (void *)&cmd_vlan_offload_on,
4294                 (void *)&cmd_vlan_offload_portid,
4295                 NULL,
4296         },
4297 };
4298
4299 /* *** VLAN TPID SET ON A PORT *** */
4300 struct cmd_vlan_tpid_result {
4301         cmdline_fixed_string_t vlan;
4302         cmdline_fixed_string_t set;
4303         cmdline_fixed_string_t vlan_type;
4304         cmdline_fixed_string_t what;
4305         uint16_t tp_id;
4306         portid_t port_id;
4307 };
4308
4309 static void
4310 cmd_vlan_tpid_parsed(void *parsed_result,
4311                           __rte_unused struct cmdline *cl,
4312                           __rte_unused void *data)
4313 {
4314         struct cmd_vlan_tpid_result *res = parsed_result;
4315         enum rte_vlan_type vlan_type;
4316
4317         if (!strcmp(res->vlan_type, "inner"))
4318                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4319         else if (!strcmp(res->vlan_type, "outer"))
4320                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4321         else {
4322                 fprintf(stderr, "Unknown vlan type\n");
4323                 return;
4324         }
4325         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4326 }
4327
4328 static cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4329         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4330                                  vlan, "vlan");
4331 static cmdline_parse_token_string_t cmd_vlan_tpid_set =
4332         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4333                                  set, "set");
4334 static cmdline_parse_token_string_t cmd_vlan_type =
4335         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4336                                  vlan_type, "inner#outer");
4337 static cmdline_parse_token_string_t cmd_vlan_tpid_what =
4338         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4339                                  what, "tpid");
4340 static cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4341         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4342                               tp_id, RTE_UINT16);
4343 static cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4344         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4345                               port_id, RTE_UINT16);
4346
4347 static cmdline_parse_inst_t cmd_vlan_tpid = {
4348         .f = cmd_vlan_tpid_parsed,
4349         .data = NULL,
4350         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4351                 "Set the VLAN Ether type",
4352         .tokens = {
4353                 (void *)&cmd_vlan_tpid_vlan,
4354                 (void *)&cmd_vlan_tpid_set,
4355                 (void *)&cmd_vlan_type,
4356                 (void *)&cmd_vlan_tpid_what,
4357                 (void *)&cmd_vlan_tpid_tpid,
4358                 (void *)&cmd_vlan_tpid_portid,
4359                 NULL,
4360         },
4361 };
4362
4363 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4364 struct cmd_rx_vlan_filter_result {
4365         cmdline_fixed_string_t rx_vlan;
4366         cmdline_fixed_string_t what;
4367         uint16_t vlan_id;
4368         portid_t port_id;
4369 };
4370
4371 static void
4372 cmd_rx_vlan_filter_parsed(void *parsed_result,
4373                           __rte_unused struct cmdline *cl,
4374                           __rte_unused void *data)
4375 {
4376         struct cmd_rx_vlan_filter_result *res = parsed_result;
4377
4378         if (!strcmp(res->what, "add"))
4379                 rx_vft_set(res->port_id, res->vlan_id, 1);
4380         else
4381                 rx_vft_set(res->port_id, res->vlan_id, 0);
4382 }
4383
4384 static cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4385         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4386                                  rx_vlan, "rx_vlan");
4387 static cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4388         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4389                                  what, "add#rm");
4390 static cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4391         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4392                               vlan_id, RTE_UINT16);
4393 static cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4394         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4395                               port_id, RTE_UINT16);
4396
4397 static cmdline_parse_inst_t cmd_rx_vlan_filter = {
4398         .f = cmd_rx_vlan_filter_parsed,
4399         .data = NULL,
4400         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4401                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4402                 "identifiers filtered by a port",
4403         .tokens = {
4404                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4405                 (void *)&cmd_rx_vlan_filter_what,
4406                 (void *)&cmd_rx_vlan_filter_vlanid,
4407                 (void *)&cmd_rx_vlan_filter_portid,
4408                 NULL,
4409         },
4410 };
4411
4412 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4413 struct cmd_tx_vlan_set_result {
4414         cmdline_fixed_string_t tx_vlan;
4415         cmdline_fixed_string_t set;
4416         portid_t port_id;
4417         uint16_t vlan_id;
4418 };
4419
4420 static void
4421 cmd_tx_vlan_set_parsed(void *parsed_result,
4422                        __rte_unused struct cmdline *cl,
4423                        __rte_unused void *data)
4424 {
4425         struct cmd_tx_vlan_set_result *res = parsed_result;
4426
4427         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4428                 return;
4429
4430         if (!port_is_stopped(res->port_id)) {
4431                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4432                 return;
4433         }
4434
4435         tx_vlan_set(res->port_id, res->vlan_id);
4436
4437         cmd_reconfig_device_queue(res->port_id, 1, 1);
4438 }
4439
4440 static cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4441         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4442                                  tx_vlan, "tx_vlan");
4443 static cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4444         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4445                                  set, "set");
4446 static cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4447         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4448                               port_id, RTE_UINT16);
4449 static cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4450         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4451                               vlan_id, RTE_UINT16);
4452
4453 static cmdline_parse_inst_t cmd_tx_vlan_set = {
4454         .f = cmd_tx_vlan_set_parsed,
4455         .data = NULL,
4456         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4457                 "Enable hardware insertion of a single VLAN header "
4458                 "with a given TAG Identifier in packets sent on a port",
4459         .tokens = {
4460                 (void *)&cmd_tx_vlan_set_tx_vlan,
4461                 (void *)&cmd_tx_vlan_set_set,
4462                 (void *)&cmd_tx_vlan_set_portid,
4463                 (void *)&cmd_tx_vlan_set_vlanid,
4464                 NULL,
4465         },
4466 };
4467
4468 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4469 struct cmd_tx_vlan_set_qinq_result {
4470         cmdline_fixed_string_t tx_vlan;
4471         cmdline_fixed_string_t set;
4472         portid_t port_id;
4473         uint16_t vlan_id;
4474         uint16_t vlan_id_outer;
4475 };
4476
4477 static void
4478 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4479                             __rte_unused struct cmdline *cl,
4480                             __rte_unused void *data)
4481 {
4482         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4483
4484         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4485                 return;
4486
4487         if (!port_is_stopped(res->port_id)) {
4488                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4489                 return;
4490         }
4491
4492         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4493
4494         cmd_reconfig_device_queue(res->port_id, 1, 1);
4495 }
4496
4497 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4498         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4499                 tx_vlan, "tx_vlan");
4500 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4501         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4502                 set, "set");
4503 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4504         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4505                 port_id, RTE_UINT16);
4506 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4507         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4508                 vlan_id, RTE_UINT16);
4509 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4510         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4511                 vlan_id_outer, RTE_UINT16);
4512
4513 static cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4514         .f = cmd_tx_vlan_set_qinq_parsed,
4515         .data = NULL,
4516         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4517                 "Enable hardware insertion of double VLAN header "
4518                 "with given TAG Identifiers in packets sent on a port",
4519         .tokens = {
4520                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4521                 (void *)&cmd_tx_vlan_set_qinq_set,
4522                 (void *)&cmd_tx_vlan_set_qinq_portid,
4523                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4524                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4525                 NULL,
4526         },
4527 };
4528
4529 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4530 struct cmd_tx_vlan_set_pvid_result {
4531         cmdline_fixed_string_t tx_vlan;
4532         cmdline_fixed_string_t set;
4533         cmdline_fixed_string_t pvid;
4534         portid_t port_id;
4535         uint16_t vlan_id;
4536         cmdline_fixed_string_t mode;
4537 };
4538
4539 static void
4540 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4541                             __rte_unused struct cmdline *cl,
4542                             __rte_unused void *data)
4543 {
4544         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4545
4546         if (strcmp(res->mode, "on") == 0)
4547                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4548         else
4549                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4550 }
4551
4552 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4553         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4554                                  tx_vlan, "tx_vlan");
4555 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4556         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4557                                  set, "set");
4558 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4559         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4560                                  pvid, "pvid");
4561 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4562         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4563                              port_id, RTE_UINT16);
4564 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4565         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4566                               vlan_id, RTE_UINT16);
4567 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4568         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4569                                  mode, "on#off");
4570
4571 static cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4572         .f = cmd_tx_vlan_set_pvid_parsed,
4573         .data = NULL,
4574         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4575         .tokens = {
4576                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4577                 (void *)&cmd_tx_vlan_set_pvid_set,
4578                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4579                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4580                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4581                 (void *)&cmd_tx_vlan_set_pvid_mode,
4582                 NULL,
4583         },
4584 };
4585
4586 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4587 struct cmd_tx_vlan_reset_result {
4588         cmdline_fixed_string_t tx_vlan;
4589         cmdline_fixed_string_t reset;
4590         portid_t port_id;
4591 };
4592
4593 static void
4594 cmd_tx_vlan_reset_parsed(void *parsed_result,
4595                          __rte_unused struct cmdline *cl,
4596                          __rte_unused void *data)
4597 {
4598         struct cmd_tx_vlan_reset_result *res = parsed_result;
4599
4600         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4601                 return;
4602
4603         if (!port_is_stopped(res->port_id)) {
4604                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4605                 return;
4606         }
4607
4608         tx_vlan_reset(res->port_id);
4609
4610         cmd_reconfig_device_queue(res->port_id, 1, 1);
4611 }
4612
4613 static cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4614         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4615                                  tx_vlan, "tx_vlan");
4616 static cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4617         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4618                                  reset, "reset");
4619 static cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4620         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4621                               port_id, RTE_UINT16);
4622
4623 static cmdline_parse_inst_t cmd_tx_vlan_reset = {
4624         .f = cmd_tx_vlan_reset_parsed,
4625         .data = NULL,
4626         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4627                 "VLAN header in packets sent on a port",
4628         .tokens = {
4629                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4630                 (void *)&cmd_tx_vlan_reset_reset,
4631                 (void *)&cmd_tx_vlan_reset_portid,
4632                 NULL,
4633         },
4634 };
4635
4636
4637 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4638 struct cmd_csum_result {
4639         cmdline_fixed_string_t csum;
4640         cmdline_fixed_string_t mode;
4641         cmdline_fixed_string_t proto;
4642         cmdline_fixed_string_t hwsw;
4643         portid_t port_id;
4644 };
4645
4646 static void
4647 csum_show(int port_id)
4648 {
4649         struct rte_eth_dev_info dev_info;
4650         uint64_t tx_offloads;
4651         int ret;
4652
4653         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4654         printf("Parse tunnel is %s\n",
4655                 (ports[port_id].parse_tunnel) ? "on" : "off");
4656         printf("IP checksum offload is %s\n",
4657                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4658         printf("UDP checksum offload is %s\n",
4659                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4660         printf("TCP checksum offload is %s\n",
4661                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4662         printf("SCTP checksum offload is %s\n",
4663                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4664         printf("Outer-Ip checksum offload is %s\n",
4665                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4666         printf("Outer-Udp checksum offload is %s\n",
4667                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4668
4669         /* display warnings if configuration is not supported by the NIC */
4670         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4671         if (ret != 0)
4672                 return;
4673
4674         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4675                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4676                 fprintf(stderr,
4677                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4678                         port_id);
4679         }
4680         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4681                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4682                 fprintf(stderr,
4683                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4684                         port_id);
4685         }
4686         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4687                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4688                 fprintf(stderr,
4689                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4690                         port_id);
4691         }
4692         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4693                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4694                 fprintf(stderr,
4695                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4696                         port_id);
4697         }
4698         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4699                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4700                 fprintf(stderr,
4701                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4702                         port_id);
4703         }
4704         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4705                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4706                         == 0) {
4707                 fprintf(stderr,
4708                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4709                         port_id);
4710         }
4711 }
4712
4713 static void
4714 cmd_config_queue_tx_offloads(struct rte_port *port)
4715 {
4716         int k;
4717
4718         /* Apply queue tx offloads configuration */
4719         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4720                 port->txq[k].conf.offloads =
4721                         port->dev_conf.txmode.offloads;
4722 }
4723
4724 static void
4725 cmd_csum_parsed(void *parsed_result,
4726                        __rte_unused struct cmdline *cl,
4727                        __rte_unused void *data)
4728 {
4729         struct cmd_csum_result *res = parsed_result;
4730         int hw = 0;
4731         uint64_t csum_offloads = 0;
4732         struct rte_eth_dev_info dev_info;
4733         int ret;
4734
4735         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4736                 fprintf(stderr, "invalid port %d\n", res->port_id);
4737                 return;
4738         }
4739         if (!port_is_stopped(res->port_id)) {
4740                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4741                 return;
4742         }
4743
4744         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4745         if (ret != 0)
4746                 return;
4747
4748         if (!strcmp(res->mode, "set")) {
4749
4750                 if (!strcmp(res->hwsw, "hw"))
4751                         hw = 1;
4752
4753                 if (!strcmp(res->proto, "ip")) {
4754                         if (hw == 0 || (dev_info.tx_offload_capa &
4755                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4756                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4757                         } else {
4758                                 fprintf(stderr,
4759                                         "IP checksum offload is not supported by port %u\n",
4760                                         res->port_id);
4761                         }
4762                 } else if (!strcmp(res->proto, "udp")) {
4763                         if (hw == 0 || (dev_info.tx_offload_capa &
4764                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4765                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4766                         } else {
4767                                 fprintf(stderr,
4768                                         "UDP checksum offload is not supported by port %u\n",
4769                                         res->port_id);
4770                         }
4771                 } else if (!strcmp(res->proto, "tcp")) {
4772                         if (hw == 0 || (dev_info.tx_offload_capa &
4773                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4774                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4775                         } else {
4776                                 fprintf(stderr,
4777                                         "TCP checksum offload is not supported by port %u\n",
4778                                         res->port_id);
4779                         }
4780                 } else if (!strcmp(res->proto, "sctp")) {
4781                         if (hw == 0 || (dev_info.tx_offload_capa &
4782                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4783                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4784                         } else {
4785                                 fprintf(stderr,
4786                                         "SCTP checksum offload is not supported by port %u\n",
4787                                         res->port_id);
4788                         }
4789                 } else if (!strcmp(res->proto, "outer-ip")) {
4790                         if (hw == 0 || (dev_info.tx_offload_capa &
4791                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4792                                 csum_offloads |=
4793                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4794                         } else {
4795                                 fprintf(stderr,
4796                                         "Outer IP checksum offload is not supported by port %u\n",
4797                                         res->port_id);
4798                         }
4799                 } else if (!strcmp(res->proto, "outer-udp")) {
4800                         if (hw == 0 || (dev_info.tx_offload_capa &
4801                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4802                                 csum_offloads |=
4803                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4804                         } else {
4805                                 fprintf(stderr,
4806                                         "Outer UDP checksum offload is not supported by port %u\n",
4807                                         res->port_id);
4808                         }
4809                 }
4810
4811                 if (hw) {
4812                         ports[res->port_id].dev_conf.txmode.offloads |=
4813                                                         csum_offloads;
4814                 } else {
4815                         ports[res->port_id].dev_conf.txmode.offloads &=
4816                                                         (~csum_offloads);
4817                 }
4818                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4819         }
4820         csum_show(res->port_id);
4821
4822         cmd_reconfig_device_queue(res->port_id, 1, 1);
4823 }
4824
4825 static cmdline_parse_token_string_t cmd_csum_csum =
4826         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4827                                 csum, "csum");
4828 static cmdline_parse_token_string_t cmd_csum_mode =
4829         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4830                                 mode, "set");
4831 static cmdline_parse_token_string_t cmd_csum_proto =
4832         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4833                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4834 static cmdline_parse_token_string_t cmd_csum_hwsw =
4835         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4836                                 hwsw, "hw#sw");
4837 static cmdline_parse_token_num_t cmd_csum_portid =
4838         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4839                                 port_id, RTE_UINT16);
4840
4841 static cmdline_parse_inst_t cmd_csum_set = {
4842         .f = cmd_csum_parsed,
4843         .data = NULL,
4844         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4845                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4846                 "using csum forward engine",
4847         .tokens = {
4848                 (void *)&cmd_csum_csum,
4849                 (void *)&cmd_csum_mode,
4850                 (void *)&cmd_csum_proto,
4851                 (void *)&cmd_csum_hwsw,
4852                 (void *)&cmd_csum_portid,
4853                 NULL,
4854         },
4855 };
4856
4857 static cmdline_parse_token_string_t cmd_csum_mode_show =
4858         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4859                                 mode, "show");
4860
4861 static cmdline_parse_inst_t cmd_csum_show = {
4862         .f = cmd_csum_parsed,
4863         .data = NULL,
4864         .help_str = "csum show <port_id>: Show checksum offload configuration",
4865         .tokens = {
4866                 (void *)&cmd_csum_csum,
4867                 (void *)&cmd_csum_mode_show,
4868                 (void *)&cmd_csum_portid,
4869                 NULL,
4870         },
4871 };
4872
4873 /* Enable/disable tunnel parsing */
4874 struct cmd_csum_tunnel_result {
4875         cmdline_fixed_string_t csum;
4876         cmdline_fixed_string_t parse;
4877         cmdline_fixed_string_t onoff;
4878         portid_t port_id;
4879 };
4880
4881 static void
4882 cmd_csum_tunnel_parsed(void *parsed_result,
4883                        __rte_unused struct cmdline *cl,
4884                        __rte_unused void *data)
4885 {
4886         struct cmd_csum_tunnel_result *res = parsed_result;
4887
4888         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4889                 return;
4890
4891         if (!strcmp(res->onoff, "on"))
4892                 ports[res->port_id].parse_tunnel = 1;
4893         else
4894                 ports[res->port_id].parse_tunnel = 0;
4895
4896         csum_show(res->port_id);
4897 }
4898
4899 static cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4900         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4901                                 csum, "csum");
4902 static cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4903         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4904                                 parse, "parse-tunnel");
4905 static cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4906         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4907                                 onoff, "on#off");
4908 static cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4909         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4910                                 port_id, RTE_UINT16);
4911
4912 static cmdline_parse_inst_t cmd_csum_tunnel = {
4913         .f = cmd_csum_tunnel_parsed,
4914         .data = NULL,
4915         .help_str = "csum parse-tunnel on|off <port_id>: "
4916                 "Enable/Disable parsing of tunnels for csum engine",
4917         .tokens = {
4918                 (void *)&cmd_csum_tunnel_csum,
4919                 (void *)&cmd_csum_tunnel_parse,
4920                 (void *)&cmd_csum_tunnel_onoff,
4921                 (void *)&cmd_csum_tunnel_portid,
4922                 NULL,
4923         },
4924 };
4925
4926 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4927 struct cmd_tso_set_result {
4928         cmdline_fixed_string_t tso;
4929         cmdline_fixed_string_t mode;
4930         uint16_t tso_segsz;
4931         portid_t port_id;
4932 };
4933
4934 static void
4935 cmd_tso_set_parsed(void *parsed_result,
4936                        __rte_unused struct cmdline *cl,
4937                        __rte_unused void *data)
4938 {
4939         struct cmd_tso_set_result *res = parsed_result;
4940         struct rte_eth_dev_info dev_info;
4941         int ret;
4942
4943         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4944                 return;
4945         if (!port_is_stopped(res->port_id)) {
4946                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4947                 return;
4948         }
4949
4950         if (!strcmp(res->mode, "set"))
4951                 ports[res->port_id].tso_segsz = res->tso_segsz;
4952
4953         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4954         if (ret != 0)
4955                 return;
4956
4957         if ((ports[res->port_id].tso_segsz != 0) &&
4958                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4959                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4960                         res->port_id);
4961                 return;
4962         }
4963
4964         if (ports[res->port_id].tso_segsz == 0) {
4965                 ports[res->port_id].dev_conf.txmode.offloads &=
4966                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4967                 printf("TSO for non-tunneled packets is disabled\n");
4968         } else {
4969                 ports[res->port_id].dev_conf.txmode.offloads |=
4970                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4971                 printf("TSO segment size for non-tunneled packets is %d\n",
4972                         ports[res->port_id].tso_segsz);
4973         }
4974         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4975
4976         /* display warnings if configuration is not supported by the NIC */
4977         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4978         if (ret != 0)
4979                 return;
4980
4981         if ((ports[res->port_id].tso_segsz != 0) &&
4982                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4983                 fprintf(stderr,
4984                         "Warning: TSO enabled but not supported by port %d\n",
4985                         res->port_id);
4986         }
4987
4988         cmd_reconfig_device_queue(res->port_id, 1, 1);
4989 }
4990
4991 static cmdline_parse_token_string_t cmd_tso_set_tso =
4992         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4993                                 tso, "tso");
4994 static cmdline_parse_token_string_t cmd_tso_set_mode =
4995         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4996                                 mode, "set");
4997 static cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4998         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4999                                 tso_segsz, RTE_UINT16);
5000 static cmdline_parse_token_num_t cmd_tso_set_portid =
5001         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
5002                                 port_id, RTE_UINT16);
5003
5004 static cmdline_parse_inst_t cmd_tso_set = {
5005         .f = cmd_tso_set_parsed,
5006         .data = NULL,
5007         .help_str = "tso set <tso_segsz> <port_id>: "
5008                 "Set TSO segment size of non-tunneled packets for csum engine "
5009                 "(0 to disable)",
5010         .tokens = {
5011                 (void *)&cmd_tso_set_tso,
5012                 (void *)&cmd_tso_set_mode,
5013                 (void *)&cmd_tso_set_tso_segsz,
5014                 (void *)&cmd_tso_set_portid,
5015                 NULL,
5016         },
5017 };
5018
5019 static cmdline_parse_token_string_t cmd_tso_show_mode =
5020         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
5021                                 mode, "show");
5022
5023
5024 static cmdline_parse_inst_t cmd_tso_show = {
5025         .f = cmd_tso_set_parsed,
5026         .data = NULL,
5027         .help_str = "tso show <port_id>: "
5028                 "Show TSO segment size of non-tunneled packets for csum engine",
5029         .tokens = {
5030                 (void *)&cmd_tso_set_tso,
5031                 (void *)&cmd_tso_show_mode,
5032                 (void *)&cmd_tso_set_portid,
5033                 NULL,
5034         },
5035 };
5036
5037 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5038 struct cmd_tunnel_tso_set_result {
5039         cmdline_fixed_string_t tso;
5040         cmdline_fixed_string_t mode;
5041         uint16_t tso_segsz;
5042         portid_t port_id;
5043 };
5044
5045 static struct rte_eth_dev_info
5046 check_tunnel_tso_nic_support(portid_t port_id)
5047 {
5048         struct rte_eth_dev_info dev_info;
5049
5050         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5051                 return dev_info;
5052
5053         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5054                 fprintf(stderr,
5055                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5056                         port_id);
5057         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5058                 fprintf(stderr,
5059                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5060                         port_id);
5061         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5062                 fprintf(stderr,
5063                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5064                         port_id);
5065         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5066                 fprintf(stderr,
5067                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5068                         port_id);
5069         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5070                 fprintf(stderr,
5071                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5072                         port_id);
5073         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5074                 fprintf(stderr,
5075                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5076                         port_id);
5077         return dev_info;
5078 }
5079
5080 static void
5081 cmd_tunnel_tso_set_parsed(void *parsed_result,
5082                           __rte_unused struct cmdline *cl,
5083                           __rte_unused void *data)
5084 {
5085         struct cmd_tunnel_tso_set_result *res = parsed_result;
5086         struct rte_eth_dev_info dev_info;
5087
5088         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5089                 return;
5090         if (!port_is_stopped(res->port_id)) {
5091                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5092                 return;
5093         }
5094
5095         if (!strcmp(res->mode, "set"))
5096                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5097
5098         dev_info = check_tunnel_tso_nic_support(res->port_id);
5099         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5100                 ports[res->port_id].dev_conf.txmode.offloads &=
5101                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5102                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5103                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5104                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5105                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5106                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5107                 printf("TSO for tunneled packets is disabled\n");
5108         } else {
5109                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5110                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5111                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5112                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5113                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5114                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5115
5116                 ports[res->port_id].dev_conf.txmode.offloads |=
5117                         (tso_offloads & dev_info.tx_offload_capa);
5118                 printf("TSO segment size for tunneled packets is %d\n",
5119                         ports[res->port_id].tunnel_tso_segsz);
5120
5121                 /* Below conditions are needed to make it work:
5122                  * (1) tunnel TSO is supported by the NIC;
5123                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5124                  * are recognized;
5125                  * (3) for tunneled pkts with outer L3 of IPv4,
5126                  * "csum set outer-ip" must be set to hw, because after tso,
5127                  * total_len of outer IP header is changed, and the checksum
5128                  * of outer IP header calculated by sw should be wrong; that
5129                  * is not necessary for IPv6 tunneled pkts because there's no
5130                  * checksum in IP header anymore.
5131                  */
5132
5133                 if (!ports[res->port_id].parse_tunnel)
5134                         fprintf(stderr,
5135                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5136                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5137                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5138                         fprintf(stderr,
5139                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5140         }
5141
5142         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5143         cmd_reconfig_device_queue(res->port_id, 1, 1);
5144 }
5145
5146 static cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5147         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5148                                 tso, "tunnel_tso");
5149 static cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5150         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5151                                 mode, "set");
5152 static cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5153         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5154                                 tso_segsz, RTE_UINT16);
5155 static cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5156         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5157                                 port_id, RTE_UINT16);
5158
5159 static cmdline_parse_inst_t cmd_tunnel_tso_set = {
5160         .f = cmd_tunnel_tso_set_parsed,
5161         .data = NULL,
5162         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5163                 "Set TSO segment size of tunneled packets for csum engine "
5164                 "(0 to disable)",
5165         .tokens = {
5166                 (void *)&cmd_tunnel_tso_set_tso,
5167                 (void *)&cmd_tunnel_tso_set_mode,
5168                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5169                 (void *)&cmd_tunnel_tso_set_portid,
5170                 NULL,
5171         },
5172 };
5173
5174 static cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5175         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5176                                 mode, "show");
5177
5178
5179 static cmdline_parse_inst_t cmd_tunnel_tso_show = {
5180         .f = cmd_tunnel_tso_set_parsed,
5181         .data = NULL,
5182         .help_str = "tunnel_tso show <port_id> "
5183                 "Show TSO segment size of tunneled packets for csum engine",
5184         .tokens = {
5185                 (void *)&cmd_tunnel_tso_set_tso,
5186                 (void *)&cmd_tunnel_tso_show_mode,
5187                 (void *)&cmd_tunnel_tso_set_portid,
5188                 NULL,
5189         },
5190 };
5191
5192 #ifdef RTE_LIB_GRO
5193 /* *** SET GRO FOR A PORT *** */
5194 struct cmd_gro_enable_result {
5195         cmdline_fixed_string_t cmd_set;
5196         cmdline_fixed_string_t cmd_port;
5197         cmdline_fixed_string_t cmd_keyword;
5198         cmdline_fixed_string_t cmd_onoff;
5199         portid_t cmd_pid;
5200 };
5201
5202 static void
5203 cmd_gro_enable_parsed(void *parsed_result,
5204                 __rte_unused struct cmdline *cl,
5205                 __rte_unused void *data)
5206 {
5207         struct cmd_gro_enable_result *res;
5208
5209         res = parsed_result;
5210         if (!strcmp(res->cmd_keyword, "gro"))
5211                 setup_gro(res->cmd_onoff, res->cmd_pid);
5212 }
5213
5214 static cmdline_parse_token_string_t cmd_gro_enable_set =
5215         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5216                         cmd_set, "set");
5217 static cmdline_parse_token_string_t cmd_gro_enable_port =
5218         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5219                         cmd_keyword, "port");
5220 static cmdline_parse_token_num_t cmd_gro_enable_pid =
5221         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5222                         cmd_pid, RTE_UINT16);
5223 static cmdline_parse_token_string_t cmd_gro_enable_keyword =
5224         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5225                         cmd_keyword, "gro");
5226 static cmdline_parse_token_string_t cmd_gro_enable_onoff =
5227         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5228                         cmd_onoff, "on#off");
5229
5230 static cmdline_parse_inst_t cmd_gro_enable = {
5231         .f = cmd_gro_enable_parsed,
5232         .data = NULL,
5233         .help_str = "set port <port_id> gro on|off",
5234         .tokens = {
5235                 (void *)&cmd_gro_enable_set,
5236                 (void *)&cmd_gro_enable_port,
5237                 (void *)&cmd_gro_enable_pid,
5238                 (void *)&cmd_gro_enable_keyword,
5239                 (void *)&cmd_gro_enable_onoff,
5240                 NULL,
5241         },
5242 };
5243
5244 /* *** DISPLAY GRO CONFIGURATION *** */
5245 struct cmd_gro_show_result {
5246         cmdline_fixed_string_t cmd_show;
5247         cmdline_fixed_string_t cmd_port;
5248         cmdline_fixed_string_t cmd_keyword;
5249         portid_t cmd_pid;
5250 };
5251
5252 static void
5253 cmd_gro_show_parsed(void *parsed_result,
5254                 __rte_unused struct cmdline *cl,
5255                 __rte_unused void *data)
5256 {
5257         struct cmd_gro_show_result *res;
5258
5259         res = parsed_result;
5260         if (!strcmp(res->cmd_keyword, "gro"))
5261                 show_gro(res->cmd_pid);
5262 }
5263
5264 static cmdline_parse_token_string_t cmd_gro_show_show =
5265         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5266                         cmd_show, "show");
5267 static cmdline_parse_token_string_t cmd_gro_show_port =
5268         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5269                         cmd_port, "port");
5270 static cmdline_parse_token_num_t cmd_gro_show_pid =
5271         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5272                         cmd_pid, RTE_UINT16);
5273 static cmdline_parse_token_string_t cmd_gro_show_keyword =
5274         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5275                         cmd_keyword, "gro");
5276
5277 static cmdline_parse_inst_t cmd_gro_show = {
5278         .f = cmd_gro_show_parsed,
5279         .data = NULL,
5280         .help_str = "show port <port_id> gro",
5281         .tokens = {
5282                 (void *)&cmd_gro_show_show,
5283                 (void *)&cmd_gro_show_port,
5284                 (void *)&cmd_gro_show_pid,
5285                 (void *)&cmd_gro_show_keyword,
5286                 NULL,
5287         },
5288 };
5289
5290 /* *** SET FLUSH CYCLES FOR GRO *** */
5291 struct cmd_gro_flush_result {
5292         cmdline_fixed_string_t cmd_set;
5293         cmdline_fixed_string_t cmd_keyword;
5294         cmdline_fixed_string_t cmd_flush;
5295         uint8_t cmd_cycles;
5296 };
5297
5298 static void
5299 cmd_gro_flush_parsed(void *parsed_result,
5300                 __rte_unused struct cmdline *cl,
5301                 __rte_unused void *data)
5302 {
5303         struct cmd_gro_flush_result *res;
5304
5305         res = parsed_result;
5306         if ((!strcmp(res->cmd_keyword, "gro")) &&
5307                         (!strcmp(res->cmd_flush, "flush")))
5308                 setup_gro_flush_cycles(res->cmd_cycles);
5309 }
5310
5311 static cmdline_parse_token_string_t cmd_gro_flush_set =
5312         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5313                         cmd_set, "set");
5314 static cmdline_parse_token_string_t cmd_gro_flush_keyword =
5315         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5316                         cmd_keyword, "gro");
5317 static cmdline_parse_token_string_t cmd_gro_flush_flush =
5318         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5319                         cmd_flush, "flush");
5320 static cmdline_parse_token_num_t cmd_gro_flush_cycles =
5321         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5322                         cmd_cycles, RTE_UINT8);
5323
5324 static cmdline_parse_inst_t cmd_gro_flush = {
5325         .f = cmd_gro_flush_parsed,
5326         .data = NULL,
5327         .help_str = "set gro flush <cycles>",
5328         .tokens = {
5329                 (void *)&cmd_gro_flush_set,
5330                 (void *)&cmd_gro_flush_keyword,
5331                 (void *)&cmd_gro_flush_flush,
5332                 (void *)&cmd_gro_flush_cycles,
5333                 NULL,
5334         },
5335 };
5336 #endif /* RTE_LIB_GRO */
5337
5338 #ifdef RTE_LIB_GSO
5339 /* *** ENABLE/DISABLE GSO *** */
5340 struct cmd_gso_enable_result {
5341         cmdline_fixed_string_t cmd_set;
5342         cmdline_fixed_string_t cmd_port;
5343         cmdline_fixed_string_t cmd_keyword;
5344         cmdline_fixed_string_t cmd_mode;
5345         portid_t cmd_pid;
5346 };
5347
5348 static void
5349 cmd_gso_enable_parsed(void *parsed_result,
5350                 __rte_unused struct cmdline *cl,
5351                 __rte_unused void *data)
5352 {
5353         struct cmd_gso_enable_result *res;
5354
5355         res = parsed_result;
5356         if (!strcmp(res->cmd_keyword, "gso"))
5357                 setup_gso(res->cmd_mode, res->cmd_pid);
5358 }
5359
5360 static cmdline_parse_token_string_t cmd_gso_enable_set =
5361         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5362                         cmd_set, "set");
5363 static cmdline_parse_token_string_t cmd_gso_enable_port =
5364         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5365                         cmd_port, "port");
5366 static cmdline_parse_token_string_t cmd_gso_enable_keyword =
5367         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5368                         cmd_keyword, "gso");
5369 static cmdline_parse_token_string_t cmd_gso_enable_mode =
5370         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5371                         cmd_mode, "on#off");
5372 static cmdline_parse_token_num_t cmd_gso_enable_pid =
5373         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5374                         cmd_pid, RTE_UINT16);
5375
5376 static cmdline_parse_inst_t cmd_gso_enable = {
5377         .f = cmd_gso_enable_parsed,
5378         .data = NULL,
5379         .help_str = "set port <port_id> gso on|off",
5380         .tokens = {
5381                 (void *)&cmd_gso_enable_set,
5382                 (void *)&cmd_gso_enable_port,
5383                 (void *)&cmd_gso_enable_pid,
5384                 (void *)&cmd_gso_enable_keyword,
5385                 (void *)&cmd_gso_enable_mode,
5386                 NULL,
5387         },
5388 };
5389
5390 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5391 struct cmd_gso_size_result {
5392         cmdline_fixed_string_t cmd_set;
5393         cmdline_fixed_string_t cmd_keyword;
5394         cmdline_fixed_string_t cmd_segsz;
5395         uint16_t cmd_size;
5396 };
5397
5398 static void
5399 cmd_gso_size_parsed(void *parsed_result,
5400                        __rte_unused struct cmdline *cl,
5401                        __rte_unused void *data)
5402 {
5403         struct cmd_gso_size_result *res = parsed_result;
5404
5405         if (test_done == 0) {
5406                 fprintf(stderr,
5407                         "Before setting GSO segsz, please first stop forwarding\n");
5408                 return;
5409         }
5410
5411         if (!strcmp(res->cmd_keyword, "gso") &&
5412                         !strcmp(res->cmd_segsz, "segsz")) {
5413                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5414                         fprintf(stderr,
5415                                 "gso_size should be larger than %zu. Please input a legal value\n",
5416                                 RTE_GSO_SEG_SIZE_MIN);
5417                 else
5418                         gso_max_segment_size = res->cmd_size;
5419         }
5420 }
5421
5422 static cmdline_parse_token_string_t cmd_gso_size_set =
5423         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5424                                 cmd_set, "set");
5425 static cmdline_parse_token_string_t cmd_gso_size_keyword =
5426         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5427                                 cmd_keyword, "gso");
5428 static cmdline_parse_token_string_t cmd_gso_size_segsz =
5429         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5430                                 cmd_segsz, "segsz");
5431 static cmdline_parse_token_num_t cmd_gso_size_size =
5432         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5433                                 cmd_size, RTE_UINT16);
5434
5435 static cmdline_parse_inst_t cmd_gso_size = {
5436         .f = cmd_gso_size_parsed,
5437         .data = NULL,
5438         .help_str = "set gso segsz <length>",
5439         .tokens = {
5440                 (void *)&cmd_gso_size_set,
5441                 (void *)&cmd_gso_size_keyword,
5442                 (void *)&cmd_gso_size_segsz,
5443                 (void *)&cmd_gso_size_size,
5444                 NULL,
5445         },
5446 };
5447
5448 /* *** SHOW GSO CONFIGURATION *** */
5449 struct cmd_gso_show_result {
5450         cmdline_fixed_string_t cmd_show;
5451         cmdline_fixed_string_t cmd_port;
5452         cmdline_fixed_string_t cmd_keyword;
5453         portid_t cmd_pid;
5454 };
5455
5456 static void
5457 cmd_gso_show_parsed(void *parsed_result,
5458                        __rte_unused struct cmdline *cl,
5459                        __rte_unused void *data)
5460 {
5461         struct cmd_gso_show_result *res = parsed_result;
5462
5463         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5464                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5465                 return;
5466         }
5467         if (!strcmp(res->cmd_keyword, "gso")) {
5468                 if (gso_ports[res->cmd_pid].enable) {
5469                         printf("Max GSO'd packet size: %uB\n"
5470                                         "Supported GSO types: TCP/IPv4, "
5471                                         "UDP/IPv4, VxLAN with inner "
5472                                         "TCP/IPv4 packet, GRE with inner "
5473                                         "TCP/IPv4 packet\n",
5474                                         gso_max_segment_size);
5475                 } else
5476                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5477         }
5478 }
5479
5480 static cmdline_parse_token_string_t cmd_gso_show_show =
5481 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5482                 cmd_show, "show");
5483 static cmdline_parse_token_string_t cmd_gso_show_port =
5484 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5485                 cmd_port, "port");
5486 static cmdline_parse_token_string_t cmd_gso_show_keyword =
5487         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5488                                 cmd_keyword, "gso");
5489 static cmdline_parse_token_num_t cmd_gso_show_pid =
5490         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5491                                 cmd_pid, RTE_UINT16);
5492
5493 static cmdline_parse_inst_t cmd_gso_show = {
5494         .f = cmd_gso_show_parsed,
5495         .data = NULL,
5496         .help_str = "show port <port_id> gso",
5497         .tokens = {
5498                 (void *)&cmd_gso_show_show,
5499                 (void *)&cmd_gso_show_port,
5500                 (void *)&cmd_gso_show_pid,
5501                 (void *)&cmd_gso_show_keyword,
5502                 NULL,
5503         },
5504 };
5505 #endif /* RTE_LIB_GSO */
5506
5507 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5508 struct cmd_set_flush_rx {
5509         cmdline_fixed_string_t set;
5510         cmdline_fixed_string_t flush_rx;
5511         cmdline_fixed_string_t mode;
5512 };
5513
5514 static void
5515 cmd_set_flush_rx_parsed(void *parsed_result,
5516                 __rte_unused struct cmdline *cl,
5517                 __rte_unused void *data)
5518 {
5519         struct cmd_set_flush_rx *res = parsed_result;
5520
5521         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5522                 printf("multi-process doesn't support to flush Rx queues.\n");
5523                 return;
5524         }
5525
5526         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5527 }
5528
5529 static cmdline_parse_token_string_t cmd_setflushrx_set =
5530         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5531                         set, "set");
5532 static cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5533         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5534                         flush_rx, "flush_rx");
5535 static cmdline_parse_token_string_t cmd_setflushrx_mode =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5537                         mode, "on#off");
5538
5539
5540 static cmdline_parse_inst_t cmd_set_flush_rx = {
5541         .f = cmd_set_flush_rx_parsed,
5542         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5543         .data = NULL,
5544         .tokens = {
5545                 (void *)&cmd_setflushrx_set,
5546                 (void *)&cmd_setflushrx_flush_rx,
5547                 (void *)&cmd_setflushrx_mode,
5548                 NULL,
5549         },
5550 };
5551
5552 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5553 struct cmd_set_link_check {
5554         cmdline_fixed_string_t set;
5555         cmdline_fixed_string_t link_check;
5556         cmdline_fixed_string_t mode;
5557 };
5558
5559 static void
5560 cmd_set_link_check_parsed(void *parsed_result,
5561                 __rte_unused struct cmdline *cl,
5562                 __rte_unused void *data)
5563 {
5564         struct cmd_set_link_check *res = parsed_result;
5565         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5566 }
5567
5568 static cmdline_parse_token_string_t cmd_setlinkcheck_set =
5569         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5570                         set, "set");
5571 static cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5572         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5573                         link_check, "link_check");
5574 static cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5575         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5576                         mode, "on#off");
5577
5578
5579 static cmdline_parse_inst_t cmd_set_link_check = {
5580         .f = cmd_set_link_check_parsed,
5581         .help_str = "set link_check on|off: Enable/Disable link status check "
5582                     "when starting/stopping a port",
5583         .data = NULL,
5584         .tokens = {
5585                 (void *)&cmd_setlinkcheck_set,
5586                 (void *)&cmd_setlinkcheck_link_check,
5587                 (void *)&cmd_setlinkcheck_mode,
5588                 NULL,
5589         },
5590 };
5591
5592 /* *** SET NIC BYPASS MODE *** */
5593 struct cmd_set_bypass_mode_result {
5594         cmdline_fixed_string_t set;
5595         cmdline_fixed_string_t bypass;
5596         cmdline_fixed_string_t mode;
5597         cmdline_fixed_string_t value;
5598         portid_t port_id;
5599 };
5600
5601 static void
5602 cmd_set_bypass_mode_parsed(void *parsed_result,
5603                 __rte_unused struct cmdline *cl,
5604                 __rte_unused void *data)
5605 {
5606         struct cmd_set_bypass_mode_result *res = parsed_result;
5607         portid_t port_id = res->port_id;
5608         int32_t rc = -EINVAL;
5609
5610 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5611         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5612
5613         if (!strcmp(res->value, "bypass"))
5614                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5615         else if (!strcmp(res->value, "isolate"))
5616                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5617         else
5618                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5619
5620         /* Set the bypass mode for the relevant port. */
5621         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5622 #endif
5623         if (rc != 0)
5624                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5625                         port_id);
5626 }
5627
5628 static cmdline_parse_token_string_t cmd_setbypass_mode_set =
5629         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5630                         set, "set");
5631 static cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5633                         bypass, "bypass");
5634 static cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5636                         mode, "mode");
5637 static cmdline_parse_token_string_t cmd_setbypass_mode_value =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5639                         value, "normal#bypass#isolate");
5640 static cmdline_parse_token_num_t cmd_setbypass_mode_port =
5641         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5642                                 port_id, RTE_UINT16);
5643
5644 static cmdline_parse_inst_t cmd_set_bypass_mode = {
5645         .f = cmd_set_bypass_mode_parsed,
5646         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5647                     "Set the NIC bypass mode for port_id",
5648         .data = NULL,
5649         .tokens = {
5650                 (void *)&cmd_setbypass_mode_set,
5651                 (void *)&cmd_setbypass_mode_bypass,
5652                 (void *)&cmd_setbypass_mode_mode,
5653                 (void *)&cmd_setbypass_mode_value,
5654                 (void *)&cmd_setbypass_mode_port,
5655                 NULL,
5656         },
5657 };
5658
5659 /* *** SET NIC BYPASS EVENT *** */
5660 struct cmd_set_bypass_event_result {
5661         cmdline_fixed_string_t set;
5662         cmdline_fixed_string_t bypass;
5663         cmdline_fixed_string_t event;
5664         cmdline_fixed_string_t event_value;
5665         cmdline_fixed_string_t mode;
5666         cmdline_fixed_string_t mode_value;
5667         portid_t port_id;
5668 };
5669
5670 static void
5671 cmd_set_bypass_event_parsed(void *parsed_result,
5672                 __rte_unused struct cmdline *cl,
5673                 __rte_unused void *data)
5674 {
5675         int32_t rc = -EINVAL;
5676         struct cmd_set_bypass_event_result *res = parsed_result;
5677         portid_t port_id = res->port_id;
5678
5679 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5680         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5681         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5682
5683         if (!strcmp(res->event_value, "timeout"))
5684                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5685         else if (!strcmp(res->event_value, "os_on"))
5686                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5687         else if (!strcmp(res->event_value, "os_off"))
5688                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5689         else if (!strcmp(res->event_value, "power_on"))
5690                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5691         else if (!strcmp(res->event_value, "power_off"))
5692                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5693         else
5694                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5695
5696         if (!strcmp(res->mode_value, "bypass"))
5697                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5698         else if (!strcmp(res->mode_value, "isolate"))
5699                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5700         else
5701                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5702
5703         /* Set the watchdog timeout. */
5704         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5705
5706                 rc = -EINVAL;
5707                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5708                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5709                                                            bypass_timeout);
5710                 }
5711                 if (rc != 0) {
5712                         fprintf(stderr,
5713                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5714                                 bypass_timeout, port_id, rc);
5715                 }
5716         }
5717
5718         /* Set the bypass event to transition to bypass mode. */
5719         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5720                                               bypass_mode);
5721 #endif
5722
5723         if (rc != 0)
5724                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5725                         port_id);
5726 }
5727
5728 static cmdline_parse_token_string_t cmd_setbypass_event_set =
5729         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5730                         set, "set");
5731 static cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5732         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5733                         bypass, "bypass");
5734 static cmdline_parse_token_string_t cmd_setbypass_event_event =
5735         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5736                         event, "event");
5737 static cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5738         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5739                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5740 static cmdline_parse_token_string_t cmd_setbypass_event_mode =
5741         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5742                         mode, "mode");
5743 static cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5744         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5745                         mode_value, "normal#bypass#isolate");
5746 static cmdline_parse_token_num_t cmd_setbypass_event_port =
5747         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5748                                 port_id, RTE_UINT16);
5749
5750 static cmdline_parse_inst_t cmd_set_bypass_event = {
5751         .f = cmd_set_bypass_event_parsed,
5752         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5753                 "power_off mode normal|bypass|isolate <port_id>: "
5754                 "Set the NIC bypass event mode for port_id",
5755         .data = NULL,
5756         .tokens = {
5757                 (void *)&cmd_setbypass_event_set,
5758                 (void *)&cmd_setbypass_event_bypass,
5759                 (void *)&cmd_setbypass_event_event,
5760                 (void *)&cmd_setbypass_event_event_value,
5761                 (void *)&cmd_setbypass_event_mode,
5762                 (void *)&cmd_setbypass_event_mode_value,
5763                 (void *)&cmd_setbypass_event_port,
5764                 NULL,
5765         },
5766 };
5767
5768
5769 /* *** SET NIC BYPASS TIMEOUT *** */
5770 struct cmd_set_bypass_timeout_result {
5771         cmdline_fixed_string_t set;
5772         cmdline_fixed_string_t bypass;
5773         cmdline_fixed_string_t timeout;
5774         cmdline_fixed_string_t value;
5775 };
5776
5777 static void
5778 cmd_set_bypass_timeout_parsed(void *parsed_result,
5779                 __rte_unused struct cmdline *cl,
5780                 __rte_unused void *data)
5781 {
5782         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5783
5784 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5785         if (!strcmp(res->value, "1.5"))
5786                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5787         else if (!strcmp(res->value, "2"))
5788                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5789         else if (!strcmp(res->value, "3"))
5790                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5791         else if (!strcmp(res->value, "4"))
5792                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5793         else if (!strcmp(res->value, "8"))
5794                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5795         else if (!strcmp(res->value, "16"))
5796                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5797         else if (!strcmp(res->value, "32"))
5798                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5799         else
5800                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5801 #endif
5802 }
5803
5804 static cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5805         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5806                         set, "set");
5807 static cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5808         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5809                         bypass, "bypass");
5810 static cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5811         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5812                         timeout, "timeout");
5813 static cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5814         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5815                         value, "0#1.5#2#3#4#8#16#32");
5816
5817 static cmdline_parse_inst_t cmd_set_bypass_timeout = {
5818         .f = cmd_set_bypass_timeout_parsed,
5819         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5820                 "Set the NIC bypass watchdog timeout in seconds",
5821         .data = NULL,
5822         .tokens = {
5823                 (void *)&cmd_setbypass_timeout_set,
5824                 (void *)&cmd_setbypass_timeout_bypass,
5825                 (void *)&cmd_setbypass_timeout_timeout,
5826                 (void *)&cmd_setbypass_timeout_value,
5827                 NULL,
5828         },
5829 };
5830
5831 /* *** SHOW NIC BYPASS MODE *** */
5832 struct cmd_show_bypass_config_result {
5833         cmdline_fixed_string_t show;
5834         cmdline_fixed_string_t bypass;
5835         cmdline_fixed_string_t config;
5836         portid_t port_id;
5837 };
5838
5839 static void
5840 cmd_show_bypass_config_parsed(void *parsed_result,
5841                 __rte_unused struct cmdline *cl,
5842                 __rte_unused void *data)
5843 {
5844         struct cmd_show_bypass_config_result *res = parsed_result;
5845         portid_t port_id = res->port_id;
5846         int rc = -EINVAL;
5847 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5848         uint32_t event_mode;
5849         uint32_t bypass_mode;
5850         uint32_t timeout = bypass_timeout;
5851         unsigned int i;
5852
5853         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5854                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5855         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5856                 {"UNKNOWN", "normal", "bypass", "isolate"};
5857         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5858                 "NONE",
5859                 "OS/board on",
5860                 "power supply on",
5861                 "OS/board off",
5862                 "power supply off",
5863                 "timeout"};
5864
5865         /* Display the bypass mode.*/
5866         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5867                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5868                         port_id);
5869                 return;
5870         }
5871         else {
5872                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5873                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5874
5875                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5876         }
5877
5878         /* Display the bypass timeout.*/
5879         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5880                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5881
5882         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5883
5884         /* Display the bypass events and associated modes. */
5885         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5886
5887                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5888                         fprintf(stderr,
5889                                 "\tFailed to get bypass mode for event = %s\n",
5890                                 events[i]);
5891                 } else {
5892                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5893                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5894
5895                         printf("\tbypass event: %-16s = %s\n", events[i],
5896                                 modes[event_mode]);
5897                 }
5898         }
5899 #endif
5900         if (rc != 0)
5901                 fprintf(stderr,
5902                         "\tFailed to get bypass configuration for port = %d\n",
5903                        port_id);
5904 }
5905
5906 static cmdline_parse_token_string_t cmd_showbypass_config_show =
5907         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5908                         show, "show");
5909 static cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5910         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5911                         bypass, "bypass");
5912 static cmdline_parse_token_string_t cmd_showbypass_config_config =
5913         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5914                         config, "config");
5915 static cmdline_parse_token_num_t cmd_showbypass_config_port =
5916         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5917                                 port_id, RTE_UINT16);
5918
5919 static cmdline_parse_inst_t cmd_show_bypass_config = {
5920         .f = cmd_show_bypass_config_parsed,
5921         .help_str = "show bypass config <port_id>: "
5922                     "Show the NIC bypass config for port_id",
5923         .data = NULL,
5924         .tokens = {
5925                 (void *)&cmd_showbypass_config_show,
5926                 (void *)&cmd_showbypass_config_bypass,
5927                 (void *)&cmd_showbypass_config_config,
5928                 (void *)&cmd_showbypass_config_port,
5929                 NULL,
5930         },
5931 };
5932
5933 #ifdef RTE_NET_BOND
5934 /* *** SET BONDING MODE *** */
5935 struct cmd_set_bonding_mode_result {
5936         cmdline_fixed_string_t set;
5937         cmdline_fixed_string_t bonding;
5938         cmdline_fixed_string_t mode;
5939         uint8_t value;
5940         portid_t port_id;
5941 };
5942
5943 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5944                 __rte_unused  struct cmdline *cl,
5945                 __rte_unused void *data)
5946 {
5947         struct cmd_set_bonding_mode_result *res = parsed_result;
5948         portid_t port_id = res->port_id;
5949         struct rte_port *port = &ports[port_id];
5950
5951         /*
5952          * Bonding mode changed means resources of device changed, like whether
5953          * started rte timer or not. Device should be restarted when resources
5954          * of device changed.
5955          */
5956         if (port->port_status != RTE_PORT_STOPPED) {
5957                 fprintf(stderr,
5958                         "\t Error: Can't set bonding mode when port %d is not stopped\n",
5959                         port_id);
5960                 return;
5961         }
5962
5963         /* Set the bonding mode for the relevant port. */
5964         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5965                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5966                         port_id);
5967 }
5968
5969 static cmdline_parse_token_string_t cmd_setbonding_mode_set =
5970 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5971                 set, "set");
5972 static cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5973 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5974                 bonding, "bonding");
5975 static cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5976 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5977                 mode, "mode");
5978 static cmdline_parse_token_num_t cmd_setbonding_mode_value =
5979 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5980                 value, RTE_UINT8);
5981 static cmdline_parse_token_num_t cmd_setbonding_mode_port =
5982 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5983                 port_id, RTE_UINT16);
5984
5985 static cmdline_parse_inst_t cmd_set_bonding_mode = {
5986                 .f = cmd_set_bonding_mode_parsed,
5987                 .help_str = "set bonding mode <mode_value> <port_id>: "
5988                         "Set the bonding mode for port_id",
5989                 .data = NULL,
5990                 .tokens = {
5991                                 (void *) &cmd_setbonding_mode_set,
5992                                 (void *) &cmd_setbonding_mode_bonding,
5993                                 (void *) &cmd_setbonding_mode_mode,
5994                                 (void *) &cmd_setbonding_mode_value,
5995                                 (void *) &cmd_setbonding_mode_port,
5996                                 NULL
5997                 }
5998 };
5999
6000 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
6001 struct cmd_set_bonding_lacp_dedicated_queues_result {
6002         cmdline_fixed_string_t set;
6003         cmdline_fixed_string_t bonding;
6004         cmdline_fixed_string_t lacp;
6005         cmdline_fixed_string_t dedicated_queues;
6006         portid_t port_id;
6007         cmdline_fixed_string_t mode;
6008 };
6009
6010 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
6011                 __rte_unused  struct cmdline *cl,
6012                 __rte_unused void *data)
6013 {
6014         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
6015         portid_t port_id = res->port_id;
6016         struct rte_port *port;
6017
6018         port = &ports[port_id];
6019
6020         /** Check if the port is not started **/
6021         if (port->port_status != RTE_PORT_STOPPED) {
6022                 fprintf(stderr, "Please stop port %d first\n", port_id);
6023                 return;
6024         }
6025
6026         if (!strcmp(res->mode, "enable")) {
6027                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6028                         printf("Dedicate queues for LACP control packets"
6029                                         " enabled\n");
6030                 else
6031                         printf("Enabling dedicate queues for LACP control "
6032                                         "packets on port %d failed\n", port_id);
6033         } else if (!strcmp(res->mode, "disable")) {
6034                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6035                         printf("Dedicated queues for LACP control packets "
6036                                         "disabled\n");
6037                 else
6038                         printf("Disabling dedicated queues for LACP control "
6039                                         "traffic on port %d failed\n", port_id);
6040         }
6041 }
6042
6043 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6044 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6045                 set, "set");
6046 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6047 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6048                 bonding, "bonding");
6049 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6051                 lacp, "lacp");
6052 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6053 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6054                 dedicated_queues, "dedicated_queues");
6055 static cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6056 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6057                 port_id, RTE_UINT16);
6058 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6059 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6060                 mode, "enable#disable");
6061
6062 static cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6063                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6064                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6065                         "enable|disable: "
6066                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6067                 .data = NULL,
6068                 .tokens = {
6069                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6070                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6071                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6072                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6073                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6074                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6075                         NULL
6076                 }
6077 };
6078
6079 /* *** SET BALANCE XMIT POLICY *** */
6080 struct cmd_set_bonding_balance_xmit_policy_result {
6081         cmdline_fixed_string_t set;
6082         cmdline_fixed_string_t bonding;
6083         cmdline_fixed_string_t balance_xmit_policy;
6084         portid_t port_id;
6085         cmdline_fixed_string_t policy;
6086 };
6087
6088 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6089                 __rte_unused  struct cmdline *cl,
6090                 __rte_unused void *data)
6091 {
6092         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6093         portid_t port_id = res->port_id;
6094         uint8_t policy;
6095
6096         if (!strcmp(res->policy, "l2")) {
6097                 policy = BALANCE_XMIT_POLICY_LAYER2;
6098         } else if (!strcmp(res->policy, "l23")) {
6099                 policy = BALANCE_XMIT_POLICY_LAYER23;
6100         } else if (!strcmp(res->policy, "l34")) {
6101                 policy = BALANCE_XMIT_POLICY_LAYER34;
6102         } else {
6103                 fprintf(stderr, "\t Invalid xmit policy selection");
6104                 return;
6105         }
6106
6107         /* Set the bonding mode for the relevant port. */
6108         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6109                 fprintf(stderr,
6110                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6111                         port_id);
6112         }
6113 }
6114
6115 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6116 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6117                 set, "set");
6118 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6119 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6120                 bonding, "bonding");
6121 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6123                 balance_xmit_policy, "balance_xmit_policy");
6124 static cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6125 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6126                 port_id, RTE_UINT16);
6127 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6128 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6129                 policy, "l2#l23#l34");
6130
6131 static cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6132                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6133                 .help_str = "set bonding balance_xmit_policy <port_id> "
6134                         "l2|l23|l34: "
6135                         "Set the bonding balance_xmit_policy for port_id",
6136                 .data = NULL,
6137                 .tokens = {
6138                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6139                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6140                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6141                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6142                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6143                                 NULL
6144                 }
6145 };
6146
6147 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6148 struct cmd_show_bonding_lacp_info_result {
6149         cmdline_fixed_string_t show;
6150         cmdline_fixed_string_t bonding;
6151         cmdline_fixed_string_t lacp;
6152         cmdline_fixed_string_t info;
6153         portid_t port_id;
6154 };
6155
6156 static void port_param_show(struct port_params *params)
6157 {
6158         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6159
6160         printf("\t\tsystem priority: %u\n", params->system_priority);
6161         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6162         printf("\t\tsystem mac address: %s\n", buf);
6163         printf("\t\tport key: %u\n", params->key);
6164         printf("\t\tport priority: %u\n", params->port_priority);
6165         printf("\t\tport number: %u\n", params->port_number);
6166 }
6167
6168 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6169 {
6170         char a_state[256] = { 0 };
6171         char p_state[256] = { 0 };
6172         int a_len = 0;
6173         int p_len = 0;
6174         uint32_t i;
6175
6176         static const char * const state[] = {
6177                 "ACTIVE",
6178                 "TIMEOUT",
6179                 "AGGREGATION",
6180                 "SYNCHRONIZATION",
6181                 "COLLECTING",
6182                 "DISTRIBUTING",
6183                 "DEFAULTED",
6184                 "EXPIRED"
6185         };
6186         static const char * const selection[] = {
6187                 "UNSELECTED",
6188                 "STANDBY",
6189                 "SELECTED"
6190         };
6191
6192         for (i = 0; i < RTE_DIM(state); i++) {
6193                 if ((info->actor_state >> i) & 1)
6194                         a_len += snprintf(&a_state[a_len],
6195                                                 RTE_DIM(a_state) - a_len, "%s ",
6196                                                 state[i]);
6197
6198                 if ((info->partner_state >> i) & 1)
6199                         p_len += snprintf(&p_state[p_len],
6200                                                 RTE_DIM(p_state) - p_len, "%s ",
6201                                                 state[i]);
6202         }
6203         printf("\tAggregator port id: %u\n", info->agg_port_id);
6204         printf("\tselection: %s\n", selection[info->selected]);
6205         printf("\tActor detail info:\n");
6206         port_param_show(&info->actor);
6207         printf("\t\tport state: %s\n", a_state);
6208         printf("\tPartner detail info:\n");
6209         port_param_show(&info->partner);
6210         printf("\t\tport state: %s\n", p_state);
6211         printf("\n");
6212 }
6213
6214 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6215 {
6216         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6217         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6218         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6219         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6220         printf("\taggregate wait timeout: %u ms\n",
6221                         conf->aggregate_wait_timeout_ms);
6222         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6223         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6224         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6225         switch (conf->agg_selection) {
6226         case AGG_BANDWIDTH:
6227                 printf("\taggregation mode: bandwidth\n");
6228                 break;
6229         case AGG_STABLE:
6230                 printf("\taggregation mode: stable\n");
6231                 break;
6232         case AGG_COUNT:
6233                 printf("\taggregation mode: count\n");
6234                 break;
6235         default:
6236                 printf("\taggregation mode: invalid\n");
6237                 break;
6238         }
6239
6240         printf("\n");
6241 }
6242
6243 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6244                 __rte_unused  struct cmdline *cl,
6245                 __rte_unused void *data)
6246 {
6247         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6248         struct rte_eth_bond_8023ad_slave_info slave_info;
6249         struct rte_eth_bond_8023ad_conf port_conf;
6250         portid_t slaves[RTE_MAX_ETHPORTS];
6251         portid_t port_id = res->port_id;
6252         int num_active_slaves;
6253         int bonding_mode;
6254         int i;
6255         int ret;
6256
6257         bonding_mode = rte_eth_bond_mode_get(port_id);
6258         if (bonding_mode != BONDING_MODE_8023AD) {
6259                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6260                 return;
6261         }
6262
6263         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6264                         RTE_MAX_ETHPORTS);
6265         if (num_active_slaves < 0) {
6266                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6267                                 port_id);
6268                 return;
6269         }
6270         if (num_active_slaves == 0)
6271                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6272                         port_id);
6273
6274         printf("\tIEEE802.3 port: %u\n", port_id);
6275         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6276         if (ret) {
6277                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6278                         port_id);
6279                 return;
6280         }
6281         lacp_conf_show(&port_conf);
6282
6283         for (i = 0; i < num_active_slaves; i++) {
6284                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6285                                 &slave_info);
6286                 if (ret) {
6287                         fprintf(stderr, "\tGet slave device %u info failed\n",
6288                                 slaves[i]);
6289                         return;
6290                 }
6291                 printf("\tSlave Port: %u\n", slaves[i]);
6292                 lacp_slave_info_show(&slave_info);
6293         }
6294 }
6295
6296 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6297 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6298                 show, "show");
6299 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6300 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6301                 bonding, "bonding");
6302 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6303 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6304                 bonding, "lacp");
6305 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6306 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6307                 info, "info");
6308 static cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6309 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6310                 port_id, RTE_UINT16);
6311
6312 static cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6313                 .f = cmd_show_bonding_lacp_info_parsed,
6314                 .help_str = "show bonding lacp info <port_id> : "
6315                         "Show bonding IEEE802.3 information for port_id",
6316                 .data = NULL,
6317                 .tokens = {
6318                         (void *)&cmd_show_bonding_lacp_info_show,
6319                         (void *)&cmd_show_bonding_lacp_info_bonding,
6320                         (void *)&cmd_show_bonding_lacp_info_lacp,
6321                         (void *)&cmd_show_bonding_lacp_info_info,
6322                         (void *)&cmd_show_bonding_lacp_info_port_id,
6323                         NULL
6324                 }
6325 };
6326
6327 /* *** SHOW NIC BONDING CONFIGURATION *** */
6328 struct cmd_show_bonding_config_result {
6329         cmdline_fixed_string_t show;
6330         cmdline_fixed_string_t bonding;
6331         cmdline_fixed_string_t config;
6332         portid_t port_id;
6333 };
6334
6335 static void cmd_show_bonding_config_parsed(void *parsed_result,
6336                 __rte_unused  struct cmdline *cl,
6337                 __rte_unused void *data)
6338 {
6339         struct cmd_show_bonding_config_result *res = parsed_result;
6340         int bonding_mode, agg_mode;
6341         portid_t slaves[RTE_MAX_ETHPORTS];
6342         int num_slaves, num_active_slaves;
6343         int primary_id;
6344         int i;
6345         portid_t port_id = res->port_id;
6346
6347         /* Display the bonding mode.*/
6348         bonding_mode = rte_eth_bond_mode_get(port_id);
6349         if (bonding_mode < 0) {
6350                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6351                         port_id);
6352                 return;
6353         } else
6354                 printf("\tBonding mode: %d\n", bonding_mode);
6355
6356         if (bonding_mode == BONDING_MODE_BALANCE ||
6357                 bonding_mode == BONDING_MODE_8023AD) {
6358                 int balance_xmit_policy;
6359
6360                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6361                 if (balance_xmit_policy < 0) {
6362                         fprintf(stderr,
6363                                 "\tFailed to get balance xmit policy for port = %d\n",
6364                                 port_id);
6365                         return;
6366                 } else {
6367                         printf("\tBalance Xmit Policy: ");
6368
6369                         switch (balance_xmit_policy) {
6370                         case BALANCE_XMIT_POLICY_LAYER2:
6371                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6372                                 break;
6373                         case BALANCE_XMIT_POLICY_LAYER23:
6374                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6375                                 break;
6376                         case BALANCE_XMIT_POLICY_LAYER34:
6377                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6378                                 break;
6379                         }
6380                         printf("\n");
6381                 }
6382         }
6383
6384         if (bonding_mode == BONDING_MODE_8023AD) {
6385                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6386                 printf("\tIEEE802.3AD Aggregator Mode: ");
6387                 switch (agg_mode) {
6388                 case AGG_BANDWIDTH:
6389                         printf("bandwidth");
6390                         break;
6391                 case AGG_STABLE:
6392                         printf("stable");
6393                         break;
6394                 case AGG_COUNT:
6395                         printf("count");
6396                         break;
6397                 }
6398                 printf("\n");
6399         }
6400
6401         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6402
6403         if (num_slaves < 0) {
6404                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6405                         port_id);
6406                 return;
6407         }
6408         if (num_slaves > 0) {
6409                 printf("\tSlaves (%d): [", num_slaves);
6410                 for (i = 0; i < num_slaves - 1; i++)
6411                         printf("%d ", slaves[i]);
6412
6413                 printf("%d]\n", slaves[num_slaves - 1]);
6414         } else {
6415                 printf("\tSlaves: []\n");
6416
6417         }
6418
6419         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6420                         RTE_MAX_ETHPORTS);
6421
6422         if (num_active_slaves < 0) {
6423                 fprintf(stderr,
6424                         "\tFailed to get active slave list for port = %d\n",
6425                         port_id);
6426                 return;
6427         }
6428         if (num_active_slaves > 0) {
6429                 printf("\tActive Slaves (%d): [", num_active_slaves);
6430                 for (i = 0; i < num_active_slaves - 1; i++)
6431                         printf("%d ", slaves[i]);
6432
6433                 printf("%d]\n", slaves[num_active_slaves - 1]);
6434
6435         } else {
6436                 printf("\tActive Slaves: []\n");
6437
6438         }
6439
6440         primary_id = rte_eth_bond_primary_get(port_id);
6441         if (primary_id < 0) {
6442                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6443                         port_id);
6444                 return;
6445         } else
6446                 printf("\tPrimary: [%d]\n", primary_id);
6447
6448 }
6449
6450 static cmdline_parse_token_string_t cmd_showbonding_config_show =
6451 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6452                 show, "show");
6453 static cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6454 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6455                 bonding, "bonding");
6456 static cmdline_parse_token_string_t cmd_showbonding_config_config =
6457 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6458                 config, "config");
6459 static cmdline_parse_token_num_t cmd_showbonding_config_port =
6460 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6461                 port_id, RTE_UINT16);
6462
6463 static cmdline_parse_inst_t cmd_show_bonding_config = {
6464                 .f = cmd_show_bonding_config_parsed,
6465                 .help_str = "show bonding config <port_id>: "
6466                         "Show the bonding config for port_id",
6467                 .data = NULL,
6468                 .tokens = {
6469                                 (void *)&cmd_showbonding_config_show,
6470                                 (void *)&cmd_showbonding_config_bonding,
6471                                 (void *)&cmd_showbonding_config_config,
6472                                 (void *)&cmd_showbonding_config_port,
6473                                 NULL
6474                 }
6475 };
6476
6477 /* *** SET BONDING PRIMARY *** */
6478 struct cmd_set_bonding_primary_result {
6479         cmdline_fixed_string_t set;
6480         cmdline_fixed_string_t bonding;
6481         cmdline_fixed_string_t primary;
6482         portid_t slave_id;
6483         portid_t port_id;
6484 };
6485
6486 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6487                 __rte_unused  struct cmdline *cl,
6488                 __rte_unused void *data)
6489 {
6490         struct cmd_set_bonding_primary_result *res = parsed_result;
6491         portid_t master_port_id = res->port_id;
6492         portid_t slave_port_id = res->slave_id;
6493
6494         /* Set the primary slave for a bonded device. */
6495         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6496                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6497                         master_port_id);
6498                 return;
6499         }
6500         init_port_config();
6501 }
6502
6503 static cmdline_parse_token_string_t cmd_setbonding_primary_set =
6504 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6505                 set, "set");
6506 static cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6507 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6508                 bonding, "bonding");
6509 static cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6510 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6511                 primary, "primary");
6512 static cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6513 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6514                 slave_id, RTE_UINT16);
6515 static cmdline_parse_token_num_t cmd_setbonding_primary_port =
6516 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6517                 port_id, RTE_UINT16);
6518
6519 static cmdline_parse_inst_t cmd_set_bonding_primary = {
6520                 .f = cmd_set_bonding_primary_parsed,
6521                 .help_str = "set bonding primary <slave_id> <port_id>: "
6522                         "Set the primary slave for port_id",
6523                 .data = NULL,
6524                 .tokens = {
6525                                 (void *)&cmd_setbonding_primary_set,
6526                                 (void *)&cmd_setbonding_primary_bonding,
6527                                 (void *)&cmd_setbonding_primary_primary,
6528                                 (void *)&cmd_setbonding_primary_slave,
6529                                 (void *)&cmd_setbonding_primary_port,
6530                                 NULL
6531                 }
6532 };
6533
6534 /* *** ADD SLAVE *** */
6535 struct cmd_add_bonding_slave_result {
6536         cmdline_fixed_string_t add;
6537         cmdline_fixed_string_t bonding;
6538         cmdline_fixed_string_t slave;
6539         portid_t slave_id;
6540         portid_t port_id;
6541 };
6542
6543 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6544                 __rte_unused  struct cmdline *cl,
6545                 __rte_unused void *data)
6546 {
6547         struct cmd_add_bonding_slave_result *res = parsed_result;
6548         portid_t master_port_id = res->port_id;
6549         portid_t slave_port_id = res->slave_id;
6550
6551         /* add the slave for a bonded device. */
6552         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6553                 fprintf(stderr,
6554                         "\t Failed to add slave %d to master port = %d.\n",
6555                         slave_port_id, master_port_id);
6556                 return;
6557         }
6558         init_port_config();
6559         set_port_slave_flag(slave_port_id);
6560 }
6561
6562 static cmdline_parse_token_string_t cmd_addbonding_slave_add =
6563 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6564                 add, "add");
6565 static cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6566 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6567                 bonding, "bonding");
6568 static cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6569 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6570                 slave, "slave");
6571 static cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6572 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6573                 slave_id, RTE_UINT16);
6574 static cmdline_parse_token_num_t cmd_addbonding_slave_port =
6575 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6576                 port_id, RTE_UINT16);
6577
6578 static cmdline_parse_inst_t cmd_add_bonding_slave = {
6579                 .f = cmd_add_bonding_slave_parsed,
6580                 .help_str = "add bonding slave <slave_id> <port_id>: "
6581                         "Add a slave device to a bonded device",
6582                 .data = NULL,
6583                 .tokens = {
6584                                 (void *)&cmd_addbonding_slave_add,
6585                                 (void *)&cmd_addbonding_slave_bonding,
6586                                 (void *)&cmd_addbonding_slave_slave,
6587                                 (void *)&cmd_addbonding_slave_slaveid,
6588                                 (void *)&cmd_addbonding_slave_port,
6589                                 NULL
6590                 }
6591 };
6592
6593 /* *** REMOVE SLAVE *** */
6594 struct cmd_remove_bonding_slave_result {
6595         cmdline_fixed_string_t remove;
6596         cmdline_fixed_string_t bonding;
6597         cmdline_fixed_string_t slave;
6598         portid_t slave_id;
6599         portid_t port_id;
6600 };
6601
6602 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6603                 __rte_unused  struct cmdline *cl,
6604                 __rte_unused void *data)
6605 {
6606         struct cmd_remove_bonding_slave_result *res = parsed_result;
6607         portid_t master_port_id = res->port_id;
6608         portid_t slave_port_id = res->slave_id;
6609
6610         /* remove the slave from a bonded device. */
6611         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6612                 fprintf(stderr,
6613                         "\t Failed to remove slave %d from master port = %d.\n",
6614                         slave_port_id, master_port_id);
6615                 return;
6616         }
6617         init_port_config();
6618         clear_port_slave_flag(slave_port_id);
6619 }
6620
6621 static cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6622                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6623                                 remove, "remove");
6624 static cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6625                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6626                                 bonding, "bonding");
6627 static cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6628                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6629                                 slave, "slave");
6630 static cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6631                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6632                                 slave_id, RTE_UINT16);
6633 static cmdline_parse_token_num_t cmd_removebonding_slave_port =
6634                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6635                                 port_id, RTE_UINT16);
6636
6637 static cmdline_parse_inst_t cmd_remove_bonding_slave = {
6638                 .f = cmd_remove_bonding_slave_parsed,
6639                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6640                         "Remove a slave device from a bonded device",
6641                 .data = NULL,
6642                 .tokens = {
6643                                 (void *)&cmd_removebonding_slave_remove,
6644                                 (void *)&cmd_removebonding_slave_bonding,
6645                                 (void *)&cmd_removebonding_slave_slave,
6646                                 (void *)&cmd_removebonding_slave_slaveid,
6647                                 (void *)&cmd_removebonding_slave_port,
6648                                 NULL
6649                 }
6650 };
6651
6652 /* *** CREATE BONDED DEVICE *** */
6653 struct cmd_create_bonded_device_result {
6654         cmdline_fixed_string_t create;
6655         cmdline_fixed_string_t bonded;
6656         cmdline_fixed_string_t device;
6657         uint8_t mode;
6658         uint8_t socket;
6659 };
6660
6661 static int bond_dev_num = 0;
6662
6663 static void cmd_create_bonded_device_parsed(void *parsed_result,
6664                 __rte_unused  struct cmdline *cl,
6665                 __rte_unused void *data)
6666 {
6667         struct cmd_create_bonded_device_result *res = parsed_result;
6668         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6669         int port_id;
6670         int ret;
6671
6672         if (test_done == 0) {
6673                 fprintf(stderr, "Please stop forwarding first\n");
6674                 return;
6675         }
6676
6677         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6678                         bond_dev_num++);
6679
6680         /* Create a new bonded device. */
6681         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6682         if (port_id < 0) {
6683                 fprintf(stderr, "\t Failed to create bonded device.\n");
6684                 return;
6685         } else {
6686                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6687                                 port_id);
6688
6689                 /* Update number of ports */
6690                 nb_ports = rte_eth_dev_count_avail();
6691                 reconfig(port_id, res->socket);
6692                 ret = rte_eth_promiscuous_enable(port_id);
6693                 if (ret != 0)
6694                         fprintf(stderr,
6695                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6696                                 port_id, rte_strerror(-ret));
6697
6698                 ports[port_id].bond_flag = 1;
6699                 ports[port_id].need_setup = 0;
6700                 ports[port_id].port_status = RTE_PORT_STOPPED;
6701         }
6702
6703 }
6704
6705 static cmdline_parse_token_string_t cmd_createbonded_device_create =
6706                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6707                                 create, "create");
6708 static cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6709                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6710                                 bonded, "bonded");
6711 static cmdline_parse_token_string_t cmd_createbonded_device_device =
6712                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6713                                 device, "device");
6714 static cmdline_parse_token_num_t cmd_createbonded_device_mode =
6715                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6716                                 mode, RTE_UINT8);
6717 static cmdline_parse_token_num_t cmd_createbonded_device_socket =
6718                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6719                                 socket, RTE_UINT8);
6720
6721 static cmdline_parse_inst_t cmd_create_bonded_device = {
6722                 .f = cmd_create_bonded_device_parsed,
6723                 .help_str = "create bonded device <mode> <socket>: "
6724                         "Create a new bonded device with specific bonding mode and socket",
6725                 .data = NULL,
6726                 .tokens = {
6727                                 (void *)&cmd_createbonded_device_create,
6728                                 (void *)&cmd_createbonded_device_bonded,
6729                                 (void *)&cmd_createbonded_device_device,
6730                                 (void *)&cmd_createbonded_device_mode,
6731                                 (void *)&cmd_createbonded_device_socket,
6732                                 NULL
6733                 }
6734 };
6735
6736 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6737 struct cmd_set_bond_mac_addr_result {
6738         cmdline_fixed_string_t set;
6739         cmdline_fixed_string_t bonding;
6740         cmdline_fixed_string_t mac_addr;
6741         uint16_t port_num;
6742         struct rte_ether_addr address;
6743 };
6744
6745 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6746                 __rte_unused  struct cmdline *cl,
6747                 __rte_unused void *data)
6748 {
6749         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6750         int ret;
6751
6752         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6753                 return;
6754
6755         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6756
6757         /* check the return value and print it if is < 0 */
6758         if (ret < 0)
6759                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6760                         strerror(-ret));
6761 }
6762
6763 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6764                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6765 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6766                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6767                                 "bonding");
6768 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6769                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6770                                 "mac_addr");
6771 static cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6772                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6773                                 port_num, RTE_UINT16);
6774 static cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6775                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6776
6777 static cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6778                 .f = cmd_set_bond_mac_addr_parsed,
6779                 .data = (void *) 0,
6780                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6781                 .tokens = {
6782                                 (void *)&cmd_set_bond_mac_addr_set,
6783                                 (void *)&cmd_set_bond_mac_addr_bonding,
6784                                 (void *)&cmd_set_bond_mac_addr_mac,
6785                                 (void *)&cmd_set_bond_mac_addr_portnum,
6786                                 (void *)&cmd_set_bond_mac_addr_addr,
6787                                 NULL
6788                 }
6789 };
6790
6791
6792 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6793 struct cmd_set_bond_mon_period_result {
6794         cmdline_fixed_string_t set;
6795         cmdline_fixed_string_t bonding;
6796         cmdline_fixed_string_t mon_period;
6797         uint16_t port_num;
6798         uint32_t period_ms;
6799 };
6800
6801 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6802                 __rte_unused  struct cmdline *cl,
6803                 __rte_unused void *data)
6804 {
6805         struct cmd_set_bond_mon_period_result *res = parsed_result;
6806         int ret;
6807
6808         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6809
6810         /* check the return value and print it if is < 0 */
6811         if (ret < 0)
6812                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6813                         strerror(-ret));
6814 }
6815
6816 static cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6817                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6818                                 set, "set");
6819 static cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6820                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6821                                 bonding, "bonding");
6822 static cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6823                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6824                                 mon_period,     "mon_period");
6825 static cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6826                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6827                                 port_num, RTE_UINT16);
6828 static cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6829                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6830                                 period_ms, RTE_UINT32);
6831
6832 static cmdline_parse_inst_t cmd_set_bond_mon_period = {
6833                 .f = cmd_set_bond_mon_period_parsed,
6834                 .data = (void *) 0,
6835                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6836                 .tokens = {
6837                                 (void *)&cmd_set_bond_mon_period_set,
6838                                 (void *)&cmd_set_bond_mon_period_bonding,
6839                                 (void *)&cmd_set_bond_mon_period_mon_period,
6840                                 (void *)&cmd_set_bond_mon_period_portnum,
6841                                 (void *)&cmd_set_bond_mon_period_period_ms,
6842                                 NULL
6843                 }
6844 };
6845
6846
6847
6848 struct cmd_set_bonding_agg_mode_policy_result {
6849         cmdline_fixed_string_t set;
6850         cmdline_fixed_string_t bonding;
6851         cmdline_fixed_string_t agg_mode;
6852         uint16_t port_num;
6853         cmdline_fixed_string_t policy;
6854 };
6855
6856
6857 static void
6858 cmd_set_bonding_agg_mode(void *parsed_result,
6859                 __rte_unused struct cmdline *cl,
6860                 __rte_unused void *data)
6861 {
6862         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6863         uint8_t policy = AGG_BANDWIDTH;
6864
6865         if (!strcmp(res->policy, "bandwidth"))
6866                 policy = AGG_BANDWIDTH;
6867         else if (!strcmp(res->policy, "stable"))
6868                 policy = AGG_STABLE;
6869         else if (!strcmp(res->policy, "count"))
6870                 policy = AGG_COUNT;
6871
6872         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6873 }
6874
6875
6876 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6877         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6878                                 set, "set");
6879 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6880         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6881                                 bonding, "bonding");
6882
6883 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6884         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6885                                 agg_mode, "agg_mode");
6886
6887 static cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6888         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6889                                 port_num, RTE_UINT16);
6890
6891 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6892         TOKEN_STRING_INITIALIZER(
6893                         struct cmd_set_bonding_balance_xmit_policy_result,
6894                 policy, "stable#bandwidth#count");
6895
6896 static cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6897         .f = cmd_set_bonding_agg_mode,
6898         .data = (void *) 0,
6899         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6900         .tokens = {
6901                         (void *)&cmd_set_bonding_agg_mode_set,
6902                         (void *)&cmd_set_bonding_agg_mode_bonding,
6903                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6904                         (void *)&cmd_set_bonding_agg_mode_portnum,
6905                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6906                         NULL
6907                 }
6908 };
6909
6910
6911 #endif /* RTE_NET_BOND */
6912
6913 /* *** SET FORWARDING MODE *** */
6914 struct cmd_set_fwd_mode_result {
6915         cmdline_fixed_string_t set;
6916         cmdline_fixed_string_t fwd;
6917         cmdline_fixed_string_t mode;
6918 };
6919
6920 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6921                                     __rte_unused struct cmdline *cl,
6922                                     __rte_unused void *data)
6923 {
6924         struct cmd_set_fwd_mode_result *res = parsed_result;
6925
6926         retry_enabled = 0;
6927         set_pkt_forwarding_mode(res->mode);
6928 }
6929
6930 static cmdline_parse_token_string_t cmd_setfwd_set =
6931         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6932 static cmdline_parse_token_string_t cmd_setfwd_fwd =
6933         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6934 static cmdline_parse_token_string_t cmd_setfwd_mode =
6935         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6936                 "" /* defined at init */);
6937
6938 static cmdline_parse_inst_t cmd_set_fwd_mode = {
6939         .f = cmd_set_fwd_mode_parsed,
6940         .data = NULL,
6941         .help_str = NULL, /* defined at init */
6942         .tokens = {
6943                 (void *)&cmd_setfwd_set,
6944                 (void *)&cmd_setfwd_fwd,
6945                 (void *)&cmd_setfwd_mode,
6946                 NULL,
6947         },
6948 };
6949
6950 static void cmd_set_fwd_mode_init(void)
6951 {
6952         char *modes, *c;
6953         static char token[128];
6954         static char help[256];
6955         cmdline_parse_token_string_t *token_struct;
6956
6957         modes = list_pkt_forwarding_modes();
6958         snprintf(help, sizeof(help), "set fwd %s: "
6959                 "Set packet forwarding mode", modes);
6960         cmd_set_fwd_mode.help_str = help;
6961
6962         /* string token separator is # */
6963         for (c = token; *modes != '\0'; modes++)
6964                 if (*modes == '|')
6965                         *c++ = '#';
6966                 else
6967                         *c++ = *modes;
6968         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6969         token_struct->string_data.str = token;
6970 }
6971
6972 /* *** SET RETRY FORWARDING MODE *** */
6973 struct cmd_set_fwd_retry_mode_result {
6974         cmdline_fixed_string_t set;
6975         cmdline_fixed_string_t fwd;
6976         cmdline_fixed_string_t mode;
6977         cmdline_fixed_string_t retry;
6978 };
6979
6980 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6981                             __rte_unused struct cmdline *cl,
6982                             __rte_unused void *data)
6983 {
6984         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6985
6986         retry_enabled = 1;
6987         set_pkt_forwarding_mode(res->mode);
6988 }
6989
6990 static cmdline_parse_token_string_t cmd_setfwd_retry_set =
6991         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6992                         set, "set");
6993 static cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6994         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6995                         fwd, "fwd");
6996 static cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6997         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6998                         mode,
6999                 "" /* defined at init */);
7000 static cmdline_parse_token_string_t cmd_setfwd_retry_retry =
7001         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
7002                         retry, "retry");
7003
7004 static cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
7005         .f = cmd_set_fwd_retry_mode_parsed,
7006         .data = NULL,
7007         .help_str = NULL, /* defined at init */
7008         .tokens = {
7009                 (void *)&cmd_setfwd_retry_set,
7010                 (void *)&cmd_setfwd_retry_fwd,
7011                 (void *)&cmd_setfwd_retry_mode,
7012                 (void *)&cmd_setfwd_retry_retry,
7013                 NULL,
7014         },
7015 };
7016
7017 static void cmd_set_fwd_retry_mode_init(void)
7018 {
7019         char *modes, *c;
7020         static char token[128];
7021         static char help[256];
7022         cmdline_parse_token_string_t *token_struct;
7023
7024         modes = list_pkt_forwarding_retry_modes();
7025         snprintf(help, sizeof(help), "set fwd %s retry: "
7026                 "Set packet forwarding mode with retry", modes);
7027         cmd_set_fwd_retry_mode.help_str = help;
7028
7029         /* string token separator is # */
7030         for (c = token; *modes != '\0'; modes++)
7031                 if (*modes == '|')
7032                         *c++ = '#';
7033                 else
7034                         *c++ = *modes;
7035         token_struct = (cmdline_parse_token_string_t *)
7036                 cmd_set_fwd_retry_mode.tokens[2];
7037         token_struct->string_data.str = token;
7038 }
7039
7040 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7041 struct cmd_set_burst_tx_retry_result {
7042         cmdline_fixed_string_t set;
7043         cmdline_fixed_string_t burst;
7044         cmdline_fixed_string_t tx;
7045         cmdline_fixed_string_t delay;
7046         uint32_t time;
7047         cmdline_fixed_string_t retry;
7048         uint32_t retry_num;
7049 };
7050
7051 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7052                                         __rte_unused struct cmdline *cl,
7053                                         __rte_unused void *data)
7054 {
7055         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7056
7057         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7058                 && !strcmp(res->tx, "tx")) {
7059                 if (!strcmp(res->delay, "delay"))
7060                         burst_tx_delay_time = res->time;
7061                 if (!strcmp(res->retry, "retry"))
7062                         burst_tx_retry_num = res->retry_num;
7063         }
7064
7065 }
7066
7067 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7068         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7069 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7070         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7071                                  "burst");
7072 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7073         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7074 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7075         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7076 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7077         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7078                                  RTE_UINT32);
7079 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7080         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7081 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7082         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7083                                  RTE_UINT32);
7084
7085 static cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7086         .f = cmd_set_burst_tx_retry_parsed,
7087         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7088         .tokens = {
7089                 (void *)&cmd_set_burst_tx_retry_set,
7090                 (void *)&cmd_set_burst_tx_retry_burst,
7091                 (void *)&cmd_set_burst_tx_retry_tx,
7092                 (void *)&cmd_set_burst_tx_retry_delay,
7093                 (void *)&cmd_set_burst_tx_retry_time,
7094                 (void *)&cmd_set_burst_tx_retry_retry,
7095                 (void *)&cmd_set_burst_tx_retry_retry_num,
7096                 NULL,
7097         },
7098 };
7099
7100 /* *** SET PROMISC MODE *** */
7101 struct cmd_set_promisc_mode_result {
7102         cmdline_fixed_string_t set;
7103         cmdline_fixed_string_t promisc;
7104         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7105         uint16_t port_num;               /* valid if "allports" argument == 0 */
7106         cmdline_fixed_string_t mode;
7107 };
7108
7109 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7110                                         __rte_unused struct cmdline *cl,
7111                                         void *allports)
7112 {
7113         struct cmd_set_promisc_mode_result *res = parsed_result;
7114         int enable;
7115         portid_t i;
7116
7117         if (!strcmp(res->mode, "on"))
7118                 enable = 1;
7119         else
7120                 enable = 0;
7121
7122         /* all ports */
7123         if (allports) {
7124                 RTE_ETH_FOREACH_DEV(i)
7125                         eth_set_promisc_mode(i, enable);
7126         } else {
7127                 eth_set_promisc_mode(res->port_num, enable);
7128         }
7129 }
7130
7131 static cmdline_parse_token_string_t cmd_setpromisc_set =
7132         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7133 static cmdline_parse_token_string_t cmd_setpromisc_promisc =
7134         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7135                                  "promisc");
7136 static cmdline_parse_token_string_t cmd_setpromisc_portall =
7137         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7138                                  "all");
7139 static cmdline_parse_token_num_t cmd_setpromisc_portnum =
7140         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7141                               RTE_UINT16);
7142 static cmdline_parse_token_string_t cmd_setpromisc_mode =
7143         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7144                                  "on#off");
7145
7146 static cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7147         .f = cmd_set_promisc_mode_parsed,
7148         .data = (void *)1,
7149         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7150         .tokens = {
7151                 (void *)&cmd_setpromisc_set,
7152                 (void *)&cmd_setpromisc_promisc,
7153                 (void *)&cmd_setpromisc_portall,
7154                 (void *)&cmd_setpromisc_mode,
7155                 NULL,
7156         },
7157 };
7158
7159 static cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7160         .f = cmd_set_promisc_mode_parsed,
7161         .data = (void *)0,
7162         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7163         .tokens = {
7164                 (void *)&cmd_setpromisc_set,
7165                 (void *)&cmd_setpromisc_promisc,
7166                 (void *)&cmd_setpromisc_portnum,
7167                 (void *)&cmd_setpromisc_mode,
7168                 NULL,
7169         },
7170 };
7171
7172 /* *** SET ALLMULTI MODE *** */
7173 struct cmd_set_allmulti_mode_result {
7174         cmdline_fixed_string_t set;
7175         cmdline_fixed_string_t allmulti;
7176         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7177         uint16_t port_num;               /* valid if "allports" argument == 0 */
7178         cmdline_fixed_string_t mode;
7179 };
7180
7181 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7182                                         __rte_unused struct cmdline *cl,
7183                                         void *allports)
7184 {
7185         struct cmd_set_allmulti_mode_result *res = parsed_result;
7186         int enable;
7187         portid_t i;
7188
7189         if (!strcmp(res->mode, "on"))
7190                 enable = 1;
7191         else
7192                 enable = 0;
7193
7194         /* all ports */
7195         if (allports) {
7196                 RTE_ETH_FOREACH_DEV(i) {
7197                         eth_set_allmulticast_mode(i, enable);
7198                 }
7199         }
7200         else {
7201                 eth_set_allmulticast_mode(res->port_num, enable);
7202         }
7203 }
7204
7205 static cmdline_parse_token_string_t cmd_setallmulti_set =
7206         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7207 static cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7208         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7209                                  "allmulti");
7210 static cmdline_parse_token_string_t cmd_setallmulti_portall =
7211         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7212                                  "all");
7213 static cmdline_parse_token_num_t cmd_setallmulti_portnum =
7214         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7215                               RTE_UINT16);
7216 static cmdline_parse_token_string_t cmd_setallmulti_mode =
7217         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7218                                  "on#off");
7219
7220 static cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7221         .f = cmd_set_allmulti_mode_parsed,
7222         .data = (void *)1,
7223         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7224         .tokens = {
7225                 (void *)&cmd_setallmulti_set,
7226                 (void *)&cmd_setallmulti_allmulti,
7227                 (void *)&cmd_setallmulti_portall,
7228                 (void *)&cmd_setallmulti_mode,
7229                 NULL,
7230         },
7231 };
7232
7233 static cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7234         .f = cmd_set_allmulti_mode_parsed,
7235         .data = (void *)0,
7236         .help_str = "set allmulti <port_id> on|off: "
7237                 "Set allmulti mode on port_id",
7238         .tokens = {
7239                 (void *)&cmd_setallmulti_set,
7240                 (void *)&cmd_setallmulti_allmulti,
7241                 (void *)&cmd_setallmulti_portnum,
7242                 (void *)&cmd_setallmulti_mode,
7243                 NULL,
7244         },
7245 };
7246
7247 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7248 struct cmd_link_flow_ctrl_show {
7249         cmdline_fixed_string_t show;
7250         cmdline_fixed_string_t port;
7251         portid_t port_id;
7252         cmdline_fixed_string_t flow_ctrl;
7253 };
7254
7255 static cmdline_parse_token_string_t cmd_lfc_show_show =
7256         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7257                                 show, "show");
7258 static cmdline_parse_token_string_t cmd_lfc_show_port =
7259         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7260                                 port, "port");
7261 static cmdline_parse_token_num_t cmd_lfc_show_portid =
7262         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7263                                 port_id, RTE_UINT16);
7264 static cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7265         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7266                                 flow_ctrl, "flow_ctrl");
7267
7268 static void
7269 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7270                               __rte_unused struct cmdline *cl,
7271                               __rte_unused void *data)
7272 {
7273         struct cmd_link_flow_ctrl_show *res = parsed_result;
7274         static const char *info_border = "*********************";
7275         struct rte_eth_fc_conf fc_conf;
7276         bool rx_fc_en = false;
7277         bool tx_fc_en = false;
7278         int ret;
7279
7280         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7281         if (ret != 0) {
7282                 fprintf(stderr,
7283                         "Failed to get current flow ctrl information: err = %d\n",
7284                         ret);
7285                 return;
7286         }
7287
7288         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7289                 rx_fc_en = true;
7290         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7291                 tx_fc_en = true;
7292
7293         printf("\n%s Flow control infos for port %-2d %s\n",
7294                 info_border, res->port_id, info_border);
7295         printf("FC mode:\n");
7296         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7297         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7298         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7299         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7300         printf("High waterline: 0x%x\n", fc_conf.high_water);
7301         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7302         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7303         printf("Forward MAC control frames: %s\n",
7304                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7305         printf("\n%s**************   End  ***********%s\n",
7306                 info_border, info_border);
7307 }
7308
7309 static cmdline_parse_inst_t cmd_link_flow_control_show = {
7310         .f = cmd_link_flow_ctrl_show_parsed,
7311         .data = NULL,
7312         .help_str = "show port <port_id> flow_ctrl",
7313         .tokens = {
7314                 (void *)&cmd_lfc_show_show,
7315                 (void *)&cmd_lfc_show_port,
7316                 (void *)&cmd_lfc_show_portid,
7317                 (void *)&cmd_lfc_show_flow_ctrl,
7318                 NULL,
7319         },
7320 };
7321
7322 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7323 struct cmd_link_flow_ctrl_set_result {
7324         cmdline_fixed_string_t set;
7325         cmdline_fixed_string_t flow_ctrl;
7326         cmdline_fixed_string_t rx;
7327         cmdline_fixed_string_t rx_lfc_mode;
7328         cmdline_fixed_string_t tx;
7329         cmdline_fixed_string_t tx_lfc_mode;
7330         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7331         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7332         cmdline_fixed_string_t autoneg_str;
7333         cmdline_fixed_string_t autoneg;
7334         cmdline_fixed_string_t hw_str;
7335         uint32_t high_water;
7336         cmdline_fixed_string_t lw_str;
7337         uint32_t low_water;
7338         cmdline_fixed_string_t pt_str;
7339         uint16_t pause_time;
7340         cmdline_fixed_string_t xon_str;
7341         uint16_t send_xon;
7342         portid_t port_id;
7343 };
7344
7345 static cmdline_parse_token_string_t cmd_lfc_set_set =
7346         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7347                                 set, "set");
7348 static cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7349         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7350                                 flow_ctrl, "flow_ctrl");
7351 static cmdline_parse_token_string_t cmd_lfc_set_rx =
7352         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7353                                 rx, "rx");
7354 static cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7355         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7356                                 rx_lfc_mode, "on#off");
7357 static cmdline_parse_token_string_t cmd_lfc_set_tx =
7358         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7359                                 tx, "tx");
7360 static cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7361         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7362                                 tx_lfc_mode, "on#off");
7363 static cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7364         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7365                                 hw_str, "high_water");
7366 static cmdline_parse_token_num_t cmd_lfc_set_high_water =
7367         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7368                                 high_water, RTE_UINT32);
7369 static cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7370         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7371                                 lw_str, "low_water");
7372 static cmdline_parse_token_num_t cmd_lfc_set_low_water =
7373         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7374                                 low_water, RTE_UINT32);
7375 static cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7376         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7377                                 pt_str, "pause_time");
7378 static cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7379         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7380                                 pause_time, RTE_UINT16);
7381 static cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7382         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7383                                 xon_str, "send_xon");
7384 static cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7385         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7386                                 send_xon, RTE_UINT16);
7387 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7388         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7389                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7390 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7391         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7392                                 mac_ctrl_frame_fwd_mode, "on#off");
7393 static cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7394         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7395                                 autoneg_str, "autoneg");
7396 static cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7397         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7398                                 autoneg, "on#off");
7399 static cmdline_parse_token_num_t cmd_lfc_set_portid =
7400         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7401                                 port_id, RTE_UINT16);
7402
7403 /* forward declaration */
7404 static void
7405 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7406                               void *data);
7407
7408 static cmdline_parse_inst_t cmd_link_flow_control_set = {
7409         .f = cmd_link_flow_ctrl_set_parsed,
7410         .data = NULL,
7411         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7412                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7413                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7414         .tokens = {
7415                 (void *)&cmd_lfc_set_set,
7416                 (void *)&cmd_lfc_set_flow_ctrl,
7417                 (void *)&cmd_lfc_set_rx,
7418                 (void *)&cmd_lfc_set_rx_mode,
7419                 (void *)&cmd_lfc_set_tx,
7420                 (void *)&cmd_lfc_set_tx_mode,
7421                 (void *)&cmd_lfc_set_high_water,
7422                 (void *)&cmd_lfc_set_low_water,
7423                 (void *)&cmd_lfc_set_pause_time,
7424                 (void *)&cmd_lfc_set_send_xon,
7425                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7426                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7427                 (void *)&cmd_lfc_set_autoneg_str,
7428                 (void *)&cmd_lfc_set_autoneg,
7429                 (void *)&cmd_lfc_set_portid,
7430                 NULL,
7431         },
7432 };
7433
7434 static cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7435         .f = cmd_link_flow_ctrl_set_parsed,
7436         .data = (void *)&cmd_link_flow_control_set_rx,
7437         .help_str = "set flow_ctrl rx on|off <port_id>: "
7438                 "Change rx flow control parameter",
7439         .tokens = {
7440                 (void *)&cmd_lfc_set_set,
7441                 (void *)&cmd_lfc_set_flow_ctrl,
7442                 (void *)&cmd_lfc_set_rx,
7443                 (void *)&cmd_lfc_set_rx_mode,
7444                 (void *)&cmd_lfc_set_portid,
7445                 NULL,
7446         },
7447 };
7448
7449 static cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7450         .f = cmd_link_flow_ctrl_set_parsed,
7451         .data = (void *)&cmd_link_flow_control_set_tx,
7452         .help_str = "set flow_ctrl tx on|off <port_id>: "
7453                 "Change tx flow control parameter",
7454         .tokens = {
7455                 (void *)&cmd_lfc_set_set,
7456                 (void *)&cmd_lfc_set_flow_ctrl,
7457                 (void *)&cmd_lfc_set_tx,
7458                 (void *)&cmd_lfc_set_tx_mode,
7459                 (void *)&cmd_lfc_set_portid,
7460                 NULL,
7461         },
7462 };
7463
7464 static cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7465         .f = cmd_link_flow_ctrl_set_parsed,
7466         .data = (void *)&cmd_link_flow_control_set_hw,
7467         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7468                 "Change high water flow control parameter",
7469         .tokens = {
7470                 (void *)&cmd_lfc_set_set,
7471                 (void *)&cmd_lfc_set_flow_ctrl,
7472                 (void *)&cmd_lfc_set_high_water_str,
7473                 (void *)&cmd_lfc_set_high_water,
7474                 (void *)&cmd_lfc_set_portid,
7475                 NULL,
7476         },
7477 };
7478
7479 static cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7480         .f = cmd_link_flow_ctrl_set_parsed,
7481         .data = (void *)&cmd_link_flow_control_set_lw,
7482         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7483                 "Change low water flow control parameter",
7484         .tokens = {
7485                 (void *)&cmd_lfc_set_set,
7486                 (void *)&cmd_lfc_set_flow_ctrl,
7487                 (void *)&cmd_lfc_set_low_water_str,
7488                 (void *)&cmd_lfc_set_low_water,
7489                 (void *)&cmd_lfc_set_portid,
7490                 NULL,
7491         },
7492 };
7493
7494 static cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7495         .f = cmd_link_flow_ctrl_set_parsed,
7496         .data = (void *)&cmd_link_flow_control_set_pt,
7497         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7498                 "Change pause time flow control parameter",
7499         .tokens = {
7500                 (void *)&cmd_lfc_set_set,
7501                 (void *)&cmd_lfc_set_flow_ctrl,
7502                 (void *)&cmd_lfc_set_pause_time_str,
7503                 (void *)&cmd_lfc_set_pause_time,
7504                 (void *)&cmd_lfc_set_portid,
7505                 NULL,
7506         },
7507 };
7508
7509 static cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7510         .f = cmd_link_flow_ctrl_set_parsed,
7511         .data = (void *)&cmd_link_flow_control_set_xon,
7512         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7513                 "Change send_xon flow control parameter",
7514         .tokens = {
7515                 (void *)&cmd_lfc_set_set,
7516                 (void *)&cmd_lfc_set_flow_ctrl,
7517                 (void *)&cmd_lfc_set_send_xon_str,
7518                 (void *)&cmd_lfc_set_send_xon,
7519                 (void *)&cmd_lfc_set_portid,
7520                 NULL,
7521         },
7522 };
7523
7524 static cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7525         .f = cmd_link_flow_ctrl_set_parsed,
7526         .data = (void *)&cmd_link_flow_control_set_macfwd,
7527         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7528                 "Change mac ctrl fwd flow control parameter",
7529         .tokens = {
7530                 (void *)&cmd_lfc_set_set,
7531                 (void *)&cmd_lfc_set_flow_ctrl,
7532                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7533                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7534                 (void *)&cmd_lfc_set_portid,
7535                 NULL,
7536         },
7537 };
7538
7539 static cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7540         .f = cmd_link_flow_ctrl_set_parsed,
7541         .data = (void *)&cmd_link_flow_control_set_autoneg,
7542         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7543                 "Change autoneg flow control parameter",
7544         .tokens = {
7545                 (void *)&cmd_lfc_set_set,
7546                 (void *)&cmd_lfc_set_flow_ctrl,
7547                 (void *)&cmd_lfc_set_autoneg_str,
7548                 (void *)&cmd_lfc_set_autoneg,
7549                 (void *)&cmd_lfc_set_portid,
7550                 NULL,
7551         },
7552 };
7553
7554 static void
7555 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7556                               __rte_unused struct cmdline *cl,
7557                               void *data)
7558 {
7559         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7560         cmdline_parse_inst_t *cmd = data;
7561         struct rte_eth_fc_conf fc_conf;
7562         int rx_fc_en = 0;
7563         int tx_fc_en = 0;
7564         int ret;
7565
7566         /*
7567          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7568          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7569          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7570          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7571          */
7572         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7573                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7574         };
7575
7576         /* Partial command line, retrieve current configuration */
7577         if (cmd) {
7578                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7579                 if (ret != 0) {
7580                         fprintf(stderr,
7581                                 "cannot get current flow ctrl parameters, return code = %d\n",
7582                                 ret);
7583                         return;
7584                 }
7585
7586                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7587                     (fc_conf.mode == RTE_ETH_FC_FULL))
7588                         rx_fc_en = 1;
7589                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7590                     (fc_conf.mode == RTE_ETH_FC_FULL))
7591                         tx_fc_en = 1;
7592         }
7593
7594         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7595                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7596
7597         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7598                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7599
7600         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7601
7602         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7603                 fc_conf.high_water = res->high_water;
7604
7605         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7606                 fc_conf.low_water = res->low_water;
7607
7608         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7609                 fc_conf.pause_time = res->pause_time;
7610
7611         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7612                 fc_conf.send_xon = res->send_xon;
7613
7614         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7615                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7616                         fc_conf.mac_ctrl_frame_fwd = 1;
7617                 else
7618                         fc_conf.mac_ctrl_frame_fwd = 0;
7619         }
7620
7621         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7622                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7623
7624         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7625         if (ret != 0)
7626                 fprintf(stderr,
7627                         "bad flow control parameter, return code = %d\n",
7628                         ret);
7629 }
7630
7631 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7632 struct cmd_priority_flow_ctrl_set_result {
7633         cmdline_fixed_string_t set;
7634         cmdline_fixed_string_t pfc_ctrl;
7635         cmdline_fixed_string_t rx;
7636         cmdline_fixed_string_t rx_pfc_mode;
7637         cmdline_fixed_string_t tx;
7638         cmdline_fixed_string_t tx_pfc_mode;
7639         uint32_t high_water;
7640         uint32_t low_water;
7641         uint16_t pause_time;
7642         uint8_t  priority;
7643         portid_t port_id;
7644 };
7645
7646 static void
7647 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7648                        __rte_unused struct cmdline *cl,
7649                        __rte_unused void *data)
7650 {
7651         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7652         struct rte_eth_pfc_conf pfc_conf;
7653         int rx_fc_enable, tx_fc_enable;
7654         int ret;
7655
7656         /*
7657          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7658          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7659          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7660          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7661          */
7662         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7663                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7664         };
7665
7666         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7667         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7668         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7669         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7670         pfc_conf.fc.high_water = res->high_water;
7671         pfc_conf.fc.low_water  = res->low_water;
7672         pfc_conf.fc.pause_time = res->pause_time;
7673         pfc_conf.priority      = res->priority;
7674
7675         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7676         if (ret != 0)
7677                 fprintf(stderr,
7678                         "bad priority flow control parameter, return code = %d\n",
7679                         ret);
7680 }
7681
7682 static cmdline_parse_token_string_t cmd_pfc_set_set =
7683         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7684                                 set, "set");
7685 static cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7686         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7687                                 pfc_ctrl, "pfc_ctrl");
7688 static cmdline_parse_token_string_t cmd_pfc_set_rx =
7689         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7690                                 rx, "rx");
7691 static cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7692         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7693                                 rx_pfc_mode, "on#off");
7694 static cmdline_parse_token_string_t cmd_pfc_set_tx =
7695         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7696                                 tx, "tx");
7697 static cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7698         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7699                                 tx_pfc_mode, "on#off");
7700 static cmdline_parse_token_num_t cmd_pfc_set_high_water =
7701         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7702                                 high_water, RTE_UINT32);
7703 static cmdline_parse_token_num_t cmd_pfc_set_low_water =
7704         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7705                                 low_water, RTE_UINT32);
7706 static cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7707         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7708                                 pause_time, RTE_UINT16);
7709 static cmdline_parse_token_num_t cmd_pfc_set_priority =
7710         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7711                                 priority, RTE_UINT8);
7712 static cmdline_parse_token_num_t cmd_pfc_set_portid =
7713         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7714                                 port_id, RTE_UINT16);
7715
7716 static cmdline_parse_inst_t cmd_priority_flow_control_set = {
7717         .f = cmd_priority_flow_ctrl_set_parsed,
7718         .data = NULL,
7719         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7720                 "<pause_time> <priority> <port_id>: "
7721                 "Configure the Ethernet priority flow control",
7722         .tokens = {
7723                 (void *)&cmd_pfc_set_set,
7724                 (void *)&cmd_pfc_set_flow_ctrl,
7725                 (void *)&cmd_pfc_set_rx,
7726                 (void *)&cmd_pfc_set_rx_mode,
7727                 (void *)&cmd_pfc_set_tx,
7728                 (void *)&cmd_pfc_set_tx_mode,
7729                 (void *)&cmd_pfc_set_high_water,
7730                 (void *)&cmd_pfc_set_low_water,
7731                 (void *)&cmd_pfc_set_pause_time,
7732                 (void *)&cmd_pfc_set_priority,
7733                 (void *)&cmd_pfc_set_portid,
7734                 NULL,
7735         },
7736 };
7737
7738 struct cmd_queue_priority_flow_ctrl_set_result {
7739         cmdline_fixed_string_t set;
7740         cmdline_fixed_string_t pfc_queue_ctrl;
7741         portid_t port_id;
7742         cmdline_fixed_string_t rx;
7743         cmdline_fixed_string_t rx_pfc_mode;
7744         uint16_t tx_qid;
7745         uint8_t  tx_tc;
7746         cmdline_fixed_string_t tx;
7747         cmdline_fixed_string_t tx_pfc_mode;
7748         uint16_t rx_qid;
7749         uint8_t  rx_tc;
7750         uint16_t pause_time;
7751 };
7752
7753 static void
7754 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7755                                         __rte_unused struct cmdline *cl,
7756                                         __rte_unused void *data)
7757 {
7758         struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7759         struct rte_eth_pfc_queue_conf pfc_queue_conf;
7760         int rx_fc_enable, tx_fc_enable;
7761         int ret;
7762
7763         /*
7764          * Rx on/off, flow control is enabled/disabled on RX side. This can
7765          * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7766          * side. Tx on/off, flow control is enabled/disabled on TX side. This
7767          * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7768          * the Tx side.
7769          */
7770         static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7771                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7772                 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7773         };
7774
7775         memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7776         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7777         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7778         pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7779         pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7780         pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7781         pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7782         pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7783         pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7784
7785         ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7786                                                              &pfc_queue_conf);
7787         if (ret != 0) {
7788                 fprintf(stderr,
7789                         "bad queue priority flow control parameter, rc = %d\n",
7790                         ret);
7791         }
7792 }
7793
7794 static cmdline_parse_token_string_t cmd_q_pfc_set_set =
7795         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7796                                 set, "set");
7797 static cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7798         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7799                                 pfc_queue_ctrl, "pfc_queue_ctrl");
7800 static cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7801         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7802                                 port_id, RTE_UINT16);
7803 static cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7804         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7805                                 rx, "rx");
7806 static cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7807         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7808                                 rx_pfc_mode, "on#off");
7809 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7810         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7811                                 tx_qid, RTE_UINT16);
7812 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7813         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7814                                 tx_tc, RTE_UINT8);
7815 static cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7816         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7817                                 tx, "tx");
7818 static cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7819         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7820                                 tx_pfc_mode, "on#off");
7821 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7822         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7823                                 rx_qid, RTE_UINT16);
7824 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7825         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7826                                 rx_tc, RTE_UINT8);
7827 static cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7828         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7829                                 pause_time, RTE_UINT16);
7830
7831 static cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7832         .f = cmd_queue_priority_flow_ctrl_set_parsed,
7833         .data = NULL,
7834         .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7835                 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7836                 "Configure the Ethernet queue priority flow control",
7837         .tokens = {
7838                 (void *)&cmd_q_pfc_set_set,
7839                 (void *)&cmd_q_pfc_set_flow_ctrl,
7840                 (void *)&cmd_q_pfc_set_portid,
7841                 (void *)&cmd_q_pfc_set_rx,
7842                 (void *)&cmd_q_pfc_set_rx_mode,
7843                 (void *)&cmd_q_pfc_set_tx_qid,
7844                 (void *)&cmd_q_pfc_set_tx_tc,
7845                 (void *)&cmd_q_pfc_set_tx,
7846                 (void *)&cmd_q_pfc_set_tx_mode,
7847                 (void *)&cmd_q_pfc_set_rx_qid,
7848                 (void *)&cmd_q_pfc_set_rx_tc,
7849                 (void *)&cmd_q_pfc_set_pause_time,
7850                 NULL,
7851         },
7852 };
7853
7854 /* *** RESET CONFIGURATION *** */
7855 struct cmd_reset_result {
7856         cmdline_fixed_string_t reset;
7857         cmdline_fixed_string_t def;
7858 };
7859
7860 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7861                              struct cmdline *cl,
7862                              __rte_unused void *data)
7863 {
7864         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7865         set_def_fwd_config();
7866 }
7867
7868 static cmdline_parse_token_string_t cmd_reset_set =
7869         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7870 static cmdline_parse_token_string_t cmd_reset_def =
7871         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7872                                  "default");
7873
7874 static cmdline_parse_inst_t cmd_reset = {
7875         .f = cmd_reset_parsed,
7876         .data = NULL,
7877         .help_str = "set default: Reset default forwarding configuration",
7878         .tokens = {
7879                 (void *)&cmd_reset_set,
7880                 (void *)&cmd_reset_def,
7881                 NULL,
7882         },
7883 };
7884
7885 /* *** START FORWARDING *** */
7886 struct cmd_start_result {
7887         cmdline_fixed_string_t start;
7888 };
7889
7890 static cmdline_parse_token_string_t cmd_start_start =
7891         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7892
7893 static void cmd_start_parsed(__rte_unused void *parsed_result,
7894                              __rte_unused struct cmdline *cl,
7895                              __rte_unused void *data)
7896 {
7897         start_packet_forwarding(0);
7898 }
7899
7900 static cmdline_parse_inst_t cmd_start = {
7901         .f = cmd_start_parsed,
7902         .data = NULL,
7903         .help_str = "start: Start packet forwarding",
7904         .tokens = {
7905                 (void *)&cmd_start_start,
7906                 NULL,
7907         },
7908 };
7909
7910 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7911 struct cmd_start_tx_first_result {
7912         cmdline_fixed_string_t start;
7913         cmdline_fixed_string_t tx_first;
7914 };
7915
7916 static void
7917 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7918                           __rte_unused struct cmdline *cl,
7919                           __rte_unused void *data)
7920 {
7921         start_packet_forwarding(1);
7922 }
7923
7924 static cmdline_parse_token_string_t cmd_start_tx_first_start =
7925         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7926                                  "start");
7927 static cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7928         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7929                                  tx_first, "tx_first");
7930
7931 static cmdline_parse_inst_t cmd_start_tx_first = {
7932         .f = cmd_start_tx_first_parsed,
7933         .data = NULL,
7934         .help_str = "start tx_first: Start packet forwarding, "
7935                 "after sending 1 burst of packets",
7936         .tokens = {
7937                 (void *)&cmd_start_tx_first_start,
7938                 (void *)&cmd_start_tx_first_tx_first,
7939                 NULL,
7940         },
7941 };
7942
7943 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7944 struct cmd_start_tx_first_n_result {
7945         cmdline_fixed_string_t start;
7946         cmdline_fixed_string_t tx_first;
7947         uint32_t tx_num;
7948 };
7949
7950 static void
7951 cmd_start_tx_first_n_parsed(void *parsed_result,
7952                           __rte_unused struct cmdline *cl,
7953                           __rte_unused void *data)
7954 {
7955         struct cmd_start_tx_first_n_result *res = parsed_result;
7956
7957         start_packet_forwarding(res->tx_num);
7958 }
7959
7960 static cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7961         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7962                         start, "start");
7963 static cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7964         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7965                         tx_first, "tx_first");
7966 static cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7967         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7968                         tx_num, RTE_UINT32);
7969
7970 static cmdline_parse_inst_t cmd_start_tx_first_n = {
7971         .f = cmd_start_tx_first_n_parsed,
7972         .data = NULL,
7973         .help_str = "start tx_first <num>: "
7974                 "packet forwarding, after sending <num> bursts of packets",
7975         .tokens = {
7976                 (void *)&cmd_start_tx_first_n_start,
7977                 (void *)&cmd_start_tx_first_n_tx_first,
7978                 (void *)&cmd_start_tx_first_n_tx_num,
7979                 NULL,
7980         },
7981 };
7982
7983 /* *** SET LINK UP *** */
7984 struct cmd_set_link_up_result {
7985         cmdline_fixed_string_t set;
7986         cmdline_fixed_string_t link_up;
7987         cmdline_fixed_string_t port;
7988         portid_t port_id;
7989 };
7990
7991 static cmdline_parse_token_string_t cmd_set_link_up_set =
7992         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7993 static cmdline_parse_token_string_t cmd_set_link_up_link_up =
7994         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7995                                 "link-up");
7996 static cmdline_parse_token_string_t cmd_set_link_up_port =
7997         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7998 static cmdline_parse_token_num_t cmd_set_link_up_port_id =
7999         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
8000                                 RTE_UINT16);
8001
8002 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
8003                              __rte_unused struct cmdline *cl,
8004                              __rte_unused void *data)
8005 {
8006         struct cmd_set_link_up_result *res = parsed_result;
8007         dev_set_link_up(res->port_id);
8008 }
8009
8010 static cmdline_parse_inst_t cmd_set_link_up = {
8011         .f = cmd_set_link_up_parsed,
8012         .data = NULL,
8013         .help_str = "set link-up port <port id>",
8014         .tokens = {
8015                 (void *)&cmd_set_link_up_set,
8016                 (void *)&cmd_set_link_up_link_up,
8017                 (void *)&cmd_set_link_up_port,
8018                 (void *)&cmd_set_link_up_port_id,
8019                 NULL,
8020         },
8021 };
8022
8023 /* *** SET LINK DOWN *** */
8024 struct cmd_set_link_down_result {
8025         cmdline_fixed_string_t set;
8026         cmdline_fixed_string_t link_down;
8027         cmdline_fixed_string_t port;
8028         portid_t port_id;
8029 };
8030
8031 static cmdline_parse_token_string_t cmd_set_link_down_set =
8032         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8033 static cmdline_parse_token_string_t cmd_set_link_down_link_down =
8034         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8035                                 "link-down");
8036 static cmdline_parse_token_string_t cmd_set_link_down_port =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8038 static cmdline_parse_token_num_t cmd_set_link_down_port_id =
8039         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8040                                 RTE_UINT16);
8041
8042 static void cmd_set_link_down_parsed(
8043                                 __rte_unused void *parsed_result,
8044                                 __rte_unused struct cmdline *cl,
8045                                 __rte_unused void *data)
8046 {
8047         struct cmd_set_link_down_result *res = parsed_result;
8048         dev_set_link_down(res->port_id);
8049 }
8050
8051 static cmdline_parse_inst_t cmd_set_link_down = {
8052         .f = cmd_set_link_down_parsed,
8053         .data = NULL,
8054         .help_str = "set link-down port <port id>",
8055         .tokens = {
8056                 (void *)&cmd_set_link_down_set,
8057                 (void *)&cmd_set_link_down_link_down,
8058                 (void *)&cmd_set_link_down_port,
8059                 (void *)&cmd_set_link_down_port_id,
8060                 NULL,
8061         },
8062 };
8063
8064 /* *** SHOW CFG *** */
8065 struct cmd_showcfg_result {
8066         cmdline_fixed_string_t show;
8067         cmdline_fixed_string_t cfg;
8068         cmdline_fixed_string_t what;
8069 };
8070
8071 static void cmd_showcfg_parsed(void *parsed_result,
8072                                __rte_unused struct cmdline *cl,
8073                                __rte_unused void *data)
8074 {
8075         struct cmd_showcfg_result *res = parsed_result;
8076         if (!strcmp(res->what, "rxtx"))
8077                 rxtx_config_display();
8078         else if (!strcmp(res->what, "cores"))
8079                 fwd_lcores_config_display();
8080         else if (!strcmp(res->what, "fwd"))
8081                 pkt_fwd_config_display(&cur_fwd_config);
8082         else if (!strcmp(res->what, "rxoffs"))
8083                 show_rx_pkt_offsets();
8084         else if (!strcmp(res->what, "rxpkts"))
8085                 show_rx_pkt_segments();
8086         else if (!strcmp(res->what, "txpkts"))
8087                 show_tx_pkt_segments();
8088         else if (!strcmp(res->what, "txtimes"))
8089                 show_tx_pkt_times();
8090 }
8091
8092 static cmdline_parse_token_string_t cmd_showcfg_show =
8093         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8094 static cmdline_parse_token_string_t cmd_showcfg_port =
8095         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8096 static cmdline_parse_token_string_t cmd_showcfg_what =
8097         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8098                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8099
8100 static cmdline_parse_inst_t cmd_showcfg = {
8101         .f = cmd_showcfg_parsed,
8102         .data = NULL,
8103         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8104         .tokens = {
8105                 (void *)&cmd_showcfg_show,
8106                 (void *)&cmd_showcfg_port,
8107                 (void *)&cmd_showcfg_what,
8108                 NULL,
8109         },
8110 };
8111
8112 /* *** SHOW ALL PORT INFO *** */
8113 struct cmd_showportall_result {
8114         cmdline_fixed_string_t show;
8115         cmdline_fixed_string_t port;
8116         cmdline_fixed_string_t what;
8117         cmdline_fixed_string_t all;
8118 };
8119
8120 static void cmd_showportall_parsed(void *parsed_result,
8121                                 __rte_unused struct cmdline *cl,
8122                                 __rte_unused void *data)
8123 {
8124         portid_t i;
8125
8126         struct cmd_showportall_result *res = parsed_result;
8127         if (!strcmp(res->show, "clear")) {
8128                 if (!strcmp(res->what, "stats"))
8129                         RTE_ETH_FOREACH_DEV(i)
8130                                 nic_stats_clear(i);
8131                 else if (!strcmp(res->what, "xstats"))
8132                         RTE_ETH_FOREACH_DEV(i)
8133                                 nic_xstats_clear(i);
8134         } else if (!strcmp(res->what, "info"))
8135                 RTE_ETH_FOREACH_DEV(i)
8136                         port_infos_display(i);
8137         else if (!strcmp(res->what, "summary")) {
8138                 port_summary_header_display();
8139                 RTE_ETH_FOREACH_DEV(i)
8140                         port_summary_display(i);
8141         }
8142         else if (!strcmp(res->what, "stats"))
8143                 RTE_ETH_FOREACH_DEV(i)
8144                         nic_stats_display(i);
8145         else if (!strcmp(res->what, "xstats"))
8146                 RTE_ETH_FOREACH_DEV(i)
8147                         nic_xstats_display(i);
8148 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8149         else if (!strcmp(res->what, "fdir"))
8150                 RTE_ETH_FOREACH_DEV(i)
8151                         fdir_get_infos(i);
8152 #endif
8153         else if (!strcmp(res->what, "dcb_tc"))
8154                 RTE_ETH_FOREACH_DEV(i)
8155                         port_dcb_info_display(i);
8156 }
8157
8158 static cmdline_parse_token_string_t cmd_showportall_show =
8159         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8160                                  "show#clear");
8161 static cmdline_parse_token_string_t cmd_showportall_port =
8162         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8163 static cmdline_parse_token_string_t cmd_showportall_what =
8164         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8165                                  "info#summary#stats#xstats#fdir#dcb_tc");
8166 static cmdline_parse_token_string_t cmd_showportall_all =
8167         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8168 static cmdline_parse_inst_t cmd_showportall = {
8169         .f = cmd_showportall_parsed,
8170         .data = NULL,
8171         .help_str = "show|clear port "
8172                 "info|summary|stats|xstats|fdir|dcb_tc all",
8173         .tokens = {
8174                 (void *)&cmd_showportall_show,
8175                 (void *)&cmd_showportall_port,
8176                 (void *)&cmd_showportall_what,
8177                 (void *)&cmd_showportall_all,
8178                 NULL,
8179         },
8180 };
8181
8182 /* *** SHOW PORT INFO *** */
8183 struct cmd_showport_result {
8184         cmdline_fixed_string_t show;
8185         cmdline_fixed_string_t port;
8186         cmdline_fixed_string_t what;
8187         uint16_t portnum;
8188 };
8189
8190 static void cmd_showport_parsed(void *parsed_result,
8191                                 __rte_unused struct cmdline *cl,
8192                                 __rte_unused void *data)
8193 {
8194         struct cmd_showport_result *res = parsed_result;
8195         if (!strcmp(res->show, "clear")) {
8196                 if (!strcmp(res->what, "stats"))
8197                         nic_stats_clear(res->portnum);
8198                 else if (!strcmp(res->what, "xstats"))
8199                         nic_xstats_clear(res->portnum);
8200         } else if (!strcmp(res->what, "info"))
8201                 port_infos_display(res->portnum);
8202         else if (!strcmp(res->what, "summary")) {
8203                 port_summary_header_display();
8204                 port_summary_display(res->portnum);
8205         }
8206         else if (!strcmp(res->what, "stats"))
8207                 nic_stats_display(res->portnum);
8208         else if (!strcmp(res->what, "xstats"))
8209                 nic_xstats_display(res->portnum);
8210 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8211         else if (!strcmp(res->what, "fdir"))
8212                  fdir_get_infos(res->portnum);
8213 #endif
8214         else if (!strcmp(res->what, "dcb_tc"))
8215                 port_dcb_info_display(res->portnum);
8216 }
8217
8218 static cmdline_parse_token_string_t cmd_showport_show =
8219         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8220                                  "show#clear");
8221 static cmdline_parse_token_string_t cmd_showport_port =
8222         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8223 static cmdline_parse_token_string_t cmd_showport_what =
8224         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8225                                  "info#summary#stats#xstats#fdir#dcb_tc");
8226 static cmdline_parse_token_num_t cmd_showport_portnum =
8227         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8228
8229 static cmdline_parse_inst_t cmd_showport = {
8230         .f = cmd_showport_parsed,
8231         .data = NULL,
8232         .help_str = "show|clear port "
8233                 "info|summary|stats|xstats|fdir|dcb_tc "
8234                 "<port_id>",
8235         .tokens = {
8236                 (void *)&cmd_showport_show,
8237                 (void *)&cmd_showport_port,
8238                 (void *)&cmd_showport_what,
8239                 (void *)&cmd_showport_portnum,
8240                 NULL,
8241         },
8242 };
8243
8244 /* *** show port representors information *** */
8245 struct cmd_representor_info_result {
8246         cmdline_fixed_string_t cmd_show;
8247         cmdline_fixed_string_t cmd_port;
8248         cmdline_fixed_string_t cmd_info;
8249         cmdline_fixed_string_t cmd_keyword;
8250         portid_t cmd_pid;
8251 };
8252
8253 static void
8254 cmd_representor_info_parsed(void *parsed_result,
8255                 __rte_unused struct cmdline *cl,
8256                 __rte_unused void *data)
8257 {
8258         struct cmd_representor_info_result *res = parsed_result;
8259         struct rte_eth_representor_info *info;
8260         struct rte_eth_representor_range *range;
8261         uint32_t range_diff;
8262         uint32_t i;
8263         int ret;
8264         int num;
8265
8266         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8267                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8268                 return;
8269         }
8270
8271         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8272         if (ret < 0) {
8273                 fprintf(stderr,
8274                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8275                         res->cmd_pid, rte_strerror(-ret));
8276                 return;
8277         }
8278         num = ret;
8279
8280         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8281         if (info == NULL) {
8282                 fprintf(stderr,
8283                         "Failed to allocate memory for representor info for port %hu\n",
8284                         res->cmd_pid);
8285                 return;
8286         }
8287         info->nb_ranges_alloc = num;
8288
8289         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8290         if (ret < 0) {
8291                 fprintf(stderr,
8292                         "Failed to get the representor info for port %hu: %s\n",
8293                         res->cmd_pid, rte_strerror(-ret));
8294                 free(info);
8295                 return;
8296         }
8297
8298         printf("Port controller: %hu\n", info->controller);
8299         printf("Port PF: %hu\n", info->pf);
8300
8301         printf("Ranges: %u\n", info->nb_ranges);
8302         for (i = 0; i < info->nb_ranges; i++) {
8303                 range = &info->ranges[i];
8304                 range_diff = range->id_end - range->id_base;
8305
8306                 printf("%u. ", i + 1);
8307                 printf("'%s' ", range->name);
8308                 if (range_diff > 0)
8309                         printf("[%u-%u]: ", range->id_base, range->id_end);
8310                 else
8311                         printf("[%u]: ", range->id_base);
8312
8313                 printf("Controller %d, PF %d", range->controller, range->pf);
8314
8315                 switch (range->type) {
8316                 case RTE_ETH_REPRESENTOR_NONE:
8317                         printf(", NONE\n");
8318                         break;
8319                 case RTE_ETH_REPRESENTOR_VF:
8320                         if (range_diff > 0)
8321                                 printf(", VF %d..%d\n", range->vf,
8322                                        range->vf + range_diff);
8323                         else
8324                                 printf(", VF %d\n", range->vf);
8325                         break;
8326                 case RTE_ETH_REPRESENTOR_SF:
8327                         printf(", SF %d\n", range->sf);
8328                         break;
8329                 case RTE_ETH_REPRESENTOR_PF:
8330                         if (range_diff > 0)
8331                                 printf("..%d\n", range->pf + range_diff);
8332                         else
8333                                 printf("\n");
8334                         break;
8335                 default:
8336                         printf(", UNKNOWN TYPE %d\n", range->type);
8337                         break;
8338                 }
8339         }
8340
8341         free(info);
8342 }
8343
8344 static cmdline_parse_token_string_t cmd_representor_info_show =
8345         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8346                         cmd_show, "show");
8347 static cmdline_parse_token_string_t cmd_representor_info_port =
8348         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8349                         cmd_port, "port");
8350 static cmdline_parse_token_string_t cmd_representor_info_info =
8351         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8352                         cmd_info, "info");
8353 static cmdline_parse_token_num_t cmd_representor_info_pid =
8354         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8355                         cmd_pid, RTE_UINT16);
8356 static cmdline_parse_token_string_t cmd_representor_info_keyword =
8357         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8358                         cmd_keyword, "representor");
8359
8360 static cmdline_parse_inst_t cmd_representor_info = {
8361         .f = cmd_representor_info_parsed,
8362         .data = NULL,
8363         .help_str = "show port info <port_id> representor",
8364         .tokens = {
8365                 (void *)&cmd_representor_info_show,
8366                 (void *)&cmd_representor_info_port,
8367                 (void *)&cmd_representor_info_info,
8368                 (void *)&cmd_representor_info_pid,
8369                 (void *)&cmd_representor_info_keyword,
8370                 NULL,
8371         },
8372 };
8373
8374
8375 /* *** SHOW DEVICE INFO *** */
8376 struct cmd_showdevice_result {
8377         cmdline_fixed_string_t show;
8378         cmdline_fixed_string_t device;
8379         cmdline_fixed_string_t what;
8380         cmdline_fixed_string_t identifier;
8381 };
8382
8383 static void cmd_showdevice_parsed(void *parsed_result,
8384                                 __rte_unused struct cmdline *cl,
8385                                 __rte_unused void *data)
8386 {
8387         struct cmd_showdevice_result *res = parsed_result;
8388         if (!strcmp(res->what, "info")) {
8389                 if (!strcmp(res->identifier, "all"))
8390                         device_infos_display(NULL);
8391                 else
8392                         device_infos_display(res->identifier);
8393         }
8394 }
8395
8396 static cmdline_parse_token_string_t cmd_showdevice_show =
8397         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8398                                  "show");
8399 static cmdline_parse_token_string_t cmd_showdevice_device =
8400         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8401 static cmdline_parse_token_string_t cmd_showdevice_what =
8402         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8403                                  "info");
8404 static cmdline_parse_token_string_t cmd_showdevice_identifier =
8405         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8406                         identifier, NULL);
8407
8408 static cmdline_parse_inst_t cmd_showdevice = {
8409         .f = cmd_showdevice_parsed,
8410         .data = NULL,
8411         .help_str = "show device info <identifier>|all",
8412         .tokens = {
8413                 (void *)&cmd_showdevice_show,
8414                 (void *)&cmd_showdevice_device,
8415                 (void *)&cmd_showdevice_what,
8416                 (void *)&cmd_showdevice_identifier,
8417                 NULL,
8418         },
8419 };
8420
8421 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8422 struct cmd_showeeprom_result {
8423         cmdline_fixed_string_t show;
8424         cmdline_fixed_string_t port;
8425         uint16_t portnum;
8426         cmdline_fixed_string_t type;
8427 };
8428
8429 static void cmd_showeeprom_parsed(void *parsed_result,
8430                 __rte_unused struct cmdline *cl,
8431                 __rte_unused void *data)
8432 {
8433         struct cmd_showeeprom_result *res = parsed_result;
8434
8435         if (!strcmp(res->type, "eeprom"))
8436                 port_eeprom_display(res->portnum);
8437         else if (!strcmp(res->type, "module_eeprom"))
8438                 port_module_eeprom_display(res->portnum);
8439         else
8440                 fprintf(stderr, "Unknown argument\n");
8441 }
8442
8443 static cmdline_parse_token_string_t cmd_showeeprom_show =
8444         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8445 static cmdline_parse_token_string_t cmd_showeeprom_port =
8446         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8447 static cmdline_parse_token_num_t cmd_showeeprom_portnum =
8448         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8449                         RTE_UINT16);
8450 static cmdline_parse_token_string_t cmd_showeeprom_type =
8451         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8452
8453 static cmdline_parse_inst_t cmd_showeeprom = {
8454         .f = cmd_showeeprom_parsed,
8455         .data = NULL,
8456         .help_str = "show port <port_id> module_eeprom|eeprom",
8457         .tokens = {
8458                 (void *)&cmd_showeeprom_show,
8459                 (void *)&cmd_showeeprom_port,
8460                 (void *)&cmd_showeeprom_portnum,
8461                 (void *)&cmd_showeeprom_type,
8462                 NULL,
8463         },
8464 };
8465
8466 /* *** SHOW QUEUE INFO *** */
8467 struct cmd_showqueue_result {
8468         cmdline_fixed_string_t show;
8469         cmdline_fixed_string_t type;
8470         cmdline_fixed_string_t what;
8471         uint16_t portnum;
8472         uint16_t queuenum;
8473 };
8474
8475 static void
8476 cmd_showqueue_parsed(void *parsed_result,
8477         __rte_unused struct cmdline *cl,
8478         __rte_unused void *data)
8479 {
8480         struct cmd_showqueue_result *res = parsed_result;
8481
8482         if (!strcmp(res->type, "rxq"))
8483                 rx_queue_infos_display(res->portnum, res->queuenum);
8484         else if (!strcmp(res->type, "txq"))
8485                 tx_queue_infos_display(res->portnum, res->queuenum);
8486 }
8487
8488 static cmdline_parse_token_string_t cmd_showqueue_show =
8489         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8490 static cmdline_parse_token_string_t cmd_showqueue_type =
8491         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8492 static cmdline_parse_token_string_t cmd_showqueue_what =
8493         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8494 static cmdline_parse_token_num_t cmd_showqueue_portnum =
8495         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8496                 RTE_UINT16);
8497 static cmdline_parse_token_num_t cmd_showqueue_queuenum =
8498         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8499                 RTE_UINT16);
8500
8501 static cmdline_parse_inst_t cmd_showqueue = {
8502         .f = cmd_showqueue_parsed,
8503         .data = NULL,
8504         .help_str = "show rxq|txq info <port_id> <queue_id>",
8505         .tokens = {
8506                 (void *)&cmd_showqueue_show,
8507                 (void *)&cmd_showqueue_type,
8508                 (void *)&cmd_showqueue_what,
8509                 (void *)&cmd_showqueue_portnum,
8510                 (void *)&cmd_showqueue_queuenum,
8511                 NULL,
8512         },
8513 };
8514
8515 /* show/clear fwd engine statistics */
8516 struct fwd_result {
8517         cmdline_fixed_string_t action;
8518         cmdline_fixed_string_t fwd;
8519         cmdline_fixed_string_t stats;
8520         cmdline_fixed_string_t all;
8521 };
8522
8523 static cmdline_parse_token_string_t cmd_fwd_action =
8524         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8525 static cmdline_parse_token_string_t cmd_fwd_fwd =
8526         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8527 static cmdline_parse_token_string_t cmd_fwd_stats =
8528         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8529 static cmdline_parse_token_string_t cmd_fwd_all =
8530         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8531
8532 static void
8533 cmd_showfwdall_parsed(void *parsed_result,
8534                       __rte_unused struct cmdline *cl,
8535                       __rte_unused void *data)
8536 {
8537         struct fwd_result *res = parsed_result;
8538
8539         if (!strcmp(res->action, "show"))
8540                 fwd_stats_display();
8541         else
8542                 fwd_stats_reset();
8543 }
8544
8545 static cmdline_parse_inst_t cmd_showfwdall = {
8546         .f = cmd_showfwdall_parsed,
8547         .data = NULL,
8548         .help_str = "show|clear fwd stats all",
8549         .tokens = {
8550                 (void *)&cmd_fwd_action,
8551                 (void *)&cmd_fwd_fwd,
8552                 (void *)&cmd_fwd_stats,
8553                 (void *)&cmd_fwd_all,
8554                 NULL,
8555         },
8556 };
8557
8558 /* *** READ PORT REGISTER *** */
8559 struct cmd_read_reg_result {
8560         cmdline_fixed_string_t read;
8561         cmdline_fixed_string_t reg;
8562         portid_t port_id;
8563         uint32_t reg_off;
8564 };
8565
8566 static void
8567 cmd_read_reg_parsed(void *parsed_result,
8568                     __rte_unused struct cmdline *cl,
8569                     __rte_unused void *data)
8570 {
8571         struct cmd_read_reg_result *res = parsed_result;
8572         port_reg_display(res->port_id, res->reg_off);
8573 }
8574
8575 static cmdline_parse_token_string_t cmd_read_reg_read =
8576         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8577 static cmdline_parse_token_string_t cmd_read_reg_reg =
8578         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8579 static cmdline_parse_token_num_t cmd_read_reg_port_id =
8580         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8581 static cmdline_parse_token_num_t cmd_read_reg_reg_off =
8582         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8583
8584 static cmdline_parse_inst_t cmd_read_reg = {
8585         .f = cmd_read_reg_parsed,
8586         .data = NULL,
8587         .help_str = "read reg <port_id> <reg_off>",
8588         .tokens = {
8589                 (void *)&cmd_read_reg_read,
8590                 (void *)&cmd_read_reg_reg,
8591                 (void *)&cmd_read_reg_port_id,
8592                 (void *)&cmd_read_reg_reg_off,
8593                 NULL,
8594         },
8595 };
8596
8597 /* *** READ PORT REGISTER BIT FIELD *** */
8598 struct cmd_read_reg_bit_field_result {
8599         cmdline_fixed_string_t read;
8600         cmdline_fixed_string_t regfield;
8601         portid_t port_id;
8602         uint32_t reg_off;
8603         uint8_t bit1_pos;
8604         uint8_t bit2_pos;
8605 };
8606
8607 static void
8608 cmd_read_reg_bit_field_parsed(void *parsed_result,
8609                               __rte_unused struct cmdline *cl,
8610                               __rte_unused void *data)
8611 {
8612         struct cmd_read_reg_bit_field_result *res = parsed_result;
8613         port_reg_bit_field_display(res->port_id, res->reg_off,
8614                                    res->bit1_pos, res->bit2_pos);
8615 }
8616
8617 static cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8618         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8619                                  "read");
8620 static cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8621         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8622                                  regfield, "regfield");
8623 static cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8624         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8625                               RTE_UINT16);
8626 static cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8627         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8628                               RTE_UINT32);
8629 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8630         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8631                               RTE_UINT8);
8632 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8633         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8634                               RTE_UINT8);
8635
8636 static cmdline_parse_inst_t cmd_read_reg_bit_field = {
8637         .f = cmd_read_reg_bit_field_parsed,
8638         .data = NULL,
8639         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8640         "Read register bit field between bit_x and bit_y included",
8641         .tokens = {
8642                 (void *)&cmd_read_reg_bit_field_read,
8643                 (void *)&cmd_read_reg_bit_field_regfield,
8644                 (void *)&cmd_read_reg_bit_field_port_id,
8645                 (void *)&cmd_read_reg_bit_field_reg_off,
8646                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8647                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8648                 NULL,
8649         },
8650 };
8651
8652 /* *** READ PORT REGISTER BIT *** */
8653 struct cmd_read_reg_bit_result {
8654         cmdline_fixed_string_t read;
8655         cmdline_fixed_string_t regbit;
8656         portid_t port_id;
8657         uint32_t reg_off;
8658         uint8_t bit_pos;
8659 };
8660
8661 static void
8662 cmd_read_reg_bit_parsed(void *parsed_result,
8663                         __rte_unused struct cmdline *cl,
8664                         __rte_unused void *data)
8665 {
8666         struct cmd_read_reg_bit_result *res = parsed_result;
8667         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8668 }
8669
8670 static cmdline_parse_token_string_t cmd_read_reg_bit_read =
8671         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8672 static cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8673         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8674                                  regbit, "regbit");
8675 static cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8676         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8677                                  RTE_UINT16);
8678 static cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8679         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8680                                  RTE_UINT32);
8681 static cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8682         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8683                                  RTE_UINT8);
8684
8685 static cmdline_parse_inst_t cmd_read_reg_bit = {
8686         .f = cmd_read_reg_bit_parsed,
8687         .data = NULL,
8688         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8689         .tokens = {
8690                 (void *)&cmd_read_reg_bit_read,
8691                 (void *)&cmd_read_reg_bit_regbit,
8692                 (void *)&cmd_read_reg_bit_port_id,
8693                 (void *)&cmd_read_reg_bit_reg_off,
8694                 (void *)&cmd_read_reg_bit_bit_pos,
8695                 NULL,
8696         },
8697 };
8698
8699 /* *** WRITE PORT REGISTER *** */
8700 struct cmd_write_reg_result {
8701         cmdline_fixed_string_t write;
8702         cmdline_fixed_string_t reg;
8703         portid_t port_id;
8704         uint32_t reg_off;
8705         uint32_t value;
8706 };
8707
8708 static void
8709 cmd_write_reg_parsed(void *parsed_result,
8710                      __rte_unused struct cmdline *cl,
8711                      __rte_unused void *data)
8712 {
8713         struct cmd_write_reg_result *res = parsed_result;
8714         port_reg_set(res->port_id, res->reg_off, res->value);
8715 }
8716
8717 static cmdline_parse_token_string_t cmd_write_reg_write =
8718         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8719 static cmdline_parse_token_string_t cmd_write_reg_reg =
8720         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8721 static cmdline_parse_token_num_t cmd_write_reg_port_id =
8722         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8723 static cmdline_parse_token_num_t cmd_write_reg_reg_off =
8724         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8725 static cmdline_parse_token_num_t cmd_write_reg_value =
8726         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8727
8728 static cmdline_parse_inst_t cmd_write_reg = {
8729         .f = cmd_write_reg_parsed,
8730         .data = NULL,
8731         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8732         .tokens = {
8733                 (void *)&cmd_write_reg_write,
8734                 (void *)&cmd_write_reg_reg,
8735                 (void *)&cmd_write_reg_port_id,
8736                 (void *)&cmd_write_reg_reg_off,
8737                 (void *)&cmd_write_reg_value,
8738                 NULL,
8739         },
8740 };
8741
8742 /* *** WRITE PORT REGISTER BIT FIELD *** */
8743 struct cmd_write_reg_bit_field_result {
8744         cmdline_fixed_string_t write;
8745         cmdline_fixed_string_t regfield;
8746         portid_t port_id;
8747         uint32_t reg_off;
8748         uint8_t bit1_pos;
8749         uint8_t bit2_pos;
8750         uint32_t value;
8751 };
8752
8753 static void
8754 cmd_write_reg_bit_field_parsed(void *parsed_result,
8755                                __rte_unused struct cmdline *cl,
8756                                __rte_unused void *data)
8757 {
8758         struct cmd_write_reg_bit_field_result *res = parsed_result;
8759         port_reg_bit_field_set(res->port_id, res->reg_off,
8760                           res->bit1_pos, res->bit2_pos, res->value);
8761 }
8762
8763 static cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8764         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8765                                  "write");
8766 static cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8767         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8768                                  regfield, "regfield");
8769 static cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8770         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8771                               RTE_UINT16);
8772 static cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8773         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8774                               RTE_UINT32);
8775 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8776         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8777                               RTE_UINT8);
8778 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8779         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8780                               RTE_UINT8);
8781 static cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8782         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8783                               RTE_UINT32);
8784
8785 static cmdline_parse_inst_t cmd_write_reg_bit_field = {
8786         .f = cmd_write_reg_bit_field_parsed,
8787         .data = NULL,
8788         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8789                 "<reg_value>: "
8790                 "Set register bit field between bit_x and bit_y included",
8791         .tokens = {
8792                 (void *)&cmd_write_reg_bit_field_write,
8793                 (void *)&cmd_write_reg_bit_field_regfield,
8794                 (void *)&cmd_write_reg_bit_field_port_id,
8795                 (void *)&cmd_write_reg_bit_field_reg_off,
8796                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8797                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8798                 (void *)&cmd_write_reg_bit_field_value,
8799                 NULL,
8800         },
8801 };
8802
8803 /* *** WRITE PORT REGISTER BIT *** */
8804 struct cmd_write_reg_bit_result {
8805         cmdline_fixed_string_t write;
8806         cmdline_fixed_string_t regbit;
8807         portid_t port_id;
8808         uint32_t reg_off;
8809         uint8_t bit_pos;
8810         uint8_t value;
8811 };
8812
8813 static void
8814 cmd_write_reg_bit_parsed(void *parsed_result,
8815                          __rte_unused struct cmdline *cl,
8816                          __rte_unused void *data)
8817 {
8818         struct cmd_write_reg_bit_result *res = parsed_result;
8819         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8820 }
8821
8822 static cmdline_parse_token_string_t cmd_write_reg_bit_write =
8823         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8824                                  "write");
8825 static cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8826         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8827                                  regbit, "regbit");
8828 static cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8829         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8830                                  RTE_UINT16);
8831 static cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8832         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8833                                  RTE_UINT32);
8834 static cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8835         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8836                                  RTE_UINT8);
8837 static cmdline_parse_token_num_t cmd_write_reg_bit_value =
8838         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8839                                  RTE_UINT8);
8840
8841 static cmdline_parse_inst_t cmd_write_reg_bit = {
8842         .f = cmd_write_reg_bit_parsed,
8843         .data = NULL,
8844         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8845                 "0 <= bit_x <= 31",
8846         .tokens = {
8847                 (void *)&cmd_write_reg_bit_write,
8848                 (void *)&cmd_write_reg_bit_regbit,
8849                 (void *)&cmd_write_reg_bit_port_id,
8850                 (void *)&cmd_write_reg_bit_reg_off,
8851                 (void *)&cmd_write_reg_bit_bit_pos,
8852                 (void *)&cmd_write_reg_bit_value,
8853                 NULL,
8854         },
8855 };
8856
8857 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8858 struct cmd_read_rxd_txd_result {
8859         cmdline_fixed_string_t read;
8860         cmdline_fixed_string_t rxd_txd;
8861         portid_t port_id;
8862         uint16_t queue_id;
8863         uint16_t desc_id;
8864 };
8865
8866 static void
8867 cmd_read_rxd_txd_parsed(void *parsed_result,
8868                         __rte_unused struct cmdline *cl,
8869                         __rte_unused void *data)
8870 {
8871         struct cmd_read_rxd_txd_result *res = parsed_result;
8872
8873         if (!strcmp(res->rxd_txd, "rxd"))
8874                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8875         else if (!strcmp(res->rxd_txd, "txd"))
8876                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8877 }
8878
8879 static cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8880         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8881 static cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8882         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8883                                  "rxd#txd");
8884 static cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8885         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8886                                  RTE_UINT16);
8887 static cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8888         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8889                                  RTE_UINT16);
8890 static cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8891         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8892                                  RTE_UINT16);
8893
8894 static cmdline_parse_inst_t cmd_read_rxd_txd = {
8895         .f = cmd_read_rxd_txd_parsed,
8896         .data = NULL,
8897         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8898         .tokens = {
8899                 (void *)&cmd_read_rxd_txd_read,
8900                 (void *)&cmd_read_rxd_txd_rxd_txd,
8901                 (void *)&cmd_read_rxd_txd_port_id,
8902                 (void *)&cmd_read_rxd_txd_queue_id,
8903                 (void *)&cmd_read_rxd_txd_desc_id,
8904                 NULL,
8905         },
8906 };
8907
8908 /* *** QUIT *** */
8909 struct cmd_quit_result {
8910         cmdline_fixed_string_t quit;
8911 };
8912
8913 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8914                             struct cmdline *cl,
8915                             __rte_unused void *data)
8916 {
8917         cmdline_quit(cl);
8918 }
8919
8920 static cmdline_parse_token_string_t cmd_quit_quit =
8921         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8922
8923 static cmdline_parse_inst_t cmd_quit = {
8924         .f = cmd_quit_parsed,
8925         .data = NULL,
8926         .help_str = "quit: Exit application",
8927         .tokens = {
8928                 (void *)&cmd_quit_quit,
8929                 NULL,
8930         },
8931 };
8932
8933 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8934 struct cmd_mac_addr_result {
8935         cmdline_fixed_string_t mac_addr_cmd;
8936         cmdline_fixed_string_t what;
8937         uint16_t port_num;
8938         struct rte_ether_addr address;
8939 };
8940
8941 static void cmd_mac_addr_parsed(void *parsed_result,
8942                 __rte_unused struct cmdline *cl,
8943                 __rte_unused void *data)
8944 {
8945         struct cmd_mac_addr_result *res = parsed_result;
8946         int ret;
8947
8948         if (strcmp(res->what, "add") == 0)
8949                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8950         else if (strcmp(res->what, "set") == 0)
8951                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8952                                                        &res->address);
8953         else
8954                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8955
8956         /* check the return value and print it if is < 0 */
8957         if(ret < 0)
8958                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8959
8960 }
8961
8962 static cmdline_parse_token_string_t cmd_mac_addr_cmd =
8963         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8964                                 "mac_addr");
8965 static cmdline_parse_token_string_t cmd_mac_addr_what =
8966         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8967                                 "add#remove#set");
8968 static cmdline_parse_token_num_t cmd_mac_addr_portnum =
8969                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8970                                         RTE_UINT16);
8971 static cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8972                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8973
8974 static cmdline_parse_inst_t cmd_mac_addr = {
8975         .f = cmd_mac_addr_parsed,
8976         .data = (void *)0,
8977         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8978                         "Add/Remove/Set MAC address on port_id",
8979         .tokens = {
8980                 (void *)&cmd_mac_addr_cmd,
8981                 (void *)&cmd_mac_addr_what,
8982                 (void *)&cmd_mac_addr_portnum,
8983                 (void *)&cmd_mac_addr_addr,
8984                 NULL,
8985         },
8986 };
8987
8988 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8989 struct cmd_eth_peer_result {
8990         cmdline_fixed_string_t set;
8991         cmdline_fixed_string_t eth_peer;
8992         portid_t port_id;
8993         cmdline_fixed_string_t peer_addr;
8994 };
8995
8996 static void cmd_set_eth_peer_parsed(void *parsed_result,
8997                         __rte_unused struct cmdline *cl,
8998                         __rte_unused void *data)
8999 {
9000                 struct cmd_eth_peer_result *res = parsed_result;
9001
9002                 if (test_done == 0) {
9003                         fprintf(stderr, "Please stop forwarding first\n");
9004                         return;
9005                 }
9006                 if (!strcmp(res->eth_peer, "eth-peer")) {
9007                         set_fwd_eth_peer(res->port_id, res->peer_addr);
9008                         fwd_config_setup();
9009                 }
9010 }
9011 static cmdline_parse_token_string_t cmd_eth_peer_set =
9012         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
9013 static cmdline_parse_token_string_t cmd_eth_peer =
9014         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
9015 static cmdline_parse_token_num_t cmd_eth_peer_port_id =
9016         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
9017                 RTE_UINT16);
9018 static cmdline_parse_token_string_t cmd_eth_peer_addr =
9019         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
9020
9021 static cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
9022         .f = cmd_set_eth_peer_parsed,
9023         .data = NULL,
9024         .help_str = "set eth-peer <port_id> <peer_mac>",
9025         .tokens = {
9026                 (void *)&cmd_eth_peer_set,
9027                 (void *)&cmd_eth_peer,
9028                 (void *)&cmd_eth_peer_port_id,
9029                 (void *)&cmd_eth_peer_addr,
9030                 NULL,
9031         },
9032 };
9033
9034 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9035 struct cmd_set_qmap_result {
9036         cmdline_fixed_string_t set;
9037         cmdline_fixed_string_t qmap;
9038         cmdline_fixed_string_t what;
9039         portid_t port_id;
9040         uint16_t queue_id;
9041         uint8_t map_value;
9042 };
9043
9044 static void
9045 cmd_set_qmap_parsed(void *parsed_result,
9046                        __rte_unused struct cmdline *cl,
9047                        __rte_unused void *data)
9048 {
9049         struct cmd_set_qmap_result *res = parsed_result;
9050         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9051
9052         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9053 }
9054
9055 static cmdline_parse_token_string_t cmd_setqmap_set =
9056         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9057                                  set, "set");
9058 static cmdline_parse_token_string_t cmd_setqmap_qmap =
9059         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9060                                  qmap, "stat_qmap");
9061 static cmdline_parse_token_string_t cmd_setqmap_what =
9062         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9063                                  what, "tx#rx");
9064 static cmdline_parse_token_num_t cmd_setqmap_portid =
9065         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9066                               port_id, RTE_UINT16);
9067 static cmdline_parse_token_num_t cmd_setqmap_queueid =
9068         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9069                               queue_id, RTE_UINT16);
9070 static cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9071         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9072                               map_value, RTE_UINT8);
9073
9074 static cmdline_parse_inst_t cmd_set_qmap = {
9075         .f = cmd_set_qmap_parsed,
9076         .data = NULL,
9077         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9078                 "Set statistics mapping value on tx|rx queue_id of port_id",
9079         .tokens = {
9080                 (void *)&cmd_setqmap_set,
9081                 (void *)&cmd_setqmap_qmap,
9082                 (void *)&cmd_setqmap_what,
9083                 (void *)&cmd_setqmap_portid,
9084                 (void *)&cmd_setqmap_queueid,
9085                 (void *)&cmd_setqmap_mapvalue,
9086                 NULL,
9087         },
9088 };
9089
9090 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9091 struct cmd_set_xstats_hide_zero_result {
9092         cmdline_fixed_string_t keyword;
9093         cmdline_fixed_string_t name;
9094         cmdline_fixed_string_t on_off;
9095 };
9096
9097 static void
9098 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9099                         __rte_unused struct cmdline *cl,
9100                         __rte_unused void *data)
9101 {
9102         struct cmd_set_xstats_hide_zero_result *res;
9103         uint16_t on_off = 0;
9104
9105         res = parsed_result;
9106         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9107         set_xstats_hide_zero(on_off);
9108 }
9109
9110 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9111         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9112                                  keyword, "set");
9113 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9114         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9115                                  name, "xstats-hide-zero");
9116 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9117         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9118                                  on_off, "on#off");
9119
9120 static cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9121         .f = cmd_set_xstats_hide_zero_parsed,
9122         .data = NULL,
9123         .help_str = "set xstats-hide-zero on|off",
9124         .tokens = {
9125                 (void *)&cmd_set_xstats_hide_zero_keyword,
9126                 (void *)&cmd_set_xstats_hide_zero_name,
9127                 (void *)&cmd_set_xstats_hide_zero_on_off,
9128                 NULL,
9129         },
9130 };
9131
9132 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9133 struct cmd_set_record_core_cycles_result {
9134         cmdline_fixed_string_t keyword;
9135         cmdline_fixed_string_t name;
9136         cmdline_fixed_string_t on_off;
9137 };
9138
9139 static void
9140 cmd_set_record_core_cycles_parsed(void *parsed_result,
9141                         __rte_unused struct cmdline *cl,
9142                         __rte_unused void *data)
9143 {
9144         struct cmd_set_record_core_cycles_result *res;
9145         uint16_t on_off = 0;
9146
9147         res = parsed_result;
9148         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9149         set_record_core_cycles(on_off);
9150 }
9151
9152 static cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9153         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9154                                  keyword, "set");
9155 static cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9156         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9157                                  name, "record-core-cycles");
9158 static cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9159         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9160                                  on_off, "on#off");
9161
9162 static cmdline_parse_inst_t cmd_set_record_core_cycles = {
9163         .f = cmd_set_record_core_cycles_parsed,
9164         .data = NULL,
9165         .help_str = "set record-core-cycles on|off",
9166         .tokens = {
9167                 (void *)&cmd_set_record_core_cycles_keyword,
9168                 (void *)&cmd_set_record_core_cycles_name,
9169                 (void *)&cmd_set_record_core_cycles_on_off,
9170                 NULL,
9171         },
9172 };
9173
9174 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9175 struct cmd_set_record_burst_stats_result {
9176         cmdline_fixed_string_t keyword;
9177         cmdline_fixed_string_t name;
9178         cmdline_fixed_string_t on_off;
9179 };
9180
9181 static void
9182 cmd_set_record_burst_stats_parsed(void *parsed_result,
9183                         __rte_unused struct cmdline *cl,
9184                         __rte_unused void *data)
9185 {
9186         struct cmd_set_record_burst_stats_result *res;
9187         uint16_t on_off = 0;
9188
9189         res = parsed_result;
9190         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9191         set_record_burst_stats(on_off);
9192 }
9193
9194 static cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9195         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9196                                  keyword, "set");
9197 static cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9198         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9199                                  name, "record-burst-stats");
9200 static cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9201         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9202                                  on_off, "on#off");
9203
9204 static cmdline_parse_inst_t cmd_set_record_burst_stats = {
9205         .f = cmd_set_record_burst_stats_parsed,
9206         .data = NULL,
9207         .help_str = "set record-burst-stats on|off",
9208         .tokens = {
9209                 (void *)&cmd_set_record_burst_stats_keyword,
9210                 (void *)&cmd_set_record_burst_stats_name,
9211                 (void *)&cmd_set_record_burst_stats_on_off,
9212                 NULL,
9213         },
9214 };
9215
9216 /* *** CONFIGURE UNICAST HASH TABLE *** */
9217 struct cmd_set_uc_hash_table {
9218         cmdline_fixed_string_t set;
9219         cmdline_fixed_string_t port;
9220         portid_t port_id;
9221         cmdline_fixed_string_t what;
9222         struct rte_ether_addr address;
9223         cmdline_fixed_string_t mode;
9224 };
9225
9226 static void
9227 cmd_set_uc_hash_parsed(void *parsed_result,
9228                        __rte_unused struct cmdline *cl,
9229                        __rte_unused void *data)
9230 {
9231         int ret=0;
9232         struct cmd_set_uc_hash_table *res = parsed_result;
9233
9234         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9235
9236         if (strcmp(res->what, "uta") == 0)
9237                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9238                                                 &res->address,(uint8_t)is_on);
9239         if (ret < 0)
9240                 fprintf(stderr,
9241                         "bad unicast hash table parameter, return code = %d\n",
9242                         ret);
9243
9244 }
9245
9246 static cmdline_parse_token_string_t cmd_set_uc_hash_set =
9247         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9248                                  set, "set");
9249 static cmdline_parse_token_string_t cmd_set_uc_hash_port =
9250         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9251                                  port, "port");
9252 static cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9253         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9254                               port_id, RTE_UINT16);
9255 static cmdline_parse_token_string_t cmd_set_uc_hash_what =
9256         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9257                                  what, "uta");
9258 static cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9259         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9260                                 address);
9261 static cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9262         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9263                                  mode, "on#off");
9264
9265 static cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9266         .f = cmd_set_uc_hash_parsed,
9267         .data = NULL,
9268         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9269         .tokens = {
9270                 (void *)&cmd_set_uc_hash_set,
9271                 (void *)&cmd_set_uc_hash_port,
9272                 (void *)&cmd_set_uc_hash_portid,
9273                 (void *)&cmd_set_uc_hash_what,
9274                 (void *)&cmd_set_uc_hash_mac,
9275                 (void *)&cmd_set_uc_hash_mode,
9276                 NULL,
9277         },
9278 };
9279
9280 struct cmd_set_uc_all_hash_table {
9281         cmdline_fixed_string_t set;
9282         cmdline_fixed_string_t port;
9283         portid_t port_id;
9284         cmdline_fixed_string_t what;
9285         cmdline_fixed_string_t value;
9286         cmdline_fixed_string_t mode;
9287 };
9288
9289 static void
9290 cmd_set_uc_all_hash_parsed(void *parsed_result,
9291                        __rte_unused struct cmdline *cl,
9292                        __rte_unused void *data)
9293 {
9294         int ret=0;
9295         struct cmd_set_uc_all_hash_table *res = parsed_result;
9296
9297         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9298
9299         if ((strcmp(res->what, "uta") == 0) &&
9300                 (strcmp(res->value, "all") == 0))
9301                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9302         if (ret < 0)
9303                 fprintf(stderr,
9304                         "bad unicast hash table parameter, return code = %d\n",
9305                         ret);
9306 }
9307
9308 static cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9309         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9310                                  set, "set");
9311 static cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9312         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9313                                  port, "port");
9314 static cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9315         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9316                               port_id, RTE_UINT16);
9317 static cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9318         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9319                                  what, "uta");
9320 static cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9321         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9322                                 value,"all");
9323 static cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9324         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9325                                  mode, "on#off");
9326
9327 static cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9328         .f = cmd_set_uc_all_hash_parsed,
9329         .data = NULL,
9330         .help_str = "set port <port_id> uta all on|off",
9331         .tokens = {
9332                 (void *)&cmd_set_uc_all_hash_set,
9333                 (void *)&cmd_set_uc_all_hash_port,
9334                 (void *)&cmd_set_uc_all_hash_portid,
9335                 (void *)&cmd_set_uc_all_hash_what,
9336                 (void *)&cmd_set_uc_all_hash_value,
9337                 (void *)&cmd_set_uc_all_hash_mode,
9338                 NULL,
9339         },
9340 };
9341
9342 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9343 struct cmd_set_vf_traffic {
9344         cmdline_fixed_string_t set;
9345         cmdline_fixed_string_t port;
9346         portid_t port_id;
9347         cmdline_fixed_string_t vf;
9348         uint8_t vf_id;
9349         cmdline_fixed_string_t what;
9350         cmdline_fixed_string_t mode;
9351 };
9352
9353 static void
9354 cmd_set_vf_traffic_parsed(void *parsed_result,
9355                        __rte_unused struct cmdline *cl,
9356                        __rte_unused void *data)
9357 {
9358         struct cmd_set_vf_traffic *res = parsed_result;
9359         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9360         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9361
9362         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9363 }
9364
9365 static cmdline_parse_token_string_t cmd_setvf_traffic_set =
9366         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9367                                  set, "set");
9368 static cmdline_parse_token_string_t cmd_setvf_traffic_port =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9370                                  port, "port");
9371 static cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9372         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9373                               port_id, RTE_UINT16);
9374 static cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9375         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9376                                  vf, "vf");
9377 static cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9378         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9379                               vf_id, RTE_UINT8);
9380 static cmdline_parse_token_string_t cmd_setvf_traffic_what =
9381         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9382                                  what, "tx#rx");
9383 static cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9384         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9385                                  mode, "on#off");
9386
9387 static cmdline_parse_inst_t cmd_set_vf_traffic = {
9388         .f = cmd_set_vf_traffic_parsed,
9389         .data = NULL,
9390         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9391         .tokens = {
9392                 (void *)&cmd_setvf_traffic_set,
9393                 (void *)&cmd_setvf_traffic_port,
9394                 (void *)&cmd_setvf_traffic_portid,
9395                 (void *)&cmd_setvf_traffic_vf,
9396                 (void *)&cmd_setvf_traffic_vfid,
9397                 (void *)&cmd_setvf_traffic_what,
9398                 (void *)&cmd_setvf_traffic_mode,
9399                 NULL,
9400         },
9401 };
9402
9403 /* *** CONFIGURE VF RECEIVE MODE *** */
9404 struct cmd_set_vf_rxmode {
9405         cmdline_fixed_string_t set;
9406         cmdline_fixed_string_t port;
9407         portid_t port_id;
9408         cmdline_fixed_string_t vf;
9409         uint8_t vf_id;
9410         cmdline_fixed_string_t what;
9411         cmdline_fixed_string_t mode;
9412         cmdline_fixed_string_t on;
9413 };
9414
9415 static void
9416 cmd_set_vf_rxmode_parsed(void *parsed_result,
9417                        __rte_unused struct cmdline *cl,
9418                        __rte_unused void *data)
9419 {
9420         int ret = -ENOTSUP;
9421         uint16_t vf_rxmode = 0;
9422         struct cmd_set_vf_rxmode *res = parsed_result;
9423
9424         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9425         if (!strcmp(res->what,"rxmode")) {
9426                 if (!strcmp(res->mode, "AUPE"))
9427                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9428                 else if (!strcmp(res->mode, "ROPE"))
9429                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9430                 else if (!strcmp(res->mode, "BAM"))
9431                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9432                 else if (!strncmp(res->mode, "MPE",3))
9433                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9434         }
9435
9436         RTE_SET_USED(is_on);
9437         RTE_SET_USED(vf_rxmode);
9438
9439 #ifdef RTE_NET_IXGBE
9440         if (ret == -ENOTSUP)
9441                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9442                                                   vf_rxmode, (uint8_t)is_on);
9443 #endif
9444 #ifdef RTE_NET_BNXT
9445         if (ret == -ENOTSUP)
9446                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9447                                                  vf_rxmode, (uint8_t)is_on);
9448 #endif
9449         if (ret < 0)
9450                 fprintf(stderr,
9451                         "bad VF receive mode parameter, return code = %d\n",
9452                         ret);
9453 }
9454
9455 static cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9456         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9457                                  set, "set");
9458 static cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9459         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9460                                  port, "port");
9461 static cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9462         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9463                               port_id, RTE_UINT16);
9464 static cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9465         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9466                                  vf, "vf");
9467 static cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9468         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9469                               vf_id, RTE_UINT8);
9470 static cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9471         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9472                                  what, "rxmode");
9473 static cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9474         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9475                                  mode, "AUPE#ROPE#BAM#MPE");
9476 static cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9477         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9478                                  on, "on#off");
9479
9480 static cmdline_parse_inst_t cmd_set_vf_rxmode = {
9481         .f = cmd_set_vf_rxmode_parsed,
9482         .data = NULL,
9483         .help_str = "set port <port_id> vf <vf_id> rxmode "
9484                 "AUPE|ROPE|BAM|MPE on|off",
9485         .tokens = {
9486                 (void *)&cmd_set_vf_rxmode_set,
9487                 (void *)&cmd_set_vf_rxmode_port,
9488                 (void *)&cmd_set_vf_rxmode_portid,
9489                 (void *)&cmd_set_vf_rxmode_vf,
9490                 (void *)&cmd_set_vf_rxmode_vfid,
9491                 (void *)&cmd_set_vf_rxmode_what,
9492                 (void *)&cmd_set_vf_rxmode_mode,
9493                 (void *)&cmd_set_vf_rxmode_on,
9494                 NULL,
9495         },
9496 };
9497
9498 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9499 struct cmd_vf_mac_addr_result {
9500         cmdline_fixed_string_t mac_addr_cmd;
9501         cmdline_fixed_string_t what;
9502         cmdline_fixed_string_t port;
9503         uint16_t port_num;
9504         cmdline_fixed_string_t vf;
9505         uint8_t vf_num;
9506         struct rte_ether_addr address;
9507 };
9508
9509 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9510                 __rte_unused struct cmdline *cl,
9511                 __rte_unused void *data)
9512 {
9513         struct cmd_vf_mac_addr_result *res = parsed_result;
9514         int ret = -ENOTSUP;
9515
9516         if (strcmp(res->what, "add") != 0)
9517                 return;
9518
9519 #ifdef RTE_NET_I40E
9520         if (ret == -ENOTSUP)
9521                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9522                                                    &res->address);
9523 #endif
9524 #ifdef RTE_NET_BNXT
9525         if (ret == -ENOTSUP)
9526                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9527                                                 res->vf_num);
9528 #endif
9529
9530         if(ret < 0)
9531                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9532
9533 }
9534
9535 static cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9536         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9537                                 mac_addr_cmd,"mac_addr");
9538 static cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9539         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9540                                 what,"add");
9541 static cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9542         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9543                                 port,"port");
9544 static cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9545         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9546                                 port_num, RTE_UINT16);
9547 static cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9548         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9549                                 vf,"vf");
9550 static cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9551         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9552                                 vf_num, RTE_UINT8);
9553 static cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9554         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9555                                 address);
9556
9557 static cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9558         .f = cmd_vf_mac_addr_parsed,
9559         .data = (void *)0,
9560         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9561                 "Add MAC address filtering for a VF on port_id",
9562         .tokens = {
9563                 (void *)&cmd_vf_mac_addr_cmd,
9564                 (void *)&cmd_vf_mac_addr_what,
9565                 (void *)&cmd_vf_mac_addr_port,
9566                 (void *)&cmd_vf_mac_addr_portnum,
9567                 (void *)&cmd_vf_mac_addr_vf,
9568                 (void *)&cmd_vf_mac_addr_vfnum,
9569                 (void *)&cmd_vf_mac_addr_addr,
9570                 NULL,
9571         },
9572 };
9573
9574 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9575 struct cmd_vf_rx_vlan_filter {
9576         cmdline_fixed_string_t rx_vlan;
9577         cmdline_fixed_string_t what;
9578         uint16_t vlan_id;
9579         cmdline_fixed_string_t port;
9580         portid_t port_id;
9581         cmdline_fixed_string_t vf;
9582         uint64_t vf_mask;
9583 };
9584
9585 static void
9586 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9587                           __rte_unused struct cmdline *cl,
9588                           __rte_unused void *data)
9589 {
9590         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9591         int ret = -ENOTSUP;
9592
9593         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9594
9595 #ifdef RTE_NET_IXGBE
9596         if (ret == -ENOTSUP)
9597                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9598                                 res->vlan_id, res->vf_mask, is_add);
9599 #endif
9600 #ifdef RTE_NET_I40E
9601         if (ret == -ENOTSUP)
9602                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9603                                 res->vlan_id, res->vf_mask, is_add);
9604 #endif
9605 #ifdef RTE_NET_BNXT
9606         if (ret == -ENOTSUP)
9607                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9608                                 res->vlan_id, res->vf_mask, is_add);
9609 #endif
9610
9611         switch (ret) {
9612         case 0:
9613                 break;
9614         case -EINVAL:
9615                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9616                         res->vlan_id, res->vf_mask);
9617                 break;
9618         case -ENODEV:
9619                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9620                 break;
9621         case -ENOTSUP:
9622                 fprintf(stderr, "function not implemented or supported\n");
9623                 break;
9624         default:
9625                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9626         }
9627 }
9628
9629 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9630         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9631                                  rx_vlan, "rx_vlan");
9632 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9633         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9634                                  what, "add#rm");
9635 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9636         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9637                               vlan_id, RTE_UINT16);
9638 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9639         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9640                                  port, "port");
9641 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9642         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9643                               port_id, RTE_UINT16);
9644 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9645         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9646                                  vf, "vf");
9647 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9648         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9649                               vf_mask, RTE_UINT64);
9650
9651 static cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9652         .f = cmd_vf_rx_vlan_filter_parsed,
9653         .data = NULL,
9654         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9655                 "(vf_mask = hexadecimal VF mask)",
9656         .tokens = {
9657                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9658                 (void *)&cmd_vf_rx_vlan_filter_what,
9659                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9660                 (void *)&cmd_vf_rx_vlan_filter_port,
9661                 (void *)&cmd_vf_rx_vlan_filter_portid,
9662                 (void *)&cmd_vf_rx_vlan_filter_vf,
9663                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9664                 NULL,
9665         },
9666 };
9667
9668 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9669 struct cmd_queue_rate_limit_result {
9670         cmdline_fixed_string_t set;
9671         cmdline_fixed_string_t port;
9672         uint16_t port_num;
9673         cmdline_fixed_string_t queue;
9674         uint8_t queue_num;
9675         cmdline_fixed_string_t rate;
9676         uint16_t rate_num;
9677 };
9678
9679 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9680                 __rte_unused struct cmdline *cl,
9681                 __rte_unused void *data)
9682 {
9683         struct cmd_queue_rate_limit_result *res = parsed_result;
9684         int ret = 0;
9685
9686         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9687                 && (strcmp(res->queue, "queue") == 0)
9688                 && (strcmp(res->rate, "rate") == 0))
9689                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9690                                         res->rate_num);
9691         if (ret < 0)
9692                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9693                         strerror(-ret));
9694
9695 }
9696
9697 static cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9698         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9699                                 set, "set");
9700 static cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9701         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9702                                 port, "port");
9703 static cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9704         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9705                                 port_num, RTE_UINT16);
9706 static cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9707         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9708                                 queue, "queue");
9709 static cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9710         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9711                                 queue_num, RTE_UINT8);
9712 static cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9713         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9714                                 rate, "rate");
9715 static cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9716         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9717                                 rate_num, RTE_UINT16);
9718
9719 static cmdline_parse_inst_t cmd_queue_rate_limit = {
9720         .f = cmd_queue_rate_limit_parsed,
9721         .data = (void *)0,
9722         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9723                 "Set rate limit for a queue on port_id",
9724         .tokens = {
9725                 (void *)&cmd_queue_rate_limit_set,
9726                 (void *)&cmd_queue_rate_limit_port,
9727                 (void *)&cmd_queue_rate_limit_portnum,
9728                 (void *)&cmd_queue_rate_limit_queue,
9729                 (void *)&cmd_queue_rate_limit_queuenum,
9730                 (void *)&cmd_queue_rate_limit_rate,
9731                 (void *)&cmd_queue_rate_limit_ratenum,
9732                 NULL,
9733         },
9734 };
9735
9736 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9737 struct cmd_vf_rate_limit_result {
9738         cmdline_fixed_string_t set;
9739         cmdline_fixed_string_t port;
9740         uint16_t port_num;
9741         cmdline_fixed_string_t vf;
9742         uint8_t vf_num;
9743         cmdline_fixed_string_t rate;
9744         uint16_t rate_num;
9745         cmdline_fixed_string_t q_msk;
9746         uint64_t q_msk_val;
9747 };
9748
9749 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9750                 __rte_unused struct cmdline *cl,
9751                 __rte_unused void *data)
9752 {
9753         struct cmd_vf_rate_limit_result *res = parsed_result;
9754         int ret = 0;
9755
9756         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9757                 && (strcmp(res->vf, "vf") == 0)
9758                 && (strcmp(res->rate, "rate") == 0)
9759                 && (strcmp(res->q_msk, "queue_mask") == 0))
9760                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9761                                         res->rate_num, res->q_msk_val);
9762         if (ret < 0)
9763                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9764                         strerror(-ret));
9765
9766 }
9767
9768 static cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9769         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9770                                 set, "set");
9771 static cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9772         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9773                                 port, "port");
9774 static cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9775         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9776                                 port_num, RTE_UINT16);
9777 static cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9778         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9779                                 vf, "vf");
9780 static cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9781         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9782                                 vf_num, RTE_UINT8);
9783 static cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9784         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9785                                 rate, "rate");
9786 static cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9787         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9788                                 rate_num, RTE_UINT16);
9789 static cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9790         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9791                                 q_msk, "queue_mask");
9792 static cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9793         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9794                                 q_msk_val, RTE_UINT64);
9795
9796 static cmdline_parse_inst_t cmd_vf_rate_limit = {
9797         .f = cmd_vf_rate_limit_parsed,
9798         .data = (void *)0,
9799         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9800                 "queue_mask <queue_mask_value>: "
9801                 "Set rate limit for queues of VF on port_id",
9802         .tokens = {
9803                 (void *)&cmd_vf_rate_limit_set,
9804                 (void *)&cmd_vf_rate_limit_port,
9805                 (void *)&cmd_vf_rate_limit_portnum,
9806                 (void *)&cmd_vf_rate_limit_vf,
9807                 (void *)&cmd_vf_rate_limit_vfnum,
9808                 (void *)&cmd_vf_rate_limit_rate,
9809                 (void *)&cmd_vf_rate_limit_ratenum,
9810                 (void *)&cmd_vf_rate_limit_q_msk,
9811                 (void *)&cmd_vf_rate_limit_q_msk_val,
9812                 NULL,
9813         },
9814 };
9815
9816 /* *** CONFIGURE TUNNEL UDP PORT *** */
9817 struct cmd_tunnel_udp_config {
9818         cmdline_fixed_string_t rx_vxlan_port;
9819         cmdline_fixed_string_t what;
9820         uint16_t udp_port;
9821         portid_t port_id;
9822 };
9823
9824 static void
9825 cmd_tunnel_udp_config_parsed(void *parsed_result,
9826                           __rte_unused struct cmdline *cl,
9827                           __rte_unused void *data)
9828 {
9829         struct cmd_tunnel_udp_config *res = parsed_result;
9830         struct rte_eth_udp_tunnel tunnel_udp;
9831         int ret;
9832
9833         tunnel_udp.udp_port = res->udp_port;
9834         tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9835
9836         if (!strcmp(res->what, "add"))
9837                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9838                                                       &tunnel_udp);
9839         else
9840                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9841                                                          &tunnel_udp);
9842
9843         if (ret < 0)
9844                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9845                         strerror(-ret));
9846 }
9847
9848 static cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9849         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9850                                 rx_vxlan_port, "rx_vxlan_port");
9851 static cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9852         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9853                                 what, "add#rm");
9854 static cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9855         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9856                                 udp_port, RTE_UINT16);
9857 static cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9858         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9859                                 port_id, RTE_UINT16);
9860
9861 static cmdline_parse_inst_t cmd_tunnel_udp_config = {
9862         .f = cmd_tunnel_udp_config_parsed,
9863         .data = (void *)0,
9864         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9865                 "Add/Remove a tunneling UDP port filter",
9866         .tokens = {
9867                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9868                 (void *)&cmd_tunnel_udp_config_what,
9869                 (void *)&cmd_tunnel_udp_config_udp_port,
9870                 (void *)&cmd_tunnel_udp_config_port_id,
9871                 NULL,
9872         },
9873 };
9874
9875 struct cmd_config_tunnel_udp_port {
9876         cmdline_fixed_string_t port;
9877         cmdline_fixed_string_t config;
9878         portid_t port_id;
9879         cmdline_fixed_string_t udp_tunnel_port;
9880         cmdline_fixed_string_t action;
9881         cmdline_fixed_string_t tunnel_type;
9882         uint16_t udp_port;
9883 };
9884
9885 static void
9886 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9887                                __rte_unused struct cmdline *cl,
9888                                __rte_unused void *data)
9889 {
9890         struct cmd_config_tunnel_udp_port *res = parsed_result;
9891         struct rte_eth_udp_tunnel tunnel_udp;
9892         int ret = 0;
9893
9894         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9895                 return;
9896
9897         tunnel_udp.udp_port = res->udp_port;
9898
9899         if (!strcmp(res->tunnel_type, "vxlan")) {
9900                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9901         } else if (!strcmp(res->tunnel_type, "geneve")) {
9902                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9903         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9904                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9905         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9906                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9907         } else {
9908                 fprintf(stderr, "Invalid tunnel type\n");
9909                 return;
9910         }
9911
9912         if (!strcmp(res->action, "add"))
9913                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9914                                                       &tunnel_udp);
9915         else
9916                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9917                                                          &tunnel_udp);
9918
9919         if (ret < 0)
9920                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9921                         strerror(-ret));
9922 }
9923
9924 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9925         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9926                                  "port");
9927 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9928         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9929                                  "config");
9930 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9931         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9932                               RTE_UINT16);
9933 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9934         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9935                                  udp_tunnel_port,
9936                                  "udp_tunnel_port");
9937 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9938         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9939                                  "add#rm");
9940 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9941         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9942                                  "vxlan#geneve#vxlan-gpe#ecpri");
9943 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9944         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9945                               RTE_UINT16);
9946
9947 static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9948         .f = cmd_cfg_tunnel_udp_port_parsed,
9949         .data = NULL,
9950         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9951                 "geneve|vxlan-gpe|ecpri <udp_port>",
9952         .tokens = {
9953                 (void *)&cmd_config_tunnel_udp_port_port,
9954                 (void *)&cmd_config_tunnel_udp_port_config,
9955                 (void *)&cmd_config_tunnel_udp_port_port_id,
9956                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9957                 (void *)&cmd_config_tunnel_udp_port_action,
9958                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9959                 (void *)&cmd_config_tunnel_udp_port_value,
9960                 NULL,
9961         },
9962 };
9963
9964 /* ******************************************************************************** */
9965
9966 struct cmd_dump_result {
9967         cmdline_fixed_string_t dump;
9968 };
9969
9970 static void
9971 dump_struct_sizes(void)
9972 {
9973 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9974         DUMP_SIZE(struct rte_mbuf);
9975         DUMP_SIZE(struct rte_mempool);
9976         DUMP_SIZE(struct rte_ring);
9977 #undef DUMP_SIZE
9978 }
9979
9980
9981 /* Dump the socket memory statistics on console */
9982 static void
9983 dump_socket_mem(FILE *f)
9984 {
9985         struct rte_malloc_socket_stats socket_stats;
9986         unsigned int i;
9987         size_t total = 0;
9988         size_t alloc = 0;
9989         size_t free = 0;
9990         unsigned int n_alloc = 0;
9991         unsigned int n_free = 0;
9992         static size_t last_allocs;
9993         static size_t last_total;
9994
9995
9996         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9997                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9998                     !socket_stats.heap_totalsz_bytes)
9999                         continue;
10000                 total += socket_stats.heap_totalsz_bytes;
10001                 alloc += socket_stats.heap_allocsz_bytes;
10002                 free += socket_stats.heap_freesz_bytes;
10003                 n_alloc += socket_stats.alloc_count;
10004                 n_free += socket_stats.free_count;
10005                 fprintf(f,
10006                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
10007                         i,
10008                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
10009                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
10010                         (double)socket_stats.heap_allocsz_bytes * 100 /
10011                         (double)socket_stats.heap_totalsz_bytes,
10012                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
10013                         socket_stats.alloc_count,
10014                         socket_stats.free_count);
10015         }
10016         fprintf(f,
10017                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
10018                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
10019                 total ? ((double)alloc * 100 / (double)total) : 0,
10020                 (double)free / (1024 * 1024),
10021                 n_alloc, n_free);
10022         if (last_allocs)
10023                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
10024                         ((double)total - (double)last_total) / (1024 * 1024),
10025                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
10026         last_allocs = alloc;
10027         last_total = total;
10028 }
10029
10030 static void cmd_dump_parsed(void *parsed_result,
10031                             __rte_unused struct cmdline *cl,
10032                             __rte_unused void *data)
10033 {
10034         struct cmd_dump_result *res = parsed_result;
10035
10036         if (!strcmp(res->dump, "dump_physmem"))
10037                 rte_dump_physmem_layout(stdout);
10038         else if (!strcmp(res->dump, "dump_socket_mem"))
10039                 dump_socket_mem(stdout);
10040         else if (!strcmp(res->dump, "dump_memzone"))
10041                 rte_memzone_dump(stdout);
10042         else if (!strcmp(res->dump, "dump_struct_sizes"))
10043                 dump_struct_sizes();
10044         else if (!strcmp(res->dump, "dump_ring"))
10045                 rte_ring_list_dump(stdout);
10046         else if (!strcmp(res->dump, "dump_mempool"))
10047                 rte_mempool_list_dump(stdout);
10048         else if (!strcmp(res->dump, "dump_devargs"))
10049                 rte_devargs_dump(stdout);
10050         else if (!strcmp(res->dump, "dump_log_types"))
10051                 rte_log_dump(stdout);
10052 }
10053
10054 static cmdline_parse_token_string_t cmd_dump_dump =
10055         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10056                 "dump_physmem#"
10057                 "dump_memzone#"
10058                 "dump_socket_mem#"
10059                 "dump_struct_sizes#"
10060                 "dump_ring#"
10061                 "dump_mempool#"
10062                 "dump_devargs#"
10063                 "dump_log_types");
10064
10065 static cmdline_parse_inst_t cmd_dump = {
10066         .f = cmd_dump_parsed,  /* function to call */
10067         .data = NULL,      /* 2nd arg of func */
10068         .help_str = "Dump status",
10069         .tokens = {        /* token list, NULL terminated */
10070                 (void *)&cmd_dump_dump,
10071                 NULL,
10072         },
10073 };
10074
10075 /* ******************************************************************************** */
10076
10077 struct cmd_dump_one_result {
10078         cmdline_fixed_string_t dump;
10079         cmdline_fixed_string_t name;
10080 };
10081
10082 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10083                                 __rte_unused void *data)
10084 {
10085         struct cmd_dump_one_result *res = parsed_result;
10086
10087         if (!strcmp(res->dump, "dump_ring")) {
10088                 struct rte_ring *r;
10089                 r = rte_ring_lookup(res->name);
10090                 if (r == NULL) {
10091                         cmdline_printf(cl, "Cannot find ring\n");
10092                         return;
10093                 }
10094                 rte_ring_dump(stdout, r);
10095         } else if (!strcmp(res->dump, "dump_mempool")) {
10096                 struct rte_mempool *mp;
10097                 mp = rte_mempool_lookup(res->name);
10098                 if (mp == NULL) {
10099                         cmdline_printf(cl, "Cannot find mempool\n");
10100                         return;
10101                 }
10102                 rte_mempool_dump(stdout, mp);
10103         }
10104 }
10105
10106 static cmdline_parse_token_string_t cmd_dump_one_dump =
10107         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10108                                  "dump_ring#dump_mempool");
10109
10110 static cmdline_parse_token_string_t cmd_dump_one_name =
10111         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10112
10113 static cmdline_parse_inst_t cmd_dump_one = {
10114         .f = cmd_dump_one_parsed,  /* function to call */
10115         .data = NULL,      /* 2nd arg of func */
10116         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10117         .tokens = {        /* token list, NULL terminated */
10118                 (void *)&cmd_dump_one_dump,
10119                 (void *)&cmd_dump_one_name,
10120                 NULL,
10121         },
10122 };
10123
10124 /* *** queue region set *** */
10125 struct cmd_queue_region_result {
10126         cmdline_fixed_string_t set;
10127         cmdline_fixed_string_t port;
10128         portid_t port_id;
10129         cmdline_fixed_string_t cmd;
10130         cmdline_fixed_string_t region;
10131         uint8_t  region_id;
10132         cmdline_fixed_string_t queue_start_index;
10133         uint8_t  queue_id;
10134         cmdline_fixed_string_t queue_num;
10135         uint8_t  queue_num_value;
10136 };
10137
10138 static void
10139 cmd_queue_region_parsed(void *parsed_result,
10140                         __rte_unused struct cmdline *cl,
10141                         __rte_unused void *data)
10142 {
10143         struct cmd_queue_region_result *res = parsed_result;
10144         int ret = -ENOTSUP;
10145 #ifdef RTE_NET_I40E
10146         struct rte_pmd_i40e_queue_region_conf region_conf;
10147         enum rte_pmd_i40e_queue_region_op op_type;
10148 #endif
10149
10150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10151                 return;
10152
10153 #ifdef RTE_NET_I40E
10154         memset(&region_conf, 0, sizeof(region_conf));
10155         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10156         region_conf.region_id = res->region_id;
10157         region_conf.queue_num = res->queue_num_value;
10158         region_conf.queue_start_index = res->queue_id;
10159
10160         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10161                                 op_type, &region_conf);
10162 #endif
10163
10164         switch (ret) {
10165         case 0:
10166                 break;
10167         case -ENOTSUP:
10168                 fprintf(stderr, "function not implemented or supported\n");
10169                 break;
10170         default:
10171                 fprintf(stderr, "queue region config error: (%s)\n",
10172                         strerror(-ret));
10173         }
10174 }
10175
10176 static cmdline_parse_token_string_t cmd_queue_region_set =
10177 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10178                 set, "set");
10179 static cmdline_parse_token_string_t cmd_queue_region_port =
10180         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10181 static cmdline_parse_token_num_t cmd_queue_region_port_id =
10182         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10183                                 port_id, RTE_UINT16);
10184 static cmdline_parse_token_string_t cmd_queue_region_cmd =
10185         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10186                                  cmd, "queue-region");
10187 static cmdline_parse_token_string_t cmd_queue_region_id =
10188         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10189                                 region, "region_id");
10190 static cmdline_parse_token_num_t cmd_queue_region_index =
10191         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10192                                 region_id, RTE_UINT8);
10193 static cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10194         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10195                                 queue_start_index, "queue_start_index");
10196 static cmdline_parse_token_num_t cmd_queue_region_queue_id =
10197         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10198                                 queue_id, RTE_UINT8);
10199 static cmdline_parse_token_string_t cmd_queue_region_queue_num =
10200         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10201                                 queue_num, "queue_num");
10202 static cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10203         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10204                                 queue_num_value, RTE_UINT8);
10205
10206 static cmdline_parse_inst_t cmd_queue_region = {
10207         .f = cmd_queue_region_parsed,
10208         .data = NULL,
10209         .help_str = "set port <port_id> queue-region region_id <value> "
10210                 "queue_start_index <value> queue_num <value>: Set a queue region",
10211         .tokens = {
10212                 (void *)&cmd_queue_region_set,
10213                 (void *)&cmd_queue_region_port,
10214                 (void *)&cmd_queue_region_port_id,
10215                 (void *)&cmd_queue_region_cmd,
10216                 (void *)&cmd_queue_region_id,
10217                 (void *)&cmd_queue_region_index,
10218                 (void *)&cmd_queue_region_queue_start_index,
10219                 (void *)&cmd_queue_region_queue_id,
10220                 (void *)&cmd_queue_region_queue_num,
10221                 (void *)&cmd_queue_region_queue_num_value,
10222                 NULL,
10223         },
10224 };
10225
10226 /* *** queue region and flowtype set *** */
10227 struct cmd_region_flowtype_result {
10228         cmdline_fixed_string_t set;
10229         cmdline_fixed_string_t port;
10230         portid_t port_id;
10231         cmdline_fixed_string_t cmd;
10232         cmdline_fixed_string_t region;
10233         uint8_t  region_id;
10234         cmdline_fixed_string_t flowtype;
10235         uint8_t  flowtype_id;
10236 };
10237
10238 static void
10239 cmd_region_flowtype_parsed(void *parsed_result,
10240                         __rte_unused struct cmdline *cl,
10241                         __rte_unused void *data)
10242 {
10243         struct cmd_region_flowtype_result *res = parsed_result;
10244         int ret = -ENOTSUP;
10245 #ifdef RTE_NET_I40E
10246         struct rte_pmd_i40e_queue_region_conf region_conf;
10247         enum rte_pmd_i40e_queue_region_op op_type;
10248 #endif
10249
10250         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10251                 return;
10252
10253 #ifdef RTE_NET_I40E
10254         memset(&region_conf, 0, sizeof(region_conf));
10255
10256         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10257         region_conf.region_id = res->region_id;
10258         region_conf.hw_flowtype = res->flowtype_id;
10259
10260         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10261                         op_type, &region_conf);
10262 #endif
10263
10264         switch (ret) {
10265         case 0:
10266                 break;
10267         case -ENOTSUP:
10268                 fprintf(stderr, "function not implemented or supported\n");
10269                 break;
10270         default:
10271                 fprintf(stderr, "region flowtype config error: (%s)\n",
10272                         strerror(-ret));
10273         }
10274 }
10275
10276 static cmdline_parse_token_string_t cmd_region_flowtype_set =
10277 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10278                                 set, "set");
10279 static cmdline_parse_token_string_t cmd_region_flowtype_port =
10280         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10281                                 port, "port");
10282 static cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10283         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10284                                 port_id, RTE_UINT16);
10285 static cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10286         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10287                                 cmd, "queue-region");
10288 static cmdline_parse_token_string_t cmd_region_flowtype_index =
10289         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10290                                 region, "region_id");
10291 static cmdline_parse_token_num_t cmd_region_flowtype_id =
10292         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10293                                 region_id, RTE_UINT8);
10294 static cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10295         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10296                                 flowtype, "flowtype");
10297 static cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10298         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10299                                 flowtype_id, RTE_UINT8);
10300 static cmdline_parse_inst_t cmd_region_flowtype = {
10301         .f = cmd_region_flowtype_parsed,
10302         .data = NULL,
10303         .help_str = "set port <port_id> queue-region region_id <value> "
10304                 "flowtype <value>: Set a flowtype region index",
10305         .tokens = {
10306                 (void *)&cmd_region_flowtype_set,
10307                 (void *)&cmd_region_flowtype_port,
10308                 (void *)&cmd_region_flowtype_port_index,
10309                 (void *)&cmd_region_flowtype_cmd,
10310                 (void *)&cmd_region_flowtype_index,
10311                 (void *)&cmd_region_flowtype_id,
10312                 (void *)&cmd_region_flowtype_flow_index,
10313                 (void *)&cmd_region_flowtype_flow_id,
10314                 NULL,
10315         },
10316 };
10317
10318 /* *** User Priority (UP) to queue region (region_id) set *** */
10319 struct cmd_user_priority_region_result {
10320         cmdline_fixed_string_t set;
10321         cmdline_fixed_string_t port;
10322         portid_t port_id;
10323         cmdline_fixed_string_t cmd;
10324         cmdline_fixed_string_t user_priority;
10325         uint8_t  user_priority_id;
10326         cmdline_fixed_string_t region;
10327         uint8_t  region_id;
10328 };
10329
10330 static void
10331 cmd_user_priority_region_parsed(void *parsed_result,
10332                         __rte_unused struct cmdline *cl,
10333                         __rte_unused void *data)
10334 {
10335         struct cmd_user_priority_region_result *res = parsed_result;
10336         int ret = -ENOTSUP;
10337 #ifdef RTE_NET_I40E
10338         struct rte_pmd_i40e_queue_region_conf region_conf;
10339         enum rte_pmd_i40e_queue_region_op op_type;
10340 #endif
10341
10342         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10343                 return;
10344
10345 #ifdef RTE_NET_I40E
10346         memset(&region_conf, 0, sizeof(region_conf));
10347         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10348         region_conf.user_priority = res->user_priority_id;
10349         region_conf.region_id = res->region_id;
10350
10351         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10352                                 op_type, &region_conf);
10353 #endif
10354
10355         switch (ret) {
10356         case 0:
10357                 break;
10358         case -ENOTSUP:
10359                 fprintf(stderr, "function not implemented or supported\n");
10360                 break;
10361         default:
10362                 fprintf(stderr, "user_priority region config error: (%s)\n",
10363                         strerror(-ret));
10364         }
10365 }
10366
10367 static cmdline_parse_token_string_t cmd_user_priority_region_set =
10368         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10369                                 set, "set");
10370 static cmdline_parse_token_string_t cmd_user_priority_region_port =
10371         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10372                                 port, "port");
10373 static cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10374         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10375                                 port_id, RTE_UINT16);
10376 static cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10377         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10378                                 cmd, "queue-region");
10379 static cmdline_parse_token_string_t cmd_user_priority_region_UP =
10380         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10381                                 user_priority, "UP");
10382 static cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10383         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10384                                 user_priority_id, RTE_UINT8);
10385 static cmdline_parse_token_string_t cmd_user_priority_region_region =
10386         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10387                                 region, "region_id");
10388 static cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10389         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10390                                 region_id, RTE_UINT8);
10391
10392 static cmdline_parse_inst_t cmd_user_priority_region = {
10393         .f = cmd_user_priority_region_parsed,
10394         .data = NULL,
10395         .help_str = "set port <port_id> queue-region UP <value> "
10396                 "region_id <value>: Set the mapping of User Priority (UP) "
10397                 "to queue region (region_id) ",
10398         .tokens = {
10399                 (void *)&cmd_user_priority_region_set,
10400                 (void *)&cmd_user_priority_region_port,
10401                 (void *)&cmd_user_priority_region_port_index,
10402                 (void *)&cmd_user_priority_region_cmd,
10403                 (void *)&cmd_user_priority_region_UP,
10404                 (void *)&cmd_user_priority_region_UP_id,
10405                 (void *)&cmd_user_priority_region_region,
10406                 (void *)&cmd_user_priority_region_region_id,
10407                 NULL,
10408         },
10409 };
10410
10411 /* *** flush all queue region related configuration *** */
10412 struct cmd_flush_queue_region_result {
10413         cmdline_fixed_string_t set;
10414         cmdline_fixed_string_t port;
10415         portid_t port_id;
10416         cmdline_fixed_string_t cmd;
10417         cmdline_fixed_string_t flush;
10418         cmdline_fixed_string_t what;
10419 };
10420
10421 static void
10422 cmd_flush_queue_region_parsed(void *parsed_result,
10423                         __rte_unused struct cmdline *cl,
10424                         __rte_unused void *data)
10425 {
10426         struct cmd_flush_queue_region_result *res = parsed_result;
10427         int ret = -ENOTSUP;
10428 #ifdef RTE_NET_I40E
10429         struct rte_pmd_i40e_queue_region_conf region_conf;
10430         enum rte_pmd_i40e_queue_region_op op_type;
10431 #endif
10432
10433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10434                 return;
10435
10436 #ifdef RTE_NET_I40E
10437         memset(&region_conf, 0, sizeof(region_conf));
10438
10439         if (strcmp(res->what, "on") == 0)
10440                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10441         else
10442                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10443
10444         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10445                                 op_type, &region_conf);
10446 #endif
10447
10448         switch (ret) {
10449         case 0:
10450                 break;
10451         case -ENOTSUP:
10452                 fprintf(stderr, "function not implemented or supported\n");
10453                 break;
10454         default:
10455                 fprintf(stderr, "queue region config flush error: (%s)\n",
10456                         strerror(-ret));
10457         }
10458 }
10459
10460 static cmdline_parse_token_string_t cmd_flush_queue_region_set =
10461         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10462                                 set, "set");
10463 static cmdline_parse_token_string_t cmd_flush_queue_region_port =
10464         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10465                                 port, "port");
10466 static cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10467         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10468                                 port_id, RTE_UINT16);
10469 static cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10470         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10471                                 cmd, "queue-region");
10472 static cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10473         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10474                                 flush, "flush");
10475 static cmdline_parse_token_string_t cmd_flush_queue_region_what =
10476         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10477                                 what, "on#off");
10478
10479 static cmdline_parse_inst_t cmd_flush_queue_region = {
10480         .f = cmd_flush_queue_region_parsed,
10481         .data = NULL,
10482         .help_str = "set port <port_id> queue-region flush on|off"
10483                 ": flush all queue region related configuration",
10484         .tokens = {
10485                 (void *)&cmd_flush_queue_region_set,
10486                 (void *)&cmd_flush_queue_region_port,
10487                 (void *)&cmd_flush_queue_region_port_index,
10488                 (void *)&cmd_flush_queue_region_cmd,
10489                 (void *)&cmd_flush_queue_region_flush,
10490                 (void *)&cmd_flush_queue_region_what,
10491                 NULL,
10492         },
10493 };
10494
10495 /* *** get all queue region related configuration info *** */
10496 struct cmd_show_queue_region_info {
10497         cmdline_fixed_string_t show;
10498         cmdline_fixed_string_t port;
10499         portid_t port_id;
10500         cmdline_fixed_string_t cmd;
10501 };
10502
10503 static void
10504 cmd_show_queue_region_info_parsed(void *parsed_result,
10505                         __rte_unused struct cmdline *cl,
10506                         __rte_unused void *data)
10507 {
10508         struct cmd_show_queue_region_info *res = parsed_result;
10509         int ret = -ENOTSUP;
10510 #ifdef RTE_NET_I40E
10511         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10512         enum rte_pmd_i40e_queue_region_op op_type;
10513 #endif
10514
10515         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10516                 return;
10517
10518 #ifdef RTE_NET_I40E
10519         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10520
10521         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10522
10523         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10524                                         op_type, &rte_pmd_regions);
10525
10526         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10527 #endif
10528
10529         switch (ret) {
10530         case 0:
10531                 break;
10532         case -ENOTSUP:
10533                 fprintf(stderr, "function not implemented or supported\n");
10534                 break;
10535         default:
10536                 fprintf(stderr, "queue region config info show error: (%s)\n",
10537                         strerror(-ret));
10538         }
10539 }
10540
10541 static cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10542 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10543                                 show, "show");
10544 static cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10545         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10546                                 port, "port");
10547 static cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10548         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10549                                 port_id, RTE_UINT16);
10550 static cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10551         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10552                                 cmd, "queue-region");
10553
10554 static cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10555         .f = cmd_show_queue_region_info_parsed,
10556         .data = NULL,
10557         .help_str = "show port <port_id> queue-region"
10558                 ": show all queue region related configuration info",
10559         .tokens = {
10560                 (void *)&cmd_show_queue_region_info_get,
10561                 (void *)&cmd_show_queue_region_info_port,
10562                 (void *)&cmd_show_queue_region_info_port_index,
10563                 (void *)&cmd_show_queue_region_info_cmd,
10564                 NULL,
10565         },
10566 };
10567
10568 /* *** Filters Control *** */
10569
10570 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10571 do { \
10572         if ((ip_addr).family == AF_INET) \
10573                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10574         else { \
10575                 fprintf(stderr, "invalid parameter.\n"); \
10576                 return; \
10577         } \
10578 } while (0)
10579
10580 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10581 do { \
10582         if ((ip_addr).family == AF_INET6) \
10583                 rte_memcpy(&(ip), \
10584                                  &((ip_addr).addr.ipv6), \
10585                                  sizeof(struct in6_addr)); \
10586         else { \
10587                 fprintf(stderr, "invalid parameter.\n"); \
10588                 return; \
10589         } \
10590 } while (0)
10591
10592 #ifdef RTE_NET_I40E
10593
10594 static uint16_t
10595 str2flowtype(char *string)
10596 {
10597         uint8_t i = 0;
10598         static const struct {
10599                 char str[32];
10600                 uint16_t type;
10601         } flowtype_str[] = {
10602                 {"raw", RTE_ETH_FLOW_RAW},
10603                 {"ipv4", RTE_ETH_FLOW_IPV4},
10604                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10605                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10606                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10607                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10608                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10609                 {"ipv6", RTE_ETH_FLOW_IPV6},
10610                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10611                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10612                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10613                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10614                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10615                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10616                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10617                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10618                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10619                 {"gtpu", RTE_ETH_FLOW_GTPU},
10620         };
10621
10622         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10623                 if (!strcmp(flowtype_str[i].str, string))
10624                         return flowtype_str[i].type;
10625         }
10626
10627         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10628                 return (uint16_t)atoi(string);
10629
10630         return RTE_ETH_FLOW_UNKNOWN;
10631 }
10632
10633 /* *** deal with flow director filter *** */
10634 struct cmd_flow_director_result {
10635         cmdline_fixed_string_t flow_director_filter;
10636         portid_t port_id;
10637         cmdline_fixed_string_t mode;
10638         cmdline_fixed_string_t mode_value;
10639         cmdline_fixed_string_t ops;
10640         cmdline_fixed_string_t flow;
10641         cmdline_fixed_string_t flow_type;
10642         cmdline_fixed_string_t drop;
10643         cmdline_fixed_string_t queue;
10644         uint16_t  queue_id;
10645         cmdline_fixed_string_t fd_id;
10646         uint32_t  fd_id_value;
10647         cmdline_fixed_string_t packet;
10648         char filepath[];
10649 };
10650
10651 static void
10652 cmd_flow_director_filter_parsed(void *parsed_result,
10653                           __rte_unused struct cmdline *cl,
10654                           __rte_unused void *data)
10655 {
10656         struct cmd_flow_director_result *res = parsed_result;
10657         int ret = 0;
10658         struct rte_pmd_i40e_flow_type_mapping
10659                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10660         struct rte_pmd_i40e_pkt_template_conf conf;
10661         uint16_t flow_type = str2flowtype(res->flow_type);
10662         uint16_t i, port = res->port_id;
10663         uint8_t add;
10664
10665         memset(&conf, 0, sizeof(conf));
10666
10667         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10668                 fprintf(stderr, "Invalid flow type specified.\n");
10669                 return;
10670         }
10671         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10672                                                  mapping);
10673         if (ret)
10674                 return;
10675         if (mapping[flow_type].pctype == 0ULL) {
10676                 fprintf(stderr, "Invalid flow type specified.\n");
10677                 return;
10678         }
10679         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10680                 if (mapping[flow_type].pctype & (1ULL << i)) {
10681                         conf.input.pctype = i;
10682                         break;
10683                 }
10684         }
10685
10686         conf.input.packet = open_file(res->filepath,
10687                                 &conf.input.length);
10688         if (!conf.input.packet)
10689                 return;
10690         if (!strcmp(res->drop, "drop"))
10691                 conf.action.behavior =
10692                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10693         else
10694                 conf.action.behavior =
10695                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10696         conf.action.report_status =
10697                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10698         conf.action.rx_queue = res->queue_id;
10699         conf.soft_id = res->fd_id_value;
10700         add  = strcmp(res->ops, "del") ? 1 : 0;
10701         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10702                                                         &conf,
10703                                                         add);
10704         if (ret < 0)
10705                 fprintf(stderr, "flow director config error: (%s)\n",
10706                         strerror(-ret));
10707         close_file(conf.input.packet);
10708 }
10709
10710 static cmdline_parse_token_string_t cmd_flow_director_filter =
10711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10712                                  flow_director_filter, "flow_director_filter");
10713 static cmdline_parse_token_num_t cmd_flow_director_port_id =
10714         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10715                               port_id, RTE_UINT16);
10716 static cmdline_parse_token_string_t cmd_flow_director_ops =
10717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10718                                  ops, "add#del#update");
10719 static cmdline_parse_token_string_t cmd_flow_director_flow =
10720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10721                                  flow, "flow");
10722 static cmdline_parse_token_string_t cmd_flow_director_flow_type =
10723         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10724                 flow_type, NULL);
10725 static cmdline_parse_token_string_t cmd_flow_director_drop =
10726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10727                                  drop, "drop#fwd");
10728 static cmdline_parse_token_string_t cmd_flow_director_queue =
10729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10730                                  queue, "queue");
10731 static cmdline_parse_token_num_t cmd_flow_director_queue_id =
10732         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10733                               queue_id, RTE_UINT16);
10734 static cmdline_parse_token_string_t cmd_flow_director_fd_id =
10735         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10736                                  fd_id, "fd_id");
10737 static cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10738         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10739                               fd_id_value, RTE_UINT32);
10740
10741 static cmdline_parse_token_string_t cmd_flow_director_mode =
10742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10743                                  mode, "mode");
10744 static cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10745         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10746                                  mode_value, "raw");
10747 static cmdline_parse_token_string_t cmd_flow_director_packet =
10748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10749                                  packet, "packet");
10750 static cmdline_parse_token_string_t cmd_flow_director_filepath =
10751         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10752                                  filepath, NULL);
10753
10754 static cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10755         .f = cmd_flow_director_filter_parsed,
10756         .data = NULL,
10757         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10758                 "director entry on NIC",
10759         .tokens = {
10760                 (void *)&cmd_flow_director_filter,
10761                 (void *)&cmd_flow_director_port_id,
10762                 (void *)&cmd_flow_director_mode,
10763                 (void *)&cmd_flow_director_mode_raw,
10764                 (void *)&cmd_flow_director_ops,
10765                 (void *)&cmd_flow_director_flow,
10766                 (void *)&cmd_flow_director_flow_type,
10767                 (void *)&cmd_flow_director_drop,
10768                 (void *)&cmd_flow_director_queue,
10769                 (void *)&cmd_flow_director_queue_id,
10770                 (void *)&cmd_flow_director_fd_id,
10771                 (void *)&cmd_flow_director_fd_id_value,
10772                 (void *)&cmd_flow_director_packet,
10773                 (void *)&cmd_flow_director_filepath,
10774                 NULL,
10775         },
10776 };
10777
10778 #endif /* RTE_NET_I40E */
10779
10780 /* *** deal with flow director mask *** */
10781 struct cmd_flow_director_mask_result {
10782         cmdline_fixed_string_t flow_director_mask;
10783         portid_t port_id;
10784         cmdline_fixed_string_t mode;
10785         cmdline_fixed_string_t mode_value;
10786         cmdline_fixed_string_t vlan;
10787         uint16_t vlan_mask;
10788         cmdline_fixed_string_t src_mask;
10789         cmdline_ipaddr_t ipv4_src;
10790         cmdline_ipaddr_t ipv6_src;
10791         uint16_t port_src;
10792         cmdline_fixed_string_t dst_mask;
10793         cmdline_ipaddr_t ipv4_dst;
10794         cmdline_ipaddr_t ipv6_dst;
10795         uint16_t port_dst;
10796         cmdline_fixed_string_t mac;
10797         uint8_t mac_addr_byte_mask;
10798         cmdline_fixed_string_t tunnel_id;
10799         uint32_t tunnel_id_mask;
10800         cmdline_fixed_string_t tunnel_type;
10801         uint8_t tunnel_type_mask;
10802 };
10803
10804 static void
10805 cmd_flow_director_mask_parsed(void *parsed_result,
10806                           __rte_unused struct cmdline *cl,
10807                           __rte_unused void *data)
10808 {
10809         struct cmd_flow_director_mask_result *res = parsed_result;
10810         struct rte_eth_fdir_masks *mask;
10811         struct rte_port *port;
10812
10813         port = &ports[res->port_id];
10814         /** Check if the port is not started **/
10815         if (port->port_status != RTE_PORT_STOPPED) {
10816                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10817                 return;
10818         }
10819
10820         mask = &port->dev_conf.fdir_conf.mask;
10821
10822         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10823                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10824                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10825                         return;
10826                 }
10827
10828                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10829         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10830                 if (strcmp(res->mode_value, "Tunnel")) {
10831                         fprintf(stderr, "Please set mode to Tunnel.\n");
10832                         return;
10833                 }
10834
10835                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10836                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10837                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10838                 mask->tunnel_type_mask = res->tunnel_type_mask;
10839         } else {
10840                 if (strcmp(res->mode_value, "IP")) {
10841                         fprintf(stderr, "Please set mode to IP.\n");
10842                         return;
10843                 }
10844
10845                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10846                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10847                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10848                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10849                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10850                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10851                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10852         }
10853
10854         cmd_reconfig_device_queue(res->port_id, 1, 1);
10855 }
10856
10857 static cmdline_parse_token_string_t cmd_flow_director_mask =
10858         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10859                                  flow_director_mask, "flow_director_mask");
10860 static cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10861         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10862                               port_id, RTE_UINT16);
10863 static cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10865                                  vlan, "vlan");
10866 static cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10867         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10868                               vlan_mask, RTE_UINT16);
10869 static cmdline_parse_token_string_t cmd_flow_director_mask_src =
10870         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10871                                  src_mask, "src_mask");
10872 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10873         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10874                                  ipv4_src);
10875 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10876         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10877                                  ipv6_src);
10878 static cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10879         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10880                               port_src, RTE_UINT16);
10881 static cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10882         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10883                                  dst_mask, "dst_mask");
10884 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10885         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10886                                  ipv4_dst);
10887 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10888         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10889                                  ipv6_dst);
10890 static cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10891         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10892                               port_dst, RTE_UINT16);
10893
10894 static cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10895         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10896                                  mode, "mode");
10897 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10898         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10899                                  mode_value, "IP");
10900 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10902                                  mode_value, "MAC-VLAN");
10903 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10904         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10905                                  mode_value, "Tunnel");
10906 static cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10907         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10908                                  mac, "mac");
10909 static cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10910         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10911                               mac_addr_byte_mask, RTE_UINT8);
10912 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10913         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10914                                  tunnel_type, "tunnel-type");
10915 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10916         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10917                               tunnel_type_mask, RTE_UINT8);
10918 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10919         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10920                                  tunnel_id, "tunnel-id");
10921 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10922         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10923                               tunnel_id_mask, RTE_UINT32);
10924
10925 static cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10926         .f = cmd_flow_director_mask_parsed,
10927         .data = NULL,
10928         .help_str = "flow_director_mask ... : "
10929                 "Set IP mode flow director's mask on NIC",
10930         .tokens = {
10931                 (void *)&cmd_flow_director_mask,
10932                 (void *)&cmd_flow_director_mask_port_id,
10933                 (void *)&cmd_flow_director_mask_mode,
10934                 (void *)&cmd_flow_director_mask_mode_ip,
10935                 (void *)&cmd_flow_director_mask_vlan,
10936                 (void *)&cmd_flow_director_mask_vlan_value,
10937                 (void *)&cmd_flow_director_mask_src,
10938                 (void *)&cmd_flow_director_mask_ipv4_src,
10939                 (void *)&cmd_flow_director_mask_ipv6_src,
10940                 (void *)&cmd_flow_director_mask_port_src,
10941                 (void *)&cmd_flow_director_mask_dst,
10942                 (void *)&cmd_flow_director_mask_ipv4_dst,
10943                 (void *)&cmd_flow_director_mask_ipv6_dst,
10944                 (void *)&cmd_flow_director_mask_port_dst,
10945                 NULL,
10946         },
10947 };
10948
10949 static cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10950         .f = cmd_flow_director_mask_parsed,
10951         .data = NULL,
10952         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10953                 "flow director's mask on NIC",
10954         .tokens = {
10955                 (void *)&cmd_flow_director_mask,
10956                 (void *)&cmd_flow_director_mask_port_id,
10957                 (void *)&cmd_flow_director_mask_mode,
10958                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10959                 (void *)&cmd_flow_director_mask_vlan,
10960                 (void *)&cmd_flow_director_mask_vlan_value,
10961                 NULL,
10962         },
10963 };
10964
10965 static cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10966         .f = cmd_flow_director_mask_parsed,
10967         .data = NULL,
10968         .help_str = "flow_director_mask ... : Set tunnel mode "
10969                 "flow director's mask on NIC",
10970         .tokens = {
10971                 (void *)&cmd_flow_director_mask,
10972                 (void *)&cmd_flow_director_mask_port_id,
10973                 (void *)&cmd_flow_director_mask_mode,
10974                 (void *)&cmd_flow_director_mask_mode_tunnel,
10975                 (void *)&cmd_flow_director_mask_vlan,
10976                 (void *)&cmd_flow_director_mask_vlan_value,
10977                 (void *)&cmd_flow_director_mask_mac,
10978                 (void *)&cmd_flow_director_mask_mac_value,
10979                 (void *)&cmd_flow_director_mask_tunnel_type,
10980                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10981                 (void *)&cmd_flow_director_mask_tunnel_id,
10982                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10983                 NULL,
10984         },
10985 };
10986
10987 /* *** deal with flow director flexible payload configuration *** */
10988 struct cmd_flow_director_flexpayload_result {
10989         cmdline_fixed_string_t flow_director_flexpayload;
10990         portid_t port_id;
10991         cmdline_fixed_string_t payload_layer;
10992         cmdline_fixed_string_t payload_cfg;
10993 };
10994
10995 static inline int
10996 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10997 {
10998         char s[256];
10999         const char *p, *p0 = q_arg;
11000         char *end;
11001         unsigned long int_fld;
11002         char *str_fld[max_num];
11003         int i;
11004         unsigned size;
11005         int ret = -1;
11006
11007         p = strchr(p0, '(');
11008         if (p == NULL)
11009                 return -1;
11010         ++p;
11011         p0 = strchr(p, ')');
11012         if (p0 == NULL)
11013                 return -1;
11014
11015         size = p0 - p;
11016         if (size >= sizeof(s))
11017                 return -1;
11018
11019         snprintf(s, sizeof(s), "%.*s", size, p);
11020         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11021         if (ret < 0 || ret > max_num)
11022                 return -1;
11023         for (i = 0; i < ret; i++) {
11024                 errno = 0;
11025                 int_fld = strtoul(str_fld[i], &end, 0);
11026                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11027                         return -1;
11028                 offsets[i] = (uint16_t)int_fld;
11029         }
11030         return ret;
11031 }
11032
11033 static void
11034 cmd_flow_director_flxpld_parsed(void *parsed_result,
11035                           __rte_unused struct cmdline *cl,
11036                           __rte_unused void *data)
11037 {
11038         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11039         struct rte_eth_flex_payload_cfg flex_cfg;
11040         struct rte_port *port;
11041         int ret = 0;
11042
11043         port = &ports[res->port_id];
11044         /** Check if the port is not started **/
11045         if (port->port_status != RTE_PORT_STOPPED) {
11046                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
11047                 return;
11048         }
11049
11050         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11051
11052         if (!strcmp(res->payload_layer, "raw"))
11053                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11054         else if (!strcmp(res->payload_layer, "l2"))
11055                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11056         else if (!strcmp(res->payload_layer, "l3"))
11057                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11058         else if (!strcmp(res->payload_layer, "l4"))
11059                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11060
11061         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11062                             RTE_ETH_FDIR_MAX_FLEXLEN);
11063         if (ret < 0) {
11064                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
11065                 return;
11066         }
11067
11068         fdir_set_flex_payload(res->port_id, &flex_cfg);
11069         cmd_reconfig_device_queue(res->port_id, 1, 1);
11070 }
11071
11072 static cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11073         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11074                                  flow_director_flexpayload,
11075                                  "flow_director_flex_payload");
11076 static cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11077         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11078                               port_id, RTE_UINT16);
11079 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11080         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11081                                  payload_layer, "raw#l2#l3#l4");
11082 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11083         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11084                                  payload_cfg, NULL);
11085
11086 static cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11087         .f = cmd_flow_director_flxpld_parsed,
11088         .data = NULL,
11089         .help_str = "flow_director_flexpayload ... : "
11090                 "Set flow director's flex payload on NIC",
11091         .tokens = {
11092                 (void *)&cmd_flow_director_flexpayload,
11093                 (void *)&cmd_flow_director_flexpayload_port_id,
11094                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11095                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11096                 NULL,
11097         },
11098 };
11099
11100 /* Generic flow interface command. */
11101 extern cmdline_parse_inst_t cmd_flow;
11102
11103 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11104 struct cmd_mcast_addr_result {
11105         cmdline_fixed_string_t mcast_addr_cmd;
11106         cmdline_fixed_string_t what;
11107         uint16_t port_num;
11108         struct rte_ether_addr mc_addr;
11109 };
11110
11111 static void cmd_mcast_addr_parsed(void *parsed_result,
11112                 __rte_unused struct cmdline *cl,
11113                 __rte_unused void *data)
11114 {
11115         struct cmd_mcast_addr_result *res = parsed_result;
11116
11117         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11118                 fprintf(stderr,
11119                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11120                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11121                 return;
11122         }
11123         if (strcmp(res->what, "add") == 0)
11124                 mcast_addr_add(res->port_num, &res->mc_addr);
11125         else
11126                 mcast_addr_remove(res->port_num, &res->mc_addr);
11127 }
11128
11129 static cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11130         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11131                                  mcast_addr_cmd, "mcast_addr");
11132 static cmdline_parse_token_string_t cmd_mcast_addr_what =
11133         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11134                                  "add#remove");
11135 static cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11136         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11137                                  RTE_UINT16);
11138 static cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11139         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11140
11141 static cmdline_parse_inst_t cmd_mcast_addr = {
11142         .f = cmd_mcast_addr_parsed,
11143         .data = (void *)0,
11144         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11145                 "Add/Remove multicast MAC address on port_id",
11146         .tokens = {
11147                 (void *)&cmd_mcast_addr_cmd,
11148                 (void *)&cmd_mcast_addr_what,
11149                 (void *)&cmd_mcast_addr_portnum,
11150                 (void *)&cmd_mcast_addr_addr,
11151                 NULL,
11152         },
11153 };
11154
11155 /* vf vlan anti spoof configuration */
11156
11157 /* Common result structure for vf vlan anti spoof */
11158 struct cmd_vf_vlan_anti_spoof_result {
11159         cmdline_fixed_string_t set;
11160         cmdline_fixed_string_t vf;
11161         cmdline_fixed_string_t vlan;
11162         cmdline_fixed_string_t antispoof;
11163         portid_t port_id;
11164         uint32_t vf_id;
11165         cmdline_fixed_string_t on_off;
11166 };
11167
11168 /* Common CLI fields for vf vlan anti spoof enable disable */
11169 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11170         TOKEN_STRING_INITIALIZER
11171                 (struct cmd_vf_vlan_anti_spoof_result,
11172                  set, "set");
11173 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11174         TOKEN_STRING_INITIALIZER
11175                 (struct cmd_vf_vlan_anti_spoof_result,
11176                  vf, "vf");
11177 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11178         TOKEN_STRING_INITIALIZER
11179                 (struct cmd_vf_vlan_anti_spoof_result,
11180                  vlan, "vlan");
11181 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11182         TOKEN_STRING_INITIALIZER
11183                 (struct cmd_vf_vlan_anti_spoof_result,
11184                  antispoof, "antispoof");
11185 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11186         TOKEN_NUM_INITIALIZER
11187                 (struct cmd_vf_vlan_anti_spoof_result,
11188                  port_id, RTE_UINT16);
11189 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11190         TOKEN_NUM_INITIALIZER
11191                 (struct cmd_vf_vlan_anti_spoof_result,
11192                  vf_id, RTE_UINT32);
11193 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11194         TOKEN_STRING_INITIALIZER
11195                 (struct cmd_vf_vlan_anti_spoof_result,
11196                  on_off, "on#off");
11197
11198 static void
11199 cmd_set_vf_vlan_anti_spoof_parsed(
11200         void *parsed_result,
11201         __rte_unused struct cmdline *cl,
11202         __rte_unused void *data)
11203 {
11204         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11205         int ret = -ENOTSUP;
11206
11207         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11208
11209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11210                 return;
11211
11212 #ifdef RTE_NET_IXGBE
11213         if (ret == -ENOTSUP)
11214                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11215                                 res->vf_id, is_on);
11216 #endif
11217 #ifdef RTE_NET_I40E
11218         if (ret == -ENOTSUP)
11219                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11220                                 res->vf_id, is_on);
11221 #endif
11222 #ifdef RTE_NET_BNXT
11223         if (ret == -ENOTSUP)
11224                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11225                                 res->vf_id, is_on);
11226 #endif
11227
11228         switch (ret) {
11229         case 0:
11230                 break;
11231         case -EINVAL:
11232                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11233                 break;
11234         case -ENODEV:
11235                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11236                 break;
11237         case -ENOTSUP:
11238                 fprintf(stderr, "function not implemented\n");
11239                 break;
11240         default:
11241                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11242         }
11243 }
11244
11245 static cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11246         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11247         .data = NULL,
11248         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11249         .tokens = {
11250                 (void *)&cmd_vf_vlan_anti_spoof_set,
11251                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11252                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11253                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11254                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11255                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11256                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11257                 NULL,
11258         },
11259 };
11260
11261 /* vf mac anti spoof configuration */
11262
11263 /* Common result structure for vf mac anti spoof */
11264 struct cmd_vf_mac_anti_spoof_result {
11265         cmdline_fixed_string_t set;
11266         cmdline_fixed_string_t vf;
11267         cmdline_fixed_string_t mac;
11268         cmdline_fixed_string_t antispoof;
11269         portid_t port_id;
11270         uint32_t vf_id;
11271         cmdline_fixed_string_t on_off;
11272 };
11273
11274 /* Common CLI fields for vf mac anti spoof enable disable */
11275 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11276         TOKEN_STRING_INITIALIZER
11277                 (struct cmd_vf_mac_anti_spoof_result,
11278                  set, "set");
11279 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11280         TOKEN_STRING_INITIALIZER
11281                 (struct cmd_vf_mac_anti_spoof_result,
11282                  vf, "vf");
11283 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11284         TOKEN_STRING_INITIALIZER
11285                 (struct cmd_vf_mac_anti_spoof_result,
11286                  mac, "mac");
11287 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11288         TOKEN_STRING_INITIALIZER
11289                 (struct cmd_vf_mac_anti_spoof_result,
11290                  antispoof, "antispoof");
11291 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11292         TOKEN_NUM_INITIALIZER
11293                 (struct cmd_vf_mac_anti_spoof_result,
11294                  port_id, RTE_UINT16);
11295 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11296         TOKEN_NUM_INITIALIZER
11297                 (struct cmd_vf_mac_anti_spoof_result,
11298                  vf_id, RTE_UINT32);
11299 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11300         TOKEN_STRING_INITIALIZER
11301                 (struct cmd_vf_mac_anti_spoof_result,
11302                  on_off, "on#off");
11303
11304 static void
11305 cmd_set_vf_mac_anti_spoof_parsed(
11306         void *parsed_result,
11307         __rte_unused struct cmdline *cl,
11308         __rte_unused void *data)
11309 {
11310         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11311         int ret = -ENOTSUP;
11312
11313         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11314
11315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11316                 return;
11317
11318 #ifdef RTE_NET_IXGBE
11319         if (ret == -ENOTSUP)
11320                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11321                         res->vf_id, is_on);
11322 #endif
11323 #ifdef RTE_NET_I40E
11324         if (ret == -ENOTSUP)
11325                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11326                         res->vf_id, is_on);
11327 #endif
11328 #ifdef RTE_NET_BNXT
11329         if (ret == -ENOTSUP)
11330                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11331                         res->vf_id, is_on);
11332 #endif
11333
11334         switch (ret) {
11335         case 0:
11336                 break;
11337         case -EINVAL:
11338                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11339                         res->vf_id, is_on);
11340                 break;
11341         case -ENODEV:
11342                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11343                 break;
11344         case -ENOTSUP:
11345                 fprintf(stderr, "function not implemented\n");
11346                 break;
11347         default:
11348                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11349         }
11350 }
11351
11352 static cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11353         .f = cmd_set_vf_mac_anti_spoof_parsed,
11354         .data = NULL,
11355         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11356         .tokens = {
11357                 (void *)&cmd_vf_mac_anti_spoof_set,
11358                 (void *)&cmd_vf_mac_anti_spoof_vf,
11359                 (void *)&cmd_vf_mac_anti_spoof_mac,
11360                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11361                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11362                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11363                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11364                 NULL,
11365         },
11366 };
11367
11368 /* vf vlan strip queue configuration */
11369
11370 /* Common result structure for vf mac anti spoof */
11371 struct cmd_vf_vlan_stripq_result {
11372         cmdline_fixed_string_t set;
11373         cmdline_fixed_string_t vf;
11374         cmdline_fixed_string_t vlan;
11375         cmdline_fixed_string_t stripq;
11376         portid_t port_id;
11377         uint16_t vf_id;
11378         cmdline_fixed_string_t on_off;
11379 };
11380
11381 /* Common CLI fields for vf vlan strip enable disable */
11382 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11383         TOKEN_STRING_INITIALIZER
11384                 (struct cmd_vf_vlan_stripq_result,
11385                  set, "set");
11386 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11387         TOKEN_STRING_INITIALIZER
11388                 (struct cmd_vf_vlan_stripq_result,
11389                  vf, "vf");
11390 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11391         TOKEN_STRING_INITIALIZER
11392                 (struct cmd_vf_vlan_stripq_result,
11393                  vlan, "vlan");
11394 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11395         TOKEN_STRING_INITIALIZER
11396                 (struct cmd_vf_vlan_stripq_result,
11397                  stripq, "stripq");
11398 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11399         TOKEN_NUM_INITIALIZER
11400                 (struct cmd_vf_vlan_stripq_result,
11401                  port_id, RTE_UINT16);
11402 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11403         TOKEN_NUM_INITIALIZER
11404                 (struct cmd_vf_vlan_stripq_result,
11405                  vf_id, RTE_UINT16);
11406 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11407         TOKEN_STRING_INITIALIZER
11408                 (struct cmd_vf_vlan_stripq_result,
11409                  on_off, "on#off");
11410
11411 static void
11412 cmd_set_vf_vlan_stripq_parsed(
11413         void *parsed_result,
11414         __rte_unused struct cmdline *cl,
11415         __rte_unused void *data)
11416 {
11417         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11418         int ret = -ENOTSUP;
11419
11420         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11421
11422         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11423                 return;
11424
11425 #ifdef RTE_NET_IXGBE
11426         if (ret == -ENOTSUP)
11427                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11428                         res->vf_id, is_on);
11429 #endif
11430 #ifdef RTE_NET_I40E
11431         if (ret == -ENOTSUP)
11432                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11433                         res->vf_id, is_on);
11434 #endif
11435 #ifdef RTE_NET_BNXT
11436         if (ret == -ENOTSUP)
11437                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11438                         res->vf_id, is_on);
11439 #endif
11440
11441         switch (ret) {
11442         case 0:
11443                 break;
11444         case -EINVAL:
11445                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11446                         res->vf_id, is_on);
11447                 break;
11448         case -ENODEV:
11449                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11450                 break;
11451         case -ENOTSUP:
11452                 fprintf(stderr, "function not implemented\n");
11453                 break;
11454         default:
11455                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11456         }
11457 }
11458
11459 static cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11460         .f = cmd_set_vf_vlan_stripq_parsed,
11461         .data = NULL,
11462         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11463         .tokens = {
11464                 (void *)&cmd_vf_vlan_stripq_set,
11465                 (void *)&cmd_vf_vlan_stripq_vf,
11466                 (void *)&cmd_vf_vlan_stripq_vlan,
11467                 (void *)&cmd_vf_vlan_stripq_stripq,
11468                 (void *)&cmd_vf_vlan_stripq_port_id,
11469                 (void *)&cmd_vf_vlan_stripq_vf_id,
11470                 (void *)&cmd_vf_vlan_stripq_on_off,
11471                 NULL,
11472         },
11473 };
11474
11475 /* vf vlan insert configuration */
11476
11477 /* Common result structure for vf vlan insert */
11478 struct cmd_vf_vlan_insert_result {
11479         cmdline_fixed_string_t set;
11480         cmdline_fixed_string_t vf;
11481         cmdline_fixed_string_t vlan;
11482         cmdline_fixed_string_t insert;
11483         portid_t port_id;
11484         uint16_t vf_id;
11485         uint16_t vlan_id;
11486 };
11487
11488 /* Common CLI fields for vf vlan insert enable disable */
11489 static cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11490         TOKEN_STRING_INITIALIZER
11491                 (struct cmd_vf_vlan_insert_result,
11492                  set, "set");
11493 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11494         TOKEN_STRING_INITIALIZER
11495                 (struct cmd_vf_vlan_insert_result,
11496                  vf, "vf");
11497 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11498         TOKEN_STRING_INITIALIZER
11499                 (struct cmd_vf_vlan_insert_result,
11500                  vlan, "vlan");
11501 static cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11502         TOKEN_STRING_INITIALIZER
11503                 (struct cmd_vf_vlan_insert_result,
11504                  insert, "insert");
11505 static cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11506         TOKEN_NUM_INITIALIZER
11507                 (struct cmd_vf_vlan_insert_result,
11508                  port_id, RTE_UINT16);
11509 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11510         TOKEN_NUM_INITIALIZER
11511                 (struct cmd_vf_vlan_insert_result,
11512                  vf_id, RTE_UINT16);
11513 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11514         TOKEN_NUM_INITIALIZER
11515                 (struct cmd_vf_vlan_insert_result,
11516                  vlan_id, RTE_UINT16);
11517
11518 static void
11519 cmd_set_vf_vlan_insert_parsed(
11520         void *parsed_result,
11521         __rte_unused struct cmdline *cl,
11522         __rte_unused void *data)
11523 {
11524         struct cmd_vf_vlan_insert_result *res = parsed_result;
11525         int ret = -ENOTSUP;
11526
11527         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11528                 return;
11529
11530 #ifdef RTE_NET_IXGBE
11531         if (ret == -ENOTSUP)
11532                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11533                         res->vlan_id);
11534 #endif
11535 #ifdef RTE_NET_I40E
11536         if (ret == -ENOTSUP)
11537                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11538                         res->vlan_id);
11539 #endif
11540 #ifdef RTE_NET_BNXT
11541         if (ret == -ENOTSUP)
11542                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11543                         res->vlan_id);
11544 #endif
11545
11546         switch (ret) {
11547         case 0:
11548                 break;
11549         case -EINVAL:
11550                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11551                         res->vf_id, res->vlan_id);
11552                 break;
11553         case -ENODEV:
11554                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11555                 break;
11556         case -ENOTSUP:
11557                 fprintf(stderr, "function not implemented\n");
11558                 break;
11559         default:
11560                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11561         }
11562 }
11563
11564 static cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11565         .f = cmd_set_vf_vlan_insert_parsed,
11566         .data = NULL,
11567         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11568         .tokens = {
11569                 (void *)&cmd_vf_vlan_insert_set,
11570                 (void *)&cmd_vf_vlan_insert_vf,
11571                 (void *)&cmd_vf_vlan_insert_vlan,
11572                 (void *)&cmd_vf_vlan_insert_insert,
11573                 (void *)&cmd_vf_vlan_insert_port_id,
11574                 (void *)&cmd_vf_vlan_insert_vf_id,
11575                 (void *)&cmd_vf_vlan_insert_vlan_id,
11576                 NULL,
11577         },
11578 };
11579
11580 /* tx loopback configuration */
11581
11582 /* Common result structure for tx loopback */
11583 struct cmd_tx_loopback_result {
11584         cmdline_fixed_string_t set;
11585         cmdline_fixed_string_t tx;
11586         cmdline_fixed_string_t loopback;
11587         portid_t port_id;
11588         cmdline_fixed_string_t on_off;
11589 };
11590
11591 /* Common CLI fields for tx loopback enable disable */
11592 static cmdline_parse_token_string_t cmd_tx_loopback_set =
11593         TOKEN_STRING_INITIALIZER
11594                 (struct cmd_tx_loopback_result,
11595                  set, "set");
11596 static cmdline_parse_token_string_t cmd_tx_loopback_tx =
11597         TOKEN_STRING_INITIALIZER
11598                 (struct cmd_tx_loopback_result,
11599                  tx, "tx");
11600 static cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11601         TOKEN_STRING_INITIALIZER
11602                 (struct cmd_tx_loopback_result,
11603                  loopback, "loopback");
11604 static cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11605         TOKEN_NUM_INITIALIZER
11606                 (struct cmd_tx_loopback_result,
11607                  port_id, RTE_UINT16);
11608 static cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11609         TOKEN_STRING_INITIALIZER
11610                 (struct cmd_tx_loopback_result,
11611                  on_off, "on#off");
11612
11613 static void
11614 cmd_set_tx_loopback_parsed(
11615         void *parsed_result,
11616         __rte_unused struct cmdline *cl,
11617         __rte_unused void *data)
11618 {
11619         struct cmd_tx_loopback_result *res = parsed_result;
11620         int ret = -ENOTSUP;
11621
11622         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11623
11624         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11625                 return;
11626
11627 #ifdef RTE_NET_IXGBE
11628         if (ret == -ENOTSUP)
11629                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11630 #endif
11631 #ifdef RTE_NET_I40E
11632         if (ret == -ENOTSUP)
11633                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11634 #endif
11635 #ifdef RTE_NET_BNXT
11636         if (ret == -ENOTSUP)
11637                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11638 #endif
11639 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11640         if (ret == -ENOTSUP)
11641                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11642 #endif
11643
11644         switch (ret) {
11645         case 0:
11646                 break;
11647         case -EINVAL:
11648                 fprintf(stderr, "invalid is_on %d\n", is_on);
11649                 break;
11650         case -ENODEV:
11651                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11652                 break;
11653         case -ENOTSUP:
11654                 fprintf(stderr, "function not implemented\n");
11655                 break;
11656         default:
11657                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11658         }
11659 }
11660
11661 static cmdline_parse_inst_t cmd_set_tx_loopback = {
11662         .f = cmd_set_tx_loopback_parsed,
11663         .data = NULL,
11664         .help_str = "set tx loopback <port_id> on|off",
11665         .tokens = {
11666                 (void *)&cmd_tx_loopback_set,
11667                 (void *)&cmd_tx_loopback_tx,
11668                 (void *)&cmd_tx_loopback_loopback,
11669                 (void *)&cmd_tx_loopback_port_id,
11670                 (void *)&cmd_tx_loopback_on_off,
11671                 NULL,
11672         },
11673 };
11674
11675 /* all queues drop enable configuration */
11676
11677 /* Common result structure for all queues drop enable */
11678 struct cmd_all_queues_drop_en_result {
11679         cmdline_fixed_string_t set;
11680         cmdline_fixed_string_t all;
11681         cmdline_fixed_string_t queues;
11682         cmdline_fixed_string_t drop;
11683         portid_t port_id;
11684         cmdline_fixed_string_t on_off;
11685 };
11686
11687 /* Common CLI fields for tx loopback enable disable */
11688 static cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11689         TOKEN_STRING_INITIALIZER
11690                 (struct cmd_all_queues_drop_en_result,
11691                  set, "set");
11692 static cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11693         TOKEN_STRING_INITIALIZER
11694                 (struct cmd_all_queues_drop_en_result,
11695                  all, "all");
11696 static cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11697         TOKEN_STRING_INITIALIZER
11698                 (struct cmd_all_queues_drop_en_result,
11699                  queues, "queues");
11700 static cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_all_queues_drop_en_result,
11703                  drop, "drop");
11704 static cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11705         TOKEN_NUM_INITIALIZER
11706                 (struct cmd_all_queues_drop_en_result,
11707                  port_id, RTE_UINT16);
11708 static cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11709         TOKEN_STRING_INITIALIZER
11710                 (struct cmd_all_queues_drop_en_result,
11711                  on_off, "on#off");
11712
11713 static void
11714 cmd_set_all_queues_drop_en_parsed(
11715         void *parsed_result,
11716         __rte_unused struct cmdline *cl,
11717         __rte_unused void *data)
11718 {
11719         struct cmd_all_queues_drop_en_result *res = parsed_result;
11720         int ret = -ENOTSUP;
11721         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11722
11723         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11724                 return;
11725
11726 #ifdef RTE_NET_IXGBE
11727         if (ret == -ENOTSUP)
11728                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11729 #endif
11730 #ifdef RTE_NET_BNXT
11731         if (ret == -ENOTSUP)
11732                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11733 #endif
11734         switch (ret) {
11735         case 0:
11736                 break;
11737         case -EINVAL:
11738                 fprintf(stderr, "invalid is_on %d\n", is_on);
11739                 break;
11740         case -ENODEV:
11741                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11742                 break;
11743         case -ENOTSUP:
11744                 fprintf(stderr, "function not implemented\n");
11745                 break;
11746         default:
11747                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11748         }
11749 }
11750
11751 static cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11752         .f = cmd_set_all_queues_drop_en_parsed,
11753         .data = NULL,
11754         .help_str = "set all queues drop <port_id> on|off",
11755         .tokens = {
11756                 (void *)&cmd_all_queues_drop_en_set,
11757                 (void *)&cmd_all_queues_drop_en_all,
11758                 (void *)&cmd_all_queues_drop_en_queues,
11759                 (void *)&cmd_all_queues_drop_en_drop,
11760                 (void *)&cmd_all_queues_drop_en_port_id,
11761                 (void *)&cmd_all_queues_drop_en_on_off,
11762                 NULL,
11763         },
11764 };
11765
11766 /* vf split drop enable configuration */
11767
11768 /* Common result structure for vf split drop enable */
11769 struct cmd_vf_split_drop_en_result {
11770         cmdline_fixed_string_t set;
11771         cmdline_fixed_string_t vf;
11772         cmdline_fixed_string_t split;
11773         cmdline_fixed_string_t drop;
11774         portid_t port_id;
11775         uint16_t vf_id;
11776         cmdline_fixed_string_t on_off;
11777 };
11778
11779 /* Common CLI fields for vf split drop enable disable */
11780 static cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11781         TOKEN_STRING_INITIALIZER
11782                 (struct cmd_vf_split_drop_en_result,
11783                  set, "set");
11784 static cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11785         TOKEN_STRING_INITIALIZER
11786                 (struct cmd_vf_split_drop_en_result,
11787                  vf, "vf");
11788 static cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11789         TOKEN_STRING_INITIALIZER
11790                 (struct cmd_vf_split_drop_en_result,
11791                  split, "split");
11792 static cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11793         TOKEN_STRING_INITIALIZER
11794                 (struct cmd_vf_split_drop_en_result,
11795                  drop, "drop");
11796 static cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11797         TOKEN_NUM_INITIALIZER
11798                 (struct cmd_vf_split_drop_en_result,
11799                  port_id, RTE_UINT16);
11800 static cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11801         TOKEN_NUM_INITIALIZER
11802                 (struct cmd_vf_split_drop_en_result,
11803                  vf_id, RTE_UINT16);
11804 static cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11805         TOKEN_STRING_INITIALIZER
11806                 (struct cmd_vf_split_drop_en_result,
11807                  on_off, "on#off");
11808
11809 static void
11810 cmd_set_vf_split_drop_en_parsed(
11811         void *parsed_result,
11812         __rte_unused struct cmdline *cl,
11813         __rte_unused void *data)
11814 {
11815         struct cmd_vf_split_drop_en_result *res = parsed_result;
11816         int ret = -ENOTSUP;
11817         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11818
11819         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11820                 return;
11821
11822 #ifdef RTE_NET_IXGBE
11823         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11824                         is_on);
11825 #endif
11826         switch (ret) {
11827         case 0:
11828                 break;
11829         case -EINVAL:
11830                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11831                         res->vf_id, is_on);
11832                 break;
11833         case -ENODEV:
11834                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11835                 break;
11836         case -ENOTSUP:
11837                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11838                 break;
11839         default:
11840                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11841         }
11842 }
11843
11844 static cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11845         .f = cmd_set_vf_split_drop_en_parsed,
11846         .data = NULL,
11847         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11848         .tokens = {
11849                 (void *)&cmd_vf_split_drop_en_set,
11850                 (void *)&cmd_vf_split_drop_en_vf,
11851                 (void *)&cmd_vf_split_drop_en_split,
11852                 (void *)&cmd_vf_split_drop_en_drop,
11853                 (void *)&cmd_vf_split_drop_en_port_id,
11854                 (void *)&cmd_vf_split_drop_en_vf_id,
11855                 (void *)&cmd_vf_split_drop_en_on_off,
11856                 NULL,
11857         },
11858 };
11859
11860 /* vf mac address configuration */
11861
11862 /* Common result structure for vf mac address */
11863 struct cmd_set_vf_mac_addr_result {
11864         cmdline_fixed_string_t set;
11865         cmdline_fixed_string_t vf;
11866         cmdline_fixed_string_t mac;
11867         cmdline_fixed_string_t addr;
11868         portid_t port_id;
11869         uint16_t vf_id;
11870         struct rte_ether_addr mac_addr;
11871
11872 };
11873
11874 /* Common CLI fields for vf split drop enable disable */
11875 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11876         TOKEN_STRING_INITIALIZER
11877                 (struct cmd_set_vf_mac_addr_result,
11878                  set, "set");
11879 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11880         TOKEN_STRING_INITIALIZER
11881                 (struct cmd_set_vf_mac_addr_result,
11882                  vf, "vf");
11883 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11884         TOKEN_STRING_INITIALIZER
11885                 (struct cmd_set_vf_mac_addr_result,
11886                  mac, "mac");
11887 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11888         TOKEN_STRING_INITIALIZER
11889                 (struct cmd_set_vf_mac_addr_result,
11890                  addr, "addr");
11891 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11892         TOKEN_NUM_INITIALIZER
11893                 (struct cmd_set_vf_mac_addr_result,
11894                  port_id, RTE_UINT16);
11895 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11896         TOKEN_NUM_INITIALIZER
11897                 (struct cmd_set_vf_mac_addr_result,
11898                  vf_id, RTE_UINT16);
11899 static cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11900         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11901                  mac_addr);
11902
11903 static void
11904 cmd_set_vf_mac_addr_parsed(
11905         void *parsed_result,
11906         __rte_unused struct cmdline *cl,
11907         __rte_unused void *data)
11908 {
11909         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11910         int ret = -ENOTSUP;
11911
11912         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11913                 return;
11914
11915 #ifdef RTE_NET_IXGBE
11916         if (ret == -ENOTSUP)
11917                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11918                                 &res->mac_addr);
11919 #endif
11920 #ifdef RTE_NET_I40E
11921         if (ret == -ENOTSUP)
11922                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11923                                 &res->mac_addr);
11924 #endif
11925 #ifdef RTE_NET_BNXT
11926         if (ret == -ENOTSUP)
11927                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11928                                 &res->mac_addr);
11929 #endif
11930
11931         switch (ret) {
11932         case 0:
11933                 break;
11934         case -EINVAL:
11935                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11936                 break;
11937         case -ENODEV:
11938                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11939                 break;
11940         case -ENOTSUP:
11941                 fprintf(stderr, "function not implemented\n");
11942                 break;
11943         default:
11944                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11945         }
11946 }
11947
11948 static cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11949         .f = cmd_set_vf_mac_addr_parsed,
11950         .data = NULL,
11951         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11952         .tokens = {
11953                 (void *)&cmd_set_vf_mac_addr_set,
11954                 (void *)&cmd_set_vf_mac_addr_vf,
11955                 (void *)&cmd_set_vf_mac_addr_mac,
11956                 (void *)&cmd_set_vf_mac_addr_addr,
11957                 (void *)&cmd_set_vf_mac_addr_port_id,
11958                 (void *)&cmd_set_vf_mac_addr_vf_id,
11959                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11960                 NULL,
11961         },
11962 };
11963
11964 /* MACsec configuration */
11965
11966 /* Common result structure for MACsec offload enable */
11967 struct cmd_macsec_offload_on_result {
11968         cmdline_fixed_string_t set;
11969         cmdline_fixed_string_t macsec;
11970         cmdline_fixed_string_t offload;
11971         portid_t port_id;
11972         cmdline_fixed_string_t on;
11973         cmdline_fixed_string_t encrypt;
11974         cmdline_fixed_string_t en_on_off;
11975         cmdline_fixed_string_t replay_protect;
11976         cmdline_fixed_string_t rp_on_off;
11977 };
11978
11979 /* Common CLI fields for MACsec offload disable */
11980 static cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11981         TOKEN_STRING_INITIALIZER
11982                 (struct cmd_macsec_offload_on_result,
11983                  set, "set");
11984 static cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11985         TOKEN_STRING_INITIALIZER
11986                 (struct cmd_macsec_offload_on_result,
11987                  macsec, "macsec");
11988 static cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11989         TOKEN_STRING_INITIALIZER
11990                 (struct cmd_macsec_offload_on_result,
11991                  offload, "offload");
11992 static cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11993         TOKEN_NUM_INITIALIZER
11994                 (struct cmd_macsec_offload_on_result,
11995                  port_id, RTE_UINT16);
11996 static cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11997         TOKEN_STRING_INITIALIZER
11998                 (struct cmd_macsec_offload_on_result,
11999                  on, "on");
12000 static cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12001         TOKEN_STRING_INITIALIZER
12002                 (struct cmd_macsec_offload_on_result,
12003                  encrypt, "encrypt");
12004 static cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12005         TOKEN_STRING_INITIALIZER
12006                 (struct cmd_macsec_offload_on_result,
12007                  en_on_off, "on#off");
12008 static cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12009         TOKEN_STRING_INITIALIZER
12010                 (struct cmd_macsec_offload_on_result,
12011                  replay_protect, "replay-protect");
12012 static cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12013         TOKEN_STRING_INITIALIZER
12014                 (struct cmd_macsec_offload_on_result,
12015                  rp_on_off, "on#off");
12016
12017 static void
12018 cmd_set_macsec_offload_on_parsed(
12019         void *parsed_result,
12020         __rte_unused struct cmdline *cl,
12021         __rte_unused void *data)
12022 {
12023         struct cmd_macsec_offload_on_result *res = parsed_result;
12024         int ret = -ENOTSUP;
12025         portid_t port_id = res->port_id;
12026         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12027         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12028         struct rte_eth_dev_info dev_info;
12029
12030         if (port_id_is_invalid(port_id, ENABLED_WARN))
12031                 return;
12032         if (!port_is_stopped(port_id)) {
12033                 fprintf(stderr, "Please stop port %d first\n", port_id);
12034                 return;
12035         }
12036
12037         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12038         if (ret != 0)
12039                 return;
12040
12041         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12042 #ifdef RTE_NET_IXGBE
12043                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12044 #endif
12045         }
12046         RTE_SET_USED(en);
12047         RTE_SET_USED(rp);
12048
12049         switch (ret) {
12050         case 0:
12051                 ports[port_id].dev_conf.txmode.offloads |=
12052                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12053                 cmd_reconfig_device_queue(port_id, 1, 1);
12054                 break;
12055         case -ENODEV:
12056                 fprintf(stderr, "invalid port_id %d\n", port_id);
12057                 break;
12058         case -ENOTSUP:
12059                 fprintf(stderr, "not supported on port %d\n", port_id);
12060                 break;
12061         default:
12062                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12063         }
12064 }
12065
12066 static cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12067         .f = cmd_set_macsec_offload_on_parsed,
12068         .data = NULL,
12069         .help_str = "set macsec offload <port_id> on "
12070                 "encrypt on|off replay-protect on|off",
12071         .tokens = {
12072                 (void *)&cmd_macsec_offload_on_set,
12073                 (void *)&cmd_macsec_offload_on_macsec,
12074                 (void *)&cmd_macsec_offload_on_offload,
12075                 (void *)&cmd_macsec_offload_on_port_id,
12076                 (void *)&cmd_macsec_offload_on_on,
12077                 (void *)&cmd_macsec_offload_on_encrypt,
12078                 (void *)&cmd_macsec_offload_on_en_on_off,
12079                 (void *)&cmd_macsec_offload_on_replay_protect,
12080                 (void *)&cmd_macsec_offload_on_rp_on_off,
12081                 NULL,
12082         },
12083 };
12084
12085 /* Common result structure for MACsec offload disable */
12086 struct cmd_macsec_offload_off_result {
12087         cmdline_fixed_string_t set;
12088         cmdline_fixed_string_t macsec;
12089         cmdline_fixed_string_t offload;
12090         portid_t port_id;
12091         cmdline_fixed_string_t off;
12092 };
12093
12094 /* Common CLI fields for MACsec offload disable */
12095 static cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12096         TOKEN_STRING_INITIALIZER
12097                 (struct cmd_macsec_offload_off_result,
12098                  set, "set");
12099 static cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12100         TOKEN_STRING_INITIALIZER
12101                 (struct cmd_macsec_offload_off_result,
12102                  macsec, "macsec");
12103 static cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12104         TOKEN_STRING_INITIALIZER
12105                 (struct cmd_macsec_offload_off_result,
12106                  offload, "offload");
12107 static cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12108         TOKEN_NUM_INITIALIZER
12109                 (struct cmd_macsec_offload_off_result,
12110                  port_id, RTE_UINT16);
12111 static cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12112         TOKEN_STRING_INITIALIZER
12113                 (struct cmd_macsec_offload_off_result,
12114                  off, "off");
12115
12116 static void
12117 cmd_set_macsec_offload_off_parsed(
12118         void *parsed_result,
12119         __rte_unused struct cmdline *cl,
12120         __rte_unused void *data)
12121 {
12122         struct cmd_macsec_offload_off_result *res = parsed_result;
12123         int ret = -ENOTSUP;
12124         struct rte_eth_dev_info dev_info;
12125         portid_t port_id = res->port_id;
12126
12127         if (port_id_is_invalid(port_id, ENABLED_WARN))
12128                 return;
12129         if (!port_is_stopped(port_id)) {
12130                 fprintf(stderr, "Please stop port %d first\n", port_id);
12131                 return;
12132         }
12133
12134         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12135         if (ret != 0)
12136                 return;
12137
12138         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12139 #ifdef RTE_NET_IXGBE
12140                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12141 #endif
12142         }
12143         switch (ret) {
12144         case 0:
12145                 ports[port_id].dev_conf.txmode.offloads &=
12146                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12147                 cmd_reconfig_device_queue(port_id, 1, 1);
12148                 break;
12149         case -ENODEV:
12150                 fprintf(stderr, "invalid port_id %d\n", port_id);
12151                 break;
12152         case -ENOTSUP:
12153                 fprintf(stderr, "not supported on port %d\n", port_id);
12154                 break;
12155         default:
12156                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12157         }
12158 }
12159
12160 static cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12161         .f = cmd_set_macsec_offload_off_parsed,
12162         .data = NULL,
12163         .help_str = "set macsec offload <port_id> off",
12164         .tokens = {
12165                 (void *)&cmd_macsec_offload_off_set,
12166                 (void *)&cmd_macsec_offload_off_macsec,
12167                 (void *)&cmd_macsec_offload_off_offload,
12168                 (void *)&cmd_macsec_offload_off_port_id,
12169                 (void *)&cmd_macsec_offload_off_off,
12170                 NULL,
12171         },
12172 };
12173
12174 /* Common result structure for MACsec secure connection configure */
12175 struct cmd_macsec_sc_result {
12176         cmdline_fixed_string_t set;
12177         cmdline_fixed_string_t macsec;
12178         cmdline_fixed_string_t sc;
12179         cmdline_fixed_string_t tx_rx;
12180         portid_t port_id;
12181         struct rte_ether_addr mac;
12182         uint16_t pi;
12183 };
12184
12185 /* Common CLI fields for MACsec secure connection configure */
12186 static cmdline_parse_token_string_t cmd_macsec_sc_set =
12187         TOKEN_STRING_INITIALIZER
12188                 (struct cmd_macsec_sc_result,
12189                  set, "set");
12190 static cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12191         TOKEN_STRING_INITIALIZER
12192                 (struct cmd_macsec_sc_result,
12193                  macsec, "macsec");
12194 static cmdline_parse_token_string_t cmd_macsec_sc_sc =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_macsec_sc_result,
12197                  sc, "sc");
12198 static cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12199         TOKEN_STRING_INITIALIZER
12200                 (struct cmd_macsec_sc_result,
12201                  tx_rx, "tx#rx");
12202 static cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12203         TOKEN_NUM_INITIALIZER
12204                 (struct cmd_macsec_sc_result,
12205                  port_id, RTE_UINT16);
12206 static cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12207         TOKEN_ETHERADDR_INITIALIZER
12208                 (struct cmd_macsec_sc_result,
12209                  mac);
12210 static cmdline_parse_token_num_t cmd_macsec_sc_pi =
12211         TOKEN_NUM_INITIALIZER
12212                 (struct cmd_macsec_sc_result,
12213                  pi, RTE_UINT16);
12214
12215 static void
12216 cmd_set_macsec_sc_parsed(
12217         void *parsed_result,
12218         __rte_unused struct cmdline *cl,
12219         __rte_unused void *data)
12220 {
12221         struct cmd_macsec_sc_result *res = parsed_result;
12222         int ret = -ENOTSUP;
12223         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12224
12225 #ifdef RTE_NET_IXGBE
12226         ret = is_tx ?
12227                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12228                                 res->mac.addr_bytes) :
12229                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12230                                 res->mac.addr_bytes, res->pi);
12231 #endif
12232         RTE_SET_USED(is_tx);
12233
12234         switch (ret) {
12235         case 0:
12236                 break;
12237         case -ENODEV:
12238                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12239                 break;
12240         case -ENOTSUP:
12241                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12242                 break;
12243         default:
12244                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12245         }
12246 }
12247
12248 static cmdline_parse_inst_t cmd_set_macsec_sc = {
12249         .f = cmd_set_macsec_sc_parsed,
12250         .data = NULL,
12251         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12252         .tokens = {
12253                 (void *)&cmd_macsec_sc_set,
12254                 (void *)&cmd_macsec_sc_macsec,
12255                 (void *)&cmd_macsec_sc_sc,
12256                 (void *)&cmd_macsec_sc_tx_rx,
12257                 (void *)&cmd_macsec_sc_port_id,
12258                 (void *)&cmd_macsec_sc_mac,
12259                 (void *)&cmd_macsec_sc_pi,
12260                 NULL,
12261         },
12262 };
12263
12264 /* Common result structure for MACsec secure connection configure */
12265 struct cmd_macsec_sa_result {
12266         cmdline_fixed_string_t set;
12267         cmdline_fixed_string_t macsec;
12268         cmdline_fixed_string_t sa;
12269         cmdline_fixed_string_t tx_rx;
12270         portid_t port_id;
12271         uint8_t idx;
12272         uint8_t an;
12273         uint32_t pn;
12274         cmdline_fixed_string_t key;
12275 };
12276
12277 /* Common CLI fields for MACsec secure connection configure */
12278 static cmdline_parse_token_string_t cmd_macsec_sa_set =
12279         TOKEN_STRING_INITIALIZER
12280                 (struct cmd_macsec_sa_result,
12281                  set, "set");
12282 static cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12283         TOKEN_STRING_INITIALIZER
12284                 (struct cmd_macsec_sa_result,
12285                  macsec, "macsec");
12286 static cmdline_parse_token_string_t cmd_macsec_sa_sa =
12287         TOKEN_STRING_INITIALIZER
12288                 (struct cmd_macsec_sa_result,
12289                  sa, "sa");
12290 static cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12291         TOKEN_STRING_INITIALIZER
12292                 (struct cmd_macsec_sa_result,
12293                  tx_rx, "tx#rx");
12294 static cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12295         TOKEN_NUM_INITIALIZER
12296                 (struct cmd_macsec_sa_result,
12297                  port_id, RTE_UINT16);
12298 static cmdline_parse_token_num_t cmd_macsec_sa_idx =
12299         TOKEN_NUM_INITIALIZER
12300                 (struct cmd_macsec_sa_result,
12301                  idx, RTE_UINT8);
12302 static cmdline_parse_token_num_t cmd_macsec_sa_an =
12303         TOKEN_NUM_INITIALIZER
12304                 (struct cmd_macsec_sa_result,
12305                  an, RTE_UINT8);
12306 static cmdline_parse_token_num_t cmd_macsec_sa_pn =
12307         TOKEN_NUM_INITIALIZER
12308                 (struct cmd_macsec_sa_result,
12309                  pn, RTE_UINT32);
12310 static cmdline_parse_token_string_t cmd_macsec_sa_key =
12311         TOKEN_STRING_INITIALIZER
12312                 (struct cmd_macsec_sa_result,
12313                  key, NULL);
12314
12315 static void
12316 cmd_set_macsec_sa_parsed(
12317         void *parsed_result,
12318         __rte_unused struct cmdline *cl,
12319         __rte_unused void *data)
12320 {
12321         struct cmd_macsec_sa_result *res = parsed_result;
12322         int ret = -ENOTSUP;
12323         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12324         uint8_t key[16] = { 0 };
12325         uint8_t xdgt0;
12326         uint8_t xdgt1;
12327         int key_len;
12328         int i;
12329
12330         key_len = strlen(res->key) / 2;
12331         if (key_len > 16)
12332                 key_len = 16;
12333
12334         for (i = 0; i < key_len; i++) {
12335                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12336                 if (xdgt0 == 0xFF)
12337                         return;
12338                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12339                 if (xdgt1 == 0xFF)
12340                         return;
12341                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12342         }
12343
12344 #ifdef RTE_NET_IXGBE
12345         ret = is_tx ?
12346                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12347                         res->idx, res->an, res->pn, key) :
12348                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12349                         res->idx, res->an, res->pn, key);
12350 #endif
12351         RTE_SET_USED(is_tx);
12352         RTE_SET_USED(key);
12353
12354         switch (ret) {
12355         case 0:
12356                 break;
12357         case -EINVAL:
12358                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12359                 break;
12360         case -ENODEV:
12361                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12362                 break;
12363         case -ENOTSUP:
12364                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12365                 break;
12366         default:
12367                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12368         }
12369 }
12370
12371 static cmdline_parse_inst_t cmd_set_macsec_sa = {
12372         .f = cmd_set_macsec_sa_parsed,
12373         .data = NULL,
12374         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12375         .tokens = {
12376                 (void *)&cmd_macsec_sa_set,
12377                 (void *)&cmd_macsec_sa_macsec,
12378                 (void *)&cmd_macsec_sa_sa,
12379                 (void *)&cmd_macsec_sa_tx_rx,
12380                 (void *)&cmd_macsec_sa_port_id,
12381                 (void *)&cmd_macsec_sa_idx,
12382                 (void *)&cmd_macsec_sa_an,
12383                 (void *)&cmd_macsec_sa_pn,
12384                 (void *)&cmd_macsec_sa_key,
12385                 NULL,
12386         },
12387 };
12388
12389 /* VF unicast promiscuous mode configuration */
12390
12391 /* Common result structure for VF unicast promiscuous mode */
12392 struct cmd_vf_promisc_result {
12393         cmdline_fixed_string_t set;
12394         cmdline_fixed_string_t vf;
12395         cmdline_fixed_string_t promisc;
12396         portid_t port_id;
12397         uint32_t vf_id;
12398         cmdline_fixed_string_t on_off;
12399 };
12400
12401 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12402 static cmdline_parse_token_string_t cmd_vf_promisc_set =
12403         TOKEN_STRING_INITIALIZER
12404                 (struct cmd_vf_promisc_result,
12405                  set, "set");
12406 static cmdline_parse_token_string_t cmd_vf_promisc_vf =
12407         TOKEN_STRING_INITIALIZER
12408                 (struct cmd_vf_promisc_result,
12409                  vf, "vf");
12410 static cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12411         TOKEN_STRING_INITIALIZER
12412                 (struct cmd_vf_promisc_result,
12413                  promisc, "promisc");
12414 static cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12415         TOKEN_NUM_INITIALIZER
12416                 (struct cmd_vf_promisc_result,
12417                  port_id, RTE_UINT16);
12418 static cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12419         TOKEN_NUM_INITIALIZER
12420                 (struct cmd_vf_promisc_result,
12421                  vf_id, RTE_UINT32);
12422 static cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12423         TOKEN_STRING_INITIALIZER
12424                 (struct cmd_vf_promisc_result,
12425                  on_off, "on#off");
12426
12427 static void
12428 cmd_set_vf_promisc_parsed(
12429         void *parsed_result,
12430         __rte_unused struct cmdline *cl,
12431         __rte_unused void *data)
12432 {
12433         struct cmd_vf_promisc_result *res = parsed_result;
12434         int ret = -ENOTSUP;
12435
12436         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12437
12438         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12439                 return;
12440
12441 #ifdef RTE_NET_I40E
12442         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12443                                                   res->vf_id, is_on);
12444 #endif
12445
12446         switch (ret) {
12447         case 0:
12448                 break;
12449         case -EINVAL:
12450                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12451                 break;
12452         case -ENODEV:
12453                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12454                 break;
12455         case -ENOTSUP:
12456                 fprintf(stderr, "function not implemented\n");
12457                 break;
12458         default:
12459                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12460         }
12461 }
12462
12463 static cmdline_parse_inst_t cmd_set_vf_promisc = {
12464         .f = cmd_set_vf_promisc_parsed,
12465         .data = NULL,
12466         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12467                 "Set unicast promiscuous mode for a VF from the PF",
12468         .tokens = {
12469                 (void *)&cmd_vf_promisc_set,
12470                 (void *)&cmd_vf_promisc_vf,
12471                 (void *)&cmd_vf_promisc_promisc,
12472                 (void *)&cmd_vf_promisc_port_id,
12473                 (void *)&cmd_vf_promisc_vf_id,
12474                 (void *)&cmd_vf_promisc_on_off,
12475                 NULL,
12476         },
12477 };
12478
12479 /* VF multicast promiscuous mode configuration */
12480
12481 /* Common result structure for VF multicast promiscuous mode */
12482 struct cmd_vf_allmulti_result {
12483         cmdline_fixed_string_t set;
12484         cmdline_fixed_string_t vf;
12485         cmdline_fixed_string_t allmulti;
12486         portid_t port_id;
12487         uint32_t vf_id;
12488         cmdline_fixed_string_t on_off;
12489 };
12490
12491 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12492 static cmdline_parse_token_string_t cmd_vf_allmulti_set =
12493         TOKEN_STRING_INITIALIZER
12494                 (struct cmd_vf_allmulti_result,
12495                  set, "set");
12496 static cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_vf_allmulti_result,
12499                  vf, "vf");
12500 static cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12501         TOKEN_STRING_INITIALIZER
12502                 (struct cmd_vf_allmulti_result,
12503                  allmulti, "allmulti");
12504 static cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12505         TOKEN_NUM_INITIALIZER
12506                 (struct cmd_vf_allmulti_result,
12507                  port_id, RTE_UINT16);
12508 static cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12509         TOKEN_NUM_INITIALIZER
12510                 (struct cmd_vf_allmulti_result,
12511                  vf_id, RTE_UINT32);
12512 static cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12513         TOKEN_STRING_INITIALIZER
12514                 (struct cmd_vf_allmulti_result,
12515                  on_off, "on#off");
12516
12517 static void
12518 cmd_set_vf_allmulti_parsed(
12519         void *parsed_result,
12520         __rte_unused struct cmdline *cl,
12521         __rte_unused void *data)
12522 {
12523         struct cmd_vf_allmulti_result *res = parsed_result;
12524         int ret = -ENOTSUP;
12525
12526         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12527
12528         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12529                 return;
12530
12531 #ifdef RTE_NET_I40E
12532         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12533                                                     res->vf_id, is_on);
12534 #endif
12535
12536         switch (ret) {
12537         case 0:
12538                 break;
12539         case -EINVAL:
12540                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12541                 break;
12542         case -ENODEV:
12543                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12544                 break;
12545         case -ENOTSUP:
12546                 fprintf(stderr, "function not implemented\n");
12547                 break;
12548         default:
12549                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12550         }
12551 }
12552
12553 static cmdline_parse_inst_t cmd_set_vf_allmulti = {
12554         .f = cmd_set_vf_allmulti_parsed,
12555         .data = NULL,
12556         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12557                 "Set multicast promiscuous mode for a VF from the PF",
12558         .tokens = {
12559                 (void *)&cmd_vf_allmulti_set,
12560                 (void *)&cmd_vf_allmulti_vf,
12561                 (void *)&cmd_vf_allmulti_allmulti,
12562                 (void *)&cmd_vf_allmulti_port_id,
12563                 (void *)&cmd_vf_allmulti_vf_id,
12564                 (void *)&cmd_vf_allmulti_on_off,
12565                 NULL,
12566         },
12567 };
12568
12569 /* vf broadcast mode configuration */
12570
12571 /* Common result structure for vf broadcast */
12572 struct cmd_set_vf_broadcast_result {
12573         cmdline_fixed_string_t set;
12574         cmdline_fixed_string_t vf;
12575         cmdline_fixed_string_t broadcast;
12576         portid_t port_id;
12577         uint16_t vf_id;
12578         cmdline_fixed_string_t on_off;
12579 };
12580
12581 /* Common CLI fields for vf broadcast enable disable */
12582 static cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12583         TOKEN_STRING_INITIALIZER
12584                 (struct cmd_set_vf_broadcast_result,
12585                  set, "set");
12586 static cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12587         TOKEN_STRING_INITIALIZER
12588                 (struct cmd_set_vf_broadcast_result,
12589                  vf, "vf");
12590 static cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12591         TOKEN_STRING_INITIALIZER
12592                 (struct cmd_set_vf_broadcast_result,
12593                  broadcast, "broadcast");
12594 static cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12595         TOKEN_NUM_INITIALIZER
12596                 (struct cmd_set_vf_broadcast_result,
12597                  port_id, RTE_UINT16);
12598 static cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12599         TOKEN_NUM_INITIALIZER
12600                 (struct cmd_set_vf_broadcast_result,
12601                  vf_id, RTE_UINT16);
12602 static cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12603         TOKEN_STRING_INITIALIZER
12604                 (struct cmd_set_vf_broadcast_result,
12605                  on_off, "on#off");
12606
12607 static void
12608 cmd_set_vf_broadcast_parsed(
12609         void *parsed_result,
12610         __rte_unused struct cmdline *cl,
12611         __rte_unused void *data)
12612 {
12613         struct cmd_set_vf_broadcast_result *res = parsed_result;
12614         int ret = -ENOTSUP;
12615
12616         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12617
12618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12619                 return;
12620
12621 #ifdef RTE_NET_I40E
12622         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12623                                             res->vf_id, is_on);
12624 #endif
12625
12626         switch (ret) {
12627         case 0:
12628                 break;
12629         case -EINVAL:
12630                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12631                         res->vf_id, is_on);
12632                 break;
12633         case -ENODEV:
12634                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12635                 break;
12636         case -ENOTSUP:
12637                 fprintf(stderr, "function not implemented\n");
12638                 break;
12639         default:
12640                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12641         }
12642 }
12643
12644 static cmdline_parse_inst_t cmd_set_vf_broadcast = {
12645         .f = cmd_set_vf_broadcast_parsed,
12646         .data = NULL,
12647         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12648         .tokens = {
12649                 (void *)&cmd_set_vf_broadcast_set,
12650                 (void *)&cmd_set_vf_broadcast_vf,
12651                 (void *)&cmd_set_vf_broadcast_broadcast,
12652                 (void *)&cmd_set_vf_broadcast_port_id,
12653                 (void *)&cmd_set_vf_broadcast_vf_id,
12654                 (void *)&cmd_set_vf_broadcast_on_off,
12655                 NULL,
12656         },
12657 };
12658
12659 /* vf vlan tag configuration */
12660
12661 /* Common result structure for vf vlan tag */
12662 struct cmd_set_vf_vlan_tag_result {
12663         cmdline_fixed_string_t set;
12664         cmdline_fixed_string_t vf;
12665         cmdline_fixed_string_t vlan;
12666         cmdline_fixed_string_t tag;
12667         portid_t port_id;
12668         uint16_t vf_id;
12669         cmdline_fixed_string_t on_off;
12670 };
12671
12672 /* Common CLI fields for vf vlan tag enable disable */
12673 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12674         TOKEN_STRING_INITIALIZER
12675                 (struct cmd_set_vf_vlan_tag_result,
12676                  set, "set");
12677 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12678         TOKEN_STRING_INITIALIZER
12679                 (struct cmd_set_vf_vlan_tag_result,
12680                  vf, "vf");
12681 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12682         TOKEN_STRING_INITIALIZER
12683                 (struct cmd_set_vf_vlan_tag_result,
12684                  vlan, "vlan");
12685 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_set_vf_vlan_tag_result,
12688                  tag, "tag");
12689 static cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12690         TOKEN_NUM_INITIALIZER
12691                 (struct cmd_set_vf_vlan_tag_result,
12692                  port_id, RTE_UINT16);
12693 static cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12694         TOKEN_NUM_INITIALIZER
12695                 (struct cmd_set_vf_vlan_tag_result,
12696                  vf_id, RTE_UINT16);
12697 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12698         TOKEN_STRING_INITIALIZER
12699                 (struct cmd_set_vf_vlan_tag_result,
12700                  on_off, "on#off");
12701
12702 static void
12703 cmd_set_vf_vlan_tag_parsed(
12704         void *parsed_result,
12705         __rte_unused struct cmdline *cl,
12706         __rte_unused void *data)
12707 {
12708         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12709         int ret = -ENOTSUP;
12710
12711         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12712
12713         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12714                 return;
12715
12716 #ifdef RTE_NET_I40E
12717         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12718                                            res->vf_id, is_on);
12719 #endif
12720
12721         switch (ret) {
12722         case 0:
12723                 break;
12724         case -EINVAL:
12725                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12726                         res->vf_id, is_on);
12727                 break;
12728         case -ENODEV:
12729                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12730                 break;
12731         case -ENOTSUP:
12732                 fprintf(stderr, "function not implemented\n");
12733                 break;
12734         default:
12735                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12736         }
12737 }
12738
12739 static cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12740         .f = cmd_set_vf_vlan_tag_parsed,
12741         .data = NULL,
12742         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12743         .tokens = {
12744                 (void *)&cmd_set_vf_vlan_tag_set,
12745                 (void *)&cmd_set_vf_vlan_tag_vf,
12746                 (void *)&cmd_set_vf_vlan_tag_vlan,
12747                 (void *)&cmd_set_vf_vlan_tag_tag,
12748                 (void *)&cmd_set_vf_vlan_tag_port_id,
12749                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12750                 (void *)&cmd_set_vf_vlan_tag_on_off,
12751                 NULL,
12752         },
12753 };
12754
12755 /* Common definition of VF and TC TX bandwidth configuration */
12756 struct cmd_vf_tc_bw_result {
12757         cmdline_fixed_string_t set;
12758         cmdline_fixed_string_t vf;
12759         cmdline_fixed_string_t tc;
12760         cmdline_fixed_string_t tx;
12761         cmdline_fixed_string_t min_bw;
12762         cmdline_fixed_string_t max_bw;
12763         cmdline_fixed_string_t strict_link_prio;
12764         portid_t port_id;
12765         uint16_t vf_id;
12766         uint8_t tc_no;
12767         uint32_t bw;
12768         cmdline_fixed_string_t bw_list;
12769         uint8_t tc_map;
12770 };
12771
12772 static cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_vf_tc_bw_result,
12775                  set, "set");
12776 static cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12777         TOKEN_STRING_INITIALIZER
12778                 (struct cmd_vf_tc_bw_result,
12779                  vf, "vf");
12780 static cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12781         TOKEN_STRING_INITIALIZER
12782                 (struct cmd_vf_tc_bw_result,
12783                  tc, "tc");
12784 static cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12785         TOKEN_STRING_INITIALIZER
12786                 (struct cmd_vf_tc_bw_result,
12787                  tx, "tx");
12788 static cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_vf_tc_bw_result,
12791                  strict_link_prio, "strict-link-priority");
12792 static cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_vf_tc_bw_result,
12795                  min_bw, "min-bandwidth");
12796 static cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12797         TOKEN_STRING_INITIALIZER
12798                 (struct cmd_vf_tc_bw_result,
12799                  max_bw, "max-bandwidth");
12800 static cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12801         TOKEN_NUM_INITIALIZER
12802                 (struct cmd_vf_tc_bw_result,
12803                  port_id, RTE_UINT16);
12804 static cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12805         TOKEN_NUM_INITIALIZER
12806                 (struct cmd_vf_tc_bw_result,
12807                  vf_id, RTE_UINT16);
12808 static cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12809         TOKEN_NUM_INITIALIZER
12810                 (struct cmd_vf_tc_bw_result,
12811                  tc_no, RTE_UINT8);
12812 static cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12813         TOKEN_NUM_INITIALIZER
12814                 (struct cmd_vf_tc_bw_result,
12815                  bw, RTE_UINT32);
12816 static cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12817         TOKEN_STRING_INITIALIZER
12818                 (struct cmd_vf_tc_bw_result,
12819                  bw_list, NULL);
12820 static cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12821         TOKEN_NUM_INITIALIZER
12822                 (struct cmd_vf_tc_bw_result,
12823                  tc_map, RTE_UINT8);
12824
12825 /* VF max bandwidth setting */
12826 static void
12827 cmd_vf_max_bw_parsed(
12828         void *parsed_result,
12829         __rte_unused struct cmdline *cl,
12830         __rte_unused void *data)
12831 {
12832         struct cmd_vf_tc_bw_result *res = parsed_result;
12833         int ret = -ENOTSUP;
12834
12835         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12836                 return;
12837
12838 #ifdef RTE_NET_I40E
12839         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12840                                          res->vf_id, res->bw);
12841 #endif
12842
12843         switch (ret) {
12844         case 0:
12845                 break;
12846         case -EINVAL:
12847                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12848                         res->vf_id, res->bw);
12849                 break;
12850         case -ENODEV:
12851                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12852                 break;
12853         case -ENOTSUP:
12854                 fprintf(stderr, "function not implemented\n");
12855                 break;
12856         default:
12857                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12858         }
12859 }
12860
12861 static cmdline_parse_inst_t cmd_vf_max_bw = {
12862         .f = cmd_vf_max_bw_parsed,
12863         .data = NULL,
12864         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12865         .tokens = {
12866                 (void *)&cmd_vf_tc_bw_set,
12867                 (void *)&cmd_vf_tc_bw_vf,
12868                 (void *)&cmd_vf_tc_bw_tx,
12869                 (void *)&cmd_vf_tc_bw_max_bw,
12870                 (void *)&cmd_vf_tc_bw_port_id,
12871                 (void *)&cmd_vf_tc_bw_vf_id,
12872                 (void *)&cmd_vf_tc_bw_bw,
12873                 NULL,
12874         },
12875 };
12876
12877 static int
12878 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12879                            uint8_t *tc_num,
12880                            char *str)
12881 {
12882         uint32_t size;
12883         const char *p, *p0 = str;
12884         char s[256];
12885         char *end;
12886         char *str_fld[16];
12887         uint16_t i;
12888         int ret;
12889
12890         p = strchr(p0, '(');
12891         if (p == NULL) {
12892                 fprintf(stderr,
12893                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12894                 return -1;
12895         }
12896         p++;
12897         p0 = strchr(p, ')');
12898         if (p0 == NULL) {
12899                 fprintf(stderr,
12900                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12901                 return -1;
12902         }
12903         size = p0 - p;
12904         if (size >= sizeof(s)) {
12905                 fprintf(stderr,
12906                         "The string size exceeds the internal buffer size\n");
12907                 return -1;
12908         }
12909         snprintf(s, sizeof(s), "%.*s", size, p);
12910         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12911         if (ret <= 0) {
12912                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12913                 return -1;
12914         }
12915         *tc_num = ret;
12916         for (i = 0; i < ret; i++)
12917                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12918
12919         return 0;
12920 }
12921
12922 /* TC min bandwidth setting */
12923 static void
12924 cmd_vf_tc_min_bw_parsed(
12925         void *parsed_result,
12926         __rte_unused struct cmdline *cl,
12927         __rte_unused void *data)
12928 {
12929         struct cmd_vf_tc_bw_result *res = parsed_result;
12930         uint8_t tc_num;
12931         uint8_t bw[16];
12932         int ret = -ENOTSUP;
12933
12934         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12935                 return;
12936
12937         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12938         if (ret)
12939                 return;
12940
12941 #ifdef RTE_NET_I40E
12942         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12943                                               tc_num, bw);
12944 #endif
12945
12946         switch (ret) {
12947         case 0:
12948                 break;
12949         case -EINVAL:
12950                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12951                 break;
12952         case -ENODEV:
12953                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12954                 break;
12955         case -ENOTSUP:
12956                 fprintf(stderr, "function not implemented\n");
12957                 break;
12958         default:
12959                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12960         }
12961 }
12962
12963 static cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12964         .f = cmd_vf_tc_min_bw_parsed,
12965         .data = NULL,
12966         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12967                     " <bw1, bw2, ...>",
12968         .tokens = {
12969                 (void *)&cmd_vf_tc_bw_set,
12970                 (void *)&cmd_vf_tc_bw_vf,
12971                 (void *)&cmd_vf_tc_bw_tc,
12972                 (void *)&cmd_vf_tc_bw_tx,
12973                 (void *)&cmd_vf_tc_bw_min_bw,
12974                 (void *)&cmd_vf_tc_bw_port_id,
12975                 (void *)&cmd_vf_tc_bw_vf_id,
12976                 (void *)&cmd_vf_tc_bw_bw_list,
12977                 NULL,
12978         },
12979 };
12980
12981 static void
12982 cmd_tc_min_bw_parsed(
12983         void *parsed_result,
12984         __rte_unused struct cmdline *cl,
12985         __rte_unused void *data)
12986 {
12987         struct cmd_vf_tc_bw_result *res = parsed_result;
12988         struct rte_port *port;
12989         uint8_t tc_num;
12990         uint8_t bw[16];
12991         int ret = -ENOTSUP;
12992
12993         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12994                 return;
12995
12996         port = &ports[res->port_id];
12997         /** Check if the port is not started **/
12998         if (port->port_status != RTE_PORT_STOPPED) {
12999                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
13000                 return;
13001         }
13002
13003         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13004         if (ret)
13005                 return;
13006
13007 #ifdef RTE_NET_IXGBE
13008         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13009 #endif
13010
13011         switch (ret) {
13012         case 0:
13013                 break;
13014         case -EINVAL:
13015                 fprintf(stderr, "invalid bandwidth\n");
13016                 break;
13017         case -ENODEV:
13018                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13019                 break;
13020         case -ENOTSUP:
13021                 fprintf(stderr, "function not implemented\n");
13022                 break;
13023         default:
13024                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13025         }
13026 }
13027
13028 static cmdline_parse_inst_t cmd_tc_min_bw = {
13029         .f = cmd_tc_min_bw_parsed,
13030         .data = NULL,
13031         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13032         .tokens = {
13033                 (void *)&cmd_vf_tc_bw_set,
13034                 (void *)&cmd_vf_tc_bw_tc,
13035                 (void *)&cmd_vf_tc_bw_tx,
13036                 (void *)&cmd_vf_tc_bw_min_bw,
13037                 (void *)&cmd_vf_tc_bw_port_id,
13038                 (void *)&cmd_vf_tc_bw_bw_list,
13039                 NULL,
13040         },
13041 };
13042
13043 /* TC max bandwidth setting */
13044 static void
13045 cmd_vf_tc_max_bw_parsed(
13046         void *parsed_result,
13047         __rte_unused struct cmdline *cl,
13048         __rte_unused void *data)
13049 {
13050         struct cmd_vf_tc_bw_result *res = parsed_result;
13051         int ret = -ENOTSUP;
13052
13053         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13054                 return;
13055
13056 #ifdef RTE_NET_I40E
13057         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13058                                             res->tc_no, res->bw);
13059 #endif
13060
13061         switch (ret) {
13062         case 0:
13063                 break;
13064         case -EINVAL:
13065                 fprintf(stderr,
13066                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
13067                         res->vf_id, res->tc_no, res->bw);
13068                 break;
13069         case -ENODEV:
13070                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13071                 break;
13072         case -ENOTSUP:
13073                 fprintf(stderr, "function not implemented\n");
13074                 break;
13075         default:
13076                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13077         }
13078 }
13079
13080 static cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13081         .f = cmd_vf_tc_max_bw_parsed,
13082         .data = NULL,
13083         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13084                     " <bandwidth>",
13085         .tokens = {
13086                 (void *)&cmd_vf_tc_bw_set,
13087                 (void *)&cmd_vf_tc_bw_vf,
13088                 (void *)&cmd_vf_tc_bw_tc,
13089                 (void *)&cmd_vf_tc_bw_tx,
13090                 (void *)&cmd_vf_tc_bw_max_bw,
13091                 (void *)&cmd_vf_tc_bw_port_id,
13092                 (void *)&cmd_vf_tc_bw_vf_id,
13093                 (void *)&cmd_vf_tc_bw_tc_no,
13094                 (void *)&cmd_vf_tc_bw_bw,
13095                 NULL,
13096         },
13097 };
13098
13099 /** Set VXLAN encapsulation details */
13100 struct cmd_set_vxlan_result {
13101         cmdline_fixed_string_t set;
13102         cmdline_fixed_string_t vxlan;
13103         cmdline_fixed_string_t pos_token;
13104         cmdline_fixed_string_t ip_version;
13105         uint32_t vlan_present:1;
13106         uint32_t vni;
13107         uint16_t udp_src;
13108         uint16_t udp_dst;
13109         cmdline_ipaddr_t ip_src;
13110         cmdline_ipaddr_t ip_dst;
13111         uint16_t tci;
13112         uint8_t tos;
13113         uint8_t ttl;
13114         struct rte_ether_addr eth_src;
13115         struct rte_ether_addr eth_dst;
13116 };
13117
13118 static cmdline_parse_token_string_t cmd_set_vxlan_set =
13119         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13120 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13121         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13122 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13123         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13124                                  "vxlan-tos-ttl");
13125 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13126         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13127                                  "vxlan-with-vlan");
13128 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13129         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13130                                  "ip-version");
13131 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13132         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13133                                  "ipv4#ipv6");
13134 static cmdline_parse_token_string_t cmd_set_vxlan_vni =
13135         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13136                                  "vni");
13137 static cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13138         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13139 static cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13140         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13141                                  "udp-src");
13142 static cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13143         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13144 static cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13145         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13146                                  "udp-dst");
13147 static cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13148         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13149 static cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13150         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13151                                  "ip-tos");
13152 static cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13153         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13154 static cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13155         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13156                                  "ip-ttl");
13157 static cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13158         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13159 static cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13160         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13161                                  "ip-src");
13162 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13163         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13164 static cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13165         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13166                                  "ip-dst");
13167 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13168         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13169 static cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13170         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13171                                  "vlan-tci");
13172 static cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13173         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13174 static cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13175         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13176                                  "eth-src");
13177 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13178         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13179 static cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13180         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13181                                  "eth-dst");
13182 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13183         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13184
13185 static void cmd_set_vxlan_parsed(void *parsed_result,
13186         __rte_unused struct cmdline *cl,
13187         __rte_unused void *data)
13188 {
13189         struct cmd_set_vxlan_result *res = parsed_result;
13190         union {
13191                 uint32_t vxlan_id;
13192                 uint8_t vni[4];
13193         } id = {
13194                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13195         };
13196
13197         vxlan_encap_conf.select_tos_ttl = 0;
13198         if (strcmp(res->vxlan, "vxlan") == 0)
13199                 vxlan_encap_conf.select_vlan = 0;
13200         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13201                 vxlan_encap_conf.select_vlan = 1;
13202         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13203                 vxlan_encap_conf.select_vlan = 0;
13204                 vxlan_encap_conf.select_tos_ttl = 1;
13205         }
13206         if (strcmp(res->ip_version, "ipv4") == 0)
13207                 vxlan_encap_conf.select_ipv4 = 1;
13208         else if (strcmp(res->ip_version, "ipv6") == 0)
13209                 vxlan_encap_conf.select_ipv4 = 0;
13210         else
13211                 return;
13212         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13213         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13214         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13215         vxlan_encap_conf.ip_tos = res->tos;
13216         vxlan_encap_conf.ip_ttl = res->ttl;
13217         if (vxlan_encap_conf.select_ipv4) {
13218                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13219                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13220         } else {
13221                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13222                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13223         }
13224         if (vxlan_encap_conf.select_vlan)
13225                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13226         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13227                    RTE_ETHER_ADDR_LEN);
13228         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13229                    RTE_ETHER_ADDR_LEN);
13230 }
13231
13232 static cmdline_parse_inst_t cmd_set_vxlan = {
13233         .f = cmd_set_vxlan_parsed,
13234         .data = NULL,
13235         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13236                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13237                 " eth-src <eth-src> eth-dst <eth-dst>",
13238         .tokens = {
13239                 (void *)&cmd_set_vxlan_set,
13240                 (void *)&cmd_set_vxlan_vxlan,
13241                 (void *)&cmd_set_vxlan_ip_version,
13242                 (void *)&cmd_set_vxlan_ip_version_value,
13243                 (void *)&cmd_set_vxlan_vni,
13244                 (void *)&cmd_set_vxlan_vni_value,
13245                 (void *)&cmd_set_vxlan_udp_src,
13246                 (void *)&cmd_set_vxlan_udp_src_value,
13247                 (void *)&cmd_set_vxlan_udp_dst,
13248                 (void *)&cmd_set_vxlan_udp_dst_value,
13249                 (void *)&cmd_set_vxlan_ip_src,
13250                 (void *)&cmd_set_vxlan_ip_src_value,
13251                 (void *)&cmd_set_vxlan_ip_dst,
13252                 (void *)&cmd_set_vxlan_ip_dst_value,
13253                 (void *)&cmd_set_vxlan_eth_src,
13254                 (void *)&cmd_set_vxlan_eth_src_value,
13255                 (void *)&cmd_set_vxlan_eth_dst,
13256                 (void *)&cmd_set_vxlan_eth_dst_value,
13257                 NULL,
13258         },
13259 };
13260
13261 static cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13262         .f = cmd_set_vxlan_parsed,
13263         .data = NULL,
13264         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13265                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13266                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13267                 " eth-dst <eth-dst>",
13268         .tokens = {
13269                 (void *)&cmd_set_vxlan_set,
13270                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13271                 (void *)&cmd_set_vxlan_ip_version,
13272                 (void *)&cmd_set_vxlan_ip_version_value,
13273                 (void *)&cmd_set_vxlan_vni,
13274                 (void *)&cmd_set_vxlan_vni_value,
13275                 (void *)&cmd_set_vxlan_udp_src,
13276                 (void *)&cmd_set_vxlan_udp_src_value,
13277                 (void *)&cmd_set_vxlan_udp_dst,
13278                 (void *)&cmd_set_vxlan_udp_dst_value,
13279                 (void *)&cmd_set_vxlan_ip_tos,
13280                 (void *)&cmd_set_vxlan_ip_tos_value,
13281                 (void *)&cmd_set_vxlan_ip_ttl,
13282                 (void *)&cmd_set_vxlan_ip_ttl_value,
13283                 (void *)&cmd_set_vxlan_ip_src,
13284                 (void *)&cmd_set_vxlan_ip_src_value,
13285                 (void *)&cmd_set_vxlan_ip_dst,
13286                 (void *)&cmd_set_vxlan_ip_dst_value,
13287                 (void *)&cmd_set_vxlan_eth_src,
13288                 (void *)&cmd_set_vxlan_eth_src_value,
13289                 (void *)&cmd_set_vxlan_eth_dst,
13290                 (void *)&cmd_set_vxlan_eth_dst_value,
13291                 NULL,
13292         },
13293 };
13294
13295 static cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13296         .f = cmd_set_vxlan_parsed,
13297         .data = NULL,
13298         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13299                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13300                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13301                 " <eth-dst>",
13302         .tokens = {
13303                 (void *)&cmd_set_vxlan_set,
13304                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13305                 (void *)&cmd_set_vxlan_ip_version,
13306                 (void *)&cmd_set_vxlan_ip_version_value,
13307                 (void *)&cmd_set_vxlan_vni,
13308                 (void *)&cmd_set_vxlan_vni_value,
13309                 (void *)&cmd_set_vxlan_udp_src,
13310                 (void *)&cmd_set_vxlan_udp_src_value,
13311                 (void *)&cmd_set_vxlan_udp_dst,
13312                 (void *)&cmd_set_vxlan_udp_dst_value,
13313                 (void *)&cmd_set_vxlan_ip_src,
13314                 (void *)&cmd_set_vxlan_ip_src_value,
13315                 (void *)&cmd_set_vxlan_ip_dst,
13316                 (void *)&cmd_set_vxlan_ip_dst_value,
13317                 (void *)&cmd_set_vxlan_vlan,
13318                 (void *)&cmd_set_vxlan_vlan_value,
13319                 (void *)&cmd_set_vxlan_eth_src,
13320                 (void *)&cmd_set_vxlan_eth_src_value,
13321                 (void *)&cmd_set_vxlan_eth_dst,
13322                 (void *)&cmd_set_vxlan_eth_dst_value,
13323                 NULL,
13324         },
13325 };
13326
13327 /** Set NVGRE encapsulation details */
13328 struct cmd_set_nvgre_result {
13329         cmdline_fixed_string_t set;
13330         cmdline_fixed_string_t nvgre;
13331         cmdline_fixed_string_t pos_token;
13332         cmdline_fixed_string_t ip_version;
13333         uint32_t tni;
13334         cmdline_ipaddr_t ip_src;
13335         cmdline_ipaddr_t ip_dst;
13336         uint16_t tci;
13337         struct rte_ether_addr eth_src;
13338         struct rte_ether_addr eth_dst;
13339 };
13340
13341 static cmdline_parse_token_string_t cmd_set_nvgre_set =
13342         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13343 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13344         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13345 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13346         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13347                                  "nvgre-with-vlan");
13348 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13349         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13350                                  "ip-version");
13351 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13352         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13353                                  "ipv4#ipv6");
13354 static cmdline_parse_token_string_t cmd_set_nvgre_tni =
13355         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13356                                  "tni");
13357 static cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13358         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13359 static cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13360         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13361                                  "ip-src");
13362 static cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13363         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13364 static cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13365         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13366                                  "ip-dst");
13367 static cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13368         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13369 static cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13370         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13371                                  "vlan-tci");
13372 static cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13373         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13374 static cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13375         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13376                                  "eth-src");
13377 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13378         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13379 static cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13380         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13381                                  "eth-dst");
13382 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13383         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13384
13385 static void cmd_set_nvgre_parsed(void *parsed_result,
13386         __rte_unused struct cmdline *cl,
13387         __rte_unused void *data)
13388 {
13389         struct cmd_set_nvgre_result *res = parsed_result;
13390         union {
13391                 uint32_t nvgre_tni;
13392                 uint8_t tni[4];
13393         } id = {
13394                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13395         };
13396
13397         if (strcmp(res->nvgre, "nvgre") == 0)
13398                 nvgre_encap_conf.select_vlan = 0;
13399         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13400                 nvgre_encap_conf.select_vlan = 1;
13401         if (strcmp(res->ip_version, "ipv4") == 0)
13402                 nvgre_encap_conf.select_ipv4 = 1;
13403         else if (strcmp(res->ip_version, "ipv6") == 0)
13404                 nvgre_encap_conf.select_ipv4 = 0;
13405         else
13406                 return;
13407         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13408         if (nvgre_encap_conf.select_ipv4) {
13409                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13410                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13411         } else {
13412                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13413                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13414         }
13415         if (nvgre_encap_conf.select_vlan)
13416                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13417         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13418                    RTE_ETHER_ADDR_LEN);
13419         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13420                    RTE_ETHER_ADDR_LEN);
13421 }
13422
13423 static cmdline_parse_inst_t cmd_set_nvgre = {
13424         .f = cmd_set_nvgre_parsed,
13425         .data = NULL,
13426         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13427                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13428                 " eth-dst <eth-dst>",
13429         .tokens = {
13430                 (void *)&cmd_set_nvgre_set,
13431                 (void *)&cmd_set_nvgre_nvgre,
13432                 (void *)&cmd_set_nvgre_ip_version,
13433                 (void *)&cmd_set_nvgre_ip_version_value,
13434                 (void *)&cmd_set_nvgre_tni,
13435                 (void *)&cmd_set_nvgre_tni_value,
13436                 (void *)&cmd_set_nvgre_ip_src,
13437                 (void *)&cmd_set_nvgre_ip_src_value,
13438                 (void *)&cmd_set_nvgre_ip_dst,
13439                 (void *)&cmd_set_nvgre_ip_dst_value,
13440                 (void *)&cmd_set_nvgre_eth_src,
13441                 (void *)&cmd_set_nvgre_eth_src_value,
13442                 (void *)&cmd_set_nvgre_eth_dst,
13443                 (void *)&cmd_set_nvgre_eth_dst_value,
13444                 NULL,
13445         },
13446 };
13447
13448 static cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13449         .f = cmd_set_nvgre_parsed,
13450         .data = NULL,
13451         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13452                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13453                 " eth-src <eth-src> eth-dst <eth-dst>",
13454         .tokens = {
13455                 (void *)&cmd_set_nvgre_set,
13456                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13457                 (void *)&cmd_set_nvgre_ip_version,
13458                 (void *)&cmd_set_nvgre_ip_version_value,
13459                 (void *)&cmd_set_nvgre_tni,
13460                 (void *)&cmd_set_nvgre_tni_value,
13461                 (void *)&cmd_set_nvgre_ip_src,
13462                 (void *)&cmd_set_nvgre_ip_src_value,
13463                 (void *)&cmd_set_nvgre_ip_dst,
13464                 (void *)&cmd_set_nvgre_ip_dst_value,
13465                 (void *)&cmd_set_nvgre_vlan,
13466                 (void *)&cmd_set_nvgre_vlan_value,
13467                 (void *)&cmd_set_nvgre_eth_src,
13468                 (void *)&cmd_set_nvgre_eth_src_value,
13469                 (void *)&cmd_set_nvgre_eth_dst,
13470                 (void *)&cmd_set_nvgre_eth_dst_value,
13471                 NULL,
13472         },
13473 };
13474
13475 /** Set L2 encapsulation details */
13476 struct cmd_set_l2_encap_result {
13477         cmdline_fixed_string_t set;
13478         cmdline_fixed_string_t l2_encap;
13479         cmdline_fixed_string_t pos_token;
13480         cmdline_fixed_string_t ip_version;
13481         uint32_t vlan_present:1;
13482         uint16_t tci;
13483         struct rte_ether_addr eth_src;
13484         struct rte_ether_addr eth_dst;
13485 };
13486
13487 static cmdline_parse_token_string_t cmd_set_l2_encap_set =
13488         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13489 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13490         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13491 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13492         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13493                                  "l2_encap-with-vlan");
13494 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13495         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13496                                  "ip-version");
13497 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13498         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13499                                  "ipv4#ipv6");
13500 static cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13501         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13502                                  "vlan-tci");
13503 static cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13504         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13505 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13506         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13507                                  "eth-src");
13508 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13509         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13510 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13511         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13512                                  "eth-dst");
13513 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13514         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13515
13516 static void cmd_set_l2_encap_parsed(void *parsed_result,
13517         __rte_unused struct cmdline *cl,
13518         __rte_unused void *data)
13519 {
13520         struct cmd_set_l2_encap_result *res = parsed_result;
13521
13522         if (strcmp(res->l2_encap, "l2_encap") == 0)
13523                 l2_encap_conf.select_vlan = 0;
13524         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13525                 l2_encap_conf.select_vlan = 1;
13526         if (strcmp(res->ip_version, "ipv4") == 0)
13527                 l2_encap_conf.select_ipv4 = 1;
13528         else if (strcmp(res->ip_version, "ipv6") == 0)
13529                 l2_encap_conf.select_ipv4 = 0;
13530         else
13531                 return;
13532         if (l2_encap_conf.select_vlan)
13533                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13534         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13535                    RTE_ETHER_ADDR_LEN);
13536         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13537                    RTE_ETHER_ADDR_LEN);
13538 }
13539
13540 static cmdline_parse_inst_t cmd_set_l2_encap = {
13541         .f = cmd_set_l2_encap_parsed,
13542         .data = NULL,
13543         .help_str = "set l2_encap ip-version ipv4|ipv6"
13544                 " eth-src <eth-src> eth-dst <eth-dst>",
13545         .tokens = {
13546                 (void *)&cmd_set_l2_encap_set,
13547                 (void *)&cmd_set_l2_encap_l2_encap,
13548                 (void *)&cmd_set_l2_encap_ip_version,
13549                 (void *)&cmd_set_l2_encap_ip_version_value,
13550                 (void *)&cmd_set_l2_encap_eth_src,
13551                 (void *)&cmd_set_l2_encap_eth_src_value,
13552                 (void *)&cmd_set_l2_encap_eth_dst,
13553                 (void *)&cmd_set_l2_encap_eth_dst_value,
13554                 NULL,
13555         },
13556 };
13557
13558 static cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13559         .f = cmd_set_l2_encap_parsed,
13560         .data = NULL,
13561         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13562                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13563         .tokens = {
13564                 (void *)&cmd_set_l2_encap_set,
13565                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13566                 (void *)&cmd_set_l2_encap_ip_version,
13567                 (void *)&cmd_set_l2_encap_ip_version_value,
13568                 (void *)&cmd_set_l2_encap_vlan,
13569                 (void *)&cmd_set_l2_encap_vlan_value,
13570                 (void *)&cmd_set_l2_encap_eth_src,
13571                 (void *)&cmd_set_l2_encap_eth_src_value,
13572                 (void *)&cmd_set_l2_encap_eth_dst,
13573                 (void *)&cmd_set_l2_encap_eth_dst_value,
13574                 NULL,
13575         },
13576 };
13577
13578 /** Set L2 decapsulation details */
13579 struct cmd_set_l2_decap_result {
13580         cmdline_fixed_string_t set;
13581         cmdline_fixed_string_t l2_decap;
13582         cmdline_fixed_string_t pos_token;
13583         uint32_t vlan_present:1;
13584 };
13585
13586 static cmdline_parse_token_string_t cmd_set_l2_decap_set =
13587         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13588 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13589         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13590                                  "l2_decap");
13591 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13592         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13593                                  "l2_decap-with-vlan");
13594
13595 static void cmd_set_l2_decap_parsed(void *parsed_result,
13596         __rte_unused struct cmdline *cl,
13597         __rte_unused void *data)
13598 {
13599         struct cmd_set_l2_decap_result *res = parsed_result;
13600
13601         if (strcmp(res->l2_decap, "l2_decap") == 0)
13602                 l2_decap_conf.select_vlan = 0;
13603         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13604                 l2_decap_conf.select_vlan = 1;
13605 }
13606
13607 static cmdline_parse_inst_t cmd_set_l2_decap = {
13608         .f = cmd_set_l2_decap_parsed,
13609         .data = NULL,
13610         .help_str = "set l2_decap",
13611         .tokens = {
13612                 (void *)&cmd_set_l2_decap_set,
13613                 (void *)&cmd_set_l2_decap_l2_decap,
13614                 NULL,
13615         },
13616 };
13617
13618 static cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13619         .f = cmd_set_l2_decap_parsed,
13620         .data = NULL,
13621         .help_str = "set l2_decap-with-vlan",
13622         .tokens = {
13623                 (void *)&cmd_set_l2_decap_set,
13624                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13625                 NULL,
13626         },
13627 };
13628
13629 /** Set MPLSoGRE encapsulation details */
13630 struct cmd_set_mplsogre_encap_result {
13631         cmdline_fixed_string_t set;
13632         cmdline_fixed_string_t mplsogre;
13633         cmdline_fixed_string_t pos_token;
13634         cmdline_fixed_string_t ip_version;
13635         uint32_t vlan_present:1;
13636         uint32_t label;
13637         cmdline_ipaddr_t ip_src;
13638         cmdline_ipaddr_t ip_dst;
13639         uint16_t tci;
13640         struct rte_ether_addr eth_src;
13641         struct rte_ether_addr eth_dst;
13642 };
13643
13644 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13645         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13646                                  "set");
13647 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13648         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13649                                  "mplsogre_encap");
13650 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13651         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13652                                  mplsogre, "mplsogre_encap-with-vlan");
13653 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13654         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13655                                  pos_token, "ip-version");
13656 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13657         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13658                                  ip_version, "ipv4#ipv6");
13659 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13660         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13661                                  pos_token, "label");
13662 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13663         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13664                               RTE_UINT32);
13665 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13666         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13667                                  pos_token, "ip-src");
13668 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13669         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13670 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13671         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13672                                  pos_token, "ip-dst");
13673 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13674         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13675 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13676         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13677                                  pos_token, "vlan-tci");
13678 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13679         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13680                               RTE_UINT16);
13681 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13682         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13683                                  pos_token, "eth-src");
13684 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13685         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13686                                     eth_src);
13687 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13688         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13689                                  pos_token, "eth-dst");
13690 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13691         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13692                                     eth_dst);
13693
13694 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13695         __rte_unused struct cmdline *cl,
13696         __rte_unused void *data)
13697 {
13698         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13699         union {
13700                 uint32_t mplsogre_label;
13701                 uint8_t label[4];
13702         } id = {
13703                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13704         };
13705
13706         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13707                 mplsogre_encap_conf.select_vlan = 0;
13708         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13709                 mplsogre_encap_conf.select_vlan = 1;
13710         if (strcmp(res->ip_version, "ipv4") == 0)
13711                 mplsogre_encap_conf.select_ipv4 = 1;
13712         else if (strcmp(res->ip_version, "ipv6") == 0)
13713                 mplsogre_encap_conf.select_ipv4 = 0;
13714         else
13715                 return;
13716         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13717         if (mplsogre_encap_conf.select_ipv4) {
13718                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13719                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13720         } else {
13721                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13722                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13723         }
13724         if (mplsogre_encap_conf.select_vlan)
13725                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13726         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13727                    RTE_ETHER_ADDR_LEN);
13728         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13729                    RTE_ETHER_ADDR_LEN);
13730 }
13731
13732 static cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13733         .f = cmd_set_mplsogre_encap_parsed,
13734         .data = NULL,
13735         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13736                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13737                 " eth-dst <eth-dst>",
13738         .tokens = {
13739                 (void *)&cmd_set_mplsogre_encap_set,
13740                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13741                 (void *)&cmd_set_mplsogre_encap_ip_version,
13742                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13743                 (void *)&cmd_set_mplsogre_encap_label,
13744                 (void *)&cmd_set_mplsogre_encap_label_value,
13745                 (void *)&cmd_set_mplsogre_encap_ip_src,
13746                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13747                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13748                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13749                 (void *)&cmd_set_mplsogre_encap_eth_src,
13750                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13751                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13752                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13753                 NULL,
13754         },
13755 };
13756
13757 static cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13758         .f = cmd_set_mplsogre_encap_parsed,
13759         .data = NULL,
13760         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13761                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13762                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13763         .tokens = {
13764                 (void *)&cmd_set_mplsogre_encap_set,
13765                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13766                 (void *)&cmd_set_mplsogre_encap_ip_version,
13767                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13768                 (void *)&cmd_set_mplsogre_encap_label,
13769                 (void *)&cmd_set_mplsogre_encap_label_value,
13770                 (void *)&cmd_set_mplsogre_encap_ip_src,
13771                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13772                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13773                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13774                 (void *)&cmd_set_mplsogre_encap_vlan,
13775                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13776                 (void *)&cmd_set_mplsogre_encap_eth_src,
13777                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13778                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13779                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13780                 NULL,
13781         },
13782 };
13783
13784 /** Set MPLSoGRE decapsulation details */
13785 struct cmd_set_mplsogre_decap_result {
13786         cmdline_fixed_string_t set;
13787         cmdline_fixed_string_t mplsogre;
13788         cmdline_fixed_string_t pos_token;
13789         cmdline_fixed_string_t ip_version;
13790         uint32_t vlan_present:1;
13791 };
13792
13793 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13794         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13795                                  "set");
13796 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13797         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13798                                  "mplsogre_decap");
13799 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13800         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13801                                  mplsogre, "mplsogre_decap-with-vlan");
13802 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13803         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13804                                  pos_token, "ip-version");
13805 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13806         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13807                                  ip_version, "ipv4#ipv6");
13808
13809 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13810         __rte_unused struct cmdline *cl,
13811         __rte_unused void *data)
13812 {
13813         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13814
13815         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13816                 mplsogre_decap_conf.select_vlan = 0;
13817         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13818                 mplsogre_decap_conf.select_vlan = 1;
13819         if (strcmp(res->ip_version, "ipv4") == 0)
13820                 mplsogre_decap_conf.select_ipv4 = 1;
13821         else if (strcmp(res->ip_version, "ipv6") == 0)
13822                 mplsogre_decap_conf.select_ipv4 = 0;
13823 }
13824
13825 static cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13826         .f = cmd_set_mplsogre_decap_parsed,
13827         .data = NULL,
13828         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13829         .tokens = {
13830                 (void *)&cmd_set_mplsogre_decap_set,
13831                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13832                 (void *)&cmd_set_mplsogre_decap_ip_version,
13833                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13834                 NULL,
13835         },
13836 };
13837
13838 static cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13839         .f = cmd_set_mplsogre_decap_parsed,
13840         .data = NULL,
13841         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13842         .tokens = {
13843                 (void *)&cmd_set_mplsogre_decap_set,
13844                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13845                 (void *)&cmd_set_mplsogre_decap_ip_version,
13846                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13847                 NULL,
13848         },
13849 };
13850
13851 /** Set MPLSoUDP encapsulation details */
13852 struct cmd_set_mplsoudp_encap_result {
13853         cmdline_fixed_string_t set;
13854         cmdline_fixed_string_t mplsoudp;
13855         cmdline_fixed_string_t pos_token;
13856         cmdline_fixed_string_t ip_version;
13857         uint32_t vlan_present:1;
13858         uint32_t label;
13859         uint16_t udp_src;
13860         uint16_t udp_dst;
13861         cmdline_ipaddr_t ip_src;
13862         cmdline_ipaddr_t ip_dst;
13863         uint16_t tci;
13864         struct rte_ether_addr eth_src;
13865         struct rte_ether_addr eth_dst;
13866 };
13867
13868 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13869         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13870                                  "set");
13871 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13872         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13873                                  "mplsoudp_encap");
13874 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13875         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13876                                  mplsoudp, "mplsoudp_encap-with-vlan");
13877 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13878         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13879                                  pos_token, "ip-version");
13880 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13881         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13882                                  ip_version, "ipv4#ipv6");
13883 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13884         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13885                                  pos_token, "label");
13886 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13887         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13888                               RTE_UINT32);
13889 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13890         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13891                                  pos_token, "udp-src");
13892 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13893         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13894                               RTE_UINT16);
13895 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13896         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13897                                  pos_token, "udp-dst");
13898 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13899         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13900                               RTE_UINT16);
13901 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13902         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13903                                  pos_token, "ip-src");
13904 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13905         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13906 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13907         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13908                                  pos_token, "ip-dst");
13909 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13910         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13911 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13912         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13913                                  pos_token, "vlan-tci");
13914 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13915         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13916                               RTE_UINT16);
13917 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13918         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13919                                  pos_token, "eth-src");
13920 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13921         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13922                                     eth_src);
13923 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13924         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13925                                  pos_token, "eth-dst");
13926 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13927         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13928                                     eth_dst);
13929
13930 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13931         __rte_unused struct cmdline *cl,
13932         __rte_unused void *data)
13933 {
13934         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13935         union {
13936                 uint32_t mplsoudp_label;
13937                 uint8_t label[4];
13938         } id = {
13939                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13940         };
13941
13942         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13943                 mplsoudp_encap_conf.select_vlan = 0;
13944         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13945                 mplsoudp_encap_conf.select_vlan = 1;
13946         if (strcmp(res->ip_version, "ipv4") == 0)
13947                 mplsoudp_encap_conf.select_ipv4 = 1;
13948         else if (strcmp(res->ip_version, "ipv6") == 0)
13949                 mplsoudp_encap_conf.select_ipv4 = 0;
13950         else
13951                 return;
13952         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13953         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13954         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13955         if (mplsoudp_encap_conf.select_ipv4) {
13956                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13957                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13958         } else {
13959                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13960                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13961         }
13962         if (mplsoudp_encap_conf.select_vlan)
13963                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13964         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13965                    RTE_ETHER_ADDR_LEN);
13966         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13967                    RTE_ETHER_ADDR_LEN);
13968 }
13969
13970 static cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13971         .f = cmd_set_mplsoudp_encap_parsed,
13972         .data = NULL,
13973         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13974                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13975                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13976         .tokens = {
13977                 (void *)&cmd_set_mplsoudp_encap_set,
13978                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13979                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13980                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13981                 (void *)&cmd_set_mplsoudp_encap_label,
13982                 (void *)&cmd_set_mplsoudp_encap_label_value,
13983                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13984                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13985                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13986                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13987                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13988                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13989                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13990                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13991                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13992                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13993                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13994                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13995                 NULL,
13996         },
13997 };
13998
13999 static cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
14000         .f = cmd_set_mplsoudp_encap_parsed,
14001         .data = NULL,
14002         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
14003                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
14004                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14005                 " eth-src <eth-src> eth-dst <eth-dst>",
14006         .tokens = {
14007                 (void *)&cmd_set_mplsoudp_encap_set,
14008                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
14009                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14010                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14011                 (void *)&cmd_set_mplsoudp_encap_label,
14012                 (void *)&cmd_set_mplsoudp_encap_label_value,
14013                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14014                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14015                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14016                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14017                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14018                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14019                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14020                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14021                 (void *)&cmd_set_mplsoudp_encap_vlan,
14022                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
14023                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14024                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14025                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14026                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14027                 NULL,
14028         },
14029 };
14030
14031 /** Set MPLSoUDP decapsulation details */
14032 struct cmd_set_mplsoudp_decap_result {
14033         cmdline_fixed_string_t set;
14034         cmdline_fixed_string_t mplsoudp;
14035         cmdline_fixed_string_t pos_token;
14036         cmdline_fixed_string_t ip_version;
14037         uint32_t vlan_present:1;
14038 };
14039
14040 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14041         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14042                                  "set");
14043 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14044         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14045                                  "mplsoudp_decap");
14046 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14048                                  mplsoudp, "mplsoudp_decap-with-vlan");
14049 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14050         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14051                                  pos_token, "ip-version");
14052 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14053         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14054                                  ip_version, "ipv4#ipv6");
14055
14056 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14057         __rte_unused struct cmdline *cl,
14058         __rte_unused void *data)
14059 {
14060         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14061
14062         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14063                 mplsoudp_decap_conf.select_vlan = 0;
14064         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14065                 mplsoudp_decap_conf.select_vlan = 1;
14066         if (strcmp(res->ip_version, "ipv4") == 0)
14067                 mplsoudp_decap_conf.select_ipv4 = 1;
14068         else if (strcmp(res->ip_version, "ipv6") == 0)
14069                 mplsoudp_decap_conf.select_ipv4 = 0;
14070 }
14071
14072 static cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14073         .f = cmd_set_mplsoudp_decap_parsed,
14074         .data = NULL,
14075         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14076         .tokens = {
14077                 (void *)&cmd_set_mplsoudp_decap_set,
14078                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14079                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14080                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14081                 NULL,
14082         },
14083 };
14084
14085 static cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14086         .f = cmd_set_mplsoudp_decap_parsed,
14087         .data = NULL,
14088         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14089         .tokens = {
14090                 (void *)&cmd_set_mplsoudp_decap_set,
14091                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14092                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14093                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14094                 NULL,
14095         },
14096 };
14097
14098 /** Set connection tracking object common details */
14099 struct cmd_set_conntrack_common_result {
14100         cmdline_fixed_string_t set;
14101         cmdline_fixed_string_t conntrack;
14102         cmdline_fixed_string_t common;
14103         cmdline_fixed_string_t peer;
14104         cmdline_fixed_string_t is_orig;
14105         cmdline_fixed_string_t enable;
14106         cmdline_fixed_string_t live;
14107         cmdline_fixed_string_t sack;
14108         cmdline_fixed_string_t cack;
14109         cmdline_fixed_string_t last_dir;
14110         cmdline_fixed_string_t liberal;
14111         cmdline_fixed_string_t state;
14112         cmdline_fixed_string_t max_ack_win;
14113         cmdline_fixed_string_t retrans;
14114         cmdline_fixed_string_t last_win;
14115         cmdline_fixed_string_t last_seq;
14116         cmdline_fixed_string_t last_ack;
14117         cmdline_fixed_string_t last_end;
14118         cmdline_fixed_string_t last_index;
14119         uint8_t stat;
14120         uint8_t factor;
14121         uint16_t peer_port;
14122         uint32_t is_original;
14123         uint32_t en;
14124         uint32_t is_live;
14125         uint32_t s_ack;
14126         uint32_t c_ack;
14127         uint32_t ld;
14128         uint32_t lb;
14129         uint8_t re_num;
14130         uint8_t li;
14131         uint16_t lw;
14132         uint32_t ls;
14133         uint32_t la;
14134         uint32_t le;
14135 };
14136
14137 static cmdline_parse_token_string_t cmd_set_conntrack_set =
14138         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14139                                  set, "set");
14140 static cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14141         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14142                                  conntrack, "conntrack");
14143 static cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14144         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14145                                  common, "com");
14146 static cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14147         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14148                                  peer, "peer");
14149 static cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14150         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14151                               peer_port, RTE_UINT16);
14152 static cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14153         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14154                                  is_orig, "is_orig");
14155 static cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14156         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14157                               is_original, RTE_UINT32);
14158 static cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14159         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14160                                  enable, "enable");
14161 static cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14162         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14163                               en, RTE_UINT32);
14164 static cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14165         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14166                                  live, "live");
14167 static cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14168         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14169                               is_live, RTE_UINT32);
14170 static cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14171         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14172                                  sack, "sack");
14173 static cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14174         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14175                               s_ack, RTE_UINT32);
14176 static cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14177         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14178                                  cack, "cack");
14179 static cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14180         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14181                               c_ack, RTE_UINT32);
14182 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14183         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14184                                  last_dir, "last_dir");
14185 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14186         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14187                               ld, RTE_UINT32);
14188 static cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14189         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14190                                  liberal, "liberal");
14191 static cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14192         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14193                               lb, RTE_UINT32);
14194 static cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14195         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14196                                  state, "state");
14197 static cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14198         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14199                               stat, RTE_UINT8);
14200 static cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14201         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14202                                  max_ack_win, "max_ack_win");
14203 static cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14204         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14205                               factor, RTE_UINT8);
14206 static cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14207         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14208                                  retrans, "r_lim");
14209 static cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14210         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14211                               re_num, RTE_UINT8);
14212 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14213         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14214                                  last_win, "last_win");
14215 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14216         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14217                               lw, RTE_UINT16);
14218 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14219         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14220                                  last_seq, "last_seq");
14221 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14222         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14223                               ls, RTE_UINT32);
14224 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14225         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14226                                  last_ack, "last_ack");
14227 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14228         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14229                               la, RTE_UINT32);
14230 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14231         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14232                                  last_end, "last_end");
14233 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14234         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14235                               le, RTE_UINT32);
14236 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14237         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14238                                  last_index, "last_index");
14239 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14240         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14241                               li, RTE_UINT8);
14242
14243 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14244         __rte_unused struct cmdline *cl,
14245         __rte_unused void *data)
14246 {
14247         struct cmd_set_conntrack_common_result *res = parsed_result;
14248
14249         /* No need to swap to big endian. */
14250         conntrack_context.peer_port = res->peer_port;
14251         conntrack_context.is_original_dir = res->is_original;
14252         conntrack_context.enable = res->en;
14253         conntrack_context.live_connection = res->is_live;
14254         conntrack_context.selective_ack = res->s_ack;
14255         conntrack_context.challenge_ack_passed = res->c_ack;
14256         conntrack_context.last_direction = res->ld;
14257         conntrack_context.liberal_mode = res->lb;
14258         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14259         conntrack_context.max_ack_window = res->factor;
14260         conntrack_context.retransmission_limit = res->re_num;
14261         conntrack_context.last_window = res->lw;
14262         conntrack_context.last_index =
14263                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14264         conntrack_context.last_seq = res->ls;
14265         conntrack_context.last_ack = res->la;
14266         conntrack_context.last_end = res->le;
14267 }
14268
14269 static cmdline_parse_inst_t cmd_set_conntrack_common = {
14270         .f = cmd_set_conntrack_common_parsed,
14271         .data = NULL,
14272         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14273                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14274                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14275                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14276                 " last_index <flag>",
14277         .tokens = {
14278                 (void *)&cmd_set_conntrack_set,
14279                 (void *)&cmd_set_conntrack_conntrack,
14280                 (void *)&cmd_set_conntrack_common_com,
14281                 (void *)&cmd_set_conntrack_common_peer,
14282                 (void *)&cmd_set_conntrack_common_peer_value,
14283                 (void *)&cmd_set_conntrack_common_is_orig,
14284                 (void *)&cmd_set_conntrack_common_is_orig_value,
14285                 (void *)&cmd_set_conntrack_common_enable,
14286                 (void *)&cmd_set_conntrack_common_enable_value,
14287                 (void *)&cmd_set_conntrack_common_live,
14288                 (void *)&cmd_set_conntrack_common_live_value,
14289                 (void *)&cmd_set_conntrack_common_sack,
14290                 (void *)&cmd_set_conntrack_common_sack_value,
14291                 (void *)&cmd_set_conntrack_common_cack,
14292                 (void *)&cmd_set_conntrack_common_cack_value,
14293                 (void *)&cmd_set_conntrack_common_last_dir,
14294                 (void *)&cmd_set_conntrack_common_last_dir_value,
14295                 (void *)&cmd_set_conntrack_common_liberal,
14296                 (void *)&cmd_set_conntrack_common_liberal_value,
14297                 (void *)&cmd_set_conntrack_common_state,
14298                 (void *)&cmd_set_conntrack_common_state_value,
14299                 (void *)&cmd_set_conntrack_common_max_ackwin,
14300                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14301                 (void *)&cmd_set_conntrack_common_retrans,
14302                 (void *)&cmd_set_conntrack_common_retrans_value,
14303                 (void *)&cmd_set_conntrack_common_last_win,
14304                 (void *)&cmd_set_conntrack_common_last_win_value,
14305                 (void *)&cmd_set_conntrack_common_last_seq,
14306                 (void *)&cmd_set_conntrack_common_last_seq_value,
14307                 (void *)&cmd_set_conntrack_common_last_ack,
14308                 (void *)&cmd_set_conntrack_common_last_ack_value,
14309                 (void *)&cmd_set_conntrack_common_last_end,
14310                 (void *)&cmd_set_conntrack_common_last_end_value,
14311                 (void *)&cmd_set_conntrack_common_last_index,
14312                 (void *)&cmd_set_conntrack_common_last_index_value,
14313                 NULL,
14314         },
14315 };
14316
14317 /** Set connection tracking object both directions' details */
14318 struct cmd_set_conntrack_dir_result {
14319         cmdline_fixed_string_t set;
14320         cmdline_fixed_string_t conntrack;
14321         cmdline_fixed_string_t dir;
14322         cmdline_fixed_string_t scale;
14323         cmdline_fixed_string_t fin;
14324         cmdline_fixed_string_t ack_seen;
14325         cmdline_fixed_string_t unack;
14326         cmdline_fixed_string_t sent_end;
14327         cmdline_fixed_string_t reply_end;
14328         cmdline_fixed_string_t max_win;
14329         cmdline_fixed_string_t max_ack;
14330         uint32_t factor;
14331         uint32_t f;
14332         uint32_t as;
14333         uint32_t un;
14334         uint32_t se;
14335         uint32_t re;
14336         uint32_t mw;
14337         uint32_t ma;
14338 };
14339
14340 static cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14341         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14342                                  dir, "orig#rply");
14343 static cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14344         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14345                                  scale, "scale");
14346 static cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14347         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14348                               factor, RTE_UINT32);
14349 static cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14350         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14351                                  fin, "fin");
14352 static cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14353         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14354                               f, RTE_UINT32);
14355 static cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14356         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14357                                  ack_seen, "acked");
14358 static cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14359         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14360                               as, RTE_UINT32);
14361 static cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14362         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14363                                  unack, "unack_data");
14364 static cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14365         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14366                               un, RTE_UINT32);
14367 static cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14368         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14369                                  sent_end, "sent_end");
14370 static cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14371         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14372                               se, RTE_UINT32);
14373 static cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14374         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14375                                  reply_end, "reply_end");
14376 static cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14377         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14378                               re, RTE_UINT32);
14379 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14380         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14381                                  max_win, "max_win");
14382 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14383         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14384                               mw, RTE_UINT32);
14385 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14386         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14387                                  max_ack, "max_ack");
14388 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14389         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14390                               ma, RTE_UINT32);
14391
14392 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14393         __rte_unused struct cmdline *cl,
14394         __rte_unused void *data)
14395 {
14396         struct cmd_set_conntrack_dir_result *res = parsed_result;
14397         struct rte_flow_tcp_dir_param *dir = NULL;
14398
14399         if (strcmp(res->dir, "orig") == 0)
14400                 dir = &conntrack_context.original_dir;
14401         else if (strcmp(res->dir, "rply") == 0)
14402                 dir = &conntrack_context.reply_dir;
14403         else
14404                 return;
14405         dir->scale = res->factor;
14406         dir->close_initiated = res->f;
14407         dir->last_ack_seen = res->as;
14408         dir->data_unacked = res->un;
14409         dir->sent_end = res->se;
14410         dir->reply_end = res->re;
14411         dir->max_ack = res->ma;
14412         dir->max_win = res->mw;
14413 }
14414
14415 static cmdline_parse_inst_t cmd_set_conntrack_dir = {
14416         .f = cmd_set_conntrack_dir_parsed,
14417         .data = NULL,
14418         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14419                     " acked <seen> unack_data <unack> sent_end <sent>"
14420                     " reply_end <reply> max_win <win> max_ack <ack>",
14421         .tokens = {
14422                 (void *)&cmd_set_conntrack_set,
14423                 (void *)&cmd_set_conntrack_conntrack,
14424                 (void *)&cmd_set_conntrack_dir_dir,
14425                 (void *)&cmd_set_conntrack_dir_scale,
14426                 (void *)&cmd_set_conntrack_dir_scale_value,
14427                 (void *)&cmd_set_conntrack_dir_fin,
14428                 (void *)&cmd_set_conntrack_dir_fin_value,
14429                 (void *)&cmd_set_conntrack_dir_ack,
14430                 (void *)&cmd_set_conntrack_dir_ack_value,
14431                 (void *)&cmd_set_conntrack_dir_unack_data,
14432                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14433                 (void *)&cmd_set_conntrack_dir_sent_end,
14434                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14435                 (void *)&cmd_set_conntrack_dir_reply_end,
14436                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14437                 (void *)&cmd_set_conntrack_dir_max_win,
14438                 (void *)&cmd_set_conntrack_dir_max_win_value,
14439                 (void *)&cmd_set_conntrack_dir_max_ack,
14440                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14441                 NULL,
14442         },
14443 };
14444
14445 /* Strict link priority scheduling mode setting */
14446 static void
14447 cmd_strict_link_prio_parsed(
14448         void *parsed_result,
14449         __rte_unused struct cmdline *cl,
14450         __rte_unused void *data)
14451 {
14452         struct cmd_vf_tc_bw_result *res = parsed_result;
14453         int ret = -ENOTSUP;
14454
14455         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14456                 return;
14457
14458 #ifdef RTE_NET_I40E
14459         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14460 #endif
14461
14462         switch (ret) {
14463         case 0:
14464                 break;
14465         case -EINVAL:
14466                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14467                 break;
14468         case -ENODEV:
14469                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14470                 break;
14471         case -ENOTSUP:
14472                 fprintf(stderr, "function not implemented\n");
14473                 break;
14474         default:
14475                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14476         }
14477 }
14478
14479 static cmdline_parse_inst_t cmd_strict_link_prio = {
14480         .f = cmd_strict_link_prio_parsed,
14481         .data = NULL,
14482         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14483         .tokens = {
14484                 (void *)&cmd_vf_tc_bw_set,
14485                 (void *)&cmd_vf_tc_bw_tx,
14486                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14487                 (void *)&cmd_vf_tc_bw_port_id,
14488                 (void *)&cmd_vf_tc_bw_tc_map,
14489                 NULL,
14490         },
14491 };
14492
14493 /* Load dynamic device personalization*/
14494 struct cmd_ddp_add_result {
14495         cmdline_fixed_string_t ddp;
14496         cmdline_fixed_string_t add;
14497         portid_t port_id;
14498         char filepath[];
14499 };
14500
14501 static cmdline_parse_token_string_t cmd_ddp_add_ddp =
14502         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14503 static cmdline_parse_token_string_t cmd_ddp_add_add =
14504         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14505 static cmdline_parse_token_num_t cmd_ddp_add_port_id =
14506         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14507                 RTE_UINT16);
14508 static cmdline_parse_token_string_t cmd_ddp_add_filepath =
14509         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14510
14511 static void
14512 cmd_ddp_add_parsed(
14513         void *parsed_result,
14514         __rte_unused struct cmdline *cl,
14515         __rte_unused void *data)
14516 {
14517         struct cmd_ddp_add_result *res = parsed_result;
14518         uint8_t *buff;
14519         uint32_t size;
14520         char *filepath;
14521         char *file_fld[2];
14522         int file_num;
14523         int ret = -ENOTSUP;
14524
14525         if (!all_ports_stopped()) {
14526                 fprintf(stderr, "Please stop all ports first\n");
14527                 return;
14528         }
14529
14530         filepath = strdup(res->filepath);
14531         if (filepath == NULL) {
14532                 fprintf(stderr, "Failed to allocate memory\n");
14533                 return;
14534         }
14535         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14536
14537         buff = open_file(file_fld[0], &size);
14538         if (!buff) {
14539                 free((void *)filepath);
14540                 return;
14541         }
14542
14543 #ifdef RTE_NET_I40E
14544         if (ret == -ENOTSUP)
14545                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14546                                                buff, size,
14547                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14548 #endif
14549
14550         if (ret == -EEXIST)
14551                 fprintf(stderr, "Profile has already existed.\n");
14552         else if (ret < 0)
14553                 fprintf(stderr, "Failed to load profile.\n");
14554         else if (file_num == 2)
14555                 save_file(file_fld[1], buff, size);
14556
14557         close_file(buff);
14558         free((void *)filepath);
14559 }
14560
14561 static cmdline_parse_inst_t cmd_ddp_add = {
14562         .f = cmd_ddp_add_parsed,
14563         .data = NULL,
14564         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14565         .tokens = {
14566                 (void *)&cmd_ddp_add_ddp,
14567                 (void *)&cmd_ddp_add_add,
14568                 (void *)&cmd_ddp_add_port_id,
14569                 (void *)&cmd_ddp_add_filepath,
14570                 NULL,
14571         },
14572 };
14573
14574 /* Delete dynamic device personalization*/
14575 struct cmd_ddp_del_result {
14576         cmdline_fixed_string_t ddp;
14577         cmdline_fixed_string_t del;
14578         portid_t port_id;
14579         char filepath[];
14580 };
14581
14582 static cmdline_parse_token_string_t cmd_ddp_del_ddp =
14583         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14584 static cmdline_parse_token_string_t cmd_ddp_del_del =
14585         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14586 static cmdline_parse_token_num_t cmd_ddp_del_port_id =
14587         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14588 static cmdline_parse_token_string_t cmd_ddp_del_filepath =
14589         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14590
14591 static void
14592 cmd_ddp_del_parsed(
14593         void *parsed_result,
14594         __rte_unused struct cmdline *cl,
14595         __rte_unused void *data)
14596 {
14597         struct cmd_ddp_del_result *res = parsed_result;
14598         uint8_t *buff;
14599         uint32_t size;
14600         int ret = -ENOTSUP;
14601
14602         if (!all_ports_stopped()) {
14603                 fprintf(stderr, "Please stop all ports first\n");
14604                 return;
14605         }
14606
14607         buff = open_file(res->filepath, &size);
14608         if (!buff)
14609                 return;
14610
14611 #ifdef RTE_NET_I40E
14612         if (ret == -ENOTSUP)
14613                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14614                                                buff, size,
14615                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14616 #endif
14617
14618         if (ret == -EACCES)
14619                 fprintf(stderr, "Profile does not exist.\n");
14620         else if (ret < 0)
14621                 fprintf(stderr, "Failed to delete profile.\n");
14622
14623         close_file(buff);
14624 }
14625
14626 static cmdline_parse_inst_t cmd_ddp_del = {
14627         .f = cmd_ddp_del_parsed,
14628         .data = NULL,
14629         .help_str = "ddp del <port_id> <backup_profile_path>",
14630         .tokens = {
14631                 (void *)&cmd_ddp_del_ddp,
14632                 (void *)&cmd_ddp_del_del,
14633                 (void *)&cmd_ddp_del_port_id,
14634                 (void *)&cmd_ddp_del_filepath,
14635                 NULL,
14636         },
14637 };
14638
14639 /* Get dynamic device personalization profile info */
14640 struct cmd_ddp_info_result {
14641         cmdline_fixed_string_t ddp;
14642         cmdline_fixed_string_t get;
14643         cmdline_fixed_string_t info;
14644         char filepath[];
14645 };
14646
14647 static cmdline_parse_token_string_t cmd_ddp_info_ddp =
14648         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14649 static cmdline_parse_token_string_t cmd_ddp_info_get =
14650         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14651 static cmdline_parse_token_string_t cmd_ddp_info_info =
14652         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14653 static cmdline_parse_token_string_t cmd_ddp_info_filepath =
14654         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14655
14656 static void
14657 cmd_ddp_info_parsed(
14658         void *parsed_result,
14659         __rte_unused struct cmdline *cl,
14660         __rte_unused void *data)
14661 {
14662         struct cmd_ddp_info_result *res = parsed_result;
14663         uint8_t *pkg;
14664         uint32_t pkg_size;
14665         int ret = -ENOTSUP;
14666 #ifdef RTE_NET_I40E
14667         uint32_t i, j, n;
14668         uint8_t *buff;
14669         uint32_t buff_size = 0;
14670         struct rte_pmd_i40e_profile_info info;
14671         uint32_t dev_num = 0;
14672         struct rte_pmd_i40e_ddp_device_id *devs;
14673         uint32_t proto_num = 0;
14674         struct rte_pmd_i40e_proto_info *proto = NULL;
14675         uint32_t pctype_num = 0;
14676         struct rte_pmd_i40e_ptype_info *pctype;
14677         uint32_t ptype_num = 0;
14678         struct rte_pmd_i40e_ptype_info *ptype;
14679         uint8_t proto_id;
14680
14681 #endif
14682
14683         pkg = open_file(res->filepath, &pkg_size);
14684         if (!pkg)
14685                 return;
14686
14687 #ifdef RTE_NET_I40E
14688         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14689                                 (uint8_t *)&info, sizeof(info),
14690                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14691         if (!ret) {
14692                 printf("Global Track id:       0x%x\n", info.track_id);
14693                 printf("Global Version:        %d.%d.%d.%d\n",
14694                         info.version.major,
14695                         info.version.minor,
14696                         info.version.update,
14697                         info.version.draft);
14698                 printf("Global Package name:   %s\n\n", info.name);
14699         }
14700
14701         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14702                                 (uint8_t *)&info, sizeof(info),
14703                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14704         if (!ret) {
14705                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14706                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14707                         info.version.major,
14708                         info.version.minor,
14709                         info.version.update,
14710                         info.version.draft);
14711                 printf("i40e Profile name:     %s\n\n", info.name);
14712         }
14713
14714         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14715                                 (uint8_t *)&buff_size, sizeof(buff_size),
14716                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14717         if (!ret && buff_size) {
14718                 buff = (uint8_t *)malloc(buff_size);
14719                 if (buff) {
14720                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14721                                                 buff, buff_size,
14722                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14723                         if (!ret)
14724                                 printf("Package Notes:\n%s\n\n", buff);
14725                         free(buff);
14726                 }
14727         }
14728
14729         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14730                                 (uint8_t *)&dev_num, sizeof(dev_num),
14731                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14732         if (!ret && dev_num) {
14733                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14734                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14735                 if (devs) {
14736                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14737                                                 (uint8_t *)devs, buff_size,
14738                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14739                         if (!ret) {
14740                                 printf("List of supported devices:\n");
14741                                 for (i = 0; i < dev_num; i++) {
14742                                         printf("  %04X:%04X %04X:%04X\n",
14743                                                 devs[i].vendor_dev_id >> 16,
14744                                                 devs[i].vendor_dev_id & 0xFFFF,
14745                                                 devs[i].sub_vendor_dev_id >> 16,
14746                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14747                                 }
14748                                 printf("\n");
14749                         }
14750                         free(devs);
14751                 }
14752         }
14753
14754         /* get information about protocols and packet types */
14755         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14756                 (uint8_t *)&proto_num, sizeof(proto_num),
14757                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14758         if (ret || !proto_num)
14759                 goto no_print_return;
14760
14761         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14762         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14763         if (!proto)
14764                 goto no_print_return;
14765
14766         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14767                                         buff_size,
14768                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14769         if (!ret) {
14770                 printf("List of used protocols:\n");
14771                 for (i = 0; i < proto_num; i++)
14772                         printf("  %2u: %s\n", proto[i].proto_id,
14773                                proto[i].name);
14774                 printf("\n");
14775         }
14776         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14777                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14778                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14779         if (ret || !pctype_num)
14780                 goto no_print_pctypes;
14781
14782         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14783         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14784         if (!pctype)
14785                 goto no_print_pctypes;
14786
14787         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14788                                         buff_size,
14789                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14790         if (ret) {
14791                 free(pctype);
14792                 goto no_print_pctypes;
14793         }
14794
14795         printf("List of defined packet classification types:\n");
14796         for (i = 0; i < pctype_num; i++) {
14797                 printf("  %2u:", pctype[i].ptype_id);
14798                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14799                         proto_id = pctype[i].protocols[j];
14800                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14801                                 for (n = 0; n < proto_num; n++) {
14802                                         if (proto[n].proto_id == proto_id) {
14803                                                 printf(" %s", proto[n].name);
14804                                                 break;
14805                                         }
14806                                 }
14807                         }
14808                 }
14809                 printf("\n");
14810         }
14811         printf("\n");
14812         free(pctype);
14813
14814 no_print_pctypes:
14815
14816         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14817                                         sizeof(ptype_num),
14818                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14819         if (ret || !ptype_num)
14820                 goto no_print_return;
14821
14822         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14823         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14824         if (!ptype)
14825                 goto no_print_return;
14826
14827         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14828                                         buff_size,
14829                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14830         if (ret) {
14831                 free(ptype);
14832                 goto no_print_return;
14833         }
14834         printf("List of defined packet types:\n");
14835         for (i = 0; i < ptype_num; i++) {
14836                 printf("  %2u:", ptype[i].ptype_id);
14837                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14838                         proto_id = ptype[i].protocols[j];
14839                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14840                                 for (n = 0; n < proto_num; n++) {
14841                                         if (proto[n].proto_id == proto_id) {
14842                                                 printf(" %s", proto[n].name);
14843                                                 break;
14844                                         }
14845                                 }
14846                         }
14847                 }
14848                 printf("\n");
14849         }
14850         free(ptype);
14851         printf("\n");
14852
14853         ret = 0;
14854 no_print_return:
14855         free(proto);
14856 #endif
14857         if (ret == -ENOTSUP)
14858                 fprintf(stderr, "Function not supported in PMD\n");
14859         close_file(pkg);
14860 }
14861
14862 static cmdline_parse_inst_t cmd_ddp_get_info = {
14863         .f = cmd_ddp_info_parsed,
14864         .data = NULL,
14865         .help_str = "ddp get info <profile_path>",
14866         .tokens = {
14867                 (void *)&cmd_ddp_info_ddp,
14868                 (void *)&cmd_ddp_info_get,
14869                 (void *)&cmd_ddp_info_info,
14870                 (void *)&cmd_ddp_info_filepath,
14871                 NULL,
14872         },
14873 };
14874
14875 /* Get dynamic device personalization profile info list*/
14876 #define PROFILE_INFO_SIZE 48
14877 #define MAX_PROFILE_NUM 16
14878
14879 struct cmd_ddp_get_list_result {
14880         cmdline_fixed_string_t ddp;
14881         cmdline_fixed_string_t get;
14882         cmdline_fixed_string_t list;
14883         portid_t port_id;
14884 };
14885
14886 static cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14887         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14888 static cmdline_parse_token_string_t cmd_ddp_get_list_get =
14889         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14890 static cmdline_parse_token_string_t cmd_ddp_get_list_list =
14891         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14892 static cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14893         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14894                 RTE_UINT16);
14895
14896 static void
14897 cmd_ddp_get_list_parsed(
14898         __rte_unused void *parsed_result,
14899         __rte_unused struct cmdline *cl,
14900         __rte_unused void *data)
14901 {
14902 #ifdef RTE_NET_I40E
14903         struct cmd_ddp_get_list_result *res = parsed_result;
14904         struct rte_pmd_i40e_profile_list *p_list;
14905         struct rte_pmd_i40e_profile_info *p_info;
14906         uint32_t p_num;
14907         uint32_t size;
14908         uint32_t i;
14909 #endif
14910         int ret = -ENOTSUP;
14911
14912 #ifdef RTE_NET_I40E
14913         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14914         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14915         if (!p_list) {
14916                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14917                 return;
14918         }
14919
14920         if (ret == -ENOTSUP)
14921                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14922                                                 (uint8_t *)p_list, size);
14923
14924         if (!ret) {
14925                 p_num = p_list->p_count;
14926                 printf("Profile number is: %d\n\n", p_num);
14927
14928                 for (i = 0; i < p_num; i++) {
14929                         p_info = &p_list->p_info[i];
14930                         printf("Profile %d:\n", i);
14931                         printf("Track id:     0x%x\n", p_info->track_id);
14932                         printf("Version:      %d.%d.%d.%d\n",
14933                                p_info->version.major,
14934                                p_info->version.minor,
14935                                p_info->version.update,
14936                                p_info->version.draft);
14937                         printf("Profile name: %s\n\n", p_info->name);
14938                 }
14939         }
14940
14941         free(p_list);
14942 #endif
14943
14944         if (ret < 0)
14945                 fprintf(stderr, "Failed to get ddp list\n");
14946 }
14947
14948 static cmdline_parse_inst_t cmd_ddp_get_list = {
14949         .f = cmd_ddp_get_list_parsed,
14950         .data = NULL,
14951         .help_str = "ddp get list <port_id>",
14952         .tokens = {
14953                 (void *)&cmd_ddp_get_list_ddp,
14954                 (void *)&cmd_ddp_get_list_get,
14955                 (void *)&cmd_ddp_get_list_list,
14956                 (void *)&cmd_ddp_get_list_port_id,
14957                 NULL,
14958         },
14959 };
14960
14961 /* Configure input set */
14962 struct cmd_cfg_input_set_result {
14963         cmdline_fixed_string_t port;
14964         cmdline_fixed_string_t cfg;
14965         portid_t port_id;
14966         cmdline_fixed_string_t pctype;
14967         uint8_t pctype_id;
14968         cmdline_fixed_string_t inset_type;
14969         cmdline_fixed_string_t opt;
14970         cmdline_fixed_string_t field;
14971         uint8_t field_idx;
14972 };
14973
14974 static void
14975 cmd_cfg_input_set_parsed(
14976         __rte_unused void *parsed_result,
14977         __rte_unused struct cmdline *cl,
14978         __rte_unused void *data)
14979 {
14980 #ifdef RTE_NET_I40E
14981         struct cmd_cfg_input_set_result *res = parsed_result;
14982         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14983         struct rte_pmd_i40e_inset inset;
14984 #endif
14985         int ret = -ENOTSUP;
14986
14987         if (!all_ports_stopped()) {
14988                 fprintf(stderr, "Please stop all ports first\n");
14989                 return;
14990         }
14991
14992 #ifdef RTE_NET_I40E
14993         if (!strcmp(res->inset_type, "hash_inset"))
14994                 inset_type = INSET_HASH;
14995         else if (!strcmp(res->inset_type, "fdir_inset"))
14996                 inset_type = INSET_FDIR;
14997         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14998                 inset_type = INSET_FDIR_FLX;
14999         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15000                                      &inset, inset_type);
15001         if (ret) {
15002                 fprintf(stderr, "Failed to get input set.\n");
15003                 return;
15004         }
15005
15006         if (!strcmp(res->opt, "get")) {
15007                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15008                                                    res->field_idx);
15009                 if (ret)
15010                         printf("Field index %d is enabled.\n", res->field_idx);
15011                 else
15012                         printf("Field index %d is disabled.\n", res->field_idx);
15013                 return;
15014         } else if (!strcmp(res->opt, "set"))
15015                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15016                                                    res->field_idx);
15017         else if (!strcmp(res->opt, "clear"))
15018                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15019                                                      res->field_idx);
15020         if (ret) {
15021                 fprintf(stderr, "Failed to configure input set field.\n");
15022                 return;
15023         }
15024
15025         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15026                                      &inset, inset_type);
15027         if (ret) {
15028                 fprintf(stderr, "Failed to set input set.\n");
15029                 return;
15030         }
15031 #endif
15032
15033         if (ret == -ENOTSUP)
15034                 fprintf(stderr, "Function not supported\n");
15035 }
15036
15037 static cmdline_parse_token_string_t cmd_cfg_input_set_port =
15038         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15039                                  port, "port");
15040 static cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15041         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15042                                  cfg, "config");
15043 static cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15044         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15045                               port_id, RTE_UINT16);
15046 static cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15047         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15048                                  pctype, "pctype");
15049 static cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15050         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15051                               pctype_id, RTE_UINT8);
15052 static cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15053         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15054                                  inset_type,
15055                                  "hash_inset#fdir_inset#fdir_flx_inset");
15056 static cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15057         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15058                                  opt, "get#set#clear");
15059 static cmdline_parse_token_string_t cmd_cfg_input_set_field =
15060         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15061                                  field, "field");
15062 static cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15063         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15064                               field_idx, RTE_UINT8);
15065
15066 static cmdline_parse_inst_t cmd_cfg_input_set = {
15067         .f = cmd_cfg_input_set_parsed,
15068         .data = NULL,
15069         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15070                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15071         .tokens = {
15072                 (void *)&cmd_cfg_input_set_port,
15073                 (void *)&cmd_cfg_input_set_cfg,
15074                 (void *)&cmd_cfg_input_set_port_id,
15075                 (void *)&cmd_cfg_input_set_pctype,
15076                 (void *)&cmd_cfg_input_set_pctype_id,
15077                 (void *)&cmd_cfg_input_set_inset_type,
15078                 (void *)&cmd_cfg_input_set_opt,
15079                 (void *)&cmd_cfg_input_set_field,
15080                 (void *)&cmd_cfg_input_set_field_idx,
15081                 NULL,
15082         },
15083 };
15084
15085 /* Clear input set */
15086 struct cmd_clear_input_set_result {
15087         cmdline_fixed_string_t port;
15088         cmdline_fixed_string_t cfg;
15089         portid_t port_id;
15090         cmdline_fixed_string_t pctype;
15091         uint8_t pctype_id;
15092         cmdline_fixed_string_t inset_type;
15093         cmdline_fixed_string_t clear;
15094         cmdline_fixed_string_t all;
15095 };
15096
15097 static void
15098 cmd_clear_input_set_parsed(
15099         __rte_unused void *parsed_result,
15100         __rte_unused struct cmdline *cl,
15101         __rte_unused void *data)
15102 {
15103 #ifdef RTE_NET_I40E
15104         struct cmd_clear_input_set_result *res = parsed_result;
15105         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15106         struct rte_pmd_i40e_inset inset;
15107 #endif
15108         int ret = -ENOTSUP;
15109
15110         if (!all_ports_stopped()) {
15111                 fprintf(stderr, "Please stop all ports first\n");
15112                 return;
15113         }
15114
15115 #ifdef RTE_NET_I40E
15116         if (!strcmp(res->inset_type, "hash_inset"))
15117                 inset_type = INSET_HASH;
15118         else if (!strcmp(res->inset_type, "fdir_inset"))
15119                 inset_type = INSET_FDIR;
15120         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15121                 inset_type = INSET_FDIR_FLX;
15122
15123         memset(&inset, 0, sizeof(inset));
15124
15125         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15126                                      &inset, inset_type);
15127         if (ret) {
15128                 fprintf(stderr, "Failed to clear input set.\n");
15129                 return;
15130         }
15131
15132 #endif
15133
15134         if (ret == -ENOTSUP)
15135                 fprintf(stderr, "Function not supported\n");
15136 }
15137
15138 static cmdline_parse_token_string_t cmd_clear_input_set_port =
15139         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15140                                  port, "port");
15141 static cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15142         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15143                                  cfg, "config");
15144 static cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15145         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15146                               port_id, RTE_UINT16);
15147 static cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15148         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15149                                  pctype, "pctype");
15150 static cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15151         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15152                               pctype_id, RTE_UINT8);
15153 static cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15154         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15155                                  inset_type,
15156                                  "hash_inset#fdir_inset#fdir_flx_inset");
15157 static cmdline_parse_token_string_t cmd_clear_input_set_clear =
15158         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15159                                  clear, "clear");
15160 static cmdline_parse_token_string_t cmd_clear_input_set_all =
15161         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15162                                  all, "all");
15163
15164 static cmdline_parse_inst_t cmd_clear_input_set = {
15165         .f = cmd_clear_input_set_parsed,
15166         .data = NULL,
15167         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15168                     "fdir_inset|fdir_flx_inset clear all",
15169         .tokens = {
15170                 (void *)&cmd_clear_input_set_port,
15171                 (void *)&cmd_clear_input_set_cfg,
15172                 (void *)&cmd_clear_input_set_port_id,
15173                 (void *)&cmd_clear_input_set_pctype,
15174                 (void *)&cmd_clear_input_set_pctype_id,
15175                 (void *)&cmd_clear_input_set_inset_type,
15176                 (void *)&cmd_clear_input_set_clear,
15177                 (void *)&cmd_clear_input_set_all,
15178                 NULL,
15179         },
15180 };
15181
15182 /* show vf stats */
15183
15184 /* Common result structure for show vf stats */
15185 struct cmd_show_vf_stats_result {
15186         cmdline_fixed_string_t show;
15187         cmdline_fixed_string_t vf;
15188         cmdline_fixed_string_t stats;
15189         portid_t port_id;
15190         uint16_t vf_id;
15191 };
15192
15193 /* Common CLI fields show vf stats*/
15194 static cmdline_parse_token_string_t cmd_show_vf_stats_show =
15195         TOKEN_STRING_INITIALIZER
15196                 (struct cmd_show_vf_stats_result,
15197                  show, "show");
15198 static cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15199         TOKEN_STRING_INITIALIZER
15200                 (struct cmd_show_vf_stats_result,
15201                  vf, "vf");
15202 static cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15203         TOKEN_STRING_INITIALIZER
15204                 (struct cmd_show_vf_stats_result,
15205                  stats, "stats");
15206 static cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15207         TOKEN_NUM_INITIALIZER
15208                 (struct cmd_show_vf_stats_result,
15209                  port_id, RTE_UINT16);
15210 static cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15211         TOKEN_NUM_INITIALIZER
15212                 (struct cmd_show_vf_stats_result,
15213                  vf_id, RTE_UINT16);
15214
15215 static void
15216 cmd_show_vf_stats_parsed(
15217         void *parsed_result,
15218         __rte_unused struct cmdline *cl,
15219         __rte_unused void *data)
15220 {
15221         struct cmd_show_vf_stats_result *res = parsed_result;
15222         struct rte_eth_stats stats;
15223         int ret = -ENOTSUP;
15224         static const char *nic_stats_border = "########################";
15225
15226         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15227                 return;
15228
15229         memset(&stats, 0, sizeof(stats));
15230
15231 #ifdef RTE_NET_I40E
15232         if (ret == -ENOTSUP)
15233                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15234                                                 res->vf_id,
15235                                                 &stats);
15236 #endif
15237 #ifdef RTE_NET_BNXT
15238         if (ret == -ENOTSUP)
15239                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15240                                                 res->vf_id,
15241                                                 &stats);
15242 #endif
15243
15244         switch (ret) {
15245         case 0:
15246                 break;
15247         case -EINVAL:
15248                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15249                 break;
15250         case -ENODEV:
15251                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15252                 break;
15253         case -ENOTSUP:
15254                 fprintf(stderr, "function not implemented\n");
15255                 break;
15256         default:
15257                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15258         }
15259
15260         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15261                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15262
15263         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15264                "%-"PRIu64"\n",
15265                stats.ipackets, stats.imissed, stats.ibytes);
15266         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15267         printf("  RX-nombuf:  %-10"PRIu64"\n",
15268                stats.rx_nombuf);
15269         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15270                "%-"PRIu64"\n",
15271                stats.opackets, stats.oerrors, stats.obytes);
15272
15273         printf("  %s############################%s\n",
15274                                nic_stats_border, nic_stats_border);
15275 }
15276
15277 static cmdline_parse_inst_t cmd_show_vf_stats = {
15278         .f = cmd_show_vf_stats_parsed,
15279         .data = NULL,
15280         .help_str = "show vf stats <port_id> <vf_id>",
15281         .tokens = {
15282                 (void *)&cmd_show_vf_stats_show,
15283                 (void *)&cmd_show_vf_stats_vf,
15284                 (void *)&cmd_show_vf_stats_stats,
15285                 (void *)&cmd_show_vf_stats_port_id,
15286                 (void *)&cmd_show_vf_stats_vf_id,
15287                 NULL,
15288         },
15289 };
15290
15291 /* clear vf stats */
15292
15293 /* Common result structure for clear vf stats */
15294 struct cmd_clear_vf_stats_result {
15295         cmdline_fixed_string_t clear;
15296         cmdline_fixed_string_t vf;
15297         cmdline_fixed_string_t stats;
15298         portid_t port_id;
15299         uint16_t vf_id;
15300 };
15301
15302 /* Common CLI fields clear vf stats*/
15303 static cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15304         TOKEN_STRING_INITIALIZER
15305                 (struct cmd_clear_vf_stats_result,
15306                  clear, "clear");
15307 static cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15308         TOKEN_STRING_INITIALIZER
15309                 (struct cmd_clear_vf_stats_result,
15310                  vf, "vf");
15311 static cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15312         TOKEN_STRING_INITIALIZER
15313                 (struct cmd_clear_vf_stats_result,
15314                  stats, "stats");
15315 static cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15316         TOKEN_NUM_INITIALIZER
15317                 (struct cmd_clear_vf_stats_result,
15318                  port_id, RTE_UINT16);
15319 static cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15320         TOKEN_NUM_INITIALIZER
15321                 (struct cmd_clear_vf_stats_result,
15322                  vf_id, RTE_UINT16);
15323
15324 static void
15325 cmd_clear_vf_stats_parsed(
15326         void *parsed_result,
15327         __rte_unused struct cmdline *cl,
15328         __rte_unused void *data)
15329 {
15330         struct cmd_clear_vf_stats_result *res = parsed_result;
15331         int ret = -ENOTSUP;
15332
15333         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15334                 return;
15335
15336 #ifdef RTE_NET_I40E
15337         if (ret == -ENOTSUP)
15338                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15339                                                   res->vf_id);
15340 #endif
15341 #ifdef RTE_NET_BNXT
15342         if (ret == -ENOTSUP)
15343                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15344                                                   res->vf_id);
15345 #endif
15346
15347         switch (ret) {
15348         case 0:
15349                 break;
15350         case -EINVAL:
15351                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15352                 break;
15353         case -ENODEV:
15354                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15355                 break;
15356         case -ENOTSUP:
15357                 fprintf(stderr, "function not implemented\n");
15358                 break;
15359         default:
15360                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15361         }
15362 }
15363
15364 static cmdline_parse_inst_t cmd_clear_vf_stats = {
15365         .f = cmd_clear_vf_stats_parsed,
15366         .data = NULL,
15367         .help_str = "clear vf stats <port_id> <vf_id>",
15368         .tokens = {
15369                 (void *)&cmd_clear_vf_stats_clear,
15370                 (void *)&cmd_clear_vf_stats_vf,
15371                 (void *)&cmd_clear_vf_stats_stats,
15372                 (void *)&cmd_clear_vf_stats_port_id,
15373                 (void *)&cmd_clear_vf_stats_vf_id,
15374                 NULL,
15375         },
15376 };
15377
15378 /* port config pctype mapping reset */
15379
15380 /* Common result structure for port config pctype mapping reset */
15381 struct cmd_pctype_mapping_reset_result {
15382         cmdline_fixed_string_t port;
15383         cmdline_fixed_string_t config;
15384         portid_t port_id;
15385         cmdline_fixed_string_t pctype;
15386         cmdline_fixed_string_t mapping;
15387         cmdline_fixed_string_t reset;
15388 };
15389
15390 /* Common CLI fields for port config pctype mapping reset*/
15391 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15392         TOKEN_STRING_INITIALIZER
15393                 (struct cmd_pctype_mapping_reset_result,
15394                  port, "port");
15395 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15396         TOKEN_STRING_INITIALIZER
15397                 (struct cmd_pctype_mapping_reset_result,
15398                  config, "config");
15399 static cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15400         TOKEN_NUM_INITIALIZER
15401                 (struct cmd_pctype_mapping_reset_result,
15402                  port_id, RTE_UINT16);
15403 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15404         TOKEN_STRING_INITIALIZER
15405                 (struct cmd_pctype_mapping_reset_result,
15406                  pctype, "pctype");
15407 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15408         TOKEN_STRING_INITIALIZER
15409                 (struct cmd_pctype_mapping_reset_result,
15410                  mapping, "mapping");
15411 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15412         TOKEN_STRING_INITIALIZER
15413                 (struct cmd_pctype_mapping_reset_result,
15414                  reset, "reset");
15415
15416 static void
15417 cmd_pctype_mapping_reset_parsed(
15418         void *parsed_result,
15419         __rte_unused struct cmdline *cl,
15420         __rte_unused void *data)
15421 {
15422         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15423         int ret = -ENOTSUP;
15424
15425         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15426                 return;
15427
15428 #ifdef RTE_NET_I40E
15429         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15430 #endif
15431
15432         switch (ret) {
15433         case 0:
15434                 break;
15435         case -ENODEV:
15436                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15437                 break;
15438         case -ENOTSUP:
15439                 fprintf(stderr, "function not implemented\n");
15440                 break;
15441         default:
15442                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15443         }
15444 }
15445
15446 static cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15447         .f = cmd_pctype_mapping_reset_parsed,
15448         .data = NULL,
15449         .help_str = "port config <port_id> pctype mapping reset",
15450         .tokens = {
15451                 (void *)&cmd_pctype_mapping_reset_port,
15452                 (void *)&cmd_pctype_mapping_reset_config,
15453                 (void *)&cmd_pctype_mapping_reset_port_id,
15454                 (void *)&cmd_pctype_mapping_reset_pctype,
15455                 (void *)&cmd_pctype_mapping_reset_mapping,
15456                 (void *)&cmd_pctype_mapping_reset_reset,
15457                 NULL,
15458         },
15459 };
15460
15461 /* show port pctype mapping */
15462
15463 /* Common result structure for show port pctype mapping */
15464 struct cmd_pctype_mapping_get_result {
15465         cmdline_fixed_string_t show;
15466         cmdline_fixed_string_t port;
15467         portid_t port_id;
15468         cmdline_fixed_string_t pctype;
15469         cmdline_fixed_string_t mapping;
15470 };
15471
15472 /* Common CLI fields for pctype mapping get */
15473 static cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15474         TOKEN_STRING_INITIALIZER
15475                 (struct cmd_pctype_mapping_get_result,
15476                  show, "show");
15477 static cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15478         TOKEN_STRING_INITIALIZER
15479                 (struct cmd_pctype_mapping_get_result,
15480                  port, "port");
15481 static cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15482         TOKEN_NUM_INITIALIZER
15483                 (struct cmd_pctype_mapping_get_result,
15484                  port_id, RTE_UINT16);
15485 static cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15486         TOKEN_STRING_INITIALIZER
15487                 (struct cmd_pctype_mapping_get_result,
15488                  pctype, "pctype");
15489 static cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15490         TOKEN_STRING_INITIALIZER
15491                 (struct cmd_pctype_mapping_get_result,
15492                  mapping, "mapping");
15493
15494 static void
15495 cmd_pctype_mapping_get_parsed(
15496         void *parsed_result,
15497         __rte_unused struct cmdline *cl,
15498         __rte_unused void *data)
15499 {
15500         struct cmd_pctype_mapping_get_result *res = parsed_result;
15501         int ret = -ENOTSUP;
15502 #ifdef RTE_NET_I40E
15503         struct rte_pmd_i40e_flow_type_mapping
15504                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15505         int i, j, first_pctype;
15506 #endif
15507
15508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15509                 return;
15510
15511 #ifdef RTE_NET_I40E
15512         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15513 #endif
15514
15515         switch (ret) {
15516         case 0:
15517                 break;
15518         case -ENODEV:
15519                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15520                 return;
15521         case -ENOTSUP:
15522                 fprintf(stderr, "function not implemented\n");
15523                 return;
15524         default:
15525                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15526                 return;
15527         }
15528
15529 #ifdef RTE_NET_I40E
15530         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15531                 if (mapping[i].pctype != 0ULL) {
15532                         first_pctype = 1;
15533
15534                         printf("pctype: ");
15535                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15536                                 if (mapping[i].pctype & (1ULL << j)) {
15537                                         printf(first_pctype ?
15538                                                "%02d" : ",%02d", j);
15539                                         first_pctype = 0;
15540                                 }
15541                         }
15542                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15543                 }
15544         }
15545 #endif
15546 }
15547
15548 static cmdline_parse_inst_t cmd_pctype_mapping_get = {
15549         .f = cmd_pctype_mapping_get_parsed,
15550         .data = NULL,
15551         .help_str = "show port <port_id> pctype mapping",
15552         .tokens = {
15553                 (void *)&cmd_pctype_mapping_get_show,
15554                 (void *)&cmd_pctype_mapping_get_port,
15555                 (void *)&cmd_pctype_mapping_get_port_id,
15556                 (void *)&cmd_pctype_mapping_get_pctype,
15557                 (void *)&cmd_pctype_mapping_get_mapping,
15558                 NULL,
15559         },
15560 };
15561
15562 /* port config pctype mapping update */
15563
15564 /* Common result structure for port config pctype mapping update */
15565 struct cmd_pctype_mapping_update_result {
15566         cmdline_fixed_string_t port;
15567         cmdline_fixed_string_t config;
15568         portid_t port_id;
15569         cmdline_fixed_string_t pctype;
15570         cmdline_fixed_string_t mapping;
15571         cmdline_fixed_string_t update;
15572         cmdline_fixed_string_t pctype_list;
15573         uint16_t flow_type;
15574 };
15575
15576 /* Common CLI fields for pctype mapping update*/
15577 static cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15578         TOKEN_STRING_INITIALIZER
15579                 (struct cmd_pctype_mapping_update_result,
15580                  port, "port");
15581 static cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15582         TOKEN_STRING_INITIALIZER
15583                 (struct cmd_pctype_mapping_update_result,
15584                  config, "config");
15585 static cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15586         TOKEN_NUM_INITIALIZER
15587                 (struct cmd_pctype_mapping_update_result,
15588                  port_id, RTE_UINT16);
15589 static cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15590         TOKEN_STRING_INITIALIZER
15591                 (struct cmd_pctype_mapping_update_result,
15592                  pctype, "pctype");
15593 static cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15594         TOKEN_STRING_INITIALIZER
15595                 (struct cmd_pctype_mapping_update_result,
15596                  mapping, "mapping");
15597 static cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15598         TOKEN_STRING_INITIALIZER
15599                 (struct cmd_pctype_mapping_update_result,
15600                  update, "update");
15601 static cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15602         TOKEN_STRING_INITIALIZER
15603                 (struct cmd_pctype_mapping_update_result,
15604                  pctype_list, NULL);
15605 static cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15606         TOKEN_NUM_INITIALIZER
15607                 (struct cmd_pctype_mapping_update_result,
15608                  flow_type, RTE_UINT16);
15609
15610 static void
15611 cmd_pctype_mapping_update_parsed(
15612         void *parsed_result,
15613         __rte_unused struct cmdline *cl,
15614         __rte_unused void *data)
15615 {
15616         struct cmd_pctype_mapping_update_result *res = parsed_result;
15617         int ret = -ENOTSUP;
15618 #ifdef RTE_NET_I40E
15619         struct rte_pmd_i40e_flow_type_mapping mapping;
15620         unsigned int i;
15621         unsigned int nb_item;
15622         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15623 #endif
15624
15625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15626                 return;
15627
15628 #ifdef RTE_NET_I40E
15629         nb_item = parse_item_list(res->pctype_list, "pctypes",
15630                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15631         mapping.flow_type = res->flow_type;
15632         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15633                 mapping.pctype |= (1ULL << pctype_list[i]);
15634         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15635                                                 &mapping,
15636                                                 1,
15637                                                 0);
15638 #endif
15639
15640         switch (ret) {
15641         case 0:
15642                 break;
15643         case -EINVAL:
15644                 fprintf(stderr, "invalid pctype or flow type\n");
15645                 break;
15646         case -ENODEV:
15647                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15648                 break;
15649         case -ENOTSUP:
15650                 fprintf(stderr, "function not implemented\n");
15651                 break;
15652         default:
15653                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15654         }
15655 }
15656
15657 static cmdline_parse_inst_t cmd_pctype_mapping_update = {
15658         .f = cmd_pctype_mapping_update_parsed,
15659         .data = NULL,
15660         .help_str = "port config <port_id> pctype mapping update"
15661         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15662         .tokens = {
15663                 (void *)&cmd_pctype_mapping_update_port,
15664                 (void *)&cmd_pctype_mapping_update_config,
15665                 (void *)&cmd_pctype_mapping_update_port_id,
15666                 (void *)&cmd_pctype_mapping_update_pctype,
15667                 (void *)&cmd_pctype_mapping_update_mapping,
15668                 (void *)&cmd_pctype_mapping_update_update,
15669                 (void *)&cmd_pctype_mapping_update_pc_type,
15670                 (void *)&cmd_pctype_mapping_update_flow_type,
15671                 NULL,
15672         },
15673 };
15674
15675 /* ptype mapping get */
15676
15677 /* Common result structure for ptype mapping get */
15678 struct cmd_ptype_mapping_get_result {
15679         cmdline_fixed_string_t ptype;
15680         cmdline_fixed_string_t mapping;
15681         cmdline_fixed_string_t get;
15682         portid_t port_id;
15683         uint8_t valid_only;
15684 };
15685
15686 /* Common CLI fields for ptype mapping get */
15687 static cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15688         TOKEN_STRING_INITIALIZER
15689                 (struct cmd_ptype_mapping_get_result,
15690                  ptype, "ptype");
15691 static cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15692         TOKEN_STRING_INITIALIZER
15693                 (struct cmd_ptype_mapping_get_result,
15694                  mapping, "mapping");
15695 static cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15696         TOKEN_STRING_INITIALIZER
15697                 (struct cmd_ptype_mapping_get_result,
15698                  get, "get");
15699 static cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15700         TOKEN_NUM_INITIALIZER
15701                 (struct cmd_ptype_mapping_get_result,
15702                  port_id, RTE_UINT16);
15703 static cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15704         TOKEN_NUM_INITIALIZER
15705                 (struct cmd_ptype_mapping_get_result,
15706                  valid_only, RTE_UINT8);
15707
15708 static void
15709 cmd_ptype_mapping_get_parsed(
15710         void *parsed_result,
15711         __rte_unused struct cmdline *cl,
15712         __rte_unused void *data)
15713 {
15714         struct cmd_ptype_mapping_get_result *res = parsed_result;
15715         int ret = -ENOTSUP;
15716 #ifdef RTE_NET_I40E
15717         int max_ptype_num = 256;
15718         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15719         uint16_t count;
15720         int i;
15721 #endif
15722
15723         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15724                 return;
15725
15726 #ifdef RTE_NET_I40E
15727         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15728                                         mapping,
15729                                         max_ptype_num,
15730                                         &count,
15731                                         res->valid_only);
15732 #endif
15733
15734         switch (ret) {
15735         case 0:
15736                 break;
15737         case -ENODEV:
15738                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15739                 break;
15740         case -ENOTSUP:
15741                 fprintf(stderr, "function not implemented\n");
15742                 break;
15743         default:
15744                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15745         }
15746
15747 #ifdef RTE_NET_I40E
15748         if (!ret) {
15749                 for (i = 0; i < count; i++)
15750                         printf("%3d\t0x%08x\n",
15751                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15752         }
15753 #endif
15754 }
15755
15756 static cmdline_parse_inst_t cmd_ptype_mapping_get = {
15757         .f = cmd_ptype_mapping_get_parsed,
15758         .data = NULL,
15759         .help_str = "ptype mapping get <port_id> <valid_only>",
15760         .tokens = {
15761                 (void *)&cmd_ptype_mapping_get_ptype,
15762                 (void *)&cmd_ptype_mapping_get_mapping,
15763                 (void *)&cmd_ptype_mapping_get_get,
15764                 (void *)&cmd_ptype_mapping_get_port_id,
15765                 (void *)&cmd_ptype_mapping_get_valid_only,
15766                 NULL,
15767         },
15768 };
15769
15770 /* ptype mapping replace */
15771
15772 /* Common result structure for ptype mapping replace */
15773 struct cmd_ptype_mapping_replace_result {
15774         cmdline_fixed_string_t ptype;
15775         cmdline_fixed_string_t mapping;
15776         cmdline_fixed_string_t replace;
15777         portid_t port_id;
15778         uint32_t target;
15779         uint8_t mask;
15780         uint32_t pkt_type;
15781 };
15782
15783 /* Common CLI fields for ptype mapping replace */
15784 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15785         TOKEN_STRING_INITIALIZER
15786                 (struct cmd_ptype_mapping_replace_result,
15787                  ptype, "ptype");
15788 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15789         TOKEN_STRING_INITIALIZER
15790                 (struct cmd_ptype_mapping_replace_result,
15791                  mapping, "mapping");
15792 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15793         TOKEN_STRING_INITIALIZER
15794                 (struct cmd_ptype_mapping_replace_result,
15795                  replace, "replace");
15796 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15797         TOKEN_NUM_INITIALIZER
15798                 (struct cmd_ptype_mapping_replace_result,
15799                  port_id, RTE_UINT16);
15800 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15801         TOKEN_NUM_INITIALIZER
15802                 (struct cmd_ptype_mapping_replace_result,
15803                  target, RTE_UINT32);
15804 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15805         TOKEN_NUM_INITIALIZER
15806                 (struct cmd_ptype_mapping_replace_result,
15807                  mask, RTE_UINT8);
15808 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15809         TOKEN_NUM_INITIALIZER
15810                 (struct cmd_ptype_mapping_replace_result,
15811                  pkt_type, RTE_UINT32);
15812
15813 static void
15814 cmd_ptype_mapping_replace_parsed(
15815         void *parsed_result,
15816         __rte_unused struct cmdline *cl,
15817         __rte_unused void *data)
15818 {
15819         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15820         int ret = -ENOTSUP;
15821
15822         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15823                 return;
15824
15825 #ifdef RTE_NET_I40E
15826         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15827                                         res->target,
15828                                         res->mask,
15829                                         res->pkt_type);
15830 #endif
15831
15832         switch (ret) {
15833         case 0:
15834                 break;
15835         case -EINVAL:
15836                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15837                         res->target, res->pkt_type);
15838                 break;
15839         case -ENODEV:
15840                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15841                 break;
15842         case -ENOTSUP:
15843                 fprintf(stderr, "function not implemented\n");
15844                 break;
15845         default:
15846                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15847         }
15848 }
15849
15850 static cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15851         .f = cmd_ptype_mapping_replace_parsed,
15852         .data = NULL,
15853         .help_str =
15854                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15855         .tokens = {
15856                 (void *)&cmd_ptype_mapping_replace_ptype,
15857                 (void *)&cmd_ptype_mapping_replace_mapping,
15858                 (void *)&cmd_ptype_mapping_replace_replace,
15859                 (void *)&cmd_ptype_mapping_replace_port_id,
15860                 (void *)&cmd_ptype_mapping_replace_target,
15861                 (void *)&cmd_ptype_mapping_replace_mask,
15862                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15863                 NULL,
15864         },
15865 };
15866
15867 /* ptype mapping reset */
15868
15869 /* Common result structure for ptype mapping reset */
15870 struct cmd_ptype_mapping_reset_result {
15871         cmdline_fixed_string_t ptype;
15872         cmdline_fixed_string_t mapping;
15873         cmdline_fixed_string_t reset;
15874         portid_t port_id;
15875 };
15876
15877 /* Common CLI fields for ptype mapping reset*/
15878 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15879         TOKEN_STRING_INITIALIZER
15880                 (struct cmd_ptype_mapping_reset_result,
15881                  ptype, "ptype");
15882 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15883         TOKEN_STRING_INITIALIZER
15884                 (struct cmd_ptype_mapping_reset_result,
15885                  mapping, "mapping");
15886 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15887         TOKEN_STRING_INITIALIZER
15888                 (struct cmd_ptype_mapping_reset_result,
15889                  reset, "reset");
15890 static cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15891         TOKEN_NUM_INITIALIZER
15892                 (struct cmd_ptype_mapping_reset_result,
15893                  port_id, RTE_UINT16);
15894
15895 static void
15896 cmd_ptype_mapping_reset_parsed(
15897         void *parsed_result,
15898         __rte_unused struct cmdline *cl,
15899         __rte_unused void *data)
15900 {
15901         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15902         int ret = -ENOTSUP;
15903
15904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15905                 return;
15906
15907 #ifdef RTE_NET_I40E
15908         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15909 #endif
15910
15911         switch (ret) {
15912         case 0:
15913                 break;
15914         case -ENODEV:
15915                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15916                 break;
15917         case -ENOTSUP:
15918                 fprintf(stderr, "function not implemented\n");
15919                 break;
15920         default:
15921                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15922         }
15923 }
15924
15925 static cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15926         .f = cmd_ptype_mapping_reset_parsed,
15927         .data = NULL,
15928         .help_str = "ptype mapping reset <port_id>",
15929         .tokens = {
15930                 (void *)&cmd_ptype_mapping_reset_ptype,
15931                 (void *)&cmd_ptype_mapping_reset_mapping,
15932                 (void *)&cmd_ptype_mapping_reset_reset,
15933                 (void *)&cmd_ptype_mapping_reset_port_id,
15934                 NULL,
15935         },
15936 };
15937
15938 /* ptype mapping update */
15939
15940 /* Common result structure for ptype mapping update */
15941 struct cmd_ptype_mapping_update_result {
15942         cmdline_fixed_string_t ptype;
15943         cmdline_fixed_string_t mapping;
15944         cmdline_fixed_string_t reset;
15945         portid_t port_id;
15946         uint8_t hw_ptype;
15947         uint32_t sw_ptype;
15948 };
15949
15950 /* Common CLI fields for ptype mapping update*/
15951 static cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15952         TOKEN_STRING_INITIALIZER
15953                 (struct cmd_ptype_mapping_update_result,
15954                  ptype, "ptype");
15955 static cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15956         TOKEN_STRING_INITIALIZER
15957                 (struct cmd_ptype_mapping_update_result,
15958                  mapping, "mapping");
15959 static cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15960         TOKEN_STRING_INITIALIZER
15961                 (struct cmd_ptype_mapping_update_result,
15962                  reset, "update");
15963 static cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15964         TOKEN_NUM_INITIALIZER
15965                 (struct cmd_ptype_mapping_update_result,
15966                  port_id, RTE_UINT16);
15967 static cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15968         TOKEN_NUM_INITIALIZER
15969                 (struct cmd_ptype_mapping_update_result,
15970                  hw_ptype, RTE_UINT8);
15971 static cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15972         TOKEN_NUM_INITIALIZER
15973                 (struct cmd_ptype_mapping_update_result,
15974                  sw_ptype, RTE_UINT32);
15975
15976 static void
15977 cmd_ptype_mapping_update_parsed(
15978         void *parsed_result,
15979         __rte_unused struct cmdline *cl,
15980         __rte_unused void *data)
15981 {
15982         struct cmd_ptype_mapping_update_result *res = parsed_result;
15983         int ret = -ENOTSUP;
15984 #ifdef RTE_NET_I40E
15985         struct rte_pmd_i40e_ptype_mapping mapping;
15986 #endif
15987         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15988                 return;
15989
15990 #ifdef RTE_NET_I40E
15991         mapping.hw_ptype = res->hw_ptype;
15992         mapping.sw_ptype = res->sw_ptype;
15993         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15994                                                 &mapping,
15995                                                 1,
15996                                                 0);
15997 #endif
15998
15999         switch (ret) {
16000         case 0:
16001                 break;
16002         case -EINVAL:
16003                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
16004                 break;
16005         case -ENODEV:
16006                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
16007                 break;
16008         case -ENOTSUP:
16009                 fprintf(stderr, "function not implemented\n");
16010                 break;
16011         default:
16012                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
16013         }
16014 }
16015
16016 static cmdline_parse_inst_t cmd_ptype_mapping_update = {
16017         .f = cmd_ptype_mapping_update_parsed,
16018         .data = NULL,
16019         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16020         .tokens = {
16021                 (void *)&cmd_ptype_mapping_update_ptype,
16022                 (void *)&cmd_ptype_mapping_update_mapping,
16023                 (void *)&cmd_ptype_mapping_update_update,
16024                 (void *)&cmd_ptype_mapping_update_port_id,
16025                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16026                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16027                 NULL,
16028         },
16029 };
16030
16031 /* Common result structure for file commands */
16032 struct cmd_cmdfile_result {
16033         cmdline_fixed_string_t load;
16034         cmdline_fixed_string_t filename;
16035 };
16036
16037 /* Common CLI fields for file commands */
16038 static cmdline_parse_token_string_t cmd_load_cmdfile =
16039         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16040 static cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16041         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16042
16043 static void
16044 cmd_load_from_file_parsed(
16045         void *parsed_result,
16046         __rte_unused struct cmdline *cl,
16047         __rte_unused void *data)
16048 {
16049         struct cmd_cmdfile_result *res = parsed_result;
16050
16051         cmdline_read_from_file(res->filename);
16052 }
16053
16054 static cmdline_parse_inst_t cmd_load_from_file = {
16055         .f = cmd_load_from_file_parsed,
16056         .data = NULL,
16057         .help_str = "load <filename>",
16058         .tokens = {
16059                 (void *)&cmd_load_cmdfile,
16060                 (void *)&cmd_load_cmdfile_filename,
16061                 NULL,
16062         },
16063 };
16064
16065 /* Get Rx offloads capabilities */
16066 struct cmd_rx_offload_get_capa_result {
16067         cmdline_fixed_string_t show;
16068         cmdline_fixed_string_t port;
16069         portid_t port_id;
16070         cmdline_fixed_string_t rx_offload;
16071         cmdline_fixed_string_t capabilities;
16072 };
16073
16074 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16075         TOKEN_STRING_INITIALIZER
16076                 (struct cmd_rx_offload_get_capa_result,
16077                  show, "show");
16078 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16079         TOKEN_STRING_INITIALIZER
16080                 (struct cmd_rx_offload_get_capa_result,
16081                  port, "port");
16082 static cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16083         TOKEN_NUM_INITIALIZER
16084                 (struct cmd_rx_offload_get_capa_result,
16085                  port_id, RTE_UINT16);
16086 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16087         TOKEN_STRING_INITIALIZER
16088                 (struct cmd_rx_offload_get_capa_result,
16089                  rx_offload, "rx_offload");
16090 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16091         TOKEN_STRING_INITIALIZER
16092                 (struct cmd_rx_offload_get_capa_result,
16093                  capabilities, "capabilities");
16094
16095 static void
16096 print_rx_offloads(uint64_t offloads)
16097 {
16098         uint64_t single_offload;
16099         int begin;
16100         int end;
16101         int bit;
16102
16103         if (offloads == 0)
16104                 return;
16105
16106         begin = __builtin_ctzll(offloads);
16107         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16108
16109         single_offload = 1ULL << begin;
16110         for (bit = begin; bit < end; bit++) {
16111                 if (offloads & single_offload)
16112                         printf(" %s",
16113                                rte_eth_dev_rx_offload_name(single_offload));
16114                 single_offload <<= 1;
16115         }
16116 }
16117
16118 static void
16119 cmd_rx_offload_get_capa_parsed(
16120         void *parsed_result,
16121         __rte_unused struct cmdline *cl,
16122         __rte_unused void *data)
16123 {
16124         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16125         struct rte_eth_dev_info dev_info;
16126         portid_t port_id = res->port_id;
16127         uint64_t queue_offloads;
16128         uint64_t port_offloads;
16129         int ret;
16130
16131         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16132         if (ret != 0)
16133                 return;
16134
16135         queue_offloads = dev_info.rx_queue_offload_capa;
16136         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16137
16138         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16139         printf("  Per Queue :");
16140         print_rx_offloads(queue_offloads);
16141
16142         printf("\n");
16143         printf("  Per Port  :");
16144         print_rx_offloads(port_offloads);
16145         printf("\n\n");
16146 }
16147
16148 static cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16149         .f = cmd_rx_offload_get_capa_parsed,
16150         .data = NULL,
16151         .help_str = "show port <port_id> rx_offload capabilities",
16152         .tokens = {
16153                 (void *)&cmd_rx_offload_get_capa_show,
16154                 (void *)&cmd_rx_offload_get_capa_port,
16155                 (void *)&cmd_rx_offload_get_capa_port_id,
16156                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16157                 (void *)&cmd_rx_offload_get_capa_capabilities,
16158                 NULL,
16159         }
16160 };
16161
16162 /* Get Rx offloads configuration */
16163 struct cmd_rx_offload_get_configuration_result {
16164         cmdline_fixed_string_t show;
16165         cmdline_fixed_string_t port;
16166         portid_t port_id;
16167         cmdline_fixed_string_t rx_offload;
16168         cmdline_fixed_string_t configuration;
16169 };
16170
16171 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16172         TOKEN_STRING_INITIALIZER
16173                 (struct cmd_rx_offload_get_configuration_result,
16174                  show, "show");
16175 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16176         TOKEN_STRING_INITIALIZER
16177                 (struct cmd_rx_offload_get_configuration_result,
16178                  port, "port");
16179 static cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16180         TOKEN_NUM_INITIALIZER
16181                 (struct cmd_rx_offload_get_configuration_result,
16182                  port_id, RTE_UINT16);
16183 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16184         TOKEN_STRING_INITIALIZER
16185                 (struct cmd_rx_offload_get_configuration_result,
16186                  rx_offload, "rx_offload");
16187 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16188         TOKEN_STRING_INITIALIZER
16189                 (struct cmd_rx_offload_get_configuration_result,
16190                  configuration, "configuration");
16191
16192 static void
16193 cmd_rx_offload_get_configuration_parsed(
16194         void *parsed_result,
16195         __rte_unused struct cmdline *cl,
16196         __rte_unused void *data)
16197 {
16198         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16199         struct rte_eth_dev_info dev_info;
16200         portid_t port_id = res->port_id;
16201         struct rte_port *port = &ports[port_id];
16202         struct rte_eth_conf dev_conf;
16203         uint64_t port_offloads;
16204         uint64_t queue_offloads;
16205         uint16_t nb_rx_queues;
16206         int q;
16207         int ret;
16208
16209         printf("Rx Offloading Configuration of port %d :\n", port_id);
16210
16211         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16212         if (ret != 0)
16213                 return;
16214
16215         port_offloads = dev_conf.rxmode.offloads;
16216         printf("  Port :");
16217         print_rx_offloads(port_offloads);
16218         printf("\n");
16219
16220         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16221         if (ret != 0)
16222                 return;
16223
16224         nb_rx_queues = dev_info.nb_rx_queues;
16225         for (q = 0; q < nb_rx_queues; q++) {
16226                 queue_offloads = port->rxq[q].conf.offloads;
16227                 printf("  Queue[%2d] :", q);
16228                 print_rx_offloads(queue_offloads);
16229                 printf("\n");
16230         }
16231         printf("\n");
16232 }
16233
16234 static cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16235         .f = cmd_rx_offload_get_configuration_parsed,
16236         .data = NULL,
16237         .help_str = "show port <port_id> rx_offload configuration",
16238         .tokens = {
16239                 (void *)&cmd_rx_offload_get_configuration_show,
16240                 (void *)&cmd_rx_offload_get_configuration_port,
16241                 (void *)&cmd_rx_offload_get_configuration_port_id,
16242                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16243                 (void *)&cmd_rx_offload_get_configuration_configuration,
16244                 NULL,
16245         }
16246 };
16247
16248 /* Enable/Disable a per port offloading */
16249 struct cmd_config_per_port_rx_offload_result {
16250         cmdline_fixed_string_t port;
16251         cmdline_fixed_string_t config;
16252         portid_t port_id;
16253         cmdline_fixed_string_t rx_offload;
16254         cmdline_fixed_string_t offload;
16255         cmdline_fixed_string_t on_off;
16256 };
16257
16258 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16259         TOKEN_STRING_INITIALIZER
16260                 (struct cmd_config_per_port_rx_offload_result,
16261                  port, "port");
16262 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16263         TOKEN_STRING_INITIALIZER
16264                 (struct cmd_config_per_port_rx_offload_result,
16265                  config, "config");
16266 static cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16267         TOKEN_NUM_INITIALIZER
16268                 (struct cmd_config_per_port_rx_offload_result,
16269                  port_id, RTE_UINT16);
16270 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16271         TOKEN_STRING_INITIALIZER
16272                 (struct cmd_config_per_port_rx_offload_result,
16273                  rx_offload, "rx_offload");
16274 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16275         TOKEN_STRING_INITIALIZER
16276                 (struct cmd_config_per_port_rx_offload_result,
16277                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16278                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16279                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16280                            "scatter#buffer_split#timestamp#security#"
16281                            "keep_crc#rss_hash");
16282 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16283         TOKEN_STRING_INITIALIZER
16284                 (struct cmd_config_per_port_rx_offload_result,
16285                  on_off, "on#off");
16286
16287 static uint64_t
16288 search_rx_offload(const char *name)
16289 {
16290         uint64_t single_offload;
16291         const char *single_name;
16292         int found = 0;
16293         unsigned int bit;
16294
16295         single_offload = 1;
16296         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16297                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16298                 if (!strcasecmp(single_name, name)) {
16299                         found = 1;
16300                         break;
16301                 }
16302                 single_offload <<= 1;
16303         }
16304
16305         if (found)
16306                 return single_offload;
16307
16308         return 0;
16309 }
16310
16311 static void
16312 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16313                                 __rte_unused struct cmdline *cl,
16314                                 __rte_unused void *data)
16315 {
16316         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16317         portid_t port_id = res->port_id;
16318         struct rte_eth_dev_info dev_info;
16319         struct rte_port *port = &ports[port_id];
16320         uint64_t single_offload;
16321         uint16_t nb_rx_queues;
16322         int q;
16323         int ret;
16324
16325         if (port->port_status != RTE_PORT_STOPPED) {
16326                 fprintf(stderr,
16327                         "Error: Can't config offload when Port %d is not stopped\n",
16328                         port_id);
16329                 return;
16330         }
16331
16332         single_offload = search_rx_offload(res->offload);
16333         if (single_offload == 0) {
16334                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16335                 return;
16336         }
16337
16338         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16339         if (ret != 0)
16340                 return;
16341
16342         nb_rx_queues = dev_info.nb_rx_queues;
16343         if (!strcmp(res->on_off, "on")) {
16344                 port->dev_conf.rxmode.offloads |= single_offload;
16345                 for (q = 0; q < nb_rx_queues; q++)
16346                         port->rxq[q].conf.offloads |= single_offload;
16347         } else {
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         }
16352
16353         cmd_reconfig_device_queue(port_id, 1, 1);
16354 }
16355
16356 static cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16357         .f = cmd_config_per_port_rx_offload_parsed,
16358         .data = NULL,
16359         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16360                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16361                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16362                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16363                     "keep_crc|rss_hash on|off",
16364         .tokens = {
16365                 (void *)&cmd_config_per_port_rx_offload_result_port,
16366                 (void *)&cmd_config_per_port_rx_offload_result_config,
16367                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16368                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16369                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16370                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16371                 NULL,
16372         }
16373 };
16374
16375 /* Enable/Disable a per queue offloading */
16376 struct cmd_config_per_queue_rx_offload_result {
16377         cmdline_fixed_string_t port;
16378         portid_t port_id;
16379         cmdline_fixed_string_t rxq;
16380         uint16_t queue_id;
16381         cmdline_fixed_string_t rx_offload;
16382         cmdline_fixed_string_t offload;
16383         cmdline_fixed_string_t on_off;
16384 };
16385
16386 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16387         TOKEN_STRING_INITIALIZER
16388                 (struct cmd_config_per_queue_rx_offload_result,
16389                  port, "port");
16390 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16391         TOKEN_NUM_INITIALIZER
16392                 (struct cmd_config_per_queue_rx_offload_result,
16393                  port_id, RTE_UINT16);
16394 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16395         TOKEN_STRING_INITIALIZER
16396                 (struct cmd_config_per_queue_rx_offload_result,
16397                  rxq, "rxq");
16398 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16399         TOKEN_NUM_INITIALIZER
16400                 (struct cmd_config_per_queue_rx_offload_result,
16401                  queue_id, RTE_UINT16);
16402 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16403         TOKEN_STRING_INITIALIZER
16404                 (struct cmd_config_per_queue_rx_offload_result,
16405                  rx_offload, "rx_offload");
16406 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16407         TOKEN_STRING_INITIALIZER
16408                 (struct cmd_config_per_queue_rx_offload_result,
16409                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16410                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16411                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16412                            "scatter#buffer_split#timestamp#security#keep_crc");
16413 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16414         TOKEN_STRING_INITIALIZER
16415                 (struct cmd_config_per_queue_rx_offload_result,
16416                  on_off, "on#off");
16417
16418 static void
16419 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16420                                 __rte_unused struct cmdline *cl,
16421                                 __rte_unused void *data)
16422 {
16423         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16424         struct rte_eth_dev_info dev_info;
16425         portid_t port_id = res->port_id;
16426         uint16_t queue_id = res->queue_id;
16427         struct rte_port *port = &ports[port_id];
16428         uint64_t single_offload;
16429         int ret;
16430
16431         if (port->port_status != RTE_PORT_STOPPED) {
16432                 fprintf(stderr,
16433                         "Error: Can't config offload when Port %d is not stopped\n",
16434                         port_id);
16435                 return;
16436         }
16437
16438         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16439         if (ret != 0)
16440                 return;
16441
16442         if (queue_id >= dev_info.nb_rx_queues) {
16443                 fprintf(stderr,
16444                         "Error: input queue_id should be 0 ... %d\n",
16445                         dev_info.nb_rx_queues - 1);
16446                 return;
16447         }
16448
16449         single_offload = search_rx_offload(res->offload);
16450         if (single_offload == 0) {
16451                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16452                 return;
16453         }
16454
16455         if (!strcmp(res->on_off, "on"))
16456                 port->rxq[queue_id].conf.offloads |= single_offload;
16457         else
16458                 port->rxq[queue_id].conf.offloads &= ~single_offload;
16459
16460         cmd_reconfig_device_queue(port_id, 1, 1);
16461 }
16462
16463 static cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16464         .f = cmd_config_per_queue_rx_offload_parsed,
16465         .data = NULL,
16466         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16467                     "vlan_strip|ipv4_cksum|"
16468                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16469                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16470                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16471                     "keep_crc on|off",
16472         .tokens = {
16473                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16474                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16475                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16476                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16477                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16478                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16479                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16480                 NULL,
16481         }
16482 };
16483
16484 /* Get Tx offloads capabilities */
16485 struct cmd_tx_offload_get_capa_result {
16486         cmdline_fixed_string_t show;
16487         cmdline_fixed_string_t port;
16488         portid_t port_id;
16489         cmdline_fixed_string_t tx_offload;
16490         cmdline_fixed_string_t capabilities;
16491 };
16492
16493 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16494         TOKEN_STRING_INITIALIZER
16495                 (struct cmd_tx_offload_get_capa_result,
16496                  show, "show");
16497 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16498         TOKEN_STRING_INITIALIZER
16499                 (struct cmd_tx_offload_get_capa_result,
16500                  port, "port");
16501 static cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16502         TOKEN_NUM_INITIALIZER
16503                 (struct cmd_tx_offload_get_capa_result,
16504                  port_id, RTE_UINT16);
16505 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16506         TOKEN_STRING_INITIALIZER
16507                 (struct cmd_tx_offload_get_capa_result,
16508                  tx_offload, "tx_offload");
16509 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16510         TOKEN_STRING_INITIALIZER
16511                 (struct cmd_tx_offload_get_capa_result,
16512                  capabilities, "capabilities");
16513
16514 static void
16515 print_tx_offloads(uint64_t offloads)
16516 {
16517         uint64_t single_offload;
16518         int begin;
16519         int end;
16520         int bit;
16521
16522         if (offloads == 0)
16523                 return;
16524
16525         begin = __builtin_ctzll(offloads);
16526         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16527
16528         single_offload = 1ULL << begin;
16529         for (bit = begin; bit < end; bit++) {
16530                 if (offloads & single_offload)
16531                         printf(" %s",
16532                                rte_eth_dev_tx_offload_name(single_offload));
16533                 single_offload <<= 1;
16534         }
16535 }
16536
16537 static void
16538 cmd_tx_offload_get_capa_parsed(
16539         void *parsed_result,
16540         __rte_unused struct cmdline *cl,
16541         __rte_unused void *data)
16542 {
16543         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16544         struct rte_eth_dev_info dev_info;
16545         portid_t port_id = res->port_id;
16546         uint64_t queue_offloads;
16547         uint64_t port_offloads;
16548         int ret;
16549
16550         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16551         if (ret != 0)
16552                 return;
16553
16554         queue_offloads = dev_info.tx_queue_offload_capa;
16555         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16556
16557         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16558         printf("  Per Queue :");
16559         print_tx_offloads(queue_offloads);
16560
16561         printf("\n");
16562         printf("  Per Port  :");
16563         print_tx_offloads(port_offloads);
16564         printf("\n\n");
16565 }
16566
16567 static cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16568         .f = cmd_tx_offload_get_capa_parsed,
16569         .data = NULL,
16570         .help_str = "show port <port_id> tx_offload capabilities",
16571         .tokens = {
16572                 (void *)&cmd_tx_offload_get_capa_show,
16573                 (void *)&cmd_tx_offload_get_capa_port,
16574                 (void *)&cmd_tx_offload_get_capa_port_id,
16575                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16576                 (void *)&cmd_tx_offload_get_capa_capabilities,
16577                 NULL,
16578         }
16579 };
16580
16581 /* Get Tx offloads configuration */
16582 struct cmd_tx_offload_get_configuration_result {
16583         cmdline_fixed_string_t show;
16584         cmdline_fixed_string_t port;
16585         portid_t port_id;
16586         cmdline_fixed_string_t tx_offload;
16587         cmdline_fixed_string_t configuration;
16588 };
16589
16590 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16591         TOKEN_STRING_INITIALIZER
16592                 (struct cmd_tx_offload_get_configuration_result,
16593                  show, "show");
16594 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16595         TOKEN_STRING_INITIALIZER
16596                 (struct cmd_tx_offload_get_configuration_result,
16597                  port, "port");
16598 static cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16599         TOKEN_NUM_INITIALIZER
16600                 (struct cmd_tx_offload_get_configuration_result,
16601                  port_id, RTE_UINT16);
16602 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16603         TOKEN_STRING_INITIALIZER
16604                 (struct cmd_tx_offload_get_configuration_result,
16605                  tx_offload, "tx_offload");
16606 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16607         TOKEN_STRING_INITIALIZER
16608                 (struct cmd_tx_offload_get_configuration_result,
16609                  configuration, "configuration");
16610
16611 static void
16612 cmd_tx_offload_get_configuration_parsed(
16613         void *parsed_result,
16614         __rte_unused struct cmdline *cl,
16615         __rte_unused void *data)
16616 {
16617         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16618         struct rte_eth_dev_info dev_info;
16619         portid_t port_id = res->port_id;
16620         struct rte_port *port = &ports[port_id];
16621         struct rte_eth_conf dev_conf;
16622         uint64_t port_offloads;
16623         uint64_t queue_offloads;
16624         uint16_t nb_tx_queues;
16625         int q;
16626         int ret;
16627
16628         printf("Tx Offloading Configuration of port %d :\n", port_id);
16629
16630         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16631         if (ret != 0)
16632                 return;
16633
16634         port_offloads = dev_conf.txmode.offloads;
16635         printf("  Port :");
16636         print_tx_offloads(port_offloads);
16637         printf("\n");
16638
16639         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16640         if (ret != 0)
16641                 return;
16642
16643         nb_tx_queues = dev_info.nb_tx_queues;
16644         for (q = 0; q < nb_tx_queues; q++) {
16645                 queue_offloads = port->txq[q].conf.offloads;
16646                 printf("  Queue[%2d] :", q);
16647                 print_tx_offloads(queue_offloads);
16648                 printf("\n");
16649         }
16650         printf("\n");
16651 }
16652
16653 static cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16654         .f = cmd_tx_offload_get_configuration_parsed,
16655         .data = NULL,
16656         .help_str = "show port <port_id> tx_offload configuration",
16657         .tokens = {
16658                 (void *)&cmd_tx_offload_get_configuration_show,
16659                 (void *)&cmd_tx_offload_get_configuration_port,
16660                 (void *)&cmd_tx_offload_get_configuration_port_id,
16661                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16662                 (void *)&cmd_tx_offload_get_configuration_configuration,
16663                 NULL,
16664         }
16665 };
16666
16667 /* Enable/Disable a per port offloading */
16668 struct cmd_config_per_port_tx_offload_result {
16669         cmdline_fixed_string_t port;
16670         cmdline_fixed_string_t config;
16671         portid_t port_id;
16672         cmdline_fixed_string_t tx_offload;
16673         cmdline_fixed_string_t offload;
16674         cmdline_fixed_string_t on_off;
16675 };
16676
16677 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16678         TOKEN_STRING_INITIALIZER
16679                 (struct cmd_config_per_port_tx_offload_result,
16680                  port, "port");
16681 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16682         TOKEN_STRING_INITIALIZER
16683                 (struct cmd_config_per_port_tx_offload_result,
16684                  config, "config");
16685 static cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16686         TOKEN_NUM_INITIALIZER
16687                 (struct cmd_config_per_port_tx_offload_result,
16688                  port_id, RTE_UINT16);
16689 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16690         TOKEN_STRING_INITIALIZER
16691                 (struct cmd_config_per_port_tx_offload_result,
16692                  tx_offload, "tx_offload");
16693 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16694         TOKEN_STRING_INITIALIZER
16695                 (struct cmd_config_per_port_tx_offload_result,
16696                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16697                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16698                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16699                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16700                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16701                           "send_on_timestamp");
16702 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16703         TOKEN_STRING_INITIALIZER
16704                 (struct cmd_config_per_port_tx_offload_result,
16705                  on_off, "on#off");
16706
16707 static uint64_t
16708 search_tx_offload(const char *name)
16709 {
16710         uint64_t single_offload;
16711         const char *single_name;
16712         int found = 0;
16713         unsigned int bit;
16714
16715         single_offload = 1;
16716         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16717                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16718                 if (single_name == NULL)
16719                         break;
16720                 if (!strcasecmp(single_name, name)) {
16721                         found = 1;
16722                         break;
16723                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16724                         break;
16725                 single_offload <<= 1;
16726         }
16727
16728         if (found)
16729                 return single_offload;
16730
16731         return 0;
16732 }
16733
16734 static void
16735 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16736                                 __rte_unused struct cmdline *cl,
16737                                 __rte_unused void *data)
16738 {
16739         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16740         portid_t port_id = res->port_id;
16741         struct rte_eth_dev_info dev_info;
16742         struct rte_port *port = &ports[port_id];
16743         uint64_t single_offload;
16744         uint16_t nb_tx_queues;
16745         int q;
16746         int ret;
16747
16748         if (port->port_status != RTE_PORT_STOPPED) {
16749                 fprintf(stderr,
16750                         "Error: Can't config offload when Port %d is not stopped\n",
16751                         port_id);
16752                 return;
16753         }
16754
16755         single_offload = search_tx_offload(res->offload);
16756         if (single_offload == 0) {
16757                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16758                 return;
16759         }
16760
16761         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16762         if (ret != 0)
16763                 return;
16764
16765         nb_tx_queues = dev_info.nb_tx_queues;
16766         if (!strcmp(res->on_off, "on")) {
16767                 port->dev_conf.txmode.offloads |= single_offload;
16768                 for (q = 0; q < nb_tx_queues; q++)
16769                         port->txq[q].conf.offloads |= single_offload;
16770         } else {
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         }
16775
16776         cmd_reconfig_device_queue(port_id, 1, 1);
16777 }
16778
16779 static cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16780         .f = cmd_config_per_port_tx_offload_parsed,
16781         .data = NULL,
16782         .help_str = "port config <port_id> tx_offload "
16783                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16784                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16785                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16786                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16787                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16788                     "send_on_timestamp on|off",
16789         .tokens = {
16790                 (void *)&cmd_config_per_port_tx_offload_result_port,
16791                 (void *)&cmd_config_per_port_tx_offload_result_config,
16792                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16793                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16794                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16795                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16796                 NULL,
16797         }
16798 };
16799
16800 /* Enable/Disable a per queue offloading */
16801 struct cmd_config_per_queue_tx_offload_result {
16802         cmdline_fixed_string_t port;
16803         portid_t port_id;
16804         cmdline_fixed_string_t txq;
16805         uint16_t queue_id;
16806         cmdline_fixed_string_t tx_offload;
16807         cmdline_fixed_string_t offload;
16808         cmdline_fixed_string_t on_off;
16809 };
16810
16811 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16812         TOKEN_STRING_INITIALIZER
16813                 (struct cmd_config_per_queue_tx_offload_result,
16814                  port, "port");
16815 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16816         TOKEN_NUM_INITIALIZER
16817                 (struct cmd_config_per_queue_tx_offload_result,
16818                  port_id, RTE_UINT16);
16819 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16820         TOKEN_STRING_INITIALIZER
16821                 (struct cmd_config_per_queue_tx_offload_result,
16822                  txq, "txq");
16823 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16824         TOKEN_NUM_INITIALIZER
16825                 (struct cmd_config_per_queue_tx_offload_result,
16826                  queue_id, RTE_UINT16);
16827 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16828         TOKEN_STRING_INITIALIZER
16829                 (struct cmd_config_per_queue_tx_offload_result,
16830                  tx_offload, "tx_offload");
16831 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16832         TOKEN_STRING_INITIALIZER
16833                 (struct cmd_config_per_queue_tx_offload_result,
16834                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16835                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16836                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16837                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16838                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16839 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16840         TOKEN_STRING_INITIALIZER
16841                 (struct cmd_config_per_queue_tx_offload_result,
16842                  on_off, "on#off");
16843
16844 static void
16845 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16846                                 __rte_unused struct cmdline *cl,
16847                                 __rte_unused void *data)
16848 {
16849         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16850         struct rte_eth_dev_info dev_info;
16851         portid_t port_id = res->port_id;
16852         uint16_t queue_id = res->queue_id;
16853         struct rte_port *port = &ports[port_id];
16854         uint64_t single_offload;
16855         int ret;
16856
16857         if (port->port_status != RTE_PORT_STOPPED) {
16858                 fprintf(stderr,
16859                         "Error: Can't config offload when Port %d is not stopped\n",
16860                         port_id);
16861                 return;
16862         }
16863
16864         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16865         if (ret != 0)
16866                 return;
16867
16868         if (queue_id >= dev_info.nb_tx_queues) {
16869                 fprintf(stderr,
16870                         "Error: input queue_id should be 0 ... %d\n",
16871                         dev_info.nb_tx_queues - 1);
16872                 return;
16873         }
16874
16875         single_offload = search_tx_offload(res->offload);
16876         if (single_offload == 0) {
16877                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16878                 return;
16879         }
16880
16881         if (!strcmp(res->on_off, "on"))
16882                 port->txq[queue_id].conf.offloads |= single_offload;
16883         else
16884                 port->txq[queue_id].conf.offloads &= ~single_offload;
16885
16886         cmd_reconfig_device_queue(port_id, 1, 1);
16887 }
16888
16889 static cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16890         .f = cmd_config_per_queue_tx_offload_parsed,
16891         .data = NULL,
16892         .help_str = "port <port_id> txq <queue_id> tx_offload "
16893                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16894                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16895                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16896                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16897                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16898                     "on|off",
16899         .tokens = {
16900                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16901                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16902                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16903                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16904                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16905                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16906                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16907                 NULL,
16908         }
16909 };
16910
16911 /* *** configure tx_metadata for specific port *** */
16912 struct cmd_config_tx_metadata_specific_result {
16913         cmdline_fixed_string_t port;
16914         cmdline_fixed_string_t keyword;
16915         uint16_t port_id;
16916         cmdline_fixed_string_t item;
16917         uint32_t value;
16918 };
16919
16920 static void
16921 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16922                                 __rte_unused struct cmdline *cl,
16923                                 __rte_unused void *data)
16924 {
16925         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16926
16927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16928                 return;
16929         ports[res->port_id].tx_metadata = res->value;
16930         /* Add/remove callback to insert valid metadata in every Tx packet. */
16931         if (ports[res->port_id].tx_metadata)
16932                 add_tx_md_callback(res->port_id);
16933         else
16934                 remove_tx_md_callback(res->port_id);
16935         rte_flow_dynf_metadata_register();
16936 }
16937
16938 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16939         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16940                         port, "port");
16941 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16942         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16943                         keyword, "config");
16944 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16945         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16946                         port_id, RTE_UINT16);
16947 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16948         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16949                         item, "tx_metadata");
16950 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16951         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16952                         value, RTE_UINT32);
16953
16954 static cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16955         .f = cmd_config_tx_metadata_specific_parsed,
16956         .data = NULL,
16957         .help_str = "port config <port_id> tx_metadata <value>",
16958         .tokens = {
16959                 (void *)&cmd_config_tx_metadata_specific_port,
16960                 (void *)&cmd_config_tx_metadata_specific_keyword,
16961                 (void *)&cmd_config_tx_metadata_specific_id,
16962                 (void *)&cmd_config_tx_metadata_specific_item,
16963                 (void *)&cmd_config_tx_metadata_specific_value,
16964                 NULL,
16965         },
16966 };
16967
16968 /* *** set dynf *** */
16969 struct cmd_config_tx_dynf_specific_result {
16970         cmdline_fixed_string_t port;
16971         cmdline_fixed_string_t keyword;
16972         uint16_t port_id;
16973         cmdline_fixed_string_t item;
16974         cmdline_fixed_string_t name;
16975         cmdline_fixed_string_t value;
16976 };
16977
16978 static void
16979 cmd_config_dynf_specific_parsed(void *parsed_result,
16980                                 __rte_unused struct cmdline *cl,
16981                                 __rte_unused void *data)
16982 {
16983         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16984         struct rte_mbuf_dynflag desc_flag;
16985         int flag;
16986         uint64_t old_port_flags;
16987
16988         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16989                 return;
16990         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16991         if (flag <= 0) {
16992                 if (strlcpy(desc_flag.name, res->name,
16993                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16994                         fprintf(stderr, "Flag name too long\n");
16995                         return;
16996                 }
16997                 desc_flag.flags = 0;
16998                 flag = rte_mbuf_dynflag_register(&desc_flag);
16999                 if (flag < 0) {
17000                         fprintf(stderr, "Can't register flag\n");
17001                         return;
17002                 }
17003                 strcpy(dynf_names[flag], desc_flag.name);
17004         }
17005         old_port_flags = ports[res->port_id].mbuf_dynf;
17006         if (!strcmp(res->value, "set")) {
17007                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
17008                 if (old_port_flags == 0)
17009                         add_tx_dynf_callback(res->port_id);
17010         } else {
17011                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
17012                 if (ports[res->port_id].mbuf_dynf == 0)
17013                         remove_tx_dynf_callback(res->port_id);
17014         }
17015 }
17016
17017 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17018         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17019                         keyword, "port");
17020 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17021         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17022                         keyword, "config");
17023 static cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17024         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17025                         port_id, RTE_UINT16);
17026 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17027         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17028                         item, "dynf");
17029 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17030         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17031                         name, NULL);
17032 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17033         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17034                         value, "set#clear");
17035
17036 static cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17037         .f = cmd_config_dynf_specific_parsed,
17038         .data = NULL,
17039         .help_str = "port config <port id> dynf <name> set|clear",
17040         .tokens = {
17041                 (void *)&cmd_config_tx_dynf_specific_port,
17042                 (void *)&cmd_config_tx_dynf_specific_keyword,
17043                 (void *)&cmd_config_tx_dynf_specific_port_id,
17044                 (void *)&cmd_config_tx_dynf_specific_item,
17045                 (void *)&cmd_config_tx_dynf_specific_name,
17046                 (void *)&cmd_config_tx_dynf_specific_value,
17047                 NULL,
17048         },
17049 };
17050
17051 /* *** display tx_metadata per port configuration *** */
17052 struct cmd_show_tx_metadata_result {
17053         cmdline_fixed_string_t cmd_show;
17054         cmdline_fixed_string_t cmd_port;
17055         cmdline_fixed_string_t cmd_keyword;
17056         portid_t cmd_pid;
17057 };
17058
17059 static void
17060 cmd_show_tx_metadata_parsed(void *parsed_result,
17061                 __rte_unused struct cmdline *cl,
17062                 __rte_unused void *data)
17063 {
17064         struct cmd_show_tx_metadata_result *res = parsed_result;
17065
17066         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17067                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17068                 return;
17069         }
17070         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17071                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17072                        ports[res->cmd_pid].tx_metadata);
17073         }
17074 }
17075
17076 static cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17077         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17078                         cmd_show, "show");
17079 static cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17080         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17081                         cmd_port, "port");
17082 static cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17083         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17084                         cmd_pid, RTE_UINT16);
17085 static cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17086         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17087                         cmd_keyword, "tx_metadata");
17088
17089 static cmdline_parse_inst_t cmd_show_tx_metadata = {
17090         .f = cmd_show_tx_metadata_parsed,
17091         .data = NULL,
17092         .help_str = "show port <port_id> tx_metadata",
17093         .tokens = {
17094                 (void *)&cmd_show_tx_metadata_show,
17095                 (void *)&cmd_show_tx_metadata_port,
17096                 (void *)&cmd_show_tx_metadata_pid,
17097                 (void *)&cmd_show_tx_metadata_keyword,
17098                 NULL,
17099         },
17100 };
17101
17102 /* *** show fec capability per port configuration *** */
17103 struct cmd_show_fec_capability_result {
17104         cmdline_fixed_string_t cmd_show;
17105         cmdline_fixed_string_t cmd_port;
17106         cmdline_fixed_string_t cmd_fec;
17107         cmdline_fixed_string_t cmd_keyword;
17108         portid_t cmd_pid;
17109 };
17110
17111 static void
17112 cmd_show_fec_capability_parsed(void *parsed_result,
17113                 __rte_unused struct cmdline *cl,
17114                 __rte_unused void *data)
17115 {
17116         struct cmd_show_fec_capability_result *res = parsed_result;
17117         struct rte_eth_fec_capa *speed_fec_capa;
17118         unsigned int num;
17119         int ret;
17120
17121         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17122                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17123                 return;
17124         }
17125
17126         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17127         if (ret == -ENOTSUP) {
17128                 fprintf(stderr, "Function not implemented\n");
17129                 return;
17130         } else if (ret < 0) {
17131                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17132                 return;
17133         }
17134
17135         num = (unsigned int)ret;
17136         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17137         if (speed_fec_capa == NULL) {
17138                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17139                 return;
17140         }
17141
17142         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17143         if (ret < 0) {
17144                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17145                 goto out;
17146         }
17147
17148         show_fec_capability(num, speed_fec_capa);
17149 out:
17150         free(speed_fec_capa);
17151 }
17152
17153 static cmdline_parse_token_string_t cmd_show_fec_capability_show =
17154         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17155                         cmd_show, "show");
17156 static cmdline_parse_token_string_t cmd_show_fec_capability_port =
17157         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17158                         cmd_port, "port");
17159 static cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17160         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17161                         cmd_pid, RTE_UINT16);
17162 static cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17163         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17164                         cmd_fec, "fec");
17165 static cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17166         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17167                         cmd_keyword, "capabilities");
17168
17169 static cmdline_parse_inst_t cmd_show_capability = {
17170         .f = cmd_show_fec_capability_parsed,
17171         .data = NULL,
17172         .help_str = "show port <port_id> fec capabilities",
17173         .tokens = {
17174                 (void *)&cmd_show_fec_capability_show,
17175                 (void *)&cmd_show_fec_capability_port,
17176                 (void *)&cmd_show_fec_capability_pid,
17177                 (void *)&cmd_show_fec_capability_fec,
17178                 (void *)&cmd_show_fec_capability_keyword,
17179                 NULL,
17180         },
17181 };
17182
17183 /* *** show fec mode per port configuration *** */
17184 struct cmd_show_fec_metadata_result {
17185         cmdline_fixed_string_t cmd_show;
17186         cmdline_fixed_string_t cmd_port;
17187         cmdline_fixed_string_t cmd_keyword;
17188         portid_t cmd_pid;
17189 };
17190
17191 static void
17192 cmd_show_fec_mode_parsed(void *parsed_result,
17193                 __rte_unused struct cmdline *cl,
17194                 __rte_unused void *data)
17195 {
17196 #define FEC_NAME_SIZE 16
17197         struct cmd_show_fec_metadata_result *res = parsed_result;
17198         uint32_t mode;
17199         char buf[FEC_NAME_SIZE];
17200         int ret;
17201
17202         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17203                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17204                 return;
17205         }
17206         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17207         if (ret == -ENOTSUP) {
17208                 fprintf(stderr, "Function not implemented\n");
17209                 return;
17210         } else if (ret < 0) {
17211                 fprintf(stderr, "Get FEC mode failed\n");
17212                 return;
17213         }
17214
17215         switch (mode) {
17216         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17217                 strlcpy(buf, "off", sizeof(buf));
17218                 break;
17219         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17220                 strlcpy(buf, "auto", sizeof(buf));
17221                 break;
17222         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17223                 strlcpy(buf, "baser", sizeof(buf));
17224                 break;
17225         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17226                 strlcpy(buf, "rs", sizeof(buf));
17227                 break;
17228         default:
17229                 return;
17230         }
17231
17232         printf("%s\n", buf);
17233 }
17234
17235 static cmdline_parse_token_string_t cmd_show_fec_mode_show =
17236         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17237                         cmd_show, "show");
17238 static cmdline_parse_token_string_t cmd_show_fec_mode_port =
17239         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17240                         cmd_port, "port");
17241 static cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17242         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17243                         cmd_pid, RTE_UINT16);
17244 static cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17245         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17246                         cmd_keyword, "fec_mode");
17247
17248 static cmdline_parse_inst_t cmd_show_fec_mode = {
17249         .f = cmd_show_fec_mode_parsed,
17250         .data = NULL,
17251         .help_str = "show port <port_id> fec_mode",
17252         .tokens = {
17253                 (void *)&cmd_show_fec_mode_show,
17254                 (void *)&cmd_show_fec_mode_port,
17255                 (void *)&cmd_show_fec_mode_pid,
17256                 (void *)&cmd_show_fec_mode_keyword,
17257                 NULL,
17258         },
17259 };
17260
17261 /* *** set fec mode per port configuration *** */
17262 struct cmd_set_port_fec_mode {
17263         cmdline_fixed_string_t set;
17264         cmdline_fixed_string_t port;
17265         portid_t port_id;
17266         cmdline_fixed_string_t fec_mode;
17267         cmdline_fixed_string_t fec_value;
17268 };
17269
17270 /* Common CLI fields for set fec mode */
17271 static cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17272         TOKEN_STRING_INITIALIZER
17273                 (struct cmd_set_port_fec_mode,
17274                  set, "set");
17275 static cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17276         TOKEN_STRING_INITIALIZER
17277                 (struct cmd_set_port_fec_mode,
17278                  port, "port");
17279 static cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17280         TOKEN_NUM_INITIALIZER
17281                 (struct cmd_set_port_fec_mode,
17282                  port_id, RTE_UINT16);
17283 static cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17284         TOKEN_STRING_INITIALIZER
17285                 (struct cmd_set_port_fec_mode,
17286                  fec_mode, "fec_mode");
17287 static cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17288         TOKEN_STRING_INITIALIZER
17289                 (struct cmd_set_port_fec_mode,
17290                  fec_value, NULL);
17291
17292 static void
17293 cmd_set_port_fec_mode_parsed(
17294         void *parsed_result,
17295         __rte_unused struct cmdline *cl,
17296         __rte_unused void *data)
17297 {
17298         struct cmd_set_port_fec_mode *res = parsed_result;
17299         uint16_t port_id = res->port_id;
17300         uint32_t fec_capa;
17301         int ret;
17302
17303         ret = parse_fec_mode(res->fec_value, &fec_capa);
17304         if (ret < 0) {
17305                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17306                                 res->fec_value, port_id);
17307                 return;
17308         }
17309
17310         ret = rte_eth_fec_set(port_id, fec_capa);
17311         if (ret == -ENOTSUP) {
17312                 fprintf(stderr, "Function not implemented\n");
17313                 return;
17314         } else if (ret < 0) {
17315                 fprintf(stderr, "Set FEC mode failed\n");
17316                 return;
17317         }
17318 }
17319
17320 static cmdline_parse_inst_t cmd_set_fec_mode = {
17321         .f = cmd_set_port_fec_mode_parsed,
17322         .data = NULL,
17323         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17324         .tokens = {
17325                 (void *)&cmd_set_port_fec_mode_set,
17326                 (void *)&cmd_set_port_fec_mode_port,
17327                 (void *)&cmd_set_port_fec_mode_port_id,
17328                 (void *)&cmd_set_port_fec_mode_str,
17329                 (void *)&cmd_set_port_fec_mode_value,
17330                 NULL,
17331         },
17332 };
17333
17334 /* show port supported ptypes */
17335
17336 /* Common result structure for show port ptypes */
17337 struct cmd_show_port_supported_ptypes_result {
17338         cmdline_fixed_string_t show;
17339         cmdline_fixed_string_t port;
17340         portid_t port_id;
17341         cmdline_fixed_string_t ptypes;
17342 };
17343
17344 /* Common CLI fields for show port ptypes */
17345 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17346         TOKEN_STRING_INITIALIZER
17347                 (struct cmd_show_port_supported_ptypes_result,
17348                  show, "show");
17349 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17350         TOKEN_STRING_INITIALIZER
17351                 (struct cmd_show_port_supported_ptypes_result,
17352                  port, "port");
17353 static cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17354         TOKEN_NUM_INITIALIZER
17355                 (struct cmd_show_port_supported_ptypes_result,
17356                  port_id, RTE_UINT16);
17357 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17358         TOKEN_STRING_INITIALIZER
17359                 (struct cmd_show_port_supported_ptypes_result,
17360                  ptypes, "ptypes");
17361
17362 static void
17363 cmd_show_port_supported_ptypes_parsed(
17364         void *parsed_result,
17365         __rte_unused struct cmdline *cl,
17366         __rte_unused void *data)
17367 {
17368 #define RSVD_PTYPE_MASK       0xf0000000
17369 #define MAX_PTYPES_PER_LAYER  16
17370 #define LTYPE_NAMESIZE        32
17371 #define PTYPE_NAMESIZE        256
17372         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17373         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17374         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17375         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17376         uint16_t port_id = res->port_id;
17377         int ret, i;
17378
17379         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17380         if (ret < 0)
17381                 return;
17382
17383         while (ptype_mask != RSVD_PTYPE_MASK) {
17384
17385                 switch (ptype_mask) {
17386                 case RTE_PTYPE_L2_MASK:
17387                         strlcpy(ltype, "L2", sizeof(ltype));
17388                         break;
17389                 case RTE_PTYPE_L3_MASK:
17390                         strlcpy(ltype, "L3", sizeof(ltype));
17391                         break;
17392                 case RTE_PTYPE_L4_MASK:
17393                         strlcpy(ltype, "L4", sizeof(ltype));
17394                         break;
17395                 case RTE_PTYPE_TUNNEL_MASK:
17396                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17397                         break;
17398                 case RTE_PTYPE_INNER_L2_MASK:
17399                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17400                         break;
17401                 case RTE_PTYPE_INNER_L3_MASK:
17402                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17403                         break;
17404                 case RTE_PTYPE_INNER_L4_MASK:
17405                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17406                         break;
17407                 default:
17408                         return;
17409                 }
17410
17411                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17412                                                        ptype_mask, ptypes,
17413                                                        MAX_PTYPES_PER_LAYER);
17414
17415                 if (ret > 0)
17416                         printf("Supported %s ptypes:\n", ltype);
17417                 else
17418                         printf("%s ptypes unsupported\n", ltype);
17419
17420                 for (i = 0; i < ret; ++i) {
17421                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17422                         printf("%s\n", buf);
17423                 }
17424
17425                 ptype_mask <<= 4;
17426         }
17427 }
17428
17429 static cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17430         .f = cmd_show_port_supported_ptypes_parsed,
17431         .data = NULL,
17432         .help_str = "show port <port_id> ptypes",
17433         .tokens = {
17434                 (void *)&cmd_show_port_supported_ptypes_show,
17435                 (void *)&cmd_show_port_supported_ptypes_port,
17436                 (void *)&cmd_show_port_supported_ptypes_port_id,
17437                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17438                 NULL,
17439         },
17440 };
17441
17442 /* *** display rx/tx descriptor status *** */
17443 struct cmd_show_rx_tx_desc_status_result {
17444         cmdline_fixed_string_t cmd_show;
17445         cmdline_fixed_string_t cmd_port;
17446         cmdline_fixed_string_t cmd_keyword;
17447         cmdline_fixed_string_t cmd_desc;
17448         cmdline_fixed_string_t cmd_status;
17449         portid_t cmd_pid;
17450         portid_t cmd_qid;
17451         portid_t cmd_did;
17452 };
17453
17454 static void
17455 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17456                 __rte_unused struct cmdline *cl,
17457                 __rte_unused void *data)
17458 {
17459         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17460         int rc;
17461
17462         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17463                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17464                 return;
17465         }
17466
17467         if (!strcmp(res->cmd_keyword, "rxq")) {
17468                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17469                                              res->cmd_did);
17470                 if (rc < 0) {
17471                         fprintf(stderr,
17472                                 "Invalid input: queue id = %d, desc id = %d\n",
17473                                 res->cmd_qid, res->cmd_did);
17474                         return;
17475                 }
17476                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17477                         printf("Desc status = AVAILABLE\n");
17478                 else if (rc == RTE_ETH_RX_DESC_DONE)
17479                         printf("Desc status = DONE\n");
17480                 else
17481                         printf("Desc status = UNAVAILABLE\n");
17482         } else if (!strcmp(res->cmd_keyword, "txq")) {
17483                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17484                                              res->cmd_did);
17485                 if (rc < 0) {
17486                         fprintf(stderr,
17487                                 "Invalid input: queue id = %d, desc id = %d\n",
17488                                 res->cmd_qid, res->cmd_did);
17489                         return;
17490                 }
17491                 if (rc == RTE_ETH_TX_DESC_FULL)
17492                         printf("Desc status = FULL\n");
17493                 else if (rc == RTE_ETH_TX_DESC_DONE)
17494                         printf("Desc status = DONE\n");
17495                 else
17496                         printf("Desc status = UNAVAILABLE\n");
17497         }
17498 }
17499
17500 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17501         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17502                         cmd_show, "show");
17503 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17504         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17505                         cmd_port, "port");
17506 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17507         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17508                         cmd_pid, RTE_UINT16);
17509 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17510         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17511                         cmd_keyword, "rxq#txq");
17512 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17513         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17514                         cmd_qid, RTE_UINT16);
17515 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17516         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17517                         cmd_desc, "desc");
17518 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17519         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17520                         cmd_did, RTE_UINT16);
17521 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17522         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17523                         cmd_status, "status");
17524 static cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17525         .f = cmd_show_rx_tx_desc_status_parsed,
17526         .data = NULL,
17527         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17528                 "status",
17529         .tokens = {
17530                 (void *)&cmd_show_rx_tx_desc_status_show,
17531                 (void *)&cmd_show_rx_tx_desc_status_port,
17532                 (void *)&cmd_show_rx_tx_desc_status_pid,
17533                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17534                 (void *)&cmd_show_rx_tx_desc_status_qid,
17535                 (void *)&cmd_show_rx_tx_desc_status_desc,
17536                 (void *)&cmd_show_rx_tx_desc_status_did,
17537                 (void *)&cmd_show_rx_tx_desc_status_status,
17538                 NULL,
17539         },
17540 };
17541
17542 /* *** display rx queue desc used count *** */
17543 struct cmd_show_rx_queue_desc_used_count_result {
17544         cmdline_fixed_string_t cmd_show;
17545         cmdline_fixed_string_t cmd_port;
17546         cmdline_fixed_string_t cmd_rxq;
17547         cmdline_fixed_string_t cmd_desc;
17548         cmdline_fixed_string_t cmd_used;
17549         cmdline_fixed_string_t cmd_count;
17550         portid_t cmd_pid;
17551         portid_t cmd_qid;
17552 };
17553
17554 static void
17555 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17556                 __rte_unused struct cmdline *cl,
17557                 __rte_unused void *data)
17558 {
17559         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17560         int rc;
17561
17562         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17563                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17564                 return;
17565         }
17566
17567         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17568         if (rc < 0) {
17569                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17570                 return;
17571         }
17572         printf("Used desc count = %d\n", rc);
17573 }
17574
17575 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17576         TOKEN_STRING_INITIALIZER
17577                 (struct cmd_show_rx_queue_desc_used_count_result,
17578                  cmd_show, "show");
17579 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17580         TOKEN_STRING_INITIALIZER
17581                 (struct cmd_show_rx_queue_desc_used_count_result,
17582                  cmd_port, "port");
17583 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17584         TOKEN_NUM_INITIALIZER
17585                 (struct cmd_show_rx_queue_desc_used_count_result,
17586                  cmd_pid, RTE_UINT16);
17587 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17588         TOKEN_STRING_INITIALIZER
17589                 (struct cmd_show_rx_queue_desc_used_count_result,
17590                  cmd_rxq, "rxq");
17591 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17592         TOKEN_NUM_INITIALIZER
17593                 (struct cmd_show_rx_queue_desc_used_count_result,
17594                  cmd_qid, RTE_UINT16);
17595 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17596         TOKEN_STRING_INITIALIZER
17597                 (struct cmd_show_rx_queue_desc_used_count_result,
17598                  cmd_count, "desc");
17599 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17600         TOKEN_STRING_INITIALIZER
17601                 (struct cmd_show_rx_queue_desc_used_count_result,
17602                  cmd_count, "used");
17603 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17604         TOKEN_STRING_INITIALIZER
17605                 (struct cmd_show_rx_queue_desc_used_count_result,
17606                  cmd_count, "count");
17607 static cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17608         .f = cmd_show_rx_queue_desc_used_count_parsed,
17609         .data = NULL,
17610         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17611         .tokens = {
17612                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17613                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17614                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17615                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17616                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17617                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17618                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17619                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17620                 NULL,
17621         },
17622 };
17623
17624 /* Common result structure for set port ptypes */
17625 struct cmd_set_port_ptypes_result {
17626         cmdline_fixed_string_t set;
17627         cmdline_fixed_string_t port;
17628         portid_t port_id;
17629         cmdline_fixed_string_t ptype_mask;
17630         uint32_t mask;
17631 };
17632
17633 /* Common CLI fields for set port ptypes */
17634 static cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17635         TOKEN_STRING_INITIALIZER
17636                 (struct cmd_set_port_ptypes_result,
17637                  set, "set");
17638 static cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17639         TOKEN_STRING_INITIALIZER
17640                 (struct cmd_set_port_ptypes_result,
17641                  port, "port");
17642 static cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17643         TOKEN_NUM_INITIALIZER
17644                 (struct cmd_set_port_ptypes_result,
17645                  port_id, RTE_UINT16);
17646 static cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17647         TOKEN_STRING_INITIALIZER
17648                 (struct cmd_set_port_ptypes_result,
17649                  ptype_mask, "ptype_mask");
17650 static cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17651         TOKEN_NUM_INITIALIZER
17652                 (struct cmd_set_port_ptypes_result,
17653                  mask, RTE_UINT32);
17654
17655 static void
17656 cmd_set_port_ptypes_parsed(
17657         void *parsed_result,
17658         __rte_unused struct cmdline *cl,
17659         __rte_unused void *data)
17660 {
17661         struct cmd_set_port_ptypes_result *res = parsed_result;
17662 #define PTYPE_NAMESIZE        256
17663         char ptype_name[PTYPE_NAMESIZE];
17664         uint16_t port_id = res->port_id;
17665         uint32_t ptype_mask = res->mask;
17666         int ret, i;
17667
17668         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17669                                                NULL, 0);
17670         if (ret <= 0) {
17671                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17672                         port_id);
17673                 return;
17674         }
17675
17676         uint32_t ptypes[ret];
17677
17678         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17679         if (ret < 0) {
17680                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17681                         port_id);
17682                 return;
17683         }
17684
17685         printf("Successfully set following ptypes for Port %d\n", port_id);
17686         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17687                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17688                 printf("%s\n", ptype_name);
17689         }
17690
17691         clear_ptypes = false;
17692 }
17693
17694 static cmdline_parse_inst_t cmd_set_port_ptypes = {
17695         .f = cmd_set_port_ptypes_parsed,
17696         .data = NULL,
17697         .help_str = "set port <port_id> ptype_mask <mask>",
17698         .tokens = {
17699                 (void *)&cmd_set_port_ptypes_set,
17700                 (void *)&cmd_set_port_ptypes_port,
17701                 (void *)&cmd_set_port_ptypes_port_id,
17702                 (void *)&cmd_set_port_ptypes_mask_str,
17703                 (void *)&cmd_set_port_ptypes_mask_u32,
17704                 NULL,
17705         },
17706 };
17707
17708 /* *** display mac addresses added to a port *** */
17709 struct cmd_showport_macs_result {
17710         cmdline_fixed_string_t cmd_show;
17711         cmdline_fixed_string_t cmd_port;
17712         cmdline_fixed_string_t cmd_keyword;
17713         portid_t cmd_pid;
17714 };
17715
17716 static void
17717 cmd_showport_macs_parsed(void *parsed_result,
17718                 __rte_unused struct cmdline *cl,
17719                 __rte_unused void *data)
17720 {
17721         struct cmd_showport_macs_result *res = parsed_result;
17722
17723         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17724                 return;
17725
17726         if (!strcmp(res->cmd_keyword, "macs"))
17727                 show_macs(res->cmd_pid);
17728         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17729                 show_mcast_macs(res->cmd_pid);
17730 }
17731
17732 static cmdline_parse_token_string_t cmd_showport_macs_show =
17733         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17734                         cmd_show, "show");
17735 static cmdline_parse_token_string_t cmd_showport_macs_port =
17736         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17737                         cmd_port, "port");
17738 static cmdline_parse_token_num_t cmd_showport_macs_pid =
17739         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17740                         cmd_pid, RTE_UINT16);
17741 static cmdline_parse_token_string_t cmd_showport_macs_keyword =
17742         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17743                         cmd_keyword, "macs#mcast_macs");
17744
17745 static cmdline_parse_inst_t cmd_showport_macs = {
17746         .f = cmd_showport_macs_parsed,
17747         .data = NULL,
17748         .help_str = "show port <port_id> macs|mcast_macs",
17749         .tokens = {
17750                 (void *)&cmd_showport_macs_show,
17751                 (void *)&cmd_showport_macs_port,
17752                 (void *)&cmd_showport_macs_pid,
17753                 (void *)&cmd_showport_macs_keyword,
17754                 NULL,
17755         },
17756 };
17757
17758 /* *** show flow transfer proxy port ID for the given port *** */
17759 struct cmd_show_port_flow_transfer_proxy_result {
17760         cmdline_fixed_string_t show;
17761         cmdline_fixed_string_t port;
17762         portid_t port_id;
17763         cmdline_fixed_string_t flow;
17764         cmdline_fixed_string_t transfer;
17765         cmdline_fixed_string_t proxy;
17766 };
17767
17768 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17769         TOKEN_STRING_INITIALIZER
17770                 (struct cmd_show_port_flow_transfer_proxy_result,
17771                  show, "show");
17772 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17773         TOKEN_STRING_INITIALIZER
17774                 (struct cmd_show_port_flow_transfer_proxy_result,
17775                  port, "port");
17776 static cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17777         TOKEN_NUM_INITIALIZER
17778                 (struct cmd_show_port_flow_transfer_proxy_result,
17779                  port_id, RTE_UINT16);
17780 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17781         TOKEN_STRING_INITIALIZER
17782                 (struct cmd_show_port_flow_transfer_proxy_result,
17783                  flow, "flow");
17784 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17785         TOKEN_STRING_INITIALIZER
17786                 (struct cmd_show_port_flow_transfer_proxy_result,
17787                  transfer, "transfer");
17788 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17789         TOKEN_STRING_INITIALIZER
17790                 (struct cmd_show_port_flow_transfer_proxy_result,
17791                  proxy, "proxy");
17792
17793 static void
17794 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17795                                          __rte_unused struct cmdline *cl,
17796                                          __rte_unused void *data)
17797 {
17798         struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17799         portid_t proxy_port_id;
17800         int ret;
17801
17802         printf("\n");
17803
17804         ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17805         if (ret != 0) {
17806                 fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17807                         rte_strerror(-ret));
17808                 return;
17809         }
17810
17811         printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17812 }
17813
17814 static cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17815         .f = cmd_show_port_flow_transfer_proxy_parsed,
17816         .data = NULL,
17817         .help_str = "show port <port_id> flow transfer proxy",
17818         .tokens = {
17819                 (void *)&cmd_show_port_flow_transfer_proxy_show,
17820                 (void *)&cmd_show_port_flow_transfer_proxy_port,
17821                 (void *)&cmd_show_port_flow_transfer_proxy_port_id,
17822                 (void *)&cmd_show_port_flow_transfer_proxy_flow,
17823                 (void *)&cmd_show_port_flow_transfer_proxy_transfer,
17824                 (void *)&cmd_show_port_flow_transfer_proxy_proxy,
17825                 NULL,
17826         }
17827 };
17828
17829 /* ******************************************************************************** */
17830
17831 /* list of instructions */
17832 static cmdline_parse_ctx_t builtin_ctx[] = {
17833         (cmdline_parse_inst_t *)&cmd_help_brief,
17834         (cmdline_parse_inst_t *)&cmd_help_long,
17835         (cmdline_parse_inst_t *)&cmd_quit,
17836         (cmdline_parse_inst_t *)&cmd_load_from_file,
17837         (cmdline_parse_inst_t *)&cmd_showport,
17838         (cmdline_parse_inst_t *)&cmd_showqueue,
17839         (cmdline_parse_inst_t *)&cmd_showeeprom,
17840         (cmdline_parse_inst_t *)&cmd_showportall,
17841         (cmdline_parse_inst_t *)&cmd_representor_info,
17842         (cmdline_parse_inst_t *)&cmd_showdevice,
17843         (cmdline_parse_inst_t *)&cmd_showcfg,
17844         (cmdline_parse_inst_t *)&cmd_showfwdall,
17845         (cmdline_parse_inst_t *)&cmd_start,
17846         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17847         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17848         (cmdline_parse_inst_t *)&cmd_set_link_up,
17849         (cmdline_parse_inst_t *)&cmd_set_link_down,
17850         (cmdline_parse_inst_t *)&cmd_reset,
17851         (cmdline_parse_inst_t *)&cmd_set_numbers,
17852         (cmdline_parse_inst_t *)&cmd_set_log,
17853         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17854         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17855         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17856         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17857         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17858         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17859         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17860         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17861         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17862         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17863         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17864         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17865         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17866         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17867         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17868         (cmdline_parse_inst_t *)&cmd_set_link_check,
17869         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17870         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17871         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17872         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17873 #ifdef RTE_NET_BOND
17874         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17875         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17876         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17877         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17878         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17879         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17880         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17881         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17882         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17883         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17884         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17885         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17886 #endif
17887         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17888         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17889         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17890         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17891         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17892         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17893         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17894         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17895         (cmdline_parse_inst_t *)&cmd_csum_set,
17896         (cmdline_parse_inst_t *)&cmd_csum_show,
17897         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17898         (cmdline_parse_inst_t *)&cmd_tso_set,
17899         (cmdline_parse_inst_t *)&cmd_tso_show,
17900         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17901         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17902 #ifdef RTE_LIB_GRO
17903         (cmdline_parse_inst_t *)&cmd_gro_enable,
17904         (cmdline_parse_inst_t *)&cmd_gro_flush,
17905         (cmdline_parse_inst_t *)&cmd_gro_show,
17906 #endif
17907 #ifdef RTE_LIB_GSO
17908         (cmdline_parse_inst_t *)&cmd_gso_enable,
17909         (cmdline_parse_inst_t *)&cmd_gso_size,
17910         (cmdline_parse_inst_t *)&cmd_gso_show,
17911 #endif
17912         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17913         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17914         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17915         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17916         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17917         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17918         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17919         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17920         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17921         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17922         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17923         (cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17924         (cmdline_parse_inst_t *)&cmd_config_dcb,
17925         (cmdline_parse_inst_t *)&cmd_read_reg,
17926         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17927         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17928         (cmdline_parse_inst_t *)&cmd_write_reg,
17929         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17930         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17931         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17932         (cmdline_parse_inst_t *)&cmd_stop,
17933         (cmdline_parse_inst_t *)&cmd_mac_addr,
17934         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17935         (cmdline_parse_inst_t *)&cmd_set_qmap,
17936         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17937         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17938         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17939         (cmdline_parse_inst_t *)&cmd_operate_port,
17940         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17941         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17942         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17943         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17944         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17945         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17946         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17947         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17948         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17949         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17950         (cmdline_parse_inst_t *)&cmd_config_mtu,
17951         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17952         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17953         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17954         (cmdline_parse_inst_t *)&cmd_config_rss,
17955         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17956         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17957         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17958         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17959         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17960         (cmdline_parse_inst_t *)&cmd_showport_reta,
17961         (cmdline_parse_inst_t *)&cmd_showport_macs,
17962         (cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
17963         (cmdline_parse_inst_t *)&cmd_config_burst,
17964         (cmdline_parse_inst_t *)&cmd_config_thresh,
17965         (cmdline_parse_inst_t *)&cmd_config_threshold,
17966         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17967         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17968         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17969         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17970         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17971         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17972         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17973         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17974         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17975         (cmdline_parse_inst_t *)&cmd_dump,
17976         (cmdline_parse_inst_t *)&cmd_dump_one,
17977 #ifdef RTE_NET_I40E
17978         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17979 #endif
17980         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17981         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17982         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17983         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17984         (cmdline_parse_inst_t *)&cmd_flow,
17985         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17986         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17987         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17988         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm_rfc4115,
17989         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17990         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17991         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17992         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17993         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17994         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17995         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17996         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17997         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17998         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17999         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18000         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18001         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18002         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18003         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18004         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18005         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18006         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18007         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18008         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18009         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18010         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18011         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18012         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18013         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18014         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18015         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18016         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18017         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18018         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18019         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18020         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18021         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18022         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18023         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18024         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18025         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18026         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18027         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18028         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18029         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18030         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18031         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18032         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18033         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18034         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18035         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18036         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18037         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18038         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18039         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18040         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18041         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18042         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18043         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18044         (cmdline_parse_inst_t *)&cmd_ddp_add,
18045         (cmdline_parse_inst_t *)&cmd_ddp_del,
18046         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18047         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18048         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18049         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18050         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18051         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18052         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18053         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18054         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18055         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18056         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18057         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18058
18059         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18060         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18061         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18062         (cmdline_parse_inst_t *)&cmd_queue_region,
18063         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18064         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18065         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18066         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18067         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18068         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18069         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18070         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18071         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18072         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18073         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18074         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18075         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18076         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18077         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18078         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18079         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18080         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18081         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18082         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18083         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18084         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18085         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18086         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18087         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18088         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18089         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18090         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18091         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18092         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18093         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18094         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18095         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18096         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18097         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18098         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18099 #ifdef RTE_LIB_BPF
18100         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18101         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18102 #endif
18103         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18104         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18105         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18106         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18107         (cmdline_parse_inst_t *)&cmd_set_raw,
18108         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18109         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18110         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18111         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18112         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18113         (cmdline_parse_inst_t *)&cmd_show_capability,
18114         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18115         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18116         NULL,
18117 };
18118
18119 void
18120 testpmd_add_driver_commands(struct testpmd_driver_commands *c)
18121 {
18122         TAILQ_INSERT_TAIL(&driver_commands_head, c, next);
18123 }
18124
18125 int
18126 init_cmdline(void)
18127 {
18128         struct testpmd_driver_commands *c;
18129         unsigned int count;
18130         unsigned int i;
18131
18132         /* initialize non-constant commands */
18133         cmd_set_fwd_mode_init();
18134         cmd_set_fwd_retry_mode_init();
18135
18136         count = 0;
18137         for (i = 0; builtin_ctx[i] != NULL; i++)
18138                 count++;
18139         TAILQ_FOREACH(c, &driver_commands_head, next) {
18140                 for (i = 0; c->commands[i].ctx != NULL; i++)
18141                         count++;
18142         }
18143
18144         /* cmdline expects a NULL terminated array */
18145         main_ctx = calloc(count + 1, sizeof(main_ctx[0]));
18146         if (main_ctx == NULL)
18147                 return -1;
18148
18149         count = 0;
18150         for (i = 0; builtin_ctx[i] != NULL; i++, count++)
18151                 main_ctx[count] = builtin_ctx[i];
18152         TAILQ_FOREACH(c, &driver_commands_head, next) {
18153                 for (i = 0; c->commands[i].ctx != NULL; i++, count++)
18154                         main_ctx[count] = c->commands[i].ctx;
18155         }
18156
18157         return 0;
18158 }
18159
18160 /* read cmdline commands from file */
18161 void
18162 cmdline_read_from_file(const char *filename)
18163 {
18164         struct cmdline *cl;
18165
18166         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18167         if (cl == NULL) {
18168                 fprintf(stderr,
18169                         "Failed to create file based cmdline context: %s\n",
18170                         filename);
18171                 return;
18172         }
18173
18174         cmdline_interact(cl);
18175         cmdline_quit(cl);
18176
18177         cmdline_free(cl);
18178
18179         printf("Read CLI commands from %s\n", filename);
18180 }
18181
18182 /* prompt function, called from main on MAIN lcore */
18183 void
18184 prompt(void)
18185 {
18186         int ret;
18187
18188         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18189         if (testpmd_cl == NULL)
18190                 return;
18191
18192         ret = atexit(prompt_exit);
18193         if (ret != 0)
18194                 fprintf(stderr, "Cannot set exit function for cmdline\n");
18195
18196         cmdline_interact(testpmd_cl);
18197         if (ret != 0)
18198                 cmdline_stdin_exit(testpmd_cl);
18199 }
18200
18201 void
18202 prompt_exit(void)
18203 {
18204         if (testpmd_cl != NULL) {
18205                 cmdline_quit(testpmd_cl);
18206                 cmdline_stdin_exit(testpmd_cl);
18207         }
18208 }
18209
18210 static void
18211 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18212 {
18213         if (id == (portid_t)RTE_PORT_ALL) {
18214                 portid_t pid;
18215
18216                 RTE_ETH_FOREACH_DEV(pid) {
18217                         /* check if need_reconfig has been set to 1 */
18218                         if (ports[pid].need_reconfig == 0)
18219                                 ports[pid].need_reconfig = dev;
18220                         /* check if need_reconfig_queues has been set to 1 */
18221                         if (ports[pid].need_reconfig_queues == 0)
18222                                 ports[pid].need_reconfig_queues = queue;
18223                 }
18224         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18225                 /* check if need_reconfig has been set to 1 */
18226                 if (ports[id].need_reconfig == 0)
18227                         ports[id].need_reconfig = dev;
18228                 /* check if need_reconfig_queues has been set to 1 */
18229                 if (ports[id].need_reconfig_queues == 0)
18230                         ports[id].need_reconfig_queues = queue;
18231         }
18232 }