ethdev: introduce available Rx descriptors threshold
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <inttypes.h>
13 #include <sys/queue.h>
14
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_debug.h>
19 #include <rte_cycles.h>
20 #include <rte_memory.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_ring.h>
29 #include <rte_mempool.h>
30 #include <rte_interrupts.h>
31 #include <rte_pci.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_string_fns.h>
35 #include <rte_devargs.h>
36 #include <rte_flow.h>
37 #ifdef RTE_LIB_GRO
38 #include <rte_gro.h>
39 #endif
40 #include <rte_mbuf_dyn.h>
41
42 #include <cmdline_rdline.h>
43 #include <cmdline_parse.h>
44 #include <cmdline_parse_num.h>
45 #include <cmdline_parse_string.h>
46 #include <cmdline_parse_ipaddr.h>
47 #include <cmdline_parse_etheraddr.h>
48 #include <cmdline_socket.h>
49 #include <cmdline.h>
50 #ifdef RTE_NET_BOND
51 #include <rte_eth_bond.h>
52 #include <rte_eth_bond_8023ad.h>
53 #endif
54 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
55 #include <rte_pmd_dpaa.h>
56 #endif
57 #ifdef RTE_NET_IXGBE
58 #include <rte_pmd_ixgbe.h>
59 #endif
60 #ifdef RTE_NET_I40E
61 #include <rte_pmd_i40e.h>
62 #endif
63 #ifdef RTE_NET_BNXT
64 #include <rte_pmd_bnxt.h>
65 #endif
66 #include "testpmd.h"
67 #include "cmdline_mtr.h"
68 #include "cmdline_tm.h"
69 #include "bpf_cmd.h"
70
71 static struct cmdline *testpmd_cl;
72 static cmdline_parse_ctx_t *main_ctx;
73 static TAILQ_HEAD(, testpmd_driver_commands) driver_commands_head =
74         TAILQ_HEAD_INITIALIZER(driver_commands_head);
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related commands.\n"
100                 "    help drivers                    : Driver specific commands.\n"
101                 "    help all                        : All of the above sections.\n\n"
102         );
103
104 }
105
106 static cmdline_parse_token_string_t cmd_help_brief_help =
107         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
108
109 static cmdline_parse_inst_t cmd_help_brief = {
110         .f = cmd_help_brief_parsed,
111         .data = NULL,
112         .help_str = "help: Show help",
113         .tokens = {
114                 (void *)&cmd_help_brief_help,
115                 NULL,
116         },
117 };
118
119 /* *** Help command with help sections. *** */
120 struct cmd_help_long_result {
121         cmdline_fixed_string_t help;
122         cmdline_fixed_string_t section;
123 };
124
125 static void cmd_help_long_parsed(void *parsed_result,
126                                  struct cmdline *cl,
127                                  __rte_unused void *data)
128 {
129         int show_all = 0;
130         struct cmd_help_long_result *res = parsed_result;
131
132         if (!strcmp(res->section, "all"))
133                 show_all = 1;
134
135         if (show_all || !strcmp(res->section, "control")) {
136
137                 cmdline_printf(
138                         cl,
139                         "\n"
140                         "Control forwarding:\n"
141                         "-------------------\n\n"
142
143                         "start\n"
144                         "    Start packet forwarding with current configuration.\n\n"
145
146                         "start tx_first\n"
147                         "    Start packet forwarding with current config"
148                         " after sending one burst of packets.\n\n"
149
150                         "stop\n"
151                         "    Stop packet forwarding, and display accumulated"
152                         " statistics.\n\n"
153
154                         "quit\n"
155                         "    Quit to prompt.\n\n"
156                 );
157         }
158
159         if (show_all || !strcmp(res->section, "display")) {
160
161                 cmdline_printf(
162                         cl,
163                         "\n"
164                         "Display:\n"
165                         "--------\n\n"
166
167                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
168                         "    Display information for port_id, or all.\n\n"
169
170                         "show port info (port_id) representor\n"
171                         "    Show supported representors for a specific port\n\n"
172
173                         "show port port_id (module_eeprom|eeprom)\n"
174                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
175
176                         "show port X rss reta (size) (mask0,mask1,...)\n"
177                         "    Display the rss redirection table entry indicated"
178                         " by masks on port X. size is used to indicate the"
179                         " hardware supported reta size\n\n"
180
181                         "show port (port_id) rss-hash [key]\n"
182                         "    Display the RSS hash functions and RSS hash key of port\n\n"
183
184                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
185                         "    Clear information for port_id, or all.\n\n"
186
187                         "show (rxq|txq) info (port_id) (queue_id)\n"
188                         "    Display information for configured RX/TX queue.\n\n"
189
190                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
191                         "    Display the given configuration.\n\n"
192
193                         "read rxd (port_id) (queue_id) (rxd_id)\n"
194                         "    Display an RX descriptor of a port RX queue.\n\n"
195
196                         "read txd (port_id) (queue_id) (txd_id)\n"
197                         "    Display a TX descriptor of a port TX queue.\n\n"
198
199                         "ddp get list (port_id)\n"
200                         "    Get ddp profile info list\n\n"
201
202                         "ddp get info (profile_path)\n"
203                         "    Get ddp profile information.\n\n"
204
205                         "show vf stats (port_id) (vf_id)\n"
206                         "    Display a VF's statistics.\n\n"
207
208                         "clear vf stats (port_id) (vf_id)\n"
209                         "    Reset a VF's statistics.\n\n"
210
211                         "show port (port_id) pctype mapping\n"
212                         "    Get flow ptype to pctype mapping on a port\n\n"
213
214                         "show port meter stats (port_id) (meter_id) (clear)\n"
215                         "    Get meter stats on a port\n\n"
216
217                         "show fwd stats all\n"
218                         "    Display statistics for all fwd engines.\n\n"
219
220                         "clear fwd stats all\n"
221                         "    Clear statistics for all fwd engines.\n\n"
222
223                         "show port (port_id) rx_offload capabilities\n"
224                         "    List all per queue and per port Rx offloading"
225                         " capabilities of a port\n\n"
226
227                         "show port (port_id) rx_offload configuration\n"
228                         "    List port level and all queue level"
229                         " Rx offloading configuration\n\n"
230
231                         "show port (port_id) tx_offload capabilities\n"
232                         "    List all per queue and per port"
233                         " Tx offloading capabilities of a port\n\n"
234
235                         "show port (port_id) tx_offload configuration\n"
236                         "    List port level and all queue level"
237                         " Tx offloading configuration\n\n"
238
239                         "show port (port_id) tx_metadata\n"
240                         "    Show Tx metadata value set"
241                         " for a specific port\n\n"
242
243                         "show port (port_id) ptypes\n"
244                         "    Show port supported ptypes"
245                         " for a specific port\n\n"
246
247                         "show device info (<identifier>|all)"
248                         "       Show general information about devices probed.\n\n"
249
250                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
251                         "       Show status of rx|tx descriptor.\n\n"
252
253                         "show port (port_id) rxq (queue_id) desc used count\n"
254                         "    Show current number of filled receive"
255                         " packet descriptors.\n\n"
256
257                         "show port (port_id) macs|mcast_macs"
258                         "       Display list of mac addresses added to port.\n\n"
259
260                         "show port (port_id) flow transfer proxy\n"
261                         "       Display proxy port to manage transfer flows\n\n"
262
263                         "show port (port_id) fec capabilities"
264                         "       Show fec capabilities of a port.\n\n"
265
266                         "show port (port_id) fec_mode"
267                         "       Show fec mode of a port.\n\n"
268
269                         "show port (port_id) flow_ctrl"
270                         "       Show flow control info of a port.\n\n"
271                 );
272         }
273
274         if (show_all || !strcmp(res->section, "config")) {
275                 cmdline_printf(
276                         cl,
277                         "\n"
278                         "Configuration:\n"
279                         "--------------\n"
280                         "Configuration changes only become active when"
281                         " forwarding is started/restarted.\n\n"
282
283                         "set default\n"
284                         "    Reset forwarding to the default configuration.\n\n"
285
286                         "set verbose (level)\n"
287                         "    Set the debug verbosity level X.\n\n"
288
289                         "set log global|(type) (level)\n"
290                         "    Set the log level.\n\n"
291
292                         "set nbport (num)\n"
293                         "    Set number of ports.\n\n"
294
295                         "set nbcore (num)\n"
296                         "    Set number of cores.\n\n"
297
298                         "set coremask (mask)\n"
299                         "    Set the forwarding cores hexadecimal mask.\n\n"
300
301                         "set portmask (mask)\n"
302                         "    Set the forwarding ports hexadecimal mask.\n\n"
303
304                         "set burst (num)\n"
305                         "    Set number of packets per burst.\n\n"
306
307                         "set burst tx delay (microseconds) retry (num)\n"
308                         "    Set the transmit delay time and number of retries,"
309                         " effective when retry is enabled.\n\n"
310
311                         "set rxoffs (x[,y]*)\n"
312                         "    Set the offset of each packet segment on"
313                         " receiving if split feature is engaged."
314                         " Affects only the queues configured with split"
315                         " offloads.\n\n"
316
317                         "set rxpkts (x[,y]*)\n"
318                         "    Set the length of each segment to scatter"
319                         " packets on receiving if split feature is engaged."
320                         " Affects only the queues configured with split"
321                         " offloads.\n\n"
322
323                         "set txpkts (x[,y]*)\n"
324                         "    Set the length of each segment of TXONLY"
325                         " and optionally CSUM packets.\n\n"
326
327                         "set txsplit (off|on|rand)\n"
328                         "    Set the split policy for the TX packets."
329                         " Right now only applicable for CSUM and TXONLY"
330                         " modes\n\n"
331
332                         "set txtimes (x, y)\n"
333                         "    Set the scheduling on timestamps"
334                         " timings for the TXONLY mode\n\n"
335
336                         "set corelist (x[,y]*)\n"
337                         "    Set the list of forwarding cores.\n\n"
338
339                         "set portlist (x[,y]*)\n"
340                         "    Set the list of forwarding ports.\n\n"
341
342                         "set port setup on (iterator|event)\n"
343                         "    Select how attached port is retrieved for setup.\n\n"
344
345                         "set tx loopback (port_id) (on|off)\n"
346                         "    Enable or disable tx loopback.\n\n"
347
348                         "set all queues drop (port_id) (on|off)\n"
349                         "    Set drop enable bit for all queues.\n\n"
350
351                         "set vf split drop (port_id) (vf_id) (on|off)\n"
352                         "    Set split drop enable bit for a VF from the PF.\n\n"
353
354                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
355                         "    Set MAC antispoof for a VF from the PF.\n\n"
356
357                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
358                         "    Enable MACsec offload.\n\n"
359
360                         "set macsec offload (port_id) off\n"
361                         "    Disable MACsec offload.\n\n"
362
363                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
364                         "    Configure MACsec secure connection (SC).\n\n"
365
366                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
367                         "    Configure MACsec secure association (SA).\n\n"
368
369                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
370                         "    Set VF broadcast for a VF from the PF.\n\n"
371
372                         "vlan set stripq (on|off) (port_id,queue_id)\n"
373                         "    Set the VLAN strip for a queue on a port.\n\n"
374
375                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
376                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
377
378                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
379                         "    Set VLAN insert for a VF from the PF.\n\n"
380
381                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
382                         "    Set VLAN antispoof for a VF from the PF.\n\n"
383
384                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
385                         "    Set VLAN tag for a VF from the PF.\n\n"
386
387                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
388                         "    Set a VF's max bandwidth(Mbps).\n\n"
389
390                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
391                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
392
393                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
394                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
395
396                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
397                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
398
399                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
400                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
401
402                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
403                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
404
405                         "vlan set (inner|outer) tpid (value) (port_id)\n"
406                         "    Set the VLAN TPID for Packet Filtering on"
407                         " a port\n\n"
408
409                         "rx_vlan add (vlan_id|all) (port_id)\n"
410                         "    Add a vlan_id, or all identifiers, to the set"
411                         " of VLAN identifiers filtered by port_id.\n\n"
412
413                         "rx_vlan rm (vlan_id|all) (port_id)\n"
414                         "    Remove a vlan_id, or all identifiers, from the set"
415                         " of VLAN identifiers filtered by port_id.\n\n"
416
417                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
418                         "    Add a vlan_id, to the set of VLAN identifiers"
419                         "filtered for VF(s) from port_id.\n\n"
420
421                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
422                         "    Remove a vlan_id, to the set of VLAN identifiers"
423                         "filtered for VF(s) from port_id.\n\n"
424
425                         "rx_vxlan_port add (udp_port) (port_id)\n"
426                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
427
428                         "rx_vxlan_port rm (udp_port) (port_id)\n"
429                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
430
431                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
432                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
433                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
434
435                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
436                         "    Set port based TX VLAN insertion.\n\n"
437
438                         "tx_vlan reset (port_id)\n"
439                         "    Disable hardware insertion of a VLAN header in"
440                         " packets sent on a port.\n\n"
441
442                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
443                         "    Select hardware or software calculation of the"
444                         " checksum when transmitting a packet using the"
445                         " csum forward engine.\n"
446                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
447                         "    outer-ip concerns the outer IP layer in"
448                         "    outer-udp concerns the outer UDP layer in"
449                         " case the packet is recognized as a tunnel packet by"
450                         " the forward engine (vxlan, gre and ipip are supported)\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "csum parse-tunnel (on|off) (tx_port_id)\n"
454                         "    If disabled, treat tunnel packets as non-tunneled"
455                         " packets (treat inner headers as payload). The port\n"
456                         "    argument is the port used for TX in csum forward"
457                         " engine.\n\n"
458
459                         "csum show (port_id)\n"
460                         "    Display tx checksum offload configuration\n\n"
461
462                         "tso set (segsize) (portid)\n"
463                         "    Enable TCP Segmentation Offload in csum forward"
464                         " engine.\n"
465                         "    Please check the NIC datasheet for HW limits.\n\n"
466
467                         "tso show (portid)"
468                         "    Display the status of TCP Segmentation Offload.\n\n"
469
470 #ifdef RTE_LIB_GRO
471                         "set port (port_id) gro on|off\n"
472                         "    Enable or disable Generic Receive Offload in"
473                         " csum forwarding engine.\n\n"
474
475                         "show port (port_id) gro\n"
476                         "    Display GRO configuration.\n\n"
477
478                         "set gro flush (cycles)\n"
479                         "    Set the cycle to flush GROed packets from"
480                         " reassembly tables.\n\n"
481 #endif
482
483 #ifdef RTE_LIB_GSO
484                         "set port (port_id) gso (on|off)"
485                         "    Enable or disable Generic Segmentation Offload in"
486                         " csum forwarding engine.\n\n"
487
488                         "set gso segsz (length)\n"
489                         "    Set max packet length for output GSO segments,"
490                         " including packet header and payload.\n\n"
491
492                         "show port (port_id) gso\n"
493                         "    Show GSO configuration.\n\n"
494 #endif
495
496                         "set fwd (%s)\n"
497                         "    Set packet forwarding mode.\n\n"
498
499                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
500                         "    Add a MAC address on port_id.\n\n"
501
502                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
503                         "    Remove a MAC address from port_id.\n\n"
504
505                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
506                         "    Set the default MAC address for port_id.\n\n"
507
508                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
509                         "    Add a MAC address for a VF on the port.\n\n"
510
511                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
512                         "    Set the MAC address for a VF from the PF.\n\n"
513
514                         "set eth-peer (port_id) (peer_addr)\n"
515                         "    set the peer address for certain port.\n\n"
516
517                         "set port (port_id) uta (mac_address|all) (on|off)\n"
518                         "    Add/Remove a or all unicast hash filter(s)"
519                         "from port X.\n\n"
520
521                         "set promisc (port_id|all) (on|off)\n"
522                         "    Set the promiscuous mode on port_id, or all.\n\n"
523
524                         "set allmulti (port_id|all) (on|off)\n"
525                         "    Set the allmulti mode on port_id, or all.\n\n"
526
527                         "set vf promisc (port_id) (vf_id) (on|off)\n"
528                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
529
530                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
531                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
532
533                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
534                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
535                         " (on|off) autoneg (on|off) (port_id)\n"
536                         "set flow_ctrl rx (on|off) (portid)\n"
537                         "set flow_ctrl tx (on|off) (portid)\n"
538                         "set flow_ctrl high_water (high_water) (portid)\n"
539                         "set flow_ctrl low_water (low_water) (portid)\n"
540                         "set flow_ctrl pause_time (pause_time) (portid)\n"
541                         "set flow_ctrl send_xon (send_xon) (portid)\n"
542                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
543                         "set flow_ctrl autoneg (on|off) (port_id)\n"
544                         "    Set the link flow control parameter on a port.\n\n"
545
546                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
547                         " (low_water) (pause_time) (priority) (port_id)\n"
548                         "    Set the priority flow control parameter on a"
549                         " port.\n\n"
550
551                         "set pfc_queue_ctrl (port_id) rx (on|off) (tx_qid)"
552                         " (tx_tc) tx (on|off) (rx_qid) (rx_tc) (pause_time)\n"
553                         "    Set the queue priority flow control parameter on a"
554                         " given Rx and Tx queues of a port.\n\n"
555
556                         "set port (port_id) rxq (queue_id) avail_thresh (0..99)>\n "
557                         "    set available descriptors threshold for Rx queue\n\n"
558
559                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
560                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
561                         " queue on port.\n"
562                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
563                         " on port 0 to mapping 5.\n\n"
564
565                         "set xstats-hide-zero on|off\n"
566                         "    Set the option to hide the zero values"
567                         " for xstats display.\n"
568
569                         "set record-core-cycles on|off\n"
570                         "    Set the option to enable measurement of CPU cycles.\n"
571
572                         "set record-burst-stats on|off\n"
573                         "    Set the option to enable display of RX and TX bursts.\n"
574
575                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
576                         "    Enable/Disable a VF receive/transmit from a port\n\n"
577
578                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
579                         "|MPE) (on|off)\n"
580                         "    AUPE:accepts untagged VLAN;"
581                         "ROPE:accept unicast hash\n\n"
582                         "    BAM:accepts broadcast packets;"
583                         "MPE:accepts all multicast packets\n\n"
584                         "    Enable/Disable a VF receive mode of a port\n\n"
585
586                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
587                         "    Set rate limit for a queue of a port\n\n"
588
589                         "set port (port_id) vf (vf_id) rate (rate_num) "
590                         "queue_mask (queue_mask_value)\n"
591                         "    Set rate limit for queues in VF of a port\n\n"
592
593                         "set flush_rx (on|off)\n"
594                         "   Flush (default) or don't flush RX streams before"
595                         " forwarding. Mainly used with PCAP drivers.\n\n"
596
597                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
598                         "   Set the bypass mode for the lowest port on bypass enabled"
599                         " NIC.\n\n"
600
601                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
602                         "mode (normal|bypass|isolate) (port_id)\n"
603                         "   Set the event required to initiate specified bypass mode for"
604                         " the lowest port on a bypass enabled NIC where:\n"
605                         "       timeout   = enable bypass after watchdog timeout.\n"
606                         "       os_on     = enable bypass when OS/board is powered on.\n"
607                         "       os_off    = enable bypass when OS/board is powered off.\n"
608                         "       power_on  = enable bypass when power supply is turned on.\n"
609                         "       power_off = enable bypass when power supply is turned off."
610                         "\n\n"
611
612                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
613                         "   Set the bypass watchdog timeout to 'n' seconds"
614                         " where 0 = instant.\n\n"
615
616                         "show bypass config (port_id)\n"
617                         "   Show the bypass configuration for a bypass enabled NIC"
618                         " using the lowest port on the NIC.\n\n"
619
620 #ifdef RTE_NET_BOND
621                         "create bonded device (mode) (socket)\n"
622                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
623
624                         "add bonding slave (slave_id) (port_id)\n"
625                         "       Add a slave device to a bonded device.\n\n"
626
627                         "remove bonding slave (slave_id) (port_id)\n"
628                         "       Remove a slave device from a bonded device.\n\n"
629
630                         "set bonding mode (value) (port_id)\n"
631                         "       Set the bonding mode on a bonded device.\n\n"
632
633                         "set bonding primary (slave_id) (port_id)\n"
634                         "       Set the primary slave for a bonded device.\n\n"
635
636                         "show bonding config (port_id)\n"
637                         "       Show the bonding config for port_id.\n\n"
638
639                         "show bonding lacp info (port_id)\n"
640                         "       Show the bonding lacp information for port_id.\n\n"
641
642                         "set bonding mac_addr (port_id) (address)\n"
643                         "       Set the MAC address of a bonded device.\n\n"
644
645                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
646                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
647
648                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
649                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
650
651                         "set bonding mon_period (port_id) (value)\n"
652                         "       Set the bonding link status monitoring polling period in ms.\n\n"
653
654                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
655                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
656
657 #endif
658                         "set link-up port (port_id)\n"
659                         "       Set link up for a port.\n\n"
660
661                         "set link-down port (port_id)\n"
662                         "       Set link down for a port.\n\n"
663
664                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
665                         "    Load a profile package on a port\n\n"
666
667                         "ddp del (port_id) (backup_profile_path)\n"
668                         "    Delete a profile package from a port\n\n"
669
670                         "ptype mapping get (port_id) (valid_only)\n"
671                         "    Get ptype mapping on a port\n\n"
672
673                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
674                         "    Replace target with the pkt_type in ptype mapping\n\n"
675
676                         "ptype mapping reset (port_id)\n"
677                         "    Reset ptype mapping on a port\n\n"
678
679                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
680                         "    Update a ptype mapping item on a port\n\n"
681
682                         "set port (port_id) ptype_mask (ptype_mask)\n"
683                         "    set packet types classification for a specific port\n\n"
684
685                         "set port (port_id) queue-region region_id (value) "
686                         "queue_start_index (value) queue_num (value)\n"
687                         "    Set a queue region on a port\n\n"
688
689                         "set port (port_id) queue-region region_id (value) "
690                         "flowtype (value)\n"
691                         "    Set a flowtype region index on a port\n\n"
692
693                         "set port (port_id) queue-region UP (value) region_id (value)\n"
694                         "    Set the mapping of User Priority to "
695                         "queue region on a port\n\n"
696
697                         "set port (port_id) queue-region flush (on|off)\n"
698                         "    flush all queue region related configuration\n\n"
699
700                         "show port meter cap (port_id)\n"
701                         "    Show port meter capability information\n\n"
702
703                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
704                         "    meter profile add - srtcm rfc 2697\n\n"
705
706                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
707                         "    meter profile add - trtcm rfc 2698\n\n"
708
709                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
710                         "    meter profile add - trtcm rfc 4115\n\n"
711
712                         "del port meter profile (port_id) (profile_id)\n"
713                         "    meter profile delete\n\n"
714
715                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
716                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
717                         "(dscp_tbl_entry63)]\n"
718                         "    meter create\n\n"
719
720                         "enable port meter (port_id) (mtr_id)\n"
721                         "    meter enable\n\n"
722
723                         "disable port meter (port_id) (mtr_id)\n"
724                         "    meter disable\n\n"
725
726                         "del port meter (port_id) (mtr_id)\n"
727                         "    meter delete\n\n"
728
729                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
730                         "y_actions (actions) r_actions (actions)\n"
731                         "    meter policy add\n\n"
732
733                         "del port meter policy (port_id) (policy_id)\n"
734                         "    meter policy delete\n\n"
735
736                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
737                         "    meter update meter profile\n\n"
738
739                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
740                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
741                         "    update meter dscp table entries\n\n"
742
743                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
744                         "(action0) [(action1) (action2)]\n"
745                         "    meter update policer action\n\n"
746
747                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
748                         "    meter update stats\n\n"
749
750                         "show port (port_id) queue-region\n"
751                         "    show all queue region related configuration info\n\n"
752
753                         "set port (port_id) fec_mode auto|off|rs|baser\n"
754                         "    set fec mode for a specific port\n\n"
755
756                         , list_pkt_forwarding_modes()
757                 );
758         }
759
760         if (show_all || !strcmp(res->section, "ports")) {
761
762                 cmdline_printf(
763                         cl,
764                         "\n"
765                         "Port Operations:\n"
766                         "----------------\n\n"
767
768                         "port start (port_id|all)\n"
769                         "    Start all ports or port_id.\n\n"
770
771                         "port stop (port_id|all)\n"
772                         "    Stop all ports or port_id.\n\n"
773
774                         "port close (port_id|all)\n"
775                         "    Close all ports or port_id.\n\n"
776
777                         "port reset (port_id|all)\n"
778                         "    Reset all ports or port_id.\n\n"
779
780                         "port attach (ident)\n"
781                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
782
783                         "port detach (port_id)\n"
784                         "    Detach physical or virtual dev by port_id\n\n"
785
786                         "port config (port_id|all)"
787                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
788                         " duplex (half|full|auto)\n"
789                         "    Set speed and duplex for all ports or port_id\n\n"
790
791                         "port config (port_id|all) loopback (mode)\n"
792                         "    Set loopback mode for all ports or port_id\n\n"
793
794                         "port config all (rxq|txq|rxd|txd) (value)\n"
795                         "    Set number for rxq/txq/rxd/txd.\n\n"
796
797                         "port config all max-pkt-len (value)\n"
798                         "    Set the max packet length.\n\n"
799
800                         "port config all max-lro-pkt-size (value)\n"
801                         "    Set the max LRO aggregated packet size.\n\n"
802
803                         "port config all drop-en (on|off)\n"
804                         "    Enable or disable packet drop on all RX queues of all ports when no "
805                         "receive buffers available.\n\n"
806
807                         "port config all rss (all|default|ip|tcp|udp|sctp|"
808                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|"
809                         "none|level-default|level-outer|level-inner|<flowtype_id>)\n"
810                         "    Set the RSS mode.\n\n"
811
812                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
813                         "    Set the RSS redirection table.\n\n"
814
815                         "port config (port_id) dcb vt (on|off) (traffic_class)"
816                         " pfc (on|off)\n"
817                         "    Set the DCB mode.\n\n"
818
819                         "port config all burst (value)\n"
820                         "    Set the number of packets per burst.\n\n"
821
822                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
823                         " (value)\n"
824                         "    Set the ring prefetch/host/writeback threshold"
825                         " for tx/rx queue.\n\n"
826
827                         "port config all (txfreet|txrst|rxfreet) (value)\n"
828                         "    Set free threshold for rx/tx, or set"
829                         " tx rs bit threshold.\n\n"
830                         "port config mtu X value\n"
831                         "    Set the MTU of port X to a given value\n\n"
832
833                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
834                         "    Set a rx/tx queue's ring size configuration, the new"
835                         " value will take effect after command that (re-)start the port"
836                         " or command that setup the specific queue\n\n"
837
838                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
839                         "    Start/stop a rx/tx queue of port X. Only take effect"
840                         " when port X is started\n\n"
841
842                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
843                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
844                         " take effect when port X is stopped.\n\n"
845
846                         "port (port_id) (rxq|txq) (queue_id) setup\n"
847                         "    Setup a rx/tx queue of port X.\n\n"
848
849                         "port config (port_id) pctype mapping reset\n"
850                         "    Reset flow type to pctype mapping on a port\n\n"
851
852                         "port config (port_id) pctype mapping update"
853                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
854                         "    Update a flow type to pctype mapping item on a port\n\n"
855
856                         "port config (port_id) pctype (pctype_id) hash_inset|"
857                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
858                         " (field_idx)\n"
859                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
860
861                         "port config (port_id) pctype (pctype_id) hash_inset|"
862                         "fdir_inset|fdir_flx_inset clear all"
863                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
864
865                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
866                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
867
868                         "port config <port_id> rx_offload vlan_strip|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870                         "outer_ipv4_cksum|macsec_strip|header_split|"
871                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
872                         "buffer_split|timestamp|security|keep_crc on|off\n"
873                         "     Enable or disable a per port Rx offloading"
874                         " on all Rx queues of a port\n\n"
875
876                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
878                         "outer_ipv4_cksum|macsec_strip|header_split|"
879                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
880                         "buffer_split|timestamp|security|keep_crc on|off\n"
881                         "    Enable or disable a per queue Rx offloading"
882                         " only on a specific Rx queue\n\n"
883
884                         "port config (port_id) tx_offload vlan_insert|"
885                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
886                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
887                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
888                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
889                         "security on|off\n"
890                         "    Enable or disable a per port Tx offloading"
891                         " on all Tx queues of a port\n\n"
892
893                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
894                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
895                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
896                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
897                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
898                         " on|off\n"
899                         "    Enable or disable a per queue Tx offloading"
900                         " only on a specific Tx queue\n\n"
901
902                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
903                         "    Load an eBPF program as a callback"
904                         " for particular RX/TX queue\n\n"
905
906                         "bpf-unload rx|tx (port) (queue)\n"
907                         "    Unload previously loaded eBPF program"
908                         " for particular RX/TX queue\n\n"
909
910                         "port config (port_id) tx_metadata (value)\n"
911                         "    Set Tx metadata value per port. Testpmd will add this value"
912                         " to any Tx packet sent from this port\n\n"
913
914                         "port config (port_id) dynf (name) set|clear\n"
915                         "    Register a dynf and Set/clear this flag on Tx. "
916                         "Testpmd will set this value to any Tx packet "
917                         "sent from this port\n\n"
918
919                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
920                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
921                 );
922         }
923
924         if (show_all || !strcmp(res->section, "registers")) {
925
926                 cmdline_printf(
927                         cl,
928                         "\n"
929                         "Registers:\n"
930                         "----------\n\n"
931
932                         "read reg (port_id) (address)\n"
933                         "    Display value of a port register.\n\n"
934
935                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
936                         "    Display a port register bit field.\n\n"
937
938                         "read regbit (port_id) (address) (bit_x)\n"
939                         "    Display a single port register bit.\n\n"
940
941                         "write reg (port_id) (address) (value)\n"
942                         "    Set value of a port register.\n\n"
943
944                         "write regfield (port_id) (address) (bit_x) (bit_y)"
945                         " (value)\n"
946                         "    Set bit field of a port register.\n\n"
947
948                         "write regbit (port_id) (address) (bit_x) (value)\n"
949                         "    Set single bit value of a port register.\n\n"
950                 );
951         }
952         if (show_all || !strcmp(res->section, "filters")) {
953
954                 cmdline_printf(
955                         cl,
956                         "\n"
957                         "filters:\n"
958                         "--------\n\n"
959
960 #ifdef RTE_NET_I40E
961                         "flow_director_filter (port_id) mode raw (add|del|update)"
962                         " flow (flow_id) (drop|fwd) queue (queue_id)"
963                         " fd_id (fd_id_value) packet (packet file name)\n"
964                         "    Add/Del a raw type flow director filter.\n\n"
965 #endif
966
967                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
968                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
969                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
970                         "    Set flow director IP mask.\n\n"
971
972                         "flow_director_mask (port_id) mode MAC-VLAN"
973                         " vlan (vlan_value)\n"
974                         "    Set flow director MAC-VLAN mask.\n\n"
975
976                         "flow_director_mask (port_id) mode Tunnel"
977                         " vlan (vlan_value) mac (mac_value)"
978                         " tunnel-type (tunnel_type_value)"
979                         " tunnel-id (tunnel_id_value)\n"
980                         "    Set flow director Tunnel mask.\n\n"
981
982                         "flow_director_flex_payload (port_id)"
983                         " (raw|l2|l3|l4) (config)\n"
984                         "    Configure flex payload selection.\n\n"
985
986                         "flow validate {port_id}"
987                         " [group {group_id}] [priority {level}]"
988                         " [ingress] [egress]"
989                         " pattern {item} [/ {item} [...]] / end"
990                         " actions {action} [/ {action} [...]] / end\n"
991                         "    Check whether a flow rule can be created.\n\n"
992
993                         "flow create {port_id}"
994                         " [group {group_id}] [priority {level}]"
995                         " [ingress] [egress]"
996                         " pattern {item} [/ {item} [...]] / end"
997                         " actions {action} [/ {action} [...]] / end\n"
998                         "    Create a flow rule.\n\n"
999
1000                         "flow destroy {port_id} rule {rule_id} [...]\n"
1001                         "    Destroy specific flow rules.\n\n"
1002
1003                         "flow flush {port_id}\n"
1004                         "    Destroy all flow rules.\n\n"
1005
1006                         "flow query {port_id} {rule_id} {action}\n"
1007                         "    Query an existing flow rule.\n\n"
1008
1009                         "flow list {port_id} [group {group_id}] [...]\n"
1010                         "    List existing flow rules sorted by priority,"
1011                         " filtered by group identifiers.\n\n"
1012
1013                         "flow isolate {port_id} {boolean}\n"
1014                         "    Restrict ingress traffic to the defined"
1015                         " flow rules\n\n"
1016
1017                         "flow aged {port_id} [destroy]\n"
1018                         "    List and destroy aged flows"
1019                         " flow rules\n\n"
1020
1021                         "flow indirect_action {port_id} create"
1022                         " [action_id {indirect_action_id}]"
1023                         " [ingress] [egress]"
1024                         " action {action} / end\n"
1025                         "    Create indirect action.\n\n"
1026
1027                         "flow indirect_action {port_id} update"
1028                         " {indirect_action_id} action {action} / end\n"
1029                         "    Update indirect action.\n\n"
1030
1031                         "flow indirect_action {port_id} destroy"
1032                         " action_id {indirect_action_id} [...]\n"
1033                         "    Destroy specific indirect actions.\n\n"
1034
1035                         "flow indirect_action {port_id} query"
1036                         " {indirect_action_id}\n"
1037                         "    Query an existing indirect action.\n\n"
1038
1039                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1040                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1041                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1042                         "       Configure the VXLAN encapsulation for flows.\n\n"
1043
1044                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1045                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1046                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1047                         " eth-dst (eth-dst)\n"
1048                         "       Configure the VXLAN encapsulation for flows.\n\n"
1049
1050                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1051                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1052                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1053                         " eth-dst (eth-dst)\n"
1054                         "       Configure the VXLAN encapsulation for flows.\n\n"
1055
1056                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1057                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1058                         " (eth-dst)\n"
1059                         "       Configure the NVGRE encapsulation for flows.\n\n"
1060
1061                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1062                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1063                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1064                         "       Configure the NVGRE encapsulation for flows.\n\n"
1065
1066                         "set raw_encap {flow items}\n"
1067                         "       Configure the encapsulation with raw data.\n\n"
1068
1069                         "set raw_decap {flow items}\n"
1070                         "       Configure the decapsulation with raw data.\n\n"
1071
1072                 );
1073         }
1074
1075         if (show_all || !strcmp(res->section, "traffic_management")) {
1076                 cmdline_printf(
1077                         cl,
1078                         "\n"
1079                         "Traffic Management:\n"
1080                         "--------------\n"
1081                         "show port tm cap (port_id)\n"
1082                         "       Display the port TM capability.\n\n"
1083
1084                         "show port tm level cap (port_id) (level_id)\n"
1085                         "       Display the port TM hierarchical level capability.\n\n"
1086
1087                         "show port tm node cap (port_id) (node_id)\n"
1088                         "       Display the port TM node capability.\n\n"
1089
1090                         "show port tm node type (port_id) (node_id)\n"
1091                         "       Display the port TM node type.\n\n"
1092
1093                         "show port tm node stats (port_id) (node_id) (clear)\n"
1094                         "       Display the port TM node stats.\n\n"
1095
1096                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1097                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1098                         " (packet_length_adjust) (packet_mode)\n"
1099                         "       Add port tm node private shaper profile.\n\n"
1100
1101                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1102                         "       Delete port tm node private shaper profile.\n\n"
1103
1104                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1105                         " (shaper_profile_id)\n"
1106                         "       Add/update port tm node shared shaper.\n\n"
1107
1108                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1109                         "       Delete port tm node shared shaper.\n\n"
1110
1111                         "set port tm node shaper profile (port_id) (node_id)"
1112                         " (shaper_profile_id)\n"
1113                         "       Set port tm node shaper profile.\n\n"
1114
1115                         "add port tm node wred profile (port_id) (wred_profile_id)"
1116                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1117                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1118                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1119                         "       Add port tm node wred profile.\n\n"
1120
1121                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1122                         "       Delete port tm node wred profile.\n\n"
1123
1124                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1125                         " (priority) (weight) (level_id) (shaper_profile_id)"
1126                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1127                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1128                         "       Add port tm nonleaf node.\n\n"
1129
1130                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1131                         " (priority) (weight) (level_id) (shaper_profile_id)"
1132                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1133                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1134                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1135
1136                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1137                         " (priority) (weight) (level_id) (shaper_profile_id)"
1138                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1139                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1140                         "       Add port tm leaf node.\n\n"
1141
1142                         "del port tm node (port_id) (node_id)\n"
1143                         "       Delete port tm node.\n\n"
1144
1145                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1146                         " (priority) (weight)\n"
1147                         "       Set port tm node parent.\n\n"
1148
1149                         "suspend port tm node (port_id) (node_id)"
1150                         "       Suspend tm node.\n\n"
1151
1152                         "resume port tm node (port_id) (node_id)"
1153                         "       Resume tm node.\n\n"
1154
1155                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1156                         "       Commit tm hierarchy.\n\n"
1157
1158                         "set port tm mark ip_ecn (port) (green) (yellow)"
1159                         " (red)\n"
1160                         "    Enables/Disables the traffic management marking"
1161                         " for IP ECN (Explicit Congestion Notification)"
1162                         " packets on a given port\n\n"
1163
1164                         "set port tm mark ip_dscp (port) (green) (yellow)"
1165                         " (red)\n"
1166                         "    Enables/Disables the traffic management marking"
1167                         " on the port for IP dscp packets\n\n"
1168
1169                         "set port tm mark vlan_dei (port) (green) (yellow)"
1170                         " (red)\n"
1171                         "    Enables/Disables the traffic management marking"
1172                         " on the port for VLAN packets with DEI enabled\n\n"
1173                 );
1174         }
1175
1176         if (show_all || !strcmp(res->section, "devices")) {
1177                 cmdline_printf(
1178                         cl,
1179                         "\n"
1180                         "Device Operations:\n"
1181                         "--------------\n"
1182                         "device detach (identifier)\n"
1183                         "       Detach device by identifier.\n\n"
1184                 );
1185         }
1186
1187         if (show_all || !strcmp(res->section, "drivers")) {
1188                 struct testpmd_driver_commands *c;
1189                 unsigned int i;
1190
1191                 cmdline_printf(
1192                         cl,
1193                         "\n"
1194                         "Driver specific:\n"
1195                         "----------------\n"
1196                 );
1197                 TAILQ_FOREACH(c, &driver_commands_head, next) {
1198                         for (i = 0; c->commands[i].ctx != NULL; i++)
1199                                 cmdline_printf(cl, "%s\n", c->commands[i].help);
1200                 }
1201         }
1202 }
1203
1204 static cmdline_parse_token_string_t cmd_help_long_help =
1205         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1206
1207 static cmdline_parse_token_string_t cmd_help_long_section =
1208         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1209                 "all#control#display#config#ports#registers#"
1210                 "filters#traffic_management#devices#drivers");
1211
1212 static cmdline_parse_inst_t cmd_help_long = {
1213         .f = cmd_help_long_parsed,
1214         .data = NULL,
1215         .help_str = "help all|control|display|config|ports|register|"
1216                 "filters|traffic_management|devices|drivers: "
1217                 "Show help",
1218         .tokens = {
1219                 (void *)&cmd_help_long_help,
1220                 (void *)&cmd_help_long_section,
1221                 NULL,
1222         },
1223 };
1224
1225
1226 /* *** start/stop/close all ports *** */
1227 struct cmd_operate_port_result {
1228         cmdline_fixed_string_t keyword;
1229         cmdline_fixed_string_t name;
1230         cmdline_fixed_string_t value;
1231 };
1232
1233 static void cmd_operate_port_parsed(void *parsed_result,
1234                                 __rte_unused struct cmdline *cl,
1235                                 __rte_unused void *data)
1236 {
1237         struct cmd_operate_port_result *res = parsed_result;
1238
1239         if (!strcmp(res->name, "start"))
1240                 start_port(RTE_PORT_ALL);
1241         else if (!strcmp(res->name, "stop"))
1242                 stop_port(RTE_PORT_ALL);
1243         else if (!strcmp(res->name, "close"))
1244                 close_port(RTE_PORT_ALL);
1245         else if (!strcmp(res->name, "reset"))
1246                 reset_port(RTE_PORT_ALL);
1247         else
1248                 fprintf(stderr, "Unknown parameter\n");
1249 }
1250
1251 static cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1252         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1253                                                                 "port");
1254 static cmdline_parse_token_string_t cmd_operate_port_all_port =
1255         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1256                                                 "start#stop#close#reset");
1257 static cmdline_parse_token_string_t cmd_operate_port_all_all =
1258         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1259
1260 static cmdline_parse_inst_t cmd_operate_port = {
1261         .f = cmd_operate_port_parsed,
1262         .data = NULL,
1263         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1264         .tokens = {
1265                 (void *)&cmd_operate_port_all_cmd,
1266                 (void *)&cmd_operate_port_all_port,
1267                 (void *)&cmd_operate_port_all_all,
1268                 NULL,
1269         },
1270 };
1271
1272 /* *** start/stop/close specific port *** */
1273 struct cmd_operate_specific_port_result {
1274         cmdline_fixed_string_t keyword;
1275         cmdline_fixed_string_t name;
1276         uint8_t value;
1277 };
1278
1279 static void cmd_operate_specific_port_parsed(void *parsed_result,
1280                         __rte_unused struct cmdline *cl,
1281                                 __rte_unused void *data)
1282 {
1283         struct cmd_operate_specific_port_result *res = parsed_result;
1284
1285         if (!strcmp(res->name, "start"))
1286                 start_port(res->value);
1287         else if (!strcmp(res->name, "stop"))
1288                 stop_port(res->value);
1289         else if (!strcmp(res->name, "close"))
1290                 close_port(res->value);
1291         else if (!strcmp(res->name, "reset"))
1292                 reset_port(res->value);
1293         else
1294                 fprintf(stderr, "Unknown parameter\n");
1295 }
1296
1297 static cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1298         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1299                                                         keyword, "port");
1300 static cmdline_parse_token_string_t cmd_operate_specific_port_port =
1301         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1302                                                 name, "start#stop#close#reset");
1303 static cmdline_parse_token_num_t cmd_operate_specific_port_id =
1304         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1305                                                         value, RTE_UINT8);
1306
1307 static cmdline_parse_inst_t cmd_operate_specific_port = {
1308         .f = cmd_operate_specific_port_parsed,
1309         .data = NULL,
1310         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1311         .tokens = {
1312                 (void *)&cmd_operate_specific_port_cmd,
1313                 (void *)&cmd_operate_specific_port_port,
1314                 (void *)&cmd_operate_specific_port_id,
1315                 NULL,
1316         },
1317 };
1318
1319 /* *** enable port setup (after attach) via iterator or event *** */
1320 struct cmd_set_port_setup_on_result {
1321         cmdline_fixed_string_t set;
1322         cmdline_fixed_string_t port;
1323         cmdline_fixed_string_t setup;
1324         cmdline_fixed_string_t on;
1325         cmdline_fixed_string_t mode;
1326 };
1327
1328 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1329                                 __rte_unused struct cmdline *cl,
1330                                 __rte_unused void *data)
1331 {
1332         struct cmd_set_port_setup_on_result *res = parsed_result;
1333
1334         if (strcmp(res->mode, "event") == 0)
1335                 setup_on_probe_event = true;
1336         else if (strcmp(res->mode, "iterator") == 0)
1337                 setup_on_probe_event = false;
1338         else
1339                 fprintf(stderr, "Unknown mode\n");
1340 }
1341
1342 static cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1343         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1344                         set, "set");
1345 static cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1346         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1347                         port, "port");
1348 static cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1349         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1350                         setup, "setup");
1351 static cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1352         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1353                         on, "on");
1354 static cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1355         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1356                         mode, "iterator#event");
1357
1358 static cmdline_parse_inst_t cmd_set_port_setup_on = {
1359         .f = cmd_set_port_setup_on_parsed,
1360         .data = NULL,
1361         .help_str = "set port setup on iterator|event",
1362         .tokens = {
1363                 (void *)&cmd_set_port_setup_on_set,
1364                 (void *)&cmd_set_port_setup_on_port,
1365                 (void *)&cmd_set_port_setup_on_setup,
1366                 (void *)&cmd_set_port_setup_on_on,
1367                 (void *)&cmd_set_port_setup_on_mode,
1368                 NULL,
1369         },
1370 };
1371
1372 /* *** attach a specified port *** */
1373 struct cmd_operate_attach_port_result {
1374         cmdline_fixed_string_t port;
1375         cmdline_fixed_string_t keyword;
1376         cmdline_multi_string_t identifier;
1377 };
1378
1379 static void cmd_operate_attach_port_parsed(void *parsed_result,
1380                                 __rte_unused struct cmdline *cl,
1381                                 __rte_unused void *data)
1382 {
1383         struct cmd_operate_attach_port_result *res = parsed_result;
1384
1385         if (!strcmp(res->keyword, "attach"))
1386                 attach_port(res->identifier);
1387         else
1388                 fprintf(stderr, "Unknown parameter\n");
1389 }
1390
1391 static cmdline_parse_token_string_t cmd_operate_attach_port_port =
1392         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1393                         port, "port");
1394 static cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1395         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1396                         keyword, "attach");
1397 static cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1398         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1399                         identifier, TOKEN_STRING_MULTI);
1400
1401 static cmdline_parse_inst_t cmd_operate_attach_port = {
1402         .f = cmd_operate_attach_port_parsed,
1403         .data = NULL,
1404         .help_str = "port attach <identifier>: "
1405                 "(identifier: pci address or virtual dev name)",
1406         .tokens = {
1407                 (void *)&cmd_operate_attach_port_port,
1408                 (void *)&cmd_operate_attach_port_keyword,
1409                 (void *)&cmd_operate_attach_port_identifier,
1410                 NULL,
1411         },
1412 };
1413
1414 /* *** detach a specified port *** */
1415 struct cmd_operate_detach_port_result {
1416         cmdline_fixed_string_t port;
1417         cmdline_fixed_string_t keyword;
1418         portid_t port_id;
1419 };
1420
1421 static void cmd_operate_detach_port_parsed(void *parsed_result,
1422                                 __rte_unused struct cmdline *cl,
1423                                 __rte_unused void *data)
1424 {
1425         struct cmd_operate_detach_port_result *res = parsed_result;
1426
1427         if (!strcmp(res->keyword, "detach")) {
1428                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1429                 detach_port_device(res->port_id);
1430         } else {
1431                 fprintf(stderr, "Unknown parameter\n");
1432         }
1433 }
1434
1435 static cmdline_parse_token_string_t cmd_operate_detach_port_port =
1436         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1437                         port, "port");
1438 static cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1439         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1440                         keyword, "detach");
1441 static cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1442         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1443                         port_id, RTE_UINT16);
1444
1445 static cmdline_parse_inst_t cmd_operate_detach_port = {
1446         .f = cmd_operate_detach_port_parsed,
1447         .data = NULL,
1448         .help_str = "port detach <port_id>",
1449         .tokens = {
1450                 (void *)&cmd_operate_detach_port_port,
1451                 (void *)&cmd_operate_detach_port_keyword,
1452                 (void *)&cmd_operate_detach_port_port_id,
1453                 NULL,
1454         },
1455 };
1456
1457 /* *** detach device by identifier *** */
1458 struct cmd_operate_detach_device_result {
1459         cmdline_fixed_string_t device;
1460         cmdline_fixed_string_t keyword;
1461         cmdline_fixed_string_t identifier;
1462 };
1463
1464 static void cmd_operate_detach_device_parsed(void *parsed_result,
1465                                 __rte_unused struct cmdline *cl,
1466                                 __rte_unused void *data)
1467 {
1468         struct cmd_operate_detach_device_result *res = parsed_result;
1469
1470         if (!strcmp(res->keyword, "detach"))
1471                 detach_devargs(res->identifier);
1472         else
1473                 fprintf(stderr, "Unknown parameter\n");
1474 }
1475
1476 static cmdline_parse_token_string_t cmd_operate_detach_device_device =
1477         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1478                         device, "device");
1479 static cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1480         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1481                         keyword, "detach");
1482 static cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1483         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1484                         identifier, NULL);
1485
1486 static cmdline_parse_inst_t cmd_operate_detach_device = {
1487         .f = cmd_operate_detach_device_parsed,
1488         .data = NULL,
1489         .help_str = "device detach <identifier>:"
1490                 "(identifier: pci address or virtual dev name)",
1491         .tokens = {
1492                 (void *)&cmd_operate_detach_device_device,
1493                 (void *)&cmd_operate_detach_device_keyword,
1494                 (void *)&cmd_operate_detach_device_identifier,
1495                 NULL,
1496         },
1497 };
1498 /* *** configure speed for all ports *** */
1499 struct cmd_config_speed_all {
1500         cmdline_fixed_string_t port;
1501         cmdline_fixed_string_t keyword;
1502         cmdline_fixed_string_t all;
1503         cmdline_fixed_string_t item1;
1504         cmdline_fixed_string_t item2;
1505         cmdline_fixed_string_t value1;
1506         cmdline_fixed_string_t value2;
1507 };
1508
1509 static int
1510 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1511 {
1512
1513         int duplex;
1514
1515         if (!strcmp(duplexstr, "half")) {
1516                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
1517         } else if (!strcmp(duplexstr, "full")) {
1518                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1519         } else if (!strcmp(duplexstr, "auto")) {
1520                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1521         } else {
1522                 fprintf(stderr, "Unknown duplex parameter\n");
1523                 return -1;
1524         }
1525
1526         if (!strcmp(speedstr, "10")) {
1527                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1528                                 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1529         } else if (!strcmp(speedstr, "100")) {
1530                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1531                                 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1532         } else {
1533                 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1534                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1535                         return -1;
1536                 }
1537                 if (!strcmp(speedstr, "1000")) {
1538                         *speed = RTE_ETH_LINK_SPEED_1G;
1539                 } else if (!strcmp(speedstr, "10000")) {
1540                         *speed = RTE_ETH_LINK_SPEED_10G;
1541                 } else if (!strcmp(speedstr, "25000")) {
1542                         *speed = RTE_ETH_LINK_SPEED_25G;
1543                 } else if (!strcmp(speedstr, "40000")) {
1544                         *speed = RTE_ETH_LINK_SPEED_40G;
1545                 } else if (!strcmp(speedstr, "50000")) {
1546                         *speed = RTE_ETH_LINK_SPEED_50G;
1547                 } else if (!strcmp(speedstr, "100000")) {
1548                         *speed = RTE_ETH_LINK_SPEED_100G;
1549                 } else if (!strcmp(speedstr, "200000")) {
1550                         *speed = RTE_ETH_LINK_SPEED_200G;
1551                 } else if (!strcmp(speedstr, "auto")) {
1552                         *speed = RTE_ETH_LINK_SPEED_AUTONEG;
1553                 } else {
1554                         fprintf(stderr, "Unknown speed parameter\n");
1555                         return -1;
1556                 }
1557         }
1558
1559         if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1560                 *speed |= RTE_ETH_LINK_SPEED_FIXED;
1561
1562         return 0;
1563 }
1564
1565 static void
1566 cmd_config_speed_all_parsed(void *parsed_result,
1567                         __rte_unused struct cmdline *cl,
1568                         __rte_unused void *data)
1569 {
1570         struct cmd_config_speed_all *res = parsed_result;
1571         uint32_t link_speed;
1572         portid_t pid;
1573
1574         if (!all_ports_stopped()) {
1575                 fprintf(stderr, "Please stop all ports first\n");
1576                 return;
1577         }
1578
1579         if (parse_and_check_speed_duplex(res->value1, res->value2,
1580                         &link_speed) < 0)
1581                 return;
1582
1583         RTE_ETH_FOREACH_DEV(pid) {
1584                 ports[pid].dev_conf.link_speeds = link_speed;
1585         }
1586
1587         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1588 }
1589
1590 static cmdline_parse_token_string_t cmd_config_speed_all_port =
1591         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1592 static cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1593         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1594                                                         "config");
1595 static cmdline_parse_token_string_t cmd_config_speed_all_all =
1596         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1597 static cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1598         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1599 static cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1600         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1601                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1602 static cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1603         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1604 static cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1605         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1606                                                 "half#full#auto");
1607
1608 static cmdline_parse_inst_t cmd_config_speed_all = {
1609         .f = cmd_config_speed_all_parsed,
1610         .data = NULL,
1611         .help_str = "port config all speed "
1612                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1613                                                         "half|full|auto",
1614         .tokens = {
1615                 (void *)&cmd_config_speed_all_port,
1616                 (void *)&cmd_config_speed_all_keyword,
1617                 (void *)&cmd_config_speed_all_all,
1618                 (void *)&cmd_config_speed_all_item1,
1619                 (void *)&cmd_config_speed_all_value1,
1620                 (void *)&cmd_config_speed_all_item2,
1621                 (void *)&cmd_config_speed_all_value2,
1622                 NULL,
1623         },
1624 };
1625
1626 /* *** configure speed for specific port *** */
1627 struct cmd_config_speed_specific {
1628         cmdline_fixed_string_t port;
1629         cmdline_fixed_string_t keyword;
1630         portid_t id;
1631         cmdline_fixed_string_t item1;
1632         cmdline_fixed_string_t item2;
1633         cmdline_fixed_string_t value1;
1634         cmdline_fixed_string_t value2;
1635 };
1636
1637 static void
1638 cmd_config_speed_specific_parsed(void *parsed_result,
1639                                 __rte_unused struct cmdline *cl,
1640                                 __rte_unused void *data)
1641 {
1642         struct cmd_config_speed_specific *res = parsed_result;
1643         uint32_t link_speed;
1644
1645         if (port_id_is_invalid(res->id, ENABLED_WARN))
1646                 return;
1647
1648         if (!port_is_stopped(res->id)) {
1649                 fprintf(stderr, "Please stop port %d first\n", res->id);
1650                 return;
1651         }
1652
1653         if (parse_and_check_speed_duplex(res->value1, res->value2,
1654                         &link_speed) < 0)
1655                 return;
1656
1657         ports[res->id].dev_conf.link_speeds = link_speed;
1658
1659         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1660 }
1661
1662
1663 static cmdline_parse_token_string_t cmd_config_speed_specific_port =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1665                                                                 "port");
1666 static cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1668                                                                 "config");
1669 static cmdline_parse_token_num_t cmd_config_speed_specific_id =
1670         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1671 static cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1673                                                                 "speed");
1674 static cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1675         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1676                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1677 static cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1679                                                                 "duplex");
1680 static cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1682                                                         "half#full#auto");
1683
1684 static cmdline_parse_inst_t cmd_config_speed_specific = {
1685         .f = cmd_config_speed_specific_parsed,
1686         .data = NULL,
1687         .help_str = "port config <port_id> speed "
1688                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1689                                                         "half|full|auto",
1690         .tokens = {
1691                 (void *)&cmd_config_speed_specific_port,
1692                 (void *)&cmd_config_speed_specific_keyword,
1693                 (void *)&cmd_config_speed_specific_id,
1694                 (void *)&cmd_config_speed_specific_item1,
1695                 (void *)&cmd_config_speed_specific_value1,
1696                 (void *)&cmd_config_speed_specific_item2,
1697                 (void *)&cmd_config_speed_specific_value2,
1698                 NULL,
1699         },
1700 };
1701
1702 /* *** configure loopback for all ports *** */
1703 struct cmd_config_loopback_all {
1704         cmdline_fixed_string_t port;
1705         cmdline_fixed_string_t keyword;
1706         cmdline_fixed_string_t all;
1707         cmdline_fixed_string_t item;
1708         uint32_t mode;
1709 };
1710
1711 static void
1712 cmd_config_loopback_all_parsed(void *parsed_result,
1713                         __rte_unused struct cmdline *cl,
1714                         __rte_unused void *data)
1715 {
1716         struct cmd_config_loopback_all *res = parsed_result;
1717         portid_t pid;
1718
1719         if (!all_ports_stopped()) {
1720                 fprintf(stderr, "Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         RTE_ETH_FOREACH_DEV(pid) {
1725                 ports[pid].dev_conf.lpbk_mode = res->mode;
1726         }
1727
1728         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1729 }
1730
1731 static cmdline_parse_token_string_t cmd_config_loopback_all_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1733 static cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1734         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1735                                                         "config");
1736 static cmdline_parse_token_string_t cmd_config_loopback_all_all =
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1738 static cmdline_parse_token_string_t cmd_config_loopback_all_item =
1739         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1740                                                         "loopback");
1741 static cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1742         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1743
1744 static cmdline_parse_inst_t cmd_config_loopback_all = {
1745         .f = cmd_config_loopback_all_parsed,
1746         .data = NULL,
1747         .help_str = "port config all loopback <mode>",
1748         .tokens = {
1749                 (void *)&cmd_config_loopback_all_port,
1750                 (void *)&cmd_config_loopback_all_keyword,
1751                 (void *)&cmd_config_loopback_all_all,
1752                 (void *)&cmd_config_loopback_all_item,
1753                 (void *)&cmd_config_loopback_all_mode,
1754                 NULL,
1755         },
1756 };
1757
1758 /* *** configure loopback for specific port *** */
1759 struct cmd_config_loopback_specific {
1760         cmdline_fixed_string_t port;
1761         cmdline_fixed_string_t keyword;
1762         uint16_t port_id;
1763         cmdline_fixed_string_t item;
1764         uint32_t mode;
1765 };
1766
1767 static void
1768 cmd_config_loopback_specific_parsed(void *parsed_result,
1769                                 __rte_unused struct cmdline *cl,
1770                                 __rte_unused void *data)
1771 {
1772         struct cmd_config_loopback_specific *res = parsed_result;
1773
1774         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1775                 return;
1776
1777         if (!port_is_stopped(res->port_id)) {
1778                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1779                 return;
1780         }
1781
1782         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1783
1784         cmd_reconfig_device_queue(res->port_id, 1, 1);
1785 }
1786
1787
1788 static cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1790                                                                 "port");
1791 static cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1793                                                                 "config");
1794 static cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1795         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1796                                                                 RTE_UINT16);
1797 static cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1798         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1799                                                                 "loopback");
1800 static cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1801         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1802                               RTE_UINT32);
1803
1804 static cmdline_parse_inst_t cmd_config_loopback_specific = {
1805         .f = cmd_config_loopback_specific_parsed,
1806         .data = NULL,
1807         .help_str = "port config <port_id> loopback <mode>",
1808         .tokens = {
1809                 (void *)&cmd_config_loopback_specific_port,
1810                 (void *)&cmd_config_loopback_specific_keyword,
1811                 (void *)&cmd_config_loopback_specific_id,
1812                 (void *)&cmd_config_loopback_specific_item,
1813                 (void *)&cmd_config_loopback_specific_mode,
1814                 NULL,
1815         },
1816 };
1817
1818 /* *** configure txq/rxq, txd/rxd *** */
1819 struct cmd_config_rx_tx {
1820         cmdline_fixed_string_t port;
1821         cmdline_fixed_string_t keyword;
1822         cmdline_fixed_string_t all;
1823         cmdline_fixed_string_t name;
1824         uint16_t value;
1825 };
1826
1827 static void
1828 cmd_config_rx_tx_parsed(void *parsed_result,
1829                         __rte_unused struct cmdline *cl,
1830                         __rte_unused void *data)
1831 {
1832         struct cmd_config_rx_tx *res = parsed_result;
1833
1834         if (!all_ports_stopped()) {
1835                 fprintf(stderr, "Please stop all ports first\n");
1836                 return;
1837         }
1838         if (!strcmp(res->name, "rxq")) {
1839                 if (!res->value && !nb_txq) {
1840                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1841                         return;
1842                 }
1843                 if (check_nb_rxq(res->value) != 0)
1844                         return;
1845                 nb_rxq = res->value;
1846         }
1847         else if (!strcmp(res->name, "txq")) {
1848                 if (!res->value && !nb_rxq) {
1849                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1850                         return;
1851                 }
1852                 if (check_nb_txq(res->value) != 0)
1853                         return;
1854                 nb_txq = res->value;
1855         }
1856         else if (!strcmp(res->name, "rxd")) {
1857                 if (check_nb_rxd(res->value) != 0)
1858                         return;
1859                 nb_rxd = res->value;
1860         } else if (!strcmp(res->name, "txd")) {
1861                 if (check_nb_txd(res->value) != 0)
1862                         return;
1863
1864                 nb_txd = res->value;
1865         } else {
1866                 fprintf(stderr, "Unknown parameter\n");
1867                 return;
1868         }
1869
1870         fwd_config_setup();
1871
1872         init_port_config();
1873
1874         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1875 }
1876
1877 static cmdline_parse_token_string_t cmd_config_rx_tx_port =
1878         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1879 static cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1880         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1881 static cmdline_parse_token_string_t cmd_config_rx_tx_all =
1882         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1883 static cmdline_parse_token_string_t cmd_config_rx_tx_name =
1884         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1885                                                 "rxq#txq#rxd#txd");
1886 static cmdline_parse_token_num_t cmd_config_rx_tx_value =
1887         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1888
1889 static cmdline_parse_inst_t cmd_config_rx_tx = {
1890         .f = cmd_config_rx_tx_parsed,
1891         .data = NULL,
1892         .help_str = "port config all rxq|txq|rxd|txd <value>",
1893         .tokens = {
1894                 (void *)&cmd_config_rx_tx_port,
1895                 (void *)&cmd_config_rx_tx_keyword,
1896                 (void *)&cmd_config_rx_tx_all,
1897                 (void *)&cmd_config_rx_tx_name,
1898                 (void *)&cmd_config_rx_tx_value,
1899                 NULL,
1900         },
1901 };
1902
1903 /* *** config max packet length *** */
1904 struct cmd_config_max_pkt_len_result {
1905         cmdline_fixed_string_t port;
1906         cmdline_fixed_string_t keyword;
1907         cmdline_fixed_string_t all;
1908         cmdline_fixed_string_t name;
1909         uint32_t value;
1910 };
1911
1912 static void
1913 cmd_config_max_pkt_len_parsed(void *parsed_result,
1914                                 __rte_unused struct cmdline *cl,
1915                                 __rte_unused void *data)
1916 {
1917         struct cmd_config_max_pkt_len_result *res = parsed_result;
1918         portid_t port_id;
1919         int ret;
1920
1921         if (strcmp(res->name, "max-pkt-len") != 0) {
1922                 printf("Unknown parameter\n");
1923                 return;
1924         }
1925
1926         if (!all_ports_stopped()) {
1927                 fprintf(stderr, "Please stop all ports first\n");
1928                 return;
1929         }
1930
1931         RTE_ETH_FOREACH_DEV(port_id) {
1932                 struct rte_port *port = &ports[port_id];
1933
1934                 if (res->value < RTE_ETHER_MIN_LEN) {
1935                         fprintf(stderr,
1936                                 "max-pkt-len can not be less than %d\n",
1937                                 RTE_ETHER_MIN_LEN);
1938                         return;
1939                 }
1940
1941                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1942                 if (ret != 0) {
1943                         fprintf(stderr,
1944                                 "rte_eth_dev_info_get() failed for port %u\n",
1945                                 port_id);
1946                         return;
1947                 }
1948
1949                 update_mtu_from_frame_size(port_id, res->value);
1950         }
1951
1952         init_port_config();
1953
1954         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1955 }
1956
1957 static cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1959                                                                 "port");
1960 static cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1962                                                                 "config");
1963 static cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1964         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1965                                                                 "all");
1966 static cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1968                                                                 "max-pkt-len");
1969 static cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1970         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1971                                                                 RTE_UINT32);
1972
1973 static cmdline_parse_inst_t cmd_config_max_pkt_len = {
1974         .f = cmd_config_max_pkt_len_parsed,
1975         .data = NULL,
1976         .help_str = "port config all max-pkt-len <value>",
1977         .tokens = {
1978                 (void *)&cmd_config_max_pkt_len_port,
1979                 (void *)&cmd_config_max_pkt_len_keyword,
1980                 (void *)&cmd_config_max_pkt_len_all,
1981                 (void *)&cmd_config_max_pkt_len_name,
1982                 (void *)&cmd_config_max_pkt_len_value,
1983                 NULL,
1984         },
1985 };
1986
1987 /* *** config max LRO aggregated packet size *** */
1988 struct cmd_config_max_lro_pkt_size_result {
1989         cmdline_fixed_string_t port;
1990         cmdline_fixed_string_t keyword;
1991         cmdline_fixed_string_t all;
1992         cmdline_fixed_string_t name;
1993         uint32_t value;
1994 };
1995
1996 static void
1997 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1998                                 __rte_unused struct cmdline *cl,
1999                                 __rte_unused void *data)
2000 {
2001         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2002         portid_t pid;
2003
2004         if (!all_ports_stopped()) {
2005                 fprintf(stderr, "Please stop all ports first\n");
2006                 return;
2007         }
2008
2009         RTE_ETH_FOREACH_DEV(pid) {
2010                 struct rte_port *port = &ports[pid];
2011
2012                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2013                         if (res->value ==
2014                                         port->dev_conf.rxmode.max_lro_pkt_size)
2015                                 return;
2016
2017                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2018                 } else {
2019                         fprintf(stderr, "Unknown parameter\n");
2020                         return;
2021                 }
2022         }
2023
2024         init_port_config();
2025
2026         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2027 }
2028
2029 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2031                                  port, "port");
2032 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2034                                  keyword, "config");
2035 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2037                                  all, "all");
2038 static cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2039         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2040                                  name, "max-lro-pkt-size");
2041 static cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2042         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2043                               value, RTE_UINT32);
2044
2045 static cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2046         .f = cmd_config_max_lro_pkt_size_parsed,
2047         .data = NULL,
2048         .help_str = "port config all max-lro-pkt-size <value>",
2049         .tokens = {
2050                 (void *)&cmd_config_max_lro_pkt_size_port,
2051                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2052                 (void *)&cmd_config_max_lro_pkt_size_all,
2053                 (void *)&cmd_config_max_lro_pkt_size_name,
2054                 (void *)&cmd_config_max_lro_pkt_size_value,
2055                 NULL,
2056         },
2057 };
2058
2059 /* *** configure port MTU *** */
2060 struct cmd_config_mtu_result {
2061         cmdline_fixed_string_t port;
2062         cmdline_fixed_string_t keyword;
2063         cmdline_fixed_string_t mtu;
2064         portid_t port_id;
2065         uint16_t value;
2066 };
2067
2068 static void
2069 cmd_config_mtu_parsed(void *parsed_result,
2070                       __rte_unused struct cmdline *cl,
2071                       __rte_unused void *data)
2072 {
2073         struct cmd_config_mtu_result *res = parsed_result;
2074
2075         port_mtu_set(res->port_id, res->value);
2076 }
2077
2078 static cmdline_parse_token_string_t cmd_config_mtu_port =
2079         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2080                                  "port");
2081 static cmdline_parse_token_string_t cmd_config_mtu_keyword =
2082         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2083                                  "config");
2084 static cmdline_parse_token_string_t cmd_config_mtu_mtu =
2085         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2086                                  "mtu");
2087 static cmdline_parse_token_num_t cmd_config_mtu_port_id =
2088         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2089                                  RTE_UINT16);
2090 static cmdline_parse_token_num_t cmd_config_mtu_value =
2091         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2092                                  RTE_UINT16);
2093
2094 static cmdline_parse_inst_t cmd_config_mtu = {
2095         .f = cmd_config_mtu_parsed,
2096         .data = NULL,
2097         .help_str = "port config mtu <port_id> <value>",
2098         .tokens = {
2099                 (void *)&cmd_config_mtu_port,
2100                 (void *)&cmd_config_mtu_keyword,
2101                 (void *)&cmd_config_mtu_mtu,
2102                 (void *)&cmd_config_mtu_port_id,
2103                 (void *)&cmd_config_mtu_value,
2104                 NULL,
2105         },
2106 };
2107
2108 /* *** configure rx mode *** */
2109 struct cmd_config_rx_mode_flag {
2110         cmdline_fixed_string_t port;
2111         cmdline_fixed_string_t keyword;
2112         cmdline_fixed_string_t all;
2113         cmdline_fixed_string_t name;
2114         cmdline_fixed_string_t value;
2115 };
2116
2117 static void
2118 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2119                                 __rte_unused struct cmdline *cl,
2120                                 __rte_unused void *data)
2121 {
2122         struct cmd_config_rx_mode_flag *res = parsed_result;
2123
2124         if (!all_ports_stopped()) {
2125                 fprintf(stderr, "Please stop all ports first\n");
2126                 return;
2127         }
2128
2129         if (!strcmp(res->name, "drop-en")) {
2130                 if (!strcmp(res->value, "on"))
2131                         rx_drop_en = 1;
2132                 else if (!strcmp(res->value, "off"))
2133                         rx_drop_en = 0;
2134                 else {
2135                         fprintf(stderr, "Unknown parameter\n");
2136                         return;
2137                 }
2138         } else {
2139                 fprintf(stderr, "Unknown parameter\n");
2140                 return;
2141         }
2142
2143         init_port_config();
2144
2145         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2146 }
2147
2148 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2150 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2151         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2152                                                                 "config");
2153 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2155 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2157                                         "drop-en");
2158 static cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2160                                                         "on#off");
2161
2162 static cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2163         .f = cmd_config_rx_mode_flag_parsed,
2164         .data = NULL,
2165         .help_str = "port config all drop-en on|off",
2166         .tokens = {
2167                 (void *)&cmd_config_rx_mode_flag_port,
2168                 (void *)&cmd_config_rx_mode_flag_keyword,
2169                 (void *)&cmd_config_rx_mode_flag_all,
2170                 (void *)&cmd_config_rx_mode_flag_name,
2171                 (void *)&cmd_config_rx_mode_flag_value,
2172                 NULL,
2173         },
2174 };
2175
2176 /* *** configure rss *** */
2177 struct cmd_config_rss {
2178         cmdline_fixed_string_t port;
2179         cmdline_fixed_string_t keyword;
2180         cmdline_fixed_string_t all;
2181         cmdline_fixed_string_t name;
2182         cmdline_fixed_string_t value;
2183 };
2184
2185 static void
2186 cmd_config_rss_parsed(void *parsed_result,
2187                         __rte_unused struct cmdline *cl,
2188                         __rte_unused void *data)
2189 {
2190         struct cmd_config_rss *res = parsed_result;
2191         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2192         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2193         int use_default = 0;
2194         int all_updated = 1;
2195         int diag;
2196         uint16_t i;
2197         int ret;
2198
2199         if (!strcmp(res->value, "all"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2201                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2202                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2203                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2204                         RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
2205         else if (!strcmp(res->value, "eth"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2207         else if (!strcmp(res->value, "vlan"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2209         else if (!strcmp(res->value, "ip"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2211         else if (!strcmp(res->value, "udp"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2213         else if (!strcmp(res->value, "tcp"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2215         else if (!strcmp(res->value, "sctp"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2217         else if (!strcmp(res->value, "ether"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2219         else if (!strcmp(res->value, "port"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2221         else if (!strcmp(res->value, "vxlan"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2223         else if (!strcmp(res->value, "geneve"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2225         else if (!strcmp(res->value, "nvgre"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2227         else if (!strcmp(res->value, "l3-pre32"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2229         else if (!strcmp(res->value, "l3-pre40"))
2230                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2231         else if (!strcmp(res->value, "l3-pre48"))
2232                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2233         else if (!strcmp(res->value, "l3-pre56"))
2234                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2235         else if (!strcmp(res->value, "l3-pre64"))
2236                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2237         else if (!strcmp(res->value, "l3-pre96"))
2238                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2239         else if (!strcmp(res->value, "l3-src-only"))
2240                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2241         else if (!strcmp(res->value, "l3-dst-only"))
2242                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2243         else if (!strcmp(res->value, "l4-src-only"))
2244                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2245         else if (!strcmp(res->value, "l4-dst-only"))
2246                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2247         else if (!strcmp(res->value, "l2-src-only"))
2248                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2249         else if (!strcmp(res->value, "l2-dst-only"))
2250                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2251         else if (!strcmp(res->value, "l2tpv3"))
2252                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2253         else if (!strcmp(res->value, "esp"))
2254                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2255         else if (!strcmp(res->value, "ah"))
2256                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2257         else if (!strcmp(res->value, "pfcp"))
2258                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2259         else if (!strcmp(res->value, "pppoe"))
2260                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2261         else if (!strcmp(res->value, "gtpu"))
2262                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2263         else if (!strcmp(res->value, "ecpri"))
2264                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2265         else if (!strcmp(res->value, "mpls"))
2266                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2267         else if (!strcmp(res->value, "ipv4-chksum"))
2268                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2269         else if (!strcmp(res->value, "l2tpv2"))
2270                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
2271         else if (!strcmp(res->value, "none"))
2272                 rss_conf.rss_hf = 0;
2273         else if (!strcmp(res->value, "level-default")) {
2274                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2275                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2276         } else if (!strcmp(res->value, "level-outer")) {
2277                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2278                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2279         } else if (!strcmp(res->value, "level-inner")) {
2280                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2281                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2282         } else if (!strcmp(res->value, "default"))
2283                 use_default = 1;
2284         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2285                                                 atoi(res->value) < 64)
2286                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2287         else {
2288                 fprintf(stderr, "Unknown parameter\n");
2289                 return;
2290         }
2291         rss_conf.rss_key = NULL;
2292         /* Update global configuration for RSS types. */
2293         RTE_ETH_FOREACH_DEV(i) {
2294                 struct rte_eth_rss_conf local_rss_conf;
2295
2296                 ret = eth_dev_info_get_print_err(i, &dev_info);
2297                 if (ret != 0)
2298                         return;
2299
2300                 if (use_default)
2301                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2302
2303                 local_rss_conf = rss_conf;
2304                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2305                         dev_info.flow_type_rss_offloads;
2306                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2307                         printf("Port %u modified RSS hash function based on hardware support,"
2308                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2309                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2310                 }
2311                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2312                 if (diag < 0) {
2313                         all_updated = 0;
2314                         fprintf(stderr,
2315                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2316                                 i, -diag, strerror(-diag));
2317                 }
2318         }
2319         if (all_updated && !use_default) {
2320                 rss_hf = rss_conf.rss_hf;
2321                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2322         }
2323 }
2324
2325 static cmdline_parse_token_string_t cmd_config_rss_port =
2326         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2327 static cmdline_parse_token_string_t cmd_config_rss_keyword =
2328         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2329 static cmdline_parse_token_string_t cmd_config_rss_all =
2330         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2331 static cmdline_parse_token_string_t cmd_config_rss_name =
2332         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2333 static cmdline_parse_token_string_t cmd_config_rss_value =
2334         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2335
2336 static cmdline_parse_inst_t cmd_config_rss = {
2337         .f = cmd_config_rss_parsed,
2338         .data = NULL,
2339         .help_str = "port config all rss "
2340                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2341                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
2342                 "none|level-default|level-outer|level-inner|<flowtype_id>",
2343         .tokens = {
2344                 (void *)&cmd_config_rss_port,
2345                 (void *)&cmd_config_rss_keyword,
2346                 (void *)&cmd_config_rss_all,
2347                 (void *)&cmd_config_rss_name,
2348                 (void *)&cmd_config_rss_value,
2349                 NULL,
2350         },
2351 };
2352
2353 /* *** configure rss hash key *** */
2354 struct cmd_config_rss_hash_key {
2355         cmdline_fixed_string_t port;
2356         cmdline_fixed_string_t config;
2357         portid_t port_id;
2358         cmdline_fixed_string_t rss_hash_key;
2359         cmdline_fixed_string_t rss_type;
2360         cmdline_fixed_string_t key;
2361 };
2362
2363 static uint8_t
2364 hexa_digit_to_value(char hexa_digit)
2365 {
2366         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2367                 return (uint8_t) (hexa_digit - '0');
2368         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2369                 return (uint8_t) ((hexa_digit - 'a') + 10);
2370         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2371                 return (uint8_t) ((hexa_digit - 'A') + 10);
2372         /* Invalid hexa digit */
2373         return 0xFF;
2374 }
2375
2376 static uint8_t
2377 parse_and_check_key_hexa_digit(char *key, int idx)
2378 {
2379         uint8_t hexa_v;
2380
2381         hexa_v = hexa_digit_to_value(key[idx]);
2382         if (hexa_v == 0xFF)
2383                 fprintf(stderr,
2384                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2385                         key[idx], idx);
2386         return hexa_v;
2387 }
2388
2389 static void
2390 cmd_config_rss_hash_key_parsed(void *parsed_result,
2391                                __rte_unused struct cmdline *cl,
2392                                __rte_unused void *data)
2393 {
2394         struct cmd_config_rss_hash_key *res = parsed_result;
2395         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2396         uint8_t xdgt0;
2397         uint8_t xdgt1;
2398         int i;
2399         struct rte_eth_dev_info dev_info;
2400         uint8_t hash_key_size;
2401         uint32_t key_len;
2402         int ret;
2403
2404         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2405         if (ret != 0)
2406                 return;
2407
2408         if (dev_info.hash_key_size > 0 &&
2409                         dev_info.hash_key_size <= sizeof(hash_key))
2410                 hash_key_size = dev_info.hash_key_size;
2411         else {
2412                 fprintf(stderr,
2413                         "dev_info did not provide a valid hash key size\n");
2414                 return;
2415         }
2416         /* Check the length of the RSS hash key */
2417         key_len = strlen(res->key);
2418         if (key_len != (hash_key_size * 2)) {
2419                 fprintf(stderr,
2420                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2421                         (int)key_len, hash_key_size * 2);
2422                 return;
2423         }
2424         /* Translate RSS hash key into binary representation */
2425         for (i = 0; i < hash_key_size; i++) {
2426                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2427                 if (xdgt0 == 0xFF)
2428                         return;
2429                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2430                 if (xdgt1 == 0xFF)
2431                         return;
2432                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2433         }
2434         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2435                         hash_key_size);
2436 }
2437
2438 static cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2440 static cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2442                                  "config");
2443 static cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2444         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2445                                  RTE_UINT16);
2446 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2447         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2448                                  rss_hash_key, "rss-hash-key");
2449 static cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2450         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2451                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2452                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2453                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2454                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2455                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2456                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2457                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2458 static cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2459         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2460
2461 static cmdline_parse_inst_t cmd_config_rss_hash_key = {
2462         .f = cmd_config_rss_hash_key_parsed,
2463         .data = NULL,
2464         .help_str = "port config <port_id> rss-hash-key "
2465                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2466                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2467                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2468                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2469                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2470                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2471                 "<string of hex digits (variable length, NIC dependent)>",
2472         .tokens = {
2473                 (void *)&cmd_config_rss_hash_key_port,
2474                 (void *)&cmd_config_rss_hash_key_config,
2475                 (void *)&cmd_config_rss_hash_key_port_id,
2476                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2477                 (void *)&cmd_config_rss_hash_key_rss_type,
2478                 (void *)&cmd_config_rss_hash_key_value,
2479                 NULL,
2480         },
2481 };
2482
2483 /* *** cleanup txq mbufs *** */
2484 struct cmd_cleanup_txq_mbufs_result {
2485         cmdline_fixed_string_t port;
2486         cmdline_fixed_string_t keyword;
2487         cmdline_fixed_string_t name;
2488         uint16_t port_id;
2489         uint16_t queue_id;
2490         uint32_t free_cnt;
2491 };
2492
2493 static void
2494 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2495                              __rte_unused struct cmdline *cl,
2496                              __rte_unused void *data)
2497 {
2498         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2499         uint16_t port_id = res->port_id;
2500         uint16_t queue_id = res->queue_id;
2501         uint32_t free_cnt = res->free_cnt;
2502         struct rte_eth_txq_info qinfo;
2503         int ret;
2504
2505         if (test_done == 0) {
2506                 fprintf(stderr, "Please stop forwarding first\n");
2507                 return;
2508         }
2509
2510         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2511                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2512                         port_id, queue_id);
2513                 return;
2514         }
2515
2516         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2517                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2518                 return;
2519         }
2520
2521         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2522         if (ret < 0) {
2523                 fprintf(stderr,
2524                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2525                         port_id, queue_id, strerror(-ret), ret);
2526                 return;
2527         }
2528
2529         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2530                port_id, queue_id, ret);
2531 }
2532
2533 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2534         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2535                                  "port");
2536 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2537         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2538                                  "cleanup");
2539 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2540         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2541                               RTE_UINT16);
2542 static cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2543         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2544                                  "txq");
2545 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2546         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2547                               RTE_UINT16);
2548 static cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2549         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2550                               RTE_UINT32);
2551
2552 static cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2553         .f = cmd_cleanup_txq_mbufs_parsed,
2554         .data = NULL,
2555         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2556         .tokens = {
2557                 (void *)&cmd_cleanup_txq_mbufs_port,
2558                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2559                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2560                 (void *)&cmd_cleanup_txq_mbufs_txq,
2561                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2562                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2563                 NULL,
2564         },
2565 };
2566
2567 /* *** configure port rxq/txq ring size *** */
2568 struct cmd_config_rxtx_ring_size {
2569         cmdline_fixed_string_t port;
2570         cmdline_fixed_string_t config;
2571         portid_t portid;
2572         cmdline_fixed_string_t rxtxq;
2573         uint16_t qid;
2574         cmdline_fixed_string_t rsize;
2575         uint16_t size;
2576 };
2577
2578 static void
2579 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2580                                  __rte_unused struct cmdline *cl,
2581                                  __rte_unused void *data)
2582 {
2583         struct cmd_config_rxtx_ring_size *res = parsed_result;
2584         struct rte_port *port;
2585         uint8_t isrx;
2586
2587         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2588                 return;
2589
2590         if (res->portid == (portid_t)RTE_PORT_ALL) {
2591                 fprintf(stderr, "Invalid port id\n");
2592                 return;
2593         }
2594
2595         port = &ports[res->portid];
2596
2597         if (!strcmp(res->rxtxq, "rxq"))
2598                 isrx = 1;
2599         else if (!strcmp(res->rxtxq, "txq"))
2600                 isrx = 0;
2601         else {
2602                 fprintf(stderr, "Unknown parameter\n");
2603                 return;
2604         }
2605
2606         if (isrx && rx_queue_id_is_invalid(res->qid))
2607                 return;
2608         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2609                 return;
2610
2611         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2612                 fprintf(stderr,
2613                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2614                         rx_free_thresh);
2615                 return;
2616         }
2617
2618         if (isrx)
2619                 port->nb_rx_desc[res->qid] = res->size;
2620         else
2621                 port->nb_tx_desc[res->qid] = res->size;
2622
2623         cmd_reconfig_device_queue(res->portid, 0, 1);
2624 }
2625
2626 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2627         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2628                                  port, "port");
2629 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2630         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2631                                  config, "config");
2632 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2633         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2634                                  portid, RTE_UINT16);
2635 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2636         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2637                                  rxtxq, "rxq#txq");
2638 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2639         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2640                               qid, RTE_UINT16);
2641 static cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2642         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2643                                  rsize, "ring_size");
2644 static cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2645         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2646                               size, RTE_UINT16);
2647
2648 static cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2649         .f = cmd_config_rxtx_ring_size_parsed,
2650         .data = NULL,
2651         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2652         .tokens = {
2653                 (void *)&cmd_config_rxtx_ring_size_port,
2654                 (void *)&cmd_config_rxtx_ring_size_config,
2655                 (void *)&cmd_config_rxtx_ring_size_portid,
2656                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2657                 (void *)&cmd_config_rxtx_ring_size_qid,
2658                 (void *)&cmd_config_rxtx_ring_size_rsize,
2659                 (void *)&cmd_config_rxtx_ring_size_size,
2660                 NULL,
2661         },
2662 };
2663
2664 /* *** configure port rxq/txq start/stop *** */
2665 struct cmd_config_rxtx_queue {
2666         cmdline_fixed_string_t port;
2667         portid_t portid;
2668         cmdline_fixed_string_t rxtxq;
2669         uint16_t qid;
2670         cmdline_fixed_string_t opname;
2671 };
2672
2673 static void
2674 cmd_config_rxtx_queue_parsed(void *parsed_result,
2675                         __rte_unused struct cmdline *cl,
2676                         __rte_unused void *data)
2677 {
2678         struct cmd_config_rxtx_queue *res = parsed_result;
2679         struct rte_port *port;
2680         uint8_t isrx;
2681         uint8_t isstart;
2682         uint8_t *state;
2683         int ret = 0;
2684
2685         if (test_done == 0) {
2686                 fprintf(stderr, "Please stop forwarding first\n");
2687                 return;
2688         }
2689
2690         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2691                 return;
2692
2693         if (port_is_started(res->portid) != 1) {
2694                 fprintf(stderr, "Please start port %u first\n", res->portid);
2695                 return;
2696         }
2697
2698         if (!strcmp(res->rxtxq, "rxq"))
2699                 isrx = 1;
2700         else if (!strcmp(res->rxtxq, "txq"))
2701                 isrx = 0;
2702         else {
2703                 fprintf(stderr, "Unknown parameter\n");
2704                 return;
2705         }
2706
2707         if (isrx && rx_queue_id_is_invalid(res->qid))
2708                 return;
2709         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2710                 return;
2711
2712         if (!strcmp(res->opname, "start"))
2713                 isstart = 1;
2714         else if (!strcmp(res->opname, "stop"))
2715                 isstart = 0;
2716         else {
2717                 fprintf(stderr, "Unknown parameter\n");
2718                 return;
2719         }
2720
2721         if (isstart && isrx)
2722                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2723         else if (!isstart && isrx)
2724                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2725         else if (isstart && !isrx)
2726                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2727         else
2728                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2729
2730         if (ret == -ENOTSUP) {
2731                 fprintf(stderr, "Function not supported in PMD\n");
2732                 return;
2733         }
2734
2735         port = &ports[res->portid];
2736         state = isrx ? &port->rxq[res->qid].state : &port->txq[res->qid].state;
2737         *state = isstart ? RTE_ETH_QUEUE_STATE_STARTED :
2738                            RTE_ETH_QUEUE_STATE_STOPPED;
2739 }
2740
2741 static cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2742         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2743 static cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2744         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2745 static cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2746         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2747 static cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2748         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2749 static cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2750         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2751                                                 "start#stop");
2752
2753 static cmdline_parse_inst_t cmd_config_rxtx_queue = {
2754         .f = cmd_config_rxtx_queue_parsed,
2755         .data = NULL,
2756         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2757         .tokens = {
2758                 (void *)&cmd_config_rxtx_queue_port,
2759                 (void *)&cmd_config_rxtx_queue_portid,
2760                 (void *)&cmd_config_rxtx_queue_rxtxq,
2761                 (void *)&cmd_config_rxtx_queue_qid,
2762                 (void *)&cmd_config_rxtx_queue_opname,
2763                 NULL,
2764         },
2765 };
2766
2767 /* *** configure port rxq/txq deferred start on/off *** */
2768 struct cmd_config_deferred_start_rxtx_queue {
2769         cmdline_fixed_string_t port;
2770         portid_t port_id;
2771         cmdline_fixed_string_t rxtxq;
2772         uint16_t qid;
2773         cmdline_fixed_string_t opname;
2774         cmdline_fixed_string_t state;
2775 };
2776
2777 static void
2778 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2779                         __rte_unused struct cmdline *cl,
2780                         __rte_unused void *data)
2781 {
2782         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2783         struct rte_port *port;
2784         uint8_t isrx;
2785         uint8_t ison;
2786         uint8_t needreconfig = 0;
2787
2788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2789                 return;
2790
2791         if (port_is_started(res->port_id) != 0) {
2792                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2793                 return;
2794         }
2795
2796         port = &ports[res->port_id];
2797
2798         isrx = !strcmp(res->rxtxq, "rxq");
2799
2800         if (isrx && rx_queue_id_is_invalid(res->qid))
2801                 return;
2802         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2803                 return;
2804
2805         ison = !strcmp(res->state, "on");
2806
2807         if (isrx && port->rxq[res->qid].conf.rx_deferred_start != ison) {
2808                 port->rxq[res->qid].conf.rx_deferred_start = ison;
2809                 needreconfig = 1;
2810         } else if (!isrx && port->txq[res->qid].conf.tx_deferred_start != ison) {
2811                 port->txq[res->qid].conf.tx_deferred_start = ison;
2812                 needreconfig = 1;
2813         }
2814
2815         if (needreconfig)
2816                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2817 }
2818
2819 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2820         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2821                                                 port, "port");
2822 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2823         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2824                                                 port_id, RTE_UINT16);
2825 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2826         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2827                                                 rxtxq, "rxq#txq");
2828 static cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2829         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2830                                                 qid, RTE_UINT16);
2831 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2832         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2833                                                 opname, "deferred_start");
2834 static cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2835         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2836                                                 state, "on#off");
2837
2838 static cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2839         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2840         .data = NULL,
2841         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2842         .tokens = {
2843                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2844                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2845                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2846                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2847                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2848                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2849                 NULL,
2850         },
2851 };
2852
2853 /* *** configure port rxq/txq setup *** */
2854 struct cmd_setup_rxtx_queue {
2855         cmdline_fixed_string_t port;
2856         portid_t portid;
2857         cmdline_fixed_string_t rxtxq;
2858         uint16_t qid;
2859         cmdline_fixed_string_t setup;
2860 };
2861
2862 /* Common CLI fields for queue setup */
2863 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2864         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2865 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2866         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2867 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2868         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2869 static cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2870         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2871 static cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2872         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2873
2874 static void
2875 cmd_setup_rxtx_queue_parsed(
2876         void *parsed_result,
2877         __rte_unused struct cmdline *cl,
2878         __rte_unused void *data)
2879 {
2880         struct cmd_setup_rxtx_queue *res = parsed_result;
2881         struct rte_port *port;
2882         struct rte_mempool *mp;
2883         unsigned int socket_id;
2884         uint8_t isrx = 0;
2885         int ret;
2886
2887         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2888                 return;
2889
2890         if (res->portid == (portid_t)RTE_PORT_ALL) {
2891                 fprintf(stderr, "Invalid port id\n");
2892                 return;
2893         }
2894
2895         if (!strcmp(res->rxtxq, "rxq"))
2896                 isrx = 1;
2897         else if (!strcmp(res->rxtxq, "txq"))
2898                 isrx = 0;
2899         else {
2900                 fprintf(stderr, "Unknown parameter\n");
2901                 return;
2902         }
2903
2904         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2905                 fprintf(stderr, "Invalid rx queue\n");
2906                 return;
2907         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2908                 fprintf(stderr, "Invalid tx queue\n");
2909                 return;
2910         }
2911
2912         port = &ports[res->portid];
2913         if (isrx) {
2914                 socket_id = rxring_numa[res->portid];
2915                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2916                         socket_id = port->socket_id;
2917
2918                 mp = mbuf_pool_find(socket_id, 0);
2919                 if (mp == NULL) {
2920                         fprintf(stderr,
2921                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2922                                 rxring_numa[res->portid]);
2923                         return;
2924                 }
2925                 ret = rx_queue_setup(res->portid,
2926                                      res->qid,
2927                                      port->nb_rx_desc[res->qid],
2928                                      socket_id,
2929                                      &port->rxq[res->qid].conf,
2930                                      mp);
2931                 if (ret)
2932                         fprintf(stderr, "Failed to setup RX queue\n");
2933         } else {
2934                 socket_id = txring_numa[res->portid];
2935                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2936                         socket_id = port->socket_id;
2937
2938                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2939                         fprintf(stderr,
2940                                 "Failed to setup TX queue: not enough descriptors\n");
2941                         return;
2942                 }
2943                 ret = rte_eth_tx_queue_setup(res->portid,
2944                                              res->qid,
2945                                              port->nb_tx_desc[res->qid],
2946                                              socket_id,
2947                                              &port->txq[res->qid].conf);
2948                 if (ret)
2949                         fprintf(stderr, "Failed to setup TX queue\n");
2950         }
2951 }
2952
2953 static cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2954         .f = cmd_setup_rxtx_queue_parsed,
2955         .data = NULL,
2956         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2957         .tokens = {
2958                 (void *)&cmd_setup_rxtx_queue_port,
2959                 (void *)&cmd_setup_rxtx_queue_portid,
2960                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2961                 (void *)&cmd_setup_rxtx_queue_qid,
2962                 (void *)&cmd_setup_rxtx_queue_setup,
2963                 NULL,
2964         },
2965 };
2966
2967
2968 /* *** Configure RSS RETA *** */
2969 struct cmd_config_rss_reta {
2970         cmdline_fixed_string_t port;
2971         cmdline_fixed_string_t keyword;
2972         portid_t port_id;
2973         cmdline_fixed_string_t name;
2974         cmdline_fixed_string_t list_name;
2975         cmdline_fixed_string_t list_of_items;
2976 };
2977
2978 static int
2979 parse_reta_config(const char *str,
2980                   struct rte_eth_rss_reta_entry64 *reta_conf,
2981                   uint16_t nb_entries)
2982 {
2983         int i;
2984         unsigned size;
2985         uint16_t hash_index, idx, shift;
2986         uint16_t nb_queue;
2987         char s[256];
2988         const char *p, *p0 = str;
2989         char *end;
2990         enum fieldnames {
2991                 FLD_HASH_INDEX = 0,
2992                 FLD_QUEUE,
2993                 _NUM_FLD
2994         };
2995         unsigned long int_fld[_NUM_FLD];
2996         char *str_fld[_NUM_FLD];
2997
2998         while ((p = strchr(p0,'(')) != NULL) {
2999                 ++p;
3000                 if((p0 = strchr(p,')')) == NULL)
3001                         return -1;
3002
3003                 size = p0 - p;
3004                 if(size >= sizeof(s))
3005                         return -1;
3006
3007                 snprintf(s, sizeof(s), "%.*s", size, p);
3008                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3009                         return -1;
3010                 for (i = 0; i < _NUM_FLD; i++) {
3011                         errno = 0;
3012                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3013                         if (errno != 0 || end == str_fld[i] ||
3014                                         int_fld[i] > 65535)
3015                                 return -1;
3016                 }
3017
3018                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3019                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3020
3021                 if (hash_index >= nb_entries) {
3022                         fprintf(stderr, "Invalid RETA hash index=%d\n",
3023                                 hash_index);
3024                         return -1;
3025                 }
3026
3027                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
3028                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
3029                 reta_conf[idx].mask |= (1ULL << shift);
3030                 reta_conf[idx].reta[shift] = nb_queue;
3031         }
3032
3033         return 0;
3034 }
3035
3036 static void
3037 cmd_set_rss_reta_parsed(void *parsed_result,
3038                         __rte_unused struct cmdline *cl,
3039                         __rte_unused void *data)
3040 {
3041         int ret;
3042         struct rte_eth_dev_info dev_info;
3043         struct rte_eth_rss_reta_entry64 reta_conf[8];
3044         struct cmd_config_rss_reta *res = parsed_result;
3045
3046         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3047         if (ret != 0)
3048                 return;
3049
3050         if (dev_info.reta_size == 0) {
3051                 fprintf(stderr,
3052                         "Redirection table size is 0 which is invalid for RSS\n");
3053                 return;
3054         } else
3055                 printf("The reta size of port %d is %u\n",
3056                         res->port_id, dev_info.reta_size);
3057         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3058                 fprintf(stderr,
3059                         "Currently do not support more than %u entries of redirection table\n",
3060                         RTE_ETH_RSS_RETA_SIZE_512);
3061                 return;
3062         }
3063
3064         memset(reta_conf, 0, sizeof(reta_conf));
3065         if (!strcmp(res->list_name, "reta")) {
3066                 if (parse_reta_config(res->list_of_items, reta_conf,
3067                                                 dev_info.reta_size)) {
3068                         fprintf(stderr,
3069                                 "Invalid RSS Redirection Table config entered\n");
3070                         return;
3071                 }
3072                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3073                                 reta_conf, dev_info.reta_size);
3074                 if (ret != 0)
3075                         fprintf(stderr,
3076                                 "Bad redirection table parameter, return code = %d\n",
3077                                 ret);
3078         }
3079 }
3080
3081 static cmdline_parse_token_string_t cmd_config_rss_reta_port =
3082         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3083 static cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3084         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3085 static cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3086         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3087 static cmdline_parse_token_string_t cmd_config_rss_reta_name =
3088         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3089 static cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3090         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3091 static cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3092         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3093                                  NULL);
3094 static cmdline_parse_inst_t cmd_config_rss_reta = {
3095         .f = cmd_set_rss_reta_parsed,
3096         .data = NULL,
3097         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3098         .tokens = {
3099                 (void *)&cmd_config_rss_reta_port,
3100                 (void *)&cmd_config_rss_reta_keyword,
3101                 (void *)&cmd_config_rss_reta_port_id,
3102                 (void *)&cmd_config_rss_reta_name,
3103                 (void *)&cmd_config_rss_reta_list_name,
3104                 (void *)&cmd_config_rss_reta_list_of_items,
3105                 NULL,
3106         },
3107 };
3108
3109 /* *** SHOW PORT RETA INFO *** */
3110 struct cmd_showport_reta {
3111         cmdline_fixed_string_t show;
3112         cmdline_fixed_string_t port;
3113         portid_t port_id;
3114         cmdline_fixed_string_t rss;
3115         cmdline_fixed_string_t reta;
3116         uint16_t size;
3117         cmdline_fixed_string_t list_of_items;
3118 };
3119
3120 static int
3121 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3122                            uint16_t nb_entries,
3123                            char *str)
3124 {
3125         uint32_t size;
3126         const char *p, *p0 = str;
3127         char s[256];
3128         char *end;
3129         char *str_fld[8];
3130         uint16_t i;
3131         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3132                         RTE_ETH_RETA_GROUP_SIZE;
3133         int ret;
3134
3135         p = strchr(p0, '(');
3136         if (p == NULL)
3137                 return -1;
3138         p++;
3139         p0 = strchr(p, ')');
3140         if (p0 == NULL)
3141                 return -1;
3142         size = p0 - p;
3143         if (size >= sizeof(s)) {
3144                 fprintf(stderr,
3145                         "The string size exceeds the internal buffer size\n");
3146                 return -1;
3147         }
3148         snprintf(s, sizeof(s), "%.*s", size, p);
3149         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3150         if (ret <= 0 || ret != num) {
3151                 fprintf(stderr,
3152                         "The bits of masks do not match the number of reta entries: %u\n",
3153                         num);
3154                 return -1;
3155         }
3156         for (i = 0; i < ret; i++)
3157                 conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
3158
3159         return 0;
3160 }
3161
3162 static void
3163 cmd_showport_reta_parsed(void *parsed_result,
3164                          __rte_unused struct cmdline *cl,
3165                          __rte_unused void *data)
3166 {
3167         struct cmd_showport_reta *res = parsed_result;
3168         struct rte_eth_rss_reta_entry64 reta_conf[8];
3169         struct rte_eth_dev_info dev_info;
3170         uint16_t max_reta_size;
3171         int ret;
3172
3173         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3174         if (ret != 0)
3175                 return;
3176
3177         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3178         if (res->size == 0 || res->size > max_reta_size) {
3179                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3180                         res->size, max_reta_size);
3181                 return;
3182         }
3183
3184         memset(reta_conf, 0, sizeof(reta_conf));
3185         if (showport_parse_reta_config(reta_conf, res->size,
3186                                 res->list_of_items) < 0) {
3187                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3188                         res->list_of_items);
3189                 return;
3190         }
3191         port_rss_reta_info(res->port_id, reta_conf, res->size);
3192 }
3193
3194 static cmdline_parse_token_string_t cmd_showport_reta_show =
3195         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3196 static cmdline_parse_token_string_t cmd_showport_reta_port =
3197         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3198 static cmdline_parse_token_num_t cmd_showport_reta_port_id =
3199         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3200 static cmdline_parse_token_string_t cmd_showport_reta_rss =
3201         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3202 static cmdline_parse_token_string_t cmd_showport_reta_reta =
3203         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3204 static cmdline_parse_token_num_t cmd_showport_reta_size =
3205         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3206 static cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3207         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3208                                         list_of_items, NULL);
3209
3210 static cmdline_parse_inst_t cmd_showport_reta = {
3211         .f = cmd_showport_reta_parsed,
3212         .data = NULL,
3213         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3214         .tokens = {
3215                 (void *)&cmd_showport_reta_show,
3216                 (void *)&cmd_showport_reta_port,
3217                 (void *)&cmd_showport_reta_port_id,
3218                 (void *)&cmd_showport_reta_rss,
3219                 (void *)&cmd_showport_reta_reta,
3220                 (void *)&cmd_showport_reta_size,
3221                 (void *)&cmd_showport_reta_list_of_items,
3222                 NULL,
3223         },
3224 };
3225
3226 /* *** Show RSS hash configuration *** */
3227 struct cmd_showport_rss_hash {
3228         cmdline_fixed_string_t show;
3229         cmdline_fixed_string_t port;
3230         portid_t port_id;
3231         cmdline_fixed_string_t rss_hash;
3232         cmdline_fixed_string_t rss_type;
3233         cmdline_fixed_string_t key; /* optional argument */
3234 };
3235
3236 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3237                                 __rte_unused struct cmdline *cl,
3238                                 void *show_rss_key)
3239 {
3240         struct cmd_showport_rss_hash *res = parsed_result;
3241
3242         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3243 }
3244
3245 static cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3246         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3247 static cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3248         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3249 static cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3250         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3251                                  RTE_UINT16);
3252 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3253         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3254                                  "rss-hash");
3255 static cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3256         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3257
3258 static cmdline_parse_inst_t cmd_showport_rss_hash = {
3259         .f = cmd_showport_rss_hash_parsed,
3260         .data = NULL,
3261         .help_str = "show port <port_id> rss-hash",
3262         .tokens = {
3263                 (void *)&cmd_showport_rss_hash_show,
3264                 (void *)&cmd_showport_rss_hash_port,
3265                 (void *)&cmd_showport_rss_hash_port_id,
3266                 (void *)&cmd_showport_rss_hash_rss_hash,
3267                 NULL,
3268         },
3269 };
3270
3271 static cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3272         .f = cmd_showport_rss_hash_parsed,
3273         .data = (void *)1,
3274         .help_str = "show port <port_id> rss-hash key",
3275         .tokens = {
3276                 (void *)&cmd_showport_rss_hash_show,
3277                 (void *)&cmd_showport_rss_hash_port,
3278                 (void *)&cmd_showport_rss_hash_port_id,
3279                 (void *)&cmd_showport_rss_hash_rss_hash,
3280                 (void *)&cmd_showport_rss_hash_rss_key,
3281                 NULL,
3282         },
3283 };
3284
3285 /* *** Configure DCB *** */
3286 struct cmd_config_dcb {
3287         cmdline_fixed_string_t port;
3288         cmdline_fixed_string_t config;
3289         portid_t port_id;
3290         cmdline_fixed_string_t dcb;
3291         cmdline_fixed_string_t vt;
3292         cmdline_fixed_string_t vt_en;
3293         uint8_t num_tcs;
3294         cmdline_fixed_string_t pfc;
3295         cmdline_fixed_string_t pfc_en;
3296 };
3297
3298 static void
3299 cmd_config_dcb_parsed(void *parsed_result,
3300                         __rte_unused struct cmdline *cl,
3301                         __rte_unused void *data)
3302 {
3303         struct cmd_config_dcb *res = parsed_result;
3304         struct rte_eth_dcb_info dcb_info;
3305         portid_t port_id = res->port_id;
3306         struct rte_port *port;
3307         uint8_t pfc_en;
3308         int ret;
3309
3310         port = &ports[port_id];
3311         /** Check if the port is not started **/
3312         if (port->port_status != RTE_PORT_STOPPED) {
3313                 fprintf(stderr, "Please stop port %d first\n", port_id);
3314                 return;
3315         }
3316
3317         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3318                 fprintf(stderr,
3319                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3320                 return;
3321         }
3322
3323         if (nb_fwd_lcores < res->num_tcs) {
3324                 fprintf(stderr,
3325                         "nb_cores shouldn't be less than number of TCs.\n");
3326                 return;
3327         }
3328
3329         /* Check whether the port supports the report of DCB info. */
3330         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3331         if (ret == -ENOTSUP) {
3332                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3333                 return;
3334         }
3335
3336         if (!strncmp(res->pfc_en, "on", 2))
3337                 pfc_en = 1;
3338         else
3339                 pfc_en = 0;
3340
3341         /* DCB in VT mode */
3342         if (!strncmp(res->vt_en, "on", 2))
3343                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3344                                 (enum rte_eth_nb_tcs)res->num_tcs,
3345                                 pfc_en);
3346         else
3347                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3348                                 (enum rte_eth_nb_tcs)res->num_tcs,
3349                                 pfc_en);
3350         if (ret != 0) {
3351                 fprintf(stderr, "Cannot initialize network ports.\n");
3352                 return;
3353         }
3354
3355         fwd_config_setup();
3356
3357         cmd_reconfig_device_queue(port_id, 1, 1);
3358 }
3359
3360 static cmdline_parse_token_string_t cmd_config_dcb_port =
3361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3362 static cmdline_parse_token_string_t cmd_config_dcb_config =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3364 static cmdline_parse_token_num_t cmd_config_dcb_port_id =
3365         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3366 static cmdline_parse_token_string_t cmd_config_dcb_dcb =
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3368 static cmdline_parse_token_string_t cmd_config_dcb_vt =
3369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3370 static cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3372 static cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3373         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3374 static cmdline_parse_token_string_t cmd_config_dcb_pfc =
3375         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3376 static cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3377         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3378
3379 static cmdline_parse_inst_t cmd_config_dcb = {
3380         .f = cmd_config_dcb_parsed,
3381         .data = NULL,
3382         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3383         .tokens = {
3384                 (void *)&cmd_config_dcb_port,
3385                 (void *)&cmd_config_dcb_config,
3386                 (void *)&cmd_config_dcb_port_id,
3387                 (void *)&cmd_config_dcb_dcb,
3388                 (void *)&cmd_config_dcb_vt,
3389                 (void *)&cmd_config_dcb_vt_en,
3390                 (void *)&cmd_config_dcb_num_tcs,
3391                 (void *)&cmd_config_dcb_pfc,
3392                 (void *)&cmd_config_dcb_pfc_en,
3393                 NULL,
3394         },
3395 };
3396
3397 /* *** configure number of packets per burst *** */
3398 struct cmd_config_burst {
3399         cmdline_fixed_string_t port;
3400         cmdline_fixed_string_t keyword;
3401         cmdline_fixed_string_t all;
3402         cmdline_fixed_string_t name;
3403         uint16_t value;
3404 };
3405
3406 static void
3407 cmd_config_burst_parsed(void *parsed_result,
3408                         __rte_unused struct cmdline *cl,
3409                         __rte_unused void *data)
3410 {
3411         struct cmd_config_burst *res = parsed_result;
3412         struct rte_eth_dev_info dev_info;
3413         uint16_t rec_nb_pkts;
3414         int ret;
3415
3416         if (!all_ports_stopped()) {
3417                 fprintf(stderr, "Please stop all ports first\n");
3418                 return;
3419         }
3420
3421         if (!strcmp(res->name, "burst")) {
3422                 if (res->value == 0) {
3423                         /* If user gives a value of zero, query the PMD for
3424                          * its recommended Rx burst size. Testpmd uses a single
3425                          * size for all ports, so assume all ports are the same
3426                          * NIC model and use the values from Port 0.
3427                          */
3428                         ret = eth_dev_info_get_print_err(0, &dev_info);
3429                         if (ret != 0)
3430                                 return;
3431
3432                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3433
3434                         if (rec_nb_pkts == 0) {
3435                                 printf("PMD does not recommend a burst size.\n"
3436                                         "User provided value must be between"
3437                                         " 1 and %d\n", MAX_PKT_BURST);
3438                                 return;
3439                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3440                                 printf("PMD recommended burst size of %d"
3441                                         " exceeds maximum value of %d\n",
3442                                         rec_nb_pkts, MAX_PKT_BURST);
3443                                 return;
3444                         }
3445                         printf("Using PMD-provided burst value of %d\n",
3446                                 rec_nb_pkts);
3447                         nb_pkt_per_burst = rec_nb_pkts;
3448                 } else if (res->value > MAX_PKT_BURST) {
3449                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3450                                 MAX_PKT_BURST);
3451                         return;
3452                 } else
3453                         nb_pkt_per_burst = res->value;
3454         } else {
3455                 fprintf(stderr, "Unknown parameter\n");
3456                 return;
3457         }
3458
3459         init_port_config();
3460
3461         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3462 }
3463
3464 static cmdline_parse_token_string_t cmd_config_burst_port =
3465         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3466 static cmdline_parse_token_string_t cmd_config_burst_keyword =
3467         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3468 static cmdline_parse_token_string_t cmd_config_burst_all =
3469         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3470 static cmdline_parse_token_string_t cmd_config_burst_name =
3471         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3472 static cmdline_parse_token_num_t cmd_config_burst_value =
3473         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3474
3475 static cmdline_parse_inst_t cmd_config_burst = {
3476         .f = cmd_config_burst_parsed,
3477         .data = NULL,
3478         .help_str = "port config all burst <value>",
3479         .tokens = {
3480                 (void *)&cmd_config_burst_port,
3481                 (void *)&cmd_config_burst_keyword,
3482                 (void *)&cmd_config_burst_all,
3483                 (void *)&cmd_config_burst_name,
3484                 (void *)&cmd_config_burst_value,
3485                 NULL,
3486         },
3487 };
3488
3489 /* *** configure rx/tx queues *** */
3490 struct cmd_config_thresh {
3491         cmdline_fixed_string_t port;
3492         cmdline_fixed_string_t keyword;
3493         cmdline_fixed_string_t all;
3494         cmdline_fixed_string_t name;
3495         uint8_t value;
3496 };
3497
3498 static void
3499 cmd_config_thresh_parsed(void *parsed_result,
3500                         __rte_unused struct cmdline *cl,
3501                         __rte_unused void *data)
3502 {
3503         struct cmd_config_thresh *res = parsed_result;
3504
3505         if (!all_ports_stopped()) {
3506                 fprintf(stderr, "Please stop all ports first\n");
3507                 return;
3508         }
3509
3510         if (!strcmp(res->name, "txpt"))
3511                 tx_pthresh = res->value;
3512         else if(!strcmp(res->name, "txht"))
3513                 tx_hthresh = res->value;
3514         else if(!strcmp(res->name, "txwt"))
3515                 tx_wthresh = res->value;
3516         else if(!strcmp(res->name, "rxpt"))
3517                 rx_pthresh = res->value;
3518         else if(!strcmp(res->name, "rxht"))
3519                 rx_hthresh = res->value;
3520         else if(!strcmp(res->name, "rxwt"))
3521                 rx_wthresh = res->value;
3522         else {
3523                 fprintf(stderr, "Unknown parameter\n");
3524                 return;
3525         }
3526
3527         init_port_config();
3528
3529         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3530 }
3531
3532 static cmdline_parse_token_string_t cmd_config_thresh_port =
3533         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3534 static cmdline_parse_token_string_t cmd_config_thresh_keyword =
3535         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3536 static cmdline_parse_token_string_t cmd_config_thresh_all =
3537         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3538 static cmdline_parse_token_string_t cmd_config_thresh_name =
3539         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3540                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3541 static cmdline_parse_token_num_t cmd_config_thresh_value =
3542         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3543
3544 static cmdline_parse_inst_t cmd_config_thresh = {
3545         .f = cmd_config_thresh_parsed,
3546         .data = NULL,
3547         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3548         .tokens = {
3549                 (void *)&cmd_config_thresh_port,
3550                 (void *)&cmd_config_thresh_keyword,
3551                 (void *)&cmd_config_thresh_all,
3552                 (void *)&cmd_config_thresh_name,
3553                 (void *)&cmd_config_thresh_value,
3554                 NULL,
3555         },
3556 };
3557
3558 /* *** configure free/rs threshold *** */
3559 struct cmd_config_threshold {
3560         cmdline_fixed_string_t port;
3561         cmdline_fixed_string_t keyword;
3562         cmdline_fixed_string_t all;
3563         cmdline_fixed_string_t name;
3564         uint16_t value;
3565 };
3566
3567 static void
3568 cmd_config_threshold_parsed(void *parsed_result,
3569                         __rte_unused struct cmdline *cl,
3570                         __rte_unused void *data)
3571 {
3572         struct cmd_config_threshold *res = parsed_result;
3573
3574         if (!all_ports_stopped()) {
3575                 fprintf(stderr, "Please stop all ports first\n");
3576                 return;
3577         }
3578
3579         if (!strcmp(res->name, "txfreet"))
3580                 tx_free_thresh = res->value;
3581         else if (!strcmp(res->name, "txrst"))
3582                 tx_rs_thresh = res->value;
3583         else if (!strcmp(res->name, "rxfreet"))
3584                 rx_free_thresh = res->value;
3585         else {
3586                 fprintf(stderr, "Unknown parameter\n");
3587                 return;
3588         }
3589
3590         init_port_config();
3591
3592         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3593 }
3594
3595 static cmdline_parse_token_string_t cmd_config_threshold_port =
3596         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3597 static cmdline_parse_token_string_t cmd_config_threshold_keyword =
3598         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3599                                                                 "config");
3600 static cmdline_parse_token_string_t cmd_config_threshold_all =
3601         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3602 static cmdline_parse_token_string_t cmd_config_threshold_name =
3603         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3604                                                 "txfreet#txrst#rxfreet");
3605 static cmdline_parse_token_num_t cmd_config_threshold_value =
3606         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3607
3608 static cmdline_parse_inst_t cmd_config_threshold = {
3609         .f = cmd_config_threshold_parsed,
3610         .data = NULL,
3611         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3612         .tokens = {
3613                 (void *)&cmd_config_threshold_port,
3614                 (void *)&cmd_config_threshold_keyword,
3615                 (void *)&cmd_config_threshold_all,
3616                 (void *)&cmd_config_threshold_name,
3617                 (void *)&cmd_config_threshold_value,
3618                 NULL,
3619         },
3620 };
3621
3622 /* *** stop *** */
3623 struct cmd_stop_result {
3624         cmdline_fixed_string_t stop;
3625 };
3626
3627 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3628                             __rte_unused struct cmdline *cl,
3629                             __rte_unused void *data)
3630 {
3631         stop_packet_forwarding();
3632 }
3633
3634 static cmdline_parse_token_string_t cmd_stop_stop =
3635         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3636
3637 static cmdline_parse_inst_t cmd_stop = {
3638         .f = cmd_stop_parsed,
3639         .data = NULL,
3640         .help_str = "stop: Stop packet forwarding",
3641         .tokens = {
3642                 (void *)&cmd_stop_stop,
3643                 NULL,
3644         },
3645 };
3646
3647 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3648
3649 unsigned int
3650 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3651                 unsigned int *parsed_items, int check_unique_values)
3652 {
3653         unsigned int nb_item;
3654         unsigned int value;
3655         unsigned int i;
3656         unsigned int j;
3657         int value_ok;
3658         char c;
3659
3660         /*
3661          * First parse all items in the list and store their value.
3662          */
3663         value = 0;
3664         nb_item = 0;
3665         value_ok = 0;
3666         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3667                 c = str[i];
3668                 if ((c >= '0') && (c <= '9')) {
3669                         value = (unsigned int) (value * 10 + (c - '0'));
3670                         value_ok = 1;
3671                         continue;
3672                 }
3673                 if (c != ',') {
3674                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3675                         return 0;
3676                 }
3677                 if (! value_ok) {
3678                         fprintf(stderr, "No valid value before comma\n");
3679                         return 0;
3680                 }
3681                 if (nb_item < max_items) {
3682                         parsed_items[nb_item] = value;
3683                         value_ok = 0;
3684                         value = 0;
3685                 }
3686                 nb_item++;
3687         }
3688         if (nb_item >= max_items) {
3689                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3690                         item_name, nb_item + 1, max_items);
3691                 return 0;
3692         }
3693         parsed_items[nb_item++] = value;
3694         if (! check_unique_values)
3695                 return nb_item;
3696
3697         /*
3698          * Then, check that all values in the list are different.
3699          * No optimization here...
3700          */
3701         for (i = 0; i < nb_item; i++) {
3702                 for (j = i + 1; j < nb_item; j++) {
3703                         if (parsed_items[j] == parsed_items[i]) {
3704                                 fprintf(stderr,
3705                                         "duplicated %s %u at index %u and %u\n",
3706                                         item_name, parsed_items[i], i, j);
3707                                 return 0;
3708                         }
3709                 }
3710         }
3711         return nb_item;
3712 }
3713
3714 struct cmd_set_list_result {
3715         cmdline_fixed_string_t cmd_keyword;
3716         cmdline_fixed_string_t list_name;
3717         cmdline_fixed_string_t list_of_items;
3718 };
3719
3720 static void cmd_set_list_parsed(void *parsed_result,
3721                                 __rte_unused struct cmdline *cl,
3722                                 __rte_unused void *data)
3723 {
3724         struct cmd_set_list_result *res;
3725         union {
3726                 unsigned int lcorelist[RTE_MAX_LCORE];
3727                 unsigned int portlist[RTE_MAX_ETHPORTS];
3728         } parsed_items;
3729         unsigned int nb_item;
3730
3731         if (test_done == 0) {
3732                 fprintf(stderr, "Please stop forwarding first\n");
3733                 return;
3734         }
3735
3736         res = parsed_result;
3737         if (!strcmp(res->list_name, "corelist")) {
3738                 nb_item = parse_item_list(res->list_of_items, "core",
3739                                           RTE_MAX_LCORE,
3740                                           parsed_items.lcorelist, 1);
3741                 if (nb_item > 0) {
3742                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3743                         fwd_config_setup();
3744                 }
3745                 return;
3746         }
3747         if (!strcmp(res->list_name, "portlist")) {
3748                 nb_item = parse_item_list(res->list_of_items, "port",
3749                                           RTE_MAX_ETHPORTS,
3750                                           parsed_items.portlist, 1);
3751                 if (nb_item > 0) {
3752                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3753                         fwd_config_setup();
3754                 }
3755         }
3756 }
3757
3758 static cmdline_parse_token_string_t cmd_set_list_keyword =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3760                                  "set");
3761 static cmdline_parse_token_string_t cmd_set_list_name =
3762         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3763                                  "corelist#portlist");
3764 static cmdline_parse_token_string_t cmd_set_list_of_items =
3765         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3766                                  NULL);
3767
3768 static cmdline_parse_inst_t cmd_set_fwd_list = {
3769         .f = cmd_set_list_parsed,
3770         .data = NULL,
3771         .help_str = "set corelist|portlist <list0[,list1]*>",
3772         .tokens = {
3773                 (void *)&cmd_set_list_keyword,
3774                 (void *)&cmd_set_list_name,
3775                 (void *)&cmd_set_list_of_items,
3776                 NULL,
3777         },
3778 };
3779
3780 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3781
3782 struct cmd_setmask_result {
3783         cmdline_fixed_string_t set;
3784         cmdline_fixed_string_t mask;
3785         uint64_t hexavalue;
3786 };
3787
3788 static void cmd_set_mask_parsed(void *parsed_result,
3789                                 __rte_unused struct cmdline *cl,
3790                                 __rte_unused void *data)
3791 {
3792         struct cmd_setmask_result *res = parsed_result;
3793
3794         if (test_done == 0) {
3795                 fprintf(stderr, "Please stop forwarding first\n");
3796                 return;
3797         }
3798         if (!strcmp(res->mask, "coremask")) {
3799                 set_fwd_lcores_mask(res->hexavalue);
3800                 fwd_config_setup();
3801         } else if (!strcmp(res->mask, "portmask")) {
3802                 set_fwd_ports_mask(res->hexavalue);
3803                 fwd_config_setup();
3804         }
3805 }
3806
3807 static cmdline_parse_token_string_t cmd_setmask_set =
3808         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3809 static cmdline_parse_token_string_t cmd_setmask_mask =
3810         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3811                                  "coremask#portmask");
3812 static cmdline_parse_token_num_t cmd_setmask_value =
3813         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3814
3815 static cmdline_parse_inst_t cmd_set_fwd_mask = {
3816         .f = cmd_set_mask_parsed,
3817         .data = NULL,
3818         .help_str = "set coremask|portmask <hexadecimal value>",
3819         .tokens = {
3820                 (void *)&cmd_setmask_set,
3821                 (void *)&cmd_setmask_mask,
3822                 (void *)&cmd_setmask_value,
3823                 NULL,
3824         },
3825 };
3826
3827 /*
3828  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3829  */
3830 struct cmd_set_result {
3831         cmdline_fixed_string_t set;
3832         cmdline_fixed_string_t what;
3833         uint16_t value;
3834 };
3835
3836 static void cmd_set_parsed(void *parsed_result,
3837                            __rte_unused struct cmdline *cl,
3838                            __rte_unused void *data)
3839 {
3840         struct cmd_set_result *res = parsed_result;
3841         if (!strcmp(res->what, "nbport")) {
3842                 set_fwd_ports_number(res->value);
3843                 fwd_config_setup();
3844         } else if (!strcmp(res->what, "nbcore")) {
3845                 set_fwd_lcores_number(res->value);
3846                 fwd_config_setup();
3847         } else if (!strcmp(res->what, "burst"))
3848                 set_nb_pkt_per_burst(res->value);
3849         else if (!strcmp(res->what, "verbose"))
3850                 set_verbose_level(res->value);
3851 }
3852
3853 static cmdline_parse_token_string_t cmd_set_set =
3854         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3855 static cmdline_parse_token_string_t cmd_set_what =
3856         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3857                                  "nbport#nbcore#burst#verbose");
3858 static cmdline_parse_token_num_t cmd_set_value =
3859         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3860
3861 static cmdline_parse_inst_t cmd_set_numbers = {
3862         .f = cmd_set_parsed,
3863         .data = NULL,
3864         .help_str = "set nbport|nbcore|burst|verbose <value>",
3865         .tokens = {
3866                 (void *)&cmd_set_set,
3867                 (void *)&cmd_set_what,
3868                 (void *)&cmd_set_value,
3869                 NULL,
3870         },
3871 };
3872
3873 /* *** SET LOG LEVEL CONFIGURATION *** */
3874
3875 struct cmd_set_log_result {
3876         cmdline_fixed_string_t set;
3877         cmdline_fixed_string_t log;
3878         cmdline_fixed_string_t type;
3879         uint32_t level;
3880 };
3881
3882 static void
3883 cmd_set_log_parsed(void *parsed_result,
3884                    __rte_unused struct cmdline *cl,
3885                    __rte_unused void *data)
3886 {
3887         struct cmd_set_log_result *res;
3888         int ret;
3889
3890         res = parsed_result;
3891         if (!strcmp(res->type, "global"))
3892                 rte_log_set_global_level(res->level);
3893         else {
3894                 ret = rte_log_set_level_regexp(res->type, res->level);
3895                 if (ret < 0)
3896                         fprintf(stderr, "Unable to set log level\n");
3897         }
3898 }
3899
3900 static cmdline_parse_token_string_t cmd_set_log_set =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3902 static cmdline_parse_token_string_t cmd_set_log_log =
3903         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3904 static cmdline_parse_token_string_t cmd_set_log_type =
3905         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3906 static cmdline_parse_token_num_t cmd_set_log_level =
3907         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3908
3909 static cmdline_parse_inst_t cmd_set_log = {
3910         .f = cmd_set_log_parsed,
3911         .data = NULL,
3912         .help_str = "set log global|<type> <level>",
3913         .tokens = {
3914                 (void *)&cmd_set_log_set,
3915                 (void *)&cmd_set_log_log,
3916                 (void *)&cmd_set_log_type,
3917                 (void *)&cmd_set_log_level,
3918                 NULL,
3919         },
3920 };
3921
3922 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3923
3924 struct cmd_set_rxoffs_result {
3925         cmdline_fixed_string_t cmd_keyword;
3926         cmdline_fixed_string_t rxoffs;
3927         cmdline_fixed_string_t seg_offsets;
3928 };
3929
3930 static void
3931 cmd_set_rxoffs_parsed(void *parsed_result,
3932                       __rte_unused struct cmdline *cl,
3933                       __rte_unused void *data)
3934 {
3935         struct cmd_set_rxoffs_result *res;
3936         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3937         unsigned int nb_segs;
3938
3939         res = parsed_result;
3940         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3941                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3942         if (nb_segs > 0)
3943                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3944         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3945 }
3946
3947 static cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3948         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3949                                  cmd_keyword, "set");
3950 static cmdline_parse_token_string_t cmd_set_rxoffs_name =
3951         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3952                                  rxoffs, "rxoffs");
3953 static cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3954         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3955                                  seg_offsets, NULL);
3956
3957 static cmdline_parse_inst_t cmd_set_rxoffs = {
3958         .f = cmd_set_rxoffs_parsed,
3959         .data = NULL,
3960         .help_str = "set rxoffs <len0[,len1]*>",
3961         .tokens = {
3962                 (void *)&cmd_set_rxoffs_keyword,
3963                 (void *)&cmd_set_rxoffs_name,
3964                 (void *)&cmd_set_rxoffs_offsets,
3965                 NULL,
3966         },
3967 };
3968
3969 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3970
3971 struct cmd_set_rxpkts_result {
3972         cmdline_fixed_string_t cmd_keyword;
3973         cmdline_fixed_string_t rxpkts;
3974         cmdline_fixed_string_t seg_lengths;
3975 };
3976
3977 static void
3978 cmd_set_rxpkts_parsed(void *parsed_result,
3979                       __rte_unused struct cmdline *cl,
3980                       __rte_unused void *data)
3981 {
3982         struct cmd_set_rxpkts_result *res;
3983         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3984         unsigned int nb_segs;
3985
3986         res = parsed_result;
3987         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3988                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3989         if (nb_segs > 0)
3990                 set_rx_pkt_segments(seg_lengths, nb_segs);
3991         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3992 }
3993
3994 static cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3995         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3996                                  cmd_keyword, "set");
3997 static cmdline_parse_token_string_t cmd_set_rxpkts_name =
3998         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3999                                  rxpkts, "rxpkts");
4000 static cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
4001         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
4002                                  seg_lengths, NULL);
4003
4004 static cmdline_parse_inst_t cmd_set_rxpkts = {
4005         .f = cmd_set_rxpkts_parsed,
4006         .data = NULL,
4007         .help_str = "set rxpkts <len0[,len1]*>",
4008         .tokens = {
4009                 (void *)&cmd_set_rxpkts_keyword,
4010                 (void *)&cmd_set_rxpkts_name,
4011                 (void *)&cmd_set_rxpkts_lengths,
4012                 NULL,
4013         },
4014 };
4015
4016 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4017
4018 struct cmd_set_txpkts_result {
4019         cmdline_fixed_string_t cmd_keyword;
4020         cmdline_fixed_string_t txpkts;
4021         cmdline_fixed_string_t seg_lengths;
4022 };
4023
4024 static void
4025 cmd_set_txpkts_parsed(void *parsed_result,
4026                       __rte_unused struct cmdline *cl,
4027                       __rte_unused void *data)
4028 {
4029         struct cmd_set_txpkts_result *res;
4030         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4031         unsigned int nb_segs;
4032
4033         res = parsed_result;
4034         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4035                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4036         if (nb_segs > 0)
4037                 set_tx_pkt_segments(seg_lengths, nb_segs);
4038 }
4039
4040 static cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4041         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4042                                  cmd_keyword, "set");
4043 static cmdline_parse_token_string_t cmd_set_txpkts_name =
4044         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4045                                  txpkts, "txpkts");
4046 static cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4047         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4048                                  seg_lengths, NULL);
4049
4050 static cmdline_parse_inst_t cmd_set_txpkts = {
4051         .f = cmd_set_txpkts_parsed,
4052         .data = NULL,
4053         .help_str = "set txpkts <len0[,len1]*>",
4054         .tokens = {
4055                 (void *)&cmd_set_txpkts_keyword,
4056                 (void *)&cmd_set_txpkts_name,
4057                 (void *)&cmd_set_txpkts_lengths,
4058                 NULL,
4059         },
4060 };
4061
4062 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4063
4064 struct cmd_set_txsplit_result {
4065         cmdline_fixed_string_t cmd_keyword;
4066         cmdline_fixed_string_t txsplit;
4067         cmdline_fixed_string_t mode;
4068 };
4069
4070 static void
4071 cmd_set_txsplit_parsed(void *parsed_result,
4072                       __rte_unused struct cmdline *cl,
4073                       __rte_unused void *data)
4074 {
4075         struct cmd_set_txsplit_result *res;
4076
4077         res = parsed_result;
4078         set_tx_pkt_split(res->mode);
4079 }
4080
4081 static cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4082         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4083                                  cmd_keyword, "set");
4084 static cmdline_parse_token_string_t cmd_set_txsplit_name =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4086                                  txsplit, "txsplit");
4087 static cmdline_parse_token_string_t cmd_set_txsplit_mode =
4088         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4089                                  mode, NULL);
4090
4091 static cmdline_parse_inst_t cmd_set_txsplit = {
4092         .f = cmd_set_txsplit_parsed,
4093         .data = NULL,
4094         .help_str = "set txsplit on|off|rand",
4095         .tokens = {
4096                 (void *)&cmd_set_txsplit_keyword,
4097                 (void *)&cmd_set_txsplit_name,
4098                 (void *)&cmd_set_txsplit_mode,
4099                 NULL,
4100         },
4101 };
4102
4103 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4104
4105 struct cmd_set_txtimes_result {
4106         cmdline_fixed_string_t cmd_keyword;
4107         cmdline_fixed_string_t txtimes;
4108         cmdline_fixed_string_t tx_times;
4109 };
4110
4111 static void
4112 cmd_set_txtimes_parsed(void *parsed_result,
4113                        __rte_unused struct cmdline *cl,
4114                        __rte_unused void *data)
4115 {
4116         struct cmd_set_txtimes_result *res;
4117         unsigned int tx_times[2] = {0, 0};
4118         unsigned int n_times;
4119
4120         res = parsed_result;
4121         n_times = parse_item_list(res->tx_times, "tx times",
4122                                   2, tx_times, 0);
4123         if (n_times == 2)
4124                 set_tx_pkt_times(tx_times);
4125 }
4126
4127 static cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4128         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4129                                  cmd_keyword, "set");
4130 static cmdline_parse_token_string_t cmd_set_txtimes_name =
4131         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4132                                  txtimes, "txtimes");
4133 static cmdline_parse_token_string_t cmd_set_txtimes_value =
4134         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4135                                  tx_times, NULL);
4136
4137 static cmdline_parse_inst_t cmd_set_txtimes = {
4138         .f = cmd_set_txtimes_parsed,
4139         .data = NULL,
4140         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4141         .tokens = {
4142                 (void *)&cmd_set_txtimes_keyword,
4143                 (void *)&cmd_set_txtimes_name,
4144                 (void *)&cmd_set_txtimes_value,
4145                 NULL,
4146         },
4147 };
4148
4149 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4150 struct cmd_rx_vlan_filter_all_result {
4151         cmdline_fixed_string_t rx_vlan;
4152         cmdline_fixed_string_t what;
4153         cmdline_fixed_string_t all;
4154         portid_t port_id;
4155 };
4156
4157 static void
4158 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4159                               __rte_unused struct cmdline *cl,
4160                               __rte_unused void *data)
4161 {
4162         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4163
4164         if (!strcmp(res->what, "add"))
4165                 rx_vlan_all_filter_set(res->port_id, 1);
4166         else
4167                 rx_vlan_all_filter_set(res->port_id, 0);
4168 }
4169
4170 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4171         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4172                                  rx_vlan, "rx_vlan");
4173 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4174         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4175                                  what, "add#rm");
4176 static cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4177         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4178                                  all, "all");
4179 static cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4180         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4181                               port_id, RTE_UINT16);
4182
4183 static cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4184         .f = cmd_rx_vlan_filter_all_parsed,
4185         .data = NULL,
4186         .help_str = "rx_vlan add|rm all <port_id>: "
4187                 "Add/Remove all identifiers to/from the set of VLAN "
4188                 "identifiers filtered by a port",
4189         .tokens = {
4190                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4191                 (void *)&cmd_rx_vlan_filter_all_what,
4192                 (void *)&cmd_rx_vlan_filter_all_all,
4193                 (void *)&cmd_rx_vlan_filter_all_portid,
4194                 NULL,
4195         },
4196 };
4197
4198 /* *** VLAN OFFLOAD SET ON A PORT *** */
4199 struct cmd_vlan_offload_result {
4200         cmdline_fixed_string_t vlan;
4201         cmdline_fixed_string_t set;
4202         cmdline_fixed_string_t vlan_type;
4203         cmdline_fixed_string_t what;
4204         cmdline_fixed_string_t on;
4205         cmdline_fixed_string_t port_id;
4206 };
4207
4208 static void
4209 cmd_vlan_offload_parsed(void *parsed_result,
4210                           __rte_unused struct cmdline *cl,
4211                           __rte_unused void *data)
4212 {
4213         int on;
4214         struct cmd_vlan_offload_result *res = parsed_result;
4215         char *str;
4216         int i, len = 0;
4217         portid_t port_id = 0;
4218         unsigned int tmp;
4219
4220         str = res->port_id;
4221         len = strnlen(str, STR_TOKEN_SIZE);
4222         i = 0;
4223         /* Get port_id first */
4224         while(i < len){
4225                 if(str[i] == ',')
4226                         break;
4227
4228                 i++;
4229         }
4230         str[i]='\0';
4231         tmp = strtoul(str, NULL, 0);
4232         /* If port_id greater that what portid_t can represent, return */
4233         if(tmp >= RTE_MAX_ETHPORTS)
4234                 return;
4235         port_id = (portid_t)tmp;
4236
4237         if (!strcmp(res->on, "on"))
4238                 on = 1;
4239         else
4240                 on = 0;
4241
4242         if (!strcmp(res->what, "strip"))
4243                 rx_vlan_strip_set(port_id,  on);
4244         else if(!strcmp(res->what, "stripq")){
4245                 uint16_t queue_id = 0;
4246
4247                 /* No queue_id, return */
4248                 if(i + 1 >= len) {
4249                         fprintf(stderr, "must specify (port,queue_id)\n");
4250                         return;
4251                 }
4252                 tmp = strtoul(str + i + 1, NULL, 0);
4253                 /* If queue_id greater that what 16-bits can represent, return */
4254                 if(tmp > 0xffff)
4255                         return;
4256
4257                 queue_id = (uint16_t)tmp;
4258                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4259         }
4260         else if (!strcmp(res->what, "filter"))
4261                 rx_vlan_filter_set(port_id, on);
4262         else if (!strcmp(res->what, "qinq_strip"))
4263                 rx_vlan_qinq_strip_set(port_id, on);
4264         else
4265                 vlan_extend_set(port_id, on);
4266
4267         return;
4268 }
4269
4270 static cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4271         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4272                                  vlan, "vlan");
4273 static cmdline_parse_token_string_t cmd_vlan_offload_set =
4274         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4275                                  set, "set");
4276 static cmdline_parse_token_string_t cmd_vlan_offload_what =
4277         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4278                                 what, "strip#filter#qinq_strip#extend#stripq");
4279 static cmdline_parse_token_string_t cmd_vlan_offload_on =
4280         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4281                               on, "on#off");
4282 static cmdline_parse_token_string_t cmd_vlan_offload_portid =
4283         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4284                               port_id, NULL);
4285
4286 static cmdline_parse_inst_t cmd_vlan_offload = {
4287         .f = cmd_vlan_offload_parsed,
4288         .data = NULL,
4289         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4290                 "<port_id[,queue_id]>: "
4291                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4292         .tokens = {
4293                 (void *)&cmd_vlan_offload_vlan,
4294                 (void *)&cmd_vlan_offload_set,
4295                 (void *)&cmd_vlan_offload_what,
4296                 (void *)&cmd_vlan_offload_on,
4297                 (void *)&cmd_vlan_offload_portid,
4298                 NULL,
4299         },
4300 };
4301
4302 /* *** VLAN TPID SET ON A PORT *** */
4303 struct cmd_vlan_tpid_result {
4304         cmdline_fixed_string_t vlan;
4305         cmdline_fixed_string_t set;
4306         cmdline_fixed_string_t vlan_type;
4307         cmdline_fixed_string_t what;
4308         uint16_t tp_id;
4309         portid_t port_id;
4310 };
4311
4312 static void
4313 cmd_vlan_tpid_parsed(void *parsed_result,
4314                           __rte_unused struct cmdline *cl,
4315                           __rte_unused void *data)
4316 {
4317         struct cmd_vlan_tpid_result *res = parsed_result;
4318         enum rte_vlan_type vlan_type;
4319
4320         if (!strcmp(res->vlan_type, "inner"))
4321                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4322         else if (!strcmp(res->vlan_type, "outer"))
4323                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4324         else {
4325                 fprintf(stderr, "Unknown vlan type\n");
4326                 return;
4327         }
4328         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4329 }
4330
4331 static cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4332         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4333                                  vlan, "vlan");
4334 static cmdline_parse_token_string_t cmd_vlan_tpid_set =
4335         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4336                                  set, "set");
4337 static cmdline_parse_token_string_t cmd_vlan_type =
4338         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4339                                  vlan_type, "inner#outer");
4340 static cmdline_parse_token_string_t cmd_vlan_tpid_what =
4341         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4342                                  what, "tpid");
4343 static cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4344         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4345                               tp_id, RTE_UINT16);
4346 static cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4347         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4348                               port_id, RTE_UINT16);
4349
4350 static cmdline_parse_inst_t cmd_vlan_tpid = {
4351         .f = cmd_vlan_tpid_parsed,
4352         .data = NULL,
4353         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4354                 "Set the VLAN Ether type",
4355         .tokens = {
4356                 (void *)&cmd_vlan_tpid_vlan,
4357                 (void *)&cmd_vlan_tpid_set,
4358                 (void *)&cmd_vlan_type,
4359                 (void *)&cmd_vlan_tpid_what,
4360                 (void *)&cmd_vlan_tpid_tpid,
4361                 (void *)&cmd_vlan_tpid_portid,
4362                 NULL,
4363         },
4364 };
4365
4366 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4367 struct cmd_rx_vlan_filter_result {
4368         cmdline_fixed_string_t rx_vlan;
4369         cmdline_fixed_string_t what;
4370         uint16_t vlan_id;
4371         portid_t port_id;
4372 };
4373
4374 static void
4375 cmd_rx_vlan_filter_parsed(void *parsed_result,
4376                           __rte_unused struct cmdline *cl,
4377                           __rte_unused void *data)
4378 {
4379         struct cmd_rx_vlan_filter_result *res = parsed_result;
4380
4381         if (!strcmp(res->what, "add"))
4382                 rx_vft_set(res->port_id, res->vlan_id, 1);
4383         else
4384                 rx_vft_set(res->port_id, res->vlan_id, 0);
4385 }
4386
4387 static cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4388         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4389                                  rx_vlan, "rx_vlan");
4390 static cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4391         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4392                                  what, "add#rm");
4393 static cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4394         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4395                               vlan_id, RTE_UINT16);
4396 static cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4397         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4398                               port_id, RTE_UINT16);
4399
4400 static cmdline_parse_inst_t cmd_rx_vlan_filter = {
4401         .f = cmd_rx_vlan_filter_parsed,
4402         .data = NULL,
4403         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4404                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4405                 "identifiers filtered by a port",
4406         .tokens = {
4407                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4408                 (void *)&cmd_rx_vlan_filter_what,
4409                 (void *)&cmd_rx_vlan_filter_vlanid,
4410                 (void *)&cmd_rx_vlan_filter_portid,
4411                 NULL,
4412         },
4413 };
4414
4415 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4416 struct cmd_tx_vlan_set_result {
4417         cmdline_fixed_string_t tx_vlan;
4418         cmdline_fixed_string_t set;
4419         portid_t port_id;
4420         uint16_t vlan_id;
4421 };
4422
4423 static void
4424 cmd_tx_vlan_set_parsed(void *parsed_result,
4425                        __rte_unused struct cmdline *cl,
4426                        __rte_unused void *data)
4427 {
4428         struct cmd_tx_vlan_set_result *res = parsed_result;
4429
4430         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4431                 return;
4432
4433         if (!port_is_stopped(res->port_id)) {
4434                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4435                 return;
4436         }
4437
4438         tx_vlan_set(res->port_id, res->vlan_id);
4439
4440         cmd_reconfig_device_queue(res->port_id, 1, 1);
4441 }
4442
4443 static cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4444         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4445                                  tx_vlan, "tx_vlan");
4446 static cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4447         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4448                                  set, "set");
4449 static cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4450         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4451                               port_id, RTE_UINT16);
4452 static cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4453         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4454                               vlan_id, RTE_UINT16);
4455
4456 static cmdline_parse_inst_t cmd_tx_vlan_set = {
4457         .f = cmd_tx_vlan_set_parsed,
4458         .data = NULL,
4459         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4460                 "Enable hardware insertion of a single VLAN header "
4461                 "with a given TAG Identifier in packets sent on a port",
4462         .tokens = {
4463                 (void *)&cmd_tx_vlan_set_tx_vlan,
4464                 (void *)&cmd_tx_vlan_set_set,
4465                 (void *)&cmd_tx_vlan_set_portid,
4466                 (void *)&cmd_tx_vlan_set_vlanid,
4467                 NULL,
4468         },
4469 };
4470
4471 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4472 struct cmd_tx_vlan_set_qinq_result {
4473         cmdline_fixed_string_t tx_vlan;
4474         cmdline_fixed_string_t set;
4475         portid_t port_id;
4476         uint16_t vlan_id;
4477         uint16_t vlan_id_outer;
4478 };
4479
4480 static void
4481 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4482                             __rte_unused struct cmdline *cl,
4483                             __rte_unused void *data)
4484 {
4485         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4486
4487         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4488                 return;
4489
4490         if (!port_is_stopped(res->port_id)) {
4491                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4492                 return;
4493         }
4494
4495         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4496
4497         cmd_reconfig_device_queue(res->port_id, 1, 1);
4498 }
4499
4500 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4501         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4502                 tx_vlan, "tx_vlan");
4503 static cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4504         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4505                 set, "set");
4506 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4507         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4508                 port_id, RTE_UINT16);
4509 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4510         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4511                 vlan_id, RTE_UINT16);
4512 static cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4513         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4514                 vlan_id_outer, RTE_UINT16);
4515
4516 static cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4517         .f = cmd_tx_vlan_set_qinq_parsed,
4518         .data = NULL,
4519         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4520                 "Enable hardware insertion of double VLAN header "
4521                 "with given TAG Identifiers in packets sent on a port",
4522         .tokens = {
4523                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4524                 (void *)&cmd_tx_vlan_set_qinq_set,
4525                 (void *)&cmd_tx_vlan_set_qinq_portid,
4526                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4527                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4528                 NULL,
4529         },
4530 };
4531
4532 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4533 struct cmd_tx_vlan_set_pvid_result {
4534         cmdline_fixed_string_t tx_vlan;
4535         cmdline_fixed_string_t set;
4536         cmdline_fixed_string_t pvid;
4537         portid_t port_id;
4538         uint16_t vlan_id;
4539         cmdline_fixed_string_t mode;
4540 };
4541
4542 static void
4543 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4544                             __rte_unused struct cmdline *cl,
4545                             __rte_unused void *data)
4546 {
4547         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4548
4549         if (strcmp(res->mode, "on") == 0)
4550                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4551         else
4552                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4553 }
4554
4555 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4556         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4557                                  tx_vlan, "tx_vlan");
4558 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4559         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4560                                  set, "set");
4561 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4562         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4563                                  pvid, "pvid");
4564 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4565         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4566                              port_id, RTE_UINT16);
4567 static cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4568         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4569                               vlan_id, RTE_UINT16);
4570 static cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4571         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4572                                  mode, "on#off");
4573
4574 static cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4575         .f = cmd_tx_vlan_set_pvid_parsed,
4576         .data = NULL,
4577         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4578         .tokens = {
4579                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4580                 (void *)&cmd_tx_vlan_set_pvid_set,
4581                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4582                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4583                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4584                 (void *)&cmd_tx_vlan_set_pvid_mode,
4585                 NULL,
4586         },
4587 };
4588
4589 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4590 struct cmd_tx_vlan_reset_result {
4591         cmdline_fixed_string_t tx_vlan;
4592         cmdline_fixed_string_t reset;
4593         portid_t port_id;
4594 };
4595
4596 static void
4597 cmd_tx_vlan_reset_parsed(void *parsed_result,
4598                          __rte_unused struct cmdline *cl,
4599                          __rte_unused void *data)
4600 {
4601         struct cmd_tx_vlan_reset_result *res = parsed_result;
4602
4603         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4604                 return;
4605
4606         if (!port_is_stopped(res->port_id)) {
4607                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4608                 return;
4609         }
4610
4611         tx_vlan_reset(res->port_id);
4612
4613         cmd_reconfig_device_queue(res->port_id, 1, 1);
4614 }
4615
4616 static cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4617         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4618                                  tx_vlan, "tx_vlan");
4619 static cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4620         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4621                                  reset, "reset");
4622 static cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4623         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4624                               port_id, RTE_UINT16);
4625
4626 static cmdline_parse_inst_t cmd_tx_vlan_reset = {
4627         .f = cmd_tx_vlan_reset_parsed,
4628         .data = NULL,
4629         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4630                 "VLAN header in packets sent on a port",
4631         .tokens = {
4632                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4633                 (void *)&cmd_tx_vlan_reset_reset,
4634                 (void *)&cmd_tx_vlan_reset_portid,
4635                 NULL,
4636         },
4637 };
4638
4639
4640 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4641 struct cmd_csum_result {
4642         cmdline_fixed_string_t csum;
4643         cmdline_fixed_string_t mode;
4644         cmdline_fixed_string_t proto;
4645         cmdline_fixed_string_t hwsw;
4646         portid_t port_id;
4647 };
4648
4649 static void
4650 csum_show(int port_id)
4651 {
4652         struct rte_eth_dev_info dev_info;
4653         uint64_t tx_offloads;
4654         int ret;
4655
4656         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4657         printf("Parse tunnel is %s\n",
4658                 (ports[port_id].parse_tunnel) ? "on" : "off");
4659         printf("IP checksum offload is %s\n",
4660                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4661         printf("UDP checksum offload is %s\n",
4662                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4663         printf("TCP checksum offload is %s\n",
4664                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4665         printf("SCTP checksum offload is %s\n",
4666                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4667         printf("Outer-Ip checksum offload is %s\n",
4668                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4669         printf("Outer-Udp checksum offload is %s\n",
4670                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4671
4672         /* display warnings if configuration is not supported by the NIC */
4673         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4674         if (ret != 0)
4675                 return;
4676
4677         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4678                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4679                 fprintf(stderr,
4680                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4681                         port_id);
4682         }
4683         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4684                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4685                 fprintf(stderr,
4686                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4687                         port_id);
4688         }
4689         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4690                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4691                 fprintf(stderr,
4692                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4693                         port_id);
4694         }
4695         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4696                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4697                 fprintf(stderr,
4698                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4699                         port_id);
4700         }
4701         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4702                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4703                 fprintf(stderr,
4704                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4705                         port_id);
4706         }
4707         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4708                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4709                         == 0) {
4710                 fprintf(stderr,
4711                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4712                         port_id);
4713         }
4714 }
4715
4716 static void
4717 cmd_config_queue_tx_offloads(struct rte_port *port)
4718 {
4719         int k;
4720
4721         /* Apply queue tx offloads configuration */
4722         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4723                 port->txq[k].conf.offloads =
4724                         port->dev_conf.txmode.offloads;
4725 }
4726
4727 static void
4728 cmd_csum_parsed(void *parsed_result,
4729                        __rte_unused struct cmdline *cl,
4730                        __rte_unused void *data)
4731 {
4732         struct cmd_csum_result *res = parsed_result;
4733         int hw = 0;
4734         uint64_t csum_offloads = 0;
4735         struct rte_eth_dev_info dev_info;
4736         int ret;
4737
4738         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4739                 fprintf(stderr, "invalid port %d\n", res->port_id);
4740                 return;
4741         }
4742         if (!port_is_stopped(res->port_id)) {
4743                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4744                 return;
4745         }
4746
4747         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4748         if (ret != 0)
4749                 return;
4750
4751         if (!strcmp(res->mode, "set")) {
4752
4753                 if (!strcmp(res->hwsw, "hw"))
4754                         hw = 1;
4755
4756                 if (!strcmp(res->proto, "ip")) {
4757                         if (hw == 0 || (dev_info.tx_offload_capa &
4758                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4759                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4760                         } else {
4761                                 fprintf(stderr,
4762                                         "IP checksum offload is not supported by port %u\n",
4763                                         res->port_id);
4764                         }
4765                 } else if (!strcmp(res->proto, "udp")) {
4766                         if (hw == 0 || (dev_info.tx_offload_capa &
4767                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4768                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4769                         } else {
4770                                 fprintf(stderr,
4771                                         "UDP checksum offload is not supported by port %u\n",
4772                                         res->port_id);
4773                         }
4774                 } else if (!strcmp(res->proto, "tcp")) {
4775                         if (hw == 0 || (dev_info.tx_offload_capa &
4776                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4777                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4778                         } else {
4779                                 fprintf(stderr,
4780                                         "TCP checksum offload is not supported by port %u\n",
4781                                         res->port_id);
4782                         }
4783                 } else if (!strcmp(res->proto, "sctp")) {
4784                         if (hw == 0 || (dev_info.tx_offload_capa &
4785                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4786                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4787                         } else {
4788                                 fprintf(stderr,
4789                                         "SCTP checksum offload is not supported by port %u\n",
4790                                         res->port_id);
4791                         }
4792                 } else if (!strcmp(res->proto, "outer-ip")) {
4793                         if (hw == 0 || (dev_info.tx_offload_capa &
4794                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4795                                 csum_offloads |=
4796                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4797                         } else {
4798                                 fprintf(stderr,
4799                                         "Outer IP checksum offload is not supported by port %u\n",
4800                                         res->port_id);
4801                         }
4802                 } else if (!strcmp(res->proto, "outer-udp")) {
4803                         if (hw == 0 || (dev_info.tx_offload_capa &
4804                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4805                                 csum_offloads |=
4806                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4807                         } else {
4808                                 fprintf(stderr,
4809                                         "Outer UDP checksum offload is not supported by port %u\n",
4810                                         res->port_id);
4811                         }
4812                 }
4813
4814                 if (hw) {
4815                         ports[res->port_id].dev_conf.txmode.offloads |=
4816                                                         csum_offloads;
4817                 } else {
4818                         ports[res->port_id].dev_conf.txmode.offloads &=
4819                                                         (~csum_offloads);
4820                 }
4821                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4822         }
4823         csum_show(res->port_id);
4824
4825         cmd_reconfig_device_queue(res->port_id, 1, 1);
4826 }
4827
4828 static cmdline_parse_token_string_t cmd_csum_csum =
4829         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4830                                 csum, "csum");
4831 static cmdline_parse_token_string_t cmd_csum_mode =
4832         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4833                                 mode, "set");
4834 static cmdline_parse_token_string_t cmd_csum_proto =
4835         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4836                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4837 static cmdline_parse_token_string_t cmd_csum_hwsw =
4838         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4839                                 hwsw, "hw#sw");
4840 static cmdline_parse_token_num_t cmd_csum_portid =
4841         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4842                                 port_id, RTE_UINT16);
4843
4844 static cmdline_parse_inst_t cmd_csum_set = {
4845         .f = cmd_csum_parsed,
4846         .data = NULL,
4847         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4848                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4849                 "using csum forward engine",
4850         .tokens = {
4851                 (void *)&cmd_csum_csum,
4852                 (void *)&cmd_csum_mode,
4853                 (void *)&cmd_csum_proto,
4854                 (void *)&cmd_csum_hwsw,
4855                 (void *)&cmd_csum_portid,
4856                 NULL,
4857         },
4858 };
4859
4860 static cmdline_parse_token_string_t cmd_csum_mode_show =
4861         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4862                                 mode, "show");
4863
4864 static cmdline_parse_inst_t cmd_csum_show = {
4865         .f = cmd_csum_parsed,
4866         .data = NULL,
4867         .help_str = "csum show <port_id>: Show checksum offload configuration",
4868         .tokens = {
4869                 (void *)&cmd_csum_csum,
4870                 (void *)&cmd_csum_mode_show,
4871                 (void *)&cmd_csum_portid,
4872                 NULL,
4873         },
4874 };
4875
4876 /* Enable/disable tunnel parsing */
4877 struct cmd_csum_tunnel_result {
4878         cmdline_fixed_string_t csum;
4879         cmdline_fixed_string_t parse;
4880         cmdline_fixed_string_t onoff;
4881         portid_t port_id;
4882 };
4883
4884 static void
4885 cmd_csum_tunnel_parsed(void *parsed_result,
4886                        __rte_unused struct cmdline *cl,
4887                        __rte_unused void *data)
4888 {
4889         struct cmd_csum_tunnel_result *res = parsed_result;
4890
4891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4892                 return;
4893
4894         if (!strcmp(res->onoff, "on"))
4895                 ports[res->port_id].parse_tunnel = 1;
4896         else
4897                 ports[res->port_id].parse_tunnel = 0;
4898
4899         csum_show(res->port_id);
4900 }
4901
4902 static cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4903         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4904                                 csum, "csum");
4905 static cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4906         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4907                                 parse, "parse-tunnel");
4908 static cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4909         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4910                                 onoff, "on#off");
4911 static cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4912         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4913                                 port_id, RTE_UINT16);
4914
4915 static cmdline_parse_inst_t cmd_csum_tunnel = {
4916         .f = cmd_csum_tunnel_parsed,
4917         .data = NULL,
4918         .help_str = "csum parse-tunnel on|off <port_id>: "
4919                 "Enable/Disable parsing of tunnels for csum engine",
4920         .tokens = {
4921                 (void *)&cmd_csum_tunnel_csum,
4922                 (void *)&cmd_csum_tunnel_parse,
4923                 (void *)&cmd_csum_tunnel_onoff,
4924                 (void *)&cmd_csum_tunnel_portid,
4925                 NULL,
4926         },
4927 };
4928
4929 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4930 struct cmd_tso_set_result {
4931         cmdline_fixed_string_t tso;
4932         cmdline_fixed_string_t mode;
4933         uint16_t tso_segsz;
4934         portid_t port_id;
4935 };
4936
4937 static void
4938 cmd_tso_set_parsed(void *parsed_result,
4939                        __rte_unused struct cmdline *cl,
4940                        __rte_unused void *data)
4941 {
4942         struct cmd_tso_set_result *res = parsed_result;
4943         struct rte_eth_dev_info dev_info;
4944         int ret;
4945
4946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4947                 return;
4948         if (!port_is_stopped(res->port_id)) {
4949                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4950                 return;
4951         }
4952
4953         if (!strcmp(res->mode, "set"))
4954                 ports[res->port_id].tso_segsz = res->tso_segsz;
4955
4956         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4957         if (ret != 0)
4958                 return;
4959
4960         if ((ports[res->port_id].tso_segsz != 0) &&
4961                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4962                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4963                         res->port_id);
4964                 return;
4965         }
4966
4967         if (ports[res->port_id].tso_segsz == 0) {
4968                 ports[res->port_id].dev_conf.txmode.offloads &=
4969                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4970                 printf("TSO for non-tunneled packets is disabled\n");
4971         } else {
4972                 ports[res->port_id].dev_conf.txmode.offloads |=
4973                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4974                 printf("TSO segment size for non-tunneled packets is %d\n",
4975                         ports[res->port_id].tso_segsz);
4976         }
4977         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4978
4979         /* display warnings if configuration is not supported by the NIC */
4980         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4981         if (ret != 0)
4982                 return;
4983
4984         if ((ports[res->port_id].tso_segsz != 0) &&
4985                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4986                 fprintf(stderr,
4987                         "Warning: TSO enabled but not supported by port %d\n",
4988                         res->port_id);
4989         }
4990
4991         cmd_reconfig_device_queue(res->port_id, 1, 1);
4992 }
4993
4994 static cmdline_parse_token_string_t cmd_tso_set_tso =
4995         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4996                                 tso, "tso");
4997 static cmdline_parse_token_string_t cmd_tso_set_mode =
4998         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4999                                 mode, "set");
5000 static cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
5001         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
5002                                 tso_segsz, RTE_UINT16);
5003 static cmdline_parse_token_num_t cmd_tso_set_portid =
5004         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
5005                                 port_id, RTE_UINT16);
5006
5007 static cmdline_parse_inst_t cmd_tso_set = {
5008         .f = cmd_tso_set_parsed,
5009         .data = NULL,
5010         .help_str = "tso set <tso_segsz> <port_id>: "
5011                 "Set TSO segment size of non-tunneled packets for csum engine "
5012                 "(0 to disable)",
5013         .tokens = {
5014                 (void *)&cmd_tso_set_tso,
5015                 (void *)&cmd_tso_set_mode,
5016                 (void *)&cmd_tso_set_tso_segsz,
5017                 (void *)&cmd_tso_set_portid,
5018                 NULL,
5019         },
5020 };
5021
5022 static cmdline_parse_token_string_t cmd_tso_show_mode =
5023         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
5024                                 mode, "show");
5025
5026
5027 static cmdline_parse_inst_t cmd_tso_show = {
5028         .f = cmd_tso_set_parsed,
5029         .data = NULL,
5030         .help_str = "tso show <port_id>: "
5031                 "Show TSO segment size of non-tunneled packets for csum engine",
5032         .tokens = {
5033                 (void *)&cmd_tso_set_tso,
5034                 (void *)&cmd_tso_show_mode,
5035                 (void *)&cmd_tso_set_portid,
5036                 NULL,
5037         },
5038 };
5039
5040 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5041 struct cmd_tunnel_tso_set_result {
5042         cmdline_fixed_string_t tso;
5043         cmdline_fixed_string_t mode;
5044         uint16_t tso_segsz;
5045         portid_t port_id;
5046 };
5047
5048 static struct rte_eth_dev_info
5049 check_tunnel_tso_nic_support(portid_t port_id)
5050 {
5051         struct rte_eth_dev_info dev_info;
5052
5053         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5054                 return dev_info;
5055
5056         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5057                 fprintf(stderr,
5058                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5059                         port_id);
5060         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5061                 fprintf(stderr,
5062                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5063                         port_id);
5064         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5065                 fprintf(stderr,
5066                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5067                         port_id);
5068         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5069                 fprintf(stderr,
5070                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5071                         port_id);
5072         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5073                 fprintf(stderr,
5074                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5075                         port_id);
5076         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5077                 fprintf(stderr,
5078                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5079                         port_id);
5080         return dev_info;
5081 }
5082
5083 static void
5084 cmd_tunnel_tso_set_parsed(void *parsed_result,
5085                           __rte_unused struct cmdline *cl,
5086                           __rte_unused void *data)
5087 {
5088         struct cmd_tunnel_tso_set_result *res = parsed_result;
5089         struct rte_eth_dev_info dev_info;
5090
5091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5092                 return;
5093         if (!port_is_stopped(res->port_id)) {
5094                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5095                 return;
5096         }
5097
5098         if (!strcmp(res->mode, "set"))
5099                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5100
5101         dev_info = check_tunnel_tso_nic_support(res->port_id);
5102         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5103                 ports[res->port_id].dev_conf.txmode.offloads &=
5104                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5105                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5106                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5107                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5108                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5109                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5110                 printf("TSO for tunneled packets is disabled\n");
5111         } else {
5112                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5113                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5114                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5115                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5116                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5117                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5118
5119                 ports[res->port_id].dev_conf.txmode.offloads |=
5120                         (tso_offloads & dev_info.tx_offload_capa);
5121                 printf("TSO segment size for tunneled packets is %d\n",
5122                         ports[res->port_id].tunnel_tso_segsz);
5123
5124                 /* Below conditions are needed to make it work:
5125                  * (1) tunnel TSO is supported by the NIC;
5126                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5127                  * are recognized;
5128                  * (3) for tunneled pkts with outer L3 of IPv4,
5129                  * "csum set outer-ip" must be set to hw, because after tso,
5130                  * total_len of outer IP header is changed, and the checksum
5131                  * of outer IP header calculated by sw should be wrong; that
5132                  * is not necessary for IPv6 tunneled pkts because there's no
5133                  * checksum in IP header anymore.
5134                  */
5135
5136                 if (!ports[res->port_id].parse_tunnel)
5137                         fprintf(stderr,
5138                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5139                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5140                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5141                         fprintf(stderr,
5142                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5143         }
5144
5145         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5146         cmd_reconfig_device_queue(res->port_id, 1, 1);
5147 }
5148
5149 static cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5150         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5151                                 tso, "tunnel_tso");
5152 static cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5153         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5154                                 mode, "set");
5155 static cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5156         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5157                                 tso_segsz, RTE_UINT16);
5158 static cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5159         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5160                                 port_id, RTE_UINT16);
5161
5162 static cmdline_parse_inst_t cmd_tunnel_tso_set = {
5163         .f = cmd_tunnel_tso_set_parsed,
5164         .data = NULL,
5165         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5166                 "Set TSO segment size of tunneled packets for csum engine "
5167                 "(0 to disable)",
5168         .tokens = {
5169                 (void *)&cmd_tunnel_tso_set_tso,
5170                 (void *)&cmd_tunnel_tso_set_mode,
5171                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5172                 (void *)&cmd_tunnel_tso_set_portid,
5173                 NULL,
5174         },
5175 };
5176
5177 static cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5178         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5179                                 mode, "show");
5180
5181
5182 static cmdline_parse_inst_t cmd_tunnel_tso_show = {
5183         .f = cmd_tunnel_tso_set_parsed,
5184         .data = NULL,
5185         .help_str = "tunnel_tso show <port_id> "
5186                 "Show TSO segment size of tunneled packets for csum engine",
5187         .tokens = {
5188                 (void *)&cmd_tunnel_tso_set_tso,
5189                 (void *)&cmd_tunnel_tso_show_mode,
5190                 (void *)&cmd_tunnel_tso_set_portid,
5191                 NULL,
5192         },
5193 };
5194
5195 #ifdef RTE_LIB_GRO
5196 /* *** SET GRO FOR A PORT *** */
5197 struct cmd_gro_enable_result {
5198         cmdline_fixed_string_t cmd_set;
5199         cmdline_fixed_string_t cmd_port;
5200         cmdline_fixed_string_t cmd_keyword;
5201         cmdline_fixed_string_t cmd_onoff;
5202         portid_t cmd_pid;
5203 };
5204
5205 static void
5206 cmd_gro_enable_parsed(void *parsed_result,
5207                 __rte_unused struct cmdline *cl,
5208                 __rte_unused void *data)
5209 {
5210         struct cmd_gro_enable_result *res;
5211
5212         res = parsed_result;
5213         if (!strcmp(res->cmd_keyword, "gro"))
5214                 setup_gro(res->cmd_onoff, res->cmd_pid);
5215 }
5216
5217 static cmdline_parse_token_string_t cmd_gro_enable_set =
5218         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5219                         cmd_set, "set");
5220 static cmdline_parse_token_string_t cmd_gro_enable_port =
5221         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5222                         cmd_keyword, "port");
5223 static cmdline_parse_token_num_t cmd_gro_enable_pid =
5224         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5225                         cmd_pid, RTE_UINT16);
5226 static cmdline_parse_token_string_t cmd_gro_enable_keyword =
5227         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5228                         cmd_keyword, "gro");
5229 static cmdline_parse_token_string_t cmd_gro_enable_onoff =
5230         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5231                         cmd_onoff, "on#off");
5232
5233 static cmdline_parse_inst_t cmd_gro_enable = {
5234         .f = cmd_gro_enable_parsed,
5235         .data = NULL,
5236         .help_str = "set port <port_id> gro on|off",
5237         .tokens = {
5238                 (void *)&cmd_gro_enable_set,
5239                 (void *)&cmd_gro_enable_port,
5240                 (void *)&cmd_gro_enable_pid,
5241                 (void *)&cmd_gro_enable_keyword,
5242                 (void *)&cmd_gro_enable_onoff,
5243                 NULL,
5244         },
5245 };
5246
5247 /* *** DISPLAY GRO CONFIGURATION *** */
5248 struct cmd_gro_show_result {
5249         cmdline_fixed_string_t cmd_show;
5250         cmdline_fixed_string_t cmd_port;
5251         cmdline_fixed_string_t cmd_keyword;
5252         portid_t cmd_pid;
5253 };
5254
5255 static void
5256 cmd_gro_show_parsed(void *parsed_result,
5257                 __rte_unused struct cmdline *cl,
5258                 __rte_unused void *data)
5259 {
5260         struct cmd_gro_show_result *res;
5261
5262         res = parsed_result;
5263         if (!strcmp(res->cmd_keyword, "gro"))
5264                 show_gro(res->cmd_pid);
5265 }
5266
5267 static cmdline_parse_token_string_t cmd_gro_show_show =
5268         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5269                         cmd_show, "show");
5270 static cmdline_parse_token_string_t cmd_gro_show_port =
5271         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5272                         cmd_port, "port");
5273 static cmdline_parse_token_num_t cmd_gro_show_pid =
5274         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5275                         cmd_pid, RTE_UINT16);
5276 static cmdline_parse_token_string_t cmd_gro_show_keyword =
5277         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5278                         cmd_keyword, "gro");
5279
5280 static cmdline_parse_inst_t cmd_gro_show = {
5281         .f = cmd_gro_show_parsed,
5282         .data = NULL,
5283         .help_str = "show port <port_id> gro",
5284         .tokens = {
5285                 (void *)&cmd_gro_show_show,
5286                 (void *)&cmd_gro_show_port,
5287                 (void *)&cmd_gro_show_pid,
5288                 (void *)&cmd_gro_show_keyword,
5289                 NULL,
5290         },
5291 };
5292
5293 /* *** SET FLUSH CYCLES FOR GRO *** */
5294 struct cmd_gro_flush_result {
5295         cmdline_fixed_string_t cmd_set;
5296         cmdline_fixed_string_t cmd_keyword;
5297         cmdline_fixed_string_t cmd_flush;
5298         uint8_t cmd_cycles;
5299 };
5300
5301 static void
5302 cmd_gro_flush_parsed(void *parsed_result,
5303                 __rte_unused struct cmdline *cl,
5304                 __rte_unused void *data)
5305 {
5306         struct cmd_gro_flush_result *res;
5307
5308         res = parsed_result;
5309         if ((!strcmp(res->cmd_keyword, "gro")) &&
5310                         (!strcmp(res->cmd_flush, "flush")))
5311                 setup_gro_flush_cycles(res->cmd_cycles);
5312 }
5313
5314 static cmdline_parse_token_string_t cmd_gro_flush_set =
5315         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5316                         cmd_set, "set");
5317 static cmdline_parse_token_string_t cmd_gro_flush_keyword =
5318         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5319                         cmd_keyword, "gro");
5320 static cmdline_parse_token_string_t cmd_gro_flush_flush =
5321         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5322                         cmd_flush, "flush");
5323 static cmdline_parse_token_num_t cmd_gro_flush_cycles =
5324         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5325                         cmd_cycles, RTE_UINT8);
5326
5327 static cmdline_parse_inst_t cmd_gro_flush = {
5328         .f = cmd_gro_flush_parsed,
5329         .data = NULL,
5330         .help_str = "set gro flush <cycles>",
5331         .tokens = {
5332                 (void *)&cmd_gro_flush_set,
5333                 (void *)&cmd_gro_flush_keyword,
5334                 (void *)&cmd_gro_flush_flush,
5335                 (void *)&cmd_gro_flush_cycles,
5336                 NULL,
5337         },
5338 };
5339 #endif /* RTE_LIB_GRO */
5340
5341 #ifdef RTE_LIB_GSO
5342 /* *** ENABLE/DISABLE GSO *** */
5343 struct cmd_gso_enable_result {
5344         cmdline_fixed_string_t cmd_set;
5345         cmdline_fixed_string_t cmd_port;
5346         cmdline_fixed_string_t cmd_keyword;
5347         cmdline_fixed_string_t cmd_mode;
5348         portid_t cmd_pid;
5349 };
5350
5351 static void
5352 cmd_gso_enable_parsed(void *parsed_result,
5353                 __rte_unused struct cmdline *cl,
5354                 __rte_unused void *data)
5355 {
5356         struct cmd_gso_enable_result *res;
5357
5358         res = parsed_result;
5359         if (!strcmp(res->cmd_keyword, "gso"))
5360                 setup_gso(res->cmd_mode, res->cmd_pid);
5361 }
5362
5363 static cmdline_parse_token_string_t cmd_gso_enable_set =
5364         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5365                         cmd_set, "set");
5366 static cmdline_parse_token_string_t cmd_gso_enable_port =
5367         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5368                         cmd_port, "port");
5369 static cmdline_parse_token_string_t cmd_gso_enable_keyword =
5370         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5371                         cmd_keyword, "gso");
5372 static cmdline_parse_token_string_t cmd_gso_enable_mode =
5373         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5374                         cmd_mode, "on#off");
5375 static cmdline_parse_token_num_t cmd_gso_enable_pid =
5376         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5377                         cmd_pid, RTE_UINT16);
5378
5379 static cmdline_parse_inst_t cmd_gso_enable = {
5380         .f = cmd_gso_enable_parsed,
5381         .data = NULL,
5382         .help_str = "set port <port_id> gso on|off",
5383         .tokens = {
5384                 (void *)&cmd_gso_enable_set,
5385                 (void *)&cmd_gso_enable_port,
5386                 (void *)&cmd_gso_enable_pid,
5387                 (void *)&cmd_gso_enable_keyword,
5388                 (void *)&cmd_gso_enable_mode,
5389                 NULL,
5390         },
5391 };
5392
5393 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5394 struct cmd_gso_size_result {
5395         cmdline_fixed_string_t cmd_set;
5396         cmdline_fixed_string_t cmd_keyword;
5397         cmdline_fixed_string_t cmd_segsz;
5398         uint16_t cmd_size;
5399 };
5400
5401 static void
5402 cmd_gso_size_parsed(void *parsed_result,
5403                        __rte_unused struct cmdline *cl,
5404                        __rte_unused void *data)
5405 {
5406         struct cmd_gso_size_result *res = parsed_result;
5407
5408         if (test_done == 0) {
5409                 fprintf(stderr,
5410                         "Before setting GSO segsz, please first stop forwarding\n");
5411                 return;
5412         }
5413
5414         if (!strcmp(res->cmd_keyword, "gso") &&
5415                         !strcmp(res->cmd_segsz, "segsz")) {
5416                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5417                         fprintf(stderr,
5418                                 "gso_size should be larger than %zu. Please input a legal value\n",
5419                                 RTE_GSO_SEG_SIZE_MIN);
5420                 else
5421                         gso_max_segment_size = res->cmd_size;
5422         }
5423 }
5424
5425 static cmdline_parse_token_string_t cmd_gso_size_set =
5426         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5427                                 cmd_set, "set");
5428 static cmdline_parse_token_string_t cmd_gso_size_keyword =
5429         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5430                                 cmd_keyword, "gso");
5431 static cmdline_parse_token_string_t cmd_gso_size_segsz =
5432         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5433                                 cmd_segsz, "segsz");
5434 static cmdline_parse_token_num_t cmd_gso_size_size =
5435         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5436                                 cmd_size, RTE_UINT16);
5437
5438 static cmdline_parse_inst_t cmd_gso_size = {
5439         .f = cmd_gso_size_parsed,
5440         .data = NULL,
5441         .help_str = "set gso segsz <length>",
5442         .tokens = {
5443                 (void *)&cmd_gso_size_set,
5444                 (void *)&cmd_gso_size_keyword,
5445                 (void *)&cmd_gso_size_segsz,
5446                 (void *)&cmd_gso_size_size,
5447                 NULL,
5448         },
5449 };
5450
5451 /* *** SHOW GSO CONFIGURATION *** */
5452 struct cmd_gso_show_result {
5453         cmdline_fixed_string_t cmd_show;
5454         cmdline_fixed_string_t cmd_port;
5455         cmdline_fixed_string_t cmd_keyword;
5456         portid_t cmd_pid;
5457 };
5458
5459 static void
5460 cmd_gso_show_parsed(void *parsed_result,
5461                        __rte_unused struct cmdline *cl,
5462                        __rte_unused void *data)
5463 {
5464         struct cmd_gso_show_result *res = parsed_result;
5465
5466         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5467                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5468                 return;
5469         }
5470         if (!strcmp(res->cmd_keyword, "gso")) {
5471                 if (gso_ports[res->cmd_pid].enable) {
5472                         printf("Max GSO'd packet size: %uB\n"
5473                                         "Supported GSO types: TCP/IPv4, "
5474                                         "UDP/IPv4, VxLAN with inner "
5475                                         "TCP/IPv4 packet, GRE with inner "
5476                                         "TCP/IPv4 packet\n",
5477                                         gso_max_segment_size);
5478                 } else
5479                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5480         }
5481 }
5482
5483 static cmdline_parse_token_string_t cmd_gso_show_show =
5484 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5485                 cmd_show, "show");
5486 static cmdline_parse_token_string_t cmd_gso_show_port =
5487 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5488                 cmd_port, "port");
5489 static cmdline_parse_token_string_t cmd_gso_show_keyword =
5490         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5491                                 cmd_keyword, "gso");
5492 static cmdline_parse_token_num_t cmd_gso_show_pid =
5493         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5494                                 cmd_pid, RTE_UINT16);
5495
5496 static cmdline_parse_inst_t cmd_gso_show = {
5497         .f = cmd_gso_show_parsed,
5498         .data = NULL,
5499         .help_str = "show port <port_id> gso",
5500         .tokens = {
5501                 (void *)&cmd_gso_show_show,
5502                 (void *)&cmd_gso_show_port,
5503                 (void *)&cmd_gso_show_pid,
5504                 (void *)&cmd_gso_show_keyword,
5505                 NULL,
5506         },
5507 };
5508 #endif /* RTE_LIB_GSO */
5509
5510 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5511 struct cmd_set_flush_rx {
5512         cmdline_fixed_string_t set;
5513         cmdline_fixed_string_t flush_rx;
5514         cmdline_fixed_string_t mode;
5515 };
5516
5517 static void
5518 cmd_set_flush_rx_parsed(void *parsed_result,
5519                 __rte_unused struct cmdline *cl,
5520                 __rte_unused void *data)
5521 {
5522         struct cmd_set_flush_rx *res = parsed_result;
5523
5524         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5525                 printf("multi-process doesn't support to flush Rx queues.\n");
5526                 return;
5527         }
5528
5529         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5530 }
5531
5532 static cmdline_parse_token_string_t cmd_setflushrx_set =
5533         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5534                         set, "set");
5535 static cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5537                         flush_rx, "flush_rx");
5538 static cmdline_parse_token_string_t cmd_setflushrx_mode =
5539         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5540                         mode, "on#off");
5541
5542
5543 static cmdline_parse_inst_t cmd_set_flush_rx = {
5544         .f = cmd_set_flush_rx_parsed,
5545         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5546         .data = NULL,
5547         .tokens = {
5548                 (void *)&cmd_setflushrx_set,
5549                 (void *)&cmd_setflushrx_flush_rx,
5550                 (void *)&cmd_setflushrx_mode,
5551                 NULL,
5552         },
5553 };
5554
5555 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5556 struct cmd_set_link_check {
5557         cmdline_fixed_string_t set;
5558         cmdline_fixed_string_t link_check;
5559         cmdline_fixed_string_t mode;
5560 };
5561
5562 static void
5563 cmd_set_link_check_parsed(void *parsed_result,
5564                 __rte_unused struct cmdline *cl,
5565                 __rte_unused void *data)
5566 {
5567         struct cmd_set_link_check *res = parsed_result;
5568         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5569 }
5570
5571 static cmdline_parse_token_string_t cmd_setlinkcheck_set =
5572         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5573                         set, "set");
5574 static cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5575         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5576                         link_check, "link_check");
5577 static cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5578         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5579                         mode, "on#off");
5580
5581
5582 static cmdline_parse_inst_t cmd_set_link_check = {
5583         .f = cmd_set_link_check_parsed,
5584         .help_str = "set link_check on|off: Enable/Disable link status check "
5585                     "when starting/stopping a port",
5586         .data = NULL,
5587         .tokens = {
5588                 (void *)&cmd_setlinkcheck_set,
5589                 (void *)&cmd_setlinkcheck_link_check,
5590                 (void *)&cmd_setlinkcheck_mode,
5591                 NULL,
5592         },
5593 };
5594
5595 /* *** SET NIC BYPASS MODE *** */
5596 struct cmd_set_bypass_mode_result {
5597         cmdline_fixed_string_t set;
5598         cmdline_fixed_string_t bypass;
5599         cmdline_fixed_string_t mode;
5600         cmdline_fixed_string_t value;
5601         portid_t port_id;
5602 };
5603
5604 static void
5605 cmd_set_bypass_mode_parsed(void *parsed_result,
5606                 __rte_unused struct cmdline *cl,
5607                 __rte_unused void *data)
5608 {
5609         struct cmd_set_bypass_mode_result *res = parsed_result;
5610         portid_t port_id = res->port_id;
5611         int32_t rc = -EINVAL;
5612
5613 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5614         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5615
5616         if (!strcmp(res->value, "bypass"))
5617                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5618         else if (!strcmp(res->value, "isolate"))
5619                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5620         else
5621                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5622
5623         /* Set the bypass mode for the relevant port. */
5624         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5625 #endif
5626         if (rc != 0)
5627                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5628                         port_id);
5629 }
5630
5631 static cmdline_parse_token_string_t cmd_setbypass_mode_set =
5632         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5633                         set, "set");
5634 static cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5636                         bypass, "bypass");
5637 static cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5639                         mode, "mode");
5640 static cmdline_parse_token_string_t cmd_setbypass_mode_value =
5641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5642                         value, "normal#bypass#isolate");
5643 static cmdline_parse_token_num_t cmd_setbypass_mode_port =
5644         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5645                                 port_id, RTE_UINT16);
5646
5647 static cmdline_parse_inst_t cmd_set_bypass_mode = {
5648         .f = cmd_set_bypass_mode_parsed,
5649         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5650                     "Set the NIC bypass mode for port_id",
5651         .data = NULL,
5652         .tokens = {
5653                 (void *)&cmd_setbypass_mode_set,
5654                 (void *)&cmd_setbypass_mode_bypass,
5655                 (void *)&cmd_setbypass_mode_mode,
5656                 (void *)&cmd_setbypass_mode_value,
5657                 (void *)&cmd_setbypass_mode_port,
5658                 NULL,
5659         },
5660 };
5661
5662 /* *** SET NIC BYPASS EVENT *** */
5663 struct cmd_set_bypass_event_result {
5664         cmdline_fixed_string_t set;
5665         cmdline_fixed_string_t bypass;
5666         cmdline_fixed_string_t event;
5667         cmdline_fixed_string_t event_value;
5668         cmdline_fixed_string_t mode;
5669         cmdline_fixed_string_t mode_value;
5670         portid_t port_id;
5671 };
5672
5673 static void
5674 cmd_set_bypass_event_parsed(void *parsed_result,
5675                 __rte_unused struct cmdline *cl,
5676                 __rte_unused void *data)
5677 {
5678         int32_t rc = -EINVAL;
5679         struct cmd_set_bypass_event_result *res = parsed_result;
5680         portid_t port_id = res->port_id;
5681
5682 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5683         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5684         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5685
5686         if (!strcmp(res->event_value, "timeout"))
5687                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5688         else if (!strcmp(res->event_value, "os_on"))
5689                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5690         else if (!strcmp(res->event_value, "os_off"))
5691                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5692         else if (!strcmp(res->event_value, "power_on"))
5693                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5694         else if (!strcmp(res->event_value, "power_off"))
5695                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5696         else
5697                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5698
5699         if (!strcmp(res->mode_value, "bypass"))
5700                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5701         else if (!strcmp(res->mode_value, "isolate"))
5702                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5703         else
5704                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5705
5706         /* Set the watchdog timeout. */
5707         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5708
5709                 rc = -EINVAL;
5710                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5711                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5712                                                            bypass_timeout);
5713                 }
5714                 if (rc != 0) {
5715                         fprintf(stderr,
5716                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5717                                 bypass_timeout, port_id, rc);
5718                 }
5719         }
5720
5721         /* Set the bypass event to transition to bypass mode. */
5722         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5723                                               bypass_mode);
5724 #endif
5725
5726         if (rc != 0)
5727                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5728                         port_id);
5729 }
5730
5731 static cmdline_parse_token_string_t cmd_setbypass_event_set =
5732         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5733                         set, "set");
5734 static cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5735         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5736                         bypass, "bypass");
5737 static cmdline_parse_token_string_t cmd_setbypass_event_event =
5738         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5739                         event, "event");
5740 static cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5741         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5742                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5743 static cmdline_parse_token_string_t cmd_setbypass_event_mode =
5744         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5745                         mode, "mode");
5746 static cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5747         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5748                         mode_value, "normal#bypass#isolate");
5749 static cmdline_parse_token_num_t cmd_setbypass_event_port =
5750         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5751                                 port_id, RTE_UINT16);
5752
5753 static cmdline_parse_inst_t cmd_set_bypass_event = {
5754         .f = cmd_set_bypass_event_parsed,
5755         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5756                 "power_off mode normal|bypass|isolate <port_id>: "
5757                 "Set the NIC bypass event mode for port_id",
5758         .data = NULL,
5759         .tokens = {
5760                 (void *)&cmd_setbypass_event_set,
5761                 (void *)&cmd_setbypass_event_bypass,
5762                 (void *)&cmd_setbypass_event_event,
5763                 (void *)&cmd_setbypass_event_event_value,
5764                 (void *)&cmd_setbypass_event_mode,
5765                 (void *)&cmd_setbypass_event_mode_value,
5766                 (void *)&cmd_setbypass_event_port,
5767                 NULL,
5768         },
5769 };
5770
5771
5772 /* *** SET NIC BYPASS TIMEOUT *** */
5773 struct cmd_set_bypass_timeout_result {
5774         cmdline_fixed_string_t set;
5775         cmdline_fixed_string_t bypass;
5776         cmdline_fixed_string_t timeout;
5777         cmdline_fixed_string_t value;
5778 };
5779
5780 static void
5781 cmd_set_bypass_timeout_parsed(void *parsed_result,
5782                 __rte_unused struct cmdline *cl,
5783                 __rte_unused void *data)
5784 {
5785         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5786
5787 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5788         if (!strcmp(res->value, "1.5"))
5789                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5790         else if (!strcmp(res->value, "2"))
5791                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5792         else if (!strcmp(res->value, "3"))
5793                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5794         else if (!strcmp(res->value, "4"))
5795                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5796         else if (!strcmp(res->value, "8"))
5797                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5798         else if (!strcmp(res->value, "16"))
5799                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5800         else if (!strcmp(res->value, "32"))
5801                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5802         else
5803                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5804 #endif
5805 }
5806
5807 static cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5808         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5809                         set, "set");
5810 static cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5811         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5812                         bypass, "bypass");
5813 static cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5814         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5815                         timeout, "timeout");
5816 static cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5817         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5818                         value, "0#1.5#2#3#4#8#16#32");
5819
5820 static cmdline_parse_inst_t cmd_set_bypass_timeout = {
5821         .f = cmd_set_bypass_timeout_parsed,
5822         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5823                 "Set the NIC bypass watchdog timeout in seconds",
5824         .data = NULL,
5825         .tokens = {
5826                 (void *)&cmd_setbypass_timeout_set,
5827                 (void *)&cmd_setbypass_timeout_bypass,
5828                 (void *)&cmd_setbypass_timeout_timeout,
5829                 (void *)&cmd_setbypass_timeout_value,
5830                 NULL,
5831         },
5832 };
5833
5834 /* *** SHOW NIC BYPASS MODE *** */
5835 struct cmd_show_bypass_config_result {
5836         cmdline_fixed_string_t show;
5837         cmdline_fixed_string_t bypass;
5838         cmdline_fixed_string_t config;
5839         portid_t port_id;
5840 };
5841
5842 static void
5843 cmd_show_bypass_config_parsed(void *parsed_result,
5844                 __rte_unused struct cmdline *cl,
5845                 __rte_unused void *data)
5846 {
5847         struct cmd_show_bypass_config_result *res = parsed_result;
5848         portid_t port_id = res->port_id;
5849         int rc = -EINVAL;
5850 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5851         uint32_t event_mode;
5852         uint32_t bypass_mode;
5853         uint32_t timeout = bypass_timeout;
5854         unsigned int i;
5855
5856         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5857                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5858         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5859                 {"UNKNOWN", "normal", "bypass", "isolate"};
5860         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5861                 "NONE",
5862                 "OS/board on",
5863                 "power supply on",
5864                 "OS/board off",
5865                 "power supply off",
5866                 "timeout"};
5867
5868         /* Display the bypass mode.*/
5869         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5870                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5871                         port_id);
5872                 return;
5873         }
5874         else {
5875                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5876                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5877
5878                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5879         }
5880
5881         /* Display the bypass timeout.*/
5882         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5883                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5884
5885         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5886
5887         /* Display the bypass events and associated modes. */
5888         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5889
5890                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5891                         fprintf(stderr,
5892                                 "\tFailed to get bypass mode for event = %s\n",
5893                                 events[i]);
5894                 } else {
5895                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5896                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5897
5898                         printf("\tbypass event: %-16s = %s\n", events[i],
5899                                 modes[event_mode]);
5900                 }
5901         }
5902 #endif
5903         if (rc != 0)
5904                 fprintf(stderr,
5905                         "\tFailed to get bypass configuration for port = %d\n",
5906                        port_id);
5907 }
5908
5909 static cmdline_parse_token_string_t cmd_showbypass_config_show =
5910         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5911                         show, "show");
5912 static cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5913         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5914                         bypass, "bypass");
5915 static cmdline_parse_token_string_t cmd_showbypass_config_config =
5916         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5917                         config, "config");
5918 static cmdline_parse_token_num_t cmd_showbypass_config_port =
5919         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5920                                 port_id, RTE_UINT16);
5921
5922 static cmdline_parse_inst_t cmd_show_bypass_config = {
5923         .f = cmd_show_bypass_config_parsed,
5924         .help_str = "show bypass config <port_id>: "
5925                     "Show the NIC bypass config for port_id",
5926         .data = NULL,
5927         .tokens = {
5928                 (void *)&cmd_showbypass_config_show,
5929                 (void *)&cmd_showbypass_config_bypass,
5930                 (void *)&cmd_showbypass_config_config,
5931                 (void *)&cmd_showbypass_config_port,
5932                 NULL,
5933         },
5934 };
5935
5936 #ifdef RTE_NET_BOND
5937 /* *** SET BONDING MODE *** */
5938 struct cmd_set_bonding_mode_result {
5939         cmdline_fixed_string_t set;
5940         cmdline_fixed_string_t bonding;
5941         cmdline_fixed_string_t mode;
5942         uint8_t value;
5943         portid_t port_id;
5944 };
5945
5946 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5947                 __rte_unused  struct cmdline *cl,
5948                 __rte_unused void *data)
5949 {
5950         struct cmd_set_bonding_mode_result *res = parsed_result;
5951         portid_t port_id = res->port_id;
5952         struct rte_port *port = &ports[port_id];
5953
5954         /*
5955          * Bonding mode changed means resources of device changed, like whether
5956          * started rte timer or not. Device should be restarted when resources
5957          * of device changed.
5958          */
5959         if (port->port_status != RTE_PORT_STOPPED) {
5960                 fprintf(stderr,
5961                         "\t Error: Can't set bonding mode when port %d is not stopped\n",
5962                         port_id);
5963                 return;
5964         }
5965
5966         /* Set the bonding mode for the relevant port. */
5967         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5968                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5969                         port_id);
5970 }
5971
5972 static cmdline_parse_token_string_t cmd_setbonding_mode_set =
5973 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5974                 set, "set");
5975 static cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5976 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5977                 bonding, "bonding");
5978 static cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5979 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5980                 mode, "mode");
5981 static cmdline_parse_token_num_t cmd_setbonding_mode_value =
5982 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5983                 value, RTE_UINT8);
5984 static cmdline_parse_token_num_t cmd_setbonding_mode_port =
5985 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5986                 port_id, RTE_UINT16);
5987
5988 static cmdline_parse_inst_t cmd_set_bonding_mode = {
5989                 .f = cmd_set_bonding_mode_parsed,
5990                 .help_str = "set bonding mode <mode_value> <port_id>: "
5991                         "Set the bonding mode for port_id",
5992                 .data = NULL,
5993                 .tokens = {
5994                                 (void *) &cmd_setbonding_mode_set,
5995                                 (void *) &cmd_setbonding_mode_bonding,
5996                                 (void *) &cmd_setbonding_mode_mode,
5997                                 (void *) &cmd_setbonding_mode_value,
5998                                 (void *) &cmd_setbonding_mode_port,
5999                                 NULL
6000                 }
6001 };
6002
6003 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
6004 struct cmd_set_bonding_lacp_dedicated_queues_result {
6005         cmdline_fixed_string_t set;
6006         cmdline_fixed_string_t bonding;
6007         cmdline_fixed_string_t lacp;
6008         cmdline_fixed_string_t dedicated_queues;
6009         portid_t port_id;
6010         cmdline_fixed_string_t mode;
6011 };
6012
6013 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
6014                 __rte_unused  struct cmdline *cl,
6015                 __rte_unused void *data)
6016 {
6017         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
6018         portid_t port_id = res->port_id;
6019         struct rte_port *port;
6020
6021         port = &ports[port_id];
6022
6023         /** Check if the port is not started **/
6024         if (port->port_status != RTE_PORT_STOPPED) {
6025                 fprintf(stderr, "Please stop port %d first\n", port_id);
6026                 return;
6027         }
6028
6029         if (!strcmp(res->mode, "enable")) {
6030                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6031                         printf("Dedicate queues for LACP control packets"
6032                                         " enabled\n");
6033                 else
6034                         printf("Enabling dedicate queues for LACP control "
6035                                         "packets on port %d failed\n", port_id);
6036         } else if (!strcmp(res->mode, "disable")) {
6037                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6038                         printf("Dedicated queues for LACP control packets "
6039                                         "disabled\n");
6040                 else
6041                         printf("Disabling dedicated queues for LACP control "
6042                                         "traffic on port %d failed\n", port_id);
6043         }
6044 }
6045
6046 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6047 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6048                 set, "set");
6049 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6050 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6051                 bonding, "bonding");
6052 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6053 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6054                 lacp, "lacp");
6055 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6056 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6057                 dedicated_queues, "dedicated_queues");
6058 static cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6059 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6060                 port_id, RTE_UINT16);
6061 static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6062 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6063                 mode, "enable#disable");
6064
6065 static cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6066                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6067                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6068                         "enable|disable: "
6069                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6070                 .data = NULL,
6071                 .tokens = {
6072                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6073                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6074                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6075                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6076                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6077                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6078                         NULL
6079                 }
6080 };
6081
6082 /* *** SET BALANCE XMIT POLICY *** */
6083 struct cmd_set_bonding_balance_xmit_policy_result {
6084         cmdline_fixed_string_t set;
6085         cmdline_fixed_string_t bonding;
6086         cmdline_fixed_string_t balance_xmit_policy;
6087         portid_t port_id;
6088         cmdline_fixed_string_t policy;
6089 };
6090
6091 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6092                 __rte_unused  struct cmdline *cl,
6093                 __rte_unused void *data)
6094 {
6095         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6096         portid_t port_id = res->port_id;
6097         uint8_t policy;
6098
6099         if (!strcmp(res->policy, "l2")) {
6100                 policy = BALANCE_XMIT_POLICY_LAYER2;
6101         } else if (!strcmp(res->policy, "l23")) {
6102                 policy = BALANCE_XMIT_POLICY_LAYER23;
6103         } else if (!strcmp(res->policy, "l34")) {
6104                 policy = BALANCE_XMIT_POLICY_LAYER34;
6105         } else {
6106                 fprintf(stderr, "\t Invalid xmit policy selection");
6107                 return;
6108         }
6109
6110         /* Set the bonding mode for the relevant port. */
6111         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6112                 fprintf(stderr,
6113                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6114                         port_id);
6115         }
6116 }
6117
6118 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6119 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6120                 set, "set");
6121 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6123                 bonding, "bonding");
6124 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6125 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6126                 balance_xmit_policy, "balance_xmit_policy");
6127 static cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6128 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6129                 port_id, RTE_UINT16);
6130 static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6131 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6132                 policy, "l2#l23#l34");
6133
6134 static cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6135                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6136                 .help_str = "set bonding balance_xmit_policy <port_id> "
6137                         "l2|l23|l34: "
6138                         "Set the bonding balance_xmit_policy for port_id",
6139                 .data = NULL,
6140                 .tokens = {
6141                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6142                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6143                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6144                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6145                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6146                                 NULL
6147                 }
6148 };
6149
6150 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6151 struct cmd_show_bonding_lacp_info_result {
6152         cmdline_fixed_string_t show;
6153         cmdline_fixed_string_t bonding;
6154         cmdline_fixed_string_t lacp;
6155         cmdline_fixed_string_t info;
6156         portid_t port_id;
6157 };
6158
6159 static void port_param_show(struct port_params *params)
6160 {
6161         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6162
6163         printf("\t\tsystem priority: %u\n", params->system_priority);
6164         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6165         printf("\t\tsystem mac address: %s\n", buf);
6166         printf("\t\tport key: %u\n", params->key);
6167         printf("\t\tport priority: %u\n", params->port_priority);
6168         printf("\t\tport number: %u\n", params->port_number);
6169 }
6170
6171 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6172 {
6173         char a_state[256] = { 0 };
6174         char p_state[256] = { 0 };
6175         int a_len = 0;
6176         int p_len = 0;
6177         uint32_t i;
6178
6179         static const char * const state[] = {
6180                 "ACTIVE",
6181                 "TIMEOUT",
6182                 "AGGREGATION",
6183                 "SYNCHRONIZATION",
6184                 "COLLECTING",
6185                 "DISTRIBUTING",
6186                 "DEFAULTED",
6187                 "EXPIRED"
6188         };
6189         static const char * const selection[] = {
6190                 "UNSELECTED",
6191                 "STANDBY",
6192                 "SELECTED"
6193         };
6194
6195         for (i = 0; i < RTE_DIM(state); i++) {
6196                 if ((info->actor_state >> i) & 1)
6197                         a_len += snprintf(&a_state[a_len],
6198                                                 RTE_DIM(a_state) - a_len, "%s ",
6199                                                 state[i]);
6200
6201                 if ((info->partner_state >> i) & 1)
6202                         p_len += snprintf(&p_state[p_len],
6203                                                 RTE_DIM(p_state) - p_len, "%s ",
6204                                                 state[i]);
6205         }
6206         printf("\tAggregator port id: %u\n", info->agg_port_id);
6207         printf("\tselection: %s\n", selection[info->selected]);
6208         printf("\tActor detail info:\n");
6209         port_param_show(&info->actor);
6210         printf("\t\tport state: %s\n", a_state);
6211         printf("\tPartner detail info:\n");
6212         port_param_show(&info->partner);
6213         printf("\t\tport state: %s\n", p_state);
6214         printf("\n");
6215 }
6216
6217 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6218 {
6219         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6220         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6221         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6222         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6223         printf("\taggregate wait timeout: %u ms\n",
6224                         conf->aggregate_wait_timeout_ms);
6225         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6226         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6227         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6228         switch (conf->agg_selection) {
6229         case AGG_BANDWIDTH:
6230                 printf("\taggregation mode: bandwidth\n");
6231                 break;
6232         case AGG_STABLE:
6233                 printf("\taggregation mode: stable\n");
6234                 break;
6235         case AGG_COUNT:
6236                 printf("\taggregation mode: count\n");
6237                 break;
6238         default:
6239                 printf("\taggregation mode: invalid\n");
6240                 break;
6241         }
6242
6243         printf("\n");
6244 }
6245
6246 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6247                 __rte_unused  struct cmdline *cl,
6248                 __rte_unused void *data)
6249 {
6250         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6251         struct rte_eth_bond_8023ad_slave_info slave_info;
6252         struct rte_eth_bond_8023ad_conf port_conf;
6253         portid_t slaves[RTE_MAX_ETHPORTS];
6254         portid_t port_id = res->port_id;
6255         int num_active_slaves;
6256         int bonding_mode;
6257         int i;
6258         int ret;
6259
6260         bonding_mode = rte_eth_bond_mode_get(port_id);
6261         if (bonding_mode != BONDING_MODE_8023AD) {
6262                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6263                 return;
6264         }
6265
6266         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6267                         RTE_MAX_ETHPORTS);
6268         if (num_active_slaves < 0) {
6269                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6270                                 port_id);
6271                 return;
6272         }
6273         if (num_active_slaves == 0)
6274                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6275                         port_id);
6276
6277         printf("\tIEEE802.3 port: %u\n", port_id);
6278         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6279         if (ret) {
6280                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6281                         port_id);
6282                 return;
6283         }
6284         lacp_conf_show(&port_conf);
6285
6286         for (i = 0; i < num_active_slaves; i++) {
6287                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6288                                 &slave_info);
6289                 if (ret) {
6290                         fprintf(stderr, "\tGet slave device %u info failed\n",
6291                                 slaves[i]);
6292                         return;
6293                 }
6294                 printf("\tSlave Port: %u\n", slaves[i]);
6295                 lacp_slave_info_show(&slave_info);
6296         }
6297 }
6298
6299 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6300 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6301                 show, "show");
6302 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6303 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6304                 bonding, "bonding");
6305 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6306 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6307                 bonding, "lacp");
6308 static cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6309 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6310                 info, "info");
6311 static cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6312 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6313                 port_id, RTE_UINT16);
6314
6315 static cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6316                 .f = cmd_show_bonding_lacp_info_parsed,
6317                 .help_str = "show bonding lacp info <port_id> : "
6318                         "Show bonding IEEE802.3 information for port_id",
6319                 .data = NULL,
6320                 .tokens = {
6321                         (void *)&cmd_show_bonding_lacp_info_show,
6322                         (void *)&cmd_show_bonding_lacp_info_bonding,
6323                         (void *)&cmd_show_bonding_lacp_info_lacp,
6324                         (void *)&cmd_show_bonding_lacp_info_info,
6325                         (void *)&cmd_show_bonding_lacp_info_port_id,
6326                         NULL
6327                 }
6328 };
6329
6330 /* *** SHOW NIC BONDING CONFIGURATION *** */
6331 struct cmd_show_bonding_config_result {
6332         cmdline_fixed_string_t show;
6333         cmdline_fixed_string_t bonding;
6334         cmdline_fixed_string_t config;
6335         portid_t port_id;
6336 };
6337
6338 static void cmd_show_bonding_config_parsed(void *parsed_result,
6339                 __rte_unused  struct cmdline *cl,
6340                 __rte_unused void *data)
6341 {
6342         struct cmd_show_bonding_config_result *res = parsed_result;
6343         int bonding_mode, agg_mode;
6344         portid_t slaves[RTE_MAX_ETHPORTS];
6345         int num_slaves, num_active_slaves;
6346         int primary_id;
6347         int i;
6348         portid_t port_id = res->port_id;
6349
6350         /* Display the bonding mode.*/
6351         bonding_mode = rte_eth_bond_mode_get(port_id);
6352         if (bonding_mode < 0) {
6353                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6354                         port_id);
6355                 return;
6356         } else
6357                 printf("\tBonding mode: %d\n", bonding_mode);
6358
6359         if (bonding_mode == BONDING_MODE_BALANCE ||
6360                 bonding_mode == BONDING_MODE_8023AD) {
6361                 int balance_xmit_policy;
6362
6363                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6364                 if (balance_xmit_policy < 0) {
6365                         fprintf(stderr,
6366                                 "\tFailed to get balance xmit policy for port = %d\n",
6367                                 port_id);
6368                         return;
6369                 } else {
6370                         printf("\tBalance Xmit Policy: ");
6371
6372                         switch (balance_xmit_policy) {
6373                         case BALANCE_XMIT_POLICY_LAYER2:
6374                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6375                                 break;
6376                         case BALANCE_XMIT_POLICY_LAYER23:
6377                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6378                                 break;
6379                         case BALANCE_XMIT_POLICY_LAYER34:
6380                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6381                                 break;
6382                         }
6383                         printf("\n");
6384                 }
6385         }
6386
6387         if (bonding_mode == BONDING_MODE_8023AD) {
6388                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6389                 printf("\tIEEE802.3AD Aggregator Mode: ");
6390                 switch (agg_mode) {
6391                 case AGG_BANDWIDTH:
6392                         printf("bandwidth");
6393                         break;
6394                 case AGG_STABLE:
6395                         printf("stable");
6396                         break;
6397                 case AGG_COUNT:
6398                         printf("count");
6399                         break;
6400                 }
6401                 printf("\n");
6402         }
6403
6404         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6405
6406         if (num_slaves < 0) {
6407                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6408                         port_id);
6409                 return;
6410         }
6411         if (num_slaves > 0) {
6412                 printf("\tSlaves (%d): [", num_slaves);
6413                 for (i = 0; i < num_slaves - 1; i++)
6414                         printf("%d ", slaves[i]);
6415
6416                 printf("%d]\n", slaves[num_slaves - 1]);
6417         } else {
6418                 printf("\tSlaves: []\n");
6419
6420         }
6421
6422         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6423                         RTE_MAX_ETHPORTS);
6424
6425         if (num_active_slaves < 0) {
6426                 fprintf(stderr,
6427                         "\tFailed to get active slave list for port = %d\n",
6428                         port_id);
6429                 return;
6430         }
6431         if (num_active_slaves > 0) {
6432                 printf("\tActive Slaves (%d): [", num_active_slaves);
6433                 for (i = 0; i < num_active_slaves - 1; i++)
6434                         printf("%d ", slaves[i]);
6435
6436                 printf("%d]\n", slaves[num_active_slaves - 1]);
6437
6438         } else {
6439                 printf("\tActive Slaves: []\n");
6440
6441         }
6442
6443         primary_id = rte_eth_bond_primary_get(port_id);
6444         if (primary_id < 0) {
6445                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6446                         port_id);
6447                 return;
6448         } else
6449                 printf("\tPrimary: [%d]\n", primary_id);
6450
6451 }
6452
6453 static cmdline_parse_token_string_t cmd_showbonding_config_show =
6454 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6455                 show, "show");
6456 static cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6457 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6458                 bonding, "bonding");
6459 static cmdline_parse_token_string_t cmd_showbonding_config_config =
6460 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6461                 config, "config");
6462 static cmdline_parse_token_num_t cmd_showbonding_config_port =
6463 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6464                 port_id, RTE_UINT16);
6465
6466 static cmdline_parse_inst_t cmd_show_bonding_config = {
6467                 .f = cmd_show_bonding_config_parsed,
6468                 .help_str = "show bonding config <port_id>: "
6469                         "Show the bonding config for port_id",
6470                 .data = NULL,
6471                 .tokens = {
6472                                 (void *)&cmd_showbonding_config_show,
6473                                 (void *)&cmd_showbonding_config_bonding,
6474                                 (void *)&cmd_showbonding_config_config,
6475                                 (void *)&cmd_showbonding_config_port,
6476                                 NULL
6477                 }
6478 };
6479
6480 /* *** SET BONDING PRIMARY *** */
6481 struct cmd_set_bonding_primary_result {
6482         cmdline_fixed_string_t set;
6483         cmdline_fixed_string_t bonding;
6484         cmdline_fixed_string_t primary;
6485         portid_t slave_id;
6486         portid_t port_id;
6487 };
6488
6489 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6490                 __rte_unused  struct cmdline *cl,
6491                 __rte_unused void *data)
6492 {
6493         struct cmd_set_bonding_primary_result *res = parsed_result;
6494         portid_t master_port_id = res->port_id;
6495         portid_t slave_port_id = res->slave_id;
6496
6497         /* Set the primary slave for a bonded device. */
6498         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6499                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6500                         master_port_id);
6501                 return;
6502         }
6503         init_port_config();
6504 }
6505
6506 static cmdline_parse_token_string_t cmd_setbonding_primary_set =
6507 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6508                 set, "set");
6509 static cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6510 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6511                 bonding, "bonding");
6512 static cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6513 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6514                 primary, "primary");
6515 static cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6516 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6517                 slave_id, RTE_UINT16);
6518 static cmdline_parse_token_num_t cmd_setbonding_primary_port =
6519 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6520                 port_id, RTE_UINT16);
6521
6522 static cmdline_parse_inst_t cmd_set_bonding_primary = {
6523                 .f = cmd_set_bonding_primary_parsed,
6524                 .help_str = "set bonding primary <slave_id> <port_id>: "
6525                         "Set the primary slave for port_id",
6526                 .data = NULL,
6527                 .tokens = {
6528                                 (void *)&cmd_setbonding_primary_set,
6529                                 (void *)&cmd_setbonding_primary_bonding,
6530                                 (void *)&cmd_setbonding_primary_primary,
6531                                 (void *)&cmd_setbonding_primary_slave,
6532                                 (void *)&cmd_setbonding_primary_port,
6533                                 NULL
6534                 }
6535 };
6536
6537 /* *** ADD SLAVE *** */
6538 struct cmd_add_bonding_slave_result {
6539         cmdline_fixed_string_t add;
6540         cmdline_fixed_string_t bonding;
6541         cmdline_fixed_string_t slave;
6542         portid_t slave_id;
6543         portid_t port_id;
6544 };
6545
6546 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6547                 __rte_unused  struct cmdline *cl,
6548                 __rte_unused void *data)
6549 {
6550         struct cmd_add_bonding_slave_result *res = parsed_result;
6551         portid_t master_port_id = res->port_id;
6552         portid_t slave_port_id = res->slave_id;
6553
6554         /* add the slave for a bonded device. */
6555         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6556                 fprintf(stderr,
6557                         "\t Failed to add slave %d to master port = %d.\n",
6558                         slave_port_id, master_port_id);
6559                 return;
6560         }
6561         init_port_config();
6562         set_port_slave_flag(slave_port_id);
6563 }
6564
6565 static cmdline_parse_token_string_t cmd_addbonding_slave_add =
6566 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6567                 add, "add");
6568 static cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6569 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6570                 bonding, "bonding");
6571 static cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6572 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6573                 slave, "slave");
6574 static cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6575 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6576                 slave_id, RTE_UINT16);
6577 static cmdline_parse_token_num_t cmd_addbonding_slave_port =
6578 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6579                 port_id, RTE_UINT16);
6580
6581 static cmdline_parse_inst_t cmd_add_bonding_slave = {
6582                 .f = cmd_add_bonding_slave_parsed,
6583                 .help_str = "add bonding slave <slave_id> <port_id>: "
6584                         "Add a slave device to a bonded device",
6585                 .data = NULL,
6586                 .tokens = {
6587                                 (void *)&cmd_addbonding_slave_add,
6588                                 (void *)&cmd_addbonding_slave_bonding,
6589                                 (void *)&cmd_addbonding_slave_slave,
6590                                 (void *)&cmd_addbonding_slave_slaveid,
6591                                 (void *)&cmd_addbonding_slave_port,
6592                                 NULL
6593                 }
6594 };
6595
6596 /* *** REMOVE SLAVE *** */
6597 struct cmd_remove_bonding_slave_result {
6598         cmdline_fixed_string_t remove;
6599         cmdline_fixed_string_t bonding;
6600         cmdline_fixed_string_t slave;
6601         portid_t slave_id;
6602         portid_t port_id;
6603 };
6604
6605 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6606                 __rte_unused  struct cmdline *cl,
6607                 __rte_unused void *data)
6608 {
6609         struct cmd_remove_bonding_slave_result *res = parsed_result;
6610         portid_t master_port_id = res->port_id;
6611         portid_t slave_port_id = res->slave_id;
6612
6613         /* remove the slave from a bonded device. */
6614         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6615                 fprintf(stderr,
6616                         "\t Failed to remove slave %d from master port = %d.\n",
6617                         slave_port_id, master_port_id);
6618                 return;
6619         }
6620         init_port_config();
6621         clear_port_slave_flag(slave_port_id);
6622 }
6623
6624 static cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6625                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6626                                 remove, "remove");
6627 static cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6628                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6629                                 bonding, "bonding");
6630 static cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6631                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6632                                 slave, "slave");
6633 static cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6634                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6635                                 slave_id, RTE_UINT16);
6636 static cmdline_parse_token_num_t cmd_removebonding_slave_port =
6637                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6638                                 port_id, RTE_UINT16);
6639
6640 static cmdline_parse_inst_t cmd_remove_bonding_slave = {
6641                 .f = cmd_remove_bonding_slave_parsed,
6642                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6643                         "Remove a slave device from a bonded device",
6644                 .data = NULL,
6645                 .tokens = {
6646                                 (void *)&cmd_removebonding_slave_remove,
6647                                 (void *)&cmd_removebonding_slave_bonding,
6648                                 (void *)&cmd_removebonding_slave_slave,
6649                                 (void *)&cmd_removebonding_slave_slaveid,
6650                                 (void *)&cmd_removebonding_slave_port,
6651                                 NULL
6652                 }
6653 };
6654
6655 /* *** CREATE BONDED DEVICE *** */
6656 struct cmd_create_bonded_device_result {
6657         cmdline_fixed_string_t create;
6658         cmdline_fixed_string_t bonded;
6659         cmdline_fixed_string_t device;
6660         uint8_t mode;
6661         uint8_t socket;
6662 };
6663
6664 static int bond_dev_num = 0;
6665
6666 static void cmd_create_bonded_device_parsed(void *parsed_result,
6667                 __rte_unused  struct cmdline *cl,
6668                 __rte_unused void *data)
6669 {
6670         struct cmd_create_bonded_device_result *res = parsed_result;
6671         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6672         int port_id;
6673         int ret;
6674
6675         if (test_done == 0) {
6676                 fprintf(stderr, "Please stop forwarding first\n");
6677                 return;
6678         }
6679
6680         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6681                         bond_dev_num++);
6682
6683         /* Create a new bonded device. */
6684         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6685         if (port_id < 0) {
6686                 fprintf(stderr, "\t Failed to create bonded device.\n");
6687                 return;
6688         } else {
6689                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6690                                 port_id);
6691
6692                 /* Update number of ports */
6693                 nb_ports = rte_eth_dev_count_avail();
6694                 reconfig(port_id, res->socket);
6695                 ret = rte_eth_promiscuous_enable(port_id);
6696                 if (ret != 0)
6697                         fprintf(stderr,
6698                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6699                                 port_id, rte_strerror(-ret));
6700
6701                 ports[port_id].bond_flag = 1;
6702                 ports[port_id].need_setup = 0;
6703                 ports[port_id].port_status = RTE_PORT_STOPPED;
6704         }
6705
6706 }
6707
6708 static cmdline_parse_token_string_t cmd_createbonded_device_create =
6709                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6710                                 create, "create");
6711 static cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6712                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6713                                 bonded, "bonded");
6714 static cmdline_parse_token_string_t cmd_createbonded_device_device =
6715                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6716                                 device, "device");
6717 static cmdline_parse_token_num_t cmd_createbonded_device_mode =
6718                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6719                                 mode, RTE_UINT8);
6720 static cmdline_parse_token_num_t cmd_createbonded_device_socket =
6721                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6722                                 socket, RTE_UINT8);
6723
6724 static cmdline_parse_inst_t cmd_create_bonded_device = {
6725                 .f = cmd_create_bonded_device_parsed,
6726                 .help_str = "create bonded device <mode> <socket>: "
6727                         "Create a new bonded device with specific bonding mode and socket",
6728                 .data = NULL,
6729                 .tokens = {
6730                                 (void *)&cmd_createbonded_device_create,
6731                                 (void *)&cmd_createbonded_device_bonded,
6732                                 (void *)&cmd_createbonded_device_device,
6733                                 (void *)&cmd_createbonded_device_mode,
6734                                 (void *)&cmd_createbonded_device_socket,
6735                                 NULL
6736                 }
6737 };
6738
6739 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6740 struct cmd_set_bond_mac_addr_result {
6741         cmdline_fixed_string_t set;
6742         cmdline_fixed_string_t bonding;
6743         cmdline_fixed_string_t mac_addr;
6744         uint16_t port_num;
6745         struct rte_ether_addr address;
6746 };
6747
6748 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6749                 __rte_unused  struct cmdline *cl,
6750                 __rte_unused void *data)
6751 {
6752         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6753         int ret;
6754
6755         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6756                 return;
6757
6758         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6759
6760         /* check the return value and print it if is < 0 */
6761         if (ret < 0)
6762                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6763                         strerror(-ret));
6764 }
6765
6766 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6767                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6768 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6769                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6770                                 "bonding");
6771 static cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6772                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6773                                 "mac_addr");
6774 static cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6775                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6776                                 port_num, RTE_UINT16);
6777 static cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6778                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6779
6780 static cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6781                 .f = cmd_set_bond_mac_addr_parsed,
6782                 .data = (void *) 0,
6783                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6784                 .tokens = {
6785                                 (void *)&cmd_set_bond_mac_addr_set,
6786                                 (void *)&cmd_set_bond_mac_addr_bonding,
6787                                 (void *)&cmd_set_bond_mac_addr_mac,
6788                                 (void *)&cmd_set_bond_mac_addr_portnum,
6789                                 (void *)&cmd_set_bond_mac_addr_addr,
6790                                 NULL
6791                 }
6792 };
6793
6794
6795 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6796 struct cmd_set_bond_mon_period_result {
6797         cmdline_fixed_string_t set;
6798         cmdline_fixed_string_t bonding;
6799         cmdline_fixed_string_t mon_period;
6800         uint16_t port_num;
6801         uint32_t period_ms;
6802 };
6803
6804 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6805                 __rte_unused  struct cmdline *cl,
6806                 __rte_unused void *data)
6807 {
6808         struct cmd_set_bond_mon_period_result *res = parsed_result;
6809         int ret;
6810
6811         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6812
6813         /* check the return value and print it if is < 0 */
6814         if (ret < 0)
6815                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6816                         strerror(-ret));
6817 }
6818
6819 static cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6820                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6821                                 set, "set");
6822 static cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6823                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6824                                 bonding, "bonding");
6825 static cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6826                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6827                                 mon_period,     "mon_period");
6828 static cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6829                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6830                                 port_num, RTE_UINT16);
6831 static cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6832                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6833                                 period_ms, RTE_UINT32);
6834
6835 static cmdline_parse_inst_t cmd_set_bond_mon_period = {
6836                 .f = cmd_set_bond_mon_period_parsed,
6837                 .data = (void *) 0,
6838                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6839                 .tokens = {
6840                                 (void *)&cmd_set_bond_mon_period_set,
6841                                 (void *)&cmd_set_bond_mon_period_bonding,
6842                                 (void *)&cmd_set_bond_mon_period_mon_period,
6843                                 (void *)&cmd_set_bond_mon_period_portnum,
6844                                 (void *)&cmd_set_bond_mon_period_period_ms,
6845                                 NULL
6846                 }
6847 };
6848
6849
6850
6851 struct cmd_set_bonding_agg_mode_policy_result {
6852         cmdline_fixed_string_t set;
6853         cmdline_fixed_string_t bonding;
6854         cmdline_fixed_string_t agg_mode;
6855         uint16_t port_num;
6856         cmdline_fixed_string_t policy;
6857 };
6858
6859
6860 static void
6861 cmd_set_bonding_agg_mode(void *parsed_result,
6862                 __rte_unused struct cmdline *cl,
6863                 __rte_unused void *data)
6864 {
6865         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6866         uint8_t policy = AGG_BANDWIDTH;
6867
6868         if (!strcmp(res->policy, "bandwidth"))
6869                 policy = AGG_BANDWIDTH;
6870         else if (!strcmp(res->policy, "stable"))
6871                 policy = AGG_STABLE;
6872         else if (!strcmp(res->policy, "count"))
6873                 policy = AGG_COUNT;
6874
6875         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6876 }
6877
6878
6879 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6880         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6881                                 set, "set");
6882 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6883         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6884                                 bonding, "bonding");
6885
6886 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6887         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6888                                 agg_mode, "agg_mode");
6889
6890 static cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6891         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6892                                 port_num, RTE_UINT16);
6893
6894 static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6895         TOKEN_STRING_INITIALIZER(
6896                         struct cmd_set_bonding_balance_xmit_policy_result,
6897                 policy, "stable#bandwidth#count");
6898
6899 static cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6900         .f = cmd_set_bonding_agg_mode,
6901         .data = (void *) 0,
6902         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6903         .tokens = {
6904                         (void *)&cmd_set_bonding_agg_mode_set,
6905                         (void *)&cmd_set_bonding_agg_mode_bonding,
6906                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6907                         (void *)&cmd_set_bonding_agg_mode_portnum,
6908                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6909                         NULL
6910                 }
6911 };
6912
6913
6914 #endif /* RTE_NET_BOND */
6915
6916 /* *** SET FORWARDING MODE *** */
6917 struct cmd_set_fwd_mode_result {
6918         cmdline_fixed_string_t set;
6919         cmdline_fixed_string_t fwd;
6920         cmdline_fixed_string_t mode;
6921 };
6922
6923 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6924                                     __rte_unused struct cmdline *cl,
6925                                     __rte_unused void *data)
6926 {
6927         struct cmd_set_fwd_mode_result *res = parsed_result;
6928
6929         retry_enabled = 0;
6930         set_pkt_forwarding_mode(res->mode);
6931 }
6932
6933 static cmdline_parse_token_string_t cmd_setfwd_set =
6934         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6935 static cmdline_parse_token_string_t cmd_setfwd_fwd =
6936         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6937 static cmdline_parse_token_string_t cmd_setfwd_mode =
6938         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6939                 "" /* defined at init */);
6940
6941 static cmdline_parse_inst_t cmd_set_fwd_mode = {
6942         .f = cmd_set_fwd_mode_parsed,
6943         .data = NULL,
6944         .help_str = NULL, /* defined at init */
6945         .tokens = {
6946                 (void *)&cmd_setfwd_set,
6947                 (void *)&cmd_setfwd_fwd,
6948                 (void *)&cmd_setfwd_mode,
6949                 NULL,
6950         },
6951 };
6952
6953 static void cmd_set_fwd_mode_init(void)
6954 {
6955         char *modes, *c;
6956         static char token[128];
6957         static char help[256];
6958         cmdline_parse_token_string_t *token_struct;
6959
6960         modes = list_pkt_forwarding_modes();
6961         snprintf(help, sizeof(help), "set fwd %s: "
6962                 "Set packet forwarding mode", modes);
6963         cmd_set_fwd_mode.help_str = help;
6964
6965         /* string token separator is # */
6966         for (c = token; *modes != '\0'; modes++)
6967                 if (*modes == '|')
6968                         *c++ = '#';
6969                 else
6970                         *c++ = *modes;
6971         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6972         token_struct->string_data.str = token;
6973 }
6974
6975 /* *** SET RETRY FORWARDING MODE *** */
6976 struct cmd_set_fwd_retry_mode_result {
6977         cmdline_fixed_string_t set;
6978         cmdline_fixed_string_t fwd;
6979         cmdline_fixed_string_t mode;
6980         cmdline_fixed_string_t retry;
6981 };
6982
6983 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6984                             __rte_unused struct cmdline *cl,
6985                             __rte_unused void *data)
6986 {
6987         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6988
6989         retry_enabled = 1;
6990         set_pkt_forwarding_mode(res->mode);
6991 }
6992
6993 static cmdline_parse_token_string_t cmd_setfwd_retry_set =
6994         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6995                         set, "set");
6996 static cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6997         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6998                         fwd, "fwd");
6999 static cmdline_parse_token_string_t cmd_setfwd_retry_mode =
7000         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
7001                         mode,
7002                 "" /* defined at init */);
7003 static cmdline_parse_token_string_t cmd_setfwd_retry_retry =
7004         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
7005                         retry, "retry");
7006
7007 static cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
7008         .f = cmd_set_fwd_retry_mode_parsed,
7009         .data = NULL,
7010         .help_str = NULL, /* defined at init */
7011         .tokens = {
7012                 (void *)&cmd_setfwd_retry_set,
7013                 (void *)&cmd_setfwd_retry_fwd,
7014                 (void *)&cmd_setfwd_retry_mode,
7015                 (void *)&cmd_setfwd_retry_retry,
7016                 NULL,
7017         },
7018 };
7019
7020 static void cmd_set_fwd_retry_mode_init(void)
7021 {
7022         char *modes, *c;
7023         static char token[128];
7024         static char help[256];
7025         cmdline_parse_token_string_t *token_struct;
7026
7027         modes = list_pkt_forwarding_retry_modes();
7028         snprintf(help, sizeof(help), "set fwd %s retry: "
7029                 "Set packet forwarding mode with retry", modes);
7030         cmd_set_fwd_retry_mode.help_str = help;
7031
7032         /* string token separator is # */
7033         for (c = token; *modes != '\0'; modes++)
7034                 if (*modes == '|')
7035                         *c++ = '#';
7036                 else
7037                         *c++ = *modes;
7038         token_struct = (cmdline_parse_token_string_t *)
7039                 cmd_set_fwd_retry_mode.tokens[2];
7040         token_struct->string_data.str = token;
7041 }
7042
7043 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7044 struct cmd_set_burst_tx_retry_result {
7045         cmdline_fixed_string_t set;
7046         cmdline_fixed_string_t burst;
7047         cmdline_fixed_string_t tx;
7048         cmdline_fixed_string_t delay;
7049         uint32_t time;
7050         cmdline_fixed_string_t retry;
7051         uint32_t retry_num;
7052 };
7053
7054 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7055                                         __rte_unused struct cmdline *cl,
7056                                         __rte_unused void *data)
7057 {
7058         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7059
7060         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7061                 && !strcmp(res->tx, "tx")) {
7062                 if (!strcmp(res->delay, "delay"))
7063                         burst_tx_delay_time = res->time;
7064                 if (!strcmp(res->retry, "retry"))
7065                         burst_tx_retry_num = res->retry_num;
7066         }
7067
7068 }
7069
7070 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7071         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7072 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7073         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7074                                  "burst");
7075 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7076         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7077 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7078         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7079 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7080         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7081                                  RTE_UINT32);
7082 static cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7083         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7084 static cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7085         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7086                                  RTE_UINT32);
7087
7088 static cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7089         .f = cmd_set_burst_tx_retry_parsed,
7090         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7091         .tokens = {
7092                 (void *)&cmd_set_burst_tx_retry_set,
7093                 (void *)&cmd_set_burst_tx_retry_burst,
7094                 (void *)&cmd_set_burst_tx_retry_tx,
7095                 (void *)&cmd_set_burst_tx_retry_delay,
7096                 (void *)&cmd_set_burst_tx_retry_time,
7097                 (void *)&cmd_set_burst_tx_retry_retry,
7098                 (void *)&cmd_set_burst_tx_retry_retry_num,
7099                 NULL,
7100         },
7101 };
7102
7103 /* *** SET PROMISC MODE *** */
7104 struct cmd_set_promisc_mode_result {
7105         cmdline_fixed_string_t set;
7106         cmdline_fixed_string_t promisc;
7107         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7108         uint16_t port_num;               /* valid if "allports" argument == 0 */
7109         cmdline_fixed_string_t mode;
7110 };
7111
7112 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7113                                         __rte_unused struct cmdline *cl,
7114                                         void *allports)
7115 {
7116         struct cmd_set_promisc_mode_result *res = parsed_result;
7117         int enable;
7118         portid_t i;
7119
7120         if (!strcmp(res->mode, "on"))
7121                 enable = 1;
7122         else
7123                 enable = 0;
7124
7125         /* all ports */
7126         if (allports) {
7127                 RTE_ETH_FOREACH_DEV(i)
7128                         eth_set_promisc_mode(i, enable);
7129         } else {
7130                 eth_set_promisc_mode(res->port_num, enable);
7131         }
7132 }
7133
7134 static cmdline_parse_token_string_t cmd_setpromisc_set =
7135         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7136 static cmdline_parse_token_string_t cmd_setpromisc_promisc =
7137         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7138                                  "promisc");
7139 static cmdline_parse_token_string_t cmd_setpromisc_portall =
7140         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7141                                  "all");
7142 static cmdline_parse_token_num_t cmd_setpromisc_portnum =
7143         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7144                               RTE_UINT16);
7145 static cmdline_parse_token_string_t cmd_setpromisc_mode =
7146         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7147                                  "on#off");
7148
7149 static cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7150         .f = cmd_set_promisc_mode_parsed,
7151         .data = (void *)1,
7152         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7153         .tokens = {
7154                 (void *)&cmd_setpromisc_set,
7155                 (void *)&cmd_setpromisc_promisc,
7156                 (void *)&cmd_setpromisc_portall,
7157                 (void *)&cmd_setpromisc_mode,
7158                 NULL,
7159         },
7160 };
7161
7162 static cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7163         .f = cmd_set_promisc_mode_parsed,
7164         .data = (void *)0,
7165         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7166         .tokens = {
7167                 (void *)&cmd_setpromisc_set,
7168                 (void *)&cmd_setpromisc_promisc,
7169                 (void *)&cmd_setpromisc_portnum,
7170                 (void *)&cmd_setpromisc_mode,
7171                 NULL,
7172         },
7173 };
7174
7175 /* *** SET ALLMULTI MODE *** */
7176 struct cmd_set_allmulti_mode_result {
7177         cmdline_fixed_string_t set;
7178         cmdline_fixed_string_t allmulti;
7179         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7180         uint16_t port_num;               /* valid if "allports" argument == 0 */
7181         cmdline_fixed_string_t mode;
7182 };
7183
7184 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7185                                         __rte_unused struct cmdline *cl,
7186                                         void *allports)
7187 {
7188         struct cmd_set_allmulti_mode_result *res = parsed_result;
7189         int enable;
7190         portid_t i;
7191
7192         if (!strcmp(res->mode, "on"))
7193                 enable = 1;
7194         else
7195                 enable = 0;
7196
7197         /* all ports */
7198         if (allports) {
7199                 RTE_ETH_FOREACH_DEV(i) {
7200                         eth_set_allmulticast_mode(i, enable);
7201                 }
7202         }
7203         else {
7204                 eth_set_allmulticast_mode(res->port_num, enable);
7205         }
7206 }
7207
7208 static cmdline_parse_token_string_t cmd_setallmulti_set =
7209         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7210 static cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7211         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7212                                  "allmulti");
7213 static cmdline_parse_token_string_t cmd_setallmulti_portall =
7214         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7215                                  "all");
7216 static cmdline_parse_token_num_t cmd_setallmulti_portnum =
7217         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7218                               RTE_UINT16);
7219 static cmdline_parse_token_string_t cmd_setallmulti_mode =
7220         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7221                                  "on#off");
7222
7223 static cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7224         .f = cmd_set_allmulti_mode_parsed,
7225         .data = (void *)1,
7226         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7227         .tokens = {
7228                 (void *)&cmd_setallmulti_set,
7229                 (void *)&cmd_setallmulti_allmulti,
7230                 (void *)&cmd_setallmulti_portall,
7231                 (void *)&cmd_setallmulti_mode,
7232                 NULL,
7233         },
7234 };
7235
7236 static cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7237         .f = cmd_set_allmulti_mode_parsed,
7238         .data = (void *)0,
7239         .help_str = "set allmulti <port_id> on|off: "
7240                 "Set allmulti mode on port_id",
7241         .tokens = {
7242                 (void *)&cmd_setallmulti_set,
7243                 (void *)&cmd_setallmulti_allmulti,
7244                 (void *)&cmd_setallmulti_portnum,
7245                 (void *)&cmd_setallmulti_mode,
7246                 NULL,
7247         },
7248 };
7249
7250 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7251 struct cmd_link_flow_ctrl_show {
7252         cmdline_fixed_string_t show;
7253         cmdline_fixed_string_t port;
7254         portid_t port_id;
7255         cmdline_fixed_string_t flow_ctrl;
7256 };
7257
7258 static cmdline_parse_token_string_t cmd_lfc_show_show =
7259         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7260                                 show, "show");
7261 static cmdline_parse_token_string_t cmd_lfc_show_port =
7262         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7263                                 port, "port");
7264 static cmdline_parse_token_num_t cmd_lfc_show_portid =
7265         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7266                                 port_id, RTE_UINT16);
7267 static cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7268         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7269                                 flow_ctrl, "flow_ctrl");
7270
7271 static void
7272 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7273                               __rte_unused struct cmdline *cl,
7274                               __rte_unused void *data)
7275 {
7276         struct cmd_link_flow_ctrl_show *res = parsed_result;
7277         static const char *info_border = "*********************";
7278         struct rte_eth_fc_conf fc_conf;
7279         bool rx_fc_en = false;
7280         bool tx_fc_en = false;
7281         int ret;
7282
7283         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7284         if (ret != 0) {
7285                 fprintf(stderr,
7286                         "Failed to get current flow ctrl information: err = %d\n",
7287                         ret);
7288                 return;
7289         }
7290
7291         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7292                 rx_fc_en = true;
7293         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7294                 tx_fc_en = true;
7295
7296         printf("\n%s Flow control infos for port %-2d %s\n",
7297                 info_border, res->port_id, info_border);
7298         printf("FC mode:\n");
7299         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7300         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7301         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7302         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7303         printf("High waterline: 0x%x\n", fc_conf.high_water);
7304         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7305         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7306         printf("Forward MAC control frames: %s\n",
7307                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7308         printf("\n%s**************   End  ***********%s\n",
7309                 info_border, info_border);
7310 }
7311
7312 static cmdline_parse_inst_t cmd_link_flow_control_show = {
7313         .f = cmd_link_flow_ctrl_show_parsed,
7314         .data = NULL,
7315         .help_str = "show port <port_id> flow_ctrl",
7316         .tokens = {
7317                 (void *)&cmd_lfc_show_show,
7318                 (void *)&cmd_lfc_show_port,
7319                 (void *)&cmd_lfc_show_portid,
7320                 (void *)&cmd_lfc_show_flow_ctrl,
7321                 NULL,
7322         },
7323 };
7324
7325 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7326 struct cmd_link_flow_ctrl_set_result {
7327         cmdline_fixed_string_t set;
7328         cmdline_fixed_string_t flow_ctrl;
7329         cmdline_fixed_string_t rx;
7330         cmdline_fixed_string_t rx_lfc_mode;
7331         cmdline_fixed_string_t tx;
7332         cmdline_fixed_string_t tx_lfc_mode;
7333         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7334         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7335         cmdline_fixed_string_t autoneg_str;
7336         cmdline_fixed_string_t autoneg;
7337         cmdline_fixed_string_t hw_str;
7338         uint32_t high_water;
7339         cmdline_fixed_string_t lw_str;
7340         uint32_t low_water;
7341         cmdline_fixed_string_t pt_str;
7342         uint16_t pause_time;
7343         cmdline_fixed_string_t xon_str;
7344         uint16_t send_xon;
7345         portid_t port_id;
7346 };
7347
7348 static cmdline_parse_token_string_t cmd_lfc_set_set =
7349         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7350                                 set, "set");
7351 static cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7352         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7353                                 flow_ctrl, "flow_ctrl");
7354 static cmdline_parse_token_string_t cmd_lfc_set_rx =
7355         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7356                                 rx, "rx");
7357 static cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7358         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7359                                 rx_lfc_mode, "on#off");
7360 static cmdline_parse_token_string_t cmd_lfc_set_tx =
7361         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7362                                 tx, "tx");
7363 static cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7364         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7365                                 tx_lfc_mode, "on#off");
7366 static cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7367         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7368                                 hw_str, "high_water");
7369 static cmdline_parse_token_num_t cmd_lfc_set_high_water =
7370         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7371                                 high_water, RTE_UINT32);
7372 static cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7373         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7374                                 lw_str, "low_water");
7375 static cmdline_parse_token_num_t cmd_lfc_set_low_water =
7376         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7377                                 low_water, RTE_UINT32);
7378 static cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7379         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7380                                 pt_str, "pause_time");
7381 static cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7382         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7383                                 pause_time, RTE_UINT16);
7384 static cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7385         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7386                                 xon_str, "send_xon");
7387 static cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7388         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7389                                 send_xon, RTE_UINT16);
7390 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7391         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7392                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7393 static cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7394         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7395                                 mac_ctrl_frame_fwd_mode, "on#off");
7396 static cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7397         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7398                                 autoneg_str, "autoneg");
7399 static cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7400         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7401                                 autoneg, "on#off");
7402 static cmdline_parse_token_num_t cmd_lfc_set_portid =
7403         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7404                                 port_id, RTE_UINT16);
7405
7406 /* forward declaration */
7407 static void
7408 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7409                               void *data);
7410
7411 static cmdline_parse_inst_t cmd_link_flow_control_set = {
7412         .f = cmd_link_flow_ctrl_set_parsed,
7413         .data = NULL,
7414         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7415                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7416                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7417         .tokens = {
7418                 (void *)&cmd_lfc_set_set,
7419                 (void *)&cmd_lfc_set_flow_ctrl,
7420                 (void *)&cmd_lfc_set_rx,
7421                 (void *)&cmd_lfc_set_rx_mode,
7422                 (void *)&cmd_lfc_set_tx,
7423                 (void *)&cmd_lfc_set_tx_mode,
7424                 (void *)&cmd_lfc_set_high_water,
7425                 (void *)&cmd_lfc_set_low_water,
7426                 (void *)&cmd_lfc_set_pause_time,
7427                 (void *)&cmd_lfc_set_send_xon,
7428                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7429                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7430                 (void *)&cmd_lfc_set_autoneg_str,
7431                 (void *)&cmd_lfc_set_autoneg,
7432                 (void *)&cmd_lfc_set_portid,
7433                 NULL,
7434         },
7435 };
7436
7437 static cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7438         .f = cmd_link_flow_ctrl_set_parsed,
7439         .data = (void *)&cmd_link_flow_control_set_rx,
7440         .help_str = "set flow_ctrl rx on|off <port_id>: "
7441                 "Change rx flow control parameter",
7442         .tokens = {
7443                 (void *)&cmd_lfc_set_set,
7444                 (void *)&cmd_lfc_set_flow_ctrl,
7445                 (void *)&cmd_lfc_set_rx,
7446                 (void *)&cmd_lfc_set_rx_mode,
7447                 (void *)&cmd_lfc_set_portid,
7448                 NULL,
7449         },
7450 };
7451
7452 static cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7453         .f = cmd_link_flow_ctrl_set_parsed,
7454         .data = (void *)&cmd_link_flow_control_set_tx,
7455         .help_str = "set flow_ctrl tx on|off <port_id>: "
7456                 "Change tx flow control parameter",
7457         .tokens = {
7458                 (void *)&cmd_lfc_set_set,
7459                 (void *)&cmd_lfc_set_flow_ctrl,
7460                 (void *)&cmd_lfc_set_tx,
7461                 (void *)&cmd_lfc_set_tx_mode,
7462                 (void *)&cmd_lfc_set_portid,
7463                 NULL,
7464         },
7465 };
7466
7467 static cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7468         .f = cmd_link_flow_ctrl_set_parsed,
7469         .data = (void *)&cmd_link_flow_control_set_hw,
7470         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7471                 "Change high water flow control parameter",
7472         .tokens = {
7473                 (void *)&cmd_lfc_set_set,
7474                 (void *)&cmd_lfc_set_flow_ctrl,
7475                 (void *)&cmd_lfc_set_high_water_str,
7476                 (void *)&cmd_lfc_set_high_water,
7477                 (void *)&cmd_lfc_set_portid,
7478                 NULL,
7479         },
7480 };
7481
7482 static cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7483         .f = cmd_link_flow_ctrl_set_parsed,
7484         .data = (void *)&cmd_link_flow_control_set_lw,
7485         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7486                 "Change low water flow control parameter",
7487         .tokens = {
7488                 (void *)&cmd_lfc_set_set,
7489                 (void *)&cmd_lfc_set_flow_ctrl,
7490                 (void *)&cmd_lfc_set_low_water_str,
7491                 (void *)&cmd_lfc_set_low_water,
7492                 (void *)&cmd_lfc_set_portid,
7493                 NULL,
7494         },
7495 };
7496
7497 static cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7498         .f = cmd_link_flow_ctrl_set_parsed,
7499         .data = (void *)&cmd_link_flow_control_set_pt,
7500         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7501                 "Change pause time flow control parameter",
7502         .tokens = {
7503                 (void *)&cmd_lfc_set_set,
7504                 (void *)&cmd_lfc_set_flow_ctrl,
7505                 (void *)&cmd_lfc_set_pause_time_str,
7506                 (void *)&cmd_lfc_set_pause_time,
7507                 (void *)&cmd_lfc_set_portid,
7508                 NULL,
7509         },
7510 };
7511
7512 static cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7513         .f = cmd_link_flow_ctrl_set_parsed,
7514         .data = (void *)&cmd_link_flow_control_set_xon,
7515         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7516                 "Change send_xon flow control parameter",
7517         .tokens = {
7518                 (void *)&cmd_lfc_set_set,
7519                 (void *)&cmd_lfc_set_flow_ctrl,
7520                 (void *)&cmd_lfc_set_send_xon_str,
7521                 (void *)&cmd_lfc_set_send_xon,
7522                 (void *)&cmd_lfc_set_portid,
7523                 NULL,
7524         },
7525 };
7526
7527 static cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7528         .f = cmd_link_flow_ctrl_set_parsed,
7529         .data = (void *)&cmd_link_flow_control_set_macfwd,
7530         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7531                 "Change mac ctrl fwd flow control parameter",
7532         .tokens = {
7533                 (void *)&cmd_lfc_set_set,
7534                 (void *)&cmd_lfc_set_flow_ctrl,
7535                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7536                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7537                 (void *)&cmd_lfc_set_portid,
7538                 NULL,
7539         },
7540 };
7541
7542 static cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7543         .f = cmd_link_flow_ctrl_set_parsed,
7544         .data = (void *)&cmd_link_flow_control_set_autoneg,
7545         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7546                 "Change autoneg flow control parameter",
7547         .tokens = {
7548                 (void *)&cmd_lfc_set_set,
7549                 (void *)&cmd_lfc_set_flow_ctrl,
7550                 (void *)&cmd_lfc_set_autoneg_str,
7551                 (void *)&cmd_lfc_set_autoneg,
7552                 (void *)&cmd_lfc_set_portid,
7553                 NULL,
7554         },
7555 };
7556
7557 static void
7558 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7559                               __rte_unused struct cmdline *cl,
7560                               void *data)
7561 {
7562         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7563         cmdline_parse_inst_t *cmd = data;
7564         struct rte_eth_fc_conf fc_conf;
7565         int rx_fc_en = 0;
7566         int tx_fc_en = 0;
7567         int ret;
7568
7569         /*
7570          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7571          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7572          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7573          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7574          */
7575         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7576                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7577         };
7578
7579         /* Partial command line, retrieve current configuration */
7580         if (cmd) {
7581                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7582                 if (ret != 0) {
7583                         fprintf(stderr,
7584                                 "cannot get current flow ctrl parameters, return code = %d\n",
7585                                 ret);
7586                         return;
7587                 }
7588
7589                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7590                     (fc_conf.mode == RTE_ETH_FC_FULL))
7591                         rx_fc_en = 1;
7592                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7593                     (fc_conf.mode == RTE_ETH_FC_FULL))
7594                         tx_fc_en = 1;
7595         }
7596
7597         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7598                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7599
7600         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7601                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7602
7603         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7604
7605         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7606                 fc_conf.high_water = res->high_water;
7607
7608         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7609                 fc_conf.low_water = res->low_water;
7610
7611         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7612                 fc_conf.pause_time = res->pause_time;
7613
7614         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7615                 fc_conf.send_xon = res->send_xon;
7616
7617         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7618                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7619                         fc_conf.mac_ctrl_frame_fwd = 1;
7620                 else
7621                         fc_conf.mac_ctrl_frame_fwd = 0;
7622         }
7623
7624         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7625                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7626
7627         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7628         if (ret != 0)
7629                 fprintf(stderr,
7630                         "bad flow control parameter, return code = %d\n",
7631                         ret);
7632 }
7633
7634 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7635 struct cmd_priority_flow_ctrl_set_result {
7636         cmdline_fixed_string_t set;
7637         cmdline_fixed_string_t pfc_ctrl;
7638         cmdline_fixed_string_t rx;
7639         cmdline_fixed_string_t rx_pfc_mode;
7640         cmdline_fixed_string_t tx;
7641         cmdline_fixed_string_t tx_pfc_mode;
7642         uint32_t high_water;
7643         uint32_t low_water;
7644         uint16_t pause_time;
7645         uint8_t  priority;
7646         portid_t port_id;
7647 };
7648
7649 static void
7650 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7651                        __rte_unused struct cmdline *cl,
7652                        __rte_unused void *data)
7653 {
7654         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7655         struct rte_eth_pfc_conf pfc_conf;
7656         int rx_fc_enable, tx_fc_enable;
7657         int ret;
7658
7659         /*
7660          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7661          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7662          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7663          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7664          */
7665         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7666                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7667         };
7668
7669         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7670         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7671         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7672         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7673         pfc_conf.fc.high_water = res->high_water;
7674         pfc_conf.fc.low_water  = res->low_water;
7675         pfc_conf.fc.pause_time = res->pause_time;
7676         pfc_conf.priority      = res->priority;
7677
7678         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7679         if (ret != 0)
7680                 fprintf(stderr,
7681                         "bad priority flow control parameter, return code = %d\n",
7682                         ret);
7683 }
7684
7685 static cmdline_parse_token_string_t cmd_pfc_set_set =
7686         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7687                                 set, "set");
7688 static cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7689         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7690                                 pfc_ctrl, "pfc_ctrl");
7691 static cmdline_parse_token_string_t cmd_pfc_set_rx =
7692         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7693                                 rx, "rx");
7694 static cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7695         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7696                                 rx_pfc_mode, "on#off");
7697 static cmdline_parse_token_string_t cmd_pfc_set_tx =
7698         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7699                                 tx, "tx");
7700 static cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7701         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7702                                 tx_pfc_mode, "on#off");
7703 static cmdline_parse_token_num_t cmd_pfc_set_high_water =
7704         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7705                                 high_water, RTE_UINT32);
7706 static cmdline_parse_token_num_t cmd_pfc_set_low_water =
7707         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7708                                 low_water, RTE_UINT32);
7709 static cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7710         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7711                                 pause_time, RTE_UINT16);
7712 static cmdline_parse_token_num_t cmd_pfc_set_priority =
7713         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7714                                 priority, RTE_UINT8);
7715 static cmdline_parse_token_num_t cmd_pfc_set_portid =
7716         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7717                                 port_id, RTE_UINT16);
7718
7719 static cmdline_parse_inst_t cmd_priority_flow_control_set = {
7720         .f = cmd_priority_flow_ctrl_set_parsed,
7721         .data = NULL,
7722         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7723                 "<pause_time> <priority> <port_id>: "
7724                 "Configure the Ethernet priority flow control",
7725         .tokens = {
7726                 (void *)&cmd_pfc_set_set,
7727                 (void *)&cmd_pfc_set_flow_ctrl,
7728                 (void *)&cmd_pfc_set_rx,
7729                 (void *)&cmd_pfc_set_rx_mode,
7730                 (void *)&cmd_pfc_set_tx,
7731                 (void *)&cmd_pfc_set_tx_mode,
7732                 (void *)&cmd_pfc_set_high_water,
7733                 (void *)&cmd_pfc_set_low_water,
7734                 (void *)&cmd_pfc_set_pause_time,
7735                 (void *)&cmd_pfc_set_priority,
7736                 (void *)&cmd_pfc_set_portid,
7737                 NULL,
7738         },
7739 };
7740
7741 struct cmd_queue_priority_flow_ctrl_set_result {
7742         cmdline_fixed_string_t set;
7743         cmdline_fixed_string_t pfc_queue_ctrl;
7744         portid_t port_id;
7745         cmdline_fixed_string_t rx;
7746         cmdline_fixed_string_t rx_pfc_mode;
7747         uint16_t tx_qid;
7748         uint8_t  tx_tc;
7749         cmdline_fixed_string_t tx;
7750         cmdline_fixed_string_t tx_pfc_mode;
7751         uint16_t rx_qid;
7752         uint8_t  rx_tc;
7753         uint16_t pause_time;
7754 };
7755
7756 static void
7757 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7758                                         __rte_unused struct cmdline *cl,
7759                                         __rte_unused void *data)
7760 {
7761         struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7762         struct rte_eth_pfc_queue_conf pfc_queue_conf;
7763         int rx_fc_enable, tx_fc_enable;
7764         int ret;
7765
7766         /*
7767          * Rx on/off, flow control is enabled/disabled on RX side. This can
7768          * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7769          * side. Tx on/off, flow control is enabled/disabled on TX side. This
7770          * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7771          * the Tx side.
7772          */
7773         static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7774                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7775                 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7776         };
7777
7778         memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7779         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7780         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7781         pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7782         pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7783         pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7784         pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7785         pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7786         pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7787
7788         ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7789                                                              &pfc_queue_conf);
7790         if (ret != 0) {
7791                 fprintf(stderr,
7792                         "bad queue priority flow control parameter, rc = %d\n",
7793                         ret);
7794         }
7795 }
7796
7797 static cmdline_parse_token_string_t cmd_q_pfc_set_set =
7798         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7799                                 set, "set");
7800 static cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7801         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7802                                 pfc_queue_ctrl, "pfc_queue_ctrl");
7803 static cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7804         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7805                                 port_id, RTE_UINT16);
7806 static cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7807         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7808                                 rx, "rx");
7809 static cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7810         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7811                                 rx_pfc_mode, "on#off");
7812 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7813         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7814                                 tx_qid, RTE_UINT16);
7815 static cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7816         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7817                                 tx_tc, RTE_UINT8);
7818 static cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7819         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7820                                 tx, "tx");
7821 static cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7822         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7823                                 tx_pfc_mode, "on#off");
7824 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7825         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7826                                 rx_qid, RTE_UINT16);
7827 static cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7828         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7829                                 rx_tc, RTE_UINT8);
7830 static cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7831         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7832                                 pause_time, RTE_UINT16);
7833
7834 static cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7835         .f = cmd_queue_priority_flow_ctrl_set_parsed,
7836         .data = NULL,
7837         .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7838                 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7839                 "Configure the Ethernet queue priority flow control",
7840         .tokens = {
7841                 (void *)&cmd_q_pfc_set_set,
7842                 (void *)&cmd_q_pfc_set_flow_ctrl,
7843                 (void *)&cmd_q_pfc_set_portid,
7844                 (void *)&cmd_q_pfc_set_rx,
7845                 (void *)&cmd_q_pfc_set_rx_mode,
7846                 (void *)&cmd_q_pfc_set_tx_qid,
7847                 (void *)&cmd_q_pfc_set_tx_tc,
7848                 (void *)&cmd_q_pfc_set_tx,
7849                 (void *)&cmd_q_pfc_set_tx_mode,
7850                 (void *)&cmd_q_pfc_set_rx_qid,
7851                 (void *)&cmd_q_pfc_set_rx_tc,
7852                 (void *)&cmd_q_pfc_set_pause_time,
7853                 NULL,
7854         },
7855 };
7856
7857 /* *** RESET CONFIGURATION *** */
7858 struct cmd_reset_result {
7859         cmdline_fixed_string_t reset;
7860         cmdline_fixed_string_t def;
7861 };
7862
7863 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7864                              struct cmdline *cl,
7865                              __rte_unused void *data)
7866 {
7867         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7868         set_def_fwd_config();
7869 }
7870
7871 static cmdline_parse_token_string_t cmd_reset_set =
7872         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7873 static cmdline_parse_token_string_t cmd_reset_def =
7874         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7875                                  "default");
7876
7877 static cmdline_parse_inst_t cmd_reset = {
7878         .f = cmd_reset_parsed,
7879         .data = NULL,
7880         .help_str = "set default: Reset default forwarding configuration",
7881         .tokens = {
7882                 (void *)&cmd_reset_set,
7883                 (void *)&cmd_reset_def,
7884                 NULL,
7885         },
7886 };
7887
7888 /* *** START FORWARDING *** */
7889 struct cmd_start_result {
7890         cmdline_fixed_string_t start;
7891 };
7892
7893 static cmdline_parse_token_string_t cmd_start_start =
7894         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7895
7896 static void cmd_start_parsed(__rte_unused void *parsed_result,
7897                              __rte_unused struct cmdline *cl,
7898                              __rte_unused void *data)
7899 {
7900         start_packet_forwarding(0);
7901 }
7902
7903 static cmdline_parse_inst_t cmd_start = {
7904         .f = cmd_start_parsed,
7905         .data = NULL,
7906         .help_str = "start: Start packet forwarding",
7907         .tokens = {
7908                 (void *)&cmd_start_start,
7909                 NULL,
7910         },
7911 };
7912
7913 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7914 struct cmd_start_tx_first_result {
7915         cmdline_fixed_string_t start;
7916         cmdline_fixed_string_t tx_first;
7917 };
7918
7919 static void
7920 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7921                           __rte_unused struct cmdline *cl,
7922                           __rte_unused void *data)
7923 {
7924         start_packet_forwarding(1);
7925 }
7926
7927 static cmdline_parse_token_string_t cmd_start_tx_first_start =
7928         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7929                                  "start");
7930 static cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7931         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7932                                  tx_first, "tx_first");
7933
7934 static cmdline_parse_inst_t cmd_start_tx_first = {
7935         .f = cmd_start_tx_first_parsed,
7936         .data = NULL,
7937         .help_str = "start tx_first: Start packet forwarding, "
7938                 "after sending 1 burst of packets",
7939         .tokens = {
7940                 (void *)&cmd_start_tx_first_start,
7941                 (void *)&cmd_start_tx_first_tx_first,
7942                 NULL,
7943         },
7944 };
7945
7946 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7947 struct cmd_start_tx_first_n_result {
7948         cmdline_fixed_string_t start;
7949         cmdline_fixed_string_t tx_first;
7950         uint32_t tx_num;
7951 };
7952
7953 static void
7954 cmd_start_tx_first_n_parsed(void *parsed_result,
7955                           __rte_unused struct cmdline *cl,
7956                           __rte_unused void *data)
7957 {
7958         struct cmd_start_tx_first_n_result *res = parsed_result;
7959
7960         start_packet_forwarding(res->tx_num);
7961 }
7962
7963 static cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7964         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7965                         start, "start");
7966 static cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7967         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7968                         tx_first, "tx_first");
7969 static cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7970         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7971                         tx_num, RTE_UINT32);
7972
7973 static cmdline_parse_inst_t cmd_start_tx_first_n = {
7974         .f = cmd_start_tx_first_n_parsed,
7975         .data = NULL,
7976         .help_str = "start tx_first <num>: "
7977                 "packet forwarding, after sending <num> bursts of packets",
7978         .tokens = {
7979                 (void *)&cmd_start_tx_first_n_start,
7980                 (void *)&cmd_start_tx_first_n_tx_first,
7981                 (void *)&cmd_start_tx_first_n_tx_num,
7982                 NULL,
7983         },
7984 };
7985
7986 /* *** SET LINK UP *** */
7987 struct cmd_set_link_up_result {
7988         cmdline_fixed_string_t set;
7989         cmdline_fixed_string_t link_up;
7990         cmdline_fixed_string_t port;
7991         portid_t port_id;
7992 };
7993
7994 static cmdline_parse_token_string_t cmd_set_link_up_set =
7995         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7996 static cmdline_parse_token_string_t cmd_set_link_up_link_up =
7997         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7998                                 "link-up");
7999 static cmdline_parse_token_string_t cmd_set_link_up_port =
8000         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
8001 static cmdline_parse_token_num_t cmd_set_link_up_port_id =
8002         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
8003                                 RTE_UINT16);
8004
8005 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
8006                              __rte_unused struct cmdline *cl,
8007                              __rte_unused void *data)
8008 {
8009         struct cmd_set_link_up_result *res = parsed_result;
8010         dev_set_link_up(res->port_id);
8011 }
8012
8013 static cmdline_parse_inst_t cmd_set_link_up = {
8014         .f = cmd_set_link_up_parsed,
8015         .data = NULL,
8016         .help_str = "set link-up port <port id>",
8017         .tokens = {
8018                 (void *)&cmd_set_link_up_set,
8019                 (void *)&cmd_set_link_up_link_up,
8020                 (void *)&cmd_set_link_up_port,
8021                 (void *)&cmd_set_link_up_port_id,
8022                 NULL,
8023         },
8024 };
8025
8026 /* *** SET LINK DOWN *** */
8027 struct cmd_set_link_down_result {
8028         cmdline_fixed_string_t set;
8029         cmdline_fixed_string_t link_down;
8030         cmdline_fixed_string_t port;
8031         portid_t port_id;
8032 };
8033
8034 static cmdline_parse_token_string_t cmd_set_link_down_set =
8035         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8036 static cmdline_parse_token_string_t cmd_set_link_down_link_down =
8037         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8038                                 "link-down");
8039 static cmdline_parse_token_string_t cmd_set_link_down_port =
8040         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8041 static cmdline_parse_token_num_t cmd_set_link_down_port_id =
8042         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8043                                 RTE_UINT16);
8044
8045 static void cmd_set_link_down_parsed(
8046                                 __rte_unused void *parsed_result,
8047                                 __rte_unused struct cmdline *cl,
8048                                 __rte_unused void *data)
8049 {
8050         struct cmd_set_link_down_result *res = parsed_result;
8051         dev_set_link_down(res->port_id);
8052 }
8053
8054 static cmdline_parse_inst_t cmd_set_link_down = {
8055         .f = cmd_set_link_down_parsed,
8056         .data = NULL,
8057         .help_str = "set link-down port <port id>",
8058         .tokens = {
8059                 (void *)&cmd_set_link_down_set,
8060                 (void *)&cmd_set_link_down_link_down,
8061                 (void *)&cmd_set_link_down_port,
8062                 (void *)&cmd_set_link_down_port_id,
8063                 NULL,
8064         },
8065 };
8066
8067 /* *** SHOW CFG *** */
8068 struct cmd_showcfg_result {
8069         cmdline_fixed_string_t show;
8070         cmdline_fixed_string_t cfg;
8071         cmdline_fixed_string_t what;
8072 };
8073
8074 static void cmd_showcfg_parsed(void *parsed_result,
8075                                __rte_unused struct cmdline *cl,
8076                                __rte_unused void *data)
8077 {
8078         struct cmd_showcfg_result *res = parsed_result;
8079         if (!strcmp(res->what, "rxtx"))
8080                 rxtx_config_display();
8081         else if (!strcmp(res->what, "cores"))
8082                 fwd_lcores_config_display();
8083         else if (!strcmp(res->what, "fwd"))
8084                 pkt_fwd_config_display(&cur_fwd_config);
8085         else if (!strcmp(res->what, "rxoffs"))
8086                 show_rx_pkt_offsets();
8087         else if (!strcmp(res->what, "rxpkts"))
8088                 show_rx_pkt_segments();
8089         else if (!strcmp(res->what, "txpkts"))
8090                 show_tx_pkt_segments();
8091         else if (!strcmp(res->what, "txtimes"))
8092                 show_tx_pkt_times();
8093 }
8094
8095 static cmdline_parse_token_string_t cmd_showcfg_show =
8096         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8097 static cmdline_parse_token_string_t cmd_showcfg_port =
8098         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8099 static cmdline_parse_token_string_t cmd_showcfg_what =
8100         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8101                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8102
8103 static cmdline_parse_inst_t cmd_showcfg = {
8104         .f = cmd_showcfg_parsed,
8105         .data = NULL,
8106         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8107         .tokens = {
8108                 (void *)&cmd_showcfg_show,
8109                 (void *)&cmd_showcfg_port,
8110                 (void *)&cmd_showcfg_what,
8111                 NULL,
8112         },
8113 };
8114
8115 /* *** SHOW ALL PORT INFO *** */
8116 struct cmd_showportall_result {
8117         cmdline_fixed_string_t show;
8118         cmdline_fixed_string_t port;
8119         cmdline_fixed_string_t what;
8120         cmdline_fixed_string_t all;
8121 };
8122
8123 static void cmd_showportall_parsed(void *parsed_result,
8124                                 __rte_unused struct cmdline *cl,
8125                                 __rte_unused void *data)
8126 {
8127         portid_t i;
8128
8129         struct cmd_showportall_result *res = parsed_result;
8130         if (!strcmp(res->show, "clear")) {
8131                 if (!strcmp(res->what, "stats"))
8132                         RTE_ETH_FOREACH_DEV(i)
8133                                 nic_stats_clear(i);
8134                 else if (!strcmp(res->what, "xstats"))
8135                         RTE_ETH_FOREACH_DEV(i)
8136                                 nic_xstats_clear(i);
8137         } else if (!strcmp(res->what, "info"))
8138                 RTE_ETH_FOREACH_DEV(i)
8139                         port_infos_display(i);
8140         else if (!strcmp(res->what, "summary")) {
8141                 port_summary_header_display();
8142                 RTE_ETH_FOREACH_DEV(i)
8143                         port_summary_display(i);
8144         }
8145         else if (!strcmp(res->what, "stats"))
8146                 RTE_ETH_FOREACH_DEV(i)
8147                         nic_stats_display(i);
8148         else if (!strcmp(res->what, "xstats"))
8149                 RTE_ETH_FOREACH_DEV(i)
8150                         nic_xstats_display(i);
8151 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8152         else if (!strcmp(res->what, "fdir"))
8153                 RTE_ETH_FOREACH_DEV(i)
8154                         fdir_get_infos(i);
8155 #endif
8156         else if (!strcmp(res->what, "dcb_tc"))
8157                 RTE_ETH_FOREACH_DEV(i)
8158                         port_dcb_info_display(i);
8159 }
8160
8161 static cmdline_parse_token_string_t cmd_showportall_show =
8162         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8163                                  "show#clear");
8164 static cmdline_parse_token_string_t cmd_showportall_port =
8165         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8166 static cmdline_parse_token_string_t cmd_showportall_what =
8167         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8168                                  "info#summary#stats#xstats#fdir#dcb_tc");
8169 static cmdline_parse_token_string_t cmd_showportall_all =
8170         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8171 static cmdline_parse_inst_t cmd_showportall = {
8172         .f = cmd_showportall_parsed,
8173         .data = NULL,
8174         .help_str = "show|clear port "
8175                 "info|summary|stats|xstats|fdir|dcb_tc all",
8176         .tokens = {
8177                 (void *)&cmd_showportall_show,
8178                 (void *)&cmd_showportall_port,
8179                 (void *)&cmd_showportall_what,
8180                 (void *)&cmd_showportall_all,
8181                 NULL,
8182         },
8183 };
8184
8185 /* *** SHOW PORT INFO *** */
8186 struct cmd_showport_result {
8187         cmdline_fixed_string_t show;
8188         cmdline_fixed_string_t port;
8189         cmdline_fixed_string_t what;
8190         uint16_t portnum;
8191 };
8192
8193 static void cmd_showport_parsed(void *parsed_result,
8194                                 __rte_unused struct cmdline *cl,
8195                                 __rte_unused void *data)
8196 {
8197         struct cmd_showport_result *res = parsed_result;
8198         if (!strcmp(res->show, "clear")) {
8199                 if (!strcmp(res->what, "stats"))
8200                         nic_stats_clear(res->portnum);
8201                 else if (!strcmp(res->what, "xstats"))
8202                         nic_xstats_clear(res->portnum);
8203         } else if (!strcmp(res->what, "info"))
8204                 port_infos_display(res->portnum);
8205         else if (!strcmp(res->what, "summary")) {
8206                 port_summary_header_display();
8207                 port_summary_display(res->portnum);
8208         }
8209         else if (!strcmp(res->what, "stats"))
8210                 nic_stats_display(res->portnum);
8211         else if (!strcmp(res->what, "xstats"))
8212                 nic_xstats_display(res->portnum);
8213 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8214         else if (!strcmp(res->what, "fdir"))
8215                  fdir_get_infos(res->portnum);
8216 #endif
8217         else if (!strcmp(res->what, "dcb_tc"))
8218                 port_dcb_info_display(res->portnum);
8219 }
8220
8221 static cmdline_parse_token_string_t cmd_showport_show =
8222         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8223                                  "show#clear");
8224 static cmdline_parse_token_string_t cmd_showport_port =
8225         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8226 static cmdline_parse_token_string_t cmd_showport_what =
8227         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8228                                  "info#summary#stats#xstats#fdir#dcb_tc");
8229 static cmdline_parse_token_num_t cmd_showport_portnum =
8230         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8231
8232 static cmdline_parse_inst_t cmd_showport = {
8233         .f = cmd_showport_parsed,
8234         .data = NULL,
8235         .help_str = "show|clear port "
8236                 "info|summary|stats|xstats|fdir|dcb_tc "
8237                 "<port_id>",
8238         .tokens = {
8239                 (void *)&cmd_showport_show,
8240                 (void *)&cmd_showport_port,
8241                 (void *)&cmd_showport_what,
8242                 (void *)&cmd_showport_portnum,
8243                 NULL,
8244         },
8245 };
8246
8247 /* *** show port representors information *** */
8248 struct cmd_representor_info_result {
8249         cmdline_fixed_string_t cmd_show;
8250         cmdline_fixed_string_t cmd_port;
8251         cmdline_fixed_string_t cmd_info;
8252         cmdline_fixed_string_t cmd_keyword;
8253         portid_t cmd_pid;
8254 };
8255
8256 static void
8257 cmd_representor_info_parsed(void *parsed_result,
8258                 __rte_unused struct cmdline *cl,
8259                 __rte_unused void *data)
8260 {
8261         struct cmd_representor_info_result *res = parsed_result;
8262         struct rte_eth_representor_info *info;
8263         struct rte_eth_representor_range *range;
8264         uint32_t range_diff;
8265         uint32_t i;
8266         int ret;
8267         int num;
8268
8269         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8270                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8271                 return;
8272         }
8273
8274         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8275         if (ret < 0) {
8276                 fprintf(stderr,
8277                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8278                         res->cmd_pid, rte_strerror(-ret));
8279                 return;
8280         }
8281         num = ret;
8282
8283         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8284         if (info == NULL) {
8285                 fprintf(stderr,
8286                         "Failed to allocate memory for representor info for port %hu\n",
8287                         res->cmd_pid);
8288                 return;
8289         }
8290         info->nb_ranges_alloc = num;
8291
8292         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8293         if (ret < 0) {
8294                 fprintf(stderr,
8295                         "Failed to get the representor info for port %hu: %s\n",
8296                         res->cmd_pid, rte_strerror(-ret));
8297                 free(info);
8298                 return;
8299         }
8300
8301         printf("Port controller: %hu\n", info->controller);
8302         printf("Port PF: %hu\n", info->pf);
8303
8304         printf("Ranges: %u\n", info->nb_ranges);
8305         for (i = 0; i < info->nb_ranges; i++) {
8306                 range = &info->ranges[i];
8307                 range_diff = range->id_end - range->id_base;
8308
8309                 printf("%u. ", i + 1);
8310                 printf("'%s' ", range->name);
8311                 if (range_diff > 0)
8312                         printf("[%u-%u]: ", range->id_base, range->id_end);
8313                 else
8314                         printf("[%u]: ", range->id_base);
8315
8316                 printf("Controller %d, PF %d", range->controller, range->pf);
8317
8318                 switch (range->type) {
8319                 case RTE_ETH_REPRESENTOR_NONE:
8320                         printf(", NONE\n");
8321                         break;
8322                 case RTE_ETH_REPRESENTOR_VF:
8323                         if (range_diff > 0)
8324                                 printf(", VF %d..%d\n", range->vf,
8325                                        range->vf + range_diff);
8326                         else
8327                                 printf(", VF %d\n", range->vf);
8328                         break;
8329                 case RTE_ETH_REPRESENTOR_SF:
8330                         printf(", SF %d\n", range->sf);
8331                         break;
8332                 case RTE_ETH_REPRESENTOR_PF:
8333                         if (range_diff > 0)
8334                                 printf("..%d\n", range->pf + range_diff);
8335                         else
8336                                 printf("\n");
8337                         break;
8338                 default:
8339                         printf(", UNKNOWN TYPE %d\n", range->type);
8340                         break;
8341                 }
8342         }
8343
8344         free(info);
8345 }
8346
8347 static cmdline_parse_token_string_t cmd_representor_info_show =
8348         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8349                         cmd_show, "show");
8350 static cmdline_parse_token_string_t cmd_representor_info_port =
8351         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8352                         cmd_port, "port");
8353 static cmdline_parse_token_string_t cmd_representor_info_info =
8354         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8355                         cmd_info, "info");
8356 static cmdline_parse_token_num_t cmd_representor_info_pid =
8357         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8358                         cmd_pid, RTE_UINT16);
8359 static cmdline_parse_token_string_t cmd_representor_info_keyword =
8360         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8361                         cmd_keyword, "representor");
8362
8363 static cmdline_parse_inst_t cmd_representor_info = {
8364         .f = cmd_representor_info_parsed,
8365         .data = NULL,
8366         .help_str = "show port info <port_id> representor",
8367         .tokens = {
8368                 (void *)&cmd_representor_info_show,
8369                 (void *)&cmd_representor_info_port,
8370                 (void *)&cmd_representor_info_info,
8371                 (void *)&cmd_representor_info_pid,
8372                 (void *)&cmd_representor_info_keyword,
8373                 NULL,
8374         },
8375 };
8376
8377
8378 /* *** SHOW DEVICE INFO *** */
8379 struct cmd_showdevice_result {
8380         cmdline_fixed_string_t show;
8381         cmdline_fixed_string_t device;
8382         cmdline_fixed_string_t what;
8383         cmdline_fixed_string_t identifier;
8384 };
8385
8386 static void cmd_showdevice_parsed(void *parsed_result,
8387                                 __rte_unused struct cmdline *cl,
8388                                 __rte_unused void *data)
8389 {
8390         struct cmd_showdevice_result *res = parsed_result;
8391         if (!strcmp(res->what, "info")) {
8392                 if (!strcmp(res->identifier, "all"))
8393                         device_infos_display(NULL);
8394                 else
8395                         device_infos_display(res->identifier);
8396         }
8397 }
8398
8399 static cmdline_parse_token_string_t cmd_showdevice_show =
8400         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8401                                  "show");
8402 static cmdline_parse_token_string_t cmd_showdevice_device =
8403         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8404 static cmdline_parse_token_string_t cmd_showdevice_what =
8405         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8406                                  "info");
8407 static cmdline_parse_token_string_t cmd_showdevice_identifier =
8408         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8409                         identifier, NULL);
8410
8411 static cmdline_parse_inst_t cmd_showdevice = {
8412         .f = cmd_showdevice_parsed,
8413         .data = NULL,
8414         .help_str = "show device info <identifier>|all",
8415         .tokens = {
8416                 (void *)&cmd_showdevice_show,
8417                 (void *)&cmd_showdevice_device,
8418                 (void *)&cmd_showdevice_what,
8419                 (void *)&cmd_showdevice_identifier,
8420                 NULL,
8421         },
8422 };
8423
8424 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8425 struct cmd_showeeprom_result {
8426         cmdline_fixed_string_t show;
8427         cmdline_fixed_string_t port;
8428         uint16_t portnum;
8429         cmdline_fixed_string_t type;
8430 };
8431
8432 static void cmd_showeeprom_parsed(void *parsed_result,
8433                 __rte_unused struct cmdline *cl,
8434                 __rte_unused void *data)
8435 {
8436         struct cmd_showeeprom_result *res = parsed_result;
8437
8438         if (!strcmp(res->type, "eeprom"))
8439                 port_eeprom_display(res->portnum);
8440         else if (!strcmp(res->type, "module_eeprom"))
8441                 port_module_eeprom_display(res->portnum);
8442         else
8443                 fprintf(stderr, "Unknown argument\n");
8444 }
8445
8446 static cmdline_parse_token_string_t cmd_showeeprom_show =
8447         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8448 static cmdline_parse_token_string_t cmd_showeeprom_port =
8449         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8450 static cmdline_parse_token_num_t cmd_showeeprom_portnum =
8451         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8452                         RTE_UINT16);
8453 static cmdline_parse_token_string_t cmd_showeeprom_type =
8454         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8455
8456 static cmdline_parse_inst_t cmd_showeeprom = {
8457         .f = cmd_showeeprom_parsed,
8458         .data = NULL,
8459         .help_str = "show port <port_id> module_eeprom|eeprom",
8460         .tokens = {
8461                 (void *)&cmd_showeeprom_show,
8462                 (void *)&cmd_showeeprom_port,
8463                 (void *)&cmd_showeeprom_portnum,
8464                 (void *)&cmd_showeeprom_type,
8465                 NULL,
8466         },
8467 };
8468
8469 /* *** SHOW QUEUE INFO *** */
8470 struct cmd_showqueue_result {
8471         cmdline_fixed_string_t show;
8472         cmdline_fixed_string_t type;
8473         cmdline_fixed_string_t what;
8474         uint16_t portnum;
8475         uint16_t queuenum;
8476 };
8477
8478 static void
8479 cmd_showqueue_parsed(void *parsed_result,
8480         __rte_unused struct cmdline *cl,
8481         __rte_unused void *data)
8482 {
8483         struct cmd_showqueue_result *res = parsed_result;
8484
8485         if (!strcmp(res->type, "rxq"))
8486                 rx_queue_infos_display(res->portnum, res->queuenum);
8487         else if (!strcmp(res->type, "txq"))
8488                 tx_queue_infos_display(res->portnum, res->queuenum);
8489 }
8490
8491 static cmdline_parse_token_string_t cmd_showqueue_show =
8492         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8493 static cmdline_parse_token_string_t cmd_showqueue_type =
8494         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8495 static cmdline_parse_token_string_t cmd_showqueue_what =
8496         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8497 static cmdline_parse_token_num_t cmd_showqueue_portnum =
8498         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8499                 RTE_UINT16);
8500 static cmdline_parse_token_num_t cmd_showqueue_queuenum =
8501         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8502                 RTE_UINT16);
8503
8504 static cmdline_parse_inst_t cmd_showqueue = {
8505         .f = cmd_showqueue_parsed,
8506         .data = NULL,
8507         .help_str = "show rxq|txq info <port_id> <queue_id>",
8508         .tokens = {
8509                 (void *)&cmd_showqueue_show,
8510                 (void *)&cmd_showqueue_type,
8511                 (void *)&cmd_showqueue_what,
8512                 (void *)&cmd_showqueue_portnum,
8513                 (void *)&cmd_showqueue_queuenum,
8514                 NULL,
8515         },
8516 };
8517
8518 /* show/clear fwd engine statistics */
8519 struct fwd_result {
8520         cmdline_fixed_string_t action;
8521         cmdline_fixed_string_t fwd;
8522         cmdline_fixed_string_t stats;
8523         cmdline_fixed_string_t all;
8524 };
8525
8526 static cmdline_parse_token_string_t cmd_fwd_action =
8527         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8528 static cmdline_parse_token_string_t cmd_fwd_fwd =
8529         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8530 static cmdline_parse_token_string_t cmd_fwd_stats =
8531         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8532 static cmdline_parse_token_string_t cmd_fwd_all =
8533         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8534
8535 static void
8536 cmd_showfwdall_parsed(void *parsed_result,
8537                       __rte_unused struct cmdline *cl,
8538                       __rte_unused void *data)
8539 {
8540         struct fwd_result *res = parsed_result;
8541
8542         if (!strcmp(res->action, "show"))
8543                 fwd_stats_display();
8544         else
8545                 fwd_stats_reset();
8546 }
8547
8548 static cmdline_parse_inst_t cmd_showfwdall = {
8549         .f = cmd_showfwdall_parsed,
8550         .data = NULL,
8551         .help_str = "show|clear fwd stats all",
8552         .tokens = {
8553                 (void *)&cmd_fwd_action,
8554                 (void *)&cmd_fwd_fwd,
8555                 (void *)&cmd_fwd_stats,
8556                 (void *)&cmd_fwd_all,
8557                 NULL,
8558         },
8559 };
8560
8561 /* *** READ PORT REGISTER *** */
8562 struct cmd_read_reg_result {
8563         cmdline_fixed_string_t read;
8564         cmdline_fixed_string_t reg;
8565         portid_t port_id;
8566         uint32_t reg_off;
8567 };
8568
8569 static void
8570 cmd_read_reg_parsed(void *parsed_result,
8571                     __rte_unused struct cmdline *cl,
8572                     __rte_unused void *data)
8573 {
8574         struct cmd_read_reg_result *res = parsed_result;
8575         port_reg_display(res->port_id, res->reg_off);
8576 }
8577
8578 static cmdline_parse_token_string_t cmd_read_reg_read =
8579         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8580 static cmdline_parse_token_string_t cmd_read_reg_reg =
8581         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8582 static cmdline_parse_token_num_t cmd_read_reg_port_id =
8583         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8584 static cmdline_parse_token_num_t cmd_read_reg_reg_off =
8585         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8586
8587 static cmdline_parse_inst_t cmd_read_reg = {
8588         .f = cmd_read_reg_parsed,
8589         .data = NULL,
8590         .help_str = "read reg <port_id> <reg_off>",
8591         .tokens = {
8592                 (void *)&cmd_read_reg_read,
8593                 (void *)&cmd_read_reg_reg,
8594                 (void *)&cmd_read_reg_port_id,
8595                 (void *)&cmd_read_reg_reg_off,
8596                 NULL,
8597         },
8598 };
8599
8600 /* *** READ PORT REGISTER BIT FIELD *** */
8601 struct cmd_read_reg_bit_field_result {
8602         cmdline_fixed_string_t read;
8603         cmdline_fixed_string_t regfield;
8604         portid_t port_id;
8605         uint32_t reg_off;
8606         uint8_t bit1_pos;
8607         uint8_t bit2_pos;
8608 };
8609
8610 static void
8611 cmd_read_reg_bit_field_parsed(void *parsed_result,
8612                               __rte_unused struct cmdline *cl,
8613                               __rte_unused void *data)
8614 {
8615         struct cmd_read_reg_bit_field_result *res = parsed_result;
8616         port_reg_bit_field_display(res->port_id, res->reg_off,
8617                                    res->bit1_pos, res->bit2_pos);
8618 }
8619
8620 static cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8621         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8622                                  "read");
8623 static cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8624         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8625                                  regfield, "regfield");
8626 static cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8627         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8628                               RTE_UINT16);
8629 static cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8630         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8631                               RTE_UINT32);
8632 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8633         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8634                               RTE_UINT8);
8635 static cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8636         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8637                               RTE_UINT8);
8638
8639 static cmdline_parse_inst_t cmd_read_reg_bit_field = {
8640         .f = cmd_read_reg_bit_field_parsed,
8641         .data = NULL,
8642         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8643         "Read register bit field between bit_x and bit_y included",
8644         .tokens = {
8645                 (void *)&cmd_read_reg_bit_field_read,
8646                 (void *)&cmd_read_reg_bit_field_regfield,
8647                 (void *)&cmd_read_reg_bit_field_port_id,
8648                 (void *)&cmd_read_reg_bit_field_reg_off,
8649                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8650                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8651                 NULL,
8652         },
8653 };
8654
8655 /* *** READ PORT REGISTER BIT *** */
8656 struct cmd_read_reg_bit_result {
8657         cmdline_fixed_string_t read;
8658         cmdline_fixed_string_t regbit;
8659         portid_t port_id;
8660         uint32_t reg_off;
8661         uint8_t bit_pos;
8662 };
8663
8664 static void
8665 cmd_read_reg_bit_parsed(void *parsed_result,
8666                         __rte_unused struct cmdline *cl,
8667                         __rte_unused void *data)
8668 {
8669         struct cmd_read_reg_bit_result *res = parsed_result;
8670         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8671 }
8672
8673 static cmdline_parse_token_string_t cmd_read_reg_bit_read =
8674         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8675 static cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8676         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8677                                  regbit, "regbit");
8678 static cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8679         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8680                                  RTE_UINT16);
8681 static cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8682         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8683                                  RTE_UINT32);
8684 static cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8685         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8686                                  RTE_UINT8);
8687
8688 static cmdline_parse_inst_t cmd_read_reg_bit = {
8689         .f = cmd_read_reg_bit_parsed,
8690         .data = NULL,
8691         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8692         .tokens = {
8693                 (void *)&cmd_read_reg_bit_read,
8694                 (void *)&cmd_read_reg_bit_regbit,
8695                 (void *)&cmd_read_reg_bit_port_id,
8696                 (void *)&cmd_read_reg_bit_reg_off,
8697                 (void *)&cmd_read_reg_bit_bit_pos,
8698                 NULL,
8699         },
8700 };
8701
8702 /* *** WRITE PORT REGISTER *** */
8703 struct cmd_write_reg_result {
8704         cmdline_fixed_string_t write;
8705         cmdline_fixed_string_t reg;
8706         portid_t port_id;
8707         uint32_t reg_off;
8708         uint32_t value;
8709 };
8710
8711 static void
8712 cmd_write_reg_parsed(void *parsed_result,
8713                      __rte_unused struct cmdline *cl,
8714                      __rte_unused void *data)
8715 {
8716         struct cmd_write_reg_result *res = parsed_result;
8717         port_reg_set(res->port_id, res->reg_off, res->value);
8718 }
8719
8720 static cmdline_parse_token_string_t cmd_write_reg_write =
8721         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8722 static cmdline_parse_token_string_t cmd_write_reg_reg =
8723         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8724 static cmdline_parse_token_num_t cmd_write_reg_port_id =
8725         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8726 static cmdline_parse_token_num_t cmd_write_reg_reg_off =
8727         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8728 static cmdline_parse_token_num_t cmd_write_reg_value =
8729         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8730
8731 static cmdline_parse_inst_t cmd_write_reg = {
8732         .f = cmd_write_reg_parsed,
8733         .data = NULL,
8734         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8735         .tokens = {
8736                 (void *)&cmd_write_reg_write,
8737                 (void *)&cmd_write_reg_reg,
8738                 (void *)&cmd_write_reg_port_id,
8739                 (void *)&cmd_write_reg_reg_off,
8740                 (void *)&cmd_write_reg_value,
8741                 NULL,
8742         },
8743 };
8744
8745 /* *** WRITE PORT REGISTER BIT FIELD *** */
8746 struct cmd_write_reg_bit_field_result {
8747         cmdline_fixed_string_t write;
8748         cmdline_fixed_string_t regfield;
8749         portid_t port_id;
8750         uint32_t reg_off;
8751         uint8_t bit1_pos;
8752         uint8_t bit2_pos;
8753         uint32_t value;
8754 };
8755
8756 static void
8757 cmd_write_reg_bit_field_parsed(void *parsed_result,
8758                                __rte_unused struct cmdline *cl,
8759                                __rte_unused void *data)
8760 {
8761         struct cmd_write_reg_bit_field_result *res = parsed_result;
8762         port_reg_bit_field_set(res->port_id, res->reg_off,
8763                           res->bit1_pos, res->bit2_pos, res->value);
8764 }
8765
8766 static cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8767         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8768                                  "write");
8769 static cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8770         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8771                                  regfield, "regfield");
8772 static cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8773         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8774                               RTE_UINT16);
8775 static cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8776         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8777                               RTE_UINT32);
8778 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8779         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8780                               RTE_UINT8);
8781 static cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8782         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8783                               RTE_UINT8);
8784 static cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8785         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8786                               RTE_UINT32);
8787
8788 static cmdline_parse_inst_t cmd_write_reg_bit_field = {
8789         .f = cmd_write_reg_bit_field_parsed,
8790         .data = NULL,
8791         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8792                 "<reg_value>: "
8793                 "Set register bit field between bit_x and bit_y included",
8794         .tokens = {
8795                 (void *)&cmd_write_reg_bit_field_write,
8796                 (void *)&cmd_write_reg_bit_field_regfield,
8797                 (void *)&cmd_write_reg_bit_field_port_id,
8798                 (void *)&cmd_write_reg_bit_field_reg_off,
8799                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8800                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8801                 (void *)&cmd_write_reg_bit_field_value,
8802                 NULL,
8803         },
8804 };
8805
8806 /* *** WRITE PORT REGISTER BIT *** */
8807 struct cmd_write_reg_bit_result {
8808         cmdline_fixed_string_t write;
8809         cmdline_fixed_string_t regbit;
8810         portid_t port_id;
8811         uint32_t reg_off;
8812         uint8_t bit_pos;
8813         uint8_t value;
8814 };
8815
8816 static void
8817 cmd_write_reg_bit_parsed(void *parsed_result,
8818                          __rte_unused struct cmdline *cl,
8819                          __rte_unused void *data)
8820 {
8821         struct cmd_write_reg_bit_result *res = parsed_result;
8822         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8823 }
8824
8825 static cmdline_parse_token_string_t cmd_write_reg_bit_write =
8826         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8827                                  "write");
8828 static cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8829         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8830                                  regbit, "regbit");
8831 static cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8832         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8833                                  RTE_UINT16);
8834 static cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8835         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8836                                  RTE_UINT32);
8837 static cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8838         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8839                                  RTE_UINT8);
8840 static cmdline_parse_token_num_t cmd_write_reg_bit_value =
8841         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8842                                  RTE_UINT8);
8843
8844 static cmdline_parse_inst_t cmd_write_reg_bit = {
8845         .f = cmd_write_reg_bit_parsed,
8846         .data = NULL,
8847         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8848                 "0 <= bit_x <= 31",
8849         .tokens = {
8850                 (void *)&cmd_write_reg_bit_write,
8851                 (void *)&cmd_write_reg_bit_regbit,
8852                 (void *)&cmd_write_reg_bit_port_id,
8853                 (void *)&cmd_write_reg_bit_reg_off,
8854                 (void *)&cmd_write_reg_bit_bit_pos,
8855                 (void *)&cmd_write_reg_bit_value,
8856                 NULL,
8857         },
8858 };
8859
8860 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8861 struct cmd_read_rxd_txd_result {
8862         cmdline_fixed_string_t read;
8863         cmdline_fixed_string_t rxd_txd;
8864         portid_t port_id;
8865         uint16_t queue_id;
8866         uint16_t desc_id;
8867 };
8868
8869 static void
8870 cmd_read_rxd_txd_parsed(void *parsed_result,
8871                         __rte_unused struct cmdline *cl,
8872                         __rte_unused void *data)
8873 {
8874         struct cmd_read_rxd_txd_result *res = parsed_result;
8875
8876         if (!strcmp(res->rxd_txd, "rxd"))
8877                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8878         else if (!strcmp(res->rxd_txd, "txd"))
8879                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8880 }
8881
8882 static cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8883         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8884 static cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8885         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8886                                  "rxd#txd");
8887 static cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8888         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8889                                  RTE_UINT16);
8890 static cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8891         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8892                                  RTE_UINT16);
8893 static cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8894         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8895                                  RTE_UINT16);
8896
8897 static cmdline_parse_inst_t cmd_read_rxd_txd = {
8898         .f = cmd_read_rxd_txd_parsed,
8899         .data = NULL,
8900         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8901         .tokens = {
8902                 (void *)&cmd_read_rxd_txd_read,
8903                 (void *)&cmd_read_rxd_txd_rxd_txd,
8904                 (void *)&cmd_read_rxd_txd_port_id,
8905                 (void *)&cmd_read_rxd_txd_queue_id,
8906                 (void *)&cmd_read_rxd_txd_desc_id,
8907                 NULL,
8908         },
8909 };
8910
8911 /* *** QUIT *** */
8912 struct cmd_quit_result {
8913         cmdline_fixed_string_t quit;
8914 };
8915
8916 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8917                             struct cmdline *cl,
8918                             __rte_unused void *data)
8919 {
8920         cmdline_quit(cl);
8921 }
8922
8923 static cmdline_parse_token_string_t cmd_quit_quit =
8924         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8925
8926 static cmdline_parse_inst_t cmd_quit = {
8927         .f = cmd_quit_parsed,
8928         .data = NULL,
8929         .help_str = "quit: Exit application",
8930         .tokens = {
8931                 (void *)&cmd_quit_quit,
8932                 NULL,
8933         },
8934 };
8935
8936 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8937 struct cmd_mac_addr_result {
8938         cmdline_fixed_string_t mac_addr_cmd;
8939         cmdline_fixed_string_t what;
8940         uint16_t port_num;
8941         struct rte_ether_addr address;
8942 };
8943
8944 static void cmd_mac_addr_parsed(void *parsed_result,
8945                 __rte_unused struct cmdline *cl,
8946                 __rte_unused void *data)
8947 {
8948         struct cmd_mac_addr_result *res = parsed_result;
8949         int ret;
8950
8951         if (strcmp(res->what, "add") == 0)
8952                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8953         else if (strcmp(res->what, "set") == 0)
8954                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8955                                                        &res->address);
8956         else
8957                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8958
8959         /* check the return value and print it if is < 0 */
8960         if(ret < 0)
8961                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8962
8963 }
8964
8965 static cmdline_parse_token_string_t cmd_mac_addr_cmd =
8966         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8967                                 "mac_addr");
8968 static cmdline_parse_token_string_t cmd_mac_addr_what =
8969         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8970                                 "add#remove#set");
8971 static cmdline_parse_token_num_t cmd_mac_addr_portnum =
8972                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8973                                         RTE_UINT16);
8974 static cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8975                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8976
8977 static cmdline_parse_inst_t cmd_mac_addr = {
8978         .f = cmd_mac_addr_parsed,
8979         .data = (void *)0,
8980         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8981                         "Add/Remove/Set MAC address on port_id",
8982         .tokens = {
8983                 (void *)&cmd_mac_addr_cmd,
8984                 (void *)&cmd_mac_addr_what,
8985                 (void *)&cmd_mac_addr_portnum,
8986                 (void *)&cmd_mac_addr_addr,
8987                 NULL,
8988         },
8989 };
8990
8991 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8992 struct cmd_eth_peer_result {
8993         cmdline_fixed_string_t set;
8994         cmdline_fixed_string_t eth_peer;
8995         portid_t port_id;
8996         cmdline_fixed_string_t peer_addr;
8997 };
8998
8999 static void cmd_set_eth_peer_parsed(void *parsed_result,
9000                         __rte_unused struct cmdline *cl,
9001                         __rte_unused void *data)
9002 {
9003                 struct cmd_eth_peer_result *res = parsed_result;
9004
9005                 if (test_done == 0) {
9006                         fprintf(stderr, "Please stop forwarding first\n");
9007                         return;
9008                 }
9009                 if (!strcmp(res->eth_peer, "eth-peer")) {
9010                         set_fwd_eth_peer(res->port_id, res->peer_addr);
9011                         fwd_config_setup();
9012                 }
9013 }
9014 static cmdline_parse_token_string_t cmd_eth_peer_set =
9015         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
9016 static cmdline_parse_token_string_t cmd_eth_peer =
9017         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
9018 static cmdline_parse_token_num_t cmd_eth_peer_port_id =
9019         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
9020                 RTE_UINT16);
9021 static cmdline_parse_token_string_t cmd_eth_peer_addr =
9022         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
9023
9024 static cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
9025         .f = cmd_set_eth_peer_parsed,
9026         .data = NULL,
9027         .help_str = "set eth-peer <port_id> <peer_mac>",
9028         .tokens = {
9029                 (void *)&cmd_eth_peer_set,
9030                 (void *)&cmd_eth_peer,
9031                 (void *)&cmd_eth_peer_port_id,
9032                 (void *)&cmd_eth_peer_addr,
9033                 NULL,
9034         },
9035 };
9036
9037 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9038 struct cmd_set_qmap_result {
9039         cmdline_fixed_string_t set;
9040         cmdline_fixed_string_t qmap;
9041         cmdline_fixed_string_t what;
9042         portid_t port_id;
9043         uint16_t queue_id;
9044         uint8_t map_value;
9045 };
9046
9047 static void
9048 cmd_set_qmap_parsed(void *parsed_result,
9049                        __rte_unused struct cmdline *cl,
9050                        __rte_unused void *data)
9051 {
9052         struct cmd_set_qmap_result *res = parsed_result;
9053         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9054
9055         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9056 }
9057
9058 static cmdline_parse_token_string_t cmd_setqmap_set =
9059         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9060                                  set, "set");
9061 static cmdline_parse_token_string_t cmd_setqmap_qmap =
9062         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9063                                  qmap, "stat_qmap");
9064 static cmdline_parse_token_string_t cmd_setqmap_what =
9065         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9066                                  what, "tx#rx");
9067 static cmdline_parse_token_num_t cmd_setqmap_portid =
9068         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9069                               port_id, RTE_UINT16);
9070 static cmdline_parse_token_num_t cmd_setqmap_queueid =
9071         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9072                               queue_id, RTE_UINT16);
9073 static cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9074         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9075                               map_value, RTE_UINT8);
9076
9077 static cmdline_parse_inst_t cmd_set_qmap = {
9078         .f = cmd_set_qmap_parsed,
9079         .data = NULL,
9080         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9081                 "Set statistics mapping value on tx|rx queue_id of port_id",
9082         .tokens = {
9083                 (void *)&cmd_setqmap_set,
9084                 (void *)&cmd_setqmap_qmap,
9085                 (void *)&cmd_setqmap_what,
9086                 (void *)&cmd_setqmap_portid,
9087                 (void *)&cmd_setqmap_queueid,
9088                 (void *)&cmd_setqmap_mapvalue,
9089                 NULL,
9090         },
9091 };
9092
9093 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9094 struct cmd_set_xstats_hide_zero_result {
9095         cmdline_fixed_string_t keyword;
9096         cmdline_fixed_string_t name;
9097         cmdline_fixed_string_t on_off;
9098 };
9099
9100 static void
9101 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9102                         __rte_unused struct cmdline *cl,
9103                         __rte_unused void *data)
9104 {
9105         struct cmd_set_xstats_hide_zero_result *res;
9106         uint16_t on_off = 0;
9107
9108         res = parsed_result;
9109         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9110         set_xstats_hide_zero(on_off);
9111 }
9112
9113 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9114         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9115                                  keyword, "set");
9116 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9117         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9118                                  name, "xstats-hide-zero");
9119 static cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9120         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9121                                  on_off, "on#off");
9122
9123 static cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9124         .f = cmd_set_xstats_hide_zero_parsed,
9125         .data = NULL,
9126         .help_str = "set xstats-hide-zero on|off",
9127         .tokens = {
9128                 (void *)&cmd_set_xstats_hide_zero_keyword,
9129                 (void *)&cmd_set_xstats_hide_zero_name,
9130                 (void *)&cmd_set_xstats_hide_zero_on_off,
9131                 NULL,
9132         },
9133 };
9134
9135 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9136 struct cmd_set_record_core_cycles_result {
9137         cmdline_fixed_string_t keyword;
9138         cmdline_fixed_string_t name;
9139         cmdline_fixed_string_t on_off;
9140 };
9141
9142 static void
9143 cmd_set_record_core_cycles_parsed(void *parsed_result,
9144                         __rte_unused struct cmdline *cl,
9145                         __rte_unused void *data)
9146 {
9147         struct cmd_set_record_core_cycles_result *res;
9148         uint16_t on_off = 0;
9149
9150         res = parsed_result;
9151         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9152         set_record_core_cycles(on_off);
9153 }
9154
9155 static cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9156         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9157                                  keyword, "set");
9158 static cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9159         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9160                                  name, "record-core-cycles");
9161 static cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9162         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9163                                  on_off, "on#off");
9164
9165 static cmdline_parse_inst_t cmd_set_record_core_cycles = {
9166         .f = cmd_set_record_core_cycles_parsed,
9167         .data = NULL,
9168         .help_str = "set record-core-cycles on|off",
9169         .tokens = {
9170                 (void *)&cmd_set_record_core_cycles_keyword,
9171                 (void *)&cmd_set_record_core_cycles_name,
9172                 (void *)&cmd_set_record_core_cycles_on_off,
9173                 NULL,
9174         },
9175 };
9176
9177 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9178 struct cmd_set_record_burst_stats_result {
9179         cmdline_fixed_string_t keyword;
9180         cmdline_fixed_string_t name;
9181         cmdline_fixed_string_t on_off;
9182 };
9183
9184 static void
9185 cmd_set_record_burst_stats_parsed(void *parsed_result,
9186                         __rte_unused struct cmdline *cl,
9187                         __rte_unused void *data)
9188 {
9189         struct cmd_set_record_burst_stats_result *res;
9190         uint16_t on_off = 0;
9191
9192         res = parsed_result;
9193         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9194         set_record_burst_stats(on_off);
9195 }
9196
9197 static cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9198         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9199                                  keyword, "set");
9200 static cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9201         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9202                                  name, "record-burst-stats");
9203 static cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9204         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9205                                  on_off, "on#off");
9206
9207 static cmdline_parse_inst_t cmd_set_record_burst_stats = {
9208         .f = cmd_set_record_burst_stats_parsed,
9209         .data = NULL,
9210         .help_str = "set record-burst-stats on|off",
9211         .tokens = {
9212                 (void *)&cmd_set_record_burst_stats_keyword,
9213                 (void *)&cmd_set_record_burst_stats_name,
9214                 (void *)&cmd_set_record_burst_stats_on_off,
9215                 NULL,
9216         },
9217 };
9218
9219 /* *** CONFIGURE UNICAST HASH TABLE *** */
9220 struct cmd_set_uc_hash_table {
9221         cmdline_fixed_string_t set;
9222         cmdline_fixed_string_t port;
9223         portid_t port_id;
9224         cmdline_fixed_string_t what;
9225         struct rte_ether_addr address;
9226         cmdline_fixed_string_t mode;
9227 };
9228
9229 static void
9230 cmd_set_uc_hash_parsed(void *parsed_result,
9231                        __rte_unused struct cmdline *cl,
9232                        __rte_unused void *data)
9233 {
9234         int ret=0;
9235         struct cmd_set_uc_hash_table *res = parsed_result;
9236
9237         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9238
9239         if (strcmp(res->what, "uta") == 0)
9240                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9241                                                 &res->address,(uint8_t)is_on);
9242         if (ret < 0)
9243                 fprintf(stderr,
9244                         "bad unicast hash table parameter, return code = %d\n",
9245                         ret);
9246
9247 }
9248
9249 static cmdline_parse_token_string_t cmd_set_uc_hash_set =
9250         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9251                                  set, "set");
9252 static cmdline_parse_token_string_t cmd_set_uc_hash_port =
9253         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9254                                  port, "port");
9255 static cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9256         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9257                               port_id, RTE_UINT16);
9258 static cmdline_parse_token_string_t cmd_set_uc_hash_what =
9259         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9260                                  what, "uta");
9261 static cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9262         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9263                                 address);
9264 static cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9265         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9266                                  mode, "on#off");
9267
9268 static cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9269         .f = cmd_set_uc_hash_parsed,
9270         .data = NULL,
9271         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9272         .tokens = {
9273                 (void *)&cmd_set_uc_hash_set,
9274                 (void *)&cmd_set_uc_hash_port,
9275                 (void *)&cmd_set_uc_hash_portid,
9276                 (void *)&cmd_set_uc_hash_what,
9277                 (void *)&cmd_set_uc_hash_mac,
9278                 (void *)&cmd_set_uc_hash_mode,
9279                 NULL,
9280         },
9281 };
9282
9283 struct cmd_set_uc_all_hash_table {
9284         cmdline_fixed_string_t set;
9285         cmdline_fixed_string_t port;
9286         portid_t port_id;
9287         cmdline_fixed_string_t what;
9288         cmdline_fixed_string_t value;
9289         cmdline_fixed_string_t mode;
9290 };
9291
9292 static void
9293 cmd_set_uc_all_hash_parsed(void *parsed_result,
9294                        __rte_unused struct cmdline *cl,
9295                        __rte_unused void *data)
9296 {
9297         int ret=0;
9298         struct cmd_set_uc_all_hash_table *res = parsed_result;
9299
9300         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9301
9302         if ((strcmp(res->what, "uta") == 0) &&
9303                 (strcmp(res->value, "all") == 0))
9304                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9305         if (ret < 0)
9306                 fprintf(stderr,
9307                         "bad unicast hash table parameter, return code = %d\n",
9308                         ret);
9309 }
9310
9311 static cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9312         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9313                                  set, "set");
9314 static cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9315         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9316                                  port, "port");
9317 static cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9318         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9319                               port_id, RTE_UINT16);
9320 static cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9321         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9322                                  what, "uta");
9323 static cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9324         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9325                                 value,"all");
9326 static cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9327         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9328                                  mode, "on#off");
9329
9330 static cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9331         .f = cmd_set_uc_all_hash_parsed,
9332         .data = NULL,
9333         .help_str = "set port <port_id> uta all on|off",
9334         .tokens = {
9335                 (void *)&cmd_set_uc_all_hash_set,
9336                 (void *)&cmd_set_uc_all_hash_port,
9337                 (void *)&cmd_set_uc_all_hash_portid,
9338                 (void *)&cmd_set_uc_all_hash_what,
9339                 (void *)&cmd_set_uc_all_hash_value,
9340                 (void *)&cmd_set_uc_all_hash_mode,
9341                 NULL,
9342         },
9343 };
9344
9345 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9346 struct cmd_set_vf_traffic {
9347         cmdline_fixed_string_t set;
9348         cmdline_fixed_string_t port;
9349         portid_t port_id;
9350         cmdline_fixed_string_t vf;
9351         uint8_t vf_id;
9352         cmdline_fixed_string_t what;
9353         cmdline_fixed_string_t mode;
9354 };
9355
9356 static void
9357 cmd_set_vf_traffic_parsed(void *parsed_result,
9358                        __rte_unused struct cmdline *cl,
9359                        __rte_unused void *data)
9360 {
9361         struct cmd_set_vf_traffic *res = parsed_result;
9362         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9363         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9364
9365         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9366 }
9367
9368 static cmdline_parse_token_string_t cmd_setvf_traffic_set =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9370                                  set, "set");
9371 static cmdline_parse_token_string_t cmd_setvf_traffic_port =
9372         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9373                                  port, "port");
9374 static cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9375         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9376                               port_id, RTE_UINT16);
9377 static cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9378         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9379                                  vf, "vf");
9380 static cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9381         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9382                               vf_id, RTE_UINT8);
9383 static cmdline_parse_token_string_t cmd_setvf_traffic_what =
9384         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9385                                  what, "tx#rx");
9386 static cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9387         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9388                                  mode, "on#off");
9389
9390 static cmdline_parse_inst_t cmd_set_vf_traffic = {
9391         .f = cmd_set_vf_traffic_parsed,
9392         .data = NULL,
9393         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9394         .tokens = {
9395                 (void *)&cmd_setvf_traffic_set,
9396                 (void *)&cmd_setvf_traffic_port,
9397                 (void *)&cmd_setvf_traffic_portid,
9398                 (void *)&cmd_setvf_traffic_vf,
9399                 (void *)&cmd_setvf_traffic_vfid,
9400                 (void *)&cmd_setvf_traffic_what,
9401                 (void *)&cmd_setvf_traffic_mode,
9402                 NULL,
9403         },
9404 };
9405
9406 /* *** CONFIGURE VF RECEIVE MODE *** */
9407 struct cmd_set_vf_rxmode {
9408         cmdline_fixed_string_t set;
9409         cmdline_fixed_string_t port;
9410         portid_t port_id;
9411         cmdline_fixed_string_t vf;
9412         uint8_t vf_id;
9413         cmdline_fixed_string_t what;
9414         cmdline_fixed_string_t mode;
9415         cmdline_fixed_string_t on;
9416 };
9417
9418 static void
9419 cmd_set_vf_rxmode_parsed(void *parsed_result,
9420                        __rte_unused struct cmdline *cl,
9421                        __rte_unused void *data)
9422 {
9423         int ret = -ENOTSUP;
9424         uint16_t vf_rxmode = 0;
9425         struct cmd_set_vf_rxmode *res = parsed_result;
9426
9427         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9428         if (!strcmp(res->what,"rxmode")) {
9429                 if (!strcmp(res->mode, "AUPE"))
9430                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9431                 else if (!strcmp(res->mode, "ROPE"))
9432                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9433                 else if (!strcmp(res->mode, "BAM"))
9434                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9435                 else if (!strncmp(res->mode, "MPE",3))
9436                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9437         }
9438
9439         RTE_SET_USED(is_on);
9440         RTE_SET_USED(vf_rxmode);
9441
9442 #ifdef RTE_NET_IXGBE
9443         if (ret == -ENOTSUP)
9444                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9445                                                   vf_rxmode, (uint8_t)is_on);
9446 #endif
9447 #ifdef RTE_NET_BNXT
9448         if (ret == -ENOTSUP)
9449                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9450                                                  vf_rxmode, (uint8_t)is_on);
9451 #endif
9452         if (ret < 0)
9453                 fprintf(stderr,
9454                         "bad VF receive mode parameter, return code = %d\n",
9455                         ret);
9456 }
9457
9458 static cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9459         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9460                                  set, "set");
9461 static cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9462         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9463                                  port, "port");
9464 static cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9465         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9466                               port_id, RTE_UINT16);
9467 static cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9468         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9469                                  vf, "vf");
9470 static cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9471         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9472                               vf_id, RTE_UINT8);
9473 static cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9474         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9475                                  what, "rxmode");
9476 static cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9477         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9478                                  mode, "AUPE#ROPE#BAM#MPE");
9479 static cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9480         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9481                                  on, "on#off");
9482
9483 static cmdline_parse_inst_t cmd_set_vf_rxmode = {
9484         .f = cmd_set_vf_rxmode_parsed,
9485         .data = NULL,
9486         .help_str = "set port <port_id> vf <vf_id> rxmode "
9487                 "AUPE|ROPE|BAM|MPE on|off",
9488         .tokens = {
9489                 (void *)&cmd_set_vf_rxmode_set,
9490                 (void *)&cmd_set_vf_rxmode_port,
9491                 (void *)&cmd_set_vf_rxmode_portid,
9492                 (void *)&cmd_set_vf_rxmode_vf,
9493                 (void *)&cmd_set_vf_rxmode_vfid,
9494                 (void *)&cmd_set_vf_rxmode_what,
9495                 (void *)&cmd_set_vf_rxmode_mode,
9496                 (void *)&cmd_set_vf_rxmode_on,
9497                 NULL,
9498         },
9499 };
9500
9501 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9502 struct cmd_vf_mac_addr_result {
9503         cmdline_fixed_string_t mac_addr_cmd;
9504         cmdline_fixed_string_t what;
9505         cmdline_fixed_string_t port;
9506         uint16_t port_num;
9507         cmdline_fixed_string_t vf;
9508         uint8_t vf_num;
9509         struct rte_ether_addr address;
9510 };
9511
9512 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9513                 __rte_unused struct cmdline *cl,
9514                 __rte_unused void *data)
9515 {
9516         struct cmd_vf_mac_addr_result *res = parsed_result;
9517         int ret = -ENOTSUP;
9518
9519         if (strcmp(res->what, "add") != 0)
9520                 return;
9521
9522 #ifdef RTE_NET_I40E
9523         if (ret == -ENOTSUP)
9524                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9525                                                    &res->address);
9526 #endif
9527 #ifdef RTE_NET_BNXT
9528         if (ret == -ENOTSUP)
9529                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9530                                                 res->vf_num);
9531 #endif
9532
9533         if(ret < 0)
9534                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9535
9536 }
9537
9538 static cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9539         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9540                                 mac_addr_cmd,"mac_addr");
9541 static cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9542         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9543                                 what,"add");
9544 static cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9545         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9546                                 port,"port");
9547 static cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9548         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9549                                 port_num, RTE_UINT16);
9550 static cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9551         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9552                                 vf,"vf");
9553 static cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9554         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9555                                 vf_num, RTE_UINT8);
9556 static cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9557         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9558                                 address);
9559
9560 static cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9561         .f = cmd_vf_mac_addr_parsed,
9562         .data = (void *)0,
9563         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9564                 "Add MAC address filtering for a VF on port_id",
9565         .tokens = {
9566                 (void *)&cmd_vf_mac_addr_cmd,
9567                 (void *)&cmd_vf_mac_addr_what,
9568                 (void *)&cmd_vf_mac_addr_port,
9569                 (void *)&cmd_vf_mac_addr_portnum,
9570                 (void *)&cmd_vf_mac_addr_vf,
9571                 (void *)&cmd_vf_mac_addr_vfnum,
9572                 (void *)&cmd_vf_mac_addr_addr,
9573                 NULL,
9574         },
9575 };
9576
9577 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9578 struct cmd_vf_rx_vlan_filter {
9579         cmdline_fixed_string_t rx_vlan;
9580         cmdline_fixed_string_t what;
9581         uint16_t vlan_id;
9582         cmdline_fixed_string_t port;
9583         portid_t port_id;
9584         cmdline_fixed_string_t vf;
9585         uint64_t vf_mask;
9586 };
9587
9588 static void
9589 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9590                           __rte_unused struct cmdline *cl,
9591                           __rte_unused void *data)
9592 {
9593         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9594         int ret = -ENOTSUP;
9595
9596         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9597
9598 #ifdef RTE_NET_IXGBE
9599         if (ret == -ENOTSUP)
9600                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9601                                 res->vlan_id, res->vf_mask, is_add);
9602 #endif
9603 #ifdef RTE_NET_I40E
9604         if (ret == -ENOTSUP)
9605                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9606                                 res->vlan_id, res->vf_mask, is_add);
9607 #endif
9608 #ifdef RTE_NET_BNXT
9609         if (ret == -ENOTSUP)
9610                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9611                                 res->vlan_id, res->vf_mask, is_add);
9612 #endif
9613
9614         switch (ret) {
9615         case 0:
9616                 break;
9617         case -EINVAL:
9618                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9619                         res->vlan_id, res->vf_mask);
9620                 break;
9621         case -ENODEV:
9622                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9623                 break;
9624         case -ENOTSUP:
9625                 fprintf(stderr, "function not implemented or supported\n");
9626                 break;
9627         default:
9628                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9629         }
9630 }
9631
9632 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9633         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9634                                  rx_vlan, "rx_vlan");
9635 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9636         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9637                                  what, "add#rm");
9638 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9639         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9640                               vlan_id, RTE_UINT16);
9641 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9642         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9643                                  port, "port");
9644 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9645         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9646                               port_id, RTE_UINT16);
9647 static cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9648         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9649                                  vf, "vf");
9650 static cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9651         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9652                               vf_mask, RTE_UINT64);
9653
9654 static cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9655         .f = cmd_vf_rx_vlan_filter_parsed,
9656         .data = NULL,
9657         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9658                 "(vf_mask = hexadecimal VF mask)",
9659         .tokens = {
9660                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9661                 (void *)&cmd_vf_rx_vlan_filter_what,
9662                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9663                 (void *)&cmd_vf_rx_vlan_filter_port,
9664                 (void *)&cmd_vf_rx_vlan_filter_portid,
9665                 (void *)&cmd_vf_rx_vlan_filter_vf,
9666                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9667                 NULL,
9668         },
9669 };
9670
9671 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9672 struct cmd_queue_rate_limit_result {
9673         cmdline_fixed_string_t set;
9674         cmdline_fixed_string_t port;
9675         uint16_t port_num;
9676         cmdline_fixed_string_t queue;
9677         uint8_t queue_num;
9678         cmdline_fixed_string_t rate;
9679         uint16_t rate_num;
9680 };
9681
9682 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9683                 __rte_unused struct cmdline *cl,
9684                 __rte_unused void *data)
9685 {
9686         struct cmd_queue_rate_limit_result *res = parsed_result;
9687         int ret = 0;
9688
9689         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9690                 && (strcmp(res->queue, "queue") == 0)
9691                 && (strcmp(res->rate, "rate") == 0))
9692                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9693                                         res->rate_num);
9694         if (ret < 0)
9695                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9696                         strerror(-ret));
9697
9698 }
9699
9700 static cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9701         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9702                                 set, "set");
9703 static cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9704         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9705                                 port, "port");
9706 static cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9707         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9708                                 port_num, RTE_UINT16);
9709 static cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9710         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9711                                 queue, "queue");
9712 static cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9713         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9714                                 queue_num, RTE_UINT8);
9715 static cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9716         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9717                                 rate, "rate");
9718 static cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9719         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9720                                 rate_num, RTE_UINT16);
9721
9722 static cmdline_parse_inst_t cmd_queue_rate_limit = {
9723         .f = cmd_queue_rate_limit_parsed,
9724         .data = (void *)0,
9725         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9726                 "Set rate limit for a queue on port_id",
9727         .tokens = {
9728                 (void *)&cmd_queue_rate_limit_set,
9729                 (void *)&cmd_queue_rate_limit_port,
9730                 (void *)&cmd_queue_rate_limit_portnum,
9731                 (void *)&cmd_queue_rate_limit_queue,
9732                 (void *)&cmd_queue_rate_limit_queuenum,
9733                 (void *)&cmd_queue_rate_limit_rate,
9734                 (void *)&cmd_queue_rate_limit_ratenum,
9735                 NULL,
9736         },
9737 };
9738
9739 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9740 struct cmd_vf_rate_limit_result {
9741         cmdline_fixed_string_t set;
9742         cmdline_fixed_string_t port;
9743         uint16_t port_num;
9744         cmdline_fixed_string_t vf;
9745         uint8_t vf_num;
9746         cmdline_fixed_string_t rate;
9747         uint16_t rate_num;
9748         cmdline_fixed_string_t q_msk;
9749         uint64_t q_msk_val;
9750 };
9751
9752 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9753                 __rte_unused struct cmdline *cl,
9754                 __rte_unused void *data)
9755 {
9756         struct cmd_vf_rate_limit_result *res = parsed_result;
9757         int ret = 0;
9758
9759         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9760                 && (strcmp(res->vf, "vf") == 0)
9761                 && (strcmp(res->rate, "rate") == 0)
9762                 && (strcmp(res->q_msk, "queue_mask") == 0))
9763                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9764                                         res->rate_num, res->q_msk_val);
9765         if (ret < 0)
9766                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9767                         strerror(-ret));
9768
9769 }
9770
9771 static cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9772         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9773                                 set, "set");
9774 static cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9775         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9776                                 port, "port");
9777 static cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9778         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9779                                 port_num, RTE_UINT16);
9780 static cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9781         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9782                                 vf, "vf");
9783 static cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9784         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9785                                 vf_num, RTE_UINT8);
9786 static cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9787         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9788                                 rate, "rate");
9789 static cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9790         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9791                                 rate_num, RTE_UINT16);
9792 static cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9793         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9794                                 q_msk, "queue_mask");
9795 static cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9796         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9797                                 q_msk_val, RTE_UINT64);
9798
9799 static cmdline_parse_inst_t cmd_vf_rate_limit = {
9800         .f = cmd_vf_rate_limit_parsed,
9801         .data = (void *)0,
9802         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9803                 "queue_mask <queue_mask_value>: "
9804                 "Set rate limit for queues of VF on port_id",
9805         .tokens = {
9806                 (void *)&cmd_vf_rate_limit_set,
9807                 (void *)&cmd_vf_rate_limit_port,
9808                 (void *)&cmd_vf_rate_limit_portnum,
9809                 (void *)&cmd_vf_rate_limit_vf,
9810                 (void *)&cmd_vf_rate_limit_vfnum,
9811                 (void *)&cmd_vf_rate_limit_rate,
9812                 (void *)&cmd_vf_rate_limit_ratenum,
9813                 (void *)&cmd_vf_rate_limit_q_msk,
9814                 (void *)&cmd_vf_rate_limit_q_msk_val,
9815                 NULL,
9816         },
9817 };
9818
9819 /* *** CONFIGURE TUNNEL UDP PORT *** */
9820 struct cmd_tunnel_udp_config {
9821         cmdline_fixed_string_t rx_vxlan_port;
9822         cmdline_fixed_string_t what;
9823         uint16_t udp_port;
9824         portid_t port_id;
9825 };
9826
9827 static void
9828 cmd_tunnel_udp_config_parsed(void *parsed_result,
9829                           __rte_unused struct cmdline *cl,
9830                           __rte_unused void *data)
9831 {
9832         struct cmd_tunnel_udp_config *res = parsed_result;
9833         struct rte_eth_udp_tunnel tunnel_udp;
9834         int ret;
9835
9836         tunnel_udp.udp_port = res->udp_port;
9837         tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9838
9839         if (!strcmp(res->what, "add"))
9840                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9841                                                       &tunnel_udp);
9842         else
9843                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9844                                                          &tunnel_udp);
9845
9846         if (ret < 0)
9847                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9848                         strerror(-ret));
9849 }
9850
9851 static cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9852         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9853                                 rx_vxlan_port, "rx_vxlan_port");
9854 static cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9855         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9856                                 what, "add#rm");
9857 static cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9858         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9859                                 udp_port, RTE_UINT16);
9860 static cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9861         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9862                                 port_id, RTE_UINT16);
9863
9864 static cmdline_parse_inst_t cmd_tunnel_udp_config = {
9865         .f = cmd_tunnel_udp_config_parsed,
9866         .data = (void *)0,
9867         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9868                 "Add/Remove a tunneling UDP port filter",
9869         .tokens = {
9870                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9871                 (void *)&cmd_tunnel_udp_config_what,
9872                 (void *)&cmd_tunnel_udp_config_udp_port,
9873                 (void *)&cmd_tunnel_udp_config_port_id,
9874                 NULL,
9875         },
9876 };
9877
9878 struct cmd_config_tunnel_udp_port {
9879         cmdline_fixed_string_t port;
9880         cmdline_fixed_string_t config;
9881         portid_t port_id;
9882         cmdline_fixed_string_t udp_tunnel_port;
9883         cmdline_fixed_string_t action;
9884         cmdline_fixed_string_t tunnel_type;
9885         uint16_t udp_port;
9886 };
9887
9888 static void
9889 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9890                                __rte_unused struct cmdline *cl,
9891                                __rte_unused void *data)
9892 {
9893         struct cmd_config_tunnel_udp_port *res = parsed_result;
9894         struct rte_eth_udp_tunnel tunnel_udp;
9895         int ret = 0;
9896
9897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9898                 return;
9899
9900         tunnel_udp.udp_port = res->udp_port;
9901
9902         if (!strcmp(res->tunnel_type, "vxlan")) {
9903                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9904         } else if (!strcmp(res->tunnel_type, "geneve")) {
9905                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9906         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9907                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9908         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9909                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9910         } else {
9911                 fprintf(stderr, "Invalid tunnel type\n");
9912                 return;
9913         }
9914
9915         if (!strcmp(res->action, "add"))
9916                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9917                                                       &tunnel_udp);
9918         else
9919                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9920                                                          &tunnel_udp);
9921
9922         if (ret < 0)
9923                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9924                         strerror(-ret));
9925 }
9926
9927 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9928         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9929                                  "port");
9930 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9931         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9932                                  "config");
9933 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9934         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9935                               RTE_UINT16);
9936 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9937         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9938                                  udp_tunnel_port,
9939                                  "udp_tunnel_port");
9940 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9941         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9942                                  "add#rm");
9943 static cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9944         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9945                                  "vxlan#geneve#vxlan-gpe#ecpri");
9946 static cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9947         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9948                               RTE_UINT16);
9949
9950 static cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9951         .f = cmd_cfg_tunnel_udp_port_parsed,
9952         .data = NULL,
9953         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9954                 "geneve|vxlan-gpe|ecpri <udp_port>",
9955         .tokens = {
9956                 (void *)&cmd_config_tunnel_udp_port_port,
9957                 (void *)&cmd_config_tunnel_udp_port_config,
9958                 (void *)&cmd_config_tunnel_udp_port_port_id,
9959                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9960                 (void *)&cmd_config_tunnel_udp_port_action,
9961                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9962                 (void *)&cmd_config_tunnel_udp_port_value,
9963                 NULL,
9964         },
9965 };
9966
9967 /* ******************************************************************************** */
9968
9969 struct cmd_dump_result {
9970         cmdline_fixed_string_t dump;
9971 };
9972
9973 static void
9974 dump_struct_sizes(void)
9975 {
9976 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9977         DUMP_SIZE(struct rte_mbuf);
9978         DUMP_SIZE(struct rte_mempool);
9979         DUMP_SIZE(struct rte_ring);
9980 #undef DUMP_SIZE
9981 }
9982
9983
9984 /* Dump the socket memory statistics on console */
9985 static void
9986 dump_socket_mem(FILE *f)
9987 {
9988         struct rte_malloc_socket_stats socket_stats;
9989         unsigned int i;
9990         size_t total = 0;
9991         size_t alloc = 0;
9992         size_t free = 0;
9993         unsigned int n_alloc = 0;
9994         unsigned int n_free = 0;
9995         static size_t last_allocs;
9996         static size_t last_total;
9997
9998
9999         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
10000                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
10001                     !socket_stats.heap_totalsz_bytes)
10002                         continue;
10003                 total += socket_stats.heap_totalsz_bytes;
10004                 alloc += socket_stats.heap_allocsz_bytes;
10005                 free += socket_stats.heap_freesz_bytes;
10006                 n_alloc += socket_stats.alloc_count;
10007                 n_free += socket_stats.free_count;
10008                 fprintf(f,
10009                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
10010                         i,
10011                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
10012                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
10013                         (double)socket_stats.heap_allocsz_bytes * 100 /
10014                         (double)socket_stats.heap_totalsz_bytes,
10015                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
10016                         socket_stats.alloc_count,
10017                         socket_stats.free_count);
10018         }
10019         fprintf(f,
10020                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
10021                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
10022                 total ? ((double)alloc * 100 / (double)total) : 0,
10023                 (double)free / (1024 * 1024),
10024                 n_alloc, n_free);
10025         if (last_allocs)
10026                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
10027                         ((double)total - (double)last_total) / (1024 * 1024),
10028                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
10029         last_allocs = alloc;
10030         last_total = total;
10031 }
10032
10033 static void cmd_dump_parsed(void *parsed_result,
10034                             __rte_unused struct cmdline *cl,
10035                             __rte_unused void *data)
10036 {
10037         struct cmd_dump_result *res = parsed_result;
10038
10039         if (!strcmp(res->dump, "dump_physmem"))
10040                 rte_dump_physmem_layout(stdout);
10041         else if (!strcmp(res->dump, "dump_socket_mem"))
10042                 dump_socket_mem(stdout);
10043         else if (!strcmp(res->dump, "dump_memzone"))
10044                 rte_memzone_dump(stdout);
10045         else if (!strcmp(res->dump, "dump_struct_sizes"))
10046                 dump_struct_sizes();
10047         else if (!strcmp(res->dump, "dump_ring"))
10048                 rte_ring_list_dump(stdout);
10049         else if (!strcmp(res->dump, "dump_mempool"))
10050                 rte_mempool_list_dump(stdout);
10051         else if (!strcmp(res->dump, "dump_devargs"))
10052                 rte_devargs_dump(stdout);
10053         else if (!strcmp(res->dump, "dump_log_types"))
10054                 rte_log_dump(stdout);
10055 }
10056
10057 static cmdline_parse_token_string_t cmd_dump_dump =
10058         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10059                 "dump_physmem#"
10060                 "dump_memzone#"
10061                 "dump_socket_mem#"
10062                 "dump_struct_sizes#"
10063                 "dump_ring#"
10064                 "dump_mempool#"
10065                 "dump_devargs#"
10066                 "dump_log_types");
10067
10068 static cmdline_parse_inst_t cmd_dump = {
10069         .f = cmd_dump_parsed,  /* function to call */
10070         .data = NULL,      /* 2nd arg of func */
10071         .help_str = "Dump status",
10072         .tokens = {        /* token list, NULL terminated */
10073                 (void *)&cmd_dump_dump,
10074                 NULL,
10075         },
10076 };
10077
10078 /* ******************************************************************************** */
10079
10080 struct cmd_dump_one_result {
10081         cmdline_fixed_string_t dump;
10082         cmdline_fixed_string_t name;
10083 };
10084
10085 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10086                                 __rte_unused void *data)
10087 {
10088         struct cmd_dump_one_result *res = parsed_result;
10089
10090         if (!strcmp(res->dump, "dump_ring")) {
10091                 struct rte_ring *r;
10092                 r = rte_ring_lookup(res->name);
10093                 if (r == NULL) {
10094                         cmdline_printf(cl, "Cannot find ring\n");
10095                         return;
10096                 }
10097                 rte_ring_dump(stdout, r);
10098         } else if (!strcmp(res->dump, "dump_mempool")) {
10099                 struct rte_mempool *mp;
10100                 mp = rte_mempool_lookup(res->name);
10101                 if (mp == NULL) {
10102                         cmdline_printf(cl, "Cannot find mempool\n");
10103                         return;
10104                 }
10105                 rte_mempool_dump(stdout, mp);
10106         }
10107 }
10108
10109 static cmdline_parse_token_string_t cmd_dump_one_dump =
10110         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10111                                  "dump_ring#dump_mempool");
10112
10113 static cmdline_parse_token_string_t cmd_dump_one_name =
10114         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10115
10116 static cmdline_parse_inst_t cmd_dump_one = {
10117         .f = cmd_dump_one_parsed,  /* function to call */
10118         .data = NULL,      /* 2nd arg of func */
10119         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10120         .tokens = {        /* token list, NULL terminated */
10121                 (void *)&cmd_dump_one_dump,
10122                 (void *)&cmd_dump_one_name,
10123                 NULL,
10124         },
10125 };
10126
10127 /* *** queue region set *** */
10128 struct cmd_queue_region_result {
10129         cmdline_fixed_string_t set;
10130         cmdline_fixed_string_t port;
10131         portid_t port_id;
10132         cmdline_fixed_string_t cmd;
10133         cmdline_fixed_string_t region;
10134         uint8_t  region_id;
10135         cmdline_fixed_string_t queue_start_index;
10136         uint8_t  queue_id;
10137         cmdline_fixed_string_t queue_num;
10138         uint8_t  queue_num_value;
10139 };
10140
10141 static void
10142 cmd_queue_region_parsed(void *parsed_result,
10143                         __rte_unused struct cmdline *cl,
10144                         __rte_unused void *data)
10145 {
10146         struct cmd_queue_region_result *res = parsed_result;
10147         int ret = -ENOTSUP;
10148 #ifdef RTE_NET_I40E
10149         struct rte_pmd_i40e_queue_region_conf region_conf;
10150         enum rte_pmd_i40e_queue_region_op op_type;
10151 #endif
10152
10153         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10154                 return;
10155
10156 #ifdef RTE_NET_I40E
10157         memset(&region_conf, 0, sizeof(region_conf));
10158         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10159         region_conf.region_id = res->region_id;
10160         region_conf.queue_num = res->queue_num_value;
10161         region_conf.queue_start_index = res->queue_id;
10162
10163         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10164                                 op_type, &region_conf);
10165 #endif
10166
10167         switch (ret) {
10168         case 0:
10169                 break;
10170         case -ENOTSUP:
10171                 fprintf(stderr, "function not implemented or supported\n");
10172                 break;
10173         default:
10174                 fprintf(stderr, "queue region config error: (%s)\n",
10175                         strerror(-ret));
10176         }
10177 }
10178
10179 static cmdline_parse_token_string_t cmd_queue_region_set =
10180 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10181                 set, "set");
10182 static cmdline_parse_token_string_t cmd_queue_region_port =
10183         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10184 static cmdline_parse_token_num_t cmd_queue_region_port_id =
10185         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10186                                 port_id, RTE_UINT16);
10187 static cmdline_parse_token_string_t cmd_queue_region_cmd =
10188         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10189                                  cmd, "queue-region");
10190 static cmdline_parse_token_string_t cmd_queue_region_id =
10191         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10192                                 region, "region_id");
10193 static cmdline_parse_token_num_t cmd_queue_region_index =
10194         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10195                                 region_id, RTE_UINT8);
10196 static cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10197         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10198                                 queue_start_index, "queue_start_index");
10199 static cmdline_parse_token_num_t cmd_queue_region_queue_id =
10200         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10201                                 queue_id, RTE_UINT8);
10202 static cmdline_parse_token_string_t cmd_queue_region_queue_num =
10203         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10204                                 queue_num, "queue_num");
10205 static cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10206         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10207                                 queue_num_value, RTE_UINT8);
10208
10209 static cmdline_parse_inst_t cmd_queue_region = {
10210         .f = cmd_queue_region_parsed,
10211         .data = NULL,
10212         .help_str = "set port <port_id> queue-region region_id <value> "
10213                 "queue_start_index <value> queue_num <value>: Set a queue region",
10214         .tokens = {
10215                 (void *)&cmd_queue_region_set,
10216                 (void *)&cmd_queue_region_port,
10217                 (void *)&cmd_queue_region_port_id,
10218                 (void *)&cmd_queue_region_cmd,
10219                 (void *)&cmd_queue_region_id,
10220                 (void *)&cmd_queue_region_index,
10221                 (void *)&cmd_queue_region_queue_start_index,
10222                 (void *)&cmd_queue_region_queue_id,
10223                 (void *)&cmd_queue_region_queue_num,
10224                 (void *)&cmd_queue_region_queue_num_value,
10225                 NULL,
10226         },
10227 };
10228
10229 /* *** queue region and flowtype set *** */
10230 struct cmd_region_flowtype_result {
10231         cmdline_fixed_string_t set;
10232         cmdline_fixed_string_t port;
10233         portid_t port_id;
10234         cmdline_fixed_string_t cmd;
10235         cmdline_fixed_string_t region;
10236         uint8_t  region_id;
10237         cmdline_fixed_string_t flowtype;
10238         uint8_t  flowtype_id;
10239 };
10240
10241 static void
10242 cmd_region_flowtype_parsed(void *parsed_result,
10243                         __rte_unused struct cmdline *cl,
10244                         __rte_unused void *data)
10245 {
10246         struct cmd_region_flowtype_result *res = parsed_result;
10247         int ret = -ENOTSUP;
10248 #ifdef RTE_NET_I40E
10249         struct rte_pmd_i40e_queue_region_conf region_conf;
10250         enum rte_pmd_i40e_queue_region_op op_type;
10251 #endif
10252
10253         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10254                 return;
10255
10256 #ifdef RTE_NET_I40E
10257         memset(&region_conf, 0, sizeof(region_conf));
10258
10259         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10260         region_conf.region_id = res->region_id;
10261         region_conf.hw_flowtype = res->flowtype_id;
10262
10263         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10264                         op_type, &region_conf);
10265 #endif
10266
10267         switch (ret) {
10268         case 0:
10269                 break;
10270         case -ENOTSUP:
10271                 fprintf(stderr, "function not implemented or supported\n");
10272                 break;
10273         default:
10274                 fprintf(stderr, "region flowtype config error: (%s)\n",
10275                         strerror(-ret));
10276         }
10277 }
10278
10279 static cmdline_parse_token_string_t cmd_region_flowtype_set =
10280 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10281                                 set, "set");
10282 static cmdline_parse_token_string_t cmd_region_flowtype_port =
10283         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10284                                 port, "port");
10285 static cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10286         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10287                                 port_id, RTE_UINT16);
10288 static cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10289         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10290                                 cmd, "queue-region");
10291 static cmdline_parse_token_string_t cmd_region_flowtype_index =
10292         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10293                                 region, "region_id");
10294 static cmdline_parse_token_num_t cmd_region_flowtype_id =
10295         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10296                                 region_id, RTE_UINT8);
10297 static cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10298         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10299                                 flowtype, "flowtype");
10300 static cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10301         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10302                                 flowtype_id, RTE_UINT8);
10303 static cmdline_parse_inst_t cmd_region_flowtype = {
10304         .f = cmd_region_flowtype_parsed,
10305         .data = NULL,
10306         .help_str = "set port <port_id> queue-region region_id <value> "
10307                 "flowtype <value>: Set a flowtype region index",
10308         .tokens = {
10309                 (void *)&cmd_region_flowtype_set,
10310                 (void *)&cmd_region_flowtype_port,
10311                 (void *)&cmd_region_flowtype_port_index,
10312                 (void *)&cmd_region_flowtype_cmd,
10313                 (void *)&cmd_region_flowtype_index,
10314                 (void *)&cmd_region_flowtype_id,
10315                 (void *)&cmd_region_flowtype_flow_index,
10316                 (void *)&cmd_region_flowtype_flow_id,
10317                 NULL,
10318         },
10319 };
10320
10321 /* *** User Priority (UP) to queue region (region_id) set *** */
10322 struct cmd_user_priority_region_result {
10323         cmdline_fixed_string_t set;
10324         cmdline_fixed_string_t port;
10325         portid_t port_id;
10326         cmdline_fixed_string_t cmd;
10327         cmdline_fixed_string_t user_priority;
10328         uint8_t  user_priority_id;
10329         cmdline_fixed_string_t region;
10330         uint8_t  region_id;
10331 };
10332
10333 static void
10334 cmd_user_priority_region_parsed(void *parsed_result,
10335                         __rte_unused struct cmdline *cl,
10336                         __rte_unused void *data)
10337 {
10338         struct cmd_user_priority_region_result *res = parsed_result;
10339         int ret = -ENOTSUP;
10340 #ifdef RTE_NET_I40E
10341         struct rte_pmd_i40e_queue_region_conf region_conf;
10342         enum rte_pmd_i40e_queue_region_op op_type;
10343 #endif
10344
10345         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10346                 return;
10347
10348 #ifdef RTE_NET_I40E
10349         memset(&region_conf, 0, sizeof(region_conf));
10350         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10351         region_conf.user_priority = res->user_priority_id;
10352         region_conf.region_id = res->region_id;
10353
10354         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10355                                 op_type, &region_conf);
10356 #endif
10357
10358         switch (ret) {
10359         case 0:
10360                 break;
10361         case -ENOTSUP:
10362                 fprintf(stderr, "function not implemented or supported\n");
10363                 break;
10364         default:
10365                 fprintf(stderr, "user_priority region config error: (%s)\n",
10366                         strerror(-ret));
10367         }
10368 }
10369
10370 static cmdline_parse_token_string_t cmd_user_priority_region_set =
10371         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10372                                 set, "set");
10373 static cmdline_parse_token_string_t cmd_user_priority_region_port =
10374         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10375                                 port, "port");
10376 static cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10377         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10378                                 port_id, RTE_UINT16);
10379 static cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10380         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10381                                 cmd, "queue-region");
10382 static cmdline_parse_token_string_t cmd_user_priority_region_UP =
10383         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10384                                 user_priority, "UP");
10385 static cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10386         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10387                                 user_priority_id, RTE_UINT8);
10388 static cmdline_parse_token_string_t cmd_user_priority_region_region =
10389         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10390                                 region, "region_id");
10391 static cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10392         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10393                                 region_id, RTE_UINT8);
10394
10395 static cmdline_parse_inst_t cmd_user_priority_region = {
10396         .f = cmd_user_priority_region_parsed,
10397         .data = NULL,
10398         .help_str = "set port <port_id> queue-region UP <value> "
10399                 "region_id <value>: Set the mapping of User Priority (UP) "
10400                 "to queue region (region_id) ",
10401         .tokens = {
10402                 (void *)&cmd_user_priority_region_set,
10403                 (void *)&cmd_user_priority_region_port,
10404                 (void *)&cmd_user_priority_region_port_index,
10405                 (void *)&cmd_user_priority_region_cmd,
10406                 (void *)&cmd_user_priority_region_UP,
10407                 (void *)&cmd_user_priority_region_UP_id,
10408                 (void *)&cmd_user_priority_region_region,
10409                 (void *)&cmd_user_priority_region_region_id,
10410                 NULL,
10411         },
10412 };
10413
10414 /* *** flush all queue region related configuration *** */
10415 struct cmd_flush_queue_region_result {
10416         cmdline_fixed_string_t set;
10417         cmdline_fixed_string_t port;
10418         portid_t port_id;
10419         cmdline_fixed_string_t cmd;
10420         cmdline_fixed_string_t flush;
10421         cmdline_fixed_string_t what;
10422 };
10423
10424 static void
10425 cmd_flush_queue_region_parsed(void *parsed_result,
10426                         __rte_unused struct cmdline *cl,
10427                         __rte_unused void *data)
10428 {
10429         struct cmd_flush_queue_region_result *res = parsed_result;
10430         int ret = -ENOTSUP;
10431 #ifdef RTE_NET_I40E
10432         struct rte_pmd_i40e_queue_region_conf region_conf;
10433         enum rte_pmd_i40e_queue_region_op op_type;
10434 #endif
10435
10436         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10437                 return;
10438
10439 #ifdef RTE_NET_I40E
10440         memset(&region_conf, 0, sizeof(region_conf));
10441
10442         if (strcmp(res->what, "on") == 0)
10443                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10444         else
10445                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10446
10447         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10448                                 op_type, &region_conf);
10449 #endif
10450
10451         switch (ret) {
10452         case 0:
10453                 break;
10454         case -ENOTSUP:
10455                 fprintf(stderr, "function not implemented or supported\n");
10456                 break;
10457         default:
10458                 fprintf(stderr, "queue region config flush error: (%s)\n",
10459                         strerror(-ret));
10460         }
10461 }
10462
10463 static cmdline_parse_token_string_t cmd_flush_queue_region_set =
10464         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10465                                 set, "set");
10466 static cmdline_parse_token_string_t cmd_flush_queue_region_port =
10467         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10468                                 port, "port");
10469 static cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10470         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10471                                 port_id, RTE_UINT16);
10472 static cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10473         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10474                                 cmd, "queue-region");
10475 static cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10476         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10477                                 flush, "flush");
10478 static cmdline_parse_token_string_t cmd_flush_queue_region_what =
10479         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10480                                 what, "on#off");
10481
10482 static cmdline_parse_inst_t cmd_flush_queue_region = {
10483         .f = cmd_flush_queue_region_parsed,
10484         .data = NULL,
10485         .help_str = "set port <port_id> queue-region flush on|off"
10486                 ": flush all queue region related configuration",
10487         .tokens = {
10488                 (void *)&cmd_flush_queue_region_set,
10489                 (void *)&cmd_flush_queue_region_port,
10490                 (void *)&cmd_flush_queue_region_port_index,
10491                 (void *)&cmd_flush_queue_region_cmd,
10492                 (void *)&cmd_flush_queue_region_flush,
10493                 (void *)&cmd_flush_queue_region_what,
10494                 NULL,
10495         },
10496 };
10497
10498 /* *** get all queue region related configuration info *** */
10499 struct cmd_show_queue_region_info {
10500         cmdline_fixed_string_t show;
10501         cmdline_fixed_string_t port;
10502         portid_t port_id;
10503         cmdline_fixed_string_t cmd;
10504 };
10505
10506 static void
10507 cmd_show_queue_region_info_parsed(void *parsed_result,
10508                         __rte_unused struct cmdline *cl,
10509                         __rte_unused void *data)
10510 {
10511         struct cmd_show_queue_region_info *res = parsed_result;
10512         int ret = -ENOTSUP;
10513 #ifdef RTE_NET_I40E
10514         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10515         enum rte_pmd_i40e_queue_region_op op_type;
10516 #endif
10517
10518         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10519                 return;
10520
10521 #ifdef RTE_NET_I40E
10522         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10523
10524         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10525
10526         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10527                                         op_type, &rte_pmd_regions);
10528
10529         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10530 #endif
10531
10532         switch (ret) {
10533         case 0:
10534                 break;
10535         case -ENOTSUP:
10536                 fprintf(stderr, "function not implemented or supported\n");
10537                 break;
10538         default:
10539                 fprintf(stderr, "queue region config info show error: (%s)\n",
10540                         strerror(-ret));
10541         }
10542 }
10543
10544 static cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10545 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10546                                 show, "show");
10547 static cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10548         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10549                                 port, "port");
10550 static cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10551         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10552                                 port_id, RTE_UINT16);
10553 static cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10554         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10555                                 cmd, "queue-region");
10556
10557 static cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10558         .f = cmd_show_queue_region_info_parsed,
10559         .data = NULL,
10560         .help_str = "show port <port_id> queue-region"
10561                 ": show all queue region related configuration info",
10562         .tokens = {
10563                 (void *)&cmd_show_queue_region_info_get,
10564                 (void *)&cmd_show_queue_region_info_port,
10565                 (void *)&cmd_show_queue_region_info_port_index,
10566                 (void *)&cmd_show_queue_region_info_cmd,
10567                 NULL,
10568         },
10569 };
10570
10571 /* *** Filters Control *** */
10572
10573 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10574 do { \
10575         if ((ip_addr).family == AF_INET) \
10576                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10577         else { \
10578                 fprintf(stderr, "invalid parameter.\n"); \
10579                 return; \
10580         } \
10581 } while (0)
10582
10583 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10584 do { \
10585         if ((ip_addr).family == AF_INET6) \
10586                 rte_memcpy(&(ip), \
10587                                  &((ip_addr).addr.ipv6), \
10588                                  sizeof(struct in6_addr)); \
10589         else { \
10590                 fprintf(stderr, "invalid parameter.\n"); \
10591                 return; \
10592         } \
10593 } while (0)
10594
10595 #ifdef RTE_NET_I40E
10596
10597 static uint16_t
10598 str2flowtype(char *string)
10599 {
10600         uint8_t i = 0;
10601         static const struct {
10602                 char str[32];
10603                 uint16_t type;
10604         } flowtype_str[] = {
10605                 {"raw", RTE_ETH_FLOW_RAW},
10606                 {"ipv4", RTE_ETH_FLOW_IPV4},
10607                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10608                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10609                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10610                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10611                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10612                 {"ipv6", RTE_ETH_FLOW_IPV6},
10613                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10614                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10615                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10616                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10617                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10618                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10619                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10620                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10621                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10622                 {"gtpu", RTE_ETH_FLOW_GTPU},
10623         };
10624
10625         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10626                 if (!strcmp(flowtype_str[i].str, string))
10627                         return flowtype_str[i].type;
10628         }
10629
10630         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10631                 return (uint16_t)atoi(string);
10632
10633         return RTE_ETH_FLOW_UNKNOWN;
10634 }
10635
10636 /* *** deal with flow director filter *** */
10637 struct cmd_flow_director_result {
10638         cmdline_fixed_string_t flow_director_filter;
10639         portid_t port_id;
10640         cmdline_fixed_string_t mode;
10641         cmdline_fixed_string_t mode_value;
10642         cmdline_fixed_string_t ops;
10643         cmdline_fixed_string_t flow;
10644         cmdline_fixed_string_t flow_type;
10645         cmdline_fixed_string_t drop;
10646         cmdline_fixed_string_t queue;
10647         uint16_t  queue_id;
10648         cmdline_fixed_string_t fd_id;
10649         uint32_t  fd_id_value;
10650         cmdline_fixed_string_t packet;
10651         char filepath[];
10652 };
10653
10654 static void
10655 cmd_flow_director_filter_parsed(void *parsed_result,
10656                           __rte_unused struct cmdline *cl,
10657                           __rte_unused void *data)
10658 {
10659         struct cmd_flow_director_result *res = parsed_result;
10660         int ret = 0;
10661         struct rte_pmd_i40e_flow_type_mapping
10662                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10663         struct rte_pmd_i40e_pkt_template_conf conf;
10664         uint16_t flow_type = str2flowtype(res->flow_type);
10665         uint16_t i, port = res->port_id;
10666         uint8_t add;
10667
10668         memset(&conf, 0, sizeof(conf));
10669
10670         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10671                 fprintf(stderr, "Invalid flow type specified.\n");
10672                 return;
10673         }
10674         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10675                                                  mapping);
10676         if (ret)
10677                 return;
10678         if (mapping[flow_type].pctype == 0ULL) {
10679                 fprintf(stderr, "Invalid flow type specified.\n");
10680                 return;
10681         }
10682         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10683                 if (mapping[flow_type].pctype & (1ULL << i)) {
10684                         conf.input.pctype = i;
10685                         break;
10686                 }
10687         }
10688
10689         conf.input.packet = open_file(res->filepath,
10690                                 &conf.input.length);
10691         if (!conf.input.packet)
10692                 return;
10693         if (!strcmp(res->drop, "drop"))
10694                 conf.action.behavior =
10695                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10696         else
10697                 conf.action.behavior =
10698                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10699         conf.action.report_status =
10700                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10701         conf.action.rx_queue = res->queue_id;
10702         conf.soft_id = res->fd_id_value;
10703         add  = strcmp(res->ops, "del") ? 1 : 0;
10704         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10705                                                         &conf,
10706                                                         add);
10707         if (ret < 0)
10708                 fprintf(stderr, "flow director config error: (%s)\n",
10709                         strerror(-ret));
10710         close_file(conf.input.packet);
10711 }
10712
10713 static cmdline_parse_token_string_t cmd_flow_director_filter =
10714         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10715                                  flow_director_filter, "flow_director_filter");
10716 static cmdline_parse_token_num_t cmd_flow_director_port_id =
10717         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10718                               port_id, RTE_UINT16);
10719 static cmdline_parse_token_string_t cmd_flow_director_ops =
10720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10721                                  ops, "add#del#update");
10722 static cmdline_parse_token_string_t cmd_flow_director_flow =
10723         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10724                                  flow, "flow");
10725 static cmdline_parse_token_string_t cmd_flow_director_flow_type =
10726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10727                 flow_type, NULL);
10728 static cmdline_parse_token_string_t cmd_flow_director_drop =
10729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10730                                  drop, "drop#fwd");
10731 static cmdline_parse_token_string_t cmd_flow_director_queue =
10732         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10733                                  queue, "queue");
10734 static cmdline_parse_token_num_t cmd_flow_director_queue_id =
10735         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10736                               queue_id, RTE_UINT16);
10737 static cmdline_parse_token_string_t cmd_flow_director_fd_id =
10738         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10739                                  fd_id, "fd_id");
10740 static cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10741         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10742                               fd_id_value, RTE_UINT32);
10743
10744 static cmdline_parse_token_string_t cmd_flow_director_mode =
10745         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10746                                  mode, "mode");
10747 static cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10749                                  mode_value, "raw");
10750 static cmdline_parse_token_string_t cmd_flow_director_packet =
10751         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10752                                  packet, "packet");
10753 static cmdline_parse_token_string_t cmd_flow_director_filepath =
10754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10755                                  filepath, NULL);
10756
10757 static cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10758         .f = cmd_flow_director_filter_parsed,
10759         .data = NULL,
10760         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10761                 "director entry on NIC",
10762         .tokens = {
10763                 (void *)&cmd_flow_director_filter,
10764                 (void *)&cmd_flow_director_port_id,
10765                 (void *)&cmd_flow_director_mode,
10766                 (void *)&cmd_flow_director_mode_raw,
10767                 (void *)&cmd_flow_director_ops,
10768                 (void *)&cmd_flow_director_flow,
10769                 (void *)&cmd_flow_director_flow_type,
10770                 (void *)&cmd_flow_director_drop,
10771                 (void *)&cmd_flow_director_queue,
10772                 (void *)&cmd_flow_director_queue_id,
10773                 (void *)&cmd_flow_director_fd_id,
10774                 (void *)&cmd_flow_director_fd_id_value,
10775                 (void *)&cmd_flow_director_packet,
10776                 (void *)&cmd_flow_director_filepath,
10777                 NULL,
10778         },
10779 };
10780
10781 #endif /* RTE_NET_I40E */
10782
10783 /* *** deal with flow director mask *** */
10784 struct cmd_flow_director_mask_result {
10785         cmdline_fixed_string_t flow_director_mask;
10786         portid_t port_id;
10787         cmdline_fixed_string_t mode;
10788         cmdline_fixed_string_t mode_value;
10789         cmdline_fixed_string_t vlan;
10790         uint16_t vlan_mask;
10791         cmdline_fixed_string_t src_mask;
10792         cmdline_ipaddr_t ipv4_src;
10793         cmdline_ipaddr_t ipv6_src;
10794         uint16_t port_src;
10795         cmdline_fixed_string_t dst_mask;
10796         cmdline_ipaddr_t ipv4_dst;
10797         cmdline_ipaddr_t ipv6_dst;
10798         uint16_t port_dst;
10799         cmdline_fixed_string_t mac;
10800         uint8_t mac_addr_byte_mask;
10801         cmdline_fixed_string_t tunnel_id;
10802         uint32_t tunnel_id_mask;
10803         cmdline_fixed_string_t tunnel_type;
10804         uint8_t tunnel_type_mask;
10805 };
10806
10807 static void
10808 cmd_flow_director_mask_parsed(void *parsed_result,
10809                           __rte_unused struct cmdline *cl,
10810                           __rte_unused void *data)
10811 {
10812         struct cmd_flow_director_mask_result *res = parsed_result;
10813         struct rte_eth_fdir_masks *mask;
10814         struct rte_port *port;
10815
10816         port = &ports[res->port_id];
10817         /** Check if the port is not started **/
10818         if (port->port_status != RTE_PORT_STOPPED) {
10819                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10820                 return;
10821         }
10822
10823         mask = &port->dev_conf.fdir_conf.mask;
10824
10825         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10826                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10827                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10828                         return;
10829                 }
10830
10831                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10832         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10833                 if (strcmp(res->mode_value, "Tunnel")) {
10834                         fprintf(stderr, "Please set mode to Tunnel.\n");
10835                         return;
10836                 }
10837
10838                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10839                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10840                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10841                 mask->tunnel_type_mask = res->tunnel_type_mask;
10842         } else {
10843                 if (strcmp(res->mode_value, "IP")) {
10844                         fprintf(stderr, "Please set mode to IP.\n");
10845                         return;
10846                 }
10847
10848                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10849                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10850                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10851                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10852                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10853                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10854                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10855         }
10856
10857         cmd_reconfig_device_queue(res->port_id, 1, 1);
10858 }
10859
10860 static cmdline_parse_token_string_t cmd_flow_director_mask =
10861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10862                                  flow_director_mask, "flow_director_mask");
10863 static cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10864         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10865                               port_id, RTE_UINT16);
10866 static cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10868                                  vlan, "vlan");
10869 static cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10870         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10871                               vlan_mask, RTE_UINT16);
10872 static cmdline_parse_token_string_t cmd_flow_director_mask_src =
10873         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10874                                  src_mask, "src_mask");
10875 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10876         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10877                                  ipv4_src);
10878 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10879         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10880                                  ipv6_src);
10881 static cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10882         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10883                               port_src, RTE_UINT16);
10884 static cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10886                                  dst_mask, "dst_mask");
10887 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10888         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10889                                  ipv4_dst);
10890 static cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10891         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10892                                  ipv6_dst);
10893 static cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10894         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10895                               port_dst, RTE_UINT16);
10896
10897 static cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10898         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10899                                  mode, "mode");
10900 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10902                                  mode_value, "IP");
10903 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10904         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10905                                  mode_value, "MAC-VLAN");
10906 static cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10907         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10908                                  mode_value, "Tunnel");
10909 static cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10910         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10911                                  mac, "mac");
10912 static cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10913         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10914                               mac_addr_byte_mask, RTE_UINT8);
10915 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10916         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10917                                  tunnel_type, "tunnel-type");
10918 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10919         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10920                               tunnel_type_mask, RTE_UINT8);
10921 static cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10922         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10923                                  tunnel_id, "tunnel-id");
10924 static cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10925         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10926                               tunnel_id_mask, RTE_UINT32);
10927
10928 static cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10929         .f = cmd_flow_director_mask_parsed,
10930         .data = NULL,
10931         .help_str = "flow_director_mask ... : "
10932                 "Set IP mode flow director's mask on NIC",
10933         .tokens = {
10934                 (void *)&cmd_flow_director_mask,
10935                 (void *)&cmd_flow_director_mask_port_id,
10936                 (void *)&cmd_flow_director_mask_mode,
10937                 (void *)&cmd_flow_director_mask_mode_ip,
10938                 (void *)&cmd_flow_director_mask_vlan,
10939                 (void *)&cmd_flow_director_mask_vlan_value,
10940                 (void *)&cmd_flow_director_mask_src,
10941                 (void *)&cmd_flow_director_mask_ipv4_src,
10942                 (void *)&cmd_flow_director_mask_ipv6_src,
10943                 (void *)&cmd_flow_director_mask_port_src,
10944                 (void *)&cmd_flow_director_mask_dst,
10945                 (void *)&cmd_flow_director_mask_ipv4_dst,
10946                 (void *)&cmd_flow_director_mask_ipv6_dst,
10947                 (void *)&cmd_flow_director_mask_port_dst,
10948                 NULL,
10949         },
10950 };
10951
10952 static cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10953         .f = cmd_flow_director_mask_parsed,
10954         .data = NULL,
10955         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10956                 "flow director's mask on NIC",
10957         .tokens = {
10958                 (void *)&cmd_flow_director_mask,
10959                 (void *)&cmd_flow_director_mask_port_id,
10960                 (void *)&cmd_flow_director_mask_mode,
10961                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10962                 (void *)&cmd_flow_director_mask_vlan,
10963                 (void *)&cmd_flow_director_mask_vlan_value,
10964                 NULL,
10965         },
10966 };
10967
10968 static cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10969         .f = cmd_flow_director_mask_parsed,
10970         .data = NULL,
10971         .help_str = "flow_director_mask ... : Set tunnel mode "
10972                 "flow director's mask on NIC",
10973         .tokens = {
10974                 (void *)&cmd_flow_director_mask,
10975                 (void *)&cmd_flow_director_mask_port_id,
10976                 (void *)&cmd_flow_director_mask_mode,
10977                 (void *)&cmd_flow_director_mask_mode_tunnel,
10978                 (void *)&cmd_flow_director_mask_vlan,
10979                 (void *)&cmd_flow_director_mask_vlan_value,
10980                 (void *)&cmd_flow_director_mask_mac,
10981                 (void *)&cmd_flow_director_mask_mac_value,
10982                 (void *)&cmd_flow_director_mask_tunnel_type,
10983                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10984                 (void *)&cmd_flow_director_mask_tunnel_id,
10985                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10986                 NULL,
10987         },
10988 };
10989
10990 /* *** deal with flow director flexible payload configuration *** */
10991 struct cmd_flow_director_flexpayload_result {
10992         cmdline_fixed_string_t flow_director_flexpayload;
10993         portid_t port_id;
10994         cmdline_fixed_string_t payload_layer;
10995         cmdline_fixed_string_t payload_cfg;
10996 };
10997
10998 static inline int
10999 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11000 {
11001         char s[256];
11002         const char *p, *p0 = q_arg;
11003         char *end;
11004         unsigned long int_fld;
11005         char *str_fld[max_num];
11006         int i;
11007         unsigned size;
11008         int ret = -1;
11009
11010         p = strchr(p0, '(');
11011         if (p == NULL)
11012                 return -1;
11013         ++p;
11014         p0 = strchr(p, ')');
11015         if (p0 == NULL)
11016                 return -1;
11017
11018         size = p0 - p;
11019         if (size >= sizeof(s))
11020                 return -1;
11021
11022         snprintf(s, sizeof(s), "%.*s", size, p);
11023         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11024         if (ret < 0 || ret > max_num)
11025                 return -1;
11026         for (i = 0; i < ret; i++) {
11027                 errno = 0;
11028                 int_fld = strtoul(str_fld[i], &end, 0);
11029                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11030                         return -1;
11031                 offsets[i] = (uint16_t)int_fld;
11032         }
11033         return ret;
11034 }
11035
11036 static void
11037 cmd_flow_director_flxpld_parsed(void *parsed_result,
11038                           __rte_unused struct cmdline *cl,
11039                           __rte_unused void *data)
11040 {
11041         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11042         struct rte_eth_flex_payload_cfg flex_cfg;
11043         struct rte_port *port;
11044         int ret = 0;
11045
11046         port = &ports[res->port_id];
11047         /** Check if the port is not started **/
11048         if (port->port_status != RTE_PORT_STOPPED) {
11049                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
11050                 return;
11051         }
11052
11053         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11054
11055         if (!strcmp(res->payload_layer, "raw"))
11056                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11057         else if (!strcmp(res->payload_layer, "l2"))
11058                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11059         else if (!strcmp(res->payload_layer, "l3"))
11060                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11061         else if (!strcmp(res->payload_layer, "l4"))
11062                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11063
11064         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11065                             RTE_ETH_FDIR_MAX_FLEXLEN);
11066         if (ret < 0) {
11067                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
11068                 return;
11069         }
11070
11071         fdir_set_flex_payload(res->port_id, &flex_cfg);
11072         cmd_reconfig_device_queue(res->port_id, 1, 1);
11073 }
11074
11075 static cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11076         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11077                                  flow_director_flexpayload,
11078                                  "flow_director_flex_payload");
11079 static cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11080         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11081                               port_id, RTE_UINT16);
11082 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11083         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11084                                  payload_layer, "raw#l2#l3#l4");
11085 static cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11086         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11087                                  payload_cfg, NULL);
11088
11089 static cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11090         .f = cmd_flow_director_flxpld_parsed,
11091         .data = NULL,
11092         .help_str = "flow_director_flexpayload ... : "
11093                 "Set flow director's flex payload on NIC",
11094         .tokens = {
11095                 (void *)&cmd_flow_director_flexpayload,
11096                 (void *)&cmd_flow_director_flexpayload_port_id,
11097                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11098                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11099                 NULL,
11100         },
11101 };
11102
11103 /* Generic flow interface command. */
11104 extern cmdline_parse_inst_t cmd_flow;
11105
11106 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11107 struct cmd_mcast_addr_result {
11108         cmdline_fixed_string_t mcast_addr_cmd;
11109         cmdline_fixed_string_t what;
11110         uint16_t port_num;
11111         struct rte_ether_addr mc_addr;
11112 };
11113
11114 static void cmd_mcast_addr_parsed(void *parsed_result,
11115                 __rte_unused struct cmdline *cl,
11116                 __rte_unused void *data)
11117 {
11118         struct cmd_mcast_addr_result *res = parsed_result;
11119
11120         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11121                 fprintf(stderr,
11122                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11123                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11124                 return;
11125         }
11126         if (strcmp(res->what, "add") == 0)
11127                 mcast_addr_add(res->port_num, &res->mc_addr);
11128         else
11129                 mcast_addr_remove(res->port_num, &res->mc_addr);
11130 }
11131
11132 static cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11133         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11134                                  mcast_addr_cmd, "mcast_addr");
11135 static cmdline_parse_token_string_t cmd_mcast_addr_what =
11136         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11137                                  "add#remove");
11138 static cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11139         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11140                                  RTE_UINT16);
11141 static cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11142         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11143
11144 static cmdline_parse_inst_t cmd_mcast_addr = {
11145         .f = cmd_mcast_addr_parsed,
11146         .data = (void *)0,
11147         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11148                 "Add/Remove multicast MAC address on port_id",
11149         .tokens = {
11150                 (void *)&cmd_mcast_addr_cmd,
11151                 (void *)&cmd_mcast_addr_what,
11152                 (void *)&cmd_mcast_addr_portnum,
11153                 (void *)&cmd_mcast_addr_addr,
11154                 NULL,
11155         },
11156 };
11157
11158 /* vf vlan anti spoof configuration */
11159
11160 /* Common result structure for vf vlan anti spoof */
11161 struct cmd_vf_vlan_anti_spoof_result {
11162         cmdline_fixed_string_t set;
11163         cmdline_fixed_string_t vf;
11164         cmdline_fixed_string_t vlan;
11165         cmdline_fixed_string_t antispoof;
11166         portid_t port_id;
11167         uint32_t vf_id;
11168         cmdline_fixed_string_t on_off;
11169 };
11170
11171 /* Common CLI fields for vf vlan anti spoof enable disable */
11172 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11173         TOKEN_STRING_INITIALIZER
11174                 (struct cmd_vf_vlan_anti_spoof_result,
11175                  set, "set");
11176 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11177         TOKEN_STRING_INITIALIZER
11178                 (struct cmd_vf_vlan_anti_spoof_result,
11179                  vf, "vf");
11180 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11181         TOKEN_STRING_INITIALIZER
11182                 (struct cmd_vf_vlan_anti_spoof_result,
11183                  vlan, "vlan");
11184 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11185         TOKEN_STRING_INITIALIZER
11186                 (struct cmd_vf_vlan_anti_spoof_result,
11187                  antispoof, "antispoof");
11188 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11189         TOKEN_NUM_INITIALIZER
11190                 (struct cmd_vf_vlan_anti_spoof_result,
11191                  port_id, RTE_UINT16);
11192 static cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11193         TOKEN_NUM_INITIALIZER
11194                 (struct cmd_vf_vlan_anti_spoof_result,
11195                  vf_id, RTE_UINT32);
11196 static cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11197         TOKEN_STRING_INITIALIZER
11198                 (struct cmd_vf_vlan_anti_spoof_result,
11199                  on_off, "on#off");
11200
11201 static void
11202 cmd_set_vf_vlan_anti_spoof_parsed(
11203         void *parsed_result,
11204         __rte_unused struct cmdline *cl,
11205         __rte_unused void *data)
11206 {
11207         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11208         int ret = -ENOTSUP;
11209
11210         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11211
11212         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11213                 return;
11214
11215 #ifdef RTE_NET_IXGBE
11216         if (ret == -ENOTSUP)
11217                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11218                                 res->vf_id, is_on);
11219 #endif
11220 #ifdef RTE_NET_I40E
11221         if (ret == -ENOTSUP)
11222                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11223                                 res->vf_id, is_on);
11224 #endif
11225 #ifdef RTE_NET_BNXT
11226         if (ret == -ENOTSUP)
11227                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11228                                 res->vf_id, is_on);
11229 #endif
11230
11231         switch (ret) {
11232         case 0:
11233                 break;
11234         case -EINVAL:
11235                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11236                 break;
11237         case -ENODEV:
11238                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11239                 break;
11240         case -ENOTSUP:
11241                 fprintf(stderr, "function not implemented\n");
11242                 break;
11243         default:
11244                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11245         }
11246 }
11247
11248 static cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11249         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11250         .data = NULL,
11251         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11252         .tokens = {
11253                 (void *)&cmd_vf_vlan_anti_spoof_set,
11254                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11255                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11256                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11257                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11258                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11259                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11260                 NULL,
11261         },
11262 };
11263
11264 /* vf mac anti spoof configuration */
11265
11266 /* Common result structure for vf mac anti spoof */
11267 struct cmd_vf_mac_anti_spoof_result {
11268         cmdline_fixed_string_t set;
11269         cmdline_fixed_string_t vf;
11270         cmdline_fixed_string_t mac;
11271         cmdline_fixed_string_t antispoof;
11272         portid_t port_id;
11273         uint32_t vf_id;
11274         cmdline_fixed_string_t on_off;
11275 };
11276
11277 /* Common CLI fields for vf mac anti spoof enable disable */
11278 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11279         TOKEN_STRING_INITIALIZER
11280                 (struct cmd_vf_mac_anti_spoof_result,
11281                  set, "set");
11282 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11283         TOKEN_STRING_INITIALIZER
11284                 (struct cmd_vf_mac_anti_spoof_result,
11285                  vf, "vf");
11286 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11287         TOKEN_STRING_INITIALIZER
11288                 (struct cmd_vf_mac_anti_spoof_result,
11289                  mac, "mac");
11290 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11291         TOKEN_STRING_INITIALIZER
11292                 (struct cmd_vf_mac_anti_spoof_result,
11293                  antispoof, "antispoof");
11294 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11295         TOKEN_NUM_INITIALIZER
11296                 (struct cmd_vf_mac_anti_spoof_result,
11297                  port_id, RTE_UINT16);
11298 static cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11299         TOKEN_NUM_INITIALIZER
11300                 (struct cmd_vf_mac_anti_spoof_result,
11301                  vf_id, RTE_UINT32);
11302 static cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11303         TOKEN_STRING_INITIALIZER
11304                 (struct cmd_vf_mac_anti_spoof_result,
11305                  on_off, "on#off");
11306
11307 static void
11308 cmd_set_vf_mac_anti_spoof_parsed(
11309         void *parsed_result,
11310         __rte_unused struct cmdline *cl,
11311         __rte_unused void *data)
11312 {
11313         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11314         int ret = -ENOTSUP;
11315
11316         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11317
11318         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11319                 return;
11320
11321 #ifdef RTE_NET_IXGBE
11322         if (ret == -ENOTSUP)
11323                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11324                         res->vf_id, is_on);
11325 #endif
11326 #ifdef RTE_NET_I40E
11327         if (ret == -ENOTSUP)
11328                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11329                         res->vf_id, is_on);
11330 #endif
11331 #ifdef RTE_NET_BNXT
11332         if (ret == -ENOTSUP)
11333                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11334                         res->vf_id, is_on);
11335 #endif
11336
11337         switch (ret) {
11338         case 0:
11339                 break;
11340         case -EINVAL:
11341                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11342                         res->vf_id, is_on);
11343                 break;
11344         case -ENODEV:
11345                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11346                 break;
11347         case -ENOTSUP:
11348                 fprintf(stderr, "function not implemented\n");
11349                 break;
11350         default:
11351                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11352         }
11353 }
11354
11355 static cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11356         .f = cmd_set_vf_mac_anti_spoof_parsed,
11357         .data = NULL,
11358         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11359         .tokens = {
11360                 (void *)&cmd_vf_mac_anti_spoof_set,
11361                 (void *)&cmd_vf_mac_anti_spoof_vf,
11362                 (void *)&cmd_vf_mac_anti_spoof_mac,
11363                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11364                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11365                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11366                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11367                 NULL,
11368         },
11369 };
11370
11371 /* vf vlan strip queue configuration */
11372
11373 /* Common result structure for vf mac anti spoof */
11374 struct cmd_vf_vlan_stripq_result {
11375         cmdline_fixed_string_t set;
11376         cmdline_fixed_string_t vf;
11377         cmdline_fixed_string_t vlan;
11378         cmdline_fixed_string_t stripq;
11379         portid_t port_id;
11380         uint16_t vf_id;
11381         cmdline_fixed_string_t on_off;
11382 };
11383
11384 /* Common CLI fields for vf vlan strip enable disable */
11385 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11386         TOKEN_STRING_INITIALIZER
11387                 (struct cmd_vf_vlan_stripq_result,
11388                  set, "set");
11389 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11390         TOKEN_STRING_INITIALIZER
11391                 (struct cmd_vf_vlan_stripq_result,
11392                  vf, "vf");
11393 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11394         TOKEN_STRING_INITIALIZER
11395                 (struct cmd_vf_vlan_stripq_result,
11396                  vlan, "vlan");
11397 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11398         TOKEN_STRING_INITIALIZER
11399                 (struct cmd_vf_vlan_stripq_result,
11400                  stripq, "stripq");
11401 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11402         TOKEN_NUM_INITIALIZER
11403                 (struct cmd_vf_vlan_stripq_result,
11404                  port_id, RTE_UINT16);
11405 static cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11406         TOKEN_NUM_INITIALIZER
11407                 (struct cmd_vf_vlan_stripq_result,
11408                  vf_id, RTE_UINT16);
11409 static cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11410         TOKEN_STRING_INITIALIZER
11411                 (struct cmd_vf_vlan_stripq_result,
11412                  on_off, "on#off");
11413
11414 static void
11415 cmd_set_vf_vlan_stripq_parsed(
11416         void *parsed_result,
11417         __rte_unused struct cmdline *cl,
11418         __rte_unused void *data)
11419 {
11420         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11421         int ret = -ENOTSUP;
11422
11423         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11424
11425         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11426                 return;
11427
11428 #ifdef RTE_NET_IXGBE
11429         if (ret == -ENOTSUP)
11430                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11431                         res->vf_id, is_on);
11432 #endif
11433 #ifdef RTE_NET_I40E
11434         if (ret == -ENOTSUP)
11435                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11436                         res->vf_id, is_on);
11437 #endif
11438 #ifdef RTE_NET_BNXT
11439         if (ret == -ENOTSUP)
11440                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11441                         res->vf_id, is_on);
11442 #endif
11443
11444         switch (ret) {
11445         case 0:
11446                 break;
11447         case -EINVAL:
11448                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11449                         res->vf_id, is_on);
11450                 break;
11451         case -ENODEV:
11452                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11453                 break;
11454         case -ENOTSUP:
11455                 fprintf(stderr, "function not implemented\n");
11456                 break;
11457         default:
11458                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11459         }
11460 }
11461
11462 static cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11463         .f = cmd_set_vf_vlan_stripq_parsed,
11464         .data = NULL,
11465         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11466         .tokens = {
11467                 (void *)&cmd_vf_vlan_stripq_set,
11468                 (void *)&cmd_vf_vlan_stripq_vf,
11469                 (void *)&cmd_vf_vlan_stripq_vlan,
11470                 (void *)&cmd_vf_vlan_stripq_stripq,
11471                 (void *)&cmd_vf_vlan_stripq_port_id,
11472                 (void *)&cmd_vf_vlan_stripq_vf_id,
11473                 (void *)&cmd_vf_vlan_stripq_on_off,
11474                 NULL,
11475         },
11476 };
11477
11478 /* vf vlan insert configuration */
11479
11480 /* Common result structure for vf vlan insert */
11481 struct cmd_vf_vlan_insert_result {
11482         cmdline_fixed_string_t set;
11483         cmdline_fixed_string_t vf;
11484         cmdline_fixed_string_t vlan;
11485         cmdline_fixed_string_t insert;
11486         portid_t port_id;
11487         uint16_t vf_id;
11488         uint16_t vlan_id;
11489 };
11490
11491 /* Common CLI fields for vf vlan insert enable disable */
11492 static cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11493         TOKEN_STRING_INITIALIZER
11494                 (struct cmd_vf_vlan_insert_result,
11495                  set, "set");
11496 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11497         TOKEN_STRING_INITIALIZER
11498                 (struct cmd_vf_vlan_insert_result,
11499                  vf, "vf");
11500 static cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11501         TOKEN_STRING_INITIALIZER
11502                 (struct cmd_vf_vlan_insert_result,
11503                  vlan, "vlan");
11504 static cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11505         TOKEN_STRING_INITIALIZER
11506                 (struct cmd_vf_vlan_insert_result,
11507                  insert, "insert");
11508 static cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11509         TOKEN_NUM_INITIALIZER
11510                 (struct cmd_vf_vlan_insert_result,
11511                  port_id, RTE_UINT16);
11512 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11513         TOKEN_NUM_INITIALIZER
11514                 (struct cmd_vf_vlan_insert_result,
11515                  vf_id, RTE_UINT16);
11516 static cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11517         TOKEN_NUM_INITIALIZER
11518                 (struct cmd_vf_vlan_insert_result,
11519                  vlan_id, RTE_UINT16);
11520
11521 static void
11522 cmd_set_vf_vlan_insert_parsed(
11523         void *parsed_result,
11524         __rte_unused struct cmdline *cl,
11525         __rte_unused void *data)
11526 {
11527         struct cmd_vf_vlan_insert_result *res = parsed_result;
11528         int ret = -ENOTSUP;
11529
11530         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11531                 return;
11532
11533 #ifdef RTE_NET_IXGBE
11534         if (ret == -ENOTSUP)
11535                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11536                         res->vlan_id);
11537 #endif
11538 #ifdef RTE_NET_I40E
11539         if (ret == -ENOTSUP)
11540                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11541                         res->vlan_id);
11542 #endif
11543 #ifdef RTE_NET_BNXT
11544         if (ret == -ENOTSUP)
11545                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11546                         res->vlan_id);
11547 #endif
11548
11549         switch (ret) {
11550         case 0:
11551                 break;
11552         case -EINVAL:
11553                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11554                         res->vf_id, res->vlan_id);
11555                 break;
11556         case -ENODEV:
11557                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11558                 break;
11559         case -ENOTSUP:
11560                 fprintf(stderr, "function not implemented\n");
11561                 break;
11562         default:
11563                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11564         }
11565 }
11566
11567 static cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11568         .f = cmd_set_vf_vlan_insert_parsed,
11569         .data = NULL,
11570         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11571         .tokens = {
11572                 (void *)&cmd_vf_vlan_insert_set,
11573                 (void *)&cmd_vf_vlan_insert_vf,
11574                 (void *)&cmd_vf_vlan_insert_vlan,
11575                 (void *)&cmd_vf_vlan_insert_insert,
11576                 (void *)&cmd_vf_vlan_insert_port_id,
11577                 (void *)&cmd_vf_vlan_insert_vf_id,
11578                 (void *)&cmd_vf_vlan_insert_vlan_id,
11579                 NULL,
11580         },
11581 };
11582
11583 /* tx loopback configuration */
11584
11585 /* Common result structure for tx loopback */
11586 struct cmd_tx_loopback_result {
11587         cmdline_fixed_string_t set;
11588         cmdline_fixed_string_t tx;
11589         cmdline_fixed_string_t loopback;
11590         portid_t port_id;
11591         cmdline_fixed_string_t on_off;
11592 };
11593
11594 /* Common CLI fields for tx loopback enable disable */
11595 static cmdline_parse_token_string_t cmd_tx_loopback_set =
11596         TOKEN_STRING_INITIALIZER
11597                 (struct cmd_tx_loopback_result,
11598                  set, "set");
11599 static cmdline_parse_token_string_t cmd_tx_loopback_tx =
11600         TOKEN_STRING_INITIALIZER
11601                 (struct cmd_tx_loopback_result,
11602                  tx, "tx");
11603 static cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11604         TOKEN_STRING_INITIALIZER
11605                 (struct cmd_tx_loopback_result,
11606                  loopback, "loopback");
11607 static cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11608         TOKEN_NUM_INITIALIZER
11609                 (struct cmd_tx_loopback_result,
11610                  port_id, RTE_UINT16);
11611 static cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11612         TOKEN_STRING_INITIALIZER
11613                 (struct cmd_tx_loopback_result,
11614                  on_off, "on#off");
11615
11616 static void
11617 cmd_set_tx_loopback_parsed(
11618         void *parsed_result,
11619         __rte_unused struct cmdline *cl,
11620         __rte_unused void *data)
11621 {
11622         struct cmd_tx_loopback_result *res = parsed_result;
11623         int ret = -ENOTSUP;
11624
11625         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11626
11627         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11628                 return;
11629
11630 #ifdef RTE_NET_IXGBE
11631         if (ret == -ENOTSUP)
11632                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11633 #endif
11634 #ifdef RTE_NET_I40E
11635         if (ret == -ENOTSUP)
11636                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11637 #endif
11638 #ifdef RTE_NET_BNXT
11639         if (ret == -ENOTSUP)
11640                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11641 #endif
11642 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11643         if (ret == -ENOTSUP)
11644                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11645 #endif
11646
11647         switch (ret) {
11648         case 0:
11649                 break;
11650         case -EINVAL:
11651                 fprintf(stderr, "invalid is_on %d\n", is_on);
11652                 break;
11653         case -ENODEV:
11654                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11655                 break;
11656         case -ENOTSUP:
11657                 fprintf(stderr, "function not implemented\n");
11658                 break;
11659         default:
11660                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11661         }
11662 }
11663
11664 static cmdline_parse_inst_t cmd_set_tx_loopback = {
11665         .f = cmd_set_tx_loopback_parsed,
11666         .data = NULL,
11667         .help_str = "set tx loopback <port_id> on|off",
11668         .tokens = {
11669                 (void *)&cmd_tx_loopback_set,
11670                 (void *)&cmd_tx_loopback_tx,
11671                 (void *)&cmd_tx_loopback_loopback,
11672                 (void *)&cmd_tx_loopback_port_id,
11673                 (void *)&cmd_tx_loopback_on_off,
11674                 NULL,
11675         },
11676 };
11677
11678 /* all queues drop enable configuration */
11679
11680 /* Common result structure for all queues drop enable */
11681 struct cmd_all_queues_drop_en_result {
11682         cmdline_fixed_string_t set;
11683         cmdline_fixed_string_t all;
11684         cmdline_fixed_string_t queues;
11685         cmdline_fixed_string_t drop;
11686         portid_t port_id;
11687         cmdline_fixed_string_t on_off;
11688 };
11689
11690 /* Common CLI fields for tx loopback enable disable */
11691 static cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11692         TOKEN_STRING_INITIALIZER
11693                 (struct cmd_all_queues_drop_en_result,
11694                  set, "set");
11695 static cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11696         TOKEN_STRING_INITIALIZER
11697                 (struct cmd_all_queues_drop_en_result,
11698                  all, "all");
11699 static cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11700         TOKEN_STRING_INITIALIZER
11701                 (struct cmd_all_queues_drop_en_result,
11702                  queues, "queues");
11703 static cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11704         TOKEN_STRING_INITIALIZER
11705                 (struct cmd_all_queues_drop_en_result,
11706                  drop, "drop");
11707 static cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11708         TOKEN_NUM_INITIALIZER
11709                 (struct cmd_all_queues_drop_en_result,
11710                  port_id, RTE_UINT16);
11711 static cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11712         TOKEN_STRING_INITIALIZER
11713                 (struct cmd_all_queues_drop_en_result,
11714                  on_off, "on#off");
11715
11716 static void
11717 cmd_set_all_queues_drop_en_parsed(
11718         void *parsed_result,
11719         __rte_unused struct cmdline *cl,
11720         __rte_unused void *data)
11721 {
11722         struct cmd_all_queues_drop_en_result *res = parsed_result;
11723         int ret = -ENOTSUP;
11724         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11725
11726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11727                 return;
11728
11729 #ifdef RTE_NET_IXGBE
11730         if (ret == -ENOTSUP)
11731                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11732 #endif
11733 #ifdef RTE_NET_BNXT
11734         if (ret == -ENOTSUP)
11735                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11736 #endif
11737         switch (ret) {
11738         case 0:
11739                 break;
11740         case -EINVAL:
11741                 fprintf(stderr, "invalid is_on %d\n", is_on);
11742                 break;
11743         case -ENODEV:
11744                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11745                 break;
11746         case -ENOTSUP:
11747                 fprintf(stderr, "function not implemented\n");
11748                 break;
11749         default:
11750                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11751         }
11752 }
11753
11754 static cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11755         .f = cmd_set_all_queues_drop_en_parsed,
11756         .data = NULL,
11757         .help_str = "set all queues drop <port_id> on|off",
11758         .tokens = {
11759                 (void *)&cmd_all_queues_drop_en_set,
11760                 (void *)&cmd_all_queues_drop_en_all,
11761                 (void *)&cmd_all_queues_drop_en_queues,
11762                 (void *)&cmd_all_queues_drop_en_drop,
11763                 (void *)&cmd_all_queues_drop_en_port_id,
11764                 (void *)&cmd_all_queues_drop_en_on_off,
11765                 NULL,
11766         },
11767 };
11768
11769 /* vf split drop enable configuration */
11770
11771 /* Common result structure for vf split drop enable */
11772 struct cmd_vf_split_drop_en_result {
11773         cmdline_fixed_string_t set;
11774         cmdline_fixed_string_t vf;
11775         cmdline_fixed_string_t split;
11776         cmdline_fixed_string_t drop;
11777         portid_t port_id;
11778         uint16_t vf_id;
11779         cmdline_fixed_string_t on_off;
11780 };
11781
11782 /* Common CLI fields for vf split drop enable disable */
11783 static cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11784         TOKEN_STRING_INITIALIZER
11785                 (struct cmd_vf_split_drop_en_result,
11786                  set, "set");
11787 static cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11788         TOKEN_STRING_INITIALIZER
11789                 (struct cmd_vf_split_drop_en_result,
11790                  vf, "vf");
11791 static cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11792         TOKEN_STRING_INITIALIZER
11793                 (struct cmd_vf_split_drop_en_result,
11794                  split, "split");
11795 static cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11796         TOKEN_STRING_INITIALIZER
11797                 (struct cmd_vf_split_drop_en_result,
11798                  drop, "drop");
11799 static cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11800         TOKEN_NUM_INITIALIZER
11801                 (struct cmd_vf_split_drop_en_result,
11802                  port_id, RTE_UINT16);
11803 static cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11804         TOKEN_NUM_INITIALIZER
11805                 (struct cmd_vf_split_drop_en_result,
11806                  vf_id, RTE_UINT16);
11807 static cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11808         TOKEN_STRING_INITIALIZER
11809                 (struct cmd_vf_split_drop_en_result,
11810                  on_off, "on#off");
11811
11812 static void
11813 cmd_set_vf_split_drop_en_parsed(
11814         void *parsed_result,
11815         __rte_unused struct cmdline *cl,
11816         __rte_unused void *data)
11817 {
11818         struct cmd_vf_split_drop_en_result *res = parsed_result;
11819         int ret = -ENOTSUP;
11820         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11821
11822         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11823                 return;
11824
11825 #ifdef RTE_NET_IXGBE
11826         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11827                         is_on);
11828 #endif
11829         switch (ret) {
11830         case 0:
11831                 break;
11832         case -EINVAL:
11833                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11834                         res->vf_id, is_on);
11835                 break;
11836         case -ENODEV:
11837                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11838                 break;
11839         case -ENOTSUP:
11840                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11841                 break;
11842         default:
11843                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11844         }
11845 }
11846
11847 static cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11848         .f = cmd_set_vf_split_drop_en_parsed,
11849         .data = NULL,
11850         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11851         .tokens = {
11852                 (void *)&cmd_vf_split_drop_en_set,
11853                 (void *)&cmd_vf_split_drop_en_vf,
11854                 (void *)&cmd_vf_split_drop_en_split,
11855                 (void *)&cmd_vf_split_drop_en_drop,
11856                 (void *)&cmd_vf_split_drop_en_port_id,
11857                 (void *)&cmd_vf_split_drop_en_vf_id,
11858                 (void *)&cmd_vf_split_drop_en_on_off,
11859                 NULL,
11860         },
11861 };
11862
11863 /* vf mac address configuration */
11864
11865 /* Common result structure for vf mac address */
11866 struct cmd_set_vf_mac_addr_result {
11867         cmdline_fixed_string_t set;
11868         cmdline_fixed_string_t vf;
11869         cmdline_fixed_string_t mac;
11870         cmdline_fixed_string_t addr;
11871         portid_t port_id;
11872         uint16_t vf_id;
11873         struct rte_ether_addr mac_addr;
11874
11875 };
11876
11877 /* Common CLI fields for vf split drop enable disable */
11878 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11879         TOKEN_STRING_INITIALIZER
11880                 (struct cmd_set_vf_mac_addr_result,
11881                  set, "set");
11882 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11883         TOKEN_STRING_INITIALIZER
11884                 (struct cmd_set_vf_mac_addr_result,
11885                  vf, "vf");
11886 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11887         TOKEN_STRING_INITIALIZER
11888                 (struct cmd_set_vf_mac_addr_result,
11889                  mac, "mac");
11890 static cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11891         TOKEN_STRING_INITIALIZER
11892                 (struct cmd_set_vf_mac_addr_result,
11893                  addr, "addr");
11894 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11895         TOKEN_NUM_INITIALIZER
11896                 (struct cmd_set_vf_mac_addr_result,
11897                  port_id, RTE_UINT16);
11898 static cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11899         TOKEN_NUM_INITIALIZER
11900                 (struct cmd_set_vf_mac_addr_result,
11901                  vf_id, RTE_UINT16);
11902 static cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11903         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11904                  mac_addr);
11905
11906 static void
11907 cmd_set_vf_mac_addr_parsed(
11908         void *parsed_result,
11909         __rte_unused struct cmdline *cl,
11910         __rte_unused void *data)
11911 {
11912         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11913         int ret = -ENOTSUP;
11914
11915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11916                 return;
11917
11918 #ifdef RTE_NET_IXGBE
11919         if (ret == -ENOTSUP)
11920                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11921                                 &res->mac_addr);
11922 #endif
11923 #ifdef RTE_NET_I40E
11924         if (ret == -ENOTSUP)
11925                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11926                                 &res->mac_addr);
11927 #endif
11928 #ifdef RTE_NET_BNXT
11929         if (ret == -ENOTSUP)
11930                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11931                                 &res->mac_addr);
11932 #endif
11933
11934         switch (ret) {
11935         case 0:
11936                 break;
11937         case -EINVAL:
11938                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11939                 break;
11940         case -ENODEV:
11941                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11942                 break;
11943         case -ENOTSUP:
11944                 fprintf(stderr, "function not implemented\n");
11945                 break;
11946         default:
11947                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11948         }
11949 }
11950
11951 static cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11952         .f = cmd_set_vf_mac_addr_parsed,
11953         .data = NULL,
11954         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11955         .tokens = {
11956                 (void *)&cmd_set_vf_mac_addr_set,
11957                 (void *)&cmd_set_vf_mac_addr_vf,
11958                 (void *)&cmd_set_vf_mac_addr_mac,
11959                 (void *)&cmd_set_vf_mac_addr_addr,
11960                 (void *)&cmd_set_vf_mac_addr_port_id,
11961                 (void *)&cmd_set_vf_mac_addr_vf_id,
11962                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11963                 NULL,
11964         },
11965 };
11966
11967 /* MACsec configuration */
11968
11969 /* Common result structure for MACsec offload enable */
11970 struct cmd_macsec_offload_on_result {
11971         cmdline_fixed_string_t set;
11972         cmdline_fixed_string_t macsec;
11973         cmdline_fixed_string_t offload;
11974         portid_t port_id;
11975         cmdline_fixed_string_t on;
11976         cmdline_fixed_string_t encrypt;
11977         cmdline_fixed_string_t en_on_off;
11978         cmdline_fixed_string_t replay_protect;
11979         cmdline_fixed_string_t rp_on_off;
11980 };
11981
11982 /* Common CLI fields for MACsec offload disable */
11983 static cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11984         TOKEN_STRING_INITIALIZER
11985                 (struct cmd_macsec_offload_on_result,
11986                  set, "set");
11987 static cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11988         TOKEN_STRING_INITIALIZER
11989                 (struct cmd_macsec_offload_on_result,
11990                  macsec, "macsec");
11991 static cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11992         TOKEN_STRING_INITIALIZER
11993                 (struct cmd_macsec_offload_on_result,
11994                  offload, "offload");
11995 static cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11996         TOKEN_NUM_INITIALIZER
11997                 (struct cmd_macsec_offload_on_result,
11998                  port_id, RTE_UINT16);
11999 static cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_macsec_offload_on_result,
12002                  on, "on");
12003 static cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12004         TOKEN_STRING_INITIALIZER
12005                 (struct cmd_macsec_offload_on_result,
12006                  encrypt, "encrypt");
12007 static cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_macsec_offload_on_result,
12010                  en_on_off, "on#off");
12011 static cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_macsec_offload_on_result,
12014                  replay_protect, "replay-protect");
12015 static cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_macsec_offload_on_result,
12018                  rp_on_off, "on#off");
12019
12020 static void
12021 cmd_set_macsec_offload_on_parsed(
12022         void *parsed_result,
12023         __rte_unused struct cmdline *cl,
12024         __rte_unused void *data)
12025 {
12026         struct cmd_macsec_offload_on_result *res = parsed_result;
12027         int ret = -ENOTSUP;
12028         portid_t port_id = res->port_id;
12029         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12030         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12031         struct rte_eth_dev_info dev_info;
12032
12033         if (port_id_is_invalid(port_id, ENABLED_WARN))
12034                 return;
12035         if (!port_is_stopped(port_id)) {
12036                 fprintf(stderr, "Please stop port %d first\n", port_id);
12037                 return;
12038         }
12039
12040         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12041         if (ret != 0)
12042                 return;
12043
12044         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12045 #ifdef RTE_NET_IXGBE
12046                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12047 #endif
12048         }
12049         RTE_SET_USED(en);
12050         RTE_SET_USED(rp);
12051
12052         switch (ret) {
12053         case 0:
12054                 ports[port_id].dev_conf.txmode.offloads |=
12055                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12056                 cmd_reconfig_device_queue(port_id, 1, 1);
12057                 break;
12058         case -ENODEV:
12059                 fprintf(stderr, "invalid port_id %d\n", port_id);
12060                 break;
12061         case -ENOTSUP:
12062                 fprintf(stderr, "not supported on port %d\n", port_id);
12063                 break;
12064         default:
12065                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12066         }
12067 }
12068
12069 static cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12070         .f = cmd_set_macsec_offload_on_parsed,
12071         .data = NULL,
12072         .help_str = "set macsec offload <port_id> on "
12073                 "encrypt on|off replay-protect on|off",
12074         .tokens = {
12075                 (void *)&cmd_macsec_offload_on_set,
12076                 (void *)&cmd_macsec_offload_on_macsec,
12077                 (void *)&cmd_macsec_offload_on_offload,
12078                 (void *)&cmd_macsec_offload_on_port_id,
12079                 (void *)&cmd_macsec_offload_on_on,
12080                 (void *)&cmd_macsec_offload_on_encrypt,
12081                 (void *)&cmd_macsec_offload_on_en_on_off,
12082                 (void *)&cmd_macsec_offload_on_replay_protect,
12083                 (void *)&cmd_macsec_offload_on_rp_on_off,
12084                 NULL,
12085         },
12086 };
12087
12088 /* Common result structure for MACsec offload disable */
12089 struct cmd_macsec_offload_off_result {
12090         cmdline_fixed_string_t set;
12091         cmdline_fixed_string_t macsec;
12092         cmdline_fixed_string_t offload;
12093         portid_t port_id;
12094         cmdline_fixed_string_t off;
12095 };
12096
12097 /* Common CLI fields for MACsec offload disable */
12098 static cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12099         TOKEN_STRING_INITIALIZER
12100                 (struct cmd_macsec_offload_off_result,
12101                  set, "set");
12102 static cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12103         TOKEN_STRING_INITIALIZER
12104                 (struct cmd_macsec_offload_off_result,
12105                  macsec, "macsec");
12106 static cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12107         TOKEN_STRING_INITIALIZER
12108                 (struct cmd_macsec_offload_off_result,
12109                  offload, "offload");
12110 static cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12111         TOKEN_NUM_INITIALIZER
12112                 (struct cmd_macsec_offload_off_result,
12113                  port_id, RTE_UINT16);
12114 static cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12115         TOKEN_STRING_INITIALIZER
12116                 (struct cmd_macsec_offload_off_result,
12117                  off, "off");
12118
12119 static void
12120 cmd_set_macsec_offload_off_parsed(
12121         void *parsed_result,
12122         __rte_unused struct cmdline *cl,
12123         __rte_unused void *data)
12124 {
12125         struct cmd_macsec_offload_off_result *res = parsed_result;
12126         int ret = -ENOTSUP;
12127         struct rte_eth_dev_info dev_info;
12128         portid_t port_id = res->port_id;
12129
12130         if (port_id_is_invalid(port_id, ENABLED_WARN))
12131                 return;
12132         if (!port_is_stopped(port_id)) {
12133                 fprintf(stderr, "Please stop port %d first\n", port_id);
12134                 return;
12135         }
12136
12137         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12138         if (ret != 0)
12139                 return;
12140
12141         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12142 #ifdef RTE_NET_IXGBE
12143                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12144 #endif
12145         }
12146         switch (ret) {
12147         case 0:
12148                 ports[port_id].dev_conf.txmode.offloads &=
12149                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12150                 cmd_reconfig_device_queue(port_id, 1, 1);
12151                 break;
12152         case -ENODEV:
12153                 fprintf(stderr, "invalid port_id %d\n", port_id);
12154                 break;
12155         case -ENOTSUP:
12156                 fprintf(stderr, "not supported on port %d\n", port_id);
12157                 break;
12158         default:
12159                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12160         }
12161 }
12162
12163 static cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12164         .f = cmd_set_macsec_offload_off_parsed,
12165         .data = NULL,
12166         .help_str = "set macsec offload <port_id> off",
12167         .tokens = {
12168                 (void *)&cmd_macsec_offload_off_set,
12169                 (void *)&cmd_macsec_offload_off_macsec,
12170                 (void *)&cmd_macsec_offload_off_offload,
12171                 (void *)&cmd_macsec_offload_off_port_id,
12172                 (void *)&cmd_macsec_offload_off_off,
12173                 NULL,
12174         },
12175 };
12176
12177 /* Common result structure for MACsec secure connection configure */
12178 struct cmd_macsec_sc_result {
12179         cmdline_fixed_string_t set;
12180         cmdline_fixed_string_t macsec;
12181         cmdline_fixed_string_t sc;
12182         cmdline_fixed_string_t tx_rx;
12183         portid_t port_id;
12184         struct rte_ether_addr mac;
12185         uint16_t pi;
12186 };
12187
12188 /* Common CLI fields for MACsec secure connection configure */
12189 static cmdline_parse_token_string_t cmd_macsec_sc_set =
12190         TOKEN_STRING_INITIALIZER
12191                 (struct cmd_macsec_sc_result,
12192                  set, "set");
12193 static cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12194         TOKEN_STRING_INITIALIZER
12195                 (struct cmd_macsec_sc_result,
12196                  macsec, "macsec");
12197 static cmdline_parse_token_string_t cmd_macsec_sc_sc =
12198         TOKEN_STRING_INITIALIZER
12199                 (struct cmd_macsec_sc_result,
12200                  sc, "sc");
12201 static cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12202         TOKEN_STRING_INITIALIZER
12203                 (struct cmd_macsec_sc_result,
12204                  tx_rx, "tx#rx");
12205 static cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12206         TOKEN_NUM_INITIALIZER
12207                 (struct cmd_macsec_sc_result,
12208                  port_id, RTE_UINT16);
12209 static cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12210         TOKEN_ETHERADDR_INITIALIZER
12211                 (struct cmd_macsec_sc_result,
12212                  mac);
12213 static cmdline_parse_token_num_t cmd_macsec_sc_pi =
12214         TOKEN_NUM_INITIALIZER
12215                 (struct cmd_macsec_sc_result,
12216                  pi, RTE_UINT16);
12217
12218 static void
12219 cmd_set_macsec_sc_parsed(
12220         void *parsed_result,
12221         __rte_unused struct cmdline *cl,
12222         __rte_unused void *data)
12223 {
12224         struct cmd_macsec_sc_result *res = parsed_result;
12225         int ret = -ENOTSUP;
12226         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12227
12228 #ifdef RTE_NET_IXGBE
12229         ret = is_tx ?
12230                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12231                                 res->mac.addr_bytes) :
12232                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12233                                 res->mac.addr_bytes, res->pi);
12234 #endif
12235         RTE_SET_USED(is_tx);
12236
12237         switch (ret) {
12238         case 0:
12239                 break;
12240         case -ENODEV:
12241                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12242                 break;
12243         case -ENOTSUP:
12244                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12245                 break;
12246         default:
12247                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12248         }
12249 }
12250
12251 static cmdline_parse_inst_t cmd_set_macsec_sc = {
12252         .f = cmd_set_macsec_sc_parsed,
12253         .data = NULL,
12254         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12255         .tokens = {
12256                 (void *)&cmd_macsec_sc_set,
12257                 (void *)&cmd_macsec_sc_macsec,
12258                 (void *)&cmd_macsec_sc_sc,
12259                 (void *)&cmd_macsec_sc_tx_rx,
12260                 (void *)&cmd_macsec_sc_port_id,
12261                 (void *)&cmd_macsec_sc_mac,
12262                 (void *)&cmd_macsec_sc_pi,
12263                 NULL,
12264         },
12265 };
12266
12267 /* Common result structure for MACsec secure connection configure */
12268 struct cmd_macsec_sa_result {
12269         cmdline_fixed_string_t set;
12270         cmdline_fixed_string_t macsec;
12271         cmdline_fixed_string_t sa;
12272         cmdline_fixed_string_t tx_rx;
12273         portid_t port_id;
12274         uint8_t idx;
12275         uint8_t an;
12276         uint32_t pn;
12277         cmdline_fixed_string_t key;
12278 };
12279
12280 /* Common CLI fields for MACsec secure connection configure */
12281 static cmdline_parse_token_string_t cmd_macsec_sa_set =
12282         TOKEN_STRING_INITIALIZER
12283                 (struct cmd_macsec_sa_result,
12284                  set, "set");
12285 static cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12286         TOKEN_STRING_INITIALIZER
12287                 (struct cmd_macsec_sa_result,
12288                  macsec, "macsec");
12289 static cmdline_parse_token_string_t cmd_macsec_sa_sa =
12290         TOKEN_STRING_INITIALIZER
12291                 (struct cmd_macsec_sa_result,
12292                  sa, "sa");
12293 static cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12294         TOKEN_STRING_INITIALIZER
12295                 (struct cmd_macsec_sa_result,
12296                  tx_rx, "tx#rx");
12297 static cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12298         TOKEN_NUM_INITIALIZER
12299                 (struct cmd_macsec_sa_result,
12300                  port_id, RTE_UINT16);
12301 static cmdline_parse_token_num_t cmd_macsec_sa_idx =
12302         TOKEN_NUM_INITIALIZER
12303                 (struct cmd_macsec_sa_result,
12304                  idx, RTE_UINT8);
12305 static cmdline_parse_token_num_t cmd_macsec_sa_an =
12306         TOKEN_NUM_INITIALIZER
12307                 (struct cmd_macsec_sa_result,
12308                  an, RTE_UINT8);
12309 static cmdline_parse_token_num_t cmd_macsec_sa_pn =
12310         TOKEN_NUM_INITIALIZER
12311                 (struct cmd_macsec_sa_result,
12312                  pn, RTE_UINT32);
12313 static cmdline_parse_token_string_t cmd_macsec_sa_key =
12314         TOKEN_STRING_INITIALIZER
12315                 (struct cmd_macsec_sa_result,
12316                  key, NULL);
12317
12318 static void
12319 cmd_set_macsec_sa_parsed(
12320         void *parsed_result,
12321         __rte_unused struct cmdline *cl,
12322         __rte_unused void *data)
12323 {
12324         struct cmd_macsec_sa_result *res = parsed_result;
12325         int ret = -ENOTSUP;
12326         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12327         uint8_t key[16] = { 0 };
12328         uint8_t xdgt0;
12329         uint8_t xdgt1;
12330         int key_len;
12331         int i;
12332
12333         key_len = strlen(res->key) / 2;
12334         if (key_len > 16)
12335                 key_len = 16;
12336
12337         for (i = 0; i < key_len; i++) {
12338                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12339                 if (xdgt0 == 0xFF)
12340                         return;
12341                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12342                 if (xdgt1 == 0xFF)
12343                         return;
12344                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12345         }
12346
12347 #ifdef RTE_NET_IXGBE
12348         ret = is_tx ?
12349                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12350                         res->idx, res->an, res->pn, key) :
12351                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12352                         res->idx, res->an, res->pn, key);
12353 #endif
12354         RTE_SET_USED(is_tx);
12355         RTE_SET_USED(key);
12356
12357         switch (ret) {
12358         case 0:
12359                 break;
12360         case -EINVAL:
12361                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12362                 break;
12363         case -ENODEV:
12364                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12365                 break;
12366         case -ENOTSUP:
12367                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12368                 break;
12369         default:
12370                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12371         }
12372 }
12373
12374 static cmdline_parse_inst_t cmd_set_macsec_sa = {
12375         .f = cmd_set_macsec_sa_parsed,
12376         .data = NULL,
12377         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12378         .tokens = {
12379                 (void *)&cmd_macsec_sa_set,
12380                 (void *)&cmd_macsec_sa_macsec,
12381                 (void *)&cmd_macsec_sa_sa,
12382                 (void *)&cmd_macsec_sa_tx_rx,
12383                 (void *)&cmd_macsec_sa_port_id,
12384                 (void *)&cmd_macsec_sa_idx,
12385                 (void *)&cmd_macsec_sa_an,
12386                 (void *)&cmd_macsec_sa_pn,
12387                 (void *)&cmd_macsec_sa_key,
12388                 NULL,
12389         },
12390 };
12391
12392 /* VF unicast promiscuous mode configuration */
12393
12394 /* Common result structure for VF unicast promiscuous mode */
12395 struct cmd_vf_promisc_result {
12396         cmdline_fixed_string_t set;
12397         cmdline_fixed_string_t vf;
12398         cmdline_fixed_string_t promisc;
12399         portid_t port_id;
12400         uint32_t vf_id;
12401         cmdline_fixed_string_t on_off;
12402 };
12403
12404 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12405 static cmdline_parse_token_string_t cmd_vf_promisc_set =
12406         TOKEN_STRING_INITIALIZER
12407                 (struct cmd_vf_promisc_result,
12408                  set, "set");
12409 static cmdline_parse_token_string_t cmd_vf_promisc_vf =
12410         TOKEN_STRING_INITIALIZER
12411                 (struct cmd_vf_promisc_result,
12412                  vf, "vf");
12413 static cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12414         TOKEN_STRING_INITIALIZER
12415                 (struct cmd_vf_promisc_result,
12416                  promisc, "promisc");
12417 static cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12418         TOKEN_NUM_INITIALIZER
12419                 (struct cmd_vf_promisc_result,
12420                  port_id, RTE_UINT16);
12421 static cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12422         TOKEN_NUM_INITIALIZER
12423                 (struct cmd_vf_promisc_result,
12424                  vf_id, RTE_UINT32);
12425 static cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12426         TOKEN_STRING_INITIALIZER
12427                 (struct cmd_vf_promisc_result,
12428                  on_off, "on#off");
12429
12430 static void
12431 cmd_set_vf_promisc_parsed(
12432         void *parsed_result,
12433         __rte_unused struct cmdline *cl,
12434         __rte_unused void *data)
12435 {
12436         struct cmd_vf_promisc_result *res = parsed_result;
12437         int ret = -ENOTSUP;
12438
12439         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12440
12441         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12442                 return;
12443
12444 #ifdef RTE_NET_I40E
12445         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12446                                                   res->vf_id, is_on);
12447 #endif
12448
12449         switch (ret) {
12450         case 0:
12451                 break;
12452         case -EINVAL:
12453                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12454                 break;
12455         case -ENODEV:
12456                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12457                 break;
12458         case -ENOTSUP:
12459                 fprintf(stderr, "function not implemented\n");
12460                 break;
12461         default:
12462                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12463         }
12464 }
12465
12466 static cmdline_parse_inst_t cmd_set_vf_promisc = {
12467         .f = cmd_set_vf_promisc_parsed,
12468         .data = NULL,
12469         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12470                 "Set unicast promiscuous mode for a VF from the PF",
12471         .tokens = {
12472                 (void *)&cmd_vf_promisc_set,
12473                 (void *)&cmd_vf_promisc_vf,
12474                 (void *)&cmd_vf_promisc_promisc,
12475                 (void *)&cmd_vf_promisc_port_id,
12476                 (void *)&cmd_vf_promisc_vf_id,
12477                 (void *)&cmd_vf_promisc_on_off,
12478                 NULL,
12479         },
12480 };
12481
12482 /* VF multicast promiscuous mode configuration */
12483
12484 /* Common result structure for VF multicast promiscuous mode */
12485 struct cmd_vf_allmulti_result {
12486         cmdline_fixed_string_t set;
12487         cmdline_fixed_string_t vf;
12488         cmdline_fixed_string_t allmulti;
12489         portid_t port_id;
12490         uint32_t vf_id;
12491         cmdline_fixed_string_t on_off;
12492 };
12493
12494 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12495 static cmdline_parse_token_string_t cmd_vf_allmulti_set =
12496         TOKEN_STRING_INITIALIZER
12497                 (struct cmd_vf_allmulti_result,
12498                  set, "set");
12499 static cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12500         TOKEN_STRING_INITIALIZER
12501                 (struct cmd_vf_allmulti_result,
12502                  vf, "vf");
12503 static cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12504         TOKEN_STRING_INITIALIZER
12505                 (struct cmd_vf_allmulti_result,
12506                  allmulti, "allmulti");
12507 static cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12508         TOKEN_NUM_INITIALIZER
12509                 (struct cmd_vf_allmulti_result,
12510                  port_id, RTE_UINT16);
12511 static cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12512         TOKEN_NUM_INITIALIZER
12513                 (struct cmd_vf_allmulti_result,
12514                  vf_id, RTE_UINT32);
12515 static cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12516         TOKEN_STRING_INITIALIZER
12517                 (struct cmd_vf_allmulti_result,
12518                  on_off, "on#off");
12519
12520 static void
12521 cmd_set_vf_allmulti_parsed(
12522         void *parsed_result,
12523         __rte_unused struct cmdline *cl,
12524         __rte_unused void *data)
12525 {
12526         struct cmd_vf_allmulti_result *res = parsed_result;
12527         int ret = -ENOTSUP;
12528
12529         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12530
12531         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12532                 return;
12533
12534 #ifdef RTE_NET_I40E
12535         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12536                                                     res->vf_id, is_on);
12537 #endif
12538
12539         switch (ret) {
12540         case 0:
12541                 break;
12542         case -EINVAL:
12543                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12544                 break;
12545         case -ENODEV:
12546                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12547                 break;
12548         case -ENOTSUP:
12549                 fprintf(stderr, "function not implemented\n");
12550                 break;
12551         default:
12552                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12553         }
12554 }
12555
12556 static cmdline_parse_inst_t cmd_set_vf_allmulti = {
12557         .f = cmd_set_vf_allmulti_parsed,
12558         .data = NULL,
12559         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12560                 "Set multicast promiscuous mode for a VF from the PF",
12561         .tokens = {
12562                 (void *)&cmd_vf_allmulti_set,
12563                 (void *)&cmd_vf_allmulti_vf,
12564                 (void *)&cmd_vf_allmulti_allmulti,
12565                 (void *)&cmd_vf_allmulti_port_id,
12566                 (void *)&cmd_vf_allmulti_vf_id,
12567                 (void *)&cmd_vf_allmulti_on_off,
12568                 NULL,
12569         },
12570 };
12571
12572 /* vf broadcast mode configuration */
12573
12574 /* Common result structure for vf broadcast */
12575 struct cmd_set_vf_broadcast_result {
12576         cmdline_fixed_string_t set;
12577         cmdline_fixed_string_t vf;
12578         cmdline_fixed_string_t broadcast;
12579         portid_t port_id;
12580         uint16_t vf_id;
12581         cmdline_fixed_string_t on_off;
12582 };
12583
12584 /* Common CLI fields for vf broadcast enable disable */
12585 static cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12586         TOKEN_STRING_INITIALIZER
12587                 (struct cmd_set_vf_broadcast_result,
12588                  set, "set");
12589 static cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12590         TOKEN_STRING_INITIALIZER
12591                 (struct cmd_set_vf_broadcast_result,
12592                  vf, "vf");
12593 static cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12594         TOKEN_STRING_INITIALIZER
12595                 (struct cmd_set_vf_broadcast_result,
12596                  broadcast, "broadcast");
12597 static cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12598         TOKEN_NUM_INITIALIZER
12599                 (struct cmd_set_vf_broadcast_result,
12600                  port_id, RTE_UINT16);
12601 static cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12602         TOKEN_NUM_INITIALIZER
12603                 (struct cmd_set_vf_broadcast_result,
12604                  vf_id, RTE_UINT16);
12605 static cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12606         TOKEN_STRING_INITIALIZER
12607                 (struct cmd_set_vf_broadcast_result,
12608                  on_off, "on#off");
12609
12610 static void
12611 cmd_set_vf_broadcast_parsed(
12612         void *parsed_result,
12613         __rte_unused struct cmdline *cl,
12614         __rte_unused void *data)
12615 {
12616         struct cmd_set_vf_broadcast_result *res = parsed_result;
12617         int ret = -ENOTSUP;
12618
12619         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12620
12621         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12622                 return;
12623
12624 #ifdef RTE_NET_I40E
12625         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12626                                             res->vf_id, is_on);
12627 #endif
12628
12629         switch (ret) {
12630         case 0:
12631                 break;
12632         case -EINVAL:
12633                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12634                         res->vf_id, is_on);
12635                 break;
12636         case -ENODEV:
12637                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12638                 break;
12639         case -ENOTSUP:
12640                 fprintf(stderr, "function not implemented\n");
12641                 break;
12642         default:
12643                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12644         }
12645 }
12646
12647 static cmdline_parse_inst_t cmd_set_vf_broadcast = {
12648         .f = cmd_set_vf_broadcast_parsed,
12649         .data = NULL,
12650         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12651         .tokens = {
12652                 (void *)&cmd_set_vf_broadcast_set,
12653                 (void *)&cmd_set_vf_broadcast_vf,
12654                 (void *)&cmd_set_vf_broadcast_broadcast,
12655                 (void *)&cmd_set_vf_broadcast_port_id,
12656                 (void *)&cmd_set_vf_broadcast_vf_id,
12657                 (void *)&cmd_set_vf_broadcast_on_off,
12658                 NULL,
12659         },
12660 };
12661
12662 /* vf vlan tag configuration */
12663
12664 /* Common result structure for vf vlan tag */
12665 struct cmd_set_vf_vlan_tag_result {
12666         cmdline_fixed_string_t set;
12667         cmdline_fixed_string_t vf;
12668         cmdline_fixed_string_t vlan;
12669         cmdline_fixed_string_t tag;
12670         portid_t port_id;
12671         uint16_t vf_id;
12672         cmdline_fixed_string_t on_off;
12673 };
12674
12675 /* Common CLI fields for vf vlan tag enable disable */
12676 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12677         TOKEN_STRING_INITIALIZER
12678                 (struct cmd_set_vf_vlan_tag_result,
12679                  set, "set");
12680 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12681         TOKEN_STRING_INITIALIZER
12682                 (struct cmd_set_vf_vlan_tag_result,
12683                  vf, "vf");
12684 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12685         TOKEN_STRING_INITIALIZER
12686                 (struct cmd_set_vf_vlan_tag_result,
12687                  vlan, "vlan");
12688 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12689         TOKEN_STRING_INITIALIZER
12690                 (struct cmd_set_vf_vlan_tag_result,
12691                  tag, "tag");
12692 static cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12693         TOKEN_NUM_INITIALIZER
12694                 (struct cmd_set_vf_vlan_tag_result,
12695                  port_id, RTE_UINT16);
12696 static cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12697         TOKEN_NUM_INITIALIZER
12698                 (struct cmd_set_vf_vlan_tag_result,
12699                  vf_id, RTE_UINT16);
12700 static cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12701         TOKEN_STRING_INITIALIZER
12702                 (struct cmd_set_vf_vlan_tag_result,
12703                  on_off, "on#off");
12704
12705 static void
12706 cmd_set_vf_vlan_tag_parsed(
12707         void *parsed_result,
12708         __rte_unused struct cmdline *cl,
12709         __rte_unused void *data)
12710 {
12711         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12712         int ret = -ENOTSUP;
12713
12714         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12715
12716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12717                 return;
12718
12719 #ifdef RTE_NET_I40E
12720         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12721                                            res->vf_id, is_on);
12722 #endif
12723
12724         switch (ret) {
12725         case 0:
12726                 break;
12727         case -EINVAL:
12728                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12729                         res->vf_id, is_on);
12730                 break;
12731         case -ENODEV:
12732                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12733                 break;
12734         case -ENOTSUP:
12735                 fprintf(stderr, "function not implemented\n");
12736                 break;
12737         default:
12738                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12739         }
12740 }
12741
12742 static cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12743         .f = cmd_set_vf_vlan_tag_parsed,
12744         .data = NULL,
12745         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12746         .tokens = {
12747                 (void *)&cmd_set_vf_vlan_tag_set,
12748                 (void *)&cmd_set_vf_vlan_tag_vf,
12749                 (void *)&cmd_set_vf_vlan_tag_vlan,
12750                 (void *)&cmd_set_vf_vlan_tag_tag,
12751                 (void *)&cmd_set_vf_vlan_tag_port_id,
12752                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12753                 (void *)&cmd_set_vf_vlan_tag_on_off,
12754                 NULL,
12755         },
12756 };
12757
12758 /* Common definition of VF and TC TX bandwidth configuration */
12759 struct cmd_vf_tc_bw_result {
12760         cmdline_fixed_string_t set;
12761         cmdline_fixed_string_t vf;
12762         cmdline_fixed_string_t tc;
12763         cmdline_fixed_string_t tx;
12764         cmdline_fixed_string_t min_bw;
12765         cmdline_fixed_string_t max_bw;
12766         cmdline_fixed_string_t strict_link_prio;
12767         portid_t port_id;
12768         uint16_t vf_id;
12769         uint8_t tc_no;
12770         uint32_t bw;
12771         cmdline_fixed_string_t bw_list;
12772         uint8_t tc_map;
12773 };
12774
12775 static cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12776         TOKEN_STRING_INITIALIZER
12777                 (struct cmd_vf_tc_bw_result,
12778                  set, "set");
12779 static cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12780         TOKEN_STRING_INITIALIZER
12781                 (struct cmd_vf_tc_bw_result,
12782                  vf, "vf");
12783 static cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12784         TOKEN_STRING_INITIALIZER
12785                 (struct cmd_vf_tc_bw_result,
12786                  tc, "tc");
12787 static cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12788         TOKEN_STRING_INITIALIZER
12789                 (struct cmd_vf_tc_bw_result,
12790                  tx, "tx");
12791 static cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12792         TOKEN_STRING_INITIALIZER
12793                 (struct cmd_vf_tc_bw_result,
12794                  strict_link_prio, "strict-link-priority");
12795 static cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12796         TOKEN_STRING_INITIALIZER
12797                 (struct cmd_vf_tc_bw_result,
12798                  min_bw, "min-bandwidth");
12799 static cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12800         TOKEN_STRING_INITIALIZER
12801                 (struct cmd_vf_tc_bw_result,
12802                  max_bw, "max-bandwidth");
12803 static cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12804         TOKEN_NUM_INITIALIZER
12805                 (struct cmd_vf_tc_bw_result,
12806                  port_id, RTE_UINT16);
12807 static cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12808         TOKEN_NUM_INITIALIZER
12809                 (struct cmd_vf_tc_bw_result,
12810                  vf_id, RTE_UINT16);
12811 static cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12812         TOKEN_NUM_INITIALIZER
12813                 (struct cmd_vf_tc_bw_result,
12814                  tc_no, RTE_UINT8);
12815 static cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12816         TOKEN_NUM_INITIALIZER
12817                 (struct cmd_vf_tc_bw_result,
12818                  bw, RTE_UINT32);
12819 static cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12820         TOKEN_STRING_INITIALIZER
12821                 (struct cmd_vf_tc_bw_result,
12822                  bw_list, NULL);
12823 static cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12824         TOKEN_NUM_INITIALIZER
12825                 (struct cmd_vf_tc_bw_result,
12826                  tc_map, RTE_UINT8);
12827
12828 /* VF max bandwidth setting */
12829 static void
12830 cmd_vf_max_bw_parsed(
12831         void *parsed_result,
12832         __rte_unused struct cmdline *cl,
12833         __rte_unused void *data)
12834 {
12835         struct cmd_vf_tc_bw_result *res = parsed_result;
12836         int ret = -ENOTSUP;
12837
12838         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12839                 return;
12840
12841 #ifdef RTE_NET_I40E
12842         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12843                                          res->vf_id, res->bw);
12844 #endif
12845
12846         switch (ret) {
12847         case 0:
12848                 break;
12849         case -EINVAL:
12850                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12851                         res->vf_id, res->bw);
12852                 break;
12853         case -ENODEV:
12854                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12855                 break;
12856         case -ENOTSUP:
12857                 fprintf(stderr, "function not implemented\n");
12858                 break;
12859         default:
12860                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12861         }
12862 }
12863
12864 static cmdline_parse_inst_t cmd_vf_max_bw = {
12865         .f = cmd_vf_max_bw_parsed,
12866         .data = NULL,
12867         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12868         .tokens = {
12869                 (void *)&cmd_vf_tc_bw_set,
12870                 (void *)&cmd_vf_tc_bw_vf,
12871                 (void *)&cmd_vf_tc_bw_tx,
12872                 (void *)&cmd_vf_tc_bw_max_bw,
12873                 (void *)&cmd_vf_tc_bw_port_id,
12874                 (void *)&cmd_vf_tc_bw_vf_id,
12875                 (void *)&cmd_vf_tc_bw_bw,
12876                 NULL,
12877         },
12878 };
12879
12880 static int
12881 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12882                            uint8_t *tc_num,
12883                            char *str)
12884 {
12885         uint32_t size;
12886         const char *p, *p0 = str;
12887         char s[256];
12888         char *end;
12889         char *str_fld[16];
12890         uint16_t i;
12891         int ret;
12892
12893         p = strchr(p0, '(');
12894         if (p == NULL) {
12895                 fprintf(stderr,
12896                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12897                 return -1;
12898         }
12899         p++;
12900         p0 = strchr(p, ')');
12901         if (p0 == NULL) {
12902                 fprintf(stderr,
12903                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12904                 return -1;
12905         }
12906         size = p0 - p;
12907         if (size >= sizeof(s)) {
12908                 fprintf(stderr,
12909                         "The string size exceeds the internal buffer size\n");
12910                 return -1;
12911         }
12912         snprintf(s, sizeof(s), "%.*s", size, p);
12913         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12914         if (ret <= 0) {
12915                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12916                 return -1;
12917         }
12918         *tc_num = ret;
12919         for (i = 0; i < ret; i++)
12920                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12921
12922         return 0;
12923 }
12924
12925 /* TC min bandwidth setting */
12926 static void
12927 cmd_vf_tc_min_bw_parsed(
12928         void *parsed_result,
12929         __rte_unused struct cmdline *cl,
12930         __rte_unused void *data)
12931 {
12932         struct cmd_vf_tc_bw_result *res = parsed_result;
12933         uint8_t tc_num;
12934         uint8_t bw[16];
12935         int ret = -ENOTSUP;
12936
12937         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12938                 return;
12939
12940         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12941         if (ret)
12942                 return;
12943
12944 #ifdef RTE_NET_I40E
12945         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12946                                               tc_num, bw);
12947 #endif
12948
12949         switch (ret) {
12950         case 0:
12951                 break;
12952         case -EINVAL:
12953                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12954                 break;
12955         case -ENODEV:
12956                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12957                 break;
12958         case -ENOTSUP:
12959                 fprintf(stderr, "function not implemented\n");
12960                 break;
12961         default:
12962                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12963         }
12964 }
12965
12966 static cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12967         .f = cmd_vf_tc_min_bw_parsed,
12968         .data = NULL,
12969         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12970                     " <bw1, bw2, ...>",
12971         .tokens = {
12972                 (void *)&cmd_vf_tc_bw_set,
12973                 (void *)&cmd_vf_tc_bw_vf,
12974                 (void *)&cmd_vf_tc_bw_tc,
12975                 (void *)&cmd_vf_tc_bw_tx,
12976                 (void *)&cmd_vf_tc_bw_min_bw,
12977                 (void *)&cmd_vf_tc_bw_port_id,
12978                 (void *)&cmd_vf_tc_bw_vf_id,
12979                 (void *)&cmd_vf_tc_bw_bw_list,
12980                 NULL,
12981         },
12982 };
12983
12984 static void
12985 cmd_tc_min_bw_parsed(
12986         void *parsed_result,
12987         __rte_unused struct cmdline *cl,
12988         __rte_unused void *data)
12989 {
12990         struct cmd_vf_tc_bw_result *res = parsed_result;
12991         struct rte_port *port;
12992         uint8_t tc_num;
12993         uint8_t bw[16];
12994         int ret = -ENOTSUP;
12995
12996         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12997                 return;
12998
12999         port = &ports[res->port_id];
13000         /** Check if the port is not started **/
13001         if (port->port_status != RTE_PORT_STOPPED) {
13002                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
13003                 return;
13004         }
13005
13006         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13007         if (ret)
13008                 return;
13009
13010 #ifdef RTE_NET_IXGBE
13011         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13012 #endif
13013
13014         switch (ret) {
13015         case 0:
13016                 break;
13017         case -EINVAL:
13018                 fprintf(stderr, "invalid bandwidth\n");
13019                 break;
13020         case -ENODEV:
13021                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13022                 break;
13023         case -ENOTSUP:
13024                 fprintf(stderr, "function not implemented\n");
13025                 break;
13026         default:
13027                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13028         }
13029 }
13030
13031 static cmdline_parse_inst_t cmd_tc_min_bw = {
13032         .f = cmd_tc_min_bw_parsed,
13033         .data = NULL,
13034         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13035         .tokens = {
13036                 (void *)&cmd_vf_tc_bw_set,
13037                 (void *)&cmd_vf_tc_bw_tc,
13038                 (void *)&cmd_vf_tc_bw_tx,
13039                 (void *)&cmd_vf_tc_bw_min_bw,
13040                 (void *)&cmd_vf_tc_bw_port_id,
13041                 (void *)&cmd_vf_tc_bw_bw_list,
13042                 NULL,
13043         },
13044 };
13045
13046 /* TC max bandwidth setting */
13047 static void
13048 cmd_vf_tc_max_bw_parsed(
13049         void *parsed_result,
13050         __rte_unused struct cmdline *cl,
13051         __rte_unused void *data)
13052 {
13053         struct cmd_vf_tc_bw_result *res = parsed_result;
13054         int ret = -ENOTSUP;
13055
13056         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13057                 return;
13058
13059 #ifdef RTE_NET_I40E
13060         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13061                                             res->tc_no, res->bw);
13062 #endif
13063
13064         switch (ret) {
13065         case 0:
13066                 break;
13067         case -EINVAL:
13068                 fprintf(stderr,
13069                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
13070                         res->vf_id, res->tc_no, res->bw);
13071                 break;
13072         case -ENODEV:
13073                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13074                 break;
13075         case -ENOTSUP:
13076                 fprintf(stderr, "function not implemented\n");
13077                 break;
13078         default:
13079                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13080         }
13081 }
13082
13083 static cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13084         .f = cmd_vf_tc_max_bw_parsed,
13085         .data = NULL,
13086         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13087                     " <bandwidth>",
13088         .tokens = {
13089                 (void *)&cmd_vf_tc_bw_set,
13090                 (void *)&cmd_vf_tc_bw_vf,
13091                 (void *)&cmd_vf_tc_bw_tc,
13092                 (void *)&cmd_vf_tc_bw_tx,
13093                 (void *)&cmd_vf_tc_bw_max_bw,
13094                 (void *)&cmd_vf_tc_bw_port_id,
13095                 (void *)&cmd_vf_tc_bw_vf_id,
13096                 (void *)&cmd_vf_tc_bw_tc_no,
13097                 (void *)&cmd_vf_tc_bw_bw,
13098                 NULL,
13099         },
13100 };
13101
13102 /** Set VXLAN encapsulation details */
13103 struct cmd_set_vxlan_result {
13104         cmdline_fixed_string_t set;
13105         cmdline_fixed_string_t vxlan;
13106         cmdline_fixed_string_t pos_token;
13107         cmdline_fixed_string_t ip_version;
13108         uint32_t vlan_present:1;
13109         uint32_t vni;
13110         uint16_t udp_src;
13111         uint16_t udp_dst;
13112         cmdline_ipaddr_t ip_src;
13113         cmdline_ipaddr_t ip_dst;
13114         uint16_t tci;
13115         uint8_t tos;
13116         uint8_t ttl;
13117         struct rte_ether_addr eth_src;
13118         struct rte_ether_addr eth_dst;
13119 };
13120
13121 static cmdline_parse_token_string_t cmd_set_vxlan_set =
13122         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13123 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13124         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13125 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13126         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13127                                  "vxlan-tos-ttl");
13128 static cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13129         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13130                                  "vxlan-with-vlan");
13131 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13132         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13133                                  "ip-version");
13134 static cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13135         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13136                                  "ipv4#ipv6");
13137 static cmdline_parse_token_string_t cmd_set_vxlan_vni =
13138         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13139                                  "vni");
13140 static cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13141         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13142 static cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13143         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13144                                  "udp-src");
13145 static cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13146         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13147 static cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13148         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13149                                  "udp-dst");
13150 static cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13151         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13152 static cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13153         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13154                                  "ip-tos");
13155 static cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13156         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13157 static cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13158         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13159                                  "ip-ttl");
13160 static cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13161         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13162 static cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13163         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13164                                  "ip-src");
13165 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13166         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13167 static cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13168         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13169                                  "ip-dst");
13170 static cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13171         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13172 static cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13173         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13174                                  "vlan-tci");
13175 static cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13176         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13177 static cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13178         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13179                                  "eth-src");
13180 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13181         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13182 static cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13183         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13184                                  "eth-dst");
13185 static cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13186         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13187
13188 static void cmd_set_vxlan_parsed(void *parsed_result,
13189         __rte_unused struct cmdline *cl,
13190         __rte_unused void *data)
13191 {
13192         struct cmd_set_vxlan_result *res = parsed_result;
13193         union {
13194                 uint32_t vxlan_id;
13195                 uint8_t vni[4];
13196         } id = {
13197                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13198         };
13199
13200         vxlan_encap_conf.select_tos_ttl = 0;
13201         if (strcmp(res->vxlan, "vxlan") == 0)
13202                 vxlan_encap_conf.select_vlan = 0;
13203         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13204                 vxlan_encap_conf.select_vlan = 1;
13205         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13206                 vxlan_encap_conf.select_vlan = 0;
13207                 vxlan_encap_conf.select_tos_ttl = 1;
13208         }
13209         if (strcmp(res->ip_version, "ipv4") == 0)
13210                 vxlan_encap_conf.select_ipv4 = 1;
13211         else if (strcmp(res->ip_version, "ipv6") == 0)
13212                 vxlan_encap_conf.select_ipv4 = 0;
13213         else
13214                 return;
13215         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13216         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13217         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13218         vxlan_encap_conf.ip_tos = res->tos;
13219         vxlan_encap_conf.ip_ttl = res->ttl;
13220         if (vxlan_encap_conf.select_ipv4) {
13221                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13222                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13223         } else {
13224                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13225                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13226         }
13227         if (vxlan_encap_conf.select_vlan)
13228                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13229         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13230                    RTE_ETHER_ADDR_LEN);
13231         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13232                    RTE_ETHER_ADDR_LEN);
13233 }
13234
13235 static cmdline_parse_inst_t cmd_set_vxlan = {
13236         .f = cmd_set_vxlan_parsed,
13237         .data = NULL,
13238         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13239                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13240                 " eth-src <eth-src> eth-dst <eth-dst>",
13241         .tokens = {
13242                 (void *)&cmd_set_vxlan_set,
13243                 (void *)&cmd_set_vxlan_vxlan,
13244                 (void *)&cmd_set_vxlan_ip_version,
13245                 (void *)&cmd_set_vxlan_ip_version_value,
13246                 (void *)&cmd_set_vxlan_vni,
13247                 (void *)&cmd_set_vxlan_vni_value,
13248                 (void *)&cmd_set_vxlan_udp_src,
13249                 (void *)&cmd_set_vxlan_udp_src_value,
13250                 (void *)&cmd_set_vxlan_udp_dst,
13251                 (void *)&cmd_set_vxlan_udp_dst_value,
13252                 (void *)&cmd_set_vxlan_ip_src,
13253                 (void *)&cmd_set_vxlan_ip_src_value,
13254                 (void *)&cmd_set_vxlan_ip_dst,
13255                 (void *)&cmd_set_vxlan_ip_dst_value,
13256                 (void *)&cmd_set_vxlan_eth_src,
13257                 (void *)&cmd_set_vxlan_eth_src_value,
13258                 (void *)&cmd_set_vxlan_eth_dst,
13259                 (void *)&cmd_set_vxlan_eth_dst_value,
13260                 NULL,
13261         },
13262 };
13263
13264 static cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13265         .f = cmd_set_vxlan_parsed,
13266         .data = NULL,
13267         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13268                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13269                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13270                 " eth-dst <eth-dst>",
13271         .tokens = {
13272                 (void *)&cmd_set_vxlan_set,
13273                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13274                 (void *)&cmd_set_vxlan_ip_version,
13275                 (void *)&cmd_set_vxlan_ip_version_value,
13276                 (void *)&cmd_set_vxlan_vni,
13277                 (void *)&cmd_set_vxlan_vni_value,
13278                 (void *)&cmd_set_vxlan_udp_src,
13279                 (void *)&cmd_set_vxlan_udp_src_value,
13280                 (void *)&cmd_set_vxlan_udp_dst,
13281                 (void *)&cmd_set_vxlan_udp_dst_value,
13282                 (void *)&cmd_set_vxlan_ip_tos,
13283                 (void *)&cmd_set_vxlan_ip_tos_value,
13284                 (void *)&cmd_set_vxlan_ip_ttl,
13285                 (void *)&cmd_set_vxlan_ip_ttl_value,
13286                 (void *)&cmd_set_vxlan_ip_src,
13287                 (void *)&cmd_set_vxlan_ip_src_value,
13288                 (void *)&cmd_set_vxlan_ip_dst,
13289                 (void *)&cmd_set_vxlan_ip_dst_value,
13290                 (void *)&cmd_set_vxlan_eth_src,
13291                 (void *)&cmd_set_vxlan_eth_src_value,
13292                 (void *)&cmd_set_vxlan_eth_dst,
13293                 (void *)&cmd_set_vxlan_eth_dst_value,
13294                 NULL,
13295         },
13296 };
13297
13298 static cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13299         .f = cmd_set_vxlan_parsed,
13300         .data = NULL,
13301         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13302                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13303                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13304                 " <eth-dst>",
13305         .tokens = {
13306                 (void *)&cmd_set_vxlan_set,
13307                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13308                 (void *)&cmd_set_vxlan_ip_version,
13309                 (void *)&cmd_set_vxlan_ip_version_value,
13310                 (void *)&cmd_set_vxlan_vni,
13311                 (void *)&cmd_set_vxlan_vni_value,
13312                 (void *)&cmd_set_vxlan_udp_src,
13313                 (void *)&cmd_set_vxlan_udp_src_value,
13314                 (void *)&cmd_set_vxlan_udp_dst,
13315                 (void *)&cmd_set_vxlan_udp_dst_value,
13316                 (void *)&cmd_set_vxlan_ip_src,
13317                 (void *)&cmd_set_vxlan_ip_src_value,
13318                 (void *)&cmd_set_vxlan_ip_dst,
13319                 (void *)&cmd_set_vxlan_ip_dst_value,
13320                 (void *)&cmd_set_vxlan_vlan,
13321                 (void *)&cmd_set_vxlan_vlan_value,
13322                 (void *)&cmd_set_vxlan_eth_src,
13323                 (void *)&cmd_set_vxlan_eth_src_value,
13324                 (void *)&cmd_set_vxlan_eth_dst,
13325                 (void *)&cmd_set_vxlan_eth_dst_value,
13326                 NULL,
13327         },
13328 };
13329
13330 /** Set NVGRE encapsulation details */
13331 struct cmd_set_nvgre_result {
13332         cmdline_fixed_string_t set;
13333         cmdline_fixed_string_t nvgre;
13334         cmdline_fixed_string_t pos_token;
13335         cmdline_fixed_string_t ip_version;
13336         uint32_t tni;
13337         cmdline_ipaddr_t ip_src;
13338         cmdline_ipaddr_t ip_dst;
13339         uint16_t tci;
13340         struct rte_ether_addr eth_src;
13341         struct rte_ether_addr eth_dst;
13342 };
13343
13344 static cmdline_parse_token_string_t cmd_set_nvgre_set =
13345         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13346 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13347         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13348 static cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13349         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13350                                  "nvgre-with-vlan");
13351 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13352         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13353                                  "ip-version");
13354 static cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13355         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13356                                  "ipv4#ipv6");
13357 static cmdline_parse_token_string_t cmd_set_nvgre_tni =
13358         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13359                                  "tni");
13360 static cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13361         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13362 static cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13363         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13364                                  "ip-src");
13365 static cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13366         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13367 static cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13368         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13369                                  "ip-dst");
13370 static cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13371         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13372 static cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13373         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13374                                  "vlan-tci");
13375 static cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13376         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13377 static cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13378         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13379                                  "eth-src");
13380 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13381         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13382 static cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13383         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13384                                  "eth-dst");
13385 static cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13386         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13387
13388 static void cmd_set_nvgre_parsed(void *parsed_result,
13389         __rte_unused struct cmdline *cl,
13390         __rte_unused void *data)
13391 {
13392         struct cmd_set_nvgre_result *res = parsed_result;
13393         union {
13394                 uint32_t nvgre_tni;
13395                 uint8_t tni[4];
13396         } id = {
13397                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13398         };
13399
13400         if (strcmp(res->nvgre, "nvgre") == 0)
13401                 nvgre_encap_conf.select_vlan = 0;
13402         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13403                 nvgre_encap_conf.select_vlan = 1;
13404         if (strcmp(res->ip_version, "ipv4") == 0)
13405                 nvgre_encap_conf.select_ipv4 = 1;
13406         else if (strcmp(res->ip_version, "ipv6") == 0)
13407                 nvgre_encap_conf.select_ipv4 = 0;
13408         else
13409                 return;
13410         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13411         if (nvgre_encap_conf.select_ipv4) {
13412                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13413                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13414         } else {
13415                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13416                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13417         }
13418         if (nvgre_encap_conf.select_vlan)
13419                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13420         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13421                    RTE_ETHER_ADDR_LEN);
13422         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13423                    RTE_ETHER_ADDR_LEN);
13424 }
13425
13426 static cmdline_parse_inst_t cmd_set_nvgre = {
13427         .f = cmd_set_nvgre_parsed,
13428         .data = NULL,
13429         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13430                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13431                 " eth-dst <eth-dst>",
13432         .tokens = {
13433                 (void *)&cmd_set_nvgre_set,
13434                 (void *)&cmd_set_nvgre_nvgre,
13435                 (void *)&cmd_set_nvgre_ip_version,
13436                 (void *)&cmd_set_nvgre_ip_version_value,
13437                 (void *)&cmd_set_nvgre_tni,
13438                 (void *)&cmd_set_nvgre_tni_value,
13439                 (void *)&cmd_set_nvgre_ip_src,
13440                 (void *)&cmd_set_nvgre_ip_src_value,
13441                 (void *)&cmd_set_nvgre_ip_dst,
13442                 (void *)&cmd_set_nvgre_ip_dst_value,
13443                 (void *)&cmd_set_nvgre_eth_src,
13444                 (void *)&cmd_set_nvgre_eth_src_value,
13445                 (void *)&cmd_set_nvgre_eth_dst,
13446                 (void *)&cmd_set_nvgre_eth_dst_value,
13447                 NULL,
13448         },
13449 };
13450
13451 static cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13452         .f = cmd_set_nvgre_parsed,
13453         .data = NULL,
13454         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13455                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13456                 " eth-src <eth-src> eth-dst <eth-dst>",
13457         .tokens = {
13458                 (void *)&cmd_set_nvgre_set,
13459                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13460                 (void *)&cmd_set_nvgre_ip_version,
13461                 (void *)&cmd_set_nvgre_ip_version_value,
13462                 (void *)&cmd_set_nvgre_tni,
13463                 (void *)&cmd_set_nvgre_tni_value,
13464                 (void *)&cmd_set_nvgre_ip_src,
13465                 (void *)&cmd_set_nvgre_ip_src_value,
13466                 (void *)&cmd_set_nvgre_ip_dst,
13467                 (void *)&cmd_set_nvgre_ip_dst_value,
13468                 (void *)&cmd_set_nvgre_vlan,
13469                 (void *)&cmd_set_nvgre_vlan_value,
13470                 (void *)&cmd_set_nvgre_eth_src,
13471                 (void *)&cmd_set_nvgre_eth_src_value,
13472                 (void *)&cmd_set_nvgre_eth_dst,
13473                 (void *)&cmd_set_nvgre_eth_dst_value,
13474                 NULL,
13475         },
13476 };
13477
13478 /** Set L2 encapsulation details */
13479 struct cmd_set_l2_encap_result {
13480         cmdline_fixed_string_t set;
13481         cmdline_fixed_string_t l2_encap;
13482         cmdline_fixed_string_t pos_token;
13483         cmdline_fixed_string_t ip_version;
13484         uint32_t vlan_present:1;
13485         uint16_t tci;
13486         struct rte_ether_addr eth_src;
13487         struct rte_ether_addr eth_dst;
13488 };
13489
13490 static cmdline_parse_token_string_t cmd_set_l2_encap_set =
13491         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13492 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13493         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13494 static cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13495         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13496                                  "l2_encap-with-vlan");
13497 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13498         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13499                                  "ip-version");
13500 static cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13501         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13502                                  "ipv4#ipv6");
13503 static cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13504         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13505                                  "vlan-tci");
13506 static cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13507         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13508 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13509         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13510                                  "eth-src");
13511 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13512         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13513 static cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13514         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13515                                  "eth-dst");
13516 static cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13517         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13518
13519 static void cmd_set_l2_encap_parsed(void *parsed_result,
13520         __rte_unused struct cmdline *cl,
13521         __rte_unused void *data)
13522 {
13523         struct cmd_set_l2_encap_result *res = parsed_result;
13524
13525         if (strcmp(res->l2_encap, "l2_encap") == 0)
13526                 l2_encap_conf.select_vlan = 0;
13527         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13528                 l2_encap_conf.select_vlan = 1;
13529         if (strcmp(res->ip_version, "ipv4") == 0)
13530                 l2_encap_conf.select_ipv4 = 1;
13531         else if (strcmp(res->ip_version, "ipv6") == 0)
13532                 l2_encap_conf.select_ipv4 = 0;
13533         else
13534                 return;
13535         if (l2_encap_conf.select_vlan)
13536                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13537         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13538                    RTE_ETHER_ADDR_LEN);
13539         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13540                    RTE_ETHER_ADDR_LEN);
13541 }
13542
13543 static cmdline_parse_inst_t cmd_set_l2_encap = {
13544         .f = cmd_set_l2_encap_parsed,
13545         .data = NULL,
13546         .help_str = "set l2_encap ip-version ipv4|ipv6"
13547                 " eth-src <eth-src> eth-dst <eth-dst>",
13548         .tokens = {
13549                 (void *)&cmd_set_l2_encap_set,
13550                 (void *)&cmd_set_l2_encap_l2_encap,
13551                 (void *)&cmd_set_l2_encap_ip_version,
13552                 (void *)&cmd_set_l2_encap_ip_version_value,
13553                 (void *)&cmd_set_l2_encap_eth_src,
13554                 (void *)&cmd_set_l2_encap_eth_src_value,
13555                 (void *)&cmd_set_l2_encap_eth_dst,
13556                 (void *)&cmd_set_l2_encap_eth_dst_value,
13557                 NULL,
13558         },
13559 };
13560
13561 static cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13562         .f = cmd_set_l2_encap_parsed,
13563         .data = NULL,
13564         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13565                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13566         .tokens = {
13567                 (void *)&cmd_set_l2_encap_set,
13568                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13569                 (void *)&cmd_set_l2_encap_ip_version,
13570                 (void *)&cmd_set_l2_encap_ip_version_value,
13571                 (void *)&cmd_set_l2_encap_vlan,
13572                 (void *)&cmd_set_l2_encap_vlan_value,
13573                 (void *)&cmd_set_l2_encap_eth_src,
13574                 (void *)&cmd_set_l2_encap_eth_src_value,
13575                 (void *)&cmd_set_l2_encap_eth_dst,
13576                 (void *)&cmd_set_l2_encap_eth_dst_value,
13577                 NULL,
13578         },
13579 };
13580
13581 /** Set L2 decapsulation details */
13582 struct cmd_set_l2_decap_result {
13583         cmdline_fixed_string_t set;
13584         cmdline_fixed_string_t l2_decap;
13585         cmdline_fixed_string_t pos_token;
13586         uint32_t vlan_present:1;
13587 };
13588
13589 static cmdline_parse_token_string_t cmd_set_l2_decap_set =
13590         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13591 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13592         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13593                                  "l2_decap");
13594 static cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13595         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13596                                  "l2_decap-with-vlan");
13597
13598 static void cmd_set_l2_decap_parsed(void *parsed_result,
13599         __rte_unused struct cmdline *cl,
13600         __rte_unused void *data)
13601 {
13602         struct cmd_set_l2_decap_result *res = parsed_result;
13603
13604         if (strcmp(res->l2_decap, "l2_decap") == 0)
13605                 l2_decap_conf.select_vlan = 0;
13606         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13607                 l2_decap_conf.select_vlan = 1;
13608 }
13609
13610 static cmdline_parse_inst_t cmd_set_l2_decap = {
13611         .f = cmd_set_l2_decap_parsed,
13612         .data = NULL,
13613         .help_str = "set l2_decap",
13614         .tokens = {
13615                 (void *)&cmd_set_l2_decap_set,
13616                 (void *)&cmd_set_l2_decap_l2_decap,
13617                 NULL,
13618         },
13619 };
13620
13621 static cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13622         .f = cmd_set_l2_decap_parsed,
13623         .data = NULL,
13624         .help_str = "set l2_decap-with-vlan",
13625         .tokens = {
13626                 (void *)&cmd_set_l2_decap_set,
13627                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13628                 NULL,
13629         },
13630 };
13631
13632 /** Set MPLSoGRE encapsulation details */
13633 struct cmd_set_mplsogre_encap_result {
13634         cmdline_fixed_string_t set;
13635         cmdline_fixed_string_t mplsogre;
13636         cmdline_fixed_string_t pos_token;
13637         cmdline_fixed_string_t ip_version;
13638         uint32_t vlan_present:1;
13639         uint32_t label;
13640         cmdline_ipaddr_t ip_src;
13641         cmdline_ipaddr_t ip_dst;
13642         uint16_t tci;
13643         struct rte_ether_addr eth_src;
13644         struct rte_ether_addr eth_dst;
13645 };
13646
13647 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13648         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13649                                  "set");
13650 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13651         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13652                                  "mplsogre_encap");
13653 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13654         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13655                                  mplsogre, "mplsogre_encap-with-vlan");
13656 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13657         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13658                                  pos_token, "ip-version");
13659 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13660         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13661                                  ip_version, "ipv4#ipv6");
13662 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13663         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13664                                  pos_token, "label");
13665 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13666         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13667                               RTE_UINT32);
13668 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13669         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13670                                  pos_token, "ip-src");
13671 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13672         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13673 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13674         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13675                                  pos_token, "ip-dst");
13676 static cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13677         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13678 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13679         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13680                                  pos_token, "vlan-tci");
13681 static cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13682         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13683                               RTE_UINT16);
13684 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13685         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13686                                  pos_token, "eth-src");
13687 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13688         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13689                                     eth_src);
13690 static cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13691         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13692                                  pos_token, "eth-dst");
13693 static cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13694         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13695                                     eth_dst);
13696
13697 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13698         __rte_unused struct cmdline *cl,
13699         __rte_unused void *data)
13700 {
13701         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13702         union {
13703                 uint32_t mplsogre_label;
13704                 uint8_t label[4];
13705         } id = {
13706                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13707         };
13708
13709         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13710                 mplsogre_encap_conf.select_vlan = 0;
13711         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13712                 mplsogre_encap_conf.select_vlan = 1;
13713         if (strcmp(res->ip_version, "ipv4") == 0)
13714                 mplsogre_encap_conf.select_ipv4 = 1;
13715         else if (strcmp(res->ip_version, "ipv6") == 0)
13716                 mplsogre_encap_conf.select_ipv4 = 0;
13717         else
13718                 return;
13719         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13720         if (mplsogre_encap_conf.select_ipv4) {
13721                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13722                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13723         } else {
13724                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13725                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13726         }
13727         if (mplsogre_encap_conf.select_vlan)
13728                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13729         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13730                    RTE_ETHER_ADDR_LEN);
13731         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13732                    RTE_ETHER_ADDR_LEN);
13733 }
13734
13735 static cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13736         .f = cmd_set_mplsogre_encap_parsed,
13737         .data = NULL,
13738         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13739                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13740                 " eth-dst <eth-dst>",
13741         .tokens = {
13742                 (void *)&cmd_set_mplsogre_encap_set,
13743                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13744                 (void *)&cmd_set_mplsogre_encap_ip_version,
13745                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13746                 (void *)&cmd_set_mplsogre_encap_label,
13747                 (void *)&cmd_set_mplsogre_encap_label_value,
13748                 (void *)&cmd_set_mplsogre_encap_ip_src,
13749                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13750                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13751                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13752                 (void *)&cmd_set_mplsogre_encap_eth_src,
13753                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13754                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13755                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13756                 NULL,
13757         },
13758 };
13759
13760 static cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13761         .f = cmd_set_mplsogre_encap_parsed,
13762         .data = NULL,
13763         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13764                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13765                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13766         .tokens = {
13767                 (void *)&cmd_set_mplsogre_encap_set,
13768                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13769                 (void *)&cmd_set_mplsogre_encap_ip_version,
13770                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13771                 (void *)&cmd_set_mplsogre_encap_label,
13772                 (void *)&cmd_set_mplsogre_encap_label_value,
13773                 (void *)&cmd_set_mplsogre_encap_ip_src,
13774                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13775                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13776                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13777                 (void *)&cmd_set_mplsogre_encap_vlan,
13778                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13779                 (void *)&cmd_set_mplsogre_encap_eth_src,
13780                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13781                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13782                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13783                 NULL,
13784         },
13785 };
13786
13787 /** Set MPLSoGRE decapsulation details */
13788 struct cmd_set_mplsogre_decap_result {
13789         cmdline_fixed_string_t set;
13790         cmdline_fixed_string_t mplsogre;
13791         cmdline_fixed_string_t pos_token;
13792         cmdline_fixed_string_t ip_version;
13793         uint32_t vlan_present:1;
13794 };
13795
13796 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13797         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13798                                  "set");
13799 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13800         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13801                                  "mplsogre_decap");
13802 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13803         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13804                                  mplsogre, "mplsogre_decap-with-vlan");
13805 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13806         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13807                                  pos_token, "ip-version");
13808 static cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13809         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13810                                  ip_version, "ipv4#ipv6");
13811
13812 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13813         __rte_unused struct cmdline *cl,
13814         __rte_unused void *data)
13815 {
13816         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13817
13818         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13819                 mplsogre_decap_conf.select_vlan = 0;
13820         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13821                 mplsogre_decap_conf.select_vlan = 1;
13822         if (strcmp(res->ip_version, "ipv4") == 0)
13823                 mplsogre_decap_conf.select_ipv4 = 1;
13824         else if (strcmp(res->ip_version, "ipv6") == 0)
13825                 mplsogre_decap_conf.select_ipv4 = 0;
13826 }
13827
13828 static cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13829         .f = cmd_set_mplsogre_decap_parsed,
13830         .data = NULL,
13831         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13832         .tokens = {
13833                 (void *)&cmd_set_mplsogre_decap_set,
13834                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13835                 (void *)&cmd_set_mplsogre_decap_ip_version,
13836                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13837                 NULL,
13838         },
13839 };
13840
13841 static cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13842         .f = cmd_set_mplsogre_decap_parsed,
13843         .data = NULL,
13844         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13845         .tokens = {
13846                 (void *)&cmd_set_mplsogre_decap_set,
13847                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13848                 (void *)&cmd_set_mplsogre_decap_ip_version,
13849                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13850                 NULL,
13851         },
13852 };
13853
13854 /** Set MPLSoUDP encapsulation details */
13855 struct cmd_set_mplsoudp_encap_result {
13856         cmdline_fixed_string_t set;
13857         cmdline_fixed_string_t mplsoudp;
13858         cmdline_fixed_string_t pos_token;
13859         cmdline_fixed_string_t ip_version;
13860         uint32_t vlan_present:1;
13861         uint32_t label;
13862         uint16_t udp_src;
13863         uint16_t udp_dst;
13864         cmdline_ipaddr_t ip_src;
13865         cmdline_ipaddr_t ip_dst;
13866         uint16_t tci;
13867         struct rte_ether_addr eth_src;
13868         struct rte_ether_addr eth_dst;
13869 };
13870
13871 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13872         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13873                                  "set");
13874 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13875         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13876                                  "mplsoudp_encap");
13877 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13878         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13879                                  mplsoudp, "mplsoudp_encap-with-vlan");
13880 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13881         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13882                                  pos_token, "ip-version");
13883 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13884         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13885                                  ip_version, "ipv4#ipv6");
13886 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13887         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13888                                  pos_token, "label");
13889 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13890         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13891                               RTE_UINT32);
13892 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13893         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13894                                  pos_token, "udp-src");
13895 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13896         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13897                               RTE_UINT16);
13898 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13899         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13900                                  pos_token, "udp-dst");
13901 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13902         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13903                               RTE_UINT16);
13904 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13905         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13906                                  pos_token, "ip-src");
13907 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13908         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13909 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13910         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13911                                  pos_token, "ip-dst");
13912 static cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13913         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13914 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13915         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13916                                  pos_token, "vlan-tci");
13917 static cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13918         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13919                               RTE_UINT16);
13920 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13921         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13922                                  pos_token, "eth-src");
13923 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13924         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13925                                     eth_src);
13926 static cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13927         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13928                                  pos_token, "eth-dst");
13929 static cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13930         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13931                                     eth_dst);
13932
13933 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13934         __rte_unused struct cmdline *cl,
13935         __rte_unused void *data)
13936 {
13937         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13938         union {
13939                 uint32_t mplsoudp_label;
13940                 uint8_t label[4];
13941         } id = {
13942                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13943         };
13944
13945         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13946                 mplsoudp_encap_conf.select_vlan = 0;
13947         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13948                 mplsoudp_encap_conf.select_vlan = 1;
13949         if (strcmp(res->ip_version, "ipv4") == 0)
13950                 mplsoudp_encap_conf.select_ipv4 = 1;
13951         else if (strcmp(res->ip_version, "ipv6") == 0)
13952                 mplsoudp_encap_conf.select_ipv4 = 0;
13953         else
13954                 return;
13955         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13956         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13957         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13958         if (mplsoudp_encap_conf.select_ipv4) {
13959                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13960                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13961         } else {
13962                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13963                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13964         }
13965         if (mplsoudp_encap_conf.select_vlan)
13966                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13967         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13968                    RTE_ETHER_ADDR_LEN);
13969         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13970                    RTE_ETHER_ADDR_LEN);
13971 }
13972
13973 static cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13974         .f = cmd_set_mplsoudp_encap_parsed,
13975         .data = NULL,
13976         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13977                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13978                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13979         .tokens = {
13980                 (void *)&cmd_set_mplsoudp_encap_set,
13981                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13982                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13983                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13984                 (void *)&cmd_set_mplsoudp_encap_label,
13985                 (void *)&cmd_set_mplsoudp_encap_label_value,
13986                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13987                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13988                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13989                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13990                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13991                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13992                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13993                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13994                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13995                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13996                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13997                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13998                 NULL,
13999         },
14000 };
14001
14002 static cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
14003         .f = cmd_set_mplsoudp_encap_parsed,
14004         .data = NULL,
14005         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
14006                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
14007                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14008                 " eth-src <eth-src> eth-dst <eth-dst>",
14009         .tokens = {
14010                 (void *)&cmd_set_mplsoudp_encap_set,
14011                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
14012                 (void *)&cmd_set_mplsoudp_encap_ip_version,
14013                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
14014                 (void *)&cmd_set_mplsoudp_encap_label,
14015                 (void *)&cmd_set_mplsoudp_encap_label_value,
14016                 (void *)&cmd_set_mplsoudp_encap_udp_src,
14017                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
14018                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
14019                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
14020                 (void *)&cmd_set_mplsoudp_encap_ip_src,
14021                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14022                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14023                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14024                 (void *)&cmd_set_mplsoudp_encap_vlan,
14025                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
14026                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14027                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14028                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14029                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14030                 NULL,
14031         },
14032 };
14033
14034 /** Set MPLSoUDP decapsulation details */
14035 struct cmd_set_mplsoudp_decap_result {
14036         cmdline_fixed_string_t set;
14037         cmdline_fixed_string_t mplsoudp;
14038         cmdline_fixed_string_t pos_token;
14039         cmdline_fixed_string_t ip_version;
14040         uint32_t vlan_present:1;
14041 };
14042
14043 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14044         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14045                                  "set");
14046 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14048                                  "mplsoudp_decap");
14049 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14050         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14051                                  mplsoudp, "mplsoudp_decap-with-vlan");
14052 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14053         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14054                                  pos_token, "ip-version");
14055 static cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14056         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14057                                  ip_version, "ipv4#ipv6");
14058
14059 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14060         __rte_unused struct cmdline *cl,
14061         __rte_unused void *data)
14062 {
14063         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14064
14065         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14066                 mplsoudp_decap_conf.select_vlan = 0;
14067         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14068                 mplsoudp_decap_conf.select_vlan = 1;
14069         if (strcmp(res->ip_version, "ipv4") == 0)
14070                 mplsoudp_decap_conf.select_ipv4 = 1;
14071         else if (strcmp(res->ip_version, "ipv6") == 0)
14072                 mplsoudp_decap_conf.select_ipv4 = 0;
14073 }
14074
14075 static cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14076         .f = cmd_set_mplsoudp_decap_parsed,
14077         .data = NULL,
14078         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14079         .tokens = {
14080                 (void *)&cmd_set_mplsoudp_decap_set,
14081                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14082                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14083                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14084                 NULL,
14085         },
14086 };
14087
14088 static cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14089         .f = cmd_set_mplsoudp_decap_parsed,
14090         .data = NULL,
14091         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14092         .tokens = {
14093                 (void *)&cmd_set_mplsoudp_decap_set,
14094                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14095                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14096                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14097                 NULL,
14098         },
14099 };
14100
14101 /** Set connection tracking object common details */
14102 struct cmd_set_conntrack_common_result {
14103         cmdline_fixed_string_t set;
14104         cmdline_fixed_string_t conntrack;
14105         cmdline_fixed_string_t common;
14106         cmdline_fixed_string_t peer;
14107         cmdline_fixed_string_t is_orig;
14108         cmdline_fixed_string_t enable;
14109         cmdline_fixed_string_t live;
14110         cmdline_fixed_string_t sack;
14111         cmdline_fixed_string_t cack;
14112         cmdline_fixed_string_t last_dir;
14113         cmdline_fixed_string_t liberal;
14114         cmdline_fixed_string_t state;
14115         cmdline_fixed_string_t max_ack_win;
14116         cmdline_fixed_string_t retrans;
14117         cmdline_fixed_string_t last_win;
14118         cmdline_fixed_string_t last_seq;
14119         cmdline_fixed_string_t last_ack;
14120         cmdline_fixed_string_t last_end;
14121         cmdline_fixed_string_t last_index;
14122         uint8_t stat;
14123         uint8_t factor;
14124         uint16_t peer_port;
14125         uint32_t is_original;
14126         uint32_t en;
14127         uint32_t is_live;
14128         uint32_t s_ack;
14129         uint32_t c_ack;
14130         uint32_t ld;
14131         uint32_t lb;
14132         uint8_t re_num;
14133         uint8_t li;
14134         uint16_t lw;
14135         uint32_t ls;
14136         uint32_t la;
14137         uint32_t le;
14138 };
14139
14140 static cmdline_parse_token_string_t cmd_set_conntrack_set =
14141         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14142                                  set, "set");
14143 static cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14144         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14145                                  conntrack, "conntrack");
14146 static cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14147         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14148                                  common, "com");
14149 static cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14150         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14151                                  peer, "peer");
14152 static cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14153         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14154                               peer_port, RTE_UINT16);
14155 static cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14156         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14157                                  is_orig, "is_orig");
14158 static cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14159         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14160                               is_original, RTE_UINT32);
14161 static cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14162         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14163                                  enable, "enable");
14164 static cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14165         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14166                               en, RTE_UINT32);
14167 static cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14168         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14169                                  live, "live");
14170 static cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14171         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14172                               is_live, RTE_UINT32);
14173 static cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14174         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14175                                  sack, "sack");
14176 static cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14177         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14178                               s_ack, RTE_UINT32);
14179 static cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14180         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14181                                  cack, "cack");
14182 static cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14183         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14184                               c_ack, RTE_UINT32);
14185 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14186         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14187                                  last_dir, "last_dir");
14188 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14189         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14190                               ld, RTE_UINT32);
14191 static cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14192         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14193                                  liberal, "liberal");
14194 static cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14195         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14196                               lb, RTE_UINT32);
14197 static cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14198         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14199                                  state, "state");
14200 static cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14201         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14202                               stat, RTE_UINT8);
14203 static cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14204         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14205                                  max_ack_win, "max_ack_win");
14206 static cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14207         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14208                               factor, RTE_UINT8);
14209 static cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14210         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14211                                  retrans, "r_lim");
14212 static cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14213         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14214                               re_num, RTE_UINT8);
14215 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14216         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14217                                  last_win, "last_win");
14218 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14219         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14220                               lw, RTE_UINT16);
14221 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14222         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14223                                  last_seq, "last_seq");
14224 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14225         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14226                               ls, RTE_UINT32);
14227 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14228         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14229                                  last_ack, "last_ack");
14230 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14231         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14232                               la, RTE_UINT32);
14233 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14234         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14235                                  last_end, "last_end");
14236 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14237         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14238                               le, RTE_UINT32);
14239 static cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14240         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14241                                  last_index, "last_index");
14242 static cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14243         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14244                               li, RTE_UINT8);
14245
14246 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14247         __rte_unused struct cmdline *cl,
14248         __rte_unused void *data)
14249 {
14250         struct cmd_set_conntrack_common_result *res = parsed_result;
14251
14252         /* No need to swap to big endian. */
14253         conntrack_context.peer_port = res->peer_port;
14254         conntrack_context.is_original_dir = res->is_original;
14255         conntrack_context.enable = res->en;
14256         conntrack_context.live_connection = res->is_live;
14257         conntrack_context.selective_ack = res->s_ack;
14258         conntrack_context.challenge_ack_passed = res->c_ack;
14259         conntrack_context.last_direction = res->ld;
14260         conntrack_context.liberal_mode = res->lb;
14261         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14262         conntrack_context.max_ack_window = res->factor;
14263         conntrack_context.retransmission_limit = res->re_num;
14264         conntrack_context.last_window = res->lw;
14265         conntrack_context.last_index =
14266                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14267         conntrack_context.last_seq = res->ls;
14268         conntrack_context.last_ack = res->la;
14269         conntrack_context.last_end = res->le;
14270 }
14271
14272 static cmdline_parse_inst_t cmd_set_conntrack_common = {
14273         .f = cmd_set_conntrack_common_parsed,
14274         .data = NULL,
14275         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14276                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14277                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14278                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14279                 " last_index <flag>",
14280         .tokens = {
14281                 (void *)&cmd_set_conntrack_set,
14282                 (void *)&cmd_set_conntrack_conntrack,
14283                 (void *)&cmd_set_conntrack_common_com,
14284                 (void *)&cmd_set_conntrack_common_peer,
14285                 (void *)&cmd_set_conntrack_common_peer_value,
14286                 (void *)&cmd_set_conntrack_common_is_orig,
14287                 (void *)&cmd_set_conntrack_common_is_orig_value,
14288                 (void *)&cmd_set_conntrack_common_enable,
14289                 (void *)&cmd_set_conntrack_common_enable_value,
14290                 (void *)&cmd_set_conntrack_common_live,
14291                 (void *)&cmd_set_conntrack_common_live_value,
14292                 (void *)&cmd_set_conntrack_common_sack,
14293                 (void *)&cmd_set_conntrack_common_sack_value,
14294                 (void *)&cmd_set_conntrack_common_cack,
14295                 (void *)&cmd_set_conntrack_common_cack_value,
14296                 (void *)&cmd_set_conntrack_common_last_dir,
14297                 (void *)&cmd_set_conntrack_common_last_dir_value,
14298                 (void *)&cmd_set_conntrack_common_liberal,
14299                 (void *)&cmd_set_conntrack_common_liberal_value,
14300                 (void *)&cmd_set_conntrack_common_state,
14301                 (void *)&cmd_set_conntrack_common_state_value,
14302                 (void *)&cmd_set_conntrack_common_max_ackwin,
14303                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14304                 (void *)&cmd_set_conntrack_common_retrans,
14305                 (void *)&cmd_set_conntrack_common_retrans_value,
14306                 (void *)&cmd_set_conntrack_common_last_win,
14307                 (void *)&cmd_set_conntrack_common_last_win_value,
14308                 (void *)&cmd_set_conntrack_common_last_seq,
14309                 (void *)&cmd_set_conntrack_common_last_seq_value,
14310                 (void *)&cmd_set_conntrack_common_last_ack,
14311                 (void *)&cmd_set_conntrack_common_last_ack_value,
14312                 (void *)&cmd_set_conntrack_common_last_end,
14313                 (void *)&cmd_set_conntrack_common_last_end_value,
14314                 (void *)&cmd_set_conntrack_common_last_index,
14315                 (void *)&cmd_set_conntrack_common_last_index_value,
14316                 NULL,
14317         },
14318 };
14319
14320 /** Set connection tracking object both directions' details */
14321 struct cmd_set_conntrack_dir_result {
14322         cmdline_fixed_string_t set;
14323         cmdline_fixed_string_t conntrack;
14324         cmdline_fixed_string_t dir;
14325         cmdline_fixed_string_t scale;
14326         cmdline_fixed_string_t fin;
14327         cmdline_fixed_string_t ack_seen;
14328         cmdline_fixed_string_t unack;
14329         cmdline_fixed_string_t sent_end;
14330         cmdline_fixed_string_t reply_end;
14331         cmdline_fixed_string_t max_win;
14332         cmdline_fixed_string_t max_ack;
14333         uint32_t factor;
14334         uint32_t f;
14335         uint32_t as;
14336         uint32_t un;
14337         uint32_t se;
14338         uint32_t re;
14339         uint32_t mw;
14340         uint32_t ma;
14341 };
14342
14343 static cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14344         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14345                                  dir, "orig#rply");
14346 static cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14347         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14348                                  scale, "scale");
14349 static cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14350         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14351                               factor, RTE_UINT32);
14352 static cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14353         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14354                                  fin, "fin");
14355 static cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14356         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14357                               f, RTE_UINT32);
14358 static cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14359         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14360                                  ack_seen, "acked");
14361 static cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14362         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14363                               as, RTE_UINT32);
14364 static cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14365         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14366                                  unack, "unack_data");
14367 static cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14368         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14369                               un, RTE_UINT32);
14370 static cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14371         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14372                                  sent_end, "sent_end");
14373 static cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14374         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14375                               se, RTE_UINT32);
14376 static cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14377         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14378                                  reply_end, "reply_end");
14379 static cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14380         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14381                               re, RTE_UINT32);
14382 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14383         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14384                                  max_win, "max_win");
14385 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14386         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14387                               mw, RTE_UINT32);
14388 static cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14389         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14390                                  max_ack, "max_ack");
14391 static cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14392         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14393                               ma, RTE_UINT32);
14394
14395 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14396         __rte_unused struct cmdline *cl,
14397         __rte_unused void *data)
14398 {
14399         struct cmd_set_conntrack_dir_result *res = parsed_result;
14400         struct rte_flow_tcp_dir_param *dir = NULL;
14401
14402         if (strcmp(res->dir, "orig") == 0)
14403                 dir = &conntrack_context.original_dir;
14404         else if (strcmp(res->dir, "rply") == 0)
14405                 dir = &conntrack_context.reply_dir;
14406         else
14407                 return;
14408         dir->scale = res->factor;
14409         dir->close_initiated = res->f;
14410         dir->last_ack_seen = res->as;
14411         dir->data_unacked = res->un;
14412         dir->sent_end = res->se;
14413         dir->reply_end = res->re;
14414         dir->max_ack = res->ma;
14415         dir->max_win = res->mw;
14416 }
14417
14418 static cmdline_parse_inst_t cmd_set_conntrack_dir = {
14419         .f = cmd_set_conntrack_dir_parsed,
14420         .data = NULL,
14421         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14422                     " acked <seen> unack_data <unack> sent_end <sent>"
14423                     " reply_end <reply> max_win <win> max_ack <ack>",
14424         .tokens = {
14425                 (void *)&cmd_set_conntrack_set,
14426                 (void *)&cmd_set_conntrack_conntrack,
14427                 (void *)&cmd_set_conntrack_dir_dir,
14428                 (void *)&cmd_set_conntrack_dir_scale,
14429                 (void *)&cmd_set_conntrack_dir_scale_value,
14430                 (void *)&cmd_set_conntrack_dir_fin,
14431                 (void *)&cmd_set_conntrack_dir_fin_value,
14432                 (void *)&cmd_set_conntrack_dir_ack,
14433                 (void *)&cmd_set_conntrack_dir_ack_value,
14434                 (void *)&cmd_set_conntrack_dir_unack_data,
14435                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14436                 (void *)&cmd_set_conntrack_dir_sent_end,
14437                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14438                 (void *)&cmd_set_conntrack_dir_reply_end,
14439                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14440                 (void *)&cmd_set_conntrack_dir_max_win,
14441                 (void *)&cmd_set_conntrack_dir_max_win_value,
14442                 (void *)&cmd_set_conntrack_dir_max_ack,
14443                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14444                 NULL,
14445         },
14446 };
14447
14448 /* Strict link priority scheduling mode setting */
14449 static void
14450 cmd_strict_link_prio_parsed(
14451         void *parsed_result,
14452         __rte_unused struct cmdline *cl,
14453         __rte_unused void *data)
14454 {
14455         struct cmd_vf_tc_bw_result *res = parsed_result;
14456         int ret = -ENOTSUP;
14457
14458         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14459                 return;
14460
14461 #ifdef RTE_NET_I40E
14462         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14463 #endif
14464
14465         switch (ret) {
14466         case 0:
14467                 break;
14468         case -EINVAL:
14469                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14470                 break;
14471         case -ENODEV:
14472                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14473                 break;
14474         case -ENOTSUP:
14475                 fprintf(stderr, "function not implemented\n");
14476                 break;
14477         default:
14478                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14479         }
14480 }
14481
14482 static cmdline_parse_inst_t cmd_strict_link_prio = {
14483         .f = cmd_strict_link_prio_parsed,
14484         .data = NULL,
14485         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14486         .tokens = {
14487                 (void *)&cmd_vf_tc_bw_set,
14488                 (void *)&cmd_vf_tc_bw_tx,
14489                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14490                 (void *)&cmd_vf_tc_bw_port_id,
14491                 (void *)&cmd_vf_tc_bw_tc_map,
14492                 NULL,
14493         },
14494 };
14495
14496 /* Load dynamic device personalization*/
14497 struct cmd_ddp_add_result {
14498         cmdline_fixed_string_t ddp;
14499         cmdline_fixed_string_t add;
14500         portid_t port_id;
14501         char filepath[];
14502 };
14503
14504 static cmdline_parse_token_string_t cmd_ddp_add_ddp =
14505         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14506 static cmdline_parse_token_string_t cmd_ddp_add_add =
14507         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14508 static cmdline_parse_token_num_t cmd_ddp_add_port_id =
14509         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14510                 RTE_UINT16);
14511 static cmdline_parse_token_string_t cmd_ddp_add_filepath =
14512         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14513
14514 static void
14515 cmd_ddp_add_parsed(
14516         void *parsed_result,
14517         __rte_unused struct cmdline *cl,
14518         __rte_unused void *data)
14519 {
14520         struct cmd_ddp_add_result *res = parsed_result;
14521         uint8_t *buff;
14522         uint32_t size;
14523         char *filepath;
14524         char *file_fld[2];
14525         int file_num;
14526         int ret = -ENOTSUP;
14527
14528         if (!all_ports_stopped()) {
14529                 fprintf(stderr, "Please stop all ports first\n");
14530                 return;
14531         }
14532
14533         filepath = strdup(res->filepath);
14534         if (filepath == NULL) {
14535                 fprintf(stderr, "Failed to allocate memory\n");
14536                 return;
14537         }
14538         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14539
14540         buff = open_file(file_fld[0], &size);
14541         if (!buff) {
14542                 free((void *)filepath);
14543                 return;
14544         }
14545
14546 #ifdef RTE_NET_I40E
14547         if (ret == -ENOTSUP)
14548                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14549                                                buff, size,
14550                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14551 #endif
14552
14553         if (ret == -EEXIST)
14554                 fprintf(stderr, "Profile has already existed.\n");
14555         else if (ret < 0)
14556                 fprintf(stderr, "Failed to load profile.\n");
14557         else if (file_num == 2)
14558                 save_file(file_fld[1], buff, size);
14559
14560         close_file(buff);
14561         free((void *)filepath);
14562 }
14563
14564 static cmdline_parse_inst_t cmd_ddp_add = {
14565         .f = cmd_ddp_add_parsed,
14566         .data = NULL,
14567         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14568         .tokens = {
14569                 (void *)&cmd_ddp_add_ddp,
14570                 (void *)&cmd_ddp_add_add,
14571                 (void *)&cmd_ddp_add_port_id,
14572                 (void *)&cmd_ddp_add_filepath,
14573                 NULL,
14574         },
14575 };
14576
14577 /* Delete dynamic device personalization*/
14578 struct cmd_ddp_del_result {
14579         cmdline_fixed_string_t ddp;
14580         cmdline_fixed_string_t del;
14581         portid_t port_id;
14582         char filepath[];
14583 };
14584
14585 static cmdline_parse_token_string_t cmd_ddp_del_ddp =
14586         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14587 static cmdline_parse_token_string_t cmd_ddp_del_del =
14588         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14589 static cmdline_parse_token_num_t cmd_ddp_del_port_id =
14590         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14591 static cmdline_parse_token_string_t cmd_ddp_del_filepath =
14592         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14593
14594 static void
14595 cmd_ddp_del_parsed(
14596         void *parsed_result,
14597         __rte_unused struct cmdline *cl,
14598         __rte_unused void *data)
14599 {
14600         struct cmd_ddp_del_result *res = parsed_result;
14601         uint8_t *buff;
14602         uint32_t size;
14603         int ret = -ENOTSUP;
14604
14605         if (!all_ports_stopped()) {
14606                 fprintf(stderr, "Please stop all ports first\n");
14607                 return;
14608         }
14609
14610         buff = open_file(res->filepath, &size);
14611         if (!buff)
14612                 return;
14613
14614 #ifdef RTE_NET_I40E
14615         if (ret == -ENOTSUP)
14616                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14617                                                buff, size,
14618                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14619 #endif
14620
14621         if (ret == -EACCES)
14622                 fprintf(stderr, "Profile does not exist.\n");
14623         else if (ret < 0)
14624                 fprintf(stderr, "Failed to delete profile.\n");
14625
14626         close_file(buff);
14627 }
14628
14629 static cmdline_parse_inst_t cmd_ddp_del = {
14630         .f = cmd_ddp_del_parsed,
14631         .data = NULL,
14632         .help_str = "ddp del <port_id> <backup_profile_path>",
14633         .tokens = {
14634                 (void *)&cmd_ddp_del_ddp,
14635                 (void *)&cmd_ddp_del_del,
14636                 (void *)&cmd_ddp_del_port_id,
14637                 (void *)&cmd_ddp_del_filepath,
14638                 NULL,
14639         },
14640 };
14641
14642 /* Get dynamic device personalization profile info */
14643 struct cmd_ddp_info_result {
14644         cmdline_fixed_string_t ddp;
14645         cmdline_fixed_string_t get;
14646         cmdline_fixed_string_t info;
14647         char filepath[];
14648 };
14649
14650 static cmdline_parse_token_string_t cmd_ddp_info_ddp =
14651         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14652 static cmdline_parse_token_string_t cmd_ddp_info_get =
14653         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14654 static cmdline_parse_token_string_t cmd_ddp_info_info =
14655         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14656 static cmdline_parse_token_string_t cmd_ddp_info_filepath =
14657         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14658
14659 static void
14660 cmd_ddp_info_parsed(
14661         void *parsed_result,
14662         __rte_unused struct cmdline *cl,
14663         __rte_unused void *data)
14664 {
14665         struct cmd_ddp_info_result *res = parsed_result;
14666         uint8_t *pkg;
14667         uint32_t pkg_size;
14668         int ret = -ENOTSUP;
14669 #ifdef RTE_NET_I40E
14670         uint32_t i, j, n;
14671         uint8_t *buff;
14672         uint32_t buff_size = 0;
14673         struct rte_pmd_i40e_profile_info info;
14674         uint32_t dev_num = 0;
14675         struct rte_pmd_i40e_ddp_device_id *devs;
14676         uint32_t proto_num = 0;
14677         struct rte_pmd_i40e_proto_info *proto = NULL;
14678         uint32_t pctype_num = 0;
14679         struct rte_pmd_i40e_ptype_info *pctype;
14680         uint32_t ptype_num = 0;
14681         struct rte_pmd_i40e_ptype_info *ptype;
14682         uint8_t proto_id;
14683
14684 #endif
14685
14686         pkg = open_file(res->filepath, &pkg_size);
14687         if (!pkg)
14688                 return;
14689
14690 #ifdef RTE_NET_I40E
14691         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14692                                 (uint8_t *)&info, sizeof(info),
14693                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14694         if (!ret) {
14695                 printf("Global Track id:       0x%x\n", info.track_id);
14696                 printf("Global Version:        %d.%d.%d.%d\n",
14697                         info.version.major,
14698                         info.version.minor,
14699                         info.version.update,
14700                         info.version.draft);
14701                 printf("Global Package name:   %s\n\n", info.name);
14702         }
14703
14704         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14705                                 (uint8_t *)&info, sizeof(info),
14706                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14707         if (!ret) {
14708                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14709                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14710                         info.version.major,
14711                         info.version.minor,
14712                         info.version.update,
14713                         info.version.draft);
14714                 printf("i40e Profile name:     %s\n\n", info.name);
14715         }
14716
14717         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14718                                 (uint8_t *)&buff_size, sizeof(buff_size),
14719                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14720         if (!ret && buff_size) {
14721                 buff = (uint8_t *)malloc(buff_size);
14722                 if (buff) {
14723                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14724                                                 buff, buff_size,
14725                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14726                         if (!ret)
14727                                 printf("Package Notes:\n%s\n\n", buff);
14728                         free(buff);
14729                 }
14730         }
14731
14732         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14733                                 (uint8_t *)&dev_num, sizeof(dev_num),
14734                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14735         if (!ret && dev_num) {
14736                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14737                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14738                 if (devs) {
14739                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14740                                                 (uint8_t *)devs, buff_size,
14741                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14742                         if (!ret) {
14743                                 printf("List of supported devices:\n");
14744                                 for (i = 0; i < dev_num; i++) {
14745                                         printf("  %04X:%04X %04X:%04X\n",
14746                                                 devs[i].vendor_dev_id >> 16,
14747                                                 devs[i].vendor_dev_id & 0xFFFF,
14748                                                 devs[i].sub_vendor_dev_id >> 16,
14749                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14750                                 }
14751                                 printf("\n");
14752                         }
14753                         free(devs);
14754                 }
14755         }
14756
14757         /* get information about protocols and packet types */
14758         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14759                 (uint8_t *)&proto_num, sizeof(proto_num),
14760                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14761         if (ret || !proto_num)
14762                 goto no_print_return;
14763
14764         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14765         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14766         if (!proto)
14767                 goto no_print_return;
14768
14769         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14770                                         buff_size,
14771                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14772         if (!ret) {
14773                 printf("List of used protocols:\n");
14774                 for (i = 0; i < proto_num; i++)
14775                         printf("  %2u: %s\n", proto[i].proto_id,
14776                                proto[i].name);
14777                 printf("\n");
14778         }
14779         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14780                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14781                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14782         if (ret || !pctype_num)
14783                 goto no_print_pctypes;
14784
14785         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14786         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14787         if (!pctype)
14788                 goto no_print_pctypes;
14789
14790         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14791                                         buff_size,
14792                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14793         if (ret) {
14794                 free(pctype);
14795                 goto no_print_pctypes;
14796         }
14797
14798         printf("List of defined packet classification types:\n");
14799         for (i = 0; i < pctype_num; i++) {
14800                 printf("  %2u:", pctype[i].ptype_id);
14801                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14802                         proto_id = pctype[i].protocols[j];
14803                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14804                                 for (n = 0; n < proto_num; n++) {
14805                                         if (proto[n].proto_id == proto_id) {
14806                                                 printf(" %s", proto[n].name);
14807                                                 break;
14808                                         }
14809                                 }
14810                         }
14811                 }
14812                 printf("\n");
14813         }
14814         printf("\n");
14815         free(pctype);
14816
14817 no_print_pctypes:
14818
14819         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14820                                         sizeof(ptype_num),
14821                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14822         if (ret || !ptype_num)
14823                 goto no_print_return;
14824
14825         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14826         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14827         if (!ptype)
14828                 goto no_print_return;
14829
14830         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14831                                         buff_size,
14832                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14833         if (ret) {
14834                 free(ptype);
14835                 goto no_print_return;
14836         }
14837         printf("List of defined packet types:\n");
14838         for (i = 0; i < ptype_num; i++) {
14839                 printf("  %2u:", ptype[i].ptype_id);
14840                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14841                         proto_id = ptype[i].protocols[j];
14842                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14843                                 for (n = 0; n < proto_num; n++) {
14844                                         if (proto[n].proto_id == proto_id) {
14845                                                 printf(" %s", proto[n].name);
14846                                                 break;
14847                                         }
14848                                 }
14849                         }
14850                 }
14851                 printf("\n");
14852         }
14853         free(ptype);
14854         printf("\n");
14855
14856         ret = 0;
14857 no_print_return:
14858         free(proto);
14859 #endif
14860         if (ret == -ENOTSUP)
14861                 fprintf(stderr, "Function not supported in PMD\n");
14862         close_file(pkg);
14863 }
14864
14865 static cmdline_parse_inst_t cmd_ddp_get_info = {
14866         .f = cmd_ddp_info_parsed,
14867         .data = NULL,
14868         .help_str = "ddp get info <profile_path>",
14869         .tokens = {
14870                 (void *)&cmd_ddp_info_ddp,
14871                 (void *)&cmd_ddp_info_get,
14872                 (void *)&cmd_ddp_info_info,
14873                 (void *)&cmd_ddp_info_filepath,
14874                 NULL,
14875         },
14876 };
14877
14878 /* Get dynamic device personalization profile info list*/
14879 #define PROFILE_INFO_SIZE 48
14880 #define MAX_PROFILE_NUM 16
14881
14882 struct cmd_ddp_get_list_result {
14883         cmdline_fixed_string_t ddp;
14884         cmdline_fixed_string_t get;
14885         cmdline_fixed_string_t list;
14886         portid_t port_id;
14887 };
14888
14889 static cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14890         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14891 static cmdline_parse_token_string_t cmd_ddp_get_list_get =
14892         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14893 static cmdline_parse_token_string_t cmd_ddp_get_list_list =
14894         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14895 static cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14896         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14897                 RTE_UINT16);
14898
14899 static void
14900 cmd_ddp_get_list_parsed(
14901         __rte_unused void *parsed_result,
14902         __rte_unused struct cmdline *cl,
14903         __rte_unused void *data)
14904 {
14905 #ifdef RTE_NET_I40E
14906         struct cmd_ddp_get_list_result *res = parsed_result;
14907         struct rte_pmd_i40e_profile_list *p_list;
14908         struct rte_pmd_i40e_profile_info *p_info;
14909         uint32_t p_num;
14910         uint32_t size;
14911         uint32_t i;
14912 #endif
14913         int ret = -ENOTSUP;
14914
14915 #ifdef RTE_NET_I40E
14916         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14917         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14918         if (!p_list) {
14919                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14920                 return;
14921         }
14922
14923         if (ret == -ENOTSUP)
14924                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14925                                                 (uint8_t *)p_list, size);
14926
14927         if (!ret) {
14928                 p_num = p_list->p_count;
14929                 printf("Profile number is: %d\n\n", p_num);
14930
14931                 for (i = 0; i < p_num; i++) {
14932                         p_info = &p_list->p_info[i];
14933                         printf("Profile %d:\n", i);
14934                         printf("Track id:     0x%x\n", p_info->track_id);
14935                         printf("Version:      %d.%d.%d.%d\n",
14936                                p_info->version.major,
14937                                p_info->version.minor,
14938                                p_info->version.update,
14939                                p_info->version.draft);
14940                         printf("Profile name: %s\n\n", p_info->name);
14941                 }
14942         }
14943
14944         free(p_list);
14945 #endif
14946
14947         if (ret < 0)
14948                 fprintf(stderr, "Failed to get ddp list\n");
14949 }
14950
14951 static cmdline_parse_inst_t cmd_ddp_get_list = {
14952         .f = cmd_ddp_get_list_parsed,
14953         .data = NULL,
14954         .help_str = "ddp get list <port_id>",
14955         .tokens = {
14956                 (void *)&cmd_ddp_get_list_ddp,
14957                 (void *)&cmd_ddp_get_list_get,
14958                 (void *)&cmd_ddp_get_list_list,
14959                 (void *)&cmd_ddp_get_list_port_id,
14960                 NULL,
14961         },
14962 };
14963
14964 /* Configure input set */
14965 struct cmd_cfg_input_set_result {
14966         cmdline_fixed_string_t port;
14967         cmdline_fixed_string_t cfg;
14968         portid_t port_id;
14969         cmdline_fixed_string_t pctype;
14970         uint8_t pctype_id;
14971         cmdline_fixed_string_t inset_type;
14972         cmdline_fixed_string_t opt;
14973         cmdline_fixed_string_t field;
14974         uint8_t field_idx;
14975 };
14976
14977 static void
14978 cmd_cfg_input_set_parsed(
14979         __rte_unused void *parsed_result,
14980         __rte_unused struct cmdline *cl,
14981         __rte_unused void *data)
14982 {
14983 #ifdef RTE_NET_I40E
14984         struct cmd_cfg_input_set_result *res = parsed_result;
14985         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14986         struct rte_pmd_i40e_inset inset;
14987 #endif
14988         int ret = -ENOTSUP;
14989
14990         if (!all_ports_stopped()) {
14991                 fprintf(stderr, "Please stop all ports first\n");
14992                 return;
14993         }
14994
14995 #ifdef RTE_NET_I40E
14996         if (!strcmp(res->inset_type, "hash_inset"))
14997                 inset_type = INSET_HASH;
14998         else if (!strcmp(res->inset_type, "fdir_inset"))
14999                 inset_type = INSET_FDIR;
15000         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15001                 inset_type = INSET_FDIR_FLX;
15002         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15003                                      &inset, inset_type);
15004         if (ret) {
15005                 fprintf(stderr, "Failed to get input set.\n");
15006                 return;
15007         }
15008
15009         if (!strcmp(res->opt, "get")) {
15010                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15011                                                    res->field_idx);
15012                 if (ret)
15013                         printf("Field index %d is enabled.\n", res->field_idx);
15014                 else
15015                         printf("Field index %d is disabled.\n", res->field_idx);
15016                 return;
15017         } else if (!strcmp(res->opt, "set"))
15018                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15019                                                    res->field_idx);
15020         else if (!strcmp(res->opt, "clear"))
15021                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15022                                                      res->field_idx);
15023         if (ret) {
15024                 fprintf(stderr, "Failed to configure input set field.\n");
15025                 return;
15026         }
15027
15028         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15029                                      &inset, inset_type);
15030         if (ret) {
15031                 fprintf(stderr, "Failed to set input set.\n");
15032                 return;
15033         }
15034 #endif
15035
15036         if (ret == -ENOTSUP)
15037                 fprintf(stderr, "Function not supported\n");
15038 }
15039
15040 static cmdline_parse_token_string_t cmd_cfg_input_set_port =
15041         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15042                                  port, "port");
15043 static cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15044         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15045                                  cfg, "config");
15046 static cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15047         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15048                               port_id, RTE_UINT16);
15049 static cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15050         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15051                                  pctype, "pctype");
15052 static cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15053         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15054                               pctype_id, RTE_UINT8);
15055 static cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15056         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15057                                  inset_type,
15058                                  "hash_inset#fdir_inset#fdir_flx_inset");
15059 static cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15060         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15061                                  opt, "get#set#clear");
15062 static cmdline_parse_token_string_t cmd_cfg_input_set_field =
15063         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15064                                  field, "field");
15065 static cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15066         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15067                               field_idx, RTE_UINT8);
15068
15069 static cmdline_parse_inst_t cmd_cfg_input_set = {
15070         .f = cmd_cfg_input_set_parsed,
15071         .data = NULL,
15072         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15073                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15074         .tokens = {
15075                 (void *)&cmd_cfg_input_set_port,
15076                 (void *)&cmd_cfg_input_set_cfg,
15077                 (void *)&cmd_cfg_input_set_port_id,
15078                 (void *)&cmd_cfg_input_set_pctype,
15079                 (void *)&cmd_cfg_input_set_pctype_id,
15080                 (void *)&cmd_cfg_input_set_inset_type,
15081                 (void *)&cmd_cfg_input_set_opt,
15082                 (void *)&cmd_cfg_input_set_field,
15083                 (void *)&cmd_cfg_input_set_field_idx,
15084                 NULL,
15085         },
15086 };
15087
15088 /* Clear input set */
15089 struct cmd_clear_input_set_result {
15090         cmdline_fixed_string_t port;
15091         cmdline_fixed_string_t cfg;
15092         portid_t port_id;
15093         cmdline_fixed_string_t pctype;
15094         uint8_t pctype_id;
15095         cmdline_fixed_string_t inset_type;
15096         cmdline_fixed_string_t clear;
15097         cmdline_fixed_string_t all;
15098 };
15099
15100 static void
15101 cmd_clear_input_set_parsed(
15102         __rte_unused void *parsed_result,
15103         __rte_unused struct cmdline *cl,
15104         __rte_unused void *data)
15105 {
15106 #ifdef RTE_NET_I40E
15107         struct cmd_clear_input_set_result *res = parsed_result;
15108         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15109         struct rte_pmd_i40e_inset inset;
15110 #endif
15111         int ret = -ENOTSUP;
15112
15113         if (!all_ports_stopped()) {
15114                 fprintf(stderr, "Please stop all ports first\n");
15115                 return;
15116         }
15117
15118 #ifdef RTE_NET_I40E
15119         if (!strcmp(res->inset_type, "hash_inset"))
15120                 inset_type = INSET_HASH;
15121         else if (!strcmp(res->inset_type, "fdir_inset"))
15122                 inset_type = INSET_FDIR;
15123         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15124                 inset_type = INSET_FDIR_FLX;
15125
15126         memset(&inset, 0, sizeof(inset));
15127
15128         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15129                                      &inset, inset_type);
15130         if (ret) {
15131                 fprintf(stderr, "Failed to clear input set.\n");
15132                 return;
15133         }
15134
15135 #endif
15136
15137         if (ret == -ENOTSUP)
15138                 fprintf(stderr, "Function not supported\n");
15139 }
15140
15141 static cmdline_parse_token_string_t cmd_clear_input_set_port =
15142         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15143                                  port, "port");
15144 static cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15145         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15146                                  cfg, "config");
15147 static cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15148         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15149                               port_id, RTE_UINT16);
15150 static cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15151         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15152                                  pctype, "pctype");
15153 static cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15154         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15155                               pctype_id, RTE_UINT8);
15156 static cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15157         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15158                                  inset_type,
15159                                  "hash_inset#fdir_inset#fdir_flx_inset");
15160 static cmdline_parse_token_string_t cmd_clear_input_set_clear =
15161         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15162                                  clear, "clear");
15163 static cmdline_parse_token_string_t cmd_clear_input_set_all =
15164         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15165                                  all, "all");
15166
15167 static cmdline_parse_inst_t cmd_clear_input_set = {
15168         .f = cmd_clear_input_set_parsed,
15169         .data = NULL,
15170         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15171                     "fdir_inset|fdir_flx_inset clear all",
15172         .tokens = {
15173                 (void *)&cmd_clear_input_set_port,
15174                 (void *)&cmd_clear_input_set_cfg,
15175                 (void *)&cmd_clear_input_set_port_id,
15176                 (void *)&cmd_clear_input_set_pctype,
15177                 (void *)&cmd_clear_input_set_pctype_id,
15178                 (void *)&cmd_clear_input_set_inset_type,
15179                 (void *)&cmd_clear_input_set_clear,
15180                 (void *)&cmd_clear_input_set_all,
15181                 NULL,
15182         },
15183 };
15184
15185 /* show vf stats */
15186
15187 /* Common result structure for show vf stats */
15188 struct cmd_show_vf_stats_result {
15189         cmdline_fixed_string_t show;
15190         cmdline_fixed_string_t vf;
15191         cmdline_fixed_string_t stats;
15192         portid_t port_id;
15193         uint16_t vf_id;
15194 };
15195
15196 /* Common CLI fields show vf stats*/
15197 static cmdline_parse_token_string_t cmd_show_vf_stats_show =
15198         TOKEN_STRING_INITIALIZER
15199                 (struct cmd_show_vf_stats_result,
15200                  show, "show");
15201 static cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15202         TOKEN_STRING_INITIALIZER
15203                 (struct cmd_show_vf_stats_result,
15204                  vf, "vf");
15205 static cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15206         TOKEN_STRING_INITIALIZER
15207                 (struct cmd_show_vf_stats_result,
15208                  stats, "stats");
15209 static cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15210         TOKEN_NUM_INITIALIZER
15211                 (struct cmd_show_vf_stats_result,
15212                  port_id, RTE_UINT16);
15213 static cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15214         TOKEN_NUM_INITIALIZER
15215                 (struct cmd_show_vf_stats_result,
15216                  vf_id, RTE_UINT16);
15217
15218 static void
15219 cmd_show_vf_stats_parsed(
15220         void *parsed_result,
15221         __rte_unused struct cmdline *cl,
15222         __rte_unused void *data)
15223 {
15224         struct cmd_show_vf_stats_result *res = parsed_result;
15225         struct rte_eth_stats stats;
15226         int ret = -ENOTSUP;
15227         static const char *nic_stats_border = "########################";
15228
15229         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15230                 return;
15231
15232         memset(&stats, 0, sizeof(stats));
15233
15234 #ifdef RTE_NET_I40E
15235         if (ret == -ENOTSUP)
15236                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15237                                                 res->vf_id,
15238                                                 &stats);
15239 #endif
15240 #ifdef RTE_NET_BNXT
15241         if (ret == -ENOTSUP)
15242                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15243                                                 res->vf_id,
15244                                                 &stats);
15245 #endif
15246
15247         switch (ret) {
15248         case 0:
15249                 break;
15250         case -EINVAL:
15251                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15252                 break;
15253         case -ENODEV:
15254                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15255                 break;
15256         case -ENOTSUP:
15257                 fprintf(stderr, "function not implemented\n");
15258                 break;
15259         default:
15260                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15261         }
15262
15263         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15264                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15265
15266         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15267                "%-"PRIu64"\n",
15268                stats.ipackets, stats.imissed, stats.ibytes);
15269         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15270         printf("  RX-nombuf:  %-10"PRIu64"\n",
15271                stats.rx_nombuf);
15272         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15273                "%-"PRIu64"\n",
15274                stats.opackets, stats.oerrors, stats.obytes);
15275
15276         printf("  %s############################%s\n",
15277                                nic_stats_border, nic_stats_border);
15278 }
15279
15280 static cmdline_parse_inst_t cmd_show_vf_stats = {
15281         .f = cmd_show_vf_stats_parsed,
15282         .data = NULL,
15283         .help_str = "show vf stats <port_id> <vf_id>",
15284         .tokens = {
15285                 (void *)&cmd_show_vf_stats_show,
15286                 (void *)&cmd_show_vf_stats_vf,
15287                 (void *)&cmd_show_vf_stats_stats,
15288                 (void *)&cmd_show_vf_stats_port_id,
15289                 (void *)&cmd_show_vf_stats_vf_id,
15290                 NULL,
15291         },
15292 };
15293
15294 /* clear vf stats */
15295
15296 /* Common result structure for clear vf stats */
15297 struct cmd_clear_vf_stats_result {
15298         cmdline_fixed_string_t clear;
15299         cmdline_fixed_string_t vf;
15300         cmdline_fixed_string_t stats;
15301         portid_t port_id;
15302         uint16_t vf_id;
15303 };
15304
15305 /* Common CLI fields clear vf stats*/
15306 static cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15307         TOKEN_STRING_INITIALIZER
15308                 (struct cmd_clear_vf_stats_result,
15309                  clear, "clear");
15310 static cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15311         TOKEN_STRING_INITIALIZER
15312                 (struct cmd_clear_vf_stats_result,
15313                  vf, "vf");
15314 static cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15315         TOKEN_STRING_INITIALIZER
15316                 (struct cmd_clear_vf_stats_result,
15317                  stats, "stats");
15318 static cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15319         TOKEN_NUM_INITIALIZER
15320                 (struct cmd_clear_vf_stats_result,
15321                  port_id, RTE_UINT16);
15322 static cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15323         TOKEN_NUM_INITIALIZER
15324                 (struct cmd_clear_vf_stats_result,
15325                  vf_id, RTE_UINT16);
15326
15327 static void
15328 cmd_clear_vf_stats_parsed(
15329         void *parsed_result,
15330         __rte_unused struct cmdline *cl,
15331         __rte_unused void *data)
15332 {
15333         struct cmd_clear_vf_stats_result *res = parsed_result;
15334         int ret = -ENOTSUP;
15335
15336         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15337                 return;
15338
15339 #ifdef RTE_NET_I40E
15340         if (ret == -ENOTSUP)
15341                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15342                                                   res->vf_id);
15343 #endif
15344 #ifdef RTE_NET_BNXT
15345         if (ret == -ENOTSUP)
15346                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15347                                                   res->vf_id);
15348 #endif
15349
15350         switch (ret) {
15351         case 0:
15352                 break;
15353         case -EINVAL:
15354                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15355                 break;
15356         case -ENODEV:
15357                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15358                 break;
15359         case -ENOTSUP:
15360                 fprintf(stderr, "function not implemented\n");
15361                 break;
15362         default:
15363                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15364         }
15365 }
15366
15367 static cmdline_parse_inst_t cmd_clear_vf_stats = {
15368         .f = cmd_clear_vf_stats_parsed,
15369         .data = NULL,
15370         .help_str = "clear vf stats <port_id> <vf_id>",
15371         .tokens = {
15372                 (void *)&cmd_clear_vf_stats_clear,
15373                 (void *)&cmd_clear_vf_stats_vf,
15374                 (void *)&cmd_clear_vf_stats_stats,
15375                 (void *)&cmd_clear_vf_stats_port_id,
15376                 (void *)&cmd_clear_vf_stats_vf_id,
15377                 NULL,
15378         },
15379 };
15380
15381 /* port config pctype mapping reset */
15382
15383 /* Common result structure for port config pctype mapping reset */
15384 struct cmd_pctype_mapping_reset_result {
15385         cmdline_fixed_string_t port;
15386         cmdline_fixed_string_t config;
15387         portid_t port_id;
15388         cmdline_fixed_string_t pctype;
15389         cmdline_fixed_string_t mapping;
15390         cmdline_fixed_string_t reset;
15391 };
15392
15393 /* Common CLI fields for port config pctype mapping reset*/
15394 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15395         TOKEN_STRING_INITIALIZER
15396                 (struct cmd_pctype_mapping_reset_result,
15397                  port, "port");
15398 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15399         TOKEN_STRING_INITIALIZER
15400                 (struct cmd_pctype_mapping_reset_result,
15401                  config, "config");
15402 static cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15403         TOKEN_NUM_INITIALIZER
15404                 (struct cmd_pctype_mapping_reset_result,
15405                  port_id, RTE_UINT16);
15406 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15407         TOKEN_STRING_INITIALIZER
15408                 (struct cmd_pctype_mapping_reset_result,
15409                  pctype, "pctype");
15410 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15411         TOKEN_STRING_INITIALIZER
15412                 (struct cmd_pctype_mapping_reset_result,
15413                  mapping, "mapping");
15414 static cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15415         TOKEN_STRING_INITIALIZER
15416                 (struct cmd_pctype_mapping_reset_result,
15417                  reset, "reset");
15418
15419 static void
15420 cmd_pctype_mapping_reset_parsed(
15421         void *parsed_result,
15422         __rte_unused struct cmdline *cl,
15423         __rte_unused void *data)
15424 {
15425         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15426         int ret = -ENOTSUP;
15427
15428         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15429                 return;
15430
15431 #ifdef RTE_NET_I40E
15432         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15433 #endif
15434
15435         switch (ret) {
15436         case 0:
15437                 break;
15438         case -ENODEV:
15439                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15440                 break;
15441         case -ENOTSUP:
15442                 fprintf(stderr, "function not implemented\n");
15443                 break;
15444         default:
15445                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15446         }
15447 }
15448
15449 static cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15450         .f = cmd_pctype_mapping_reset_parsed,
15451         .data = NULL,
15452         .help_str = "port config <port_id> pctype mapping reset",
15453         .tokens = {
15454                 (void *)&cmd_pctype_mapping_reset_port,
15455                 (void *)&cmd_pctype_mapping_reset_config,
15456                 (void *)&cmd_pctype_mapping_reset_port_id,
15457                 (void *)&cmd_pctype_mapping_reset_pctype,
15458                 (void *)&cmd_pctype_mapping_reset_mapping,
15459                 (void *)&cmd_pctype_mapping_reset_reset,
15460                 NULL,
15461         },
15462 };
15463
15464 /* show port pctype mapping */
15465
15466 /* Common result structure for show port pctype mapping */
15467 struct cmd_pctype_mapping_get_result {
15468         cmdline_fixed_string_t show;
15469         cmdline_fixed_string_t port;
15470         portid_t port_id;
15471         cmdline_fixed_string_t pctype;
15472         cmdline_fixed_string_t mapping;
15473 };
15474
15475 /* Common CLI fields for pctype mapping get */
15476 static cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15477         TOKEN_STRING_INITIALIZER
15478                 (struct cmd_pctype_mapping_get_result,
15479                  show, "show");
15480 static cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15481         TOKEN_STRING_INITIALIZER
15482                 (struct cmd_pctype_mapping_get_result,
15483                  port, "port");
15484 static cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15485         TOKEN_NUM_INITIALIZER
15486                 (struct cmd_pctype_mapping_get_result,
15487                  port_id, RTE_UINT16);
15488 static cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15489         TOKEN_STRING_INITIALIZER
15490                 (struct cmd_pctype_mapping_get_result,
15491                  pctype, "pctype");
15492 static cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15493         TOKEN_STRING_INITIALIZER
15494                 (struct cmd_pctype_mapping_get_result,
15495                  mapping, "mapping");
15496
15497 static void
15498 cmd_pctype_mapping_get_parsed(
15499         void *parsed_result,
15500         __rte_unused struct cmdline *cl,
15501         __rte_unused void *data)
15502 {
15503         struct cmd_pctype_mapping_get_result *res = parsed_result;
15504         int ret = -ENOTSUP;
15505 #ifdef RTE_NET_I40E
15506         struct rte_pmd_i40e_flow_type_mapping
15507                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15508         int i, j, first_pctype;
15509 #endif
15510
15511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15512                 return;
15513
15514 #ifdef RTE_NET_I40E
15515         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15516 #endif
15517
15518         switch (ret) {
15519         case 0:
15520                 break;
15521         case -ENODEV:
15522                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15523                 return;
15524         case -ENOTSUP:
15525                 fprintf(stderr, "function not implemented\n");
15526                 return;
15527         default:
15528                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15529                 return;
15530         }
15531
15532 #ifdef RTE_NET_I40E
15533         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15534                 if (mapping[i].pctype != 0ULL) {
15535                         first_pctype = 1;
15536
15537                         printf("pctype: ");
15538                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15539                                 if (mapping[i].pctype & (1ULL << j)) {
15540                                         printf(first_pctype ?
15541                                                "%02d" : ",%02d", j);
15542                                         first_pctype = 0;
15543                                 }
15544                         }
15545                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15546                 }
15547         }
15548 #endif
15549 }
15550
15551 static cmdline_parse_inst_t cmd_pctype_mapping_get = {
15552         .f = cmd_pctype_mapping_get_parsed,
15553         .data = NULL,
15554         .help_str = "show port <port_id> pctype mapping",
15555         .tokens = {
15556                 (void *)&cmd_pctype_mapping_get_show,
15557                 (void *)&cmd_pctype_mapping_get_port,
15558                 (void *)&cmd_pctype_mapping_get_port_id,
15559                 (void *)&cmd_pctype_mapping_get_pctype,
15560                 (void *)&cmd_pctype_mapping_get_mapping,
15561                 NULL,
15562         },
15563 };
15564
15565 /* port config pctype mapping update */
15566
15567 /* Common result structure for port config pctype mapping update */
15568 struct cmd_pctype_mapping_update_result {
15569         cmdline_fixed_string_t port;
15570         cmdline_fixed_string_t config;
15571         portid_t port_id;
15572         cmdline_fixed_string_t pctype;
15573         cmdline_fixed_string_t mapping;
15574         cmdline_fixed_string_t update;
15575         cmdline_fixed_string_t pctype_list;
15576         uint16_t flow_type;
15577 };
15578
15579 /* Common CLI fields for pctype mapping update*/
15580 static cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15581         TOKEN_STRING_INITIALIZER
15582                 (struct cmd_pctype_mapping_update_result,
15583                  port, "port");
15584 static cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15585         TOKEN_STRING_INITIALIZER
15586                 (struct cmd_pctype_mapping_update_result,
15587                  config, "config");
15588 static cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15589         TOKEN_NUM_INITIALIZER
15590                 (struct cmd_pctype_mapping_update_result,
15591                  port_id, RTE_UINT16);
15592 static cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15593         TOKEN_STRING_INITIALIZER
15594                 (struct cmd_pctype_mapping_update_result,
15595                  pctype, "pctype");
15596 static cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15597         TOKEN_STRING_INITIALIZER
15598                 (struct cmd_pctype_mapping_update_result,
15599                  mapping, "mapping");
15600 static cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15601         TOKEN_STRING_INITIALIZER
15602                 (struct cmd_pctype_mapping_update_result,
15603                  update, "update");
15604 static cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15605         TOKEN_STRING_INITIALIZER
15606                 (struct cmd_pctype_mapping_update_result,
15607                  pctype_list, NULL);
15608 static cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15609         TOKEN_NUM_INITIALIZER
15610                 (struct cmd_pctype_mapping_update_result,
15611                  flow_type, RTE_UINT16);
15612
15613 static void
15614 cmd_pctype_mapping_update_parsed(
15615         void *parsed_result,
15616         __rte_unused struct cmdline *cl,
15617         __rte_unused void *data)
15618 {
15619         struct cmd_pctype_mapping_update_result *res = parsed_result;
15620         int ret = -ENOTSUP;
15621 #ifdef RTE_NET_I40E
15622         struct rte_pmd_i40e_flow_type_mapping mapping;
15623         unsigned int i;
15624         unsigned int nb_item;
15625         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15626 #endif
15627
15628         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15629                 return;
15630
15631 #ifdef RTE_NET_I40E
15632         nb_item = parse_item_list(res->pctype_list, "pctypes",
15633                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15634         mapping.flow_type = res->flow_type;
15635         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15636                 mapping.pctype |= (1ULL << pctype_list[i]);
15637         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15638                                                 &mapping,
15639                                                 1,
15640                                                 0);
15641 #endif
15642
15643         switch (ret) {
15644         case 0:
15645                 break;
15646         case -EINVAL:
15647                 fprintf(stderr, "invalid pctype or flow type\n");
15648                 break;
15649         case -ENODEV:
15650                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15651                 break;
15652         case -ENOTSUP:
15653                 fprintf(stderr, "function not implemented\n");
15654                 break;
15655         default:
15656                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15657         }
15658 }
15659
15660 static cmdline_parse_inst_t cmd_pctype_mapping_update = {
15661         .f = cmd_pctype_mapping_update_parsed,
15662         .data = NULL,
15663         .help_str = "port config <port_id> pctype mapping update"
15664         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15665         .tokens = {
15666                 (void *)&cmd_pctype_mapping_update_port,
15667                 (void *)&cmd_pctype_mapping_update_config,
15668                 (void *)&cmd_pctype_mapping_update_port_id,
15669                 (void *)&cmd_pctype_mapping_update_pctype,
15670                 (void *)&cmd_pctype_mapping_update_mapping,
15671                 (void *)&cmd_pctype_mapping_update_update,
15672                 (void *)&cmd_pctype_mapping_update_pc_type,
15673                 (void *)&cmd_pctype_mapping_update_flow_type,
15674                 NULL,
15675         },
15676 };
15677
15678 /* ptype mapping get */
15679
15680 /* Common result structure for ptype mapping get */
15681 struct cmd_ptype_mapping_get_result {
15682         cmdline_fixed_string_t ptype;
15683         cmdline_fixed_string_t mapping;
15684         cmdline_fixed_string_t get;
15685         portid_t port_id;
15686         uint8_t valid_only;
15687 };
15688
15689 /* Common CLI fields for ptype mapping get */
15690 static cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15691         TOKEN_STRING_INITIALIZER
15692                 (struct cmd_ptype_mapping_get_result,
15693                  ptype, "ptype");
15694 static cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15695         TOKEN_STRING_INITIALIZER
15696                 (struct cmd_ptype_mapping_get_result,
15697                  mapping, "mapping");
15698 static cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15699         TOKEN_STRING_INITIALIZER
15700                 (struct cmd_ptype_mapping_get_result,
15701                  get, "get");
15702 static cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15703         TOKEN_NUM_INITIALIZER
15704                 (struct cmd_ptype_mapping_get_result,
15705                  port_id, RTE_UINT16);
15706 static cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15707         TOKEN_NUM_INITIALIZER
15708                 (struct cmd_ptype_mapping_get_result,
15709                  valid_only, RTE_UINT8);
15710
15711 static void
15712 cmd_ptype_mapping_get_parsed(
15713         void *parsed_result,
15714         __rte_unused struct cmdline *cl,
15715         __rte_unused void *data)
15716 {
15717         struct cmd_ptype_mapping_get_result *res = parsed_result;
15718         int ret = -ENOTSUP;
15719 #ifdef RTE_NET_I40E
15720         int max_ptype_num = 256;
15721         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15722         uint16_t count;
15723         int i;
15724 #endif
15725
15726         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15727                 return;
15728
15729 #ifdef RTE_NET_I40E
15730         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15731                                         mapping,
15732                                         max_ptype_num,
15733                                         &count,
15734                                         res->valid_only);
15735 #endif
15736
15737         switch (ret) {
15738         case 0:
15739                 break;
15740         case -ENODEV:
15741                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15742                 break;
15743         case -ENOTSUP:
15744                 fprintf(stderr, "function not implemented\n");
15745                 break;
15746         default:
15747                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15748         }
15749
15750 #ifdef RTE_NET_I40E
15751         if (!ret) {
15752                 for (i = 0; i < count; i++)
15753                         printf("%3d\t0x%08x\n",
15754                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15755         }
15756 #endif
15757 }
15758
15759 static cmdline_parse_inst_t cmd_ptype_mapping_get = {
15760         .f = cmd_ptype_mapping_get_parsed,
15761         .data = NULL,
15762         .help_str = "ptype mapping get <port_id> <valid_only>",
15763         .tokens = {
15764                 (void *)&cmd_ptype_mapping_get_ptype,
15765                 (void *)&cmd_ptype_mapping_get_mapping,
15766                 (void *)&cmd_ptype_mapping_get_get,
15767                 (void *)&cmd_ptype_mapping_get_port_id,
15768                 (void *)&cmd_ptype_mapping_get_valid_only,
15769                 NULL,
15770         },
15771 };
15772
15773 /* ptype mapping replace */
15774
15775 /* Common result structure for ptype mapping replace */
15776 struct cmd_ptype_mapping_replace_result {
15777         cmdline_fixed_string_t ptype;
15778         cmdline_fixed_string_t mapping;
15779         cmdline_fixed_string_t replace;
15780         portid_t port_id;
15781         uint32_t target;
15782         uint8_t mask;
15783         uint32_t pkt_type;
15784 };
15785
15786 /* Common CLI fields for ptype mapping replace */
15787 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15788         TOKEN_STRING_INITIALIZER
15789                 (struct cmd_ptype_mapping_replace_result,
15790                  ptype, "ptype");
15791 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15792         TOKEN_STRING_INITIALIZER
15793                 (struct cmd_ptype_mapping_replace_result,
15794                  mapping, "mapping");
15795 static cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15796         TOKEN_STRING_INITIALIZER
15797                 (struct cmd_ptype_mapping_replace_result,
15798                  replace, "replace");
15799 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15800         TOKEN_NUM_INITIALIZER
15801                 (struct cmd_ptype_mapping_replace_result,
15802                  port_id, RTE_UINT16);
15803 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15804         TOKEN_NUM_INITIALIZER
15805                 (struct cmd_ptype_mapping_replace_result,
15806                  target, RTE_UINT32);
15807 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15808         TOKEN_NUM_INITIALIZER
15809                 (struct cmd_ptype_mapping_replace_result,
15810                  mask, RTE_UINT8);
15811 static cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15812         TOKEN_NUM_INITIALIZER
15813                 (struct cmd_ptype_mapping_replace_result,
15814                  pkt_type, RTE_UINT32);
15815
15816 static void
15817 cmd_ptype_mapping_replace_parsed(
15818         void *parsed_result,
15819         __rte_unused struct cmdline *cl,
15820         __rte_unused void *data)
15821 {
15822         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15823         int ret = -ENOTSUP;
15824
15825         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15826                 return;
15827
15828 #ifdef RTE_NET_I40E
15829         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15830                                         res->target,
15831                                         res->mask,
15832                                         res->pkt_type);
15833 #endif
15834
15835         switch (ret) {
15836         case 0:
15837                 break;
15838         case -EINVAL:
15839                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15840                         res->target, res->pkt_type);
15841                 break;
15842         case -ENODEV:
15843                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15844                 break;
15845         case -ENOTSUP:
15846                 fprintf(stderr, "function not implemented\n");
15847                 break;
15848         default:
15849                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15850         }
15851 }
15852
15853 static cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15854         .f = cmd_ptype_mapping_replace_parsed,
15855         .data = NULL,
15856         .help_str =
15857                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15858         .tokens = {
15859                 (void *)&cmd_ptype_mapping_replace_ptype,
15860                 (void *)&cmd_ptype_mapping_replace_mapping,
15861                 (void *)&cmd_ptype_mapping_replace_replace,
15862                 (void *)&cmd_ptype_mapping_replace_port_id,
15863                 (void *)&cmd_ptype_mapping_replace_target,
15864                 (void *)&cmd_ptype_mapping_replace_mask,
15865                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15866                 NULL,
15867         },
15868 };
15869
15870 /* ptype mapping reset */
15871
15872 /* Common result structure for ptype mapping reset */
15873 struct cmd_ptype_mapping_reset_result {
15874         cmdline_fixed_string_t ptype;
15875         cmdline_fixed_string_t mapping;
15876         cmdline_fixed_string_t reset;
15877         portid_t port_id;
15878 };
15879
15880 /* Common CLI fields for ptype mapping reset*/
15881 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15882         TOKEN_STRING_INITIALIZER
15883                 (struct cmd_ptype_mapping_reset_result,
15884                  ptype, "ptype");
15885 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15886         TOKEN_STRING_INITIALIZER
15887                 (struct cmd_ptype_mapping_reset_result,
15888                  mapping, "mapping");
15889 static cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15890         TOKEN_STRING_INITIALIZER
15891                 (struct cmd_ptype_mapping_reset_result,
15892                  reset, "reset");
15893 static cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15894         TOKEN_NUM_INITIALIZER
15895                 (struct cmd_ptype_mapping_reset_result,
15896                  port_id, RTE_UINT16);
15897
15898 static void
15899 cmd_ptype_mapping_reset_parsed(
15900         void *parsed_result,
15901         __rte_unused struct cmdline *cl,
15902         __rte_unused void *data)
15903 {
15904         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15905         int ret = -ENOTSUP;
15906
15907         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15908                 return;
15909
15910 #ifdef RTE_NET_I40E
15911         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15912 #endif
15913
15914         switch (ret) {
15915         case 0:
15916                 break;
15917         case -ENODEV:
15918                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15919                 break;
15920         case -ENOTSUP:
15921                 fprintf(stderr, "function not implemented\n");
15922                 break;
15923         default:
15924                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15925         }
15926 }
15927
15928 static cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15929         .f = cmd_ptype_mapping_reset_parsed,
15930         .data = NULL,
15931         .help_str = "ptype mapping reset <port_id>",
15932         .tokens = {
15933                 (void *)&cmd_ptype_mapping_reset_ptype,
15934                 (void *)&cmd_ptype_mapping_reset_mapping,
15935                 (void *)&cmd_ptype_mapping_reset_reset,
15936                 (void *)&cmd_ptype_mapping_reset_port_id,
15937                 NULL,
15938         },
15939 };
15940
15941 /* ptype mapping update */
15942
15943 /* Common result structure for ptype mapping update */
15944 struct cmd_ptype_mapping_update_result {
15945         cmdline_fixed_string_t ptype;
15946         cmdline_fixed_string_t mapping;
15947         cmdline_fixed_string_t reset;
15948         portid_t port_id;
15949         uint8_t hw_ptype;
15950         uint32_t sw_ptype;
15951 };
15952
15953 /* Common CLI fields for ptype mapping update*/
15954 static cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15955         TOKEN_STRING_INITIALIZER
15956                 (struct cmd_ptype_mapping_update_result,
15957                  ptype, "ptype");
15958 static cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15959         TOKEN_STRING_INITIALIZER
15960                 (struct cmd_ptype_mapping_update_result,
15961                  mapping, "mapping");
15962 static cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15963         TOKEN_STRING_INITIALIZER
15964                 (struct cmd_ptype_mapping_update_result,
15965                  reset, "update");
15966 static cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15967         TOKEN_NUM_INITIALIZER
15968                 (struct cmd_ptype_mapping_update_result,
15969                  port_id, RTE_UINT16);
15970 static cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15971         TOKEN_NUM_INITIALIZER
15972                 (struct cmd_ptype_mapping_update_result,
15973                  hw_ptype, RTE_UINT8);
15974 static cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15975         TOKEN_NUM_INITIALIZER
15976                 (struct cmd_ptype_mapping_update_result,
15977                  sw_ptype, RTE_UINT32);
15978
15979 static void
15980 cmd_ptype_mapping_update_parsed(
15981         void *parsed_result,
15982         __rte_unused struct cmdline *cl,
15983         __rte_unused void *data)
15984 {
15985         struct cmd_ptype_mapping_update_result *res = parsed_result;
15986         int ret = -ENOTSUP;
15987 #ifdef RTE_NET_I40E
15988         struct rte_pmd_i40e_ptype_mapping mapping;
15989 #endif
15990         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15991                 return;
15992
15993 #ifdef RTE_NET_I40E
15994         mapping.hw_ptype = res->hw_ptype;
15995         mapping.sw_ptype = res->sw_ptype;
15996         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15997                                                 &mapping,
15998                                                 1,
15999                                                 0);
16000 #endif
16001
16002         switch (ret) {
16003         case 0:
16004                 break;
16005         case -EINVAL:
16006                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
16007                 break;
16008         case -ENODEV:
16009                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
16010                 break;
16011         case -ENOTSUP:
16012                 fprintf(stderr, "function not implemented\n");
16013                 break;
16014         default:
16015                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
16016         }
16017 }
16018
16019 static cmdline_parse_inst_t cmd_ptype_mapping_update = {
16020         .f = cmd_ptype_mapping_update_parsed,
16021         .data = NULL,
16022         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16023         .tokens = {
16024                 (void *)&cmd_ptype_mapping_update_ptype,
16025                 (void *)&cmd_ptype_mapping_update_mapping,
16026                 (void *)&cmd_ptype_mapping_update_update,
16027                 (void *)&cmd_ptype_mapping_update_port_id,
16028                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16029                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16030                 NULL,
16031         },
16032 };
16033
16034 /* Common result structure for file commands */
16035 struct cmd_cmdfile_result {
16036         cmdline_fixed_string_t load;
16037         cmdline_fixed_string_t filename;
16038 };
16039
16040 /* Common CLI fields for file commands */
16041 static cmdline_parse_token_string_t cmd_load_cmdfile =
16042         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16043 static cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16044         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16045
16046 static void
16047 cmd_load_from_file_parsed(
16048         void *parsed_result,
16049         __rte_unused struct cmdline *cl,
16050         __rte_unused void *data)
16051 {
16052         struct cmd_cmdfile_result *res = parsed_result;
16053
16054         cmdline_read_from_file(res->filename);
16055 }
16056
16057 static cmdline_parse_inst_t cmd_load_from_file = {
16058         .f = cmd_load_from_file_parsed,
16059         .data = NULL,
16060         .help_str = "load <filename>",
16061         .tokens = {
16062                 (void *)&cmd_load_cmdfile,
16063                 (void *)&cmd_load_cmdfile_filename,
16064                 NULL,
16065         },
16066 };
16067
16068 /* Get Rx offloads capabilities */
16069 struct cmd_rx_offload_get_capa_result {
16070         cmdline_fixed_string_t show;
16071         cmdline_fixed_string_t port;
16072         portid_t port_id;
16073         cmdline_fixed_string_t rx_offload;
16074         cmdline_fixed_string_t capabilities;
16075 };
16076
16077 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16078         TOKEN_STRING_INITIALIZER
16079                 (struct cmd_rx_offload_get_capa_result,
16080                  show, "show");
16081 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16082         TOKEN_STRING_INITIALIZER
16083                 (struct cmd_rx_offload_get_capa_result,
16084                  port, "port");
16085 static cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16086         TOKEN_NUM_INITIALIZER
16087                 (struct cmd_rx_offload_get_capa_result,
16088                  port_id, RTE_UINT16);
16089 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16090         TOKEN_STRING_INITIALIZER
16091                 (struct cmd_rx_offload_get_capa_result,
16092                  rx_offload, "rx_offload");
16093 static cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16094         TOKEN_STRING_INITIALIZER
16095                 (struct cmd_rx_offload_get_capa_result,
16096                  capabilities, "capabilities");
16097
16098 static void
16099 print_rx_offloads(uint64_t offloads)
16100 {
16101         uint64_t single_offload;
16102         int begin;
16103         int end;
16104         int bit;
16105
16106         if (offloads == 0)
16107                 return;
16108
16109         begin = __builtin_ctzll(offloads);
16110         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16111
16112         single_offload = 1ULL << begin;
16113         for (bit = begin; bit < end; bit++) {
16114                 if (offloads & single_offload)
16115                         printf(" %s",
16116                                rte_eth_dev_rx_offload_name(single_offload));
16117                 single_offload <<= 1;
16118         }
16119 }
16120
16121 static void
16122 cmd_rx_offload_get_capa_parsed(
16123         void *parsed_result,
16124         __rte_unused struct cmdline *cl,
16125         __rte_unused void *data)
16126 {
16127         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16128         struct rte_eth_dev_info dev_info;
16129         portid_t port_id = res->port_id;
16130         uint64_t queue_offloads;
16131         uint64_t port_offloads;
16132         int ret;
16133
16134         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16135         if (ret != 0)
16136                 return;
16137
16138         queue_offloads = dev_info.rx_queue_offload_capa;
16139         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16140
16141         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16142         printf("  Per Queue :");
16143         print_rx_offloads(queue_offloads);
16144
16145         printf("\n");
16146         printf("  Per Port  :");
16147         print_rx_offloads(port_offloads);
16148         printf("\n\n");
16149 }
16150
16151 static cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16152         .f = cmd_rx_offload_get_capa_parsed,
16153         .data = NULL,
16154         .help_str = "show port <port_id> rx_offload capabilities",
16155         .tokens = {
16156                 (void *)&cmd_rx_offload_get_capa_show,
16157                 (void *)&cmd_rx_offload_get_capa_port,
16158                 (void *)&cmd_rx_offload_get_capa_port_id,
16159                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16160                 (void *)&cmd_rx_offload_get_capa_capabilities,
16161                 NULL,
16162         }
16163 };
16164
16165 /* Get Rx offloads configuration */
16166 struct cmd_rx_offload_get_configuration_result {
16167         cmdline_fixed_string_t show;
16168         cmdline_fixed_string_t port;
16169         portid_t port_id;
16170         cmdline_fixed_string_t rx_offload;
16171         cmdline_fixed_string_t configuration;
16172 };
16173
16174 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16175         TOKEN_STRING_INITIALIZER
16176                 (struct cmd_rx_offload_get_configuration_result,
16177                  show, "show");
16178 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16179         TOKEN_STRING_INITIALIZER
16180                 (struct cmd_rx_offload_get_configuration_result,
16181                  port, "port");
16182 static cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16183         TOKEN_NUM_INITIALIZER
16184                 (struct cmd_rx_offload_get_configuration_result,
16185                  port_id, RTE_UINT16);
16186 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16187         TOKEN_STRING_INITIALIZER
16188                 (struct cmd_rx_offload_get_configuration_result,
16189                  rx_offload, "rx_offload");
16190 static cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16191         TOKEN_STRING_INITIALIZER
16192                 (struct cmd_rx_offload_get_configuration_result,
16193                  configuration, "configuration");
16194
16195 static void
16196 cmd_rx_offload_get_configuration_parsed(
16197         void *parsed_result,
16198         __rte_unused struct cmdline *cl,
16199         __rte_unused void *data)
16200 {
16201         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16202         struct rte_eth_dev_info dev_info;
16203         portid_t port_id = res->port_id;
16204         struct rte_port *port = &ports[port_id];
16205         struct rte_eth_conf dev_conf;
16206         uint64_t port_offloads;
16207         uint64_t queue_offloads;
16208         uint16_t nb_rx_queues;
16209         int q;
16210         int ret;
16211
16212         printf("Rx Offloading Configuration of port %d :\n", port_id);
16213
16214         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16215         if (ret != 0)
16216                 return;
16217
16218         port_offloads = dev_conf.rxmode.offloads;
16219         printf("  Port :");
16220         print_rx_offloads(port_offloads);
16221         printf("\n");
16222
16223         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16224         if (ret != 0)
16225                 return;
16226
16227         nb_rx_queues = dev_info.nb_rx_queues;
16228         for (q = 0; q < nb_rx_queues; q++) {
16229                 queue_offloads = port->rxq[q].conf.offloads;
16230                 printf("  Queue[%2d] :", q);
16231                 print_rx_offloads(queue_offloads);
16232                 printf("\n");
16233         }
16234         printf("\n");
16235 }
16236
16237 static cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16238         .f = cmd_rx_offload_get_configuration_parsed,
16239         .data = NULL,
16240         .help_str = "show port <port_id> rx_offload configuration",
16241         .tokens = {
16242                 (void *)&cmd_rx_offload_get_configuration_show,
16243                 (void *)&cmd_rx_offload_get_configuration_port,
16244                 (void *)&cmd_rx_offload_get_configuration_port_id,
16245                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16246                 (void *)&cmd_rx_offload_get_configuration_configuration,
16247                 NULL,
16248         }
16249 };
16250
16251 /* Enable/Disable a per port offloading */
16252 struct cmd_config_per_port_rx_offload_result {
16253         cmdline_fixed_string_t port;
16254         cmdline_fixed_string_t config;
16255         portid_t port_id;
16256         cmdline_fixed_string_t rx_offload;
16257         cmdline_fixed_string_t offload;
16258         cmdline_fixed_string_t on_off;
16259 };
16260
16261 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16262         TOKEN_STRING_INITIALIZER
16263                 (struct cmd_config_per_port_rx_offload_result,
16264                  port, "port");
16265 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16266         TOKEN_STRING_INITIALIZER
16267                 (struct cmd_config_per_port_rx_offload_result,
16268                  config, "config");
16269 static cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16270         TOKEN_NUM_INITIALIZER
16271                 (struct cmd_config_per_port_rx_offload_result,
16272                  port_id, RTE_UINT16);
16273 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16274         TOKEN_STRING_INITIALIZER
16275                 (struct cmd_config_per_port_rx_offload_result,
16276                  rx_offload, "rx_offload");
16277 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16278         TOKEN_STRING_INITIALIZER
16279                 (struct cmd_config_per_port_rx_offload_result,
16280                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16281                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16282                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16283                            "scatter#buffer_split#timestamp#security#"
16284                            "keep_crc#rss_hash");
16285 static cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16286         TOKEN_STRING_INITIALIZER
16287                 (struct cmd_config_per_port_rx_offload_result,
16288                  on_off, "on#off");
16289
16290 static uint64_t
16291 search_rx_offload(const char *name)
16292 {
16293         uint64_t single_offload;
16294         const char *single_name;
16295         int found = 0;
16296         unsigned int bit;
16297
16298         single_offload = 1;
16299         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16300                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16301                 if (!strcasecmp(single_name, name)) {
16302                         found = 1;
16303                         break;
16304                 }
16305                 single_offload <<= 1;
16306         }
16307
16308         if (found)
16309                 return single_offload;
16310
16311         return 0;
16312 }
16313
16314 static void
16315 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16316                                 __rte_unused struct cmdline *cl,
16317                                 __rte_unused void *data)
16318 {
16319         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16320         portid_t port_id = res->port_id;
16321         struct rte_eth_dev_info dev_info;
16322         struct rte_port *port = &ports[port_id];
16323         uint64_t single_offload;
16324         uint16_t nb_rx_queues;
16325         int q;
16326         int ret;
16327
16328         if (port->port_status != RTE_PORT_STOPPED) {
16329                 fprintf(stderr,
16330                         "Error: Can't config offload when Port %d is not stopped\n",
16331                         port_id);
16332                 return;
16333         }
16334
16335         single_offload = search_rx_offload(res->offload);
16336         if (single_offload == 0) {
16337                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16338                 return;
16339         }
16340
16341         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16342         if (ret != 0)
16343                 return;
16344
16345         nb_rx_queues = dev_info.nb_rx_queues;
16346         if (!strcmp(res->on_off, "on")) {
16347                 port->dev_conf.rxmode.offloads |= single_offload;
16348                 for (q = 0; q < nb_rx_queues; q++)
16349                         port->rxq[q].conf.offloads |= single_offload;
16350         } else {
16351                 port->dev_conf.rxmode.offloads &= ~single_offload;
16352                 for (q = 0; q < nb_rx_queues; q++)
16353                         port->rxq[q].conf.offloads &= ~single_offload;
16354         }
16355
16356         cmd_reconfig_device_queue(port_id, 1, 1);
16357 }
16358
16359 static cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16360         .f = cmd_config_per_port_rx_offload_parsed,
16361         .data = NULL,
16362         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16363                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16364                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16365                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16366                     "keep_crc|rss_hash on|off",
16367         .tokens = {
16368                 (void *)&cmd_config_per_port_rx_offload_result_port,
16369                 (void *)&cmd_config_per_port_rx_offload_result_config,
16370                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16371                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16372                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16373                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16374                 NULL,
16375         }
16376 };
16377
16378 /* Enable/Disable a per queue offloading */
16379 struct cmd_config_per_queue_rx_offload_result {
16380         cmdline_fixed_string_t port;
16381         portid_t port_id;
16382         cmdline_fixed_string_t rxq;
16383         uint16_t queue_id;
16384         cmdline_fixed_string_t rx_offload;
16385         cmdline_fixed_string_t offload;
16386         cmdline_fixed_string_t on_off;
16387 };
16388
16389 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16390         TOKEN_STRING_INITIALIZER
16391                 (struct cmd_config_per_queue_rx_offload_result,
16392                  port, "port");
16393 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16394         TOKEN_NUM_INITIALIZER
16395                 (struct cmd_config_per_queue_rx_offload_result,
16396                  port_id, RTE_UINT16);
16397 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16398         TOKEN_STRING_INITIALIZER
16399                 (struct cmd_config_per_queue_rx_offload_result,
16400                  rxq, "rxq");
16401 static cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16402         TOKEN_NUM_INITIALIZER
16403                 (struct cmd_config_per_queue_rx_offload_result,
16404                  queue_id, RTE_UINT16);
16405 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16406         TOKEN_STRING_INITIALIZER
16407                 (struct cmd_config_per_queue_rx_offload_result,
16408                  rx_offload, "rx_offload");
16409 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16410         TOKEN_STRING_INITIALIZER
16411                 (struct cmd_config_per_queue_rx_offload_result,
16412                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16413                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16414                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16415                            "scatter#buffer_split#timestamp#security#keep_crc");
16416 static cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16417         TOKEN_STRING_INITIALIZER
16418                 (struct cmd_config_per_queue_rx_offload_result,
16419                  on_off, "on#off");
16420
16421 static void
16422 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16423                                 __rte_unused struct cmdline *cl,
16424                                 __rte_unused void *data)
16425 {
16426         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16427         struct rte_eth_dev_info dev_info;
16428         portid_t port_id = res->port_id;
16429         uint16_t queue_id = res->queue_id;
16430         struct rte_port *port = &ports[port_id];
16431         uint64_t single_offload;
16432         int ret;
16433
16434         if (port->port_status != RTE_PORT_STOPPED) {
16435                 fprintf(stderr,
16436                         "Error: Can't config offload when Port %d is not stopped\n",
16437                         port_id);
16438                 return;
16439         }
16440
16441         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16442         if (ret != 0)
16443                 return;
16444
16445         if (queue_id >= dev_info.nb_rx_queues) {
16446                 fprintf(stderr,
16447                         "Error: input queue_id should be 0 ... %d\n",
16448                         dev_info.nb_rx_queues - 1);
16449                 return;
16450         }
16451
16452         single_offload = search_rx_offload(res->offload);
16453         if (single_offload == 0) {
16454                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16455                 return;
16456         }
16457
16458         if (!strcmp(res->on_off, "on"))
16459                 port->rxq[queue_id].conf.offloads |= single_offload;
16460         else
16461                 port->rxq[queue_id].conf.offloads &= ~single_offload;
16462
16463         cmd_reconfig_device_queue(port_id, 1, 1);
16464 }
16465
16466 static cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16467         .f = cmd_config_per_queue_rx_offload_parsed,
16468         .data = NULL,
16469         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16470                     "vlan_strip|ipv4_cksum|"
16471                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16472                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16473                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16474                     "keep_crc on|off",
16475         .tokens = {
16476                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16477                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16478                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16479                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16480                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16481                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16482                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16483                 NULL,
16484         }
16485 };
16486
16487 /* Get Tx offloads capabilities */
16488 struct cmd_tx_offload_get_capa_result {
16489         cmdline_fixed_string_t show;
16490         cmdline_fixed_string_t port;
16491         portid_t port_id;
16492         cmdline_fixed_string_t tx_offload;
16493         cmdline_fixed_string_t capabilities;
16494 };
16495
16496 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16497         TOKEN_STRING_INITIALIZER
16498                 (struct cmd_tx_offload_get_capa_result,
16499                  show, "show");
16500 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16501         TOKEN_STRING_INITIALIZER
16502                 (struct cmd_tx_offload_get_capa_result,
16503                  port, "port");
16504 static cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16505         TOKEN_NUM_INITIALIZER
16506                 (struct cmd_tx_offload_get_capa_result,
16507                  port_id, RTE_UINT16);
16508 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16509         TOKEN_STRING_INITIALIZER
16510                 (struct cmd_tx_offload_get_capa_result,
16511                  tx_offload, "tx_offload");
16512 static cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16513         TOKEN_STRING_INITIALIZER
16514                 (struct cmd_tx_offload_get_capa_result,
16515                  capabilities, "capabilities");
16516
16517 static void
16518 print_tx_offloads(uint64_t offloads)
16519 {
16520         uint64_t single_offload;
16521         int begin;
16522         int end;
16523         int bit;
16524
16525         if (offloads == 0)
16526                 return;
16527
16528         begin = __builtin_ctzll(offloads);
16529         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16530
16531         single_offload = 1ULL << begin;
16532         for (bit = begin; bit < end; bit++) {
16533                 if (offloads & single_offload)
16534                         printf(" %s",
16535                                rte_eth_dev_tx_offload_name(single_offload));
16536                 single_offload <<= 1;
16537         }
16538 }
16539
16540 static void
16541 cmd_tx_offload_get_capa_parsed(
16542         void *parsed_result,
16543         __rte_unused struct cmdline *cl,
16544         __rte_unused void *data)
16545 {
16546         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16547         struct rte_eth_dev_info dev_info;
16548         portid_t port_id = res->port_id;
16549         uint64_t queue_offloads;
16550         uint64_t port_offloads;
16551         int ret;
16552
16553         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16554         if (ret != 0)
16555                 return;
16556
16557         queue_offloads = dev_info.tx_queue_offload_capa;
16558         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16559
16560         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16561         printf("  Per Queue :");
16562         print_tx_offloads(queue_offloads);
16563
16564         printf("\n");
16565         printf("  Per Port  :");
16566         print_tx_offloads(port_offloads);
16567         printf("\n\n");
16568 }
16569
16570 static cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16571         .f = cmd_tx_offload_get_capa_parsed,
16572         .data = NULL,
16573         .help_str = "show port <port_id> tx_offload capabilities",
16574         .tokens = {
16575                 (void *)&cmd_tx_offload_get_capa_show,
16576                 (void *)&cmd_tx_offload_get_capa_port,
16577                 (void *)&cmd_tx_offload_get_capa_port_id,
16578                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16579                 (void *)&cmd_tx_offload_get_capa_capabilities,
16580                 NULL,
16581         }
16582 };
16583
16584 /* Get Tx offloads configuration */
16585 struct cmd_tx_offload_get_configuration_result {
16586         cmdline_fixed_string_t show;
16587         cmdline_fixed_string_t port;
16588         portid_t port_id;
16589         cmdline_fixed_string_t tx_offload;
16590         cmdline_fixed_string_t configuration;
16591 };
16592
16593 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16594         TOKEN_STRING_INITIALIZER
16595                 (struct cmd_tx_offload_get_configuration_result,
16596                  show, "show");
16597 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16598         TOKEN_STRING_INITIALIZER
16599                 (struct cmd_tx_offload_get_configuration_result,
16600                  port, "port");
16601 static cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16602         TOKEN_NUM_INITIALIZER
16603                 (struct cmd_tx_offload_get_configuration_result,
16604                  port_id, RTE_UINT16);
16605 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16606         TOKEN_STRING_INITIALIZER
16607                 (struct cmd_tx_offload_get_configuration_result,
16608                  tx_offload, "tx_offload");
16609 static cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16610         TOKEN_STRING_INITIALIZER
16611                 (struct cmd_tx_offload_get_configuration_result,
16612                  configuration, "configuration");
16613
16614 static void
16615 cmd_tx_offload_get_configuration_parsed(
16616         void *parsed_result,
16617         __rte_unused struct cmdline *cl,
16618         __rte_unused void *data)
16619 {
16620         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16621         struct rte_eth_dev_info dev_info;
16622         portid_t port_id = res->port_id;
16623         struct rte_port *port = &ports[port_id];
16624         struct rte_eth_conf dev_conf;
16625         uint64_t port_offloads;
16626         uint64_t queue_offloads;
16627         uint16_t nb_tx_queues;
16628         int q;
16629         int ret;
16630
16631         printf("Tx Offloading Configuration of port %d :\n", port_id);
16632
16633         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16634         if (ret != 0)
16635                 return;
16636
16637         port_offloads = dev_conf.txmode.offloads;
16638         printf("  Port :");
16639         print_tx_offloads(port_offloads);
16640         printf("\n");
16641
16642         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16643         if (ret != 0)
16644                 return;
16645
16646         nb_tx_queues = dev_info.nb_tx_queues;
16647         for (q = 0; q < nb_tx_queues; q++) {
16648                 queue_offloads = port->txq[q].conf.offloads;
16649                 printf("  Queue[%2d] :", q);
16650                 print_tx_offloads(queue_offloads);
16651                 printf("\n");
16652         }
16653         printf("\n");
16654 }
16655
16656 static cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16657         .f = cmd_tx_offload_get_configuration_parsed,
16658         .data = NULL,
16659         .help_str = "show port <port_id> tx_offload configuration",
16660         .tokens = {
16661                 (void *)&cmd_tx_offload_get_configuration_show,
16662                 (void *)&cmd_tx_offload_get_configuration_port,
16663                 (void *)&cmd_tx_offload_get_configuration_port_id,
16664                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16665                 (void *)&cmd_tx_offload_get_configuration_configuration,
16666                 NULL,
16667         }
16668 };
16669
16670 /* Enable/Disable a per port offloading */
16671 struct cmd_config_per_port_tx_offload_result {
16672         cmdline_fixed_string_t port;
16673         cmdline_fixed_string_t config;
16674         portid_t port_id;
16675         cmdline_fixed_string_t tx_offload;
16676         cmdline_fixed_string_t offload;
16677         cmdline_fixed_string_t on_off;
16678 };
16679
16680 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16681         TOKEN_STRING_INITIALIZER
16682                 (struct cmd_config_per_port_tx_offload_result,
16683                  port, "port");
16684 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16685         TOKEN_STRING_INITIALIZER
16686                 (struct cmd_config_per_port_tx_offload_result,
16687                  config, "config");
16688 static cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16689         TOKEN_NUM_INITIALIZER
16690                 (struct cmd_config_per_port_tx_offload_result,
16691                  port_id, RTE_UINT16);
16692 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16693         TOKEN_STRING_INITIALIZER
16694                 (struct cmd_config_per_port_tx_offload_result,
16695                  tx_offload, "tx_offload");
16696 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16697         TOKEN_STRING_INITIALIZER
16698                 (struct cmd_config_per_port_tx_offload_result,
16699                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16700                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16701                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16702                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16703                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16704                           "send_on_timestamp");
16705 static cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16706         TOKEN_STRING_INITIALIZER
16707                 (struct cmd_config_per_port_tx_offload_result,
16708                  on_off, "on#off");
16709
16710 static uint64_t
16711 search_tx_offload(const char *name)
16712 {
16713         uint64_t single_offload;
16714         const char *single_name;
16715         int found = 0;
16716         unsigned int bit;
16717
16718         single_offload = 1;
16719         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16720                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16721                 if (single_name == NULL)
16722                         break;
16723                 if (!strcasecmp(single_name, name)) {
16724                         found = 1;
16725                         break;
16726                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16727                         break;
16728                 single_offload <<= 1;
16729         }
16730
16731         if (found)
16732                 return single_offload;
16733
16734         return 0;
16735 }
16736
16737 static void
16738 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16739                                 __rte_unused struct cmdline *cl,
16740                                 __rte_unused void *data)
16741 {
16742         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16743         portid_t port_id = res->port_id;
16744         struct rte_eth_dev_info dev_info;
16745         struct rte_port *port = &ports[port_id];
16746         uint64_t single_offload;
16747         uint16_t nb_tx_queues;
16748         int q;
16749         int ret;
16750
16751         if (port->port_status != RTE_PORT_STOPPED) {
16752                 fprintf(stderr,
16753                         "Error: Can't config offload when Port %d is not stopped\n",
16754                         port_id);
16755                 return;
16756         }
16757
16758         single_offload = search_tx_offload(res->offload);
16759         if (single_offload == 0) {
16760                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16761                 return;
16762         }
16763
16764         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16765         if (ret != 0)
16766                 return;
16767
16768         nb_tx_queues = dev_info.nb_tx_queues;
16769         if (!strcmp(res->on_off, "on")) {
16770                 port->dev_conf.txmode.offloads |= single_offload;
16771                 for (q = 0; q < nb_tx_queues; q++)
16772                         port->txq[q].conf.offloads |= single_offload;
16773         } else {
16774                 port->dev_conf.txmode.offloads &= ~single_offload;
16775                 for (q = 0; q < nb_tx_queues; q++)
16776                         port->txq[q].conf.offloads &= ~single_offload;
16777         }
16778
16779         cmd_reconfig_device_queue(port_id, 1, 1);
16780 }
16781
16782 static cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16783         .f = cmd_config_per_port_tx_offload_parsed,
16784         .data = NULL,
16785         .help_str = "port config <port_id> tx_offload "
16786                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16787                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16788                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16789                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16790                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16791                     "send_on_timestamp on|off",
16792         .tokens = {
16793                 (void *)&cmd_config_per_port_tx_offload_result_port,
16794                 (void *)&cmd_config_per_port_tx_offload_result_config,
16795                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16796                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16797                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16798                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16799                 NULL,
16800         }
16801 };
16802
16803 /* Enable/Disable a per queue offloading */
16804 struct cmd_config_per_queue_tx_offload_result {
16805         cmdline_fixed_string_t port;
16806         portid_t port_id;
16807         cmdline_fixed_string_t txq;
16808         uint16_t queue_id;
16809         cmdline_fixed_string_t tx_offload;
16810         cmdline_fixed_string_t offload;
16811         cmdline_fixed_string_t on_off;
16812 };
16813
16814 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16815         TOKEN_STRING_INITIALIZER
16816                 (struct cmd_config_per_queue_tx_offload_result,
16817                  port, "port");
16818 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16819         TOKEN_NUM_INITIALIZER
16820                 (struct cmd_config_per_queue_tx_offload_result,
16821                  port_id, RTE_UINT16);
16822 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16823         TOKEN_STRING_INITIALIZER
16824                 (struct cmd_config_per_queue_tx_offload_result,
16825                  txq, "txq");
16826 static cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16827         TOKEN_NUM_INITIALIZER
16828                 (struct cmd_config_per_queue_tx_offload_result,
16829                  queue_id, RTE_UINT16);
16830 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16831         TOKEN_STRING_INITIALIZER
16832                 (struct cmd_config_per_queue_tx_offload_result,
16833                  tx_offload, "tx_offload");
16834 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16835         TOKEN_STRING_INITIALIZER
16836                 (struct cmd_config_per_queue_tx_offload_result,
16837                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16838                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16839                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16840                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16841                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16842 static cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16843         TOKEN_STRING_INITIALIZER
16844                 (struct cmd_config_per_queue_tx_offload_result,
16845                  on_off, "on#off");
16846
16847 static void
16848 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16849                                 __rte_unused struct cmdline *cl,
16850                                 __rte_unused void *data)
16851 {
16852         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16853         struct rte_eth_dev_info dev_info;
16854         portid_t port_id = res->port_id;
16855         uint16_t queue_id = res->queue_id;
16856         struct rte_port *port = &ports[port_id];
16857         uint64_t single_offload;
16858         int ret;
16859
16860         if (port->port_status != RTE_PORT_STOPPED) {
16861                 fprintf(stderr,
16862                         "Error: Can't config offload when Port %d is not stopped\n",
16863                         port_id);
16864                 return;
16865         }
16866
16867         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16868         if (ret != 0)
16869                 return;
16870
16871         if (queue_id >= dev_info.nb_tx_queues) {
16872                 fprintf(stderr,
16873                         "Error: input queue_id should be 0 ... %d\n",
16874                         dev_info.nb_tx_queues - 1);
16875                 return;
16876         }
16877
16878         single_offload = search_tx_offload(res->offload);
16879         if (single_offload == 0) {
16880                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16881                 return;
16882         }
16883
16884         if (!strcmp(res->on_off, "on"))
16885                 port->txq[queue_id].conf.offloads |= single_offload;
16886         else
16887                 port->txq[queue_id].conf.offloads &= ~single_offload;
16888
16889         cmd_reconfig_device_queue(port_id, 1, 1);
16890 }
16891
16892 static cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16893         .f = cmd_config_per_queue_tx_offload_parsed,
16894         .data = NULL,
16895         .help_str = "port <port_id> txq <queue_id> tx_offload "
16896                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16897                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16898                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16899                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16900                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16901                     "on|off",
16902         .tokens = {
16903                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16904                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16905                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16906                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16907                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16908                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16909                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16910                 NULL,
16911         }
16912 };
16913
16914 /* *** configure tx_metadata for specific port *** */
16915 struct cmd_config_tx_metadata_specific_result {
16916         cmdline_fixed_string_t port;
16917         cmdline_fixed_string_t keyword;
16918         uint16_t port_id;
16919         cmdline_fixed_string_t item;
16920         uint32_t value;
16921 };
16922
16923 static void
16924 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16925                                 __rte_unused struct cmdline *cl,
16926                                 __rte_unused void *data)
16927 {
16928         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16929
16930         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16931                 return;
16932         ports[res->port_id].tx_metadata = res->value;
16933         /* Add/remove callback to insert valid metadata in every Tx packet. */
16934         if (ports[res->port_id].tx_metadata)
16935                 add_tx_md_callback(res->port_id);
16936         else
16937                 remove_tx_md_callback(res->port_id);
16938         rte_flow_dynf_metadata_register();
16939 }
16940
16941 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16942         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16943                         port, "port");
16944 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16945         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16946                         keyword, "config");
16947 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16948         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16949                         port_id, RTE_UINT16);
16950 static cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16951         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16952                         item, "tx_metadata");
16953 static cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16954         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16955                         value, RTE_UINT32);
16956
16957 static cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16958         .f = cmd_config_tx_metadata_specific_parsed,
16959         .data = NULL,
16960         .help_str = "port config <port_id> tx_metadata <value>",
16961         .tokens = {
16962                 (void *)&cmd_config_tx_metadata_specific_port,
16963                 (void *)&cmd_config_tx_metadata_specific_keyword,
16964                 (void *)&cmd_config_tx_metadata_specific_id,
16965                 (void *)&cmd_config_tx_metadata_specific_item,
16966                 (void *)&cmd_config_tx_metadata_specific_value,
16967                 NULL,
16968         },
16969 };
16970
16971 /* *** set dynf *** */
16972 struct cmd_config_tx_dynf_specific_result {
16973         cmdline_fixed_string_t port;
16974         cmdline_fixed_string_t keyword;
16975         uint16_t port_id;
16976         cmdline_fixed_string_t item;
16977         cmdline_fixed_string_t name;
16978         cmdline_fixed_string_t value;
16979 };
16980
16981 static void
16982 cmd_config_dynf_specific_parsed(void *parsed_result,
16983                                 __rte_unused struct cmdline *cl,
16984                                 __rte_unused void *data)
16985 {
16986         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16987         struct rte_mbuf_dynflag desc_flag;
16988         int flag;
16989         uint64_t old_port_flags;
16990
16991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16992                 return;
16993         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16994         if (flag <= 0) {
16995                 if (strlcpy(desc_flag.name, res->name,
16996                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16997                         fprintf(stderr, "Flag name too long\n");
16998                         return;
16999                 }
17000                 desc_flag.flags = 0;
17001                 flag = rte_mbuf_dynflag_register(&desc_flag);
17002                 if (flag < 0) {
17003                         fprintf(stderr, "Can't register flag\n");
17004                         return;
17005                 }
17006                 strcpy(dynf_names[flag], desc_flag.name);
17007         }
17008         old_port_flags = ports[res->port_id].mbuf_dynf;
17009         if (!strcmp(res->value, "set")) {
17010                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
17011                 if (old_port_flags == 0)
17012                         add_tx_dynf_callback(res->port_id);
17013         } else {
17014                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
17015                 if (ports[res->port_id].mbuf_dynf == 0)
17016                         remove_tx_dynf_callback(res->port_id);
17017         }
17018 }
17019
17020 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17021         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17022                         keyword, "port");
17023 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17024         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17025                         keyword, "config");
17026 static cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17027         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17028                         port_id, RTE_UINT16);
17029 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17030         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17031                         item, "dynf");
17032 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17033         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17034                         name, NULL);
17035 static cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17036         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17037                         value, "set#clear");
17038
17039 static cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17040         .f = cmd_config_dynf_specific_parsed,
17041         .data = NULL,
17042         .help_str = "port config <port id> dynf <name> set|clear",
17043         .tokens = {
17044                 (void *)&cmd_config_tx_dynf_specific_port,
17045                 (void *)&cmd_config_tx_dynf_specific_keyword,
17046                 (void *)&cmd_config_tx_dynf_specific_port_id,
17047                 (void *)&cmd_config_tx_dynf_specific_item,
17048                 (void *)&cmd_config_tx_dynf_specific_name,
17049                 (void *)&cmd_config_tx_dynf_specific_value,
17050                 NULL,
17051         },
17052 };
17053
17054 /* *** display tx_metadata per port configuration *** */
17055 struct cmd_show_tx_metadata_result {
17056         cmdline_fixed_string_t cmd_show;
17057         cmdline_fixed_string_t cmd_port;
17058         cmdline_fixed_string_t cmd_keyword;
17059         portid_t cmd_pid;
17060 };
17061
17062 static void
17063 cmd_show_tx_metadata_parsed(void *parsed_result,
17064                 __rte_unused struct cmdline *cl,
17065                 __rte_unused void *data)
17066 {
17067         struct cmd_show_tx_metadata_result *res = parsed_result;
17068
17069         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17070                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17071                 return;
17072         }
17073         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17074                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17075                        ports[res->cmd_pid].tx_metadata);
17076         }
17077 }
17078
17079 static cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17080         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17081                         cmd_show, "show");
17082 static cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17083         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17084                         cmd_port, "port");
17085 static cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17086         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17087                         cmd_pid, RTE_UINT16);
17088 static cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17089         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17090                         cmd_keyword, "tx_metadata");
17091
17092 static cmdline_parse_inst_t cmd_show_tx_metadata = {
17093         .f = cmd_show_tx_metadata_parsed,
17094         .data = NULL,
17095         .help_str = "show port <port_id> tx_metadata",
17096         .tokens = {
17097                 (void *)&cmd_show_tx_metadata_show,
17098                 (void *)&cmd_show_tx_metadata_port,
17099                 (void *)&cmd_show_tx_metadata_pid,
17100                 (void *)&cmd_show_tx_metadata_keyword,
17101                 NULL,
17102         },
17103 };
17104
17105 /* *** show fec capability per port configuration *** */
17106 struct cmd_show_fec_capability_result {
17107         cmdline_fixed_string_t cmd_show;
17108         cmdline_fixed_string_t cmd_port;
17109         cmdline_fixed_string_t cmd_fec;
17110         cmdline_fixed_string_t cmd_keyword;
17111         portid_t cmd_pid;
17112 };
17113
17114 static void
17115 cmd_show_fec_capability_parsed(void *parsed_result,
17116                 __rte_unused struct cmdline *cl,
17117                 __rte_unused void *data)
17118 {
17119         struct cmd_show_fec_capability_result *res = parsed_result;
17120         struct rte_eth_fec_capa *speed_fec_capa;
17121         unsigned int num;
17122         int ret;
17123
17124         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17125                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17126                 return;
17127         }
17128
17129         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17130         if (ret == -ENOTSUP) {
17131                 fprintf(stderr, "Function not implemented\n");
17132                 return;
17133         } else if (ret < 0) {
17134                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17135                 return;
17136         }
17137
17138         num = (unsigned int)ret;
17139         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17140         if (speed_fec_capa == NULL) {
17141                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17142                 return;
17143         }
17144
17145         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17146         if (ret < 0) {
17147                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17148                 goto out;
17149         }
17150
17151         show_fec_capability(num, speed_fec_capa);
17152 out:
17153         free(speed_fec_capa);
17154 }
17155
17156 static cmdline_parse_token_string_t cmd_show_fec_capability_show =
17157         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17158                         cmd_show, "show");
17159 static cmdline_parse_token_string_t cmd_show_fec_capability_port =
17160         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17161                         cmd_port, "port");
17162 static cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17163         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17164                         cmd_pid, RTE_UINT16);
17165 static cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17166         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17167                         cmd_fec, "fec");
17168 static cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17169         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17170                         cmd_keyword, "capabilities");
17171
17172 static cmdline_parse_inst_t cmd_show_capability = {
17173         .f = cmd_show_fec_capability_parsed,
17174         .data = NULL,
17175         .help_str = "show port <port_id> fec capabilities",
17176         .tokens = {
17177                 (void *)&cmd_show_fec_capability_show,
17178                 (void *)&cmd_show_fec_capability_port,
17179                 (void *)&cmd_show_fec_capability_pid,
17180                 (void *)&cmd_show_fec_capability_fec,
17181                 (void *)&cmd_show_fec_capability_keyword,
17182                 NULL,
17183         },
17184 };
17185
17186 /* *** show fec mode per port configuration *** */
17187 struct cmd_show_fec_metadata_result {
17188         cmdline_fixed_string_t cmd_show;
17189         cmdline_fixed_string_t cmd_port;
17190         cmdline_fixed_string_t cmd_keyword;
17191         portid_t cmd_pid;
17192 };
17193
17194 static void
17195 cmd_show_fec_mode_parsed(void *parsed_result,
17196                 __rte_unused struct cmdline *cl,
17197                 __rte_unused void *data)
17198 {
17199 #define FEC_NAME_SIZE 16
17200         struct cmd_show_fec_metadata_result *res = parsed_result;
17201         uint32_t mode;
17202         char buf[FEC_NAME_SIZE];
17203         int ret;
17204
17205         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17206                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17207                 return;
17208         }
17209         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17210         if (ret == -ENOTSUP) {
17211                 fprintf(stderr, "Function not implemented\n");
17212                 return;
17213         } else if (ret < 0) {
17214                 fprintf(stderr, "Get FEC mode failed\n");
17215                 return;
17216         }
17217
17218         switch (mode) {
17219         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17220                 strlcpy(buf, "off", sizeof(buf));
17221                 break;
17222         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17223                 strlcpy(buf, "auto", sizeof(buf));
17224                 break;
17225         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17226                 strlcpy(buf, "baser", sizeof(buf));
17227                 break;
17228         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17229                 strlcpy(buf, "rs", sizeof(buf));
17230                 break;
17231         default:
17232                 return;
17233         }
17234
17235         printf("%s\n", buf);
17236 }
17237
17238 static cmdline_parse_token_string_t cmd_show_fec_mode_show =
17239         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17240                         cmd_show, "show");
17241 static cmdline_parse_token_string_t cmd_show_fec_mode_port =
17242         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17243                         cmd_port, "port");
17244 static cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17245         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17246                         cmd_pid, RTE_UINT16);
17247 static cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17248         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17249                         cmd_keyword, "fec_mode");
17250
17251 static cmdline_parse_inst_t cmd_show_fec_mode = {
17252         .f = cmd_show_fec_mode_parsed,
17253         .data = NULL,
17254         .help_str = "show port <port_id> fec_mode",
17255         .tokens = {
17256                 (void *)&cmd_show_fec_mode_show,
17257                 (void *)&cmd_show_fec_mode_port,
17258                 (void *)&cmd_show_fec_mode_pid,
17259                 (void *)&cmd_show_fec_mode_keyword,
17260                 NULL,
17261         },
17262 };
17263
17264 /* *** set fec mode per port configuration *** */
17265 struct cmd_set_port_fec_mode {
17266         cmdline_fixed_string_t set;
17267         cmdline_fixed_string_t port;
17268         portid_t port_id;
17269         cmdline_fixed_string_t fec_mode;
17270         cmdline_fixed_string_t fec_value;
17271 };
17272
17273 /* Common CLI fields for set fec mode */
17274 static cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17275         TOKEN_STRING_INITIALIZER
17276                 (struct cmd_set_port_fec_mode,
17277                  set, "set");
17278 static cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17279         TOKEN_STRING_INITIALIZER
17280                 (struct cmd_set_port_fec_mode,
17281                  port, "port");
17282 static cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17283         TOKEN_NUM_INITIALIZER
17284                 (struct cmd_set_port_fec_mode,
17285                  port_id, RTE_UINT16);
17286 static cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17287         TOKEN_STRING_INITIALIZER
17288                 (struct cmd_set_port_fec_mode,
17289                  fec_mode, "fec_mode");
17290 static cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17291         TOKEN_STRING_INITIALIZER
17292                 (struct cmd_set_port_fec_mode,
17293                  fec_value, NULL);
17294
17295 static void
17296 cmd_set_port_fec_mode_parsed(
17297         void *parsed_result,
17298         __rte_unused struct cmdline *cl,
17299         __rte_unused void *data)
17300 {
17301         struct cmd_set_port_fec_mode *res = parsed_result;
17302         uint16_t port_id = res->port_id;
17303         uint32_t fec_capa;
17304         int ret;
17305
17306         ret = parse_fec_mode(res->fec_value, &fec_capa);
17307         if (ret < 0) {
17308                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17309                                 res->fec_value, port_id);
17310                 return;
17311         }
17312
17313         ret = rte_eth_fec_set(port_id, fec_capa);
17314         if (ret == -ENOTSUP) {
17315                 fprintf(stderr, "Function not implemented\n");
17316                 return;
17317         } else if (ret < 0) {
17318                 fprintf(stderr, "Set FEC mode failed\n");
17319                 return;
17320         }
17321 }
17322
17323 static cmdline_parse_inst_t cmd_set_fec_mode = {
17324         .f = cmd_set_port_fec_mode_parsed,
17325         .data = NULL,
17326         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17327         .tokens = {
17328                 (void *)&cmd_set_port_fec_mode_set,
17329                 (void *)&cmd_set_port_fec_mode_port,
17330                 (void *)&cmd_set_port_fec_mode_port_id,
17331                 (void *)&cmd_set_port_fec_mode_str,
17332                 (void *)&cmd_set_port_fec_mode_value,
17333                 NULL,
17334         },
17335 };
17336
17337 /* *** set available descriptors threshold for an RxQ of a port *** */
17338 struct cmd_set_rxq_avail_thresh_result {
17339         cmdline_fixed_string_t set;
17340         cmdline_fixed_string_t port;
17341         uint16_t port_num;
17342         cmdline_fixed_string_t rxq;
17343         uint16_t rxq_num;
17344         cmdline_fixed_string_t avail_thresh;
17345         uint8_t avail_thresh_num;
17346 };
17347
17348 static void cmd_set_rxq_avail_thresh_parsed(void *parsed_result,
17349                 __rte_unused struct cmdline *cl,
17350                 __rte_unused void *data)
17351 {
17352         struct cmd_set_rxq_avail_thresh_result *res = parsed_result;
17353         int ret = 0;
17354
17355         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
17356             && (strcmp(res->rxq, "rxq") == 0)
17357             && (strcmp(res->avail_thresh, "avail_thresh") == 0))
17358                 ret = set_rxq_avail_thresh(res->port_num, res->rxq_num,
17359                                   res->avail_thresh_num);
17360         if (ret < 0)
17361                 printf("rxq_avail_thresh_cmd error: (%s)\n", strerror(-ret));
17362
17363 }
17364
17365 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_set =
17366         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17367                                 set, "set");
17368 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_port =
17369         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17370                                 port, "port");
17371 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_portnum =
17372         TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17373                                 port_num, RTE_UINT16);
17374 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_rxq =
17375         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17376                                 rxq, "rxq");
17377 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_rxqnum =
17378         TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17379                                 rxq_num, RTE_UINT16);
17380 static cmdline_parse_token_string_t cmd_set_rxq_avail_thresh_avail_thresh =
17381         TOKEN_STRING_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17382                                 avail_thresh, "avail_thresh");
17383 static cmdline_parse_token_num_t cmd_set_rxq_avail_thresh_avail_threshnum =
17384         TOKEN_NUM_INITIALIZER(struct cmd_set_rxq_avail_thresh_result,
17385                                 avail_thresh_num, RTE_UINT8);
17386
17387 static cmdline_parse_inst_t cmd_set_rxq_avail_thresh = {
17388         .f = cmd_set_rxq_avail_thresh_parsed,
17389         .data = (void *)0,
17390         .help_str =
17391                 "set port <port_id> rxq <queue_id> avail_thresh <0..99>: "
17392                 "Set available descriptors threshold for Rx queue",
17393         .tokens = {
17394                 (void *)&cmd_set_rxq_avail_thresh_set,
17395                 (void *)&cmd_set_rxq_avail_thresh_port,
17396                 (void *)&cmd_set_rxq_avail_thresh_portnum,
17397                 (void *)&cmd_set_rxq_avail_thresh_rxq,
17398                 (void *)&cmd_set_rxq_avail_thresh_rxqnum,
17399                 (void *)&cmd_set_rxq_avail_thresh_avail_thresh,
17400                 (void *)&cmd_set_rxq_avail_thresh_avail_threshnum,
17401                 NULL,
17402         },
17403 };
17404
17405 /* show port supported ptypes */
17406
17407 /* Common result structure for show port ptypes */
17408 struct cmd_show_port_supported_ptypes_result {
17409         cmdline_fixed_string_t show;
17410         cmdline_fixed_string_t port;
17411         portid_t port_id;
17412         cmdline_fixed_string_t ptypes;
17413 };
17414
17415 /* Common CLI fields for show port ptypes */
17416 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17417         TOKEN_STRING_INITIALIZER
17418                 (struct cmd_show_port_supported_ptypes_result,
17419                  show, "show");
17420 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17421         TOKEN_STRING_INITIALIZER
17422                 (struct cmd_show_port_supported_ptypes_result,
17423                  port, "port");
17424 static cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17425         TOKEN_NUM_INITIALIZER
17426                 (struct cmd_show_port_supported_ptypes_result,
17427                  port_id, RTE_UINT16);
17428 static cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17429         TOKEN_STRING_INITIALIZER
17430                 (struct cmd_show_port_supported_ptypes_result,
17431                  ptypes, "ptypes");
17432
17433 static void
17434 cmd_show_port_supported_ptypes_parsed(
17435         void *parsed_result,
17436         __rte_unused struct cmdline *cl,
17437         __rte_unused void *data)
17438 {
17439 #define RSVD_PTYPE_MASK       0xf0000000
17440 #define MAX_PTYPES_PER_LAYER  16
17441 #define LTYPE_NAMESIZE        32
17442 #define PTYPE_NAMESIZE        256
17443         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17444         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17445         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17446         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17447         uint16_t port_id = res->port_id;
17448         int ret, i;
17449
17450         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17451         if (ret < 0)
17452                 return;
17453
17454         while (ptype_mask != RSVD_PTYPE_MASK) {
17455
17456                 switch (ptype_mask) {
17457                 case RTE_PTYPE_L2_MASK:
17458                         strlcpy(ltype, "L2", sizeof(ltype));
17459                         break;
17460                 case RTE_PTYPE_L3_MASK:
17461                         strlcpy(ltype, "L3", sizeof(ltype));
17462                         break;
17463                 case RTE_PTYPE_L4_MASK:
17464                         strlcpy(ltype, "L4", sizeof(ltype));
17465                         break;
17466                 case RTE_PTYPE_TUNNEL_MASK:
17467                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17468                         break;
17469                 case RTE_PTYPE_INNER_L2_MASK:
17470                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17471                         break;
17472                 case RTE_PTYPE_INNER_L3_MASK:
17473                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17474                         break;
17475                 case RTE_PTYPE_INNER_L4_MASK:
17476                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17477                         break;
17478                 default:
17479                         return;
17480                 }
17481
17482                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17483                                                        ptype_mask, ptypes,
17484                                                        MAX_PTYPES_PER_LAYER);
17485
17486                 if (ret > 0)
17487                         printf("Supported %s ptypes:\n", ltype);
17488                 else
17489                         printf("%s ptypes unsupported\n", ltype);
17490
17491                 for (i = 0; i < ret; ++i) {
17492                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17493                         printf("%s\n", buf);
17494                 }
17495
17496                 ptype_mask <<= 4;
17497         }
17498 }
17499
17500 static cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17501         .f = cmd_show_port_supported_ptypes_parsed,
17502         .data = NULL,
17503         .help_str = "show port <port_id> ptypes",
17504         .tokens = {
17505                 (void *)&cmd_show_port_supported_ptypes_show,
17506                 (void *)&cmd_show_port_supported_ptypes_port,
17507                 (void *)&cmd_show_port_supported_ptypes_port_id,
17508                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17509                 NULL,
17510         },
17511 };
17512
17513 /* *** display rx/tx descriptor status *** */
17514 struct cmd_show_rx_tx_desc_status_result {
17515         cmdline_fixed_string_t cmd_show;
17516         cmdline_fixed_string_t cmd_port;
17517         cmdline_fixed_string_t cmd_keyword;
17518         cmdline_fixed_string_t cmd_desc;
17519         cmdline_fixed_string_t cmd_status;
17520         portid_t cmd_pid;
17521         portid_t cmd_qid;
17522         portid_t cmd_did;
17523 };
17524
17525 static void
17526 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17527                 __rte_unused struct cmdline *cl,
17528                 __rte_unused void *data)
17529 {
17530         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17531         int rc;
17532
17533         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17534                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17535                 return;
17536         }
17537
17538         if (!strcmp(res->cmd_keyword, "rxq")) {
17539                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17540                                              res->cmd_did);
17541                 if (rc < 0) {
17542                         fprintf(stderr,
17543                                 "Invalid input: queue id = %d, desc id = %d\n",
17544                                 res->cmd_qid, res->cmd_did);
17545                         return;
17546                 }
17547                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17548                         printf("Desc status = AVAILABLE\n");
17549                 else if (rc == RTE_ETH_RX_DESC_DONE)
17550                         printf("Desc status = DONE\n");
17551                 else
17552                         printf("Desc status = UNAVAILABLE\n");
17553         } else if (!strcmp(res->cmd_keyword, "txq")) {
17554                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17555                                              res->cmd_did);
17556                 if (rc < 0) {
17557                         fprintf(stderr,
17558                                 "Invalid input: queue id = %d, desc id = %d\n",
17559                                 res->cmd_qid, res->cmd_did);
17560                         return;
17561                 }
17562                 if (rc == RTE_ETH_TX_DESC_FULL)
17563                         printf("Desc status = FULL\n");
17564                 else if (rc == RTE_ETH_TX_DESC_DONE)
17565                         printf("Desc status = DONE\n");
17566                 else
17567                         printf("Desc status = UNAVAILABLE\n");
17568         }
17569 }
17570
17571 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17572         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17573                         cmd_show, "show");
17574 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17575         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17576                         cmd_port, "port");
17577 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17578         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17579                         cmd_pid, RTE_UINT16);
17580 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17581         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17582                         cmd_keyword, "rxq#txq");
17583 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17584         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17585                         cmd_qid, RTE_UINT16);
17586 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17587         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17588                         cmd_desc, "desc");
17589 static cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17590         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17591                         cmd_did, RTE_UINT16);
17592 static cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17593         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17594                         cmd_status, "status");
17595 static cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17596         .f = cmd_show_rx_tx_desc_status_parsed,
17597         .data = NULL,
17598         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17599                 "status",
17600         .tokens = {
17601                 (void *)&cmd_show_rx_tx_desc_status_show,
17602                 (void *)&cmd_show_rx_tx_desc_status_port,
17603                 (void *)&cmd_show_rx_tx_desc_status_pid,
17604                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17605                 (void *)&cmd_show_rx_tx_desc_status_qid,
17606                 (void *)&cmd_show_rx_tx_desc_status_desc,
17607                 (void *)&cmd_show_rx_tx_desc_status_did,
17608                 (void *)&cmd_show_rx_tx_desc_status_status,
17609                 NULL,
17610         },
17611 };
17612
17613 /* *** display rx queue desc used count *** */
17614 struct cmd_show_rx_queue_desc_used_count_result {
17615         cmdline_fixed_string_t cmd_show;
17616         cmdline_fixed_string_t cmd_port;
17617         cmdline_fixed_string_t cmd_rxq;
17618         cmdline_fixed_string_t cmd_desc;
17619         cmdline_fixed_string_t cmd_used;
17620         cmdline_fixed_string_t cmd_count;
17621         portid_t cmd_pid;
17622         portid_t cmd_qid;
17623 };
17624
17625 static void
17626 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17627                 __rte_unused struct cmdline *cl,
17628                 __rte_unused void *data)
17629 {
17630         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17631         int rc;
17632
17633         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17634                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17635                 return;
17636         }
17637
17638         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17639         if (rc < 0) {
17640                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17641                 return;
17642         }
17643         printf("Used desc count = %d\n", rc);
17644 }
17645
17646 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17647         TOKEN_STRING_INITIALIZER
17648                 (struct cmd_show_rx_queue_desc_used_count_result,
17649                  cmd_show, "show");
17650 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17651         TOKEN_STRING_INITIALIZER
17652                 (struct cmd_show_rx_queue_desc_used_count_result,
17653                  cmd_port, "port");
17654 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17655         TOKEN_NUM_INITIALIZER
17656                 (struct cmd_show_rx_queue_desc_used_count_result,
17657                  cmd_pid, RTE_UINT16);
17658 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17659         TOKEN_STRING_INITIALIZER
17660                 (struct cmd_show_rx_queue_desc_used_count_result,
17661                  cmd_rxq, "rxq");
17662 static cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17663         TOKEN_NUM_INITIALIZER
17664                 (struct cmd_show_rx_queue_desc_used_count_result,
17665                  cmd_qid, RTE_UINT16);
17666 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17667         TOKEN_STRING_INITIALIZER
17668                 (struct cmd_show_rx_queue_desc_used_count_result,
17669                  cmd_count, "desc");
17670 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17671         TOKEN_STRING_INITIALIZER
17672                 (struct cmd_show_rx_queue_desc_used_count_result,
17673                  cmd_count, "used");
17674 static cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17675         TOKEN_STRING_INITIALIZER
17676                 (struct cmd_show_rx_queue_desc_used_count_result,
17677                  cmd_count, "count");
17678 static cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17679         .f = cmd_show_rx_queue_desc_used_count_parsed,
17680         .data = NULL,
17681         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17682         .tokens = {
17683                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17684                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17685                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17686                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17687                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17688                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17689                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17690                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17691                 NULL,
17692         },
17693 };
17694
17695 /* Common result structure for set port ptypes */
17696 struct cmd_set_port_ptypes_result {
17697         cmdline_fixed_string_t set;
17698         cmdline_fixed_string_t port;
17699         portid_t port_id;
17700         cmdline_fixed_string_t ptype_mask;
17701         uint32_t mask;
17702 };
17703
17704 /* Common CLI fields for set port ptypes */
17705 static cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17706         TOKEN_STRING_INITIALIZER
17707                 (struct cmd_set_port_ptypes_result,
17708                  set, "set");
17709 static cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17710         TOKEN_STRING_INITIALIZER
17711                 (struct cmd_set_port_ptypes_result,
17712                  port, "port");
17713 static cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17714         TOKEN_NUM_INITIALIZER
17715                 (struct cmd_set_port_ptypes_result,
17716                  port_id, RTE_UINT16);
17717 static cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17718         TOKEN_STRING_INITIALIZER
17719                 (struct cmd_set_port_ptypes_result,
17720                  ptype_mask, "ptype_mask");
17721 static cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17722         TOKEN_NUM_INITIALIZER
17723                 (struct cmd_set_port_ptypes_result,
17724                  mask, RTE_UINT32);
17725
17726 static void
17727 cmd_set_port_ptypes_parsed(
17728         void *parsed_result,
17729         __rte_unused struct cmdline *cl,
17730         __rte_unused void *data)
17731 {
17732         struct cmd_set_port_ptypes_result *res = parsed_result;
17733 #define PTYPE_NAMESIZE        256
17734         char ptype_name[PTYPE_NAMESIZE];
17735         uint16_t port_id = res->port_id;
17736         uint32_t ptype_mask = res->mask;
17737         int ret, i;
17738
17739         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17740                                                NULL, 0);
17741         if (ret <= 0) {
17742                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17743                         port_id);
17744                 return;
17745         }
17746
17747         uint32_t ptypes[ret];
17748
17749         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17750         if (ret < 0) {
17751                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17752                         port_id);
17753                 return;
17754         }
17755
17756         printf("Successfully set following ptypes for Port %d\n", port_id);
17757         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17758                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17759                 printf("%s\n", ptype_name);
17760         }
17761
17762         clear_ptypes = false;
17763 }
17764
17765 static cmdline_parse_inst_t cmd_set_port_ptypes = {
17766         .f = cmd_set_port_ptypes_parsed,
17767         .data = NULL,
17768         .help_str = "set port <port_id> ptype_mask <mask>",
17769         .tokens = {
17770                 (void *)&cmd_set_port_ptypes_set,
17771                 (void *)&cmd_set_port_ptypes_port,
17772                 (void *)&cmd_set_port_ptypes_port_id,
17773                 (void *)&cmd_set_port_ptypes_mask_str,
17774                 (void *)&cmd_set_port_ptypes_mask_u32,
17775                 NULL,
17776         },
17777 };
17778
17779 /* *** display mac addresses added to a port *** */
17780 struct cmd_showport_macs_result {
17781         cmdline_fixed_string_t cmd_show;
17782         cmdline_fixed_string_t cmd_port;
17783         cmdline_fixed_string_t cmd_keyword;
17784         portid_t cmd_pid;
17785 };
17786
17787 static void
17788 cmd_showport_macs_parsed(void *parsed_result,
17789                 __rte_unused struct cmdline *cl,
17790                 __rte_unused void *data)
17791 {
17792         struct cmd_showport_macs_result *res = parsed_result;
17793
17794         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17795                 return;
17796
17797         if (!strcmp(res->cmd_keyword, "macs"))
17798                 show_macs(res->cmd_pid);
17799         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17800                 show_mcast_macs(res->cmd_pid);
17801 }
17802
17803 static cmdline_parse_token_string_t cmd_showport_macs_show =
17804         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17805                         cmd_show, "show");
17806 static cmdline_parse_token_string_t cmd_showport_macs_port =
17807         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17808                         cmd_port, "port");
17809 static cmdline_parse_token_num_t cmd_showport_macs_pid =
17810         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17811                         cmd_pid, RTE_UINT16);
17812 static cmdline_parse_token_string_t cmd_showport_macs_keyword =
17813         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17814                         cmd_keyword, "macs#mcast_macs");
17815
17816 static cmdline_parse_inst_t cmd_showport_macs = {
17817         .f = cmd_showport_macs_parsed,
17818         .data = NULL,
17819         .help_str = "show port <port_id> macs|mcast_macs",
17820         .tokens = {
17821                 (void *)&cmd_showport_macs_show,
17822                 (void *)&cmd_showport_macs_port,
17823                 (void *)&cmd_showport_macs_pid,
17824                 (void *)&cmd_showport_macs_keyword,
17825                 NULL,
17826         },
17827 };
17828
17829 /* *** show flow transfer proxy port ID for the given port *** */
17830 struct cmd_show_port_flow_transfer_proxy_result {
17831         cmdline_fixed_string_t show;
17832         cmdline_fixed_string_t port;
17833         portid_t port_id;
17834         cmdline_fixed_string_t flow;
17835         cmdline_fixed_string_t transfer;
17836         cmdline_fixed_string_t proxy;
17837 };
17838
17839 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17840         TOKEN_STRING_INITIALIZER
17841                 (struct cmd_show_port_flow_transfer_proxy_result,
17842                  show, "show");
17843 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17844         TOKEN_STRING_INITIALIZER
17845                 (struct cmd_show_port_flow_transfer_proxy_result,
17846                  port, "port");
17847 static cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17848         TOKEN_NUM_INITIALIZER
17849                 (struct cmd_show_port_flow_transfer_proxy_result,
17850                  port_id, RTE_UINT16);
17851 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17852         TOKEN_STRING_INITIALIZER
17853                 (struct cmd_show_port_flow_transfer_proxy_result,
17854                  flow, "flow");
17855 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17856         TOKEN_STRING_INITIALIZER
17857                 (struct cmd_show_port_flow_transfer_proxy_result,
17858                  transfer, "transfer");
17859 static cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17860         TOKEN_STRING_INITIALIZER
17861                 (struct cmd_show_port_flow_transfer_proxy_result,
17862                  proxy, "proxy");
17863
17864 static void
17865 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17866                                          __rte_unused struct cmdline *cl,
17867                                          __rte_unused void *data)
17868 {
17869         struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17870         portid_t proxy_port_id;
17871         int ret;
17872
17873         printf("\n");
17874
17875         ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17876         if (ret != 0) {
17877                 fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17878                         rte_strerror(-ret));
17879                 return;
17880         }
17881
17882         printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17883 }
17884
17885 static cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17886         .f = cmd_show_port_flow_transfer_proxy_parsed,
17887         .data = NULL,
17888         .help_str = "show port <port_id> flow transfer proxy",
17889         .tokens = {
17890                 (void *)&cmd_show_port_flow_transfer_proxy_show,
17891                 (void *)&cmd_show_port_flow_transfer_proxy_port,
17892                 (void *)&cmd_show_port_flow_transfer_proxy_port_id,
17893                 (void *)&cmd_show_port_flow_transfer_proxy_flow,
17894                 (void *)&cmd_show_port_flow_transfer_proxy_transfer,
17895                 (void *)&cmd_show_port_flow_transfer_proxy_proxy,
17896                 NULL,
17897         }
17898 };
17899
17900 /* ******************************************************************************** */
17901
17902 /* list of instructions */
17903 static cmdline_parse_ctx_t builtin_ctx[] = {
17904         (cmdline_parse_inst_t *)&cmd_help_brief,
17905         (cmdline_parse_inst_t *)&cmd_help_long,
17906         (cmdline_parse_inst_t *)&cmd_quit,
17907         (cmdline_parse_inst_t *)&cmd_load_from_file,
17908         (cmdline_parse_inst_t *)&cmd_showport,
17909         (cmdline_parse_inst_t *)&cmd_showqueue,
17910         (cmdline_parse_inst_t *)&cmd_showeeprom,
17911         (cmdline_parse_inst_t *)&cmd_showportall,
17912         (cmdline_parse_inst_t *)&cmd_representor_info,
17913         (cmdline_parse_inst_t *)&cmd_showdevice,
17914         (cmdline_parse_inst_t *)&cmd_showcfg,
17915         (cmdline_parse_inst_t *)&cmd_showfwdall,
17916         (cmdline_parse_inst_t *)&cmd_start,
17917         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17918         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17919         (cmdline_parse_inst_t *)&cmd_set_link_up,
17920         (cmdline_parse_inst_t *)&cmd_set_link_down,
17921         (cmdline_parse_inst_t *)&cmd_reset,
17922         (cmdline_parse_inst_t *)&cmd_set_numbers,
17923         (cmdline_parse_inst_t *)&cmd_set_log,
17924         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17925         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17926         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17927         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17928         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17929         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17930         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17931         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17932         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17933         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17934         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17935         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17936         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17937         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17938         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17939         (cmdline_parse_inst_t *)&cmd_set_link_check,
17940         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17941         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17942         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17943         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17944 #ifdef RTE_NET_BOND
17945         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17946         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17947         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17948         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17949         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17950         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17951         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17952         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17953         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17954         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17955         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17956         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17957 #endif
17958         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17959         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17960         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17961         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17962         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17963         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17964         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17965         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17966         (cmdline_parse_inst_t *)&cmd_csum_set,
17967         (cmdline_parse_inst_t *)&cmd_csum_show,
17968         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17969         (cmdline_parse_inst_t *)&cmd_tso_set,
17970         (cmdline_parse_inst_t *)&cmd_tso_show,
17971         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17972         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17973 #ifdef RTE_LIB_GRO
17974         (cmdline_parse_inst_t *)&cmd_gro_enable,
17975         (cmdline_parse_inst_t *)&cmd_gro_flush,
17976         (cmdline_parse_inst_t *)&cmd_gro_show,
17977 #endif
17978 #ifdef RTE_LIB_GSO
17979         (cmdline_parse_inst_t *)&cmd_gso_enable,
17980         (cmdline_parse_inst_t *)&cmd_gso_size,
17981         (cmdline_parse_inst_t *)&cmd_gso_show,
17982 #endif
17983         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17984         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17985         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17986         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17987         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17988         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17989         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17990         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17991         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17992         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17993         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17994         (cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17995         (cmdline_parse_inst_t *)&cmd_config_dcb,
17996         (cmdline_parse_inst_t *)&cmd_read_reg,
17997         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17998         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17999         (cmdline_parse_inst_t *)&cmd_write_reg,
18000         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18001         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18002         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18003         (cmdline_parse_inst_t *)&cmd_stop,
18004         (cmdline_parse_inst_t *)&cmd_mac_addr,
18005         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18006         (cmdline_parse_inst_t *)&cmd_set_qmap,
18007         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18008         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
18009         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
18010         (cmdline_parse_inst_t *)&cmd_operate_port,
18011         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18012         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18013         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18014         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18015         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18016         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18017         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18018         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18019         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18020         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18021         (cmdline_parse_inst_t *)&cmd_config_mtu,
18022         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18023         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
18024         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18025         (cmdline_parse_inst_t *)&cmd_config_rss,
18026         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18027         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18028         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18029         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18030         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18031         (cmdline_parse_inst_t *)&cmd_showport_reta,
18032         (cmdline_parse_inst_t *)&cmd_showport_macs,
18033         (cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
18034         (cmdline_parse_inst_t *)&cmd_config_burst,
18035         (cmdline_parse_inst_t *)&cmd_config_thresh,
18036         (cmdline_parse_inst_t *)&cmd_config_threshold,
18037         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18038         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18039         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18040         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18041         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18042         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18043         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18044         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18045         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
18046         (cmdline_parse_inst_t *)&cmd_dump,
18047         (cmdline_parse_inst_t *)&cmd_dump_one,
18048 #ifdef RTE_NET_I40E
18049         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18050 #endif
18051         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18052         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18053         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18054         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18055         (cmdline_parse_inst_t *)&cmd_flow,
18056         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18057         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18058         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18059         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm_rfc4115,
18060         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18061         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18062         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18063         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18064         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18065         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
18066         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18067         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18068         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18069         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18070         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18071         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18072         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18073         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18074         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18075         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18076         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18077         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18078         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18079         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18080         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18081         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18082         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18083         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18084         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18085         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18086         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18087         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18088         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18089         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18090         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18091         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18092         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18093         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18094         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18095         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18096         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18097         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18098         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18099         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18100         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18101         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18102         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18103         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18104         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18105         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18106         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18107         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18108         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18109         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18110         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18111         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18112         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18113         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18114         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18115         (cmdline_parse_inst_t *)&cmd_ddp_add,
18116         (cmdline_parse_inst_t *)&cmd_ddp_del,
18117         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18118         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18119         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18120         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18121         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18122         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18123         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18124         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18125         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18126         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18127         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18128         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18129
18130         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18131         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18132         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18133         (cmdline_parse_inst_t *)&cmd_queue_region,
18134         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18135         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18136         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18137         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18138         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18139         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18140         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18141         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18142         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18143         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18144         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18145         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18146         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18147         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18148         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18149         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18150         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18151         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18152         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18153         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18154         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18155         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18156         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18157         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18158         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18159         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18160         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18161         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18162         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18163         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18164         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18165         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18166         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18167         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18168         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18169         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18170 #ifdef RTE_LIB_BPF
18171         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18172         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18173 #endif
18174         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18175         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18176         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18177         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18178         (cmdline_parse_inst_t *)&cmd_set_raw,
18179         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18180         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18181         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18182         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18183         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18184         (cmdline_parse_inst_t *)&cmd_set_rxq_avail_thresh,
18185         (cmdline_parse_inst_t *)&cmd_show_capability,
18186         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18187         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18188         NULL,
18189 };
18190
18191 void
18192 testpmd_add_driver_commands(struct testpmd_driver_commands *c)
18193 {
18194         TAILQ_INSERT_TAIL(&driver_commands_head, c, next);
18195 }
18196
18197 int
18198 init_cmdline(void)
18199 {
18200         struct testpmd_driver_commands *c;
18201         unsigned int count;
18202         unsigned int i;
18203
18204         /* initialize non-constant commands */
18205         cmd_set_fwd_mode_init();
18206         cmd_set_fwd_retry_mode_init();
18207
18208         count = 0;
18209         for (i = 0; builtin_ctx[i] != NULL; i++)
18210                 count++;
18211         TAILQ_FOREACH(c, &driver_commands_head, next) {
18212                 for (i = 0; c->commands[i].ctx != NULL; i++)
18213                         count++;
18214         }
18215
18216         /* cmdline expects a NULL terminated array */
18217         main_ctx = calloc(count + 1, sizeof(main_ctx[0]));
18218         if (main_ctx == NULL)
18219                 return -1;
18220
18221         count = 0;
18222         for (i = 0; builtin_ctx[i] != NULL; i++, count++)
18223                 main_ctx[count] = builtin_ctx[i];
18224         TAILQ_FOREACH(c, &driver_commands_head, next) {
18225                 for (i = 0; c->commands[i].ctx != NULL; i++, count++)
18226                         main_ctx[count] = c->commands[i].ctx;
18227         }
18228
18229         return 0;
18230 }
18231
18232 /* read cmdline commands from file */
18233 void
18234 cmdline_read_from_file(const char *filename)
18235 {
18236         struct cmdline *cl;
18237
18238         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18239         if (cl == NULL) {
18240                 fprintf(stderr,
18241                         "Failed to create file based cmdline context: %s\n",
18242                         filename);
18243                 return;
18244         }
18245
18246         cmdline_interact(cl);
18247         cmdline_quit(cl);
18248
18249         cmdline_free(cl);
18250
18251         printf("Read CLI commands from %s\n", filename);
18252 }
18253
18254 /* prompt function, called from main on MAIN lcore */
18255 void
18256 prompt(void)
18257 {
18258         int ret;
18259
18260         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18261         if (testpmd_cl == NULL)
18262                 return;
18263
18264         ret = atexit(prompt_exit);
18265         if (ret != 0)
18266                 fprintf(stderr, "Cannot set exit function for cmdline\n");
18267
18268         cmdline_interact(testpmd_cl);
18269         if (ret != 0)
18270                 cmdline_stdin_exit(testpmd_cl);
18271 }
18272
18273 void
18274 prompt_exit(void)
18275 {
18276         if (testpmd_cl != NULL) {
18277                 cmdline_quit(testpmd_cl);
18278                 cmdline_stdin_exit(testpmd_cl);
18279         }
18280 }
18281
18282 static void
18283 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18284 {
18285         if (id == (portid_t)RTE_PORT_ALL) {
18286                 portid_t pid;
18287
18288                 RTE_ETH_FOREACH_DEV(pid) {
18289                         /* check if need_reconfig has been set to 1 */
18290                         if (ports[pid].need_reconfig == 0)
18291                                 ports[pid].need_reconfig = dev;
18292                         /* check if need_reconfig_queues has been set to 1 */
18293                         if (ports[pid].need_reconfig_queues == 0)
18294                                 ports[pid].need_reconfig_queues = queue;
18295                 }
18296         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18297                 /* check if need_reconfig has been set to 1 */
18298                 if (ports[id].need_reconfig == 0)
18299                         ports[id].need_reconfig = dev;
18300                 /* check if need_reconfig_queues has been set to 1 */
18301                 if (ports[id].need_reconfig_queues == 0)
18302                         ports[id].need_reconfig_queues = queue;
18303         }
18304 }