app/testpmd: do not poll stopped queues
[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
73 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
74
75 /* *** Help command with introduction. *** */
76 struct cmd_help_brief_result {
77         cmdline_fixed_string_t help;
78 };
79
80 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
81                                   struct cmdline *cl,
82                                   __rte_unused void *data)
83 {
84         cmdline_printf(
85                 cl,
86                 "\n"
87                 "Help is available for the following sections:\n\n"
88                 "    help control                    : Start and stop forwarding.\n"
89                 "    help display                    : Displaying port, stats and config "
90                 "information.\n"
91                 "    help config                     : Configuration information.\n"
92                 "    help ports                      : Configuring ports.\n"
93                 "    help registers                  : Reading and setting port registers.\n"
94                 "    help filters                    : Filters configuration help.\n"
95                 "    help traffic_management         : Traffic Management commands.\n"
96                 "    help devices                    : Device related cmds.\n"
97                 "    help all                        : All of the above sections.\n\n"
98         );
99
100 }
101
102 cmdline_parse_token_string_t cmd_help_brief_help =
103         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
104
105 cmdline_parse_inst_t cmd_help_brief = {
106         .f = cmd_help_brief_parsed,
107         .data = NULL,
108         .help_str = "help: Show help",
109         .tokens = {
110                 (void *)&cmd_help_brief_help,
111                 NULL,
112         },
113 };
114
115 /* *** Help command with help sections. *** */
116 struct cmd_help_long_result {
117         cmdline_fixed_string_t help;
118         cmdline_fixed_string_t section;
119 };
120
121 static void cmd_help_long_parsed(void *parsed_result,
122                                  struct cmdline *cl,
123                                  __rte_unused void *data)
124 {
125         int show_all = 0;
126         struct cmd_help_long_result *res = parsed_result;
127
128         if (!strcmp(res->section, "all"))
129                 show_all = 1;
130
131         if (show_all || !strcmp(res->section, "control")) {
132
133                 cmdline_printf(
134                         cl,
135                         "\n"
136                         "Control forwarding:\n"
137                         "-------------------\n\n"
138
139                         "start\n"
140                         "    Start packet forwarding with current configuration.\n\n"
141
142                         "start tx_first\n"
143                         "    Start packet forwarding with current config"
144                         " after sending one burst of packets.\n\n"
145
146                         "stop\n"
147                         "    Stop packet forwarding, and display accumulated"
148                         " statistics.\n\n"
149
150                         "quit\n"
151                         "    Quit to prompt.\n\n"
152                 );
153         }
154
155         if (show_all || !strcmp(res->section, "display")) {
156
157                 cmdline_printf(
158                         cl,
159                         "\n"
160                         "Display:\n"
161                         "--------\n\n"
162
163                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
164                         "    Display information for port_id, or all.\n\n"
165
166                         "show port info (port_id) representor\n"
167                         "    Show supported representors for a specific port\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) rxq (queue_id) desc used count\n"
250                         "    Show current number of filled receive"
251                         " packet descriptors.\n\n"
252
253                         "show port (port_id) macs|mcast_macs"
254                         "       Display list of mac addresses added to port.\n\n"
255
256                         "show port (port_id) flow transfer proxy\n"
257                         "       Display proxy port to manage transfer flows\n\n"
258
259                         "show port (port_id) fec capabilities"
260                         "       Show fec capabilities of a port.\n\n"
261
262                         "show port (port_id) fec_mode"
263                         "       Show fec mode of a port.\n\n"
264
265                         "show port (port_id) flow_ctrl"
266                         "       Show flow control info of a port.\n\n"
267                 );
268         }
269
270         if (show_all || !strcmp(res->section, "config")) {
271                 cmdline_printf(
272                         cl,
273                         "\n"
274                         "Configuration:\n"
275                         "--------------\n"
276                         "Configuration changes only become active when"
277                         " forwarding is started/restarted.\n\n"
278
279                         "set default\n"
280                         "    Reset forwarding to the default configuration.\n\n"
281
282                         "set verbose (level)\n"
283                         "    Set the debug verbosity level X.\n\n"
284
285                         "set log global|(type) (level)\n"
286                         "    Set the log level.\n\n"
287
288                         "set nbport (num)\n"
289                         "    Set number of ports.\n\n"
290
291                         "set nbcore (num)\n"
292                         "    Set number of cores.\n\n"
293
294                         "set coremask (mask)\n"
295                         "    Set the forwarding cores hexadecimal mask.\n\n"
296
297                         "set portmask (mask)\n"
298                         "    Set the forwarding ports hexadecimal mask.\n\n"
299
300                         "set burst (num)\n"
301                         "    Set number of packets per burst.\n\n"
302
303                         "set burst tx delay (microseconds) retry (num)\n"
304                         "    Set the transmit delay time and number of retries,"
305                         " effective when retry is enabled.\n\n"
306
307                         "set rxoffs (x[,y]*)\n"
308                         "    Set the offset of each packet segment on"
309                         " receiving if split feature is engaged."
310                         " Affects only the queues configured with split"
311                         " offloads.\n\n"
312
313                         "set rxpkts (x[,y]*)\n"
314                         "    Set the length of each segment to scatter"
315                         " packets on receiving if split feature is engaged."
316                         " Affects only the queues configured with split"
317                         " offloads.\n\n"
318
319                         "set txpkts (x[,y]*)\n"
320                         "    Set the length of each segment of TXONLY"
321                         " and optionally CSUM packets.\n\n"
322
323                         "set txsplit (off|on|rand)\n"
324                         "    Set the split policy for the TX packets."
325                         " Right now only applicable for CSUM and TXONLY"
326                         " modes\n\n"
327
328                         "set txtimes (x, y)\n"
329                         "    Set the scheduling on timestamps"
330                         " timings for the TXONLY mode\n\n"
331
332                         "set corelist (x[,y]*)\n"
333                         "    Set the list of forwarding cores.\n\n"
334
335                         "set portlist (x[,y]*)\n"
336                         "    Set the list of forwarding ports.\n\n"
337
338                         "set port setup on (iterator|event)\n"
339                         "    Select how attached port is retrieved for setup.\n\n"
340
341                         "set tx loopback (port_id) (on|off)\n"
342                         "    Enable or disable tx loopback.\n\n"
343
344                         "set all queues drop (port_id) (on|off)\n"
345                         "    Set drop enable bit for all queues.\n\n"
346
347                         "set vf split drop (port_id) (vf_id) (on|off)\n"
348                         "    Set split drop enable bit for a VF from the PF.\n\n"
349
350                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
351                         "    Set MAC antispoof for a VF from the PF.\n\n"
352
353                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
354                         "    Enable MACsec offload.\n\n"
355
356                         "set macsec offload (port_id) off\n"
357                         "    Disable MACsec offload.\n\n"
358
359                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
360                         "    Configure MACsec secure connection (SC).\n\n"
361
362                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
363                         "    Configure MACsec secure association (SA).\n\n"
364
365                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
366                         "    Set VF broadcast for a VF from the PF.\n\n"
367
368                         "vlan set stripq (on|off) (port_id,queue_id)\n"
369                         "    Set the VLAN strip for a queue on a port.\n\n"
370
371                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
372                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
373
374                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
375                         "    Set VLAN insert for a VF from the PF.\n\n"
376
377                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
378                         "    Set VLAN antispoof for a VF from the PF.\n\n"
379
380                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
381                         "    Set VLAN tag for a VF from the PF.\n\n"
382
383                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
384                         "    Set a VF's max bandwidth(Mbps).\n\n"
385
386                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
387                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
388
389                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
390                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
391
392                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
393                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
394
395                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
396                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
397
398                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
399                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
400
401                         "vlan set (inner|outer) tpid (value) (port_id)\n"
402                         "    Set the VLAN TPID for Packet Filtering on"
403                         " a port\n\n"
404
405                         "rx_vlan add (vlan_id|all) (port_id)\n"
406                         "    Add a vlan_id, or all identifiers, to the set"
407                         " of VLAN identifiers filtered by port_id.\n\n"
408
409                         "rx_vlan rm (vlan_id|all) (port_id)\n"
410                         "    Remove a vlan_id, or all identifiers, from the set"
411                         " of VLAN identifiers filtered by port_id.\n\n"
412
413                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
414                         "    Add a vlan_id, to the set of VLAN identifiers"
415                         "filtered for VF(s) from port_id.\n\n"
416
417                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
418                         "    Remove a vlan_id, to the set of VLAN identifiers"
419                         "filtered for VF(s) from port_id.\n\n"
420
421                         "rx_vxlan_port add (udp_port) (port_id)\n"
422                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
423
424                         "rx_vxlan_port rm (udp_port) (port_id)\n"
425                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
426
427                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
428                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
429                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
430
431                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
432                         "    Set port based TX VLAN insertion.\n\n"
433
434                         "tx_vlan reset (port_id)\n"
435                         "    Disable hardware insertion of a VLAN header in"
436                         " packets sent on a port.\n\n"
437
438                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
439                         "    Select hardware or software calculation of the"
440                         " checksum when transmitting a packet using the"
441                         " csum forward engine.\n"
442                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
443                         "    outer-ip concerns the outer IP layer in"
444                         "    outer-udp concerns the outer UDP layer in"
445                         " case the packet is recognized as a tunnel packet by"
446                         " the forward engine (vxlan, gre and ipip are supported)\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "csum parse-tunnel (on|off) (tx_port_id)\n"
450                         "    If disabled, treat tunnel packets as non-tunneled"
451                         " packets (treat inner headers as payload). The port\n"
452                         "    argument is the port used for TX in csum forward"
453                         " engine.\n\n"
454
455                         "csum show (port_id)\n"
456                         "    Display tx checksum offload configuration\n\n"
457
458                         "tso set (segsize) (portid)\n"
459                         "    Enable TCP Segmentation Offload in csum forward"
460                         " engine.\n"
461                         "    Please check the NIC datasheet for HW limits.\n\n"
462
463                         "tso show (portid)"
464                         "    Display the status of TCP Segmentation Offload.\n\n"
465
466 #ifdef RTE_LIB_GRO
467                         "set port (port_id) gro on|off\n"
468                         "    Enable or disable Generic Receive Offload in"
469                         " csum forwarding engine.\n\n"
470
471                         "show port (port_id) gro\n"
472                         "    Display GRO configuration.\n\n"
473
474                         "set gro flush (cycles)\n"
475                         "    Set the cycle to flush GROed packets from"
476                         " reassembly tables.\n\n"
477 #endif
478
479 #ifdef RTE_LIB_GSO
480                         "set port (port_id) gso (on|off)"
481                         "    Enable or disable Generic Segmentation Offload in"
482                         " csum forwarding engine.\n\n"
483
484                         "set gso segsz (length)\n"
485                         "    Set max packet length for output GSO segments,"
486                         " including packet header and payload.\n\n"
487
488                         "show port (port_id) gso\n"
489                         "    Show GSO configuration.\n\n"
490 #endif
491
492                         "set fwd (%s)\n"
493                         "    Set packet forwarding mode.\n\n"
494
495                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
496                         "    Add a MAC address on port_id.\n\n"
497
498                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
499                         "    Remove a MAC address from port_id.\n\n"
500
501                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
502                         "    Set the default MAC address for port_id.\n\n"
503
504                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
505                         "    Add a MAC address for a VF on the port.\n\n"
506
507                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
508                         "    Set the MAC address for a VF from the PF.\n\n"
509
510                         "set eth-peer (port_id) (peer_addr)\n"
511                         "    set the peer address for certain port.\n\n"
512
513                         "set port (port_id) uta (mac_address|all) (on|off)\n"
514                         "    Add/Remove a or all unicast hash filter(s)"
515                         "from port X.\n\n"
516
517                         "set promisc (port_id|all) (on|off)\n"
518                         "    Set the promiscuous mode on port_id, or all.\n\n"
519
520                         "set allmulti (port_id|all) (on|off)\n"
521                         "    Set the allmulti mode on port_id, or all.\n\n"
522
523                         "set vf promisc (port_id) (vf_id) (on|off)\n"
524                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
525
526                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
527                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
528
529                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
530                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
531                         " (on|off) autoneg (on|off) (port_id)\n"
532                         "set flow_ctrl rx (on|off) (portid)\n"
533                         "set flow_ctrl tx (on|off) (portid)\n"
534                         "set flow_ctrl high_water (high_water) (portid)\n"
535                         "set flow_ctrl low_water (low_water) (portid)\n"
536                         "set flow_ctrl pause_time (pause_time) (portid)\n"
537                         "set flow_ctrl send_xon (send_xon) (portid)\n"
538                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
539                         "set flow_ctrl autoneg (on|off) (port_id)\n"
540                         "    Set the link flow control parameter on a port.\n\n"
541
542                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
543                         " (low_water) (pause_time) (priority) (port_id)\n"
544                         "    Set the priority flow control parameter on a"
545                         " port.\n\n"
546
547                         "set pfc_queue_ctrl (port_id) rx (on|off) (tx_qid)"
548                         " (tx_tc) tx (on|off) (rx_qid) (rx_tc) (pause_time)\n"
549                         "    Set the queue priority flow control parameter on a"
550                         " given Rx and Tx queues of a port.\n\n"
551
552                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
553                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
554                         " queue on port.\n"
555                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
556                         " on port 0 to mapping 5.\n\n"
557
558                         "set xstats-hide-zero on|off\n"
559                         "    Set the option to hide the zero values"
560                         " for xstats display.\n"
561
562                         "set record-core-cycles on|off\n"
563                         "    Set the option to enable measurement of CPU cycles.\n"
564
565                         "set record-burst-stats on|off\n"
566                         "    Set the option to enable display of RX and TX bursts.\n"
567
568                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
569                         "    Enable/Disable a VF receive/transmit from a port\n\n"
570
571                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
572                         "|MPE) (on|off)\n"
573                         "    AUPE:accepts untagged VLAN;"
574                         "ROPE:accept unicast hash\n\n"
575                         "    BAM:accepts broadcast packets;"
576                         "MPE:accepts all multicast packets\n\n"
577                         "    Enable/Disable a VF receive mode of a port\n\n"
578
579                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
580                         "    Set rate limit for a queue of a port\n\n"
581
582                         "set port (port_id) vf (vf_id) rate (rate_num) "
583                         "queue_mask (queue_mask_value)\n"
584                         "    Set rate limit for queues in VF of a port\n\n"
585
586                         "set flush_rx (on|off)\n"
587                         "   Flush (default) or don't flush RX streams before"
588                         " forwarding. Mainly used with PCAP drivers.\n\n"
589
590                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
591                         "   Set the bypass mode for the lowest port on bypass enabled"
592                         " NIC.\n\n"
593
594                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
595                         "mode (normal|bypass|isolate) (port_id)\n"
596                         "   Set the event required to initiate specified bypass mode for"
597                         " the lowest port on a bypass enabled NIC where:\n"
598                         "       timeout   = enable bypass after watchdog timeout.\n"
599                         "       os_on     = enable bypass when OS/board is powered on.\n"
600                         "       os_off    = enable bypass when OS/board is powered off.\n"
601                         "       power_on  = enable bypass when power supply is turned on.\n"
602                         "       power_off = enable bypass when power supply is turned off."
603                         "\n\n"
604
605                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
606                         "   Set the bypass watchdog timeout to 'n' seconds"
607                         " where 0 = instant.\n\n"
608
609                         "show bypass config (port_id)\n"
610                         "   Show the bypass configuration for a bypass enabled NIC"
611                         " using the lowest port on the NIC.\n\n"
612
613 #ifdef RTE_NET_BOND
614                         "create bonded device (mode) (socket)\n"
615                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
616
617                         "add bonding slave (slave_id) (port_id)\n"
618                         "       Add a slave device to a bonded device.\n\n"
619
620                         "remove bonding slave (slave_id) (port_id)\n"
621                         "       Remove a slave device from a bonded device.\n\n"
622
623                         "set bonding mode (value) (port_id)\n"
624                         "       Set the bonding mode on a bonded device.\n\n"
625
626                         "set bonding primary (slave_id) (port_id)\n"
627                         "       Set the primary slave for a bonded device.\n\n"
628
629                         "show bonding config (port_id)\n"
630                         "       Show the bonding config for port_id.\n\n"
631
632                         "show bonding lacp info (port_id)\n"
633                         "       Show the bonding lacp information for port_id.\n\n"
634
635                         "set bonding mac_addr (port_id) (address)\n"
636                         "       Set the MAC address of a bonded device.\n\n"
637
638                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
639                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
640
641                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
642                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
643
644                         "set bonding mon_period (port_id) (value)\n"
645                         "       Set the bonding link status monitoring polling period in ms.\n\n"
646
647                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
648                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
649
650 #endif
651                         "set link-up port (port_id)\n"
652                         "       Set link up for a port.\n\n"
653
654                         "set link-down port (port_id)\n"
655                         "       Set link down for a port.\n\n"
656
657                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
658                         "    Load a profile package on a port\n\n"
659
660                         "ddp del (port_id) (backup_profile_path)\n"
661                         "    Delete a profile package from a port\n\n"
662
663                         "ptype mapping get (port_id) (valid_only)\n"
664                         "    Get ptype mapping on a port\n\n"
665
666                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
667                         "    Replace target with the pkt_type in ptype mapping\n\n"
668
669                         "ptype mapping reset (port_id)\n"
670                         "    Reset ptype mapping on a port\n\n"
671
672                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
673                         "    Update a ptype mapping item on a port\n\n"
674
675                         "set port (port_id) ptype_mask (ptype_mask)\n"
676                         "    set packet types classification for a specific port\n\n"
677
678                         "set port (port_id) queue-region region_id (value) "
679                         "queue_start_index (value) queue_num (value)\n"
680                         "    Set a queue region on a port\n\n"
681
682                         "set port (port_id) queue-region region_id (value) "
683                         "flowtype (value)\n"
684                         "    Set a flowtype region index on a port\n\n"
685
686                         "set port (port_id) queue-region UP (value) region_id (value)\n"
687                         "    Set the mapping of User Priority to "
688                         "queue region on a port\n\n"
689
690                         "set port (port_id) queue-region flush (on|off)\n"
691                         "    flush all queue region related configuration\n\n"
692
693                         "show port meter cap (port_id)\n"
694                         "    Show port meter capability information\n\n"
695
696                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
697                         "    meter profile add - srtcm rfc 2697\n\n"
698
699                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
700                         "    meter profile add - trtcm rfc 2698\n\n"
701
702                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
703                         "    meter profile add - trtcm rfc 4115\n\n"
704
705                         "del port meter profile (port_id) (profile_id)\n"
706                         "    meter profile delete\n\n"
707
708                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
709                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
710                         "(dscp_tbl_entry63)]\n"
711                         "    meter create\n\n"
712
713                         "enable port meter (port_id) (mtr_id)\n"
714                         "    meter enable\n\n"
715
716                         "disable port meter (port_id) (mtr_id)\n"
717                         "    meter disable\n\n"
718
719                         "del port meter (port_id) (mtr_id)\n"
720                         "    meter delete\n\n"
721
722                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
723                         "y_actions (actions) r_actions (actions)\n"
724                         "    meter policy add\n\n"
725
726                         "del port meter policy (port_id) (policy_id)\n"
727                         "    meter policy delete\n\n"
728
729                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
730                         "    meter update meter profile\n\n"
731
732                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
733                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
734                         "    update meter dscp table entries\n\n"
735
736                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
737                         "(action0) [(action1) (action2)]\n"
738                         "    meter update policer action\n\n"
739
740                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
741                         "    meter update stats\n\n"
742
743                         "show port (port_id) queue-region\n"
744                         "    show all queue region related configuration info\n\n"
745
746                         "set port (port_id) fec_mode auto|off|rs|baser\n"
747                         "    set fec mode for a specific port\n\n"
748
749                         , list_pkt_forwarding_modes()
750                 );
751         }
752
753         if (show_all || !strcmp(res->section, "ports")) {
754
755                 cmdline_printf(
756                         cl,
757                         "\n"
758                         "Port Operations:\n"
759                         "----------------\n\n"
760
761                         "port start (port_id|all)\n"
762                         "    Start all ports or port_id.\n\n"
763
764                         "port stop (port_id|all)\n"
765                         "    Stop all ports or port_id.\n\n"
766
767                         "port close (port_id|all)\n"
768                         "    Close all ports or port_id.\n\n"
769
770                         "port reset (port_id|all)\n"
771                         "    Reset all ports or port_id.\n\n"
772
773                         "port attach (ident)\n"
774                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
775
776                         "port detach (port_id)\n"
777                         "    Detach physical or virtual dev by port_id\n\n"
778
779                         "port config (port_id|all)"
780                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
781                         " duplex (half|full|auto)\n"
782                         "    Set speed and duplex for all ports or port_id\n\n"
783
784                         "port config (port_id|all) loopback (mode)\n"
785                         "    Set loopback mode for all ports or port_id\n\n"
786
787                         "port config all (rxq|txq|rxd|txd) (value)\n"
788                         "    Set number for rxq/txq/rxd/txd.\n\n"
789
790                         "port config all max-pkt-len (value)\n"
791                         "    Set the max packet length.\n\n"
792
793                         "port config all max-lro-pkt-size (value)\n"
794                         "    Set the max LRO aggregated packet size.\n\n"
795
796                         "port config all drop-en (on|off)\n"
797                         "    Enable or disable packet drop on all RX queues of all ports when no "
798                         "receive buffers available.\n\n"
799
800                         "port config all rss (all|default|ip|tcp|udp|sctp|"
801                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|"
802                         "none|level-default|level-outer|level-inner|<flowtype_id>)\n"
803                         "    Set the RSS mode.\n\n"
804
805                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
806                         "    Set the RSS redirection table.\n\n"
807
808                         "port config (port_id) dcb vt (on|off) (traffic_class)"
809                         " pfc (on|off)\n"
810                         "    Set the DCB mode.\n\n"
811
812                         "port config all burst (value)\n"
813                         "    Set the number of packets per burst.\n\n"
814
815                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
816                         " (value)\n"
817                         "    Set the ring prefetch/host/writeback threshold"
818                         " for tx/rx queue.\n\n"
819
820                         "port config all (txfreet|txrst|rxfreet) (value)\n"
821                         "    Set free threshold for rx/tx, or set"
822                         " tx rs bit threshold.\n\n"
823                         "port config mtu X value\n"
824                         "    Set the MTU of port X to a given value\n\n"
825
826                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
827                         "    Set a rx/tx queue's ring size configuration, the new"
828                         " value will take effect after command that (re-)start the port"
829                         " or command that setup the specific queue\n\n"
830
831                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
832                         "    Start/stop a rx/tx queue of port X. Only take effect"
833                         " when port X is started\n\n"
834
835                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
836                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
837                         " take effect when port X is stopped.\n\n"
838
839                         "port (port_id) (rxq|txq) (queue_id) setup\n"
840                         "    Setup a rx/tx queue of port X.\n\n"
841
842                         "port config (port_id) pctype mapping reset\n"
843                         "    Reset flow type to pctype mapping on a port\n\n"
844
845                         "port config (port_id) pctype mapping update"
846                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
847                         "    Update a flow type to pctype mapping item on a port\n\n"
848
849                         "port config (port_id) pctype (pctype_id) hash_inset|"
850                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
851                         " (field_idx)\n"
852                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
853
854                         "port config (port_id) pctype (pctype_id) hash_inset|"
855                         "fdir_inset|fdir_flx_inset clear all"
856                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
857
858                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
859                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
860
861                         "port config <port_id> rx_offload vlan_strip|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863                         "outer_ipv4_cksum|macsec_strip|header_split|"
864                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
865                         "buffer_split|timestamp|security|keep_crc on|off\n"
866                         "     Enable or disable a per port Rx offloading"
867                         " on all Rx queues of a port\n\n"
868
869                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
871                         "outer_ipv4_cksum|macsec_strip|header_split|"
872                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
873                         "buffer_split|timestamp|security|keep_crc on|off\n"
874                         "    Enable or disable a per queue Rx offloading"
875                         " only on a specific Rx queue\n\n"
876
877                         "port config (port_id) tx_offload vlan_insert|"
878                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
879                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
880                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
881                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
882                         "security on|off\n"
883                         "    Enable or disable a per port Tx offloading"
884                         " on all Tx queues of a port\n\n"
885
886                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
887                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
888                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
889                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
890                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
891                         " on|off\n"
892                         "    Enable or disable a per queue Tx offloading"
893                         " only on a specific Tx queue\n\n"
894
895                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
896                         "    Load an eBPF program as a callback"
897                         " for particular RX/TX queue\n\n"
898
899                         "bpf-unload rx|tx (port) (queue)\n"
900                         "    Unload previously loaded eBPF program"
901                         " for particular RX/TX queue\n\n"
902
903                         "port config (port_id) tx_metadata (value)\n"
904                         "    Set Tx metadata value per port. Testpmd will add this value"
905                         " to any Tx packet sent from this port\n\n"
906
907                         "port config (port_id) dynf (name) set|clear\n"
908                         "    Register a dynf and Set/clear this flag on Tx. "
909                         "Testpmd will set this value to any Tx packet "
910                         "sent from this port\n\n"
911
912                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
913                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
914                 );
915         }
916
917         if (show_all || !strcmp(res->section, "registers")) {
918
919                 cmdline_printf(
920                         cl,
921                         "\n"
922                         "Registers:\n"
923                         "----------\n\n"
924
925                         "read reg (port_id) (address)\n"
926                         "    Display value of a port register.\n\n"
927
928                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
929                         "    Display a port register bit field.\n\n"
930
931                         "read regbit (port_id) (address) (bit_x)\n"
932                         "    Display a single port register bit.\n\n"
933
934                         "write reg (port_id) (address) (value)\n"
935                         "    Set value of a port register.\n\n"
936
937                         "write regfield (port_id) (address) (bit_x) (bit_y)"
938                         " (value)\n"
939                         "    Set bit field of a port register.\n\n"
940
941                         "write regbit (port_id) (address) (bit_x) (value)\n"
942                         "    Set single bit value of a port register.\n\n"
943                 );
944         }
945         if (show_all || !strcmp(res->section, "filters")) {
946
947                 cmdline_printf(
948                         cl,
949                         "\n"
950                         "filters:\n"
951                         "--------\n\n"
952
953 #ifdef RTE_NET_I40E
954                         "flow_director_filter (port_id) mode raw (add|del|update)"
955                         " flow (flow_id) (drop|fwd) queue (queue_id)"
956                         " fd_id (fd_id_value) packet (packet file name)\n"
957                         "    Add/Del a raw type flow director filter.\n\n"
958 #endif
959
960                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
961                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
962                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
963                         "    Set flow director IP mask.\n\n"
964
965                         "flow_director_mask (port_id) mode MAC-VLAN"
966                         " vlan (vlan_value)\n"
967                         "    Set flow director MAC-VLAN mask.\n\n"
968
969                         "flow_director_mask (port_id) mode Tunnel"
970                         " vlan (vlan_value) mac (mac_value)"
971                         " tunnel-type (tunnel_type_value)"
972                         " tunnel-id (tunnel_id_value)\n"
973                         "    Set flow director Tunnel mask.\n\n"
974
975                         "flow_director_flex_payload (port_id)"
976                         " (raw|l2|l3|l4) (config)\n"
977                         "    Configure flex payload selection.\n\n"
978
979                         "flow validate {port_id}"
980                         " [group {group_id}] [priority {level}]"
981                         " [ingress] [egress]"
982                         " pattern {item} [/ {item} [...]] / end"
983                         " actions {action} [/ {action} [...]] / end\n"
984                         "    Check whether a flow rule can be created.\n\n"
985
986                         "flow create {port_id}"
987                         " [group {group_id}] [priority {level}]"
988                         " [ingress] [egress]"
989                         " pattern {item} [/ {item} [...]] / end"
990                         " actions {action} [/ {action} [...]] / end\n"
991                         "    Create a flow rule.\n\n"
992
993                         "flow destroy {port_id} rule {rule_id} [...]\n"
994                         "    Destroy specific flow rules.\n\n"
995
996                         "flow flush {port_id}\n"
997                         "    Destroy all flow rules.\n\n"
998
999                         "flow query {port_id} {rule_id} {action}\n"
1000                         "    Query an existing flow rule.\n\n"
1001
1002                         "flow list {port_id} [group {group_id}] [...]\n"
1003                         "    List existing flow rules sorted by priority,"
1004                         " filtered by group identifiers.\n\n"
1005
1006                         "flow isolate {port_id} {boolean}\n"
1007                         "    Restrict ingress traffic to the defined"
1008                         " flow rules\n\n"
1009
1010                         "flow aged {port_id} [destroy]\n"
1011                         "    List and destroy aged flows"
1012                         " flow rules\n\n"
1013
1014                         "flow indirect_action {port_id} create"
1015                         " [action_id {indirect_action_id}]"
1016                         " [ingress] [egress]"
1017                         " action {action} / end\n"
1018                         "    Create indirect action.\n\n"
1019
1020                         "flow indirect_action {port_id} update"
1021                         " {indirect_action_id} action {action} / end\n"
1022                         "    Update indirect action.\n\n"
1023
1024                         "flow indirect_action {port_id} destroy"
1025                         " action_id {indirect_action_id} [...]\n"
1026                         "    Destroy specific indirect actions.\n\n"
1027
1028                         "flow indirect_action {port_id} query"
1029                         " {indirect_action_id}\n"
1030                         "    Query an existing indirect action.\n\n"
1031
1032                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1033                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1034                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1035                         "       Configure the VXLAN encapsulation for flows.\n\n"
1036
1037                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1038                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1039                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1040                         " eth-dst (eth-dst)\n"
1041                         "       Configure the VXLAN encapsulation for flows.\n\n"
1042
1043                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1044                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1045                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1046                         " eth-dst (eth-dst)\n"
1047                         "       Configure the VXLAN encapsulation for flows.\n\n"
1048
1049                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1050                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1051                         " (eth-dst)\n"
1052                         "       Configure the NVGRE encapsulation for flows.\n\n"
1053
1054                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1055                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1056                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1057                         "       Configure the NVGRE encapsulation for flows.\n\n"
1058
1059                         "set raw_encap {flow items}\n"
1060                         "       Configure the encapsulation with raw data.\n\n"
1061
1062                         "set raw_decap {flow items}\n"
1063                         "       Configure the decapsulation with raw data.\n\n"
1064
1065                 );
1066         }
1067
1068         if (show_all || !strcmp(res->section, "traffic_management")) {
1069                 cmdline_printf(
1070                         cl,
1071                         "\n"
1072                         "Traffic Management:\n"
1073                         "--------------\n"
1074                         "show port tm cap (port_id)\n"
1075                         "       Display the port TM capability.\n\n"
1076
1077                         "show port tm level cap (port_id) (level_id)\n"
1078                         "       Display the port TM hierarchical level capability.\n\n"
1079
1080                         "show port tm node cap (port_id) (node_id)\n"
1081                         "       Display the port TM node capability.\n\n"
1082
1083                         "show port tm node type (port_id) (node_id)\n"
1084                         "       Display the port TM node type.\n\n"
1085
1086                         "show port tm node stats (port_id) (node_id) (clear)\n"
1087                         "       Display the port TM node stats.\n\n"
1088
1089                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1090                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1091                         " (packet_length_adjust) (packet_mode)\n"
1092                         "       Add port tm node private shaper profile.\n\n"
1093
1094                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1095                         "       Delete port tm node private shaper profile.\n\n"
1096
1097                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1098                         " (shaper_profile_id)\n"
1099                         "       Add/update port tm node shared shaper.\n\n"
1100
1101                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1102                         "       Delete port tm node shared shaper.\n\n"
1103
1104                         "set port tm node shaper profile (port_id) (node_id)"
1105                         " (shaper_profile_id)\n"
1106                         "       Set port tm node shaper profile.\n\n"
1107
1108                         "add port tm node wred profile (port_id) (wred_profile_id)"
1109                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1110                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1111                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1112                         "       Add port tm node wred profile.\n\n"
1113
1114                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1115                         "       Delete port tm node wred profile.\n\n"
1116
1117                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1118                         " (priority) (weight) (level_id) (shaper_profile_id)"
1119                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1120                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1121                         "       Add port tm nonleaf node.\n\n"
1122
1123                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1124                         " (priority) (weight) (level_id) (shaper_profile_id)"
1125                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1126                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1127                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1128
1129                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1130                         " (priority) (weight) (level_id) (shaper_profile_id)"
1131                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1132                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1133                         "       Add port tm leaf node.\n\n"
1134
1135                         "del port tm node (port_id) (node_id)\n"
1136                         "       Delete port tm node.\n\n"
1137
1138                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1139                         " (priority) (weight)\n"
1140                         "       Set port tm node parent.\n\n"
1141
1142                         "suspend port tm node (port_id) (node_id)"
1143                         "       Suspend tm node.\n\n"
1144
1145                         "resume port tm node (port_id) (node_id)"
1146                         "       Resume tm node.\n\n"
1147
1148                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1149                         "       Commit tm hierarchy.\n\n"
1150
1151                         "set port tm mark ip_ecn (port) (green) (yellow)"
1152                         " (red)\n"
1153                         "    Enables/Disables the traffic management marking"
1154                         " for IP ECN (Explicit Congestion Notification)"
1155                         " packets on a given port\n\n"
1156
1157                         "set port tm mark ip_dscp (port) (green) (yellow)"
1158                         " (red)\n"
1159                         "    Enables/Disables the traffic management marking"
1160                         " on the port for IP dscp packets\n\n"
1161
1162                         "set port tm mark vlan_dei (port) (green) (yellow)"
1163                         " (red)\n"
1164                         "    Enables/Disables the traffic management marking"
1165                         " on the port for VLAN packets with DEI enabled\n\n"
1166                 );
1167         }
1168
1169         if (show_all || !strcmp(res->section, "devices")) {
1170                 cmdline_printf(
1171                         cl,
1172                         "\n"
1173                         "Device Operations:\n"
1174                         "--------------\n"
1175                         "device detach (identifier)\n"
1176                         "       Detach device by identifier.\n\n"
1177                 );
1178         }
1179
1180 }
1181
1182 cmdline_parse_token_string_t cmd_help_long_help =
1183         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1184
1185 cmdline_parse_token_string_t cmd_help_long_section =
1186         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1187                         "all#control#display#config#"
1188                         "ports#registers#filters#traffic_management#devices");
1189
1190 cmdline_parse_inst_t cmd_help_long = {
1191         .f = cmd_help_long_parsed,
1192         .data = NULL,
1193         .help_str = "help all|control|display|config|ports|register|"
1194                 "filters|traffic_management|devices: "
1195                 "Show help",
1196         .tokens = {
1197                 (void *)&cmd_help_long_help,
1198                 (void *)&cmd_help_long_section,
1199                 NULL,
1200         },
1201 };
1202
1203
1204 /* *** start/stop/close all ports *** */
1205 struct cmd_operate_port_result {
1206         cmdline_fixed_string_t keyword;
1207         cmdline_fixed_string_t name;
1208         cmdline_fixed_string_t value;
1209 };
1210
1211 static void cmd_operate_port_parsed(void *parsed_result,
1212                                 __rte_unused struct cmdline *cl,
1213                                 __rte_unused void *data)
1214 {
1215         struct cmd_operate_port_result *res = parsed_result;
1216
1217         if (!strcmp(res->name, "start"))
1218                 start_port(RTE_PORT_ALL);
1219         else if (!strcmp(res->name, "stop"))
1220                 stop_port(RTE_PORT_ALL);
1221         else if (!strcmp(res->name, "close"))
1222                 close_port(RTE_PORT_ALL);
1223         else if (!strcmp(res->name, "reset"))
1224                 reset_port(RTE_PORT_ALL);
1225         else
1226                 fprintf(stderr, "Unknown parameter\n");
1227 }
1228
1229 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1230         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1231                                                                 "port");
1232 cmdline_parse_token_string_t cmd_operate_port_all_port =
1233         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1234                                                 "start#stop#close#reset");
1235 cmdline_parse_token_string_t cmd_operate_port_all_all =
1236         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1237
1238 cmdline_parse_inst_t cmd_operate_port = {
1239         .f = cmd_operate_port_parsed,
1240         .data = NULL,
1241         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1242         .tokens = {
1243                 (void *)&cmd_operate_port_all_cmd,
1244                 (void *)&cmd_operate_port_all_port,
1245                 (void *)&cmd_operate_port_all_all,
1246                 NULL,
1247         },
1248 };
1249
1250 /* *** start/stop/close specific port *** */
1251 struct cmd_operate_specific_port_result {
1252         cmdline_fixed_string_t keyword;
1253         cmdline_fixed_string_t name;
1254         uint8_t value;
1255 };
1256
1257 static void cmd_operate_specific_port_parsed(void *parsed_result,
1258                         __rte_unused struct cmdline *cl,
1259                                 __rte_unused void *data)
1260 {
1261         struct cmd_operate_specific_port_result *res = parsed_result;
1262
1263         if (!strcmp(res->name, "start"))
1264                 start_port(res->value);
1265         else if (!strcmp(res->name, "stop"))
1266                 stop_port(res->value);
1267         else if (!strcmp(res->name, "close"))
1268                 close_port(res->value);
1269         else if (!strcmp(res->name, "reset"))
1270                 reset_port(res->value);
1271         else
1272                 fprintf(stderr, "Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1277                                                         keyword, "port");
1278 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1280                                                 name, "start#stop#close#reset");
1281 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1283                                                         value, RTE_UINT8);
1284
1285 cmdline_parse_inst_t cmd_operate_specific_port = {
1286         .f = cmd_operate_specific_port_parsed,
1287         .data = NULL,
1288         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1289         .tokens = {
1290                 (void *)&cmd_operate_specific_port_cmd,
1291                 (void *)&cmd_operate_specific_port_port,
1292                 (void *)&cmd_operate_specific_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** enable port setup (after attach) via iterator or event *** */
1298 struct cmd_set_port_setup_on_result {
1299         cmdline_fixed_string_t set;
1300         cmdline_fixed_string_t port;
1301         cmdline_fixed_string_t setup;
1302         cmdline_fixed_string_t on;
1303         cmdline_fixed_string_t mode;
1304 };
1305
1306 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1307                                 __rte_unused struct cmdline *cl,
1308                                 __rte_unused void *data)
1309 {
1310         struct cmd_set_port_setup_on_result *res = parsed_result;
1311
1312         if (strcmp(res->mode, "event") == 0)
1313                 setup_on_probe_event = true;
1314         else if (strcmp(res->mode, "iterator") == 0)
1315                 setup_on_probe_event = false;
1316         else
1317                 fprintf(stderr, "Unknown mode\n");
1318 }
1319
1320 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1321         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1322                         set, "set");
1323 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1324         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1325                         port, "port");
1326 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1327         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1328                         setup, "setup");
1329 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1330         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1331                         on, "on");
1332 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1333         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1334                         mode, "iterator#event");
1335
1336 cmdline_parse_inst_t cmd_set_port_setup_on = {
1337         .f = cmd_set_port_setup_on_parsed,
1338         .data = NULL,
1339         .help_str = "set port setup on iterator|event",
1340         .tokens = {
1341                 (void *)&cmd_set_port_setup_on_set,
1342                 (void *)&cmd_set_port_setup_on_port,
1343                 (void *)&cmd_set_port_setup_on_setup,
1344                 (void *)&cmd_set_port_setup_on_on,
1345                 (void *)&cmd_set_port_setup_on_mode,
1346                 NULL,
1347         },
1348 };
1349
1350 /* *** attach a specified port *** */
1351 struct cmd_operate_attach_port_result {
1352         cmdline_fixed_string_t port;
1353         cmdline_fixed_string_t keyword;
1354         cmdline_multi_string_t identifier;
1355 };
1356
1357 static void cmd_operate_attach_port_parsed(void *parsed_result,
1358                                 __rte_unused struct cmdline *cl,
1359                                 __rte_unused void *data)
1360 {
1361         struct cmd_operate_attach_port_result *res = parsed_result;
1362
1363         if (!strcmp(res->keyword, "attach"))
1364                 attach_port(res->identifier);
1365         else
1366                 fprintf(stderr, "Unknown parameter\n");
1367 }
1368
1369 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1370         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1371                         port, "port");
1372 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1373         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1374                         keyword, "attach");
1375 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1376         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1377                         identifier, TOKEN_STRING_MULTI);
1378
1379 cmdline_parse_inst_t cmd_operate_attach_port = {
1380         .f = cmd_operate_attach_port_parsed,
1381         .data = NULL,
1382         .help_str = "port attach <identifier>: "
1383                 "(identifier: pci address or virtual dev name)",
1384         .tokens = {
1385                 (void *)&cmd_operate_attach_port_port,
1386                 (void *)&cmd_operate_attach_port_keyword,
1387                 (void *)&cmd_operate_attach_port_identifier,
1388                 NULL,
1389         },
1390 };
1391
1392 /* *** detach a specified port *** */
1393 struct cmd_operate_detach_port_result {
1394         cmdline_fixed_string_t port;
1395         cmdline_fixed_string_t keyword;
1396         portid_t port_id;
1397 };
1398
1399 static void cmd_operate_detach_port_parsed(void *parsed_result,
1400                                 __rte_unused struct cmdline *cl,
1401                                 __rte_unused void *data)
1402 {
1403         struct cmd_operate_detach_port_result *res = parsed_result;
1404
1405         if (!strcmp(res->keyword, "detach")) {
1406                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1407                 detach_port_device(res->port_id);
1408         } else {
1409                 fprintf(stderr, "Unknown parameter\n");
1410         }
1411 }
1412
1413 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1414         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1415                         port, "port");
1416 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1417         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1418                         keyword, "detach");
1419 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1420         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1421                         port_id, RTE_UINT16);
1422
1423 cmdline_parse_inst_t cmd_operate_detach_port = {
1424         .f = cmd_operate_detach_port_parsed,
1425         .data = NULL,
1426         .help_str = "port detach <port_id>",
1427         .tokens = {
1428                 (void *)&cmd_operate_detach_port_port,
1429                 (void *)&cmd_operate_detach_port_keyword,
1430                 (void *)&cmd_operate_detach_port_port_id,
1431                 NULL,
1432         },
1433 };
1434
1435 /* *** detach device by identifier *** */
1436 struct cmd_operate_detach_device_result {
1437         cmdline_fixed_string_t device;
1438         cmdline_fixed_string_t keyword;
1439         cmdline_fixed_string_t identifier;
1440 };
1441
1442 static void cmd_operate_detach_device_parsed(void *parsed_result,
1443                                 __rte_unused struct cmdline *cl,
1444                                 __rte_unused void *data)
1445 {
1446         struct cmd_operate_detach_device_result *res = parsed_result;
1447
1448         if (!strcmp(res->keyword, "detach"))
1449                 detach_devargs(res->identifier);
1450         else
1451                 fprintf(stderr, "Unknown parameter\n");
1452 }
1453
1454 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1455         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1456                         device, "device");
1457 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1458         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1459                         keyword, "detach");
1460 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1461         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1462                         identifier, NULL);
1463
1464 cmdline_parse_inst_t cmd_operate_detach_device = {
1465         .f = cmd_operate_detach_device_parsed,
1466         .data = NULL,
1467         .help_str = "device detach <identifier>:"
1468                 "(identifier: pci address or virtual dev name)",
1469         .tokens = {
1470                 (void *)&cmd_operate_detach_device_device,
1471                 (void *)&cmd_operate_detach_device_keyword,
1472                 (void *)&cmd_operate_detach_device_identifier,
1473                 NULL,
1474         },
1475 };
1476 /* *** configure speed for all ports *** */
1477 struct cmd_config_speed_all {
1478         cmdline_fixed_string_t port;
1479         cmdline_fixed_string_t keyword;
1480         cmdline_fixed_string_t all;
1481         cmdline_fixed_string_t item1;
1482         cmdline_fixed_string_t item2;
1483         cmdline_fixed_string_t value1;
1484         cmdline_fixed_string_t value2;
1485 };
1486
1487 static int
1488 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1489 {
1490
1491         int duplex;
1492
1493         if (!strcmp(duplexstr, "half")) {
1494                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
1495         } else if (!strcmp(duplexstr, "full")) {
1496                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1497         } else if (!strcmp(duplexstr, "auto")) {
1498                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1499         } else {
1500                 fprintf(stderr, "Unknown duplex parameter\n");
1501                 return -1;
1502         }
1503
1504         if (!strcmp(speedstr, "10")) {
1505                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1506                                 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1507         } else if (!strcmp(speedstr, "100")) {
1508                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1509                                 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1510         } else {
1511                 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1512                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1513                         return -1;
1514                 }
1515                 if (!strcmp(speedstr, "1000")) {
1516                         *speed = RTE_ETH_LINK_SPEED_1G;
1517                 } else if (!strcmp(speedstr, "10000")) {
1518                         *speed = RTE_ETH_LINK_SPEED_10G;
1519                 } else if (!strcmp(speedstr, "25000")) {
1520                         *speed = RTE_ETH_LINK_SPEED_25G;
1521                 } else if (!strcmp(speedstr, "40000")) {
1522                         *speed = RTE_ETH_LINK_SPEED_40G;
1523                 } else if (!strcmp(speedstr, "50000")) {
1524                         *speed = RTE_ETH_LINK_SPEED_50G;
1525                 } else if (!strcmp(speedstr, "100000")) {
1526                         *speed = RTE_ETH_LINK_SPEED_100G;
1527                 } else if (!strcmp(speedstr, "200000")) {
1528                         *speed = RTE_ETH_LINK_SPEED_200G;
1529                 } else if (!strcmp(speedstr, "auto")) {
1530                         *speed = RTE_ETH_LINK_SPEED_AUTONEG;
1531                 } else {
1532                         fprintf(stderr, "Unknown speed parameter\n");
1533                         return -1;
1534                 }
1535         }
1536
1537         if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1538                 *speed |= RTE_ETH_LINK_SPEED_FIXED;
1539
1540         return 0;
1541 }
1542
1543 static void
1544 cmd_config_speed_all_parsed(void *parsed_result,
1545                         __rte_unused struct cmdline *cl,
1546                         __rte_unused void *data)
1547 {
1548         struct cmd_config_speed_all *res = parsed_result;
1549         uint32_t link_speed;
1550         portid_t pid;
1551
1552         if (!all_ports_stopped()) {
1553                 fprintf(stderr, "Please stop all ports first\n");
1554                 return;
1555         }
1556
1557         if (parse_and_check_speed_duplex(res->value1, res->value2,
1558                         &link_speed) < 0)
1559                 return;
1560
1561         RTE_ETH_FOREACH_DEV(pid) {
1562                 ports[pid].dev_conf.link_speeds = link_speed;
1563         }
1564
1565         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1566 }
1567
1568 cmdline_parse_token_string_t cmd_config_speed_all_port =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1570 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1571         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1572                                                         "config");
1573 cmdline_parse_token_string_t cmd_config_speed_all_all =
1574         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1575 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1576         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1577 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1578         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1579                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1580 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1581         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1582 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1583         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1584                                                 "half#full#auto");
1585
1586 cmdline_parse_inst_t cmd_config_speed_all = {
1587         .f = cmd_config_speed_all_parsed,
1588         .data = NULL,
1589         .help_str = "port config all speed "
1590                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1591                                                         "half|full|auto",
1592         .tokens = {
1593                 (void *)&cmd_config_speed_all_port,
1594                 (void *)&cmd_config_speed_all_keyword,
1595                 (void *)&cmd_config_speed_all_all,
1596                 (void *)&cmd_config_speed_all_item1,
1597                 (void *)&cmd_config_speed_all_value1,
1598                 (void *)&cmd_config_speed_all_item2,
1599                 (void *)&cmd_config_speed_all_value2,
1600                 NULL,
1601         },
1602 };
1603
1604 /* *** configure speed for specific port *** */
1605 struct cmd_config_speed_specific {
1606         cmdline_fixed_string_t port;
1607         cmdline_fixed_string_t keyword;
1608         portid_t id;
1609         cmdline_fixed_string_t item1;
1610         cmdline_fixed_string_t item2;
1611         cmdline_fixed_string_t value1;
1612         cmdline_fixed_string_t value2;
1613 };
1614
1615 static void
1616 cmd_config_speed_specific_parsed(void *parsed_result,
1617                                 __rte_unused struct cmdline *cl,
1618                                 __rte_unused void *data)
1619 {
1620         struct cmd_config_speed_specific *res = parsed_result;
1621         uint32_t link_speed;
1622
1623         if (port_id_is_invalid(res->id, ENABLED_WARN))
1624                 return;
1625
1626         if (!port_is_stopped(res->id)) {
1627                 fprintf(stderr, "Please stop port %d first\n", res->id);
1628                 return;
1629         }
1630
1631         if (parse_and_check_speed_duplex(res->value1, res->value2,
1632                         &link_speed) < 0)
1633                 return;
1634
1635         ports[res->id].dev_conf.link_speeds = link_speed;
1636
1637         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1638 }
1639
1640
1641 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1642         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1643                                                                 "port");
1644 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1646                                                                 "config");
1647 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1648         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1649 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1650         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1651                                                                 "speed");
1652 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1654                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1655 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1657                                                                 "duplex");
1658 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1660                                                         "half#full#auto");
1661
1662 cmdline_parse_inst_t cmd_config_speed_specific = {
1663         .f = cmd_config_speed_specific_parsed,
1664         .data = NULL,
1665         .help_str = "port config <port_id> speed "
1666                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1667                                                         "half|full|auto",
1668         .tokens = {
1669                 (void *)&cmd_config_speed_specific_port,
1670                 (void *)&cmd_config_speed_specific_keyword,
1671                 (void *)&cmd_config_speed_specific_id,
1672                 (void *)&cmd_config_speed_specific_item1,
1673                 (void *)&cmd_config_speed_specific_value1,
1674                 (void *)&cmd_config_speed_specific_item2,
1675                 (void *)&cmd_config_speed_specific_value2,
1676                 NULL,
1677         },
1678 };
1679
1680 /* *** configure loopback for all ports *** */
1681 struct cmd_config_loopback_all {
1682         cmdline_fixed_string_t port;
1683         cmdline_fixed_string_t keyword;
1684         cmdline_fixed_string_t all;
1685         cmdline_fixed_string_t item;
1686         uint32_t mode;
1687 };
1688
1689 static void
1690 cmd_config_loopback_all_parsed(void *parsed_result,
1691                         __rte_unused struct cmdline *cl,
1692                         __rte_unused void *data)
1693 {
1694         struct cmd_config_loopback_all *res = parsed_result;
1695         portid_t pid;
1696
1697         if (!all_ports_stopped()) {
1698                 fprintf(stderr, "Please stop all ports first\n");
1699                 return;
1700         }
1701
1702         RTE_ETH_FOREACH_DEV(pid) {
1703                 ports[pid].dev_conf.lpbk_mode = res->mode;
1704         }
1705
1706         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1707 }
1708
1709 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1710         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1711 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1712         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1713                                                         "config");
1714 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1716 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1717         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1718                                                         "loopback");
1719 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1720         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1721
1722 cmdline_parse_inst_t cmd_config_loopback_all = {
1723         .f = cmd_config_loopback_all_parsed,
1724         .data = NULL,
1725         .help_str = "port config all loopback <mode>",
1726         .tokens = {
1727                 (void *)&cmd_config_loopback_all_port,
1728                 (void *)&cmd_config_loopback_all_keyword,
1729                 (void *)&cmd_config_loopback_all_all,
1730                 (void *)&cmd_config_loopback_all_item,
1731                 (void *)&cmd_config_loopback_all_mode,
1732                 NULL,
1733         },
1734 };
1735
1736 /* *** configure loopback for specific port *** */
1737 struct cmd_config_loopback_specific {
1738         cmdline_fixed_string_t port;
1739         cmdline_fixed_string_t keyword;
1740         uint16_t port_id;
1741         cmdline_fixed_string_t item;
1742         uint32_t mode;
1743 };
1744
1745 static void
1746 cmd_config_loopback_specific_parsed(void *parsed_result,
1747                                 __rte_unused struct cmdline *cl,
1748                                 __rte_unused void *data)
1749 {
1750         struct cmd_config_loopback_specific *res = parsed_result;
1751
1752         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1753                 return;
1754
1755         if (!port_is_stopped(res->port_id)) {
1756                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1757                 return;
1758         }
1759
1760         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1761
1762         cmd_reconfig_device_queue(res->port_id, 1, 1);
1763 }
1764
1765
1766 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1767         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1768                                                                 "port");
1769 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1770         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1771                                                                 "config");
1772 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1773         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1774                                                                 RTE_UINT16);
1775 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1776         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1777                                                                 "loopback");
1778 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1779         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1780                               RTE_UINT32);
1781
1782 cmdline_parse_inst_t cmd_config_loopback_specific = {
1783         .f = cmd_config_loopback_specific_parsed,
1784         .data = NULL,
1785         .help_str = "port config <port_id> loopback <mode>",
1786         .tokens = {
1787                 (void *)&cmd_config_loopback_specific_port,
1788                 (void *)&cmd_config_loopback_specific_keyword,
1789                 (void *)&cmd_config_loopback_specific_id,
1790                 (void *)&cmd_config_loopback_specific_item,
1791                 (void *)&cmd_config_loopback_specific_mode,
1792                 NULL,
1793         },
1794 };
1795
1796 /* *** configure txq/rxq, txd/rxd *** */
1797 struct cmd_config_rx_tx {
1798         cmdline_fixed_string_t port;
1799         cmdline_fixed_string_t keyword;
1800         cmdline_fixed_string_t all;
1801         cmdline_fixed_string_t name;
1802         uint16_t value;
1803 };
1804
1805 static void
1806 cmd_config_rx_tx_parsed(void *parsed_result,
1807                         __rte_unused struct cmdline *cl,
1808                         __rte_unused void *data)
1809 {
1810         struct cmd_config_rx_tx *res = parsed_result;
1811
1812         if (!all_ports_stopped()) {
1813                 fprintf(stderr, "Please stop all ports first\n");
1814                 return;
1815         }
1816         if (!strcmp(res->name, "rxq")) {
1817                 if (!res->value && !nb_txq) {
1818                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1819                         return;
1820                 }
1821                 if (check_nb_rxq(res->value) != 0)
1822                         return;
1823                 nb_rxq = res->value;
1824         }
1825         else if (!strcmp(res->name, "txq")) {
1826                 if (!res->value && !nb_rxq) {
1827                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1828                         return;
1829                 }
1830                 if (check_nb_txq(res->value) != 0)
1831                         return;
1832                 nb_txq = res->value;
1833         }
1834         else if (!strcmp(res->name, "rxd")) {
1835                 if (check_nb_rxd(res->value) != 0)
1836                         return;
1837                 nb_rxd = res->value;
1838         } else if (!strcmp(res->name, "txd")) {
1839                 if (check_nb_txd(res->value) != 0)
1840                         return;
1841
1842                 nb_txd = res->value;
1843         } else {
1844                 fprintf(stderr, "Unknown parameter\n");
1845                 return;
1846         }
1847
1848         fwd_config_setup();
1849
1850         init_port_config();
1851
1852         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1853 }
1854
1855 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1856         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1857 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1858         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1859 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1861 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1862         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1863                                                 "rxq#txq#rxd#txd");
1864 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1865         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1866
1867 cmdline_parse_inst_t cmd_config_rx_tx = {
1868         .f = cmd_config_rx_tx_parsed,
1869         .data = NULL,
1870         .help_str = "port config all rxq|txq|rxd|txd <value>",
1871         .tokens = {
1872                 (void *)&cmd_config_rx_tx_port,
1873                 (void *)&cmd_config_rx_tx_keyword,
1874                 (void *)&cmd_config_rx_tx_all,
1875                 (void *)&cmd_config_rx_tx_name,
1876                 (void *)&cmd_config_rx_tx_value,
1877                 NULL,
1878         },
1879 };
1880
1881 /* *** config max packet length *** */
1882 struct cmd_config_max_pkt_len_result {
1883         cmdline_fixed_string_t port;
1884         cmdline_fixed_string_t keyword;
1885         cmdline_fixed_string_t all;
1886         cmdline_fixed_string_t name;
1887         uint32_t value;
1888 };
1889
1890 static void
1891 cmd_config_max_pkt_len_parsed(void *parsed_result,
1892                                 __rte_unused struct cmdline *cl,
1893                                 __rte_unused void *data)
1894 {
1895         struct cmd_config_max_pkt_len_result *res = parsed_result;
1896         portid_t port_id;
1897         int ret;
1898
1899         if (strcmp(res->name, "max-pkt-len") != 0) {
1900                 printf("Unknown parameter\n");
1901                 return;
1902         }
1903
1904         if (!all_ports_stopped()) {
1905                 fprintf(stderr, "Please stop all ports first\n");
1906                 return;
1907         }
1908
1909         RTE_ETH_FOREACH_DEV(port_id) {
1910                 struct rte_port *port = &ports[port_id];
1911
1912                 if (res->value < RTE_ETHER_MIN_LEN) {
1913                         fprintf(stderr,
1914                                 "max-pkt-len can not be less than %d\n",
1915                                 RTE_ETHER_MIN_LEN);
1916                         return;
1917                 }
1918
1919                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1920                 if (ret != 0) {
1921                         fprintf(stderr,
1922                                 "rte_eth_dev_info_get() failed for port %u\n",
1923                                 port_id);
1924                         return;
1925                 }
1926
1927                 update_mtu_from_frame_size(port_id, res->value);
1928         }
1929
1930         init_port_config();
1931
1932         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1933 }
1934
1935 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1936         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1937                                                                 "port");
1938 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1939         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1940                                                                 "config");
1941 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1943                                                                 "all");
1944 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1945         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1946                                                                 "max-pkt-len");
1947 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1948         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1949                                                                 RTE_UINT32);
1950
1951 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1952         .f = cmd_config_max_pkt_len_parsed,
1953         .data = NULL,
1954         .help_str = "port config all max-pkt-len <value>",
1955         .tokens = {
1956                 (void *)&cmd_config_max_pkt_len_port,
1957                 (void *)&cmd_config_max_pkt_len_keyword,
1958                 (void *)&cmd_config_max_pkt_len_all,
1959                 (void *)&cmd_config_max_pkt_len_name,
1960                 (void *)&cmd_config_max_pkt_len_value,
1961                 NULL,
1962         },
1963 };
1964
1965 /* *** config max LRO aggregated packet size *** */
1966 struct cmd_config_max_lro_pkt_size_result {
1967         cmdline_fixed_string_t port;
1968         cmdline_fixed_string_t keyword;
1969         cmdline_fixed_string_t all;
1970         cmdline_fixed_string_t name;
1971         uint32_t value;
1972 };
1973
1974 static void
1975 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1976                                 __rte_unused struct cmdline *cl,
1977                                 __rte_unused void *data)
1978 {
1979         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1980         portid_t pid;
1981
1982         if (!all_ports_stopped()) {
1983                 fprintf(stderr, "Please stop all ports first\n");
1984                 return;
1985         }
1986
1987         RTE_ETH_FOREACH_DEV(pid) {
1988                 struct rte_port *port = &ports[pid];
1989
1990                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1991                         if (res->value ==
1992                                         port->dev_conf.rxmode.max_lro_pkt_size)
1993                                 return;
1994
1995                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1996                 } else {
1997                         fprintf(stderr, "Unknown parameter\n");
1998                         return;
1999                 }
2000         }
2001
2002         init_port_config();
2003
2004         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2005 }
2006
2007 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2009                                  port, "port");
2010 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2011         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2012                                  keyword, "config");
2013 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2015                                  all, "all");
2016 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2018                                  name, "max-lro-pkt-size");
2019 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2020         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2021                               value, RTE_UINT32);
2022
2023 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2024         .f = cmd_config_max_lro_pkt_size_parsed,
2025         .data = NULL,
2026         .help_str = "port config all max-lro-pkt-size <value>",
2027         .tokens = {
2028                 (void *)&cmd_config_max_lro_pkt_size_port,
2029                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2030                 (void *)&cmd_config_max_lro_pkt_size_all,
2031                 (void *)&cmd_config_max_lro_pkt_size_name,
2032                 (void *)&cmd_config_max_lro_pkt_size_value,
2033                 NULL,
2034         },
2035 };
2036
2037 /* *** configure port MTU *** */
2038 struct cmd_config_mtu_result {
2039         cmdline_fixed_string_t port;
2040         cmdline_fixed_string_t keyword;
2041         cmdline_fixed_string_t mtu;
2042         portid_t port_id;
2043         uint16_t value;
2044 };
2045
2046 static void
2047 cmd_config_mtu_parsed(void *parsed_result,
2048                       __rte_unused struct cmdline *cl,
2049                       __rte_unused void *data)
2050 {
2051         struct cmd_config_mtu_result *res = parsed_result;
2052
2053         port_mtu_set(res->port_id, res->value);
2054 }
2055
2056 cmdline_parse_token_string_t cmd_config_mtu_port =
2057         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2058                                  "port");
2059 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2060         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2061                                  "config");
2062 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2063         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2064                                  "mtu");
2065 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2066         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2067                                  RTE_UINT16);
2068 cmdline_parse_token_num_t cmd_config_mtu_value =
2069         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2070                                  RTE_UINT16);
2071
2072 cmdline_parse_inst_t cmd_config_mtu = {
2073         .f = cmd_config_mtu_parsed,
2074         .data = NULL,
2075         .help_str = "port config mtu <port_id> <value>",
2076         .tokens = {
2077                 (void *)&cmd_config_mtu_port,
2078                 (void *)&cmd_config_mtu_keyword,
2079                 (void *)&cmd_config_mtu_mtu,
2080                 (void *)&cmd_config_mtu_port_id,
2081                 (void *)&cmd_config_mtu_value,
2082                 NULL,
2083         },
2084 };
2085
2086 /* *** configure rx mode *** */
2087 struct cmd_config_rx_mode_flag {
2088         cmdline_fixed_string_t port;
2089         cmdline_fixed_string_t keyword;
2090         cmdline_fixed_string_t all;
2091         cmdline_fixed_string_t name;
2092         cmdline_fixed_string_t value;
2093 };
2094
2095 static void
2096 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2097                                 __rte_unused struct cmdline *cl,
2098                                 __rte_unused void *data)
2099 {
2100         struct cmd_config_rx_mode_flag *res = parsed_result;
2101
2102         if (!all_ports_stopped()) {
2103                 fprintf(stderr, "Please stop all ports first\n");
2104                 return;
2105         }
2106
2107         if (!strcmp(res->name, "drop-en")) {
2108                 if (!strcmp(res->value, "on"))
2109                         rx_drop_en = 1;
2110                 else if (!strcmp(res->value, "off"))
2111                         rx_drop_en = 0;
2112                 else {
2113                         fprintf(stderr, "Unknown parameter\n");
2114                         return;
2115                 }
2116         } else {
2117                 fprintf(stderr, "Unknown parameter\n");
2118                 return;
2119         }
2120
2121         init_port_config();
2122
2123         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2124 }
2125
2126 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2127         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2128 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2129         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2130                                                                 "config");
2131 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2133 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2134         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2135                                         "drop-en");
2136 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2137         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2138                                                         "on#off");
2139
2140 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2141         .f = cmd_config_rx_mode_flag_parsed,
2142         .data = NULL,
2143         .help_str = "port config all drop-en on|off",
2144         .tokens = {
2145                 (void *)&cmd_config_rx_mode_flag_port,
2146                 (void *)&cmd_config_rx_mode_flag_keyword,
2147                 (void *)&cmd_config_rx_mode_flag_all,
2148                 (void *)&cmd_config_rx_mode_flag_name,
2149                 (void *)&cmd_config_rx_mode_flag_value,
2150                 NULL,
2151         },
2152 };
2153
2154 /* *** configure rss *** */
2155 struct cmd_config_rss {
2156         cmdline_fixed_string_t port;
2157         cmdline_fixed_string_t keyword;
2158         cmdline_fixed_string_t all;
2159         cmdline_fixed_string_t name;
2160         cmdline_fixed_string_t value;
2161 };
2162
2163 static void
2164 cmd_config_rss_parsed(void *parsed_result,
2165                         __rte_unused struct cmdline *cl,
2166                         __rte_unused void *data)
2167 {
2168         struct cmd_config_rss *res = parsed_result;
2169         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2170         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2171         int use_default = 0;
2172         int all_updated = 1;
2173         int diag;
2174         uint16_t i;
2175         int ret;
2176
2177         if (!strcmp(res->value, "all"))
2178                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2179                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2180                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2181                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2182                         RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
2183         else if (!strcmp(res->value, "eth"))
2184                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2185         else if (!strcmp(res->value, "vlan"))
2186                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2187         else if (!strcmp(res->value, "ip"))
2188                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2189         else if (!strcmp(res->value, "udp"))
2190                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2191         else if (!strcmp(res->value, "tcp"))
2192                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2193         else if (!strcmp(res->value, "sctp"))
2194                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2195         else if (!strcmp(res->value, "ether"))
2196                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2197         else if (!strcmp(res->value, "port"))
2198                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2199         else if (!strcmp(res->value, "vxlan"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2201         else if (!strcmp(res->value, "geneve"))
2202                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2203         else if (!strcmp(res->value, "nvgre"))
2204                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2205         else if (!strcmp(res->value, "l3-pre32"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2207         else if (!strcmp(res->value, "l3-pre40"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2209         else if (!strcmp(res->value, "l3-pre48"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2211         else if (!strcmp(res->value, "l3-pre56"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2213         else if (!strcmp(res->value, "l3-pre64"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2215         else if (!strcmp(res->value, "l3-pre96"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2217         else if (!strcmp(res->value, "l3-src-only"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2219         else if (!strcmp(res->value, "l3-dst-only"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2221         else if (!strcmp(res->value, "l4-src-only"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2223         else if (!strcmp(res->value, "l4-dst-only"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2225         else if (!strcmp(res->value, "l2-src-only"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2227         else if (!strcmp(res->value, "l2-dst-only"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2229         else if (!strcmp(res->value, "l2tpv3"))
2230                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2231         else if (!strcmp(res->value, "esp"))
2232                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2233         else if (!strcmp(res->value, "ah"))
2234                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2235         else if (!strcmp(res->value, "pfcp"))
2236                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2237         else if (!strcmp(res->value, "pppoe"))
2238                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2239         else if (!strcmp(res->value, "gtpu"))
2240                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2241         else if (!strcmp(res->value, "ecpri"))
2242                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2243         else if (!strcmp(res->value, "mpls"))
2244                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2245         else if (!strcmp(res->value, "ipv4-chksum"))
2246                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2247         else if (!strcmp(res->value, "l2tpv2"))
2248                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
2249         else if (!strcmp(res->value, "none"))
2250                 rss_conf.rss_hf = 0;
2251         else if (!strcmp(res->value, "level-default")) {
2252                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2253                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2254         } else if (!strcmp(res->value, "level-outer")) {
2255                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2256                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2257         } else if (!strcmp(res->value, "level-inner")) {
2258                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2259                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2260         } else if (!strcmp(res->value, "default"))
2261                 use_default = 1;
2262         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2263                                                 atoi(res->value) < 64)
2264                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2265         else {
2266                 fprintf(stderr, "Unknown parameter\n");
2267                 return;
2268         }
2269         rss_conf.rss_key = NULL;
2270         /* Update global configuration for RSS types. */
2271         RTE_ETH_FOREACH_DEV(i) {
2272                 struct rte_eth_rss_conf local_rss_conf;
2273
2274                 ret = eth_dev_info_get_print_err(i, &dev_info);
2275                 if (ret != 0)
2276                         return;
2277
2278                 if (use_default)
2279                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2280
2281                 local_rss_conf = rss_conf;
2282                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2283                         dev_info.flow_type_rss_offloads;
2284                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2285                         printf("Port %u modified RSS hash function based on hardware support,"
2286                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2287                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2288                 }
2289                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2290                 if (diag < 0) {
2291                         all_updated = 0;
2292                         fprintf(stderr,
2293                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2294                                 i, -diag, strerror(-diag));
2295                 }
2296         }
2297         if (all_updated && !use_default) {
2298                 rss_hf = rss_conf.rss_hf;
2299                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2300         }
2301 }
2302
2303 cmdline_parse_token_string_t cmd_config_rss_port =
2304         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2305 cmdline_parse_token_string_t cmd_config_rss_keyword =
2306         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2307 cmdline_parse_token_string_t cmd_config_rss_all =
2308         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2309 cmdline_parse_token_string_t cmd_config_rss_name =
2310         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2311 cmdline_parse_token_string_t cmd_config_rss_value =
2312         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2313
2314 cmdline_parse_inst_t cmd_config_rss = {
2315         .f = cmd_config_rss_parsed,
2316         .data = NULL,
2317         .help_str = "port config all rss "
2318                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2319                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
2320                 "none|level-default|level-outer|level-inner|<flowtype_id>",
2321         .tokens = {
2322                 (void *)&cmd_config_rss_port,
2323                 (void *)&cmd_config_rss_keyword,
2324                 (void *)&cmd_config_rss_all,
2325                 (void *)&cmd_config_rss_name,
2326                 (void *)&cmd_config_rss_value,
2327                 NULL,
2328         },
2329 };
2330
2331 /* *** configure rss hash key *** */
2332 struct cmd_config_rss_hash_key {
2333         cmdline_fixed_string_t port;
2334         cmdline_fixed_string_t config;
2335         portid_t port_id;
2336         cmdline_fixed_string_t rss_hash_key;
2337         cmdline_fixed_string_t rss_type;
2338         cmdline_fixed_string_t key;
2339 };
2340
2341 static uint8_t
2342 hexa_digit_to_value(char hexa_digit)
2343 {
2344         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2345                 return (uint8_t) (hexa_digit - '0');
2346         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2347                 return (uint8_t) ((hexa_digit - 'a') + 10);
2348         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2349                 return (uint8_t) ((hexa_digit - 'A') + 10);
2350         /* Invalid hexa digit */
2351         return 0xFF;
2352 }
2353
2354 static uint8_t
2355 parse_and_check_key_hexa_digit(char *key, int idx)
2356 {
2357         uint8_t hexa_v;
2358
2359         hexa_v = hexa_digit_to_value(key[idx]);
2360         if (hexa_v == 0xFF)
2361                 fprintf(stderr,
2362                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2363                         key[idx], idx);
2364         return hexa_v;
2365 }
2366
2367 static void
2368 cmd_config_rss_hash_key_parsed(void *parsed_result,
2369                                __rte_unused struct cmdline *cl,
2370                                __rte_unused void *data)
2371 {
2372         struct cmd_config_rss_hash_key *res = parsed_result;
2373         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2374         uint8_t xdgt0;
2375         uint8_t xdgt1;
2376         int i;
2377         struct rte_eth_dev_info dev_info;
2378         uint8_t hash_key_size;
2379         uint32_t key_len;
2380         int ret;
2381
2382         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2383         if (ret != 0)
2384                 return;
2385
2386         if (dev_info.hash_key_size > 0 &&
2387                         dev_info.hash_key_size <= sizeof(hash_key))
2388                 hash_key_size = dev_info.hash_key_size;
2389         else {
2390                 fprintf(stderr,
2391                         "dev_info did not provide a valid hash key size\n");
2392                 return;
2393         }
2394         /* Check the length of the RSS hash key */
2395         key_len = strlen(res->key);
2396         if (key_len != (hash_key_size * 2)) {
2397                 fprintf(stderr,
2398                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2399                         (int)key_len, hash_key_size * 2);
2400                 return;
2401         }
2402         /* Translate RSS hash key into binary representation */
2403         for (i = 0; i < hash_key_size; i++) {
2404                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2405                 if (xdgt0 == 0xFF)
2406                         return;
2407                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2408                 if (xdgt1 == 0xFF)
2409                         return;
2410                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2411         }
2412         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2413                         hash_key_size);
2414 }
2415
2416 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2417         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2420                                  "config");
2421 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2422         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2423                                  RTE_UINT16);
2424 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2425         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2426                                  rss_hash_key, "rss-hash-key");
2427 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2428         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2429                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2430                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2431                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2432                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2433                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2434                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2435                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls#l2tpv2");
2436 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2438
2439 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2440         .f = cmd_config_rss_hash_key_parsed,
2441         .data = NULL,
2442         .help_str = "port config <port_id> rss-hash-key "
2443                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2444                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2445                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2446                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2447                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2448                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls|l2tpv2 "
2449                 "<string of hex digits (variable length, NIC dependent)>",
2450         .tokens = {
2451                 (void *)&cmd_config_rss_hash_key_port,
2452                 (void *)&cmd_config_rss_hash_key_config,
2453                 (void *)&cmd_config_rss_hash_key_port_id,
2454                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2455                 (void *)&cmd_config_rss_hash_key_rss_type,
2456                 (void *)&cmd_config_rss_hash_key_value,
2457                 NULL,
2458         },
2459 };
2460
2461 /* *** cleanup txq mbufs *** */
2462 struct cmd_cleanup_txq_mbufs_result {
2463         cmdline_fixed_string_t port;
2464         cmdline_fixed_string_t keyword;
2465         cmdline_fixed_string_t name;
2466         uint16_t port_id;
2467         uint16_t queue_id;
2468         uint32_t free_cnt;
2469 };
2470
2471 static void
2472 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2473                              __rte_unused struct cmdline *cl,
2474                              __rte_unused void *data)
2475 {
2476         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2477         uint16_t port_id = res->port_id;
2478         uint16_t queue_id = res->queue_id;
2479         uint32_t free_cnt = res->free_cnt;
2480         struct rte_eth_txq_info qinfo;
2481         int ret;
2482
2483         if (test_done == 0) {
2484                 fprintf(stderr, "Please stop forwarding first\n");
2485                 return;
2486         }
2487
2488         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2489                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2490                         port_id, queue_id);
2491                 return;
2492         }
2493
2494         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2495                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2496                 return;
2497         }
2498
2499         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2500         if (ret < 0) {
2501                 fprintf(stderr,
2502                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2503                         port_id, queue_id, strerror(-ret), ret);
2504                 return;
2505         }
2506
2507         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2508                port_id, queue_id, ret);
2509 }
2510
2511 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2512         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2513                                  "port");
2514 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2515         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2516                                  "cleanup");
2517 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2518         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2519                               RTE_UINT16);
2520 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2521         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2522                                  "txq");
2523 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2524         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2525                               RTE_UINT16);
2526 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2527         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2528                               RTE_UINT32);
2529
2530 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2531         .f = cmd_cleanup_txq_mbufs_parsed,
2532         .data = NULL,
2533         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2534         .tokens = {
2535                 (void *)&cmd_cleanup_txq_mbufs_port,
2536                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2537                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2538                 (void *)&cmd_cleanup_txq_mbufs_txq,
2539                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2540                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2541                 NULL,
2542         },
2543 };
2544
2545 /* *** configure port rxq/txq ring size *** */
2546 struct cmd_config_rxtx_ring_size {
2547         cmdline_fixed_string_t port;
2548         cmdline_fixed_string_t config;
2549         portid_t portid;
2550         cmdline_fixed_string_t rxtxq;
2551         uint16_t qid;
2552         cmdline_fixed_string_t rsize;
2553         uint16_t size;
2554 };
2555
2556 static void
2557 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2558                                  __rte_unused struct cmdline *cl,
2559                                  __rte_unused void *data)
2560 {
2561         struct cmd_config_rxtx_ring_size *res = parsed_result;
2562         struct rte_port *port;
2563         uint8_t isrx;
2564
2565         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2566                 return;
2567
2568         if (res->portid == (portid_t)RTE_PORT_ALL) {
2569                 fprintf(stderr, "Invalid port id\n");
2570                 return;
2571         }
2572
2573         port = &ports[res->portid];
2574
2575         if (!strcmp(res->rxtxq, "rxq"))
2576                 isrx = 1;
2577         else if (!strcmp(res->rxtxq, "txq"))
2578                 isrx = 0;
2579         else {
2580                 fprintf(stderr, "Unknown parameter\n");
2581                 return;
2582         }
2583
2584         if (isrx && rx_queue_id_is_invalid(res->qid))
2585                 return;
2586         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2587                 return;
2588
2589         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2590                 fprintf(stderr,
2591                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2592                         rx_free_thresh);
2593                 return;
2594         }
2595
2596         if (isrx)
2597                 port->nb_rx_desc[res->qid] = res->size;
2598         else
2599                 port->nb_tx_desc[res->qid] = res->size;
2600
2601         cmd_reconfig_device_queue(res->portid, 0, 1);
2602 }
2603
2604 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2605         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606                                  port, "port");
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609                                  config, "config");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2611         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612                                  portid, RTE_UINT16);
2613 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2614         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2615                                  rxtxq, "rxq#txq");
2616 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2617         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2618                               qid, RTE_UINT16);
2619 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2621                                  rsize, "ring_size");
2622 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2623         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2624                               size, RTE_UINT16);
2625
2626 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2627         .f = cmd_config_rxtx_ring_size_parsed,
2628         .data = NULL,
2629         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2630         .tokens = {
2631                 (void *)&cmd_config_rxtx_ring_size_port,
2632                 (void *)&cmd_config_rxtx_ring_size_config,
2633                 (void *)&cmd_config_rxtx_ring_size_portid,
2634                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2635                 (void *)&cmd_config_rxtx_ring_size_qid,
2636                 (void *)&cmd_config_rxtx_ring_size_rsize,
2637                 (void *)&cmd_config_rxtx_ring_size_size,
2638                 NULL,
2639         },
2640 };
2641
2642 /* *** configure port rxq/txq start/stop *** */
2643 struct cmd_config_rxtx_queue {
2644         cmdline_fixed_string_t port;
2645         portid_t portid;
2646         cmdline_fixed_string_t rxtxq;
2647         uint16_t qid;
2648         cmdline_fixed_string_t opname;
2649 };
2650
2651 static void
2652 cmd_config_rxtx_queue_parsed(void *parsed_result,
2653                         __rte_unused struct cmdline *cl,
2654                         __rte_unused void *data)
2655 {
2656         struct cmd_config_rxtx_queue *res = parsed_result;
2657         struct rte_port *port;
2658         uint8_t isrx;
2659         uint8_t isstart;
2660         uint8_t *state;
2661         int ret = 0;
2662
2663         if (test_done == 0) {
2664                 fprintf(stderr, "Please stop forwarding first\n");
2665                 return;
2666         }
2667
2668         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2669                 return;
2670
2671         if (port_is_started(res->portid) != 1) {
2672                 fprintf(stderr, "Please start port %u first\n", res->portid);
2673                 return;
2674         }
2675
2676         if (!strcmp(res->rxtxq, "rxq"))
2677                 isrx = 1;
2678         else if (!strcmp(res->rxtxq, "txq"))
2679                 isrx = 0;
2680         else {
2681                 fprintf(stderr, "Unknown parameter\n");
2682                 return;
2683         }
2684
2685         if (isrx && rx_queue_id_is_invalid(res->qid))
2686                 return;
2687         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2688                 return;
2689
2690         if (!strcmp(res->opname, "start"))
2691                 isstart = 1;
2692         else if (!strcmp(res->opname, "stop"))
2693                 isstart = 0;
2694         else {
2695                 fprintf(stderr, "Unknown parameter\n");
2696                 return;
2697         }
2698
2699         if (isstart && isrx)
2700                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2701         else if (!isstart && isrx)
2702                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2703         else if (isstart && !isrx)
2704                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2705         else
2706                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2707
2708         if (ret == -ENOTSUP) {
2709                 fprintf(stderr, "Function not supported in PMD\n");
2710                 return;
2711         }
2712
2713         port = &ports[res->portid];
2714         state = isrx ? &port->rxq[res->qid].state : &port->txq[res->qid].state;
2715         *state = isstart ? RTE_ETH_QUEUE_STATE_STARTED :
2716                            RTE_ETH_QUEUE_STATE_STOPPED;
2717 }
2718
2719 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2720         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2721 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2722         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2723 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2724         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2725 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2726         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2727 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2728         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2729                                                 "start#stop");
2730
2731 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2732         .f = cmd_config_rxtx_queue_parsed,
2733         .data = NULL,
2734         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2735         .tokens = {
2736                 (void *)&cmd_config_rxtx_queue_port,
2737                 (void *)&cmd_config_rxtx_queue_portid,
2738                 (void *)&cmd_config_rxtx_queue_rxtxq,
2739                 (void *)&cmd_config_rxtx_queue_qid,
2740                 (void *)&cmd_config_rxtx_queue_opname,
2741                 NULL,
2742         },
2743 };
2744
2745 /* *** configure port rxq/txq deferred start on/off *** */
2746 struct cmd_config_deferred_start_rxtx_queue {
2747         cmdline_fixed_string_t port;
2748         portid_t port_id;
2749         cmdline_fixed_string_t rxtxq;
2750         uint16_t qid;
2751         cmdline_fixed_string_t opname;
2752         cmdline_fixed_string_t state;
2753 };
2754
2755 static void
2756 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2757                         __rte_unused struct cmdline *cl,
2758                         __rte_unused void *data)
2759 {
2760         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2761         struct rte_port *port;
2762         uint8_t isrx;
2763         uint8_t ison;
2764         uint8_t needreconfig = 0;
2765
2766         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2767                 return;
2768
2769         if (port_is_started(res->port_id) != 0) {
2770                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2771                 return;
2772         }
2773
2774         port = &ports[res->port_id];
2775
2776         isrx = !strcmp(res->rxtxq, "rxq");
2777
2778         if (isrx && rx_queue_id_is_invalid(res->qid))
2779                 return;
2780         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2781                 return;
2782
2783         ison = !strcmp(res->state, "on");
2784
2785         if (isrx && port->rxq[res->qid].conf.rx_deferred_start != ison) {
2786                 port->rxq[res->qid].conf.rx_deferred_start = ison;
2787                 needreconfig = 1;
2788         } else if (!isrx && port->txq[res->qid].conf.tx_deferred_start != ison) {
2789                 port->txq[res->qid].conf.tx_deferred_start = ison;
2790                 needreconfig = 1;
2791         }
2792
2793         if (needreconfig)
2794                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2795 }
2796
2797 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2798         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799                                                 port, "port");
2800 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2801         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2802                                                 port_id, RTE_UINT16);
2803 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2804         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2805                                                 rxtxq, "rxq#txq");
2806 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2807         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2808                                                 qid, RTE_UINT16);
2809 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2810         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2811                                                 opname, "deferred_start");
2812 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2813         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2814                                                 state, "on#off");
2815
2816 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2817         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2818         .data = NULL,
2819         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2820         .tokens = {
2821                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2822                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2823                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2824                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2825                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2826                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2827                 NULL,
2828         },
2829 };
2830
2831 /* *** configure port rxq/txq setup *** */
2832 struct cmd_setup_rxtx_queue {
2833         cmdline_fixed_string_t port;
2834         portid_t portid;
2835         cmdline_fixed_string_t rxtxq;
2836         uint16_t qid;
2837         cmdline_fixed_string_t setup;
2838 };
2839
2840 /* Common CLI fields for queue setup */
2841 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2842         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2843 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2844         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2845 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2846         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2847 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2848         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2849 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2850         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2851
2852 static void
2853 cmd_setup_rxtx_queue_parsed(
2854         void *parsed_result,
2855         __rte_unused struct cmdline *cl,
2856         __rte_unused void *data)
2857 {
2858         struct cmd_setup_rxtx_queue *res = parsed_result;
2859         struct rte_port *port;
2860         struct rte_mempool *mp;
2861         unsigned int socket_id;
2862         uint8_t isrx = 0;
2863         int ret;
2864
2865         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2866                 return;
2867
2868         if (res->portid == (portid_t)RTE_PORT_ALL) {
2869                 fprintf(stderr, "Invalid port id\n");
2870                 return;
2871         }
2872
2873         if (!strcmp(res->rxtxq, "rxq"))
2874                 isrx = 1;
2875         else if (!strcmp(res->rxtxq, "txq"))
2876                 isrx = 0;
2877         else {
2878                 fprintf(stderr, "Unknown parameter\n");
2879                 return;
2880         }
2881
2882         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2883                 fprintf(stderr, "Invalid rx queue\n");
2884                 return;
2885         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2886                 fprintf(stderr, "Invalid tx queue\n");
2887                 return;
2888         }
2889
2890         port = &ports[res->portid];
2891         if (isrx) {
2892                 socket_id = rxring_numa[res->portid];
2893                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2894                         socket_id = port->socket_id;
2895
2896                 mp = mbuf_pool_find(socket_id, 0);
2897                 if (mp == NULL) {
2898                         fprintf(stderr,
2899                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2900                                 rxring_numa[res->portid]);
2901                         return;
2902                 }
2903                 ret = rx_queue_setup(res->portid,
2904                                      res->qid,
2905                                      port->nb_rx_desc[res->qid],
2906                                      socket_id,
2907                                      &port->rxq[res->qid].conf,
2908                                      mp);
2909                 if (ret)
2910                         fprintf(stderr, "Failed to setup RX queue\n");
2911         } else {
2912                 socket_id = txring_numa[res->portid];
2913                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2914                         socket_id = port->socket_id;
2915
2916                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2917                         fprintf(stderr,
2918                                 "Failed to setup TX queue: not enough descriptors\n");
2919                         return;
2920                 }
2921                 ret = rte_eth_tx_queue_setup(res->portid,
2922                                              res->qid,
2923                                              port->nb_tx_desc[res->qid],
2924                                              socket_id,
2925                                              &port->txq[res->qid].conf);
2926                 if (ret)
2927                         fprintf(stderr, "Failed to setup TX queue\n");
2928         }
2929 }
2930
2931 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2932         .f = cmd_setup_rxtx_queue_parsed,
2933         .data = NULL,
2934         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2935         .tokens = {
2936                 (void *)&cmd_setup_rxtx_queue_port,
2937                 (void *)&cmd_setup_rxtx_queue_portid,
2938                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2939                 (void *)&cmd_setup_rxtx_queue_qid,
2940                 (void *)&cmd_setup_rxtx_queue_setup,
2941                 NULL,
2942         },
2943 };
2944
2945
2946 /* *** Configure RSS RETA *** */
2947 struct cmd_config_rss_reta {
2948         cmdline_fixed_string_t port;
2949         cmdline_fixed_string_t keyword;
2950         portid_t port_id;
2951         cmdline_fixed_string_t name;
2952         cmdline_fixed_string_t list_name;
2953         cmdline_fixed_string_t list_of_items;
2954 };
2955
2956 static int
2957 parse_reta_config(const char *str,
2958                   struct rte_eth_rss_reta_entry64 *reta_conf,
2959                   uint16_t nb_entries)
2960 {
2961         int i;
2962         unsigned size;
2963         uint16_t hash_index, idx, shift;
2964         uint16_t nb_queue;
2965         char s[256];
2966         const char *p, *p0 = str;
2967         char *end;
2968         enum fieldnames {
2969                 FLD_HASH_INDEX = 0,
2970                 FLD_QUEUE,
2971                 _NUM_FLD
2972         };
2973         unsigned long int_fld[_NUM_FLD];
2974         char *str_fld[_NUM_FLD];
2975
2976         while ((p = strchr(p0,'(')) != NULL) {
2977                 ++p;
2978                 if((p0 = strchr(p,')')) == NULL)
2979                         return -1;
2980
2981                 size = p0 - p;
2982                 if(size >= sizeof(s))
2983                         return -1;
2984
2985                 snprintf(s, sizeof(s), "%.*s", size, p);
2986                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2987                         return -1;
2988                 for (i = 0; i < _NUM_FLD; i++) {
2989                         errno = 0;
2990                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2991                         if (errno != 0 || end == str_fld[i] ||
2992                                         int_fld[i] > 65535)
2993                                 return -1;
2994                 }
2995
2996                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2997                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2998
2999                 if (hash_index >= nb_entries) {
3000                         fprintf(stderr, "Invalid RETA hash index=%d\n",
3001                                 hash_index);
3002                         return -1;
3003                 }
3004
3005                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
3006                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
3007                 reta_conf[idx].mask |= (1ULL << shift);
3008                 reta_conf[idx].reta[shift] = nb_queue;
3009         }
3010
3011         return 0;
3012 }
3013
3014 static void
3015 cmd_set_rss_reta_parsed(void *parsed_result,
3016                         __rte_unused struct cmdline *cl,
3017                         __rte_unused void *data)
3018 {
3019         int ret;
3020         struct rte_eth_dev_info dev_info;
3021         struct rte_eth_rss_reta_entry64 reta_conf[8];
3022         struct cmd_config_rss_reta *res = parsed_result;
3023
3024         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3025         if (ret != 0)
3026                 return;
3027
3028         if (dev_info.reta_size == 0) {
3029                 fprintf(stderr,
3030                         "Redirection table size is 0 which is invalid for RSS\n");
3031                 return;
3032         } else
3033                 printf("The reta size of port %d is %u\n",
3034                         res->port_id, dev_info.reta_size);
3035         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3036                 fprintf(stderr,
3037                         "Currently do not support more than %u entries of redirection table\n",
3038                         RTE_ETH_RSS_RETA_SIZE_512);
3039                 return;
3040         }
3041
3042         memset(reta_conf, 0, sizeof(reta_conf));
3043         if (!strcmp(res->list_name, "reta")) {
3044                 if (parse_reta_config(res->list_of_items, reta_conf,
3045                                                 dev_info.reta_size)) {
3046                         fprintf(stderr,
3047                                 "Invalid RSS Redirection Table config entered\n");
3048                         return;
3049                 }
3050                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3051                                 reta_conf, dev_info.reta_size);
3052                 if (ret != 0)
3053                         fprintf(stderr,
3054                                 "Bad redirection table parameter, return code = %d\n",
3055                                 ret);
3056         }
3057 }
3058
3059 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3060         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3061 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3062         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3063 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3064         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3065 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3066         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3067 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3068         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3069 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3070         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3071                                  NULL);
3072 cmdline_parse_inst_t cmd_config_rss_reta = {
3073         .f = cmd_set_rss_reta_parsed,
3074         .data = NULL,
3075         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3076         .tokens = {
3077                 (void *)&cmd_config_rss_reta_port,
3078                 (void *)&cmd_config_rss_reta_keyword,
3079                 (void *)&cmd_config_rss_reta_port_id,
3080                 (void *)&cmd_config_rss_reta_name,
3081                 (void *)&cmd_config_rss_reta_list_name,
3082                 (void *)&cmd_config_rss_reta_list_of_items,
3083                 NULL,
3084         },
3085 };
3086
3087 /* *** SHOW PORT RETA INFO *** */
3088 struct cmd_showport_reta {
3089         cmdline_fixed_string_t show;
3090         cmdline_fixed_string_t port;
3091         portid_t port_id;
3092         cmdline_fixed_string_t rss;
3093         cmdline_fixed_string_t reta;
3094         uint16_t size;
3095         cmdline_fixed_string_t list_of_items;
3096 };
3097
3098 static int
3099 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3100                            uint16_t nb_entries,
3101                            char *str)
3102 {
3103         uint32_t size;
3104         const char *p, *p0 = str;
3105         char s[256];
3106         char *end;
3107         char *str_fld[8];
3108         uint16_t i;
3109         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3110                         RTE_ETH_RETA_GROUP_SIZE;
3111         int ret;
3112
3113         p = strchr(p0, '(');
3114         if (p == NULL)
3115                 return -1;
3116         p++;
3117         p0 = strchr(p, ')');
3118         if (p0 == NULL)
3119                 return -1;
3120         size = p0 - p;
3121         if (size >= sizeof(s)) {
3122                 fprintf(stderr,
3123                         "The string size exceeds the internal buffer size\n");
3124                 return -1;
3125         }
3126         snprintf(s, sizeof(s), "%.*s", size, p);
3127         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3128         if (ret <= 0 || ret != num) {
3129                 fprintf(stderr,
3130                         "The bits of masks do not match the number of reta entries: %u\n",
3131                         num);
3132                 return -1;
3133         }
3134         for (i = 0; i < ret; i++)
3135                 conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
3136
3137         return 0;
3138 }
3139
3140 static void
3141 cmd_showport_reta_parsed(void *parsed_result,
3142                          __rte_unused struct cmdline *cl,
3143                          __rte_unused void *data)
3144 {
3145         struct cmd_showport_reta *res = parsed_result;
3146         struct rte_eth_rss_reta_entry64 reta_conf[8];
3147         struct rte_eth_dev_info dev_info;
3148         uint16_t max_reta_size;
3149         int ret;
3150
3151         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3152         if (ret != 0)
3153                 return;
3154
3155         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3156         if (res->size == 0 || res->size > max_reta_size) {
3157                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3158                         res->size, max_reta_size);
3159                 return;
3160         }
3161
3162         memset(reta_conf, 0, sizeof(reta_conf));
3163         if (showport_parse_reta_config(reta_conf, res->size,
3164                                 res->list_of_items) < 0) {
3165                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3166                         res->list_of_items);
3167                 return;
3168         }
3169         port_rss_reta_info(res->port_id, reta_conf, res->size);
3170 }
3171
3172 cmdline_parse_token_string_t cmd_showport_reta_show =
3173         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3174 cmdline_parse_token_string_t cmd_showport_reta_port =
3175         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3176 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3177         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3178 cmdline_parse_token_string_t cmd_showport_reta_rss =
3179         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3180 cmdline_parse_token_string_t cmd_showport_reta_reta =
3181         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3182 cmdline_parse_token_num_t cmd_showport_reta_size =
3183         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3184 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3185         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3186                                         list_of_items, NULL);
3187
3188 cmdline_parse_inst_t cmd_showport_reta = {
3189         .f = cmd_showport_reta_parsed,
3190         .data = NULL,
3191         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3192         .tokens = {
3193                 (void *)&cmd_showport_reta_show,
3194                 (void *)&cmd_showport_reta_port,
3195                 (void *)&cmd_showport_reta_port_id,
3196                 (void *)&cmd_showport_reta_rss,
3197                 (void *)&cmd_showport_reta_reta,
3198                 (void *)&cmd_showport_reta_size,
3199                 (void *)&cmd_showport_reta_list_of_items,
3200                 NULL,
3201         },
3202 };
3203
3204 /* *** Show RSS hash configuration *** */
3205 struct cmd_showport_rss_hash {
3206         cmdline_fixed_string_t show;
3207         cmdline_fixed_string_t port;
3208         portid_t port_id;
3209         cmdline_fixed_string_t rss_hash;
3210         cmdline_fixed_string_t rss_type;
3211         cmdline_fixed_string_t key; /* optional argument */
3212 };
3213
3214 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3215                                 __rte_unused struct cmdline *cl,
3216                                 void *show_rss_key)
3217 {
3218         struct cmd_showport_rss_hash *res = parsed_result;
3219
3220         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3221 }
3222
3223 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3224         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3225 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3226         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3227 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3228         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3229                                  RTE_UINT16);
3230 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3231         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3232                                  "rss-hash");
3233 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3234         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3235
3236 cmdline_parse_inst_t cmd_showport_rss_hash = {
3237         .f = cmd_showport_rss_hash_parsed,
3238         .data = NULL,
3239         .help_str = "show port <port_id> rss-hash",
3240         .tokens = {
3241                 (void *)&cmd_showport_rss_hash_show,
3242                 (void *)&cmd_showport_rss_hash_port,
3243                 (void *)&cmd_showport_rss_hash_port_id,
3244                 (void *)&cmd_showport_rss_hash_rss_hash,
3245                 NULL,
3246         },
3247 };
3248
3249 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3250         .f = cmd_showport_rss_hash_parsed,
3251         .data = (void *)1,
3252         .help_str = "show port <port_id> rss-hash key",
3253         .tokens = {
3254                 (void *)&cmd_showport_rss_hash_show,
3255                 (void *)&cmd_showport_rss_hash_port,
3256                 (void *)&cmd_showport_rss_hash_port_id,
3257                 (void *)&cmd_showport_rss_hash_rss_hash,
3258                 (void *)&cmd_showport_rss_hash_rss_key,
3259                 NULL,
3260         },
3261 };
3262
3263 /* *** Configure DCB *** */
3264 struct cmd_config_dcb {
3265         cmdline_fixed_string_t port;
3266         cmdline_fixed_string_t config;
3267         portid_t port_id;
3268         cmdline_fixed_string_t dcb;
3269         cmdline_fixed_string_t vt;
3270         cmdline_fixed_string_t vt_en;
3271         uint8_t num_tcs;
3272         cmdline_fixed_string_t pfc;
3273         cmdline_fixed_string_t pfc_en;
3274 };
3275
3276 static void
3277 cmd_config_dcb_parsed(void *parsed_result,
3278                         __rte_unused struct cmdline *cl,
3279                         __rte_unused void *data)
3280 {
3281         struct cmd_config_dcb *res = parsed_result;
3282         struct rte_eth_dcb_info dcb_info;
3283         portid_t port_id = res->port_id;
3284         struct rte_port *port;
3285         uint8_t pfc_en;
3286         int ret;
3287
3288         port = &ports[port_id];
3289         /** Check if the port is not started **/
3290         if (port->port_status != RTE_PORT_STOPPED) {
3291                 fprintf(stderr, "Please stop port %d first\n", port_id);
3292                 return;
3293         }
3294
3295         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3296                 fprintf(stderr,
3297                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3298                 return;
3299         }
3300
3301         if (nb_fwd_lcores < res->num_tcs) {
3302                 fprintf(stderr,
3303                         "nb_cores shouldn't be less than number of TCs.\n");
3304                 return;
3305         }
3306
3307         /* Check whether the port supports the report of DCB info. */
3308         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3309         if (ret == -ENOTSUP) {
3310                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3311                 return;
3312         }
3313
3314         if (!strncmp(res->pfc_en, "on", 2))
3315                 pfc_en = 1;
3316         else
3317                 pfc_en = 0;
3318
3319         /* DCB in VT mode */
3320         if (!strncmp(res->vt_en, "on", 2))
3321                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3322                                 (enum rte_eth_nb_tcs)res->num_tcs,
3323                                 pfc_en);
3324         else
3325                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3326                                 (enum rte_eth_nb_tcs)res->num_tcs,
3327                                 pfc_en);
3328         if (ret != 0) {
3329                 fprintf(stderr, "Cannot initialize network ports.\n");
3330                 return;
3331         }
3332
3333         fwd_config_setup();
3334
3335         cmd_reconfig_device_queue(port_id, 1, 1);
3336 }
3337
3338 cmdline_parse_token_string_t cmd_config_dcb_port =
3339         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3340 cmdline_parse_token_string_t cmd_config_dcb_config =
3341         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3342 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3343         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3344 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3345         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3346 cmdline_parse_token_string_t cmd_config_dcb_vt =
3347         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3348 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3349         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3350 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3351         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3352 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3354 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3355         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3356
3357 cmdline_parse_inst_t cmd_config_dcb = {
3358         .f = cmd_config_dcb_parsed,
3359         .data = NULL,
3360         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3361         .tokens = {
3362                 (void *)&cmd_config_dcb_port,
3363                 (void *)&cmd_config_dcb_config,
3364                 (void *)&cmd_config_dcb_port_id,
3365                 (void *)&cmd_config_dcb_dcb,
3366                 (void *)&cmd_config_dcb_vt,
3367                 (void *)&cmd_config_dcb_vt_en,
3368                 (void *)&cmd_config_dcb_num_tcs,
3369                 (void *)&cmd_config_dcb_pfc,
3370                 (void *)&cmd_config_dcb_pfc_en,
3371                 NULL,
3372         },
3373 };
3374
3375 /* *** configure number of packets per burst *** */
3376 struct cmd_config_burst {
3377         cmdline_fixed_string_t port;
3378         cmdline_fixed_string_t keyword;
3379         cmdline_fixed_string_t all;
3380         cmdline_fixed_string_t name;
3381         uint16_t value;
3382 };
3383
3384 static void
3385 cmd_config_burst_parsed(void *parsed_result,
3386                         __rte_unused struct cmdline *cl,
3387                         __rte_unused void *data)
3388 {
3389         struct cmd_config_burst *res = parsed_result;
3390         struct rte_eth_dev_info dev_info;
3391         uint16_t rec_nb_pkts;
3392         int ret;
3393
3394         if (!all_ports_stopped()) {
3395                 fprintf(stderr, "Please stop all ports first\n");
3396                 return;
3397         }
3398
3399         if (!strcmp(res->name, "burst")) {
3400                 if (res->value == 0) {
3401                         /* If user gives a value of zero, query the PMD for
3402                          * its recommended Rx burst size. Testpmd uses a single
3403                          * size for all ports, so assume all ports are the same
3404                          * NIC model and use the values from Port 0.
3405                          */
3406                         ret = eth_dev_info_get_print_err(0, &dev_info);
3407                         if (ret != 0)
3408                                 return;
3409
3410                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3411
3412                         if (rec_nb_pkts == 0) {
3413                                 printf("PMD does not recommend a burst size.\n"
3414                                         "User provided value must be between"
3415                                         " 1 and %d\n", MAX_PKT_BURST);
3416                                 return;
3417                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3418                                 printf("PMD recommended burst size of %d"
3419                                         " exceeds maximum value of %d\n",
3420                                         rec_nb_pkts, MAX_PKT_BURST);
3421                                 return;
3422                         }
3423                         printf("Using PMD-provided burst value of %d\n",
3424                                 rec_nb_pkts);
3425                         nb_pkt_per_burst = rec_nb_pkts;
3426                 } else if (res->value > MAX_PKT_BURST) {
3427                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3428                                 MAX_PKT_BURST);
3429                         return;
3430                 } else
3431                         nb_pkt_per_burst = res->value;
3432         } else {
3433                 fprintf(stderr, "Unknown parameter\n");
3434                 return;
3435         }
3436
3437         init_port_config();
3438
3439         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3440 }
3441
3442 cmdline_parse_token_string_t cmd_config_burst_port =
3443         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3444 cmdline_parse_token_string_t cmd_config_burst_keyword =
3445         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3446 cmdline_parse_token_string_t cmd_config_burst_all =
3447         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3448 cmdline_parse_token_string_t cmd_config_burst_name =
3449         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3450 cmdline_parse_token_num_t cmd_config_burst_value =
3451         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3452
3453 cmdline_parse_inst_t cmd_config_burst = {
3454         .f = cmd_config_burst_parsed,
3455         .data = NULL,
3456         .help_str = "port config all burst <value>",
3457         .tokens = {
3458                 (void *)&cmd_config_burst_port,
3459                 (void *)&cmd_config_burst_keyword,
3460                 (void *)&cmd_config_burst_all,
3461                 (void *)&cmd_config_burst_name,
3462                 (void *)&cmd_config_burst_value,
3463                 NULL,
3464         },
3465 };
3466
3467 /* *** configure rx/tx queues *** */
3468 struct cmd_config_thresh {
3469         cmdline_fixed_string_t port;
3470         cmdline_fixed_string_t keyword;
3471         cmdline_fixed_string_t all;
3472         cmdline_fixed_string_t name;
3473         uint8_t value;
3474 };
3475
3476 static void
3477 cmd_config_thresh_parsed(void *parsed_result,
3478                         __rte_unused struct cmdline *cl,
3479                         __rte_unused void *data)
3480 {
3481         struct cmd_config_thresh *res = parsed_result;
3482
3483         if (!all_ports_stopped()) {
3484                 fprintf(stderr, "Please stop all ports first\n");
3485                 return;
3486         }
3487
3488         if (!strcmp(res->name, "txpt"))
3489                 tx_pthresh = res->value;
3490         else if(!strcmp(res->name, "txht"))
3491                 tx_hthresh = res->value;
3492         else if(!strcmp(res->name, "txwt"))
3493                 tx_wthresh = res->value;
3494         else if(!strcmp(res->name, "rxpt"))
3495                 rx_pthresh = res->value;
3496         else if(!strcmp(res->name, "rxht"))
3497                 rx_hthresh = res->value;
3498         else if(!strcmp(res->name, "rxwt"))
3499                 rx_wthresh = res->value;
3500         else {
3501                 fprintf(stderr, "Unknown parameter\n");
3502                 return;
3503         }
3504
3505         init_port_config();
3506
3507         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3508 }
3509
3510 cmdline_parse_token_string_t cmd_config_thresh_port =
3511         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3512 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3513         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3514 cmdline_parse_token_string_t cmd_config_thresh_all =
3515         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3516 cmdline_parse_token_string_t cmd_config_thresh_name =
3517         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3518                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3519 cmdline_parse_token_num_t cmd_config_thresh_value =
3520         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3521
3522 cmdline_parse_inst_t cmd_config_thresh = {
3523         .f = cmd_config_thresh_parsed,
3524         .data = NULL,
3525         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3526         .tokens = {
3527                 (void *)&cmd_config_thresh_port,
3528                 (void *)&cmd_config_thresh_keyword,
3529                 (void *)&cmd_config_thresh_all,
3530                 (void *)&cmd_config_thresh_name,
3531                 (void *)&cmd_config_thresh_value,
3532                 NULL,
3533         },
3534 };
3535
3536 /* *** configure free/rs threshold *** */
3537 struct cmd_config_threshold {
3538         cmdline_fixed_string_t port;
3539         cmdline_fixed_string_t keyword;
3540         cmdline_fixed_string_t all;
3541         cmdline_fixed_string_t name;
3542         uint16_t value;
3543 };
3544
3545 static void
3546 cmd_config_threshold_parsed(void *parsed_result,
3547                         __rte_unused struct cmdline *cl,
3548                         __rte_unused void *data)
3549 {
3550         struct cmd_config_threshold *res = parsed_result;
3551
3552         if (!all_ports_stopped()) {
3553                 fprintf(stderr, "Please stop all ports first\n");
3554                 return;
3555         }
3556
3557         if (!strcmp(res->name, "txfreet"))
3558                 tx_free_thresh = res->value;
3559         else if (!strcmp(res->name, "txrst"))
3560                 tx_rs_thresh = res->value;
3561         else if (!strcmp(res->name, "rxfreet"))
3562                 rx_free_thresh = res->value;
3563         else {
3564                 fprintf(stderr, "Unknown parameter\n");
3565                 return;
3566         }
3567
3568         init_port_config();
3569
3570         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3571 }
3572
3573 cmdline_parse_token_string_t cmd_config_threshold_port =
3574         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3575 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3576         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3577                                                                 "config");
3578 cmdline_parse_token_string_t cmd_config_threshold_all =
3579         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3580 cmdline_parse_token_string_t cmd_config_threshold_name =
3581         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3582                                                 "txfreet#txrst#rxfreet");
3583 cmdline_parse_token_num_t cmd_config_threshold_value =
3584         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3585
3586 cmdline_parse_inst_t cmd_config_threshold = {
3587         .f = cmd_config_threshold_parsed,
3588         .data = NULL,
3589         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3590         .tokens = {
3591                 (void *)&cmd_config_threshold_port,
3592                 (void *)&cmd_config_threshold_keyword,
3593                 (void *)&cmd_config_threshold_all,
3594                 (void *)&cmd_config_threshold_name,
3595                 (void *)&cmd_config_threshold_value,
3596                 NULL,
3597         },
3598 };
3599
3600 /* *** stop *** */
3601 struct cmd_stop_result {
3602         cmdline_fixed_string_t stop;
3603 };
3604
3605 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3606                             __rte_unused struct cmdline *cl,
3607                             __rte_unused void *data)
3608 {
3609         stop_packet_forwarding();
3610 }
3611
3612 cmdline_parse_token_string_t cmd_stop_stop =
3613         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3614
3615 cmdline_parse_inst_t cmd_stop = {
3616         .f = cmd_stop_parsed,
3617         .data = NULL,
3618         .help_str = "stop: Stop packet forwarding",
3619         .tokens = {
3620                 (void *)&cmd_stop_stop,
3621                 NULL,
3622         },
3623 };
3624
3625 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3626
3627 unsigned int
3628 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3629                 unsigned int *parsed_items, int check_unique_values)
3630 {
3631         unsigned int nb_item;
3632         unsigned int value;
3633         unsigned int i;
3634         unsigned int j;
3635         int value_ok;
3636         char c;
3637
3638         /*
3639          * First parse all items in the list and store their value.
3640          */
3641         value = 0;
3642         nb_item = 0;
3643         value_ok = 0;
3644         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3645                 c = str[i];
3646                 if ((c >= '0') && (c <= '9')) {
3647                         value = (unsigned int) (value * 10 + (c - '0'));
3648                         value_ok = 1;
3649                         continue;
3650                 }
3651                 if (c != ',') {
3652                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3653                         return 0;
3654                 }
3655                 if (! value_ok) {
3656                         fprintf(stderr, "No valid value before comma\n");
3657                         return 0;
3658                 }
3659                 if (nb_item < max_items) {
3660                         parsed_items[nb_item] = value;
3661                         value_ok = 0;
3662                         value = 0;
3663                 }
3664                 nb_item++;
3665         }
3666         if (nb_item >= max_items) {
3667                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3668                         item_name, nb_item + 1, max_items);
3669                 return 0;
3670         }
3671         parsed_items[nb_item++] = value;
3672         if (! check_unique_values)
3673                 return nb_item;
3674
3675         /*
3676          * Then, check that all values in the list are different.
3677          * No optimization here...
3678          */
3679         for (i = 0; i < nb_item; i++) {
3680                 for (j = i + 1; j < nb_item; j++) {
3681                         if (parsed_items[j] == parsed_items[i]) {
3682                                 fprintf(stderr,
3683                                         "duplicated %s %u at index %u and %u\n",
3684                                         item_name, parsed_items[i], i, j);
3685                                 return 0;
3686                         }
3687                 }
3688         }
3689         return nb_item;
3690 }
3691
3692 struct cmd_set_list_result {
3693         cmdline_fixed_string_t cmd_keyword;
3694         cmdline_fixed_string_t list_name;
3695         cmdline_fixed_string_t list_of_items;
3696 };
3697
3698 static void cmd_set_list_parsed(void *parsed_result,
3699                                 __rte_unused struct cmdline *cl,
3700                                 __rte_unused void *data)
3701 {
3702         struct cmd_set_list_result *res;
3703         union {
3704                 unsigned int lcorelist[RTE_MAX_LCORE];
3705                 unsigned int portlist[RTE_MAX_ETHPORTS];
3706         } parsed_items;
3707         unsigned int nb_item;
3708
3709         if (test_done == 0) {
3710                 fprintf(stderr, "Please stop forwarding first\n");
3711                 return;
3712         }
3713
3714         res = parsed_result;
3715         if (!strcmp(res->list_name, "corelist")) {
3716                 nb_item = parse_item_list(res->list_of_items, "core",
3717                                           RTE_MAX_LCORE,
3718                                           parsed_items.lcorelist, 1);
3719                 if (nb_item > 0) {
3720                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3721                         fwd_config_setup();
3722                 }
3723                 return;
3724         }
3725         if (!strcmp(res->list_name, "portlist")) {
3726                 nb_item = parse_item_list(res->list_of_items, "port",
3727                                           RTE_MAX_ETHPORTS,
3728                                           parsed_items.portlist, 1);
3729                 if (nb_item > 0) {
3730                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3731                         fwd_config_setup();
3732                 }
3733         }
3734 }
3735
3736 cmdline_parse_token_string_t cmd_set_list_keyword =
3737         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3738                                  "set");
3739 cmdline_parse_token_string_t cmd_set_list_name =
3740         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3741                                  "corelist#portlist");
3742 cmdline_parse_token_string_t cmd_set_list_of_items =
3743         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3744                                  NULL);
3745
3746 cmdline_parse_inst_t cmd_set_fwd_list = {
3747         .f = cmd_set_list_parsed,
3748         .data = NULL,
3749         .help_str = "set corelist|portlist <list0[,list1]*>",
3750         .tokens = {
3751                 (void *)&cmd_set_list_keyword,
3752                 (void *)&cmd_set_list_name,
3753                 (void *)&cmd_set_list_of_items,
3754                 NULL,
3755         },
3756 };
3757
3758 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3759
3760 struct cmd_setmask_result {
3761         cmdline_fixed_string_t set;
3762         cmdline_fixed_string_t mask;
3763         uint64_t hexavalue;
3764 };
3765
3766 static void cmd_set_mask_parsed(void *parsed_result,
3767                                 __rte_unused struct cmdline *cl,
3768                                 __rte_unused void *data)
3769 {
3770         struct cmd_setmask_result *res = parsed_result;
3771
3772         if (test_done == 0) {
3773                 fprintf(stderr, "Please stop forwarding first\n");
3774                 return;
3775         }
3776         if (!strcmp(res->mask, "coremask")) {
3777                 set_fwd_lcores_mask(res->hexavalue);
3778                 fwd_config_setup();
3779         } else if (!strcmp(res->mask, "portmask")) {
3780                 set_fwd_ports_mask(res->hexavalue);
3781                 fwd_config_setup();
3782         }
3783 }
3784
3785 cmdline_parse_token_string_t cmd_setmask_set =
3786         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3787 cmdline_parse_token_string_t cmd_setmask_mask =
3788         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3789                                  "coremask#portmask");
3790 cmdline_parse_token_num_t cmd_setmask_value =
3791         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3792
3793 cmdline_parse_inst_t cmd_set_fwd_mask = {
3794         .f = cmd_set_mask_parsed,
3795         .data = NULL,
3796         .help_str = "set coremask|portmask <hexadecimal value>",
3797         .tokens = {
3798                 (void *)&cmd_setmask_set,
3799                 (void *)&cmd_setmask_mask,
3800                 (void *)&cmd_setmask_value,
3801                 NULL,
3802         },
3803 };
3804
3805 /*
3806  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3807  */
3808 struct cmd_set_result {
3809         cmdline_fixed_string_t set;
3810         cmdline_fixed_string_t what;
3811         uint16_t value;
3812 };
3813
3814 static void cmd_set_parsed(void *parsed_result,
3815                            __rte_unused struct cmdline *cl,
3816                            __rte_unused void *data)
3817 {
3818         struct cmd_set_result *res = parsed_result;
3819         if (!strcmp(res->what, "nbport")) {
3820                 set_fwd_ports_number(res->value);
3821                 fwd_config_setup();
3822         } else if (!strcmp(res->what, "nbcore")) {
3823                 set_fwd_lcores_number(res->value);
3824                 fwd_config_setup();
3825         } else if (!strcmp(res->what, "burst"))
3826                 set_nb_pkt_per_burst(res->value);
3827         else if (!strcmp(res->what, "verbose"))
3828                 set_verbose_level(res->value);
3829 }
3830
3831 cmdline_parse_token_string_t cmd_set_set =
3832         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3833 cmdline_parse_token_string_t cmd_set_what =
3834         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3835                                  "nbport#nbcore#burst#verbose");
3836 cmdline_parse_token_num_t cmd_set_value =
3837         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3838
3839 cmdline_parse_inst_t cmd_set_numbers = {
3840         .f = cmd_set_parsed,
3841         .data = NULL,
3842         .help_str = "set nbport|nbcore|burst|verbose <value>",
3843         .tokens = {
3844                 (void *)&cmd_set_set,
3845                 (void *)&cmd_set_what,
3846                 (void *)&cmd_set_value,
3847                 NULL,
3848         },
3849 };
3850
3851 /* *** SET LOG LEVEL CONFIGURATION *** */
3852
3853 struct cmd_set_log_result {
3854         cmdline_fixed_string_t set;
3855         cmdline_fixed_string_t log;
3856         cmdline_fixed_string_t type;
3857         uint32_t level;
3858 };
3859
3860 static void
3861 cmd_set_log_parsed(void *parsed_result,
3862                    __rte_unused struct cmdline *cl,
3863                    __rte_unused void *data)
3864 {
3865         struct cmd_set_log_result *res;
3866         int ret;
3867
3868         res = parsed_result;
3869         if (!strcmp(res->type, "global"))
3870                 rte_log_set_global_level(res->level);
3871         else {
3872                 ret = rte_log_set_level_regexp(res->type, res->level);
3873                 if (ret < 0)
3874                         fprintf(stderr, "Unable to set log level\n");
3875         }
3876 }
3877
3878 cmdline_parse_token_string_t cmd_set_log_set =
3879         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3880 cmdline_parse_token_string_t cmd_set_log_log =
3881         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3882 cmdline_parse_token_string_t cmd_set_log_type =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3884 cmdline_parse_token_num_t cmd_set_log_level =
3885         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3886
3887 cmdline_parse_inst_t cmd_set_log = {
3888         .f = cmd_set_log_parsed,
3889         .data = NULL,
3890         .help_str = "set log global|<type> <level>",
3891         .tokens = {
3892                 (void *)&cmd_set_log_set,
3893                 (void *)&cmd_set_log_log,
3894                 (void *)&cmd_set_log_type,
3895                 (void *)&cmd_set_log_level,
3896                 NULL,
3897         },
3898 };
3899
3900 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3901
3902 struct cmd_set_rxoffs_result {
3903         cmdline_fixed_string_t cmd_keyword;
3904         cmdline_fixed_string_t rxoffs;
3905         cmdline_fixed_string_t seg_offsets;
3906 };
3907
3908 static void
3909 cmd_set_rxoffs_parsed(void *parsed_result,
3910                       __rte_unused struct cmdline *cl,
3911                       __rte_unused void *data)
3912 {
3913         struct cmd_set_rxoffs_result *res;
3914         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3915         unsigned int nb_segs;
3916
3917         res = parsed_result;
3918         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3919                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3920         if (nb_segs > 0)
3921                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3922         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3923 }
3924
3925 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3926         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3927                                  cmd_keyword, "set");
3928 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3929         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3930                                  rxoffs, "rxoffs");
3931 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3932         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3933                                  seg_offsets, NULL);
3934
3935 cmdline_parse_inst_t cmd_set_rxoffs = {
3936         .f = cmd_set_rxoffs_parsed,
3937         .data = NULL,
3938         .help_str = "set rxoffs <len0[,len1]*>",
3939         .tokens = {
3940                 (void *)&cmd_set_rxoffs_keyword,
3941                 (void *)&cmd_set_rxoffs_name,
3942                 (void *)&cmd_set_rxoffs_offsets,
3943                 NULL,
3944         },
3945 };
3946
3947 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3948
3949 struct cmd_set_rxpkts_result {
3950         cmdline_fixed_string_t cmd_keyword;
3951         cmdline_fixed_string_t rxpkts;
3952         cmdline_fixed_string_t seg_lengths;
3953 };
3954
3955 static void
3956 cmd_set_rxpkts_parsed(void *parsed_result,
3957                       __rte_unused struct cmdline *cl,
3958                       __rte_unused void *data)
3959 {
3960         struct cmd_set_rxpkts_result *res;
3961         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3962         unsigned int nb_segs;
3963
3964         res = parsed_result;
3965         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3966                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3967         if (nb_segs > 0)
3968                 set_rx_pkt_segments(seg_lengths, nb_segs);
3969         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3970 }
3971
3972 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3973         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3974                                  cmd_keyword, "set");
3975 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3976         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3977                                  rxpkts, "rxpkts");
3978 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3979         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3980                                  seg_lengths, NULL);
3981
3982 cmdline_parse_inst_t cmd_set_rxpkts = {
3983         .f = cmd_set_rxpkts_parsed,
3984         .data = NULL,
3985         .help_str = "set rxpkts <len0[,len1]*>",
3986         .tokens = {
3987                 (void *)&cmd_set_rxpkts_keyword,
3988                 (void *)&cmd_set_rxpkts_name,
3989                 (void *)&cmd_set_rxpkts_lengths,
3990                 NULL,
3991         },
3992 };
3993
3994 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3995
3996 struct cmd_set_txpkts_result {
3997         cmdline_fixed_string_t cmd_keyword;
3998         cmdline_fixed_string_t txpkts;
3999         cmdline_fixed_string_t seg_lengths;
4000 };
4001
4002 static void
4003 cmd_set_txpkts_parsed(void *parsed_result,
4004                       __rte_unused struct cmdline *cl,
4005                       __rte_unused void *data)
4006 {
4007         struct cmd_set_txpkts_result *res;
4008         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4009         unsigned int nb_segs;
4010
4011         res = parsed_result;
4012         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4013                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4014         if (nb_segs > 0)
4015                 set_tx_pkt_segments(seg_lengths, nb_segs);
4016 }
4017
4018 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4019         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4020                                  cmd_keyword, "set");
4021 cmdline_parse_token_string_t cmd_set_txpkts_name =
4022         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4023                                  txpkts, "txpkts");
4024 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4025         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4026                                  seg_lengths, NULL);
4027
4028 cmdline_parse_inst_t cmd_set_txpkts = {
4029         .f = cmd_set_txpkts_parsed,
4030         .data = NULL,
4031         .help_str = "set txpkts <len0[,len1]*>",
4032         .tokens = {
4033                 (void *)&cmd_set_txpkts_keyword,
4034                 (void *)&cmd_set_txpkts_name,
4035                 (void *)&cmd_set_txpkts_lengths,
4036                 NULL,
4037         },
4038 };
4039
4040 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4041
4042 struct cmd_set_txsplit_result {
4043         cmdline_fixed_string_t cmd_keyword;
4044         cmdline_fixed_string_t txsplit;
4045         cmdline_fixed_string_t mode;
4046 };
4047
4048 static void
4049 cmd_set_txsplit_parsed(void *parsed_result,
4050                       __rte_unused struct cmdline *cl,
4051                       __rte_unused void *data)
4052 {
4053         struct cmd_set_txsplit_result *res;
4054
4055         res = parsed_result;
4056         set_tx_pkt_split(res->mode);
4057 }
4058
4059 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4060         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4061                                  cmd_keyword, "set");
4062 cmdline_parse_token_string_t cmd_set_txsplit_name =
4063         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4064                                  txsplit, "txsplit");
4065 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4066         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4067                                  mode, NULL);
4068
4069 cmdline_parse_inst_t cmd_set_txsplit = {
4070         .f = cmd_set_txsplit_parsed,
4071         .data = NULL,
4072         .help_str = "set txsplit on|off|rand",
4073         .tokens = {
4074                 (void *)&cmd_set_txsplit_keyword,
4075                 (void *)&cmd_set_txsplit_name,
4076                 (void *)&cmd_set_txsplit_mode,
4077                 NULL,
4078         },
4079 };
4080
4081 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4082
4083 struct cmd_set_txtimes_result {
4084         cmdline_fixed_string_t cmd_keyword;
4085         cmdline_fixed_string_t txtimes;
4086         cmdline_fixed_string_t tx_times;
4087 };
4088
4089 static void
4090 cmd_set_txtimes_parsed(void *parsed_result,
4091                        __rte_unused struct cmdline *cl,
4092                        __rte_unused void *data)
4093 {
4094         struct cmd_set_txtimes_result *res;
4095         unsigned int tx_times[2] = {0, 0};
4096         unsigned int n_times;
4097
4098         res = parsed_result;
4099         n_times = parse_item_list(res->tx_times, "tx times",
4100                                   2, tx_times, 0);
4101         if (n_times == 2)
4102                 set_tx_pkt_times(tx_times);
4103 }
4104
4105 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4106         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4107                                  cmd_keyword, "set");
4108 cmdline_parse_token_string_t cmd_set_txtimes_name =
4109         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4110                                  txtimes, "txtimes");
4111 cmdline_parse_token_string_t cmd_set_txtimes_value =
4112         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4113                                  tx_times, NULL);
4114
4115 cmdline_parse_inst_t cmd_set_txtimes = {
4116         .f = cmd_set_txtimes_parsed,
4117         .data = NULL,
4118         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4119         .tokens = {
4120                 (void *)&cmd_set_txtimes_keyword,
4121                 (void *)&cmd_set_txtimes_name,
4122                 (void *)&cmd_set_txtimes_value,
4123                 NULL,
4124         },
4125 };
4126
4127 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4128 struct cmd_rx_vlan_filter_all_result {
4129         cmdline_fixed_string_t rx_vlan;
4130         cmdline_fixed_string_t what;
4131         cmdline_fixed_string_t all;
4132         portid_t port_id;
4133 };
4134
4135 static void
4136 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4137                               __rte_unused struct cmdline *cl,
4138                               __rte_unused void *data)
4139 {
4140         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4141
4142         if (!strcmp(res->what, "add"))
4143                 rx_vlan_all_filter_set(res->port_id, 1);
4144         else
4145                 rx_vlan_all_filter_set(res->port_id, 0);
4146 }
4147
4148 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4149         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4150                                  rx_vlan, "rx_vlan");
4151 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4152         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4153                                  what, "add#rm");
4154 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4155         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4156                                  all, "all");
4157 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4158         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4159                               port_id, RTE_UINT16);
4160
4161 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4162         .f = cmd_rx_vlan_filter_all_parsed,
4163         .data = NULL,
4164         .help_str = "rx_vlan add|rm all <port_id>: "
4165                 "Add/Remove all identifiers to/from the set of VLAN "
4166                 "identifiers filtered by a port",
4167         .tokens = {
4168                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4169                 (void *)&cmd_rx_vlan_filter_all_what,
4170                 (void *)&cmd_rx_vlan_filter_all_all,
4171                 (void *)&cmd_rx_vlan_filter_all_portid,
4172                 NULL,
4173         },
4174 };
4175
4176 /* *** VLAN OFFLOAD SET ON A PORT *** */
4177 struct cmd_vlan_offload_result {
4178         cmdline_fixed_string_t vlan;
4179         cmdline_fixed_string_t set;
4180         cmdline_fixed_string_t vlan_type;
4181         cmdline_fixed_string_t what;
4182         cmdline_fixed_string_t on;
4183         cmdline_fixed_string_t port_id;
4184 };
4185
4186 static void
4187 cmd_vlan_offload_parsed(void *parsed_result,
4188                           __rte_unused struct cmdline *cl,
4189                           __rte_unused void *data)
4190 {
4191         int on;
4192         struct cmd_vlan_offload_result *res = parsed_result;
4193         char *str;
4194         int i, len = 0;
4195         portid_t port_id = 0;
4196         unsigned int tmp;
4197
4198         str = res->port_id;
4199         len = strnlen(str, STR_TOKEN_SIZE);
4200         i = 0;
4201         /* Get port_id first */
4202         while(i < len){
4203                 if(str[i] == ',')
4204                         break;
4205
4206                 i++;
4207         }
4208         str[i]='\0';
4209         tmp = strtoul(str, NULL, 0);
4210         /* If port_id greater that what portid_t can represent, return */
4211         if(tmp >= RTE_MAX_ETHPORTS)
4212                 return;
4213         port_id = (portid_t)tmp;
4214
4215         if (!strcmp(res->on, "on"))
4216                 on = 1;
4217         else
4218                 on = 0;
4219
4220         if (!strcmp(res->what, "strip"))
4221                 rx_vlan_strip_set(port_id,  on);
4222         else if(!strcmp(res->what, "stripq")){
4223                 uint16_t queue_id = 0;
4224
4225                 /* No queue_id, return */
4226                 if(i + 1 >= len) {
4227                         fprintf(stderr, "must specify (port,queue_id)\n");
4228                         return;
4229                 }
4230                 tmp = strtoul(str + i + 1, NULL, 0);
4231                 /* If queue_id greater that what 16-bits can represent, return */
4232                 if(tmp > 0xffff)
4233                         return;
4234
4235                 queue_id = (uint16_t)tmp;
4236                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4237         }
4238         else if (!strcmp(res->what, "filter"))
4239                 rx_vlan_filter_set(port_id, on);
4240         else if (!strcmp(res->what, "qinq_strip"))
4241                 rx_vlan_qinq_strip_set(port_id, on);
4242         else
4243                 vlan_extend_set(port_id, on);
4244
4245         return;
4246 }
4247
4248 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4249         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4250                                  vlan, "vlan");
4251 cmdline_parse_token_string_t cmd_vlan_offload_set =
4252         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4253                                  set, "set");
4254 cmdline_parse_token_string_t cmd_vlan_offload_what =
4255         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4256                                 what, "strip#filter#qinq_strip#extend#stripq");
4257 cmdline_parse_token_string_t cmd_vlan_offload_on =
4258         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4259                               on, "on#off");
4260 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4261         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4262                               port_id, NULL);
4263
4264 cmdline_parse_inst_t cmd_vlan_offload = {
4265         .f = cmd_vlan_offload_parsed,
4266         .data = NULL,
4267         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4268                 "<port_id[,queue_id]>: "
4269                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4270         .tokens = {
4271                 (void *)&cmd_vlan_offload_vlan,
4272                 (void *)&cmd_vlan_offload_set,
4273                 (void *)&cmd_vlan_offload_what,
4274                 (void *)&cmd_vlan_offload_on,
4275                 (void *)&cmd_vlan_offload_portid,
4276                 NULL,
4277         },
4278 };
4279
4280 /* *** VLAN TPID SET ON A PORT *** */
4281 struct cmd_vlan_tpid_result {
4282         cmdline_fixed_string_t vlan;
4283         cmdline_fixed_string_t set;
4284         cmdline_fixed_string_t vlan_type;
4285         cmdline_fixed_string_t what;
4286         uint16_t tp_id;
4287         portid_t port_id;
4288 };
4289
4290 static void
4291 cmd_vlan_tpid_parsed(void *parsed_result,
4292                           __rte_unused struct cmdline *cl,
4293                           __rte_unused void *data)
4294 {
4295         struct cmd_vlan_tpid_result *res = parsed_result;
4296         enum rte_vlan_type vlan_type;
4297
4298         if (!strcmp(res->vlan_type, "inner"))
4299                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4300         else if (!strcmp(res->vlan_type, "outer"))
4301                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4302         else {
4303                 fprintf(stderr, "Unknown vlan type\n");
4304                 return;
4305         }
4306         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4307 }
4308
4309 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4310         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4311                                  vlan, "vlan");
4312 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4313         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4314                                  set, "set");
4315 cmdline_parse_token_string_t cmd_vlan_type =
4316         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4317                                  vlan_type, "inner#outer");
4318 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4319         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4320                                  what, "tpid");
4321 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4322         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4323                               tp_id, RTE_UINT16);
4324 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4325         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4326                               port_id, RTE_UINT16);
4327
4328 cmdline_parse_inst_t cmd_vlan_tpid = {
4329         .f = cmd_vlan_tpid_parsed,
4330         .data = NULL,
4331         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4332                 "Set the VLAN Ether type",
4333         .tokens = {
4334                 (void *)&cmd_vlan_tpid_vlan,
4335                 (void *)&cmd_vlan_tpid_set,
4336                 (void *)&cmd_vlan_type,
4337                 (void *)&cmd_vlan_tpid_what,
4338                 (void *)&cmd_vlan_tpid_tpid,
4339                 (void *)&cmd_vlan_tpid_portid,
4340                 NULL,
4341         },
4342 };
4343
4344 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4345 struct cmd_rx_vlan_filter_result {
4346         cmdline_fixed_string_t rx_vlan;
4347         cmdline_fixed_string_t what;
4348         uint16_t vlan_id;
4349         portid_t port_id;
4350 };
4351
4352 static void
4353 cmd_rx_vlan_filter_parsed(void *parsed_result,
4354                           __rte_unused struct cmdline *cl,
4355                           __rte_unused void *data)
4356 {
4357         struct cmd_rx_vlan_filter_result *res = parsed_result;
4358
4359         if (!strcmp(res->what, "add"))
4360                 rx_vft_set(res->port_id, res->vlan_id, 1);
4361         else
4362                 rx_vft_set(res->port_id, res->vlan_id, 0);
4363 }
4364
4365 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4366         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4367                                  rx_vlan, "rx_vlan");
4368 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4369         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4370                                  what, "add#rm");
4371 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4372         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4373                               vlan_id, RTE_UINT16);
4374 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4375         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4376                               port_id, RTE_UINT16);
4377
4378 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4379         .f = cmd_rx_vlan_filter_parsed,
4380         .data = NULL,
4381         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4382                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4383                 "identifiers filtered by a port",
4384         .tokens = {
4385                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4386                 (void *)&cmd_rx_vlan_filter_what,
4387                 (void *)&cmd_rx_vlan_filter_vlanid,
4388                 (void *)&cmd_rx_vlan_filter_portid,
4389                 NULL,
4390         },
4391 };
4392
4393 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4394 struct cmd_tx_vlan_set_result {
4395         cmdline_fixed_string_t tx_vlan;
4396         cmdline_fixed_string_t set;
4397         portid_t port_id;
4398         uint16_t vlan_id;
4399 };
4400
4401 static void
4402 cmd_tx_vlan_set_parsed(void *parsed_result,
4403                        __rte_unused struct cmdline *cl,
4404                        __rte_unused void *data)
4405 {
4406         struct cmd_tx_vlan_set_result *res = parsed_result;
4407
4408         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4409                 return;
4410
4411         if (!port_is_stopped(res->port_id)) {
4412                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4413                 return;
4414         }
4415
4416         tx_vlan_set(res->port_id, res->vlan_id);
4417
4418         cmd_reconfig_device_queue(res->port_id, 1, 1);
4419 }
4420
4421 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4422         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4423                                  tx_vlan, "tx_vlan");
4424 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4425         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4426                                  set, "set");
4427 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4428         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4429                               port_id, RTE_UINT16);
4430 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4431         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4432                               vlan_id, RTE_UINT16);
4433
4434 cmdline_parse_inst_t cmd_tx_vlan_set = {
4435         .f = cmd_tx_vlan_set_parsed,
4436         .data = NULL,
4437         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4438                 "Enable hardware insertion of a single VLAN header "
4439                 "with a given TAG Identifier in packets sent on a port",
4440         .tokens = {
4441                 (void *)&cmd_tx_vlan_set_tx_vlan,
4442                 (void *)&cmd_tx_vlan_set_set,
4443                 (void *)&cmd_tx_vlan_set_portid,
4444                 (void *)&cmd_tx_vlan_set_vlanid,
4445                 NULL,
4446         },
4447 };
4448
4449 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4450 struct cmd_tx_vlan_set_qinq_result {
4451         cmdline_fixed_string_t tx_vlan;
4452         cmdline_fixed_string_t set;
4453         portid_t port_id;
4454         uint16_t vlan_id;
4455         uint16_t vlan_id_outer;
4456 };
4457
4458 static void
4459 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4460                             __rte_unused struct cmdline *cl,
4461                             __rte_unused void *data)
4462 {
4463         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4464
4465         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4466                 return;
4467
4468         if (!port_is_stopped(res->port_id)) {
4469                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4470                 return;
4471         }
4472
4473         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4474
4475         cmd_reconfig_device_queue(res->port_id, 1, 1);
4476 }
4477
4478 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4479         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4480                 tx_vlan, "tx_vlan");
4481 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4482         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4483                 set, "set");
4484 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4485         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4486                 port_id, RTE_UINT16);
4487 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4488         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4489                 vlan_id, RTE_UINT16);
4490 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4491         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4492                 vlan_id_outer, RTE_UINT16);
4493
4494 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4495         .f = cmd_tx_vlan_set_qinq_parsed,
4496         .data = NULL,
4497         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4498                 "Enable hardware insertion of double VLAN header "
4499                 "with given TAG Identifiers in packets sent on a port",
4500         .tokens = {
4501                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4502                 (void *)&cmd_tx_vlan_set_qinq_set,
4503                 (void *)&cmd_tx_vlan_set_qinq_portid,
4504                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4505                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4506                 NULL,
4507         },
4508 };
4509
4510 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4511 struct cmd_tx_vlan_set_pvid_result {
4512         cmdline_fixed_string_t tx_vlan;
4513         cmdline_fixed_string_t set;
4514         cmdline_fixed_string_t pvid;
4515         portid_t port_id;
4516         uint16_t vlan_id;
4517         cmdline_fixed_string_t mode;
4518 };
4519
4520 static void
4521 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4522                             __rte_unused struct cmdline *cl,
4523                             __rte_unused void *data)
4524 {
4525         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4526
4527         if (strcmp(res->mode, "on") == 0)
4528                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4529         else
4530                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4531 }
4532
4533 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4534         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4535                                  tx_vlan, "tx_vlan");
4536 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4537         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4538                                  set, "set");
4539 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4540         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4541                                  pvid, "pvid");
4542 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4543         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4544                              port_id, RTE_UINT16);
4545 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4546         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4547                               vlan_id, RTE_UINT16);
4548 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4549         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4550                                  mode, "on#off");
4551
4552 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4553         .f = cmd_tx_vlan_set_pvid_parsed,
4554         .data = NULL,
4555         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4556         .tokens = {
4557                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4558                 (void *)&cmd_tx_vlan_set_pvid_set,
4559                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4560                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4561                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4562                 (void *)&cmd_tx_vlan_set_pvid_mode,
4563                 NULL,
4564         },
4565 };
4566
4567 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4568 struct cmd_tx_vlan_reset_result {
4569         cmdline_fixed_string_t tx_vlan;
4570         cmdline_fixed_string_t reset;
4571         portid_t port_id;
4572 };
4573
4574 static void
4575 cmd_tx_vlan_reset_parsed(void *parsed_result,
4576                          __rte_unused struct cmdline *cl,
4577                          __rte_unused void *data)
4578 {
4579         struct cmd_tx_vlan_reset_result *res = parsed_result;
4580
4581         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4582                 return;
4583
4584         if (!port_is_stopped(res->port_id)) {
4585                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4586                 return;
4587         }
4588
4589         tx_vlan_reset(res->port_id);
4590
4591         cmd_reconfig_device_queue(res->port_id, 1, 1);
4592 }
4593
4594 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4595         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4596                                  tx_vlan, "tx_vlan");
4597 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4598         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4599                                  reset, "reset");
4600 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4601         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4602                               port_id, RTE_UINT16);
4603
4604 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4605         .f = cmd_tx_vlan_reset_parsed,
4606         .data = NULL,
4607         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4608                 "VLAN header in packets sent on a port",
4609         .tokens = {
4610                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4611                 (void *)&cmd_tx_vlan_reset_reset,
4612                 (void *)&cmd_tx_vlan_reset_portid,
4613                 NULL,
4614         },
4615 };
4616
4617
4618 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4619 struct cmd_csum_result {
4620         cmdline_fixed_string_t csum;
4621         cmdline_fixed_string_t mode;
4622         cmdline_fixed_string_t proto;
4623         cmdline_fixed_string_t hwsw;
4624         portid_t port_id;
4625 };
4626
4627 static void
4628 csum_show(int port_id)
4629 {
4630         struct rte_eth_dev_info dev_info;
4631         uint64_t tx_offloads;
4632         int ret;
4633
4634         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4635         printf("Parse tunnel is %s\n",
4636                 (ports[port_id].parse_tunnel) ? "on" : "off");
4637         printf("IP checksum offload is %s\n",
4638                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4639         printf("UDP checksum offload is %s\n",
4640                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4641         printf("TCP checksum offload is %s\n",
4642                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4643         printf("SCTP checksum offload is %s\n",
4644                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4645         printf("Outer-Ip checksum offload is %s\n",
4646                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4647         printf("Outer-Udp checksum offload is %s\n",
4648                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4649
4650         /* display warnings if configuration is not supported by the NIC */
4651         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4652         if (ret != 0)
4653                 return;
4654
4655         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4656                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4657                 fprintf(stderr,
4658                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4659                         port_id);
4660         }
4661         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4662                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4663                 fprintf(stderr,
4664                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4665                         port_id);
4666         }
4667         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4668                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4669                 fprintf(stderr,
4670                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4671                         port_id);
4672         }
4673         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4674                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4675                 fprintf(stderr,
4676                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4677                         port_id);
4678         }
4679         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4680                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4681                 fprintf(stderr,
4682                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4683                         port_id);
4684         }
4685         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4686                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4687                         == 0) {
4688                 fprintf(stderr,
4689                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4690                         port_id);
4691         }
4692 }
4693
4694 static void
4695 cmd_config_queue_tx_offloads(struct rte_port *port)
4696 {
4697         int k;
4698
4699         /* Apply queue tx offloads configuration */
4700         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4701                 port->txq[k].conf.offloads =
4702                         port->dev_conf.txmode.offloads;
4703 }
4704
4705 static void
4706 cmd_csum_parsed(void *parsed_result,
4707                        __rte_unused struct cmdline *cl,
4708                        __rte_unused void *data)
4709 {
4710         struct cmd_csum_result *res = parsed_result;
4711         int hw = 0;
4712         uint64_t csum_offloads = 0;
4713         struct rte_eth_dev_info dev_info;
4714         int ret;
4715
4716         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4717                 fprintf(stderr, "invalid port %d\n", res->port_id);
4718                 return;
4719         }
4720         if (!port_is_stopped(res->port_id)) {
4721                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4722                 return;
4723         }
4724
4725         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4726         if (ret != 0)
4727                 return;
4728
4729         if (!strcmp(res->mode, "set")) {
4730
4731                 if (!strcmp(res->hwsw, "hw"))
4732                         hw = 1;
4733
4734                 if (!strcmp(res->proto, "ip")) {
4735                         if (hw == 0 || (dev_info.tx_offload_capa &
4736                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4737                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4738                         } else {
4739                                 fprintf(stderr,
4740                                         "IP checksum offload is not supported by port %u\n",
4741                                         res->port_id);
4742                         }
4743                 } else if (!strcmp(res->proto, "udp")) {
4744                         if (hw == 0 || (dev_info.tx_offload_capa &
4745                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4746                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4747                         } else {
4748                                 fprintf(stderr,
4749                                         "UDP checksum offload is not supported by port %u\n",
4750                                         res->port_id);
4751                         }
4752                 } else if (!strcmp(res->proto, "tcp")) {
4753                         if (hw == 0 || (dev_info.tx_offload_capa &
4754                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4755                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4756                         } else {
4757                                 fprintf(stderr,
4758                                         "TCP checksum offload is not supported by port %u\n",
4759                                         res->port_id);
4760                         }
4761                 } else if (!strcmp(res->proto, "sctp")) {
4762                         if (hw == 0 || (dev_info.tx_offload_capa &
4763                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4764                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4765                         } else {
4766                                 fprintf(stderr,
4767                                         "SCTP checksum offload is not supported by port %u\n",
4768                                         res->port_id);
4769                         }
4770                 } else if (!strcmp(res->proto, "outer-ip")) {
4771                         if (hw == 0 || (dev_info.tx_offload_capa &
4772                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4773                                 csum_offloads |=
4774                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4775                         } else {
4776                                 fprintf(stderr,
4777                                         "Outer IP checksum offload is not supported by port %u\n",
4778                                         res->port_id);
4779                         }
4780                 } else if (!strcmp(res->proto, "outer-udp")) {
4781                         if (hw == 0 || (dev_info.tx_offload_capa &
4782                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4783                                 csum_offloads |=
4784                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4785                         } else {
4786                                 fprintf(stderr,
4787                                         "Outer UDP checksum offload is not supported by port %u\n",
4788                                         res->port_id);
4789                         }
4790                 }
4791
4792                 if (hw) {
4793                         ports[res->port_id].dev_conf.txmode.offloads |=
4794                                                         csum_offloads;
4795                 } else {
4796                         ports[res->port_id].dev_conf.txmode.offloads &=
4797                                                         (~csum_offloads);
4798                 }
4799                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4800         }
4801         csum_show(res->port_id);
4802
4803         cmd_reconfig_device_queue(res->port_id, 1, 1);
4804 }
4805
4806 cmdline_parse_token_string_t cmd_csum_csum =
4807         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4808                                 csum, "csum");
4809 cmdline_parse_token_string_t cmd_csum_mode =
4810         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4811                                 mode, "set");
4812 cmdline_parse_token_string_t cmd_csum_proto =
4813         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4814                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4815 cmdline_parse_token_string_t cmd_csum_hwsw =
4816         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4817                                 hwsw, "hw#sw");
4818 cmdline_parse_token_num_t cmd_csum_portid =
4819         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4820                                 port_id, RTE_UINT16);
4821
4822 cmdline_parse_inst_t cmd_csum_set = {
4823         .f = cmd_csum_parsed,
4824         .data = NULL,
4825         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4826                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4827                 "using csum forward engine",
4828         .tokens = {
4829                 (void *)&cmd_csum_csum,
4830                 (void *)&cmd_csum_mode,
4831                 (void *)&cmd_csum_proto,
4832                 (void *)&cmd_csum_hwsw,
4833                 (void *)&cmd_csum_portid,
4834                 NULL,
4835         },
4836 };
4837
4838 cmdline_parse_token_string_t cmd_csum_mode_show =
4839         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4840                                 mode, "show");
4841
4842 cmdline_parse_inst_t cmd_csum_show = {
4843         .f = cmd_csum_parsed,
4844         .data = NULL,
4845         .help_str = "csum show <port_id>: Show checksum offload configuration",
4846         .tokens = {
4847                 (void *)&cmd_csum_csum,
4848                 (void *)&cmd_csum_mode_show,
4849                 (void *)&cmd_csum_portid,
4850                 NULL,
4851         },
4852 };
4853
4854 /* Enable/disable tunnel parsing */
4855 struct cmd_csum_tunnel_result {
4856         cmdline_fixed_string_t csum;
4857         cmdline_fixed_string_t parse;
4858         cmdline_fixed_string_t onoff;
4859         portid_t port_id;
4860 };
4861
4862 static void
4863 cmd_csum_tunnel_parsed(void *parsed_result,
4864                        __rte_unused struct cmdline *cl,
4865                        __rte_unused void *data)
4866 {
4867         struct cmd_csum_tunnel_result *res = parsed_result;
4868
4869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4870                 return;
4871
4872         if (!strcmp(res->onoff, "on"))
4873                 ports[res->port_id].parse_tunnel = 1;
4874         else
4875                 ports[res->port_id].parse_tunnel = 0;
4876
4877         csum_show(res->port_id);
4878 }
4879
4880 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4881         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4882                                 csum, "csum");
4883 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4884         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4885                                 parse, "parse-tunnel");
4886 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4887         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4888                                 onoff, "on#off");
4889 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4890         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4891                                 port_id, RTE_UINT16);
4892
4893 cmdline_parse_inst_t cmd_csum_tunnel = {
4894         .f = cmd_csum_tunnel_parsed,
4895         .data = NULL,
4896         .help_str = "csum parse-tunnel on|off <port_id>: "
4897                 "Enable/Disable parsing of tunnels for csum engine",
4898         .tokens = {
4899                 (void *)&cmd_csum_tunnel_csum,
4900                 (void *)&cmd_csum_tunnel_parse,
4901                 (void *)&cmd_csum_tunnel_onoff,
4902                 (void *)&cmd_csum_tunnel_portid,
4903                 NULL,
4904         },
4905 };
4906
4907 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4908 struct cmd_tso_set_result {
4909         cmdline_fixed_string_t tso;
4910         cmdline_fixed_string_t mode;
4911         uint16_t tso_segsz;
4912         portid_t port_id;
4913 };
4914
4915 static void
4916 cmd_tso_set_parsed(void *parsed_result,
4917                        __rte_unused struct cmdline *cl,
4918                        __rte_unused void *data)
4919 {
4920         struct cmd_tso_set_result *res = parsed_result;
4921         struct rte_eth_dev_info dev_info;
4922         int ret;
4923
4924         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4925                 return;
4926         if (!port_is_stopped(res->port_id)) {
4927                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4928                 return;
4929         }
4930
4931         if (!strcmp(res->mode, "set"))
4932                 ports[res->port_id].tso_segsz = res->tso_segsz;
4933
4934         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4935         if (ret != 0)
4936                 return;
4937
4938         if ((ports[res->port_id].tso_segsz != 0) &&
4939                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4940                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4941                         res->port_id);
4942                 return;
4943         }
4944
4945         if (ports[res->port_id].tso_segsz == 0) {
4946                 ports[res->port_id].dev_conf.txmode.offloads &=
4947                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4948                 printf("TSO for non-tunneled packets is disabled\n");
4949         } else {
4950                 ports[res->port_id].dev_conf.txmode.offloads |=
4951                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4952                 printf("TSO segment size for non-tunneled packets is %d\n",
4953                         ports[res->port_id].tso_segsz);
4954         }
4955         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4956
4957         /* display warnings if configuration is not supported by the NIC */
4958         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4959         if (ret != 0)
4960                 return;
4961
4962         if ((ports[res->port_id].tso_segsz != 0) &&
4963                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4964                 fprintf(stderr,
4965                         "Warning: TSO enabled but not supported by port %d\n",
4966                         res->port_id);
4967         }
4968
4969         cmd_reconfig_device_queue(res->port_id, 1, 1);
4970 }
4971
4972 cmdline_parse_token_string_t cmd_tso_set_tso =
4973         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4974                                 tso, "tso");
4975 cmdline_parse_token_string_t cmd_tso_set_mode =
4976         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4977                                 mode, "set");
4978 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4979         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4980                                 tso_segsz, RTE_UINT16);
4981 cmdline_parse_token_num_t cmd_tso_set_portid =
4982         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4983                                 port_id, RTE_UINT16);
4984
4985 cmdline_parse_inst_t cmd_tso_set = {
4986         .f = cmd_tso_set_parsed,
4987         .data = NULL,
4988         .help_str = "tso set <tso_segsz> <port_id>: "
4989                 "Set TSO segment size of non-tunneled packets for csum engine "
4990                 "(0 to disable)",
4991         .tokens = {
4992                 (void *)&cmd_tso_set_tso,
4993                 (void *)&cmd_tso_set_mode,
4994                 (void *)&cmd_tso_set_tso_segsz,
4995                 (void *)&cmd_tso_set_portid,
4996                 NULL,
4997         },
4998 };
4999
5000 cmdline_parse_token_string_t cmd_tso_show_mode =
5001         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
5002                                 mode, "show");
5003
5004
5005 cmdline_parse_inst_t cmd_tso_show = {
5006         .f = cmd_tso_set_parsed,
5007         .data = NULL,
5008         .help_str = "tso show <port_id>: "
5009                 "Show TSO segment size of non-tunneled packets for csum engine",
5010         .tokens = {
5011                 (void *)&cmd_tso_set_tso,
5012                 (void *)&cmd_tso_show_mode,
5013                 (void *)&cmd_tso_set_portid,
5014                 NULL,
5015         },
5016 };
5017
5018 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5019 struct cmd_tunnel_tso_set_result {
5020         cmdline_fixed_string_t tso;
5021         cmdline_fixed_string_t mode;
5022         uint16_t tso_segsz;
5023         portid_t port_id;
5024 };
5025
5026 static struct rte_eth_dev_info
5027 check_tunnel_tso_nic_support(portid_t port_id)
5028 {
5029         struct rte_eth_dev_info dev_info;
5030
5031         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5032                 return dev_info;
5033
5034         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5035                 fprintf(stderr,
5036                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5037                         port_id);
5038         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5039                 fprintf(stderr,
5040                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5041                         port_id);
5042         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5043                 fprintf(stderr,
5044                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5045                         port_id);
5046         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5047                 fprintf(stderr,
5048                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5049                         port_id);
5050         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5051                 fprintf(stderr,
5052                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5053                         port_id);
5054         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5055                 fprintf(stderr,
5056                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5057                         port_id);
5058         return dev_info;
5059 }
5060
5061 static void
5062 cmd_tunnel_tso_set_parsed(void *parsed_result,
5063                           __rte_unused struct cmdline *cl,
5064                           __rte_unused void *data)
5065 {
5066         struct cmd_tunnel_tso_set_result *res = parsed_result;
5067         struct rte_eth_dev_info dev_info;
5068
5069         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5070                 return;
5071         if (!port_is_stopped(res->port_id)) {
5072                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5073                 return;
5074         }
5075
5076         if (!strcmp(res->mode, "set"))
5077                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5078
5079         dev_info = check_tunnel_tso_nic_support(res->port_id);
5080         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5081                 ports[res->port_id].dev_conf.txmode.offloads &=
5082                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5083                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5084                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5085                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5086                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5087                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5088                 printf("TSO for tunneled packets is disabled\n");
5089         } else {
5090                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5091                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5092                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5093                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5094                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5095                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5096
5097                 ports[res->port_id].dev_conf.txmode.offloads |=
5098                         (tso_offloads & dev_info.tx_offload_capa);
5099                 printf("TSO segment size for tunneled packets is %d\n",
5100                         ports[res->port_id].tunnel_tso_segsz);
5101
5102                 /* Below conditions are needed to make it work:
5103                  * (1) tunnel TSO is supported by the NIC;
5104                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5105                  * are recognized;
5106                  * (3) for tunneled pkts with outer L3 of IPv4,
5107                  * "csum set outer-ip" must be set to hw, because after tso,
5108                  * total_len of outer IP header is changed, and the checksum
5109                  * of outer IP header calculated by sw should be wrong; that
5110                  * is not necessary for IPv6 tunneled pkts because there's no
5111                  * checksum in IP header anymore.
5112                  */
5113
5114                 if (!ports[res->port_id].parse_tunnel)
5115                         fprintf(stderr,
5116                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5117                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5118                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5119                         fprintf(stderr,
5120                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5121         }
5122
5123         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5124         cmd_reconfig_device_queue(res->port_id, 1, 1);
5125 }
5126
5127 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5128         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5129                                 tso, "tunnel_tso");
5130 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5131         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5132                                 mode, "set");
5133 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5134         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5135                                 tso_segsz, RTE_UINT16);
5136 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5137         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5138                                 port_id, RTE_UINT16);
5139
5140 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5141         .f = cmd_tunnel_tso_set_parsed,
5142         .data = NULL,
5143         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5144                 "Set TSO segment size of tunneled packets for csum engine "
5145                 "(0 to disable)",
5146         .tokens = {
5147                 (void *)&cmd_tunnel_tso_set_tso,
5148                 (void *)&cmd_tunnel_tso_set_mode,
5149                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5150                 (void *)&cmd_tunnel_tso_set_portid,
5151                 NULL,
5152         },
5153 };
5154
5155 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5156         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5157                                 mode, "show");
5158
5159
5160 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5161         .f = cmd_tunnel_tso_set_parsed,
5162         .data = NULL,
5163         .help_str = "tunnel_tso show <port_id> "
5164                 "Show TSO segment size of tunneled packets for csum engine",
5165         .tokens = {
5166                 (void *)&cmd_tunnel_tso_set_tso,
5167                 (void *)&cmd_tunnel_tso_show_mode,
5168                 (void *)&cmd_tunnel_tso_set_portid,
5169                 NULL,
5170         },
5171 };
5172
5173 #ifdef RTE_LIB_GRO
5174 /* *** SET GRO FOR A PORT *** */
5175 struct cmd_gro_enable_result {
5176         cmdline_fixed_string_t cmd_set;
5177         cmdline_fixed_string_t cmd_port;
5178         cmdline_fixed_string_t cmd_keyword;
5179         cmdline_fixed_string_t cmd_onoff;
5180         portid_t cmd_pid;
5181 };
5182
5183 static void
5184 cmd_gro_enable_parsed(void *parsed_result,
5185                 __rte_unused struct cmdline *cl,
5186                 __rte_unused void *data)
5187 {
5188         struct cmd_gro_enable_result *res;
5189
5190         res = parsed_result;
5191         if (!strcmp(res->cmd_keyword, "gro"))
5192                 setup_gro(res->cmd_onoff, res->cmd_pid);
5193 }
5194
5195 cmdline_parse_token_string_t cmd_gro_enable_set =
5196         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5197                         cmd_set, "set");
5198 cmdline_parse_token_string_t cmd_gro_enable_port =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5200                         cmd_keyword, "port");
5201 cmdline_parse_token_num_t cmd_gro_enable_pid =
5202         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5203                         cmd_pid, RTE_UINT16);
5204 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5205         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5206                         cmd_keyword, "gro");
5207 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5208         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5209                         cmd_onoff, "on#off");
5210
5211 cmdline_parse_inst_t cmd_gro_enable = {
5212         .f = cmd_gro_enable_parsed,
5213         .data = NULL,
5214         .help_str = "set port <port_id> gro on|off",
5215         .tokens = {
5216                 (void *)&cmd_gro_enable_set,
5217                 (void *)&cmd_gro_enable_port,
5218                 (void *)&cmd_gro_enable_pid,
5219                 (void *)&cmd_gro_enable_keyword,
5220                 (void *)&cmd_gro_enable_onoff,
5221                 NULL,
5222         },
5223 };
5224
5225 /* *** DISPLAY GRO CONFIGURATION *** */
5226 struct cmd_gro_show_result {
5227         cmdline_fixed_string_t cmd_show;
5228         cmdline_fixed_string_t cmd_port;
5229         cmdline_fixed_string_t cmd_keyword;
5230         portid_t cmd_pid;
5231 };
5232
5233 static void
5234 cmd_gro_show_parsed(void *parsed_result,
5235                 __rte_unused struct cmdline *cl,
5236                 __rte_unused void *data)
5237 {
5238         struct cmd_gro_show_result *res;
5239
5240         res = parsed_result;
5241         if (!strcmp(res->cmd_keyword, "gro"))
5242                 show_gro(res->cmd_pid);
5243 }
5244
5245 cmdline_parse_token_string_t cmd_gro_show_show =
5246         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5247                         cmd_show, "show");
5248 cmdline_parse_token_string_t cmd_gro_show_port =
5249         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5250                         cmd_port, "port");
5251 cmdline_parse_token_num_t cmd_gro_show_pid =
5252         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5253                         cmd_pid, RTE_UINT16);
5254 cmdline_parse_token_string_t cmd_gro_show_keyword =
5255         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5256                         cmd_keyword, "gro");
5257
5258 cmdline_parse_inst_t cmd_gro_show = {
5259         .f = cmd_gro_show_parsed,
5260         .data = NULL,
5261         .help_str = "show port <port_id> gro",
5262         .tokens = {
5263                 (void *)&cmd_gro_show_show,
5264                 (void *)&cmd_gro_show_port,
5265                 (void *)&cmd_gro_show_pid,
5266                 (void *)&cmd_gro_show_keyword,
5267                 NULL,
5268         },
5269 };
5270
5271 /* *** SET FLUSH CYCLES FOR GRO *** */
5272 struct cmd_gro_flush_result {
5273         cmdline_fixed_string_t cmd_set;
5274         cmdline_fixed_string_t cmd_keyword;
5275         cmdline_fixed_string_t cmd_flush;
5276         uint8_t cmd_cycles;
5277 };
5278
5279 static void
5280 cmd_gro_flush_parsed(void *parsed_result,
5281                 __rte_unused struct cmdline *cl,
5282                 __rte_unused void *data)
5283 {
5284         struct cmd_gro_flush_result *res;
5285
5286         res = parsed_result;
5287         if ((!strcmp(res->cmd_keyword, "gro")) &&
5288                         (!strcmp(res->cmd_flush, "flush")))
5289                 setup_gro_flush_cycles(res->cmd_cycles);
5290 }
5291
5292 cmdline_parse_token_string_t cmd_gro_flush_set =
5293         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5294                         cmd_set, "set");
5295 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5296         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5297                         cmd_keyword, "gro");
5298 cmdline_parse_token_string_t cmd_gro_flush_flush =
5299         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5300                         cmd_flush, "flush");
5301 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5302         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5303                         cmd_cycles, RTE_UINT8);
5304
5305 cmdline_parse_inst_t cmd_gro_flush = {
5306         .f = cmd_gro_flush_parsed,
5307         .data = NULL,
5308         .help_str = "set gro flush <cycles>",
5309         .tokens = {
5310                 (void *)&cmd_gro_flush_set,
5311                 (void *)&cmd_gro_flush_keyword,
5312                 (void *)&cmd_gro_flush_flush,
5313                 (void *)&cmd_gro_flush_cycles,
5314                 NULL,
5315         },
5316 };
5317 #endif /* RTE_LIB_GRO */
5318
5319 #ifdef RTE_LIB_GSO
5320 /* *** ENABLE/DISABLE GSO *** */
5321 struct cmd_gso_enable_result {
5322         cmdline_fixed_string_t cmd_set;
5323         cmdline_fixed_string_t cmd_port;
5324         cmdline_fixed_string_t cmd_keyword;
5325         cmdline_fixed_string_t cmd_mode;
5326         portid_t cmd_pid;
5327 };
5328
5329 static void
5330 cmd_gso_enable_parsed(void *parsed_result,
5331                 __rte_unused struct cmdline *cl,
5332                 __rte_unused void *data)
5333 {
5334         struct cmd_gso_enable_result *res;
5335
5336         res = parsed_result;
5337         if (!strcmp(res->cmd_keyword, "gso"))
5338                 setup_gso(res->cmd_mode, res->cmd_pid);
5339 }
5340
5341 cmdline_parse_token_string_t cmd_gso_enable_set =
5342         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5343                         cmd_set, "set");
5344 cmdline_parse_token_string_t cmd_gso_enable_port =
5345         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5346                         cmd_port, "port");
5347 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5348         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5349                         cmd_keyword, "gso");
5350 cmdline_parse_token_string_t cmd_gso_enable_mode =
5351         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5352                         cmd_mode, "on#off");
5353 cmdline_parse_token_num_t cmd_gso_enable_pid =
5354         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5355                         cmd_pid, RTE_UINT16);
5356
5357 cmdline_parse_inst_t cmd_gso_enable = {
5358         .f = cmd_gso_enable_parsed,
5359         .data = NULL,
5360         .help_str = "set port <port_id> gso on|off",
5361         .tokens = {
5362                 (void *)&cmd_gso_enable_set,
5363                 (void *)&cmd_gso_enable_port,
5364                 (void *)&cmd_gso_enable_pid,
5365                 (void *)&cmd_gso_enable_keyword,
5366                 (void *)&cmd_gso_enable_mode,
5367                 NULL,
5368         },
5369 };
5370
5371 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5372 struct cmd_gso_size_result {
5373         cmdline_fixed_string_t cmd_set;
5374         cmdline_fixed_string_t cmd_keyword;
5375         cmdline_fixed_string_t cmd_segsz;
5376         uint16_t cmd_size;
5377 };
5378
5379 static void
5380 cmd_gso_size_parsed(void *parsed_result,
5381                        __rte_unused struct cmdline *cl,
5382                        __rte_unused void *data)
5383 {
5384         struct cmd_gso_size_result *res = parsed_result;
5385
5386         if (test_done == 0) {
5387                 fprintf(stderr,
5388                         "Before setting GSO segsz, please first stop forwarding\n");
5389                 return;
5390         }
5391
5392         if (!strcmp(res->cmd_keyword, "gso") &&
5393                         !strcmp(res->cmd_segsz, "segsz")) {
5394                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5395                         fprintf(stderr,
5396                                 "gso_size should be larger than %zu. Please input a legal value\n",
5397                                 RTE_GSO_SEG_SIZE_MIN);
5398                 else
5399                         gso_max_segment_size = res->cmd_size;
5400         }
5401 }
5402
5403 cmdline_parse_token_string_t cmd_gso_size_set =
5404         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5405                                 cmd_set, "set");
5406 cmdline_parse_token_string_t cmd_gso_size_keyword =
5407         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5408                                 cmd_keyword, "gso");
5409 cmdline_parse_token_string_t cmd_gso_size_segsz =
5410         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5411                                 cmd_segsz, "segsz");
5412 cmdline_parse_token_num_t cmd_gso_size_size =
5413         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5414                                 cmd_size, RTE_UINT16);
5415
5416 cmdline_parse_inst_t cmd_gso_size = {
5417         .f = cmd_gso_size_parsed,
5418         .data = NULL,
5419         .help_str = "set gso segsz <length>",
5420         .tokens = {
5421                 (void *)&cmd_gso_size_set,
5422                 (void *)&cmd_gso_size_keyword,
5423                 (void *)&cmd_gso_size_segsz,
5424                 (void *)&cmd_gso_size_size,
5425                 NULL,
5426         },
5427 };
5428
5429 /* *** SHOW GSO CONFIGURATION *** */
5430 struct cmd_gso_show_result {
5431         cmdline_fixed_string_t cmd_show;
5432         cmdline_fixed_string_t cmd_port;
5433         cmdline_fixed_string_t cmd_keyword;
5434         portid_t cmd_pid;
5435 };
5436
5437 static void
5438 cmd_gso_show_parsed(void *parsed_result,
5439                        __rte_unused struct cmdline *cl,
5440                        __rte_unused void *data)
5441 {
5442         struct cmd_gso_show_result *res = parsed_result;
5443
5444         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5445                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5446                 return;
5447         }
5448         if (!strcmp(res->cmd_keyword, "gso")) {
5449                 if (gso_ports[res->cmd_pid].enable) {
5450                         printf("Max GSO'd packet size: %uB\n"
5451                                         "Supported GSO types: TCP/IPv4, "
5452                                         "UDP/IPv4, VxLAN with inner "
5453                                         "TCP/IPv4 packet, GRE with inner "
5454                                         "TCP/IPv4 packet\n",
5455                                         gso_max_segment_size);
5456                 } else
5457                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5458         }
5459 }
5460
5461 cmdline_parse_token_string_t cmd_gso_show_show =
5462 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5463                 cmd_show, "show");
5464 cmdline_parse_token_string_t cmd_gso_show_port =
5465 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5466                 cmd_port, "port");
5467 cmdline_parse_token_string_t cmd_gso_show_keyword =
5468         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5469                                 cmd_keyword, "gso");
5470 cmdline_parse_token_num_t cmd_gso_show_pid =
5471         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5472                                 cmd_pid, RTE_UINT16);
5473
5474 cmdline_parse_inst_t cmd_gso_show = {
5475         .f = cmd_gso_show_parsed,
5476         .data = NULL,
5477         .help_str = "show port <port_id> gso",
5478         .tokens = {
5479                 (void *)&cmd_gso_show_show,
5480                 (void *)&cmd_gso_show_port,
5481                 (void *)&cmd_gso_show_pid,
5482                 (void *)&cmd_gso_show_keyword,
5483                 NULL,
5484         },
5485 };
5486 #endif /* RTE_LIB_GSO */
5487
5488 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5489 struct cmd_set_flush_rx {
5490         cmdline_fixed_string_t set;
5491         cmdline_fixed_string_t flush_rx;
5492         cmdline_fixed_string_t mode;
5493 };
5494
5495 static void
5496 cmd_set_flush_rx_parsed(void *parsed_result,
5497                 __rte_unused struct cmdline *cl,
5498                 __rte_unused void *data)
5499 {
5500         struct cmd_set_flush_rx *res = parsed_result;
5501
5502         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5503                 printf("multi-process doesn't support to flush Rx queues.\n");
5504                 return;
5505         }
5506
5507         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5508 }
5509
5510 cmdline_parse_token_string_t cmd_setflushrx_set =
5511         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5512                         set, "set");
5513 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5514         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5515                         flush_rx, "flush_rx");
5516 cmdline_parse_token_string_t cmd_setflushrx_mode =
5517         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5518                         mode, "on#off");
5519
5520
5521 cmdline_parse_inst_t cmd_set_flush_rx = {
5522         .f = cmd_set_flush_rx_parsed,
5523         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5524         .data = NULL,
5525         .tokens = {
5526                 (void *)&cmd_setflushrx_set,
5527                 (void *)&cmd_setflushrx_flush_rx,
5528                 (void *)&cmd_setflushrx_mode,
5529                 NULL,
5530         },
5531 };
5532
5533 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5534 struct cmd_set_link_check {
5535         cmdline_fixed_string_t set;
5536         cmdline_fixed_string_t link_check;
5537         cmdline_fixed_string_t mode;
5538 };
5539
5540 static void
5541 cmd_set_link_check_parsed(void *parsed_result,
5542                 __rte_unused struct cmdline *cl,
5543                 __rte_unused void *data)
5544 {
5545         struct cmd_set_link_check *res = parsed_result;
5546         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5547 }
5548
5549 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5550         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5551                         set, "set");
5552 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5553         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5554                         link_check, "link_check");
5555 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5556         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5557                         mode, "on#off");
5558
5559
5560 cmdline_parse_inst_t cmd_set_link_check = {
5561         .f = cmd_set_link_check_parsed,
5562         .help_str = "set link_check on|off: Enable/Disable link status check "
5563                     "when starting/stopping a port",
5564         .data = NULL,
5565         .tokens = {
5566                 (void *)&cmd_setlinkcheck_set,
5567                 (void *)&cmd_setlinkcheck_link_check,
5568                 (void *)&cmd_setlinkcheck_mode,
5569                 NULL,
5570         },
5571 };
5572
5573 /* *** SET NIC BYPASS MODE *** */
5574 struct cmd_set_bypass_mode_result {
5575         cmdline_fixed_string_t set;
5576         cmdline_fixed_string_t bypass;
5577         cmdline_fixed_string_t mode;
5578         cmdline_fixed_string_t value;
5579         portid_t port_id;
5580 };
5581
5582 static void
5583 cmd_set_bypass_mode_parsed(void *parsed_result,
5584                 __rte_unused struct cmdline *cl,
5585                 __rte_unused void *data)
5586 {
5587         struct cmd_set_bypass_mode_result *res = parsed_result;
5588         portid_t port_id = res->port_id;
5589         int32_t rc = -EINVAL;
5590
5591 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5592         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5593
5594         if (!strcmp(res->value, "bypass"))
5595                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5596         else if (!strcmp(res->value, "isolate"))
5597                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5598         else
5599                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5600
5601         /* Set the bypass mode for the relevant port. */
5602         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5603 #endif
5604         if (rc != 0)
5605                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5606                         port_id);
5607 }
5608
5609 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5610         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5611                         set, "set");
5612 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5613         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5614                         bypass, "bypass");
5615 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5616         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5617                         mode, "mode");
5618 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5619         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5620                         value, "normal#bypass#isolate");
5621 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5622         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5623                                 port_id, RTE_UINT16);
5624
5625 cmdline_parse_inst_t cmd_set_bypass_mode = {
5626         .f = cmd_set_bypass_mode_parsed,
5627         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5628                     "Set the NIC bypass mode for port_id",
5629         .data = NULL,
5630         .tokens = {
5631                 (void *)&cmd_setbypass_mode_set,
5632                 (void *)&cmd_setbypass_mode_bypass,
5633                 (void *)&cmd_setbypass_mode_mode,
5634                 (void *)&cmd_setbypass_mode_value,
5635                 (void *)&cmd_setbypass_mode_port,
5636                 NULL,
5637         },
5638 };
5639
5640 /* *** SET NIC BYPASS EVENT *** */
5641 struct cmd_set_bypass_event_result {
5642         cmdline_fixed_string_t set;
5643         cmdline_fixed_string_t bypass;
5644         cmdline_fixed_string_t event;
5645         cmdline_fixed_string_t event_value;
5646         cmdline_fixed_string_t mode;
5647         cmdline_fixed_string_t mode_value;
5648         portid_t port_id;
5649 };
5650
5651 static void
5652 cmd_set_bypass_event_parsed(void *parsed_result,
5653                 __rte_unused struct cmdline *cl,
5654                 __rte_unused void *data)
5655 {
5656         int32_t rc = -EINVAL;
5657         struct cmd_set_bypass_event_result *res = parsed_result;
5658         portid_t port_id = res->port_id;
5659
5660 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5661         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5662         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5663
5664         if (!strcmp(res->event_value, "timeout"))
5665                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5666         else if (!strcmp(res->event_value, "os_on"))
5667                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5668         else if (!strcmp(res->event_value, "os_off"))
5669                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5670         else if (!strcmp(res->event_value, "power_on"))
5671                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5672         else if (!strcmp(res->event_value, "power_off"))
5673                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5674         else
5675                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5676
5677         if (!strcmp(res->mode_value, "bypass"))
5678                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5679         else if (!strcmp(res->mode_value, "isolate"))
5680                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5681         else
5682                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5683
5684         /* Set the watchdog timeout. */
5685         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5686
5687                 rc = -EINVAL;
5688                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5689                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5690                                                            bypass_timeout);
5691                 }
5692                 if (rc != 0) {
5693                         fprintf(stderr,
5694                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5695                                 bypass_timeout, port_id, rc);
5696                 }
5697         }
5698
5699         /* Set the bypass event to transition to bypass mode. */
5700         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5701                                               bypass_mode);
5702 #endif
5703
5704         if (rc != 0)
5705                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5706                         port_id);
5707 }
5708
5709 cmdline_parse_token_string_t cmd_setbypass_event_set =
5710         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5711                         set, "set");
5712 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5713         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5714                         bypass, "bypass");
5715 cmdline_parse_token_string_t cmd_setbypass_event_event =
5716         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5717                         event, "event");
5718 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5719         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5720                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5721 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5722         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5723                         mode, "mode");
5724 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5725         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5726                         mode_value, "normal#bypass#isolate");
5727 cmdline_parse_token_num_t cmd_setbypass_event_port =
5728         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5729                                 port_id, RTE_UINT16);
5730
5731 cmdline_parse_inst_t cmd_set_bypass_event = {
5732         .f = cmd_set_bypass_event_parsed,
5733         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5734                 "power_off mode normal|bypass|isolate <port_id>: "
5735                 "Set the NIC bypass event mode for port_id",
5736         .data = NULL,
5737         .tokens = {
5738                 (void *)&cmd_setbypass_event_set,
5739                 (void *)&cmd_setbypass_event_bypass,
5740                 (void *)&cmd_setbypass_event_event,
5741                 (void *)&cmd_setbypass_event_event_value,
5742                 (void *)&cmd_setbypass_event_mode,
5743                 (void *)&cmd_setbypass_event_mode_value,
5744                 (void *)&cmd_setbypass_event_port,
5745                 NULL,
5746         },
5747 };
5748
5749
5750 /* *** SET NIC BYPASS TIMEOUT *** */
5751 struct cmd_set_bypass_timeout_result {
5752         cmdline_fixed_string_t set;
5753         cmdline_fixed_string_t bypass;
5754         cmdline_fixed_string_t timeout;
5755         cmdline_fixed_string_t value;
5756 };
5757
5758 static void
5759 cmd_set_bypass_timeout_parsed(void *parsed_result,
5760                 __rte_unused struct cmdline *cl,
5761                 __rte_unused void *data)
5762 {
5763         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5764
5765 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5766         if (!strcmp(res->value, "1.5"))
5767                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5768         else if (!strcmp(res->value, "2"))
5769                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5770         else if (!strcmp(res->value, "3"))
5771                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5772         else if (!strcmp(res->value, "4"))
5773                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5774         else if (!strcmp(res->value, "8"))
5775                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5776         else if (!strcmp(res->value, "16"))
5777                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5778         else if (!strcmp(res->value, "32"))
5779                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5780         else
5781                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5782 #endif
5783 }
5784
5785 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5786         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5787                         set, "set");
5788 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5789         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5790                         bypass, "bypass");
5791 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5792         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5793                         timeout, "timeout");
5794 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5795         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5796                         value, "0#1.5#2#3#4#8#16#32");
5797
5798 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5799         .f = cmd_set_bypass_timeout_parsed,
5800         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5801                 "Set the NIC bypass watchdog timeout in seconds",
5802         .data = NULL,
5803         .tokens = {
5804                 (void *)&cmd_setbypass_timeout_set,
5805                 (void *)&cmd_setbypass_timeout_bypass,
5806                 (void *)&cmd_setbypass_timeout_timeout,
5807                 (void *)&cmd_setbypass_timeout_value,
5808                 NULL,
5809         },
5810 };
5811
5812 /* *** SHOW NIC BYPASS MODE *** */
5813 struct cmd_show_bypass_config_result {
5814         cmdline_fixed_string_t show;
5815         cmdline_fixed_string_t bypass;
5816         cmdline_fixed_string_t config;
5817         portid_t port_id;
5818 };
5819
5820 static void
5821 cmd_show_bypass_config_parsed(void *parsed_result,
5822                 __rte_unused struct cmdline *cl,
5823                 __rte_unused void *data)
5824 {
5825         struct cmd_show_bypass_config_result *res = parsed_result;
5826         portid_t port_id = res->port_id;
5827         int rc = -EINVAL;
5828 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5829         uint32_t event_mode;
5830         uint32_t bypass_mode;
5831         uint32_t timeout = bypass_timeout;
5832         unsigned int i;
5833
5834         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5835                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5836         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5837                 {"UNKNOWN", "normal", "bypass", "isolate"};
5838         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5839                 "NONE",
5840                 "OS/board on",
5841                 "power supply on",
5842                 "OS/board off",
5843                 "power supply off",
5844                 "timeout"};
5845
5846         /* Display the bypass mode.*/
5847         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5848                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5849                         port_id);
5850                 return;
5851         }
5852         else {
5853                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5854                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5855
5856                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5857         }
5858
5859         /* Display the bypass timeout.*/
5860         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5861                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5862
5863         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5864
5865         /* Display the bypass events and associated modes. */
5866         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5867
5868                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5869                         fprintf(stderr,
5870                                 "\tFailed to get bypass mode for event = %s\n",
5871                                 events[i]);
5872                 } else {
5873                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5874                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5875
5876                         printf("\tbypass event: %-16s = %s\n", events[i],
5877                                 modes[event_mode]);
5878                 }
5879         }
5880 #endif
5881         if (rc != 0)
5882                 fprintf(stderr,
5883                         "\tFailed to get bypass configuration for port = %d\n",
5884                        port_id);
5885 }
5886
5887 cmdline_parse_token_string_t cmd_showbypass_config_show =
5888         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5889                         show, "show");
5890 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5891         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5892                         bypass, "bypass");
5893 cmdline_parse_token_string_t cmd_showbypass_config_config =
5894         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5895                         config, "config");
5896 cmdline_parse_token_num_t cmd_showbypass_config_port =
5897         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5898                                 port_id, RTE_UINT16);
5899
5900 cmdline_parse_inst_t cmd_show_bypass_config = {
5901         .f = cmd_show_bypass_config_parsed,
5902         .help_str = "show bypass config <port_id>: "
5903                     "Show the NIC bypass config for port_id",
5904         .data = NULL,
5905         .tokens = {
5906                 (void *)&cmd_showbypass_config_show,
5907                 (void *)&cmd_showbypass_config_bypass,
5908                 (void *)&cmd_showbypass_config_config,
5909                 (void *)&cmd_showbypass_config_port,
5910                 NULL,
5911         },
5912 };
5913
5914 #ifdef RTE_NET_BOND
5915 /* *** SET BONDING MODE *** */
5916 struct cmd_set_bonding_mode_result {
5917         cmdline_fixed_string_t set;
5918         cmdline_fixed_string_t bonding;
5919         cmdline_fixed_string_t mode;
5920         uint8_t value;
5921         portid_t port_id;
5922 };
5923
5924 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5925                 __rte_unused  struct cmdline *cl,
5926                 __rte_unused void *data)
5927 {
5928         struct cmd_set_bonding_mode_result *res = parsed_result;
5929         portid_t port_id = res->port_id;
5930         struct rte_port *port = &ports[port_id];
5931
5932         /*
5933          * Bonding mode changed means resources of device changed, like whether
5934          * started rte timer or not. Device should be restarted when resources
5935          * of device changed.
5936          */
5937         if (port->port_status != RTE_PORT_STOPPED) {
5938                 fprintf(stderr,
5939                         "\t Error: Can't set bonding mode when port %d is not stopped\n",
5940                         port_id);
5941                 return;
5942         }
5943
5944         /* Set the bonding mode for the relevant port. */
5945         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5946                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5947                         port_id);
5948 }
5949
5950 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5951 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5952                 set, "set");
5953 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5954 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5955                 bonding, "bonding");
5956 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5957 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5958                 mode, "mode");
5959 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5960 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5961                 value, RTE_UINT8);
5962 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5963 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5964                 port_id, RTE_UINT16);
5965
5966 cmdline_parse_inst_t cmd_set_bonding_mode = {
5967                 .f = cmd_set_bonding_mode_parsed,
5968                 .help_str = "set bonding mode <mode_value> <port_id>: "
5969                         "Set the bonding mode for port_id",
5970                 .data = NULL,
5971                 .tokens = {
5972                                 (void *) &cmd_setbonding_mode_set,
5973                                 (void *) &cmd_setbonding_mode_bonding,
5974                                 (void *) &cmd_setbonding_mode_mode,
5975                                 (void *) &cmd_setbonding_mode_value,
5976                                 (void *) &cmd_setbonding_mode_port,
5977                                 NULL
5978                 }
5979 };
5980
5981 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5982 struct cmd_set_bonding_lacp_dedicated_queues_result {
5983         cmdline_fixed_string_t set;
5984         cmdline_fixed_string_t bonding;
5985         cmdline_fixed_string_t lacp;
5986         cmdline_fixed_string_t dedicated_queues;
5987         portid_t port_id;
5988         cmdline_fixed_string_t mode;
5989 };
5990
5991 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5992                 __rte_unused  struct cmdline *cl,
5993                 __rte_unused void *data)
5994 {
5995         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5996         portid_t port_id = res->port_id;
5997         struct rte_port *port;
5998
5999         port = &ports[port_id];
6000
6001         /** Check if the port is not started **/
6002         if (port->port_status != RTE_PORT_STOPPED) {
6003                 fprintf(stderr, "Please stop port %d first\n", port_id);
6004                 return;
6005         }
6006
6007         if (!strcmp(res->mode, "enable")) {
6008                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6009                         printf("Dedicate queues for LACP control packets"
6010                                         " enabled\n");
6011                 else
6012                         printf("Enabling dedicate queues for LACP control "
6013                                         "packets on port %d failed\n", port_id);
6014         } else if (!strcmp(res->mode, "disable")) {
6015                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6016                         printf("Dedicated queues for LACP control packets "
6017                                         "disabled\n");
6018                 else
6019                         printf("Disabling dedicated queues for LACP control "
6020                                         "traffic on port %d failed\n", port_id);
6021         }
6022 }
6023
6024 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6025 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6026                 set, "set");
6027 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6028 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6029                 bonding, "bonding");
6030 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6031 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6032                 lacp, "lacp");
6033 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6034 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6035                 dedicated_queues, "dedicated_queues");
6036 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6037 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6038                 port_id, RTE_UINT16);
6039 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6040 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6041                 mode, "enable#disable");
6042
6043 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6044                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6045                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6046                         "enable|disable: "
6047                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6048                 .data = NULL,
6049                 .tokens = {
6050                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6051                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6052                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6053                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6054                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6055                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6056                         NULL
6057                 }
6058 };
6059
6060 /* *** SET BALANCE XMIT POLICY *** */
6061 struct cmd_set_bonding_balance_xmit_policy_result {
6062         cmdline_fixed_string_t set;
6063         cmdline_fixed_string_t bonding;
6064         cmdline_fixed_string_t balance_xmit_policy;
6065         portid_t port_id;
6066         cmdline_fixed_string_t policy;
6067 };
6068
6069 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6070                 __rte_unused  struct cmdline *cl,
6071                 __rte_unused void *data)
6072 {
6073         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6074         portid_t port_id = res->port_id;
6075         uint8_t policy;
6076
6077         if (!strcmp(res->policy, "l2")) {
6078                 policy = BALANCE_XMIT_POLICY_LAYER2;
6079         } else if (!strcmp(res->policy, "l23")) {
6080                 policy = BALANCE_XMIT_POLICY_LAYER23;
6081         } else if (!strcmp(res->policy, "l34")) {
6082                 policy = BALANCE_XMIT_POLICY_LAYER34;
6083         } else {
6084                 fprintf(stderr, "\t Invalid xmit policy selection");
6085                 return;
6086         }
6087
6088         /* Set the bonding mode for the relevant port. */
6089         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6090                 fprintf(stderr,
6091                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6092                         port_id);
6093         }
6094 }
6095
6096 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6097 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6098                 set, "set");
6099 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6100 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6101                 bonding, "bonding");
6102 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6103 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6104                 balance_xmit_policy, "balance_xmit_policy");
6105 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6106 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6107                 port_id, RTE_UINT16);
6108 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6109 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6110                 policy, "l2#l23#l34");
6111
6112 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6113                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6114                 .help_str = "set bonding balance_xmit_policy <port_id> "
6115                         "l2|l23|l34: "
6116                         "Set the bonding balance_xmit_policy for port_id",
6117                 .data = NULL,
6118                 .tokens = {
6119                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6120                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6121                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6122                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6123                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6124                                 NULL
6125                 }
6126 };
6127
6128 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6129 struct cmd_show_bonding_lacp_info_result {
6130         cmdline_fixed_string_t show;
6131         cmdline_fixed_string_t bonding;
6132         cmdline_fixed_string_t lacp;
6133         cmdline_fixed_string_t info;
6134         portid_t port_id;
6135 };
6136
6137 static void port_param_show(struct port_params *params)
6138 {
6139         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6140
6141         printf("\t\tsystem priority: %u\n", params->system_priority);
6142         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6143         printf("\t\tsystem mac address: %s\n", buf);
6144         printf("\t\tport key: %u\n", params->key);
6145         printf("\t\tport priority: %u\n", params->port_priority);
6146         printf("\t\tport number: %u\n", params->port_number);
6147 }
6148
6149 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6150 {
6151         char a_state[256] = { 0 };
6152         char p_state[256] = { 0 };
6153         int a_len = 0;
6154         int p_len = 0;
6155         uint32_t i;
6156
6157         static const char * const state[] = {
6158                 "ACTIVE",
6159                 "TIMEOUT",
6160                 "AGGREGATION",
6161                 "SYNCHRONIZATION",
6162                 "COLLECTING",
6163                 "DISTRIBUTING",
6164                 "DEFAULTED",
6165                 "EXPIRED"
6166         };
6167         static const char * const selection[] = {
6168                 "UNSELECTED",
6169                 "STANDBY",
6170                 "SELECTED"
6171         };
6172
6173         for (i = 0; i < RTE_DIM(state); i++) {
6174                 if ((info->actor_state >> i) & 1)
6175                         a_len += snprintf(&a_state[a_len],
6176                                                 RTE_DIM(a_state) - a_len, "%s ",
6177                                                 state[i]);
6178
6179                 if ((info->partner_state >> i) & 1)
6180                         p_len += snprintf(&p_state[p_len],
6181                                                 RTE_DIM(p_state) - p_len, "%s ",
6182                                                 state[i]);
6183         }
6184         printf("\tAggregator port id: %u\n", info->agg_port_id);
6185         printf("\tselection: %s\n", selection[info->selected]);
6186         printf("\tActor detail info:\n");
6187         port_param_show(&info->actor);
6188         printf("\t\tport state: %s\n", a_state);
6189         printf("\tPartner detail info:\n");
6190         port_param_show(&info->partner);
6191         printf("\t\tport state: %s\n", p_state);
6192         printf("\n");
6193 }
6194
6195 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6196 {
6197         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6198         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6199         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6200         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6201         printf("\taggregate wait timeout: %u ms\n",
6202                         conf->aggregate_wait_timeout_ms);
6203         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6204         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6205         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6206         switch (conf->agg_selection) {
6207         case AGG_BANDWIDTH:
6208                 printf("\taggregation mode: bandwidth\n");
6209                 break;
6210         case AGG_STABLE:
6211                 printf("\taggregation mode: stable\n");
6212                 break;
6213         case AGG_COUNT:
6214                 printf("\taggregation mode: count\n");
6215                 break;
6216         default:
6217                 printf("\taggregation mode: invalid\n");
6218                 break;
6219         }
6220
6221         printf("\n");
6222 }
6223
6224 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6225                 __rte_unused  struct cmdline *cl,
6226                 __rte_unused void *data)
6227 {
6228         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6229         struct rte_eth_bond_8023ad_slave_info slave_info;
6230         struct rte_eth_bond_8023ad_conf port_conf;
6231         portid_t slaves[RTE_MAX_ETHPORTS];
6232         portid_t port_id = res->port_id;
6233         int num_active_slaves;
6234         int bonding_mode;
6235         int i;
6236         int ret;
6237
6238         bonding_mode = rte_eth_bond_mode_get(port_id);
6239         if (bonding_mode != BONDING_MODE_8023AD) {
6240                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6241                 return;
6242         }
6243
6244         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6245                         RTE_MAX_ETHPORTS);
6246         if (num_active_slaves < 0) {
6247                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6248                                 port_id);
6249                 return;
6250         }
6251         if (num_active_slaves == 0)
6252                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6253                         port_id);
6254
6255         printf("\tIEEE802.3 port: %u\n", port_id);
6256         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6257         if (ret) {
6258                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6259                         port_id);
6260                 return;
6261         }
6262         lacp_conf_show(&port_conf);
6263
6264         for (i = 0; i < num_active_slaves; i++) {
6265                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6266                                 &slave_info);
6267                 if (ret) {
6268                         fprintf(stderr, "\tGet slave device %u info failed\n",
6269                                 slaves[i]);
6270                         return;
6271                 }
6272                 printf("\tSlave Port: %u\n", slaves[i]);
6273                 lacp_slave_info_show(&slave_info);
6274         }
6275 }
6276
6277 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6278 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6279                 show, "show");
6280 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6281 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6282                 bonding, "bonding");
6283 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6284 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6285                 bonding, "lacp");
6286 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6287 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6288                 info, "info");
6289 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6290 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6291                 port_id, RTE_UINT16);
6292
6293 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6294                 .f = cmd_show_bonding_lacp_info_parsed,
6295                 .help_str = "show bonding lacp info <port_id> : "
6296                         "Show bonding IEEE802.3 information for port_id",
6297                 .data = NULL,
6298                 .tokens = {
6299                         (void *)&cmd_show_bonding_lacp_info_show,
6300                         (void *)&cmd_show_bonding_lacp_info_bonding,
6301                         (void *)&cmd_show_bonding_lacp_info_lacp,
6302                         (void *)&cmd_show_bonding_lacp_info_info,
6303                         (void *)&cmd_show_bonding_lacp_info_port_id,
6304                         NULL
6305                 }
6306 };
6307
6308 /* *** SHOW NIC BONDING CONFIGURATION *** */
6309 struct cmd_show_bonding_config_result {
6310         cmdline_fixed_string_t show;
6311         cmdline_fixed_string_t bonding;
6312         cmdline_fixed_string_t config;
6313         portid_t port_id;
6314 };
6315
6316 static void cmd_show_bonding_config_parsed(void *parsed_result,
6317                 __rte_unused  struct cmdline *cl,
6318                 __rte_unused void *data)
6319 {
6320         struct cmd_show_bonding_config_result *res = parsed_result;
6321         int bonding_mode, agg_mode;
6322         portid_t slaves[RTE_MAX_ETHPORTS];
6323         int num_slaves, num_active_slaves;
6324         int primary_id;
6325         int i;
6326         portid_t port_id = res->port_id;
6327
6328         /* Display the bonding mode.*/
6329         bonding_mode = rte_eth_bond_mode_get(port_id);
6330         if (bonding_mode < 0) {
6331                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6332                         port_id);
6333                 return;
6334         } else
6335                 printf("\tBonding mode: %d\n", bonding_mode);
6336
6337         if (bonding_mode == BONDING_MODE_BALANCE ||
6338                 bonding_mode == BONDING_MODE_8023AD) {
6339                 int balance_xmit_policy;
6340
6341                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6342                 if (balance_xmit_policy < 0) {
6343                         fprintf(stderr,
6344                                 "\tFailed to get balance xmit policy for port = %d\n",
6345                                 port_id);
6346                         return;
6347                 } else {
6348                         printf("\tBalance Xmit Policy: ");
6349
6350                         switch (balance_xmit_policy) {
6351                         case BALANCE_XMIT_POLICY_LAYER2:
6352                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6353                                 break;
6354                         case BALANCE_XMIT_POLICY_LAYER23:
6355                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6356                                 break;
6357                         case BALANCE_XMIT_POLICY_LAYER34:
6358                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6359                                 break;
6360                         }
6361                         printf("\n");
6362                 }
6363         }
6364
6365         if (bonding_mode == BONDING_MODE_8023AD) {
6366                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6367                 printf("\tIEEE802.3AD Aggregator Mode: ");
6368                 switch (agg_mode) {
6369                 case AGG_BANDWIDTH:
6370                         printf("bandwidth");
6371                         break;
6372                 case AGG_STABLE:
6373                         printf("stable");
6374                         break;
6375                 case AGG_COUNT:
6376                         printf("count");
6377                         break;
6378                 }
6379                 printf("\n");
6380         }
6381
6382         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6383
6384         if (num_slaves < 0) {
6385                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6386                         port_id);
6387                 return;
6388         }
6389         if (num_slaves > 0) {
6390                 printf("\tSlaves (%d): [", num_slaves);
6391                 for (i = 0; i < num_slaves - 1; i++)
6392                         printf("%d ", slaves[i]);
6393
6394                 printf("%d]\n", slaves[num_slaves - 1]);
6395         } else {
6396                 printf("\tSlaves: []\n");
6397
6398         }
6399
6400         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6401                         RTE_MAX_ETHPORTS);
6402
6403         if (num_active_slaves < 0) {
6404                 fprintf(stderr,
6405                         "\tFailed to get active slave list for port = %d\n",
6406                         port_id);
6407                 return;
6408         }
6409         if (num_active_slaves > 0) {
6410                 printf("\tActive Slaves (%d): [", num_active_slaves);
6411                 for (i = 0; i < num_active_slaves - 1; i++)
6412                         printf("%d ", slaves[i]);
6413
6414                 printf("%d]\n", slaves[num_active_slaves - 1]);
6415
6416         } else {
6417                 printf("\tActive Slaves: []\n");
6418
6419         }
6420
6421         primary_id = rte_eth_bond_primary_get(port_id);
6422         if (primary_id < 0) {
6423                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6424                         port_id);
6425                 return;
6426         } else
6427                 printf("\tPrimary: [%d]\n", primary_id);
6428
6429 }
6430
6431 cmdline_parse_token_string_t cmd_showbonding_config_show =
6432 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6433                 show, "show");
6434 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6435 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6436                 bonding, "bonding");
6437 cmdline_parse_token_string_t cmd_showbonding_config_config =
6438 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6439                 config, "config");
6440 cmdline_parse_token_num_t cmd_showbonding_config_port =
6441 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6442                 port_id, RTE_UINT16);
6443
6444 cmdline_parse_inst_t cmd_show_bonding_config = {
6445                 .f = cmd_show_bonding_config_parsed,
6446                 .help_str = "show bonding config <port_id>: "
6447                         "Show the bonding config for port_id",
6448                 .data = NULL,
6449                 .tokens = {
6450                                 (void *)&cmd_showbonding_config_show,
6451                                 (void *)&cmd_showbonding_config_bonding,
6452                                 (void *)&cmd_showbonding_config_config,
6453                                 (void *)&cmd_showbonding_config_port,
6454                                 NULL
6455                 }
6456 };
6457
6458 /* *** SET BONDING PRIMARY *** */
6459 struct cmd_set_bonding_primary_result {
6460         cmdline_fixed_string_t set;
6461         cmdline_fixed_string_t bonding;
6462         cmdline_fixed_string_t primary;
6463         portid_t slave_id;
6464         portid_t port_id;
6465 };
6466
6467 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6468                 __rte_unused  struct cmdline *cl,
6469                 __rte_unused void *data)
6470 {
6471         struct cmd_set_bonding_primary_result *res = parsed_result;
6472         portid_t master_port_id = res->port_id;
6473         portid_t slave_port_id = res->slave_id;
6474
6475         /* Set the primary slave for a bonded device. */
6476         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6477                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6478                         master_port_id);
6479                 return;
6480         }
6481         init_port_config();
6482 }
6483
6484 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6485 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6486                 set, "set");
6487 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6488 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6489                 bonding, "bonding");
6490 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6491 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6492                 primary, "primary");
6493 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6494 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6495                 slave_id, RTE_UINT16);
6496 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6497 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6498                 port_id, RTE_UINT16);
6499
6500 cmdline_parse_inst_t cmd_set_bonding_primary = {
6501                 .f = cmd_set_bonding_primary_parsed,
6502                 .help_str = "set bonding primary <slave_id> <port_id>: "
6503                         "Set the primary slave for port_id",
6504                 .data = NULL,
6505                 .tokens = {
6506                                 (void *)&cmd_setbonding_primary_set,
6507                                 (void *)&cmd_setbonding_primary_bonding,
6508                                 (void *)&cmd_setbonding_primary_primary,
6509                                 (void *)&cmd_setbonding_primary_slave,
6510                                 (void *)&cmd_setbonding_primary_port,
6511                                 NULL
6512                 }
6513 };
6514
6515 /* *** ADD SLAVE *** */
6516 struct cmd_add_bonding_slave_result {
6517         cmdline_fixed_string_t add;
6518         cmdline_fixed_string_t bonding;
6519         cmdline_fixed_string_t slave;
6520         portid_t slave_id;
6521         portid_t port_id;
6522 };
6523
6524 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6525                 __rte_unused  struct cmdline *cl,
6526                 __rte_unused void *data)
6527 {
6528         struct cmd_add_bonding_slave_result *res = parsed_result;
6529         portid_t master_port_id = res->port_id;
6530         portid_t slave_port_id = res->slave_id;
6531
6532         /* add the slave for a bonded device. */
6533         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6534                 fprintf(stderr,
6535                         "\t Failed to add slave %d to master port = %d.\n",
6536                         slave_port_id, master_port_id);
6537                 return;
6538         }
6539         init_port_config();
6540         set_port_slave_flag(slave_port_id);
6541 }
6542
6543 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6544 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6545                 add, "add");
6546 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6547 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6548                 bonding, "bonding");
6549 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6550 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6551                 slave, "slave");
6552 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6553 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6554                 slave_id, RTE_UINT16);
6555 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6556 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6557                 port_id, RTE_UINT16);
6558
6559 cmdline_parse_inst_t cmd_add_bonding_slave = {
6560                 .f = cmd_add_bonding_slave_parsed,
6561                 .help_str = "add bonding slave <slave_id> <port_id>: "
6562                         "Add a slave device to a bonded device",
6563                 .data = NULL,
6564                 .tokens = {
6565                                 (void *)&cmd_addbonding_slave_add,
6566                                 (void *)&cmd_addbonding_slave_bonding,
6567                                 (void *)&cmd_addbonding_slave_slave,
6568                                 (void *)&cmd_addbonding_slave_slaveid,
6569                                 (void *)&cmd_addbonding_slave_port,
6570                                 NULL
6571                 }
6572 };
6573
6574 /* *** REMOVE SLAVE *** */
6575 struct cmd_remove_bonding_slave_result {
6576         cmdline_fixed_string_t remove;
6577         cmdline_fixed_string_t bonding;
6578         cmdline_fixed_string_t slave;
6579         portid_t slave_id;
6580         portid_t port_id;
6581 };
6582
6583 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6584                 __rte_unused  struct cmdline *cl,
6585                 __rte_unused void *data)
6586 {
6587         struct cmd_remove_bonding_slave_result *res = parsed_result;
6588         portid_t master_port_id = res->port_id;
6589         portid_t slave_port_id = res->slave_id;
6590
6591         /* remove the slave from a bonded device. */
6592         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6593                 fprintf(stderr,
6594                         "\t Failed to remove slave %d from master port = %d.\n",
6595                         slave_port_id, master_port_id);
6596                 return;
6597         }
6598         init_port_config();
6599         clear_port_slave_flag(slave_port_id);
6600 }
6601
6602 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6603                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6604                                 remove, "remove");
6605 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6606                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6607                                 bonding, "bonding");
6608 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6609                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6610                                 slave, "slave");
6611 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6612                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6613                                 slave_id, RTE_UINT16);
6614 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6615                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6616                                 port_id, RTE_UINT16);
6617
6618 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6619                 .f = cmd_remove_bonding_slave_parsed,
6620                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6621                         "Remove a slave device from a bonded device",
6622                 .data = NULL,
6623                 .tokens = {
6624                                 (void *)&cmd_removebonding_slave_remove,
6625                                 (void *)&cmd_removebonding_slave_bonding,
6626                                 (void *)&cmd_removebonding_slave_slave,
6627                                 (void *)&cmd_removebonding_slave_slaveid,
6628                                 (void *)&cmd_removebonding_slave_port,
6629                                 NULL
6630                 }
6631 };
6632
6633 /* *** CREATE BONDED DEVICE *** */
6634 struct cmd_create_bonded_device_result {
6635         cmdline_fixed_string_t create;
6636         cmdline_fixed_string_t bonded;
6637         cmdline_fixed_string_t device;
6638         uint8_t mode;
6639         uint8_t socket;
6640 };
6641
6642 static int bond_dev_num = 0;
6643
6644 static void cmd_create_bonded_device_parsed(void *parsed_result,
6645                 __rte_unused  struct cmdline *cl,
6646                 __rte_unused void *data)
6647 {
6648         struct cmd_create_bonded_device_result *res = parsed_result;
6649         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6650         int port_id;
6651         int ret;
6652
6653         if (test_done == 0) {
6654                 fprintf(stderr, "Please stop forwarding first\n");
6655                 return;
6656         }
6657
6658         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6659                         bond_dev_num++);
6660
6661         /* Create a new bonded device. */
6662         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6663         if (port_id < 0) {
6664                 fprintf(stderr, "\t Failed to create bonded device.\n");
6665                 return;
6666         } else {
6667                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6668                                 port_id);
6669
6670                 /* Update number of ports */
6671                 nb_ports = rte_eth_dev_count_avail();
6672                 reconfig(port_id, res->socket);
6673                 ret = rte_eth_promiscuous_enable(port_id);
6674                 if (ret != 0)
6675                         fprintf(stderr,
6676                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6677                                 port_id, rte_strerror(-ret));
6678
6679                 ports[port_id].bond_flag = 1;
6680                 ports[port_id].need_setup = 0;
6681                 ports[port_id].port_status = RTE_PORT_STOPPED;
6682         }
6683
6684 }
6685
6686 cmdline_parse_token_string_t cmd_createbonded_device_create =
6687                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6688                                 create, "create");
6689 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6690                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6691                                 bonded, "bonded");
6692 cmdline_parse_token_string_t cmd_createbonded_device_device =
6693                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6694                                 device, "device");
6695 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6696                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6697                                 mode, RTE_UINT8);
6698 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6699                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6700                                 socket, RTE_UINT8);
6701
6702 cmdline_parse_inst_t cmd_create_bonded_device = {
6703                 .f = cmd_create_bonded_device_parsed,
6704                 .help_str = "create bonded device <mode> <socket>: "
6705                         "Create a new bonded device with specific bonding mode and socket",
6706                 .data = NULL,
6707                 .tokens = {
6708                                 (void *)&cmd_createbonded_device_create,
6709                                 (void *)&cmd_createbonded_device_bonded,
6710                                 (void *)&cmd_createbonded_device_device,
6711                                 (void *)&cmd_createbonded_device_mode,
6712                                 (void *)&cmd_createbonded_device_socket,
6713                                 NULL
6714                 }
6715 };
6716
6717 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6718 struct cmd_set_bond_mac_addr_result {
6719         cmdline_fixed_string_t set;
6720         cmdline_fixed_string_t bonding;
6721         cmdline_fixed_string_t mac_addr;
6722         uint16_t port_num;
6723         struct rte_ether_addr address;
6724 };
6725
6726 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6727                 __rte_unused  struct cmdline *cl,
6728                 __rte_unused void *data)
6729 {
6730         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6731         int ret;
6732
6733         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6734                 return;
6735
6736         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6737
6738         /* check the return value and print it if is < 0 */
6739         if (ret < 0)
6740                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6741                         strerror(-ret));
6742 }
6743
6744 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6745                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6746 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6747                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6748                                 "bonding");
6749 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6750                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6751                                 "mac_addr");
6752 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6753                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6754                                 port_num, RTE_UINT16);
6755 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6756                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6757
6758 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6759                 .f = cmd_set_bond_mac_addr_parsed,
6760                 .data = (void *) 0,
6761                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6762                 .tokens = {
6763                                 (void *)&cmd_set_bond_mac_addr_set,
6764                                 (void *)&cmd_set_bond_mac_addr_bonding,
6765                                 (void *)&cmd_set_bond_mac_addr_mac,
6766                                 (void *)&cmd_set_bond_mac_addr_portnum,
6767                                 (void *)&cmd_set_bond_mac_addr_addr,
6768                                 NULL
6769                 }
6770 };
6771
6772
6773 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6774 struct cmd_set_bond_mon_period_result {
6775         cmdline_fixed_string_t set;
6776         cmdline_fixed_string_t bonding;
6777         cmdline_fixed_string_t mon_period;
6778         uint16_t port_num;
6779         uint32_t period_ms;
6780 };
6781
6782 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6783                 __rte_unused  struct cmdline *cl,
6784                 __rte_unused void *data)
6785 {
6786         struct cmd_set_bond_mon_period_result *res = parsed_result;
6787         int ret;
6788
6789         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6790
6791         /* check the return value and print it if is < 0 */
6792         if (ret < 0)
6793                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6794                         strerror(-ret));
6795 }
6796
6797 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6798                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6799                                 set, "set");
6800 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6801                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6802                                 bonding, "bonding");
6803 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6804                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6805                                 mon_period,     "mon_period");
6806 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6807                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6808                                 port_num, RTE_UINT16);
6809 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6810                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6811                                 period_ms, RTE_UINT32);
6812
6813 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6814                 .f = cmd_set_bond_mon_period_parsed,
6815                 .data = (void *) 0,
6816                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6817                 .tokens = {
6818                                 (void *)&cmd_set_bond_mon_period_set,
6819                                 (void *)&cmd_set_bond_mon_period_bonding,
6820                                 (void *)&cmd_set_bond_mon_period_mon_period,
6821                                 (void *)&cmd_set_bond_mon_period_portnum,
6822                                 (void *)&cmd_set_bond_mon_period_period_ms,
6823                                 NULL
6824                 }
6825 };
6826
6827
6828
6829 struct cmd_set_bonding_agg_mode_policy_result {
6830         cmdline_fixed_string_t set;
6831         cmdline_fixed_string_t bonding;
6832         cmdline_fixed_string_t agg_mode;
6833         uint16_t port_num;
6834         cmdline_fixed_string_t policy;
6835 };
6836
6837
6838 static void
6839 cmd_set_bonding_agg_mode(void *parsed_result,
6840                 __rte_unused struct cmdline *cl,
6841                 __rte_unused void *data)
6842 {
6843         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6844         uint8_t policy = AGG_BANDWIDTH;
6845
6846         if (!strcmp(res->policy, "bandwidth"))
6847                 policy = AGG_BANDWIDTH;
6848         else if (!strcmp(res->policy, "stable"))
6849                 policy = AGG_STABLE;
6850         else if (!strcmp(res->policy, "count"))
6851                 policy = AGG_COUNT;
6852
6853         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6854 }
6855
6856
6857 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6858         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6859                                 set, "set");
6860 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6861         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6862                                 bonding, "bonding");
6863
6864 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6865         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6866                                 agg_mode, "agg_mode");
6867
6868 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6869         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6870                                 port_num, RTE_UINT16);
6871
6872 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6873         TOKEN_STRING_INITIALIZER(
6874                         struct cmd_set_bonding_balance_xmit_policy_result,
6875                 policy, "stable#bandwidth#count");
6876
6877 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6878         .f = cmd_set_bonding_agg_mode,
6879         .data = (void *) 0,
6880         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6881         .tokens = {
6882                         (void *)&cmd_set_bonding_agg_mode_set,
6883                         (void *)&cmd_set_bonding_agg_mode_bonding,
6884                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6885                         (void *)&cmd_set_bonding_agg_mode_portnum,
6886                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6887                         NULL
6888                 }
6889 };
6890
6891
6892 #endif /* RTE_NET_BOND */
6893
6894 /* *** SET FORWARDING MODE *** */
6895 struct cmd_set_fwd_mode_result {
6896         cmdline_fixed_string_t set;
6897         cmdline_fixed_string_t fwd;
6898         cmdline_fixed_string_t mode;
6899 };
6900
6901 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6902                                     __rte_unused struct cmdline *cl,
6903                                     __rte_unused void *data)
6904 {
6905         struct cmd_set_fwd_mode_result *res = parsed_result;
6906
6907         retry_enabled = 0;
6908         set_pkt_forwarding_mode(res->mode);
6909 }
6910
6911 cmdline_parse_token_string_t cmd_setfwd_set =
6912         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6913 cmdline_parse_token_string_t cmd_setfwd_fwd =
6914         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6915 cmdline_parse_token_string_t cmd_setfwd_mode =
6916         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6917                 "" /* defined at init */);
6918
6919 cmdline_parse_inst_t cmd_set_fwd_mode = {
6920         .f = cmd_set_fwd_mode_parsed,
6921         .data = NULL,
6922         .help_str = NULL, /* defined at init */
6923         .tokens = {
6924                 (void *)&cmd_setfwd_set,
6925                 (void *)&cmd_setfwd_fwd,
6926                 (void *)&cmd_setfwd_mode,
6927                 NULL,
6928         },
6929 };
6930
6931 static void cmd_set_fwd_mode_init(void)
6932 {
6933         char *modes, *c;
6934         static char token[128];
6935         static char help[256];
6936         cmdline_parse_token_string_t *token_struct;
6937
6938         modes = list_pkt_forwarding_modes();
6939         snprintf(help, sizeof(help), "set fwd %s: "
6940                 "Set packet forwarding mode", modes);
6941         cmd_set_fwd_mode.help_str = help;
6942
6943         /* string token separator is # */
6944         for (c = token; *modes != '\0'; modes++)
6945                 if (*modes == '|')
6946                         *c++ = '#';
6947                 else
6948                         *c++ = *modes;
6949         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6950         token_struct->string_data.str = token;
6951 }
6952
6953 /* *** SET RETRY FORWARDING MODE *** */
6954 struct cmd_set_fwd_retry_mode_result {
6955         cmdline_fixed_string_t set;
6956         cmdline_fixed_string_t fwd;
6957         cmdline_fixed_string_t mode;
6958         cmdline_fixed_string_t retry;
6959 };
6960
6961 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6962                             __rte_unused struct cmdline *cl,
6963                             __rte_unused void *data)
6964 {
6965         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6966
6967         retry_enabled = 1;
6968         set_pkt_forwarding_mode(res->mode);
6969 }
6970
6971 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6972         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6973                         set, "set");
6974 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6975         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6976                         fwd, "fwd");
6977 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6978         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6979                         mode,
6980                 "" /* defined at init */);
6981 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6982         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6983                         retry, "retry");
6984
6985 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6986         .f = cmd_set_fwd_retry_mode_parsed,
6987         .data = NULL,
6988         .help_str = NULL, /* defined at init */
6989         .tokens = {
6990                 (void *)&cmd_setfwd_retry_set,
6991                 (void *)&cmd_setfwd_retry_fwd,
6992                 (void *)&cmd_setfwd_retry_mode,
6993                 (void *)&cmd_setfwd_retry_retry,
6994                 NULL,
6995         },
6996 };
6997
6998 static void cmd_set_fwd_retry_mode_init(void)
6999 {
7000         char *modes, *c;
7001         static char token[128];
7002         static char help[256];
7003         cmdline_parse_token_string_t *token_struct;
7004
7005         modes = list_pkt_forwarding_retry_modes();
7006         snprintf(help, sizeof(help), "set fwd %s retry: "
7007                 "Set packet forwarding mode with retry", modes);
7008         cmd_set_fwd_retry_mode.help_str = help;
7009
7010         /* string token separator is # */
7011         for (c = token; *modes != '\0'; modes++)
7012                 if (*modes == '|')
7013                         *c++ = '#';
7014                 else
7015                         *c++ = *modes;
7016         token_struct = (cmdline_parse_token_string_t *)
7017                 cmd_set_fwd_retry_mode.tokens[2];
7018         token_struct->string_data.str = token;
7019 }
7020
7021 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7022 struct cmd_set_burst_tx_retry_result {
7023         cmdline_fixed_string_t set;
7024         cmdline_fixed_string_t burst;
7025         cmdline_fixed_string_t tx;
7026         cmdline_fixed_string_t delay;
7027         uint32_t time;
7028         cmdline_fixed_string_t retry;
7029         uint32_t retry_num;
7030 };
7031
7032 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7033                                         __rte_unused struct cmdline *cl,
7034                                         __rte_unused void *data)
7035 {
7036         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7037
7038         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7039                 && !strcmp(res->tx, "tx")) {
7040                 if (!strcmp(res->delay, "delay"))
7041                         burst_tx_delay_time = res->time;
7042                 if (!strcmp(res->retry, "retry"))
7043                         burst_tx_retry_num = res->retry_num;
7044         }
7045
7046 }
7047
7048 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7049         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7050 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7051         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7052                                  "burst");
7053 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7054         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7055 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7056         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7057 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7058         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7059                                  RTE_UINT32);
7060 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7061         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7062 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7063         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7064                                  RTE_UINT32);
7065
7066 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7067         .f = cmd_set_burst_tx_retry_parsed,
7068         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7069         .tokens = {
7070                 (void *)&cmd_set_burst_tx_retry_set,
7071                 (void *)&cmd_set_burst_tx_retry_burst,
7072                 (void *)&cmd_set_burst_tx_retry_tx,
7073                 (void *)&cmd_set_burst_tx_retry_delay,
7074                 (void *)&cmd_set_burst_tx_retry_time,
7075                 (void *)&cmd_set_burst_tx_retry_retry,
7076                 (void *)&cmd_set_burst_tx_retry_retry_num,
7077                 NULL,
7078         },
7079 };
7080
7081 /* *** SET PROMISC MODE *** */
7082 struct cmd_set_promisc_mode_result {
7083         cmdline_fixed_string_t set;
7084         cmdline_fixed_string_t promisc;
7085         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7086         uint16_t port_num;               /* valid if "allports" argument == 0 */
7087         cmdline_fixed_string_t mode;
7088 };
7089
7090 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7091                                         __rte_unused struct cmdline *cl,
7092                                         void *allports)
7093 {
7094         struct cmd_set_promisc_mode_result *res = parsed_result;
7095         int enable;
7096         portid_t i;
7097
7098         if (!strcmp(res->mode, "on"))
7099                 enable = 1;
7100         else
7101                 enable = 0;
7102
7103         /* all ports */
7104         if (allports) {
7105                 RTE_ETH_FOREACH_DEV(i)
7106                         eth_set_promisc_mode(i, enable);
7107         } else {
7108                 eth_set_promisc_mode(res->port_num, enable);
7109         }
7110 }
7111
7112 cmdline_parse_token_string_t cmd_setpromisc_set =
7113         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7114 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7115         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7116                                  "promisc");
7117 cmdline_parse_token_string_t cmd_setpromisc_portall =
7118         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7119                                  "all");
7120 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7121         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7122                               RTE_UINT16);
7123 cmdline_parse_token_string_t cmd_setpromisc_mode =
7124         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7125                                  "on#off");
7126
7127 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7128         .f = cmd_set_promisc_mode_parsed,
7129         .data = (void *)1,
7130         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7131         .tokens = {
7132                 (void *)&cmd_setpromisc_set,
7133                 (void *)&cmd_setpromisc_promisc,
7134                 (void *)&cmd_setpromisc_portall,
7135                 (void *)&cmd_setpromisc_mode,
7136                 NULL,
7137         },
7138 };
7139
7140 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7141         .f = cmd_set_promisc_mode_parsed,
7142         .data = (void *)0,
7143         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7144         .tokens = {
7145                 (void *)&cmd_setpromisc_set,
7146                 (void *)&cmd_setpromisc_promisc,
7147                 (void *)&cmd_setpromisc_portnum,
7148                 (void *)&cmd_setpromisc_mode,
7149                 NULL,
7150         },
7151 };
7152
7153 /* *** SET ALLMULTI MODE *** */
7154 struct cmd_set_allmulti_mode_result {
7155         cmdline_fixed_string_t set;
7156         cmdline_fixed_string_t allmulti;
7157         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7158         uint16_t port_num;               /* valid if "allports" argument == 0 */
7159         cmdline_fixed_string_t mode;
7160 };
7161
7162 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7163                                         __rte_unused struct cmdline *cl,
7164                                         void *allports)
7165 {
7166         struct cmd_set_allmulti_mode_result *res = parsed_result;
7167         int enable;
7168         portid_t i;
7169
7170         if (!strcmp(res->mode, "on"))
7171                 enable = 1;
7172         else
7173                 enable = 0;
7174
7175         /* all ports */
7176         if (allports) {
7177                 RTE_ETH_FOREACH_DEV(i) {
7178                         eth_set_allmulticast_mode(i, enable);
7179                 }
7180         }
7181         else {
7182                 eth_set_allmulticast_mode(res->port_num, enable);
7183         }
7184 }
7185
7186 cmdline_parse_token_string_t cmd_setallmulti_set =
7187         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7188 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7189         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7190                                  "allmulti");
7191 cmdline_parse_token_string_t cmd_setallmulti_portall =
7192         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7193                                  "all");
7194 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7195         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7196                               RTE_UINT16);
7197 cmdline_parse_token_string_t cmd_setallmulti_mode =
7198         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7199                                  "on#off");
7200
7201 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7202         .f = cmd_set_allmulti_mode_parsed,
7203         .data = (void *)1,
7204         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7205         .tokens = {
7206                 (void *)&cmd_setallmulti_set,
7207                 (void *)&cmd_setallmulti_allmulti,
7208                 (void *)&cmd_setallmulti_portall,
7209                 (void *)&cmd_setallmulti_mode,
7210                 NULL,
7211         },
7212 };
7213
7214 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7215         .f = cmd_set_allmulti_mode_parsed,
7216         .data = (void *)0,
7217         .help_str = "set allmulti <port_id> on|off: "
7218                 "Set allmulti mode on port_id",
7219         .tokens = {
7220                 (void *)&cmd_setallmulti_set,
7221                 (void *)&cmd_setallmulti_allmulti,
7222                 (void *)&cmd_setallmulti_portnum,
7223                 (void *)&cmd_setallmulti_mode,
7224                 NULL,
7225         },
7226 };
7227
7228 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7229 struct cmd_link_flow_ctrl_show {
7230         cmdline_fixed_string_t show;
7231         cmdline_fixed_string_t port;
7232         portid_t port_id;
7233         cmdline_fixed_string_t flow_ctrl;
7234 };
7235
7236 cmdline_parse_token_string_t cmd_lfc_show_show =
7237         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7238                                 show, "show");
7239 cmdline_parse_token_string_t cmd_lfc_show_port =
7240         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7241                                 port, "port");
7242 cmdline_parse_token_num_t cmd_lfc_show_portid =
7243         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7244                                 port_id, RTE_UINT16);
7245 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7246         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7247                                 flow_ctrl, "flow_ctrl");
7248
7249 static void
7250 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7251                               __rte_unused struct cmdline *cl,
7252                               __rte_unused void *data)
7253 {
7254         struct cmd_link_flow_ctrl_show *res = parsed_result;
7255         static const char *info_border = "*********************";
7256         struct rte_eth_fc_conf fc_conf;
7257         bool rx_fc_en = false;
7258         bool tx_fc_en = false;
7259         int ret;
7260
7261         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7262         if (ret != 0) {
7263                 fprintf(stderr,
7264                         "Failed to get current flow ctrl information: err = %d\n",
7265                         ret);
7266                 return;
7267         }
7268
7269         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7270                 rx_fc_en = true;
7271         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7272                 tx_fc_en = true;
7273
7274         printf("\n%s Flow control infos for port %-2d %s\n",
7275                 info_border, res->port_id, info_border);
7276         printf("FC mode:\n");
7277         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7278         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7279         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7280         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7281         printf("High waterline: 0x%x\n", fc_conf.high_water);
7282         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7283         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7284         printf("Forward MAC control frames: %s\n",
7285                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7286         printf("\n%s**************   End  ***********%s\n",
7287                 info_border, info_border);
7288 }
7289
7290 cmdline_parse_inst_t cmd_link_flow_control_show = {
7291         .f = cmd_link_flow_ctrl_show_parsed,
7292         .data = NULL,
7293         .help_str = "show port <port_id> flow_ctrl",
7294         .tokens = {
7295                 (void *)&cmd_lfc_show_show,
7296                 (void *)&cmd_lfc_show_port,
7297                 (void *)&cmd_lfc_show_portid,
7298                 (void *)&cmd_lfc_show_flow_ctrl,
7299                 NULL,
7300         },
7301 };
7302
7303 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7304 struct cmd_link_flow_ctrl_set_result {
7305         cmdline_fixed_string_t set;
7306         cmdline_fixed_string_t flow_ctrl;
7307         cmdline_fixed_string_t rx;
7308         cmdline_fixed_string_t rx_lfc_mode;
7309         cmdline_fixed_string_t tx;
7310         cmdline_fixed_string_t tx_lfc_mode;
7311         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7312         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7313         cmdline_fixed_string_t autoneg_str;
7314         cmdline_fixed_string_t autoneg;
7315         cmdline_fixed_string_t hw_str;
7316         uint32_t high_water;
7317         cmdline_fixed_string_t lw_str;
7318         uint32_t low_water;
7319         cmdline_fixed_string_t pt_str;
7320         uint16_t pause_time;
7321         cmdline_fixed_string_t xon_str;
7322         uint16_t send_xon;
7323         portid_t port_id;
7324 };
7325
7326 cmdline_parse_token_string_t cmd_lfc_set_set =
7327         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7328                                 set, "set");
7329 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7330         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7331                                 flow_ctrl, "flow_ctrl");
7332 cmdline_parse_token_string_t cmd_lfc_set_rx =
7333         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7334                                 rx, "rx");
7335 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7336         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7337                                 rx_lfc_mode, "on#off");
7338 cmdline_parse_token_string_t cmd_lfc_set_tx =
7339         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7340                                 tx, "tx");
7341 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7342         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7343                                 tx_lfc_mode, "on#off");
7344 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7345         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7346                                 hw_str, "high_water");
7347 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7348         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7349                                 high_water, RTE_UINT32);
7350 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7351         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7352                                 lw_str, "low_water");
7353 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7354         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7355                                 low_water, RTE_UINT32);
7356 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7357         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7358                                 pt_str, "pause_time");
7359 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7360         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7361                                 pause_time, RTE_UINT16);
7362 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7363         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7364                                 xon_str, "send_xon");
7365 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7366         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7367                                 send_xon, RTE_UINT16);
7368 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7369         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7370                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7371 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7372         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7373                                 mac_ctrl_frame_fwd_mode, "on#off");
7374 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7375         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7376                                 autoneg_str, "autoneg");
7377 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7378         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7379                                 autoneg, "on#off");
7380 cmdline_parse_token_num_t cmd_lfc_set_portid =
7381         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7382                                 port_id, RTE_UINT16);
7383
7384 /* forward declaration */
7385 static void
7386 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7387                               void *data);
7388
7389 cmdline_parse_inst_t cmd_link_flow_control_set = {
7390         .f = cmd_link_flow_ctrl_set_parsed,
7391         .data = NULL,
7392         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7393                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7394                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7395         .tokens = {
7396                 (void *)&cmd_lfc_set_set,
7397                 (void *)&cmd_lfc_set_flow_ctrl,
7398                 (void *)&cmd_lfc_set_rx,
7399                 (void *)&cmd_lfc_set_rx_mode,
7400                 (void *)&cmd_lfc_set_tx,
7401                 (void *)&cmd_lfc_set_tx_mode,
7402                 (void *)&cmd_lfc_set_high_water,
7403                 (void *)&cmd_lfc_set_low_water,
7404                 (void *)&cmd_lfc_set_pause_time,
7405                 (void *)&cmd_lfc_set_send_xon,
7406                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7407                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7408                 (void *)&cmd_lfc_set_autoneg_str,
7409                 (void *)&cmd_lfc_set_autoneg,
7410                 (void *)&cmd_lfc_set_portid,
7411                 NULL,
7412         },
7413 };
7414
7415 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7416         .f = cmd_link_flow_ctrl_set_parsed,
7417         .data = (void *)&cmd_link_flow_control_set_rx,
7418         .help_str = "set flow_ctrl rx on|off <port_id>: "
7419                 "Change rx flow control parameter",
7420         .tokens = {
7421                 (void *)&cmd_lfc_set_set,
7422                 (void *)&cmd_lfc_set_flow_ctrl,
7423                 (void *)&cmd_lfc_set_rx,
7424                 (void *)&cmd_lfc_set_rx_mode,
7425                 (void *)&cmd_lfc_set_portid,
7426                 NULL,
7427         },
7428 };
7429
7430 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7431         .f = cmd_link_flow_ctrl_set_parsed,
7432         .data = (void *)&cmd_link_flow_control_set_tx,
7433         .help_str = "set flow_ctrl tx on|off <port_id>: "
7434                 "Change tx flow control parameter",
7435         .tokens = {
7436                 (void *)&cmd_lfc_set_set,
7437                 (void *)&cmd_lfc_set_flow_ctrl,
7438                 (void *)&cmd_lfc_set_tx,
7439                 (void *)&cmd_lfc_set_tx_mode,
7440                 (void *)&cmd_lfc_set_portid,
7441                 NULL,
7442         },
7443 };
7444
7445 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7446         .f = cmd_link_flow_ctrl_set_parsed,
7447         .data = (void *)&cmd_link_flow_control_set_hw,
7448         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7449                 "Change high water flow control parameter",
7450         .tokens = {
7451                 (void *)&cmd_lfc_set_set,
7452                 (void *)&cmd_lfc_set_flow_ctrl,
7453                 (void *)&cmd_lfc_set_high_water_str,
7454                 (void *)&cmd_lfc_set_high_water,
7455                 (void *)&cmd_lfc_set_portid,
7456                 NULL,
7457         },
7458 };
7459
7460 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7461         .f = cmd_link_flow_ctrl_set_parsed,
7462         .data = (void *)&cmd_link_flow_control_set_lw,
7463         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7464                 "Change low water flow control parameter",
7465         .tokens = {
7466                 (void *)&cmd_lfc_set_set,
7467                 (void *)&cmd_lfc_set_flow_ctrl,
7468                 (void *)&cmd_lfc_set_low_water_str,
7469                 (void *)&cmd_lfc_set_low_water,
7470                 (void *)&cmd_lfc_set_portid,
7471                 NULL,
7472         },
7473 };
7474
7475 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7476         .f = cmd_link_flow_ctrl_set_parsed,
7477         .data = (void *)&cmd_link_flow_control_set_pt,
7478         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7479                 "Change pause time flow control parameter",
7480         .tokens = {
7481                 (void *)&cmd_lfc_set_set,
7482                 (void *)&cmd_lfc_set_flow_ctrl,
7483                 (void *)&cmd_lfc_set_pause_time_str,
7484                 (void *)&cmd_lfc_set_pause_time,
7485                 (void *)&cmd_lfc_set_portid,
7486                 NULL,
7487         },
7488 };
7489
7490 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7491         .f = cmd_link_flow_ctrl_set_parsed,
7492         .data = (void *)&cmd_link_flow_control_set_xon,
7493         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7494                 "Change send_xon flow control parameter",
7495         .tokens = {
7496                 (void *)&cmd_lfc_set_set,
7497                 (void *)&cmd_lfc_set_flow_ctrl,
7498                 (void *)&cmd_lfc_set_send_xon_str,
7499                 (void *)&cmd_lfc_set_send_xon,
7500                 (void *)&cmd_lfc_set_portid,
7501                 NULL,
7502         },
7503 };
7504
7505 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7506         .f = cmd_link_flow_ctrl_set_parsed,
7507         .data = (void *)&cmd_link_flow_control_set_macfwd,
7508         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7509                 "Change mac ctrl fwd flow control parameter",
7510         .tokens = {
7511                 (void *)&cmd_lfc_set_set,
7512                 (void *)&cmd_lfc_set_flow_ctrl,
7513                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7514                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7515                 (void *)&cmd_lfc_set_portid,
7516                 NULL,
7517         },
7518 };
7519
7520 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7521         .f = cmd_link_flow_ctrl_set_parsed,
7522         .data = (void *)&cmd_link_flow_control_set_autoneg,
7523         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7524                 "Change autoneg flow control parameter",
7525         .tokens = {
7526                 (void *)&cmd_lfc_set_set,
7527                 (void *)&cmd_lfc_set_flow_ctrl,
7528                 (void *)&cmd_lfc_set_autoneg_str,
7529                 (void *)&cmd_lfc_set_autoneg,
7530                 (void *)&cmd_lfc_set_portid,
7531                 NULL,
7532         },
7533 };
7534
7535 static void
7536 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7537                               __rte_unused struct cmdline *cl,
7538                               void *data)
7539 {
7540         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7541         cmdline_parse_inst_t *cmd = data;
7542         struct rte_eth_fc_conf fc_conf;
7543         int rx_fc_en = 0;
7544         int tx_fc_en = 0;
7545         int ret;
7546
7547         /*
7548          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7549          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7550          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7551          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7552          */
7553         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7554                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7555         };
7556
7557         /* Partial command line, retrieve current configuration */
7558         if (cmd) {
7559                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7560                 if (ret != 0) {
7561                         fprintf(stderr,
7562                                 "cannot get current flow ctrl parameters, return code = %d\n",
7563                                 ret);
7564                         return;
7565                 }
7566
7567                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7568                     (fc_conf.mode == RTE_ETH_FC_FULL))
7569                         rx_fc_en = 1;
7570                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7571                     (fc_conf.mode == RTE_ETH_FC_FULL))
7572                         tx_fc_en = 1;
7573         }
7574
7575         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7576                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7577
7578         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7579                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7580
7581         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7582
7583         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7584                 fc_conf.high_water = res->high_water;
7585
7586         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7587                 fc_conf.low_water = res->low_water;
7588
7589         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7590                 fc_conf.pause_time = res->pause_time;
7591
7592         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7593                 fc_conf.send_xon = res->send_xon;
7594
7595         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7596                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7597                         fc_conf.mac_ctrl_frame_fwd = 1;
7598                 else
7599                         fc_conf.mac_ctrl_frame_fwd = 0;
7600         }
7601
7602         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7603                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7604
7605         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7606         if (ret != 0)
7607                 fprintf(stderr,
7608                         "bad flow control parameter, return code = %d\n",
7609                         ret);
7610 }
7611
7612 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7613 struct cmd_priority_flow_ctrl_set_result {
7614         cmdline_fixed_string_t set;
7615         cmdline_fixed_string_t pfc_ctrl;
7616         cmdline_fixed_string_t rx;
7617         cmdline_fixed_string_t rx_pfc_mode;
7618         cmdline_fixed_string_t tx;
7619         cmdline_fixed_string_t tx_pfc_mode;
7620         uint32_t high_water;
7621         uint32_t low_water;
7622         uint16_t pause_time;
7623         uint8_t  priority;
7624         portid_t port_id;
7625 };
7626
7627 static void
7628 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7629                        __rte_unused struct cmdline *cl,
7630                        __rte_unused void *data)
7631 {
7632         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7633         struct rte_eth_pfc_conf pfc_conf;
7634         int rx_fc_enable, tx_fc_enable;
7635         int ret;
7636
7637         /*
7638          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7639          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7640          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7641          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7642          */
7643         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7644                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7645         };
7646
7647         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7648         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7649         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7650         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7651         pfc_conf.fc.high_water = res->high_water;
7652         pfc_conf.fc.low_water  = res->low_water;
7653         pfc_conf.fc.pause_time = res->pause_time;
7654         pfc_conf.priority      = res->priority;
7655
7656         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7657         if (ret != 0)
7658                 fprintf(stderr,
7659                         "bad priority flow control parameter, return code = %d\n",
7660                         ret);
7661 }
7662
7663 cmdline_parse_token_string_t cmd_pfc_set_set =
7664         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7665                                 set, "set");
7666 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7667         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7668                                 pfc_ctrl, "pfc_ctrl");
7669 cmdline_parse_token_string_t cmd_pfc_set_rx =
7670         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7671                                 rx, "rx");
7672 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7673         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7674                                 rx_pfc_mode, "on#off");
7675 cmdline_parse_token_string_t cmd_pfc_set_tx =
7676         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7677                                 tx, "tx");
7678 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7679         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7680                                 tx_pfc_mode, "on#off");
7681 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7682         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7683                                 high_water, RTE_UINT32);
7684 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7685         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7686                                 low_water, RTE_UINT32);
7687 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7688         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7689                                 pause_time, RTE_UINT16);
7690 cmdline_parse_token_num_t cmd_pfc_set_priority =
7691         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7692                                 priority, RTE_UINT8);
7693 cmdline_parse_token_num_t cmd_pfc_set_portid =
7694         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7695                                 port_id, RTE_UINT16);
7696
7697 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7698         .f = cmd_priority_flow_ctrl_set_parsed,
7699         .data = NULL,
7700         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7701                 "<pause_time> <priority> <port_id>: "
7702                 "Configure the Ethernet priority flow control",
7703         .tokens = {
7704                 (void *)&cmd_pfc_set_set,
7705                 (void *)&cmd_pfc_set_flow_ctrl,
7706                 (void *)&cmd_pfc_set_rx,
7707                 (void *)&cmd_pfc_set_rx_mode,
7708                 (void *)&cmd_pfc_set_tx,
7709                 (void *)&cmd_pfc_set_tx_mode,
7710                 (void *)&cmd_pfc_set_high_water,
7711                 (void *)&cmd_pfc_set_low_water,
7712                 (void *)&cmd_pfc_set_pause_time,
7713                 (void *)&cmd_pfc_set_priority,
7714                 (void *)&cmd_pfc_set_portid,
7715                 NULL,
7716         },
7717 };
7718
7719 struct cmd_queue_priority_flow_ctrl_set_result {
7720         cmdline_fixed_string_t set;
7721         cmdline_fixed_string_t pfc_queue_ctrl;
7722         portid_t port_id;
7723         cmdline_fixed_string_t rx;
7724         cmdline_fixed_string_t rx_pfc_mode;
7725         uint16_t tx_qid;
7726         uint8_t  tx_tc;
7727         cmdline_fixed_string_t tx;
7728         cmdline_fixed_string_t tx_pfc_mode;
7729         uint16_t rx_qid;
7730         uint8_t  rx_tc;
7731         uint16_t pause_time;
7732 };
7733
7734 static void
7735 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7736                                         __rte_unused struct cmdline *cl,
7737                                         __rte_unused void *data)
7738 {
7739         struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7740         struct rte_eth_pfc_queue_conf pfc_queue_conf;
7741         int rx_fc_enable, tx_fc_enable;
7742         int ret;
7743
7744         /*
7745          * Rx on/off, flow control is enabled/disabled on RX side. This can
7746          * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7747          * side. Tx on/off, flow control is enabled/disabled on TX side. This
7748          * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7749          * the Tx side.
7750          */
7751         static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7752                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7753                 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7754         };
7755
7756         memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7757         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7758         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7759         pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7760         pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7761         pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7762         pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7763         pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7764         pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7765
7766         ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7767                                                              &pfc_queue_conf);
7768         if (ret != 0) {
7769                 fprintf(stderr,
7770                         "bad queue priority flow control parameter, rc = %d\n",
7771                         ret);
7772         }
7773 }
7774
7775 cmdline_parse_token_string_t cmd_q_pfc_set_set =
7776         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7777                                 set, "set");
7778 cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7779         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7780                                 pfc_queue_ctrl, "pfc_queue_ctrl");
7781 cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7782         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7783                                 port_id, RTE_UINT16);
7784 cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7785         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7786                                 rx, "rx");
7787 cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7788         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7789                                 rx_pfc_mode, "on#off");
7790 cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7791         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7792                                 tx_qid, RTE_UINT16);
7793 cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7794         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7795                                 tx_tc, RTE_UINT8);
7796 cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7797         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7798                                 tx, "tx");
7799 cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7800         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7801                                 tx_pfc_mode, "on#off");
7802 cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7803         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7804                                 rx_qid, RTE_UINT16);
7805 cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7806         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7807                                 rx_tc, RTE_UINT8);
7808 cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7809         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7810                                 pause_time, RTE_UINT16);
7811
7812 cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7813         .f = cmd_queue_priority_flow_ctrl_set_parsed,
7814         .data = NULL,
7815         .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7816                 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7817                 "Configure the Ethernet queue priority flow control",
7818         .tokens = {
7819                 (void *)&cmd_q_pfc_set_set,
7820                 (void *)&cmd_q_pfc_set_flow_ctrl,
7821                 (void *)&cmd_q_pfc_set_portid,
7822                 (void *)&cmd_q_pfc_set_rx,
7823                 (void *)&cmd_q_pfc_set_rx_mode,
7824                 (void *)&cmd_q_pfc_set_tx_qid,
7825                 (void *)&cmd_q_pfc_set_tx_tc,
7826                 (void *)&cmd_q_pfc_set_tx,
7827                 (void *)&cmd_q_pfc_set_tx_mode,
7828                 (void *)&cmd_q_pfc_set_rx_qid,
7829                 (void *)&cmd_q_pfc_set_rx_tc,
7830                 (void *)&cmd_q_pfc_set_pause_time,
7831                 NULL,
7832         },
7833 };
7834
7835 /* *** RESET CONFIGURATION *** */
7836 struct cmd_reset_result {
7837         cmdline_fixed_string_t reset;
7838         cmdline_fixed_string_t def;
7839 };
7840
7841 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7842                              struct cmdline *cl,
7843                              __rte_unused void *data)
7844 {
7845         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7846         set_def_fwd_config();
7847 }
7848
7849 cmdline_parse_token_string_t cmd_reset_set =
7850         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7851 cmdline_parse_token_string_t cmd_reset_def =
7852         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7853                                  "default");
7854
7855 cmdline_parse_inst_t cmd_reset = {
7856         .f = cmd_reset_parsed,
7857         .data = NULL,
7858         .help_str = "set default: Reset default forwarding configuration",
7859         .tokens = {
7860                 (void *)&cmd_reset_set,
7861                 (void *)&cmd_reset_def,
7862                 NULL,
7863         },
7864 };
7865
7866 /* *** START FORWARDING *** */
7867 struct cmd_start_result {
7868         cmdline_fixed_string_t start;
7869 };
7870
7871 cmdline_parse_token_string_t cmd_start_start =
7872         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7873
7874 static void cmd_start_parsed(__rte_unused void *parsed_result,
7875                              __rte_unused struct cmdline *cl,
7876                              __rte_unused void *data)
7877 {
7878         start_packet_forwarding(0);
7879 }
7880
7881 cmdline_parse_inst_t cmd_start = {
7882         .f = cmd_start_parsed,
7883         .data = NULL,
7884         .help_str = "start: Start packet forwarding",
7885         .tokens = {
7886                 (void *)&cmd_start_start,
7887                 NULL,
7888         },
7889 };
7890
7891 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7892 struct cmd_start_tx_first_result {
7893         cmdline_fixed_string_t start;
7894         cmdline_fixed_string_t tx_first;
7895 };
7896
7897 static void
7898 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7899                           __rte_unused struct cmdline *cl,
7900                           __rte_unused void *data)
7901 {
7902         start_packet_forwarding(1);
7903 }
7904
7905 cmdline_parse_token_string_t cmd_start_tx_first_start =
7906         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7907                                  "start");
7908 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7909         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7910                                  tx_first, "tx_first");
7911
7912 cmdline_parse_inst_t cmd_start_tx_first = {
7913         .f = cmd_start_tx_first_parsed,
7914         .data = NULL,
7915         .help_str = "start tx_first: Start packet forwarding, "
7916                 "after sending 1 burst of packets",
7917         .tokens = {
7918                 (void *)&cmd_start_tx_first_start,
7919                 (void *)&cmd_start_tx_first_tx_first,
7920                 NULL,
7921         },
7922 };
7923
7924 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7925 struct cmd_start_tx_first_n_result {
7926         cmdline_fixed_string_t start;
7927         cmdline_fixed_string_t tx_first;
7928         uint32_t tx_num;
7929 };
7930
7931 static void
7932 cmd_start_tx_first_n_parsed(void *parsed_result,
7933                           __rte_unused struct cmdline *cl,
7934                           __rte_unused void *data)
7935 {
7936         struct cmd_start_tx_first_n_result *res = parsed_result;
7937
7938         start_packet_forwarding(res->tx_num);
7939 }
7940
7941 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7942         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7943                         start, "start");
7944 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7945         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7946                         tx_first, "tx_first");
7947 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7948         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7949                         tx_num, RTE_UINT32);
7950
7951 cmdline_parse_inst_t cmd_start_tx_first_n = {
7952         .f = cmd_start_tx_first_n_parsed,
7953         .data = NULL,
7954         .help_str = "start tx_first <num>: "
7955                 "packet forwarding, after sending <num> bursts of packets",
7956         .tokens = {
7957                 (void *)&cmd_start_tx_first_n_start,
7958                 (void *)&cmd_start_tx_first_n_tx_first,
7959                 (void *)&cmd_start_tx_first_n_tx_num,
7960                 NULL,
7961         },
7962 };
7963
7964 /* *** SET LINK UP *** */
7965 struct cmd_set_link_up_result {
7966         cmdline_fixed_string_t set;
7967         cmdline_fixed_string_t link_up;
7968         cmdline_fixed_string_t port;
7969         portid_t port_id;
7970 };
7971
7972 cmdline_parse_token_string_t cmd_set_link_up_set =
7973         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7974 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7975         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7976                                 "link-up");
7977 cmdline_parse_token_string_t cmd_set_link_up_port =
7978         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7979 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7980         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7981                                 RTE_UINT16);
7982
7983 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7984                              __rte_unused struct cmdline *cl,
7985                              __rte_unused void *data)
7986 {
7987         struct cmd_set_link_up_result *res = parsed_result;
7988         dev_set_link_up(res->port_id);
7989 }
7990
7991 cmdline_parse_inst_t cmd_set_link_up = {
7992         .f = cmd_set_link_up_parsed,
7993         .data = NULL,
7994         .help_str = "set link-up port <port id>",
7995         .tokens = {
7996                 (void *)&cmd_set_link_up_set,
7997                 (void *)&cmd_set_link_up_link_up,
7998                 (void *)&cmd_set_link_up_port,
7999                 (void *)&cmd_set_link_up_port_id,
8000                 NULL,
8001         },
8002 };
8003
8004 /* *** SET LINK DOWN *** */
8005 struct cmd_set_link_down_result {
8006         cmdline_fixed_string_t set;
8007         cmdline_fixed_string_t link_down;
8008         cmdline_fixed_string_t port;
8009         portid_t port_id;
8010 };
8011
8012 cmdline_parse_token_string_t cmd_set_link_down_set =
8013         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8014 cmdline_parse_token_string_t cmd_set_link_down_link_down =
8015         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8016                                 "link-down");
8017 cmdline_parse_token_string_t cmd_set_link_down_port =
8018         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8019 cmdline_parse_token_num_t cmd_set_link_down_port_id =
8020         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8021                                 RTE_UINT16);
8022
8023 static void cmd_set_link_down_parsed(
8024                                 __rte_unused void *parsed_result,
8025                                 __rte_unused struct cmdline *cl,
8026                                 __rte_unused void *data)
8027 {
8028         struct cmd_set_link_down_result *res = parsed_result;
8029         dev_set_link_down(res->port_id);
8030 }
8031
8032 cmdline_parse_inst_t cmd_set_link_down = {
8033         .f = cmd_set_link_down_parsed,
8034         .data = NULL,
8035         .help_str = "set link-down port <port id>",
8036         .tokens = {
8037                 (void *)&cmd_set_link_down_set,
8038                 (void *)&cmd_set_link_down_link_down,
8039                 (void *)&cmd_set_link_down_port,
8040                 (void *)&cmd_set_link_down_port_id,
8041                 NULL,
8042         },
8043 };
8044
8045 /* *** SHOW CFG *** */
8046 struct cmd_showcfg_result {
8047         cmdline_fixed_string_t show;
8048         cmdline_fixed_string_t cfg;
8049         cmdline_fixed_string_t what;
8050 };
8051
8052 static void cmd_showcfg_parsed(void *parsed_result,
8053                                __rte_unused struct cmdline *cl,
8054                                __rte_unused void *data)
8055 {
8056         struct cmd_showcfg_result *res = parsed_result;
8057         if (!strcmp(res->what, "rxtx"))
8058                 rxtx_config_display();
8059         else if (!strcmp(res->what, "cores"))
8060                 fwd_lcores_config_display();
8061         else if (!strcmp(res->what, "fwd"))
8062                 pkt_fwd_config_display(&cur_fwd_config);
8063         else if (!strcmp(res->what, "rxoffs"))
8064                 show_rx_pkt_offsets();
8065         else if (!strcmp(res->what, "rxpkts"))
8066                 show_rx_pkt_segments();
8067         else if (!strcmp(res->what, "txpkts"))
8068                 show_tx_pkt_segments();
8069         else if (!strcmp(res->what, "txtimes"))
8070                 show_tx_pkt_times();
8071 }
8072
8073 cmdline_parse_token_string_t cmd_showcfg_show =
8074         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8075 cmdline_parse_token_string_t cmd_showcfg_port =
8076         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8077 cmdline_parse_token_string_t cmd_showcfg_what =
8078         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8079                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8080
8081 cmdline_parse_inst_t cmd_showcfg = {
8082         .f = cmd_showcfg_parsed,
8083         .data = NULL,
8084         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8085         .tokens = {
8086                 (void *)&cmd_showcfg_show,
8087                 (void *)&cmd_showcfg_port,
8088                 (void *)&cmd_showcfg_what,
8089                 NULL,
8090         },
8091 };
8092
8093 /* *** SHOW ALL PORT INFO *** */
8094 struct cmd_showportall_result {
8095         cmdline_fixed_string_t show;
8096         cmdline_fixed_string_t port;
8097         cmdline_fixed_string_t what;
8098         cmdline_fixed_string_t all;
8099 };
8100
8101 static void cmd_showportall_parsed(void *parsed_result,
8102                                 __rte_unused struct cmdline *cl,
8103                                 __rte_unused void *data)
8104 {
8105         portid_t i;
8106
8107         struct cmd_showportall_result *res = parsed_result;
8108         if (!strcmp(res->show, "clear")) {
8109                 if (!strcmp(res->what, "stats"))
8110                         RTE_ETH_FOREACH_DEV(i)
8111                                 nic_stats_clear(i);
8112                 else if (!strcmp(res->what, "xstats"))
8113                         RTE_ETH_FOREACH_DEV(i)
8114                                 nic_xstats_clear(i);
8115         } else if (!strcmp(res->what, "info"))
8116                 RTE_ETH_FOREACH_DEV(i)
8117                         port_infos_display(i);
8118         else if (!strcmp(res->what, "summary")) {
8119                 port_summary_header_display();
8120                 RTE_ETH_FOREACH_DEV(i)
8121                         port_summary_display(i);
8122         }
8123         else if (!strcmp(res->what, "stats"))
8124                 RTE_ETH_FOREACH_DEV(i)
8125                         nic_stats_display(i);
8126         else if (!strcmp(res->what, "xstats"))
8127                 RTE_ETH_FOREACH_DEV(i)
8128                         nic_xstats_display(i);
8129 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8130         else if (!strcmp(res->what, "fdir"))
8131                 RTE_ETH_FOREACH_DEV(i)
8132                         fdir_get_infos(i);
8133 #endif
8134         else if (!strcmp(res->what, "dcb_tc"))
8135                 RTE_ETH_FOREACH_DEV(i)
8136                         port_dcb_info_display(i);
8137 }
8138
8139 cmdline_parse_token_string_t cmd_showportall_show =
8140         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8141                                  "show#clear");
8142 cmdline_parse_token_string_t cmd_showportall_port =
8143         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8144 cmdline_parse_token_string_t cmd_showportall_what =
8145         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8146                                  "info#summary#stats#xstats#fdir#dcb_tc");
8147 cmdline_parse_token_string_t cmd_showportall_all =
8148         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8149 cmdline_parse_inst_t cmd_showportall = {
8150         .f = cmd_showportall_parsed,
8151         .data = NULL,
8152         .help_str = "show|clear port "
8153                 "info|summary|stats|xstats|fdir|dcb_tc all",
8154         .tokens = {
8155                 (void *)&cmd_showportall_show,
8156                 (void *)&cmd_showportall_port,
8157                 (void *)&cmd_showportall_what,
8158                 (void *)&cmd_showportall_all,
8159                 NULL,
8160         },
8161 };
8162
8163 /* *** SHOW PORT INFO *** */
8164 struct cmd_showport_result {
8165         cmdline_fixed_string_t show;
8166         cmdline_fixed_string_t port;
8167         cmdline_fixed_string_t what;
8168         uint16_t portnum;
8169 };
8170
8171 static void cmd_showport_parsed(void *parsed_result,
8172                                 __rte_unused struct cmdline *cl,
8173                                 __rte_unused void *data)
8174 {
8175         struct cmd_showport_result *res = parsed_result;
8176         if (!strcmp(res->show, "clear")) {
8177                 if (!strcmp(res->what, "stats"))
8178                         nic_stats_clear(res->portnum);
8179                 else if (!strcmp(res->what, "xstats"))
8180                         nic_xstats_clear(res->portnum);
8181         } else if (!strcmp(res->what, "info"))
8182                 port_infos_display(res->portnum);
8183         else if (!strcmp(res->what, "summary")) {
8184                 port_summary_header_display();
8185                 port_summary_display(res->portnum);
8186         }
8187         else if (!strcmp(res->what, "stats"))
8188                 nic_stats_display(res->portnum);
8189         else if (!strcmp(res->what, "xstats"))
8190                 nic_xstats_display(res->portnum);
8191 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8192         else if (!strcmp(res->what, "fdir"))
8193                  fdir_get_infos(res->portnum);
8194 #endif
8195         else if (!strcmp(res->what, "dcb_tc"))
8196                 port_dcb_info_display(res->portnum);
8197 }
8198
8199 cmdline_parse_token_string_t cmd_showport_show =
8200         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8201                                  "show#clear");
8202 cmdline_parse_token_string_t cmd_showport_port =
8203         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8204 cmdline_parse_token_string_t cmd_showport_what =
8205         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8206                                  "info#summary#stats#xstats#fdir#dcb_tc");
8207 cmdline_parse_token_num_t cmd_showport_portnum =
8208         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8209
8210 cmdline_parse_inst_t cmd_showport = {
8211         .f = cmd_showport_parsed,
8212         .data = NULL,
8213         .help_str = "show|clear port "
8214                 "info|summary|stats|xstats|fdir|dcb_tc "
8215                 "<port_id>",
8216         .tokens = {
8217                 (void *)&cmd_showport_show,
8218                 (void *)&cmd_showport_port,
8219                 (void *)&cmd_showport_what,
8220                 (void *)&cmd_showport_portnum,
8221                 NULL,
8222         },
8223 };
8224
8225 /* *** show port representors information *** */
8226 struct cmd_representor_info_result {
8227         cmdline_fixed_string_t cmd_show;
8228         cmdline_fixed_string_t cmd_port;
8229         cmdline_fixed_string_t cmd_info;
8230         cmdline_fixed_string_t cmd_keyword;
8231         portid_t cmd_pid;
8232 };
8233
8234 static void
8235 cmd_representor_info_parsed(void *parsed_result,
8236                 __rte_unused struct cmdline *cl,
8237                 __rte_unused void *data)
8238 {
8239         struct cmd_representor_info_result *res = parsed_result;
8240         struct rte_eth_representor_info *info;
8241         struct rte_eth_representor_range *range;
8242         uint32_t range_diff;
8243         uint32_t i;
8244         int ret;
8245         int num;
8246
8247         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8248                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8249                 return;
8250         }
8251
8252         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8253         if (ret < 0) {
8254                 fprintf(stderr,
8255                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8256                         res->cmd_pid, rte_strerror(-ret));
8257                 return;
8258         }
8259         num = ret;
8260
8261         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8262         if (info == NULL) {
8263                 fprintf(stderr,
8264                         "Failed to allocate memory for representor info for port %hu\n",
8265                         res->cmd_pid);
8266                 return;
8267         }
8268         info->nb_ranges_alloc = num;
8269
8270         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8271         if (ret < 0) {
8272                 fprintf(stderr,
8273                         "Failed to get the representor info for port %hu: %s\n",
8274                         res->cmd_pid, rte_strerror(-ret));
8275                 free(info);
8276                 return;
8277         }
8278
8279         printf("Port controller: %hu\n", info->controller);
8280         printf("Port PF: %hu\n", info->pf);
8281
8282         printf("Ranges: %u\n", info->nb_ranges);
8283         for (i = 0; i < info->nb_ranges; i++) {
8284                 range = &info->ranges[i];
8285                 range_diff = range->id_end - range->id_base;
8286
8287                 printf("%u. ", i + 1);
8288                 printf("'%s' ", range->name);
8289                 if (range_diff > 0)
8290                         printf("[%u-%u]: ", range->id_base, range->id_end);
8291                 else
8292                         printf("[%u]: ", range->id_base);
8293
8294                 printf("Controller %d, PF %d", range->controller, range->pf);
8295
8296                 switch (range->type) {
8297                 case RTE_ETH_REPRESENTOR_NONE:
8298                         printf(", NONE\n");
8299                         break;
8300                 case RTE_ETH_REPRESENTOR_VF:
8301                         if (range_diff > 0)
8302                                 printf(", VF %d..%d\n", range->vf,
8303                                        range->vf + range_diff);
8304                         else
8305                                 printf(", VF %d\n", range->vf);
8306                         break;
8307                 case RTE_ETH_REPRESENTOR_SF:
8308                         printf(", SF %d\n", range->sf);
8309                         break;
8310                 case RTE_ETH_REPRESENTOR_PF:
8311                         if (range_diff > 0)
8312                                 printf("..%d\n", range->pf + range_diff);
8313                         else
8314                                 printf("\n");
8315                         break;
8316                 default:
8317                         printf(", UNKNOWN TYPE %d\n", range->type);
8318                         break;
8319                 }
8320         }
8321
8322         free(info);
8323 }
8324
8325 cmdline_parse_token_string_t cmd_representor_info_show =
8326         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8327                         cmd_show, "show");
8328 cmdline_parse_token_string_t cmd_representor_info_port =
8329         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8330                         cmd_port, "port");
8331 cmdline_parse_token_string_t cmd_representor_info_info =
8332         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8333                         cmd_info, "info");
8334 cmdline_parse_token_num_t cmd_representor_info_pid =
8335         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8336                         cmd_pid, RTE_UINT16);
8337 cmdline_parse_token_string_t cmd_representor_info_keyword =
8338         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8339                         cmd_keyword, "representor");
8340
8341 cmdline_parse_inst_t cmd_representor_info = {
8342         .f = cmd_representor_info_parsed,
8343         .data = NULL,
8344         .help_str = "show port info <port_id> representor",
8345         .tokens = {
8346                 (void *)&cmd_representor_info_show,
8347                 (void *)&cmd_representor_info_port,
8348                 (void *)&cmd_representor_info_info,
8349                 (void *)&cmd_representor_info_pid,
8350                 (void *)&cmd_representor_info_keyword,
8351                 NULL,
8352         },
8353 };
8354
8355
8356 /* *** SHOW DEVICE INFO *** */
8357 struct cmd_showdevice_result {
8358         cmdline_fixed_string_t show;
8359         cmdline_fixed_string_t device;
8360         cmdline_fixed_string_t what;
8361         cmdline_fixed_string_t identifier;
8362 };
8363
8364 static void cmd_showdevice_parsed(void *parsed_result,
8365                                 __rte_unused struct cmdline *cl,
8366                                 __rte_unused void *data)
8367 {
8368         struct cmd_showdevice_result *res = parsed_result;
8369         if (!strcmp(res->what, "info")) {
8370                 if (!strcmp(res->identifier, "all"))
8371                         device_infos_display(NULL);
8372                 else
8373                         device_infos_display(res->identifier);
8374         }
8375 }
8376
8377 cmdline_parse_token_string_t cmd_showdevice_show =
8378         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8379                                  "show");
8380 cmdline_parse_token_string_t cmd_showdevice_device =
8381         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8382 cmdline_parse_token_string_t cmd_showdevice_what =
8383         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8384                                  "info");
8385 cmdline_parse_token_string_t cmd_showdevice_identifier =
8386         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8387                         identifier, NULL);
8388
8389 cmdline_parse_inst_t cmd_showdevice = {
8390         .f = cmd_showdevice_parsed,
8391         .data = NULL,
8392         .help_str = "show device info <identifier>|all",
8393         .tokens = {
8394                 (void *)&cmd_showdevice_show,
8395                 (void *)&cmd_showdevice_device,
8396                 (void *)&cmd_showdevice_what,
8397                 (void *)&cmd_showdevice_identifier,
8398                 NULL,
8399         },
8400 };
8401
8402 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8403 struct cmd_showeeprom_result {
8404         cmdline_fixed_string_t show;
8405         cmdline_fixed_string_t port;
8406         uint16_t portnum;
8407         cmdline_fixed_string_t type;
8408 };
8409
8410 static void cmd_showeeprom_parsed(void *parsed_result,
8411                 __rte_unused struct cmdline *cl,
8412                 __rte_unused void *data)
8413 {
8414         struct cmd_showeeprom_result *res = parsed_result;
8415
8416         if (!strcmp(res->type, "eeprom"))
8417                 port_eeprom_display(res->portnum);
8418         else if (!strcmp(res->type, "module_eeprom"))
8419                 port_module_eeprom_display(res->portnum);
8420         else
8421                 fprintf(stderr, "Unknown argument\n");
8422 }
8423
8424 cmdline_parse_token_string_t cmd_showeeprom_show =
8425         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8426 cmdline_parse_token_string_t cmd_showeeprom_port =
8427         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8428 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8429         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8430                         RTE_UINT16);
8431 cmdline_parse_token_string_t cmd_showeeprom_type =
8432         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8433
8434 cmdline_parse_inst_t cmd_showeeprom = {
8435         .f = cmd_showeeprom_parsed,
8436         .data = NULL,
8437         .help_str = "show port <port_id> module_eeprom|eeprom",
8438         .tokens = {
8439                 (void *)&cmd_showeeprom_show,
8440                 (void *)&cmd_showeeprom_port,
8441                 (void *)&cmd_showeeprom_portnum,
8442                 (void *)&cmd_showeeprom_type,
8443                 NULL,
8444         },
8445 };
8446
8447 /* *** SHOW QUEUE INFO *** */
8448 struct cmd_showqueue_result {
8449         cmdline_fixed_string_t show;
8450         cmdline_fixed_string_t type;
8451         cmdline_fixed_string_t what;
8452         uint16_t portnum;
8453         uint16_t queuenum;
8454 };
8455
8456 static void
8457 cmd_showqueue_parsed(void *parsed_result,
8458         __rte_unused struct cmdline *cl,
8459         __rte_unused void *data)
8460 {
8461         struct cmd_showqueue_result *res = parsed_result;
8462
8463         if (!strcmp(res->type, "rxq"))
8464                 rx_queue_infos_display(res->portnum, res->queuenum);
8465         else if (!strcmp(res->type, "txq"))
8466                 tx_queue_infos_display(res->portnum, res->queuenum);
8467 }
8468
8469 cmdline_parse_token_string_t cmd_showqueue_show =
8470         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8471 cmdline_parse_token_string_t cmd_showqueue_type =
8472         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8473 cmdline_parse_token_string_t cmd_showqueue_what =
8474         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8475 cmdline_parse_token_num_t cmd_showqueue_portnum =
8476         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8477                 RTE_UINT16);
8478 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8479         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8480                 RTE_UINT16);
8481
8482 cmdline_parse_inst_t cmd_showqueue = {
8483         .f = cmd_showqueue_parsed,
8484         .data = NULL,
8485         .help_str = "show rxq|txq info <port_id> <queue_id>",
8486         .tokens = {
8487                 (void *)&cmd_showqueue_show,
8488                 (void *)&cmd_showqueue_type,
8489                 (void *)&cmd_showqueue_what,
8490                 (void *)&cmd_showqueue_portnum,
8491                 (void *)&cmd_showqueue_queuenum,
8492                 NULL,
8493         },
8494 };
8495
8496 /* show/clear fwd engine statistics */
8497 struct fwd_result {
8498         cmdline_fixed_string_t action;
8499         cmdline_fixed_string_t fwd;
8500         cmdline_fixed_string_t stats;
8501         cmdline_fixed_string_t all;
8502 };
8503
8504 cmdline_parse_token_string_t cmd_fwd_action =
8505         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8506 cmdline_parse_token_string_t cmd_fwd_fwd =
8507         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8508 cmdline_parse_token_string_t cmd_fwd_stats =
8509         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8510 cmdline_parse_token_string_t cmd_fwd_all =
8511         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8512
8513 static void
8514 cmd_showfwdall_parsed(void *parsed_result,
8515                       __rte_unused struct cmdline *cl,
8516                       __rte_unused void *data)
8517 {
8518         struct fwd_result *res = parsed_result;
8519
8520         if (!strcmp(res->action, "show"))
8521                 fwd_stats_display();
8522         else
8523                 fwd_stats_reset();
8524 }
8525
8526 static cmdline_parse_inst_t cmd_showfwdall = {
8527         .f = cmd_showfwdall_parsed,
8528         .data = NULL,
8529         .help_str = "show|clear fwd stats all",
8530         .tokens = {
8531                 (void *)&cmd_fwd_action,
8532                 (void *)&cmd_fwd_fwd,
8533                 (void *)&cmd_fwd_stats,
8534                 (void *)&cmd_fwd_all,
8535                 NULL,
8536         },
8537 };
8538
8539 /* *** READ PORT REGISTER *** */
8540 struct cmd_read_reg_result {
8541         cmdline_fixed_string_t read;
8542         cmdline_fixed_string_t reg;
8543         portid_t port_id;
8544         uint32_t reg_off;
8545 };
8546
8547 static void
8548 cmd_read_reg_parsed(void *parsed_result,
8549                     __rte_unused struct cmdline *cl,
8550                     __rte_unused void *data)
8551 {
8552         struct cmd_read_reg_result *res = parsed_result;
8553         port_reg_display(res->port_id, res->reg_off);
8554 }
8555
8556 cmdline_parse_token_string_t cmd_read_reg_read =
8557         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8558 cmdline_parse_token_string_t cmd_read_reg_reg =
8559         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8560 cmdline_parse_token_num_t cmd_read_reg_port_id =
8561         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8562 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8563         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8564
8565 cmdline_parse_inst_t cmd_read_reg = {
8566         .f = cmd_read_reg_parsed,
8567         .data = NULL,
8568         .help_str = "read reg <port_id> <reg_off>",
8569         .tokens = {
8570                 (void *)&cmd_read_reg_read,
8571                 (void *)&cmd_read_reg_reg,
8572                 (void *)&cmd_read_reg_port_id,
8573                 (void *)&cmd_read_reg_reg_off,
8574                 NULL,
8575         },
8576 };
8577
8578 /* *** READ PORT REGISTER BIT FIELD *** */
8579 struct cmd_read_reg_bit_field_result {
8580         cmdline_fixed_string_t read;
8581         cmdline_fixed_string_t regfield;
8582         portid_t port_id;
8583         uint32_t reg_off;
8584         uint8_t bit1_pos;
8585         uint8_t bit2_pos;
8586 };
8587
8588 static void
8589 cmd_read_reg_bit_field_parsed(void *parsed_result,
8590                               __rte_unused struct cmdline *cl,
8591                               __rte_unused void *data)
8592 {
8593         struct cmd_read_reg_bit_field_result *res = parsed_result;
8594         port_reg_bit_field_display(res->port_id, res->reg_off,
8595                                    res->bit1_pos, res->bit2_pos);
8596 }
8597
8598 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8599         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8600                                  "read");
8601 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8602         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8603                                  regfield, "regfield");
8604 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8605         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8606                               RTE_UINT16);
8607 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8608         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8609                               RTE_UINT32);
8610 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8611         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8612                               RTE_UINT8);
8613 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8614         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8615                               RTE_UINT8);
8616
8617 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8618         .f = cmd_read_reg_bit_field_parsed,
8619         .data = NULL,
8620         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8621         "Read register bit field between bit_x and bit_y included",
8622         .tokens = {
8623                 (void *)&cmd_read_reg_bit_field_read,
8624                 (void *)&cmd_read_reg_bit_field_regfield,
8625                 (void *)&cmd_read_reg_bit_field_port_id,
8626                 (void *)&cmd_read_reg_bit_field_reg_off,
8627                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8628                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8629                 NULL,
8630         },
8631 };
8632
8633 /* *** READ PORT REGISTER BIT *** */
8634 struct cmd_read_reg_bit_result {
8635         cmdline_fixed_string_t read;
8636         cmdline_fixed_string_t regbit;
8637         portid_t port_id;
8638         uint32_t reg_off;
8639         uint8_t bit_pos;
8640 };
8641
8642 static void
8643 cmd_read_reg_bit_parsed(void *parsed_result,
8644                         __rte_unused struct cmdline *cl,
8645                         __rte_unused void *data)
8646 {
8647         struct cmd_read_reg_bit_result *res = parsed_result;
8648         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8649 }
8650
8651 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8652         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8653 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8654         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8655                                  regbit, "regbit");
8656 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8657         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8658                                  RTE_UINT16);
8659 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8660         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8661                                  RTE_UINT32);
8662 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8663         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8664                                  RTE_UINT8);
8665
8666 cmdline_parse_inst_t cmd_read_reg_bit = {
8667         .f = cmd_read_reg_bit_parsed,
8668         .data = NULL,
8669         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8670         .tokens = {
8671                 (void *)&cmd_read_reg_bit_read,
8672                 (void *)&cmd_read_reg_bit_regbit,
8673                 (void *)&cmd_read_reg_bit_port_id,
8674                 (void *)&cmd_read_reg_bit_reg_off,
8675                 (void *)&cmd_read_reg_bit_bit_pos,
8676                 NULL,
8677         },
8678 };
8679
8680 /* *** WRITE PORT REGISTER *** */
8681 struct cmd_write_reg_result {
8682         cmdline_fixed_string_t write;
8683         cmdline_fixed_string_t reg;
8684         portid_t port_id;
8685         uint32_t reg_off;
8686         uint32_t value;
8687 };
8688
8689 static void
8690 cmd_write_reg_parsed(void *parsed_result,
8691                      __rte_unused struct cmdline *cl,
8692                      __rte_unused void *data)
8693 {
8694         struct cmd_write_reg_result *res = parsed_result;
8695         port_reg_set(res->port_id, res->reg_off, res->value);
8696 }
8697
8698 cmdline_parse_token_string_t cmd_write_reg_write =
8699         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8700 cmdline_parse_token_string_t cmd_write_reg_reg =
8701         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8702 cmdline_parse_token_num_t cmd_write_reg_port_id =
8703         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8704 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8705         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8706 cmdline_parse_token_num_t cmd_write_reg_value =
8707         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8708
8709 cmdline_parse_inst_t cmd_write_reg = {
8710         .f = cmd_write_reg_parsed,
8711         .data = NULL,
8712         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8713         .tokens = {
8714                 (void *)&cmd_write_reg_write,
8715                 (void *)&cmd_write_reg_reg,
8716                 (void *)&cmd_write_reg_port_id,
8717                 (void *)&cmd_write_reg_reg_off,
8718                 (void *)&cmd_write_reg_value,
8719                 NULL,
8720         },
8721 };
8722
8723 /* *** WRITE PORT REGISTER BIT FIELD *** */
8724 struct cmd_write_reg_bit_field_result {
8725         cmdline_fixed_string_t write;
8726         cmdline_fixed_string_t regfield;
8727         portid_t port_id;
8728         uint32_t reg_off;
8729         uint8_t bit1_pos;
8730         uint8_t bit2_pos;
8731         uint32_t value;
8732 };
8733
8734 static void
8735 cmd_write_reg_bit_field_parsed(void *parsed_result,
8736                                __rte_unused struct cmdline *cl,
8737                                __rte_unused void *data)
8738 {
8739         struct cmd_write_reg_bit_field_result *res = parsed_result;
8740         port_reg_bit_field_set(res->port_id, res->reg_off,
8741                           res->bit1_pos, res->bit2_pos, res->value);
8742 }
8743
8744 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8745         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8746                                  "write");
8747 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8748         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8749                                  regfield, "regfield");
8750 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8751         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8752                               RTE_UINT16);
8753 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8754         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8755                               RTE_UINT32);
8756 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8757         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8758                               RTE_UINT8);
8759 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8760         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8761                               RTE_UINT8);
8762 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8763         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8764                               RTE_UINT32);
8765
8766 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8767         .f = cmd_write_reg_bit_field_parsed,
8768         .data = NULL,
8769         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8770                 "<reg_value>: "
8771                 "Set register bit field between bit_x and bit_y included",
8772         .tokens = {
8773                 (void *)&cmd_write_reg_bit_field_write,
8774                 (void *)&cmd_write_reg_bit_field_regfield,
8775                 (void *)&cmd_write_reg_bit_field_port_id,
8776                 (void *)&cmd_write_reg_bit_field_reg_off,
8777                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8778                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8779                 (void *)&cmd_write_reg_bit_field_value,
8780                 NULL,
8781         },
8782 };
8783
8784 /* *** WRITE PORT REGISTER BIT *** */
8785 struct cmd_write_reg_bit_result {
8786         cmdline_fixed_string_t write;
8787         cmdline_fixed_string_t regbit;
8788         portid_t port_id;
8789         uint32_t reg_off;
8790         uint8_t bit_pos;
8791         uint8_t value;
8792 };
8793
8794 static void
8795 cmd_write_reg_bit_parsed(void *parsed_result,
8796                          __rte_unused struct cmdline *cl,
8797                          __rte_unused void *data)
8798 {
8799         struct cmd_write_reg_bit_result *res = parsed_result;
8800         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8801 }
8802
8803 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8804         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8805                                  "write");
8806 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8807         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8808                                  regbit, "regbit");
8809 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8811                                  RTE_UINT16);
8812 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8813         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8814                                  RTE_UINT32);
8815 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8816         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8817                                  RTE_UINT8);
8818 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8819         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8820                                  RTE_UINT8);
8821
8822 cmdline_parse_inst_t cmd_write_reg_bit = {
8823         .f = cmd_write_reg_bit_parsed,
8824         .data = NULL,
8825         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8826                 "0 <= bit_x <= 31",
8827         .tokens = {
8828                 (void *)&cmd_write_reg_bit_write,
8829                 (void *)&cmd_write_reg_bit_regbit,
8830                 (void *)&cmd_write_reg_bit_port_id,
8831                 (void *)&cmd_write_reg_bit_reg_off,
8832                 (void *)&cmd_write_reg_bit_bit_pos,
8833                 (void *)&cmd_write_reg_bit_value,
8834                 NULL,
8835         },
8836 };
8837
8838 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8839 struct cmd_read_rxd_txd_result {
8840         cmdline_fixed_string_t read;
8841         cmdline_fixed_string_t rxd_txd;
8842         portid_t port_id;
8843         uint16_t queue_id;
8844         uint16_t desc_id;
8845 };
8846
8847 static void
8848 cmd_read_rxd_txd_parsed(void *parsed_result,
8849                         __rte_unused struct cmdline *cl,
8850                         __rte_unused void *data)
8851 {
8852         struct cmd_read_rxd_txd_result *res = parsed_result;
8853
8854         if (!strcmp(res->rxd_txd, "rxd"))
8855                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8856         else if (!strcmp(res->rxd_txd, "txd"))
8857                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8858 }
8859
8860 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8861         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8862 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8863         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8864                                  "rxd#txd");
8865 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8866         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8867                                  RTE_UINT16);
8868 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8869         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8870                                  RTE_UINT16);
8871 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8872         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8873                                  RTE_UINT16);
8874
8875 cmdline_parse_inst_t cmd_read_rxd_txd = {
8876         .f = cmd_read_rxd_txd_parsed,
8877         .data = NULL,
8878         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8879         .tokens = {
8880                 (void *)&cmd_read_rxd_txd_read,
8881                 (void *)&cmd_read_rxd_txd_rxd_txd,
8882                 (void *)&cmd_read_rxd_txd_port_id,
8883                 (void *)&cmd_read_rxd_txd_queue_id,
8884                 (void *)&cmd_read_rxd_txd_desc_id,
8885                 NULL,
8886         },
8887 };
8888
8889 /* *** QUIT *** */
8890 struct cmd_quit_result {
8891         cmdline_fixed_string_t quit;
8892 };
8893
8894 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8895                             struct cmdline *cl,
8896                             __rte_unused void *data)
8897 {
8898         cmdline_quit(cl);
8899 }
8900
8901 cmdline_parse_token_string_t cmd_quit_quit =
8902         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8903
8904 cmdline_parse_inst_t cmd_quit = {
8905         .f = cmd_quit_parsed,
8906         .data = NULL,
8907         .help_str = "quit: Exit application",
8908         .tokens = {
8909                 (void *)&cmd_quit_quit,
8910                 NULL,
8911         },
8912 };
8913
8914 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8915 struct cmd_mac_addr_result {
8916         cmdline_fixed_string_t mac_addr_cmd;
8917         cmdline_fixed_string_t what;
8918         uint16_t port_num;
8919         struct rte_ether_addr address;
8920 };
8921
8922 static void cmd_mac_addr_parsed(void *parsed_result,
8923                 __rte_unused struct cmdline *cl,
8924                 __rte_unused void *data)
8925 {
8926         struct cmd_mac_addr_result *res = parsed_result;
8927         int ret;
8928
8929         if (strcmp(res->what, "add") == 0)
8930                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8931         else if (strcmp(res->what, "set") == 0)
8932                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8933                                                        &res->address);
8934         else
8935                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8936
8937         /* check the return value and print it if is < 0 */
8938         if(ret < 0)
8939                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8940
8941 }
8942
8943 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8944         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8945                                 "mac_addr");
8946 cmdline_parse_token_string_t cmd_mac_addr_what =
8947         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8948                                 "add#remove#set");
8949 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8950                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8951                                         RTE_UINT16);
8952 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8953                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8954
8955 cmdline_parse_inst_t cmd_mac_addr = {
8956         .f = cmd_mac_addr_parsed,
8957         .data = (void *)0,
8958         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8959                         "Add/Remove/Set MAC address on port_id",
8960         .tokens = {
8961                 (void *)&cmd_mac_addr_cmd,
8962                 (void *)&cmd_mac_addr_what,
8963                 (void *)&cmd_mac_addr_portnum,
8964                 (void *)&cmd_mac_addr_addr,
8965                 NULL,
8966         },
8967 };
8968
8969 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8970 struct cmd_eth_peer_result {
8971         cmdline_fixed_string_t set;
8972         cmdline_fixed_string_t eth_peer;
8973         portid_t port_id;
8974         cmdline_fixed_string_t peer_addr;
8975 };
8976
8977 static void cmd_set_eth_peer_parsed(void *parsed_result,
8978                         __rte_unused struct cmdline *cl,
8979                         __rte_unused void *data)
8980 {
8981                 struct cmd_eth_peer_result *res = parsed_result;
8982
8983                 if (test_done == 0) {
8984                         fprintf(stderr, "Please stop forwarding first\n");
8985                         return;
8986                 }
8987                 if (!strcmp(res->eth_peer, "eth-peer")) {
8988                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8989                         fwd_config_setup();
8990                 }
8991 }
8992 cmdline_parse_token_string_t cmd_eth_peer_set =
8993         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8994 cmdline_parse_token_string_t cmd_eth_peer =
8995         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8996 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8997         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8998                 RTE_UINT16);
8999 cmdline_parse_token_string_t cmd_eth_peer_addr =
9000         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
9001
9002 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
9003         .f = cmd_set_eth_peer_parsed,
9004         .data = NULL,
9005         .help_str = "set eth-peer <port_id> <peer_mac>",
9006         .tokens = {
9007                 (void *)&cmd_eth_peer_set,
9008                 (void *)&cmd_eth_peer,
9009                 (void *)&cmd_eth_peer_port_id,
9010                 (void *)&cmd_eth_peer_addr,
9011                 NULL,
9012         },
9013 };
9014
9015 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9016 struct cmd_set_qmap_result {
9017         cmdline_fixed_string_t set;
9018         cmdline_fixed_string_t qmap;
9019         cmdline_fixed_string_t what;
9020         portid_t port_id;
9021         uint16_t queue_id;
9022         uint8_t map_value;
9023 };
9024
9025 static void
9026 cmd_set_qmap_parsed(void *parsed_result,
9027                        __rte_unused struct cmdline *cl,
9028                        __rte_unused void *data)
9029 {
9030         struct cmd_set_qmap_result *res = parsed_result;
9031         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9032
9033         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9034 }
9035
9036 cmdline_parse_token_string_t cmd_setqmap_set =
9037         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9038                                  set, "set");
9039 cmdline_parse_token_string_t cmd_setqmap_qmap =
9040         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9041                                  qmap, "stat_qmap");
9042 cmdline_parse_token_string_t cmd_setqmap_what =
9043         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9044                                  what, "tx#rx");
9045 cmdline_parse_token_num_t cmd_setqmap_portid =
9046         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9047                               port_id, RTE_UINT16);
9048 cmdline_parse_token_num_t cmd_setqmap_queueid =
9049         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9050                               queue_id, RTE_UINT16);
9051 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9052         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9053                               map_value, RTE_UINT8);
9054
9055 cmdline_parse_inst_t cmd_set_qmap = {
9056         .f = cmd_set_qmap_parsed,
9057         .data = NULL,
9058         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9059                 "Set statistics mapping value on tx|rx queue_id of port_id",
9060         .tokens = {
9061                 (void *)&cmd_setqmap_set,
9062                 (void *)&cmd_setqmap_qmap,
9063                 (void *)&cmd_setqmap_what,
9064                 (void *)&cmd_setqmap_portid,
9065                 (void *)&cmd_setqmap_queueid,
9066                 (void *)&cmd_setqmap_mapvalue,
9067                 NULL,
9068         },
9069 };
9070
9071 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9072 struct cmd_set_xstats_hide_zero_result {
9073         cmdline_fixed_string_t keyword;
9074         cmdline_fixed_string_t name;
9075         cmdline_fixed_string_t on_off;
9076 };
9077
9078 static void
9079 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9080                         __rte_unused struct cmdline *cl,
9081                         __rte_unused void *data)
9082 {
9083         struct cmd_set_xstats_hide_zero_result *res;
9084         uint16_t on_off = 0;
9085
9086         res = parsed_result;
9087         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9088         set_xstats_hide_zero(on_off);
9089 }
9090
9091 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9092         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9093                                  keyword, "set");
9094 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9095         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9096                                  name, "xstats-hide-zero");
9097 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9098         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9099                                  on_off, "on#off");
9100
9101 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9102         .f = cmd_set_xstats_hide_zero_parsed,
9103         .data = NULL,
9104         .help_str = "set xstats-hide-zero on|off",
9105         .tokens = {
9106                 (void *)&cmd_set_xstats_hide_zero_keyword,
9107                 (void *)&cmd_set_xstats_hide_zero_name,
9108                 (void *)&cmd_set_xstats_hide_zero_on_off,
9109                 NULL,
9110         },
9111 };
9112
9113 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9114 struct cmd_set_record_core_cycles_result {
9115         cmdline_fixed_string_t keyword;
9116         cmdline_fixed_string_t name;
9117         cmdline_fixed_string_t on_off;
9118 };
9119
9120 static void
9121 cmd_set_record_core_cycles_parsed(void *parsed_result,
9122                         __rte_unused struct cmdline *cl,
9123                         __rte_unused void *data)
9124 {
9125         struct cmd_set_record_core_cycles_result *res;
9126         uint16_t on_off = 0;
9127
9128         res = parsed_result;
9129         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9130         set_record_core_cycles(on_off);
9131 }
9132
9133 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9134         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9135                                  keyword, "set");
9136 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9137         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9138                                  name, "record-core-cycles");
9139 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9140         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9141                                  on_off, "on#off");
9142
9143 cmdline_parse_inst_t cmd_set_record_core_cycles = {
9144         .f = cmd_set_record_core_cycles_parsed,
9145         .data = NULL,
9146         .help_str = "set record-core-cycles on|off",
9147         .tokens = {
9148                 (void *)&cmd_set_record_core_cycles_keyword,
9149                 (void *)&cmd_set_record_core_cycles_name,
9150                 (void *)&cmd_set_record_core_cycles_on_off,
9151                 NULL,
9152         },
9153 };
9154
9155 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9156 struct cmd_set_record_burst_stats_result {
9157         cmdline_fixed_string_t keyword;
9158         cmdline_fixed_string_t name;
9159         cmdline_fixed_string_t on_off;
9160 };
9161
9162 static void
9163 cmd_set_record_burst_stats_parsed(void *parsed_result,
9164                         __rte_unused struct cmdline *cl,
9165                         __rte_unused void *data)
9166 {
9167         struct cmd_set_record_burst_stats_result *res;
9168         uint16_t on_off = 0;
9169
9170         res = parsed_result;
9171         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9172         set_record_burst_stats(on_off);
9173 }
9174
9175 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9176         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9177                                  keyword, "set");
9178 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9179         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9180                                  name, "record-burst-stats");
9181 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9182         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9183                                  on_off, "on#off");
9184
9185 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9186         .f = cmd_set_record_burst_stats_parsed,
9187         .data = NULL,
9188         .help_str = "set record-burst-stats on|off",
9189         .tokens = {
9190                 (void *)&cmd_set_record_burst_stats_keyword,
9191                 (void *)&cmd_set_record_burst_stats_name,
9192                 (void *)&cmd_set_record_burst_stats_on_off,
9193                 NULL,
9194         },
9195 };
9196
9197 /* *** CONFIGURE UNICAST HASH TABLE *** */
9198 struct cmd_set_uc_hash_table {
9199         cmdline_fixed_string_t set;
9200         cmdline_fixed_string_t port;
9201         portid_t port_id;
9202         cmdline_fixed_string_t what;
9203         struct rte_ether_addr address;
9204         cmdline_fixed_string_t mode;
9205 };
9206
9207 static void
9208 cmd_set_uc_hash_parsed(void *parsed_result,
9209                        __rte_unused struct cmdline *cl,
9210                        __rte_unused void *data)
9211 {
9212         int ret=0;
9213         struct cmd_set_uc_hash_table *res = parsed_result;
9214
9215         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9216
9217         if (strcmp(res->what, "uta") == 0)
9218                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9219                                                 &res->address,(uint8_t)is_on);
9220         if (ret < 0)
9221                 fprintf(stderr,
9222                         "bad unicast hash table parameter, return code = %d\n",
9223                         ret);
9224
9225 }
9226
9227 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9228         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9229                                  set, "set");
9230 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9231         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9232                                  port, "port");
9233 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9234         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9235                               port_id, RTE_UINT16);
9236 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9237         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9238                                  what, "uta");
9239 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9240         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9241                                 address);
9242 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9243         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9244                                  mode, "on#off");
9245
9246 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9247         .f = cmd_set_uc_hash_parsed,
9248         .data = NULL,
9249         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9250         .tokens = {
9251                 (void *)&cmd_set_uc_hash_set,
9252                 (void *)&cmd_set_uc_hash_port,
9253                 (void *)&cmd_set_uc_hash_portid,
9254                 (void *)&cmd_set_uc_hash_what,
9255                 (void *)&cmd_set_uc_hash_mac,
9256                 (void *)&cmd_set_uc_hash_mode,
9257                 NULL,
9258         },
9259 };
9260
9261 struct cmd_set_uc_all_hash_table {
9262         cmdline_fixed_string_t set;
9263         cmdline_fixed_string_t port;
9264         portid_t port_id;
9265         cmdline_fixed_string_t what;
9266         cmdline_fixed_string_t value;
9267         cmdline_fixed_string_t mode;
9268 };
9269
9270 static void
9271 cmd_set_uc_all_hash_parsed(void *parsed_result,
9272                        __rte_unused struct cmdline *cl,
9273                        __rte_unused void *data)
9274 {
9275         int ret=0;
9276         struct cmd_set_uc_all_hash_table *res = parsed_result;
9277
9278         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9279
9280         if ((strcmp(res->what, "uta") == 0) &&
9281                 (strcmp(res->value, "all") == 0))
9282                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9283         if (ret < 0)
9284                 fprintf(stderr,
9285                         "bad unicast hash table parameter, return code = %d\n",
9286                         ret);
9287 }
9288
9289 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9290         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9291                                  set, "set");
9292 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9293         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9294                                  port, "port");
9295 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9296         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9297                               port_id, RTE_UINT16);
9298 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9299         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9300                                  what, "uta");
9301 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9302         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9303                                 value,"all");
9304 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9305         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9306                                  mode, "on#off");
9307
9308 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9309         .f = cmd_set_uc_all_hash_parsed,
9310         .data = NULL,
9311         .help_str = "set port <port_id> uta all on|off",
9312         .tokens = {
9313                 (void *)&cmd_set_uc_all_hash_set,
9314                 (void *)&cmd_set_uc_all_hash_port,
9315                 (void *)&cmd_set_uc_all_hash_portid,
9316                 (void *)&cmd_set_uc_all_hash_what,
9317                 (void *)&cmd_set_uc_all_hash_value,
9318                 (void *)&cmd_set_uc_all_hash_mode,
9319                 NULL,
9320         },
9321 };
9322
9323 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9324 struct cmd_set_vf_traffic {
9325         cmdline_fixed_string_t set;
9326         cmdline_fixed_string_t port;
9327         portid_t port_id;
9328         cmdline_fixed_string_t vf;
9329         uint8_t vf_id;
9330         cmdline_fixed_string_t what;
9331         cmdline_fixed_string_t mode;
9332 };
9333
9334 static void
9335 cmd_set_vf_traffic_parsed(void *parsed_result,
9336                        __rte_unused struct cmdline *cl,
9337                        __rte_unused void *data)
9338 {
9339         struct cmd_set_vf_traffic *res = parsed_result;
9340         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9341         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9342
9343         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9344 }
9345
9346 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9347         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9348                                  set, "set");
9349 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9350         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9351                                  port, "port");
9352 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9353         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9354                               port_id, RTE_UINT16);
9355 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9356         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9357                                  vf, "vf");
9358 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9359         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9360                               vf_id, RTE_UINT8);
9361 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9362         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9363                                  what, "tx#rx");
9364 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9366                                  mode, "on#off");
9367
9368 cmdline_parse_inst_t cmd_set_vf_traffic = {
9369         .f = cmd_set_vf_traffic_parsed,
9370         .data = NULL,
9371         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9372         .tokens = {
9373                 (void *)&cmd_setvf_traffic_set,
9374                 (void *)&cmd_setvf_traffic_port,
9375                 (void *)&cmd_setvf_traffic_portid,
9376                 (void *)&cmd_setvf_traffic_vf,
9377                 (void *)&cmd_setvf_traffic_vfid,
9378                 (void *)&cmd_setvf_traffic_what,
9379                 (void *)&cmd_setvf_traffic_mode,
9380                 NULL,
9381         },
9382 };
9383
9384 /* *** CONFIGURE VF RECEIVE MODE *** */
9385 struct cmd_set_vf_rxmode {
9386         cmdline_fixed_string_t set;
9387         cmdline_fixed_string_t port;
9388         portid_t port_id;
9389         cmdline_fixed_string_t vf;
9390         uint8_t vf_id;
9391         cmdline_fixed_string_t what;
9392         cmdline_fixed_string_t mode;
9393         cmdline_fixed_string_t on;
9394 };
9395
9396 static void
9397 cmd_set_vf_rxmode_parsed(void *parsed_result,
9398                        __rte_unused struct cmdline *cl,
9399                        __rte_unused void *data)
9400 {
9401         int ret = -ENOTSUP;
9402         uint16_t vf_rxmode = 0;
9403         struct cmd_set_vf_rxmode *res = parsed_result;
9404
9405         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9406         if (!strcmp(res->what,"rxmode")) {
9407                 if (!strcmp(res->mode, "AUPE"))
9408                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9409                 else if (!strcmp(res->mode, "ROPE"))
9410                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9411                 else if (!strcmp(res->mode, "BAM"))
9412                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9413                 else if (!strncmp(res->mode, "MPE",3))
9414                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9415         }
9416
9417         RTE_SET_USED(is_on);
9418         RTE_SET_USED(vf_rxmode);
9419
9420 #ifdef RTE_NET_IXGBE
9421         if (ret == -ENOTSUP)
9422                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9423                                                   vf_rxmode, (uint8_t)is_on);
9424 #endif
9425 #ifdef RTE_NET_BNXT
9426         if (ret == -ENOTSUP)
9427                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9428                                                  vf_rxmode, (uint8_t)is_on);
9429 #endif
9430         if (ret < 0)
9431                 fprintf(stderr,
9432                         "bad VF receive mode parameter, return code = %d\n",
9433                         ret);
9434 }
9435
9436 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9437         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9438                                  set, "set");
9439 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9440         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9441                                  port, "port");
9442 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9443         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9444                               port_id, RTE_UINT16);
9445 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9446         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9447                                  vf, "vf");
9448 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9449         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9450                               vf_id, RTE_UINT8);
9451 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9452         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9453                                  what, "rxmode");
9454 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9455         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9456                                  mode, "AUPE#ROPE#BAM#MPE");
9457 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9458         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9459                                  on, "on#off");
9460
9461 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9462         .f = cmd_set_vf_rxmode_parsed,
9463         .data = NULL,
9464         .help_str = "set port <port_id> vf <vf_id> rxmode "
9465                 "AUPE|ROPE|BAM|MPE on|off",
9466         .tokens = {
9467                 (void *)&cmd_set_vf_rxmode_set,
9468                 (void *)&cmd_set_vf_rxmode_port,
9469                 (void *)&cmd_set_vf_rxmode_portid,
9470                 (void *)&cmd_set_vf_rxmode_vf,
9471                 (void *)&cmd_set_vf_rxmode_vfid,
9472                 (void *)&cmd_set_vf_rxmode_what,
9473                 (void *)&cmd_set_vf_rxmode_mode,
9474                 (void *)&cmd_set_vf_rxmode_on,
9475                 NULL,
9476         },
9477 };
9478
9479 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9480 struct cmd_vf_mac_addr_result {
9481         cmdline_fixed_string_t mac_addr_cmd;
9482         cmdline_fixed_string_t what;
9483         cmdline_fixed_string_t port;
9484         uint16_t port_num;
9485         cmdline_fixed_string_t vf;
9486         uint8_t vf_num;
9487         struct rte_ether_addr address;
9488 };
9489
9490 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9491                 __rte_unused struct cmdline *cl,
9492                 __rte_unused void *data)
9493 {
9494         struct cmd_vf_mac_addr_result *res = parsed_result;
9495         int ret = -ENOTSUP;
9496
9497         if (strcmp(res->what, "add") != 0)
9498                 return;
9499
9500 #ifdef RTE_NET_I40E
9501         if (ret == -ENOTSUP)
9502                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9503                                                    &res->address);
9504 #endif
9505 #ifdef RTE_NET_BNXT
9506         if (ret == -ENOTSUP)
9507                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9508                                                 res->vf_num);
9509 #endif
9510
9511         if(ret < 0)
9512                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9513
9514 }
9515
9516 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9517         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9518                                 mac_addr_cmd,"mac_addr");
9519 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9520         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9521                                 what,"add");
9522 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9523         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9524                                 port,"port");
9525 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9526         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9527                                 port_num, RTE_UINT16);
9528 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9529         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9530                                 vf,"vf");
9531 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9532         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9533                                 vf_num, RTE_UINT8);
9534 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9535         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9536                                 address);
9537
9538 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9539         .f = cmd_vf_mac_addr_parsed,
9540         .data = (void *)0,
9541         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9542                 "Add MAC address filtering for a VF on port_id",
9543         .tokens = {
9544                 (void *)&cmd_vf_mac_addr_cmd,
9545                 (void *)&cmd_vf_mac_addr_what,
9546                 (void *)&cmd_vf_mac_addr_port,
9547                 (void *)&cmd_vf_mac_addr_portnum,
9548                 (void *)&cmd_vf_mac_addr_vf,
9549                 (void *)&cmd_vf_mac_addr_vfnum,
9550                 (void *)&cmd_vf_mac_addr_addr,
9551                 NULL,
9552         },
9553 };
9554
9555 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9556 struct cmd_vf_rx_vlan_filter {
9557         cmdline_fixed_string_t rx_vlan;
9558         cmdline_fixed_string_t what;
9559         uint16_t vlan_id;
9560         cmdline_fixed_string_t port;
9561         portid_t port_id;
9562         cmdline_fixed_string_t vf;
9563         uint64_t vf_mask;
9564 };
9565
9566 static void
9567 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9568                           __rte_unused struct cmdline *cl,
9569                           __rte_unused void *data)
9570 {
9571         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9572         int ret = -ENOTSUP;
9573
9574         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9575
9576 #ifdef RTE_NET_IXGBE
9577         if (ret == -ENOTSUP)
9578                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9579                                 res->vlan_id, res->vf_mask, is_add);
9580 #endif
9581 #ifdef RTE_NET_I40E
9582         if (ret == -ENOTSUP)
9583                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9584                                 res->vlan_id, res->vf_mask, is_add);
9585 #endif
9586 #ifdef RTE_NET_BNXT
9587         if (ret == -ENOTSUP)
9588                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9589                                 res->vlan_id, res->vf_mask, is_add);
9590 #endif
9591
9592         switch (ret) {
9593         case 0:
9594                 break;
9595         case -EINVAL:
9596                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9597                         res->vlan_id, res->vf_mask);
9598                 break;
9599         case -ENODEV:
9600                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9601                 break;
9602         case -ENOTSUP:
9603                 fprintf(stderr, "function not implemented or supported\n");
9604                 break;
9605         default:
9606                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9607         }
9608 }
9609
9610 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9611         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9612                                  rx_vlan, "rx_vlan");
9613 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9614         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9615                                  what, "add#rm");
9616 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9617         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9618                               vlan_id, RTE_UINT16);
9619 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9620         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9621                                  port, "port");
9622 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9623         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9624                               port_id, RTE_UINT16);
9625 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9626         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9627                                  vf, "vf");
9628 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9629         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9630                               vf_mask, RTE_UINT64);
9631
9632 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9633         .f = cmd_vf_rx_vlan_filter_parsed,
9634         .data = NULL,
9635         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9636                 "(vf_mask = hexadecimal VF mask)",
9637         .tokens = {
9638                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9639                 (void *)&cmd_vf_rx_vlan_filter_what,
9640                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9641                 (void *)&cmd_vf_rx_vlan_filter_port,
9642                 (void *)&cmd_vf_rx_vlan_filter_portid,
9643                 (void *)&cmd_vf_rx_vlan_filter_vf,
9644                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9645                 NULL,
9646         },
9647 };
9648
9649 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9650 struct cmd_queue_rate_limit_result {
9651         cmdline_fixed_string_t set;
9652         cmdline_fixed_string_t port;
9653         uint16_t port_num;
9654         cmdline_fixed_string_t queue;
9655         uint8_t queue_num;
9656         cmdline_fixed_string_t rate;
9657         uint16_t rate_num;
9658 };
9659
9660 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9661                 __rte_unused struct cmdline *cl,
9662                 __rte_unused void *data)
9663 {
9664         struct cmd_queue_rate_limit_result *res = parsed_result;
9665         int ret = 0;
9666
9667         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9668                 && (strcmp(res->queue, "queue") == 0)
9669                 && (strcmp(res->rate, "rate") == 0))
9670                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9671                                         res->rate_num);
9672         if (ret < 0)
9673                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9674                         strerror(-ret));
9675
9676 }
9677
9678 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9679         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9680                                 set, "set");
9681 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9682         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9683                                 port, "port");
9684 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9685         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9686                                 port_num, RTE_UINT16);
9687 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9688         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9689                                 queue, "queue");
9690 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9691         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9692                                 queue_num, RTE_UINT8);
9693 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9694         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9695                                 rate, "rate");
9696 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9697         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9698                                 rate_num, RTE_UINT16);
9699
9700 cmdline_parse_inst_t cmd_queue_rate_limit = {
9701         .f = cmd_queue_rate_limit_parsed,
9702         .data = (void *)0,
9703         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9704                 "Set rate limit for a queue on port_id",
9705         .tokens = {
9706                 (void *)&cmd_queue_rate_limit_set,
9707                 (void *)&cmd_queue_rate_limit_port,
9708                 (void *)&cmd_queue_rate_limit_portnum,
9709                 (void *)&cmd_queue_rate_limit_queue,
9710                 (void *)&cmd_queue_rate_limit_queuenum,
9711                 (void *)&cmd_queue_rate_limit_rate,
9712                 (void *)&cmd_queue_rate_limit_ratenum,
9713                 NULL,
9714         },
9715 };
9716
9717 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9718 struct cmd_vf_rate_limit_result {
9719         cmdline_fixed_string_t set;
9720         cmdline_fixed_string_t port;
9721         uint16_t port_num;
9722         cmdline_fixed_string_t vf;
9723         uint8_t vf_num;
9724         cmdline_fixed_string_t rate;
9725         uint16_t rate_num;
9726         cmdline_fixed_string_t q_msk;
9727         uint64_t q_msk_val;
9728 };
9729
9730 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9731                 __rte_unused struct cmdline *cl,
9732                 __rte_unused void *data)
9733 {
9734         struct cmd_vf_rate_limit_result *res = parsed_result;
9735         int ret = 0;
9736
9737         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9738                 && (strcmp(res->vf, "vf") == 0)
9739                 && (strcmp(res->rate, "rate") == 0)
9740                 && (strcmp(res->q_msk, "queue_mask") == 0))
9741                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9742                                         res->rate_num, res->q_msk_val);
9743         if (ret < 0)
9744                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9745                         strerror(-ret));
9746
9747 }
9748
9749 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9750         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9751                                 set, "set");
9752 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9753         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9754                                 port, "port");
9755 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9756         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9757                                 port_num, RTE_UINT16);
9758 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9759         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9760                                 vf, "vf");
9761 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9762         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9763                                 vf_num, RTE_UINT8);
9764 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9765         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9766                                 rate, "rate");
9767 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9768         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9769                                 rate_num, RTE_UINT16);
9770 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9771         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9772                                 q_msk, "queue_mask");
9773 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9774         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9775                                 q_msk_val, RTE_UINT64);
9776
9777 cmdline_parse_inst_t cmd_vf_rate_limit = {
9778         .f = cmd_vf_rate_limit_parsed,
9779         .data = (void *)0,
9780         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9781                 "queue_mask <queue_mask_value>: "
9782                 "Set rate limit for queues of VF on port_id",
9783         .tokens = {
9784                 (void *)&cmd_vf_rate_limit_set,
9785                 (void *)&cmd_vf_rate_limit_port,
9786                 (void *)&cmd_vf_rate_limit_portnum,
9787                 (void *)&cmd_vf_rate_limit_vf,
9788                 (void *)&cmd_vf_rate_limit_vfnum,
9789                 (void *)&cmd_vf_rate_limit_rate,
9790                 (void *)&cmd_vf_rate_limit_ratenum,
9791                 (void *)&cmd_vf_rate_limit_q_msk,
9792                 (void *)&cmd_vf_rate_limit_q_msk_val,
9793                 NULL,
9794         },
9795 };
9796
9797 /* *** CONFIGURE TUNNEL UDP PORT *** */
9798 struct cmd_tunnel_udp_config {
9799         cmdline_fixed_string_t rx_vxlan_port;
9800         cmdline_fixed_string_t what;
9801         uint16_t udp_port;
9802         portid_t port_id;
9803 };
9804
9805 static void
9806 cmd_tunnel_udp_config_parsed(void *parsed_result,
9807                           __rte_unused struct cmdline *cl,
9808                           __rte_unused void *data)
9809 {
9810         struct cmd_tunnel_udp_config *res = parsed_result;
9811         struct rte_eth_udp_tunnel tunnel_udp;
9812         int ret;
9813
9814         tunnel_udp.udp_port = res->udp_port;
9815         tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9816
9817         if (!strcmp(res->what, "add"))
9818                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9819                                                       &tunnel_udp);
9820         else
9821                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9822                                                          &tunnel_udp);
9823
9824         if (ret < 0)
9825                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9826                         strerror(-ret));
9827 }
9828
9829 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9830         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9831                                 rx_vxlan_port, "rx_vxlan_port");
9832 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9833         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9834                                 what, "add#rm");
9835 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9836         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9837                                 udp_port, RTE_UINT16);
9838 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9839         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9840                                 port_id, RTE_UINT16);
9841
9842 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9843         .f = cmd_tunnel_udp_config_parsed,
9844         .data = (void *)0,
9845         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9846                 "Add/Remove a tunneling UDP port filter",
9847         .tokens = {
9848                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9849                 (void *)&cmd_tunnel_udp_config_what,
9850                 (void *)&cmd_tunnel_udp_config_udp_port,
9851                 (void *)&cmd_tunnel_udp_config_port_id,
9852                 NULL,
9853         },
9854 };
9855
9856 struct cmd_config_tunnel_udp_port {
9857         cmdline_fixed_string_t port;
9858         cmdline_fixed_string_t config;
9859         portid_t port_id;
9860         cmdline_fixed_string_t udp_tunnel_port;
9861         cmdline_fixed_string_t action;
9862         cmdline_fixed_string_t tunnel_type;
9863         uint16_t udp_port;
9864 };
9865
9866 static void
9867 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9868                                __rte_unused struct cmdline *cl,
9869                                __rte_unused void *data)
9870 {
9871         struct cmd_config_tunnel_udp_port *res = parsed_result;
9872         struct rte_eth_udp_tunnel tunnel_udp;
9873         int ret = 0;
9874
9875         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9876                 return;
9877
9878         tunnel_udp.udp_port = res->udp_port;
9879
9880         if (!strcmp(res->tunnel_type, "vxlan")) {
9881                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9882         } else if (!strcmp(res->tunnel_type, "geneve")) {
9883                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9884         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9885                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9886         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9887                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9888         } else {
9889                 fprintf(stderr, "Invalid tunnel type\n");
9890                 return;
9891         }
9892
9893         if (!strcmp(res->action, "add"))
9894                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9895                                                       &tunnel_udp);
9896         else
9897                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9898                                                          &tunnel_udp);
9899
9900         if (ret < 0)
9901                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9902                         strerror(-ret));
9903 }
9904
9905 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9906         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9907                                  "port");
9908 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9909         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9910                                  "config");
9911 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9912         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9913                               RTE_UINT16);
9914 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9915         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9916                                  udp_tunnel_port,
9917                                  "udp_tunnel_port");
9918 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9919         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9920                                  "add#rm");
9921 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9922         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9923                                  "vxlan#geneve#vxlan-gpe#ecpri");
9924 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9925         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9926                               RTE_UINT16);
9927
9928 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9929         .f = cmd_cfg_tunnel_udp_port_parsed,
9930         .data = NULL,
9931         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9932                 "geneve|vxlan-gpe|ecpri <udp_port>",
9933         .tokens = {
9934                 (void *)&cmd_config_tunnel_udp_port_port,
9935                 (void *)&cmd_config_tunnel_udp_port_config,
9936                 (void *)&cmd_config_tunnel_udp_port_port_id,
9937                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9938                 (void *)&cmd_config_tunnel_udp_port_action,
9939                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9940                 (void *)&cmd_config_tunnel_udp_port_value,
9941                 NULL,
9942         },
9943 };
9944
9945 /* ******************************************************************************** */
9946
9947 struct cmd_dump_result {
9948         cmdline_fixed_string_t dump;
9949 };
9950
9951 static void
9952 dump_struct_sizes(void)
9953 {
9954 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9955         DUMP_SIZE(struct rte_mbuf);
9956         DUMP_SIZE(struct rte_mempool);
9957         DUMP_SIZE(struct rte_ring);
9958 #undef DUMP_SIZE
9959 }
9960
9961
9962 /* Dump the socket memory statistics on console */
9963 static void
9964 dump_socket_mem(FILE *f)
9965 {
9966         struct rte_malloc_socket_stats socket_stats;
9967         unsigned int i;
9968         size_t total = 0;
9969         size_t alloc = 0;
9970         size_t free = 0;
9971         unsigned int n_alloc = 0;
9972         unsigned int n_free = 0;
9973         static size_t last_allocs;
9974         static size_t last_total;
9975
9976
9977         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9978                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9979                     !socket_stats.heap_totalsz_bytes)
9980                         continue;
9981                 total += socket_stats.heap_totalsz_bytes;
9982                 alloc += socket_stats.heap_allocsz_bytes;
9983                 free += socket_stats.heap_freesz_bytes;
9984                 n_alloc += socket_stats.alloc_count;
9985                 n_free += socket_stats.free_count;
9986                 fprintf(f,
9987                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9988                         i,
9989                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9990                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9991                         (double)socket_stats.heap_allocsz_bytes * 100 /
9992                         (double)socket_stats.heap_totalsz_bytes,
9993                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9994                         socket_stats.alloc_count,
9995                         socket_stats.free_count);
9996         }
9997         fprintf(f,
9998                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9999                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
10000                 total ? ((double)alloc * 100 / (double)total) : 0,
10001                 (double)free / (1024 * 1024),
10002                 n_alloc, n_free);
10003         if (last_allocs)
10004                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
10005                         ((double)total - (double)last_total) / (1024 * 1024),
10006                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
10007         last_allocs = alloc;
10008         last_total = total;
10009 }
10010
10011 static void cmd_dump_parsed(void *parsed_result,
10012                             __rte_unused struct cmdline *cl,
10013                             __rte_unused void *data)
10014 {
10015         struct cmd_dump_result *res = parsed_result;
10016
10017         if (!strcmp(res->dump, "dump_physmem"))
10018                 rte_dump_physmem_layout(stdout);
10019         else if (!strcmp(res->dump, "dump_socket_mem"))
10020                 dump_socket_mem(stdout);
10021         else if (!strcmp(res->dump, "dump_memzone"))
10022                 rte_memzone_dump(stdout);
10023         else if (!strcmp(res->dump, "dump_struct_sizes"))
10024                 dump_struct_sizes();
10025         else if (!strcmp(res->dump, "dump_ring"))
10026                 rte_ring_list_dump(stdout);
10027         else if (!strcmp(res->dump, "dump_mempool"))
10028                 rte_mempool_list_dump(stdout);
10029         else if (!strcmp(res->dump, "dump_devargs"))
10030                 rte_devargs_dump(stdout);
10031         else if (!strcmp(res->dump, "dump_log_types"))
10032                 rte_log_dump(stdout);
10033 }
10034
10035 cmdline_parse_token_string_t cmd_dump_dump =
10036         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10037                 "dump_physmem#"
10038                 "dump_memzone#"
10039                 "dump_socket_mem#"
10040                 "dump_struct_sizes#"
10041                 "dump_ring#"
10042                 "dump_mempool#"
10043                 "dump_devargs#"
10044                 "dump_log_types");
10045
10046 cmdline_parse_inst_t cmd_dump = {
10047         .f = cmd_dump_parsed,  /* function to call */
10048         .data = NULL,      /* 2nd arg of func */
10049         .help_str = "Dump status",
10050         .tokens = {        /* token list, NULL terminated */
10051                 (void *)&cmd_dump_dump,
10052                 NULL,
10053         },
10054 };
10055
10056 /* ******************************************************************************** */
10057
10058 struct cmd_dump_one_result {
10059         cmdline_fixed_string_t dump;
10060         cmdline_fixed_string_t name;
10061 };
10062
10063 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10064                                 __rte_unused void *data)
10065 {
10066         struct cmd_dump_one_result *res = parsed_result;
10067
10068         if (!strcmp(res->dump, "dump_ring")) {
10069                 struct rte_ring *r;
10070                 r = rte_ring_lookup(res->name);
10071                 if (r == NULL) {
10072                         cmdline_printf(cl, "Cannot find ring\n");
10073                         return;
10074                 }
10075                 rte_ring_dump(stdout, r);
10076         } else if (!strcmp(res->dump, "dump_mempool")) {
10077                 struct rte_mempool *mp;
10078                 mp = rte_mempool_lookup(res->name);
10079                 if (mp == NULL) {
10080                         cmdline_printf(cl, "Cannot find mempool\n");
10081                         return;
10082                 }
10083                 rte_mempool_dump(stdout, mp);
10084         }
10085 }
10086
10087 cmdline_parse_token_string_t cmd_dump_one_dump =
10088         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10089                                  "dump_ring#dump_mempool");
10090
10091 cmdline_parse_token_string_t cmd_dump_one_name =
10092         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10093
10094 cmdline_parse_inst_t cmd_dump_one = {
10095         .f = cmd_dump_one_parsed,  /* function to call */
10096         .data = NULL,      /* 2nd arg of func */
10097         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10098         .tokens = {        /* token list, NULL terminated */
10099                 (void *)&cmd_dump_one_dump,
10100                 (void *)&cmd_dump_one_name,
10101                 NULL,
10102         },
10103 };
10104
10105 /* *** queue region set *** */
10106 struct cmd_queue_region_result {
10107         cmdline_fixed_string_t set;
10108         cmdline_fixed_string_t port;
10109         portid_t port_id;
10110         cmdline_fixed_string_t cmd;
10111         cmdline_fixed_string_t region;
10112         uint8_t  region_id;
10113         cmdline_fixed_string_t queue_start_index;
10114         uint8_t  queue_id;
10115         cmdline_fixed_string_t queue_num;
10116         uint8_t  queue_num_value;
10117 };
10118
10119 static void
10120 cmd_queue_region_parsed(void *parsed_result,
10121                         __rte_unused struct cmdline *cl,
10122                         __rte_unused void *data)
10123 {
10124         struct cmd_queue_region_result *res = parsed_result;
10125         int ret = -ENOTSUP;
10126 #ifdef RTE_NET_I40E
10127         struct rte_pmd_i40e_queue_region_conf region_conf;
10128         enum rte_pmd_i40e_queue_region_op op_type;
10129 #endif
10130
10131         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10132                 return;
10133
10134 #ifdef RTE_NET_I40E
10135         memset(&region_conf, 0, sizeof(region_conf));
10136         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10137         region_conf.region_id = res->region_id;
10138         region_conf.queue_num = res->queue_num_value;
10139         region_conf.queue_start_index = res->queue_id;
10140
10141         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10142                                 op_type, &region_conf);
10143 #endif
10144
10145         switch (ret) {
10146         case 0:
10147                 break;
10148         case -ENOTSUP:
10149                 fprintf(stderr, "function not implemented or supported\n");
10150                 break;
10151         default:
10152                 fprintf(stderr, "queue region config error: (%s)\n",
10153                         strerror(-ret));
10154         }
10155 }
10156
10157 cmdline_parse_token_string_t cmd_queue_region_set =
10158 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10159                 set, "set");
10160 cmdline_parse_token_string_t cmd_queue_region_port =
10161         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10162 cmdline_parse_token_num_t cmd_queue_region_port_id =
10163         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10164                                 port_id, RTE_UINT16);
10165 cmdline_parse_token_string_t cmd_queue_region_cmd =
10166         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10167                                  cmd, "queue-region");
10168 cmdline_parse_token_string_t cmd_queue_region_id =
10169         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10170                                 region, "region_id");
10171 cmdline_parse_token_num_t cmd_queue_region_index =
10172         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10173                                 region_id, RTE_UINT8);
10174 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10175         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10176                                 queue_start_index, "queue_start_index");
10177 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10178         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10179                                 queue_id, RTE_UINT8);
10180 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10181         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10182                                 queue_num, "queue_num");
10183 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10184         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10185                                 queue_num_value, RTE_UINT8);
10186
10187 cmdline_parse_inst_t cmd_queue_region = {
10188         .f = cmd_queue_region_parsed,
10189         .data = NULL,
10190         .help_str = "set port <port_id> queue-region region_id <value> "
10191                 "queue_start_index <value> queue_num <value>: Set a queue region",
10192         .tokens = {
10193                 (void *)&cmd_queue_region_set,
10194                 (void *)&cmd_queue_region_port,
10195                 (void *)&cmd_queue_region_port_id,
10196                 (void *)&cmd_queue_region_cmd,
10197                 (void *)&cmd_queue_region_id,
10198                 (void *)&cmd_queue_region_index,
10199                 (void *)&cmd_queue_region_queue_start_index,
10200                 (void *)&cmd_queue_region_queue_id,
10201                 (void *)&cmd_queue_region_queue_num,
10202                 (void *)&cmd_queue_region_queue_num_value,
10203                 NULL,
10204         },
10205 };
10206
10207 /* *** queue region and flowtype set *** */
10208 struct cmd_region_flowtype_result {
10209         cmdline_fixed_string_t set;
10210         cmdline_fixed_string_t port;
10211         portid_t port_id;
10212         cmdline_fixed_string_t cmd;
10213         cmdline_fixed_string_t region;
10214         uint8_t  region_id;
10215         cmdline_fixed_string_t flowtype;
10216         uint8_t  flowtype_id;
10217 };
10218
10219 static void
10220 cmd_region_flowtype_parsed(void *parsed_result,
10221                         __rte_unused struct cmdline *cl,
10222                         __rte_unused void *data)
10223 {
10224         struct cmd_region_flowtype_result *res = parsed_result;
10225         int ret = -ENOTSUP;
10226 #ifdef RTE_NET_I40E
10227         struct rte_pmd_i40e_queue_region_conf region_conf;
10228         enum rte_pmd_i40e_queue_region_op op_type;
10229 #endif
10230
10231         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10232                 return;
10233
10234 #ifdef RTE_NET_I40E
10235         memset(&region_conf, 0, sizeof(region_conf));
10236
10237         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10238         region_conf.region_id = res->region_id;
10239         region_conf.hw_flowtype = res->flowtype_id;
10240
10241         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10242                         op_type, &region_conf);
10243 #endif
10244
10245         switch (ret) {
10246         case 0:
10247                 break;
10248         case -ENOTSUP:
10249                 fprintf(stderr, "function not implemented or supported\n");
10250                 break;
10251         default:
10252                 fprintf(stderr, "region flowtype config error: (%s)\n",
10253                         strerror(-ret));
10254         }
10255 }
10256
10257 cmdline_parse_token_string_t cmd_region_flowtype_set =
10258 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10259                                 set, "set");
10260 cmdline_parse_token_string_t cmd_region_flowtype_port =
10261         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10262                                 port, "port");
10263 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10264         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10265                                 port_id, RTE_UINT16);
10266 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10267         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10268                                 cmd, "queue-region");
10269 cmdline_parse_token_string_t cmd_region_flowtype_index =
10270         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10271                                 region, "region_id");
10272 cmdline_parse_token_num_t cmd_region_flowtype_id =
10273         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10274                                 region_id, RTE_UINT8);
10275 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10276         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10277                                 flowtype, "flowtype");
10278 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10279         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10280                                 flowtype_id, RTE_UINT8);
10281 cmdline_parse_inst_t cmd_region_flowtype = {
10282         .f = cmd_region_flowtype_parsed,
10283         .data = NULL,
10284         .help_str = "set port <port_id> queue-region region_id <value> "
10285                 "flowtype <value>: Set a flowtype region index",
10286         .tokens = {
10287                 (void *)&cmd_region_flowtype_set,
10288                 (void *)&cmd_region_flowtype_port,
10289                 (void *)&cmd_region_flowtype_port_index,
10290                 (void *)&cmd_region_flowtype_cmd,
10291                 (void *)&cmd_region_flowtype_index,
10292                 (void *)&cmd_region_flowtype_id,
10293                 (void *)&cmd_region_flowtype_flow_index,
10294                 (void *)&cmd_region_flowtype_flow_id,
10295                 NULL,
10296         },
10297 };
10298
10299 /* *** User Priority (UP) to queue region (region_id) set *** */
10300 struct cmd_user_priority_region_result {
10301         cmdline_fixed_string_t set;
10302         cmdline_fixed_string_t port;
10303         portid_t port_id;
10304         cmdline_fixed_string_t cmd;
10305         cmdline_fixed_string_t user_priority;
10306         uint8_t  user_priority_id;
10307         cmdline_fixed_string_t region;
10308         uint8_t  region_id;
10309 };
10310
10311 static void
10312 cmd_user_priority_region_parsed(void *parsed_result,
10313                         __rte_unused struct cmdline *cl,
10314                         __rte_unused void *data)
10315 {
10316         struct cmd_user_priority_region_result *res = parsed_result;
10317         int ret = -ENOTSUP;
10318 #ifdef RTE_NET_I40E
10319         struct rte_pmd_i40e_queue_region_conf region_conf;
10320         enum rte_pmd_i40e_queue_region_op op_type;
10321 #endif
10322
10323         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10324                 return;
10325
10326 #ifdef RTE_NET_I40E
10327         memset(&region_conf, 0, sizeof(region_conf));
10328         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10329         region_conf.user_priority = res->user_priority_id;
10330         region_conf.region_id = res->region_id;
10331
10332         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10333                                 op_type, &region_conf);
10334 #endif
10335
10336         switch (ret) {
10337         case 0:
10338                 break;
10339         case -ENOTSUP:
10340                 fprintf(stderr, "function not implemented or supported\n");
10341                 break;
10342         default:
10343                 fprintf(stderr, "user_priority region config error: (%s)\n",
10344                         strerror(-ret));
10345         }
10346 }
10347
10348 cmdline_parse_token_string_t cmd_user_priority_region_set =
10349         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10350                                 set, "set");
10351 cmdline_parse_token_string_t cmd_user_priority_region_port =
10352         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10353                                 port, "port");
10354 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10355         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10356                                 port_id, RTE_UINT16);
10357 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10358         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10359                                 cmd, "queue-region");
10360 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10361         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10362                                 user_priority, "UP");
10363 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10364         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10365                                 user_priority_id, RTE_UINT8);
10366 cmdline_parse_token_string_t cmd_user_priority_region_region =
10367         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10368                                 region, "region_id");
10369 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10370         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10371                                 region_id, RTE_UINT8);
10372
10373 cmdline_parse_inst_t cmd_user_priority_region = {
10374         .f = cmd_user_priority_region_parsed,
10375         .data = NULL,
10376         .help_str = "set port <port_id> queue-region UP <value> "
10377                 "region_id <value>: Set the mapping of User Priority (UP) "
10378                 "to queue region (region_id) ",
10379         .tokens = {
10380                 (void *)&cmd_user_priority_region_set,
10381                 (void *)&cmd_user_priority_region_port,
10382                 (void *)&cmd_user_priority_region_port_index,
10383                 (void *)&cmd_user_priority_region_cmd,
10384                 (void *)&cmd_user_priority_region_UP,
10385                 (void *)&cmd_user_priority_region_UP_id,
10386                 (void *)&cmd_user_priority_region_region,
10387                 (void *)&cmd_user_priority_region_region_id,
10388                 NULL,
10389         },
10390 };
10391
10392 /* *** flush all queue region related configuration *** */
10393 struct cmd_flush_queue_region_result {
10394         cmdline_fixed_string_t set;
10395         cmdline_fixed_string_t port;
10396         portid_t port_id;
10397         cmdline_fixed_string_t cmd;
10398         cmdline_fixed_string_t flush;
10399         cmdline_fixed_string_t what;
10400 };
10401
10402 static void
10403 cmd_flush_queue_region_parsed(void *parsed_result,
10404                         __rte_unused struct cmdline *cl,
10405                         __rte_unused void *data)
10406 {
10407         struct cmd_flush_queue_region_result *res = parsed_result;
10408         int ret = -ENOTSUP;
10409 #ifdef RTE_NET_I40E
10410         struct rte_pmd_i40e_queue_region_conf region_conf;
10411         enum rte_pmd_i40e_queue_region_op op_type;
10412 #endif
10413
10414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10415                 return;
10416
10417 #ifdef RTE_NET_I40E
10418         memset(&region_conf, 0, sizeof(region_conf));
10419
10420         if (strcmp(res->what, "on") == 0)
10421                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10422         else
10423                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10424
10425         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10426                                 op_type, &region_conf);
10427 #endif
10428
10429         switch (ret) {
10430         case 0:
10431                 break;
10432         case -ENOTSUP:
10433                 fprintf(stderr, "function not implemented or supported\n");
10434                 break;
10435         default:
10436                 fprintf(stderr, "queue region config flush error: (%s)\n",
10437                         strerror(-ret));
10438         }
10439 }
10440
10441 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10443                                 set, "set");
10444 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10445         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10446                                 port, "port");
10447 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10448         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10449                                 port_id, RTE_UINT16);
10450 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10451         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10452                                 cmd, "queue-region");
10453 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10454         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10455                                 flush, "flush");
10456 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10457         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10458                                 what, "on#off");
10459
10460 cmdline_parse_inst_t cmd_flush_queue_region = {
10461         .f = cmd_flush_queue_region_parsed,
10462         .data = NULL,
10463         .help_str = "set port <port_id> queue-region flush on|off"
10464                 ": flush all queue region related configuration",
10465         .tokens = {
10466                 (void *)&cmd_flush_queue_region_set,
10467                 (void *)&cmd_flush_queue_region_port,
10468                 (void *)&cmd_flush_queue_region_port_index,
10469                 (void *)&cmd_flush_queue_region_cmd,
10470                 (void *)&cmd_flush_queue_region_flush,
10471                 (void *)&cmd_flush_queue_region_what,
10472                 NULL,
10473         },
10474 };
10475
10476 /* *** get all queue region related configuration info *** */
10477 struct cmd_show_queue_region_info {
10478         cmdline_fixed_string_t show;
10479         cmdline_fixed_string_t port;
10480         portid_t port_id;
10481         cmdline_fixed_string_t cmd;
10482 };
10483
10484 static void
10485 cmd_show_queue_region_info_parsed(void *parsed_result,
10486                         __rte_unused struct cmdline *cl,
10487                         __rte_unused void *data)
10488 {
10489         struct cmd_show_queue_region_info *res = parsed_result;
10490         int ret = -ENOTSUP;
10491 #ifdef RTE_NET_I40E
10492         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10493         enum rte_pmd_i40e_queue_region_op op_type;
10494 #endif
10495
10496         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10497                 return;
10498
10499 #ifdef RTE_NET_I40E
10500         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10501
10502         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10503
10504         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10505                                         op_type, &rte_pmd_regions);
10506
10507         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10508 #endif
10509
10510         switch (ret) {
10511         case 0:
10512                 break;
10513         case -ENOTSUP:
10514                 fprintf(stderr, "function not implemented or supported\n");
10515                 break;
10516         default:
10517                 fprintf(stderr, "queue region config info show error: (%s)\n",
10518                         strerror(-ret));
10519         }
10520 }
10521
10522 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10523 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10524                                 show, "show");
10525 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10526         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10527                                 port, "port");
10528 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10529         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10530                                 port_id, RTE_UINT16);
10531 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10532         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10533                                 cmd, "queue-region");
10534
10535 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10536         .f = cmd_show_queue_region_info_parsed,
10537         .data = NULL,
10538         .help_str = "show port <port_id> queue-region"
10539                 ": show all queue region related configuration info",
10540         .tokens = {
10541                 (void *)&cmd_show_queue_region_info_get,
10542                 (void *)&cmd_show_queue_region_info_port,
10543                 (void *)&cmd_show_queue_region_info_port_index,
10544                 (void *)&cmd_show_queue_region_info_cmd,
10545                 NULL,
10546         },
10547 };
10548
10549 /* *** Filters Control *** */
10550
10551 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10552 do { \
10553         if ((ip_addr).family == AF_INET) \
10554                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10555         else { \
10556                 fprintf(stderr, "invalid parameter.\n"); \
10557                 return; \
10558         } \
10559 } while (0)
10560
10561 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10562 do { \
10563         if ((ip_addr).family == AF_INET6) \
10564                 rte_memcpy(&(ip), \
10565                                  &((ip_addr).addr.ipv6), \
10566                                  sizeof(struct in6_addr)); \
10567         else { \
10568                 fprintf(stderr, "invalid parameter.\n"); \
10569                 return; \
10570         } \
10571 } while (0)
10572
10573 #ifdef RTE_NET_I40E
10574
10575 static uint16_t
10576 str2flowtype(char *string)
10577 {
10578         uint8_t i = 0;
10579         static const struct {
10580                 char str[32];
10581                 uint16_t type;
10582         } flowtype_str[] = {
10583                 {"raw", RTE_ETH_FLOW_RAW},
10584                 {"ipv4", RTE_ETH_FLOW_IPV4},
10585                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10586                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10587                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10588                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10589                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10590                 {"ipv6", RTE_ETH_FLOW_IPV6},
10591                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10592                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10593                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10594                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10595                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10596                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10597                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10598                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10599                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10600                 {"gtpu", RTE_ETH_FLOW_GTPU},
10601         };
10602
10603         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10604                 if (!strcmp(flowtype_str[i].str, string))
10605                         return flowtype_str[i].type;
10606         }
10607
10608         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10609                 return (uint16_t)atoi(string);
10610
10611         return RTE_ETH_FLOW_UNKNOWN;
10612 }
10613
10614 /* *** deal with flow director filter *** */
10615 struct cmd_flow_director_result {
10616         cmdline_fixed_string_t flow_director_filter;
10617         portid_t port_id;
10618         cmdline_fixed_string_t mode;
10619         cmdline_fixed_string_t mode_value;
10620         cmdline_fixed_string_t ops;
10621         cmdline_fixed_string_t flow;
10622         cmdline_fixed_string_t flow_type;
10623         cmdline_fixed_string_t drop;
10624         cmdline_fixed_string_t queue;
10625         uint16_t  queue_id;
10626         cmdline_fixed_string_t fd_id;
10627         uint32_t  fd_id_value;
10628         cmdline_fixed_string_t packet;
10629         char filepath[];
10630 };
10631
10632 static void
10633 cmd_flow_director_filter_parsed(void *parsed_result,
10634                           __rte_unused struct cmdline *cl,
10635                           __rte_unused void *data)
10636 {
10637         struct cmd_flow_director_result *res = parsed_result;
10638         int ret = 0;
10639         struct rte_pmd_i40e_flow_type_mapping
10640                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10641         struct rte_pmd_i40e_pkt_template_conf conf;
10642         uint16_t flow_type = str2flowtype(res->flow_type);
10643         uint16_t i, port = res->port_id;
10644         uint8_t add;
10645
10646         memset(&conf, 0, sizeof(conf));
10647
10648         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10649                 fprintf(stderr, "Invalid flow type specified.\n");
10650                 return;
10651         }
10652         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10653                                                  mapping);
10654         if (ret)
10655                 return;
10656         if (mapping[flow_type].pctype == 0ULL) {
10657                 fprintf(stderr, "Invalid flow type specified.\n");
10658                 return;
10659         }
10660         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10661                 if (mapping[flow_type].pctype & (1ULL << i)) {
10662                         conf.input.pctype = i;
10663                         break;
10664                 }
10665         }
10666
10667         conf.input.packet = open_file(res->filepath,
10668                                 &conf.input.length);
10669         if (!conf.input.packet)
10670                 return;
10671         if (!strcmp(res->drop, "drop"))
10672                 conf.action.behavior =
10673                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10674         else
10675                 conf.action.behavior =
10676                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10677         conf.action.report_status =
10678                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10679         conf.action.rx_queue = res->queue_id;
10680         conf.soft_id = res->fd_id_value;
10681         add  = strcmp(res->ops, "del") ? 1 : 0;
10682         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10683                                                         &conf,
10684                                                         add);
10685         if (ret < 0)
10686                 fprintf(stderr, "flow director config error: (%s)\n",
10687                         strerror(-ret));
10688         close_file(conf.input.packet);
10689 }
10690
10691 cmdline_parse_token_string_t cmd_flow_director_filter =
10692         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10693                                  flow_director_filter, "flow_director_filter");
10694 cmdline_parse_token_num_t cmd_flow_director_port_id =
10695         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10696                               port_id, RTE_UINT16);
10697 cmdline_parse_token_string_t cmd_flow_director_ops =
10698         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10699                                  ops, "add#del#update");
10700 cmdline_parse_token_string_t cmd_flow_director_flow =
10701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10702                                  flow, "flow");
10703 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10704         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10705                 flow_type, NULL);
10706 cmdline_parse_token_string_t cmd_flow_director_drop =
10707         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10708                                  drop, "drop#fwd");
10709 cmdline_parse_token_string_t cmd_flow_director_queue =
10710         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10711                                  queue, "queue");
10712 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10713         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10714                               queue_id, RTE_UINT16);
10715 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10716         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10717                                  fd_id, "fd_id");
10718 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10719         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10720                               fd_id_value, RTE_UINT32);
10721
10722 cmdline_parse_token_string_t cmd_flow_director_mode =
10723         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10724                                  mode, "mode");
10725 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10727                                  mode_value, "raw");
10728 cmdline_parse_token_string_t cmd_flow_director_packet =
10729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10730                                  packet, "packet");
10731 cmdline_parse_token_string_t cmd_flow_director_filepath =
10732         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10733                                  filepath, NULL);
10734
10735 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10736         .f = cmd_flow_director_filter_parsed,
10737         .data = NULL,
10738         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10739                 "director entry on NIC",
10740         .tokens = {
10741                 (void *)&cmd_flow_director_filter,
10742                 (void *)&cmd_flow_director_port_id,
10743                 (void *)&cmd_flow_director_mode,
10744                 (void *)&cmd_flow_director_mode_raw,
10745                 (void *)&cmd_flow_director_ops,
10746                 (void *)&cmd_flow_director_flow,
10747                 (void *)&cmd_flow_director_flow_type,
10748                 (void *)&cmd_flow_director_drop,
10749                 (void *)&cmd_flow_director_queue,
10750                 (void *)&cmd_flow_director_queue_id,
10751                 (void *)&cmd_flow_director_fd_id,
10752                 (void *)&cmd_flow_director_fd_id_value,
10753                 (void *)&cmd_flow_director_packet,
10754                 (void *)&cmd_flow_director_filepath,
10755                 NULL,
10756         },
10757 };
10758
10759 #endif /* RTE_NET_I40E */
10760
10761 /* *** deal with flow director mask *** */
10762 struct cmd_flow_director_mask_result {
10763         cmdline_fixed_string_t flow_director_mask;
10764         portid_t port_id;
10765         cmdline_fixed_string_t mode;
10766         cmdline_fixed_string_t mode_value;
10767         cmdline_fixed_string_t vlan;
10768         uint16_t vlan_mask;
10769         cmdline_fixed_string_t src_mask;
10770         cmdline_ipaddr_t ipv4_src;
10771         cmdline_ipaddr_t ipv6_src;
10772         uint16_t port_src;
10773         cmdline_fixed_string_t dst_mask;
10774         cmdline_ipaddr_t ipv4_dst;
10775         cmdline_ipaddr_t ipv6_dst;
10776         uint16_t port_dst;
10777         cmdline_fixed_string_t mac;
10778         uint8_t mac_addr_byte_mask;
10779         cmdline_fixed_string_t tunnel_id;
10780         uint32_t tunnel_id_mask;
10781         cmdline_fixed_string_t tunnel_type;
10782         uint8_t tunnel_type_mask;
10783 };
10784
10785 static void
10786 cmd_flow_director_mask_parsed(void *parsed_result,
10787                           __rte_unused struct cmdline *cl,
10788                           __rte_unused void *data)
10789 {
10790         struct cmd_flow_director_mask_result *res = parsed_result;
10791         struct rte_eth_fdir_masks *mask;
10792         struct rte_port *port;
10793
10794         port = &ports[res->port_id];
10795         /** Check if the port is not started **/
10796         if (port->port_status != RTE_PORT_STOPPED) {
10797                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10798                 return;
10799         }
10800
10801         mask = &port->dev_conf.fdir_conf.mask;
10802
10803         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10804                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10805                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10806                         return;
10807                 }
10808
10809                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10810         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10811                 if (strcmp(res->mode_value, "Tunnel")) {
10812                         fprintf(stderr, "Please set mode to Tunnel.\n");
10813                         return;
10814                 }
10815
10816                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10817                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10818                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10819                 mask->tunnel_type_mask = res->tunnel_type_mask;
10820         } else {
10821                 if (strcmp(res->mode_value, "IP")) {
10822                         fprintf(stderr, "Please set mode to IP.\n");
10823                         return;
10824                 }
10825
10826                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10827                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10828                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10829                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10830                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10831                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10832                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10833         }
10834
10835         cmd_reconfig_device_queue(res->port_id, 1, 1);
10836 }
10837
10838 cmdline_parse_token_string_t cmd_flow_director_mask =
10839         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10840                                  flow_director_mask, "flow_director_mask");
10841 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10842         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10843                               port_id, RTE_UINT16);
10844 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10845         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10846                                  vlan, "vlan");
10847 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10848         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10849                               vlan_mask, RTE_UINT16);
10850 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10851         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10852                                  src_mask, "src_mask");
10853 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10854         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10855                                  ipv4_src);
10856 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10857         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10858                                  ipv6_src);
10859 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10860         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10861                               port_src, RTE_UINT16);
10862 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10863         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10864                                  dst_mask, "dst_mask");
10865 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10866         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10867                                  ipv4_dst);
10868 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10869         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10870                                  ipv6_dst);
10871 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10872         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10873                               port_dst, RTE_UINT16);
10874
10875 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10876         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10877                                  mode, "mode");
10878 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10880                                  mode_value, "IP");
10881 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10882         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10883                                  mode_value, "MAC-VLAN");
10884 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10886                                  mode_value, "Tunnel");
10887 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10888         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10889                                  mac, "mac");
10890 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10891         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10892                               mac_addr_byte_mask, RTE_UINT8);
10893 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10894         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10895                                  tunnel_type, "tunnel-type");
10896 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10897         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10898                               tunnel_type_mask, RTE_UINT8);
10899 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10900         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10901                                  tunnel_id, "tunnel-id");
10902 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10903         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10904                               tunnel_id_mask, RTE_UINT32);
10905
10906 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10907         .f = cmd_flow_director_mask_parsed,
10908         .data = NULL,
10909         .help_str = "flow_director_mask ... : "
10910                 "Set IP mode flow director's mask on NIC",
10911         .tokens = {
10912                 (void *)&cmd_flow_director_mask,
10913                 (void *)&cmd_flow_director_mask_port_id,
10914                 (void *)&cmd_flow_director_mask_mode,
10915                 (void *)&cmd_flow_director_mask_mode_ip,
10916                 (void *)&cmd_flow_director_mask_vlan,
10917                 (void *)&cmd_flow_director_mask_vlan_value,
10918                 (void *)&cmd_flow_director_mask_src,
10919                 (void *)&cmd_flow_director_mask_ipv4_src,
10920                 (void *)&cmd_flow_director_mask_ipv6_src,
10921                 (void *)&cmd_flow_director_mask_port_src,
10922                 (void *)&cmd_flow_director_mask_dst,
10923                 (void *)&cmd_flow_director_mask_ipv4_dst,
10924                 (void *)&cmd_flow_director_mask_ipv6_dst,
10925                 (void *)&cmd_flow_director_mask_port_dst,
10926                 NULL,
10927         },
10928 };
10929
10930 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10931         .f = cmd_flow_director_mask_parsed,
10932         .data = NULL,
10933         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10934                 "flow director's mask on NIC",
10935         .tokens = {
10936                 (void *)&cmd_flow_director_mask,
10937                 (void *)&cmd_flow_director_mask_port_id,
10938                 (void *)&cmd_flow_director_mask_mode,
10939                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10940                 (void *)&cmd_flow_director_mask_vlan,
10941                 (void *)&cmd_flow_director_mask_vlan_value,
10942                 NULL,
10943         },
10944 };
10945
10946 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10947         .f = cmd_flow_director_mask_parsed,
10948         .data = NULL,
10949         .help_str = "flow_director_mask ... : Set tunnel mode "
10950                 "flow director's mask on NIC",
10951         .tokens = {
10952                 (void *)&cmd_flow_director_mask,
10953                 (void *)&cmd_flow_director_mask_port_id,
10954                 (void *)&cmd_flow_director_mask_mode,
10955                 (void *)&cmd_flow_director_mask_mode_tunnel,
10956                 (void *)&cmd_flow_director_mask_vlan,
10957                 (void *)&cmd_flow_director_mask_vlan_value,
10958                 (void *)&cmd_flow_director_mask_mac,
10959                 (void *)&cmd_flow_director_mask_mac_value,
10960                 (void *)&cmd_flow_director_mask_tunnel_type,
10961                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10962                 (void *)&cmd_flow_director_mask_tunnel_id,
10963                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10964                 NULL,
10965         },
10966 };
10967
10968 /* *** deal with flow director flexible payload configuration *** */
10969 struct cmd_flow_director_flexpayload_result {
10970         cmdline_fixed_string_t flow_director_flexpayload;
10971         portid_t port_id;
10972         cmdline_fixed_string_t payload_layer;
10973         cmdline_fixed_string_t payload_cfg;
10974 };
10975
10976 static inline int
10977 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10978 {
10979         char s[256];
10980         const char *p, *p0 = q_arg;
10981         char *end;
10982         unsigned long int_fld;
10983         char *str_fld[max_num];
10984         int i;
10985         unsigned size;
10986         int ret = -1;
10987
10988         p = strchr(p0, '(');
10989         if (p == NULL)
10990                 return -1;
10991         ++p;
10992         p0 = strchr(p, ')');
10993         if (p0 == NULL)
10994                 return -1;
10995
10996         size = p0 - p;
10997         if (size >= sizeof(s))
10998                 return -1;
10999
11000         snprintf(s, sizeof(s), "%.*s", size, p);
11001         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11002         if (ret < 0 || ret > max_num)
11003                 return -1;
11004         for (i = 0; i < ret; i++) {
11005                 errno = 0;
11006                 int_fld = strtoul(str_fld[i], &end, 0);
11007                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11008                         return -1;
11009                 offsets[i] = (uint16_t)int_fld;
11010         }
11011         return ret;
11012 }
11013
11014 static void
11015 cmd_flow_director_flxpld_parsed(void *parsed_result,
11016                           __rte_unused struct cmdline *cl,
11017                           __rte_unused void *data)
11018 {
11019         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11020         struct rte_eth_flex_payload_cfg flex_cfg;
11021         struct rte_port *port;
11022         int ret = 0;
11023
11024         port = &ports[res->port_id];
11025         /** Check if the port is not started **/
11026         if (port->port_status != RTE_PORT_STOPPED) {
11027                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
11028                 return;
11029         }
11030
11031         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11032
11033         if (!strcmp(res->payload_layer, "raw"))
11034                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11035         else if (!strcmp(res->payload_layer, "l2"))
11036                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11037         else if (!strcmp(res->payload_layer, "l3"))
11038                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11039         else if (!strcmp(res->payload_layer, "l4"))
11040                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11041
11042         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11043                             RTE_ETH_FDIR_MAX_FLEXLEN);
11044         if (ret < 0) {
11045                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
11046                 return;
11047         }
11048
11049         fdir_set_flex_payload(res->port_id, &flex_cfg);
11050         cmd_reconfig_device_queue(res->port_id, 1, 1);
11051 }
11052
11053 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11054         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11055                                  flow_director_flexpayload,
11056                                  "flow_director_flex_payload");
11057 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11058         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11059                               port_id, RTE_UINT16);
11060 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11061         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11062                                  payload_layer, "raw#l2#l3#l4");
11063 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11064         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11065                                  payload_cfg, NULL);
11066
11067 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11068         .f = cmd_flow_director_flxpld_parsed,
11069         .data = NULL,
11070         .help_str = "flow_director_flexpayload ... : "
11071                 "Set flow director's flex payload on NIC",
11072         .tokens = {
11073                 (void *)&cmd_flow_director_flexpayload,
11074                 (void *)&cmd_flow_director_flexpayload_port_id,
11075                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11076                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11077                 NULL,
11078         },
11079 };
11080
11081 /* Generic flow interface command. */
11082 extern cmdline_parse_inst_t cmd_flow;
11083
11084 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11085 struct cmd_mcast_addr_result {
11086         cmdline_fixed_string_t mcast_addr_cmd;
11087         cmdline_fixed_string_t what;
11088         uint16_t port_num;
11089         struct rte_ether_addr mc_addr;
11090 };
11091
11092 static void cmd_mcast_addr_parsed(void *parsed_result,
11093                 __rte_unused struct cmdline *cl,
11094                 __rte_unused void *data)
11095 {
11096         struct cmd_mcast_addr_result *res = parsed_result;
11097
11098         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11099                 fprintf(stderr,
11100                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11101                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11102                 return;
11103         }
11104         if (strcmp(res->what, "add") == 0)
11105                 mcast_addr_add(res->port_num, &res->mc_addr);
11106         else
11107                 mcast_addr_remove(res->port_num, &res->mc_addr);
11108 }
11109
11110 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11111         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11112                                  mcast_addr_cmd, "mcast_addr");
11113 cmdline_parse_token_string_t cmd_mcast_addr_what =
11114         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11115                                  "add#remove");
11116 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11117         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11118                                  RTE_UINT16);
11119 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11120         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11121
11122 cmdline_parse_inst_t cmd_mcast_addr = {
11123         .f = cmd_mcast_addr_parsed,
11124         .data = (void *)0,
11125         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11126                 "Add/Remove multicast MAC address on port_id",
11127         .tokens = {
11128                 (void *)&cmd_mcast_addr_cmd,
11129                 (void *)&cmd_mcast_addr_what,
11130                 (void *)&cmd_mcast_addr_portnum,
11131                 (void *)&cmd_mcast_addr_addr,
11132                 NULL,
11133         },
11134 };
11135
11136 /* vf vlan anti spoof configuration */
11137
11138 /* Common result structure for vf vlan anti spoof */
11139 struct cmd_vf_vlan_anti_spoof_result {
11140         cmdline_fixed_string_t set;
11141         cmdline_fixed_string_t vf;
11142         cmdline_fixed_string_t vlan;
11143         cmdline_fixed_string_t antispoof;
11144         portid_t port_id;
11145         uint32_t vf_id;
11146         cmdline_fixed_string_t on_off;
11147 };
11148
11149 /* Common CLI fields for vf vlan anti spoof enable disable */
11150 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11151         TOKEN_STRING_INITIALIZER
11152                 (struct cmd_vf_vlan_anti_spoof_result,
11153                  set, "set");
11154 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11155         TOKEN_STRING_INITIALIZER
11156                 (struct cmd_vf_vlan_anti_spoof_result,
11157                  vf, "vf");
11158 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11159         TOKEN_STRING_INITIALIZER
11160                 (struct cmd_vf_vlan_anti_spoof_result,
11161                  vlan, "vlan");
11162 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11163         TOKEN_STRING_INITIALIZER
11164                 (struct cmd_vf_vlan_anti_spoof_result,
11165                  antispoof, "antispoof");
11166 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11167         TOKEN_NUM_INITIALIZER
11168                 (struct cmd_vf_vlan_anti_spoof_result,
11169                  port_id, RTE_UINT16);
11170 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11171         TOKEN_NUM_INITIALIZER
11172                 (struct cmd_vf_vlan_anti_spoof_result,
11173                  vf_id, RTE_UINT32);
11174 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11175         TOKEN_STRING_INITIALIZER
11176                 (struct cmd_vf_vlan_anti_spoof_result,
11177                  on_off, "on#off");
11178
11179 static void
11180 cmd_set_vf_vlan_anti_spoof_parsed(
11181         void *parsed_result,
11182         __rte_unused struct cmdline *cl,
11183         __rte_unused void *data)
11184 {
11185         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11186         int ret = -ENOTSUP;
11187
11188         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11189
11190         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11191                 return;
11192
11193 #ifdef RTE_NET_IXGBE
11194         if (ret == -ENOTSUP)
11195                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11196                                 res->vf_id, is_on);
11197 #endif
11198 #ifdef RTE_NET_I40E
11199         if (ret == -ENOTSUP)
11200                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11201                                 res->vf_id, is_on);
11202 #endif
11203 #ifdef RTE_NET_BNXT
11204         if (ret == -ENOTSUP)
11205                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11206                                 res->vf_id, is_on);
11207 #endif
11208
11209         switch (ret) {
11210         case 0:
11211                 break;
11212         case -EINVAL:
11213                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11214                 break;
11215         case -ENODEV:
11216                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11217                 break;
11218         case -ENOTSUP:
11219                 fprintf(stderr, "function not implemented\n");
11220                 break;
11221         default:
11222                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11223         }
11224 }
11225
11226 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11227         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11228         .data = NULL,
11229         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11230         .tokens = {
11231                 (void *)&cmd_vf_vlan_anti_spoof_set,
11232                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11233                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11234                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11235                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11236                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11237                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11238                 NULL,
11239         },
11240 };
11241
11242 /* vf mac anti spoof configuration */
11243
11244 /* Common result structure for vf mac anti spoof */
11245 struct cmd_vf_mac_anti_spoof_result {
11246         cmdline_fixed_string_t set;
11247         cmdline_fixed_string_t vf;
11248         cmdline_fixed_string_t mac;
11249         cmdline_fixed_string_t antispoof;
11250         portid_t port_id;
11251         uint32_t vf_id;
11252         cmdline_fixed_string_t on_off;
11253 };
11254
11255 /* Common CLI fields for vf mac anti spoof enable disable */
11256 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11257         TOKEN_STRING_INITIALIZER
11258                 (struct cmd_vf_mac_anti_spoof_result,
11259                  set, "set");
11260 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11261         TOKEN_STRING_INITIALIZER
11262                 (struct cmd_vf_mac_anti_spoof_result,
11263                  vf, "vf");
11264 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11265         TOKEN_STRING_INITIALIZER
11266                 (struct cmd_vf_mac_anti_spoof_result,
11267                  mac, "mac");
11268 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11269         TOKEN_STRING_INITIALIZER
11270                 (struct cmd_vf_mac_anti_spoof_result,
11271                  antispoof, "antispoof");
11272 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11273         TOKEN_NUM_INITIALIZER
11274                 (struct cmd_vf_mac_anti_spoof_result,
11275                  port_id, RTE_UINT16);
11276 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11277         TOKEN_NUM_INITIALIZER
11278                 (struct cmd_vf_mac_anti_spoof_result,
11279                  vf_id, RTE_UINT32);
11280 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11281         TOKEN_STRING_INITIALIZER
11282                 (struct cmd_vf_mac_anti_spoof_result,
11283                  on_off, "on#off");
11284
11285 static void
11286 cmd_set_vf_mac_anti_spoof_parsed(
11287         void *parsed_result,
11288         __rte_unused struct cmdline *cl,
11289         __rte_unused void *data)
11290 {
11291         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11292         int ret = -ENOTSUP;
11293
11294         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11295
11296         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11297                 return;
11298
11299 #ifdef RTE_NET_IXGBE
11300         if (ret == -ENOTSUP)
11301                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11302                         res->vf_id, is_on);
11303 #endif
11304 #ifdef RTE_NET_I40E
11305         if (ret == -ENOTSUP)
11306                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11307                         res->vf_id, is_on);
11308 #endif
11309 #ifdef RTE_NET_BNXT
11310         if (ret == -ENOTSUP)
11311                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11312                         res->vf_id, is_on);
11313 #endif
11314
11315         switch (ret) {
11316         case 0:
11317                 break;
11318         case -EINVAL:
11319                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11320                         res->vf_id, is_on);
11321                 break;
11322         case -ENODEV:
11323                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11324                 break;
11325         case -ENOTSUP:
11326                 fprintf(stderr, "function not implemented\n");
11327                 break;
11328         default:
11329                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11330         }
11331 }
11332
11333 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11334         .f = cmd_set_vf_mac_anti_spoof_parsed,
11335         .data = NULL,
11336         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11337         .tokens = {
11338                 (void *)&cmd_vf_mac_anti_spoof_set,
11339                 (void *)&cmd_vf_mac_anti_spoof_vf,
11340                 (void *)&cmd_vf_mac_anti_spoof_mac,
11341                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11342                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11343                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11344                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11345                 NULL,
11346         },
11347 };
11348
11349 /* vf vlan strip queue configuration */
11350
11351 /* Common result structure for vf mac anti spoof */
11352 struct cmd_vf_vlan_stripq_result {
11353         cmdline_fixed_string_t set;
11354         cmdline_fixed_string_t vf;
11355         cmdline_fixed_string_t vlan;
11356         cmdline_fixed_string_t stripq;
11357         portid_t port_id;
11358         uint16_t vf_id;
11359         cmdline_fixed_string_t on_off;
11360 };
11361
11362 /* Common CLI fields for vf vlan strip enable disable */
11363 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11364         TOKEN_STRING_INITIALIZER
11365                 (struct cmd_vf_vlan_stripq_result,
11366                  set, "set");
11367 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11368         TOKEN_STRING_INITIALIZER
11369                 (struct cmd_vf_vlan_stripq_result,
11370                  vf, "vf");
11371 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11372         TOKEN_STRING_INITIALIZER
11373                 (struct cmd_vf_vlan_stripq_result,
11374                  vlan, "vlan");
11375 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11376         TOKEN_STRING_INITIALIZER
11377                 (struct cmd_vf_vlan_stripq_result,
11378                  stripq, "stripq");
11379 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11380         TOKEN_NUM_INITIALIZER
11381                 (struct cmd_vf_vlan_stripq_result,
11382                  port_id, RTE_UINT16);
11383 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11384         TOKEN_NUM_INITIALIZER
11385                 (struct cmd_vf_vlan_stripq_result,
11386                  vf_id, RTE_UINT16);
11387 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11388         TOKEN_STRING_INITIALIZER
11389                 (struct cmd_vf_vlan_stripq_result,
11390                  on_off, "on#off");
11391
11392 static void
11393 cmd_set_vf_vlan_stripq_parsed(
11394         void *parsed_result,
11395         __rte_unused struct cmdline *cl,
11396         __rte_unused void *data)
11397 {
11398         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11399         int ret = -ENOTSUP;
11400
11401         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11402
11403         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11404                 return;
11405
11406 #ifdef RTE_NET_IXGBE
11407         if (ret == -ENOTSUP)
11408                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11409                         res->vf_id, is_on);
11410 #endif
11411 #ifdef RTE_NET_I40E
11412         if (ret == -ENOTSUP)
11413                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11414                         res->vf_id, is_on);
11415 #endif
11416 #ifdef RTE_NET_BNXT
11417         if (ret == -ENOTSUP)
11418                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11419                         res->vf_id, is_on);
11420 #endif
11421
11422         switch (ret) {
11423         case 0:
11424                 break;
11425         case -EINVAL:
11426                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11427                         res->vf_id, is_on);
11428                 break;
11429         case -ENODEV:
11430                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11431                 break;
11432         case -ENOTSUP:
11433                 fprintf(stderr, "function not implemented\n");
11434                 break;
11435         default:
11436                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11437         }
11438 }
11439
11440 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11441         .f = cmd_set_vf_vlan_stripq_parsed,
11442         .data = NULL,
11443         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11444         .tokens = {
11445                 (void *)&cmd_vf_vlan_stripq_set,
11446                 (void *)&cmd_vf_vlan_stripq_vf,
11447                 (void *)&cmd_vf_vlan_stripq_vlan,
11448                 (void *)&cmd_vf_vlan_stripq_stripq,
11449                 (void *)&cmd_vf_vlan_stripq_port_id,
11450                 (void *)&cmd_vf_vlan_stripq_vf_id,
11451                 (void *)&cmd_vf_vlan_stripq_on_off,
11452                 NULL,
11453         },
11454 };
11455
11456 /* vf vlan insert configuration */
11457
11458 /* Common result structure for vf vlan insert */
11459 struct cmd_vf_vlan_insert_result {
11460         cmdline_fixed_string_t set;
11461         cmdline_fixed_string_t vf;
11462         cmdline_fixed_string_t vlan;
11463         cmdline_fixed_string_t insert;
11464         portid_t port_id;
11465         uint16_t vf_id;
11466         uint16_t vlan_id;
11467 };
11468
11469 /* Common CLI fields for vf vlan insert enable disable */
11470 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11471         TOKEN_STRING_INITIALIZER
11472                 (struct cmd_vf_vlan_insert_result,
11473                  set, "set");
11474 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11475         TOKEN_STRING_INITIALIZER
11476                 (struct cmd_vf_vlan_insert_result,
11477                  vf, "vf");
11478 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11479         TOKEN_STRING_INITIALIZER
11480                 (struct cmd_vf_vlan_insert_result,
11481                  vlan, "vlan");
11482 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11483         TOKEN_STRING_INITIALIZER
11484                 (struct cmd_vf_vlan_insert_result,
11485                  insert, "insert");
11486 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11487         TOKEN_NUM_INITIALIZER
11488                 (struct cmd_vf_vlan_insert_result,
11489                  port_id, RTE_UINT16);
11490 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11491         TOKEN_NUM_INITIALIZER
11492                 (struct cmd_vf_vlan_insert_result,
11493                  vf_id, RTE_UINT16);
11494 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11495         TOKEN_NUM_INITIALIZER
11496                 (struct cmd_vf_vlan_insert_result,
11497                  vlan_id, RTE_UINT16);
11498
11499 static void
11500 cmd_set_vf_vlan_insert_parsed(
11501         void *parsed_result,
11502         __rte_unused struct cmdline *cl,
11503         __rte_unused void *data)
11504 {
11505         struct cmd_vf_vlan_insert_result *res = parsed_result;
11506         int ret = -ENOTSUP;
11507
11508         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11509                 return;
11510
11511 #ifdef RTE_NET_IXGBE
11512         if (ret == -ENOTSUP)
11513                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11514                         res->vlan_id);
11515 #endif
11516 #ifdef RTE_NET_I40E
11517         if (ret == -ENOTSUP)
11518                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11519                         res->vlan_id);
11520 #endif
11521 #ifdef RTE_NET_BNXT
11522         if (ret == -ENOTSUP)
11523                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11524                         res->vlan_id);
11525 #endif
11526
11527         switch (ret) {
11528         case 0:
11529                 break;
11530         case -EINVAL:
11531                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11532                         res->vf_id, res->vlan_id);
11533                 break;
11534         case -ENODEV:
11535                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11536                 break;
11537         case -ENOTSUP:
11538                 fprintf(stderr, "function not implemented\n");
11539                 break;
11540         default:
11541                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11542         }
11543 }
11544
11545 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11546         .f = cmd_set_vf_vlan_insert_parsed,
11547         .data = NULL,
11548         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11549         .tokens = {
11550                 (void *)&cmd_vf_vlan_insert_set,
11551                 (void *)&cmd_vf_vlan_insert_vf,
11552                 (void *)&cmd_vf_vlan_insert_vlan,
11553                 (void *)&cmd_vf_vlan_insert_insert,
11554                 (void *)&cmd_vf_vlan_insert_port_id,
11555                 (void *)&cmd_vf_vlan_insert_vf_id,
11556                 (void *)&cmd_vf_vlan_insert_vlan_id,
11557                 NULL,
11558         },
11559 };
11560
11561 /* tx loopback configuration */
11562
11563 /* Common result structure for tx loopback */
11564 struct cmd_tx_loopback_result {
11565         cmdline_fixed_string_t set;
11566         cmdline_fixed_string_t tx;
11567         cmdline_fixed_string_t loopback;
11568         portid_t port_id;
11569         cmdline_fixed_string_t on_off;
11570 };
11571
11572 /* Common CLI fields for tx loopback enable disable */
11573 cmdline_parse_token_string_t cmd_tx_loopback_set =
11574         TOKEN_STRING_INITIALIZER
11575                 (struct cmd_tx_loopback_result,
11576                  set, "set");
11577 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11578         TOKEN_STRING_INITIALIZER
11579                 (struct cmd_tx_loopback_result,
11580                  tx, "tx");
11581 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11582         TOKEN_STRING_INITIALIZER
11583                 (struct cmd_tx_loopback_result,
11584                  loopback, "loopback");
11585 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11586         TOKEN_NUM_INITIALIZER
11587                 (struct cmd_tx_loopback_result,
11588                  port_id, RTE_UINT16);
11589 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11590         TOKEN_STRING_INITIALIZER
11591                 (struct cmd_tx_loopback_result,
11592                  on_off, "on#off");
11593
11594 static void
11595 cmd_set_tx_loopback_parsed(
11596         void *parsed_result,
11597         __rte_unused struct cmdline *cl,
11598         __rte_unused void *data)
11599 {
11600         struct cmd_tx_loopback_result *res = parsed_result;
11601         int ret = -ENOTSUP;
11602
11603         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11604
11605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11606                 return;
11607
11608 #ifdef RTE_NET_IXGBE
11609         if (ret == -ENOTSUP)
11610                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11611 #endif
11612 #ifdef RTE_NET_I40E
11613         if (ret == -ENOTSUP)
11614                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11615 #endif
11616 #ifdef RTE_NET_BNXT
11617         if (ret == -ENOTSUP)
11618                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11619 #endif
11620 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11621         if (ret == -ENOTSUP)
11622                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11623 #endif
11624
11625         switch (ret) {
11626         case 0:
11627                 break;
11628         case -EINVAL:
11629                 fprintf(stderr, "invalid is_on %d\n", is_on);
11630                 break;
11631         case -ENODEV:
11632                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11633                 break;
11634         case -ENOTSUP:
11635                 fprintf(stderr, "function not implemented\n");
11636                 break;
11637         default:
11638                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11639         }
11640 }
11641
11642 cmdline_parse_inst_t cmd_set_tx_loopback = {
11643         .f = cmd_set_tx_loopback_parsed,
11644         .data = NULL,
11645         .help_str = "set tx loopback <port_id> on|off",
11646         .tokens = {
11647                 (void *)&cmd_tx_loopback_set,
11648                 (void *)&cmd_tx_loopback_tx,
11649                 (void *)&cmd_tx_loopback_loopback,
11650                 (void *)&cmd_tx_loopback_port_id,
11651                 (void *)&cmd_tx_loopback_on_off,
11652                 NULL,
11653         },
11654 };
11655
11656 /* all queues drop enable configuration */
11657
11658 /* Common result structure for all queues drop enable */
11659 struct cmd_all_queues_drop_en_result {
11660         cmdline_fixed_string_t set;
11661         cmdline_fixed_string_t all;
11662         cmdline_fixed_string_t queues;
11663         cmdline_fixed_string_t drop;
11664         portid_t port_id;
11665         cmdline_fixed_string_t on_off;
11666 };
11667
11668 /* Common CLI fields for tx loopback enable disable */
11669 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11670         TOKEN_STRING_INITIALIZER
11671                 (struct cmd_all_queues_drop_en_result,
11672                  set, "set");
11673 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11674         TOKEN_STRING_INITIALIZER
11675                 (struct cmd_all_queues_drop_en_result,
11676                  all, "all");
11677 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11678         TOKEN_STRING_INITIALIZER
11679                 (struct cmd_all_queues_drop_en_result,
11680                  queues, "queues");
11681 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11682         TOKEN_STRING_INITIALIZER
11683                 (struct cmd_all_queues_drop_en_result,
11684                  drop, "drop");
11685 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11686         TOKEN_NUM_INITIALIZER
11687                 (struct cmd_all_queues_drop_en_result,
11688                  port_id, RTE_UINT16);
11689 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11690         TOKEN_STRING_INITIALIZER
11691                 (struct cmd_all_queues_drop_en_result,
11692                  on_off, "on#off");
11693
11694 static void
11695 cmd_set_all_queues_drop_en_parsed(
11696         void *parsed_result,
11697         __rte_unused struct cmdline *cl,
11698         __rte_unused void *data)
11699 {
11700         struct cmd_all_queues_drop_en_result *res = parsed_result;
11701         int ret = -ENOTSUP;
11702         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11703
11704         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11705                 return;
11706
11707 #ifdef RTE_NET_IXGBE
11708         if (ret == -ENOTSUP)
11709                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11710 #endif
11711 #ifdef RTE_NET_BNXT
11712         if (ret == -ENOTSUP)
11713                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11714 #endif
11715         switch (ret) {
11716         case 0:
11717                 break;
11718         case -EINVAL:
11719                 fprintf(stderr, "invalid is_on %d\n", is_on);
11720                 break;
11721         case -ENODEV:
11722                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11723                 break;
11724         case -ENOTSUP:
11725                 fprintf(stderr, "function not implemented\n");
11726                 break;
11727         default:
11728                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11729         }
11730 }
11731
11732 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11733         .f = cmd_set_all_queues_drop_en_parsed,
11734         .data = NULL,
11735         .help_str = "set all queues drop <port_id> on|off",
11736         .tokens = {
11737                 (void *)&cmd_all_queues_drop_en_set,
11738                 (void *)&cmd_all_queues_drop_en_all,
11739                 (void *)&cmd_all_queues_drop_en_queues,
11740                 (void *)&cmd_all_queues_drop_en_drop,
11741                 (void *)&cmd_all_queues_drop_en_port_id,
11742                 (void *)&cmd_all_queues_drop_en_on_off,
11743                 NULL,
11744         },
11745 };
11746
11747 /* vf split drop enable configuration */
11748
11749 /* Common result structure for vf split drop enable */
11750 struct cmd_vf_split_drop_en_result {
11751         cmdline_fixed_string_t set;
11752         cmdline_fixed_string_t vf;
11753         cmdline_fixed_string_t split;
11754         cmdline_fixed_string_t drop;
11755         portid_t port_id;
11756         uint16_t vf_id;
11757         cmdline_fixed_string_t on_off;
11758 };
11759
11760 /* Common CLI fields for vf split drop enable disable */
11761 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11762         TOKEN_STRING_INITIALIZER
11763                 (struct cmd_vf_split_drop_en_result,
11764                  set, "set");
11765 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11766         TOKEN_STRING_INITIALIZER
11767                 (struct cmd_vf_split_drop_en_result,
11768                  vf, "vf");
11769 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11770         TOKEN_STRING_INITIALIZER
11771                 (struct cmd_vf_split_drop_en_result,
11772                  split, "split");
11773 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11774         TOKEN_STRING_INITIALIZER
11775                 (struct cmd_vf_split_drop_en_result,
11776                  drop, "drop");
11777 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11778         TOKEN_NUM_INITIALIZER
11779                 (struct cmd_vf_split_drop_en_result,
11780                  port_id, RTE_UINT16);
11781 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11782         TOKEN_NUM_INITIALIZER
11783                 (struct cmd_vf_split_drop_en_result,
11784                  vf_id, RTE_UINT16);
11785 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11786         TOKEN_STRING_INITIALIZER
11787                 (struct cmd_vf_split_drop_en_result,
11788                  on_off, "on#off");
11789
11790 static void
11791 cmd_set_vf_split_drop_en_parsed(
11792         void *parsed_result,
11793         __rte_unused struct cmdline *cl,
11794         __rte_unused void *data)
11795 {
11796         struct cmd_vf_split_drop_en_result *res = parsed_result;
11797         int ret = -ENOTSUP;
11798         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11799
11800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11801                 return;
11802
11803 #ifdef RTE_NET_IXGBE
11804         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11805                         is_on);
11806 #endif
11807         switch (ret) {
11808         case 0:
11809                 break;
11810         case -EINVAL:
11811                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11812                         res->vf_id, is_on);
11813                 break;
11814         case -ENODEV:
11815                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11816                 break;
11817         case -ENOTSUP:
11818                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11819                 break;
11820         default:
11821                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11822         }
11823 }
11824
11825 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11826         .f = cmd_set_vf_split_drop_en_parsed,
11827         .data = NULL,
11828         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11829         .tokens = {
11830                 (void *)&cmd_vf_split_drop_en_set,
11831                 (void *)&cmd_vf_split_drop_en_vf,
11832                 (void *)&cmd_vf_split_drop_en_split,
11833                 (void *)&cmd_vf_split_drop_en_drop,
11834                 (void *)&cmd_vf_split_drop_en_port_id,
11835                 (void *)&cmd_vf_split_drop_en_vf_id,
11836                 (void *)&cmd_vf_split_drop_en_on_off,
11837                 NULL,
11838         },
11839 };
11840
11841 /* vf mac address configuration */
11842
11843 /* Common result structure for vf mac address */
11844 struct cmd_set_vf_mac_addr_result {
11845         cmdline_fixed_string_t set;
11846         cmdline_fixed_string_t vf;
11847         cmdline_fixed_string_t mac;
11848         cmdline_fixed_string_t addr;
11849         portid_t port_id;
11850         uint16_t vf_id;
11851         struct rte_ether_addr mac_addr;
11852
11853 };
11854
11855 /* Common CLI fields for vf split drop enable disable */
11856 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11857         TOKEN_STRING_INITIALIZER
11858                 (struct cmd_set_vf_mac_addr_result,
11859                  set, "set");
11860 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11861         TOKEN_STRING_INITIALIZER
11862                 (struct cmd_set_vf_mac_addr_result,
11863                  vf, "vf");
11864 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11865         TOKEN_STRING_INITIALIZER
11866                 (struct cmd_set_vf_mac_addr_result,
11867                  mac, "mac");
11868 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11869         TOKEN_STRING_INITIALIZER
11870                 (struct cmd_set_vf_mac_addr_result,
11871                  addr, "addr");
11872 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11873         TOKEN_NUM_INITIALIZER
11874                 (struct cmd_set_vf_mac_addr_result,
11875                  port_id, RTE_UINT16);
11876 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11877         TOKEN_NUM_INITIALIZER
11878                 (struct cmd_set_vf_mac_addr_result,
11879                  vf_id, RTE_UINT16);
11880 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11881         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11882                  mac_addr);
11883
11884 static void
11885 cmd_set_vf_mac_addr_parsed(
11886         void *parsed_result,
11887         __rte_unused struct cmdline *cl,
11888         __rte_unused void *data)
11889 {
11890         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11891         int ret = -ENOTSUP;
11892
11893         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11894                 return;
11895
11896 #ifdef RTE_NET_IXGBE
11897         if (ret == -ENOTSUP)
11898                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11899                                 &res->mac_addr);
11900 #endif
11901 #ifdef RTE_NET_I40E
11902         if (ret == -ENOTSUP)
11903                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11904                                 &res->mac_addr);
11905 #endif
11906 #ifdef RTE_NET_BNXT
11907         if (ret == -ENOTSUP)
11908                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11909                                 &res->mac_addr);
11910 #endif
11911
11912         switch (ret) {
11913         case 0:
11914                 break;
11915         case -EINVAL:
11916                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11917                 break;
11918         case -ENODEV:
11919                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11920                 break;
11921         case -ENOTSUP:
11922                 fprintf(stderr, "function not implemented\n");
11923                 break;
11924         default:
11925                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11926         }
11927 }
11928
11929 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11930         .f = cmd_set_vf_mac_addr_parsed,
11931         .data = NULL,
11932         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11933         .tokens = {
11934                 (void *)&cmd_set_vf_mac_addr_set,
11935                 (void *)&cmd_set_vf_mac_addr_vf,
11936                 (void *)&cmd_set_vf_mac_addr_mac,
11937                 (void *)&cmd_set_vf_mac_addr_addr,
11938                 (void *)&cmd_set_vf_mac_addr_port_id,
11939                 (void *)&cmd_set_vf_mac_addr_vf_id,
11940                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11941                 NULL,
11942         },
11943 };
11944
11945 /* MACsec configuration */
11946
11947 /* Common result structure for MACsec offload enable */
11948 struct cmd_macsec_offload_on_result {
11949         cmdline_fixed_string_t set;
11950         cmdline_fixed_string_t macsec;
11951         cmdline_fixed_string_t offload;
11952         portid_t port_id;
11953         cmdline_fixed_string_t on;
11954         cmdline_fixed_string_t encrypt;
11955         cmdline_fixed_string_t en_on_off;
11956         cmdline_fixed_string_t replay_protect;
11957         cmdline_fixed_string_t rp_on_off;
11958 };
11959
11960 /* Common CLI fields for MACsec offload disable */
11961 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11962         TOKEN_STRING_INITIALIZER
11963                 (struct cmd_macsec_offload_on_result,
11964                  set, "set");
11965 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11966         TOKEN_STRING_INITIALIZER
11967                 (struct cmd_macsec_offload_on_result,
11968                  macsec, "macsec");
11969 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11970         TOKEN_STRING_INITIALIZER
11971                 (struct cmd_macsec_offload_on_result,
11972                  offload, "offload");
11973 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11974         TOKEN_NUM_INITIALIZER
11975                 (struct cmd_macsec_offload_on_result,
11976                  port_id, RTE_UINT16);
11977 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11978         TOKEN_STRING_INITIALIZER
11979                 (struct cmd_macsec_offload_on_result,
11980                  on, "on");
11981 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11982         TOKEN_STRING_INITIALIZER
11983                 (struct cmd_macsec_offload_on_result,
11984                  encrypt, "encrypt");
11985 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11986         TOKEN_STRING_INITIALIZER
11987                 (struct cmd_macsec_offload_on_result,
11988                  en_on_off, "on#off");
11989 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11990         TOKEN_STRING_INITIALIZER
11991                 (struct cmd_macsec_offload_on_result,
11992                  replay_protect, "replay-protect");
11993 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11994         TOKEN_STRING_INITIALIZER
11995                 (struct cmd_macsec_offload_on_result,
11996                  rp_on_off, "on#off");
11997
11998 static void
11999 cmd_set_macsec_offload_on_parsed(
12000         void *parsed_result,
12001         __rte_unused struct cmdline *cl,
12002         __rte_unused void *data)
12003 {
12004         struct cmd_macsec_offload_on_result *res = parsed_result;
12005         int ret = -ENOTSUP;
12006         portid_t port_id = res->port_id;
12007         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
12008         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12009         struct rte_eth_dev_info dev_info;
12010
12011         if (port_id_is_invalid(port_id, ENABLED_WARN))
12012                 return;
12013         if (!port_is_stopped(port_id)) {
12014                 fprintf(stderr, "Please stop port %d first\n", port_id);
12015                 return;
12016         }
12017
12018         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12019         if (ret != 0)
12020                 return;
12021
12022         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12023 #ifdef RTE_NET_IXGBE
12024                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12025 #endif
12026         }
12027         RTE_SET_USED(en);
12028         RTE_SET_USED(rp);
12029
12030         switch (ret) {
12031         case 0:
12032                 ports[port_id].dev_conf.txmode.offloads |=
12033                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12034                 cmd_reconfig_device_queue(port_id, 1, 1);
12035                 break;
12036         case -ENODEV:
12037                 fprintf(stderr, "invalid port_id %d\n", port_id);
12038                 break;
12039         case -ENOTSUP:
12040                 fprintf(stderr, "not supported on port %d\n", port_id);
12041                 break;
12042         default:
12043                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12044         }
12045 }
12046
12047 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12048         .f = cmd_set_macsec_offload_on_parsed,
12049         .data = NULL,
12050         .help_str = "set macsec offload <port_id> on "
12051                 "encrypt on|off replay-protect on|off",
12052         .tokens = {
12053                 (void *)&cmd_macsec_offload_on_set,
12054                 (void *)&cmd_macsec_offload_on_macsec,
12055                 (void *)&cmd_macsec_offload_on_offload,
12056                 (void *)&cmd_macsec_offload_on_port_id,
12057                 (void *)&cmd_macsec_offload_on_on,
12058                 (void *)&cmd_macsec_offload_on_encrypt,
12059                 (void *)&cmd_macsec_offload_on_en_on_off,
12060                 (void *)&cmd_macsec_offload_on_replay_protect,
12061                 (void *)&cmd_macsec_offload_on_rp_on_off,
12062                 NULL,
12063         },
12064 };
12065
12066 /* Common result structure for MACsec offload disable */
12067 struct cmd_macsec_offload_off_result {
12068         cmdline_fixed_string_t set;
12069         cmdline_fixed_string_t macsec;
12070         cmdline_fixed_string_t offload;
12071         portid_t port_id;
12072         cmdline_fixed_string_t off;
12073 };
12074
12075 /* Common CLI fields for MACsec offload disable */
12076 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12077         TOKEN_STRING_INITIALIZER
12078                 (struct cmd_macsec_offload_off_result,
12079                  set, "set");
12080 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12081         TOKEN_STRING_INITIALIZER
12082                 (struct cmd_macsec_offload_off_result,
12083                  macsec, "macsec");
12084 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12085         TOKEN_STRING_INITIALIZER
12086                 (struct cmd_macsec_offload_off_result,
12087                  offload, "offload");
12088 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12089         TOKEN_NUM_INITIALIZER
12090                 (struct cmd_macsec_offload_off_result,
12091                  port_id, RTE_UINT16);
12092 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12093         TOKEN_STRING_INITIALIZER
12094                 (struct cmd_macsec_offload_off_result,
12095                  off, "off");
12096
12097 static void
12098 cmd_set_macsec_offload_off_parsed(
12099         void *parsed_result,
12100         __rte_unused struct cmdline *cl,
12101         __rte_unused void *data)
12102 {
12103         struct cmd_macsec_offload_off_result *res = parsed_result;
12104         int ret = -ENOTSUP;
12105         struct rte_eth_dev_info dev_info;
12106         portid_t port_id = res->port_id;
12107
12108         if (port_id_is_invalid(port_id, ENABLED_WARN))
12109                 return;
12110         if (!port_is_stopped(port_id)) {
12111                 fprintf(stderr, "Please stop port %d first\n", port_id);
12112                 return;
12113         }
12114
12115         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12116         if (ret != 0)
12117                 return;
12118
12119         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12120 #ifdef RTE_NET_IXGBE
12121                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12122 #endif
12123         }
12124         switch (ret) {
12125         case 0:
12126                 ports[port_id].dev_conf.txmode.offloads &=
12127                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12128                 cmd_reconfig_device_queue(port_id, 1, 1);
12129                 break;
12130         case -ENODEV:
12131                 fprintf(stderr, "invalid port_id %d\n", port_id);
12132                 break;
12133         case -ENOTSUP:
12134                 fprintf(stderr, "not supported on port %d\n", port_id);
12135                 break;
12136         default:
12137                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12138         }
12139 }
12140
12141 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12142         .f = cmd_set_macsec_offload_off_parsed,
12143         .data = NULL,
12144         .help_str = "set macsec offload <port_id> off",
12145         .tokens = {
12146                 (void *)&cmd_macsec_offload_off_set,
12147                 (void *)&cmd_macsec_offload_off_macsec,
12148                 (void *)&cmd_macsec_offload_off_offload,
12149                 (void *)&cmd_macsec_offload_off_port_id,
12150                 (void *)&cmd_macsec_offload_off_off,
12151                 NULL,
12152         },
12153 };
12154
12155 /* Common result structure for MACsec secure connection configure */
12156 struct cmd_macsec_sc_result {
12157         cmdline_fixed_string_t set;
12158         cmdline_fixed_string_t macsec;
12159         cmdline_fixed_string_t sc;
12160         cmdline_fixed_string_t tx_rx;
12161         portid_t port_id;
12162         struct rte_ether_addr mac;
12163         uint16_t pi;
12164 };
12165
12166 /* Common CLI fields for MACsec secure connection configure */
12167 cmdline_parse_token_string_t cmd_macsec_sc_set =
12168         TOKEN_STRING_INITIALIZER
12169                 (struct cmd_macsec_sc_result,
12170                  set, "set");
12171 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12172         TOKEN_STRING_INITIALIZER
12173                 (struct cmd_macsec_sc_result,
12174                  macsec, "macsec");
12175 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12176         TOKEN_STRING_INITIALIZER
12177                 (struct cmd_macsec_sc_result,
12178                  sc, "sc");
12179 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12180         TOKEN_STRING_INITIALIZER
12181                 (struct cmd_macsec_sc_result,
12182                  tx_rx, "tx#rx");
12183 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12184         TOKEN_NUM_INITIALIZER
12185                 (struct cmd_macsec_sc_result,
12186                  port_id, RTE_UINT16);
12187 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12188         TOKEN_ETHERADDR_INITIALIZER
12189                 (struct cmd_macsec_sc_result,
12190                  mac);
12191 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12192         TOKEN_NUM_INITIALIZER
12193                 (struct cmd_macsec_sc_result,
12194                  pi, RTE_UINT16);
12195
12196 static void
12197 cmd_set_macsec_sc_parsed(
12198         void *parsed_result,
12199         __rte_unused struct cmdline *cl,
12200         __rte_unused void *data)
12201 {
12202         struct cmd_macsec_sc_result *res = parsed_result;
12203         int ret = -ENOTSUP;
12204         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12205
12206 #ifdef RTE_NET_IXGBE
12207         ret = is_tx ?
12208                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12209                                 res->mac.addr_bytes) :
12210                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12211                                 res->mac.addr_bytes, res->pi);
12212 #endif
12213         RTE_SET_USED(is_tx);
12214
12215         switch (ret) {
12216         case 0:
12217                 break;
12218         case -ENODEV:
12219                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12220                 break;
12221         case -ENOTSUP:
12222                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12223                 break;
12224         default:
12225                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12226         }
12227 }
12228
12229 cmdline_parse_inst_t cmd_set_macsec_sc = {
12230         .f = cmd_set_macsec_sc_parsed,
12231         .data = NULL,
12232         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12233         .tokens = {
12234                 (void *)&cmd_macsec_sc_set,
12235                 (void *)&cmd_macsec_sc_macsec,
12236                 (void *)&cmd_macsec_sc_sc,
12237                 (void *)&cmd_macsec_sc_tx_rx,
12238                 (void *)&cmd_macsec_sc_port_id,
12239                 (void *)&cmd_macsec_sc_mac,
12240                 (void *)&cmd_macsec_sc_pi,
12241                 NULL,
12242         },
12243 };
12244
12245 /* Common result structure for MACsec secure connection configure */
12246 struct cmd_macsec_sa_result {
12247         cmdline_fixed_string_t set;
12248         cmdline_fixed_string_t macsec;
12249         cmdline_fixed_string_t sa;
12250         cmdline_fixed_string_t tx_rx;
12251         portid_t port_id;
12252         uint8_t idx;
12253         uint8_t an;
12254         uint32_t pn;
12255         cmdline_fixed_string_t key;
12256 };
12257
12258 /* Common CLI fields for MACsec secure connection configure */
12259 cmdline_parse_token_string_t cmd_macsec_sa_set =
12260         TOKEN_STRING_INITIALIZER
12261                 (struct cmd_macsec_sa_result,
12262                  set, "set");
12263 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12264         TOKEN_STRING_INITIALIZER
12265                 (struct cmd_macsec_sa_result,
12266                  macsec, "macsec");
12267 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12268         TOKEN_STRING_INITIALIZER
12269                 (struct cmd_macsec_sa_result,
12270                  sa, "sa");
12271 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12272         TOKEN_STRING_INITIALIZER
12273                 (struct cmd_macsec_sa_result,
12274                  tx_rx, "tx#rx");
12275 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12276         TOKEN_NUM_INITIALIZER
12277                 (struct cmd_macsec_sa_result,
12278                  port_id, RTE_UINT16);
12279 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12280         TOKEN_NUM_INITIALIZER
12281                 (struct cmd_macsec_sa_result,
12282                  idx, RTE_UINT8);
12283 cmdline_parse_token_num_t cmd_macsec_sa_an =
12284         TOKEN_NUM_INITIALIZER
12285                 (struct cmd_macsec_sa_result,
12286                  an, RTE_UINT8);
12287 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12288         TOKEN_NUM_INITIALIZER
12289                 (struct cmd_macsec_sa_result,
12290                  pn, RTE_UINT32);
12291 cmdline_parse_token_string_t cmd_macsec_sa_key =
12292         TOKEN_STRING_INITIALIZER
12293                 (struct cmd_macsec_sa_result,
12294                  key, NULL);
12295
12296 static void
12297 cmd_set_macsec_sa_parsed(
12298         void *parsed_result,
12299         __rte_unused struct cmdline *cl,
12300         __rte_unused void *data)
12301 {
12302         struct cmd_macsec_sa_result *res = parsed_result;
12303         int ret = -ENOTSUP;
12304         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12305         uint8_t key[16] = { 0 };
12306         uint8_t xdgt0;
12307         uint8_t xdgt1;
12308         int key_len;
12309         int i;
12310
12311         key_len = strlen(res->key) / 2;
12312         if (key_len > 16)
12313                 key_len = 16;
12314
12315         for (i = 0; i < key_len; i++) {
12316                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12317                 if (xdgt0 == 0xFF)
12318                         return;
12319                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12320                 if (xdgt1 == 0xFF)
12321                         return;
12322                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12323         }
12324
12325 #ifdef RTE_NET_IXGBE
12326         ret = is_tx ?
12327                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12328                         res->idx, res->an, res->pn, key) :
12329                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12330                         res->idx, res->an, res->pn, key);
12331 #endif
12332         RTE_SET_USED(is_tx);
12333         RTE_SET_USED(key);
12334
12335         switch (ret) {
12336         case 0:
12337                 break;
12338         case -EINVAL:
12339                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12340                 break;
12341         case -ENODEV:
12342                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12343                 break;
12344         case -ENOTSUP:
12345                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12346                 break;
12347         default:
12348                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12349         }
12350 }
12351
12352 cmdline_parse_inst_t cmd_set_macsec_sa = {
12353         .f = cmd_set_macsec_sa_parsed,
12354         .data = NULL,
12355         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12356         .tokens = {
12357                 (void *)&cmd_macsec_sa_set,
12358                 (void *)&cmd_macsec_sa_macsec,
12359                 (void *)&cmd_macsec_sa_sa,
12360                 (void *)&cmd_macsec_sa_tx_rx,
12361                 (void *)&cmd_macsec_sa_port_id,
12362                 (void *)&cmd_macsec_sa_idx,
12363                 (void *)&cmd_macsec_sa_an,
12364                 (void *)&cmd_macsec_sa_pn,
12365                 (void *)&cmd_macsec_sa_key,
12366                 NULL,
12367         },
12368 };
12369
12370 /* VF unicast promiscuous mode configuration */
12371
12372 /* Common result structure for VF unicast promiscuous mode */
12373 struct cmd_vf_promisc_result {
12374         cmdline_fixed_string_t set;
12375         cmdline_fixed_string_t vf;
12376         cmdline_fixed_string_t promisc;
12377         portid_t port_id;
12378         uint32_t vf_id;
12379         cmdline_fixed_string_t on_off;
12380 };
12381
12382 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12383 cmdline_parse_token_string_t cmd_vf_promisc_set =
12384         TOKEN_STRING_INITIALIZER
12385                 (struct cmd_vf_promisc_result,
12386                  set, "set");
12387 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12388         TOKEN_STRING_INITIALIZER
12389                 (struct cmd_vf_promisc_result,
12390                  vf, "vf");
12391 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12392         TOKEN_STRING_INITIALIZER
12393                 (struct cmd_vf_promisc_result,
12394                  promisc, "promisc");
12395 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12396         TOKEN_NUM_INITIALIZER
12397                 (struct cmd_vf_promisc_result,
12398                  port_id, RTE_UINT16);
12399 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12400         TOKEN_NUM_INITIALIZER
12401                 (struct cmd_vf_promisc_result,
12402                  vf_id, RTE_UINT32);
12403 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12404         TOKEN_STRING_INITIALIZER
12405                 (struct cmd_vf_promisc_result,
12406                  on_off, "on#off");
12407
12408 static void
12409 cmd_set_vf_promisc_parsed(
12410         void *parsed_result,
12411         __rte_unused struct cmdline *cl,
12412         __rte_unused void *data)
12413 {
12414         struct cmd_vf_promisc_result *res = parsed_result;
12415         int ret = -ENOTSUP;
12416
12417         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12418
12419         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12420                 return;
12421
12422 #ifdef RTE_NET_I40E
12423         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12424                                                   res->vf_id, is_on);
12425 #endif
12426
12427         switch (ret) {
12428         case 0:
12429                 break;
12430         case -EINVAL:
12431                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12432                 break;
12433         case -ENODEV:
12434                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12435                 break;
12436         case -ENOTSUP:
12437                 fprintf(stderr, "function not implemented\n");
12438                 break;
12439         default:
12440                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12441         }
12442 }
12443
12444 cmdline_parse_inst_t cmd_set_vf_promisc = {
12445         .f = cmd_set_vf_promisc_parsed,
12446         .data = NULL,
12447         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12448                 "Set unicast promiscuous mode for a VF from the PF",
12449         .tokens = {
12450                 (void *)&cmd_vf_promisc_set,
12451                 (void *)&cmd_vf_promisc_vf,
12452                 (void *)&cmd_vf_promisc_promisc,
12453                 (void *)&cmd_vf_promisc_port_id,
12454                 (void *)&cmd_vf_promisc_vf_id,
12455                 (void *)&cmd_vf_promisc_on_off,
12456                 NULL,
12457         },
12458 };
12459
12460 /* VF multicast promiscuous mode configuration */
12461
12462 /* Common result structure for VF multicast promiscuous mode */
12463 struct cmd_vf_allmulti_result {
12464         cmdline_fixed_string_t set;
12465         cmdline_fixed_string_t vf;
12466         cmdline_fixed_string_t allmulti;
12467         portid_t port_id;
12468         uint32_t vf_id;
12469         cmdline_fixed_string_t on_off;
12470 };
12471
12472 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12473 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12474         TOKEN_STRING_INITIALIZER
12475                 (struct cmd_vf_allmulti_result,
12476                  set, "set");
12477 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12478         TOKEN_STRING_INITIALIZER
12479                 (struct cmd_vf_allmulti_result,
12480                  vf, "vf");
12481 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12482         TOKEN_STRING_INITIALIZER
12483                 (struct cmd_vf_allmulti_result,
12484                  allmulti, "allmulti");
12485 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12486         TOKEN_NUM_INITIALIZER
12487                 (struct cmd_vf_allmulti_result,
12488                  port_id, RTE_UINT16);
12489 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12490         TOKEN_NUM_INITIALIZER
12491                 (struct cmd_vf_allmulti_result,
12492                  vf_id, RTE_UINT32);
12493 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12494         TOKEN_STRING_INITIALIZER
12495                 (struct cmd_vf_allmulti_result,
12496                  on_off, "on#off");
12497
12498 static void
12499 cmd_set_vf_allmulti_parsed(
12500         void *parsed_result,
12501         __rte_unused struct cmdline *cl,
12502         __rte_unused void *data)
12503 {
12504         struct cmd_vf_allmulti_result *res = parsed_result;
12505         int ret = -ENOTSUP;
12506
12507         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12508
12509         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12510                 return;
12511
12512 #ifdef RTE_NET_I40E
12513         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12514                                                     res->vf_id, is_on);
12515 #endif
12516
12517         switch (ret) {
12518         case 0:
12519                 break;
12520         case -EINVAL:
12521                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12522                 break;
12523         case -ENODEV:
12524                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12525                 break;
12526         case -ENOTSUP:
12527                 fprintf(stderr, "function not implemented\n");
12528                 break;
12529         default:
12530                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12531         }
12532 }
12533
12534 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12535         .f = cmd_set_vf_allmulti_parsed,
12536         .data = NULL,
12537         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12538                 "Set multicast promiscuous mode for a VF from the PF",
12539         .tokens = {
12540                 (void *)&cmd_vf_allmulti_set,
12541                 (void *)&cmd_vf_allmulti_vf,
12542                 (void *)&cmd_vf_allmulti_allmulti,
12543                 (void *)&cmd_vf_allmulti_port_id,
12544                 (void *)&cmd_vf_allmulti_vf_id,
12545                 (void *)&cmd_vf_allmulti_on_off,
12546                 NULL,
12547         },
12548 };
12549
12550 /* vf broadcast mode configuration */
12551
12552 /* Common result structure for vf broadcast */
12553 struct cmd_set_vf_broadcast_result {
12554         cmdline_fixed_string_t set;
12555         cmdline_fixed_string_t vf;
12556         cmdline_fixed_string_t broadcast;
12557         portid_t port_id;
12558         uint16_t vf_id;
12559         cmdline_fixed_string_t on_off;
12560 };
12561
12562 /* Common CLI fields for vf broadcast enable disable */
12563 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12564         TOKEN_STRING_INITIALIZER
12565                 (struct cmd_set_vf_broadcast_result,
12566                  set, "set");
12567 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12568         TOKEN_STRING_INITIALIZER
12569                 (struct cmd_set_vf_broadcast_result,
12570                  vf, "vf");
12571 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12572         TOKEN_STRING_INITIALIZER
12573                 (struct cmd_set_vf_broadcast_result,
12574                  broadcast, "broadcast");
12575 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12576         TOKEN_NUM_INITIALIZER
12577                 (struct cmd_set_vf_broadcast_result,
12578                  port_id, RTE_UINT16);
12579 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12580         TOKEN_NUM_INITIALIZER
12581                 (struct cmd_set_vf_broadcast_result,
12582                  vf_id, RTE_UINT16);
12583 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12584         TOKEN_STRING_INITIALIZER
12585                 (struct cmd_set_vf_broadcast_result,
12586                  on_off, "on#off");
12587
12588 static void
12589 cmd_set_vf_broadcast_parsed(
12590         void *parsed_result,
12591         __rte_unused struct cmdline *cl,
12592         __rte_unused void *data)
12593 {
12594         struct cmd_set_vf_broadcast_result *res = parsed_result;
12595         int ret = -ENOTSUP;
12596
12597         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12598
12599         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12600                 return;
12601
12602 #ifdef RTE_NET_I40E
12603         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12604                                             res->vf_id, is_on);
12605 #endif
12606
12607         switch (ret) {
12608         case 0:
12609                 break;
12610         case -EINVAL:
12611                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12612                         res->vf_id, is_on);
12613                 break;
12614         case -ENODEV:
12615                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12616                 break;
12617         case -ENOTSUP:
12618                 fprintf(stderr, "function not implemented\n");
12619                 break;
12620         default:
12621                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12622         }
12623 }
12624
12625 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12626         .f = cmd_set_vf_broadcast_parsed,
12627         .data = NULL,
12628         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12629         .tokens = {
12630                 (void *)&cmd_set_vf_broadcast_set,
12631                 (void *)&cmd_set_vf_broadcast_vf,
12632                 (void *)&cmd_set_vf_broadcast_broadcast,
12633                 (void *)&cmd_set_vf_broadcast_port_id,
12634                 (void *)&cmd_set_vf_broadcast_vf_id,
12635                 (void *)&cmd_set_vf_broadcast_on_off,
12636                 NULL,
12637         },
12638 };
12639
12640 /* vf vlan tag configuration */
12641
12642 /* Common result structure for vf vlan tag */
12643 struct cmd_set_vf_vlan_tag_result {
12644         cmdline_fixed_string_t set;
12645         cmdline_fixed_string_t vf;
12646         cmdline_fixed_string_t vlan;
12647         cmdline_fixed_string_t tag;
12648         portid_t port_id;
12649         uint16_t vf_id;
12650         cmdline_fixed_string_t on_off;
12651 };
12652
12653 /* Common CLI fields for vf vlan tag enable disable */
12654 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12655         TOKEN_STRING_INITIALIZER
12656                 (struct cmd_set_vf_vlan_tag_result,
12657                  set, "set");
12658 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12659         TOKEN_STRING_INITIALIZER
12660                 (struct cmd_set_vf_vlan_tag_result,
12661                  vf, "vf");
12662 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12663         TOKEN_STRING_INITIALIZER
12664                 (struct cmd_set_vf_vlan_tag_result,
12665                  vlan, "vlan");
12666 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12667         TOKEN_STRING_INITIALIZER
12668                 (struct cmd_set_vf_vlan_tag_result,
12669                  tag, "tag");
12670 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12671         TOKEN_NUM_INITIALIZER
12672                 (struct cmd_set_vf_vlan_tag_result,
12673                  port_id, RTE_UINT16);
12674 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12675         TOKEN_NUM_INITIALIZER
12676                 (struct cmd_set_vf_vlan_tag_result,
12677                  vf_id, RTE_UINT16);
12678 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12679         TOKEN_STRING_INITIALIZER
12680                 (struct cmd_set_vf_vlan_tag_result,
12681                  on_off, "on#off");
12682
12683 static void
12684 cmd_set_vf_vlan_tag_parsed(
12685         void *parsed_result,
12686         __rte_unused struct cmdline *cl,
12687         __rte_unused void *data)
12688 {
12689         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12690         int ret = -ENOTSUP;
12691
12692         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12693
12694         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12695                 return;
12696
12697 #ifdef RTE_NET_I40E
12698         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12699                                            res->vf_id, is_on);
12700 #endif
12701
12702         switch (ret) {
12703         case 0:
12704                 break;
12705         case -EINVAL:
12706                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12707                         res->vf_id, is_on);
12708                 break;
12709         case -ENODEV:
12710                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12711                 break;
12712         case -ENOTSUP:
12713                 fprintf(stderr, "function not implemented\n");
12714                 break;
12715         default:
12716                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12717         }
12718 }
12719
12720 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12721         .f = cmd_set_vf_vlan_tag_parsed,
12722         .data = NULL,
12723         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12724         .tokens = {
12725                 (void *)&cmd_set_vf_vlan_tag_set,
12726                 (void *)&cmd_set_vf_vlan_tag_vf,
12727                 (void *)&cmd_set_vf_vlan_tag_vlan,
12728                 (void *)&cmd_set_vf_vlan_tag_tag,
12729                 (void *)&cmd_set_vf_vlan_tag_port_id,
12730                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12731                 (void *)&cmd_set_vf_vlan_tag_on_off,
12732                 NULL,
12733         },
12734 };
12735
12736 /* Common definition of VF and TC TX bandwidth configuration */
12737 struct cmd_vf_tc_bw_result {
12738         cmdline_fixed_string_t set;
12739         cmdline_fixed_string_t vf;
12740         cmdline_fixed_string_t tc;
12741         cmdline_fixed_string_t tx;
12742         cmdline_fixed_string_t min_bw;
12743         cmdline_fixed_string_t max_bw;
12744         cmdline_fixed_string_t strict_link_prio;
12745         portid_t port_id;
12746         uint16_t vf_id;
12747         uint8_t tc_no;
12748         uint32_t bw;
12749         cmdline_fixed_string_t bw_list;
12750         uint8_t tc_map;
12751 };
12752
12753 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12754         TOKEN_STRING_INITIALIZER
12755                 (struct cmd_vf_tc_bw_result,
12756                  set, "set");
12757 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12758         TOKEN_STRING_INITIALIZER
12759                 (struct cmd_vf_tc_bw_result,
12760                  vf, "vf");
12761 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12762         TOKEN_STRING_INITIALIZER
12763                 (struct cmd_vf_tc_bw_result,
12764                  tc, "tc");
12765 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12766         TOKEN_STRING_INITIALIZER
12767                 (struct cmd_vf_tc_bw_result,
12768                  tx, "tx");
12769 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12770         TOKEN_STRING_INITIALIZER
12771                 (struct cmd_vf_tc_bw_result,
12772                  strict_link_prio, "strict-link-priority");
12773 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12774         TOKEN_STRING_INITIALIZER
12775                 (struct cmd_vf_tc_bw_result,
12776                  min_bw, "min-bandwidth");
12777 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12778         TOKEN_STRING_INITIALIZER
12779                 (struct cmd_vf_tc_bw_result,
12780                  max_bw, "max-bandwidth");
12781 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12782         TOKEN_NUM_INITIALIZER
12783                 (struct cmd_vf_tc_bw_result,
12784                  port_id, RTE_UINT16);
12785 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12786         TOKEN_NUM_INITIALIZER
12787                 (struct cmd_vf_tc_bw_result,
12788                  vf_id, RTE_UINT16);
12789 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12790         TOKEN_NUM_INITIALIZER
12791                 (struct cmd_vf_tc_bw_result,
12792                  tc_no, RTE_UINT8);
12793 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12794         TOKEN_NUM_INITIALIZER
12795                 (struct cmd_vf_tc_bw_result,
12796                  bw, RTE_UINT32);
12797 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12798         TOKEN_STRING_INITIALIZER
12799                 (struct cmd_vf_tc_bw_result,
12800                  bw_list, NULL);
12801 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12802         TOKEN_NUM_INITIALIZER
12803                 (struct cmd_vf_tc_bw_result,
12804                  tc_map, RTE_UINT8);
12805
12806 /* VF max bandwidth setting */
12807 static void
12808 cmd_vf_max_bw_parsed(
12809         void *parsed_result,
12810         __rte_unused struct cmdline *cl,
12811         __rte_unused void *data)
12812 {
12813         struct cmd_vf_tc_bw_result *res = parsed_result;
12814         int ret = -ENOTSUP;
12815
12816         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12817                 return;
12818
12819 #ifdef RTE_NET_I40E
12820         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12821                                          res->vf_id, res->bw);
12822 #endif
12823
12824         switch (ret) {
12825         case 0:
12826                 break;
12827         case -EINVAL:
12828                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12829                         res->vf_id, res->bw);
12830                 break;
12831         case -ENODEV:
12832                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12833                 break;
12834         case -ENOTSUP:
12835                 fprintf(stderr, "function not implemented\n");
12836                 break;
12837         default:
12838                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12839         }
12840 }
12841
12842 cmdline_parse_inst_t cmd_vf_max_bw = {
12843         .f = cmd_vf_max_bw_parsed,
12844         .data = NULL,
12845         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12846         .tokens = {
12847                 (void *)&cmd_vf_tc_bw_set,
12848                 (void *)&cmd_vf_tc_bw_vf,
12849                 (void *)&cmd_vf_tc_bw_tx,
12850                 (void *)&cmd_vf_tc_bw_max_bw,
12851                 (void *)&cmd_vf_tc_bw_port_id,
12852                 (void *)&cmd_vf_tc_bw_vf_id,
12853                 (void *)&cmd_vf_tc_bw_bw,
12854                 NULL,
12855         },
12856 };
12857
12858 static int
12859 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12860                            uint8_t *tc_num,
12861                            char *str)
12862 {
12863         uint32_t size;
12864         const char *p, *p0 = str;
12865         char s[256];
12866         char *end;
12867         char *str_fld[16];
12868         uint16_t i;
12869         int ret;
12870
12871         p = strchr(p0, '(');
12872         if (p == NULL) {
12873                 fprintf(stderr,
12874                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12875                 return -1;
12876         }
12877         p++;
12878         p0 = strchr(p, ')');
12879         if (p0 == NULL) {
12880                 fprintf(stderr,
12881                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12882                 return -1;
12883         }
12884         size = p0 - p;
12885         if (size >= sizeof(s)) {
12886                 fprintf(stderr,
12887                         "The string size exceeds the internal buffer size\n");
12888                 return -1;
12889         }
12890         snprintf(s, sizeof(s), "%.*s", size, p);
12891         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12892         if (ret <= 0) {
12893                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12894                 return -1;
12895         }
12896         *tc_num = ret;
12897         for (i = 0; i < ret; i++)
12898                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12899
12900         return 0;
12901 }
12902
12903 /* TC min bandwidth setting */
12904 static void
12905 cmd_vf_tc_min_bw_parsed(
12906         void *parsed_result,
12907         __rte_unused struct cmdline *cl,
12908         __rte_unused void *data)
12909 {
12910         struct cmd_vf_tc_bw_result *res = parsed_result;
12911         uint8_t tc_num;
12912         uint8_t bw[16];
12913         int ret = -ENOTSUP;
12914
12915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12916                 return;
12917
12918         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12919         if (ret)
12920                 return;
12921
12922 #ifdef RTE_NET_I40E
12923         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12924                                               tc_num, bw);
12925 #endif
12926
12927         switch (ret) {
12928         case 0:
12929                 break;
12930         case -EINVAL:
12931                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12932                 break;
12933         case -ENODEV:
12934                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12935                 break;
12936         case -ENOTSUP:
12937                 fprintf(stderr, "function not implemented\n");
12938                 break;
12939         default:
12940                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12941         }
12942 }
12943
12944 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12945         .f = cmd_vf_tc_min_bw_parsed,
12946         .data = NULL,
12947         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12948                     " <bw1, bw2, ...>",
12949         .tokens = {
12950                 (void *)&cmd_vf_tc_bw_set,
12951                 (void *)&cmd_vf_tc_bw_vf,
12952                 (void *)&cmd_vf_tc_bw_tc,
12953                 (void *)&cmd_vf_tc_bw_tx,
12954                 (void *)&cmd_vf_tc_bw_min_bw,
12955                 (void *)&cmd_vf_tc_bw_port_id,
12956                 (void *)&cmd_vf_tc_bw_vf_id,
12957                 (void *)&cmd_vf_tc_bw_bw_list,
12958                 NULL,
12959         },
12960 };
12961
12962 static void
12963 cmd_tc_min_bw_parsed(
12964         void *parsed_result,
12965         __rte_unused struct cmdline *cl,
12966         __rte_unused void *data)
12967 {
12968         struct cmd_vf_tc_bw_result *res = parsed_result;
12969         struct rte_port *port;
12970         uint8_t tc_num;
12971         uint8_t bw[16];
12972         int ret = -ENOTSUP;
12973
12974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12975                 return;
12976
12977         port = &ports[res->port_id];
12978         /** Check if the port is not started **/
12979         if (port->port_status != RTE_PORT_STOPPED) {
12980                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
12981                 return;
12982         }
12983
12984         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12985         if (ret)
12986                 return;
12987
12988 #ifdef RTE_NET_IXGBE
12989         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12990 #endif
12991
12992         switch (ret) {
12993         case 0:
12994                 break;
12995         case -EINVAL:
12996                 fprintf(stderr, "invalid bandwidth\n");
12997                 break;
12998         case -ENODEV:
12999                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13000                 break;
13001         case -ENOTSUP:
13002                 fprintf(stderr, "function not implemented\n");
13003                 break;
13004         default:
13005                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13006         }
13007 }
13008
13009 cmdline_parse_inst_t cmd_tc_min_bw = {
13010         .f = cmd_tc_min_bw_parsed,
13011         .data = NULL,
13012         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13013         .tokens = {
13014                 (void *)&cmd_vf_tc_bw_set,
13015                 (void *)&cmd_vf_tc_bw_tc,
13016                 (void *)&cmd_vf_tc_bw_tx,
13017                 (void *)&cmd_vf_tc_bw_min_bw,
13018                 (void *)&cmd_vf_tc_bw_port_id,
13019                 (void *)&cmd_vf_tc_bw_bw_list,
13020                 NULL,
13021         },
13022 };
13023
13024 /* TC max bandwidth setting */
13025 static void
13026 cmd_vf_tc_max_bw_parsed(
13027         void *parsed_result,
13028         __rte_unused struct cmdline *cl,
13029         __rte_unused void *data)
13030 {
13031         struct cmd_vf_tc_bw_result *res = parsed_result;
13032         int ret = -ENOTSUP;
13033
13034         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13035                 return;
13036
13037 #ifdef RTE_NET_I40E
13038         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13039                                             res->tc_no, res->bw);
13040 #endif
13041
13042         switch (ret) {
13043         case 0:
13044                 break;
13045         case -EINVAL:
13046                 fprintf(stderr,
13047                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
13048                         res->vf_id, res->tc_no, res->bw);
13049                 break;
13050         case -ENODEV:
13051                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13052                 break;
13053         case -ENOTSUP:
13054                 fprintf(stderr, "function not implemented\n");
13055                 break;
13056         default:
13057                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13058         }
13059 }
13060
13061 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13062         .f = cmd_vf_tc_max_bw_parsed,
13063         .data = NULL,
13064         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13065                     " <bandwidth>",
13066         .tokens = {
13067                 (void *)&cmd_vf_tc_bw_set,
13068                 (void *)&cmd_vf_tc_bw_vf,
13069                 (void *)&cmd_vf_tc_bw_tc,
13070                 (void *)&cmd_vf_tc_bw_tx,
13071                 (void *)&cmd_vf_tc_bw_max_bw,
13072                 (void *)&cmd_vf_tc_bw_port_id,
13073                 (void *)&cmd_vf_tc_bw_vf_id,
13074                 (void *)&cmd_vf_tc_bw_tc_no,
13075                 (void *)&cmd_vf_tc_bw_bw,
13076                 NULL,
13077         },
13078 };
13079
13080 /** Set VXLAN encapsulation details */
13081 struct cmd_set_vxlan_result {
13082         cmdline_fixed_string_t set;
13083         cmdline_fixed_string_t vxlan;
13084         cmdline_fixed_string_t pos_token;
13085         cmdline_fixed_string_t ip_version;
13086         uint32_t vlan_present:1;
13087         uint32_t vni;
13088         uint16_t udp_src;
13089         uint16_t udp_dst;
13090         cmdline_ipaddr_t ip_src;
13091         cmdline_ipaddr_t ip_dst;
13092         uint16_t tci;
13093         uint8_t tos;
13094         uint8_t ttl;
13095         struct rte_ether_addr eth_src;
13096         struct rte_ether_addr eth_dst;
13097 };
13098
13099 cmdline_parse_token_string_t cmd_set_vxlan_set =
13100         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13101 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13102         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13103 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13104         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13105                                  "vxlan-tos-ttl");
13106 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13107         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13108                                  "vxlan-with-vlan");
13109 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13110         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13111                                  "ip-version");
13112 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13113         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13114                                  "ipv4#ipv6");
13115 cmdline_parse_token_string_t cmd_set_vxlan_vni =
13116         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13117                                  "vni");
13118 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13119         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13120 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13121         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13122                                  "udp-src");
13123 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13124         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13125 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13126         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13127                                  "udp-dst");
13128 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13129         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13130 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13131         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13132                                  "ip-tos");
13133 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13134         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13135 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13136         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13137                                  "ip-ttl");
13138 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13139         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13140 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13141         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13142                                  "ip-src");
13143 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13144         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13145 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13146         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13147                                  "ip-dst");
13148 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13149         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13150 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13151         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13152                                  "vlan-tci");
13153 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13154         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13155 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13156         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13157                                  "eth-src");
13158 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13159         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13160 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13161         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13162                                  "eth-dst");
13163 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13164         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13165
13166 static void cmd_set_vxlan_parsed(void *parsed_result,
13167         __rte_unused struct cmdline *cl,
13168         __rte_unused void *data)
13169 {
13170         struct cmd_set_vxlan_result *res = parsed_result;
13171         union {
13172                 uint32_t vxlan_id;
13173                 uint8_t vni[4];
13174         } id = {
13175                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13176         };
13177
13178         vxlan_encap_conf.select_tos_ttl = 0;
13179         if (strcmp(res->vxlan, "vxlan") == 0)
13180                 vxlan_encap_conf.select_vlan = 0;
13181         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13182                 vxlan_encap_conf.select_vlan = 1;
13183         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13184                 vxlan_encap_conf.select_vlan = 0;
13185                 vxlan_encap_conf.select_tos_ttl = 1;
13186         }
13187         if (strcmp(res->ip_version, "ipv4") == 0)
13188                 vxlan_encap_conf.select_ipv4 = 1;
13189         else if (strcmp(res->ip_version, "ipv6") == 0)
13190                 vxlan_encap_conf.select_ipv4 = 0;
13191         else
13192                 return;
13193         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13194         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13195         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13196         vxlan_encap_conf.ip_tos = res->tos;
13197         vxlan_encap_conf.ip_ttl = res->ttl;
13198         if (vxlan_encap_conf.select_ipv4) {
13199                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13200                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13201         } else {
13202                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13203                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13204         }
13205         if (vxlan_encap_conf.select_vlan)
13206                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13207         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13208                    RTE_ETHER_ADDR_LEN);
13209         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13210                    RTE_ETHER_ADDR_LEN);
13211 }
13212
13213 cmdline_parse_inst_t cmd_set_vxlan = {
13214         .f = cmd_set_vxlan_parsed,
13215         .data = NULL,
13216         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13217                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13218                 " eth-src <eth-src> eth-dst <eth-dst>",
13219         .tokens = {
13220                 (void *)&cmd_set_vxlan_set,
13221                 (void *)&cmd_set_vxlan_vxlan,
13222                 (void *)&cmd_set_vxlan_ip_version,
13223                 (void *)&cmd_set_vxlan_ip_version_value,
13224                 (void *)&cmd_set_vxlan_vni,
13225                 (void *)&cmd_set_vxlan_vni_value,
13226                 (void *)&cmd_set_vxlan_udp_src,
13227                 (void *)&cmd_set_vxlan_udp_src_value,
13228                 (void *)&cmd_set_vxlan_udp_dst,
13229                 (void *)&cmd_set_vxlan_udp_dst_value,
13230                 (void *)&cmd_set_vxlan_ip_src,
13231                 (void *)&cmd_set_vxlan_ip_src_value,
13232                 (void *)&cmd_set_vxlan_ip_dst,
13233                 (void *)&cmd_set_vxlan_ip_dst_value,
13234                 (void *)&cmd_set_vxlan_eth_src,
13235                 (void *)&cmd_set_vxlan_eth_src_value,
13236                 (void *)&cmd_set_vxlan_eth_dst,
13237                 (void *)&cmd_set_vxlan_eth_dst_value,
13238                 NULL,
13239         },
13240 };
13241
13242 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13243         .f = cmd_set_vxlan_parsed,
13244         .data = NULL,
13245         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13246                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13247                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13248                 " eth-dst <eth-dst>",
13249         .tokens = {
13250                 (void *)&cmd_set_vxlan_set,
13251                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13252                 (void *)&cmd_set_vxlan_ip_version,
13253                 (void *)&cmd_set_vxlan_ip_version_value,
13254                 (void *)&cmd_set_vxlan_vni,
13255                 (void *)&cmd_set_vxlan_vni_value,
13256                 (void *)&cmd_set_vxlan_udp_src,
13257                 (void *)&cmd_set_vxlan_udp_src_value,
13258                 (void *)&cmd_set_vxlan_udp_dst,
13259                 (void *)&cmd_set_vxlan_udp_dst_value,
13260                 (void *)&cmd_set_vxlan_ip_tos,
13261                 (void *)&cmd_set_vxlan_ip_tos_value,
13262                 (void *)&cmd_set_vxlan_ip_ttl,
13263                 (void *)&cmd_set_vxlan_ip_ttl_value,
13264                 (void *)&cmd_set_vxlan_ip_src,
13265                 (void *)&cmd_set_vxlan_ip_src_value,
13266                 (void *)&cmd_set_vxlan_ip_dst,
13267                 (void *)&cmd_set_vxlan_ip_dst_value,
13268                 (void *)&cmd_set_vxlan_eth_src,
13269                 (void *)&cmd_set_vxlan_eth_src_value,
13270                 (void *)&cmd_set_vxlan_eth_dst,
13271                 (void *)&cmd_set_vxlan_eth_dst_value,
13272                 NULL,
13273         },
13274 };
13275
13276 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13277         .f = cmd_set_vxlan_parsed,
13278         .data = NULL,
13279         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13280                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13281                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13282                 " <eth-dst>",
13283         .tokens = {
13284                 (void *)&cmd_set_vxlan_set,
13285                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13286                 (void *)&cmd_set_vxlan_ip_version,
13287                 (void *)&cmd_set_vxlan_ip_version_value,
13288                 (void *)&cmd_set_vxlan_vni,
13289                 (void *)&cmd_set_vxlan_vni_value,
13290                 (void *)&cmd_set_vxlan_udp_src,
13291                 (void *)&cmd_set_vxlan_udp_src_value,
13292                 (void *)&cmd_set_vxlan_udp_dst,
13293                 (void *)&cmd_set_vxlan_udp_dst_value,
13294                 (void *)&cmd_set_vxlan_ip_src,
13295                 (void *)&cmd_set_vxlan_ip_src_value,
13296                 (void *)&cmd_set_vxlan_ip_dst,
13297                 (void *)&cmd_set_vxlan_ip_dst_value,
13298                 (void *)&cmd_set_vxlan_vlan,
13299                 (void *)&cmd_set_vxlan_vlan_value,
13300                 (void *)&cmd_set_vxlan_eth_src,
13301                 (void *)&cmd_set_vxlan_eth_src_value,
13302                 (void *)&cmd_set_vxlan_eth_dst,
13303                 (void *)&cmd_set_vxlan_eth_dst_value,
13304                 NULL,
13305         },
13306 };
13307
13308 /** Set NVGRE encapsulation details */
13309 struct cmd_set_nvgre_result {
13310         cmdline_fixed_string_t set;
13311         cmdline_fixed_string_t nvgre;
13312         cmdline_fixed_string_t pos_token;
13313         cmdline_fixed_string_t ip_version;
13314         uint32_t tni;
13315         cmdline_ipaddr_t ip_src;
13316         cmdline_ipaddr_t ip_dst;
13317         uint16_t tci;
13318         struct rte_ether_addr eth_src;
13319         struct rte_ether_addr eth_dst;
13320 };
13321
13322 cmdline_parse_token_string_t cmd_set_nvgre_set =
13323         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13324 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13325         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13326 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13327         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13328                                  "nvgre-with-vlan");
13329 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13330         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13331                                  "ip-version");
13332 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13333         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13334                                  "ipv4#ipv6");
13335 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13336         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13337                                  "tni");
13338 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13339         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13340 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13341         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13342                                  "ip-src");
13343 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13344         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13345 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13346         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13347                                  "ip-dst");
13348 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13349         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13350 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13351         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13352                                  "vlan-tci");
13353 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13354         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13355 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13356         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13357                                  "eth-src");
13358 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13359         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13360 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13361         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13362                                  "eth-dst");
13363 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13364         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13365
13366 static void cmd_set_nvgre_parsed(void *parsed_result,
13367         __rte_unused struct cmdline *cl,
13368         __rte_unused void *data)
13369 {
13370         struct cmd_set_nvgre_result *res = parsed_result;
13371         union {
13372                 uint32_t nvgre_tni;
13373                 uint8_t tni[4];
13374         } id = {
13375                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13376         };
13377
13378         if (strcmp(res->nvgre, "nvgre") == 0)
13379                 nvgre_encap_conf.select_vlan = 0;
13380         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13381                 nvgre_encap_conf.select_vlan = 1;
13382         if (strcmp(res->ip_version, "ipv4") == 0)
13383                 nvgre_encap_conf.select_ipv4 = 1;
13384         else if (strcmp(res->ip_version, "ipv6") == 0)
13385                 nvgre_encap_conf.select_ipv4 = 0;
13386         else
13387                 return;
13388         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13389         if (nvgre_encap_conf.select_ipv4) {
13390                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13391                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13392         } else {
13393                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13394                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13395         }
13396         if (nvgre_encap_conf.select_vlan)
13397                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13398         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13399                    RTE_ETHER_ADDR_LEN);
13400         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13401                    RTE_ETHER_ADDR_LEN);
13402 }
13403
13404 cmdline_parse_inst_t cmd_set_nvgre = {
13405         .f = cmd_set_nvgre_parsed,
13406         .data = NULL,
13407         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13408                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13409                 " eth-dst <eth-dst>",
13410         .tokens = {
13411                 (void *)&cmd_set_nvgre_set,
13412                 (void *)&cmd_set_nvgre_nvgre,
13413                 (void *)&cmd_set_nvgre_ip_version,
13414                 (void *)&cmd_set_nvgre_ip_version_value,
13415                 (void *)&cmd_set_nvgre_tni,
13416                 (void *)&cmd_set_nvgre_tni_value,
13417                 (void *)&cmd_set_nvgre_ip_src,
13418                 (void *)&cmd_set_nvgre_ip_src_value,
13419                 (void *)&cmd_set_nvgre_ip_dst,
13420                 (void *)&cmd_set_nvgre_ip_dst_value,
13421                 (void *)&cmd_set_nvgre_eth_src,
13422                 (void *)&cmd_set_nvgre_eth_src_value,
13423                 (void *)&cmd_set_nvgre_eth_dst,
13424                 (void *)&cmd_set_nvgre_eth_dst_value,
13425                 NULL,
13426         },
13427 };
13428
13429 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13430         .f = cmd_set_nvgre_parsed,
13431         .data = NULL,
13432         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13433                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13434                 " eth-src <eth-src> eth-dst <eth-dst>",
13435         .tokens = {
13436                 (void *)&cmd_set_nvgre_set,
13437                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13438                 (void *)&cmd_set_nvgre_ip_version,
13439                 (void *)&cmd_set_nvgre_ip_version_value,
13440                 (void *)&cmd_set_nvgre_tni,
13441                 (void *)&cmd_set_nvgre_tni_value,
13442                 (void *)&cmd_set_nvgre_ip_src,
13443                 (void *)&cmd_set_nvgre_ip_src_value,
13444                 (void *)&cmd_set_nvgre_ip_dst,
13445                 (void *)&cmd_set_nvgre_ip_dst_value,
13446                 (void *)&cmd_set_nvgre_vlan,
13447                 (void *)&cmd_set_nvgre_vlan_value,
13448                 (void *)&cmd_set_nvgre_eth_src,
13449                 (void *)&cmd_set_nvgre_eth_src_value,
13450                 (void *)&cmd_set_nvgre_eth_dst,
13451                 (void *)&cmd_set_nvgre_eth_dst_value,
13452                 NULL,
13453         },
13454 };
13455
13456 /** Set L2 encapsulation details */
13457 struct cmd_set_l2_encap_result {
13458         cmdline_fixed_string_t set;
13459         cmdline_fixed_string_t l2_encap;
13460         cmdline_fixed_string_t pos_token;
13461         cmdline_fixed_string_t ip_version;
13462         uint32_t vlan_present:1;
13463         uint16_t tci;
13464         struct rte_ether_addr eth_src;
13465         struct rte_ether_addr eth_dst;
13466 };
13467
13468 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13469         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13470 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13471         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13472 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13473         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13474                                  "l2_encap-with-vlan");
13475 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13476         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13477                                  "ip-version");
13478 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13479         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13480                                  "ipv4#ipv6");
13481 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13482         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13483                                  "vlan-tci");
13484 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13485         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13486 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13487         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13488                                  "eth-src");
13489 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13490         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13491 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13492         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13493                                  "eth-dst");
13494 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13495         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13496
13497 static void cmd_set_l2_encap_parsed(void *parsed_result,
13498         __rte_unused struct cmdline *cl,
13499         __rte_unused void *data)
13500 {
13501         struct cmd_set_l2_encap_result *res = parsed_result;
13502
13503         if (strcmp(res->l2_encap, "l2_encap") == 0)
13504                 l2_encap_conf.select_vlan = 0;
13505         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13506                 l2_encap_conf.select_vlan = 1;
13507         if (strcmp(res->ip_version, "ipv4") == 0)
13508                 l2_encap_conf.select_ipv4 = 1;
13509         else if (strcmp(res->ip_version, "ipv6") == 0)
13510                 l2_encap_conf.select_ipv4 = 0;
13511         else
13512                 return;
13513         if (l2_encap_conf.select_vlan)
13514                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13515         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13516                    RTE_ETHER_ADDR_LEN);
13517         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13518                    RTE_ETHER_ADDR_LEN);
13519 }
13520
13521 cmdline_parse_inst_t cmd_set_l2_encap = {
13522         .f = cmd_set_l2_encap_parsed,
13523         .data = NULL,
13524         .help_str = "set l2_encap ip-version ipv4|ipv6"
13525                 " eth-src <eth-src> eth-dst <eth-dst>",
13526         .tokens = {
13527                 (void *)&cmd_set_l2_encap_set,
13528                 (void *)&cmd_set_l2_encap_l2_encap,
13529                 (void *)&cmd_set_l2_encap_ip_version,
13530                 (void *)&cmd_set_l2_encap_ip_version_value,
13531                 (void *)&cmd_set_l2_encap_eth_src,
13532                 (void *)&cmd_set_l2_encap_eth_src_value,
13533                 (void *)&cmd_set_l2_encap_eth_dst,
13534                 (void *)&cmd_set_l2_encap_eth_dst_value,
13535                 NULL,
13536         },
13537 };
13538
13539 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13540         .f = cmd_set_l2_encap_parsed,
13541         .data = NULL,
13542         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13543                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13544         .tokens = {
13545                 (void *)&cmd_set_l2_encap_set,
13546                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13547                 (void *)&cmd_set_l2_encap_ip_version,
13548                 (void *)&cmd_set_l2_encap_ip_version_value,
13549                 (void *)&cmd_set_l2_encap_vlan,
13550                 (void *)&cmd_set_l2_encap_vlan_value,
13551                 (void *)&cmd_set_l2_encap_eth_src,
13552                 (void *)&cmd_set_l2_encap_eth_src_value,
13553                 (void *)&cmd_set_l2_encap_eth_dst,
13554                 (void *)&cmd_set_l2_encap_eth_dst_value,
13555                 NULL,
13556         },
13557 };
13558
13559 /** Set L2 decapsulation details */
13560 struct cmd_set_l2_decap_result {
13561         cmdline_fixed_string_t set;
13562         cmdline_fixed_string_t l2_decap;
13563         cmdline_fixed_string_t pos_token;
13564         uint32_t vlan_present:1;
13565 };
13566
13567 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13568         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13569 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13570         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13571                                  "l2_decap");
13572 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13573         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13574                                  "l2_decap-with-vlan");
13575
13576 static void cmd_set_l2_decap_parsed(void *parsed_result,
13577         __rte_unused struct cmdline *cl,
13578         __rte_unused void *data)
13579 {
13580         struct cmd_set_l2_decap_result *res = parsed_result;
13581
13582         if (strcmp(res->l2_decap, "l2_decap") == 0)
13583                 l2_decap_conf.select_vlan = 0;
13584         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13585                 l2_decap_conf.select_vlan = 1;
13586 }
13587
13588 cmdline_parse_inst_t cmd_set_l2_decap = {
13589         .f = cmd_set_l2_decap_parsed,
13590         .data = NULL,
13591         .help_str = "set l2_decap",
13592         .tokens = {
13593                 (void *)&cmd_set_l2_decap_set,
13594                 (void *)&cmd_set_l2_decap_l2_decap,
13595                 NULL,
13596         },
13597 };
13598
13599 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13600         .f = cmd_set_l2_decap_parsed,
13601         .data = NULL,
13602         .help_str = "set l2_decap-with-vlan",
13603         .tokens = {
13604                 (void *)&cmd_set_l2_decap_set,
13605                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13606                 NULL,
13607         },
13608 };
13609
13610 /** Set MPLSoGRE encapsulation details */
13611 struct cmd_set_mplsogre_encap_result {
13612         cmdline_fixed_string_t set;
13613         cmdline_fixed_string_t mplsogre;
13614         cmdline_fixed_string_t pos_token;
13615         cmdline_fixed_string_t ip_version;
13616         uint32_t vlan_present:1;
13617         uint32_t label;
13618         cmdline_ipaddr_t ip_src;
13619         cmdline_ipaddr_t ip_dst;
13620         uint16_t tci;
13621         struct rte_ether_addr eth_src;
13622         struct rte_ether_addr eth_dst;
13623 };
13624
13625 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13626         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13627                                  "set");
13628 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13629         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13630                                  "mplsogre_encap");
13631 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13632         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13633                                  mplsogre, "mplsogre_encap-with-vlan");
13634 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13635         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13636                                  pos_token, "ip-version");
13637 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13638         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13639                                  ip_version, "ipv4#ipv6");
13640 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13641         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13642                                  pos_token, "label");
13643 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13644         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13645                               RTE_UINT32);
13646 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13647         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13648                                  pos_token, "ip-src");
13649 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13650         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13651 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13652         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13653                                  pos_token, "ip-dst");
13654 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13655         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13656 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13657         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13658                                  pos_token, "vlan-tci");
13659 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13660         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13661                               RTE_UINT16);
13662 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13663         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13664                                  pos_token, "eth-src");
13665 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13667                                     eth_src);
13668 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13669         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13670                                  pos_token, "eth-dst");
13671 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13672         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13673                                     eth_dst);
13674
13675 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13676         __rte_unused struct cmdline *cl,
13677         __rte_unused void *data)
13678 {
13679         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13680         union {
13681                 uint32_t mplsogre_label;
13682                 uint8_t label[4];
13683         } id = {
13684                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13685         };
13686
13687         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13688                 mplsogre_encap_conf.select_vlan = 0;
13689         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13690                 mplsogre_encap_conf.select_vlan = 1;
13691         if (strcmp(res->ip_version, "ipv4") == 0)
13692                 mplsogre_encap_conf.select_ipv4 = 1;
13693         else if (strcmp(res->ip_version, "ipv6") == 0)
13694                 mplsogre_encap_conf.select_ipv4 = 0;
13695         else
13696                 return;
13697         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13698         if (mplsogre_encap_conf.select_ipv4) {
13699                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13700                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13701         } else {
13702                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13703                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13704         }
13705         if (mplsogre_encap_conf.select_vlan)
13706                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13707         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13708                    RTE_ETHER_ADDR_LEN);
13709         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13710                    RTE_ETHER_ADDR_LEN);
13711 }
13712
13713 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13714         .f = cmd_set_mplsogre_encap_parsed,
13715         .data = NULL,
13716         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13717                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13718                 " eth-dst <eth-dst>",
13719         .tokens = {
13720                 (void *)&cmd_set_mplsogre_encap_set,
13721                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13722                 (void *)&cmd_set_mplsogre_encap_ip_version,
13723                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13724                 (void *)&cmd_set_mplsogre_encap_label,
13725                 (void *)&cmd_set_mplsogre_encap_label_value,
13726                 (void *)&cmd_set_mplsogre_encap_ip_src,
13727                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13728                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13729                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13730                 (void *)&cmd_set_mplsogre_encap_eth_src,
13731                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13732                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13733                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13734                 NULL,
13735         },
13736 };
13737
13738 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13739         .f = cmd_set_mplsogre_encap_parsed,
13740         .data = NULL,
13741         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13742                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13743                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13744         .tokens = {
13745                 (void *)&cmd_set_mplsogre_encap_set,
13746                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13747                 (void *)&cmd_set_mplsogre_encap_ip_version,
13748                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13749                 (void *)&cmd_set_mplsogre_encap_label,
13750                 (void *)&cmd_set_mplsogre_encap_label_value,
13751                 (void *)&cmd_set_mplsogre_encap_ip_src,
13752                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13753                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13754                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13755                 (void *)&cmd_set_mplsogre_encap_vlan,
13756                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13757                 (void *)&cmd_set_mplsogre_encap_eth_src,
13758                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13759                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13760                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13761                 NULL,
13762         },
13763 };
13764
13765 /** Set MPLSoGRE decapsulation details */
13766 struct cmd_set_mplsogre_decap_result {
13767         cmdline_fixed_string_t set;
13768         cmdline_fixed_string_t mplsogre;
13769         cmdline_fixed_string_t pos_token;
13770         cmdline_fixed_string_t ip_version;
13771         uint32_t vlan_present:1;
13772 };
13773
13774 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13775         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13776                                  "set");
13777 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13778         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13779                                  "mplsogre_decap");
13780 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13781         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13782                                  mplsogre, "mplsogre_decap-with-vlan");
13783 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13784         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13785                                  pos_token, "ip-version");
13786 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13787         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13788                                  ip_version, "ipv4#ipv6");
13789
13790 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13791         __rte_unused struct cmdline *cl,
13792         __rte_unused void *data)
13793 {
13794         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13795
13796         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13797                 mplsogre_decap_conf.select_vlan = 0;
13798         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13799                 mplsogre_decap_conf.select_vlan = 1;
13800         if (strcmp(res->ip_version, "ipv4") == 0)
13801                 mplsogre_decap_conf.select_ipv4 = 1;
13802         else if (strcmp(res->ip_version, "ipv6") == 0)
13803                 mplsogre_decap_conf.select_ipv4 = 0;
13804 }
13805
13806 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13807         .f = cmd_set_mplsogre_decap_parsed,
13808         .data = NULL,
13809         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13810         .tokens = {
13811                 (void *)&cmd_set_mplsogre_decap_set,
13812                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13813                 (void *)&cmd_set_mplsogre_decap_ip_version,
13814                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13815                 NULL,
13816         },
13817 };
13818
13819 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13820         .f = cmd_set_mplsogre_decap_parsed,
13821         .data = NULL,
13822         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13823         .tokens = {
13824                 (void *)&cmd_set_mplsogre_decap_set,
13825                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13826                 (void *)&cmd_set_mplsogre_decap_ip_version,
13827                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13828                 NULL,
13829         },
13830 };
13831
13832 /** Set MPLSoUDP encapsulation details */
13833 struct cmd_set_mplsoudp_encap_result {
13834         cmdline_fixed_string_t set;
13835         cmdline_fixed_string_t mplsoudp;
13836         cmdline_fixed_string_t pos_token;
13837         cmdline_fixed_string_t ip_version;
13838         uint32_t vlan_present:1;
13839         uint32_t label;
13840         uint16_t udp_src;
13841         uint16_t udp_dst;
13842         cmdline_ipaddr_t ip_src;
13843         cmdline_ipaddr_t ip_dst;
13844         uint16_t tci;
13845         struct rte_ether_addr eth_src;
13846         struct rte_ether_addr eth_dst;
13847 };
13848
13849 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13850         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13851                                  "set");
13852 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13853         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13854                                  "mplsoudp_encap");
13855 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13856         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13857                                  mplsoudp, "mplsoudp_encap-with-vlan");
13858 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13859         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13860                                  pos_token, "ip-version");
13861 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13862         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13863                                  ip_version, "ipv4#ipv6");
13864 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13865         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13866                                  pos_token, "label");
13867 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13868         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13869                               RTE_UINT32);
13870 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13871         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13872                                  pos_token, "udp-src");
13873 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13874         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13875                               RTE_UINT16);
13876 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13877         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13878                                  pos_token, "udp-dst");
13879 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13880         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13881                               RTE_UINT16);
13882 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13883         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13884                                  pos_token, "ip-src");
13885 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13886         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13887 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13888         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13889                                  pos_token, "ip-dst");
13890 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13891         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13892 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13893         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13894                                  pos_token, "vlan-tci");
13895 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13896         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13897                               RTE_UINT16);
13898 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13899         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13900                                  pos_token, "eth-src");
13901 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13902         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13903                                     eth_src);
13904 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13905         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13906                                  pos_token, "eth-dst");
13907 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13908         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13909                                     eth_dst);
13910
13911 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13912         __rte_unused struct cmdline *cl,
13913         __rte_unused void *data)
13914 {
13915         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13916         union {
13917                 uint32_t mplsoudp_label;
13918                 uint8_t label[4];
13919         } id = {
13920                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13921         };
13922
13923         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13924                 mplsoudp_encap_conf.select_vlan = 0;
13925         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13926                 mplsoudp_encap_conf.select_vlan = 1;
13927         if (strcmp(res->ip_version, "ipv4") == 0)
13928                 mplsoudp_encap_conf.select_ipv4 = 1;
13929         else if (strcmp(res->ip_version, "ipv6") == 0)
13930                 mplsoudp_encap_conf.select_ipv4 = 0;
13931         else
13932                 return;
13933         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13934         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13935         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13936         if (mplsoudp_encap_conf.select_ipv4) {
13937                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13938                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13939         } else {
13940                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13941                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13942         }
13943         if (mplsoudp_encap_conf.select_vlan)
13944                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13945         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13946                    RTE_ETHER_ADDR_LEN);
13947         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13948                    RTE_ETHER_ADDR_LEN);
13949 }
13950
13951 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13952         .f = cmd_set_mplsoudp_encap_parsed,
13953         .data = NULL,
13954         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13955                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13956                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13957         .tokens = {
13958                 (void *)&cmd_set_mplsoudp_encap_set,
13959                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13960                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13961                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13962                 (void *)&cmd_set_mplsoudp_encap_label,
13963                 (void *)&cmd_set_mplsoudp_encap_label_value,
13964                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13965                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13966                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13967                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13968                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13969                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13970                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13971                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13972                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13973                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13974                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13975                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13976                 NULL,
13977         },
13978 };
13979
13980 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13981         .f = cmd_set_mplsoudp_encap_parsed,
13982         .data = NULL,
13983         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13984                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13985                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13986                 " eth-src <eth-src> eth-dst <eth-dst>",
13987         .tokens = {
13988                 (void *)&cmd_set_mplsoudp_encap_set,
13989                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13990                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13991                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13992                 (void *)&cmd_set_mplsoudp_encap_label,
13993                 (void *)&cmd_set_mplsoudp_encap_label_value,
13994                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13995                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13996                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13997                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13998                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13999                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
14000                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
14001                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
14002                 (void *)&cmd_set_mplsoudp_encap_vlan,
14003                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
14004                 (void *)&cmd_set_mplsoudp_encap_eth_src,
14005                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
14006                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
14007                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
14008                 NULL,
14009         },
14010 };
14011
14012 /** Set MPLSoUDP decapsulation details */
14013 struct cmd_set_mplsoudp_decap_result {
14014         cmdline_fixed_string_t set;
14015         cmdline_fixed_string_t mplsoudp;
14016         cmdline_fixed_string_t pos_token;
14017         cmdline_fixed_string_t ip_version;
14018         uint32_t vlan_present:1;
14019 };
14020
14021 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14022         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14023                                  "set");
14024 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14025         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14026                                  "mplsoudp_decap");
14027 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14028         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14029                                  mplsoudp, "mplsoudp_decap-with-vlan");
14030 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14031         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14032                                  pos_token, "ip-version");
14033 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14034         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14035                                  ip_version, "ipv4#ipv6");
14036
14037 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14038         __rte_unused struct cmdline *cl,
14039         __rte_unused void *data)
14040 {
14041         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14042
14043         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14044                 mplsoudp_decap_conf.select_vlan = 0;
14045         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14046                 mplsoudp_decap_conf.select_vlan = 1;
14047         if (strcmp(res->ip_version, "ipv4") == 0)
14048                 mplsoudp_decap_conf.select_ipv4 = 1;
14049         else if (strcmp(res->ip_version, "ipv6") == 0)
14050                 mplsoudp_decap_conf.select_ipv4 = 0;
14051 }
14052
14053 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14054         .f = cmd_set_mplsoudp_decap_parsed,
14055         .data = NULL,
14056         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14057         .tokens = {
14058                 (void *)&cmd_set_mplsoudp_decap_set,
14059                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14060                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14061                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14062                 NULL,
14063         },
14064 };
14065
14066 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14067         .f = cmd_set_mplsoudp_decap_parsed,
14068         .data = NULL,
14069         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14070         .tokens = {
14071                 (void *)&cmd_set_mplsoudp_decap_set,
14072                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14073                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14074                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14075                 NULL,
14076         },
14077 };
14078
14079 /** Set connection tracking object common details */
14080 struct cmd_set_conntrack_common_result {
14081         cmdline_fixed_string_t set;
14082         cmdline_fixed_string_t conntrack;
14083         cmdline_fixed_string_t common;
14084         cmdline_fixed_string_t peer;
14085         cmdline_fixed_string_t is_orig;
14086         cmdline_fixed_string_t enable;
14087         cmdline_fixed_string_t live;
14088         cmdline_fixed_string_t sack;
14089         cmdline_fixed_string_t cack;
14090         cmdline_fixed_string_t last_dir;
14091         cmdline_fixed_string_t liberal;
14092         cmdline_fixed_string_t state;
14093         cmdline_fixed_string_t max_ack_win;
14094         cmdline_fixed_string_t retrans;
14095         cmdline_fixed_string_t last_win;
14096         cmdline_fixed_string_t last_seq;
14097         cmdline_fixed_string_t last_ack;
14098         cmdline_fixed_string_t last_end;
14099         cmdline_fixed_string_t last_index;
14100         uint8_t stat;
14101         uint8_t factor;
14102         uint16_t peer_port;
14103         uint32_t is_original;
14104         uint32_t en;
14105         uint32_t is_live;
14106         uint32_t s_ack;
14107         uint32_t c_ack;
14108         uint32_t ld;
14109         uint32_t lb;
14110         uint8_t re_num;
14111         uint8_t li;
14112         uint16_t lw;
14113         uint32_t ls;
14114         uint32_t la;
14115         uint32_t le;
14116 };
14117
14118 cmdline_parse_token_string_t cmd_set_conntrack_set =
14119         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14120                                  set, "set");
14121 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14122         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14123                                  conntrack, "conntrack");
14124 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14125         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14126                                  common, "com");
14127 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14128         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14129                                  peer, "peer");
14130 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14131         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14132                               peer_port, RTE_UINT16);
14133 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14134         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14135                                  is_orig, "is_orig");
14136 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14137         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14138                               is_original, RTE_UINT32);
14139 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14140         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14141                                  enable, "enable");
14142 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14143         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14144                               en, RTE_UINT32);
14145 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14146         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14147                                  live, "live");
14148 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14149         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14150                               is_live, RTE_UINT32);
14151 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14152         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14153                                  sack, "sack");
14154 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14155         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14156                               s_ack, RTE_UINT32);
14157 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14158         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14159                                  cack, "cack");
14160 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14161         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14162                               c_ack, RTE_UINT32);
14163 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14164         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14165                                  last_dir, "last_dir");
14166 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14167         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14168                               ld, RTE_UINT32);
14169 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14170         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14171                                  liberal, "liberal");
14172 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14173         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14174                               lb, RTE_UINT32);
14175 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14176         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14177                                  state, "state");
14178 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14179         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14180                               stat, RTE_UINT8);
14181 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14182         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14183                                  max_ack_win, "max_ack_win");
14184 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14185         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14186                               factor, RTE_UINT8);
14187 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14188         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14189                                  retrans, "r_lim");
14190 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14191         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14192                               re_num, RTE_UINT8);
14193 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14194         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14195                                  last_win, "last_win");
14196 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14197         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14198                               lw, RTE_UINT16);
14199 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14200         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14201                                  last_seq, "last_seq");
14202 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14203         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14204                               ls, RTE_UINT32);
14205 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14206         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14207                                  last_ack, "last_ack");
14208 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14209         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14210                               la, RTE_UINT32);
14211 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14212         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14213                                  last_end, "last_end");
14214 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14215         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14216                               le, RTE_UINT32);
14217 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14218         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14219                                  last_index, "last_index");
14220 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14221         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14222                               li, RTE_UINT8);
14223
14224 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14225         __rte_unused struct cmdline *cl,
14226         __rte_unused void *data)
14227 {
14228         struct cmd_set_conntrack_common_result *res = parsed_result;
14229
14230         /* No need to swap to big endian. */
14231         conntrack_context.peer_port = res->peer_port;
14232         conntrack_context.is_original_dir = res->is_original;
14233         conntrack_context.enable = res->en;
14234         conntrack_context.live_connection = res->is_live;
14235         conntrack_context.selective_ack = res->s_ack;
14236         conntrack_context.challenge_ack_passed = res->c_ack;
14237         conntrack_context.last_direction = res->ld;
14238         conntrack_context.liberal_mode = res->lb;
14239         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14240         conntrack_context.max_ack_window = res->factor;
14241         conntrack_context.retransmission_limit = res->re_num;
14242         conntrack_context.last_window = res->lw;
14243         conntrack_context.last_index =
14244                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14245         conntrack_context.last_seq = res->ls;
14246         conntrack_context.last_ack = res->la;
14247         conntrack_context.last_end = res->le;
14248 }
14249
14250 cmdline_parse_inst_t cmd_set_conntrack_common = {
14251         .f = cmd_set_conntrack_common_parsed,
14252         .data = NULL,
14253         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14254                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14255                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14256                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14257                 " last_index <flag>",
14258         .tokens = {
14259                 (void *)&cmd_set_conntrack_set,
14260                 (void *)&cmd_set_conntrack_conntrack,
14261                 (void *)&cmd_set_conntrack_common_com,
14262                 (void *)&cmd_set_conntrack_common_peer,
14263                 (void *)&cmd_set_conntrack_common_peer_value,
14264                 (void *)&cmd_set_conntrack_common_is_orig,
14265                 (void *)&cmd_set_conntrack_common_is_orig_value,
14266                 (void *)&cmd_set_conntrack_common_enable,
14267                 (void *)&cmd_set_conntrack_common_enable_value,
14268                 (void *)&cmd_set_conntrack_common_live,
14269                 (void *)&cmd_set_conntrack_common_live_value,
14270                 (void *)&cmd_set_conntrack_common_sack,
14271                 (void *)&cmd_set_conntrack_common_sack_value,
14272                 (void *)&cmd_set_conntrack_common_cack,
14273                 (void *)&cmd_set_conntrack_common_cack_value,
14274                 (void *)&cmd_set_conntrack_common_last_dir,
14275                 (void *)&cmd_set_conntrack_common_last_dir_value,
14276                 (void *)&cmd_set_conntrack_common_liberal,
14277                 (void *)&cmd_set_conntrack_common_liberal_value,
14278                 (void *)&cmd_set_conntrack_common_state,
14279                 (void *)&cmd_set_conntrack_common_state_value,
14280                 (void *)&cmd_set_conntrack_common_max_ackwin,
14281                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14282                 (void *)&cmd_set_conntrack_common_retrans,
14283                 (void *)&cmd_set_conntrack_common_retrans_value,
14284                 (void *)&cmd_set_conntrack_common_last_win,
14285                 (void *)&cmd_set_conntrack_common_last_win_value,
14286                 (void *)&cmd_set_conntrack_common_last_seq,
14287                 (void *)&cmd_set_conntrack_common_last_seq_value,
14288                 (void *)&cmd_set_conntrack_common_last_ack,
14289                 (void *)&cmd_set_conntrack_common_last_ack_value,
14290                 (void *)&cmd_set_conntrack_common_last_end,
14291                 (void *)&cmd_set_conntrack_common_last_end_value,
14292                 (void *)&cmd_set_conntrack_common_last_index,
14293                 (void *)&cmd_set_conntrack_common_last_index_value,
14294                 NULL,
14295         },
14296 };
14297
14298 /** Set connection tracking object both directions' details */
14299 struct cmd_set_conntrack_dir_result {
14300         cmdline_fixed_string_t set;
14301         cmdline_fixed_string_t conntrack;
14302         cmdline_fixed_string_t dir;
14303         cmdline_fixed_string_t scale;
14304         cmdline_fixed_string_t fin;
14305         cmdline_fixed_string_t ack_seen;
14306         cmdline_fixed_string_t unack;
14307         cmdline_fixed_string_t sent_end;
14308         cmdline_fixed_string_t reply_end;
14309         cmdline_fixed_string_t max_win;
14310         cmdline_fixed_string_t max_ack;
14311         uint32_t factor;
14312         uint32_t f;
14313         uint32_t as;
14314         uint32_t un;
14315         uint32_t se;
14316         uint32_t re;
14317         uint32_t mw;
14318         uint32_t ma;
14319 };
14320
14321 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14322         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14323                                  set, "set");
14324 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14325         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14326                                  conntrack, "conntrack");
14327 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14328         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14329                                  dir, "orig#rply");
14330 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14331         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14332                                  scale, "scale");
14333 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14334         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14335                               factor, RTE_UINT32);
14336 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14337         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14338                                  fin, "fin");
14339 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14340         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14341                               f, RTE_UINT32);
14342 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14343         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14344                                  ack_seen, "acked");
14345 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14346         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14347                               as, RTE_UINT32);
14348 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14349         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14350                                  unack, "unack_data");
14351 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14352         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14353                               un, RTE_UINT32);
14354 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14355         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14356                                  sent_end, "sent_end");
14357 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14358         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14359                               se, RTE_UINT32);
14360 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14361         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14362                                  reply_end, "reply_end");
14363 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14364         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14365                               re, RTE_UINT32);
14366 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14367         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14368                                  max_win, "max_win");
14369 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14370         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14371                               mw, RTE_UINT32);
14372 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14373         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14374                                  max_ack, "max_ack");
14375 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14376         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14377                               ma, RTE_UINT32);
14378
14379 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14380         __rte_unused struct cmdline *cl,
14381         __rte_unused void *data)
14382 {
14383         struct cmd_set_conntrack_dir_result *res = parsed_result;
14384         struct rte_flow_tcp_dir_param *dir = NULL;
14385
14386         if (strcmp(res->dir, "orig") == 0)
14387                 dir = &conntrack_context.original_dir;
14388         else if (strcmp(res->dir, "rply") == 0)
14389                 dir = &conntrack_context.reply_dir;
14390         else
14391                 return;
14392         dir->scale = res->factor;
14393         dir->close_initiated = res->f;
14394         dir->last_ack_seen = res->as;
14395         dir->data_unacked = res->un;
14396         dir->sent_end = res->se;
14397         dir->reply_end = res->re;
14398         dir->max_ack = res->ma;
14399         dir->max_win = res->mw;
14400 }
14401
14402 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14403         .f = cmd_set_conntrack_dir_parsed,
14404         .data = NULL,
14405         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14406                     " acked <seen> unack_data <unack> sent_end <sent>"
14407                     " reply_end <reply> max_win <win> max_ack <ack>",
14408         .tokens = {
14409                 (void *)&cmd_set_conntrack_set,
14410                 (void *)&cmd_set_conntrack_conntrack,
14411                 (void *)&cmd_set_conntrack_dir_dir,
14412                 (void *)&cmd_set_conntrack_dir_scale,
14413                 (void *)&cmd_set_conntrack_dir_scale_value,
14414                 (void *)&cmd_set_conntrack_dir_fin,
14415                 (void *)&cmd_set_conntrack_dir_fin_value,
14416                 (void *)&cmd_set_conntrack_dir_ack,
14417                 (void *)&cmd_set_conntrack_dir_ack_value,
14418                 (void *)&cmd_set_conntrack_dir_unack_data,
14419                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14420                 (void *)&cmd_set_conntrack_dir_sent_end,
14421                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14422                 (void *)&cmd_set_conntrack_dir_reply_end,
14423                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14424                 (void *)&cmd_set_conntrack_dir_max_win,
14425                 (void *)&cmd_set_conntrack_dir_max_win_value,
14426                 (void *)&cmd_set_conntrack_dir_max_ack,
14427                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14428                 NULL,
14429         },
14430 };
14431
14432 /* Strict link priority scheduling mode setting */
14433 static void
14434 cmd_strict_link_prio_parsed(
14435         void *parsed_result,
14436         __rte_unused struct cmdline *cl,
14437         __rte_unused void *data)
14438 {
14439         struct cmd_vf_tc_bw_result *res = parsed_result;
14440         int ret = -ENOTSUP;
14441
14442         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14443                 return;
14444
14445 #ifdef RTE_NET_I40E
14446         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14447 #endif
14448
14449         switch (ret) {
14450         case 0:
14451                 break;
14452         case -EINVAL:
14453                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14454                 break;
14455         case -ENODEV:
14456                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14457                 break;
14458         case -ENOTSUP:
14459                 fprintf(stderr, "function not implemented\n");
14460                 break;
14461         default:
14462                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14463         }
14464 }
14465
14466 cmdline_parse_inst_t cmd_strict_link_prio = {
14467         .f = cmd_strict_link_prio_parsed,
14468         .data = NULL,
14469         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14470         .tokens = {
14471                 (void *)&cmd_vf_tc_bw_set,
14472                 (void *)&cmd_vf_tc_bw_tx,
14473                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14474                 (void *)&cmd_vf_tc_bw_port_id,
14475                 (void *)&cmd_vf_tc_bw_tc_map,
14476                 NULL,
14477         },
14478 };
14479
14480 /* Load dynamic device personalization*/
14481 struct cmd_ddp_add_result {
14482         cmdline_fixed_string_t ddp;
14483         cmdline_fixed_string_t add;
14484         portid_t port_id;
14485         char filepath[];
14486 };
14487
14488 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14489         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14490 cmdline_parse_token_string_t cmd_ddp_add_add =
14491         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14492 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14493         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14494                 RTE_UINT16);
14495 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14496         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14497
14498 static void
14499 cmd_ddp_add_parsed(
14500         void *parsed_result,
14501         __rte_unused struct cmdline *cl,
14502         __rte_unused void *data)
14503 {
14504         struct cmd_ddp_add_result *res = parsed_result;
14505         uint8_t *buff;
14506         uint32_t size;
14507         char *filepath;
14508         char *file_fld[2];
14509         int file_num;
14510         int ret = -ENOTSUP;
14511
14512         if (!all_ports_stopped()) {
14513                 fprintf(stderr, "Please stop all ports first\n");
14514                 return;
14515         }
14516
14517         filepath = strdup(res->filepath);
14518         if (filepath == NULL) {
14519                 fprintf(stderr, "Failed to allocate memory\n");
14520                 return;
14521         }
14522         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14523
14524         buff = open_file(file_fld[0], &size);
14525         if (!buff) {
14526                 free((void *)filepath);
14527                 return;
14528         }
14529
14530 #ifdef RTE_NET_I40E
14531         if (ret == -ENOTSUP)
14532                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14533                                                buff, size,
14534                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14535 #endif
14536
14537         if (ret == -EEXIST)
14538                 fprintf(stderr, "Profile has already existed.\n");
14539         else if (ret < 0)
14540                 fprintf(stderr, "Failed to load profile.\n");
14541         else if (file_num == 2)
14542                 save_file(file_fld[1], buff, size);
14543
14544         close_file(buff);
14545         free((void *)filepath);
14546 }
14547
14548 cmdline_parse_inst_t cmd_ddp_add = {
14549         .f = cmd_ddp_add_parsed,
14550         .data = NULL,
14551         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14552         .tokens = {
14553                 (void *)&cmd_ddp_add_ddp,
14554                 (void *)&cmd_ddp_add_add,
14555                 (void *)&cmd_ddp_add_port_id,
14556                 (void *)&cmd_ddp_add_filepath,
14557                 NULL,
14558         },
14559 };
14560
14561 /* Delete dynamic device personalization*/
14562 struct cmd_ddp_del_result {
14563         cmdline_fixed_string_t ddp;
14564         cmdline_fixed_string_t del;
14565         portid_t port_id;
14566         char filepath[];
14567 };
14568
14569 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14570         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14571 cmdline_parse_token_string_t cmd_ddp_del_del =
14572         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14573 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14574         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14575 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14576         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14577
14578 static void
14579 cmd_ddp_del_parsed(
14580         void *parsed_result,
14581         __rte_unused struct cmdline *cl,
14582         __rte_unused void *data)
14583 {
14584         struct cmd_ddp_del_result *res = parsed_result;
14585         uint8_t *buff;
14586         uint32_t size;
14587         int ret = -ENOTSUP;
14588
14589         if (!all_ports_stopped()) {
14590                 fprintf(stderr, "Please stop all ports first\n");
14591                 return;
14592         }
14593
14594         buff = open_file(res->filepath, &size);
14595         if (!buff)
14596                 return;
14597
14598 #ifdef RTE_NET_I40E
14599         if (ret == -ENOTSUP)
14600                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14601                                                buff, size,
14602                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14603 #endif
14604
14605         if (ret == -EACCES)
14606                 fprintf(stderr, "Profile does not exist.\n");
14607         else if (ret < 0)
14608                 fprintf(stderr, "Failed to delete profile.\n");
14609
14610         close_file(buff);
14611 }
14612
14613 cmdline_parse_inst_t cmd_ddp_del = {
14614         .f = cmd_ddp_del_parsed,
14615         .data = NULL,
14616         .help_str = "ddp del <port_id> <backup_profile_path>",
14617         .tokens = {
14618                 (void *)&cmd_ddp_del_ddp,
14619                 (void *)&cmd_ddp_del_del,
14620                 (void *)&cmd_ddp_del_port_id,
14621                 (void *)&cmd_ddp_del_filepath,
14622                 NULL,
14623         },
14624 };
14625
14626 /* Get dynamic device personalization profile info */
14627 struct cmd_ddp_info_result {
14628         cmdline_fixed_string_t ddp;
14629         cmdline_fixed_string_t get;
14630         cmdline_fixed_string_t info;
14631         char filepath[];
14632 };
14633
14634 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14635         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14636 cmdline_parse_token_string_t cmd_ddp_info_get =
14637         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14638 cmdline_parse_token_string_t cmd_ddp_info_info =
14639         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14640 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14641         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14642
14643 static void
14644 cmd_ddp_info_parsed(
14645         void *parsed_result,
14646         __rte_unused struct cmdline *cl,
14647         __rte_unused void *data)
14648 {
14649         struct cmd_ddp_info_result *res = parsed_result;
14650         uint8_t *pkg;
14651         uint32_t pkg_size;
14652         int ret = -ENOTSUP;
14653 #ifdef RTE_NET_I40E
14654         uint32_t i, j, n;
14655         uint8_t *buff;
14656         uint32_t buff_size = 0;
14657         struct rte_pmd_i40e_profile_info info;
14658         uint32_t dev_num = 0;
14659         struct rte_pmd_i40e_ddp_device_id *devs;
14660         uint32_t proto_num = 0;
14661         struct rte_pmd_i40e_proto_info *proto = NULL;
14662         uint32_t pctype_num = 0;
14663         struct rte_pmd_i40e_ptype_info *pctype;
14664         uint32_t ptype_num = 0;
14665         struct rte_pmd_i40e_ptype_info *ptype;
14666         uint8_t proto_id;
14667
14668 #endif
14669
14670         pkg = open_file(res->filepath, &pkg_size);
14671         if (!pkg)
14672                 return;
14673
14674 #ifdef RTE_NET_I40E
14675         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14676                                 (uint8_t *)&info, sizeof(info),
14677                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14678         if (!ret) {
14679                 printf("Global Track id:       0x%x\n", info.track_id);
14680                 printf("Global Version:        %d.%d.%d.%d\n",
14681                         info.version.major,
14682                         info.version.minor,
14683                         info.version.update,
14684                         info.version.draft);
14685                 printf("Global Package name:   %s\n\n", info.name);
14686         }
14687
14688         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14689                                 (uint8_t *)&info, sizeof(info),
14690                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14691         if (!ret) {
14692                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14693                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14694                         info.version.major,
14695                         info.version.minor,
14696                         info.version.update,
14697                         info.version.draft);
14698                 printf("i40e Profile name:     %s\n\n", info.name);
14699         }
14700
14701         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14702                                 (uint8_t *)&buff_size, sizeof(buff_size),
14703                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14704         if (!ret && buff_size) {
14705                 buff = (uint8_t *)malloc(buff_size);
14706                 if (buff) {
14707                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14708                                                 buff, buff_size,
14709                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14710                         if (!ret)
14711                                 printf("Package Notes:\n%s\n\n", buff);
14712                         free(buff);
14713                 }
14714         }
14715
14716         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14717                                 (uint8_t *)&dev_num, sizeof(dev_num),
14718                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14719         if (!ret && dev_num) {
14720                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14721                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14722                 if (devs) {
14723                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14724                                                 (uint8_t *)devs, buff_size,
14725                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14726                         if (!ret) {
14727                                 printf("List of supported devices:\n");
14728                                 for (i = 0; i < dev_num; i++) {
14729                                         printf("  %04X:%04X %04X:%04X\n",
14730                                                 devs[i].vendor_dev_id >> 16,
14731                                                 devs[i].vendor_dev_id & 0xFFFF,
14732                                                 devs[i].sub_vendor_dev_id >> 16,
14733                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14734                                 }
14735                                 printf("\n");
14736                         }
14737                         free(devs);
14738                 }
14739         }
14740
14741         /* get information about protocols and packet types */
14742         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14743                 (uint8_t *)&proto_num, sizeof(proto_num),
14744                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14745         if (ret || !proto_num)
14746                 goto no_print_return;
14747
14748         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14749         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14750         if (!proto)
14751                 goto no_print_return;
14752
14753         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14754                                         buff_size,
14755                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14756         if (!ret) {
14757                 printf("List of used protocols:\n");
14758                 for (i = 0; i < proto_num; i++)
14759                         printf("  %2u: %s\n", proto[i].proto_id,
14760                                proto[i].name);
14761                 printf("\n");
14762         }
14763         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14764                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14765                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14766         if (ret || !pctype_num)
14767                 goto no_print_pctypes;
14768
14769         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14770         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14771         if (!pctype)
14772                 goto no_print_pctypes;
14773
14774         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14775                                         buff_size,
14776                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14777         if (ret) {
14778                 free(pctype);
14779                 goto no_print_pctypes;
14780         }
14781
14782         printf("List of defined packet classification types:\n");
14783         for (i = 0; i < pctype_num; i++) {
14784                 printf("  %2u:", pctype[i].ptype_id);
14785                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14786                         proto_id = pctype[i].protocols[j];
14787                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14788                                 for (n = 0; n < proto_num; n++) {
14789                                         if (proto[n].proto_id == proto_id) {
14790                                                 printf(" %s", proto[n].name);
14791                                                 break;
14792                                         }
14793                                 }
14794                         }
14795                 }
14796                 printf("\n");
14797         }
14798         printf("\n");
14799         free(pctype);
14800
14801 no_print_pctypes:
14802
14803         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14804                                         sizeof(ptype_num),
14805                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14806         if (ret || !ptype_num)
14807                 goto no_print_return;
14808
14809         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14810         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14811         if (!ptype)
14812                 goto no_print_return;
14813
14814         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14815                                         buff_size,
14816                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14817         if (ret) {
14818                 free(ptype);
14819                 goto no_print_return;
14820         }
14821         printf("List of defined packet types:\n");
14822         for (i = 0; i < ptype_num; i++) {
14823                 printf("  %2u:", ptype[i].ptype_id);
14824                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14825                         proto_id = ptype[i].protocols[j];
14826                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14827                                 for (n = 0; n < proto_num; n++) {
14828                                         if (proto[n].proto_id == proto_id) {
14829                                                 printf(" %s", proto[n].name);
14830                                                 break;
14831                                         }
14832                                 }
14833                         }
14834                 }
14835                 printf("\n");
14836         }
14837         free(ptype);
14838         printf("\n");
14839
14840         ret = 0;
14841 no_print_return:
14842         free(proto);
14843 #endif
14844         if (ret == -ENOTSUP)
14845                 fprintf(stderr, "Function not supported in PMD\n");
14846         close_file(pkg);
14847 }
14848
14849 cmdline_parse_inst_t cmd_ddp_get_info = {
14850         .f = cmd_ddp_info_parsed,
14851         .data = NULL,
14852         .help_str = "ddp get info <profile_path>",
14853         .tokens = {
14854                 (void *)&cmd_ddp_info_ddp,
14855                 (void *)&cmd_ddp_info_get,
14856                 (void *)&cmd_ddp_info_info,
14857                 (void *)&cmd_ddp_info_filepath,
14858                 NULL,
14859         },
14860 };
14861
14862 /* Get dynamic device personalization profile info list*/
14863 #define PROFILE_INFO_SIZE 48
14864 #define MAX_PROFILE_NUM 16
14865
14866 struct cmd_ddp_get_list_result {
14867         cmdline_fixed_string_t ddp;
14868         cmdline_fixed_string_t get;
14869         cmdline_fixed_string_t list;
14870         portid_t port_id;
14871 };
14872
14873 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14874         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14875 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14876         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14877 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14878         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14879 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14880         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14881                 RTE_UINT16);
14882
14883 static void
14884 cmd_ddp_get_list_parsed(
14885         __rte_unused void *parsed_result,
14886         __rte_unused struct cmdline *cl,
14887         __rte_unused void *data)
14888 {
14889 #ifdef RTE_NET_I40E
14890         struct cmd_ddp_get_list_result *res = parsed_result;
14891         struct rte_pmd_i40e_profile_list *p_list;
14892         struct rte_pmd_i40e_profile_info *p_info;
14893         uint32_t p_num;
14894         uint32_t size;
14895         uint32_t i;
14896 #endif
14897         int ret = -ENOTSUP;
14898
14899 #ifdef RTE_NET_I40E
14900         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14901         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14902         if (!p_list) {
14903                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14904                 return;
14905         }
14906
14907         if (ret == -ENOTSUP)
14908                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14909                                                 (uint8_t *)p_list, size);
14910
14911         if (!ret) {
14912                 p_num = p_list->p_count;
14913                 printf("Profile number is: %d\n\n", p_num);
14914
14915                 for (i = 0; i < p_num; i++) {
14916                         p_info = &p_list->p_info[i];
14917                         printf("Profile %d:\n", i);
14918                         printf("Track id:     0x%x\n", p_info->track_id);
14919                         printf("Version:      %d.%d.%d.%d\n",
14920                                p_info->version.major,
14921                                p_info->version.minor,
14922                                p_info->version.update,
14923                                p_info->version.draft);
14924                         printf("Profile name: %s\n\n", p_info->name);
14925                 }
14926         }
14927
14928         free(p_list);
14929 #endif
14930
14931         if (ret < 0)
14932                 fprintf(stderr, "Failed to get ddp list\n");
14933 }
14934
14935 cmdline_parse_inst_t cmd_ddp_get_list = {
14936         .f = cmd_ddp_get_list_parsed,
14937         .data = NULL,
14938         .help_str = "ddp get list <port_id>",
14939         .tokens = {
14940                 (void *)&cmd_ddp_get_list_ddp,
14941                 (void *)&cmd_ddp_get_list_get,
14942                 (void *)&cmd_ddp_get_list_list,
14943                 (void *)&cmd_ddp_get_list_port_id,
14944                 NULL,
14945         },
14946 };
14947
14948 /* Configure input set */
14949 struct cmd_cfg_input_set_result {
14950         cmdline_fixed_string_t port;
14951         cmdline_fixed_string_t cfg;
14952         portid_t port_id;
14953         cmdline_fixed_string_t pctype;
14954         uint8_t pctype_id;
14955         cmdline_fixed_string_t inset_type;
14956         cmdline_fixed_string_t opt;
14957         cmdline_fixed_string_t field;
14958         uint8_t field_idx;
14959 };
14960
14961 static void
14962 cmd_cfg_input_set_parsed(
14963         __rte_unused void *parsed_result,
14964         __rte_unused struct cmdline *cl,
14965         __rte_unused void *data)
14966 {
14967 #ifdef RTE_NET_I40E
14968         struct cmd_cfg_input_set_result *res = parsed_result;
14969         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14970         struct rte_pmd_i40e_inset inset;
14971 #endif
14972         int ret = -ENOTSUP;
14973
14974         if (!all_ports_stopped()) {
14975                 fprintf(stderr, "Please stop all ports first\n");
14976                 return;
14977         }
14978
14979 #ifdef RTE_NET_I40E
14980         if (!strcmp(res->inset_type, "hash_inset"))
14981                 inset_type = INSET_HASH;
14982         else if (!strcmp(res->inset_type, "fdir_inset"))
14983                 inset_type = INSET_FDIR;
14984         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14985                 inset_type = INSET_FDIR_FLX;
14986         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14987                                      &inset, inset_type);
14988         if (ret) {
14989                 fprintf(stderr, "Failed to get input set.\n");
14990                 return;
14991         }
14992
14993         if (!strcmp(res->opt, "get")) {
14994                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14995                                                    res->field_idx);
14996                 if (ret)
14997                         printf("Field index %d is enabled.\n", res->field_idx);
14998                 else
14999                         printf("Field index %d is disabled.\n", res->field_idx);
15000                 return;
15001         } else if (!strcmp(res->opt, "set"))
15002                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15003                                                    res->field_idx);
15004         else if (!strcmp(res->opt, "clear"))
15005                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15006                                                      res->field_idx);
15007         if (ret) {
15008                 fprintf(stderr, "Failed to configure input set field.\n");
15009                 return;
15010         }
15011
15012         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15013                                      &inset, inset_type);
15014         if (ret) {
15015                 fprintf(stderr, "Failed to set input set.\n");
15016                 return;
15017         }
15018 #endif
15019
15020         if (ret == -ENOTSUP)
15021                 fprintf(stderr, "Function not supported\n");
15022 }
15023
15024 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15025         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15026                                  port, "port");
15027 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15028         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15029                                  cfg, "config");
15030 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15031         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15032                               port_id, RTE_UINT16);
15033 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15034         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15035                                  pctype, "pctype");
15036 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15037         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15038                               pctype_id, RTE_UINT8);
15039 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15040         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15041                                  inset_type,
15042                                  "hash_inset#fdir_inset#fdir_flx_inset");
15043 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15044         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15045                                  opt, "get#set#clear");
15046 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15047         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15048                                  field, "field");
15049 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15050         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15051                               field_idx, RTE_UINT8);
15052
15053 cmdline_parse_inst_t cmd_cfg_input_set = {
15054         .f = cmd_cfg_input_set_parsed,
15055         .data = NULL,
15056         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15057                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15058         .tokens = {
15059                 (void *)&cmd_cfg_input_set_port,
15060                 (void *)&cmd_cfg_input_set_cfg,
15061                 (void *)&cmd_cfg_input_set_port_id,
15062                 (void *)&cmd_cfg_input_set_pctype,
15063                 (void *)&cmd_cfg_input_set_pctype_id,
15064                 (void *)&cmd_cfg_input_set_inset_type,
15065                 (void *)&cmd_cfg_input_set_opt,
15066                 (void *)&cmd_cfg_input_set_field,
15067                 (void *)&cmd_cfg_input_set_field_idx,
15068                 NULL,
15069         },
15070 };
15071
15072 /* Clear input set */
15073 struct cmd_clear_input_set_result {
15074         cmdline_fixed_string_t port;
15075         cmdline_fixed_string_t cfg;
15076         portid_t port_id;
15077         cmdline_fixed_string_t pctype;
15078         uint8_t pctype_id;
15079         cmdline_fixed_string_t inset_type;
15080         cmdline_fixed_string_t clear;
15081         cmdline_fixed_string_t all;
15082 };
15083
15084 static void
15085 cmd_clear_input_set_parsed(
15086         __rte_unused void *parsed_result,
15087         __rte_unused struct cmdline *cl,
15088         __rte_unused void *data)
15089 {
15090 #ifdef RTE_NET_I40E
15091         struct cmd_clear_input_set_result *res = parsed_result;
15092         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15093         struct rte_pmd_i40e_inset inset;
15094 #endif
15095         int ret = -ENOTSUP;
15096
15097         if (!all_ports_stopped()) {
15098                 fprintf(stderr, "Please stop all ports first\n");
15099                 return;
15100         }
15101
15102 #ifdef RTE_NET_I40E
15103         if (!strcmp(res->inset_type, "hash_inset"))
15104                 inset_type = INSET_HASH;
15105         else if (!strcmp(res->inset_type, "fdir_inset"))
15106                 inset_type = INSET_FDIR;
15107         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15108                 inset_type = INSET_FDIR_FLX;
15109
15110         memset(&inset, 0, sizeof(inset));
15111
15112         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15113                                      &inset, inset_type);
15114         if (ret) {
15115                 fprintf(stderr, "Failed to clear input set.\n");
15116                 return;
15117         }
15118
15119 #endif
15120
15121         if (ret == -ENOTSUP)
15122                 fprintf(stderr, "Function not supported\n");
15123 }
15124
15125 cmdline_parse_token_string_t cmd_clear_input_set_port =
15126         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15127                                  port, "port");
15128 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15129         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15130                                  cfg, "config");
15131 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15132         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15133                               port_id, RTE_UINT16);
15134 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15135         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15136                                  pctype, "pctype");
15137 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15138         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15139                               pctype_id, RTE_UINT8);
15140 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15141         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15142                                  inset_type,
15143                                  "hash_inset#fdir_inset#fdir_flx_inset");
15144 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15145         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15146                                  clear, "clear");
15147 cmdline_parse_token_string_t cmd_clear_input_set_all =
15148         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15149                                  all, "all");
15150
15151 cmdline_parse_inst_t cmd_clear_input_set = {
15152         .f = cmd_clear_input_set_parsed,
15153         .data = NULL,
15154         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15155                     "fdir_inset|fdir_flx_inset clear all",
15156         .tokens = {
15157                 (void *)&cmd_clear_input_set_port,
15158                 (void *)&cmd_clear_input_set_cfg,
15159                 (void *)&cmd_clear_input_set_port_id,
15160                 (void *)&cmd_clear_input_set_pctype,
15161                 (void *)&cmd_clear_input_set_pctype_id,
15162                 (void *)&cmd_clear_input_set_inset_type,
15163                 (void *)&cmd_clear_input_set_clear,
15164                 (void *)&cmd_clear_input_set_all,
15165                 NULL,
15166         },
15167 };
15168
15169 /* show vf stats */
15170
15171 /* Common result structure for show vf stats */
15172 struct cmd_show_vf_stats_result {
15173         cmdline_fixed_string_t show;
15174         cmdline_fixed_string_t vf;
15175         cmdline_fixed_string_t stats;
15176         portid_t port_id;
15177         uint16_t vf_id;
15178 };
15179
15180 /* Common CLI fields show vf stats*/
15181 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15182         TOKEN_STRING_INITIALIZER
15183                 (struct cmd_show_vf_stats_result,
15184                  show, "show");
15185 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15186         TOKEN_STRING_INITIALIZER
15187                 (struct cmd_show_vf_stats_result,
15188                  vf, "vf");
15189 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15190         TOKEN_STRING_INITIALIZER
15191                 (struct cmd_show_vf_stats_result,
15192                  stats, "stats");
15193 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15194         TOKEN_NUM_INITIALIZER
15195                 (struct cmd_show_vf_stats_result,
15196                  port_id, RTE_UINT16);
15197 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15198         TOKEN_NUM_INITIALIZER
15199                 (struct cmd_show_vf_stats_result,
15200                  vf_id, RTE_UINT16);
15201
15202 static void
15203 cmd_show_vf_stats_parsed(
15204         void *parsed_result,
15205         __rte_unused struct cmdline *cl,
15206         __rte_unused void *data)
15207 {
15208         struct cmd_show_vf_stats_result *res = parsed_result;
15209         struct rte_eth_stats stats;
15210         int ret = -ENOTSUP;
15211         static const char *nic_stats_border = "########################";
15212
15213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15214                 return;
15215
15216         memset(&stats, 0, sizeof(stats));
15217
15218 #ifdef RTE_NET_I40E
15219         if (ret == -ENOTSUP)
15220                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15221                                                 res->vf_id,
15222                                                 &stats);
15223 #endif
15224 #ifdef RTE_NET_BNXT
15225         if (ret == -ENOTSUP)
15226                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15227                                                 res->vf_id,
15228                                                 &stats);
15229 #endif
15230
15231         switch (ret) {
15232         case 0:
15233                 break;
15234         case -EINVAL:
15235                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15236                 break;
15237         case -ENODEV:
15238                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15239                 break;
15240         case -ENOTSUP:
15241                 fprintf(stderr, "function not implemented\n");
15242                 break;
15243         default:
15244                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15245         }
15246
15247         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15248                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15249
15250         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15251                "%-"PRIu64"\n",
15252                stats.ipackets, stats.imissed, stats.ibytes);
15253         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15254         printf("  RX-nombuf:  %-10"PRIu64"\n",
15255                stats.rx_nombuf);
15256         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15257                "%-"PRIu64"\n",
15258                stats.opackets, stats.oerrors, stats.obytes);
15259
15260         printf("  %s############################%s\n",
15261                                nic_stats_border, nic_stats_border);
15262 }
15263
15264 cmdline_parse_inst_t cmd_show_vf_stats = {
15265         .f = cmd_show_vf_stats_parsed,
15266         .data = NULL,
15267         .help_str = "show vf stats <port_id> <vf_id>",
15268         .tokens = {
15269                 (void *)&cmd_show_vf_stats_show,
15270                 (void *)&cmd_show_vf_stats_vf,
15271                 (void *)&cmd_show_vf_stats_stats,
15272                 (void *)&cmd_show_vf_stats_port_id,
15273                 (void *)&cmd_show_vf_stats_vf_id,
15274                 NULL,
15275         },
15276 };
15277
15278 /* clear vf stats */
15279
15280 /* Common result structure for clear vf stats */
15281 struct cmd_clear_vf_stats_result {
15282         cmdline_fixed_string_t clear;
15283         cmdline_fixed_string_t vf;
15284         cmdline_fixed_string_t stats;
15285         portid_t port_id;
15286         uint16_t vf_id;
15287 };
15288
15289 /* Common CLI fields clear vf stats*/
15290 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15291         TOKEN_STRING_INITIALIZER
15292                 (struct cmd_clear_vf_stats_result,
15293                  clear, "clear");
15294 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15295         TOKEN_STRING_INITIALIZER
15296                 (struct cmd_clear_vf_stats_result,
15297                  vf, "vf");
15298 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15299         TOKEN_STRING_INITIALIZER
15300                 (struct cmd_clear_vf_stats_result,
15301                  stats, "stats");
15302 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15303         TOKEN_NUM_INITIALIZER
15304                 (struct cmd_clear_vf_stats_result,
15305                  port_id, RTE_UINT16);
15306 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15307         TOKEN_NUM_INITIALIZER
15308                 (struct cmd_clear_vf_stats_result,
15309                  vf_id, RTE_UINT16);
15310
15311 static void
15312 cmd_clear_vf_stats_parsed(
15313         void *parsed_result,
15314         __rte_unused struct cmdline *cl,
15315         __rte_unused void *data)
15316 {
15317         struct cmd_clear_vf_stats_result *res = parsed_result;
15318         int ret = -ENOTSUP;
15319
15320         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15321                 return;
15322
15323 #ifdef RTE_NET_I40E
15324         if (ret == -ENOTSUP)
15325                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15326                                                   res->vf_id);
15327 #endif
15328 #ifdef RTE_NET_BNXT
15329         if (ret == -ENOTSUP)
15330                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15331                                                   res->vf_id);
15332 #endif
15333
15334         switch (ret) {
15335         case 0:
15336                 break;
15337         case -EINVAL:
15338                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15339                 break;
15340         case -ENODEV:
15341                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15342                 break;
15343         case -ENOTSUP:
15344                 fprintf(stderr, "function not implemented\n");
15345                 break;
15346         default:
15347                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15348         }
15349 }
15350
15351 cmdline_parse_inst_t cmd_clear_vf_stats = {
15352         .f = cmd_clear_vf_stats_parsed,
15353         .data = NULL,
15354         .help_str = "clear vf stats <port_id> <vf_id>",
15355         .tokens = {
15356                 (void *)&cmd_clear_vf_stats_clear,
15357                 (void *)&cmd_clear_vf_stats_vf,
15358                 (void *)&cmd_clear_vf_stats_stats,
15359                 (void *)&cmd_clear_vf_stats_port_id,
15360                 (void *)&cmd_clear_vf_stats_vf_id,
15361                 NULL,
15362         },
15363 };
15364
15365 /* port config pctype mapping reset */
15366
15367 /* Common result structure for port config pctype mapping reset */
15368 struct cmd_pctype_mapping_reset_result {
15369         cmdline_fixed_string_t port;
15370         cmdline_fixed_string_t config;
15371         portid_t port_id;
15372         cmdline_fixed_string_t pctype;
15373         cmdline_fixed_string_t mapping;
15374         cmdline_fixed_string_t reset;
15375 };
15376
15377 /* Common CLI fields for port config pctype mapping reset*/
15378 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15379         TOKEN_STRING_INITIALIZER
15380                 (struct cmd_pctype_mapping_reset_result,
15381                  port, "port");
15382 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15383         TOKEN_STRING_INITIALIZER
15384                 (struct cmd_pctype_mapping_reset_result,
15385                  config, "config");
15386 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15387         TOKEN_NUM_INITIALIZER
15388                 (struct cmd_pctype_mapping_reset_result,
15389                  port_id, RTE_UINT16);
15390 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15391         TOKEN_STRING_INITIALIZER
15392                 (struct cmd_pctype_mapping_reset_result,
15393                  pctype, "pctype");
15394 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15395         TOKEN_STRING_INITIALIZER
15396                 (struct cmd_pctype_mapping_reset_result,
15397                  mapping, "mapping");
15398 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15399         TOKEN_STRING_INITIALIZER
15400                 (struct cmd_pctype_mapping_reset_result,
15401                  reset, "reset");
15402
15403 static void
15404 cmd_pctype_mapping_reset_parsed(
15405         void *parsed_result,
15406         __rte_unused struct cmdline *cl,
15407         __rte_unused void *data)
15408 {
15409         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15410         int ret = -ENOTSUP;
15411
15412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15413                 return;
15414
15415 #ifdef RTE_NET_I40E
15416         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15417 #endif
15418
15419         switch (ret) {
15420         case 0:
15421                 break;
15422         case -ENODEV:
15423                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15424                 break;
15425         case -ENOTSUP:
15426                 fprintf(stderr, "function not implemented\n");
15427                 break;
15428         default:
15429                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15430         }
15431 }
15432
15433 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15434         .f = cmd_pctype_mapping_reset_parsed,
15435         .data = NULL,
15436         .help_str = "port config <port_id> pctype mapping reset",
15437         .tokens = {
15438                 (void *)&cmd_pctype_mapping_reset_port,
15439                 (void *)&cmd_pctype_mapping_reset_config,
15440                 (void *)&cmd_pctype_mapping_reset_port_id,
15441                 (void *)&cmd_pctype_mapping_reset_pctype,
15442                 (void *)&cmd_pctype_mapping_reset_mapping,
15443                 (void *)&cmd_pctype_mapping_reset_reset,
15444                 NULL,
15445         },
15446 };
15447
15448 /* show port pctype mapping */
15449
15450 /* Common result structure for show port pctype mapping */
15451 struct cmd_pctype_mapping_get_result {
15452         cmdline_fixed_string_t show;
15453         cmdline_fixed_string_t port;
15454         portid_t port_id;
15455         cmdline_fixed_string_t pctype;
15456         cmdline_fixed_string_t mapping;
15457 };
15458
15459 /* Common CLI fields for pctype mapping get */
15460 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15461         TOKEN_STRING_INITIALIZER
15462                 (struct cmd_pctype_mapping_get_result,
15463                  show, "show");
15464 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15465         TOKEN_STRING_INITIALIZER
15466                 (struct cmd_pctype_mapping_get_result,
15467                  port, "port");
15468 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15469         TOKEN_NUM_INITIALIZER
15470                 (struct cmd_pctype_mapping_get_result,
15471                  port_id, RTE_UINT16);
15472 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15473         TOKEN_STRING_INITIALIZER
15474                 (struct cmd_pctype_mapping_get_result,
15475                  pctype, "pctype");
15476 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15477         TOKEN_STRING_INITIALIZER
15478                 (struct cmd_pctype_mapping_get_result,
15479                  mapping, "mapping");
15480
15481 static void
15482 cmd_pctype_mapping_get_parsed(
15483         void *parsed_result,
15484         __rte_unused struct cmdline *cl,
15485         __rte_unused void *data)
15486 {
15487         struct cmd_pctype_mapping_get_result *res = parsed_result;
15488         int ret = -ENOTSUP;
15489 #ifdef RTE_NET_I40E
15490         struct rte_pmd_i40e_flow_type_mapping
15491                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15492         int i, j, first_pctype;
15493 #endif
15494
15495         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15496                 return;
15497
15498 #ifdef RTE_NET_I40E
15499         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15500 #endif
15501
15502         switch (ret) {
15503         case 0:
15504                 break;
15505         case -ENODEV:
15506                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15507                 return;
15508         case -ENOTSUP:
15509                 fprintf(stderr, "function not implemented\n");
15510                 return;
15511         default:
15512                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15513                 return;
15514         }
15515
15516 #ifdef RTE_NET_I40E
15517         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15518                 if (mapping[i].pctype != 0ULL) {
15519                         first_pctype = 1;
15520
15521                         printf("pctype: ");
15522                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15523                                 if (mapping[i].pctype & (1ULL << j)) {
15524                                         printf(first_pctype ?
15525                                                "%02d" : ",%02d", j);
15526                                         first_pctype = 0;
15527                                 }
15528                         }
15529                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15530                 }
15531         }
15532 #endif
15533 }
15534
15535 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15536         .f = cmd_pctype_mapping_get_parsed,
15537         .data = NULL,
15538         .help_str = "show port <port_id> pctype mapping",
15539         .tokens = {
15540                 (void *)&cmd_pctype_mapping_get_show,
15541                 (void *)&cmd_pctype_mapping_get_port,
15542                 (void *)&cmd_pctype_mapping_get_port_id,
15543                 (void *)&cmd_pctype_mapping_get_pctype,
15544                 (void *)&cmd_pctype_mapping_get_mapping,
15545                 NULL,
15546         },
15547 };
15548
15549 /* port config pctype mapping update */
15550
15551 /* Common result structure for port config pctype mapping update */
15552 struct cmd_pctype_mapping_update_result {
15553         cmdline_fixed_string_t port;
15554         cmdline_fixed_string_t config;
15555         portid_t port_id;
15556         cmdline_fixed_string_t pctype;
15557         cmdline_fixed_string_t mapping;
15558         cmdline_fixed_string_t update;
15559         cmdline_fixed_string_t pctype_list;
15560         uint16_t flow_type;
15561 };
15562
15563 /* Common CLI fields for pctype mapping update*/
15564 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15565         TOKEN_STRING_INITIALIZER
15566                 (struct cmd_pctype_mapping_update_result,
15567                  port, "port");
15568 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15569         TOKEN_STRING_INITIALIZER
15570                 (struct cmd_pctype_mapping_update_result,
15571                  config, "config");
15572 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15573         TOKEN_NUM_INITIALIZER
15574                 (struct cmd_pctype_mapping_update_result,
15575                  port_id, RTE_UINT16);
15576 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15577         TOKEN_STRING_INITIALIZER
15578                 (struct cmd_pctype_mapping_update_result,
15579                  pctype, "pctype");
15580 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15581         TOKEN_STRING_INITIALIZER
15582                 (struct cmd_pctype_mapping_update_result,
15583                  mapping, "mapping");
15584 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15585         TOKEN_STRING_INITIALIZER
15586                 (struct cmd_pctype_mapping_update_result,
15587                  update, "update");
15588 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15589         TOKEN_STRING_INITIALIZER
15590                 (struct cmd_pctype_mapping_update_result,
15591                  pctype_list, NULL);
15592 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15593         TOKEN_NUM_INITIALIZER
15594                 (struct cmd_pctype_mapping_update_result,
15595                  flow_type, RTE_UINT16);
15596
15597 static void
15598 cmd_pctype_mapping_update_parsed(
15599         void *parsed_result,
15600         __rte_unused struct cmdline *cl,
15601         __rte_unused void *data)
15602 {
15603         struct cmd_pctype_mapping_update_result *res = parsed_result;
15604         int ret = -ENOTSUP;
15605 #ifdef RTE_NET_I40E
15606         struct rte_pmd_i40e_flow_type_mapping mapping;
15607         unsigned int i;
15608         unsigned int nb_item;
15609         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15610 #endif
15611
15612         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15613                 return;
15614
15615 #ifdef RTE_NET_I40E
15616         nb_item = parse_item_list(res->pctype_list, "pctypes",
15617                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15618         mapping.flow_type = res->flow_type;
15619         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15620                 mapping.pctype |= (1ULL << pctype_list[i]);
15621         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15622                                                 &mapping,
15623                                                 1,
15624                                                 0);
15625 #endif
15626
15627         switch (ret) {
15628         case 0:
15629                 break;
15630         case -EINVAL:
15631                 fprintf(stderr, "invalid pctype or flow type\n");
15632                 break;
15633         case -ENODEV:
15634                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15635                 break;
15636         case -ENOTSUP:
15637                 fprintf(stderr, "function not implemented\n");
15638                 break;
15639         default:
15640                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15641         }
15642 }
15643
15644 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15645         .f = cmd_pctype_mapping_update_parsed,
15646         .data = NULL,
15647         .help_str = "port config <port_id> pctype mapping update"
15648         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15649         .tokens = {
15650                 (void *)&cmd_pctype_mapping_update_port,
15651                 (void *)&cmd_pctype_mapping_update_config,
15652                 (void *)&cmd_pctype_mapping_update_port_id,
15653                 (void *)&cmd_pctype_mapping_update_pctype,
15654                 (void *)&cmd_pctype_mapping_update_mapping,
15655                 (void *)&cmd_pctype_mapping_update_update,
15656                 (void *)&cmd_pctype_mapping_update_pc_type,
15657                 (void *)&cmd_pctype_mapping_update_flow_type,
15658                 NULL,
15659         },
15660 };
15661
15662 /* ptype mapping get */
15663
15664 /* Common result structure for ptype mapping get */
15665 struct cmd_ptype_mapping_get_result {
15666         cmdline_fixed_string_t ptype;
15667         cmdline_fixed_string_t mapping;
15668         cmdline_fixed_string_t get;
15669         portid_t port_id;
15670         uint8_t valid_only;
15671 };
15672
15673 /* Common CLI fields for ptype mapping get */
15674 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15675         TOKEN_STRING_INITIALIZER
15676                 (struct cmd_ptype_mapping_get_result,
15677                  ptype, "ptype");
15678 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15679         TOKEN_STRING_INITIALIZER
15680                 (struct cmd_ptype_mapping_get_result,
15681                  mapping, "mapping");
15682 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15683         TOKEN_STRING_INITIALIZER
15684                 (struct cmd_ptype_mapping_get_result,
15685                  get, "get");
15686 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15687         TOKEN_NUM_INITIALIZER
15688                 (struct cmd_ptype_mapping_get_result,
15689                  port_id, RTE_UINT16);
15690 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15691         TOKEN_NUM_INITIALIZER
15692                 (struct cmd_ptype_mapping_get_result,
15693                  valid_only, RTE_UINT8);
15694
15695 static void
15696 cmd_ptype_mapping_get_parsed(
15697         void *parsed_result,
15698         __rte_unused struct cmdline *cl,
15699         __rte_unused void *data)
15700 {
15701         struct cmd_ptype_mapping_get_result *res = parsed_result;
15702         int ret = -ENOTSUP;
15703 #ifdef RTE_NET_I40E
15704         int max_ptype_num = 256;
15705         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15706         uint16_t count;
15707         int i;
15708 #endif
15709
15710         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15711                 return;
15712
15713 #ifdef RTE_NET_I40E
15714         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15715                                         mapping,
15716                                         max_ptype_num,
15717                                         &count,
15718                                         res->valid_only);
15719 #endif
15720
15721         switch (ret) {
15722         case 0:
15723                 break;
15724         case -ENODEV:
15725                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15726                 break;
15727         case -ENOTSUP:
15728                 fprintf(stderr, "function not implemented\n");
15729                 break;
15730         default:
15731                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15732         }
15733
15734 #ifdef RTE_NET_I40E
15735         if (!ret) {
15736                 for (i = 0; i < count; i++)
15737                         printf("%3d\t0x%08x\n",
15738                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15739         }
15740 #endif
15741 }
15742
15743 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15744         .f = cmd_ptype_mapping_get_parsed,
15745         .data = NULL,
15746         .help_str = "ptype mapping get <port_id> <valid_only>",
15747         .tokens = {
15748                 (void *)&cmd_ptype_mapping_get_ptype,
15749                 (void *)&cmd_ptype_mapping_get_mapping,
15750                 (void *)&cmd_ptype_mapping_get_get,
15751                 (void *)&cmd_ptype_mapping_get_port_id,
15752                 (void *)&cmd_ptype_mapping_get_valid_only,
15753                 NULL,
15754         },
15755 };
15756
15757 /* ptype mapping replace */
15758
15759 /* Common result structure for ptype mapping replace */
15760 struct cmd_ptype_mapping_replace_result {
15761         cmdline_fixed_string_t ptype;
15762         cmdline_fixed_string_t mapping;
15763         cmdline_fixed_string_t replace;
15764         portid_t port_id;
15765         uint32_t target;
15766         uint8_t mask;
15767         uint32_t pkt_type;
15768 };
15769
15770 /* Common CLI fields for ptype mapping replace */
15771 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15772         TOKEN_STRING_INITIALIZER
15773                 (struct cmd_ptype_mapping_replace_result,
15774                  ptype, "ptype");
15775 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15776         TOKEN_STRING_INITIALIZER
15777                 (struct cmd_ptype_mapping_replace_result,
15778                  mapping, "mapping");
15779 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15780         TOKEN_STRING_INITIALIZER
15781                 (struct cmd_ptype_mapping_replace_result,
15782                  replace, "replace");
15783 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15784         TOKEN_NUM_INITIALIZER
15785                 (struct cmd_ptype_mapping_replace_result,
15786                  port_id, RTE_UINT16);
15787 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15788         TOKEN_NUM_INITIALIZER
15789                 (struct cmd_ptype_mapping_replace_result,
15790                  target, RTE_UINT32);
15791 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15792         TOKEN_NUM_INITIALIZER
15793                 (struct cmd_ptype_mapping_replace_result,
15794                  mask, RTE_UINT8);
15795 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15796         TOKEN_NUM_INITIALIZER
15797                 (struct cmd_ptype_mapping_replace_result,
15798                  pkt_type, RTE_UINT32);
15799
15800 static void
15801 cmd_ptype_mapping_replace_parsed(
15802         void *parsed_result,
15803         __rte_unused struct cmdline *cl,
15804         __rte_unused void *data)
15805 {
15806         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15807         int ret = -ENOTSUP;
15808
15809         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15810                 return;
15811
15812 #ifdef RTE_NET_I40E
15813         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15814                                         res->target,
15815                                         res->mask,
15816                                         res->pkt_type);
15817 #endif
15818
15819         switch (ret) {
15820         case 0:
15821                 break;
15822         case -EINVAL:
15823                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15824                         res->target, res->pkt_type);
15825                 break;
15826         case -ENODEV:
15827                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15828                 break;
15829         case -ENOTSUP:
15830                 fprintf(stderr, "function not implemented\n");
15831                 break;
15832         default:
15833                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15834         }
15835 }
15836
15837 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15838         .f = cmd_ptype_mapping_replace_parsed,
15839         .data = NULL,
15840         .help_str =
15841                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15842         .tokens = {
15843                 (void *)&cmd_ptype_mapping_replace_ptype,
15844                 (void *)&cmd_ptype_mapping_replace_mapping,
15845                 (void *)&cmd_ptype_mapping_replace_replace,
15846                 (void *)&cmd_ptype_mapping_replace_port_id,
15847                 (void *)&cmd_ptype_mapping_replace_target,
15848                 (void *)&cmd_ptype_mapping_replace_mask,
15849                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15850                 NULL,
15851         },
15852 };
15853
15854 /* ptype mapping reset */
15855
15856 /* Common result structure for ptype mapping reset */
15857 struct cmd_ptype_mapping_reset_result {
15858         cmdline_fixed_string_t ptype;
15859         cmdline_fixed_string_t mapping;
15860         cmdline_fixed_string_t reset;
15861         portid_t port_id;
15862 };
15863
15864 /* Common CLI fields for ptype mapping reset*/
15865 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15866         TOKEN_STRING_INITIALIZER
15867                 (struct cmd_ptype_mapping_reset_result,
15868                  ptype, "ptype");
15869 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15870         TOKEN_STRING_INITIALIZER
15871                 (struct cmd_ptype_mapping_reset_result,
15872                  mapping, "mapping");
15873 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15874         TOKEN_STRING_INITIALIZER
15875                 (struct cmd_ptype_mapping_reset_result,
15876                  reset, "reset");
15877 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15878         TOKEN_NUM_INITIALIZER
15879                 (struct cmd_ptype_mapping_reset_result,
15880                  port_id, RTE_UINT16);
15881
15882 static void
15883 cmd_ptype_mapping_reset_parsed(
15884         void *parsed_result,
15885         __rte_unused struct cmdline *cl,
15886         __rte_unused void *data)
15887 {
15888         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15889         int ret = -ENOTSUP;
15890
15891         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15892                 return;
15893
15894 #ifdef RTE_NET_I40E
15895         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15896 #endif
15897
15898         switch (ret) {
15899         case 0:
15900                 break;
15901         case -ENODEV:
15902                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15903                 break;
15904         case -ENOTSUP:
15905                 fprintf(stderr, "function not implemented\n");
15906                 break;
15907         default:
15908                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15909         }
15910 }
15911
15912 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15913         .f = cmd_ptype_mapping_reset_parsed,
15914         .data = NULL,
15915         .help_str = "ptype mapping reset <port_id>",
15916         .tokens = {
15917                 (void *)&cmd_ptype_mapping_reset_ptype,
15918                 (void *)&cmd_ptype_mapping_reset_mapping,
15919                 (void *)&cmd_ptype_mapping_reset_reset,
15920                 (void *)&cmd_ptype_mapping_reset_port_id,
15921                 NULL,
15922         },
15923 };
15924
15925 /* ptype mapping update */
15926
15927 /* Common result structure for ptype mapping update */
15928 struct cmd_ptype_mapping_update_result {
15929         cmdline_fixed_string_t ptype;
15930         cmdline_fixed_string_t mapping;
15931         cmdline_fixed_string_t reset;
15932         portid_t port_id;
15933         uint8_t hw_ptype;
15934         uint32_t sw_ptype;
15935 };
15936
15937 /* Common CLI fields for ptype mapping update*/
15938 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15939         TOKEN_STRING_INITIALIZER
15940                 (struct cmd_ptype_mapping_update_result,
15941                  ptype, "ptype");
15942 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15943         TOKEN_STRING_INITIALIZER
15944                 (struct cmd_ptype_mapping_update_result,
15945                  mapping, "mapping");
15946 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15947         TOKEN_STRING_INITIALIZER
15948                 (struct cmd_ptype_mapping_update_result,
15949                  reset, "update");
15950 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15951         TOKEN_NUM_INITIALIZER
15952                 (struct cmd_ptype_mapping_update_result,
15953                  port_id, RTE_UINT16);
15954 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15955         TOKEN_NUM_INITIALIZER
15956                 (struct cmd_ptype_mapping_update_result,
15957                  hw_ptype, RTE_UINT8);
15958 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15959         TOKEN_NUM_INITIALIZER
15960                 (struct cmd_ptype_mapping_update_result,
15961                  sw_ptype, RTE_UINT32);
15962
15963 static void
15964 cmd_ptype_mapping_update_parsed(
15965         void *parsed_result,
15966         __rte_unused struct cmdline *cl,
15967         __rte_unused void *data)
15968 {
15969         struct cmd_ptype_mapping_update_result *res = parsed_result;
15970         int ret = -ENOTSUP;
15971 #ifdef RTE_NET_I40E
15972         struct rte_pmd_i40e_ptype_mapping mapping;
15973 #endif
15974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15975                 return;
15976
15977 #ifdef RTE_NET_I40E
15978         mapping.hw_ptype = res->hw_ptype;
15979         mapping.sw_ptype = res->sw_ptype;
15980         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15981                                                 &mapping,
15982                                                 1,
15983                                                 0);
15984 #endif
15985
15986         switch (ret) {
15987         case 0:
15988                 break;
15989         case -EINVAL:
15990                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15991                 break;
15992         case -ENODEV:
15993                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15994                 break;
15995         case -ENOTSUP:
15996                 fprintf(stderr, "function not implemented\n");
15997                 break;
15998         default:
15999                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
16000         }
16001 }
16002
16003 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16004         .f = cmd_ptype_mapping_update_parsed,
16005         .data = NULL,
16006         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16007         .tokens = {
16008                 (void *)&cmd_ptype_mapping_update_ptype,
16009                 (void *)&cmd_ptype_mapping_update_mapping,
16010                 (void *)&cmd_ptype_mapping_update_update,
16011                 (void *)&cmd_ptype_mapping_update_port_id,
16012                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16013                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16014                 NULL,
16015         },
16016 };
16017
16018 /* Common result structure for file commands */
16019 struct cmd_cmdfile_result {
16020         cmdline_fixed_string_t load;
16021         cmdline_fixed_string_t filename;
16022 };
16023
16024 /* Common CLI fields for file commands */
16025 cmdline_parse_token_string_t cmd_load_cmdfile =
16026         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16027 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16028         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16029
16030 static void
16031 cmd_load_from_file_parsed(
16032         void *parsed_result,
16033         __rte_unused struct cmdline *cl,
16034         __rte_unused void *data)
16035 {
16036         struct cmd_cmdfile_result *res = parsed_result;
16037
16038         cmdline_read_from_file(res->filename);
16039 }
16040
16041 cmdline_parse_inst_t cmd_load_from_file = {
16042         .f = cmd_load_from_file_parsed,
16043         .data = NULL,
16044         .help_str = "load <filename>",
16045         .tokens = {
16046                 (void *)&cmd_load_cmdfile,
16047                 (void *)&cmd_load_cmdfile_filename,
16048                 NULL,
16049         },
16050 };
16051
16052 /* Get Rx offloads capabilities */
16053 struct cmd_rx_offload_get_capa_result {
16054         cmdline_fixed_string_t show;
16055         cmdline_fixed_string_t port;
16056         portid_t port_id;
16057         cmdline_fixed_string_t rx_offload;
16058         cmdline_fixed_string_t capabilities;
16059 };
16060
16061 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16062         TOKEN_STRING_INITIALIZER
16063                 (struct cmd_rx_offload_get_capa_result,
16064                  show, "show");
16065 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16066         TOKEN_STRING_INITIALIZER
16067                 (struct cmd_rx_offload_get_capa_result,
16068                  port, "port");
16069 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16070         TOKEN_NUM_INITIALIZER
16071                 (struct cmd_rx_offload_get_capa_result,
16072                  port_id, RTE_UINT16);
16073 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16074         TOKEN_STRING_INITIALIZER
16075                 (struct cmd_rx_offload_get_capa_result,
16076                  rx_offload, "rx_offload");
16077 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16078         TOKEN_STRING_INITIALIZER
16079                 (struct cmd_rx_offload_get_capa_result,
16080                  capabilities, "capabilities");
16081
16082 static void
16083 print_rx_offloads(uint64_t offloads)
16084 {
16085         uint64_t single_offload;
16086         int begin;
16087         int end;
16088         int bit;
16089
16090         if (offloads == 0)
16091                 return;
16092
16093         begin = __builtin_ctzll(offloads);
16094         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16095
16096         single_offload = 1ULL << begin;
16097         for (bit = begin; bit < end; bit++) {
16098                 if (offloads & single_offload)
16099                         printf(" %s",
16100                                rte_eth_dev_rx_offload_name(single_offload));
16101                 single_offload <<= 1;
16102         }
16103 }
16104
16105 static void
16106 cmd_rx_offload_get_capa_parsed(
16107         void *parsed_result,
16108         __rte_unused struct cmdline *cl,
16109         __rte_unused void *data)
16110 {
16111         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16112         struct rte_eth_dev_info dev_info;
16113         portid_t port_id = res->port_id;
16114         uint64_t queue_offloads;
16115         uint64_t port_offloads;
16116         int ret;
16117
16118         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16119         if (ret != 0)
16120                 return;
16121
16122         queue_offloads = dev_info.rx_queue_offload_capa;
16123         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16124
16125         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16126         printf("  Per Queue :");
16127         print_rx_offloads(queue_offloads);
16128
16129         printf("\n");
16130         printf("  Per Port  :");
16131         print_rx_offloads(port_offloads);
16132         printf("\n\n");
16133 }
16134
16135 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16136         .f = cmd_rx_offload_get_capa_parsed,
16137         .data = NULL,
16138         .help_str = "show port <port_id> rx_offload capabilities",
16139         .tokens = {
16140                 (void *)&cmd_rx_offload_get_capa_show,
16141                 (void *)&cmd_rx_offload_get_capa_port,
16142                 (void *)&cmd_rx_offload_get_capa_port_id,
16143                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16144                 (void *)&cmd_rx_offload_get_capa_capabilities,
16145                 NULL,
16146         }
16147 };
16148
16149 /* Get Rx offloads configuration */
16150 struct cmd_rx_offload_get_configuration_result {
16151         cmdline_fixed_string_t show;
16152         cmdline_fixed_string_t port;
16153         portid_t port_id;
16154         cmdline_fixed_string_t rx_offload;
16155         cmdline_fixed_string_t configuration;
16156 };
16157
16158 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16159         TOKEN_STRING_INITIALIZER
16160                 (struct cmd_rx_offload_get_configuration_result,
16161                  show, "show");
16162 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16163         TOKEN_STRING_INITIALIZER
16164                 (struct cmd_rx_offload_get_configuration_result,
16165                  port, "port");
16166 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16167         TOKEN_NUM_INITIALIZER
16168                 (struct cmd_rx_offload_get_configuration_result,
16169                  port_id, RTE_UINT16);
16170 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16171         TOKEN_STRING_INITIALIZER
16172                 (struct cmd_rx_offload_get_configuration_result,
16173                  rx_offload, "rx_offload");
16174 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16175         TOKEN_STRING_INITIALIZER
16176                 (struct cmd_rx_offload_get_configuration_result,
16177                  configuration, "configuration");
16178
16179 static void
16180 cmd_rx_offload_get_configuration_parsed(
16181         void *parsed_result,
16182         __rte_unused struct cmdline *cl,
16183         __rte_unused void *data)
16184 {
16185         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16186         struct rte_eth_dev_info dev_info;
16187         portid_t port_id = res->port_id;
16188         struct rte_port *port = &ports[port_id];
16189         struct rte_eth_conf dev_conf;
16190         uint64_t port_offloads;
16191         uint64_t queue_offloads;
16192         uint16_t nb_rx_queues;
16193         int q;
16194         int ret;
16195
16196         printf("Rx Offloading Configuration of port %d :\n", port_id);
16197
16198         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16199         if (ret != 0)
16200                 return;
16201
16202         port_offloads = dev_conf.rxmode.offloads;
16203         printf("  Port :");
16204         print_rx_offloads(port_offloads);
16205         printf("\n");
16206
16207         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16208         if (ret != 0)
16209                 return;
16210
16211         nb_rx_queues = dev_info.nb_rx_queues;
16212         for (q = 0; q < nb_rx_queues; q++) {
16213                 queue_offloads = port->rxq[q].conf.offloads;
16214                 printf("  Queue[%2d] :", q);
16215                 print_rx_offloads(queue_offloads);
16216                 printf("\n");
16217         }
16218         printf("\n");
16219 }
16220
16221 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16222         .f = cmd_rx_offload_get_configuration_parsed,
16223         .data = NULL,
16224         .help_str = "show port <port_id> rx_offload configuration",
16225         .tokens = {
16226                 (void *)&cmd_rx_offload_get_configuration_show,
16227                 (void *)&cmd_rx_offload_get_configuration_port,
16228                 (void *)&cmd_rx_offload_get_configuration_port_id,
16229                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16230                 (void *)&cmd_rx_offload_get_configuration_configuration,
16231                 NULL,
16232         }
16233 };
16234
16235 /* Enable/Disable a per port offloading */
16236 struct cmd_config_per_port_rx_offload_result {
16237         cmdline_fixed_string_t port;
16238         cmdline_fixed_string_t config;
16239         portid_t port_id;
16240         cmdline_fixed_string_t rx_offload;
16241         cmdline_fixed_string_t offload;
16242         cmdline_fixed_string_t on_off;
16243 };
16244
16245 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16246         TOKEN_STRING_INITIALIZER
16247                 (struct cmd_config_per_port_rx_offload_result,
16248                  port, "port");
16249 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16250         TOKEN_STRING_INITIALIZER
16251                 (struct cmd_config_per_port_rx_offload_result,
16252                  config, "config");
16253 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16254         TOKEN_NUM_INITIALIZER
16255                 (struct cmd_config_per_port_rx_offload_result,
16256                  port_id, RTE_UINT16);
16257 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16258         TOKEN_STRING_INITIALIZER
16259                 (struct cmd_config_per_port_rx_offload_result,
16260                  rx_offload, "rx_offload");
16261 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16262         TOKEN_STRING_INITIALIZER
16263                 (struct cmd_config_per_port_rx_offload_result,
16264                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16265                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16266                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16267                            "scatter#buffer_split#timestamp#security#"
16268                            "keep_crc#rss_hash");
16269 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16270         TOKEN_STRING_INITIALIZER
16271                 (struct cmd_config_per_port_rx_offload_result,
16272                  on_off, "on#off");
16273
16274 static uint64_t
16275 search_rx_offload(const char *name)
16276 {
16277         uint64_t single_offload;
16278         const char *single_name;
16279         int found = 0;
16280         unsigned int bit;
16281
16282         single_offload = 1;
16283         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16284                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16285                 if (!strcasecmp(single_name, name)) {
16286                         found = 1;
16287                         break;
16288                 }
16289                 single_offload <<= 1;
16290         }
16291
16292         if (found)
16293                 return single_offload;
16294
16295         return 0;
16296 }
16297
16298 static void
16299 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16300                                 __rte_unused struct cmdline *cl,
16301                                 __rte_unused void *data)
16302 {
16303         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16304         portid_t port_id = res->port_id;
16305         struct rte_eth_dev_info dev_info;
16306         struct rte_port *port = &ports[port_id];
16307         uint64_t single_offload;
16308         uint16_t nb_rx_queues;
16309         int q;
16310         int ret;
16311
16312         if (port->port_status != RTE_PORT_STOPPED) {
16313                 fprintf(stderr,
16314                         "Error: Can't config offload when Port %d is not stopped\n",
16315                         port_id);
16316                 return;
16317         }
16318
16319         single_offload = search_rx_offload(res->offload);
16320         if (single_offload == 0) {
16321                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16322                 return;
16323         }
16324
16325         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16326         if (ret != 0)
16327                 return;
16328
16329         nb_rx_queues = dev_info.nb_rx_queues;
16330         if (!strcmp(res->on_off, "on")) {
16331                 port->dev_conf.rxmode.offloads |= single_offload;
16332                 for (q = 0; q < nb_rx_queues; q++)
16333                         port->rxq[q].conf.offloads |= single_offload;
16334         } else {
16335                 port->dev_conf.rxmode.offloads &= ~single_offload;
16336                 for (q = 0; q < nb_rx_queues; q++)
16337                         port->rxq[q].conf.offloads &= ~single_offload;
16338         }
16339
16340         cmd_reconfig_device_queue(port_id, 1, 1);
16341 }
16342
16343 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16344         .f = cmd_config_per_port_rx_offload_parsed,
16345         .data = NULL,
16346         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16347                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16348                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16349                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16350                     "keep_crc|rss_hash on|off",
16351         .tokens = {
16352                 (void *)&cmd_config_per_port_rx_offload_result_port,
16353                 (void *)&cmd_config_per_port_rx_offload_result_config,
16354                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16355                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16356                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16357                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16358                 NULL,
16359         }
16360 };
16361
16362 /* Enable/Disable a per queue offloading */
16363 struct cmd_config_per_queue_rx_offload_result {
16364         cmdline_fixed_string_t port;
16365         portid_t port_id;
16366         cmdline_fixed_string_t rxq;
16367         uint16_t queue_id;
16368         cmdline_fixed_string_t rx_offload;
16369         cmdline_fixed_string_t offload;
16370         cmdline_fixed_string_t on_off;
16371 };
16372
16373 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16374         TOKEN_STRING_INITIALIZER
16375                 (struct cmd_config_per_queue_rx_offload_result,
16376                  port, "port");
16377 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16378         TOKEN_NUM_INITIALIZER
16379                 (struct cmd_config_per_queue_rx_offload_result,
16380                  port_id, RTE_UINT16);
16381 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16382         TOKEN_STRING_INITIALIZER
16383                 (struct cmd_config_per_queue_rx_offload_result,
16384                  rxq, "rxq");
16385 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16386         TOKEN_NUM_INITIALIZER
16387                 (struct cmd_config_per_queue_rx_offload_result,
16388                  queue_id, RTE_UINT16);
16389 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16390         TOKEN_STRING_INITIALIZER
16391                 (struct cmd_config_per_queue_rx_offload_result,
16392                  rx_offload, "rx_offload");
16393 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16394         TOKEN_STRING_INITIALIZER
16395                 (struct cmd_config_per_queue_rx_offload_result,
16396                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16397                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16398                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16399                            "scatter#buffer_split#timestamp#security#keep_crc");
16400 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16401         TOKEN_STRING_INITIALIZER
16402                 (struct cmd_config_per_queue_rx_offload_result,
16403                  on_off, "on#off");
16404
16405 static void
16406 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16407                                 __rte_unused struct cmdline *cl,
16408                                 __rte_unused void *data)
16409 {
16410         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16411         struct rte_eth_dev_info dev_info;
16412         portid_t port_id = res->port_id;
16413         uint16_t queue_id = res->queue_id;
16414         struct rte_port *port = &ports[port_id];
16415         uint64_t single_offload;
16416         int ret;
16417
16418         if (port->port_status != RTE_PORT_STOPPED) {
16419                 fprintf(stderr,
16420                         "Error: Can't config offload when Port %d is not stopped\n",
16421                         port_id);
16422                 return;
16423         }
16424
16425         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16426         if (ret != 0)
16427                 return;
16428
16429         if (queue_id >= dev_info.nb_rx_queues) {
16430                 fprintf(stderr,
16431                         "Error: input queue_id should be 0 ... %d\n",
16432                         dev_info.nb_rx_queues - 1);
16433                 return;
16434         }
16435
16436         single_offload = search_rx_offload(res->offload);
16437         if (single_offload == 0) {
16438                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16439                 return;
16440         }
16441
16442         if (!strcmp(res->on_off, "on"))
16443                 port->rxq[queue_id].conf.offloads |= single_offload;
16444         else
16445                 port->rxq[queue_id].conf.offloads &= ~single_offload;
16446
16447         cmd_reconfig_device_queue(port_id, 1, 1);
16448 }
16449
16450 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16451         .f = cmd_config_per_queue_rx_offload_parsed,
16452         .data = NULL,
16453         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16454                     "vlan_strip|ipv4_cksum|"
16455                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16456                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16457                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16458                     "keep_crc on|off",
16459         .tokens = {
16460                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16461                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16462                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16463                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16464                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16465                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16466                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16467                 NULL,
16468         }
16469 };
16470
16471 /* Get Tx offloads capabilities */
16472 struct cmd_tx_offload_get_capa_result {
16473         cmdline_fixed_string_t show;
16474         cmdline_fixed_string_t port;
16475         portid_t port_id;
16476         cmdline_fixed_string_t tx_offload;
16477         cmdline_fixed_string_t capabilities;
16478 };
16479
16480 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16481         TOKEN_STRING_INITIALIZER
16482                 (struct cmd_tx_offload_get_capa_result,
16483                  show, "show");
16484 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16485         TOKEN_STRING_INITIALIZER
16486                 (struct cmd_tx_offload_get_capa_result,
16487                  port, "port");
16488 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16489         TOKEN_NUM_INITIALIZER
16490                 (struct cmd_tx_offload_get_capa_result,
16491                  port_id, RTE_UINT16);
16492 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16493         TOKEN_STRING_INITIALIZER
16494                 (struct cmd_tx_offload_get_capa_result,
16495                  tx_offload, "tx_offload");
16496 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16497         TOKEN_STRING_INITIALIZER
16498                 (struct cmd_tx_offload_get_capa_result,
16499                  capabilities, "capabilities");
16500
16501 static void
16502 print_tx_offloads(uint64_t offloads)
16503 {
16504         uint64_t single_offload;
16505         int begin;
16506         int end;
16507         int bit;
16508
16509         if (offloads == 0)
16510                 return;
16511
16512         begin = __builtin_ctzll(offloads);
16513         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16514
16515         single_offload = 1ULL << begin;
16516         for (bit = begin; bit < end; bit++) {
16517                 if (offloads & single_offload)
16518                         printf(" %s",
16519                                rte_eth_dev_tx_offload_name(single_offload));
16520                 single_offload <<= 1;
16521         }
16522 }
16523
16524 static void
16525 cmd_tx_offload_get_capa_parsed(
16526         void *parsed_result,
16527         __rte_unused struct cmdline *cl,
16528         __rte_unused void *data)
16529 {
16530         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16531         struct rte_eth_dev_info dev_info;
16532         portid_t port_id = res->port_id;
16533         uint64_t queue_offloads;
16534         uint64_t port_offloads;
16535         int ret;
16536
16537         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16538         if (ret != 0)
16539                 return;
16540
16541         queue_offloads = dev_info.tx_queue_offload_capa;
16542         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16543
16544         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16545         printf("  Per Queue :");
16546         print_tx_offloads(queue_offloads);
16547
16548         printf("\n");
16549         printf("  Per Port  :");
16550         print_tx_offloads(port_offloads);
16551         printf("\n\n");
16552 }
16553
16554 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16555         .f = cmd_tx_offload_get_capa_parsed,
16556         .data = NULL,
16557         .help_str = "show port <port_id> tx_offload capabilities",
16558         .tokens = {
16559                 (void *)&cmd_tx_offload_get_capa_show,
16560                 (void *)&cmd_tx_offload_get_capa_port,
16561                 (void *)&cmd_tx_offload_get_capa_port_id,
16562                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16563                 (void *)&cmd_tx_offload_get_capa_capabilities,
16564                 NULL,
16565         }
16566 };
16567
16568 /* Get Tx offloads configuration */
16569 struct cmd_tx_offload_get_configuration_result {
16570         cmdline_fixed_string_t show;
16571         cmdline_fixed_string_t port;
16572         portid_t port_id;
16573         cmdline_fixed_string_t tx_offload;
16574         cmdline_fixed_string_t configuration;
16575 };
16576
16577 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16578         TOKEN_STRING_INITIALIZER
16579                 (struct cmd_tx_offload_get_configuration_result,
16580                  show, "show");
16581 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16582         TOKEN_STRING_INITIALIZER
16583                 (struct cmd_tx_offload_get_configuration_result,
16584                  port, "port");
16585 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16586         TOKEN_NUM_INITIALIZER
16587                 (struct cmd_tx_offload_get_configuration_result,
16588                  port_id, RTE_UINT16);
16589 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16590         TOKEN_STRING_INITIALIZER
16591                 (struct cmd_tx_offload_get_configuration_result,
16592                  tx_offload, "tx_offload");
16593 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16594         TOKEN_STRING_INITIALIZER
16595                 (struct cmd_tx_offload_get_configuration_result,
16596                  configuration, "configuration");
16597
16598 static void
16599 cmd_tx_offload_get_configuration_parsed(
16600         void *parsed_result,
16601         __rte_unused struct cmdline *cl,
16602         __rte_unused void *data)
16603 {
16604         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16605         struct rte_eth_dev_info dev_info;
16606         portid_t port_id = res->port_id;
16607         struct rte_port *port = &ports[port_id];
16608         struct rte_eth_conf dev_conf;
16609         uint64_t port_offloads;
16610         uint64_t queue_offloads;
16611         uint16_t nb_tx_queues;
16612         int q;
16613         int ret;
16614
16615         printf("Tx Offloading Configuration of port %d :\n", port_id);
16616
16617         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16618         if (ret != 0)
16619                 return;
16620
16621         port_offloads = dev_conf.txmode.offloads;
16622         printf("  Port :");
16623         print_tx_offloads(port_offloads);
16624         printf("\n");
16625
16626         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16627         if (ret != 0)
16628                 return;
16629
16630         nb_tx_queues = dev_info.nb_tx_queues;
16631         for (q = 0; q < nb_tx_queues; q++) {
16632                 queue_offloads = port->txq[q].conf.offloads;
16633                 printf("  Queue[%2d] :", q);
16634                 print_tx_offloads(queue_offloads);
16635                 printf("\n");
16636         }
16637         printf("\n");
16638 }
16639
16640 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16641         .f = cmd_tx_offload_get_configuration_parsed,
16642         .data = NULL,
16643         .help_str = "show port <port_id> tx_offload configuration",
16644         .tokens = {
16645                 (void *)&cmd_tx_offload_get_configuration_show,
16646                 (void *)&cmd_tx_offload_get_configuration_port,
16647                 (void *)&cmd_tx_offload_get_configuration_port_id,
16648                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16649                 (void *)&cmd_tx_offload_get_configuration_configuration,
16650                 NULL,
16651         }
16652 };
16653
16654 /* Enable/Disable a per port offloading */
16655 struct cmd_config_per_port_tx_offload_result {
16656         cmdline_fixed_string_t port;
16657         cmdline_fixed_string_t config;
16658         portid_t port_id;
16659         cmdline_fixed_string_t tx_offload;
16660         cmdline_fixed_string_t offload;
16661         cmdline_fixed_string_t on_off;
16662 };
16663
16664 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16665         TOKEN_STRING_INITIALIZER
16666                 (struct cmd_config_per_port_tx_offload_result,
16667                  port, "port");
16668 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16669         TOKEN_STRING_INITIALIZER
16670                 (struct cmd_config_per_port_tx_offload_result,
16671                  config, "config");
16672 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16673         TOKEN_NUM_INITIALIZER
16674                 (struct cmd_config_per_port_tx_offload_result,
16675                  port_id, RTE_UINT16);
16676 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16677         TOKEN_STRING_INITIALIZER
16678                 (struct cmd_config_per_port_tx_offload_result,
16679                  tx_offload, "tx_offload");
16680 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16681         TOKEN_STRING_INITIALIZER
16682                 (struct cmd_config_per_port_tx_offload_result,
16683                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16684                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16685                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16686                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16687                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16688                           "send_on_timestamp");
16689 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16690         TOKEN_STRING_INITIALIZER
16691                 (struct cmd_config_per_port_tx_offload_result,
16692                  on_off, "on#off");
16693
16694 static uint64_t
16695 search_tx_offload(const char *name)
16696 {
16697         uint64_t single_offload;
16698         const char *single_name;
16699         int found = 0;
16700         unsigned int bit;
16701
16702         single_offload = 1;
16703         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16704                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16705                 if (single_name == NULL)
16706                         break;
16707                 if (!strcasecmp(single_name, name)) {
16708                         found = 1;
16709                         break;
16710                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16711                         break;
16712                 single_offload <<= 1;
16713         }
16714
16715         if (found)
16716                 return single_offload;
16717
16718         return 0;
16719 }
16720
16721 static void
16722 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16723                                 __rte_unused struct cmdline *cl,
16724                                 __rte_unused void *data)
16725 {
16726         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16727         portid_t port_id = res->port_id;
16728         struct rte_eth_dev_info dev_info;
16729         struct rte_port *port = &ports[port_id];
16730         uint64_t single_offload;
16731         uint16_t nb_tx_queues;
16732         int q;
16733         int ret;
16734
16735         if (port->port_status != RTE_PORT_STOPPED) {
16736                 fprintf(stderr,
16737                         "Error: Can't config offload when Port %d is not stopped\n",
16738                         port_id);
16739                 return;
16740         }
16741
16742         single_offload = search_tx_offload(res->offload);
16743         if (single_offload == 0) {
16744                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16745                 return;
16746         }
16747
16748         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16749         if (ret != 0)
16750                 return;
16751
16752         nb_tx_queues = dev_info.nb_tx_queues;
16753         if (!strcmp(res->on_off, "on")) {
16754                 port->dev_conf.txmode.offloads |= single_offload;
16755                 for (q = 0; q < nb_tx_queues; q++)
16756                         port->txq[q].conf.offloads |= single_offload;
16757         } else {
16758                 port->dev_conf.txmode.offloads &= ~single_offload;
16759                 for (q = 0; q < nb_tx_queues; q++)
16760                         port->txq[q].conf.offloads &= ~single_offload;
16761         }
16762
16763         cmd_reconfig_device_queue(port_id, 1, 1);
16764 }
16765
16766 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16767         .f = cmd_config_per_port_tx_offload_parsed,
16768         .data = NULL,
16769         .help_str = "port config <port_id> tx_offload "
16770                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16771                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16772                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16773                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16774                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16775                     "send_on_timestamp on|off",
16776         .tokens = {
16777                 (void *)&cmd_config_per_port_tx_offload_result_port,
16778                 (void *)&cmd_config_per_port_tx_offload_result_config,
16779                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16780                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16781                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16782                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16783                 NULL,
16784         }
16785 };
16786
16787 /* Enable/Disable a per queue offloading */
16788 struct cmd_config_per_queue_tx_offload_result {
16789         cmdline_fixed_string_t port;
16790         portid_t port_id;
16791         cmdline_fixed_string_t txq;
16792         uint16_t queue_id;
16793         cmdline_fixed_string_t tx_offload;
16794         cmdline_fixed_string_t offload;
16795         cmdline_fixed_string_t on_off;
16796 };
16797
16798 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16799         TOKEN_STRING_INITIALIZER
16800                 (struct cmd_config_per_queue_tx_offload_result,
16801                  port, "port");
16802 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16803         TOKEN_NUM_INITIALIZER
16804                 (struct cmd_config_per_queue_tx_offload_result,
16805                  port_id, RTE_UINT16);
16806 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16807         TOKEN_STRING_INITIALIZER
16808                 (struct cmd_config_per_queue_tx_offload_result,
16809                  txq, "txq");
16810 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16811         TOKEN_NUM_INITIALIZER
16812                 (struct cmd_config_per_queue_tx_offload_result,
16813                  queue_id, RTE_UINT16);
16814 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16815         TOKEN_STRING_INITIALIZER
16816                 (struct cmd_config_per_queue_tx_offload_result,
16817                  tx_offload, "tx_offload");
16818 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16819         TOKEN_STRING_INITIALIZER
16820                 (struct cmd_config_per_queue_tx_offload_result,
16821                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16822                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16823                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16824                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16825                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16826 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16827         TOKEN_STRING_INITIALIZER
16828                 (struct cmd_config_per_queue_tx_offload_result,
16829                  on_off, "on#off");
16830
16831 static void
16832 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16833                                 __rte_unused struct cmdline *cl,
16834                                 __rte_unused void *data)
16835 {
16836         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16837         struct rte_eth_dev_info dev_info;
16838         portid_t port_id = res->port_id;
16839         uint16_t queue_id = res->queue_id;
16840         struct rte_port *port = &ports[port_id];
16841         uint64_t single_offload;
16842         int ret;
16843
16844         if (port->port_status != RTE_PORT_STOPPED) {
16845                 fprintf(stderr,
16846                         "Error: Can't config offload when Port %d is not stopped\n",
16847                         port_id);
16848                 return;
16849         }
16850
16851         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16852         if (ret != 0)
16853                 return;
16854
16855         if (queue_id >= dev_info.nb_tx_queues) {
16856                 fprintf(stderr,
16857                         "Error: input queue_id should be 0 ... %d\n",
16858                         dev_info.nb_tx_queues - 1);
16859                 return;
16860         }
16861
16862         single_offload = search_tx_offload(res->offload);
16863         if (single_offload == 0) {
16864                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16865                 return;
16866         }
16867
16868         if (!strcmp(res->on_off, "on"))
16869                 port->txq[queue_id].conf.offloads |= single_offload;
16870         else
16871                 port->txq[queue_id].conf.offloads &= ~single_offload;
16872
16873         cmd_reconfig_device_queue(port_id, 1, 1);
16874 }
16875
16876 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16877         .f = cmd_config_per_queue_tx_offload_parsed,
16878         .data = NULL,
16879         .help_str = "port <port_id> txq <queue_id> tx_offload "
16880                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16881                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16882                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16883                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16884                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16885                     "on|off",
16886         .tokens = {
16887                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16888                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16889                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16890                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16891                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16892                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16893                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16894                 NULL,
16895         }
16896 };
16897
16898 /* *** configure tx_metadata for specific port *** */
16899 struct cmd_config_tx_metadata_specific_result {
16900         cmdline_fixed_string_t port;
16901         cmdline_fixed_string_t keyword;
16902         uint16_t port_id;
16903         cmdline_fixed_string_t item;
16904         uint32_t value;
16905 };
16906
16907 static void
16908 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16909                                 __rte_unused struct cmdline *cl,
16910                                 __rte_unused void *data)
16911 {
16912         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16913
16914         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16915                 return;
16916         ports[res->port_id].tx_metadata = res->value;
16917         /* Add/remove callback to insert valid metadata in every Tx packet. */
16918         if (ports[res->port_id].tx_metadata)
16919                 add_tx_md_callback(res->port_id);
16920         else
16921                 remove_tx_md_callback(res->port_id);
16922         rte_flow_dynf_metadata_register();
16923 }
16924
16925 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16926         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16927                         port, "port");
16928 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16929         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16930                         keyword, "config");
16931 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16932         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16933                         port_id, RTE_UINT16);
16934 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16935         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16936                         item, "tx_metadata");
16937 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16938         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16939                         value, RTE_UINT32);
16940
16941 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16942         .f = cmd_config_tx_metadata_specific_parsed,
16943         .data = NULL,
16944         .help_str = "port config <port_id> tx_metadata <value>",
16945         .tokens = {
16946                 (void *)&cmd_config_tx_metadata_specific_port,
16947                 (void *)&cmd_config_tx_metadata_specific_keyword,
16948                 (void *)&cmd_config_tx_metadata_specific_id,
16949                 (void *)&cmd_config_tx_metadata_specific_item,
16950                 (void *)&cmd_config_tx_metadata_specific_value,
16951                 NULL,
16952         },
16953 };
16954
16955 /* *** set dynf *** */
16956 struct cmd_config_tx_dynf_specific_result {
16957         cmdline_fixed_string_t port;
16958         cmdline_fixed_string_t keyword;
16959         uint16_t port_id;
16960         cmdline_fixed_string_t item;
16961         cmdline_fixed_string_t name;
16962         cmdline_fixed_string_t value;
16963 };
16964
16965 static void
16966 cmd_config_dynf_specific_parsed(void *parsed_result,
16967                                 __rte_unused struct cmdline *cl,
16968                                 __rte_unused void *data)
16969 {
16970         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16971         struct rte_mbuf_dynflag desc_flag;
16972         int flag;
16973         uint64_t old_port_flags;
16974
16975         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16976                 return;
16977         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16978         if (flag <= 0) {
16979                 if (strlcpy(desc_flag.name, res->name,
16980                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16981                         fprintf(stderr, "Flag name too long\n");
16982                         return;
16983                 }
16984                 desc_flag.flags = 0;
16985                 flag = rte_mbuf_dynflag_register(&desc_flag);
16986                 if (flag < 0) {
16987                         fprintf(stderr, "Can't register flag\n");
16988                         return;
16989                 }
16990                 strcpy(dynf_names[flag], desc_flag.name);
16991         }
16992         old_port_flags = ports[res->port_id].mbuf_dynf;
16993         if (!strcmp(res->value, "set")) {
16994                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16995                 if (old_port_flags == 0)
16996                         add_tx_dynf_callback(res->port_id);
16997         } else {
16998                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16999                 if (ports[res->port_id].mbuf_dynf == 0)
17000                         remove_tx_dynf_callback(res->port_id);
17001         }
17002 }
17003
17004 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17005         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17006                         keyword, "port");
17007 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17008         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17009                         keyword, "config");
17010 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17011         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17012                         port_id, RTE_UINT16);
17013 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17014         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17015                         item, "dynf");
17016 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17017         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17018                         name, NULL);
17019 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17020         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17021                         value, "set#clear");
17022
17023 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17024         .f = cmd_config_dynf_specific_parsed,
17025         .data = NULL,
17026         .help_str = "port config <port id> dynf <name> set|clear",
17027         .tokens = {
17028                 (void *)&cmd_config_tx_dynf_specific_port,
17029                 (void *)&cmd_config_tx_dynf_specific_keyword,
17030                 (void *)&cmd_config_tx_dynf_specific_port_id,
17031                 (void *)&cmd_config_tx_dynf_specific_item,
17032                 (void *)&cmd_config_tx_dynf_specific_name,
17033                 (void *)&cmd_config_tx_dynf_specific_value,
17034                 NULL,
17035         },
17036 };
17037
17038 /* *** display tx_metadata per port configuration *** */
17039 struct cmd_show_tx_metadata_result {
17040         cmdline_fixed_string_t cmd_show;
17041         cmdline_fixed_string_t cmd_port;
17042         cmdline_fixed_string_t cmd_keyword;
17043         portid_t cmd_pid;
17044 };
17045
17046 static void
17047 cmd_show_tx_metadata_parsed(void *parsed_result,
17048                 __rte_unused struct cmdline *cl,
17049                 __rte_unused void *data)
17050 {
17051         struct cmd_show_tx_metadata_result *res = parsed_result;
17052
17053         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17054                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17055                 return;
17056         }
17057         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17058                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17059                        ports[res->cmd_pid].tx_metadata);
17060         }
17061 }
17062
17063 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17064         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17065                         cmd_show, "show");
17066 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17067         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17068                         cmd_port, "port");
17069 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17070         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17071                         cmd_pid, RTE_UINT16);
17072 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17073         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17074                         cmd_keyword, "tx_metadata");
17075
17076 cmdline_parse_inst_t cmd_show_tx_metadata = {
17077         .f = cmd_show_tx_metadata_parsed,
17078         .data = NULL,
17079         .help_str = "show port <port_id> tx_metadata",
17080         .tokens = {
17081                 (void *)&cmd_show_tx_metadata_show,
17082                 (void *)&cmd_show_tx_metadata_port,
17083                 (void *)&cmd_show_tx_metadata_pid,
17084                 (void *)&cmd_show_tx_metadata_keyword,
17085                 NULL,
17086         },
17087 };
17088
17089 /* *** show fec capability per port configuration *** */
17090 struct cmd_show_fec_capability_result {
17091         cmdline_fixed_string_t cmd_show;
17092         cmdline_fixed_string_t cmd_port;
17093         cmdline_fixed_string_t cmd_fec;
17094         cmdline_fixed_string_t cmd_keyword;
17095         portid_t cmd_pid;
17096 };
17097
17098 static void
17099 cmd_show_fec_capability_parsed(void *parsed_result,
17100                 __rte_unused struct cmdline *cl,
17101                 __rte_unused void *data)
17102 {
17103         struct cmd_show_fec_capability_result *res = parsed_result;
17104         struct rte_eth_fec_capa *speed_fec_capa;
17105         unsigned int num;
17106         int ret;
17107
17108         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17109                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17110                 return;
17111         }
17112
17113         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17114         if (ret == -ENOTSUP) {
17115                 fprintf(stderr, "Function not implemented\n");
17116                 return;
17117         } else if (ret < 0) {
17118                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17119                 return;
17120         }
17121
17122         num = (unsigned int)ret;
17123         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17124         if (speed_fec_capa == NULL) {
17125                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17126                 return;
17127         }
17128
17129         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17130         if (ret < 0) {
17131                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17132                 goto out;
17133         }
17134
17135         show_fec_capability(num, speed_fec_capa);
17136 out:
17137         free(speed_fec_capa);
17138 }
17139
17140 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17141         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17142                         cmd_show, "show");
17143 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17144         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17145                         cmd_port, "port");
17146 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17147         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17148                         cmd_pid, RTE_UINT16);
17149 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17150         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17151                         cmd_fec, "fec");
17152 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17153         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17154                         cmd_keyword, "capabilities");
17155
17156 cmdline_parse_inst_t cmd_show_capability = {
17157         .f = cmd_show_fec_capability_parsed,
17158         .data = NULL,
17159         .help_str = "show port <port_id> fec capabilities",
17160         .tokens = {
17161                 (void *)&cmd_show_fec_capability_show,
17162                 (void *)&cmd_show_fec_capability_port,
17163                 (void *)&cmd_show_fec_capability_pid,
17164                 (void *)&cmd_show_fec_capability_fec,
17165                 (void *)&cmd_show_fec_capability_keyword,
17166                 NULL,
17167         },
17168 };
17169
17170 /* *** show fec mode per port configuration *** */
17171 struct cmd_show_fec_metadata_result {
17172         cmdline_fixed_string_t cmd_show;
17173         cmdline_fixed_string_t cmd_port;
17174         cmdline_fixed_string_t cmd_keyword;
17175         portid_t cmd_pid;
17176 };
17177
17178 static void
17179 cmd_show_fec_mode_parsed(void *parsed_result,
17180                 __rte_unused struct cmdline *cl,
17181                 __rte_unused void *data)
17182 {
17183 #define FEC_NAME_SIZE 16
17184         struct cmd_show_fec_metadata_result *res = parsed_result;
17185         uint32_t mode;
17186         char buf[FEC_NAME_SIZE];
17187         int ret;
17188
17189         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17190                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17191                 return;
17192         }
17193         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17194         if (ret == -ENOTSUP) {
17195                 fprintf(stderr, "Function not implemented\n");
17196                 return;
17197         } else if (ret < 0) {
17198                 fprintf(stderr, "Get FEC mode failed\n");
17199                 return;
17200         }
17201
17202         switch (mode) {
17203         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17204                 strlcpy(buf, "off", sizeof(buf));
17205                 break;
17206         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17207                 strlcpy(buf, "auto", sizeof(buf));
17208                 break;
17209         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17210                 strlcpy(buf, "baser", sizeof(buf));
17211                 break;
17212         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17213                 strlcpy(buf, "rs", sizeof(buf));
17214                 break;
17215         default:
17216                 return;
17217         }
17218
17219         printf("%s\n", buf);
17220 }
17221
17222 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17223         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17224                         cmd_show, "show");
17225 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17226         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17227                         cmd_port, "port");
17228 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17229         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17230                         cmd_pid, RTE_UINT16);
17231 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17232         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17233                         cmd_keyword, "fec_mode");
17234
17235 cmdline_parse_inst_t cmd_show_fec_mode = {
17236         .f = cmd_show_fec_mode_parsed,
17237         .data = NULL,
17238         .help_str = "show port <port_id> fec_mode",
17239         .tokens = {
17240                 (void *)&cmd_show_fec_mode_show,
17241                 (void *)&cmd_show_fec_mode_port,
17242                 (void *)&cmd_show_fec_mode_pid,
17243                 (void *)&cmd_show_fec_mode_keyword,
17244                 NULL,
17245         },
17246 };
17247
17248 /* *** set fec mode per port configuration *** */
17249 struct cmd_set_port_fec_mode {
17250         cmdline_fixed_string_t set;
17251         cmdline_fixed_string_t port;
17252         portid_t port_id;
17253         cmdline_fixed_string_t fec_mode;
17254         cmdline_fixed_string_t fec_value;
17255 };
17256
17257 /* Common CLI fields for set fec mode */
17258 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17259         TOKEN_STRING_INITIALIZER
17260                 (struct cmd_set_port_fec_mode,
17261                  set, "set");
17262 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17263         TOKEN_STRING_INITIALIZER
17264                 (struct cmd_set_port_fec_mode,
17265                  port, "port");
17266 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17267         TOKEN_NUM_INITIALIZER
17268                 (struct cmd_set_port_fec_mode,
17269                  port_id, RTE_UINT16);
17270 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17271         TOKEN_STRING_INITIALIZER
17272                 (struct cmd_set_port_fec_mode,
17273                  fec_mode, "fec_mode");
17274 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17275         TOKEN_STRING_INITIALIZER
17276                 (struct cmd_set_port_fec_mode,
17277                  fec_value, NULL);
17278
17279 static void
17280 cmd_set_port_fec_mode_parsed(
17281         void *parsed_result,
17282         __rte_unused struct cmdline *cl,
17283         __rte_unused void *data)
17284 {
17285         struct cmd_set_port_fec_mode *res = parsed_result;
17286         uint16_t port_id = res->port_id;
17287         uint32_t fec_capa;
17288         int ret;
17289
17290         ret = parse_fec_mode(res->fec_value, &fec_capa);
17291         if (ret < 0) {
17292                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17293                                 res->fec_value, port_id);
17294                 return;
17295         }
17296
17297         ret = rte_eth_fec_set(port_id, fec_capa);
17298         if (ret == -ENOTSUP) {
17299                 fprintf(stderr, "Function not implemented\n");
17300                 return;
17301         } else if (ret < 0) {
17302                 fprintf(stderr, "Set FEC mode failed\n");
17303                 return;
17304         }
17305 }
17306
17307 cmdline_parse_inst_t cmd_set_fec_mode = {
17308         .f = cmd_set_port_fec_mode_parsed,
17309         .data = NULL,
17310         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17311         .tokens = {
17312                 (void *)&cmd_set_port_fec_mode_set,
17313                 (void *)&cmd_set_port_fec_mode_port,
17314                 (void *)&cmd_set_port_fec_mode_port_id,
17315                 (void *)&cmd_set_port_fec_mode_str,
17316                 (void *)&cmd_set_port_fec_mode_value,
17317                 NULL,
17318         },
17319 };
17320
17321 /* show port supported ptypes */
17322
17323 /* Common result structure for show port ptypes */
17324 struct cmd_show_port_supported_ptypes_result {
17325         cmdline_fixed_string_t show;
17326         cmdline_fixed_string_t port;
17327         portid_t port_id;
17328         cmdline_fixed_string_t ptypes;
17329 };
17330
17331 /* Common CLI fields for show port ptypes */
17332 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17333         TOKEN_STRING_INITIALIZER
17334                 (struct cmd_show_port_supported_ptypes_result,
17335                  show, "show");
17336 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17337         TOKEN_STRING_INITIALIZER
17338                 (struct cmd_show_port_supported_ptypes_result,
17339                  port, "port");
17340 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17341         TOKEN_NUM_INITIALIZER
17342                 (struct cmd_show_port_supported_ptypes_result,
17343                  port_id, RTE_UINT16);
17344 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17345         TOKEN_STRING_INITIALIZER
17346                 (struct cmd_show_port_supported_ptypes_result,
17347                  ptypes, "ptypes");
17348
17349 static void
17350 cmd_show_port_supported_ptypes_parsed(
17351         void *parsed_result,
17352         __rte_unused struct cmdline *cl,
17353         __rte_unused void *data)
17354 {
17355 #define RSVD_PTYPE_MASK       0xf0000000
17356 #define MAX_PTYPES_PER_LAYER  16
17357 #define LTYPE_NAMESIZE        32
17358 #define PTYPE_NAMESIZE        256
17359         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17360         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17361         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17362         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17363         uint16_t port_id = res->port_id;
17364         int ret, i;
17365
17366         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17367         if (ret < 0)
17368                 return;
17369
17370         while (ptype_mask != RSVD_PTYPE_MASK) {
17371
17372                 switch (ptype_mask) {
17373                 case RTE_PTYPE_L2_MASK:
17374                         strlcpy(ltype, "L2", sizeof(ltype));
17375                         break;
17376                 case RTE_PTYPE_L3_MASK:
17377                         strlcpy(ltype, "L3", sizeof(ltype));
17378                         break;
17379                 case RTE_PTYPE_L4_MASK:
17380                         strlcpy(ltype, "L4", sizeof(ltype));
17381                         break;
17382                 case RTE_PTYPE_TUNNEL_MASK:
17383                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17384                         break;
17385                 case RTE_PTYPE_INNER_L2_MASK:
17386                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17387                         break;
17388                 case RTE_PTYPE_INNER_L3_MASK:
17389                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17390                         break;
17391                 case RTE_PTYPE_INNER_L4_MASK:
17392                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17393                         break;
17394                 default:
17395                         return;
17396                 }
17397
17398                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17399                                                        ptype_mask, ptypes,
17400                                                        MAX_PTYPES_PER_LAYER);
17401
17402                 if (ret > 0)
17403                         printf("Supported %s ptypes:\n", ltype);
17404                 else
17405                         printf("%s ptypes unsupported\n", ltype);
17406
17407                 for (i = 0; i < ret; ++i) {
17408                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17409                         printf("%s\n", buf);
17410                 }
17411
17412                 ptype_mask <<= 4;
17413         }
17414 }
17415
17416 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17417         .f = cmd_show_port_supported_ptypes_parsed,
17418         .data = NULL,
17419         .help_str = "show port <port_id> ptypes",
17420         .tokens = {
17421                 (void *)&cmd_show_port_supported_ptypes_show,
17422                 (void *)&cmd_show_port_supported_ptypes_port,
17423                 (void *)&cmd_show_port_supported_ptypes_port_id,
17424                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17425                 NULL,
17426         },
17427 };
17428
17429 /* *** display rx/tx descriptor status *** */
17430 struct cmd_show_rx_tx_desc_status_result {
17431         cmdline_fixed_string_t cmd_show;
17432         cmdline_fixed_string_t cmd_port;
17433         cmdline_fixed_string_t cmd_keyword;
17434         cmdline_fixed_string_t cmd_desc;
17435         cmdline_fixed_string_t cmd_status;
17436         portid_t cmd_pid;
17437         portid_t cmd_qid;
17438         portid_t cmd_did;
17439 };
17440
17441 static void
17442 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17443                 __rte_unused struct cmdline *cl,
17444                 __rte_unused void *data)
17445 {
17446         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17447         int rc;
17448
17449         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17450                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17451                 return;
17452         }
17453
17454         if (!strcmp(res->cmd_keyword, "rxq")) {
17455                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17456                                              res->cmd_did);
17457                 if (rc < 0) {
17458                         fprintf(stderr,
17459                                 "Invalid input: queue id = %d, desc id = %d\n",
17460                                 res->cmd_qid, res->cmd_did);
17461                         return;
17462                 }
17463                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17464                         printf("Desc status = AVAILABLE\n");
17465                 else if (rc == RTE_ETH_RX_DESC_DONE)
17466                         printf("Desc status = DONE\n");
17467                 else
17468                         printf("Desc status = UNAVAILABLE\n");
17469         } else if (!strcmp(res->cmd_keyword, "txq")) {
17470                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17471                                              res->cmd_did);
17472                 if (rc < 0) {
17473                         fprintf(stderr,
17474                                 "Invalid input: queue id = %d, desc id = %d\n",
17475                                 res->cmd_qid, res->cmd_did);
17476                         return;
17477                 }
17478                 if (rc == RTE_ETH_TX_DESC_FULL)
17479                         printf("Desc status = FULL\n");
17480                 else if (rc == RTE_ETH_TX_DESC_DONE)
17481                         printf("Desc status = DONE\n");
17482                 else
17483                         printf("Desc status = UNAVAILABLE\n");
17484         }
17485 }
17486
17487 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17488         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17489                         cmd_show, "show");
17490 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17491         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17492                         cmd_port, "port");
17493 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17494         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17495                         cmd_pid, RTE_UINT16);
17496 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17497         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17498                         cmd_keyword, "rxq#txq");
17499 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17500         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17501                         cmd_qid, RTE_UINT16);
17502 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17503         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17504                         cmd_desc, "desc");
17505 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17506         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17507                         cmd_did, RTE_UINT16);
17508 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17509         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17510                         cmd_status, "status");
17511 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17512         .f = cmd_show_rx_tx_desc_status_parsed,
17513         .data = NULL,
17514         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17515                 "status",
17516         .tokens = {
17517                 (void *)&cmd_show_rx_tx_desc_status_show,
17518                 (void *)&cmd_show_rx_tx_desc_status_port,
17519                 (void *)&cmd_show_rx_tx_desc_status_pid,
17520                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17521                 (void *)&cmd_show_rx_tx_desc_status_qid,
17522                 (void *)&cmd_show_rx_tx_desc_status_desc,
17523                 (void *)&cmd_show_rx_tx_desc_status_did,
17524                 (void *)&cmd_show_rx_tx_desc_status_status,
17525                 NULL,
17526         },
17527 };
17528
17529 /* *** display rx queue desc used count *** */
17530 struct cmd_show_rx_queue_desc_used_count_result {
17531         cmdline_fixed_string_t cmd_show;
17532         cmdline_fixed_string_t cmd_port;
17533         cmdline_fixed_string_t cmd_rxq;
17534         cmdline_fixed_string_t cmd_desc;
17535         cmdline_fixed_string_t cmd_used;
17536         cmdline_fixed_string_t cmd_count;
17537         portid_t cmd_pid;
17538         portid_t cmd_qid;
17539 };
17540
17541 static void
17542 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17543                 __rte_unused struct cmdline *cl,
17544                 __rte_unused void *data)
17545 {
17546         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17547         int rc;
17548
17549         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17550                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17551                 return;
17552         }
17553
17554         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17555         if (rc < 0) {
17556                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17557                 return;
17558         }
17559         printf("Used desc count = %d\n", rc);
17560 }
17561
17562 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17563         TOKEN_STRING_INITIALIZER
17564                 (struct cmd_show_rx_queue_desc_used_count_result,
17565                  cmd_show, "show");
17566 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17567         TOKEN_STRING_INITIALIZER
17568                 (struct cmd_show_rx_queue_desc_used_count_result,
17569                  cmd_port, "port");
17570 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17571         TOKEN_NUM_INITIALIZER
17572                 (struct cmd_show_rx_queue_desc_used_count_result,
17573                  cmd_pid, RTE_UINT16);
17574 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17575         TOKEN_STRING_INITIALIZER
17576                 (struct cmd_show_rx_queue_desc_used_count_result,
17577                  cmd_rxq, "rxq");
17578 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17579         TOKEN_NUM_INITIALIZER
17580                 (struct cmd_show_rx_queue_desc_used_count_result,
17581                  cmd_qid, RTE_UINT16);
17582 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17583         TOKEN_STRING_INITIALIZER
17584                 (struct cmd_show_rx_queue_desc_used_count_result,
17585                  cmd_count, "desc");
17586 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17587         TOKEN_STRING_INITIALIZER
17588                 (struct cmd_show_rx_queue_desc_used_count_result,
17589                  cmd_count, "used");
17590 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17591         TOKEN_STRING_INITIALIZER
17592                 (struct cmd_show_rx_queue_desc_used_count_result,
17593                  cmd_count, "count");
17594 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17595         .f = cmd_show_rx_queue_desc_used_count_parsed,
17596         .data = NULL,
17597         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17598         .tokens = {
17599                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17600                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17601                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17602                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17603                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17604                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17605                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17606                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17607                 NULL,
17608         },
17609 };
17610
17611 /* Common result structure for set port ptypes */
17612 struct cmd_set_port_ptypes_result {
17613         cmdline_fixed_string_t set;
17614         cmdline_fixed_string_t port;
17615         portid_t port_id;
17616         cmdline_fixed_string_t ptype_mask;
17617         uint32_t mask;
17618 };
17619
17620 /* Common CLI fields for set port ptypes */
17621 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17622         TOKEN_STRING_INITIALIZER
17623                 (struct cmd_set_port_ptypes_result,
17624                  set, "set");
17625 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17626         TOKEN_STRING_INITIALIZER
17627                 (struct cmd_set_port_ptypes_result,
17628                  port, "port");
17629 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17630         TOKEN_NUM_INITIALIZER
17631                 (struct cmd_set_port_ptypes_result,
17632                  port_id, RTE_UINT16);
17633 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17634         TOKEN_STRING_INITIALIZER
17635                 (struct cmd_set_port_ptypes_result,
17636                  ptype_mask, "ptype_mask");
17637 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17638         TOKEN_NUM_INITIALIZER
17639                 (struct cmd_set_port_ptypes_result,
17640                  mask, RTE_UINT32);
17641
17642 static void
17643 cmd_set_port_ptypes_parsed(
17644         void *parsed_result,
17645         __rte_unused struct cmdline *cl,
17646         __rte_unused void *data)
17647 {
17648         struct cmd_set_port_ptypes_result *res = parsed_result;
17649 #define PTYPE_NAMESIZE        256
17650         char ptype_name[PTYPE_NAMESIZE];
17651         uint16_t port_id = res->port_id;
17652         uint32_t ptype_mask = res->mask;
17653         int ret, i;
17654
17655         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17656                                                NULL, 0);
17657         if (ret <= 0) {
17658                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17659                         port_id);
17660                 return;
17661         }
17662
17663         uint32_t ptypes[ret];
17664
17665         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17666         if (ret < 0) {
17667                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17668                         port_id);
17669                 return;
17670         }
17671
17672         printf("Successfully set following ptypes for Port %d\n", port_id);
17673         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17674                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17675                 printf("%s\n", ptype_name);
17676         }
17677
17678         clear_ptypes = false;
17679 }
17680
17681 cmdline_parse_inst_t cmd_set_port_ptypes = {
17682         .f = cmd_set_port_ptypes_parsed,
17683         .data = NULL,
17684         .help_str = "set port <port_id> ptype_mask <mask>",
17685         .tokens = {
17686                 (void *)&cmd_set_port_ptypes_set,
17687                 (void *)&cmd_set_port_ptypes_port,
17688                 (void *)&cmd_set_port_ptypes_port_id,
17689                 (void *)&cmd_set_port_ptypes_mask_str,
17690                 (void *)&cmd_set_port_ptypes_mask_u32,
17691                 NULL,
17692         },
17693 };
17694
17695 /* *** display mac addresses added to a port *** */
17696 struct cmd_showport_macs_result {
17697         cmdline_fixed_string_t cmd_show;
17698         cmdline_fixed_string_t cmd_port;
17699         cmdline_fixed_string_t cmd_keyword;
17700         portid_t cmd_pid;
17701 };
17702
17703 static void
17704 cmd_showport_macs_parsed(void *parsed_result,
17705                 __rte_unused struct cmdline *cl,
17706                 __rte_unused void *data)
17707 {
17708         struct cmd_showport_macs_result *res = parsed_result;
17709
17710         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17711                 return;
17712
17713         if (!strcmp(res->cmd_keyword, "macs"))
17714                 show_macs(res->cmd_pid);
17715         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17716                 show_mcast_macs(res->cmd_pid);
17717 }
17718
17719 cmdline_parse_token_string_t cmd_showport_macs_show =
17720         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17721                         cmd_show, "show");
17722 cmdline_parse_token_string_t cmd_showport_macs_port =
17723         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17724                         cmd_port, "port");
17725 cmdline_parse_token_num_t cmd_showport_macs_pid =
17726         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17727                         cmd_pid, RTE_UINT16);
17728 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17729         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17730                         cmd_keyword, "macs#mcast_macs");
17731
17732 cmdline_parse_inst_t cmd_showport_macs = {
17733         .f = cmd_showport_macs_parsed,
17734         .data = NULL,
17735         .help_str = "show port <port_id> macs|mcast_macs",
17736         .tokens = {
17737                 (void *)&cmd_showport_macs_show,
17738                 (void *)&cmd_showport_macs_port,
17739                 (void *)&cmd_showport_macs_pid,
17740                 (void *)&cmd_showport_macs_keyword,
17741                 NULL,
17742         },
17743 };
17744
17745 /* *** show flow transfer proxy port ID for the given port *** */
17746 struct cmd_show_port_flow_transfer_proxy_result {
17747         cmdline_fixed_string_t show;
17748         cmdline_fixed_string_t port;
17749         portid_t port_id;
17750         cmdline_fixed_string_t flow;
17751         cmdline_fixed_string_t transfer;
17752         cmdline_fixed_string_t proxy;
17753 };
17754
17755 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17756         TOKEN_STRING_INITIALIZER
17757                 (struct cmd_show_port_flow_transfer_proxy_result,
17758                  show, "show");
17759 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17760         TOKEN_STRING_INITIALIZER
17761                 (struct cmd_show_port_flow_transfer_proxy_result,
17762                  port, "port");
17763 cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17764         TOKEN_NUM_INITIALIZER
17765                 (struct cmd_show_port_flow_transfer_proxy_result,
17766                  port_id, RTE_UINT16);
17767 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17768         TOKEN_STRING_INITIALIZER
17769                 (struct cmd_show_port_flow_transfer_proxy_result,
17770                  flow, "flow");
17771 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17772         TOKEN_STRING_INITIALIZER
17773                 (struct cmd_show_port_flow_transfer_proxy_result,
17774                  transfer, "transfer");
17775 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17776         TOKEN_STRING_INITIALIZER
17777                 (struct cmd_show_port_flow_transfer_proxy_result,
17778                  proxy, "proxy");
17779
17780 static void
17781 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17782                                          __rte_unused struct cmdline *cl,
17783                                          __rte_unused void *data)
17784 {
17785         struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17786         portid_t proxy_port_id;
17787         int ret;
17788
17789         printf("\n");
17790
17791         ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17792         if (ret != 0) {
17793                 fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17794                         rte_strerror(-ret));
17795                 return;
17796         }
17797
17798         printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17799 }
17800
17801 cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17802         .f = cmd_show_port_flow_transfer_proxy_parsed,
17803         .data = NULL,
17804         .help_str = "show port <port_id> flow transfer proxy",
17805         .tokens = {
17806                 (void *)&cmd_show_port_flow_transfer_proxy_show,
17807                 (void *)&cmd_show_port_flow_transfer_proxy_port,
17808                 (void *)&cmd_show_port_flow_transfer_proxy_port_id,
17809                 (void *)&cmd_show_port_flow_transfer_proxy_flow,
17810                 (void *)&cmd_show_port_flow_transfer_proxy_transfer,
17811                 (void *)&cmd_show_port_flow_transfer_proxy_proxy,
17812                 NULL,
17813         }
17814 };
17815
17816 /* ******************************************************************************** */
17817
17818 /* list of instructions */
17819 cmdline_parse_ctx_t main_ctx[] = {
17820         (cmdline_parse_inst_t *)&cmd_help_brief,
17821         (cmdline_parse_inst_t *)&cmd_help_long,
17822         (cmdline_parse_inst_t *)&cmd_quit,
17823         (cmdline_parse_inst_t *)&cmd_load_from_file,
17824         (cmdline_parse_inst_t *)&cmd_showport,
17825         (cmdline_parse_inst_t *)&cmd_showqueue,
17826         (cmdline_parse_inst_t *)&cmd_showeeprom,
17827         (cmdline_parse_inst_t *)&cmd_showportall,
17828         (cmdline_parse_inst_t *)&cmd_representor_info,
17829         (cmdline_parse_inst_t *)&cmd_showdevice,
17830         (cmdline_parse_inst_t *)&cmd_showcfg,
17831         (cmdline_parse_inst_t *)&cmd_showfwdall,
17832         (cmdline_parse_inst_t *)&cmd_start,
17833         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17834         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17835         (cmdline_parse_inst_t *)&cmd_set_link_up,
17836         (cmdline_parse_inst_t *)&cmd_set_link_down,
17837         (cmdline_parse_inst_t *)&cmd_reset,
17838         (cmdline_parse_inst_t *)&cmd_set_numbers,
17839         (cmdline_parse_inst_t *)&cmd_set_log,
17840         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17841         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17842         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17843         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17844         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17845         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17846         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17847         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17848         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17849         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17850         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17851         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17852         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17853         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17854         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17855         (cmdline_parse_inst_t *)&cmd_set_link_check,
17856         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17857         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17858         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17859         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17860 #ifdef RTE_NET_BOND
17861         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17862         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17863         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17864         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17865         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17866         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17867         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17868         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17869         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17870         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17871         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17872         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17873 #endif
17874         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17875         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17876         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17877         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17878         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17879         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17880         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17881         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17882         (cmdline_parse_inst_t *)&cmd_csum_set,
17883         (cmdline_parse_inst_t *)&cmd_csum_show,
17884         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17885         (cmdline_parse_inst_t *)&cmd_tso_set,
17886         (cmdline_parse_inst_t *)&cmd_tso_show,
17887         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17888         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17889 #ifdef RTE_LIB_GRO
17890         (cmdline_parse_inst_t *)&cmd_gro_enable,
17891         (cmdline_parse_inst_t *)&cmd_gro_flush,
17892         (cmdline_parse_inst_t *)&cmd_gro_show,
17893 #endif
17894 #ifdef RTE_LIB_GSO
17895         (cmdline_parse_inst_t *)&cmd_gso_enable,
17896         (cmdline_parse_inst_t *)&cmd_gso_size,
17897         (cmdline_parse_inst_t *)&cmd_gso_show,
17898 #endif
17899         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17900         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17901         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17902         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17903         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17904         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17905         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17906         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17907         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17908         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17909         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17910         (cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17911         (cmdline_parse_inst_t *)&cmd_config_dcb,
17912         (cmdline_parse_inst_t *)&cmd_read_reg,
17913         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17914         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17915         (cmdline_parse_inst_t *)&cmd_write_reg,
17916         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17917         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17918         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17919         (cmdline_parse_inst_t *)&cmd_stop,
17920         (cmdline_parse_inst_t *)&cmd_mac_addr,
17921         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17922         (cmdline_parse_inst_t *)&cmd_set_qmap,
17923         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17924         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17925         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17926         (cmdline_parse_inst_t *)&cmd_operate_port,
17927         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17928         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17929         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17930         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17931         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17932         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17933         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17934         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17935         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17936         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17937         (cmdline_parse_inst_t *)&cmd_config_mtu,
17938         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17939         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17940         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17941         (cmdline_parse_inst_t *)&cmd_config_rss,
17942         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17943         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17944         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17945         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17946         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17947         (cmdline_parse_inst_t *)&cmd_showport_reta,
17948         (cmdline_parse_inst_t *)&cmd_showport_macs,
17949         (cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
17950         (cmdline_parse_inst_t *)&cmd_config_burst,
17951         (cmdline_parse_inst_t *)&cmd_config_thresh,
17952         (cmdline_parse_inst_t *)&cmd_config_threshold,
17953         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17954         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17955         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17956         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17957         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17958         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17959         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17960         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17961         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17962         (cmdline_parse_inst_t *)&cmd_dump,
17963         (cmdline_parse_inst_t *)&cmd_dump_one,
17964 #ifdef RTE_NET_I40E
17965         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17966 #endif
17967         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17968         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17969         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17970         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17971         (cmdline_parse_inst_t *)&cmd_flow,
17972         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17973         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17974         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17975         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm_rfc4115,
17976         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17977         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17978         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17979         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17980         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17981         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17982         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17983         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17984         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17985         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17986         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17987         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17988         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17989         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17990         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17991         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17992         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17993         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17994         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17995         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17996         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17997         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17998         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17999         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18000         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18001         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18002         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18003         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18004         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18005         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18006         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18007         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18008         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18009         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18010         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18011         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18012         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18013         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18014         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18015         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18016         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18017         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18018         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18019         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18020         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18021         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18022         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18023         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18024         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18025         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18026         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18027         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18028         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18029         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18030         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18031         (cmdline_parse_inst_t *)&cmd_ddp_add,
18032         (cmdline_parse_inst_t *)&cmd_ddp_del,
18033         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18034         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18035         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18036         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18037         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18038         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18039         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18040         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18041         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18042         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18043         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18044         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18045
18046         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18047         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18048         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18049         (cmdline_parse_inst_t *)&cmd_queue_region,
18050         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18051         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18052         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18053         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18054         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18055         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18056         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18057         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18058         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18059         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18060         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18061         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18062         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18063         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18064         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18065         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18066         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18067         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18068         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18069         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18070         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18071         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18072         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18073         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18074         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18075         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18076         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18077         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18078         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18079         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18080         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18081         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18082         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18083         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18084         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18085         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18086 #ifdef RTE_LIB_BPF
18087         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18088         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18089 #endif
18090         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18091         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18092         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18093         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18094         (cmdline_parse_inst_t *)&cmd_set_raw,
18095         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18096         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18097         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18098         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18099         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18100         (cmdline_parse_inst_t *)&cmd_show_capability,
18101         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18102         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18103         NULL,
18104 };
18105
18106 /* read cmdline commands from file */
18107 void
18108 cmdline_read_from_file(const char *filename)
18109 {
18110         struct cmdline *cl;
18111
18112         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18113         if (cl == NULL) {
18114                 fprintf(stderr,
18115                         "Failed to create file based cmdline context: %s\n",
18116                         filename);
18117                 return;
18118         }
18119
18120         cmdline_interact(cl);
18121         cmdline_quit(cl);
18122
18123         cmdline_free(cl);
18124
18125         printf("Read CLI commands from %s\n", filename);
18126 }
18127
18128 /* prompt function, called from main on MAIN lcore */
18129 void
18130 prompt(void)
18131 {
18132         int ret;
18133         /* initialize non-constant commands */
18134         cmd_set_fwd_mode_init();
18135         cmd_set_fwd_retry_mode_init();
18136
18137         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18138         if (testpmd_cl == NULL)
18139                 return;
18140
18141         ret = atexit(prompt_exit);
18142         if (ret != 0)
18143                 fprintf(stderr, "Cannot set exit function for cmdline\n");
18144
18145         cmdline_interact(testpmd_cl);
18146         if (ret != 0)
18147                 cmdline_stdin_exit(testpmd_cl);
18148 }
18149
18150 void
18151 prompt_exit(void)
18152 {
18153         if (testpmd_cl != NULL) {
18154                 cmdline_quit(testpmd_cl);
18155                 cmdline_stdin_exit(testpmd_cl);
18156         }
18157 }
18158
18159 static void
18160 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18161 {
18162         if (id == (portid_t)RTE_PORT_ALL) {
18163                 portid_t pid;
18164
18165                 RTE_ETH_FOREACH_DEV(pid) {
18166                         /* check if need_reconfig has been set to 1 */
18167                         if (ports[pid].need_reconfig == 0)
18168                                 ports[pid].need_reconfig = dev;
18169                         /* check if need_reconfig_queues has been set to 1 */
18170                         if (ports[pid].need_reconfig_queues == 0)
18171                                 ports[pid].need_reconfig_queues = queue;
18172                 }
18173         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18174                 /* check if need_reconfig has been set to 1 */
18175                 if (ports[id].need_reconfig == 0)
18176                         ports[id].need_reconfig = dev;
18177                 /* check if need_reconfig_queues has been set to 1 */
18178                 if (ports[id].need_reconfig_queues == 0)
18179                         ports[id].need_reconfig_queues = queue;
18180         }
18181 }