app/testpmd: fix port status of bonding slave device
[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         uint8_t isrx;
2658         uint8_t isstart;
2659         int ret = 0;
2660
2661         if (test_done == 0) {
2662                 fprintf(stderr, "Please stop forwarding first\n");
2663                 return;
2664         }
2665
2666         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2667                 return;
2668
2669         if (port_is_started(res->portid) != 1) {
2670                 fprintf(stderr, "Please start port %u first\n", res->portid);
2671                 return;
2672         }
2673
2674         if (!strcmp(res->rxtxq, "rxq"))
2675                 isrx = 1;
2676         else if (!strcmp(res->rxtxq, "txq"))
2677                 isrx = 0;
2678         else {
2679                 fprintf(stderr, "Unknown parameter\n");
2680                 return;
2681         }
2682
2683         if (isrx && rx_queue_id_is_invalid(res->qid))
2684                 return;
2685         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2686                 return;
2687
2688         if (!strcmp(res->opname, "start"))
2689                 isstart = 1;
2690         else if (!strcmp(res->opname, "stop"))
2691                 isstart = 0;
2692         else {
2693                 fprintf(stderr, "Unknown parameter\n");
2694                 return;
2695         }
2696
2697         if (isstart && isrx)
2698                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2699         else if (!isstart && isrx)
2700                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2701         else if (isstart && !isrx)
2702                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2703         else
2704                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2705
2706         if (ret == -ENOTSUP)
2707                 fprintf(stderr, "Function not supported in PMD\n");
2708 }
2709
2710 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2711         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2712 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2713         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2714 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2715         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2716 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2717         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2718 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2719         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2720                                                 "start#stop");
2721
2722 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2723         .f = cmd_config_rxtx_queue_parsed,
2724         .data = NULL,
2725         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2726         .tokens = {
2727                 (void *)&cmd_config_rxtx_queue_port,
2728                 (void *)&cmd_config_rxtx_queue_portid,
2729                 (void *)&cmd_config_rxtx_queue_rxtxq,
2730                 (void *)&cmd_config_rxtx_queue_qid,
2731                 (void *)&cmd_config_rxtx_queue_opname,
2732                 NULL,
2733         },
2734 };
2735
2736 /* *** configure port rxq/txq deferred start on/off *** */
2737 struct cmd_config_deferred_start_rxtx_queue {
2738         cmdline_fixed_string_t port;
2739         portid_t port_id;
2740         cmdline_fixed_string_t rxtxq;
2741         uint16_t qid;
2742         cmdline_fixed_string_t opname;
2743         cmdline_fixed_string_t state;
2744 };
2745
2746 static void
2747 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2748                         __rte_unused struct cmdline *cl,
2749                         __rte_unused void *data)
2750 {
2751         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2752         struct rte_port *port;
2753         uint8_t isrx;
2754         uint8_t ison;
2755         uint8_t needreconfig = 0;
2756
2757         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2758                 return;
2759
2760         if (port_is_started(res->port_id) != 0) {
2761                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2762                 return;
2763         }
2764
2765         port = &ports[res->port_id];
2766
2767         isrx = !strcmp(res->rxtxq, "rxq");
2768
2769         if (isrx && rx_queue_id_is_invalid(res->qid))
2770                 return;
2771         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2772                 return;
2773
2774         ison = !strcmp(res->state, "on");
2775
2776         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2777                 port->rx_conf[res->qid].rx_deferred_start = ison;
2778                 needreconfig = 1;
2779         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2780                 port->tx_conf[res->qid].tx_deferred_start = ison;
2781                 needreconfig = 1;
2782         }
2783
2784         if (needreconfig)
2785                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2786 }
2787
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2789         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790                                                 port, "port");
2791 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2792         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793                                                 port_id, RTE_UINT16);
2794 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2795         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2796                                                 rxtxq, "rxq#txq");
2797 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2798         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799                                                 qid, RTE_UINT16);
2800 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2801         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2802                                                 opname, "deferred_start");
2803 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2804         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2805                                                 state, "on#off");
2806
2807 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2808         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2809         .data = NULL,
2810         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2811         .tokens = {
2812                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2813                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2814                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2815                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2816                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2817                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2818                 NULL,
2819         },
2820 };
2821
2822 /* *** configure port rxq/txq setup *** */
2823 struct cmd_setup_rxtx_queue {
2824         cmdline_fixed_string_t port;
2825         portid_t portid;
2826         cmdline_fixed_string_t rxtxq;
2827         uint16_t qid;
2828         cmdline_fixed_string_t setup;
2829 };
2830
2831 /* Common CLI fields for queue setup */
2832 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2833         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2834 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2835         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2836 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2837         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2838 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2839         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2840 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2841         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2842
2843 static void
2844 cmd_setup_rxtx_queue_parsed(
2845         void *parsed_result,
2846         __rte_unused struct cmdline *cl,
2847         __rte_unused void *data)
2848 {
2849         struct cmd_setup_rxtx_queue *res = parsed_result;
2850         struct rte_port *port;
2851         struct rte_mempool *mp;
2852         unsigned int socket_id;
2853         uint8_t isrx = 0;
2854         int ret;
2855
2856         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2857                 return;
2858
2859         if (res->portid == (portid_t)RTE_PORT_ALL) {
2860                 fprintf(stderr, "Invalid port id\n");
2861                 return;
2862         }
2863
2864         if (!strcmp(res->rxtxq, "rxq"))
2865                 isrx = 1;
2866         else if (!strcmp(res->rxtxq, "txq"))
2867                 isrx = 0;
2868         else {
2869                 fprintf(stderr, "Unknown parameter\n");
2870                 return;
2871         }
2872
2873         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2874                 fprintf(stderr, "Invalid rx queue\n");
2875                 return;
2876         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2877                 fprintf(stderr, "Invalid tx queue\n");
2878                 return;
2879         }
2880
2881         port = &ports[res->portid];
2882         if (isrx) {
2883                 socket_id = rxring_numa[res->portid];
2884                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2885                         socket_id = port->socket_id;
2886
2887                 mp = mbuf_pool_find(socket_id, 0);
2888                 if (mp == NULL) {
2889                         fprintf(stderr,
2890                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2891                                 rxring_numa[res->portid]);
2892                         return;
2893                 }
2894                 ret = rx_queue_setup(res->portid,
2895                                      res->qid,
2896                                      port->nb_rx_desc[res->qid],
2897                                      socket_id,
2898                                      &port->rx_conf[res->qid],
2899                                      mp);
2900                 if (ret)
2901                         fprintf(stderr, "Failed to setup RX queue\n");
2902         } else {
2903                 socket_id = txring_numa[res->portid];
2904                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2905                         socket_id = port->socket_id;
2906
2907                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2908                         fprintf(stderr,
2909                                 "Failed to setup TX queue: not enough descriptors\n");
2910                         return;
2911                 }
2912                 ret = rte_eth_tx_queue_setup(res->portid,
2913                                              res->qid,
2914                                              port->nb_tx_desc[res->qid],
2915                                              socket_id,
2916                                              &port->tx_conf[res->qid]);
2917                 if (ret)
2918                         fprintf(stderr, "Failed to setup TX queue\n");
2919         }
2920 }
2921
2922 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2923         .f = cmd_setup_rxtx_queue_parsed,
2924         .data = NULL,
2925         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2926         .tokens = {
2927                 (void *)&cmd_setup_rxtx_queue_port,
2928                 (void *)&cmd_setup_rxtx_queue_portid,
2929                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2930                 (void *)&cmd_setup_rxtx_queue_qid,
2931                 (void *)&cmd_setup_rxtx_queue_setup,
2932                 NULL,
2933         },
2934 };
2935
2936
2937 /* *** Configure RSS RETA *** */
2938 struct cmd_config_rss_reta {
2939         cmdline_fixed_string_t port;
2940         cmdline_fixed_string_t keyword;
2941         portid_t port_id;
2942         cmdline_fixed_string_t name;
2943         cmdline_fixed_string_t list_name;
2944         cmdline_fixed_string_t list_of_items;
2945 };
2946
2947 static int
2948 parse_reta_config(const char *str,
2949                   struct rte_eth_rss_reta_entry64 *reta_conf,
2950                   uint16_t nb_entries)
2951 {
2952         int i;
2953         unsigned size;
2954         uint16_t hash_index, idx, shift;
2955         uint16_t nb_queue;
2956         char s[256];
2957         const char *p, *p0 = str;
2958         char *end;
2959         enum fieldnames {
2960                 FLD_HASH_INDEX = 0,
2961                 FLD_QUEUE,
2962                 _NUM_FLD
2963         };
2964         unsigned long int_fld[_NUM_FLD];
2965         char *str_fld[_NUM_FLD];
2966
2967         while ((p = strchr(p0,'(')) != NULL) {
2968                 ++p;
2969                 if((p0 = strchr(p,')')) == NULL)
2970                         return -1;
2971
2972                 size = p0 - p;
2973                 if(size >= sizeof(s))
2974                         return -1;
2975
2976                 snprintf(s, sizeof(s), "%.*s", size, p);
2977                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2978                         return -1;
2979                 for (i = 0; i < _NUM_FLD; i++) {
2980                         errno = 0;
2981                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2982                         if (errno != 0 || end == str_fld[i] ||
2983                                         int_fld[i] > 65535)
2984                                 return -1;
2985                 }
2986
2987                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2988                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2989
2990                 if (hash_index >= nb_entries) {
2991                         fprintf(stderr, "Invalid RETA hash index=%d\n",
2992                                 hash_index);
2993                         return -1;
2994                 }
2995
2996                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
2997                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
2998                 reta_conf[idx].mask |= (1ULL << shift);
2999                 reta_conf[idx].reta[shift] = nb_queue;
3000         }
3001
3002         return 0;
3003 }
3004
3005 static void
3006 cmd_set_rss_reta_parsed(void *parsed_result,
3007                         __rte_unused struct cmdline *cl,
3008                         __rte_unused void *data)
3009 {
3010         int ret;
3011         struct rte_eth_dev_info dev_info;
3012         struct rte_eth_rss_reta_entry64 reta_conf[8];
3013         struct cmd_config_rss_reta *res = parsed_result;
3014
3015         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3016         if (ret != 0)
3017                 return;
3018
3019         if (dev_info.reta_size == 0) {
3020                 fprintf(stderr,
3021                         "Redirection table size is 0 which is invalid for RSS\n");
3022                 return;
3023         } else
3024                 printf("The reta size of port %d is %u\n",
3025                         res->port_id, dev_info.reta_size);
3026         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3027                 fprintf(stderr,
3028                         "Currently do not support more than %u entries of redirection table\n",
3029                         RTE_ETH_RSS_RETA_SIZE_512);
3030                 return;
3031         }
3032
3033         memset(reta_conf, 0, sizeof(reta_conf));
3034         if (!strcmp(res->list_name, "reta")) {
3035                 if (parse_reta_config(res->list_of_items, reta_conf,
3036                                                 dev_info.reta_size)) {
3037                         fprintf(stderr,
3038                                 "Invalid RSS Redirection Table config entered\n");
3039                         return;
3040                 }
3041                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3042                                 reta_conf, dev_info.reta_size);
3043                 if (ret != 0)
3044                         fprintf(stderr,
3045                                 "Bad redirection table parameter, return code = %d\n",
3046                                 ret);
3047         }
3048 }
3049
3050 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3051         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3052 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3053         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3054 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3055         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3056 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3057         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3058 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3059         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3060 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3062                                  NULL);
3063 cmdline_parse_inst_t cmd_config_rss_reta = {
3064         .f = cmd_set_rss_reta_parsed,
3065         .data = NULL,
3066         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3067         .tokens = {
3068                 (void *)&cmd_config_rss_reta_port,
3069                 (void *)&cmd_config_rss_reta_keyword,
3070                 (void *)&cmd_config_rss_reta_port_id,
3071                 (void *)&cmd_config_rss_reta_name,
3072                 (void *)&cmd_config_rss_reta_list_name,
3073                 (void *)&cmd_config_rss_reta_list_of_items,
3074                 NULL,
3075         },
3076 };
3077
3078 /* *** SHOW PORT RETA INFO *** */
3079 struct cmd_showport_reta {
3080         cmdline_fixed_string_t show;
3081         cmdline_fixed_string_t port;
3082         portid_t port_id;
3083         cmdline_fixed_string_t rss;
3084         cmdline_fixed_string_t reta;
3085         uint16_t size;
3086         cmdline_fixed_string_t list_of_items;
3087 };
3088
3089 static int
3090 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3091                            uint16_t nb_entries,
3092                            char *str)
3093 {
3094         uint32_t size;
3095         const char *p, *p0 = str;
3096         char s[256];
3097         char *end;
3098         char *str_fld[8];
3099         uint16_t i;
3100         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3101                         RTE_ETH_RETA_GROUP_SIZE;
3102         int ret;
3103
3104         p = strchr(p0, '(');
3105         if (p == NULL)
3106                 return -1;
3107         p++;
3108         p0 = strchr(p, ')');
3109         if (p0 == NULL)
3110                 return -1;
3111         size = p0 - p;
3112         if (size >= sizeof(s)) {
3113                 fprintf(stderr,
3114                         "The string size exceeds the internal buffer size\n");
3115                 return -1;
3116         }
3117         snprintf(s, sizeof(s), "%.*s", size, p);
3118         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3119         if (ret <= 0 || ret != num) {
3120                 fprintf(stderr,
3121                         "The bits of masks do not match the number of reta entries: %u\n",
3122                         num);
3123                 return -1;
3124         }
3125         for (i = 0; i < ret; i++)
3126                 conf[i].mask = (uint64_t)strtoull(str_fld[i], &end, 0);
3127
3128         return 0;
3129 }
3130
3131 static void
3132 cmd_showport_reta_parsed(void *parsed_result,
3133                          __rte_unused struct cmdline *cl,
3134                          __rte_unused void *data)
3135 {
3136         struct cmd_showport_reta *res = parsed_result;
3137         struct rte_eth_rss_reta_entry64 reta_conf[8];
3138         struct rte_eth_dev_info dev_info;
3139         uint16_t max_reta_size;
3140         int ret;
3141
3142         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3143         if (ret != 0)
3144                 return;
3145
3146         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3147         if (res->size == 0 || res->size > max_reta_size) {
3148                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3149                         res->size, max_reta_size);
3150                 return;
3151         }
3152
3153         memset(reta_conf, 0, sizeof(reta_conf));
3154         if (showport_parse_reta_config(reta_conf, res->size,
3155                                 res->list_of_items) < 0) {
3156                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3157                         res->list_of_items);
3158                 return;
3159         }
3160         port_rss_reta_info(res->port_id, reta_conf, res->size);
3161 }
3162
3163 cmdline_parse_token_string_t cmd_showport_reta_show =
3164         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3165 cmdline_parse_token_string_t cmd_showport_reta_port =
3166         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3167 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3168         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3169 cmdline_parse_token_string_t cmd_showport_reta_rss =
3170         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3171 cmdline_parse_token_string_t cmd_showport_reta_reta =
3172         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3173 cmdline_parse_token_num_t cmd_showport_reta_size =
3174         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3175 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3176         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3177                                         list_of_items, NULL);
3178
3179 cmdline_parse_inst_t cmd_showport_reta = {
3180         .f = cmd_showport_reta_parsed,
3181         .data = NULL,
3182         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3183         .tokens = {
3184                 (void *)&cmd_showport_reta_show,
3185                 (void *)&cmd_showport_reta_port,
3186                 (void *)&cmd_showport_reta_port_id,
3187                 (void *)&cmd_showport_reta_rss,
3188                 (void *)&cmd_showport_reta_reta,
3189                 (void *)&cmd_showport_reta_size,
3190                 (void *)&cmd_showport_reta_list_of_items,
3191                 NULL,
3192         },
3193 };
3194
3195 /* *** Show RSS hash configuration *** */
3196 struct cmd_showport_rss_hash {
3197         cmdline_fixed_string_t show;
3198         cmdline_fixed_string_t port;
3199         portid_t port_id;
3200         cmdline_fixed_string_t rss_hash;
3201         cmdline_fixed_string_t rss_type;
3202         cmdline_fixed_string_t key; /* optional argument */
3203 };
3204
3205 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3206                                 __rte_unused struct cmdline *cl,
3207                                 void *show_rss_key)
3208 {
3209         struct cmd_showport_rss_hash *res = parsed_result;
3210
3211         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3212 }
3213
3214 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3215         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3216 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3217         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3218 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3219         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3220                                  RTE_UINT16);
3221 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3222         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3223                                  "rss-hash");
3224 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3225         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3226
3227 cmdline_parse_inst_t cmd_showport_rss_hash = {
3228         .f = cmd_showport_rss_hash_parsed,
3229         .data = NULL,
3230         .help_str = "show port <port_id> rss-hash",
3231         .tokens = {
3232                 (void *)&cmd_showport_rss_hash_show,
3233                 (void *)&cmd_showport_rss_hash_port,
3234                 (void *)&cmd_showport_rss_hash_port_id,
3235                 (void *)&cmd_showport_rss_hash_rss_hash,
3236                 NULL,
3237         },
3238 };
3239
3240 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3241         .f = cmd_showport_rss_hash_parsed,
3242         .data = (void *)1,
3243         .help_str = "show port <port_id> rss-hash key",
3244         .tokens = {
3245                 (void *)&cmd_showport_rss_hash_show,
3246                 (void *)&cmd_showport_rss_hash_port,
3247                 (void *)&cmd_showport_rss_hash_port_id,
3248                 (void *)&cmd_showport_rss_hash_rss_hash,
3249                 (void *)&cmd_showport_rss_hash_rss_key,
3250                 NULL,
3251         },
3252 };
3253
3254 /* *** Configure DCB *** */
3255 struct cmd_config_dcb {
3256         cmdline_fixed_string_t port;
3257         cmdline_fixed_string_t config;
3258         portid_t port_id;
3259         cmdline_fixed_string_t dcb;
3260         cmdline_fixed_string_t vt;
3261         cmdline_fixed_string_t vt_en;
3262         uint8_t num_tcs;
3263         cmdline_fixed_string_t pfc;
3264         cmdline_fixed_string_t pfc_en;
3265 };
3266
3267 static void
3268 cmd_config_dcb_parsed(void *parsed_result,
3269                         __rte_unused struct cmdline *cl,
3270                         __rte_unused void *data)
3271 {
3272         struct cmd_config_dcb *res = parsed_result;
3273         struct rte_eth_dcb_info dcb_info;
3274         portid_t port_id = res->port_id;
3275         struct rte_port *port;
3276         uint8_t pfc_en;
3277         int ret;
3278
3279         port = &ports[port_id];
3280         /** Check if the port is not started **/
3281         if (port->port_status != RTE_PORT_STOPPED) {
3282                 fprintf(stderr, "Please stop port %d first\n", port_id);
3283                 return;
3284         }
3285
3286         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3287                 fprintf(stderr,
3288                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3289                 return;
3290         }
3291
3292         if (nb_fwd_lcores < res->num_tcs) {
3293                 fprintf(stderr,
3294                         "nb_cores shouldn't be less than number of TCs.\n");
3295                 return;
3296         }
3297
3298         /* Check whether the port supports the report of DCB info. */
3299         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3300         if (ret == -ENOTSUP) {
3301                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3302                 return;
3303         }
3304
3305         if (!strncmp(res->pfc_en, "on", 2))
3306                 pfc_en = 1;
3307         else
3308                 pfc_en = 0;
3309
3310         /* DCB in VT mode */
3311         if (!strncmp(res->vt_en, "on", 2))
3312                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3313                                 (enum rte_eth_nb_tcs)res->num_tcs,
3314                                 pfc_en);
3315         else
3316                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3317                                 (enum rte_eth_nb_tcs)res->num_tcs,
3318                                 pfc_en);
3319         if (ret != 0) {
3320                 fprintf(stderr, "Cannot initialize network ports.\n");
3321                 return;
3322         }
3323
3324         fwd_config_setup();
3325
3326         cmd_reconfig_device_queue(port_id, 1, 1);
3327 }
3328
3329 cmdline_parse_token_string_t cmd_config_dcb_port =
3330         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3331 cmdline_parse_token_string_t cmd_config_dcb_config =
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3333 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3334         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3335 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3336         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3337 cmdline_parse_token_string_t cmd_config_dcb_vt =
3338         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3339 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3341 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3342         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3343 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3344         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3345 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3346         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3347
3348 cmdline_parse_inst_t cmd_config_dcb = {
3349         .f = cmd_config_dcb_parsed,
3350         .data = NULL,
3351         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3352         .tokens = {
3353                 (void *)&cmd_config_dcb_port,
3354                 (void *)&cmd_config_dcb_config,
3355                 (void *)&cmd_config_dcb_port_id,
3356                 (void *)&cmd_config_dcb_dcb,
3357                 (void *)&cmd_config_dcb_vt,
3358                 (void *)&cmd_config_dcb_vt_en,
3359                 (void *)&cmd_config_dcb_num_tcs,
3360                 (void *)&cmd_config_dcb_pfc,
3361                 (void *)&cmd_config_dcb_pfc_en,
3362                 NULL,
3363         },
3364 };
3365
3366 /* *** configure number of packets per burst *** */
3367 struct cmd_config_burst {
3368         cmdline_fixed_string_t port;
3369         cmdline_fixed_string_t keyword;
3370         cmdline_fixed_string_t all;
3371         cmdline_fixed_string_t name;
3372         uint16_t value;
3373 };
3374
3375 static void
3376 cmd_config_burst_parsed(void *parsed_result,
3377                         __rte_unused struct cmdline *cl,
3378                         __rte_unused void *data)
3379 {
3380         struct cmd_config_burst *res = parsed_result;
3381         struct rte_eth_dev_info dev_info;
3382         uint16_t rec_nb_pkts;
3383         int ret;
3384
3385         if (!all_ports_stopped()) {
3386                 fprintf(stderr, "Please stop all ports first\n");
3387                 return;
3388         }
3389
3390         if (!strcmp(res->name, "burst")) {
3391                 if (res->value == 0) {
3392                         /* If user gives a value of zero, query the PMD for
3393                          * its recommended Rx burst size. Testpmd uses a single
3394                          * size for all ports, so assume all ports are the same
3395                          * NIC model and use the values from Port 0.
3396                          */
3397                         ret = eth_dev_info_get_print_err(0, &dev_info);
3398                         if (ret != 0)
3399                                 return;
3400
3401                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3402
3403                         if (rec_nb_pkts == 0) {
3404                                 printf("PMD does not recommend a burst size.\n"
3405                                         "User provided value must be between"
3406                                         " 1 and %d\n", MAX_PKT_BURST);
3407                                 return;
3408                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3409                                 printf("PMD recommended burst size of %d"
3410                                         " exceeds maximum value of %d\n",
3411                                         rec_nb_pkts, MAX_PKT_BURST);
3412                                 return;
3413                         }
3414                         printf("Using PMD-provided burst value of %d\n",
3415                                 rec_nb_pkts);
3416                         nb_pkt_per_burst = rec_nb_pkts;
3417                 } else if (res->value > MAX_PKT_BURST) {
3418                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3419                                 MAX_PKT_BURST);
3420                         return;
3421                 } else
3422                         nb_pkt_per_burst = res->value;
3423         } else {
3424                 fprintf(stderr, "Unknown parameter\n");
3425                 return;
3426         }
3427
3428         init_port_config();
3429
3430         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3431 }
3432
3433 cmdline_parse_token_string_t cmd_config_burst_port =
3434         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3435 cmdline_parse_token_string_t cmd_config_burst_keyword =
3436         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3437 cmdline_parse_token_string_t cmd_config_burst_all =
3438         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3439 cmdline_parse_token_string_t cmd_config_burst_name =
3440         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3441 cmdline_parse_token_num_t cmd_config_burst_value =
3442         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3443
3444 cmdline_parse_inst_t cmd_config_burst = {
3445         .f = cmd_config_burst_parsed,
3446         .data = NULL,
3447         .help_str = "port config all burst <value>",
3448         .tokens = {
3449                 (void *)&cmd_config_burst_port,
3450                 (void *)&cmd_config_burst_keyword,
3451                 (void *)&cmd_config_burst_all,
3452                 (void *)&cmd_config_burst_name,
3453                 (void *)&cmd_config_burst_value,
3454                 NULL,
3455         },
3456 };
3457
3458 /* *** configure rx/tx queues *** */
3459 struct cmd_config_thresh {
3460         cmdline_fixed_string_t port;
3461         cmdline_fixed_string_t keyword;
3462         cmdline_fixed_string_t all;
3463         cmdline_fixed_string_t name;
3464         uint8_t value;
3465 };
3466
3467 static void
3468 cmd_config_thresh_parsed(void *parsed_result,
3469                         __rte_unused struct cmdline *cl,
3470                         __rte_unused void *data)
3471 {
3472         struct cmd_config_thresh *res = parsed_result;
3473
3474         if (!all_ports_stopped()) {
3475                 fprintf(stderr, "Please stop all ports first\n");
3476                 return;
3477         }
3478
3479         if (!strcmp(res->name, "txpt"))
3480                 tx_pthresh = res->value;
3481         else if(!strcmp(res->name, "txht"))
3482                 tx_hthresh = res->value;
3483         else if(!strcmp(res->name, "txwt"))
3484                 tx_wthresh = res->value;
3485         else if(!strcmp(res->name, "rxpt"))
3486                 rx_pthresh = res->value;
3487         else if(!strcmp(res->name, "rxht"))
3488                 rx_hthresh = res->value;
3489         else if(!strcmp(res->name, "rxwt"))
3490                 rx_wthresh = res->value;
3491         else {
3492                 fprintf(stderr, "Unknown parameter\n");
3493                 return;
3494         }
3495
3496         init_port_config();
3497
3498         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3499 }
3500
3501 cmdline_parse_token_string_t cmd_config_thresh_port =
3502         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3503 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3504         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3505 cmdline_parse_token_string_t cmd_config_thresh_all =
3506         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3507 cmdline_parse_token_string_t cmd_config_thresh_name =
3508         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3509                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3510 cmdline_parse_token_num_t cmd_config_thresh_value =
3511         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3512
3513 cmdline_parse_inst_t cmd_config_thresh = {
3514         .f = cmd_config_thresh_parsed,
3515         .data = NULL,
3516         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3517         .tokens = {
3518                 (void *)&cmd_config_thresh_port,
3519                 (void *)&cmd_config_thresh_keyword,
3520                 (void *)&cmd_config_thresh_all,
3521                 (void *)&cmd_config_thresh_name,
3522                 (void *)&cmd_config_thresh_value,
3523                 NULL,
3524         },
3525 };
3526
3527 /* *** configure free/rs threshold *** */
3528 struct cmd_config_threshold {
3529         cmdline_fixed_string_t port;
3530         cmdline_fixed_string_t keyword;
3531         cmdline_fixed_string_t all;
3532         cmdline_fixed_string_t name;
3533         uint16_t value;
3534 };
3535
3536 static void
3537 cmd_config_threshold_parsed(void *parsed_result,
3538                         __rte_unused struct cmdline *cl,
3539                         __rte_unused void *data)
3540 {
3541         struct cmd_config_threshold *res = parsed_result;
3542
3543         if (!all_ports_stopped()) {
3544                 fprintf(stderr, "Please stop all ports first\n");
3545                 return;
3546         }
3547
3548         if (!strcmp(res->name, "txfreet"))
3549                 tx_free_thresh = res->value;
3550         else if (!strcmp(res->name, "txrst"))
3551                 tx_rs_thresh = res->value;
3552         else if (!strcmp(res->name, "rxfreet"))
3553                 rx_free_thresh = res->value;
3554         else {
3555                 fprintf(stderr, "Unknown parameter\n");
3556                 return;
3557         }
3558
3559         init_port_config();
3560
3561         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3562 }
3563
3564 cmdline_parse_token_string_t cmd_config_threshold_port =
3565         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3566 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3567         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3568                                                                 "config");
3569 cmdline_parse_token_string_t cmd_config_threshold_all =
3570         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3571 cmdline_parse_token_string_t cmd_config_threshold_name =
3572         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3573                                                 "txfreet#txrst#rxfreet");
3574 cmdline_parse_token_num_t cmd_config_threshold_value =
3575         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3576
3577 cmdline_parse_inst_t cmd_config_threshold = {
3578         .f = cmd_config_threshold_parsed,
3579         .data = NULL,
3580         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3581         .tokens = {
3582                 (void *)&cmd_config_threshold_port,
3583                 (void *)&cmd_config_threshold_keyword,
3584                 (void *)&cmd_config_threshold_all,
3585                 (void *)&cmd_config_threshold_name,
3586                 (void *)&cmd_config_threshold_value,
3587                 NULL,
3588         },
3589 };
3590
3591 /* *** stop *** */
3592 struct cmd_stop_result {
3593         cmdline_fixed_string_t stop;
3594 };
3595
3596 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3597                             __rte_unused struct cmdline *cl,
3598                             __rte_unused void *data)
3599 {
3600         stop_packet_forwarding();
3601 }
3602
3603 cmdline_parse_token_string_t cmd_stop_stop =
3604         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3605
3606 cmdline_parse_inst_t cmd_stop = {
3607         .f = cmd_stop_parsed,
3608         .data = NULL,
3609         .help_str = "stop: Stop packet forwarding",
3610         .tokens = {
3611                 (void *)&cmd_stop_stop,
3612                 NULL,
3613         },
3614 };
3615
3616 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3617
3618 unsigned int
3619 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3620                 unsigned int *parsed_items, int check_unique_values)
3621 {
3622         unsigned int nb_item;
3623         unsigned int value;
3624         unsigned int i;
3625         unsigned int j;
3626         int value_ok;
3627         char c;
3628
3629         /*
3630          * First parse all items in the list and store their value.
3631          */
3632         value = 0;
3633         nb_item = 0;
3634         value_ok = 0;
3635         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3636                 c = str[i];
3637                 if ((c >= '0') && (c <= '9')) {
3638                         value = (unsigned int) (value * 10 + (c - '0'));
3639                         value_ok = 1;
3640                         continue;
3641                 }
3642                 if (c != ',') {
3643                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3644                         return 0;
3645                 }
3646                 if (! value_ok) {
3647                         fprintf(stderr, "No valid value before comma\n");
3648                         return 0;
3649                 }
3650                 if (nb_item < max_items) {
3651                         parsed_items[nb_item] = value;
3652                         value_ok = 0;
3653                         value = 0;
3654                 }
3655                 nb_item++;
3656         }
3657         if (nb_item >= max_items) {
3658                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3659                         item_name, nb_item + 1, max_items);
3660                 return 0;
3661         }
3662         parsed_items[nb_item++] = value;
3663         if (! check_unique_values)
3664                 return nb_item;
3665
3666         /*
3667          * Then, check that all values in the list are different.
3668          * No optimization here...
3669          */
3670         for (i = 0; i < nb_item; i++) {
3671                 for (j = i + 1; j < nb_item; j++) {
3672                         if (parsed_items[j] == parsed_items[i]) {
3673                                 fprintf(stderr,
3674                                         "duplicated %s %u at index %u and %u\n",
3675                                         item_name, parsed_items[i], i, j);
3676                                 return 0;
3677                         }
3678                 }
3679         }
3680         return nb_item;
3681 }
3682
3683 struct cmd_set_list_result {
3684         cmdline_fixed_string_t cmd_keyword;
3685         cmdline_fixed_string_t list_name;
3686         cmdline_fixed_string_t list_of_items;
3687 };
3688
3689 static void cmd_set_list_parsed(void *parsed_result,
3690                                 __rte_unused struct cmdline *cl,
3691                                 __rte_unused void *data)
3692 {
3693         struct cmd_set_list_result *res;
3694         union {
3695                 unsigned int lcorelist[RTE_MAX_LCORE];
3696                 unsigned int portlist[RTE_MAX_ETHPORTS];
3697         } parsed_items;
3698         unsigned int nb_item;
3699
3700         if (test_done == 0) {
3701                 fprintf(stderr, "Please stop forwarding first\n");
3702                 return;
3703         }
3704
3705         res = parsed_result;
3706         if (!strcmp(res->list_name, "corelist")) {
3707                 nb_item = parse_item_list(res->list_of_items, "core",
3708                                           RTE_MAX_LCORE,
3709                                           parsed_items.lcorelist, 1);
3710                 if (nb_item > 0) {
3711                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3712                         fwd_config_setup();
3713                 }
3714                 return;
3715         }
3716         if (!strcmp(res->list_name, "portlist")) {
3717                 nb_item = parse_item_list(res->list_of_items, "port",
3718                                           RTE_MAX_ETHPORTS,
3719                                           parsed_items.portlist, 1);
3720                 if (nb_item > 0) {
3721                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3722                         fwd_config_setup();
3723                 }
3724         }
3725 }
3726
3727 cmdline_parse_token_string_t cmd_set_list_keyword =
3728         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3729                                  "set");
3730 cmdline_parse_token_string_t cmd_set_list_name =
3731         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3732                                  "corelist#portlist");
3733 cmdline_parse_token_string_t cmd_set_list_of_items =
3734         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3735                                  NULL);
3736
3737 cmdline_parse_inst_t cmd_set_fwd_list = {
3738         .f = cmd_set_list_parsed,
3739         .data = NULL,
3740         .help_str = "set corelist|portlist <list0[,list1]*>",
3741         .tokens = {
3742                 (void *)&cmd_set_list_keyword,
3743                 (void *)&cmd_set_list_name,
3744                 (void *)&cmd_set_list_of_items,
3745                 NULL,
3746         },
3747 };
3748
3749 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3750
3751 struct cmd_setmask_result {
3752         cmdline_fixed_string_t set;
3753         cmdline_fixed_string_t mask;
3754         uint64_t hexavalue;
3755 };
3756
3757 static void cmd_set_mask_parsed(void *parsed_result,
3758                                 __rte_unused struct cmdline *cl,
3759                                 __rte_unused void *data)
3760 {
3761         struct cmd_setmask_result *res = parsed_result;
3762
3763         if (test_done == 0) {
3764                 fprintf(stderr, "Please stop forwarding first\n");
3765                 return;
3766         }
3767         if (!strcmp(res->mask, "coremask")) {
3768                 set_fwd_lcores_mask(res->hexavalue);
3769                 fwd_config_setup();
3770         } else if (!strcmp(res->mask, "portmask")) {
3771                 set_fwd_ports_mask(res->hexavalue);
3772                 fwd_config_setup();
3773         }
3774 }
3775
3776 cmdline_parse_token_string_t cmd_setmask_set =
3777         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3778 cmdline_parse_token_string_t cmd_setmask_mask =
3779         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3780                                  "coremask#portmask");
3781 cmdline_parse_token_num_t cmd_setmask_value =
3782         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3783
3784 cmdline_parse_inst_t cmd_set_fwd_mask = {
3785         .f = cmd_set_mask_parsed,
3786         .data = NULL,
3787         .help_str = "set coremask|portmask <hexadecimal value>",
3788         .tokens = {
3789                 (void *)&cmd_setmask_set,
3790                 (void *)&cmd_setmask_mask,
3791                 (void *)&cmd_setmask_value,
3792                 NULL,
3793         },
3794 };
3795
3796 /*
3797  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3798  */
3799 struct cmd_set_result {
3800         cmdline_fixed_string_t set;
3801         cmdline_fixed_string_t what;
3802         uint16_t value;
3803 };
3804
3805 static void cmd_set_parsed(void *parsed_result,
3806                            __rte_unused struct cmdline *cl,
3807                            __rte_unused void *data)
3808 {
3809         struct cmd_set_result *res = parsed_result;
3810         if (!strcmp(res->what, "nbport")) {
3811                 set_fwd_ports_number(res->value);
3812                 fwd_config_setup();
3813         } else if (!strcmp(res->what, "nbcore")) {
3814                 set_fwd_lcores_number(res->value);
3815                 fwd_config_setup();
3816         } else if (!strcmp(res->what, "burst"))
3817                 set_nb_pkt_per_burst(res->value);
3818         else if (!strcmp(res->what, "verbose"))
3819                 set_verbose_level(res->value);
3820 }
3821
3822 cmdline_parse_token_string_t cmd_set_set =
3823         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3824 cmdline_parse_token_string_t cmd_set_what =
3825         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3826                                  "nbport#nbcore#burst#verbose");
3827 cmdline_parse_token_num_t cmd_set_value =
3828         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3829
3830 cmdline_parse_inst_t cmd_set_numbers = {
3831         .f = cmd_set_parsed,
3832         .data = NULL,
3833         .help_str = "set nbport|nbcore|burst|verbose <value>",
3834         .tokens = {
3835                 (void *)&cmd_set_set,
3836                 (void *)&cmd_set_what,
3837                 (void *)&cmd_set_value,
3838                 NULL,
3839         },
3840 };
3841
3842 /* *** SET LOG LEVEL CONFIGURATION *** */
3843
3844 struct cmd_set_log_result {
3845         cmdline_fixed_string_t set;
3846         cmdline_fixed_string_t log;
3847         cmdline_fixed_string_t type;
3848         uint32_t level;
3849 };
3850
3851 static void
3852 cmd_set_log_parsed(void *parsed_result,
3853                    __rte_unused struct cmdline *cl,
3854                    __rte_unused void *data)
3855 {
3856         struct cmd_set_log_result *res;
3857         int ret;
3858
3859         res = parsed_result;
3860         if (!strcmp(res->type, "global"))
3861                 rte_log_set_global_level(res->level);
3862         else {
3863                 ret = rte_log_set_level_regexp(res->type, res->level);
3864                 if (ret < 0)
3865                         fprintf(stderr, "Unable to set log level\n");
3866         }
3867 }
3868
3869 cmdline_parse_token_string_t cmd_set_log_set =
3870         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3871 cmdline_parse_token_string_t cmd_set_log_log =
3872         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3873 cmdline_parse_token_string_t cmd_set_log_type =
3874         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3875 cmdline_parse_token_num_t cmd_set_log_level =
3876         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3877
3878 cmdline_parse_inst_t cmd_set_log = {
3879         .f = cmd_set_log_parsed,
3880         .data = NULL,
3881         .help_str = "set log global|<type> <level>",
3882         .tokens = {
3883                 (void *)&cmd_set_log_set,
3884                 (void *)&cmd_set_log_log,
3885                 (void *)&cmd_set_log_type,
3886                 (void *)&cmd_set_log_level,
3887                 NULL,
3888         },
3889 };
3890
3891 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3892
3893 struct cmd_set_rxoffs_result {
3894         cmdline_fixed_string_t cmd_keyword;
3895         cmdline_fixed_string_t rxoffs;
3896         cmdline_fixed_string_t seg_offsets;
3897 };
3898
3899 static void
3900 cmd_set_rxoffs_parsed(void *parsed_result,
3901                       __rte_unused struct cmdline *cl,
3902                       __rte_unused void *data)
3903 {
3904         struct cmd_set_rxoffs_result *res;
3905         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3906         unsigned int nb_segs;
3907
3908         res = parsed_result;
3909         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3910                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3911         if (nb_segs > 0)
3912                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3913         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3914 }
3915
3916 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3917         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3918                                  cmd_keyword, "set");
3919 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3920         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3921                                  rxoffs, "rxoffs");
3922 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3923         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3924                                  seg_offsets, NULL);
3925
3926 cmdline_parse_inst_t cmd_set_rxoffs = {
3927         .f = cmd_set_rxoffs_parsed,
3928         .data = NULL,
3929         .help_str = "set rxoffs <len0[,len1]*>",
3930         .tokens = {
3931                 (void *)&cmd_set_rxoffs_keyword,
3932                 (void *)&cmd_set_rxoffs_name,
3933                 (void *)&cmd_set_rxoffs_offsets,
3934                 NULL,
3935         },
3936 };
3937
3938 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3939
3940 struct cmd_set_rxpkts_result {
3941         cmdline_fixed_string_t cmd_keyword;
3942         cmdline_fixed_string_t rxpkts;
3943         cmdline_fixed_string_t seg_lengths;
3944 };
3945
3946 static void
3947 cmd_set_rxpkts_parsed(void *parsed_result,
3948                       __rte_unused struct cmdline *cl,
3949                       __rte_unused void *data)
3950 {
3951         struct cmd_set_rxpkts_result *res;
3952         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3953         unsigned int nb_segs;
3954
3955         res = parsed_result;
3956         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3957                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3958         if (nb_segs > 0)
3959                 set_rx_pkt_segments(seg_lengths, nb_segs);
3960         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3961 }
3962
3963 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3964         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3965                                  cmd_keyword, "set");
3966 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3967         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3968                                  rxpkts, "rxpkts");
3969 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3970         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3971                                  seg_lengths, NULL);
3972
3973 cmdline_parse_inst_t cmd_set_rxpkts = {
3974         .f = cmd_set_rxpkts_parsed,
3975         .data = NULL,
3976         .help_str = "set rxpkts <len0[,len1]*>",
3977         .tokens = {
3978                 (void *)&cmd_set_rxpkts_keyword,
3979                 (void *)&cmd_set_rxpkts_name,
3980                 (void *)&cmd_set_rxpkts_lengths,
3981                 NULL,
3982         },
3983 };
3984
3985 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3986
3987 struct cmd_set_txpkts_result {
3988         cmdline_fixed_string_t cmd_keyword;
3989         cmdline_fixed_string_t txpkts;
3990         cmdline_fixed_string_t seg_lengths;
3991 };
3992
3993 static void
3994 cmd_set_txpkts_parsed(void *parsed_result,
3995                       __rte_unused struct cmdline *cl,
3996                       __rte_unused void *data)
3997 {
3998         struct cmd_set_txpkts_result *res;
3999         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4000         unsigned int nb_segs;
4001
4002         res = parsed_result;
4003         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4004                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4005         if (nb_segs > 0)
4006                 set_tx_pkt_segments(seg_lengths, nb_segs);
4007 }
4008
4009 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4010         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4011                                  cmd_keyword, "set");
4012 cmdline_parse_token_string_t cmd_set_txpkts_name =
4013         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4014                                  txpkts, "txpkts");
4015 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4016         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4017                                  seg_lengths, NULL);
4018
4019 cmdline_parse_inst_t cmd_set_txpkts = {
4020         .f = cmd_set_txpkts_parsed,
4021         .data = NULL,
4022         .help_str = "set txpkts <len0[,len1]*>",
4023         .tokens = {
4024                 (void *)&cmd_set_txpkts_keyword,
4025                 (void *)&cmd_set_txpkts_name,
4026                 (void *)&cmd_set_txpkts_lengths,
4027                 NULL,
4028         },
4029 };
4030
4031 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4032
4033 struct cmd_set_txsplit_result {
4034         cmdline_fixed_string_t cmd_keyword;
4035         cmdline_fixed_string_t txsplit;
4036         cmdline_fixed_string_t mode;
4037 };
4038
4039 static void
4040 cmd_set_txsplit_parsed(void *parsed_result,
4041                       __rte_unused struct cmdline *cl,
4042                       __rte_unused void *data)
4043 {
4044         struct cmd_set_txsplit_result *res;
4045
4046         res = parsed_result;
4047         set_tx_pkt_split(res->mode);
4048 }
4049
4050 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4051         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4052                                  cmd_keyword, "set");
4053 cmdline_parse_token_string_t cmd_set_txsplit_name =
4054         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4055                                  txsplit, "txsplit");
4056 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4057         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4058                                  mode, NULL);
4059
4060 cmdline_parse_inst_t cmd_set_txsplit = {
4061         .f = cmd_set_txsplit_parsed,
4062         .data = NULL,
4063         .help_str = "set txsplit on|off|rand",
4064         .tokens = {
4065                 (void *)&cmd_set_txsplit_keyword,
4066                 (void *)&cmd_set_txsplit_name,
4067                 (void *)&cmd_set_txsplit_mode,
4068                 NULL,
4069         },
4070 };
4071
4072 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4073
4074 struct cmd_set_txtimes_result {
4075         cmdline_fixed_string_t cmd_keyword;
4076         cmdline_fixed_string_t txtimes;
4077         cmdline_fixed_string_t tx_times;
4078 };
4079
4080 static void
4081 cmd_set_txtimes_parsed(void *parsed_result,
4082                        __rte_unused struct cmdline *cl,
4083                        __rte_unused void *data)
4084 {
4085         struct cmd_set_txtimes_result *res;
4086         unsigned int tx_times[2] = {0, 0};
4087         unsigned int n_times;
4088
4089         res = parsed_result;
4090         n_times = parse_item_list(res->tx_times, "tx times",
4091                                   2, tx_times, 0);
4092         if (n_times == 2)
4093                 set_tx_pkt_times(tx_times);
4094 }
4095
4096 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4097         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4098                                  cmd_keyword, "set");
4099 cmdline_parse_token_string_t cmd_set_txtimes_name =
4100         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4101                                  txtimes, "txtimes");
4102 cmdline_parse_token_string_t cmd_set_txtimes_value =
4103         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4104                                  tx_times, NULL);
4105
4106 cmdline_parse_inst_t cmd_set_txtimes = {
4107         .f = cmd_set_txtimes_parsed,
4108         .data = NULL,
4109         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4110         .tokens = {
4111                 (void *)&cmd_set_txtimes_keyword,
4112                 (void *)&cmd_set_txtimes_name,
4113                 (void *)&cmd_set_txtimes_value,
4114                 NULL,
4115         },
4116 };
4117
4118 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4119 struct cmd_rx_vlan_filter_all_result {
4120         cmdline_fixed_string_t rx_vlan;
4121         cmdline_fixed_string_t what;
4122         cmdline_fixed_string_t all;
4123         portid_t port_id;
4124 };
4125
4126 static void
4127 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4128                               __rte_unused struct cmdline *cl,
4129                               __rte_unused void *data)
4130 {
4131         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4132
4133         if (!strcmp(res->what, "add"))
4134                 rx_vlan_all_filter_set(res->port_id, 1);
4135         else
4136                 rx_vlan_all_filter_set(res->port_id, 0);
4137 }
4138
4139 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4140         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4141                                  rx_vlan, "rx_vlan");
4142 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4143         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4144                                  what, "add#rm");
4145 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4146         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4147                                  all, "all");
4148 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4149         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4150                               port_id, RTE_UINT16);
4151
4152 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4153         .f = cmd_rx_vlan_filter_all_parsed,
4154         .data = NULL,
4155         .help_str = "rx_vlan add|rm all <port_id>: "
4156                 "Add/Remove all identifiers to/from the set of VLAN "
4157                 "identifiers filtered by a port",
4158         .tokens = {
4159                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4160                 (void *)&cmd_rx_vlan_filter_all_what,
4161                 (void *)&cmd_rx_vlan_filter_all_all,
4162                 (void *)&cmd_rx_vlan_filter_all_portid,
4163                 NULL,
4164         },
4165 };
4166
4167 /* *** VLAN OFFLOAD SET ON A PORT *** */
4168 struct cmd_vlan_offload_result {
4169         cmdline_fixed_string_t vlan;
4170         cmdline_fixed_string_t set;
4171         cmdline_fixed_string_t vlan_type;
4172         cmdline_fixed_string_t what;
4173         cmdline_fixed_string_t on;
4174         cmdline_fixed_string_t port_id;
4175 };
4176
4177 static void
4178 cmd_vlan_offload_parsed(void *parsed_result,
4179                           __rte_unused struct cmdline *cl,
4180                           __rte_unused void *data)
4181 {
4182         int on;
4183         struct cmd_vlan_offload_result *res = parsed_result;
4184         char *str;
4185         int i, len = 0;
4186         portid_t port_id = 0;
4187         unsigned int tmp;
4188
4189         str = res->port_id;
4190         len = strnlen(str, STR_TOKEN_SIZE);
4191         i = 0;
4192         /* Get port_id first */
4193         while(i < len){
4194                 if(str[i] == ',')
4195                         break;
4196
4197                 i++;
4198         }
4199         str[i]='\0';
4200         tmp = strtoul(str, NULL, 0);
4201         /* If port_id greater that what portid_t can represent, return */
4202         if(tmp >= RTE_MAX_ETHPORTS)
4203                 return;
4204         port_id = (portid_t)tmp;
4205
4206         if (!strcmp(res->on, "on"))
4207                 on = 1;
4208         else
4209                 on = 0;
4210
4211         if (!strcmp(res->what, "strip"))
4212                 rx_vlan_strip_set(port_id,  on);
4213         else if(!strcmp(res->what, "stripq")){
4214                 uint16_t queue_id = 0;
4215
4216                 /* No queue_id, return */
4217                 if(i + 1 >= len) {
4218                         fprintf(stderr, "must specify (port,queue_id)\n");
4219                         return;
4220                 }
4221                 tmp = strtoul(str + i + 1, NULL, 0);
4222                 /* If queue_id greater that what 16-bits can represent, return */
4223                 if(tmp > 0xffff)
4224                         return;
4225
4226                 queue_id = (uint16_t)tmp;
4227                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4228         }
4229         else if (!strcmp(res->what, "filter"))
4230                 rx_vlan_filter_set(port_id, on);
4231         else if (!strcmp(res->what, "qinq_strip"))
4232                 rx_vlan_qinq_strip_set(port_id, on);
4233         else
4234                 vlan_extend_set(port_id, on);
4235
4236         return;
4237 }
4238
4239 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4240         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4241                                  vlan, "vlan");
4242 cmdline_parse_token_string_t cmd_vlan_offload_set =
4243         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4244                                  set, "set");
4245 cmdline_parse_token_string_t cmd_vlan_offload_what =
4246         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4247                                 what, "strip#filter#qinq_strip#extend#stripq");
4248 cmdline_parse_token_string_t cmd_vlan_offload_on =
4249         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4250                               on, "on#off");
4251 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4252         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4253                               port_id, NULL);
4254
4255 cmdline_parse_inst_t cmd_vlan_offload = {
4256         .f = cmd_vlan_offload_parsed,
4257         .data = NULL,
4258         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4259                 "<port_id[,queue_id]>: "
4260                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4261         .tokens = {
4262                 (void *)&cmd_vlan_offload_vlan,
4263                 (void *)&cmd_vlan_offload_set,
4264                 (void *)&cmd_vlan_offload_what,
4265                 (void *)&cmd_vlan_offload_on,
4266                 (void *)&cmd_vlan_offload_portid,
4267                 NULL,
4268         },
4269 };
4270
4271 /* *** VLAN TPID SET ON A PORT *** */
4272 struct cmd_vlan_tpid_result {
4273         cmdline_fixed_string_t vlan;
4274         cmdline_fixed_string_t set;
4275         cmdline_fixed_string_t vlan_type;
4276         cmdline_fixed_string_t what;
4277         uint16_t tp_id;
4278         portid_t port_id;
4279 };
4280
4281 static void
4282 cmd_vlan_tpid_parsed(void *parsed_result,
4283                           __rte_unused struct cmdline *cl,
4284                           __rte_unused void *data)
4285 {
4286         struct cmd_vlan_tpid_result *res = parsed_result;
4287         enum rte_vlan_type vlan_type;
4288
4289         if (!strcmp(res->vlan_type, "inner"))
4290                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4291         else if (!strcmp(res->vlan_type, "outer"))
4292                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4293         else {
4294                 fprintf(stderr, "Unknown vlan type\n");
4295                 return;
4296         }
4297         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4298 }
4299
4300 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4301         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4302                                  vlan, "vlan");
4303 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4304         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4305                                  set, "set");
4306 cmdline_parse_token_string_t cmd_vlan_type =
4307         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4308                                  vlan_type, "inner#outer");
4309 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4310         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4311                                  what, "tpid");
4312 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4313         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4314                               tp_id, RTE_UINT16);
4315 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4316         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4317                               port_id, RTE_UINT16);
4318
4319 cmdline_parse_inst_t cmd_vlan_tpid = {
4320         .f = cmd_vlan_tpid_parsed,
4321         .data = NULL,
4322         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4323                 "Set the VLAN Ether type",
4324         .tokens = {
4325                 (void *)&cmd_vlan_tpid_vlan,
4326                 (void *)&cmd_vlan_tpid_set,
4327                 (void *)&cmd_vlan_type,
4328                 (void *)&cmd_vlan_tpid_what,
4329                 (void *)&cmd_vlan_tpid_tpid,
4330                 (void *)&cmd_vlan_tpid_portid,
4331                 NULL,
4332         },
4333 };
4334
4335 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4336 struct cmd_rx_vlan_filter_result {
4337         cmdline_fixed_string_t rx_vlan;
4338         cmdline_fixed_string_t what;
4339         uint16_t vlan_id;
4340         portid_t port_id;
4341 };
4342
4343 static void
4344 cmd_rx_vlan_filter_parsed(void *parsed_result,
4345                           __rte_unused struct cmdline *cl,
4346                           __rte_unused void *data)
4347 {
4348         struct cmd_rx_vlan_filter_result *res = parsed_result;
4349
4350         if (!strcmp(res->what, "add"))
4351                 rx_vft_set(res->port_id, res->vlan_id, 1);
4352         else
4353                 rx_vft_set(res->port_id, res->vlan_id, 0);
4354 }
4355
4356 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4357         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4358                                  rx_vlan, "rx_vlan");
4359 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4360         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4361                                  what, "add#rm");
4362 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4363         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4364                               vlan_id, RTE_UINT16);
4365 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4366         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4367                               port_id, RTE_UINT16);
4368
4369 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4370         .f = cmd_rx_vlan_filter_parsed,
4371         .data = NULL,
4372         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4373                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4374                 "identifiers filtered by a port",
4375         .tokens = {
4376                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4377                 (void *)&cmd_rx_vlan_filter_what,
4378                 (void *)&cmd_rx_vlan_filter_vlanid,
4379                 (void *)&cmd_rx_vlan_filter_portid,
4380                 NULL,
4381         },
4382 };
4383
4384 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4385 struct cmd_tx_vlan_set_result {
4386         cmdline_fixed_string_t tx_vlan;
4387         cmdline_fixed_string_t set;
4388         portid_t port_id;
4389         uint16_t vlan_id;
4390 };
4391
4392 static void
4393 cmd_tx_vlan_set_parsed(void *parsed_result,
4394                        __rte_unused struct cmdline *cl,
4395                        __rte_unused void *data)
4396 {
4397         struct cmd_tx_vlan_set_result *res = parsed_result;
4398
4399         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4400                 return;
4401
4402         if (!port_is_stopped(res->port_id)) {
4403                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4404                 return;
4405         }
4406
4407         tx_vlan_set(res->port_id, res->vlan_id);
4408
4409         cmd_reconfig_device_queue(res->port_id, 1, 1);
4410 }
4411
4412 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4413         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4414                                  tx_vlan, "tx_vlan");
4415 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4416         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4417                                  set, "set");
4418 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4419         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4420                               port_id, RTE_UINT16);
4421 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4422         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4423                               vlan_id, RTE_UINT16);
4424
4425 cmdline_parse_inst_t cmd_tx_vlan_set = {
4426         .f = cmd_tx_vlan_set_parsed,
4427         .data = NULL,
4428         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4429                 "Enable hardware insertion of a single VLAN header "
4430                 "with a given TAG Identifier in packets sent on a port",
4431         .tokens = {
4432                 (void *)&cmd_tx_vlan_set_tx_vlan,
4433                 (void *)&cmd_tx_vlan_set_set,
4434                 (void *)&cmd_tx_vlan_set_portid,
4435                 (void *)&cmd_tx_vlan_set_vlanid,
4436                 NULL,
4437         },
4438 };
4439
4440 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4441 struct cmd_tx_vlan_set_qinq_result {
4442         cmdline_fixed_string_t tx_vlan;
4443         cmdline_fixed_string_t set;
4444         portid_t port_id;
4445         uint16_t vlan_id;
4446         uint16_t vlan_id_outer;
4447 };
4448
4449 static void
4450 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4451                             __rte_unused struct cmdline *cl,
4452                             __rte_unused void *data)
4453 {
4454         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4455
4456         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4457                 return;
4458
4459         if (!port_is_stopped(res->port_id)) {
4460                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4461                 return;
4462         }
4463
4464         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4465
4466         cmd_reconfig_device_queue(res->port_id, 1, 1);
4467 }
4468
4469 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4470         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4471                 tx_vlan, "tx_vlan");
4472 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4473         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4474                 set, "set");
4475 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4476         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4477                 port_id, RTE_UINT16);
4478 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4479         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4480                 vlan_id, RTE_UINT16);
4481 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4482         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4483                 vlan_id_outer, RTE_UINT16);
4484
4485 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4486         .f = cmd_tx_vlan_set_qinq_parsed,
4487         .data = NULL,
4488         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4489                 "Enable hardware insertion of double VLAN header "
4490                 "with given TAG Identifiers in packets sent on a port",
4491         .tokens = {
4492                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4493                 (void *)&cmd_tx_vlan_set_qinq_set,
4494                 (void *)&cmd_tx_vlan_set_qinq_portid,
4495                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4496                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4497                 NULL,
4498         },
4499 };
4500
4501 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4502 struct cmd_tx_vlan_set_pvid_result {
4503         cmdline_fixed_string_t tx_vlan;
4504         cmdline_fixed_string_t set;
4505         cmdline_fixed_string_t pvid;
4506         portid_t port_id;
4507         uint16_t vlan_id;
4508         cmdline_fixed_string_t mode;
4509 };
4510
4511 static void
4512 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4513                             __rte_unused struct cmdline *cl,
4514                             __rte_unused void *data)
4515 {
4516         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4517
4518         if (strcmp(res->mode, "on") == 0)
4519                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4520         else
4521                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4522 }
4523
4524 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4525         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4526                                  tx_vlan, "tx_vlan");
4527 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4528         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4529                                  set, "set");
4530 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4531         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4532                                  pvid, "pvid");
4533 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4534         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4535                              port_id, RTE_UINT16);
4536 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4537         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4538                               vlan_id, RTE_UINT16);
4539 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4540         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4541                                  mode, "on#off");
4542
4543 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4544         .f = cmd_tx_vlan_set_pvid_parsed,
4545         .data = NULL,
4546         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4547         .tokens = {
4548                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4549                 (void *)&cmd_tx_vlan_set_pvid_set,
4550                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4551                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4552                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4553                 (void *)&cmd_tx_vlan_set_pvid_mode,
4554                 NULL,
4555         },
4556 };
4557
4558 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4559 struct cmd_tx_vlan_reset_result {
4560         cmdline_fixed_string_t tx_vlan;
4561         cmdline_fixed_string_t reset;
4562         portid_t port_id;
4563 };
4564
4565 static void
4566 cmd_tx_vlan_reset_parsed(void *parsed_result,
4567                          __rte_unused struct cmdline *cl,
4568                          __rte_unused void *data)
4569 {
4570         struct cmd_tx_vlan_reset_result *res = parsed_result;
4571
4572         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4573                 return;
4574
4575         if (!port_is_stopped(res->port_id)) {
4576                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4577                 return;
4578         }
4579
4580         tx_vlan_reset(res->port_id);
4581
4582         cmd_reconfig_device_queue(res->port_id, 1, 1);
4583 }
4584
4585 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4586         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4587                                  tx_vlan, "tx_vlan");
4588 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4589         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4590                                  reset, "reset");
4591 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4592         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4593                               port_id, RTE_UINT16);
4594
4595 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4596         .f = cmd_tx_vlan_reset_parsed,
4597         .data = NULL,
4598         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4599                 "VLAN header in packets sent on a port",
4600         .tokens = {
4601                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4602                 (void *)&cmd_tx_vlan_reset_reset,
4603                 (void *)&cmd_tx_vlan_reset_portid,
4604                 NULL,
4605         },
4606 };
4607
4608
4609 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4610 struct cmd_csum_result {
4611         cmdline_fixed_string_t csum;
4612         cmdline_fixed_string_t mode;
4613         cmdline_fixed_string_t proto;
4614         cmdline_fixed_string_t hwsw;
4615         portid_t port_id;
4616 };
4617
4618 static void
4619 csum_show(int port_id)
4620 {
4621         struct rte_eth_dev_info dev_info;
4622         uint64_t tx_offloads;
4623         int ret;
4624
4625         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4626         printf("Parse tunnel is %s\n",
4627                 (ports[port_id].parse_tunnel) ? "on" : "off");
4628         printf("IP checksum offload is %s\n",
4629                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4630         printf("UDP checksum offload is %s\n",
4631                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4632         printf("TCP checksum offload is %s\n",
4633                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4634         printf("SCTP checksum offload is %s\n",
4635                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4636         printf("Outer-Ip checksum offload is %s\n",
4637                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4638         printf("Outer-Udp checksum offload is %s\n",
4639                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4640
4641         /* display warnings if configuration is not supported by the NIC */
4642         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4643         if (ret != 0)
4644                 return;
4645
4646         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4647                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4648                 fprintf(stderr,
4649                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4650                         port_id);
4651         }
4652         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4653                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4654                 fprintf(stderr,
4655                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4656                         port_id);
4657         }
4658         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4659                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4660                 fprintf(stderr,
4661                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4662                         port_id);
4663         }
4664         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4665                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4666                 fprintf(stderr,
4667                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4668                         port_id);
4669         }
4670         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4671                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4672                 fprintf(stderr,
4673                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4674                         port_id);
4675         }
4676         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4677                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4678                         == 0) {
4679                 fprintf(stderr,
4680                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4681                         port_id);
4682         }
4683 }
4684
4685 static void
4686 cmd_config_queue_tx_offloads(struct rte_port *port)
4687 {
4688         int k;
4689
4690         /* Apply queue tx offloads configuration */
4691         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4692                 port->tx_conf[k].offloads =
4693                         port->dev_conf.txmode.offloads;
4694 }
4695
4696 static void
4697 cmd_csum_parsed(void *parsed_result,
4698                        __rte_unused struct cmdline *cl,
4699                        __rte_unused void *data)
4700 {
4701         struct cmd_csum_result *res = parsed_result;
4702         int hw = 0;
4703         uint64_t csum_offloads = 0;
4704         struct rte_eth_dev_info dev_info;
4705         int ret;
4706
4707         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4708                 fprintf(stderr, "invalid port %d\n", res->port_id);
4709                 return;
4710         }
4711         if (!port_is_stopped(res->port_id)) {
4712                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4713                 return;
4714         }
4715
4716         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4717         if (ret != 0)
4718                 return;
4719
4720         if (!strcmp(res->mode, "set")) {
4721
4722                 if (!strcmp(res->hwsw, "hw"))
4723                         hw = 1;
4724
4725                 if (!strcmp(res->proto, "ip")) {
4726                         if (hw == 0 || (dev_info.tx_offload_capa &
4727                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4728                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4729                         } else {
4730                                 fprintf(stderr,
4731                                         "IP checksum offload is not supported by port %u\n",
4732                                         res->port_id);
4733                         }
4734                 } else if (!strcmp(res->proto, "udp")) {
4735                         if (hw == 0 || (dev_info.tx_offload_capa &
4736                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4737                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4738                         } else {
4739                                 fprintf(stderr,
4740                                         "UDP checksum offload is not supported by port %u\n",
4741                                         res->port_id);
4742                         }
4743                 } else if (!strcmp(res->proto, "tcp")) {
4744                         if (hw == 0 || (dev_info.tx_offload_capa &
4745                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4746                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4747                         } else {
4748                                 fprintf(stderr,
4749                                         "TCP checksum offload is not supported by port %u\n",
4750                                         res->port_id);
4751                         }
4752                 } else if (!strcmp(res->proto, "sctp")) {
4753                         if (hw == 0 || (dev_info.tx_offload_capa &
4754                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4755                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4756                         } else {
4757                                 fprintf(stderr,
4758                                         "SCTP checksum offload is not supported by port %u\n",
4759                                         res->port_id);
4760                         }
4761                 } else if (!strcmp(res->proto, "outer-ip")) {
4762                         if (hw == 0 || (dev_info.tx_offload_capa &
4763                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4764                                 csum_offloads |=
4765                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4766                         } else {
4767                                 fprintf(stderr,
4768                                         "Outer IP checksum offload is not supported by port %u\n",
4769                                         res->port_id);
4770                         }
4771                 } else if (!strcmp(res->proto, "outer-udp")) {
4772                         if (hw == 0 || (dev_info.tx_offload_capa &
4773                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4774                                 csum_offloads |=
4775                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4776                         } else {
4777                                 fprintf(stderr,
4778                                         "Outer UDP checksum offload is not supported by port %u\n",
4779                                         res->port_id);
4780                         }
4781                 }
4782
4783                 if (hw) {
4784                         ports[res->port_id].dev_conf.txmode.offloads |=
4785                                                         csum_offloads;
4786                 } else {
4787                         ports[res->port_id].dev_conf.txmode.offloads &=
4788                                                         (~csum_offloads);
4789                 }
4790                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4791         }
4792         csum_show(res->port_id);
4793
4794         cmd_reconfig_device_queue(res->port_id, 1, 1);
4795 }
4796
4797 cmdline_parse_token_string_t cmd_csum_csum =
4798         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4799                                 csum, "csum");
4800 cmdline_parse_token_string_t cmd_csum_mode =
4801         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4802                                 mode, "set");
4803 cmdline_parse_token_string_t cmd_csum_proto =
4804         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4805                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4806 cmdline_parse_token_string_t cmd_csum_hwsw =
4807         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4808                                 hwsw, "hw#sw");
4809 cmdline_parse_token_num_t cmd_csum_portid =
4810         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4811                                 port_id, RTE_UINT16);
4812
4813 cmdline_parse_inst_t cmd_csum_set = {
4814         .f = cmd_csum_parsed,
4815         .data = NULL,
4816         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4817                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4818                 "using csum forward engine",
4819         .tokens = {
4820                 (void *)&cmd_csum_csum,
4821                 (void *)&cmd_csum_mode,
4822                 (void *)&cmd_csum_proto,
4823                 (void *)&cmd_csum_hwsw,
4824                 (void *)&cmd_csum_portid,
4825                 NULL,
4826         },
4827 };
4828
4829 cmdline_parse_token_string_t cmd_csum_mode_show =
4830         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4831                                 mode, "show");
4832
4833 cmdline_parse_inst_t cmd_csum_show = {
4834         .f = cmd_csum_parsed,
4835         .data = NULL,
4836         .help_str = "csum show <port_id>: Show checksum offload configuration",
4837         .tokens = {
4838                 (void *)&cmd_csum_csum,
4839                 (void *)&cmd_csum_mode_show,
4840                 (void *)&cmd_csum_portid,
4841                 NULL,
4842         },
4843 };
4844
4845 /* Enable/disable tunnel parsing */
4846 struct cmd_csum_tunnel_result {
4847         cmdline_fixed_string_t csum;
4848         cmdline_fixed_string_t parse;
4849         cmdline_fixed_string_t onoff;
4850         portid_t port_id;
4851 };
4852
4853 static void
4854 cmd_csum_tunnel_parsed(void *parsed_result,
4855                        __rte_unused struct cmdline *cl,
4856                        __rte_unused void *data)
4857 {
4858         struct cmd_csum_tunnel_result *res = parsed_result;
4859
4860         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4861                 return;
4862
4863         if (!strcmp(res->onoff, "on"))
4864                 ports[res->port_id].parse_tunnel = 1;
4865         else
4866                 ports[res->port_id].parse_tunnel = 0;
4867
4868         csum_show(res->port_id);
4869 }
4870
4871 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4872         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4873                                 csum, "csum");
4874 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4875         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4876                                 parse, "parse-tunnel");
4877 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4878         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4879                                 onoff, "on#off");
4880 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4881         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4882                                 port_id, RTE_UINT16);
4883
4884 cmdline_parse_inst_t cmd_csum_tunnel = {
4885         .f = cmd_csum_tunnel_parsed,
4886         .data = NULL,
4887         .help_str = "csum parse-tunnel on|off <port_id>: "
4888                 "Enable/Disable parsing of tunnels for csum engine",
4889         .tokens = {
4890                 (void *)&cmd_csum_tunnel_csum,
4891                 (void *)&cmd_csum_tunnel_parse,
4892                 (void *)&cmd_csum_tunnel_onoff,
4893                 (void *)&cmd_csum_tunnel_portid,
4894                 NULL,
4895         },
4896 };
4897
4898 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4899 struct cmd_tso_set_result {
4900         cmdline_fixed_string_t tso;
4901         cmdline_fixed_string_t mode;
4902         uint16_t tso_segsz;
4903         portid_t port_id;
4904 };
4905
4906 static void
4907 cmd_tso_set_parsed(void *parsed_result,
4908                        __rte_unused struct cmdline *cl,
4909                        __rte_unused void *data)
4910 {
4911         struct cmd_tso_set_result *res = parsed_result;
4912         struct rte_eth_dev_info dev_info;
4913         int ret;
4914
4915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4916                 return;
4917         if (!port_is_stopped(res->port_id)) {
4918                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4919                 return;
4920         }
4921
4922         if (!strcmp(res->mode, "set"))
4923                 ports[res->port_id].tso_segsz = res->tso_segsz;
4924
4925         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4926         if (ret != 0)
4927                 return;
4928
4929         if ((ports[res->port_id].tso_segsz != 0) &&
4930                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4931                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4932                         res->port_id);
4933                 return;
4934         }
4935
4936         if (ports[res->port_id].tso_segsz == 0) {
4937                 ports[res->port_id].dev_conf.txmode.offloads &=
4938                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4939                 printf("TSO for non-tunneled packets is disabled\n");
4940         } else {
4941                 ports[res->port_id].dev_conf.txmode.offloads |=
4942                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4943                 printf("TSO segment size for non-tunneled packets is %d\n",
4944                         ports[res->port_id].tso_segsz);
4945         }
4946         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4947
4948         /* display warnings if configuration is not supported by the NIC */
4949         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4950         if (ret != 0)
4951                 return;
4952
4953         if ((ports[res->port_id].tso_segsz != 0) &&
4954                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4955                 fprintf(stderr,
4956                         "Warning: TSO enabled but not supported by port %d\n",
4957                         res->port_id);
4958         }
4959
4960         cmd_reconfig_device_queue(res->port_id, 1, 1);
4961 }
4962
4963 cmdline_parse_token_string_t cmd_tso_set_tso =
4964         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4965                                 tso, "tso");
4966 cmdline_parse_token_string_t cmd_tso_set_mode =
4967         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4968                                 mode, "set");
4969 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4970         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4971                                 tso_segsz, RTE_UINT16);
4972 cmdline_parse_token_num_t cmd_tso_set_portid =
4973         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4974                                 port_id, RTE_UINT16);
4975
4976 cmdline_parse_inst_t cmd_tso_set = {
4977         .f = cmd_tso_set_parsed,
4978         .data = NULL,
4979         .help_str = "tso set <tso_segsz> <port_id>: "
4980                 "Set TSO segment size of non-tunneled packets for csum engine "
4981                 "(0 to disable)",
4982         .tokens = {
4983                 (void *)&cmd_tso_set_tso,
4984                 (void *)&cmd_tso_set_mode,
4985                 (void *)&cmd_tso_set_tso_segsz,
4986                 (void *)&cmd_tso_set_portid,
4987                 NULL,
4988         },
4989 };
4990
4991 cmdline_parse_token_string_t cmd_tso_show_mode =
4992         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4993                                 mode, "show");
4994
4995
4996 cmdline_parse_inst_t cmd_tso_show = {
4997         .f = cmd_tso_set_parsed,
4998         .data = NULL,
4999         .help_str = "tso show <port_id>: "
5000                 "Show TSO segment size of non-tunneled packets for csum engine",
5001         .tokens = {
5002                 (void *)&cmd_tso_set_tso,
5003                 (void *)&cmd_tso_show_mode,
5004                 (void *)&cmd_tso_set_portid,
5005                 NULL,
5006         },
5007 };
5008
5009 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5010 struct cmd_tunnel_tso_set_result {
5011         cmdline_fixed_string_t tso;
5012         cmdline_fixed_string_t mode;
5013         uint16_t tso_segsz;
5014         portid_t port_id;
5015 };
5016
5017 static struct rte_eth_dev_info
5018 check_tunnel_tso_nic_support(portid_t port_id)
5019 {
5020         struct rte_eth_dev_info dev_info;
5021
5022         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5023                 return dev_info;
5024
5025         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5026                 fprintf(stderr,
5027                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5028                         port_id);
5029         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5030                 fprintf(stderr,
5031                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5032                         port_id);
5033         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5034                 fprintf(stderr,
5035                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5036                         port_id);
5037         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5038                 fprintf(stderr,
5039                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5040                         port_id);
5041         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5042                 fprintf(stderr,
5043                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5044                         port_id);
5045         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5046                 fprintf(stderr,
5047                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5048                         port_id);
5049         return dev_info;
5050 }
5051
5052 static void
5053 cmd_tunnel_tso_set_parsed(void *parsed_result,
5054                           __rte_unused struct cmdline *cl,
5055                           __rte_unused void *data)
5056 {
5057         struct cmd_tunnel_tso_set_result *res = parsed_result;
5058         struct rte_eth_dev_info dev_info;
5059
5060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5061                 return;
5062         if (!port_is_stopped(res->port_id)) {
5063                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5064                 return;
5065         }
5066
5067         if (!strcmp(res->mode, "set"))
5068                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5069
5070         dev_info = check_tunnel_tso_nic_support(res->port_id);
5071         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5072                 ports[res->port_id].dev_conf.txmode.offloads &=
5073                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5074                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5075                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5076                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5077                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5078                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5079                 printf("TSO for tunneled packets is disabled\n");
5080         } else {
5081                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5082                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5083                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5084                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5085                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5086                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5087
5088                 ports[res->port_id].dev_conf.txmode.offloads |=
5089                         (tso_offloads & dev_info.tx_offload_capa);
5090                 printf("TSO segment size for tunneled packets is %d\n",
5091                         ports[res->port_id].tunnel_tso_segsz);
5092
5093                 /* Below conditions are needed to make it work:
5094                  * (1) tunnel TSO is supported by the NIC;
5095                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5096                  * are recognized;
5097                  * (3) for tunneled pkts with outer L3 of IPv4,
5098                  * "csum set outer-ip" must be set to hw, because after tso,
5099                  * total_len of outer IP header is changed, and the checksum
5100                  * of outer IP header calculated by sw should be wrong; that
5101                  * is not necessary for IPv6 tunneled pkts because there's no
5102                  * checksum in IP header anymore.
5103                  */
5104
5105                 if (!ports[res->port_id].parse_tunnel)
5106                         fprintf(stderr,
5107                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5108                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5109                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5110                         fprintf(stderr,
5111                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5112         }
5113
5114         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5115         cmd_reconfig_device_queue(res->port_id, 1, 1);
5116 }
5117
5118 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5119         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5120                                 tso, "tunnel_tso");
5121 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5122         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5123                                 mode, "set");
5124 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5125         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5126                                 tso_segsz, RTE_UINT16);
5127 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5128         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5129                                 port_id, RTE_UINT16);
5130
5131 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5132         .f = cmd_tunnel_tso_set_parsed,
5133         .data = NULL,
5134         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5135                 "Set TSO segment size of tunneled packets for csum engine "
5136                 "(0 to disable)",
5137         .tokens = {
5138                 (void *)&cmd_tunnel_tso_set_tso,
5139                 (void *)&cmd_tunnel_tso_set_mode,
5140                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5141                 (void *)&cmd_tunnel_tso_set_portid,
5142                 NULL,
5143         },
5144 };
5145
5146 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5147         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5148                                 mode, "show");
5149
5150
5151 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5152         .f = cmd_tunnel_tso_set_parsed,
5153         .data = NULL,
5154         .help_str = "tunnel_tso show <port_id> "
5155                 "Show TSO segment size of tunneled packets for csum engine",
5156         .tokens = {
5157                 (void *)&cmd_tunnel_tso_set_tso,
5158                 (void *)&cmd_tunnel_tso_show_mode,
5159                 (void *)&cmd_tunnel_tso_set_portid,
5160                 NULL,
5161         },
5162 };
5163
5164 #ifdef RTE_LIB_GRO
5165 /* *** SET GRO FOR A PORT *** */
5166 struct cmd_gro_enable_result {
5167         cmdline_fixed_string_t cmd_set;
5168         cmdline_fixed_string_t cmd_port;
5169         cmdline_fixed_string_t cmd_keyword;
5170         cmdline_fixed_string_t cmd_onoff;
5171         portid_t cmd_pid;
5172 };
5173
5174 static void
5175 cmd_gro_enable_parsed(void *parsed_result,
5176                 __rte_unused struct cmdline *cl,
5177                 __rte_unused void *data)
5178 {
5179         struct cmd_gro_enable_result *res;
5180
5181         res = parsed_result;
5182         if (!strcmp(res->cmd_keyword, "gro"))
5183                 setup_gro(res->cmd_onoff, res->cmd_pid);
5184 }
5185
5186 cmdline_parse_token_string_t cmd_gro_enable_set =
5187         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5188                         cmd_set, "set");
5189 cmdline_parse_token_string_t cmd_gro_enable_port =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5191                         cmd_keyword, "port");
5192 cmdline_parse_token_num_t cmd_gro_enable_pid =
5193         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5194                         cmd_pid, RTE_UINT16);
5195 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5196         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5197                         cmd_keyword, "gro");
5198 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5200                         cmd_onoff, "on#off");
5201
5202 cmdline_parse_inst_t cmd_gro_enable = {
5203         .f = cmd_gro_enable_parsed,
5204         .data = NULL,
5205         .help_str = "set port <port_id> gro on|off",
5206         .tokens = {
5207                 (void *)&cmd_gro_enable_set,
5208                 (void *)&cmd_gro_enable_port,
5209                 (void *)&cmd_gro_enable_pid,
5210                 (void *)&cmd_gro_enable_keyword,
5211                 (void *)&cmd_gro_enable_onoff,
5212                 NULL,
5213         },
5214 };
5215
5216 /* *** DISPLAY GRO CONFIGURATION *** */
5217 struct cmd_gro_show_result {
5218         cmdline_fixed_string_t cmd_show;
5219         cmdline_fixed_string_t cmd_port;
5220         cmdline_fixed_string_t cmd_keyword;
5221         portid_t cmd_pid;
5222 };
5223
5224 static void
5225 cmd_gro_show_parsed(void *parsed_result,
5226                 __rte_unused struct cmdline *cl,
5227                 __rte_unused void *data)
5228 {
5229         struct cmd_gro_show_result *res;
5230
5231         res = parsed_result;
5232         if (!strcmp(res->cmd_keyword, "gro"))
5233                 show_gro(res->cmd_pid);
5234 }
5235
5236 cmdline_parse_token_string_t cmd_gro_show_show =
5237         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5238                         cmd_show, "show");
5239 cmdline_parse_token_string_t cmd_gro_show_port =
5240         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5241                         cmd_port, "port");
5242 cmdline_parse_token_num_t cmd_gro_show_pid =
5243         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5244                         cmd_pid, RTE_UINT16);
5245 cmdline_parse_token_string_t cmd_gro_show_keyword =
5246         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5247                         cmd_keyword, "gro");
5248
5249 cmdline_parse_inst_t cmd_gro_show = {
5250         .f = cmd_gro_show_parsed,
5251         .data = NULL,
5252         .help_str = "show port <port_id> gro",
5253         .tokens = {
5254                 (void *)&cmd_gro_show_show,
5255                 (void *)&cmd_gro_show_port,
5256                 (void *)&cmd_gro_show_pid,
5257                 (void *)&cmd_gro_show_keyword,
5258                 NULL,
5259         },
5260 };
5261
5262 /* *** SET FLUSH CYCLES FOR GRO *** */
5263 struct cmd_gro_flush_result {
5264         cmdline_fixed_string_t cmd_set;
5265         cmdline_fixed_string_t cmd_keyword;
5266         cmdline_fixed_string_t cmd_flush;
5267         uint8_t cmd_cycles;
5268 };
5269
5270 static void
5271 cmd_gro_flush_parsed(void *parsed_result,
5272                 __rte_unused struct cmdline *cl,
5273                 __rte_unused void *data)
5274 {
5275         struct cmd_gro_flush_result *res;
5276
5277         res = parsed_result;
5278         if ((!strcmp(res->cmd_keyword, "gro")) &&
5279                         (!strcmp(res->cmd_flush, "flush")))
5280                 setup_gro_flush_cycles(res->cmd_cycles);
5281 }
5282
5283 cmdline_parse_token_string_t cmd_gro_flush_set =
5284         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5285                         cmd_set, "set");
5286 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5287         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5288                         cmd_keyword, "gro");
5289 cmdline_parse_token_string_t cmd_gro_flush_flush =
5290         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5291                         cmd_flush, "flush");
5292 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5293         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5294                         cmd_cycles, RTE_UINT8);
5295
5296 cmdline_parse_inst_t cmd_gro_flush = {
5297         .f = cmd_gro_flush_parsed,
5298         .data = NULL,
5299         .help_str = "set gro flush <cycles>",
5300         .tokens = {
5301                 (void *)&cmd_gro_flush_set,
5302                 (void *)&cmd_gro_flush_keyword,
5303                 (void *)&cmd_gro_flush_flush,
5304                 (void *)&cmd_gro_flush_cycles,
5305                 NULL,
5306         },
5307 };
5308 #endif /* RTE_LIB_GRO */
5309
5310 #ifdef RTE_LIB_GSO
5311 /* *** ENABLE/DISABLE GSO *** */
5312 struct cmd_gso_enable_result {
5313         cmdline_fixed_string_t cmd_set;
5314         cmdline_fixed_string_t cmd_port;
5315         cmdline_fixed_string_t cmd_keyword;
5316         cmdline_fixed_string_t cmd_mode;
5317         portid_t cmd_pid;
5318 };
5319
5320 static void
5321 cmd_gso_enable_parsed(void *parsed_result,
5322                 __rte_unused struct cmdline *cl,
5323                 __rte_unused void *data)
5324 {
5325         struct cmd_gso_enable_result *res;
5326
5327         res = parsed_result;
5328         if (!strcmp(res->cmd_keyword, "gso"))
5329                 setup_gso(res->cmd_mode, res->cmd_pid);
5330 }
5331
5332 cmdline_parse_token_string_t cmd_gso_enable_set =
5333         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5334                         cmd_set, "set");
5335 cmdline_parse_token_string_t cmd_gso_enable_port =
5336         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5337                         cmd_port, "port");
5338 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5339         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5340                         cmd_keyword, "gso");
5341 cmdline_parse_token_string_t cmd_gso_enable_mode =
5342         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5343                         cmd_mode, "on#off");
5344 cmdline_parse_token_num_t cmd_gso_enable_pid =
5345         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5346                         cmd_pid, RTE_UINT16);
5347
5348 cmdline_parse_inst_t cmd_gso_enable = {
5349         .f = cmd_gso_enable_parsed,
5350         .data = NULL,
5351         .help_str = "set port <port_id> gso on|off",
5352         .tokens = {
5353                 (void *)&cmd_gso_enable_set,
5354                 (void *)&cmd_gso_enable_port,
5355                 (void *)&cmd_gso_enable_pid,
5356                 (void *)&cmd_gso_enable_keyword,
5357                 (void *)&cmd_gso_enable_mode,
5358                 NULL,
5359         },
5360 };
5361
5362 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5363 struct cmd_gso_size_result {
5364         cmdline_fixed_string_t cmd_set;
5365         cmdline_fixed_string_t cmd_keyword;
5366         cmdline_fixed_string_t cmd_segsz;
5367         uint16_t cmd_size;
5368 };
5369
5370 static void
5371 cmd_gso_size_parsed(void *parsed_result,
5372                        __rte_unused struct cmdline *cl,
5373                        __rte_unused void *data)
5374 {
5375         struct cmd_gso_size_result *res = parsed_result;
5376
5377         if (test_done == 0) {
5378                 fprintf(stderr,
5379                         "Before setting GSO segsz, please first stop forwarding\n");
5380                 return;
5381         }
5382
5383         if (!strcmp(res->cmd_keyword, "gso") &&
5384                         !strcmp(res->cmd_segsz, "segsz")) {
5385                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5386                         fprintf(stderr,
5387                                 "gso_size should be larger than %zu. Please input a legal value\n",
5388                                 RTE_GSO_SEG_SIZE_MIN);
5389                 else
5390                         gso_max_segment_size = res->cmd_size;
5391         }
5392 }
5393
5394 cmdline_parse_token_string_t cmd_gso_size_set =
5395         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5396                                 cmd_set, "set");
5397 cmdline_parse_token_string_t cmd_gso_size_keyword =
5398         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5399                                 cmd_keyword, "gso");
5400 cmdline_parse_token_string_t cmd_gso_size_segsz =
5401         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5402                                 cmd_segsz, "segsz");
5403 cmdline_parse_token_num_t cmd_gso_size_size =
5404         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5405                                 cmd_size, RTE_UINT16);
5406
5407 cmdline_parse_inst_t cmd_gso_size = {
5408         .f = cmd_gso_size_parsed,
5409         .data = NULL,
5410         .help_str = "set gso segsz <length>",
5411         .tokens = {
5412                 (void *)&cmd_gso_size_set,
5413                 (void *)&cmd_gso_size_keyword,
5414                 (void *)&cmd_gso_size_segsz,
5415                 (void *)&cmd_gso_size_size,
5416                 NULL,
5417         },
5418 };
5419
5420 /* *** SHOW GSO CONFIGURATION *** */
5421 struct cmd_gso_show_result {
5422         cmdline_fixed_string_t cmd_show;
5423         cmdline_fixed_string_t cmd_port;
5424         cmdline_fixed_string_t cmd_keyword;
5425         portid_t cmd_pid;
5426 };
5427
5428 static void
5429 cmd_gso_show_parsed(void *parsed_result,
5430                        __rte_unused struct cmdline *cl,
5431                        __rte_unused void *data)
5432 {
5433         struct cmd_gso_show_result *res = parsed_result;
5434
5435         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5436                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5437                 return;
5438         }
5439         if (!strcmp(res->cmd_keyword, "gso")) {
5440                 if (gso_ports[res->cmd_pid].enable) {
5441                         printf("Max GSO'd packet size: %uB\n"
5442                                         "Supported GSO types: TCP/IPv4, "
5443                                         "UDP/IPv4, VxLAN with inner "
5444                                         "TCP/IPv4 packet, GRE with inner "
5445                                         "TCP/IPv4 packet\n",
5446                                         gso_max_segment_size);
5447                 } else
5448                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5449         }
5450 }
5451
5452 cmdline_parse_token_string_t cmd_gso_show_show =
5453 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5454                 cmd_show, "show");
5455 cmdline_parse_token_string_t cmd_gso_show_port =
5456 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5457                 cmd_port, "port");
5458 cmdline_parse_token_string_t cmd_gso_show_keyword =
5459         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5460                                 cmd_keyword, "gso");
5461 cmdline_parse_token_num_t cmd_gso_show_pid =
5462         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5463                                 cmd_pid, RTE_UINT16);
5464
5465 cmdline_parse_inst_t cmd_gso_show = {
5466         .f = cmd_gso_show_parsed,
5467         .data = NULL,
5468         .help_str = "show port <port_id> gso",
5469         .tokens = {
5470                 (void *)&cmd_gso_show_show,
5471                 (void *)&cmd_gso_show_port,
5472                 (void *)&cmd_gso_show_pid,
5473                 (void *)&cmd_gso_show_keyword,
5474                 NULL,
5475         },
5476 };
5477 #endif /* RTE_LIB_GSO */
5478
5479 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5480 struct cmd_set_flush_rx {
5481         cmdline_fixed_string_t set;
5482         cmdline_fixed_string_t flush_rx;
5483         cmdline_fixed_string_t mode;
5484 };
5485
5486 static void
5487 cmd_set_flush_rx_parsed(void *parsed_result,
5488                 __rte_unused struct cmdline *cl,
5489                 __rte_unused void *data)
5490 {
5491         struct cmd_set_flush_rx *res = parsed_result;
5492
5493         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5494                 printf("multi-process doesn't support to flush Rx queues.\n");
5495                 return;
5496         }
5497
5498         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5499 }
5500
5501 cmdline_parse_token_string_t cmd_setflushrx_set =
5502         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5503                         set, "set");
5504 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5505         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5506                         flush_rx, "flush_rx");
5507 cmdline_parse_token_string_t cmd_setflushrx_mode =
5508         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5509                         mode, "on#off");
5510
5511
5512 cmdline_parse_inst_t cmd_set_flush_rx = {
5513         .f = cmd_set_flush_rx_parsed,
5514         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5515         .data = NULL,
5516         .tokens = {
5517                 (void *)&cmd_setflushrx_set,
5518                 (void *)&cmd_setflushrx_flush_rx,
5519                 (void *)&cmd_setflushrx_mode,
5520                 NULL,
5521         },
5522 };
5523
5524 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5525 struct cmd_set_link_check {
5526         cmdline_fixed_string_t set;
5527         cmdline_fixed_string_t link_check;
5528         cmdline_fixed_string_t mode;
5529 };
5530
5531 static void
5532 cmd_set_link_check_parsed(void *parsed_result,
5533                 __rte_unused struct cmdline *cl,
5534                 __rte_unused void *data)
5535 {
5536         struct cmd_set_link_check *res = parsed_result;
5537         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5538 }
5539
5540 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5542                         set, "set");
5543 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5545                         link_check, "link_check");
5546 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5547         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5548                         mode, "on#off");
5549
5550
5551 cmdline_parse_inst_t cmd_set_link_check = {
5552         .f = cmd_set_link_check_parsed,
5553         .help_str = "set link_check on|off: Enable/Disable link status check "
5554                     "when starting/stopping a port",
5555         .data = NULL,
5556         .tokens = {
5557                 (void *)&cmd_setlinkcheck_set,
5558                 (void *)&cmd_setlinkcheck_link_check,
5559                 (void *)&cmd_setlinkcheck_mode,
5560                 NULL,
5561         },
5562 };
5563
5564 /* *** SET NIC BYPASS MODE *** */
5565 struct cmd_set_bypass_mode_result {
5566         cmdline_fixed_string_t set;
5567         cmdline_fixed_string_t bypass;
5568         cmdline_fixed_string_t mode;
5569         cmdline_fixed_string_t value;
5570         portid_t port_id;
5571 };
5572
5573 static void
5574 cmd_set_bypass_mode_parsed(void *parsed_result,
5575                 __rte_unused struct cmdline *cl,
5576                 __rte_unused void *data)
5577 {
5578         struct cmd_set_bypass_mode_result *res = parsed_result;
5579         portid_t port_id = res->port_id;
5580         int32_t rc = -EINVAL;
5581
5582 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5583         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5584
5585         if (!strcmp(res->value, "bypass"))
5586                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5587         else if (!strcmp(res->value, "isolate"))
5588                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5589         else
5590                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5591
5592         /* Set the bypass mode for the relevant port. */
5593         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5594 #endif
5595         if (rc != 0)
5596                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5597                         port_id);
5598 }
5599
5600 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5601         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5602                         set, "set");
5603 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5604         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5605                         bypass, "bypass");
5606 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5607         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5608                         mode, "mode");
5609 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5610         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5611                         value, "normal#bypass#isolate");
5612 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5613         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5614                                 port_id, RTE_UINT16);
5615
5616 cmdline_parse_inst_t cmd_set_bypass_mode = {
5617         .f = cmd_set_bypass_mode_parsed,
5618         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5619                     "Set the NIC bypass mode for port_id",
5620         .data = NULL,
5621         .tokens = {
5622                 (void *)&cmd_setbypass_mode_set,
5623                 (void *)&cmd_setbypass_mode_bypass,
5624                 (void *)&cmd_setbypass_mode_mode,
5625                 (void *)&cmd_setbypass_mode_value,
5626                 (void *)&cmd_setbypass_mode_port,
5627                 NULL,
5628         },
5629 };
5630
5631 /* *** SET NIC BYPASS EVENT *** */
5632 struct cmd_set_bypass_event_result {
5633         cmdline_fixed_string_t set;
5634         cmdline_fixed_string_t bypass;
5635         cmdline_fixed_string_t event;
5636         cmdline_fixed_string_t event_value;
5637         cmdline_fixed_string_t mode;
5638         cmdline_fixed_string_t mode_value;
5639         portid_t port_id;
5640 };
5641
5642 static void
5643 cmd_set_bypass_event_parsed(void *parsed_result,
5644                 __rte_unused struct cmdline *cl,
5645                 __rte_unused void *data)
5646 {
5647         int32_t rc = -EINVAL;
5648         struct cmd_set_bypass_event_result *res = parsed_result;
5649         portid_t port_id = res->port_id;
5650
5651 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5652         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5653         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5654
5655         if (!strcmp(res->event_value, "timeout"))
5656                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5657         else if (!strcmp(res->event_value, "os_on"))
5658                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5659         else if (!strcmp(res->event_value, "os_off"))
5660                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5661         else if (!strcmp(res->event_value, "power_on"))
5662                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5663         else if (!strcmp(res->event_value, "power_off"))
5664                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5665         else
5666                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5667
5668         if (!strcmp(res->mode_value, "bypass"))
5669                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5670         else if (!strcmp(res->mode_value, "isolate"))
5671                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5672         else
5673                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5674
5675         /* Set the watchdog timeout. */
5676         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5677
5678                 rc = -EINVAL;
5679                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5680                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5681                                                            bypass_timeout);
5682                 }
5683                 if (rc != 0) {
5684                         fprintf(stderr,
5685                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5686                                 bypass_timeout, port_id, rc);
5687                 }
5688         }
5689
5690         /* Set the bypass event to transition to bypass mode. */
5691         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5692                                               bypass_mode);
5693 #endif
5694
5695         if (rc != 0)
5696                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5697                         port_id);
5698 }
5699
5700 cmdline_parse_token_string_t cmd_setbypass_event_set =
5701         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5702                         set, "set");
5703 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5704         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5705                         bypass, "bypass");
5706 cmdline_parse_token_string_t cmd_setbypass_event_event =
5707         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5708                         event, "event");
5709 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5710         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5711                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5712 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5713         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5714                         mode, "mode");
5715 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5716         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5717                         mode_value, "normal#bypass#isolate");
5718 cmdline_parse_token_num_t cmd_setbypass_event_port =
5719         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5720                                 port_id, RTE_UINT16);
5721
5722 cmdline_parse_inst_t cmd_set_bypass_event = {
5723         .f = cmd_set_bypass_event_parsed,
5724         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5725                 "power_off mode normal|bypass|isolate <port_id>: "
5726                 "Set the NIC bypass event mode for port_id",
5727         .data = NULL,
5728         .tokens = {
5729                 (void *)&cmd_setbypass_event_set,
5730                 (void *)&cmd_setbypass_event_bypass,
5731                 (void *)&cmd_setbypass_event_event,
5732                 (void *)&cmd_setbypass_event_event_value,
5733                 (void *)&cmd_setbypass_event_mode,
5734                 (void *)&cmd_setbypass_event_mode_value,
5735                 (void *)&cmd_setbypass_event_port,
5736                 NULL,
5737         },
5738 };
5739
5740
5741 /* *** SET NIC BYPASS TIMEOUT *** */
5742 struct cmd_set_bypass_timeout_result {
5743         cmdline_fixed_string_t set;
5744         cmdline_fixed_string_t bypass;
5745         cmdline_fixed_string_t timeout;
5746         cmdline_fixed_string_t value;
5747 };
5748
5749 static void
5750 cmd_set_bypass_timeout_parsed(void *parsed_result,
5751                 __rte_unused struct cmdline *cl,
5752                 __rte_unused void *data)
5753 {
5754         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5755
5756 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5757         if (!strcmp(res->value, "1.5"))
5758                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5759         else if (!strcmp(res->value, "2"))
5760                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5761         else if (!strcmp(res->value, "3"))
5762                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5763         else if (!strcmp(res->value, "4"))
5764                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5765         else if (!strcmp(res->value, "8"))
5766                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5767         else if (!strcmp(res->value, "16"))
5768                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5769         else if (!strcmp(res->value, "32"))
5770                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5771         else
5772                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5773 #endif
5774 }
5775
5776 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5777         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5778                         set, "set");
5779 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5780         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5781                         bypass, "bypass");
5782 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5783         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5784                         timeout, "timeout");
5785 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5786         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5787                         value, "0#1.5#2#3#4#8#16#32");
5788
5789 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5790         .f = cmd_set_bypass_timeout_parsed,
5791         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5792                 "Set the NIC bypass watchdog timeout in seconds",
5793         .data = NULL,
5794         .tokens = {
5795                 (void *)&cmd_setbypass_timeout_set,
5796                 (void *)&cmd_setbypass_timeout_bypass,
5797                 (void *)&cmd_setbypass_timeout_timeout,
5798                 (void *)&cmd_setbypass_timeout_value,
5799                 NULL,
5800         },
5801 };
5802
5803 /* *** SHOW NIC BYPASS MODE *** */
5804 struct cmd_show_bypass_config_result {
5805         cmdline_fixed_string_t show;
5806         cmdline_fixed_string_t bypass;
5807         cmdline_fixed_string_t config;
5808         portid_t port_id;
5809 };
5810
5811 static void
5812 cmd_show_bypass_config_parsed(void *parsed_result,
5813                 __rte_unused struct cmdline *cl,
5814                 __rte_unused void *data)
5815 {
5816         struct cmd_show_bypass_config_result *res = parsed_result;
5817         portid_t port_id = res->port_id;
5818         int rc = -EINVAL;
5819 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5820         uint32_t event_mode;
5821         uint32_t bypass_mode;
5822         uint32_t timeout = bypass_timeout;
5823         unsigned int i;
5824
5825         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5826                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5827         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5828                 {"UNKNOWN", "normal", "bypass", "isolate"};
5829         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5830                 "NONE",
5831                 "OS/board on",
5832                 "power supply on",
5833                 "OS/board off",
5834                 "power supply off",
5835                 "timeout"};
5836
5837         /* Display the bypass mode.*/
5838         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5839                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5840                         port_id);
5841                 return;
5842         }
5843         else {
5844                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5845                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5846
5847                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5848         }
5849
5850         /* Display the bypass timeout.*/
5851         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5852                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5853
5854         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5855
5856         /* Display the bypass events and associated modes. */
5857         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5858
5859                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5860                         fprintf(stderr,
5861                                 "\tFailed to get bypass mode for event = %s\n",
5862                                 events[i]);
5863                 } else {
5864                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5865                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5866
5867                         printf("\tbypass event: %-16s = %s\n", events[i],
5868                                 modes[event_mode]);
5869                 }
5870         }
5871 #endif
5872         if (rc != 0)
5873                 fprintf(stderr,
5874                         "\tFailed to get bypass configuration for port = %d\n",
5875                        port_id);
5876 }
5877
5878 cmdline_parse_token_string_t cmd_showbypass_config_show =
5879         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5880                         show, "show");
5881 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5882         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5883                         bypass, "bypass");
5884 cmdline_parse_token_string_t cmd_showbypass_config_config =
5885         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5886                         config, "config");
5887 cmdline_parse_token_num_t cmd_showbypass_config_port =
5888         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5889                                 port_id, RTE_UINT16);
5890
5891 cmdline_parse_inst_t cmd_show_bypass_config = {
5892         .f = cmd_show_bypass_config_parsed,
5893         .help_str = "show bypass config <port_id>: "
5894                     "Show the NIC bypass config for port_id",
5895         .data = NULL,
5896         .tokens = {
5897                 (void *)&cmd_showbypass_config_show,
5898                 (void *)&cmd_showbypass_config_bypass,
5899                 (void *)&cmd_showbypass_config_config,
5900                 (void *)&cmd_showbypass_config_port,
5901                 NULL,
5902         },
5903 };
5904
5905 #ifdef RTE_NET_BOND
5906 /* *** SET BONDING MODE *** */
5907 struct cmd_set_bonding_mode_result {
5908         cmdline_fixed_string_t set;
5909         cmdline_fixed_string_t bonding;
5910         cmdline_fixed_string_t mode;
5911         uint8_t value;
5912         portid_t port_id;
5913 };
5914
5915 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5916                 __rte_unused  struct cmdline *cl,
5917                 __rte_unused void *data)
5918 {
5919         struct cmd_set_bonding_mode_result *res = parsed_result;
5920         portid_t port_id = res->port_id;
5921         struct rte_port *port = &ports[port_id];
5922
5923         /*
5924          * Bonding mode changed means resources of device changed, like whether
5925          * started rte timer or not. Device should be restarted when resources
5926          * of device changed.
5927          */
5928         if (port->port_status != RTE_PORT_STOPPED) {
5929                 fprintf(stderr,
5930                         "\t Error: Can't set bonding mode when port %d is not stopped\n",
5931                         port_id);
5932                 return;
5933         }
5934
5935         /* Set the bonding mode for the relevant port. */
5936         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5937                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5938                         port_id);
5939 }
5940
5941 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5942 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5943                 set, "set");
5944 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5945 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5946                 bonding, "bonding");
5947 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5948 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5949                 mode, "mode");
5950 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5951 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5952                 value, RTE_UINT8);
5953 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5954 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5955                 port_id, RTE_UINT16);
5956
5957 cmdline_parse_inst_t cmd_set_bonding_mode = {
5958                 .f = cmd_set_bonding_mode_parsed,
5959                 .help_str = "set bonding mode <mode_value> <port_id>: "
5960                         "Set the bonding mode for port_id",
5961                 .data = NULL,
5962                 .tokens = {
5963                                 (void *) &cmd_setbonding_mode_set,
5964                                 (void *) &cmd_setbonding_mode_bonding,
5965                                 (void *) &cmd_setbonding_mode_mode,
5966                                 (void *) &cmd_setbonding_mode_value,
5967                                 (void *) &cmd_setbonding_mode_port,
5968                                 NULL
5969                 }
5970 };
5971
5972 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5973 struct cmd_set_bonding_lacp_dedicated_queues_result {
5974         cmdline_fixed_string_t set;
5975         cmdline_fixed_string_t bonding;
5976         cmdline_fixed_string_t lacp;
5977         cmdline_fixed_string_t dedicated_queues;
5978         portid_t port_id;
5979         cmdline_fixed_string_t mode;
5980 };
5981
5982 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5983                 __rte_unused  struct cmdline *cl,
5984                 __rte_unused void *data)
5985 {
5986         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5987         portid_t port_id = res->port_id;
5988         struct rte_port *port;
5989
5990         port = &ports[port_id];
5991
5992         /** Check if the port is not started **/
5993         if (port->port_status != RTE_PORT_STOPPED) {
5994                 fprintf(stderr, "Please stop port %d first\n", port_id);
5995                 return;
5996         }
5997
5998         if (!strcmp(res->mode, "enable")) {
5999                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6000                         printf("Dedicate queues for LACP control packets"
6001                                         " enabled\n");
6002                 else
6003                         printf("Enabling dedicate queues for LACP control "
6004                                         "packets on port %d failed\n", port_id);
6005         } else if (!strcmp(res->mode, "disable")) {
6006                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6007                         printf("Dedicated queues for LACP control packets "
6008                                         "disabled\n");
6009                 else
6010                         printf("Disabling dedicated queues for LACP control "
6011                                         "traffic on port %d failed\n", port_id);
6012         }
6013 }
6014
6015 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6016 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6017                 set, "set");
6018 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6019 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6020                 bonding, "bonding");
6021 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6022 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6023                 lacp, "lacp");
6024 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6025 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6026                 dedicated_queues, "dedicated_queues");
6027 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6028 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6029                 port_id, RTE_UINT16);
6030 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6031 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6032                 mode, "enable#disable");
6033
6034 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6035                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6036                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6037                         "enable|disable: "
6038                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6039                 .data = NULL,
6040                 .tokens = {
6041                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6042                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6043                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6044                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6045                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6046                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6047                         NULL
6048                 }
6049 };
6050
6051 /* *** SET BALANCE XMIT POLICY *** */
6052 struct cmd_set_bonding_balance_xmit_policy_result {
6053         cmdline_fixed_string_t set;
6054         cmdline_fixed_string_t bonding;
6055         cmdline_fixed_string_t balance_xmit_policy;
6056         portid_t port_id;
6057         cmdline_fixed_string_t policy;
6058 };
6059
6060 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6061                 __rte_unused  struct cmdline *cl,
6062                 __rte_unused void *data)
6063 {
6064         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6065         portid_t port_id = res->port_id;
6066         uint8_t policy;
6067
6068         if (!strcmp(res->policy, "l2")) {
6069                 policy = BALANCE_XMIT_POLICY_LAYER2;
6070         } else if (!strcmp(res->policy, "l23")) {
6071                 policy = BALANCE_XMIT_POLICY_LAYER23;
6072         } else if (!strcmp(res->policy, "l34")) {
6073                 policy = BALANCE_XMIT_POLICY_LAYER34;
6074         } else {
6075                 fprintf(stderr, "\t Invalid xmit policy selection");
6076                 return;
6077         }
6078
6079         /* Set the bonding mode for the relevant port. */
6080         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6081                 fprintf(stderr,
6082                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6083                         port_id);
6084         }
6085 }
6086
6087 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6088 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6089                 set, "set");
6090 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6091 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6092                 bonding, "bonding");
6093 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6094 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6095                 balance_xmit_policy, "balance_xmit_policy");
6096 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6097 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6098                 port_id, RTE_UINT16);
6099 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6100 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6101                 policy, "l2#l23#l34");
6102
6103 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6104                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6105                 .help_str = "set bonding balance_xmit_policy <port_id> "
6106                         "l2|l23|l34: "
6107                         "Set the bonding balance_xmit_policy for port_id",
6108                 .data = NULL,
6109                 .tokens = {
6110                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6111                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6112                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6113                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6114                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6115                                 NULL
6116                 }
6117 };
6118
6119 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6120 struct cmd_show_bonding_lacp_info_result {
6121         cmdline_fixed_string_t show;
6122         cmdline_fixed_string_t bonding;
6123         cmdline_fixed_string_t lacp;
6124         cmdline_fixed_string_t info;
6125         portid_t port_id;
6126 };
6127
6128 static void port_param_show(struct port_params *params)
6129 {
6130         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6131
6132         printf("\t\tsystem priority: %u\n", params->system_priority);
6133         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6134         printf("\t\tsystem mac address: %s\n", buf);
6135         printf("\t\tport key: %u\n", params->key);
6136         printf("\t\tport priority: %u\n", params->port_priority);
6137         printf("\t\tport number: %u\n", params->port_number);
6138 }
6139
6140 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6141 {
6142         char a_state[256] = { 0 };
6143         char p_state[256] = { 0 };
6144         int a_len = 0;
6145         int p_len = 0;
6146         uint32_t i;
6147
6148         static const char * const state[] = {
6149                 "ACTIVE",
6150                 "TIMEOUT",
6151                 "AGGREGATION",
6152                 "SYNCHRONIZATION",
6153                 "COLLECTING",
6154                 "DISTRIBUTING",
6155                 "DEFAULTED",
6156                 "EXPIRED"
6157         };
6158         static const char * const selection[] = {
6159                 "UNSELECTED",
6160                 "STANDBY",
6161                 "SELECTED"
6162         };
6163
6164         for (i = 0; i < RTE_DIM(state); i++) {
6165                 if ((info->actor_state >> i) & 1)
6166                         a_len += snprintf(&a_state[a_len],
6167                                                 RTE_DIM(a_state) - a_len, "%s ",
6168                                                 state[i]);
6169
6170                 if ((info->partner_state >> i) & 1)
6171                         p_len += snprintf(&p_state[p_len],
6172                                                 RTE_DIM(p_state) - p_len, "%s ",
6173                                                 state[i]);
6174         }
6175         printf("\tAggregator port id: %u\n", info->agg_port_id);
6176         printf("\tselection: %s\n", selection[info->selected]);
6177         printf("\tActor detail info:\n");
6178         port_param_show(&info->actor);
6179         printf("\t\tport state: %s\n", a_state);
6180         printf("\tPartner detail info:\n");
6181         port_param_show(&info->partner);
6182         printf("\t\tport state: %s\n", p_state);
6183         printf("\n");
6184 }
6185
6186 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6187 {
6188         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6189         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6190         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6191         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6192         printf("\taggregate wait timeout: %u ms\n",
6193                         conf->aggregate_wait_timeout_ms);
6194         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6195         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6196         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6197         switch (conf->agg_selection) {
6198         case AGG_BANDWIDTH:
6199                 printf("\taggregation mode: bandwidth\n");
6200                 break;
6201         case AGG_STABLE:
6202                 printf("\taggregation mode: stable\n");
6203                 break;
6204         case AGG_COUNT:
6205                 printf("\taggregation mode: count\n");
6206                 break;
6207         default:
6208                 printf("\taggregation mode: invalid\n");
6209                 break;
6210         }
6211
6212         printf("\n");
6213 }
6214
6215 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6216                 __rte_unused  struct cmdline *cl,
6217                 __rte_unused void *data)
6218 {
6219         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6220         struct rte_eth_bond_8023ad_slave_info slave_info;
6221         struct rte_eth_bond_8023ad_conf port_conf;
6222         portid_t slaves[RTE_MAX_ETHPORTS];
6223         portid_t port_id = res->port_id;
6224         int num_active_slaves;
6225         int bonding_mode;
6226         int i;
6227         int ret;
6228
6229         bonding_mode = rte_eth_bond_mode_get(port_id);
6230         if (bonding_mode != BONDING_MODE_8023AD) {
6231                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6232                 return;
6233         }
6234
6235         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6236                         RTE_MAX_ETHPORTS);
6237         if (num_active_slaves < 0) {
6238                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6239                                 port_id);
6240                 return;
6241         }
6242         if (num_active_slaves == 0)
6243                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6244                         port_id);
6245
6246         printf("\tIEEE802.3 port: %u\n", port_id);
6247         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6248         if (ret) {
6249                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6250                         port_id);
6251                 return;
6252         }
6253         lacp_conf_show(&port_conf);
6254
6255         for (i = 0; i < num_active_slaves; i++) {
6256                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6257                                 &slave_info);
6258                 if (ret) {
6259                         fprintf(stderr, "\tGet slave device %u info failed\n",
6260                                 slaves[i]);
6261                         return;
6262                 }
6263                 printf("\tSlave Port: %u\n", slaves[i]);
6264                 lacp_slave_info_show(&slave_info);
6265         }
6266 }
6267
6268 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6269 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6270                 show, "show");
6271 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6272 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6273                 bonding, "bonding");
6274 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6275 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6276                 bonding, "lacp");
6277 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6278 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6279                 info, "info");
6280 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6281 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6282                 port_id, RTE_UINT16);
6283
6284 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6285                 .f = cmd_show_bonding_lacp_info_parsed,
6286                 .help_str = "show bonding lacp info <port_id> : "
6287                         "Show bonding IEEE802.3 information for port_id",
6288                 .data = NULL,
6289                 .tokens = {
6290                         (void *)&cmd_show_bonding_lacp_info_show,
6291                         (void *)&cmd_show_bonding_lacp_info_bonding,
6292                         (void *)&cmd_show_bonding_lacp_info_lacp,
6293                         (void *)&cmd_show_bonding_lacp_info_info,
6294                         (void *)&cmd_show_bonding_lacp_info_port_id,
6295                         NULL
6296                 }
6297 };
6298
6299 /* *** SHOW NIC BONDING CONFIGURATION *** */
6300 struct cmd_show_bonding_config_result {
6301         cmdline_fixed_string_t show;
6302         cmdline_fixed_string_t bonding;
6303         cmdline_fixed_string_t config;
6304         portid_t port_id;
6305 };
6306
6307 static void cmd_show_bonding_config_parsed(void *parsed_result,
6308                 __rte_unused  struct cmdline *cl,
6309                 __rte_unused void *data)
6310 {
6311         struct cmd_show_bonding_config_result *res = parsed_result;
6312         int bonding_mode, agg_mode;
6313         portid_t slaves[RTE_MAX_ETHPORTS];
6314         int num_slaves, num_active_slaves;
6315         int primary_id;
6316         int i;
6317         portid_t port_id = res->port_id;
6318
6319         /* Display the bonding mode.*/
6320         bonding_mode = rte_eth_bond_mode_get(port_id);
6321         if (bonding_mode < 0) {
6322                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6323                         port_id);
6324                 return;
6325         } else
6326                 printf("\tBonding mode: %d\n", bonding_mode);
6327
6328         if (bonding_mode == BONDING_MODE_BALANCE ||
6329                 bonding_mode == BONDING_MODE_8023AD) {
6330                 int balance_xmit_policy;
6331
6332                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6333                 if (balance_xmit_policy < 0) {
6334                         fprintf(stderr,
6335                                 "\tFailed to get balance xmit policy for port = %d\n",
6336                                 port_id);
6337                         return;
6338                 } else {
6339                         printf("\tBalance Xmit Policy: ");
6340
6341                         switch (balance_xmit_policy) {
6342                         case BALANCE_XMIT_POLICY_LAYER2:
6343                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6344                                 break;
6345                         case BALANCE_XMIT_POLICY_LAYER23:
6346                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6347                                 break;
6348                         case BALANCE_XMIT_POLICY_LAYER34:
6349                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6350                                 break;
6351                         }
6352                         printf("\n");
6353                 }
6354         }
6355
6356         if (bonding_mode == BONDING_MODE_8023AD) {
6357                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6358                 printf("\tIEEE802.3AD Aggregator Mode: ");
6359                 switch (agg_mode) {
6360                 case AGG_BANDWIDTH:
6361                         printf("bandwidth");
6362                         break;
6363                 case AGG_STABLE:
6364                         printf("stable");
6365                         break;
6366                 case AGG_COUNT:
6367                         printf("count");
6368                         break;
6369                 }
6370                 printf("\n");
6371         }
6372
6373         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6374
6375         if (num_slaves < 0) {
6376                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6377                         port_id);
6378                 return;
6379         }
6380         if (num_slaves > 0) {
6381                 printf("\tSlaves (%d): [", num_slaves);
6382                 for (i = 0; i < num_slaves - 1; i++)
6383                         printf("%d ", slaves[i]);
6384
6385                 printf("%d]\n", slaves[num_slaves - 1]);
6386         } else {
6387                 printf("\tSlaves: []\n");
6388
6389         }
6390
6391         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6392                         RTE_MAX_ETHPORTS);
6393
6394         if (num_active_slaves < 0) {
6395                 fprintf(stderr,
6396                         "\tFailed to get active slave list for port = %d\n",
6397                         port_id);
6398                 return;
6399         }
6400         if (num_active_slaves > 0) {
6401                 printf("\tActive Slaves (%d): [", num_active_slaves);
6402                 for (i = 0; i < num_active_slaves - 1; i++)
6403                         printf("%d ", slaves[i]);
6404
6405                 printf("%d]\n", slaves[num_active_slaves - 1]);
6406
6407         } else {
6408                 printf("\tActive Slaves: []\n");
6409
6410         }
6411
6412         primary_id = rte_eth_bond_primary_get(port_id);
6413         if (primary_id < 0) {
6414                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6415                         port_id);
6416                 return;
6417         } else
6418                 printf("\tPrimary: [%d]\n", primary_id);
6419
6420 }
6421
6422 cmdline_parse_token_string_t cmd_showbonding_config_show =
6423 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6424                 show, "show");
6425 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6426 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6427                 bonding, "bonding");
6428 cmdline_parse_token_string_t cmd_showbonding_config_config =
6429 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6430                 config, "config");
6431 cmdline_parse_token_num_t cmd_showbonding_config_port =
6432 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6433                 port_id, RTE_UINT16);
6434
6435 cmdline_parse_inst_t cmd_show_bonding_config = {
6436                 .f = cmd_show_bonding_config_parsed,
6437                 .help_str = "show bonding config <port_id>: "
6438                         "Show the bonding config for port_id",
6439                 .data = NULL,
6440                 .tokens = {
6441                                 (void *)&cmd_showbonding_config_show,
6442                                 (void *)&cmd_showbonding_config_bonding,
6443                                 (void *)&cmd_showbonding_config_config,
6444                                 (void *)&cmd_showbonding_config_port,
6445                                 NULL
6446                 }
6447 };
6448
6449 /* *** SET BONDING PRIMARY *** */
6450 struct cmd_set_bonding_primary_result {
6451         cmdline_fixed_string_t set;
6452         cmdline_fixed_string_t bonding;
6453         cmdline_fixed_string_t primary;
6454         portid_t slave_id;
6455         portid_t port_id;
6456 };
6457
6458 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6459                 __rte_unused  struct cmdline *cl,
6460                 __rte_unused void *data)
6461 {
6462         struct cmd_set_bonding_primary_result *res = parsed_result;
6463         portid_t master_port_id = res->port_id;
6464         portid_t slave_port_id = res->slave_id;
6465
6466         /* Set the primary slave for a bonded device. */
6467         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6468                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6469                         master_port_id);
6470                 return;
6471         }
6472         init_port_config();
6473 }
6474
6475 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6476 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6477                 set, "set");
6478 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6479 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6480                 bonding, "bonding");
6481 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6482 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6483                 primary, "primary");
6484 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6485 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6486                 slave_id, RTE_UINT16);
6487 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6488 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6489                 port_id, RTE_UINT16);
6490
6491 cmdline_parse_inst_t cmd_set_bonding_primary = {
6492                 .f = cmd_set_bonding_primary_parsed,
6493                 .help_str = "set bonding primary <slave_id> <port_id>: "
6494                         "Set the primary slave for port_id",
6495                 .data = NULL,
6496                 .tokens = {
6497                                 (void *)&cmd_setbonding_primary_set,
6498                                 (void *)&cmd_setbonding_primary_bonding,
6499                                 (void *)&cmd_setbonding_primary_primary,
6500                                 (void *)&cmd_setbonding_primary_slave,
6501                                 (void *)&cmd_setbonding_primary_port,
6502                                 NULL
6503                 }
6504 };
6505
6506 /* *** ADD SLAVE *** */
6507 struct cmd_add_bonding_slave_result {
6508         cmdline_fixed_string_t add;
6509         cmdline_fixed_string_t bonding;
6510         cmdline_fixed_string_t slave;
6511         portid_t slave_id;
6512         portid_t port_id;
6513 };
6514
6515 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6516                 __rte_unused  struct cmdline *cl,
6517                 __rte_unused void *data)
6518 {
6519         struct cmd_add_bonding_slave_result *res = parsed_result;
6520         portid_t master_port_id = res->port_id;
6521         portid_t slave_port_id = res->slave_id;
6522
6523         /* add the slave for a bonded device. */
6524         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6525                 fprintf(stderr,
6526                         "\t Failed to add slave %d to master port = %d.\n",
6527                         slave_port_id, master_port_id);
6528                 return;
6529         }
6530         init_port_config();
6531         set_port_slave_flag(slave_port_id);
6532 }
6533
6534 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6535 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6536                 add, "add");
6537 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6538 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6539                 bonding, "bonding");
6540 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6541 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6542                 slave, "slave");
6543 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6544 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6545                 slave_id, RTE_UINT16);
6546 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6547 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6548                 port_id, RTE_UINT16);
6549
6550 cmdline_parse_inst_t cmd_add_bonding_slave = {
6551                 .f = cmd_add_bonding_slave_parsed,
6552                 .help_str = "add bonding slave <slave_id> <port_id>: "
6553                         "Add a slave device to a bonded device",
6554                 .data = NULL,
6555                 .tokens = {
6556                                 (void *)&cmd_addbonding_slave_add,
6557                                 (void *)&cmd_addbonding_slave_bonding,
6558                                 (void *)&cmd_addbonding_slave_slave,
6559                                 (void *)&cmd_addbonding_slave_slaveid,
6560                                 (void *)&cmd_addbonding_slave_port,
6561                                 NULL
6562                 }
6563 };
6564
6565 /* *** REMOVE SLAVE *** */
6566 struct cmd_remove_bonding_slave_result {
6567         cmdline_fixed_string_t remove;
6568         cmdline_fixed_string_t bonding;
6569         cmdline_fixed_string_t slave;
6570         portid_t slave_id;
6571         portid_t port_id;
6572 };
6573
6574 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6575                 __rte_unused  struct cmdline *cl,
6576                 __rte_unused void *data)
6577 {
6578         struct cmd_remove_bonding_slave_result *res = parsed_result;
6579         portid_t master_port_id = res->port_id;
6580         portid_t slave_port_id = res->slave_id;
6581
6582         /* remove the slave from a bonded device. */
6583         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6584                 fprintf(stderr,
6585                         "\t Failed to remove slave %d from master port = %d.\n",
6586                         slave_port_id, master_port_id);
6587                 return;
6588         }
6589         init_port_config();
6590         clear_port_slave_flag(slave_port_id);
6591 }
6592
6593 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6594                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6595                                 remove, "remove");
6596 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6597                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6598                                 bonding, "bonding");
6599 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6600                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6601                                 slave, "slave");
6602 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6603                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6604                                 slave_id, RTE_UINT16);
6605 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6606                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6607                                 port_id, RTE_UINT16);
6608
6609 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6610                 .f = cmd_remove_bonding_slave_parsed,
6611                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6612                         "Remove a slave device from a bonded device",
6613                 .data = NULL,
6614                 .tokens = {
6615                                 (void *)&cmd_removebonding_slave_remove,
6616                                 (void *)&cmd_removebonding_slave_bonding,
6617                                 (void *)&cmd_removebonding_slave_slave,
6618                                 (void *)&cmd_removebonding_slave_slaveid,
6619                                 (void *)&cmd_removebonding_slave_port,
6620                                 NULL
6621                 }
6622 };
6623
6624 /* *** CREATE BONDED DEVICE *** */
6625 struct cmd_create_bonded_device_result {
6626         cmdline_fixed_string_t create;
6627         cmdline_fixed_string_t bonded;
6628         cmdline_fixed_string_t device;
6629         uint8_t mode;
6630         uint8_t socket;
6631 };
6632
6633 static int bond_dev_num = 0;
6634
6635 static void cmd_create_bonded_device_parsed(void *parsed_result,
6636                 __rte_unused  struct cmdline *cl,
6637                 __rte_unused void *data)
6638 {
6639         struct cmd_create_bonded_device_result *res = parsed_result;
6640         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6641         int port_id;
6642         int ret;
6643
6644         if (test_done == 0) {
6645                 fprintf(stderr, "Please stop forwarding first\n");
6646                 return;
6647         }
6648
6649         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6650                         bond_dev_num++);
6651
6652         /* Create a new bonded device. */
6653         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6654         if (port_id < 0) {
6655                 fprintf(stderr, "\t Failed to create bonded device.\n");
6656                 return;
6657         } else {
6658                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6659                                 port_id);
6660
6661                 /* Update number of ports */
6662                 nb_ports = rte_eth_dev_count_avail();
6663                 reconfig(port_id, res->socket);
6664                 ret = rte_eth_promiscuous_enable(port_id);
6665                 if (ret != 0)
6666                         fprintf(stderr,
6667                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6668                                 port_id, rte_strerror(-ret));
6669
6670                 ports[port_id].bond_flag = 1;
6671                 ports[port_id].need_setup = 0;
6672                 ports[port_id].port_status = RTE_PORT_STOPPED;
6673         }
6674
6675 }
6676
6677 cmdline_parse_token_string_t cmd_createbonded_device_create =
6678                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6679                                 create, "create");
6680 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6681                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6682                                 bonded, "bonded");
6683 cmdline_parse_token_string_t cmd_createbonded_device_device =
6684                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6685                                 device, "device");
6686 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6687                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6688                                 mode, RTE_UINT8);
6689 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6690                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6691                                 socket, RTE_UINT8);
6692
6693 cmdline_parse_inst_t cmd_create_bonded_device = {
6694                 .f = cmd_create_bonded_device_parsed,
6695                 .help_str = "create bonded device <mode> <socket>: "
6696                         "Create a new bonded device with specific bonding mode and socket",
6697                 .data = NULL,
6698                 .tokens = {
6699                                 (void *)&cmd_createbonded_device_create,
6700                                 (void *)&cmd_createbonded_device_bonded,
6701                                 (void *)&cmd_createbonded_device_device,
6702                                 (void *)&cmd_createbonded_device_mode,
6703                                 (void *)&cmd_createbonded_device_socket,
6704                                 NULL
6705                 }
6706 };
6707
6708 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6709 struct cmd_set_bond_mac_addr_result {
6710         cmdline_fixed_string_t set;
6711         cmdline_fixed_string_t bonding;
6712         cmdline_fixed_string_t mac_addr;
6713         uint16_t port_num;
6714         struct rte_ether_addr address;
6715 };
6716
6717 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6718                 __rte_unused  struct cmdline *cl,
6719                 __rte_unused void *data)
6720 {
6721         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6722         int ret;
6723
6724         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6725                 return;
6726
6727         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6728
6729         /* check the return value and print it if is < 0 */
6730         if (ret < 0)
6731                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6732                         strerror(-ret));
6733 }
6734
6735 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6736                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6737 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6738                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6739                                 "bonding");
6740 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6741                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6742                                 "mac_addr");
6743 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6744                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6745                                 port_num, RTE_UINT16);
6746 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6747                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6748
6749 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6750                 .f = cmd_set_bond_mac_addr_parsed,
6751                 .data = (void *) 0,
6752                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6753                 .tokens = {
6754                                 (void *)&cmd_set_bond_mac_addr_set,
6755                                 (void *)&cmd_set_bond_mac_addr_bonding,
6756                                 (void *)&cmd_set_bond_mac_addr_mac,
6757                                 (void *)&cmd_set_bond_mac_addr_portnum,
6758                                 (void *)&cmd_set_bond_mac_addr_addr,
6759                                 NULL
6760                 }
6761 };
6762
6763
6764 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6765 struct cmd_set_bond_mon_period_result {
6766         cmdline_fixed_string_t set;
6767         cmdline_fixed_string_t bonding;
6768         cmdline_fixed_string_t mon_period;
6769         uint16_t port_num;
6770         uint32_t period_ms;
6771 };
6772
6773 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6774                 __rte_unused  struct cmdline *cl,
6775                 __rte_unused void *data)
6776 {
6777         struct cmd_set_bond_mon_period_result *res = parsed_result;
6778         int ret;
6779
6780         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6781
6782         /* check the return value and print it if is < 0 */
6783         if (ret < 0)
6784                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6785                         strerror(-ret));
6786 }
6787
6788 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6789                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6790                                 set, "set");
6791 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6792                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6793                                 bonding, "bonding");
6794 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6795                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6796                                 mon_period,     "mon_period");
6797 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6798                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6799                                 port_num, RTE_UINT16);
6800 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6801                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6802                                 period_ms, RTE_UINT32);
6803
6804 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6805                 .f = cmd_set_bond_mon_period_parsed,
6806                 .data = (void *) 0,
6807                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6808                 .tokens = {
6809                                 (void *)&cmd_set_bond_mon_period_set,
6810                                 (void *)&cmd_set_bond_mon_period_bonding,
6811                                 (void *)&cmd_set_bond_mon_period_mon_period,
6812                                 (void *)&cmd_set_bond_mon_period_portnum,
6813                                 (void *)&cmd_set_bond_mon_period_period_ms,
6814                                 NULL
6815                 }
6816 };
6817
6818
6819
6820 struct cmd_set_bonding_agg_mode_policy_result {
6821         cmdline_fixed_string_t set;
6822         cmdline_fixed_string_t bonding;
6823         cmdline_fixed_string_t agg_mode;
6824         uint16_t port_num;
6825         cmdline_fixed_string_t policy;
6826 };
6827
6828
6829 static void
6830 cmd_set_bonding_agg_mode(void *parsed_result,
6831                 __rte_unused struct cmdline *cl,
6832                 __rte_unused void *data)
6833 {
6834         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6835         uint8_t policy = AGG_BANDWIDTH;
6836
6837         if (!strcmp(res->policy, "bandwidth"))
6838                 policy = AGG_BANDWIDTH;
6839         else if (!strcmp(res->policy, "stable"))
6840                 policy = AGG_STABLE;
6841         else if (!strcmp(res->policy, "count"))
6842                 policy = AGG_COUNT;
6843
6844         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6845 }
6846
6847
6848 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6849         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6850                                 set, "set");
6851 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6852         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6853                                 bonding, "bonding");
6854
6855 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6856         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6857                                 agg_mode, "agg_mode");
6858
6859 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6860         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6861                                 port_num, RTE_UINT16);
6862
6863 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6864         TOKEN_STRING_INITIALIZER(
6865                         struct cmd_set_bonding_balance_xmit_policy_result,
6866                 policy, "stable#bandwidth#count");
6867
6868 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6869         .f = cmd_set_bonding_agg_mode,
6870         .data = (void *) 0,
6871         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6872         .tokens = {
6873                         (void *)&cmd_set_bonding_agg_mode_set,
6874                         (void *)&cmd_set_bonding_agg_mode_bonding,
6875                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6876                         (void *)&cmd_set_bonding_agg_mode_portnum,
6877                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6878                         NULL
6879                 }
6880 };
6881
6882
6883 #endif /* RTE_NET_BOND */
6884
6885 /* *** SET FORWARDING MODE *** */
6886 struct cmd_set_fwd_mode_result {
6887         cmdline_fixed_string_t set;
6888         cmdline_fixed_string_t fwd;
6889         cmdline_fixed_string_t mode;
6890 };
6891
6892 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6893                                     __rte_unused struct cmdline *cl,
6894                                     __rte_unused void *data)
6895 {
6896         struct cmd_set_fwd_mode_result *res = parsed_result;
6897
6898         retry_enabled = 0;
6899         set_pkt_forwarding_mode(res->mode);
6900 }
6901
6902 cmdline_parse_token_string_t cmd_setfwd_set =
6903         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6904 cmdline_parse_token_string_t cmd_setfwd_fwd =
6905         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6906 cmdline_parse_token_string_t cmd_setfwd_mode =
6907         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6908                 "" /* defined at init */);
6909
6910 cmdline_parse_inst_t cmd_set_fwd_mode = {
6911         .f = cmd_set_fwd_mode_parsed,
6912         .data = NULL,
6913         .help_str = NULL, /* defined at init */
6914         .tokens = {
6915                 (void *)&cmd_setfwd_set,
6916                 (void *)&cmd_setfwd_fwd,
6917                 (void *)&cmd_setfwd_mode,
6918                 NULL,
6919         },
6920 };
6921
6922 static void cmd_set_fwd_mode_init(void)
6923 {
6924         char *modes, *c;
6925         static char token[128];
6926         static char help[256];
6927         cmdline_parse_token_string_t *token_struct;
6928
6929         modes = list_pkt_forwarding_modes();
6930         snprintf(help, sizeof(help), "set fwd %s: "
6931                 "Set packet forwarding mode", modes);
6932         cmd_set_fwd_mode.help_str = help;
6933
6934         /* string token separator is # */
6935         for (c = token; *modes != '\0'; modes++)
6936                 if (*modes == '|')
6937                         *c++ = '#';
6938                 else
6939                         *c++ = *modes;
6940         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6941         token_struct->string_data.str = token;
6942 }
6943
6944 /* *** SET RETRY FORWARDING MODE *** */
6945 struct cmd_set_fwd_retry_mode_result {
6946         cmdline_fixed_string_t set;
6947         cmdline_fixed_string_t fwd;
6948         cmdline_fixed_string_t mode;
6949         cmdline_fixed_string_t retry;
6950 };
6951
6952 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6953                             __rte_unused struct cmdline *cl,
6954                             __rte_unused void *data)
6955 {
6956         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6957
6958         retry_enabled = 1;
6959         set_pkt_forwarding_mode(res->mode);
6960 }
6961
6962 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6963         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6964                         set, "set");
6965 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6966         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6967                         fwd, "fwd");
6968 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6969         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6970                         mode,
6971                 "" /* defined at init */);
6972 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6973         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6974                         retry, "retry");
6975
6976 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6977         .f = cmd_set_fwd_retry_mode_parsed,
6978         .data = NULL,
6979         .help_str = NULL, /* defined at init */
6980         .tokens = {
6981                 (void *)&cmd_setfwd_retry_set,
6982                 (void *)&cmd_setfwd_retry_fwd,
6983                 (void *)&cmd_setfwd_retry_mode,
6984                 (void *)&cmd_setfwd_retry_retry,
6985                 NULL,
6986         },
6987 };
6988
6989 static void cmd_set_fwd_retry_mode_init(void)
6990 {
6991         char *modes, *c;
6992         static char token[128];
6993         static char help[256];
6994         cmdline_parse_token_string_t *token_struct;
6995
6996         modes = list_pkt_forwarding_retry_modes();
6997         snprintf(help, sizeof(help), "set fwd %s retry: "
6998                 "Set packet forwarding mode with retry", modes);
6999         cmd_set_fwd_retry_mode.help_str = help;
7000
7001         /* string token separator is # */
7002         for (c = token; *modes != '\0'; modes++)
7003                 if (*modes == '|')
7004                         *c++ = '#';
7005                 else
7006                         *c++ = *modes;
7007         token_struct = (cmdline_parse_token_string_t *)
7008                 cmd_set_fwd_retry_mode.tokens[2];
7009         token_struct->string_data.str = token;
7010 }
7011
7012 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7013 struct cmd_set_burst_tx_retry_result {
7014         cmdline_fixed_string_t set;
7015         cmdline_fixed_string_t burst;
7016         cmdline_fixed_string_t tx;
7017         cmdline_fixed_string_t delay;
7018         uint32_t time;
7019         cmdline_fixed_string_t retry;
7020         uint32_t retry_num;
7021 };
7022
7023 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7024                                         __rte_unused struct cmdline *cl,
7025                                         __rte_unused void *data)
7026 {
7027         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7028
7029         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7030                 && !strcmp(res->tx, "tx")) {
7031                 if (!strcmp(res->delay, "delay"))
7032                         burst_tx_delay_time = res->time;
7033                 if (!strcmp(res->retry, "retry"))
7034                         burst_tx_retry_num = res->retry_num;
7035         }
7036
7037 }
7038
7039 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7040         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7041 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7042         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7043                                  "burst");
7044 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7045         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7046 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7047         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7048 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7049         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7050                                  RTE_UINT32);
7051 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7052         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7053 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7054         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7055                                  RTE_UINT32);
7056
7057 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7058         .f = cmd_set_burst_tx_retry_parsed,
7059         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7060         .tokens = {
7061                 (void *)&cmd_set_burst_tx_retry_set,
7062                 (void *)&cmd_set_burst_tx_retry_burst,
7063                 (void *)&cmd_set_burst_tx_retry_tx,
7064                 (void *)&cmd_set_burst_tx_retry_delay,
7065                 (void *)&cmd_set_burst_tx_retry_time,
7066                 (void *)&cmd_set_burst_tx_retry_retry,
7067                 (void *)&cmd_set_burst_tx_retry_retry_num,
7068                 NULL,
7069         },
7070 };
7071
7072 /* *** SET PROMISC MODE *** */
7073 struct cmd_set_promisc_mode_result {
7074         cmdline_fixed_string_t set;
7075         cmdline_fixed_string_t promisc;
7076         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7077         uint16_t port_num;               /* valid if "allports" argument == 0 */
7078         cmdline_fixed_string_t mode;
7079 };
7080
7081 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7082                                         __rte_unused struct cmdline *cl,
7083                                         void *allports)
7084 {
7085         struct cmd_set_promisc_mode_result *res = parsed_result;
7086         int enable;
7087         portid_t i;
7088
7089         if (!strcmp(res->mode, "on"))
7090                 enable = 1;
7091         else
7092                 enable = 0;
7093
7094         /* all ports */
7095         if (allports) {
7096                 RTE_ETH_FOREACH_DEV(i)
7097                         eth_set_promisc_mode(i, enable);
7098         } else {
7099                 eth_set_promisc_mode(res->port_num, enable);
7100         }
7101 }
7102
7103 cmdline_parse_token_string_t cmd_setpromisc_set =
7104         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7105 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7106         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7107                                  "promisc");
7108 cmdline_parse_token_string_t cmd_setpromisc_portall =
7109         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7110                                  "all");
7111 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7112         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7113                               RTE_UINT16);
7114 cmdline_parse_token_string_t cmd_setpromisc_mode =
7115         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7116                                  "on#off");
7117
7118 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7119         .f = cmd_set_promisc_mode_parsed,
7120         .data = (void *)1,
7121         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7122         .tokens = {
7123                 (void *)&cmd_setpromisc_set,
7124                 (void *)&cmd_setpromisc_promisc,
7125                 (void *)&cmd_setpromisc_portall,
7126                 (void *)&cmd_setpromisc_mode,
7127                 NULL,
7128         },
7129 };
7130
7131 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7132         .f = cmd_set_promisc_mode_parsed,
7133         .data = (void *)0,
7134         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7135         .tokens = {
7136                 (void *)&cmd_setpromisc_set,
7137                 (void *)&cmd_setpromisc_promisc,
7138                 (void *)&cmd_setpromisc_portnum,
7139                 (void *)&cmd_setpromisc_mode,
7140                 NULL,
7141         },
7142 };
7143
7144 /* *** SET ALLMULTI MODE *** */
7145 struct cmd_set_allmulti_mode_result {
7146         cmdline_fixed_string_t set;
7147         cmdline_fixed_string_t allmulti;
7148         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7149         uint16_t port_num;               /* valid if "allports" argument == 0 */
7150         cmdline_fixed_string_t mode;
7151 };
7152
7153 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7154                                         __rte_unused struct cmdline *cl,
7155                                         void *allports)
7156 {
7157         struct cmd_set_allmulti_mode_result *res = parsed_result;
7158         int enable;
7159         portid_t i;
7160
7161         if (!strcmp(res->mode, "on"))
7162                 enable = 1;
7163         else
7164                 enable = 0;
7165
7166         /* all ports */
7167         if (allports) {
7168                 RTE_ETH_FOREACH_DEV(i) {
7169                         eth_set_allmulticast_mode(i, enable);
7170                 }
7171         }
7172         else {
7173                 eth_set_allmulticast_mode(res->port_num, enable);
7174         }
7175 }
7176
7177 cmdline_parse_token_string_t cmd_setallmulti_set =
7178         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7179 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7180         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7181                                  "allmulti");
7182 cmdline_parse_token_string_t cmd_setallmulti_portall =
7183         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7184                                  "all");
7185 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7186         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7187                               RTE_UINT16);
7188 cmdline_parse_token_string_t cmd_setallmulti_mode =
7189         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7190                                  "on#off");
7191
7192 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7193         .f = cmd_set_allmulti_mode_parsed,
7194         .data = (void *)1,
7195         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7196         .tokens = {
7197                 (void *)&cmd_setallmulti_set,
7198                 (void *)&cmd_setallmulti_allmulti,
7199                 (void *)&cmd_setallmulti_portall,
7200                 (void *)&cmd_setallmulti_mode,
7201                 NULL,
7202         },
7203 };
7204
7205 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7206         .f = cmd_set_allmulti_mode_parsed,
7207         .data = (void *)0,
7208         .help_str = "set allmulti <port_id> on|off: "
7209                 "Set allmulti mode on port_id",
7210         .tokens = {
7211                 (void *)&cmd_setallmulti_set,
7212                 (void *)&cmd_setallmulti_allmulti,
7213                 (void *)&cmd_setallmulti_portnum,
7214                 (void *)&cmd_setallmulti_mode,
7215                 NULL,
7216         },
7217 };
7218
7219 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7220 struct cmd_link_flow_ctrl_show {
7221         cmdline_fixed_string_t show;
7222         cmdline_fixed_string_t port;
7223         portid_t port_id;
7224         cmdline_fixed_string_t flow_ctrl;
7225 };
7226
7227 cmdline_parse_token_string_t cmd_lfc_show_show =
7228         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7229                                 show, "show");
7230 cmdline_parse_token_string_t cmd_lfc_show_port =
7231         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7232                                 port, "port");
7233 cmdline_parse_token_num_t cmd_lfc_show_portid =
7234         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7235                                 port_id, RTE_UINT16);
7236 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7237         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7238                                 flow_ctrl, "flow_ctrl");
7239
7240 static void
7241 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7242                               __rte_unused struct cmdline *cl,
7243                               __rte_unused void *data)
7244 {
7245         struct cmd_link_flow_ctrl_show *res = parsed_result;
7246         static const char *info_border = "*********************";
7247         struct rte_eth_fc_conf fc_conf;
7248         bool rx_fc_en = false;
7249         bool tx_fc_en = false;
7250         int ret;
7251
7252         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7253         if (ret != 0) {
7254                 fprintf(stderr,
7255                         "Failed to get current flow ctrl information: err = %d\n",
7256                         ret);
7257                 return;
7258         }
7259
7260         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7261                 rx_fc_en = true;
7262         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7263                 tx_fc_en = true;
7264
7265         printf("\n%s Flow control infos for port %-2d %s\n",
7266                 info_border, res->port_id, info_border);
7267         printf("FC mode:\n");
7268         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7269         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7270         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7271         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7272         printf("High waterline: 0x%x\n", fc_conf.high_water);
7273         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7274         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7275         printf("Forward MAC control frames: %s\n",
7276                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7277         printf("\n%s**************   End  ***********%s\n",
7278                 info_border, info_border);
7279 }
7280
7281 cmdline_parse_inst_t cmd_link_flow_control_show = {
7282         .f = cmd_link_flow_ctrl_show_parsed,
7283         .data = NULL,
7284         .help_str = "show port <port_id> flow_ctrl",
7285         .tokens = {
7286                 (void *)&cmd_lfc_show_show,
7287                 (void *)&cmd_lfc_show_port,
7288                 (void *)&cmd_lfc_show_portid,
7289                 (void *)&cmd_lfc_show_flow_ctrl,
7290                 NULL,
7291         },
7292 };
7293
7294 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7295 struct cmd_link_flow_ctrl_set_result {
7296         cmdline_fixed_string_t set;
7297         cmdline_fixed_string_t flow_ctrl;
7298         cmdline_fixed_string_t rx;
7299         cmdline_fixed_string_t rx_lfc_mode;
7300         cmdline_fixed_string_t tx;
7301         cmdline_fixed_string_t tx_lfc_mode;
7302         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7303         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7304         cmdline_fixed_string_t autoneg_str;
7305         cmdline_fixed_string_t autoneg;
7306         cmdline_fixed_string_t hw_str;
7307         uint32_t high_water;
7308         cmdline_fixed_string_t lw_str;
7309         uint32_t low_water;
7310         cmdline_fixed_string_t pt_str;
7311         uint16_t pause_time;
7312         cmdline_fixed_string_t xon_str;
7313         uint16_t send_xon;
7314         portid_t port_id;
7315 };
7316
7317 cmdline_parse_token_string_t cmd_lfc_set_set =
7318         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7319                                 set, "set");
7320 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7321         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7322                                 flow_ctrl, "flow_ctrl");
7323 cmdline_parse_token_string_t cmd_lfc_set_rx =
7324         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7325                                 rx, "rx");
7326 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7327         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7328                                 rx_lfc_mode, "on#off");
7329 cmdline_parse_token_string_t cmd_lfc_set_tx =
7330         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7331                                 tx, "tx");
7332 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7333         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7334                                 tx_lfc_mode, "on#off");
7335 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7336         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7337                                 hw_str, "high_water");
7338 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7339         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7340                                 high_water, RTE_UINT32);
7341 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7342         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7343                                 lw_str, "low_water");
7344 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7345         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7346                                 low_water, RTE_UINT32);
7347 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7348         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7349                                 pt_str, "pause_time");
7350 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7351         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7352                                 pause_time, RTE_UINT16);
7353 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7354         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7355                                 xon_str, "send_xon");
7356 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7357         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7358                                 send_xon, RTE_UINT16);
7359 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7360         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7361                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7362 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7363         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7364                                 mac_ctrl_frame_fwd_mode, "on#off");
7365 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7366         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7367                                 autoneg_str, "autoneg");
7368 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7369         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7370                                 autoneg, "on#off");
7371 cmdline_parse_token_num_t cmd_lfc_set_portid =
7372         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7373                                 port_id, RTE_UINT16);
7374
7375 /* forward declaration */
7376 static void
7377 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7378                               void *data);
7379
7380 cmdline_parse_inst_t cmd_link_flow_control_set = {
7381         .f = cmd_link_flow_ctrl_set_parsed,
7382         .data = NULL,
7383         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7384                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7385                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7386         .tokens = {
7387                 (void *)&cmd_lfc_set_set,
7388                 (void *)&cmd_lfc_set_flow_ctrl,
7389                 (void *)&cmd_lfc_set_rx,
7390                 (void *)&cmd_lfc_set_rx_mode,
7391                 (void *)&cmd_lfc_set_tx,
7392                 (void *)&cmd_lfc_set_tx_mode,
7393                 (void *)&cmd_lfc_set_high_water,
7394                 (void *)&cmd_lfc_set_low_water,
7395                 (void *)&cmd_lfc_set_pause_time,
7396                 (void *)&cmd_lfc_set_send_xon,
7397                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7398                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7399                 (void *)&cmd_lfc_set_autoneg_str,
7400                 (void *)&cmd_lfc_set_autoneg,
7401                 (void *)&cmd_lfc_set_portid,
7402                 NULL,
7403         },
7404 };
7405
7406 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7407         .f = cmd_link_flow_ctrl_set_parsed,
7408         .data = (void *)&cmd_link_flow_control_set_rx,
7409         .help_str = "set flow_ctrl rx on|off <port_id>: "
7410                 "Change rx flow control parameter",
7411         .tokens = {
7412                 (void *)&cmd_lfc_set_set,
7413                 (void *)&cmd_lfc_set_flow_ctrl,
7414                 (void *)&cmd_lfc_set_rx,
7415                 (void *)&cmd_lfc_set_rx_mode,
7416                 (void *)&cmd_lfc_set_portid,
7417                 NULL,
7418         },
7419 };
7420
7421 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7422         .f = cmd_link_flow_ctrl_set_parsed,
7423         .data = (void *)&cmd_link_flow_control_set_tx,
7424         .help_str = "set flow_ctrl tx on|off <port_id>: "
7425                 "Change tx flow control parameter",
7426         .tokens = {
7427                 (void *)&cmd_lfc_set_set,
7428                 (void *)&cmd_lfc_set_flow_ctrl,
7429                 (void *)&cmd_lfc_set_tx,
7430                 (void *)&cmd_lfc_set_tx_mode,
7431                 (void *)&cmd_lfc_set_portid,
7432                 NULL,
7433         },
7434 };
7435
7436 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7437         .f = cmd_link_flow_ctrl_set_parsed,
7438         .data = (void *)&cmd_link_flow_control_set_hw,
7439         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7440                 "Change high water flow control parameter",
7441         .tokens = {
7442                 (void *)&cmd_lfc_set_set,
7443                 (void *)&cmd_lfc_set_flow_ctrl,
7444                 (void *)&cmd_lfc_set_high_water_str,
7445                 (void *)&cmd_lfc_set_high_water,
7446                 (void *)&cmd_lfc_set_portid,
7447                 NULL,
7448         },
7449 };
7450
7451 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7452         .f = cmd_link_flow_ctrl_set_parsed,
7453         .data = (void *)&cmd_link_flow_control_set_lw,
7454         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7455                 "Change low water flow control parameter",
7456         .tokens = {
7457                 (void *)&cmd_lfc_set_set,
7458                 (void *)&cmd_lfc_set_flow_ctrl,
7459                 (void *)&cmd_lfc_set_low_water_str,
7460                 (void *)&cmd_lfc_set_low_water,
7461                 (void *)&cmd_lfc_set_portid,
7462                 NULL,
7463         },
7464 };
7465
7466 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7467         .f = cmd_link_flow_ctrl_set_parsed,
7468         .data = (void *)&cmd_link_flow_control_set_pt,
7469         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7470                 "Change pause time flow control parameter",
7471         .tokens = {
7472                 (void *)&cmd_lfc_set_set,
7473                 (void *)&cmd_lfc_set_flow_ctrl,
7474                 (void *)&cmd_lfc_set_pause_time_str,
7475                 (void *)&cmd_lfc_set_pause_time,
7476                 (void *)&cmd_lfc_set_portid,
7477                 NULL,
7478         },
7479 };
7480
7481 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7482         .f = cmd_link_flow_ctrl_set_parsed,
7483         .data = (void *)&cmd_link_flow_control_set_xon,
7484         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7485                 "Change send_xon flow control parameter",
7486         .tokens = {
7487                 (void *)&cmd_lfc_set_set,
7488                 (void *)&cmd_lfc_set_flow_ctrl,
7489                 (void *)&cmd_lfc_set_send_xon_str,
7490                 (void *)&cmd_lfc_set_send_xon,
7491                 (void *)&cmd_lfc_set_portid,
7492                 NULL,
7493         },
7494 };
7495
7496 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7497         .f = cmd_link_flow_ctrl_set_parsed,
7498         .data = (void *)&cmd_link_flow_control_set_macfwd,
7499         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7500                 "Change mac ctrl fwd flow control parameter",
7501         .tokens = {
7502                 (void *)&cmd_lfc_set_set,
7503                 (void *)&cmd_lfc_set_flow_ctrl,
7504                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7505                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7506                 (void *)&cmd_lfc_set_portid,
7507                 NULL,
7508         },
7509 };
7510
7511 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7512         .f = cmd_link_flow_ctrl_set_parsed,
7513         .data = (void *)&cmd_link_flow_control_set_autoneg,
7514         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7515                 "Change autoneg flow control parameter",
7516         .tokens = {
7517                 (void *)&cmd_lfc_set_set,
7518                 (void *)&cmd_lfc_set_flow_ctrl,
7519                 (void *)&cmd_lfc_set_autoneg_str,
7520                 (void *)&cmd_lfc_set_autoneg,
7521                 (void *)&cmd_lfc_set_portid,
7522                 NULL,
7523         },
7524 };
7525
7526 static void
7527 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7528                               __rte_unused struct cmdline *cl,
7529                               void *data)
7530 {
7531         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7532         cmdline_parse_inst_t *cmd = data;
7533         struct rte_eth_fc_conf fc_conf;
7534         int rx_fc_en = 0;
7535         int tx_fc_en = 0;
7536         int ret;
7537
7538         /*
7539          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7540          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7541          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7542          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7543          */
7544         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7545                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7546         };
7547
7548         /* Partial command line, retrieve current configuration */
7549         if (cmd) {
7550                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7551                 if (ret != 0) {
7552                         fprintf(stderr,
7553                                 "cannot get current flow ctrl parameters, return code = %d\n",
7554                                 ret);
7555                         return;
7556                 }
7557
7558                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7559                     (fc_conf.mode == RTE_ETH_FC_FULL))
7560                         rx_fc_en = 1;
7561                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7562                     (fc_conf.mode == RTE_ETH_FC_FULL))
7563                         tx_fc_en = 1;
7564         }
7565
7566         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7567                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7568
7569         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7570                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7571
7572         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7573
7574         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7575                 fc_conf.high_water = res->high_water;
7576
7577         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7578                 fc_conf.low_water = res->low_water;
7579
7580         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7581                 fc_conf.pause_time = res->pause_time;
7582
7583         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7584                 fc_conf.send_xon = res->send_xon;
7585
7586         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7587                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7588                         fc_conf.mac_ctrl_frame_fwd = 1;
7589                 else
7590                         fc_conf.mac_ctrl_frame_fwd = 0;
7591         }
7592
7593         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7594                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7595
7596         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7597         if (ret != 0)
7598                 fprintf(stderr,
7599                         "bad flow control parameter, return code = %d\n",
7600                         ret);
7601 }
7602
7603 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7604 struct cmd_priority_flow_ctrl_set_result {
7605         cmdline_fixed_string_t set;
7606         cmdline_fixed_string_t pfc_ctrl;
7607         cmdline_fixed_string_t rx;
7608         cmdline_fixed_string_t rx_pfc_mode;
7609         cmdline_fixed_string_t tx;
7610         cmdline_fixed_string_t tx_pfc_mode;
7611         uint32_t high_water;
7612         uint32_t low_water;
7613         uint16_t pause_time;
7614         uint8_t  priority;
7615         portid_t port_id;
7616 };
7617
7618 static void
7619 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7620                        __rte_unused struct cmdline *cl,
7621                        __rte_unused void *data)
7622 {
7623         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7624         struct rte_eth_pfc_conf pfc_conf;
7625         int rx_fc_enable, tx_fc_enable;
7626         int ret;
7627
7628         /*
7629          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7630          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7631          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7632          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7633          */
7634         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7635                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7636         };
7637
7638         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7639         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7640         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7641         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7642         pfc_conf.fc.high_water = res->high_water;
7643         pfc_conf.fc.low_water  = res->low_water;
7644         pfc_conf.fc.pause_time = res->pause_time;
7645         pfc_conf.priority      = res->priority;
7646
7647         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7648         if (ret != 0)
7649                 fprintf(stderr,
7650                         "bad priority flow control parameter, return code = %d\n",
7651                         ret);
7652 }
7653
7654 cmdline_parse_token_string_t cmd_pfc_set_set =
7655         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7656                                 set, "set");
7657 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7658         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7659                                 pfc_ctrl, "pfc_ctrl");
7660 cmdline_parse_token_string_t cmd_pfc_set_rx =
7661         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7662                                 rx, "rx");
7663 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7664         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7665                                 rx_pfc_mode, "on#off");
7666 cmdline_parse_token_string_t cmd_pfc_set_tx =
7667         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7668                                 tx, "tx");
7669 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7670         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7671                                 tx_pfc_mode, "on#off");
7672 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7673         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7674                                 high_water, RTE_UINT32);
7675 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7676         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7677                                 low_water, RTE_UINT32);
7678 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7679         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7680                                 pause_time, RTE_UINT16);
7681 cmdline_parse_token_num_t cmd_pfc_set_priority =
7682         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7683                                 priority, RTE_UINT8);
7684 cmdline_parse_token_num_t cmd_pfc_set_portid =
7685         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7686                                 port_id, RTE_UINT16);
7687
7688 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7689         .f = cmd_priority_flow_ctrl_set_parsed,
7690         .data = NULL,
7691         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7692                 "<pause_time> <priority> <port_id>: "
7693                 "Configure the Ethernet priority flow control",
7694         .tokens = {
7695                 (void *)&cmd_pfc_set_set,
7696                 (void *)&cmd_pfc_set_flow_ctrl,
7697                 (void *)&cmd_pfc_set_rx,
7698                 (void *)&cmd_pfc_set_rx_mode,
7699                 (void *)&cmd_pfc_set_tx,
7700                 (void *)&cmd_pfc_set_tx_mode,
7701                 (void *)&cmd_pfc_set_high_water,
7702                 (void *)&cmd_pfc_set_low_water,
7703                 (void *)&cmd_pfc_set_pause_time,
7704                 (void *)&cmd_pfc_set_priority,
7705                 (void *)&cmd_pfc_set_portid,
7706                 NULL,
7707         },
7708 };
7709
7710 struct cmd_queue_priority_flow_ctrl_set_result {
7711         cmdline_fixed_string_t set;
7712         cmdline_fixed_string_t pfc_queue_ctrl;
7713         portid_t port_id;
7714         cmdline_fixed_string_t rx;
7715         cmdline_fixed_string_t rx_pfc_mode;
7716         uint16_t tx_qid;
7717         uint8_t  tx_tc;
7718         cmdline_fixed_string_t tx;
7719         cmdline_fixed_string_t tx_pfc_mode;
7720         uint16_t rx_qid;
7721         uint8_t  rx_tc;
7722         uint16_t pause_time;
7723 };
7724
7725 static void
7726 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7727                                         __rte_unused struct cmdline *cl,
7728                                         __rte_unused void *data)
7729 {
7730         struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7731         struct rte_eth_pfc_queue_conf pfc_queue_conf;
7732         int rx_fc_enable, tx_fc_enable;
7733         int ret;
7734
7735         /*
7736          * Rx on/off, flow control is enabled/disabled on RX side. This can
7737          * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7738          * side. Tx on/off, flow control is enabled/disabled on TX side. This
7739          * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7740          * the Tx side.
7741          */
7742         static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7743                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7744                 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7745         };
7746
7747         memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7748         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7749         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7750         pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7751         pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7752         pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7753         pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7754         pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7755         pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7756
7757         ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7758                                                              &pfc_queue_conf);
7759         if (ret != 0) {
7760                 fprintf(stderr,
7761                         "bad queue priority flow control parameter, rc = %d\n",
7762                         ret);
7763         }
7764 }
7765
7766 cmdline_parse_token_string_t cmd_q_pfc_set_set =
7767         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7768                                 set, "set");
7769 cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7770         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7771                                 pfc_queue_ctrl, "pfc_queue_ctrl");
7772 cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7773         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7774                                 port_id, RTE_UINT16);
7775 cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7776         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7777                                 rx, "rx");
7778 cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7779         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7780                                 rx_pfc_mode, "on#off");
7781 cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7782         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7783                                 tx_qid, RTE_UINT16);
7784 cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7785         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7786                                 tx_tc, RTE_UINT8);
7787 cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7788         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7789                                 tx, "tx");
7790 cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7791         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7792                                 tx_pfc_mode, "on#off");
7793 cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7794         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7795                                 rx_qid, RTE_UINT16);
7796 cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7797         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7798                                 rx_tc, RTE_UINT8);
7799 cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7800         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7801                                 pause_time, RTE_UINT16);
7802
7803 cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7804         .f = cmd_queue_priority_flow_ctrl_set_parsed,
7805         .data = NULL,
7806         .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7807                 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7808                 "Configure the Ethernet queue priority flow control",
7809         .tokens = {
7810                 (void *)&cmd_q_pfc_set_set,
7811                 (void *)&cmd_q_pfc_set_flow_ctrl,
7812                 (void *)&cmd_q_pfc_set_portid,
7813                 (void *)&cmd_q_pfc_set_rx,
7814                 (void *)&cmd_q_pfc_set_rx_mode,
7815                 (void *)&cmd_q_pfc_set_tx_qid,
7816                 (void *)&cmd_q_pfc_set_tx_tc,
7817                 (void *)&cmd_q_pfc_set_tx,
7818                 (void *)&cmd_q_pfc_set_tx_mode,
7819                 (void *)&cmd_q_pfc_set_rx_qid,
7820                 (void *)&cmd_q_pfc_set_rx_tc,
7821                 (void *)&cmd_q_pfc_set_pause_time,
7822                 NULL,
7823         },
7824 };
7825
7826 /* *** RESET CONFIGURATION *** */
7827 struct cmd_reset_result {
7828         cmdline_fixed_string_t reset;
7829         cmdline_fixed_string_t def;
7830 };
7831
7832 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7833                              struct cmdline *cl,
7834                              __rte_unused void *data)
7835 {
7836         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7837         set_def_fwd_config();
7838 }
7839
7840 cmdline_parse_token_string_t cmd_reset_set =
7841         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7842 cmdline_parse_token_string_t cmd_reset_def =
7843         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7844                                  "default");
7845
7846 cmdline_parse_inst_t cmd_reset = {
7847         .f = cmd_reset_parsed,
7848         .data = NULL,
7849         .help_str = "set default: Reset default forwarding configuration",
7850         .tokens = {
7851                 (void *)&cmd_reset_set,
7852                 (void *)&cmd_reset_def,
7853                 NULL,
7854         },
7855 };
7856
7857 /* *** START FORWARDING *** */
7858 struct cmd_start_result {
7859         cmdline_fixed_string_t start;
7860 };
7861
7862 cmdline_parse_token_string_t cmd_start_start =
7863         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7864
7865 static void cmd_start_parsed(__rte_unused void *parsed_result,
7866                              __rte_unused struct cmdline *cl,
7867                              __rte_unused void *data)
7868 {
7869         start_packet_forwarding(0);
7870 }
7871
7872 cmdline_parse_inst_t cmd_start = {
7873         .f = cmd_start_parsed,
7874         .data = NULL,
7875         .help_str = "start: Start packet forwarding",
7876         .tokens = {
7877                 (void *)&cmd_start_start,
7878                 NULL,
7879         },
7880 };
7881
7882 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7883 struct cmd_start_tx_first_result {
7884         cmdline_fixed_string_t start;
7885         cmdline_fixed_string_t tx_first;
7886 };
7887
7888 static void
7889 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7890                           __rte_unused struct cmdline *cl,
7891                           __rte_unused void *data)
7892 {
7893         start_packet_forwarding(1);
7894 }
7895
7896 cmdline_parse_token_string_t cmd_start_tx_first_start =
7897         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7898                                  "start");
7899 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7900         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7901                                  tx_first, "tx_first");
7902
7903 cmdline_parse_inst_t cmd_start_tx_first = {
7904         .f = cmd_start_tx_first_parsed,
7905         .data = NULL,
7906         .help_str = "start tx_first: Start packet forwarding, "
7907                 "after sending 1 burst of packets",
7908         .tokens = {
7909                 (void *)&cmd_start_tx_first_start,
7910                 (void *)&cmd_start_tx_first_tx_first,
7911                 NULL,
7912         },
7913 };
7914
7915 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7916 struct cmd_start_tx_first_n_result {
7917         cmdline_fixed_string_t start;
7918         cmdline_fixed_string_t tx_first;
7919         uint32_t tx_num;
7920 };
7921
7922 static void
7923 cmd_start_tx_first_n_parsed(void *parsed_result,
7924                           __rte_unused struct cmdline *cl,
7925                           __rte_unused void *data)
7926 {
7927         struct cmd_start_tx_first_n_result *res = parsed_result;
7928
7929         start_packet_forwarding(res->tx_num);
7930 }
7931
7932 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7933         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7934                         start, "start");
7935 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7936         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7937                         tx_first, "tx_first");
7938 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7939         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7940                         tx_num, RTE_UINT32);
7941
7942 cmdline_parse_inst_t cmd_start_tx_first_n = {
7943         .f = cmd_start_tx_first_n_parsed,
7944         .data = NULL,
7945         .help_str = "start tx_first <num>: "
7946                 "packet forwarding, after sending <num> bursts of packets",
7947         .tokens = {
7948                 (void *)&cmd_start_tx_first_n_start,
7949                 (void *)&cmd_start_tx_first_n_tx_first,
7950                 (void *)&cmd_start_tx_first_n_tx_num,
7951                 NULL,
7952         },
7953 };
7954
7955 /* *** SET LINK UP *** */
7956 struct cmd_set_link_up_result {
7957         cmdline_fixed_string_t set;
7958         cmdline_fixed_string_t link_up;
7959         cmdline_fixed_string_t port;
7960         portid_t port_id;
7961 };
7962
7963 cmdline_parse_token_string_t cmd_set_link_up_set =
7964         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7965 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7966         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7967                                 "link-up");
7968 cmdline_parse_token_string_t cmd_set_link_up_port =
7969         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7970 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7971         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7972                                 RTE_UINT16);
7973
7974 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7975                              __rte_unused struct cmdline *cl,
7976                              __rte_unused void *data)
7977 {
7978         struct cmd_set_link_up_result *res = parsed_result;
7979         dev_set_link_up(res->port_id);
7980 }
7981
7982 cmdline_parse_inst_t cmd_set_link_up = {
7983         .f = cmd_set_link_up_parsed,
7984         .data = NULL,
7985         .help_str = "set link-up port <port id>",
7986         .tokens = {
7987                 (void *)&cmd_set_link_up_set,
7988                 (void *)&cmd_set_link_up_link_up,
7989                 (void *)&cmd_set_link_up_port,
7990                 (void *)&cmd_set_link_up_port_id,
7991                 NULL,
7992         },
7993 };
7994
7995 /* *** SET LINK DOWN *** */
7996 struct cmd_set_link_down_result {
7997         cmdline_fixed_string_t set;
7998         cmdline_fixed_string_t link_down;
7999         cmdline_fixed_string_t port;
8000         portid_t port_id;
8001 };
8002
8003 cmdline_parse_token_string_t cmd_set_link_down_set =
8004         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8005 cmdline_parse_token_string_t cmd_set_link_down_link_down =
8006         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8007                                 "link-down");
8008 cmdline_parse_token_string_t cmd_set_link_down_port =
8009         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8010 cmdline_parse_token_num_t cmd_set_link_down_port_id =
8011         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8012                                 RTE_UINT16);
8013
8014 static void cmd_set_link_down_parsed(
8015                                 __rte_unused void *parsed_result,
8016                                 __rte_unused struct cmdline *cl,
8017                                 __rte_unused void *data)
8018 {
8019         struct cmd_set_link_down_result *res = parsed_result;
8020         dev_set_link_down(res->port_id);
8021 }
8022
8023 cmdline_parse_inst_t cmd_set_link_down = {
8024         .f = cmd_set_link_down_parsed,
8025         .data = NULL,
8026         .help_str = "set link-down port <port id>",
8027         .tokens = {
8028                 (void *)&cmd_set_link_down_set,
8029                 (void *)&cmd_set_link_down_link_down,
8030                 (void *)&cmd_set_link_down_port,
8031                 (void *)&cmd_set_link_down_port_id,
8032                 NULL,
8033         },
8034 };
8035
8036 /* *** SHOW CFG *** */
8037 struct cmd_showcfg_result {
8038         cmdline_fixed_string_t show;
8039         cmdline_fixed_string_t cfg;
8040         cmdline_fixed_string_t what;
8041 };
8042
8043 static void cmd_showcfg_parsed(void *parsed_result,
8044                                __rte_unused struct cmdline *cl,
8045                                __rte_unused void *data)
8046 {
8047         struct cmd_showcfg_result *res = parsed_result;
8048         if (!strcmp(res->what, "rxtx"))
8049                 rxtx_config_display();
8050         else if (!strcmp(res->what, "cores"))
8051                 fwd_lcores_config_display();
8052         else if (!strcmp(res->what, "fwd"))
8053                 pkt_fwd_config_display(&cur_fwd_config);
8054         else if (!strcmp(res->what, "rxoffs"))
8055                 show_rx_pkt_offsets();
8056         else if (!strcmp(res->what, "rxpkts"))
8057                 show_rx_pkt_segments();
8058         else if (!strcmp(res->what, "txpkts"))
8059                 show_tx_pkt_segments();
8060         else if (!strcmp(res->what, "txtimes"))
8061                 show_tx_pkt_times();
8062 }
8063
8064 cmdline_parse_token_string_t cmd_showcfg_show =
8065         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8066 cmdline_parse_token_string_t cmd_showcfg_port =
8067         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8068 cmdline_parse_token_string_t cmd_showcfg_what =
8069         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8070                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8071
8072 cmdline_parse_inst_t cmd_showcfg = {
8073         .f = cmd_showcfg_parsed,
8074         .data = NULL,
8075         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8076         .tokens = {
8077                 (void *)&cmd_showcfg_show,
8078                 (void *)&cmd_showcfg_port,
8079                 (void *)&cmd_showcfg_what,
8080                 NULL,
8081         },
8082 };
8083
8084 /* *** SHOW ALL PORT INFO *** */
8085 struct cmd_showportall_result {
8086         cmdline_fixed_string_t show;
8087         cmdline_fixed_string_t port;
8088         cmdline_fixed_string_t what;
8089         cmdline_fixed_string_t all;
8090 };
8091
8092 static void cmd_showportall_parsed(void *parsed_result,
8093                                 __rte_unused struct cmdline *cl,
8094                                 __rte_unused void *data)
8095 {
8096         portid_t i;
8097
8098         struct cmd_showportall_result *res = parsed_result;
8099         if (!strcmp(res->show, "clear")) {
8100                 if (!strcmp(res->what, "stats"))
8101                         RTE_ETH_FOREACH_DEV(i)
8102                                 nic_stats_clear(i);
8103                 else if (!strcmp(res->what, "xstats"))
8104                         RTE_ETH_FOREACH_DEV(i)
8105                                 nic_xstats_clear(i);
8106         } else if (!strcmp(res->what, "info"))
8107                 RTE_ETH_FOREACH_DEV(i)
8108                         port_infos_display(i);
8109         else if (!strcmp(res->what, "summary")) {
8110                 port_summary_header_display();
8111                 RTE_ETH_FOREACH_DEV(i)
8112                         port_summary_display(i);
8113         }
8114         else if (!strcmp(res->what, "stats"))
8115                 RTE_ETH_FOREACH_DEV(i)
8116                         nic_stats_display(i);
8117         else if (!strcmp(res->what, "xstats"))
8118                 RTE_ETH_FOREACH_DEV(i)
8119                         nic_xstats_display(i);
8120 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8121         else if (!strcmp(res->what, "fdir"))
8122                 RTE_ETH_FOREACH_DEV(i)
8123                         fdir_get_infos(i);
8124 #endif
8125         else if (!strcmp(res->what, "dcb_tc"))
8126                 RTE_ETH_FOREACH_DEV(i)
8127                         port_dcb_info_display(i);
8128 }
8129
8130 cmdline_parse_token_string_t cmd_showportall_show =
8131         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8132                                  "show#clear");
8133 cmdline_parse_token_string_t cmd_showportall_port =
8134         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8135 cmdline_parse_token_string_t cmd_showportall_what =
8136         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8137                                  "info#summary#stats#xstats#fdir#dcb_tc");
8138 cmdline_parse_token_string_t cmd_showportall_all =
8139         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8140 cmdline_parse_inst_t cmd_showportall = {
8141         .f = cmd_showportall_parsed,
8142         .data = NULL,
8143         .help_str = "show|clear port "
8144                 "info|summary|stats|xstats|fdir|dcb_tc all",
8145         .tokens = {
8146                 (void *)&cmd_showportall_show,
8147                 (void *)&cmd_showportall_port,
8148                 (void *)&cmd_showportall_what,
8149                 (void *)&cmd_showportall_all,
8150                 NULL,
8151         },
8152 };
8153
8154 /* *** SHOW PORT INFO *** */
8155 struct cmd_showport_result {
8156         cmdline_fixed_string_t show;
8157         cmdline_fixed_string_t port;
8158         cmdline_fixed_string_t what;
8159         uint16_t portnum;
8160 };
8161
8162 static void cmd_showport_parsed(void *parsed_result,
8163                                 __rte_unused struct cmdline *cl,
8164                                 __rte_unused void *data)
8165 {
8166         struct cmd_showport_result *res = parsed_result;
8167         if (!strcmp(res->show, "clear")) {
8168                 if (!strcmp(res->what, "stats"))
8169                         nic_stats_clear(res->portnum);
8170                 else if (!strcmp(res->what, "xstats"))
8171                         nic_xstats_clear(res->portnum);
8172         } else if (!strcmp(res->what, "info"))
8173                 port_infos_display(res->portnum);
8174         else if (!strcmp(res->what, "summary")) {
8175                 port_summary_header_display();
8176                 port_summary_display(res->portnum);
8177         }
8178         else if (!strcmp(res->what, "stats"))
8179                 nic_stats_display(res->portnum);
8180         else if (!strcmp(res->what, "xstats"))
8181                 nic_xstats_display(res->portnum);
8182 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8183         else if (!strcmp(res->what, "fdir"))
8184                  fdir_get_infos(res->portnum);
8185 #endif
8186         else if (!strcmp(res->what, "dcb_tc"))
8187                 port_dcb_info_display(res->portnum);
8188 }
8189
8190 cmdline_parse_token_string_t cmd_showport_show =
8191         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8192                                  "show#clear");
8193 cmdline_parse_token_string_t cmd_showport_port =
8194         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8195 cmdline_parse_token_string_t cmd_showport_what =
8196         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8197                                  "info#summary#stats#xstats#fdir#dcb_tc");
8198 cmdline_parse_token_num_t cmd_showport_portnum =
8199         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8200
8201 cmdline_parse_inst_t cmd_showport = {
8202         .f = cmd_showport_parsed,
8203         .data = NULL,
8204         .help_str = "show|clear port "
8205                 "info|summary|stats|xstats|fdir|dcb_tc "
8206                 "<port_id>",
8207         .tokens = {
8208                 (void *)&cmd_showport_show,
8209                 (void *)&cmd_showport_port,
8210                 (void *)&cmd_showport_what,
8211                 (void *)&cmd_showport_portnum,
8212                 NULL,
8213         },
8214 };
8215
8216 /* *** show port representors information *** */
8217 struct cmd_representor_info_result {
8218         cmdline_fixed_string_t cmd_show;
8219         cmdline_fixed_string_t cmd_port;
8220         cmdline_fixed_string_t cmd_info;
8221         cmdline_fixed_string_t cmd_keyword;
8222         portid_t cmd_pid;
8223 };
8224
8225 static void
8226 cmd_representor_info_parsed(void *parsed_result,
8227                 __rte_unused struct cmdline *cl,
8228                 __rte_unused void *data)
8229 {
8230         struct cmd_representor_info_result *res = parsed_result;
8231         struct rte_eth_representor_info *info;
8232         struct rte_eth_representor_range *range;
8233         uint32_t range_diff;
8234         uint32_t i;
8235         int ret;
8236         int num;
8237
8238         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8239                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8240                 return;
8241         }
8242
8243         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8244         if (ret < 0) {
8245                 fprintf(stderr,
8246                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8247                         res->cmd_pid, rte_strerror(-ret));
8248                 return;
8249         }
8250         num = ret;
8251
8252         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8253         if (info == NULL) {
8254                 fprintf(stderr,
8255                         "Failed to allocate memory for representor info for port %hu\n",
8256                         res->cmd_pid);
8257                 return;
8258         }
8259         info->nb_ranges_alloc = num;
8260
8261         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8262         if (ret < 0) {
8263                 fprintf(stderr,
8264                         "Failed to get the representor info for port %hu: %s\n",
8265                         res->cmd_pid, rte_strerror(-ret));
8266                 free(info);
8267                 return;
8268         }
8269
8270         printf("Port controller: %hu\n", info->controller);
8271         printf("Port PF: %hu\n", info->pf);
8272
8273         printf("Ranges: %u\n", info->nb_ranges);
8274         for (i = 0; i < info->nb_ranges; i++) {
8275                 range = &info->ranges[i];
8276                 range_diff = range->id_end - range->id_base;
8277
8278                 printf("%u. ", i + 1);
8279                 printf("'%s' ", range->name);
8280                 if (range_diff > 0)
8281                         printf("[%u-%u]: ", range->id_base, range->id_end);
8282                 else
8283                         printf("[%u]: ", range->id_base);
8284
8285                 printf("Controller %d, PF %d", range->controller, range->pf);
8286
8287                 switch (range->type) {
8288                 case RTE_ETH_REPRESENTOR_NONE:
8289                         printf(", NONE\n");
8290                         break;
8291                 case RTE_ETH_REPRESENTOR_VF:
8292                         if (range_diff > 0)
8293                                 printf(", VF %d..%d\n", range->vf,
8294                                        range->vf + range_diff);
8295                         else
8296                                 printf(", VF %d\n", range->vf);
8297                         break;
8298                 case RTE_ETH_REPRESENTOR_SF:
8299                         printf(", SF %d\n", range->sf);
8300                         break;
8301                 case RTE_ETH_REPRESENTOR_PF:
8302                         if (range_diff > 0)
8303                                 printf("..%d\n", range->pf + range_diff);
8304                         else
8305                                 printf("\n");
8306                         break;
8307                 default:
8308                         printf(", UNKNOWN TYPE %d\n", range->type);
8309                         break;
8310                 }
8311         }
8312
8313         free(info);
8314 }
8315
8316 cmdline_parse_token_string_t cmd_representor_info_show =
8317         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8318                         cmd_show, "show");
8319 cmdline_parse_token_string_t cmd_representor_info_port =
8320         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8321                         cmd_port, "port");
8322 cmdline_parse_token_string_t cmd_representor_info_info =
8323         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8324                         cmd_info, "info");
8325 cmdline_parse_token_num_t cmd_representor_info_pid =
8326         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8327                         cmd_pid, RTE_UINT16);
8328 cmdline_parse_token_string_t cmd_representor_info_keyword =
8329         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8330                         cmd_keyword, "representor");
8331
8332 cmdline_parse_inst_t cmd_representor_info = {
8333         .f = cmd_representor_info_parsed,
8334         .data = NULL,
8335         .help_str = "show port info <port_id> representor",
8336         .tokens = {
8337                 (void *)&cmd_representor_info_show,
8338                 (void *)&cmd_representor_info_port,
8339                 (void *)&cmd_representor_info_info,
8340                 (void *)&cmd_representor_info_pid,
8341                 (void *)&cmd_representor_info_keyword,
8342                 NULL,
8343         },
8344 };
8345
8346
8347 /* *** SHOW DEVICE INFO *** */
8348 struct cmd_showdevice_result {
8349         cmdline_fixed_string_t show;
8350         cmdline_fixed_string_t device;
8351         cmdline_fixed_string_t what;
8352         cmdline_fixed_string_t identifier;
8353 };
8354
8355 static void cmd_showdevice_parsed(void *parsed_result,
8356                                 __rte_unused struct cmdline *cl,
8357                                 __rte_unused void *data)
8358 {
8359         struct cmd_showdevice_result *res = parsed_result;
8360         if (!strcmp(res->what, "info")) {
8361                 if (!strcmp(res->identifier, "all"))
8362                         device_infos_display(NULL);
8363                 else
8364                         device_infos_display(res->identifier);
8365         }
8366 }
8367
8368 cmdline_parse_token_string_t cmd_showdevice_show =
8369         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8370                                  "show");
8371 cmdline_parse_token_string_t cmd_showdevice_device =
8372         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8373 cmdline_parse_token_string_t cmd_showdevice_what =
8374         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8375                                  "info");
8376 cmdline_parse_token_string_t cmd_showdevice_identifier =
8377         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8378                         identifier, NULL);
8379
8380 cmdline_parse_inst_t cmd_showdevice = {
8381         .f = cmd_showdevice_parsed,
8382         .data = NULL,
8383         .help_str = "show device info <identifier>|all",
8384         .tokens = {
8385                 (void *)&cmd_showdevice_show,
8386                 (void *)&cmd_showdevice_device,
8387                 (void *)&cmd_showdevice_what,
8388                 (void *)&cmd_showdevice_identifier,
8389                 NULL,
8390         },
8391 };
8392
8393 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8394 struct cmd_showeeprom_result {
8395         cmdline_fixed_string_t show;
8396         cmdline_fixed_string_t port;
8397         uint16_t portnum;
8398         cmdline_fixed_string_t type;
8399 };
8400
8401 static void cmd_showeeprom_parsed(void *parsed_result,
8402                 __rte_unused struct cmdline *cl,
8403                 __rte_unused void *data)
8404 {
8405         struct cmd_showeeprom_result *res = parsed_result;
8406
8407         if (!strcmp(res->type, "eeprom"))
8408                 port_eeprom_display(res->portnum);
8409         else if (!strcmp(res->type, "module_eeprom"))
8410                 port_module_eeprom_display(res->portnum);
8411         else
8412                 fprintf(stderr, "Unknown argument\n");
8413 }
8414
8415 cmdline_parse_token_string_t cmd_showeeprom_show =
8416         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8417 cmdline_parse_token_string_t cmd_showeeprom_port =
8418         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8419 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8420         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8421                         RTE_UINT16);
8422 cmdline_parse_token_string_t cmd_showeeprom_type =
8423         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8424
8425 cmdline_parse_inst_t cmd_showeeprom = {
8426         .f = cmd_showeeprom_parsed,
8427         .data = NULL,
8428         .help_str = "show port <port_id> module_eeprom|eeprom",
8429         .tokens = {
8430                 (void *)&cmd_showeeprom_show,
8431                 (void *)&cmd_showeeprom_port,
8432                 (void *)&cmd_showeeprom_portnum,
8433                 (void *)&cmd_showeeprom_type,
8434                 NULL,
8435         },
8436 };
8437
8438 /* *** SHOW QUEUE INFO *** */
8439 struct cmd_showqueue_result {
8440         cmdline_fixed_string_t show;
8441         cmdline_fixed_string_t type;
8442         cmdline_fixed_string_t what;
8443         uint16_t portnum;
8444         uint16_t queuenum;
8445 };
8446
8447 static void
8448 cmd_showqueue_parsed(void *parsed_result,
8449         __rte_unused struct cmdline *cl,
8450         __rte_unused void *data)
8451 {
8452         struct cmd_showqueue_result *res = parsed_result;
8453
8454         if (!strcmp(res->type, "rxq"))
8455                 rx_queue_infos_display(res->portnum, res->queuenum);
8456         else if (!strcmp(res->type, "txq"))
8457                 tx_queue_infos_display(res->portnum, res->queuenum);
8458 }
8459
8460 cmdline_parse_token_string_t cmd_showqueue_show =
8461         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8462 cmdline_parse_token_string_t cmd_showqueue_type =
8463         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8464 cmdline_parse_token_string_t cmd_showqueue_what =
8465         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8466 cmdline_parse_token_num_t cmd_showqueue_portnum =
8467         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8468                 RTE_UINT16);
8469 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8470         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8471                 RTE_UINT16);
8472
8473 cmdline_parse_inst_t cmd_showqueue = {
8474         .f = cmd_showqueue_parsed,
8475         .data = NULL,
8476         .help_str = "show rxq|txq info <port_id> <queue_id>",
8477         .tokens = {
8478                 (void *)&cmd_showqueue_show,
8479                 (void *)&cmd_showqueue_type,
8480                 (void *)&cmd_showqueue_what,
8481                 (void *)&cmd_showqueue_portnum,
8482                 (void *)&cmd_showqueue_queuenum,
8483                 NULL,
8484         },
8485 };
8486
8487 /* show/clear fwd engine statistics */
8488 struct fwd_result {
8489         cmdline_fixed_string_t action;
8490         cmdline_fixed_string_t fwd;
8491         cmdline_fixed_string_t stats;
8492         cmdline_fixed_string_t all;
8493 };
8494
8495 cmdline_parse_token_string_t cmd_fwd_action =
8496         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8497 cmdline_parse_token_string_t cmd_fwd_fwd =
8498         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8499 cmdline_parse_token_string_t cmd_fwd_stats =
8500         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8501 cmdline_parse_token_string_t cmd_fwd_all =
8502         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8503
8504 static void
8505 cmd_showfwdall_parsed(void *parsed_result,
8506                       __rte_unused struct cmdline *cl,
8507                       __rte_unused void *data)
8508 {
8509         struct fwd_result *res = parsed_result;
8510
8511         if (!strcmp(res->action, "show"))
8512                 fwd_stats_display();
8513         else
8514                 fwd_stats_reset();
8515 }
8516
8517 static cmdline_parse_inst_t cmd_showfwdall = {
8518         .f = cmd_showfwdall_parsed,
8519         .data = NULL,
8520         .help_str = "show|clear fwd stats all",
8521         .tokens = {
8522                 (void *)&cmd_fwd_action,
8523                 (void *)&cmd_fwd_fwd,
8524                 (void *)&cmd_fwd_stats,
8525                 (void *)&cmd_fwd_all,
8526                 NULL,
8527         },
8528 };
8529
8530 /* *** READ PORT REGISTER *** */
8531 struct cmd_read_reg_result {
8532         cmdline_fixed_string_t read;
8533         cmdline_fixed_string_t reg;
8534         portid_t port_id;
8535         uint32_t reg_off;
8536 };
8537
8538 static void
8539 cmd_read_reg_parsed(void *parsed_result,
8540                     __rte_unused struct cmdline *cl,
8541                     __rte_unused void *data)
8542 {
8543         struct cmd_read_reg_result *res = parsed_result;
8544         port_reg_display(res->port_id, res->reg_off);
8545 }
8546
8547 cmdline_parse_token_string_t cmd_read_reg_read =
8548         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8549 cmdline_parse_token_string_t cmd_read_reg_reg =
8550         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8551 cmdline_parse_token_num_t cmd_read_reg_port_id =
8552         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8553 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8554         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8555
8556 cmdline_parse_inst_t cmd_read_reg = {
8557         .f = cmd_read_reg_parsed,
8558         .data = NULL,
8559         .help_str = "read reg <port_id> <reg_off>",
8560         .tokens = {
8561                 (void *)&cmd_read_reg_read,
8562                 (void *)&cmd_read_reg_reg,
8563                 (void *)&cmd_read_reg_port_id,
8564                 (void *)&cmd_read_reg_reg_off,
8565                 NULL,
8566         },
8567 };
8568
8569 /* *** READ PORT REGISTER BIT FIELD *** */
8570 struct cmd_read_reg_bit_field_result {
8571         cmdline_fixed_string_t read;
8572         cmdline_fixed_string_t regfield;
8573         portid_t port_id;
8574         uint32_t reg_off;
8575         uint8_t bit1_pos;
8576         uint8_t bit2_pos;
8577 };
8578
8579 static void
8580 cmd_read_reg_bit_field_parsed(void *parsed_result,
8581                               __rte_unused struct cmdline *cl,
8582                               __rte_unused void *data)
8583 {
8584         struct cmd_read_reg_bit_field_result *res = parsed_result;
8585         port_reg_bit_field_display(res->port_id, res->reg_off,
8586                                    res->bit1_pos, res->bit2_pos);
8587 }
8588
8589 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8590         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8591                                  "read");
8592 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8593         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8594                                  regfield, "regfield");
8595 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8596         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8597                               RTE_UINT16);
8598 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8599         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8600                               RTE_UINT32);
8601 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8602         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8603                               RTE_UINT8);
8604 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8605         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8606                               RTE_UINT8);
8607
8608 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8609         .f = cmd_read_reg_bit_field_parsed,
8610         .data = NULL,
8611         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8612         "Read register bit field between bit_x and bit_y included",
8613         .tokens = {
8614                 (void *)&cmd_read_reg_bit_field_read,
8615                 (void *)&cmd_read_reg_bit_field_regfield,
8616                 (void *)&cmd_read_reg_bit_field_port_id,
8617                 (void *)&cmd_read_reg_bit_field_reg_off,
8618                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8619                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8620                 NULL,
8621         },
8622 };
8623
8624 /* *** READ PORT REGISTER BIT *** */
8625 struct cmd_read_reg_bit_result {
8626         cmdline_fixed_string_t read;
8627         cmdline_fixed_string_t regbit;
8628         portid_t port_id;
8629         uint32_t reg_off;
8630         uint8_t bit_pos;
8631 };
8632
8633 static void
8634 cmd_read_reg_bit_parsed(void *parsed_result,
8635                         __rte_unused struct cmdline *cl,
8636                         __rte_unused void *data)
8637 {
8638         struct cmd_read_reg_bit_result *res = parsed_result;
8639         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8640 }
8641
8642 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8643         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8644 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8645         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8646                                  regbit, "regbit");
8647 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8648         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8649                                  RTE_UINT16);
8650 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8651         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8652                                  RTE_UINT32);
8653 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8654         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8655                                  RTE_UINT8);
8656
8657 cmdline_parse_inst_t cmd_read_reg_bit = {
8658         .f = cmd_read_reg_bit_parsed,
8659         .data = NULL,
8660         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8661         .tokens = {
8662                 (void *)&cmd_read_reg_bit_read,
8663                 (void *)&cmd_read_reg_bit_regbit,
8664                 (void *)&cmd_read_reg_bit_port_id,
8665                 (void *)&cmd_read_reg_bit_reg_off,
8666                 (void *)&cmd_read_reg_bit_bit_pos,
8667                 NULL,
8668         },
8669 };
8670
8671 /* *** WRITE PORT REGISTER *** */
8672 struct cmd_write_reg_result {
8673         cmdline_fixed_string_t write;
8674         cmdline_fixed_string_t reg;
8675         portid_t port_id;
8676         uint32_t reg_off;
8677         uint32_t value;
8678 };
8679
8680 static void
8681 cmd_write_reg_parsed(void *parsed_result,
8682                      __rte_unused struct cmdline *cl,
8683                      __rte_unused void *data)
8684 {
8685         struct cmd_write_reg_result *res = parsed_result;
8686         port_reg_set(res->port_id, res->reg_off, res->value);
8687 }
8688
8689 cmdline_parse_token_string_t cmd_write_reg_write =
8690         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8691 cmdline_parse_token_string_t cmd_write_reg_reg =
8692         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8693 cmdline_parse_token_num_t cmd_write_reg_port_id =
8694         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8695 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8696         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8697 cmdline_parse_token_num_t cmd_write_reg_value =
8698         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8699
8700 cmdline_parse_inst_t cmd_write_reg = {
8701         .f = cmd_write_reg_parsed,
8702         .data = NULL,
8703         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8704         .tokens = {
8705                 (void *)&cmd_write_reg_write,
8706                 (void *)&cmd_write_reg_reg,
8707                 (void *)&cmd_write_reg_port_id,
8708                 (void *)&cmd_write_reg_reg_off,
8709                 (void *)&cmd_write_reg_value,
8710                 NULL,
8711         },
8712 };
8713
8714 /* *** WRITE PORT REGISTER BIT FIELD *** */
8715 struct cmd_write_reg_bit_field_result {
8716         cmdline_fixed_string_t write;
8717         cmdline_fixed_string_t regfield;
8718         portid_t port_id;
8719         uint32_t reg_off;
8720         uint8_t bit1_pos;
8721         uint8_t bit2_pos;
8722         uint32_t value;
8723 };
8724
8725 static void
8726 cmd_write_reg_bit_field_parsed(void *parsed_result,
8727                                __rte_unused struct cmdline *cl,
8728                                __rte_unused void *data)
8729 {
8730         struct cmd_write_reg_bit_field_result *res = parsed_result;
8731         port_reg_bit_field_set(res->port_id, res->reg_off,
8732                           res->bit1_pos, res->bit2_pos, res->value);
8733 }
8734
8735 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8736         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8737                                  "write");
8738 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8739         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8740                                  regfield, "regfield");
8741 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8742         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8743                               RTE_UINT16);
8744 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8745         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8746                               RTE_UINT32);
8747 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8748         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8749                               RTE_UINT8);
8750 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8751         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8752                               RTE_UINT8);
8753 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8754         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8755                               RTE_UINT32);
8756
8757 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8758         .f = cmd_write_reg_bit_field_parsed,
8759         .data = NULL,
8760         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8761                 "<reg_value>: "
8762                 "Set register bit field between bit_x and bit_y included",
8763         .tokens = {
8764                 (void *)&cmd_write_reg_bit_field_write,
8765                 (void *)&cmd_write_reg_bit_field_regfield,
8766                 (void *)&cmd_write_reg_bit_field_port_id,
8767                 (void *)&cmd_write_reg_bit_field_reg_off,
8768                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8769                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8770                 (void *)&cmd_write_reg_bit_field_value,
8771                 NULL,
8772         },
8773 };
8774
8775 /* *** WRITE PORT REGISTER BIT *** */
8776 struct cmd_write_reg_bit_result {
8777         cmdline_fixed_string_t write;
8778         cmdline_fixed_string_t regbit;
8779         portid_t port_id;
8780         uint32_t reg_off;
8781         uint8_t bit_pos;
8782         uint8_t value;
8783 };
8784
8785 static void
8786 cmd_write_reg_bit_parsed(void *parsed_result,
8787                          __rte_unused struct cmdline *cl,
8788                          __rte_unused void *data)
8789 {
8790         struct cmd_write_reg_bit_result *res = parsed_result;
8791         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8792 }
8793
8794 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8795         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8796                                  "write");
8797 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8798         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8799                                  regbit, "regbit");
8800 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8801         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8802                                  RTE_UINT16);
8803 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8804         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8805                                  RTE_UINT32);
8806 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8807         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8808                                  RTE_UINT8);
8809 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8810         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8811                                  RTE_UINT8);
8812
8813 cmdline_parse_inst_t cmd_write_reg_bit = {
8814         .f = cmd_write_reg_bit_parsed,
8815         .data = NULL,
8816         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8817                 "0 <= bit_x <= 31",
8818         .tokens = {
8819                 (void *)&cmd_write_reg_bit_write,
8820                 (void *)&cmd_write_reg_bit_regbit,
8821                 (void *)&cmd_write_reg_bit_port_id,
8822                 (void *)&cmd_write_reg_bit_reg_off,
8823                 (void *)&cmd_write_reg_bit_bit_pos,
8824                 (void *)&cmd_write_reg_bit_value,
8825                 NULL,
8826         },
8827 };
8828
8829 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8830 struct cmd_read_rxd_txd_result {
8831         cmdline_fixed_string_t read;
8832         cmdline_fixed_string_t rxd_txd;
8833         portid_t port_id;
8834         uint16_t queue_id;
8835         uint16_t desc_id;
8836 };
8837
8838 static void
8839 cmd_read_rxd_txd_parsed(void *parsed_result,
8840                         __rte_unused struct cmdline *cl,
8841                         __rte_unused void *data)
8842 {
8843         struct cmd_read_rxd_txd_result *res = parsed_result;
8844
8845         if (!strcmp(res->rxd_txd, "rxd"))
8846                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8847         else if (!strcmp(res->rxd_txd, "txd"))
8848                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8849 }
8850
8851 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8852         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8853 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8854         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8855                                  "rxd#txd");
8856 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8857         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8858                                  RTE_UINT16);
8859 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8860         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8861                                  RTE_UINT16);
8862 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8863         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8864                                  RTE_UINT16);
8865
8866 cmdline_parse_inst_t cmd_read_rxd_txd = {
8867         .f = cmd_read_rxd_txd_parsed,
8868         .data = NULL,
8869         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8870         .tokens = {
8871                 (void *)&cmd_read_rxd_txd_read,
8872                 (void *)&cmd_read_rxd_txd_rxd_txd,
8873                 (void *)&cmd_read_rxd_txd_port_id,
8874                 (void *)&cmd_read_rxd_txd_queue_id,
8875                 (void *)&cmd_read_rxd_txd_desc_id,
8876                 NULL,
8877         },
8878 };
8879
8880 /* *** QUIT *** */
8881 struct cmd_quit_result {
8882         cmdline_fixed_string_t quit;
8883 };
8884
8885 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8886                             struct cmdline *cl,
8887                             __rte_unused void *data)
8888 {
8889         cmdline_quit(cl);
8890 }
8891
8892 cmdline_parse_token_string_t cmd_quit_quit =
8893         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8894
8895 cmdline_parse_inst_t cmd_quit = {
8896         .f = cmd_quit_parsed,
8897         .data = NULL,
8898         .help_str = "quit: Exit application",
8899         .tokens = {
8900                 (void *)&cmd_quit_quit,
8901                 NULL,
8902         },
8903 };
8904
8905 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8906 struct cmd_mac_addr_result {
8907         cmdline_fixed_string_t mac_addr_cmd;
8908         cmdline_fixed_string_t what;
8909         uint16_t port_num;
8910         struct rte_ether_addr address;
8911 };
8912
8913 static void cmd_mac_addr_parsed(void *parsed_result,
8914                 __rte_unused struct cmdline *cl,
8915                 __rte_unused void *data)
8916 {
8917         struct cmd_mac_addr_result *res = parsed_result;
8918         int ret;
8919
8920         if (strcmp(res->what, "add") == 0)
8921                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8922         else if (strcmp(res->what, "set") == 0)
8923                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8924                                                        &res->address);
8925         else
8926                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8927
8928         /* check the return value and print it if is < 0 */
8929         if(ret < 0)
8930                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8931
8932 }
8933
8934 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8935         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8936                                 "mac_addr");
8937 cmdline_parse_token_string_t cmd_mac_addr_what =
8938         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8939                                 "add#remove#set");
8940 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8941                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8942                                         RTE_UINT16);
8943 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8944                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8945
8946 cmdline_parse_inst_t cmd_mac_addr = {
8947         .f = cmd_mac_addr_parsed,
8948         .data = (void *)0,
8949         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8950                         "Add/Remove/Set MAC address on port_id",
8951         .tokens = {
8952                 (void *)&cmd_mac_addr_cmd,
8953                 (void *)&cmd_mac_addr_what,
8954                 (void *)&cmd_mac_addr_portnum,
8955                 (void *)&cmd_mac_addr_addr,
8956                 NULL,
8957         },
8958 };
8959
8960 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8961 struct cmd_eth_peer_result {
8962         cmdline_fixed_string_t set;
8963         cmdline_fixed_string_t eth_peer;
8964         portid_t port_id;
8965         cmdline_fixed_string_t peer_addr;
8966 };
8967
8968 static void cmd_set_eth_peer_parsed(void *parsed_result,
8969                         __rte_unused struct cmdline *cl,
8970                         __rte_unused void *data)
8971 {
8972                 struct cmd_eth_peer_result *res = parsed_result;
8973
8974                 if (test_done == 0) {
8975                         fprintf(stderr, "Please stop forwarding first\n");
8976                         return;
8977                 }
8978                 if (!strcmp(res->eth_peer, "eth-peer")) {
8979                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8980                         fwd_config_setup();
8981                 }
8982 }
8983 cmdline_parse_token_string_t cmd_eth_peer_set =
8984         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8985 cmdline_parse_token_string_t cmd_eth_peer =
8986         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8987 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8988         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8989                 RTE_UINT16);
8990 cmdline_parse_token_string_t cmd_eth_peer_addr =
8991         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8992
8993 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8994         .f = cmd_set_eth_peer_parsed,
8995         .data = NULL,
8996         .help_str = "set eth-peer <port_id> <peer_mac>",
8997         .tokens = {
8998                 (void *)&cmd_eth_peer_set,
8999                 (void *)&cmd_eth_peer,
9000                 (void *)&cmd_eth_peer_port_id,
9001                 (void *)&cmd_eth_peer_addr,
9002                 NULL,
9003         },
9004 };
9005
9006 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9007 struct cmd_set_qmap_result {
9008         cmdline_fixed_string_t set;
9009         cmdline_fixed_string_t qmap;
9010         cmdline_fixed_string_t what;
9011         portid_t port_id;
9012         uint16_t queue_id;
9013         uint8_t map_value;
9014 };
9015
9016 static void
9017 cmd_set_qmap_parsed(void *parsed_result,
9018                        __rte_unused struct cmdline *cl,
9019                        __rte_unused void *data)
9020 {
9021         struct cmd_set_qmap_result *res = parsed_result;
9022         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9023
9024         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9025 }
9026
9027 cmdline_parse_token_string_t cmd_setqmap_set =
9028         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9029                                  set, "set");
9030 cmdline_parse_token_string_t cmd_setqmap_qmap =
9031         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9032                                  qmap, "stat_qmap");
9033 cmdline_parse_token_string_t cmd_setqmap_what =
9034         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9035                                  what, "tx#rx");
9036 cmdline_parse_token_num_t cmd_setqmap_portid =
9037         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9038                               port_id, RTE_UINT16);
9039 cmdline_parse_token_num_t cmd_setqmap_queueid =
9040         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9041                               queue_id, RTE_UINT16);
9042 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9043         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9044                               map_value, RTE_UINT8);
9045
9046 cmdline_parse_inst_t cmd_set_qmap = {
9047         .f = cmd_set_qmap_parsed,
9048         .data = NULL,
9049         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9050                 "Set statistics mapping value on tx|rx queue_id of port_id",
9051         .tokens = {
9052                 (void *)&cmd_setqmap_set,
9053                 (void *)&cmd_setqmap_qmap,
9054                 (void *)&cmd_setqmap_what,
9055                 (void *)&cmd_setqmap_portid,
9056                 (void *)&cmd_setqmap_queueid,
9057                 (void *)&cmd_setqmap_mapvalue,
9058                 NULL,
9059         },
9060 };
9061
9062 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9063 struct cmd_set_xstats_hide_zero_result {
9064         cmdline_fixed_string_t keyword;
9065         cmdline_fixed_string_t name;
9066         cmdline_fixed_string_t on_off;
9067 };
9068
9069 static void
9070 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9071                         __rte_unused struct cmdline *cl,
9072                         __rte_unused void *data)
9073 {
9074         struct cmd_set_xstats_hide_zero_result *res;
9075         uint16_t on_off = 0;
9076
9077         res = parsed_result;
9078         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9079         set_xstats_hide_zero(on_off);
9080 }
9081
9082 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9083         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9084                                  keyword, "set");
9085 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9086         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9087                                  name, "xstats-hide-zero");
9088 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9089         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9090                                  on_off, "on#off");
9091
9092 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9093         .f = cmd_set_xstats_hide_zero_parsed,
9094         .data = NULL,
9095         .help_str = "set xstats-hide-zero on|off",
9096         .tokens = {
9097                 (void *)&cmd_set_xstats_hide_zero_keyword,
9098                 (void *)&cmd_set_xstats_hide_zero_name,
9099                 (void *)&cmd_set_xstats_hide_zero_on_off,
9100                 NULL,
9101         },
9102 };
9103
9104 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9105 struct cmd_set_record_core_cycles_result {
9106         cmdline_fixed_string_t keyword;
9107         cmdline_fixed_string_t name;
9108         cmdline_fixed_string_t on_off;
9109 };
9110
9111 static void
9112 cmd_set_record_core_cycles_parsed(void *parsed_result,
9113                         __rte_unused struct cmdline *cl,
9114                         __rte_unused void *data)
9115 {
9116         struct cmd_set_record_core_cycles_result *res;
9117         uint16_t on_off = 0;
9118
9119         res = parsed_result;
9120         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9121         set_record_core_cycles(on_off);
9122 }
9123
9124 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9125         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9126                                  keyword, "set");
9127 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9128         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9129                                  name, "record-core-cycles");
9130 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9131         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9132                                  on_off, "on#off");
9133
9134 cmdline_parse_inst_t cmd_set_record_core_cycles = {
9135         .f = cmd_set_record_core_cycles_parsed,
9136         .data = NULL,
9137         .help_str = "set record-core-cycles on|off",
9138         .tokens = {
9139                 (void *)&cmd_set_record_core_cycles_keyword,
9140                 (void *)&cmd_set_record_core_cycles_name,
9141                 (void *)&cmd_set_record_core_cycles_on_off,
9142                 NULL,
9143         },
9144 };
9145
9146 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9147 struct cmd_set_record_burst_stats_result {
9148         cmdline_fixed_string_t keyword;
9149         cmdline_fixed_string_t name;
9150         cmdline_fixed_string_t on_off;
9151 };
9152
9153 static void
9154 cmd_set_record_burst_stats_parsed(void *parsed_result,
9155                         __rte_unused struct cmdline *cl,
9156                         __rte_unused void *data)
9157 {
9158         struct cmd_set_record_burst_stats_result *res;
9159         uint16_t on_off = 0;
9160
9161         res = parsed_result;
9162         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9163         set_record_burst_stats(on_off);
9164 }
9165
9166 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9167         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9168                                  keyword, "set");
9169 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9170         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9171                                  name, "record-burst-stats");
9172 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9173         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9174                                  on_off, "on#off");
9175
9176 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9177         .f = cmd_set_record_burst_stats_parsed,
9178         .data = NULL,
9179         .help_str = "set record-burst-stats on|off",
9180         .tokens = {
9181                 (void *)&cmd_set_record_burst_stats_keyword,
9182                 (void *)&cmd_set_record_burst_stats_name,
9183                 (void *)&cmd_set_record_burst_stats_on_off,
9184                 NULL,
9185         },
9186 };
9187
9188 /* *** CONFIGURE UNICAST HASH TABLE *** */
9189 struct cmd_set_uc_hash_table {
9190         cmdline_fixed_string_t set;
9191         cmdline_fixed_string_t port;
9192         portid_t port_id;
9193         cmdline_fixed_string_t what;
9194         struct rte_ether_addr address;
9195         cmdline_fixed_string_t mode;
9196 };
9197
9198 static void
9199 cmd_set_uc_hash_parsed(void *parsed_result,
9200                        __rte_unused struct cmdline *cl,
9201                        __rte_unused void *data)
9202 {
9203         int ret=0;
9204         struct cmd_set_uc_hash_table *res = parsed_result;
9205
9206         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9207
9208         if (strcmp(res->what, "uta") == 0)
9209                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9210                                                 &res->address,(uint8_t)is_on);
9211         if (ret < 0)
9212                 fprintf(stderr,
9213                         "bad unicast hash table parameter, return code = %d\n",
9214                         ret);
9215
9216 }
9217
9218 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9219         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9220                                  set, "set");
9221 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9222         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9223                                  port, "port");
9224 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9225         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9226                               port_id, RTE_UINT16);
9227 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9228         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9229                                  what, "uta");
9230 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9231         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9232                                 address);
9233 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9234         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9235                                  mode, "on#off");
9236
9237 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9238         .f = cmd_set_uc_hash_parsed,
9239         .data = NULL,
9240         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9241         .tokens = {
9242                 (void *)&cmd_set_uc_hash_set,
9243                 (void *)&cmd_set_uc_hash_port,
9244                 (void *)&cmd_set_uc_hash_portid,
9245                 (void *)&cmd_set_uc_hash_what,
9246                 (void *)&cmd_set_uc_hash_mac,
9247                 (void *)&cmd_set_uc_hash_mode,
9248                 NULL,
9249         },
9250 };
9251
9252 struct cmd_set_uc_all_hash_table {
9253         cmdline_fixed_string_t set;
9254         cmdline_fixed_string_t port;
9255         portid_t port_id;
9256         cmdline_fixed_string_t what;
9257         cmdline_fixed_string_t value;
9258         cmdline_fixed_string_t mode;
9259 };
9260
9261 static void
9262 cmd_set_uc_all_hash_parsed(void *parsed_result,
9263                        __rte_unused struct cmdline *cl,
9264                        __rte_unused void *data)
9265 {
9266         int ret=0;
9267         struct cmd_set_uc_all_hash_table *res = parsed_result;
9268
9269         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9270
9271         if ((strcmp(res->what, "uta") == 0) &&
9272                 (strcmp(res->value, "all") == 0))
9273                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9274         if (ret < 0)
9275                 fprintf(stderr,
9276                         "bad unicast hash table parameter, return code = %d\n",
9277                         ret);
9278 }
9279
9280 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9281         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9282                                  set, "set");
9283 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9284         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9285                                  port, "port");
9286 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9287         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9288                               port_id, RTE_UINT16);
9289 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9290         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9291                                  what, "uta");
9292 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9293         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9294                                 value,"all");
9295 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9296         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9297                                  mode, "on#off");
9298
9299 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9300         .f = cmd_set_uc_all_hash_parsed,
9301         .data = NULL,
9302         .help_str = "set port <port_id> uta all on|off",
9303         .tokens = {
9304                 (void *)&cmd_set_uc_all_hash_set,
9305                 (void *)&cmd_set_uc_all_hash_port,
9306                 (void *)&cmd_set_uc_all_hash_portid,
9307                 (void *)&cmd_set_uc_all_hash_what,
9308                 (void *)&cmd_set_uc_all_hash_value,
9309                 (void *)&cmd_set_uc_all_hash_mode,
9310                 NULL,
9311         },
9312 };
9313
9314 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9315 struct cmd_set_vf_traffic {
9316         cmdline_fixed_string_t set;
9317         cmdline_fixed_string_t port;
9318         portid_t port_id;
9319         cmdline_fixed_string_t vf;
9320         uint8_t vf_id;
9321         cmdline_fixed_string_t what;
9322         cmdline_fixed_string_t mode;
9323 };
9324
9325 static void
9326 cmd_set_vf_traffic_parsed(void *parsed_result,
9327                        __rte_unused struct cmdline *cl,
9328                        __rte_unused void *data)
9329 {
9330         struct cmd_set_vf_traffic *res = parsed_result;
9331         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9332         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9333
9334         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9335 }
9336
9337 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9338         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9339                                  set, "set");
9340 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9341         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9342                                  port, "port");
9343 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9344         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9345                               port_id, RTE_UINT16);
9346 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9347         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9348                                  vf, "vf");
9349 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9350         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9351                               vf_id, RTE_UINT8);
9352 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9353         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9354                                  what, "tx#rx");
9355 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9356         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9357                                  mode, "on#off");
9358
9359 cmdline_parse_inst_t cmd_set_vf_traffic = {
9360         .f = cmd_set_vf_traffic_parsed,
9361         .data = NULL,
9362         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9363         .tokens = {
9364                 (void *)&cmd_setvf_traffic_set,
9365                 (void *)&cmd_setvf_traffic_port,
9366                 (void *)&cmd_setvf_traffic_portid,
9367                 (void *)&cmd_setvf_traffic_vf,
9368                 (void *)&cmd_setvf_traffic_vfid,
9369                 (void *)&cmd_setvf_traffic_what,
9370                 (void *)&cmd_setvf_traffic_mode,
9371                 NULL,
9372         },
9373 };
9374
9375 /* *** CONFIGURE VF RECEIVE MODE *** */
9376 struct cmd_set_vf_rxmode {
9377         cmdline_fixed_string_t set;
9378         cmdline_fixed_string_t port;
9379         portid_t port_id;
9380         cmdline_fixed_string_t vf;
9381         uint8_t vf_id;
9382         cmdline_fixed_string_t what;
9383         cmdline_fixed_string_t mode;
9384         cmdline_fixed_string_t on;
9385 };
9386
9387 static void
9388 cmd_set_vf_rxmode_parsed(void *parsed_result,
9389                        __rte_unused struct cmdline *cl,
9390                        __rte_unused void *data)
9391 {
9392         int ret = -ENOTSUP;
9393         uint16_t vf_rxmode = 0;
9394         struct cmd_set_vf_rxmode *res = parsed_result;
9395
9396         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9397         if (!strcmp(res->what,"rxmode")) {
9398                 if (!strcmp(res->mode, "AUPE"))
9399                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9400                 else if (!strcmp(res->mode, "ROPE"))
9401                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9402                 else if (!strcmp(res->mode, "BAM"))
9403                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9404                 else if (!strncmp(res->mode, "MPE",3))
9405                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9406         }
9407
9408         RTE_SET_USED(is_on);
9409         RTE_SET_USED(vf_rxmode);
9410
9411 #ifdef RTE_NET_IXGBE
9412         if (ret == -ENOTSUP)
9413                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9414                                                   vf_rxmode, (uint8_t)is_on);
9415 #endif
9416 #ifdef RTE_NET_BNXT
9417         if (ret == -ENOTSUP)
9418                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9419                                                  vf_rxmode, (uint8_t)is_on);
9420 #endif
9421         if (ret < 0)
9422                 fprintf(stderr,
9423                         "bad VF receive mode parameter, return code = %d\n",
9424                         ret);
9425 }
9426
9427 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9428         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9429                                  set, "set");
9430 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9431         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9432                                  port, "port");
9433 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9434         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9435                               port_id, RTE_UINT16);
9436 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9437         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9438                                  vf, "vf");
9439 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9440         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9441                               vf_id, RTE_UINT8);
9442 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9443         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9444                                  what, "rxmode");
9445 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9446         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9447                                  mode, "AUPE#ROPE#BAM#MPE");
9448 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9449         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9450                                  on, "on#off");
9451
9452 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9453         .f = cmd_set_vf_rxmode_parsed,
9454         .data = NULL,
9455         .help_str = "set port <port_id> vf <vf_id> rxmode "
9456                 "AUPE|ROPE|BAM|MPE on|off",
9457         .tokens = {
9458                 (void *)&cmd_set_vf_rxmode_set,
9459                 (void *)&cmd_set_vf_rxmode_port,
9460                 (void *)&cmd_set_vf_rxmode_portid,
9461                 (void *)&cmd_set_vf_rxmode_vf,
9462                 (void *)&cmd_set_vf_rxmode_vfid,
9463                 (void *)&cmd_set_vf_rxmode_what,
9464                 (void *)&cmd_set_vf_rxmode_mode,
9465                 (void *)&cmd_set_vf_rxmode_on,
9466                 NULL,
9467         },
9468 };
9469
9470 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9471 struct cmd_vf_mac_addr_result {
9472         cmdline_fixed_string_t mac_addr_cmd;
9473         cmdline_fixed_string_t what;
9474         cmdline_fixed_string_t port;
9475         uint16_t port_num;
9476         cmdline_fixed_string_t vf;
9477         uint8_t vf_num;
9478         struct rte_ether_addr address;
9479 };
9480
9481 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9482                 __rte_unused struct cmdline *cl,
9483                 __rte_unused void *data)
9484 {
9485         struct cmd_vf_mac_addr_result *res = parsed_result;
9486         int ret = -ENOTSUP;
9487
9488         if (strcmp(res->what, "add") != 0)
9489                 return;
9490
9491 #ifdef RTE_NET_I40E
9492         if (ret == -ENOTSUP)
9493                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9494                                                    &res->address);
9495 #endif
9496 #ifdef RTE_NET_BNXT
9497         if (ret == -ENOTSUP)
9498                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9499                                                 res->vf_num);
9500 #endif
9501
9502         if(ret < 0)
9503                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9504
9505 }
9506
9507 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9508         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9509                                 mac_addr_cmd,"mac_addr");
9510 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9511         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9512                                 what,"add");
9513 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9514         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9515                                 port,"port");
9516 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9517         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9518                                 port_num, RTE_UINT16);
9519 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9520         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9521                                 vf,"vf");
9522 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9523         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9524                                 vf_num, RTE_UINT8);
9525 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9526         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9527                                 address);
9528
9529 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9530         .f = cmd_vf_mac_addr_parsed,
9531         .data = (void *)0,
9532         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9533                 "Add MAC address filtering for a VF on port_id",
9534         .tokens = {
9535                 (void *)&cmd_vf_mac_addr_cmd,
9536                 (void *)&cmd_vf_mac_addr_what,
9537                 (void *)&cmd_vf_mac_addr_port,
9538                 (void *)&cmd_vf_mac_addr_portnum,
9539                 (void *)&cmd_vf_mac_addr_vf,
9540                 (void *)&cmd_vf_mac_addr_vfnum,
9541                 (void *)&cmd_vf_mac_addr_addr,
9542                 NULL,
9543         },
9544 };
9545
9546 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9547 struct cmd_vf_rx_vlan_filter {
9548         cmdline_fixed_string_t rx_vlan;
9549         cmdline_fixed_string_t what;
9550         uint16_t vlan_id;
9551         cmdline_fixed_string_t port;
9552         portid_t port_id;
9553         cmdline_fixed_string_t vf;
9554         uint64_t vf_mask;
9555 };
9556
9557 static void
9558 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9559                           __rte_unused struct cmdline *cl,
9560                           __rte_unused void *data)
9561 {
9562         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9563         int ret = -ENOTSUP;
9564
9565         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9566
9567 #ifdef RTE_NET_IXGBE
9568         if (ret == -ENOTSUP)
9569                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9570                                 res->vlan_id, res->vf_mask, is_add);
9571 #endif
9572 #ifdef RTE_NET_I40E
9573         if (ret == -ENOTSUP)
9574                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9575                                 res->vlan_id, res->vf_mask, is_add);
9576 #endif
9577 #ifdef RTE_NET_BNXT
9578         if (ret == -ENOTSUP)
9579                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9580                                 res->vlan_id, res->vf_mask, is_add);
9581 #endif
9582
9583         switch (ret) {
9584         case 0:
9585                 break;
9586         case -EINVAL:
9587                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9588                         res->vlan_id, res->vf_mask);
9589                 break;
9590         case -ENODEV:
9591                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9592                 break;
9593         case -ENOTSUP:
9594                 fprintf(stderr, "function not implemented or supported\n");
9595                 break;
9596         default:
9597                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9598         }
9599 }
9600
9601 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9602         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9603                                  rx_vlan, "rx_vlan");
9604 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9605         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9606                                  what, "add#rm");
9607 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9608         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9609                               vlan_id, RTE_UINT16);
9610 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9611         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9612                                  port, "port");
9613 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9614         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9615                               port_id, RTE_UINT16);
9616 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9617         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9618                                  vf, "vf");
9619 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9620         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9621                               vf_mask, RTE_UINT64);
9622
9623 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9624         .f = cmd_vf_rx_vlan_filter_parsed,
9625         .data = NULL,
9626         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9627                 "(vf_mask = hexadecimal VF mask)",
9628         .tokens = {
9629                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9630                 (void *)&cmd_vf_rx_vlan_filter_what,
9631                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9632                 (void *)&cmd_vf_rx_vlan_filter_port,
9633                 (void *)&cmd_vf_rx_vlan_filter_portid,
9634                 (void *)&cmd_vf_rx_vlan_filter_vf,
9635                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9636                 NULL,
9637         },
9638 };
9639
9640 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9641 struct cmd_queue_rate_limit_result {
9642         cmdline_fixed_string_t set;
9643         cmdline_fixed_string_t port;
9644         uint16_t port_num;
9645         cmdline_fixed_string_t queue;
9646         uint8_t queue_num;
9647         cmdline_fixed_string_t rate;
9648         uint16_t rate_num;
9649 };
9650
9651 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9652                 __rte_unused struct cmdline *cl,
9653                 __rte_unused void *data)
9654 {
9655         struct cmd_queue_rate_limit_result *res = parsed_result;
9656         int ret = 0;
9657
9658         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9659                 && (strcmp(res->queue, "queue") == 0)
9660                 && (strcmp(res->rate, "rate") == 0))
9661                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9662                                         res->rate_num);
9663         if (ret < 0)
9664                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9665                         strerror(-ret));
9666
9667 }
9668
9669 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9670         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9671                                 set, "set");
9672 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9673         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9674                                 port, "port");
9675 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9676         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9677                                 port_num, RTE_UINT16);
9678 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9679         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9680                                 queue, "queue");
9681 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9682         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9683                                 queue_num, RTE_UINT8);
9684 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9685         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9686                                 rate, "rate");
9687 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9688         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9689                                 rate_num, RTE_UINT16);
9690
9691 cmdline_parse_inst_t cmd_queue_rate_limit = {
9692         .f = cmd_queue_rate_limit_parsed,
9693         .data = (void *)0,
9694         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9695                 "Set rate limit for a queue on port_id",
9696         .tokens = {
9697                 (void *)&cmd_queue_rate_limit_set,
9698                 (void *)&cmd_queue_rate_limit_port,
9699                 (void *)&cmd_queue_rate_limit_portnum,
9700                 (void *)&cmd_queue_rate_limit_queue,
9701                 (void *)&cmd_queue_rate_limit_queuenum,
9702                 (void *)&cmd_queue_rate_limit_rate,
9703                 (void *)&cmd_queue_rate_limit_ratenum,
9704                 NULL,
9705         },
9706 };
9707
9708 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9709 struct cmd_vf_rate_limit_result {
9710         cmdline_fixed_string_t set;
9711         cmdline_fixed_string_t port;
9712         uint16_t port_num;
9713         cmdline_fixed_string_t vf;
9714         uint8_t vf_num;
9715         cmdline_fixed_string_t rate;
9716         uint16_t rate_num;
9717         cmdline_fixed_string_t q_msk;
9718         uint64_t q_msk_val;
9719 };
9720
9721 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9722                 __rte_unused struct cmdline *cl,
9723                 __rte_unused void *data)
9724 {
9725         struct cmd_vf_rate_limit_result *res = parsed_result;
9726         int ret = 0;
9727
9728         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9729                 && (strcmp(res->vf, "vf") == 0)
9730                 && (strcmp(res->rate, "rate") == 0)
9731                 && (strcmp(res->q_msk, "queue_mask") == 0))
9732                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9733                                         res->rate_num, res->q_msk_val);
9734         if (ret < 0)
9735                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9736                         strerror(-ret));
9737
9738 }
9739
9740 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9741         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9742                                 set, "set");
9743 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9744         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9745                                 port, "port");
9746 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9747         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9748                                 port_num, RTE_UINT16);
9749 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9750         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9751                                 vf, "vf");
9752 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9753         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9754                                 vf_num, RTE_UINT8);
9755 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9756         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9757                                 rate, "rate");
9758 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9759         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9760                                 rate_num, RTE_UINT16);
9761 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9762         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9763                                 q_msk, "queue_mask");
9764 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9765         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9766                                 q_msk_val, RTE_UINT64);
9767
9768 cmdline_parse_inst_t cmd_vf_rate_limit = {
9769         .f = cmd_vf_rate_limit_parsed,
9770         .data = (void *)0,
9771         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9772                 "queue_mask <queue_mask_value>: "
9773                 "Set rate limit for queues of VF on port_id",
9774         .tokens = {
9775                 (void *)&cmd_vf_rate_limit_set,
9776                 (void *)&cmd_vf_rate_limit_port,
9777                 (void *)&cmd_vf_rate_limit_portnum,
9778                 (void *)&cmd_vf_rate_limit_vf,
9779                 (void *)&cmd_vf_rate_limit_vfnum,
9780                 (void *)&cmd_vf_rate_limit_rate,
9781                 (void *)&cmd_vf_rate_limit_ratenum,
9782                 (void *)&cmd_vf_rate_limit_q_msk,
9783                 (void *)&cmd_vf_rate_limit_q_msk_val,
9784                 NULL,
9785         },
9786 };
9787
9788 /* *** CONFIGURE TUNNEL UDP PORT *** */
9789 struct cmd_tunnel_udp_config {
9790         cmdline_fixed_string_t rx_vxlan_port;
9791         cmdline_fixed_string_t what;
9792         uint16_t udp_port;
9793         portid_t port_id;
9794 };
9795
9796 static void
9797 cmd_tunnel_udp_config_parsed(void *parsed_result,
9798                           __rte_unused struct cmdline *cl,
9799                           __rte_unused void *data)
9800 {
9801         struct cmd_tunnel_udp_config *res = parsed_result;
9802         struct rte_eth_udp_tunnel tunnel_udp;
9803         int ret;
9804
9805         tunnel_udp.udp_port = res->udp_port;
9806         tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9807
9808         if (!strcmp(res->what, "add"))
9809                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9810                                                       &tunnel_udp);
9811         else
9812                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9813                                                          &tunnel_udp);
9814
9815         if (ret < 0)
9816                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9817                         strerror(-ret));
9818 }
9819
9820 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9821         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9822                                 rx_vxlan_port, "rx_vxlan_port");
9823 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9824         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9825                                 what, "add#rm");
9826 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9827         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9828                                 udp_port, RTE_UINT16);
9829 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9830         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9831                                 port_id, RTE_UINT16);
9832
9833 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9834         .f = cmd_tunnel_udp_config_parsed,
9835         .data = (void *)0,
9836         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9837                 "Add/Remove a tunneling UDP port filter",
9838         .tokens = {
9839                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9840                 (void *)&cmd_tunnel_udp_config_what,
9841                 (void *)&cmd_tunnel_udp_config_udp_port,
9842                 (void *)&cmd_tunnel_udp_config_port_id,
9843                 NULL,
9844         },
9845 };
9846
9847 struct cmd_config_tunnel_udp_port {
9848         cmdline_fixed_string_t port;
9849         cmdline_fixed_string_t config;
9850         portid_t port_id;
9851         cmdline_fixed_string_t udp_tunnel_port;
9852         cmdline_fixed_string_t action;
9853         cmdline_fixed_string_t tunnel_type;
9854         uint16_t udp_port;
9855 };
9856
9857 static void
9858 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9859                                __rte_unused struct cmdline *cl,
9860                                __rte_unused void *data)
9861 {
9862         struct cmd_config_tunnel_udp_port *res = parsed_result;
9863         struct rte_eth_udp_tunnel tunnel_udp;
9864         int ret = 0;
9865
9866         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9867                 return;
9868
9869         tunnel_udp.udp_port = res->udp_port;
9870
9871         if (!strcmp(res->tunnel_type, "vxlan")) {
9872                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9873         } else if (!strcmp(res->tunnel_type, "geneve")) {
9874                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9875         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9876                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9877         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9878                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9879         } else {
9880                 fprintf(stderr, "Invalid tunnel type\n");
9881                 return;
9882         }
9883
9884         if (!strcmp(res->action, "add"))
9885                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9886                                                       &tunnel_udp);
9887         else
9888                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9889                                                          &tunnel_udp);
9890
9891         if (ret < 0)
9892                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9893                         strerror(-ret));
9894 }
9895
9896 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9897         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9898                                  "port");
9899 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9900         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9901                                  "config");
9902 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9903         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9904                               RTE_UINT16);
9905 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9906         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9907                                  udp_tunnel_port,
9908                                  "udp_tunnel_port");
9909 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9910         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9911                                  "add#rm");
9912 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9913         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9914                                  "vxlan#geneve#vxlan-gpe#ecpri");
9915 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9916         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9917                               RTE_UINT16);
9918
9919 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9920         .f = cmd_cfg_tunnel_udp_port_parsed,
9921         .data = NULL,
9922         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9923                 "geneve|vxlan-gpe|ecpri <udp_port>",
9924         .tokens = {
9925                 (void *)&cmd_config_tunnel_udp_port_port,
9926                 (void *)&cmd_config_tunnel_udp_port_config,
9927                 (void *)&cmd_config_tunnel_udp_port_port_id,
9928                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9929                 (void *)&cmd_config_tunnel_udp_port_action,
9930                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9931                 (void *)&cmd_config_tunnel_udp_port_value,
9932                 NULL,
9933         },
9934 };
9935
9936 /* ******************************************************************************** */
9937
9938 struct cmd_dump_result {
9939         cmdline_fixed_string_t dump;
9940 };
9941
9942 static void
9943 dump_struct_sizes(void)
9944 {
9945 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9946         DUMP_SIZE(struct rte_mbuf);
9947         DUMP_SIZE(struct rte_mempool);
9948         DUMP_SIZE(struct rte_ring);
9949 #undef DUMP_SIZE
9950 }
9951
9952
9953 /* Dump the socket memory statistics on console */
9954 static void
9955 dump_socket_mem(FILE *f)
9956 {
9957         struct rte_malloc_socket_stats socket_stats;
9958         unsigned int i;
9959         size_t total = 0;
9960         size_t alloc = 0;
9961         size_t free = 0;
9962         unsigned int n_alloc = 0;
9963         unsigned int n_free = 0;
9964         static size_t last_allocs;
9965         static size_t last_total;
9966
9967
9968         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9969                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9970                     !socket_stats.heap_totalsz_bytes)
9971                         continue;
9972                 total += socket_stats.heap_totalsz_bytes;
9973                 alloc += socket_stats.heap_allocsz_bytes;
9974                 free += socket_stats.heap_freesz_bytes;
9975                 n_alloc += socket_stats.alloc_count;
9976                 n_free += socket_stats.free_count;
9977                 fprintf(f,
9978                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9979                         i,
9980                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9981                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9982                         (double)socket_stats.heap_allocsz_bytes * 100 /
9983                         (double)socket_stats.heap_totalsz_bytes,
9984                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9985                         socket_stats.alloc_count,
9986                         socket_stats.free_count);
9987         }
9988         fprintf(f,
9989                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9990                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9991                 total ? ((double)alloc * 100 / (double)total) : 0,
9992                 (double)free / (1024 * 1024),
9993                 n_alloc, n_free);
9994         if (last_allocs)
9995                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9996                         ((double)total - (double)last_total) / (1024 * 1024),
9997                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9998         last_allocs = alloc;
9999         last_total = total;
10000 }
10001
10002 static void cmd_dump_parsed(void *parsed_result,
10003                             __rte_unused struct cmdline *cl,
10004                             __rte_unused void *data)
10005 {
10006         struct cmd_dump_result *res = parsed_result;
10007
10008         if (!strcmp(res->dump, "dump_physmem"))
10009                 rte_dump_physmem_layout(stdout);
10010         else if (!strcmp(res->dump, "dump_socket_mem"))
10011                 dump_socket_mem(stdout);
10012         else if (!strcmp(res->dump, "dump_memzone"))
10013                 rte_memzone_dump(stdout);
10014         else if (!strcmp(res->dump, "dump_struct_sizes"))
10015                 dump_struct_sizes();
10016         else if (!strcmp(res->dump, "dump_ring"))
10017                 rte_ring_list_dump(stdout);
10018         else if (!strcmp(res->dump, "dump_mempool"))
10019                 rte_mempool_list_dump(stdout);
10020         else if (!strcmp(res->dump, "dump_devargs"))
10021                 rte_devargs_dump(stdout);
10022         else if (!strcmp(res->dump, "dump_log_types"))
10023                 rte_log_dump(stdout);
10024 }
10025
10026 cmdline_parse_token_string_t cmd_dump_dump =
10027         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10028                 "dump_physmem#"
10029                 "dump_memzone#"
10030                 "dump_socket_mem#"
10031                 "dump_struct_sizes#"
10032                 "dump_ring#"
10033                 "dump_mempool#"
10034                 "dump_devargs#"
10035                 "dump_log_types");
10036
10037 cmdline_parse_inst_t cmd_dump = {
10038         .f = cmd_dump_parsed,  /* function to call */
10039         .data = NULL,      /* 2nd arg of func */
10040         .help_str = "Dump status",
10041         .tokens = {        /* token list, NULL terminated */
10042                 (void *)&cmd_dump_dump,
10043                 NULL,
10044         },
10045 };
10046
10047 /* ******************************************************************************** */
10048
10049 struct cmd_dump_one_result {
10050         cmdline_fixed_string_t dump;
10051         cmdline_fixed_string_t name;
10052 };
10053
10054 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10055                                 __rte_unused void *data)
10056 {
10057         struct cmd_dump_one_result *res = parsed_result;
10058
10059         if (!strcmp(res->dump, "dump_ring")) {
10060                 struct rte_ring *r;
10061                 r = rte_ring_lookup(res->name);
10062                 if (r == NULL) {
10063                         cmdline_printf(cl, "Cannot find ring\n");
10064                         return;
10065                 }
10066                 rte_ring_dump(stdout, r);
10067         } else if (!strcmp(res->dump, "dump_mempool")) {
10068                 struct rte_mempool *mp;
10069                 mp = rte_mempool_lookup(res->name);
10070                 if (mp == NULL) {
10071                         cmdline_printf(cl, "Cannot find mempool\n");
10072                         return;
10073                 }
10074                 rte_mempool_dump(stdout, mp);
10075         }
10076 }
10077
10078 cmdline_parse_token_string_t cmd_dump_one_dump =
10079         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10080                                  "dump_ring#dump_mempool");
10081
10082 cmdline_parse_token_string_t cmd_dump_one_name =
10083         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10084
10085 cmdline_parse_inst_t cmd_dump_one = {
10086         .f = cmd_dump_one_parsed,  /* function to call */
10087         .data = NULL,      /* 2nd arg of func */
10088         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10089         .tokens = {        /* token list, NULL terminated */
10090                 (void *)&cmd_dump_one_dump,
10091                 (void *)&cmd_dump_one_name,
10092                 NULL,
10093         },
10094 };
10095
10096 /* *** queue region set *** */
10097 struct cmd_queue_region_result {
10098         cmdline_fixed_string_t set;
10099         cmdline_fixed_string_t port;
10100         portid_t port_id;
10101         cmdline_fixed_string_t cmd;
10102         cmdline_fixed_string_t region;
10103         uint8_t  region_id;
10104         cmdline_fixed_string_t queue_start_index;
10105         uint8_t  queue_id;
10106         cmdline_fixed_string_t queue_num;
10107         uint8_t  queue_num_value;
10108 };
10109
10110 static void
10111 cmd_queue_region_parsed(void *parsed_result,
10112                         __rte_unused struct cmdline *cl,
10113                         __rte_unused void *data)
10114 {
10115         struct cmd_queue_region_result *res = parsed_result;
10116         int ret = -ENOTSUP;
10117 #ifdef RTE_NET_I40E
10118         struct rte_pmd_i40e_queue_region_conf region_conf;
10119         enum rte_pmd_i40e_queue_region_op op_type;
10120 #endif
10121
10122         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10123                 return;
10124
10125 #ifdef RTE_NET_I40E
10126         memset(&region_conf, 0, sizeof(region_conf));
10127         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10128         region_conf.region_id = res->region_id;
10129         region_conf.queue_num = res->queue_num_value;
10130         region_conf.queue_start_index = res->queue_id;
10131
10132         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10133                                 op_type, &region_conf);
10134 #endif
10135
10136         switch (ret) {
10137         case 0:
10138                 break;
10139         case -ENOTSUP:
10140                 fprintf(stderr, "function not implemented or supported\n");
10141                 break;
10142         default:
10143                 fprintf(stderr, "queue region config error: (%s)\n",
10144                         strerror(-ret));
10145         }
10146 }
10147
10148 cmdline_parse_token_string_t cmd_queue_region_set =
10149 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10150                 set, "set");
10151 cmdline_parse_token_string_t cmd_queue_region_port =
10152         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10153 cmdline_parse_token_num_t cmd_queue_region_port_id =
10154         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10155                                 port_id, RTE_UINT16);
10156 cmdline_parse_token_string_t cmd_queue_region_cmd =
10157         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10158                                  cmd, "queue-region");
10159 cmdline_parse_token_string_t cmd_queue_region_id =
10160         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10161                                 region, "region_id");
10162 cmdline_parse_token_num_t cmd_queue_region_index =
10163         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10164                                 region_id, RTE_UINT8);
10165 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10166         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10167                                 queue_start_index, "queue_start_index");
10168 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10169         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10170                                 queue_id, RTE_UINT8);
10171 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10172         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10173                                 queue_num, "queue_num");
10174 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10175         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10176                                 queue_num_value, RTE_UINT8);
10177
10178 cmdline_parse_inst_t cmd_queue_region = {
10179         .f = cmd_queue_region_parsed,
10180         .data = NULL,
10181         .help_str = "set port <port_id> queue-region region_id <value> "
10182                 "queue_start_index <value> queue_num <value>: Set a queue region",
10183         .tokens = {
10184                 (void *)&cmd_queue_region_set,
10185                 (void *)&cmd_queue_region_port,
10186                 (void *)&cmd_queue_region_port_id,
10187                 (void *)&cmd_queue_region_cmd,
10188                 (void *)&cmd_queue_region_id,
10189                 (void *)&cmd_queue_region_index,
10190                 (void *)&cmd_queue_region_queue_start_index,
10191                 (void *)&cmd_queue_region_queue_id,
10192                 (void *)&cmd_queue_region_queue_num,
10193                 (void *)&cmd_queue_region_queue_num_value,
10194                 NULL,
10195         },
10196 };
10197
10198 /* *** queue region and flowtype set *** */
10199 struct cmd_region_flowtype_result {
10200         cmdline_fixed_string_t set;
10201         cmdline_fixed_string_t port;
10202         portid_t port_id;
10203         cmdline_fixed_string_t cmd;
10204         cmdline_fixed_string_t region;
10205         uint8_t  region_id;
10206         cmdline_fixed_string_t flowtype;
10207         uint8_t  flowtype_id;
10208 };
10209
10210 static void
10211 cmd_region_flowtype_parsed(void *parsed_result,
10212                         __rte_unused struct cmdline *cl,
10213                         __rte_unused void *data)
10214 {
10215         struct cmd_region_flowtype_result *res = parsed_result;
10216         int ret = -ENOTSUP;
10217 #ifdef RTE_NET_I40E
10218         struct rte_pmd_i40e_queue_region_conf region_conf;
10219         enum rte_pmd_i40e_queue_region_op op_type;
10220 #endif
10221
10222         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10223                 return;
10224
10225 #ifdef RTE_NET_I40E
10226         memset(&region_conf, 0, sizeof(region_conf));
10227
10228         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10229         region_conf.region_id = res->region_id;
10230         region_conf.hw_flowtype = res->flowtype_id;
10231
10232         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10233                         op_type, &region_conf);
10234 #endif
10235
10236         switch (ret) {
10237         case 0:
10238                 break;
10239         case -ENOTSUP:
10240                 fprintf(stderr, "function not implemented or supported\n");
10241                 break;
10242         default:
10243                 fprintf(stderr, "region flowtype config error: (%s)\n",
10244                         strerror(-ret));
10245         }
10246 }
10247
10248 cmdline_parse_token_string_t cmd_region_flowtype_set =
10249 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10250                                 set, "set");
10251 cmdline_parse_token_string_t cmd_region_flowtype_port =
10252         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10253                                 port, "port");
10254 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10255         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10256                                 port_id, RTE_UINT16);
10257 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10258         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10259                                 cmd, "queue-region");
10260 cmdline_parse_token_string_t cmd_region_flowtype_index =
10261         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10262                                 region, "region_id");
10263 cmdline_parse_token_num_t cmd_region_flowtype_id =
10264         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10265                                 region_id, RTE_UINT8);
10266 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10267         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10268                                 flowtype, "flowtype");
10269 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10270         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10271                                 flowtype_id, RTE_UINT8);
10272 cmdline_parse_inst_t cmd_region_flowtype = {
10273         .f = cmd_region_flowtype_parsed,
10274         .data = NULL,
10275         .help_str = "set port <port_id> queue-region region_id <value> "
10276                 "flowtype <value>: Set a flowtype region index",
10277         .tokens = {
10278                 (void *)&cmd_region_flowtype_set,
10279                 (void *)&cmd_region_flowtype_port,
10280                 (void *)&cmd_region_flowtype_port_index,
10281                 (void *)&cmd_region_flowtype_cmd,
10282                 (void *)&cmd_region_flowtype_index,
10283                 (void *)&cmd_region_flowtype_id,
10284                 (void *)&cmd_region_flowtype_flow_index,
10285                 (void *)&cmd_region_flowtype_flow_id,
10286                 NULL,
10287         },
10288 };
10289
10290 /* *** User Priority (UP) to queue region (region_id) set *** */
10291 struct cmd_user_priority_region_result {
10292         cmdline_fixed_string_t set;
10293         cmdline_fixed_string_t port;
10294         portid_t port_id;
10295         cmdline_fixed_string_t cmd;
10296         cmdline_fixed_string_t user_priority;
10297         uint8_t  user_priority_id;
10298         cmdline_fixed_string_t region;
10299         uint8_t  region_id;
10300 };
10301
10302 static void
10303 cmd_user_priority_region_parsed(void *parsed_result,
10304                         __rte_unused struct cmdline *cl,
10305                         __rte_unused void *data)
10306 {
10307         struct cmd_user_priority_region_result *res = parsed_result;
10308         int ret = -ENOTSUP;
10309 #ifdef RTE_NET_I40E
10310         struct rte_pmd_i40e_queue_region_conf region_conf;
10311         enum rte_pmd_i40e_queue_region_op op_type;
10312 #endif
10313
10314         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10315                 return;
10316
10317 #ifdef RTE_NET_I40E
10318         memset(&region_conf, 0, sizeof(region_conf));
10319         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10320         region_conf.user_priority = res->user_priority_id;
10321         region_conf.region_id = res->region_id;
10322
10323         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10324                                 op_type, &region_conf);
10325 #endif
10326
10327         switch (ret) {
10328         case 0:
10329                 break;
10330         case -ENOTSUP:
10331                 fprintf(stderr, "function not implemented or supported\n");
10332                 break;
10333         default:
10334                 fprintf(stderr, "user_priority region config error: (%s)\n",
10335                         strerror(-ret));
10336         }
10337 }
10338
10339 cmdline_parse_token_string_t cmd_user_priority_region_set =
10340         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10341                                 set, "set");
10342 cmdline_parse_token_string_t cmd_user_priority_region_port =
10343         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10344                                 port, "port");
10345 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10346         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10347                                 port_id, RTE_UINT16);
10348 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10349         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10350                                 cmd, "queue-region");
10351 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10352         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10353                                 user_priority, "UP");
10354 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10355         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10356                                 user_priority_id, RTE_UINT8);
10357 cmdline_parse_token_string_t cmd_user_priority_region_region =
10358         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10359                                 region, "region_id");
10360 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10361         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10362                                 region_id, RTE_UINT8);
10363
10364 cmdline_parse_inst_t cmd_user_priority_region = {
10365         .f = cmd_user_priority_region_parsed,
10366         .data = NULL,
10367         .help_str = "set port <port_id> queue-region UP <value> "
10368                 "region_id <value>: Set the mapping of User Priority (UP) "
10369                 "to queue region (region_id) ",
10370         .tokens = {
10371                 (void *)&cmd_user_priority_region_set,
10372                 (void *)&cmd_user_priority_region_port,
10373                 (void *)&cmd_user_priority_region_port_index,
10374                 (void *)&cmd_user_priority_region_cmd,
10375                 (void *)&cmd_user_priority_region_UP,
10376                 (void *)&cmd_user_priority_region_UP_id,
10377                 (void *)&cmd_user_priority_region_region,
10378                 (void *)&cmd_user_priority_region_region_id,
10379                 NULL,
10380         },
10381 };
10382
10383 /* *** flush all queue region related configuration *** */
10384 struct cmd_flush_queue_region_result {
10385         cmdline_fixed_string_t set;
10386         cmdline_fixed_string_t port;
10387         portid_t port_id;
10388         cmdline_fixed_string_t cmd;
10389         cmdline_fixed_string_t flush;
10390         cmdline_fixed_string_t what;
10391 };
10392
10393 static void
10394 cmd_flush_queue_region_parsed(void *parsed_result,
10395                         __rte_unused struct cmdline *cl,
10396                         __rte_unused void *data)
10397 {
10398         struct cmd_flush_queue_region_result *res = parsed_result;
10399         int ret = -ENOTSUP;
10400 #ifdef RTE_NET_I40E
10401         struct rte_pmd_i40e_queue_region_conf region_conf;
10402         enum rte_pmd_i40e_queue_region_op op_type;
10403 #endif
10404
10405         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10406                 return;
10407
10408 #ifdef RTE_NET_I40E
10409         memset(&region_conf, 0, sizeof(region_conf));
10410
10411         if (strcmp(res->what, "on") == 0)
10412                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10413         else
10414                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10415
10416         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10417                                 op_type, &region_conf);
10418 #endif
10419
10420         switch (ret) {
10421         case 0:
10422                 break;
10423         case -ENOTSUP:
10424                 fprintf(stderr, "function not implemented or supported\n");
10425                 break;
10426         default:
10427                 fprintf(stderr, "queue region config flush error: (%s)\n",
10428                         strerror(-ret));
10429         }
10430 }
10431
10432 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10433         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10434                                 set, "set");
10435 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10437                                 port, "port");
10438 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10439         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10440                                 port_id, RTE_UINT16);
10441 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10443                                 cmd, "queue-region");
10444 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10445         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10446                                 flush, "flush");
10447 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10448         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10449                                 what, "on#off");
10450
10451 cmdline_parse_inst_t cmd_flush_queue_region = {
10452         .f = cmd_flush_queue_region_parsed,
10453         .data = NULL,
10454         .help_str = "set port <port_id> queue-region flush on|off"
10455                 ": flush all queue region related configuration",
10456         .tokens = {
10457                 (void *)&cmd_flush_queue_region_set,
10458                 (void *)&cmd_flush_queue_region_port,
10459                 (void *)&cmd_flush_queue_region_port_index,
10460                 (void *)&cmd_flush_queue_region_cmd,
10461                 (void *)&cmd_flush_queue_region_flush,
10462                 (void *)&cmd_flush_queue_region_what,
10463                 NULL,
10464         },
10465 };
10466
10467 /* *** get all queue region related configuration info *** */
10468 struct cmd_show_queue_region_info {
10469         cmdline_fixed_string_t show;
10470         cmdline_fixed_string_t port;
10471         portid_t port_id;
10472         cmdline_fixed_string_t cmd;
10473 };
10474
10475 static void
10476 cmd_show_queue_region_info_parsed(void *parsed_result,
10477                         __rte_unused struct cmdline *cl,
10478                         __rte_unused void *data)
10479 {
10480         struct cmd_show_queue_region_info *res = parsed_result;
10481         int ret = -ENOTSUP;
10482 #ifdef RTE_NET_I40E
10483         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10484         enum rte_pmd_i40e_queue_region_op op_type;
10485 #endif
10486
10487         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10488                 return;
10489
10490 #ifdef RTE_NET_I40E
10491         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10492
10493         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10494
10495         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10496                                         op_type, &rte_pmd_regions);
10497
10498         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10499 #endif
10500
10501         switch (ret) {
10502         case 0:
10503                 break;
10504         case -ENOTSUP:
10505                 fprintf(stderr, "function not implemented or supported\n");
10506                 break;
10507         default:
10508                 fprintf(stderr, "queue region config info show error: (%s)\n",
10509                         strerror(-ret));
10510         }
10511 }
10512
10513 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10514 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10515                                 show, "show");
10516 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10517         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10518                                 port, "port");
10519 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10520         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10521                                 port_id, RTE_UINT16);
10522 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10523         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10524                                 cmd, "queue-region");
10525
10526 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10527         .f = cmd_show_queue_region_info_parsed,
10528         .data = NULL,
10529         .help_str = "show port <port_id> queue-region"
10530                 ": show all queue region related configuration info",
10531         .tokens = {
10532                 (void *)&cmd_show_queue_region_info_get,
10533                 (void *)&cmd_show_queue_region_info_port,
10534                 (void *)&cmd_show_queue_region_info_port_index,
10535                 (void *)&cmd_show_queue_region_info_cmd,
10536                 NULL,
10537         },
10538 };
10539
10540 /* *** Filters Control *** */
10541
10542 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10543 do { \
10544         if ((ip_addr).family == AF_INET) \
10545                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10546         else { \
10547                 fprintf(stderr, "invalid parameter.\n"); \
10548                 return; \
10549         } \
10550 } while (0)
10551
10552 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10553 do { \
10554         if ((ip_addr).family == AF_INET6) \
10555                 rte_memcpy(&(ip), \
10556                                  &((ip_addr).addr.ipv6), \
10557                                  sizeof(struct in6_addr)); \
10558         else { \
10559                 fprintf(stderr, "invalid parameter.\n"); \
10560                 return; \
10561         } \
10562 } while (0)
10563
10564 #ifdef RTE_NET_I40E
10565
10566 static uint16_t
10567 str2flowtype(char *string)
10568 {
10569         uint8_t i = 0;
10570         static const struct {
10571                 char str[32];
10572                 uint16_t type;
10573         } flowtype_str[] = {
10574                 {"raw", RTE_ETH_FLOW_RAW},
10575                 {"ipv4", RTE_ETH_FLOW_IPV4},
10576                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10577                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10578                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10579                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10580                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10581                 {"ipv6", RTE_ETH_FLOW_IPV6},
10582                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10583                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10584                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10585                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10586                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10587                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10588                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10589                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10590                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10591                 {"gtpu", RTE_ETH_FLOW_GTPU},
10592         };
10593
10594         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10595                 if (!strcmp(flowtype_str[i].str, string))
10596                         return flowtype_str[i].type;
10597         }
10598
10599         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10600                 return (uint16_t)atoi(string);
10601
10602         return RTE_ETH_FLOW_UNKNOWN;
10603 }
10604
10605 /* *** deal with flow director filter *** */
10606 struct cmd_flow_director_result {
10607         cmdline_fixed_string_t flow_director_filter;
10608         portid_t port_id;
10609         cmdline_fixed_string_t mode;
10610         cmdline_fixed_string_t mode_value;
10611         cmdline_fixed_string_t ops;
10612         cmdline_fixed_string_t flow;
10613         cmdline_fixed_string_t flow_type;
10614         cmdline_fixed_string_t drop;
10615         cmdline_fixed_string_t queue;
10616         uint16_t  queue_id;
10617         cmdline_fixed_string_t fd_id;
10618         uint32_t  fd_id_value;
10619         cmdline_fixed_string_t packet;
10620         char filepath[];
10621 };
10622
10623 static void
10624 cmd_flow_director_filter_parsed(void *parsed_result,
10625                           __rte_unused struct cmdline *cl,
10626                           __rte_unused void *data)
10627 {
10628         struct cmd_flow_director_result *res = parsed_result;
10629         int ret = 0;
10630         struct rte_pmd_i40e_flow_type_mapping
10631                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10632         struct rte_pmd_i40e_pkt_template_conf conf;
10633         uint16_t flow_type = str2flowtype(res->flow_type);
10634         uint16_t i, port = res->port_id;
10635         uint8_t add;
10636
10637         memset(&conf, 0, sizeof(conf));
10638
10639         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10640                 fprintf(stderr, "Invalid flow type specified.\n");
10641                 return;
10642         }
10643         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10644                                                  mapping);
10645         if (ret)
10646                 return;
10647         if (mapping[flow_type].pctype == 0ULL) {
10648                 fprintf(stderr, "Invalid flow type specified.\n");
10649                 return;
10650         }
10651         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10652                 if (mapping[flow_type].pctype & (1ULL << i)) {
10653                         conf.input.pctype = i;
10654                         break;
10655                 }
10656         }
10657
10658         conf.input.packet = open_file(res->filepath,
10659                                 &conf.input.length);
10660         if (!conf.input.packet)
10661                 return;
10662         if (!strcmp(res->drop, "drop"))
10663                 conf.action.behavior =
10664                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10665         else
10666                 conf.action.behavior =
10667                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10668         conf.action.report_status =
10669                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10670         conf.action.rx_queue = res->queue_id;
10671         conf.soft_id = res->fd_id_value;
10672         add  = strcmp(res->ops, "del") ? 1 : 0;
10673         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10674                                                         &conf,
10675                                                         add);
10676         if (ret < 0)
10677                 fprintf(stderr, "flow director config error: (%s)\n",
10678                         strerror(-ret));
10679         close_file(conf.input.packet);
10680 }
10681
10682 cmdline_parse_token_string_t cmd_flow_director_filter =
10683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10684                                  flow_director_filter, "flow_director_filter");
10685 cmdline_parse_token_num_t cmd_flow_director_port_id =
10686         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10687                               port_id, RTE_UINT16);
10688 cmdline_parse_token_string_t cmd_flow_director_ops =
10689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10690                                  ops, "add#del#update");
10691 cmdline_parse_token_string_t cmd_flow_director_flow =
10692         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10693                                  flow, "flow");
10694 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10696                 flow_type, NULL);
10697 cmdline_parse_token_string_t cmd_flow_director_drop =
10698         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10699                                  drop, "drop#fwd");
10700 cmdline_parse_token_string_t cmd_flow_director_queue =
10701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10702                                  queue, "queue");
10703 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10704         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10705                               queue_id, RTE_UINT16);
10706 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10707         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10708                                  fd_id, "fd_id");
10709 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10710         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10711                               fd_id_value, RTE_UINT32);
10712
10713 cmdline_parse_token_string_t cmd_flow_director_mode =
10714         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10715                                  mode, "mode");
10716 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10718                                  mode_value, "raw");
10719 cmdline_parse_token_string_t cmd_flow_director_packet =
10720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10721                                  packet, "packet");
10722 cmdline_parse_token_string_t cmd_flow_director_filepath =
10723         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10724                                  filepath, NULL);
10725
10726 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10727         .f = cmd_flow_director_filter_parsed,
10728         .data = NULL,
10729         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10730                 "director entry on NIC",
10731         .tokens = {
10732                 (void *)&cmd_flow_director_filter,
10733                 (void *)&cmd_flow_director_port_id,
10734                 (void *)&cmd_flow_director_mode,
10735                 (void *)&cmd_flow_director_mode_raw,
10736                 (void *)&cmd_flow_director_ops,
10737                 (void *)&cmd_flow_director_flow,
10738                 (void *)&cmd_flow_director_flow_type,
10739                 (void *)&cmd_flow_director_drop,
10740                 (void *)&cmd_flow_director_queue,
10741                 (void *)&cmd_flow_director_queue_id,
10742                 (void *)&cmd_flow_director_fd_id,
10743                 (void *)&cmd_flow_director_fd_id_value,
10744                 (void *)&cmd_flow_director_packet,
10745                 (void *)&cmd_flow_director_filepath,
10746                 NULL,
10747         },
10748 };
10749
10750 #endif /* RTE_NET_I40E */
10751
10752 /* *** deal with flow director mask *** */
10753 struct cmd_flow_director_mask_result {
10754         cmdline_fixed_string_t flow_director_mask;
10755         portid_t port_id;
10756         cmdline_fixed_string_t mode;
10757         cmdline_fixed_string_t mode_value;
10758         cmdline_fixed_string_t vlan;
10759         uint16_t vlan_mask;
10760         cmdline_fixed_string_t src_mask;
10761         cmdline_ipaddr_t ipv4_src;
10762         cmdline_ipaddr_t ipv6_src;
10763         uint16_t port_src;
10764         cmdline_fixed_string_t dst_mask;
10765         cmdline_ipaddr_t ipv4_dst;
10766         cmdline_ipaddr_t ipv6_dst;
10767         uint16_t port_dst;
10768         cmdline_fixed_string_t mac;
10769         uint8_t mac_addr_byte_mask;
10770         cmdline_fixed_string_t tunnel_id;
10771         uint32_t tunnel_id_mask;
10772         cmdline_fixed_string_t tunnel_type;
10773         uint8_t tunnel_type_mask;
10774 };
10775
10776 static void
10777 cmd_flow_director_mask_parsed(void *parsed_result,
10778                           __rte_unused struct cmdline *cl,
10779                           __rte_unused void *data)
10780 {
10781         struct cmd_flow_director_mask_result *res = parsed_result;
10782         struct rte_eth_fdir_masks *mask;
10783         struct rte_port *port;
10784
10785         port = &ports[res->port_id];
10786         /** Check if the port is not started **/
10787         if (port->port_status != RTE_PORT_STOPPED) {
10788                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10789                 return;
10790         }
10791
10792         mask = &port->dev_conf.fdir_conf.mask;
10793
10794         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10795                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10796                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10797                         return;
10798                 }
10799
10800                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10801         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10802                 if (strcmp(res->mode_value, "Tunnel")) {
10803                         fprintf(stderr, "Please set mode to Tunnel.\n");
10804                         return;
10805                 }
10806
10807                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10808                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10809                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10810                 mask->tunnel_type_mask = res->tunnel_type_mask;
10811         } else {
10812                 if (strcmp(res->mode_value, "IP")) {
10813                         fprintf(stderr, "Please set mode to IP.\n");
10814                         return;
10815                 }
10816
10817                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10818                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10819                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10820                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10821                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10822                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10823                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10824         }
10825
10826         cmd_reconfig_device_queue(res->port_id, 1, 1);
10827 }
10828
10829 cmdline_parse_token_string_t cmd_flow_director_mask =
10830         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10831                                  flow_director_mask, "flow_director_mask");
10832 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10833         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10834                               port_id, RTE_UINT16);
10835 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10836         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10837                                  vlan, "vlan");
10838 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10839         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10840                               vlan_mask, RTE_UINT16);
10841 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10842         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10843                                  src_mask, "src_mask");
10844 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10845         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10846                                  ipv4_src);
10847 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10848         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10849                                  ipv6_src);
10850 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10851         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10852                               port_src, RTE_UINT16);
10853 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10854         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10855                                  dst_mask, "dst_mask");
10856 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10857         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10858                                  ipv4_dst);
10859 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10860         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10861                                  ipv6_dst);
10862 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10863         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10864                               port_dst, RTE_UINT16);
10865
10866 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10868                                  mode, "mode");
10869 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10870         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10871                                  mode_value, "IP");
10872 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10873         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10874                                  mode_value, "MAC-VLAN");
10875 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10876         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10877                                  mode_value, "Tunnel");
10878 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10880                                  mac, "mac");
10881 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10882         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10883                               mac_addr_byte_mask, RTE_UINT8);
10884 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10886                                  tunnel_type, "tunnel-type");
10887 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10888         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10889                               tunnel_type_mask, RTE_UINT8);
10890 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10891         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10892                                  tunnel_id, "tunnel-id");
10893 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10894         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10895                               tunnel_id_mask, RTE_UINT32);
10896
10897 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10898         .f = cmd_flow_director_mask_parsed,
10899         .data = NULL,
10900         .help_str = "flow_director_mask ... : "
10901                 "Set IP mode flow director's mask on NIC",
10902         .tokens = {
10903                 (void *)&cmd_flow_director_mask,
10904                 (void *)&cmd_flow_director_mask_port_id,
10905                 (void *)&cmd_flow_director_mask_mode,
10906                 (void *)&cmd_flow_director_mask_mode_ip,
10907                 (void *)&cmd_flow_director_mask_vlan,
10908                 (void *)&cmd_flow_director_mask_vlan_value,
10909                 (void *)&cmd_flow_director_mask_src,
10910                 (void *)&cmd_flow_director_mask_ipv4_src,
10911                 (void *)&cmd_flow_director_mask_ipv6_src,
10912                 (void *)&cmd_flow_director_mask_port_src,
10913                 (void *)&cmd_flow_director_mask_dst,
10914                 (void *)&cmd_flow_director_mask_ipv4_dst,
10915                 (void *)&cmd_flow_director_mask_ipv6_dst,
10916                 (void *)&cmd_flow_director_mask_port_dst,
10917                 NULL,
10918         },
10919 };
10920
10921 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10922         .f = cmd_flow_director_mask_parsed,
10923         .data = NULL,
10924         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10925                 "flow director's mask on NIC",
10926         .tokens = {
10927                 (void *)&cmd_flow_director_mask,
10928                 (void *)&cmd_flow_director_mask_port_id,
10929                 (void *)&cmd_flow_director_mask_mode,
10930                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10931                 (void *)&cmd_flow_director_mask_vlan,
10932                 (void *)&cmd_flow_director_mask_vlan_value,
10933                 NULL,
10934         },
10935 };
10936
10937 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10938         .f = cmd_flow_director_mask_parsed,
10939         .data = NULL,
10940         .help_str = "flow_director_mask ... : Set tunnel mode "
10941                 "flow director's mask on NIC",
10942         .tokens = {
10943                 (void *)&cmd_flow_director_mask,
10944                 (void *)&cmd_flow_director_mask_port_id,
10945                 (void *)&cmd_flow_director_mask_mode,
10946                 (void *)&cmd_flow_director_mask_mode_tunnel,
10947                 (void *)&cmd_flow_director_mask_vlan,
10948                 (void *)&cmd_flow_director_mask_vlan_value,
10949                 (void *)&cmd_flow_director_mask_mac,
10950                 (void *)&cmd_flow_director_mask_mac_value,
10951                 (void *)&cmd_flow_director_mask_tunnel_type,
10952                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10953                 (void *)&cmd_flow_director_mask_tunnel_id,
10954                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10955                 NULL,
10956         },
10957 };
10958
10959 /* *** deal with flow director flexible payload configuration *** */
10960 struct cmd_flow_director_flexpayload_result {
10961         cmdline_fixed_string_t flow_director_flexpayload;
10962         portid_t port_id;
10963         cmdline_fixed_string_t payload_layer;
10964         cmdline_fixed_string_t payload_cfg;
10965 };
10966
10967 static inline int
10968 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10969 {
10970         char s[256];
10971         const char *p, *p0 = q_arg;
10972         char *end;
10973         unsigned long int_fld;
10974         char *str_fld[max_num];
10975         int i;
10976         unsigned size;
10977         int ret = -1;
10978
10979         p = strchr(p0, '(');
10980         if (p == NULL)
10981                 return -1;
10982         ++p;
10983         p0 = strchr(p, ')');
10984         if (p0 == NULL)
10985                 return -1;
10986
10987         size = p0 - p;
10988         if (size >= sizeof(s))
10989                 return -1;
10990
10991         snprintf(s, sizeof(s), "%.*s", size, p);
10992         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10993         if (ret < 0 || ret > max_num)
10994                 return -1;
10995         for (i = 0; i < ret; i++) {
10996                 errno = 0;
10997                 int_fld = strtoul(str_fld[i], &end, 0);
10998                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10999                         return -1;
11000                 offsets[i] = (uint16_t)int_fld;
11001         }
11002         return ret;
11003 }
11004
11005 static void
11006 cmd_flow_director_flxpld_parsed(void *parsed_result,
11007                           __rte_unused struct cmdline *cl,
11008                           __rte_unused void *data)
11009 {
11010         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11011         struct rte_eth_flex_payload_cfg flex_cfg;
11012         struct rte_port *port;
11013         int ret = 0;
11014
11015         port = &ports[res->port_id];
11016         /** Check if the port is not started **/
11017         if (port->port_status != RTE_PORT_STOPPED) {
11018                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
11019                 return;
11020         }
11021
11022         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11023
11024         if (!strcmp(res->payload_layer, "raw"))
11025                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11026         else if (!strcmp(res->payload_layer, "l2"))
11027                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11028         else if (!strcmp(res->payload_layer, "l3"))
11029                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11030         else if (!strcmp(res->payload_layer, "l4"))
11031                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11032
11033         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11034                             RTE_ETH_FDIR_MAX_FLEXLEN);
11035         if (ret < 0) {
11036                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
11037                 return;
11038         }
11039
11040         fdir_set_flex_payload(res->port_id, &flex_cfg);
11041         cmd_reconfig_device_queue(res->port_id, 1, 1);
11042 }
11043
11044 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11046                                  flow_director_flexpayload,
11047                                  "flow_director_flex_payload");
11048 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11049         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11050                               port_id, RTE_UINT16);
11051 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11052         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11053                                  payload_layer, "raw#l2#l3#l4");
11054 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11055         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11056                                  payload_cfg, NULL);
11057
11058 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11059         .f = cmd_flow_director_flxpld_parsed,
11060         .data = NULL,
11061         .help_str = "flow_director_flexpayload ... : "
11062                 "Set flow director's flex payload on NIC",
11063         .tokens = {
11064                 (void *)&cmd_flow_director_flexpayload,
11065                 (void *)&cmd_flow_director_flexpayload_port_id,
11066                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11067                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11068                 NULL,
11069         },
11070 };
11071
11072 /* Generic flow interface command. */
11073 extern cmdline_parse_inst_t cmd_flow;
11074
11075 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11076 struct cmd_mcast_addr_result {
11077         cmdline_fixed_string_t mcast_addr_cmd;
11078         cmdline_fixed_string_t what;
11079         uint16_t port_num;
11080         struct rte_ether_addr mc_addr;
11081 };
11082
11083 static void cmd_mcast_addr_parsed(void *parsed_result,
11084                 __rte_unused struct cmdline *cl,
11085                 __rte_unused void *data)
11086 {
11087         struct cmd_mcast_addr_result *res = parsed_result;
11088
11089         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11090                 fprintf(stderr,
11091                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
11092                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
11093                 return;
11094         }
11095         if (strcmp(res->what, "add") == 0)
11096                 mcast_addr_add(res->port_num, &res->mc_addr);
11097         else
11098                 mcast_addr_remove(res->port_num, &res->mc_addr);
11099 }
11100
11101 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11102         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11103                                  mcast_addr_cmd, "mcast_addr");
11104 cmdline_parse_token_string_t cmd_mcast_addr_what =
11105         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11106                                  "add#remove");
11107 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11108         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
11109                                  RTE_UINT16);
11110 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11111         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11112
11113 cmdline_parse_inst_t cmd_mcast_addr = {
11114         .f = cmd_mcast_addr_parsed,
11115         .data = (void *)0,
11116         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11117                 "Add/Remove multicast MAC address on port_id",
11118         .tokens = {
11119                 (void *)&cmd_mcast_addr_cmd,
11120                 (void *)&cmd_mcast_addr_what,
11121                 (void *)&cmd_mcast_addr_portnum,
11122                 (void *)&cmd_mcast_addr_addr,
11123                 NULL,
11124         },
11125 };
11126
11127 /* vf vlan anti spoof configuration */
11128
11129 /* Common result structure for vf vlan anti spoof */
11130 struct cmd_vf_vlan_anti_spoof_result {
11131         cmdline_fixed_string_t set;
11132         cmdline_fixed_string_t vf;
11133         cmdline_fixed_string_t vlan;
11134         cmdline_fixed_string_t antispoof;
11135         portid_t port_id;
11136         uint32_t vf_id;
11137         cmdline_fixed_string_t on_off;
11138 };
11139
11140 /* Common CLI fields for vf vlan anti spoof enable disable */
11141 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11142         TOKEN_STRING_INITIALIZER
11143                 (struct cmd_vf_vlan_anti_spoof_result,
11144                  set, "set");
11145 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11146         TOKEN_STRING_INITIALIZER
11147                 (struct cmd_vf_vlan_anti_spoof_result,
11148                  vf, "vf");
11149 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11150         TOKEN_STRING_INITIALIZER
11151                 (struct cmd_vf_vlan_anti_spoof_result,
11152                  vlan, "vlan");
11153 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11154         TOKEN_STRING_INITIALIZER
11155                 (struct cmd_vf_vlan_anti_spoof_result,
11156                  antispoof, "antispoof");
11157 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11158         TOKEN_NUM_INITIALIZER
11159                 (struct cmd_vf_vlan_anti_spoof_result,
11160                  port_id, RTE_UINT16);
11161 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11162         TOKEN_NUM_INITIALIZER
11163                 (struct cmd_vf_vlan_anti_spoof_result,
11164                  vf_id, RTE_UINT32);
11165 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11166         TOKEN_STRING_INITIALIZER
11167                 (struct cmd_vf_vlan_anti_spoof_result,
11168                  on_off, "on#off");
11169
11170 static void
11171 cmd_set_vf_vlan_anti_spoof_parsed(
11172         void *parsed_result,
11173         __rte_unused struct cmdline *cl,
11174         __rte_unused void *data)
11175 {
11176         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11177         int ret = -ENOTSUP;
11178
11179         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11180
11181         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11182                 return;
11183
11184 #ifdef RTE_NET_IXGBE
11185         if (ret == -ENOTSUP)
11186                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11187                                 res->vf_id, is_on);
11188 #endif
11189 #ifdef RTE_NET_I40E
11190         if (ret == -ENOTSUP)
11191                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11192                                 res->vf_id, is_on);
11193 #endif
11194 #ifdef RTE_NET_BNXT
11195         if (ret == -ENOTSUP)
11196                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11197                                 res->vf_id, is_on);
11198 #endif
11199
11200         switch (ret) {
11201         case 0:
11202                 break;
11203         case -EINVAL:
11204                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11205                 break;
11206         case -ENODEV:
11207                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11208                 break;
11209         case -ENOTSUP:
11210                 fprintf(stderr, "function not implemented\n");
11211                 break;
11212         default:
11213                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11214         }
11215 }
11216
11217 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11218         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11219         .data = NULL,
11220         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11221         .tokens = {
11222                 (void *)&cmd_vf_vlan_anti_spoof_set,
11223                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11224                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11225                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11226                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11227                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11228                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11229                 NULL,
11230         },
11231 };
11232
11233 /* vf mac anti spoof configuration */
11234
11235 /* Common result structure for vf mac anti spoof */
11236 struct cmd_vf_mac_anti_spoof_result {
11237         cmdline_fixed_string_t set;
11238         cmdline_fixed_string_t vf;
11239         cmdline_fixed_string_t mac;
11240         cmdline_fixed_string_t antispoof;
11241         portid_t port_id;
11242         uint32_t vf_id;
11243         cmdline_fixed_string_t on_off;
11244 };
11245
11246 /* Common CLI fields for vf mac anti spoof enable disable */
11247 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11248         TOKEN_STRING_INITIALIZER
11249                 (struct cmd_vf_mac_anti_spoof_result,
11250                  set, "set");
11251 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11252         TOKEN_STRING_INITIALIZER
11253                 (struct cmd_vf_mac_anti_spoof_result,
11254                  vf, "vf");
11255 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11256         TOKEN_STRING_INITIALIZER
11257                 (struct cmd_vf_mac_anti_spoof_result,
11258                  mac, "mac");
11259 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11260         TOKEN_STRING_INITIALIZER
11261                 (struct cmd_vf_mac_anti_spoof_result,
11262                  antispoof, "antispoof");
11263 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11264         TOKEN_NUM_INITIALIZER
11265                 (struct cmd_vf_mac_anti_spoof_result,
11266                  port_id, RTE_UINT16);
11267 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11268         TOKEN_NUM_INITIALIZER
11269                 (struct cmd_vf_mac_anti_spoof_result,
11270                  vf_id, RTE_UINT32);
11271 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11272         TOKEN_STRING_INITIALIZER
11273                 (struct cmd_vf_mac_anti_spoof_result,
11274                  on_off, "on#off");
11275
11276 static void
11277 cmd_set_vf_mac_anti_spoof_parsed(
11278         void *parsed_result,
11279         __rte_unused struct cmdline *cl,
11280         __rte_unused void *data)
11281 {
11282         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11283         int ret = -ENOTSUP;
11284
11285         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11286
11287         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11288                 return;
11289
11290 #ifdef RTE_NET_IXGBE
11291         if (ret == -ENOTSUP)
11292                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11293                         res->vf_id, is_on);
11294 #endif
11295 #ifdef RTE_NET_I40E
11296         if (ret == -ENOTSUP)
11297                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11298                         res->vf_id, is_on);
11299 #endif
11300 #ifdef RTE_NET_BNXT
11301         if (ret == -ENOTSUP)
11302                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11303                         res->vf_id, is_on);
11304 #endif
11305
11306         switch (ret) {
11307         case 0:
11308                 break;
11309         case -EINVAL:
11310                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11311                         res->vf_id, is_on);
11312                 break;
11313         case -ENODEV:
11314                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11315                 break;
11316         case -ENOTSUP:
11317                 fprintf(stderr, "function not implemented\n");
11318                 break;
11319         default:
11320                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11321         }
11322 }
11323
11324 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11325         .f = cmd_set_vf_mac_anti_spoof_parsed,
11326         .data = NULL,
11327         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11328         .tokens = {
11329                 (void *)&cmd_vf_mac_anti_spoof_set,
11330                 (void *)&cmd_vf_mac_anti_spoof_vf,
11331                 (void *)&cmd_vf_mac_anti_spoof_mac,
11332                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11333                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11334                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11335                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11336                 NULL,
11337         },
11338 };
11339
11340 /* vf vlan strip queue configuration */
11341
11342 /* Common result structure for vf mac anti spoof */
11343 struct cmd_vf_vlan_stripq_result {
11344         cmdline_fixed_string_t set;
11345         cmdline_fixed_string_t vf;
11346         cmdline_fixed_string_t vlan;
11347         cmdline_fixed_string_t stripq;
11348         portid_t port_id;
11349         uint16_t vf_id;
11350         cmdline_fixed_string_t on_off;
11351 };
11352
11353 /* Common CLI fields for vf vlan strip enable disable */
11354 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11355         TOKEN_STRING_INITIALIZER
11356                 (struct cmd_vf_vlan_stripq_result,
11357                  set, "set");
11358 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11359         TOKEN_STRING_INITIALIZER
11360                 (struct cmd_vf_vlan_stripq_result,
11361                  vf, "vf");
11362 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11363         TOKEN_STRING_INITIALIZER
11364                 (struct cmd_vf_vlan_stripq_result,
11365                  vlan, "vlan");
11366 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11367         TOKEN_STRING_INITIALIZER
11368                 (struct cmd_vf_vlan_stripq_result,
11369                  stripq, "stripq");
11370 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11371         TOKEN_NUM_INITIALIZER
11372                 (struct cmd_vf_vlan_stripq_result,
11373                  port_id, RTE_UINT16);
11374 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11375         TOKEN_NUM_INITIALIZER
11376                 (struct cmd_vf_vlan_stripq_result,
11377                  vf_id, RTE_UINT16);
11378 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11379         TOKEN_STRING_INITIALIZER
11380                 (struct cmd_vf_vlan_stripq_result,
11381                  on_off, "on#off");
11382
11383 static void
11384 cmd_set_vf_vlan_stripq_parsed(
11385         void *parsed_result,
11386         __rte_unused struct cmdline *cl,
11387         __rte_unused void *data)
11388 {
11389         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11390         int ret = -ENOTSUP;
11391
11392         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11393
11394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11395                 return;
11396
11397 #ifdef RTE_NET_IXGBE
11398         if (ret == -ENOTSUP)
11399                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11400                         res->vf_id, is_on);
11401 #endif
11402 #ifdef RTE_NET_I40E
11403         if (ret == -ENOTSUP)
11404                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11405                         res->vf_id, is_on);
11406 #endif
11407 #ifdef RTE_NET_BNXT
11408         if (ret == -ENOTSUP)
11409                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11410                         res->vf_id, is_on);
11411 #endif
11412
11413         switch (ret) {
11414         case 0:
11415                 break;
11416         case -EINVAL:
11417                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11418                         res->vf_id, is_on);
11419                 break;
11420         case -ENODEV:
11421                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11422                 break;
11423         case -ENOTSUP:
11424                 fprintf(stderr, "function not implemented\n");
11425                 break;
11426         default:
11427                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11428         }
11429 }
11430
11431 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11432         .f = cmd_set_vf_vlan_stripq_parsed,
11433         .data = NULL,
11434         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11435         .tokens = {
11436                 (void *)&cmd_vf_vlan_stripq_set,
11437                 (void *)&cmd_vf_vlan_stripq_vf,
11438                 (void *)&cmd_vf_vlan_stripq_vlan,
11439                 (void *)&cmd_vf_vlan_stripq_stripq,
11440                 (void *)&cmd_vf_vlan_stripq_port_id,
11441                 (void *)&cmd_vf_vlan_stripq_vf_id,
11442                 (void *)&cmd_vf_vlan_stripq_on_off,
11443                 NULL,
11444         },
11445 };
11446
11447 /* vf vlan insert configuration */
11448
11449 /* Common result structure for vf vlan insert */
11450 struct cmd_vf_vlan_insert_result {
11451         cmdline_fixed_string_t set;
11452         cmdline_fixed_string_t vf;
11453         cmdline_fixed_string_t vlan;
11454         cmdline_fixed_string_t insert;
11455         portid_t port_id;
11456         uint16_t vf_id;
11457         uint16_t vlan_id;
11458 };
11459
11460 /* Common CLI fields for vf vlan insert enable disable */
11461 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11462         TOKEN_STRING_INITIALIZER
11463                 (struct cmd_vf_vlan_insert_result,
11464                  set, "set");
11465 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11466         TOKEN_STRING_INITIALIZER
11467                 (struct cmd_vf_vlan_insert_result,
11468                  vf, "vf");
11469 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11470         TOKEN_STRING_INITIALIZER
11471                 (struct cmd_vf_vlan_insert_result,
11472                  vlan, "vlan");
11473 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11474         TOKEN_STRING_INITIALIZER
11475                 (struct cmd_vf_vlan_insert_result,
11476                  insert, "insert");
11477 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11478         TOKEN_NUM_INITIALIZER
11479                 (struct cmd_vf_vlan_insert_result,
11480                  port_id, RTE_UINT16);
11481 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11482         TOKEN_NUM_INITIALIZER
11483                 (struct cmd_vf_vlan_insert_result,
11484                  vf_id, RTE_UINT16);
11485 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11486         TOKEN_NUM_INITIALIZER
11487                 (struct cmd_vf_vlan_insert_result,
11488                  vlan_id, RTE_UINT16);
11489
11490 static void
11491 cmd_set_vf_vlan_insert_parsed(
11492         void *parsed_result,
11493         __rte_unused struct cmdline *cl,
11494         __rte_unused void *data)
11495 {
11496         struct cmd_vf_vlan_insert_result *res = parsed_result;
11497         int ret = -ENOTSUP;
11498
11499         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11500                 return;
11501
11502 #ifdef RTE_NET_IXGBE
11503         if (ret == -ENOTSUP)
11504                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11505                         res->vlan_id);
11506 #endif
11507 #ifdef RTE_NET_I40E
11508         if (ret == -ENOTSUP)
11509                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11510                         res->vlan_id);
11511 #endif
11512 #ifdef RTE_NET_BNXT
11513         if (ret == -ENOTSUP)
11514                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11515                         res->vlan_id);
11516 #endif
11517
11518         switch (ret) {
11519         case 0:
11520                 break;
11521         case -EINVAL:
11522                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11523                         res->vf_id, res->vlan_id);
11524                 break;
11525         case -ENODEV:
11526                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11527                 break;
11528         case -ENOTSUP:
11529                 fprintf(stderr, "function not implemented\n");
11530                 break;
11531         default:
11532                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11533         }
11534 }
11535
11536 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11537         .f = cmd_set_vf_vlan_insert_parsed,
11538         .data = NULL,
11539         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11540         .tokens = {
11541                 (void *)&cmd_vf_vlan_insert_set,
11542                 (void *)&cmd_vf_vlan_insert_vf,
11543                 (void *)&cmd_vf_vlan_insert_vlan,
11544                 (void *)&cmd_vf_vlan_insert_insert,
11545                 (void *)&cmd_vf_vlan_insert_port_id,
11546                 (void *)&cmd_vf_vlan_insert_vf_id,
11547                 (void *)&cmd_vf_vlan_insert_vlan_id,
11548                 NULL,
11549         },
11550 };
11551
11552 /* tx loopback configuration */
11553
11554 /* Common result structure for tx loopback */
11555 struct cmd_tx_loopback_result {
11556         cmdline_fixed_string_t set;
11557         cmdline_fixed_string_t tx;
11558         cmdline_fixed_string_t loopback;
11559         portid_t port_id;
11560         cmdline_fixed_string_t on_off;
11561 };
11562
11563 /* Common CLI fields for tx loopback enable disable */
11564 cmdline_parse_token_string_t cmd_tx_loopback_set =
11565         TOKEN_STRING_INITIALIZER
11566                 (struct cmd_tx_loopback_result,
11567                  set, "set");
11568 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11569         TOKEN_STRING_INITIALIZER
11570                 (struct cmd_tx_loopback_result,
11571                  tx, "tx");
11572 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11573         TOKEN_STRING_INITIALIZER
11574                 (struct cmd_tx_loopback_result,
11575                  loopback, "loopback");
11576 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11577         TOKEN_NUM_INITIALIZER
11578                 (struct cmd_tx_loopback_result,
11579                  port_id, RTE_UINT16);
11580 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11581         TOKEN_STRING_INITIALIZER
11582                 (struct cmd_tx_loopback_result,
11583                  on_off, "on#off");
11584
11585 static void
11586 cmd_set_tx_loopback_parsed(
11587         void *parsed_result,
11588         __rte_unused struct cmdline *cl,
11589         __rte_unused void *data)
11590 {
11591         struct cmd_tx_loopback_result *res = parsed_result;
11592         int ret = -ENOTSUP;
11593
11594         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11595
11596         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11597                 return;
11598
11599 #ifdef RTE_NET_IXGBE
11600         if (ret == -ENOTSUP)
11601                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11602 #endif
11603 #ifdef RTE_NET_I40E
11604         if (ret == -ENOTSUP)
11605                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11606 #endif
11607 #ifdef RTE_NET_BNXT
11608         if (ret == -ENOTSUP)
11609                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11610 #endif
11611 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11612         if (ret == -ENOTSUP)
11613                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11614 #endif
11615
11616         switch (ret) {
11617         case 0:
11618                 break;
11619         case -EINVAL:
11620                 fprintf(stderr, "invalid is_on %d\n", is_on);
11621                 break;
11622         case -ENODEV:
11623                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11624                 break;
11625         case -ENOTSUP:
11626                 fprintf(stderr, "function not implemented\n");
11627                 break;
11628         default:
11629                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11630         }
11631 }
11632
11633 cmdline_parse_inst_t cmd_set_tx_loopback = {
11634         .f = cmd_set_tx_loopback_parsed,
11635         .data = NULL,
11636         .help_str = "set tx loopback <port_id> on|off",
11637         .tokens = {
11638                 (void *)&cmd_tx_loopback_set,
11639                 (void *)&cmd_tx_loopback_tx,
11640                 (void *)&cmd_tx_loopback_loopback,
11641                 (void *)&cmd_tx_loopback_port_id,
11642                 (void *)&cmd_tx_loopback_on_off,
11643                 NULL,
11644         },
11645 };
11646
11647 /* all queues drop enable configuration */
11648
11649 /* Common result structure for all queues drop enable */
11650 struct cmd_all_queues_drop_en_result {
11651         cmdline_fixed_string_t set;
11652         cmdline_fixed_string_t all;
11653         cmdline_fixed_string_t queues;
11654         cmdline_fixed_string_t drop;
11655         portid_t port_id;
11656         cmdline_fixed_string_t on_off;
11657 };
11658
11659 /* Common CLI fields for tx loopback enable disable */
11660 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11661         TOKEN_STRING_INITIALIZER
11662                 (struct cmd_all_queues_drop_en_result,
11663                  set, "set");
11664 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11665         TOKEN_STRING_INITIALIZER
11666                 (struct cmd_all_queues_drop_en_result,
11667                  all, "all");
11668 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11669         TOKEN_STRING_INITIALIZER
11670                 (struct cmd_all_queues_drop_en_result,
11671                  queues, "queues");
11672 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11673         TOKEN_STRING_INITIALIZER
11674                 (struct cmd_all_queues_drop_en_result,
11675                  drop, "drop");
11676 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11677         TOKEN_NUM_INITIALIZER
11678                 (struct cmd_all_queues_drop_en_result,
11679                  port_id, RTE_UINT16);
11680 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11681         TOKEN_STRING_INITIALIZER
11682                 (struct cmd_all_queues_drop_en_result,
11683                  on_off, "on#off");
11684
11685 static void
11686 cmd_set_all_queues_drop_en_parsed(
11687         void *parsed_result,
11688         __rte_unused struct cmdline *cl,
11689         __rte_unused void *data)
11690 {
11691         struct cmd_all_queues_drop_en_result *res = parsed_result;
11692         int ret = -ENOTSUP;
11693         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11694
11695         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11696                 return;
11697
11698 #ifdef RTE_NET_IXGBE
11699         if (ret == -ENOTSUP)
11700                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11701 #endif
11702 #ifdef RTE_NET_BNXT
11703         if (ret == -ENOTSUP)
11704                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11705 #endif
11706         switch (ret) {
11707         case 0:
11708                 break;
11709         case -EINVAL:
11710                 fprintf(stderr, "invalid is_on %d\n", is_on);
11711                 break;
11712         case -ENODEV:
11713                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11714                 break;
11715         case -ENOTSUP:
11716                 fprintf(stderr, "function not implemented\n");
11717                 break;
11718         default:
11719                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11720         }
11721 }
11722
11723 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11724         .f = cmd_set_all_queues_drop_en_parsed,
11725         .data = NULL,
11726         .help_str = "set all queues drop <port_id> on|off",
11727         .tokens = {
11728                 (void *)&cmd_all_queues_drop_en_set,
11729                 (void *)&cmd_all_queues_drop_en_all,
11730                 (void *)&cmd_all_queues_drop_en_queues,
11731                 (void *)&cmd_all_queues_drop_en_drop,
11732                 (void *)&cmd_all_queues_drop_en_port_id,
11733                 (void *)&cmd_all_queues_drop_en_on_off,
11734                 NULL,
11735         },
11736 };
11737
11738 /* vf split drop enable configuration */
11739
11740 /* Common result structure for vf split drop enable */
11741 struct cmd_vf_split_drop_en_result {
11742         cmdline_fixed_string_t set;
11743         cmdline_fixed_string_t vf;
11744         cmdline_fixed_string_t split;
11745         cmdline_fixed_string_t drop;
11746         portid_t port_id;
11747         uint16_t vf_id;
11748         cmdline_fixed_string_t on_off;
11749 };
11750
11751 /* Common CLI fields for vf split drop enable disable */
11752 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11753         TOKEN_STRING_INITIALIZER
11754                 (struct cmd_vf_split_drop_en_result,
11755                  set, "set");
11756 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11757         TOKEN_STRING_INITIALIZER
11758                 (struct cmd_vf_split_drop_en_result,
11759                  vf, "vf");
11760 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11761         TOKEN_STRING_INITIALIZER
11762                 (struct cmd_vf_split_drop_en_result,
11763                  split, "split");
11764 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11765         TOKEN_STRING_INITIALIZER
11766                 (struct cmd_vf_split_drop_en_result,
11767                  drop, "drop");
11768 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11769         TOKEN_NUM_INITIALIZER
11770                 (struct cmd_vf_split_drop_en_result,
11771                  port_id, RTE_UINT16);
11772 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11773         TOKEN_NUM_INITIALIZER
11774                 (struct cmd_vf_split_drop_en_result,
11775                  vf_id, RTE_UINT16);
11776 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11777         TOKEN_STRING_INITIALIZER
11778                 (struct cmd_vf_split_drop_en_result,
11779                  on_off, "on#off");
11780
11781 static void
11782 cmd_set_vf_split_drop_en_parsed(
11783         void *parsed_result,
11784         __rte_unused struct cmdline *cl,
11785         __rte_unused void *data)
11786 {
11787         struct cmd_vf_split_drop_en_result *res = parsed_result;
11788         int ret = -ENOTSUP;
11789         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11790
11791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11792                 return;
11793
11794 #ifdef RTE_NET_IXGBE
11795         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11796                         is_on);
11797 #endif
11798         switch (ret) {
11799         case 0:
11800                 break;
11801         case -EINVAL:
11802                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11803                         res->vf_id, is_on);
11804                 break;
11805         case -ENODEV:
11806                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11807                 break;
11808         case -ENOTSUP:
11809                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11810                 break;
11811         default:
11812                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11813         }
11814 }
11815
11816 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11817         .f = cmd_set_vf_split_drop_en_parsed,
11818         .data = NULL,
11819         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11820         .tokens = {
11821                 (void *)&cmd_vf_split_drop_en_set,
11822                 (void *)&cmd_vf_split_drop_en_vf,
11823                 (void *)&cmd_vf_split_drop_en_split,
11824                 (void *)&cmd_vf_split_drop_en_drop,
11825                 (void *)&cmd_vf_split_drop_en_port_id,
11826                 (void *)&cmd_vf_split_drop_en_vf_id,
11827                 (void *)&cmd_vf_split_drop_en_on_off,
11828                 NULL,
11829         },
11830 };
11831
11832 /* vf mac address configuration */
11833
11834 /* Common result structure for vf mac address */
11835 struct cmd_set_vf_mac_addr_result {
11836         cmdline_fixed_string_t set;
11837         cmdline_fixed_string_t vf;
11838         cmdline_fixed_string_t mac;
11839         cmdline_fixed_string_t addr;
11840         portid_t port_id;
11841         uint16_t vf_id;
11842         struct rte_ether_addr mac_addr;
11843
11844 };
11845
11846 /* Common CLI fields for vf split drop enable disable */
11847 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11848         TOKEN_STRING_INITIALIZER
11849                 (struct cmd_set_vf_mac_addr_result,
11850                  set, "set");
11851 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11852         TOKEN_STRING_INITIALIZER
11853                 (struct cmd_set_vf_mac_addr_result,
11854                  vf, "vf");
11855 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11856         TOKEN_STRING_INITIALIZER
11857                 (struct cmd_set_vf_mac_addr_result,
11858                  mac, "mac");
11859 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11860         TOKEN_STRING_INITIALIZER
11861                 (struct cmd_set_vf_mac_addr_result,
11862                  addr, "addr");
11863 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11864         TOKEN_NUM_INITIALIZER
11865                 (struct cmd_set_vf_mac_addr_result,
11866                  port_id, RTE_UINT16);
11867 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11868         TOKEN_NUM_INITIALIZER
11869                 (struct cmd_set_vf_mac_addr_result,
11870                  vf_id, RTE_UINT16);
11871 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11872         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11873                  mac_addr);
11874
11875 static void
11876 cmd_set_vf_mac_addr_parsed(
11877         void *parsed_result,
11878         __rte_unused struct cmdline *cl,
11879         __rte_unused void *data)
11880 {
11881         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11882         int ret = -ENOTSUP;
11883
11884         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11885                 return;
11886
11887 #ifdef RTE_NET_IXGBE
11888         if (ret == -ENOTSUP)
11889                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11890                                 &res->mac_addr);
11891 #endif
11892 #ifdef RTE_NET_I40E
11893         if (ret == -ENOTSUP)
11894                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11895                                 &res->mac_addr);
11896 #endif
11897 #ifdef RTE_NET_BNXT
11898         if (ret == -ENOTSUP)
11899                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11900                                 &res->mac_addr);
11901 #endif
11902
11903         switch (ret) {
11904         case 0:
11905                 break;
11906         case -EINVAL:
11907                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11908                 break;
11909         case -ENODEV:
11910                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11911                 break;
11912         case -ENOTSUP:
11913                 fprintf(stderr, "function not implemented\n");
11914                 break;
11915         default:
11916                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11917         }
11918 }
11919
11920 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11921         .f = cmd_set_vf_mac_addr_parsed,
11922         .data = NULL,
11923         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11924         .tokens = {
11925                 (void *)&cmd_set_vf_mac_addr_set,
11926                 (void *)&cmd_set_vf_mac_addr_vf,
11927                 (void *)&cmd_set_vf_mac_addr_mac,
11928                 (void *)&cmd_set_vf_mac_addr_addr,
11929                 (void *)&cmd_set_vf_mac_addr_port_id,
11930                 (void *)&cmd_set_vf_mac_addr_vf_id,
11931                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11932                 NULL,
11933         },
11934 };
11935
11936 /* MACsec configuration */
11937
11938 /* Common result structure for MACsec offload enable */
11939 struct cmd_macsec_offload_on_result {
11940         cmdline_fixed_string_t set;
11941         cmdline_fixed_string_t macsec;
11942         cmdline_fixed_string_t offload;
11943         portid_t port_id;
11944         cmdline_fixed_string_t on;
11945         cmdline_fixed_string_t encrypt;
11946         cmdline_fixed_string_t en_on_off;
11947         cmdline_fixed_string_t replay_protect;
11948         cmdline_fixed_string_t rp_on_off;
11949 };
11950
11951 /* Common CLI fields for MACsec offload disable */
11952 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11953         TOKEN_STRING_INITIALIZER
11954                 (struct cmd_macsec_offload_on_result,
11955                  set, "set");
11956 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11957         TOKEN_STRING_INITIALIZER
11958                 (struct cmd_macsec_offload_on_result,
11959                  macsec, "macsec");
11960 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11961         TOKEN_STRING_INITIALIZER
11962                 (struct cmd_macsec_offload_on_result,
11963                  offload, "offload");
11964 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11965         TOKEN_NUM_INITIALIZER
11966                 (struct cmd_macsec_offload_on_result,
11967                  port_id, RTE_UINT16);
11968 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11969         TOKEN_STRING_INITIALIZER
11970                 (struct cmd_macsec_offload_on_result,
11971                  on, "on");
11972 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11973         TOKEN_STRING_INITIALIZER
11974                 (struct cmd_macsec_offload_on_result,
11975                  encrypt, "encrypt");
11976 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11977         TOKEN_STRING_INITIALIZER
11978                 (struct cmd_macsec_offload_on_result,
11979                  en_on_off, "on#off");
11980 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11981         TOKEN_STRING_INITIALIZER
11982                 (struct cmd_macsec_offload_on_result,
11983                  replay_protect, "replay-protect");
11984 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11985         TOKEN_STRING_INITIALIZER
11986                 (struct cmd_macsec_offload_on_result,
11987                  rp_on_off, "on#off");
11988
11989 static void
11990 cmd_set_macsec_offload_on_parsed(
11991         void *parsed_result,
11992         __rte_unused struct cmdline *cl,
11993         __rte_unused void *data)
11994 {
11995         struct cmd_macsec_offload_on_result *res = parsed_result;
11996         int ret = -ENOTSUP;
11997         portid_t port_id = res->port_id;
11998         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11999         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
12000         struct rte_eth_dev_info dev_info;
12001
12002         if (port_id_is_invalid(port_id, ENABLED_WARN))
12003                 return;
12004         if (!port_is_stopped(port_id)) {
12005                 fprintf(stderr, "Please stop port %d first\n", port_id);
12006                 return;
12007         }
12008
12009         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12010         if (ret != 0)
12011                 return;
12012
12013         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12014 #ifdef RTE_NET_IXGBE
12015                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
12016 #endif
12017         }
12018         RTE_SET_USED(en);
12019         RTE_SET_USED(rp);
12020
12021         switch (ret) {
12022         case 0:
12023                 ports[port_id].dev_conf.txmode.offloads |=
12024                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12025                 cmd_reconfig_device_queue(port_id, 1, 1);
12026                 break;
12027         case -ENODEV:
12028                 fprintf(stderr, "invalid port_id %d\n", port_id);
12029                 break;
12030         case -ENOTSUP:
12031                 fprintf(stderr, "not supported on port %d\n", port_id);
12032                 break;
12033         default:
12034                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12035         }
12036 }
12037
12038 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
12039         .f = cmd_set_macsec_offload_on_parsed,
12040         .data = NULL,
12041         .help_str = "set macsec offload <port_id> on "
12042                 "encrypt on|off replay-protect on|off",
12043         .tokens = {
12044                 (void *)&cmd_macsec_offload_on_set,
12045                 (void *)&cmd_macsec_offload_on_macsec,
12046                 (void *)&cmd_macsec_offload_on_offload,
12047                 (void *)&cmd_macsec_offload_on_port_id,
12048                 (void *)&cmd_macsec_offload_on_on,
12049                 (void *)&cmd_macsec_offload_on_encrypt,
12050                 (void *)&cmd_macsec_offload_on_en_on_off,
12051                 (void *)&cmd_macsec_offload_on_replay_protect,
12052                 (void *)&cmd_macsec_offload_on_rp_on_off,
12053                 NULL,
12054         },
12055 };
12056
12057 /* Common result structure for MACsec offload disable */
12058 struct cmd_macsec_offload_off_result {
12059         cmdline_fixed_string_t set;
12060         cmdline_fixed_string_t macsec;
12061         cmdline_fixed_string_t offload;
12062         portid_t port_id;
12063         cmdline_fixed_string_t off;
12064 };
12065
12066 /* Common CLI fields for MACsec offload disable */
12067 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
12068         TOKEN_STRING_INITIALIZER
12069                 (struct cmd_macsec_offload_off_result,
12070                  set, "set");
12071 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
12072         TOKEN_STRING_INITIALIZER
12073                 (struct cmd_macsec_offload_off_result,
12074                  macsec, "macsec");
12075 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
12076         TOKEN_STRING_INITIALIZER
12077                 (struct cmd_macsec_offload_off_result,
12078                  offload, "offload");
12079 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
12080         TOKEN_NUM_INITIALIZER
12081                 (struct cmd_macsec_offload_off_result,
12082                  port_id, RTE_UINT16);
12083 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
12084         TOKEN_STRING_INITIALIZER
12085                 (struct cmd_macsec_offload_off_result,
12086                  off, "off");
12087
12088 static void
12089 cmd_set_macsec_offload_off_parsed(
12090         void *parsed_result,
12091         __rte_unused struct cmdline *cl,
12092         __rte_unused void *data)
12093 {
12094         struct cmd_macsec_offload_off_result *res = parsed_result;
12095         int ret = -ENOTSUP;
12096         struct rte_eth_dev_info dev_info;
12097         portid_t port_id = res->port_id;
12098
12099         if (port_id_is_invalid(port_id, ENABLED_WARN))
12100                 return;
12101         if (!port_is_stopped(port_id)) {
12102                 fprintf(stderr, "Please stop port %d first\n", port_id);
12103                 return;
12104         }
12105
12106         ret = eth_dev_info_get_print_err(port_id, &dev_info);
12107         if (ret != 0)
12108                 return;
12109
12110         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
12111 #ifdef RTE_NET_IXGBE
12112                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
12113 #endif
12114         }
12115         switch (ret) {
12116         case 0:
12117                 ports[port_id].dev_conf.txmode.offloads &=
12118                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
12119                 cmd_reconfig_device_queue(port_id, 1, 1);
12120                 break;
12121         case -ENODEV:
12122                 fprintf(stderr, "invalid port_id %d\n", port_id);
12123                 break;
12124         case -ENOTSUP:
12125                 fprintf(stderr, "not supported on port %d\n", port_id);
12126                 break;
12127         default:
12128                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12129         }
12130 }
12131
12132 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
12133         .f = cmd_set_macsec_offload_off_parsed,
12134         .data = NULL,
12135         .help_str = "set macsec offload <port_id> off",
12136         .tokens = {
12137                 (void *)&cmd_macsec_offload_off_set,
12138                 (void *)&cmd_macsec_offload_off_macsec,
12139                 (void *)&cmd_macsec_offload_off_offload,
12140                 (void *)&cmd_macsec_offload_off_port_id,
12141                 (void *)&cmd_macsec_offload_off_off,
12142                 NULL,
12143         },
12144 };
12145
12146 /* Common result structure for MACsec secure connection configure */
12147 struct cmd_macsec_sc_result {
12148         cmdline_fixed_string_t set;
12149         cmdline_fixed_string_t macsec;
12150         cmdline_fixed_string_t sc;
12151         cmdline_fixed_string_t tx_rx;
12152         portid_t port_id;
12153         struct rte_ether_addr mac;
12154         uint16_t pi;
12155 };
12156
12157 /* Common CLI fields for MACsec secure connection configure */
12158 cmdline_parse_token_string_t cmd_macsec_sc_set =
12159         TOKEN_STRING_INITIALIZER
12160                 (struct cmd_macsec_sc_result,
12161                  set, "set");
12162 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12163         TOKEN_STRING_INITIALIZER
12164                 (struct cmd_macsec_sc_result,
12165                  macsec, "macsec");
12166 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12167         TOKEN_STRING_INITIALIZER
12168                 (struct cmd_macsec_sc_result,
12169                  sc, "sc");
12170 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12171         TOKEN_STRING_INITIALIZER
12172                 (struct cmd_macsec_sc_result,
12173                  tx_rx, "tx#rx");
12174 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12175         TOKEN_NUM_INITIALIZER
12176                 (struct cmd_macsec_sc_result,
12177                  port_id, RTE_UINT16);
12178 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12179         TOKEN_ETHERADDR_INITIALIZER
12180                 (struct cmd_macsec_sc_result,
12181                  mac);
12182 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12183         TOKEN_NUM_INITIALIZER
12184                 (struct cmd_macsec_sc_result,
12185                  pi, RTE_UINT16);
12186
12187 static void
12188 cmd_set_macsec_sc_parsed(
12189         void *parsed_result,
12190         __rte_unused struct cmdline *cl,
12191         __rte_unused void *data)
12192 {
12193         struct cmd_macsec_sc_result *res = parsed_result;
12194         int ret = -ENOTSUP;
12195         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12196
12197 #ifdef RTE_NET_IXGBE
12198         ret = is_tx ?
12199                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12200                                 res->mac.addr_bytes) :
12201                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12202                                 res->mac.addr_bytes, res->pi);
12203 #endif
12204         RTE_SET_USED(is_tx);
12205
12206         switch (ret) {
12207         case 0:
12208                 break;
12209         case -ENODEV:
12210                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12211                 break;
12212         case -ENOTSUP:
12213                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12214                 break;
12215         default:
12216                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12217         }
12218 }
12219
12220 cmdline_parse_inst_t cmd_set_macsec_sc = {
12221         .f = cmd_set_macsec_sc_parsed,
12222         .data = NULL,
12223         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12224         .tokens = {
12225                 (void *)&cmd_macsec_sc_set,
12226                 (void *)&cmd_macsec_sc_macsec,
12227                 (void *)&cmd_macsec_sc_sc,
12228                 (void *)&cmd_macsec_sc_tx_rx,
12229                 (void *)&cmd_macsec_sc_port_id,
12230                 (void *)&cmd_macsec_sc_mac,
12231                 (void *)&cmd_macsec_sc_pi,
12232                 NULL,
12233         },
12234 };
12235
12236 /* Common result structure for MACsec secure connection configure */
12237 struct cmd_macsec_sa_result {
12238         cmdline_fixed_string_t set;
12239         cmdline_fixed_string_t macsec;
12240         cmdline_fixed_string_t sa;
12241         cmdline_fixed_string_t tx_rx;
12242         portid_t port_id;
12243         uint8_t idx;
12244         uint8_t an;
12245         uint32_t pn;
12246         cmdline_fixed_string_t key;
12247 };
12248
12249 /* Common CLI fields for MACsec secure connection configure */
12250 cmdline_parse_token_string_t cmd_macsec_sa_set =
12251         TOKEN_STRING_INITIALIZER
12252                 (struct cmd_macsec_sa_result,
12253                  set, "set");
12254 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12255         TOKEN_STRING_INITIALIZER
12256                 (struct cmd_macsec_sa_result,
12257                  macsec, "macsec");
12258 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12259         TOKEN_STRING_INITIALIZER
12260                 (struct cmd_macsec_sa_result,
12261                  sa, "sa");
12262 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12263         TOKEN_STRING_INITIALIZER
12264                 (struct cmd_macsec_sa_result,
12265                  tx_rx, "tx#rx");
12266 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12267         TOKEN_NUM_INITIALIZER
12268                 (struct cmd_macsec_sa_result,
12269                  port_id, RTE_UINT16);
12270 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12271         TOKEN_NUM_INITIALIZER
12272                 (struct cmd_macsec_sa_result,
12273                  idx, RTE_UINT8);
12274 cmdline_parse_token_num_t cmd_macsec_sa_an =
12275         TOKEN_NUM_INITIALIZER
12276                 (struct cmd_macsec_sa_result,
12277                  an, RTE_UINT8);
12278 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12279         TOKEN_NUM_INITIALIZER
12280                 (struct cmd_macsec_sa_result,
12281                  pn, RTE_UINT32);
12282 cmdline_parse_token_string_t cmd_macsec_sa_key =
12283         TOKEN_STRING_INITIALIZER
12284                 (struct cmd_macsec_sa_result,
12285                  key, NULL);
12286
12287 static void
12288 cmd_set_macsec_sa_parsed(
12289         void *parsed_result,
12290         __rte_unused struct cmdline *cl,
12291         __rte_unused void *data)
12292 {
12293         struct cmd_macsec_sa_result *res = parsed_result;
12294         int ret = -ENOTSUP;
12295         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12296         uint8_t key[16] = { 0 };
12297         uint8_t xdgt0;
12298         uint8_t xdgt1;
12299         int key_len;
12300         int i;
12301
12302         key_len = strlen(res->key) / 2;
12303         if (key_len > 16)
12304                 key_len = 16;
12305
12306         for (i = 0; i < key_len; i++) {
12307                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12308                 if (xdgt0 == 0xFF)
12309                         return;
12310                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12311                 if (xdgt1 == 0xFF)
12312                         return;
12313                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12314         }
12315
12316 #ifdef RTE_NET_IXGBE
12317         ret = is_tx ?
12318                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12319                         res->idx, res->an, res->pn, key) :
12320                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12321                         res->idx, res->an, res->pn, key);
12322 #endif
12323         RTE_SET_USED(is_tx);
12324         RTE_SET_USED(key);
12325
12326         switch (ret) {
12327         case 0:
12328                 break;
12329         case -EINVAL:
12330                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12331                 break;
12332         case -ENODEV:
12333                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12334                 break;
12335         case -ENOTSUP:
12336                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12337                 break;
12338         default:
12339                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12340         }
12341 }
12342
12343 cmdline_parse_inst_t cmd_set_macsec_sa = {
12344         .f = cmd_set_macsec_sa_parsed,
12345         .data = NULL,
12346         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12347         .tokens = {
12348                 (void *)&cmd_macsec_sa_set,
12349                 (void *)&cmd_macsec_sa_macsec,
12350                 (void *)&cmd_macsec_sa_sa,
12351                 (void *)&cmd_macsec_sa_tx_rx,
12352                 (void *)&cmd_macsec_sa_port_id,
12353                 (void *)&cmd_macsec_sa_idx,
12354                 (void *)&cmd_macsec_sa_an,
12355                 (void *)&cmd_macsec_sa_pn,
12356                 (void *)&cmd_macsec_sa_key,
12357                 NULL,
12358         },
12359 };
12360
12361 /* VF unicast promiscuous mode configuration */
12362
12363 /* Common result structure for VF unicast promiscuous mode */
12364 struct cmd_vf_promisc_result {
12365         cmdline_fixed_string_t set;
12366         cmdline_fixed_string_t vf;
12367         cmdline_fixed_string_t promisc;
12368         portid_t port_id;
12369         uint32_t vf_id;
12370         cmdline_fixed_string_t on_off;
12371 };
12372
12373 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12374 cmdline_parse_token_string_t cmd_vf_promisc_set =
12375         TOKEN_STRING_INITIALIZER
12376                 (struct cmd_vf_promisc_result,
12377                  set, "set");
12378 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_vf_promisc_result,
12381                  vf, "vf");
12382 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12383         TOKEN_STRING_INITIALIZER
12384                 (struct cmd_vf_promisc_result,
12385                  promisc, "promisc");
12386 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12387         TOKEN_NUM_INITIALIZER
12388                 (struct cmd_vf_promisc_result,
12389                  port_id, RTE_UINT16);
12390 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12391         TOKEN_NUM_INITIALIZER
12392                 (struct cmd_vf_promisc_result,
12393                  vf_id, RTE_UINT32);
12394 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12395         TOKEN_STRING_INITIALIZER
12396                 (struct cmd_vf_promisc_result,
12397                  on_off, "on#off");
12398
12399 static void
12400 cmd_set_vf_promisc_parsed(
12401         void *parsed_result,
12402         __rte_unused struct cmdline *cl,
12403         __rte_unused void *data)
12404 {
12405         struct cmd_vf_promisc_result *res = parsed_result;
12406         int ret = -ENOTSUP;
12407
12408         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12409
12410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12411                 return;
12412
12413 #ifdef RTE_NET_I40E
12414         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12415                                                   res->vf_id, is_on);
12416 #endif
12417
12418         switch (ret) {
12419         case 0:
12420                 break;
12421         case -EINVAL:
12422                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12423                 break;
12424         case -ENODEV:
12425                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12426                 break;
12427         case -ENOTSUP:
12428                 fprintf(stderr, "function not implemented\n");
12429                 break;
12430         default:
12431                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12432         }
12433 }
12434
12435 cmdline_parse_inst_t cmd_set_vf_promisc = {
12436         .f = cmd_set_vf_promisc_parsed,
12437         .data = NULL,
12438         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12439                 "Set unicast promiscuous mode for a VF from the PF",
12440         .tokens = {
12441                 (void *)&cmd_vf_promisc_set,
12442                 (void *)&cmd_vf_promisc_vf,
12443                 (void *)&cmd_vf_promisc_promisc,
12444                 (void *)&cmd_vf_promisc_port_id,
12445                 (void *)&cmd_vf_promisc_vf_id,
12446                 (void *)&cmd_vf_promisc_on_off,
12447                 NULL,
12448         },
12449 };
12450
12451 /* VF multicast promiscuous mode configuration */
12452
12453 /* Common result structure for VF multicast promiscuous mode */
12454 struct cmd_vf_allmulti_result {
12455         cmdline_fixed_string_t set;
12456         cmdline_fixed_string_t vf;
12457         cmdline_fixed_string_t allmulti;
12458         portid_t port_id;
12459         uint32_t vf_id;
12460         cmdline_fixed_string_t on_off;
12461 };
12462
12463 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12464 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12465         TOKEN_STRING_INITIALIZER
12466                 (struct cmd_vf_allmulti_result,
12467                  set, "set");
12468 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12469         TOKEN_STRING_INITIALIZER
12470                 (struct cmd_vf_allmulti_result,
12471                  vf, "vf");
12472 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12473         TOKEN_STRING_INITIALIZER
12474                 (struct cmd_vf_allmulti_result,
12475                  allmulti, "allmulti");
12476 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12477         TOKEN_NUM_INITIALIZER
12478                 (struct cmd_vf_allmulti_result,
12479                  port_id, RTE_UINT16);
12480 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12481         TOKEN_NUM_INITIALIZER
12482                 (struct cmd_vf_allmulti_result,
12483                  vf_id, RTE_UINT32);
12484 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12485         TOKEN_STRING_INITIALIZER
12486                 (struct cmd_vf_allmulti_result,
12487                  on_off, "on#off");
12488
12489 static void
12490 cmd_set_vf_allmulti_parsed(
12491         void *parsed_result,
12492         __rte_unused struct cmdline *cl,
12493         __rte_unused void *data)
12494 {
12495         struct cmd_vf_allmulti_result *res = parsed_result;
12496         int ret = -ENOTSUP;
12497
12498         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12499
12500         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12501                 return;
12502
12503 #ifdef RTE_NET_I40E
12504         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12505                                                     res->vf_id, is_on);
12506 #endif
12507
12508         switch (ret) {
12509         case 0:
12510                 break;
12511         case -EINVAL:
12512                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12513                 break;
12514         case -ENODEV:
12515                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12516                 break;
12517         case -ENOTSUP:
12518                 fprintf(stderr, "function not implemented\n");
12519                 break;
12520         default:
12521                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12522         }
12523 }
12524
12525 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12526         .f = cmd_set_vf_allmulti_parsed,
12527         .data = NULL,
12528         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12529                 "Set multicast promiscuous mode for a VF from the PF",
12530         .tokens = {
12531                 (void *)&cmd_vf_allmulti_set,
12532                 (void *)&cmd_vf_allmulti_vf,
12533                 (void *)&cmd_vf_allmulti_allmulti,
12534                 (void *)&cmd_vf_allmulti_port_id,
12535                 (void *)&cmd_vf_allmulti_vf_id,
12536                 (void *)&cmd_vf_allmulti_on_off,
12537                 NULL,
12538         },
12539 };
12540
12541 /* vf broadcast mode configuration */
12542
12543 /* Common result structure for vf broadcast */
12544 struct cmd_set_vf_broadcast_result {
12545         cmdline_fixed_string_t set;
12546         cmdline_fixed_string_t vf;
12547         cmdline_fixed_string_t broadcast;
12548         portid_t port_id;
12549         uint16_t vf_id;
12550         cmdline_fixed_string_t on_off;
12551 };
12552
12553 /* Common CLI fields for vf broadcast enable disable */
12554 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12555         TOKEN_STRING_INITIALIZER
12556                 (struct cmd_set_vf_broadcast_result,
12557                  set, "set");
12558 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12559         TOKEN_STRING_INITIALIZER
12560                 (struct cmd_set_vf_broadcast_result,
12561                  vf, "vf");
12562 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12563         TOKEN_STRING_INITIALIZER
12564                 (struct cmd_set_vf_broadcast_result,
12565                  broadcast, "broadcast");
12566 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12567         TOKEN_NUM_INITIALIZER
12568                 (struct cmd_set_vf_broadcast_result,
12569                  port_id, RTE_UINT16);
12570 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12571         TOKEN_NUM_INITIALIZER
12572                 (struct cmd_set_vf_broadcast_result,
12573                  vf_id, RTE_UINT16);
12574 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12575         TOKEN_STRING_INITIALIZER
12576                 (struct cmd_set_vf_broadcast_result,
12577                  on_off, "on#off");
12578
12579 static void
12580 cmd_set_vf_broadcast_parsed(
12581         void *parsed_result,
12582         __rte_unused struct cmdline *cl,
12583         __rte_unused void *data)
12584 {
12585         struct cmd_set_vf_broadcast_result *res = parsed_result;
12586         int ret = -ENOTSUP;
12587
12588         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12589
12590         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12591                 return;
12592
12593 #ifdef RTE_NET_I40E
12594         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12595                                             res->vf_id, is_on);
12596 #endif
12597
12598         switch (ret) {
12599         case 0:
12600                 break;
12601         case -EINVAL:
12602                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12603                         res->vf_id, is_on);
12604                 break;
12605         case -ENODEV:
12606                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12607                 break;
12608         case -ENOTSUP:
12609                 fprintf(stderr, "function not implemented\n");
12610                 break;
12611         default:
12612                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12613         }
12614 }
12615
12616 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12617         .f = cmd_set_vf_broadcast_parsed,
12618         .data = NULL,
12619         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12620         .tokens = {
12621                 (void *)&cmd_set_vf_broadcast_set,
12622                 (void *)&cmd_set_vf_broadcast_vf,
12623                 (void *)&cmd_set_vf_broadcast_broadcast,
12624                 (void *)&cmd_set_vf_broadcast_port_id,
12625                 (void *)&cmd_set_vf_broadcast_vf_id,
12626                 (void *)&cmd_set_vf_broadcast_on_off,
12627                 NULL,
12628         },
12629 };
12630
12631 /* vf vlan tag configuration */
12632
12633 /* Common result structure for vf vlan tag */
12634 struct cmd_set_vf_vlan_tag_result {
12635         cmdline_fixed_string_t set;
12636         cmdline_fixed_string_t vf;
12637         cmdline_fixed_string_t vlan;
12638         cmdline_fixed_string_t tag;
12639         portid_t port_id;
12640         uint16_t vf_id;
12641         cmdline_fixed_string_t on_off;
12642 };
12643
12644 /* Common CLI fields for vf vlan tag enable disable */
12645 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12646         TOKEN_STRING_INITIALIZER
12647                 (struct cmd_set_vf_vlan_tag_result,
12648                  set, "set");
12649 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12650         TOKEN_STRING_INITIALIZER
12651                 (struct cmd_set_vf_vlan_tag_result,
12652                  vf, "vf");
12653 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12654         TOKEN_STRING_INITIALIZER
12655                 (struct cmd_set_vf_vlan_tag_result,
12656                  vlan, "vlan");
12657 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12658         TOKEN_STRING_INITIALIZER
12659                 (struct cmd_set_vf_vlan_tag_result,
12660                  tag, "tag");
12661 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12662         TOKEN_NUM_INITIALIZER
12663                 (struct cmd_set_vf_vlan_tag_result,
12664                  port_id, RTE_UINT16);
12665 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12666         TOKEN_NUM_INITIALIZER
12667                 (struct cmd_set_vf_vlan_tag_result,
12668                  vf_id, RTE_UINT16);
12669 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12670         TOKEN_STRING_INITIALIZER
12671                 (struct cmd_set_vf_vlan_tag_result,
12672                  on_off, "on#off");
12673
12674 static void
12675 cmd_set_vf_vlan_tag_parsed(
12676         void *parsed_result,
12677         __rte_unused struct cmdline *cl,
12678         __rte_unused void *data)
12679 {
12680         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12681         int ret = -ENOTSUP;
12682
12683         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12684
12685         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12686                 return;
12687
12688 #ifdef RTE_NET_I40E
12689         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12690                                            res->vf_id, is_on);
12691 #endif
12692
12693         switch (ret) {
12694         case 0:
12695                 break;
12696         case -EINVAL:
12697                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12698                         res->vf_id, is_on);
12699                 break;
12700         case -ENODEV:
12701                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12702                 break;
12703         case -ENOTSUP:
12704                 fprintf(stderr, "function not implemented\n");
12705                 break;
12706         default:
12707                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12708         }
12709 }
12710
12711 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12712         .f = cmd_set_vf_vlan_tag_parsed,
12713         .data = NULL,
12714         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12715         .tokens = {
12716                 (void *)&cmd_set_vf_vlan_tag_set,
12717                 (void *)&cmd_set_vf_vlan_tag_vf,
12718                 (void *)&cmd_set_vf_vlan_tag_vlan,
12719                 (void *)&cmd_set_vf_vlan_tag_tag,
12720                 (void *)&cmd_set_vf_vlan_tag_port_id,
12721                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12722                 (void *)&cmd_set_vf_vlan_tag_on_off,
12723                 NULL,
12724         },
12725 };
12726
12727 /* Common definition of VF and TC TX bandwidth configuration */
12728 struct cmd_vf_tc_bw_result {
12729         cmdline_fixed_string_t set;
12730         cmdline_fixed_string_t vf;
12731         cmdline_fixed_string_t tc;
12732         cmdline_fixed_string_t tx;
12733         cmdline_fixed_string_t min_bw;
12734         cmdline_fixed_string_t max_bw;
12735         cmdline_fixed_string_t strict_link_prio;
12736         portid_t port_id;
12737         uint16_t vf_id;
12738         uint8_t tc_no;
12739         uint32_t bw;
12740         cmdline_fixed_string_t bw_list;
12741         uint8_t tc_map;
12742 };
12743
12744 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12745         TOKEN_STRING_INITIALIZER
12746                 (struct cmd_vf_tc_bw_result,
12747                  set, "set");
12748 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12749         TOKEN_STRING_INITIALIZER
12750                 (struct cmd_vf_tc_bw_result,
12751                  vf, "vf");
12752 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12753         TOKEN_STRING_INITIALIZER
12754                 (struct cmd_vf_tc_bw_result,
12755                  tc, "tc");
12756 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12757         TOKEN_STRING_INITIALIZER
12758                 (struct cmd_vf_tc_bw_result,
12759                  tx, "tx");
12760 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12761         TOKEN_STRING_INITIALIZER
12762                 (struct cmd_vf_tc_bw_result,
12763                  strict_link_prio, "strict-link-priority");
12764 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12765         TOKEN_STRING_INITIALIZER
12766                 (struct cmd_vf_tc_bw_result,
12767                  min_bw, "min-bandwidth");
12768 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12769         TOKEN_STRING_INITIALIZER
12770                 (struct cmd_vf_tc_bw_result,
12771                  max_bw, "max-bandwidth");
12772 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12773         TOKEN_NUM_INITIALIZER
12774                 (struct cmd_vf_tc_bw_result,
12775                  port_id, RTE_UINT16);
12776 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12777         TOKEN_NUM_INITIALIZER
12778                 (struct cmd_vf_tc_bw_result,
12779                  vf_id, RTE_UINT16);
12780 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12781         TOKEN_NUM_INITIALIZER
12782                 (struct cmd_vf_tc_bw_result,
12783                  tc_no, RTE_UINT8);
12784 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12785         TOKEN_NUM_INITIALIZER
12786                 (struct cmd_vf_tc_bw_result,
12787                  bw, RTE_UINT32);
12788 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_vf_tc_bw_result,
12791                  bw_list, NULL);
12792 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12793         TOKEN_NUM_INITIALIZER
12794                 (struct cmd_vf_tc_bw_result,
12795                  tc_map, RTE_UINT8);
12796
12797 /* VF max bandwidth setting */
12798 static void
12799 cmd_vf_max_bw_parsed(
12800         void *parsed_result,
12801         __rte_unused struct cmdline *cl,
12802         __rte_unused void *data)
12803 {
12804         struct cmd_vf_tc_bw_result *res = parsed_result;
12805         int ret = -ENOTSUP;
12806
12807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12808                 return;
12809
12810 #ifdef RTE_NET_I40E
12811         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12812                                          res->vf_id, res->bw);
12813 #endif
12814
12815         switch (ret) {
12816         case 0:
12817                 break;
12818         case -EINVAL:
12819                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12820                         res->vf_id, res->bw);
12821                 break;
12822         case -ENODEV:
12823                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12824                 break;
12825         case -ENOTSUP:
12826                 fprintf(stderr, "function not implemented\n");
12827                 break;
12828         default:
12829                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12830         }
12831 }
12832
12833 cmdline_parse_inst_t cmd_vf_max_bw = {
12834         .f = cmd_vf_max_bw_parsed,
12835         .data = NULL,
12836         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12837         .tokens = {
12838                 (void *)&cmd_vf_tc_bw_set,
12839                 (void *)&cmd_vf_tc_bw_vf,
12840                 (void *)&cmd_vf_tc_bw_tx,
12841                 (void *)&cmd_vf_tc_bw_max_bw,
12842                 (void *)&cmd_vf_tc_bw_port_id,
12843                 (void *)&cmd_vf_tc_bw_vf_id,
12844                 (void *)&cmd_vf_tc_bw_bw,
12845                 NULL,
12846         },
12847 };
12848
12849 static int
12850 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12851                            uint8_t *tc_num,
12852                            char *str)
12853 {
12854         uint32_t size;
12855         const char *p, *p0 = str;
12856         char s[256];
12857         char *end;
12858         char *str_fld[16];
12859         uint16_t i;
12860         int ret;
12861
12862         p = strchr(p0, '(');
12863         if (p == NULL) {
12864                 fprintf(stderr,
12865                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12866                 return -1;
12867         }
12868         p++;
12869         p0 = strchr(p, ')');
12870         if (p0 == NULL) {
12871                 fprintf(stderr,
12872                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12873                 return -1;
12874         }
12875         size = p0 - p;
12876         if (size >= sizeof(s)) {
12877                 fprintf(stderr,
12878                         "The string size exceeds the internal buffer size\n");
12879                 return -1;
12880         }
12881         snprintf(s, sizeof(s), "%.*s", size, p);
12882         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12883         if (ret <= 0) {
12884                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12885                 return -1;
12886         }
12887         *tc_num = ret;
12888         for (i = 0; i < ret; i++)
12889                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12890
12891         return 0;
12892 }
12893
12894 /* TC min bandwidth setting */
12895 static void
12896 cmd_vf_tc_min_bw_parsed(
12897         void *parsed_result,
12898         __rte_unused struct cmdline *cl,
12899         __rte_unused void *data)
12900 {
12901         struct cmd_vf_tc_bw_result *res = parsed_result;
12902         uint8_t tc_num;
12903         uint8_t bw[16];
12904         int ret = -ENOTSUP;
12905
12906         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12907                 return;
12908
12909         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12910         if (ret)
12911                 return;
12912
12913 #ifdef RTE_NET_I40E
12914         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12915                                               tc_num, bw);
12916 #endif
12917
12918         switch (ret) {
12919         case 0:
12920                 break;
12921         case -EINVAL:
12922                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12923                 break;
12924         case -ENODEV:
12925                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12926                 break;
12927         case -ENOTSUP:
12928                 fprintf(stderr, "function not implemented\n");
12929                 break;
12930         default:
12931                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12932         }
12933 }
12934
12935 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12936         .f = cmd_vf_tc_min_bw_parsed,
12937         .data = NULL,
12938         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12939                     " <bw1, bw2, ...>",
12940         .tokens = {
12941                 (void *)&cmd_vf_tc_bw_set,
12942                 (void *)&cmd_vf_tc_bw_vf,
12943                 (void *)&cmd_vf_tc_bw_tc,
12944                 (void *)&cmd_vf_tc_bw_tx,
12945                 (void *)&cmd_vf_tc_bw_min_bw,
12946                 (void *)&cmd_vf_tc_bw_port_id,
12947                 (void *)&cmd_vf_tc_bw_vf_id,
12948                 (void *)&cmd_vf_tc_bw_bw_list,
12949                 NULL,
12950         },
12951 };
12952
12953 static void
12954 cmd_tc_min_bw_parsed(
12955         void *parsed_result,
12956         __rte_unused struct cmdline *cl,
12957         __rte_unused void *data)
12958 {
12959         struct cmd_vf_tc_bw_result *res = parsed_result;
12960         struct rte_port *port;
12961         uint8_t tc_num;
12962         uint8_t bw[16];
12963         int ret = -ENOTSUP;
12964
12965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12966                 return;
12967
12968         port = &ports[res->port_id];
12969         /** Check if the port is not started **/
12970         if (port->port_status != RTE_PORT_STOPPED) {
12971                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
12972                 return;
12973         }
12974
12975         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12976         if (ret)
12977                 return;
12978
12979 #ifdef RTE_NET_IXGBE
12980         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12981 #endif
12982
12983         switch (ret) {
12984         case 0:
12985                 break;
12986         case -EINVAL:
12987                 fprintf(stderr, "invalid bandwidth\n");
12988                 break;
12989         case -ENODEV:
12990                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12991                 break;
12992         case -ENOTSUP:
12993                 fprintf(stderr, "function not implemented\n");
12994                 break;
12995         default:
12996                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12997         }
12998 }
12999
13000 cmdline_parse_inst_t cmd_tc_min_bw = {
13001         .f = cmd_tc_min_bw_parsed,
13002         .data = NULL,
13003         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13004         .tokens = {
13005                 (void *)&cmd_vf_tc_bw_set,
13006                 (void *)&cmd_vf_tc_bw_tc,
13007                 (void *)&cmd_vf_tc_bw_tx,
13008                 (void *)&cmd_vf_tc_bw_min_bw,
13009                 (void *)&cmd_vf_tc_bw_port_id,
13010                 (void *)&cmd_vf_tc_bw_bw_list,
13011                 NULL,
13012         },
13013 };
13014
13015 /* TC max bandwidth setting */
13016 static void
13017 cmd_vf_tc_max_bw_parsed(
13018         void *parsed_result,
13019         __rte_unused struct cmdline *cl,
13020         __rte_unused void *data)
13021 {
13022         struct cmd_vf_tc_bw_result *res = parsed_result;
13023         int ret = -ENOTSUP;
13024
13025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13026                 return;
13027
13028 #ifdef RTE_NET_I40E
13029         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
13030                                             res->tc_no, res->bw);
13031 #endif
13032
13033         switch (ret) {
13034         case 0:
13035                 break;
13036         case -EINVAL:
13037                 fprintf(stderr,
13038                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
13039                         res->vf_id, res->tc_no, res->bw);
13040                 break;
13041         case -ENODEV:
13042                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
13043                 break;
13044         case -ENOTSUP:
13045                 fprintf(stderr, "function not implemented\n");
13046                 break;
13047         default:
13048                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
13049         }
13050 }
13051
13052 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
13053         .f = cmd_vf_tc_max_bw_parsed,
13054         .data = NULL,
13055         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
13056                     " <bandwidth>",
13057         .tokens = {
13058                 (void *)&cmd_vf_tc_bw_set,
13059                 (void *)&cmd_vf_tc_bw_vf,
13060                 (void *)&cmd_vf_tc_bw_tc,
13061                 (void *)&cmd_vf_tc_bw_tx,
13062                 (void *)&cmd_vf_tc_bw_max_bw,
13063                 (void *)&cmd_vf_tc_bw_port_id,
13064                 (void *)&cmd_vf_tc_bw_vf_id,
13065                 (void *)&cmd_vf_tc_bw_tc_no,
13066                 (void *)&cmd_vf_tc_bw_bw,
13067                 NULL,
13068         },
13069 };
13070
13071 /** Set VXLAN encapsulation details */
13072 struct cmd_set_vxlan_result {
13073         cmdline_fixed_string_t set;
13074         cmdline_fixed_string_t vxlan;
13075         cmdline_fixed_string_t pos_token;
13076         cmdline_fixed_string_t ip_version;
13077         uint32_t vlan_present:1;
13078         uint32_t vni;
13079         uint16_t udp_src;
13080         uint16_t udp_dst;
13081         cmdline_ipaddr_t ip_src;
13082         cmdline_ipaddr_t ip_dst;
13083         uint16_t tci;
13084         uint8_t tos;
13085         uint8_t ttl;
13086         struct rte_ether_addr eth_src;
13087         struct rte_ether_addr eth_dst;
13088 };
13089
13090 cmdline_parse_token_string_t cmd_set_vxlan_set =
13091         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
13092 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
13093         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
13094 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
13095         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13096                                  "vxlan-tos-ttl");
13097 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
13098         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
13099                                  "vxlan-with-vlan");
13100 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
13101         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13102                                  "ip-version");
13103 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
13104         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
13105                                  "ipv4#ipv6");
13106 cmdline_parse_token_string_t cmd_set_vxlan_vni =
13107         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13108                                  "vni");
13109 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
13110         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
13111 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
13112         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13113                                  "udp-src");
13114 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
13115         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
13116 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
13117         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13118                                  "udp-dst");
13119 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
13120         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
13121 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
13122         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13123                                  "ip-tos");
13124 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
13125         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
13126 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
13127         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13128                                  "ip-ttl");
13129 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
13130         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
13131 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
13132         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13133                                  "ip-src");
13134 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
13135         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
13136 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13137         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13138                                  "ip-dst");
13139 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13140         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13141 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13142         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13143                                  "vlan-tci");
13144 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13145         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13146 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13147         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13148                                  "eth-src");
13149 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13150         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13151 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13152         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13153                                  "eth-dst");
13154 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13155         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13156
13157 static void cmd_set_vxlan_parsed(void *parsed_result,
13158         __rte_unused struct cmdline *cl,
13159         __rte_unused void *data)
13160 {
13161         struct cmd_set_vxlan_result *res = parsed_result;
13162         union {
13163                 uint32_t vxlan_id;
13164                 uint8_t vni[4];
13165         } id = {
13166                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13167         };
13168
13169         vxlan_encap_conf.select_tos_ttl = 0;
13170         if (strcmp(res->vxlan, "vxlan") == 0)
13171                 vxlan_encap_conf.select_vlan = 0;
13172         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13173                 vxlan_encap_conf.select_vlan = 1;
13174         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13175                 vxlan_encap_conf.select_vlan = 0;
13176                 vxlan_encap_conf.select_tos_ttl = 1;
13177         }
13178         if (strcmp(res->ip_version, "ipv4") == 0)
13179                 vxlan_encap_conf.select_ipv4 = 1;
13180         else if (strcmp(res->ip_version, "ipv6") == 0)
13181                 vxlan_encap_conf.select_ipv4 = 0;
13182         else
13183                 return;
13184         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13185         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13186         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13187         vxlan_encap_conf.ip_tos = res->tos;
13188         vxlan_encap_conf.ip_ttl = res->ttl;
13189         if (vxlan_encap_conf.select_ipv4) {
13190                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13191                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13192         } else {
13193                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13194                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13195         }
13196         if (vxlan_encap_conf.select_vlan)
13197                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13198         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13199                    RTE_ETHER_ADDR_LEN);
13200         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13201                    RTE_ETHER_ADDR_LEN);
13202 }
13203
13204 cmdline_parse_inst_t cmd_set_vxlan = {
13205         .f = cmd_set_vxlan_parsed,
13206         .data = NULL,
13207         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13208                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13209                 " eth-src <eth-src> eth-dst <eth-dst>",
13210         .tokens = {
13211                 (void *)&cmd_set_vxlan_set,
13212                 (void *)&cmd_set_vxlan_vxlan,
13213                 (void *)&cmd_set_vxlan_ip_version,
13214                 (void *)&cmd_set_vxlan_ip_version_value,
13215                 (void *)&cmd_set_vxlan_vni,
13216                 (void *)&cmd_set_vxlan_vni_value,
13217                 (void *)&cmd_set_vxlan_udp_src,
13218                 (void *)&cmd_set_vxlan_udp_src_value,
13219                 (void *)&cmd_set_vxlan_udp_dst,
13220                 (void *)&cmd_set_vxlan_udp_dst_value,
13221                 (void *)&cmd_set_vxlan_ip_src,
13222                 (void *)&cmd_set_vxlan_ip_src_value,
13223                 (void *)&cmd_set_vxlan_ip_dst,
13224                 (void *)&cmd_set_vxlan_ip_dst_value,
13225                 (void *)&cmd_set_vxlan_eth_src,
13226                 (void *)&cmd_set_vxlan_eth_src_value,
13227                 (void *)&cmd_set_vxlan_eth_dst,
13228                 (void *)&cmd_set_vxlan_eth_dst_value,
13229                 NULL,
13230         },
13231 };
13232
13233 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13234         .f = cmd_set_vxlan_parsed,
13235         .data = NULL,
13236         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13237                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13238                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13239                 " eth-dst <eth-dst>",
13240         .tokens = {
13241                 (void *)&cmd_set_vxlan_set,
13242                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13243                 (void *)&cmd_set_vxlan_ip_version,
13244                 (void *)&cmd_set_vxlan_ip_version_value,
13245                 (void *)&cmd_set_vxlan_vni,
13246                 (void *)&cmd_set_vxlan_vni_value,
13247                 (void *)&cmd_set_vxlan_udp_src,
13248                 (void *)&cmd_set_vxlan_udp_src_value,
13249                 (void *)&cmd_set_vxlan_udp_dst,
13250                 (void *)&cmd_set_vxlan_udp_dst_value,
13251                 (void *)&cmd_set_vxlan_ip_tos,
13252                 (void *)&cmd_set_vxlan_ip_tos_value,
13253                 (void *)&cmd_set_vxlan_ip_ttl,
13254                 (void *)&cmd_set_vxlan_ip_ttl_value,
13255                 (void *)&cmd_set_vxlan_ip_src,
13256                 (void *)&cmd_set_vxlan_ip_src_value,
13257                 (void *)&cmd_set_vxlan_ip_dst,
13258                 (void *)&cmd_set_vxlan_ip_dst_value,
13259                 (void *)&cmd_set_vxlan_eth_src,
13260                 (void *)&cmd_set_vxlan_eth_src_value,
13261                 (void *)&cmd_set_vxlan_eth_dst,
13262                 (void *)&cmd_set_vxlan_eth_dst_value,
13263                 NULL,
13264         },
13265 };
13266
13267 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13268         .f = cmd_set_vxlan_parsed,
13269         .data = NULL,
13270         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13271                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13272                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13273                 " <eth-dst>",
13274         .tokens = {
13275                 (void *)&cmd_set_vxlan_set,
13276                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13277                 (void *)&cmd_set_vxlan_ip_version,
13278                 (void *)&cmd_set_vxlan_ip_version_value,
13279                 (void *)&cmd_set_vxlan_vni,
13280                 (void *)&cmd_set_vxlan_vni_value,
13281                 (void *)&cmd_set_vxlan_udp_src,
13282                 (void *)&cmd_set_vxlan_udp_src_value,
13283                 (void *)&cmd_set_vxlan_udp_dst,
13284                 (void *)&cmd_set_vxlan_udp_dst_value,
13285                 (void *)&cmd_set_vxlan_ip_src,
13286                 (void *)&cmd_set_vxlan_ip_src_value,
13287                 (void *)&cmd_set_vxlan_ip_dst,
13288                 (void *)&cmd_set_vxlan_ip_dst_value,
13289                 (void *)&cmd_set_vxlan_vlan,
13290                 (void *)&cmd_set_vxlan_vlan_value,
13291                 (void *)&cmd_set_vxlan_eth_src,
13292                 (void *)&cmd_set_vxlan_eth_src_value,
13293                 (void *)&cmd_set_vxlan_eth_dst,
13294                 (void *)&cmd_set_vxlan_eth_dst_value,
13295                 NULL,
13296         },
13297 };
13298
13299 /** Set NVGRE encapsulation details */
13300 struct cmd_set_nvgre_result {
13301         cmdline_fixed_string_t set;
13302         cmdline_fixed_string_t nvgre;
13303         cmdline_fixed_string_t pos_token;
13304         cmdline_fixed_string_t ip_version;
13305         uint32_t tni;
13306         cmdline_ipaddr_t ip_src;
13307         cmdline_ipaddr_t ip_dst;
13308         uint16_t tci;
13309         struct rte_ether_addr eth_src;
13310         struct rte_ether_addr eth_dst;
13311 };
13312
13313 cmdline_parse_token_string_t cmd_set_nvgre_set =
13314         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13315 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13316         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13317 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13318         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13319                                  "nvgre-with-vlan");
13320 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13321         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13322                                  "ip-version");
13323 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13324         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13325                                  "ipv4#ipv6");
13326 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13327         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13328                                  "tni");
13329 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13330         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13331 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13332         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13333                                  "ip-src");
13334 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13335         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13336 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13337         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13338                                  "ip-dst");
13339 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13340         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13341 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13342         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13343                                  "vlan-tci");
13344 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13345         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13346 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13347         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13348                                  "eth-src");
13349 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13350         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13351 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13352         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13353                                  "eth-dst");
13354 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13355         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13356
13357 static void cmd_set_nvgre_parsed(void *parsed_result,
13358         __rte_unused struct cmdline *cl,
13359         __rte_unused void *data)
13360 {
13361         struct cmd_set_nvgre_result *res = parsed_result;
13362         union {
13363                 uint32_t nvgre_tni;
13364                 uint8_t tni[4];
13365         } id = {
13366                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13367         };
13368
13369         if (strcmp(res->nvgre, "nvgre") == 0)
13370                 nvgre_encap_conf.select_vlan = 0;
13371         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13372                 nvgre_encap_conf.select_vlan = 1;
13373         if (strcmp(res->ip_version, "ipv4") == 0)
13374                 nvgre_encap_conf.select_ipv4 = 1;
13375         else if (strcmp(res->ip_version, "ipv6") == 0)
13376                 nvgre_encap_conf.select_ipv4 = 0;
13377         else
13378                 return;
13379         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13380         if (nvgre_encap_conf.select_ipv4) {
13381                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13382                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13383         } else {
13384                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13385                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13386         }
13387         if (nvgre_encap_conf.select_vlan)
13388                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13389         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13390                    RTE_ETHER_ADDR_LEN);
13391         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13392                    RTE_ETHER_ADDR_LEN);
13393 }
13394
13395 cmdline_parse_inst_t cmd_set_nvgre = {
13396         .f = cmd_set_nvgre_parsed,
13397         .data = NULL,
13398         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13399                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13400                 " eth-dst <eth-dst>",
13401         .tokens = {
13402                 (void *)&cmd_set_nvgre_set,
13403                 (void *)&cmd_set_nvgre_nvgre,
13404                 (void *)&cmd_set_nvgre_ip_version,
13405                 (void *)&cmd_set_nvgre_ip_version_value,
13406                 (void *)&cmd_set_nvgre_tni,
13407                 (void *)&cmd_set_nvgre_tni_value,
13408                 (void *)&cmd_set_nvgre_ip_src,
13409                 (void *)&cmd_set_nvgre_ip_src_value,
13410                 (void *)&cmd_set_nvgre_ip_dst,
13411                 (void *)&cmd_set_nvgre_ip_dst_value,
13412                 (void *)&cmd_set_nvgre_eth_src,
13413                 (void *)&cmd_set_nvgre_eth_src_value,
13414                 (void *)&cmd_set_nvgre_eth_dst,
13415                 (void *)&cmd_set_nvgre_eth_dst_value,
13416                 NULL,
13417         },
13418 };
13419
13420 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13421         .f = cmd_set_nvgre_parsed,
13422         .data = NULL,
13423         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13424                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13425                 " eth-src <eth-src> eth-dst <eth-dst>",
13426         .tokens = {
13427                 (void *)&cmd_set_nvgre_set,
13428                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13429                 (void *)&cmd_set_nvgre_ip_version,
13430                 (void *)&cmd_set_nvgre_ip_version_value,
13431                 (void *)&cmd_set_nvgre_tni,
13432                 (void *)&cmd_set_nvgre_tni_value,
13433                 (void *)&cmd_set_nvgre_ip_src,
13434                 (void *)&cmd_set_nvgre_ip_src_value,
13435                 (void *)&cmd_set_nvgre_ip_dst,
13436                 (void *)&cmd_set_nvgre_ip_dst_value,
13437                 (void *)&cmd_set_nvgre_vlan,
13438                 (void *)&cmd_set_nvgre_vlan_value,
13439                 (void *)&cmd_set_nvgre_eth_src,
13440                 (void *)&cmd_set_nvgre_eth_src_value,
13441                 (void *)&cmd_set_nvgre_eth_dst,
13442                 (void *)&cmd_set_nvgre_eth_dst_value,
13443                 NULL,
13444         },
13445 };
13446
13447 /** Set L2 encapsulation details */
13448 struct cmd_set_l2_encap_result {
13449         cmdline_fixed_string_t set;
13450         cmdline_fixed_string_t l2_encap;
13451         cmdline_fixed_string_t pos_token;
13452         cmdline_fixed_string_t ip_version;
13453         uint32_t vlan_present:1;
13454         uint16_t tci;
13455         struct rte_ether_addr eth_src;
13456         struct rte_ether_addr eth_dst;
13457 };
13458
13459 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13460         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13461 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13462         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13463 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13464         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13465                                  "l2_encap-with-vlan");
13466 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13467         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13468                                  "ip-version");
13469 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13470         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13471                                  "ipv4#ipv6");
13472 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13473         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13474                                  "vlan-tci");
13475 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13476         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13477 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13478         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13479                                  "eth-src");
13480 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13481         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13482 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13483         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13484                                  "eth-dst");
13485 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13486         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13487
13488 static void cmd_set_l2_encap_parsed(void *parsed_result,
13489         __rte_unused struct cmdline *cl,
13490         __rte_unused void *data)
13491 {
13492         struct cmd_set_l2_encap_result *res = parsed_result;
13493
13494         if (strcmp(res->l2_encap, "l2_encap") == 0)
13495                 l2_encap_conf.select_vlan = 0;
13496         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13497                 l2_encap_conf.select_vlan = 1;
13498         if (strcmp(res->ip_version, "ipv4") == 0)
13499                 l2_encap_conf.select_ipv4 = 1;
13500         else if (strcmp(res->ip_version, "ipv6") == 0)
13501                 l2_encap_conf.select_ipv4 = 0;
13502         else
13503                 return;
13504         if (l2_encap_conf.select_vlan)
13505                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13506         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13507                    RTE_ETHER_ADDR_LEN);
13508         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13509                    RTE_ETHER_ADDR_LEN);
13510 }
13511
13512 cmdline_parse_inst_t cmd_set_l2_encap = {
13513         .f = cmd_set_l2_encap_parsed,
13514         .data = NULL,
13515         .help_str = "set l2_encap ip-version ipv4|ipv6"
13516                 " eth-src <eth-src> eth-dst <eth-dst>",
13517         .tokens = {
13518                 (void *)&cmd_set_l2_encap_set,
13519                 (void *)&cmd_set_l2_encap_l2_encap,
13520                 (void *)&cmd_set_l2_encap_ip_version,
13521                 (void *)&cmd_set_l2_encap_ip_version_value,
13522                 (void *)&cmd_set_l2_encap_eth_src,
13523                 (void *)&cmd_set_l2_encap_eth_src_value,
13524                 (void *)&cmd_set_l2_encap_eth_dst,
13525                 (void *)&cmd_set_l2_encap_eth_dst_value,
13526                 NULL,
13527         },
13528 };
13529
13530 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13531         .f = cmd_set_l2_encap_parsed,
13532         .data = NULL,
13533         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13534                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13535         .tokens = {
13536                 (void *)&cmd_set_l2_encap_set,
13537                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13538                 (void *)&cmd_set_l2_encap_ip_version,
13539                 (void *)&cmd_set_l2_encap_ip_version_value,
13540                 (void *)&cmd_set_l2_encap_vlan,
13541                 (void *)&cmd_set_l2_encap_vlan_value,
13542                 (void *)&cmd_set_l2_encap_eth_src,
13543                 (void *)&cmd_set_l2_encap_eth_src_value,
13544                 (void *)&cmd_set_l2_encap_eth_dst,
13545                 (void *)&cmd_set_l2_encap_eth_dst_value,
13546                 NULL,
13547         },
13548 };
13549
13550 /** Set L2 decapsulation details */
13551 struct cmd_set_l2_decap_result {
13552         cmdline_fixed_string_t set;
13553         cmdline_fixed_string_t l2_decap;
13554         cmdline_fixed_string_t pos_token;
13555         uint32_t vlan_present:1;
13556 };
13557
13558 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13559         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13560 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13561         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13562                                  "l2_decap");
13563 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13564         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13565                                  "l2_decap-with-vlan");
13566
13567 static void cmd_set_l2_decap_parsed(void *parsed_result,
13568         __rte_unused struct cmdline *cl,
13569         __rte_unused void *data)
13570 {
13571         struct cmd_set_l2_decap_result *res = parsed_result;
13572
13573         if (strcmp(res->l2_decap, "l2_decap") == 0)
13574                 l2_decap_conf.select_vlan = 0;
13575         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13576                 l2_decap_conf.select_vlan = 1;
13577 }
13578
13579 cmdline_parse_inst_t cmd_set_l2_decap = {
13580         .f = cmd_set_l2_decap_parsed,
13581         .data = NULL,
13582         .help_str = "set l2_decap",
13583         .tokens = {
13584                 (void *)&cmd_set_l2_decap_set,
13585                 (void *)&cmd_set_l2_decap_l2_decap,
13586                 NULL,
13587         },
13588 };
13589
13590 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13591         .f = cmd_set_l2_decap_parsed,
13592         .data = NULL,
13593         .help_str = "set l2_decap-with-vlan",
13594         .tokens = {
13595                 (void *)&cmd_set_l2_decap_set,
13596                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13597                 NULL,
13598         },
13599 };
13600
13601 /** Set MPLSoGRE encapsulation details */
13602 struct cmd_set_mplsogre_encap_result {
13603         cmdline_fixed_string_t set;
13604         cmdline_fixed_string_t mplsogre;
13605         cmdline_fixed_string_t pos_token;
13606         cmdline_fixed_string_t ip_version;
13607         uint32_t vlan_present:1;
13608         uint32_t label;
13609         cmdline_ipaddr_t ip_src;
13610         cmdline_ipaddr_t ip_dst;
13611         uint16_t tci;
13612         struct rte_ether_addr eth_src;
13613         struct rte_ether_addr eth_dst;
13614 };
13615
13616 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13617         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13618                                  "set");
13619 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13620         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13621                                  "mplsogre_encap");
13622 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13623         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13624                                  mplsogre, "mplsogre_encap-with-vlan");
13625 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13626         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13627                                  pos_token, "ip-version");
13628 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13629         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13630                                  ip_version, "ipv4#ipv6");
13631 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13632         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13633                                  pos_token, "label");
13634 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13635         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13636                               RTE_UINT32);
13637 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13638         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13639                                  pos_token, "ip-src");
13640 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13641         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13642 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13643         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13644                                  pos_token, "ip-dst");
13645 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13646         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13647 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13648         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13649                                  pos_token, "vlan-tci");
13650 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13651         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13652                               RTE_UINT16);
13653 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13654         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13655                                  pos_token, "eth-src");
13656 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13657         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13658                                     eth_src);
13659 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13660         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13661                                  pos_token, "eth-dst");
13662 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13664                                     eth_dst);
13665
13666 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13667         __rte_unused struct cmdline *cl,
13668         __rte_unused void *data)
13669 {
13670         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13671         union {
13672                 uint32_t mplsogre_label;
13673                 uint8_t label[4];
13674         } id = {
13675                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13676         };
13677
13678         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13679                 mplsogre_encap_conf.select_vlan = 0;
13680         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13681                 mplsogre_encap_conf.select_vlan = 1;
13682         if (strcmp(res->ip_version, "ipv4") == 0)
13683                 mplsogre_encap_conf.select_ipv4 = 1;
13684         else if (strcmp(res->ip_version, "ipv6") == 0)
13685                 mplsogre_encap_conf.select_ipv4 = 0;
13686         else
13687                 return;
13688         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13689         if (mplsogre_encap_conf.select_ipv4) {
13690                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13691                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13692         } else {
13693                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13694                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13695         }
13696         if (mplsogre_encap_conf.select_vlan)
13697                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13698         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13699                    RTE_ETHER_ADDR_LEN);
13700         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13701                    RTE_ETHER_ADDR_LEN);
13702 }
13703
13704 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13705         .f = cmd_set_mplsogre_encap_parsed,
13706         .data = NULL,
13707         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13708                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13709                 " eth-dst <eth-dst>",
13710         .tokens = {
13711                 (void *)&cmd_set_mplsogre_encap_set,
13712                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13713                 (void *)&cmd_set_mplsogre_encap_ip_version,
13714                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13715                 (void *)&cmd_set_mplsogre_encap_label,
13716                 (void *)&cmd_set_mplsogre_encap_label_value,
13717                 (void *)&cmd_set_mplsogre_encap_ip_src,
13718                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13719                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13720                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13721                 (void *)&cmd_set_mplsogre_encap_eth_src,
13722                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13723                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13724                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13725                 NULL,
13726         },
13727 };
13728
13729 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13730         .f = cmd_set_mplsogre_encap_parsed,
13731         .data = NULL,
13732         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13733                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13734                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13735         .tokens = {
13736                 (void *)&cmd_set_mplsogre_encap_set,
13737                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13738                 (void *)&cmd_set_mplsogre_encap_ip_version,
13739                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13740                 (void *)&cmd_set_mplsogre_encap_label,
13741                 (void *)&cmd_set_mplsogre_encap_label_value,
13742                 (void *)&cmd_set_mplsogre_encap_ip_src,
13743                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13744                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13745                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13746                 (void *)&cmd_set_mplsogre_encap_vlan,
13747                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13748                 (void *)&cmd_set_mplsogre_encap_eth_src,
13749                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13750                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13751                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13752                 NULL,
13753         },
13754 };
13755
13756 /** Set MPLSoGRE decapsulation details */
13757 struct cmd_set_mplsogre_decap_result {
13758         cmdline_fixed_string_t set;
13759         cmdline_fixed_string_t mplsogre;
13760         cmdline_fixed_string_t pos_token;
13761         cmdline_fixed_string_t ip_version;
13762         uint32_t vlan_present:1;
13763 };
13764
13765 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13766         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13767                                  "set");
13768 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13769         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13770                                  "mplsogre_decap");
13771 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13772         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13773                                  mplsogre, "mplsogre_decap-with-vlan");
13774 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13775         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13776                                  pos_token, "ip-version");
13777 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13778         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13779                                  ip_version, "ipv4#ipv6");
13780
13781 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13782         __rte_unused struct cmdline *cl,
13783         __rte_unused void *data)
13784 {
13785         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13786
13787         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13788                 mplsogre_decap_conf.select_vlan = 0;
13789         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13790                 mplsogre_decap_conf.select_vlan = 1;
13791         if (strcmp(res->ip_version, "ipv4") == 0)
13792                 mplsogre_decap_conf.select_ipv4 = 1;
13793         else if (strcmp(res->ip_version, "ipv6") == 0)
13794                 mplsogre_decap_conf.select_ipv4 = 0;
13795 }
13796
13797 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13798         .f = cmd_set_mplsogre_decap_parsed,
13799         .data = NULL,
13800         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13801         .tokens = {
13802                 (void *)&cmd_set_mplsogre_decap_set,
13803                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13804                 (void *)&cmd_set_mplsogre_decap_ip_version,
13805                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13806                 NULL,
13807         },
13808 };
13809
13810 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13811         .f = cmd_set_mplsogre_decap_parsed,
13812         .data = NULL,
13813         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13814         .tokens = {
13815                 (void *)&cmd_set_mplsogre_decap_set,
13816                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13817                 (void *)&cmd_set_mplsogre_decap_ip_version,
13818                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13819                 NULL,
13820         },
13821 };
13822
13823 /** Set MPLSoUDP encapsulation details */
13824 struct cmd_set_mplsoudp_encap_result {
13825         cmdline_fixed_string_t set;
13826         cmdline_fixed_string_t mplsoudp;
13827         cmdline_fixed_string_t pos_token;
13828         cmdline_fixed_string_t ip_version;
13829         uint32_t vlan_present:1;
13830         uint32_t label;
13831         uint16_t udp_src;
13832         uint16_t udp_dst;
13833         cmdline_ipaddr_t ip_src;
13834         cmdline_ipaddr_t ip_dst;
13835         uint16_t tci;
13836         struct rte_ether_addr eth_src;
13837         struct rte_ether_addr eth_dst;
13838 };
13839
13840 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13841         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13842                                  "set");
13843 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13844         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13845                                  "mplsoudp_encap");
13846 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13847         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13848                                  mplsoudp, "mplsoudp_encap-with-vlan");
13849 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13850         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13851                                  pos_token, "ip-version");
13852 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13853         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13854                                  ip_version, "ipv4#ipv6");
13855 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13856         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13857                                  pos_token, "label");
13858 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13859         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13860                               RTE_UINT32);
13861 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13862         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13863                                  pos_token, "udp-src");
13864 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13865         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13866                               RTE_UINT16);
13867 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13868         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13869                                  pos_token, "udp-dst");
13870 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13871         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13872                               RTE_UINT16);
13873 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13874         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13875                                  pos_token, "ip-src");
13876 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13877         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13878 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13879         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13880                                  pos_token, "ip-dst");
13881 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13882         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13883 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13884         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13885                                  pos_token, "vlan-tci");
13886 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13887         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13888                               RTE_UINT16);
13889 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13890         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13891                                  pos_token, "eth-src");
13892 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13893         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13894                                     eth_src);
13895 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13896         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13897                                  pos_token, "eth-dst");
13898 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13899         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13900                                     eth_dst);
13901
13902 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13903         __rte_unused struct cmdline *cl,
13904         __rte_unused void *data)
13905 {
13906         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13907         union {
13908                 uint32_t mplsoudp_label;
13909                 uint8_t label[4];
13910         } id = {
13911                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13912         };
13913
13914         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13915                 mplsoudp_encap_conf.select_vlan = 0;
13916         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13917                 mplsoudp_encap_conf.select_vlan = 1;
13918         if (strcmp(res->ip_version, "ipv4") == 0)
13919                 mplsoudp_encap_conf.select_ipv4 = 1;
13920         else if (strcmp(res->ip_version, "ipv6") == 0)
13921                 mplsoudp_encap_conf.select_ipv4 = 0;
13922         else
13923                 return;
13924         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13925         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13926         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13927         if (mplsoudp_encap_conf.select_ipv4) {
13928                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13929                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13930         } else {
13931                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13932                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13933         }
13934         if (mplsoudp_encap_conf.select_vlan)
13935                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13936         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13937                    RTE_ETHER_ADDR_LEN);
13938         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13939                    RTE_ETHER_ADDR_LEN);
13940 }
13941
13942 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13943         .f = cmd_set_mplsoudp_encap_parsed,
13944         .data = NULL,
13945         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13946                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13947                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13948         .tokens = {
13949                 (void *)&cmd_set_mplsoudp_encap_set,
13950                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13951                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13952                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13953                 (void *)&cmd_set_mplsoudp_encap_label,
13954                 (void *)&cmd_set_mplsoudp_encap_label_value,
13955                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13956                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13957                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13958                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13959                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13960                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13961                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13962                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13963                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13964                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13965                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13966                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13967                 NULL,
13968         },
13969 };
13970
13971 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13972         .f = cmd_set_mplsoudp_encap_parsed,
13973         .data = NULL,
13974         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13975                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13976                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13977                 " eth-src <eth-src> eth-dst <eth-dst>",
13978         .tokens = {
13979                 (void *)&cmd_set_mplsoudp_encap_set,
13980                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13981                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13982                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13983                 (void *)&cmd_set_mplsoudp_encap_label,
13984                 (void *)&cmd_set_mplsoudp_encap_label_value,
13985                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13986                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13987                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13988                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13989                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13990                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13991                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13992                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13993                 (void *)&cmd_set_mplsoudp_encap_vlan,
13994                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13995                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13996                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13997                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13998                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13999                 NULL,
14000         },
14001 };
14002
14003 /** Set MPLSoUDP decapsulation details */
14004 struct cmd_set_mplsoudp_decap_result {
14005         cmdline_fixed_string_t set;
14006         cmdline_fixed_string_t mplsoudp;
14007         cmdline_fixed_string_t pos_token;
14008         cmdline_fixed_string_t ip_version;
14009         uint32_t vlan_present:1;
14010 };
14011
14012 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
14013         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
14014                                  "set");
14015 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
14016         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
14017                                  "mplsoudp_decap");
14018 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
14019         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14020                                  mplsoudp, "mplsoudp_decap-with-vlan");
14021 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
14022         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14023                                  pos_token, "ip-version");
14024 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
14025         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
14026                                  ip_version, "ipv4#ipv6");
14027
14028 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
14029         __rte_unused struct cmdline *cl,
14030         __rte_unused void *data)
14031 {
14032         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
14033
14034         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
14035                 mplsoudp_decap_conf.select_vlan = 0;
14036         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
14037                 mplsoudp_decap_conf.select_vlan = 1;
14038         if (strcmp(res->ip_version, "ipv4") == 0)
14039                 mplsoudp_decap_conf.select_ipv4 = 1;
14040         else if (strcmp(res->ip_version, "ipv6") == 0)
14041                 mplsoudp_decap_conf.select_ipv4 = 0;
14042 }
14043
14044 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
14045         .f = cmd_set_mplsoudp_decap_parsed,
14046         .data = NULL,
14047         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
14048         .tokens = {
14049                 (void *)&cmd_set_mplsoudp_decap_set,
14050                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
14051                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14052                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14053                 NULL,
14054         },
14055 };
14056
14057 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
14058         .f = cmd_set_mplsoudp_decap_parsed,
14059         .data = NULL,
14060         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
14061         .tokens = {
14062                 (void *)&cmd_set_mplsoudp_decap_set,
14063                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
14064                 (void *)&cmd_set_mplsoudp_decap_ip_version,
14065                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
14066                 NULL,
14067         },
14068 };
14069
14070 /** Set connection tracking object common details */
14071 struct cmd_set_conntrack_common_result {
14072         cmdline_fixed_string_t set;
14073         cmdline_fixed_string_t conntrack;
14074         cmdline_fixed_string_t common;
14075         cmdline_fixed_string_t peer;
14076         cmdline_fixed_string_t is_orig;
14077         cmdline_fixed_string_t enable;
14078         cmdline_fixed_string_t live;
14079         cmdline_fixed_string_t sack;
14080         cmdline_fixed_string_t cack;
14081         cmdline_fixed_string_t last_dir;
14082         cmdline_fixed_string_t liberal;
14083         cmdline_fixed_string_t state;
14084         cmdline_fixed_string_t max_ack_win;
14085         cmdline_fixed_string_t retrans;
14086         cmdline_fixed_string_t last_win;
14087         cmdline_fixed_string_t last_seq;
14088         cmdline_fixed_string_t last_ack;
14089         cmdline_fixed_string_t last_end;
14090         cmdline_fixed_string_t last_index;
14091         uint8_t stat;
14092         uint8_t factor;
14093         uint16_t peer_port;
14094         uint32_t is_original;
14095         uint32_t en;
14096         uint32_t is_live;
14097         uint32_t s_ack;
14098         uint32_t c_ack;
14099         uint32_t ld;
14100         uint32_t lb;
14101         uint8_t re_num;
14102         uint8_t li;
14103         uint16_t lw;
14104         uint32_t ls;
14105         uint32_t la;
14106         uint32_t le;
14107 };
14108
14109 cmdline_parse_token_string_t cmd_set_conntrack_set =
14110         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14111                                  set, "set");
14112 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
14113         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14114                                  conntrack, "conntrack");
14115 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
14116         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14117                                  common, "com");
14118 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
14119         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14120                                  peer, "peer");
14121 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
14122         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14123                               peer_port, RTE_UINT16);
14124 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
14125         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14126                                  is_orig, "is_orig");
14127 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
14128         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14129                               is_original, RTE_UINT32);
14130 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
14131         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14132                                  enable, "enable");
14133 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
14134         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14135                               en, RTE_UINT32);
14136 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14137         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14138                                  live, "live");
14139 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14140         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14141                               is_live, RTE_UINT32);
14142 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14143         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14144                                  sack, "sack");
14145 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14146         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14147                               s_ack, RTE_UINT32);
14148 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14149         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14150                                  cack, "cack");
14151 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14152         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14153                               c_ack, RTE_UINT32);
14154 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14155         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14156                                  last_dir, "last_dir");
14157 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14158         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14159                               ld, RTE_UINT32);
14160 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14161         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14162                                  liberal, "liberal");
14163 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14164         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14165                               lb, RTE_UINT32);
14166 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14167         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14168                                  state, "state");
14169 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14170         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14171                               stat, RTE_UINT8);
14172 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14173         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14174                                  max_ack_win, "max_ack_win");
14175 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14176         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14177                               factor, RTE_UINT8);
14178 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14179         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14180                                  retrans, "r_lim");
14181 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14182         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14183                               re_num, RTE_UINT8);
14184 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14185         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14186                                  last_win, "last_win");
14187 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14188         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14189                               lw, RTE_UINT16);
14190 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14191         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14192                                  last_seq, "last_seq");
14193 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14194         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14195                               ls, RTE_UINT32);
14196 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14197         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14198                                  last_ack, "last_ack");
14199 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14200         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14201                               la, RTE_UINT32);
14202 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14203         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14204                                  last_end, "last_end");
14205 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14206         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14207                               le, RTE_UINT32);
14208 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14209         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14210                                  last_index, "last_index");
14211 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14212         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14213                               li, RTE_UINT8);
14214
14215 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14216         __rte_unused struct cmdline *cl,
14217         __rte_unused void *data)
14218 {
14219         struct cmd_set_conntrack_common_result *res = parsed_result;
14220
14221         /* No need to swap to big endian. */
14222         conntrack_context.peer_port = res->peer_port;
14223         conntrack_context.is_original_dir = res->is_original;
14224         conntrack_context.enable = res->en;
14225         conntrack_context.live_connection = res->is_live;
14226         conntrack_context.selective_ack = res->s_ack;
14227         conntrack_context.challenge_ack_passed = res->c_ack;
14228         conntrack_context.last_direction = res->ld;
14229         conntrack_context.liberal_mode = res->lb;
14230         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14231         conntrack_context.max_ack_window = res->factor;
14232         conntrack_context.retransmission_limit = res->re_num;
14233         conntrack_context.last_window = res->lw;
14234         conntrack_context.last_index =
14235                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14236         conntrack_context.last_seq = res->ls;
14237         conntrack_context.last_ack = res->la;
14238         conntrack_context.last_end = res->le;
14239 }
14240
14241 cmdline_parse_inst_t cmd_set_conntrack_common = {
14242         .f = cmd_set_conntrack_common_parsed,
14243         .data = NULL,
14244         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14245                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14246                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14247                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14248                 " last_index <flag>",
14249         .tokens = {
14250                 (void *)&cmd_set_conntrack_set,
14251                 (void *)&cmd_set_conntrack_conntrack,
14252                 (void *)&cmd_set_conntrack_common_com,
14253                 (void *)&cmd_set_conntrack_common_peer,
14254                 (void *)&cmd_set_conntrack_common_peer_value,
14255                 (void *)&cmd_set_conntrack_common_is_orig,
14256                 (void *)&cmd_set_conntrack_common_is_orig_value,
14257                 (void *)&cmd_set_conntrack_common_enable,
14258                 (void *)&cmd_set_conntrack_common_enable_value,
14259                 (void *)&cmd_set_conntrack_common_live,
14260                 (void *)&cmd_set_conntrack_common_live_value,
14261                 (void *)&cmd_set_conntrack_common_sack,
14262                 (void *)&cmd_set_conntrack_common_sack_value,
14263                 (void *)&cmd_set_conntrack_common_cack,
14264                 (void *)&cmd_set_conntrack_common_cack_value,
14265                 (void *)&cmd_set_conntrack_common_last_dir,
14266                 (void *)&cmd_set_conntrack_common_last_dir_value,
14267                 (void *)&cmd_set_conntrack_common_liberal,
14268                 (void *)&cmd_set_conntrack_common_liberal_value,
14269                 (void *)&cmd_set_conntrack_common_state,
14270                 (void *)&cmd_set_conntrack_common_state_value,
14271                 (void *)&cmd_set_conntrack_common_max_ackwin,
14272                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14273                 (void *)&cmd_set_conntrack_common_retrans,
14274                 (void *)&cmd_set_conntrack_common_retrans_value,
14275                 (void *)&cmd_set_conntrack_common_last_win,
14276                 (void *)&cmd_set_conntrack_common_last_win_value,
14277                 (void *)&cmd_set_conntrack_common_last_seq,
14278                 (void *)&cmd_set_conntrack_common_last_seq_value,
14279                 (void *)&cmd_set_conntrack_common_last_ack,
14280                 (void *)&cmd_set_conntrack_common_last_ack_value,
14281                 (void *)&cmd_set_conntrack_common_last_end,
14282                 (void *)&cmd_set_conntrack_common_last_end_value,
14283                 (void *)&cmd_set_conntrack_common_last_index,
14284                 (void *)&cmd_set_conntrack_common_last_index_value,
14285                 NULL,
14286         },
14287 };
14288
14289 /** Set connection tracking object both directions' details */
14290 struct cmd_set_conntrack_dir_result {
14291         cmdline_fixed_string_t set;
14292         cmdline_fixed_string_t conntrack;
14293         cmdline_fixed_string_t dir;
14294         cmdline_fixed_string_t scale;
14295         cmdline_fixed_string_t fin;
14296         cmdline_fixed_string_t ack_seen;
14297         cmdline_fixed_string_t unack;
14298         cmdline_fixed_string_t sent_end;
14299         cmdline_fixed_string_t reply_end;
14300         cmdline_fixed_string_t max_win;
14301         cmdline_fixed_string_t max_ack;
14302         uint32_t factor;
14303         uint32_t f;
14304         uint32_t as;
14305         uint32_t un;
14306         uint32_t se;
14307         uint32_t re;
14308         uint32_t mw;
14309         uint32_t ma;
14310 };
14311
14312 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14313         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14314                                  set, "set");
14315 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14316         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14317                                  conntrack, "conntrack");
14318 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14319         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14320                                  dir, "orig#rply");
14321 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14322         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14323                                  scale, "scale");
14324 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14325         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14326                               factor, RTE_UINT32);
14327 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14328         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14329                                  fin, "fin");
14330 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14331         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14332                               f, RTE_UINT32);
14333 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14334         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14335                                  ack_seen, "acked");
14336 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14337         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14338                               as, RTE_UINT32);
14339 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14340         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14341                                  unack, "unack_data");
14342 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14343         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14344                               un, RTE_UINT32);
14345 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14346         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14347                                  sent_end, "sent_end");
14348 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14349         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14350                               se, RTE_UINT32);
14351 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14352         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14353                                  reply_end, "reply_end");
14354 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14355         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14356                               re, RTE_UINT32);
14357 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14358         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14359                                  max_win, "max_win");
14360 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14361         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14362                               mw, RTE_UINT32);
14363 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14364         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14365                                  max_ack, "max_ack");
14366 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14367         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14368                               ma, RTE_UINT32);
14369
14370 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14371         __rte_unused struct cmdline *cl,
14372         __rte_unused void *data)
14373 {
14374         struct cmd_set_conntrack_dir_result *res = parsed_result;
14375         struct rte_flow_tcp_dir_param *dir = NULL;
14376
14377         if (strcmp(res->dir, "orig") == 0)
14378                 dir = &conntrack_context.original_dir;
14379         else if (strcmp(res->dir, "rply") == 0)
14380                 dir = &conntrack_context.reply_dir;
14381         else
14382                 return;
14383         dir->scale = res->factor;
14384         dir->close_initiated = res->f;
14385         dir->last_ack_seen = res->as;
14386         dir->data_unacked = res->un;
14387         dir->sent_end = res->se;
14388         dir->reply_end = res->re;
14389         dir->max_ack = res->ma;
14390         dir->max_win = res->mw;
14391 }
14392
14393 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14394         .f = cmd_set_conntrack_dir_parsed,
14395         .data = NULL,
14396         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14397                     " acked <seen> unack_data <unack> sent_end <sent>"
14398                     " reply_end <reply> max_win <win> max_ack <ack>",
14399         .tokens = {
14400                 (void *)&cmd_set_conntrack_set,
14401                 (void *)&cmd_set_conntrack_conntrack,
14402                 (void *)&cmd_set_conntrack_dir_dir,
14403                 (void *)&cmd_set_conntrack_dir_scale,
14404                 (void *)&cmd_set_conntrack_dir_scale_value,
14405                 (void *)&cmd_set_conntrack_dir_fin,
14406                 (void *)&cmd_set_conntrack_dir_fin_value,
14407                 (void *)&cmd_set_conntrack_dir_ack,
14408                 (void *)&cmd_set_conntrack_dir_ack_value,
14409                 (void *)&cmd_set_conntrack_dir_unack_data,
14410                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14411                 (void *)&cmd_set_conntrack_dir_sent_end,
14412                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14413                 (void *)&cmd_set_conntrack_dir_reply_end,
14414                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14415                 (void *)&cmd_set_conntrack_dir_max_win,
14416                 (void *)&cmd_set_conntrack_dir_max_win_value,
14417                 (void *)&cmd_set_conntrack_dir_max_ack,
14418                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14419                 NULL,
14420         },
14421 };
14422
14423 /* Strict link priority scheduling mode setting */
14424 static void
14425 cmd_strict_link_prio_parsed(
14426         void *parsed_result,
14427         __rte_unused struct cmdline *cl,
14428         __rte_unused void *data)
14429 {
14430         struct cmd_vf_tc_bw_result *res = parsed_result;
14431         int ret = -ENOTSUP;
14432
14433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14434                 return;
14435
14436 #ifdef RTE_NET_I40E
14437         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14438 #endif
14439
14440         switch (ret) {
14441         case 0:
14442                 break;
14443         case -EINVAL:
14444                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14445                 break;
14446         case -ENODEV:
14447                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14448                 break;
14449         case -ENOTSUP:
14450                 fprintf(stderr, "function not implemented\n");
14451                 break;
14452         default:
14453                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14454         }
14455 }
14456
14457 cmdline_parse_inst_t cmd_strict_link_prio = {
14458         .f = cmd_strict_link_prio_parsed,
14459         .data = NULL,
14460         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14461         .tokens = {
14462                 (void *)&cmd_vf_tc_bw_set,
14463                 (void *)&cmd_vf_tc_bw_tx,
14464                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14465                 (void *)&cmd_vf_tc_bw_port_id,
14466                 (void *)&cmd_vf_tc_bw_tc_map,
14467                 NULL,
14468         },
14469 };
14470
14471 /* Load dynamic device personalization*/
14472 struct cmd_ddp_add_result {
14473         cmdline_fixed_string_t ddp;
14474         cmdline_fixed_string_t add;
14475         portid_t port_id;
14476         char filepath[];
14477 };
14478
14479 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14480         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14481 cmdline_parse_token_string_t cmd_ddp_add_add =
14482         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14483 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14484         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14485                 RTE_UINT16);
14486 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14487         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14488
14489 static void
14490 cmd_ddp_add_parsed(
14491         void *parsed_result,
14492         __rte_unused struct cmdline *cl,
14493         __rte_unused void *data)
14494 {
14495         struct cmd_ddp_add_result *res = parsed_result;
14496         uint8_t *buff;
14497         uint32_t size;
14498         char *filepath;
14499         char *file_fld[2];
14500         int file_num;
14501         int ret = -ENOTSUP;
14502
14503         if (!all_ports_stopped()) {
14504                 fprintf(stderr, "Please stop all ports first\n");
14505                 return;
14506         }
14507
14508         filepath = strdup(res->filepath);
14509         if (filepath == NULL) {
14510                 fprintf(stderr, "Failed to allocate memory\n");
14511                 return;
14512         }
14513         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14514
14515         buff = open_file(file_fld[0], &size);
14516         if (!buff) {
14517                 free((void *)filepath);
14518                 return;
14519         }
14520
14521 #ifdef RTE_NET_I40E
14522         if (ret == -ENOTSUP)
14523                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14524                                                buff, size,
14525                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14526 #endif
14527
14528         if (ret == -EEXIST)
14529                 fprintf(stderr, "Profile has already existed.\n");
14530         else if (ret < 0)
14531                 fprintf(stderr, "Failed to load profile.\n");
14532         else if (file_num == 2)
14533                 save_file(file_fld[1], buff, size);
14534
14535         close_file(buff);
14536         free((void *)filepath);
14537 }
14538
14539 cmdline_parse_inst_t cmd_ddp_add = {
14540         .f = cmd_ddp_add_parsed,
14541         .data = NULL,
14542         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14543         .tokens = {
14544                 (void *)&cmd_ddp_add_ddp,
14545                 (void *)&cmd_ddp_add_add,
14546                 (void *)&cmd_ddp_add_port_id,
14547                 (void *)&cmd_ddp_add_filepath,
14548                 NULL,
14549         },
14550 };
14551
14552 /* Delete dynamic device personalization*/
14553 struct cmd_ddp_del_result {
14554         cmdline_fixed_string_t ddp;
14555         cmdline_fixed_string_t del;
14556         portid_t port_id;
14557         char filepath[];
14558 };
14559
14560 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14561         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14562 cmdline_parse_token_string_t cmd_ddp_del_del =
14563         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14564 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14565         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14566 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14567         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14568
14569 static void
14570 cmd_ddp_del_parsed(
14571         void *parsed_result,
14572         __rte_unused struct cmdline *cl,
14573         __rte_unused void *data)
14574 {
14575         struct cmd_ddp_del_result *res = parsed_result;
14576         uint8_t *buff;
14577         uint32_t size;
14578         int ret = -ENOTSUP;
14579
14580         if (!all_ports_stopped()) {
14581                 fprintf(stderr, "Please stop all ports first\n");
14582                 return;
14583         }
14584
14585         buff = open_file(res->filepath, &size);
14586         if (!buff)
14587                 return;
14588
14589 #ifdef RTE_NET_I40E
14590         if (ret == -ENOTSUP)
14591                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14592                                                buff, size,
14593                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14594 #endif
14595
14596         if (ret == -EACCES)
14597                 fprintf(stderr, "Profile does not exist.\n");
14598         else if (ret < 0)
14599                 fprintf(stderr, "Failed to delete profile.\n");
14600
14601         close_file(buff);
14602 }
14603
14604 cmdline_parse_inst_t cmd_ddp_del = {
14605         .f = cmd_ddp_del_parsed,
14606         .data = NULL,
14607         .help_str = "ddp del <port_id> <backup_profile_path>",
14608         .tokens = {
14609                 (void *)&cmd_ddp_del_ddp,
14610                 (void *)&cmd_ddp_del_del,
14611                 (void *)&cmd_ddp_del_port_id,
14612                 (void *)&cmd_ddp_del_filepath,
14613                 NULL,
14614         },
14615 };
14616
14617 /* Get dynamic device personalization profile info */
14618 struct cmd_ddp_info_result {
14619         cmdline_fixed_string_t ddp;
14620         cmdline_fixed_string_t get;
14621         cmdline_fixed_string_t info;
14622         char filepath[];
14623 };
14624
14625 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14626         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14627 cmdline_parse_token_string_t cmd_ddp_info_get =
14628         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14629 cmdline_parse_token_string_t cmd_ddp_info_info =
14630         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14631 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14632         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14633
14634 static void
14635 cmd_ddp_info_parsed(
14636         void *parsed_result,
14637         __rte_unused struct cmdline *cl,
14638         __rte_unused void *data)
14639 {
14640         struct cmd_ddp_info_result *res = parsed_result;
14641         uint8_t *pkg;
14642         uint32_t pkg_size;
14643         int ret = -ENOTSUP;
14644 #ifdef RTE_NET_I40E
14645         uint32_t i, j, n;
14646         uint8_t *buff;
14647         uint32_t buff_size = 0;
14648         struct rte_pmd_i40e_profile_info info;
14649         uint32_t dev_num = 0;
14650         struct rte_pmd_i40e_ddp_device_id *devs;
14651         uint32_t proto_num = 0;
14652         struct rte_pmd_i40e_proto_info *proto = NULL;
14653         uint32_t pctype_num = 0;
14654         struct rte_pmd_i40e_ptype_info *pctype;
14655         uint32_t ptype_num = 0;
14656         struct rte_pmd_i40e_ptype_info *ptype;
14657         uint8_t proto_id;
14658
14659 #endif
14660
14661         pkg = open_file(res->filepath, &pkg_size);
14662         if (!pkg)
14663                 return;
14664
14665 #ifdef RTE_NET_I40E
14666         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14667                                 (uint8_t *)&info, sizeof(info),
14668                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14669         if (!ret) {
14670                 printf("Global Track id:       0x%x\n", info.track_id);
14671                 printf("Global Version:        %d.%d.%d.%d\n",
14672                         info.version.major,
14673                         info.version.minor,
14674                         info.version.update,
14675                         info.version.draft);
14676                 printf("Global Package name:   %s\n\n", info.name);
14677         }
14678
14679         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14680                                 (uint8_t *)&info, sizeof(info),
14681                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14682         if (!ret) {
14683                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14684                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14685                         info.version.major,
14686                         info.version.minor,
14687                         info.version.update,
14688                         info.version.draft);
14689                 printf("i40e Profile name:     %s\n\n", info.name);
14690         }
14691
14692         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14693                                 (uint8_t *)&buff_size, sizeof(buff_size),
14694                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14695         if (!ret && buff_size) {
14696                 buff = (uint8_t *)malloc(buff_size);
14697                 if (buff) {
14698                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14699                                                 buff, buff_size,
14700                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14701                         if (!ret)
14702                                 printf("Package Notes:\n%s\n\n", buff);
14703                         free(buff);
14704                 }
14705         }
14706
14707         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14708                                 (uint8_t *)&dev_num, sizeof(dev_num),
14709                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14710         if (!ret && dev_num) {
14711                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14712                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14713                 if (devs) {
14714                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14715                                                 (uint8_t *)devs, buff_size,
14716                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14717                         if (!ret) {
14718                                 printf("List of supported devices:\n");
14719                                 for (i = 0; i < dev_num; i++) {
14720                                         printf("  %04X:%04X %04X:%04X\n",
14721                                                 devs[i].vendor_dev_id >> 16,
14722                                                 devs[i].vendor_dev_id & 0xFFFF,
14723                                                 devs[i].sub_vendor_dev_id >> 16,
14724                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14725                                 }
14726                                 printf("\n");
14727                         }
14728                         free(devs);
14729                 }
14730         }
14731
14732         /* get information about protocols and packet types */
14733         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14734                 (uint8_t *)&proto_num, sizeof(proto_num),
14735                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14736         if (ret || !proto_num)
14737                 goto no_print_return;
14738
14739         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14740         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14741         if (!proto)
14742                 goto no_print_return;
14743
14744         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14745                                         buff_size,
14746                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14747         if (!ret) {
14748                 printf("List of used protocols:\n");
14749                 for (i = 0; i < proto_num; i++)
14750                         printf("  %2u: %s\n", proto[i].proto_id,
14751                                proto[i].name);
14752                 printf("\n");
14753         }
14754         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14755                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14756                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14757         if (ret || !pctype_num)
14758                 goto no_print_pctypes;
14759
14760         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14761         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14762         if (!pctype)
14763                 goto no_print_pctypes;
14764
14765         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14766                                         buff_size,
14767                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14768         if (ret) {
14769                 free(pctype);
14770                 goto no_print_pctypes;
14771         }
14772
14773         printf("List of defined packet classification types:\n");
14774         for (i = 0; i < pctype_num; i++) {
14775                 printf("  %2u:", pctype[i].ptype_id);
14776                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14777                         proto_id = pctype[i].protocols[j];
14778                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14779                                 for (n = 0; n < proto_num; n++) {
14780                                         if (proto[n].proto_id == proto_id) {
14781                                                 printf(" %s", proto[n].name);
14782                                                 break;
14783                                         }
14784                                 }
14785                         }
14786                 }
14787                 printf("\n");
14788         }
14789         printf("\n");
14790         free(pctype);
14791
14792 no_print_pctypes:
14793
14794         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14795                                         sizeof(ptype_num),
14796                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14797         if (ret || !ptype_num)
14798                 goto no_print_return;
14799
14800         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14801         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14802         if (!ptype)
14803                 goto no_print_return;
14804
14805         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14806                                         buff_size,
14807                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14808         if (ret) {
14809                 free(ptype);
14810                 goto no_print_return;
14811         }
14812         printf("List of defined packet types:\n");
14813         for (i = 0; i < ptype_num; i++) {
14814                 printf("  %2u:", ptype[i].ptype_id);
14815                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14816                         proto_id = ptype[i].protocols[j];
14817                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14818                                 for (n = 0; n < proto_num; n++) {
14819                                         if (proto[n].proto_id == proto_id) {
14820                                                 printf(" %s", proto[n].name);
14821                                                 break;
14822                                         }
14823                                 }
14824                         }
14825                 }
14826                 printf("\n");
14827         }
14828         free(ptype);
14829         printf("\n");
14830
14831         ret = 0;
14832 no_print_return:
14833         free(proto);
14834 #endif
14835         if (ret == -ENOTSUP)
14836                 fprintf(stderr, "Function not supported in PMD\n");
14837         close_file(pkg);
14838 }
14839
14840 cmdline_parse_inst_t cmd_ddp_get_info = {
14841         .f = cmd_ddp_info_parsed,
14842         .data = NULL,
14843         .help_str = "ddp get info <profile_path>",
14844         .tokens = {
14845                 (void *)&cmd_ddp_info_ddp,
14846                 (void *)&cmd_ddp_info_get,
14847                 (void *)&cmd_ddp_info_info,
14848                 (void *)&cmd_ddp_info_filepath,
14849                 NULL,
14850         },
14851 };
14852
14853 /* Get dynamic device personalization profile info list*/
14854 #define PROFILE_INFO_SIZE 48
14855 #define MAX_PROFILE_NUM 16
14856
14857 struct cmd_ddp_get_list_result {
14858         cmdline_fixed_string_t ddp;
14859         cmdline_fixed_string_t get;
14860         cmdline_fixed_string_t list;
14861         portid_t port_id;
14862 };
14863
14864 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14865         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14866 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14867         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14868 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14869         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14870 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14871         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14872                 RTE_UINT16);
14873
14874 static void
14875 cmd_ddp_get_list_parsed(
14876         __rte_unused void *parsed_result,
14877         __rte_unused struct cmdline *cl,
14878         __rte_unused void *data)
14879 {
14880 #ifdef RTE_NET_I40E
14881         struct cmd_ddp_get_list_result *res = parsed_result;
14882         struct rte_pmd_i40e_profile_list *p_list;
14883         struct rte_pmd_i40e_profile_info *p_info;
14884         uint32_t p_num;
14885         uint32_t size;
14886         uint32_t i;
14887 #endif
14888         int ret = -ENOTSUP;
14889
14890 #ifdef RTE_NET_I40E
14891         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14892         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14893         if (!p_list) {
14894                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14895                 return;
14896         }
14897
14898         if (ret == -ENOTSUP)
14899                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14900                                                 (uint8_t *)p_list, size);
14901
14902         if (!ret) {
14903                 p_num = p_list->p_count;
14904                 printf("Profile number is: %d\n\n", p_num);
14905
14906                 for (i = 0; i < p_num; i++) {
14907                         p_info = &p_list->p_info[i];
14908                         printf("Profile %d:\n", i);
14909                         printf("Track id:     0x%x\n", p_info->track_id);
14910                         printf("Version:      %d.%d.%d.%d\n",
14911                                p_info->version.major,
14912                                p_info->version.minor,
14913                                p_info->version.update,
14914                                p_info->version.draft);
14915                         printf("Profile name: %s\n\n", p_info->name);
14916                 }
14917         }
14918
14919         free(p_list);
14920 #endif
14921
14922         if (ret < 0)
14923                 fprintf(stderr, "Failed to get ddp list\n");
14924 }
14925
14926 cmdline_parse_inst_t cmd_ddp_get_list = {
14927         .f = cmd_ddp_get_list_parsed,
14928         .data = NULL,
14929         .help_str = "ddp get list <port_id>",
14930         .tokens = {
14931                 (void *)&cmd_ddp_get_list_ddp,
14932                 (void *)&cmd_ddp_get_list_get,
14933                 (void *)&cmd_ddp_get_list_list,
14934                 (void *)&cmd_ddp_get_list_port_id,
14935                 NULL,
14936         },
14937 };
14938
14939 /* Configure input set */
14940 struct cmd_cfg_input_set_result {
14941         cmdline_fixed_string_t port;
14942         cmdline_fixed_string_t cfg;
14943         portid_t port_id;
14944         cmdline_fixed_string_t pctype;
14945         uint8_t pctype_id;
14946         cmdline_fixed_string_t inset_type;
14947         cmdline_fixed_string_t opt;
14948         cmdline_fixed_string_t field;
14949         uint8_t field_idx;
14950 };
14951
14952 static void
14953 cmd_cfg_input_set_parsed(
14954         __rte_unused void *parsed_result,
14955         __rte_unused struct cmdline *cl,
14956         __rte_unused void *data)
14957 {
14958 #ifdef RTE_NET_I40E
14959         struct cmd_cfg_input_set_result *res = parsed_result;
14960         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14961         struct rte_pmd_i40e_inset inset;
14962 #endif
14963         int ret = -ENOTSUP;
14964
14965         if (!all_ports_stopped()) {
14966                 fprintf(stderr, "Please stop all ports first\n");
14967                 return;
14968         }
14969
14970 #ifdef RTE_NET_I40E
14971         if (!strcmp(res->inset_type, "hash_inset"))
14972                 inset_type = INSET_HASH;
14973         else if (!strcmp(res->inset_type, "fdir_inset"))
14974                 inset_type = INSET_FDIR;
14975         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14976                 inset_type = INSET_FDIR_FLX;
14977         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14978                                      &inset, inset_type);
14979         if (ret) {
14980                 fprintf(stderr, "Failed to get input set.\n");
14981                 return;
14982         }
14983
14984         if (!strcmp(res->opt, "get")) {
14985                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14986                                                    res->field_idx);
14987                 if (ret)
14988                         printf("Field index %d is enabled.\n", res->field_idx);
14989                 else
14990                         printf("Field index %d is disabled.\n", res->field_idx);
14991                 return;
14992         } else if (!strcmp(res->opt, "set"))
14993                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14994                                                    res->field_idx);
14995         else if (!strcmp(res->opt, "clear"))
14996                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14997                                                      res->field_idx);
14998         if (ret) {
14999                 fprintf(stderr, "Failed to configure input set field.\n");
15000                 return;
15001         }
15002
15003         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15004                                      &inset, inset_type);
15005         if (ret) {
15006                 fprintf(stderr, "Failed to set input set.\n");
15007                 return;
15008         }
15009 #endif
15010
15011         if (ret == -ENOTSUP)
15012                 fprintf(stderr, "Function not supported\n");
15013 }
15014
15015 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15016         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15017                                  port, "port");
15018 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15019         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15020                                  cfg, "config");
15021 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15022         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15023                               port_id, RTE_UINT16);
15024 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15025         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15026                                  pctype, "pctype");
15027 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15028         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15029                               pctype_id, RTE_UINT8);
15030 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15031         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15032                                  inset_type,
15033                                  "hash_inset#fdir_inset#fdir_flx_inset");
15034 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15035         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15036                                  opt, "get#set#clear");
15037 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15038         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15039                                  field, "field");
15040 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15041         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15042                               field_idx, RTE_UINT8);
15043
15044 cmdline_parse_inst_t cmd_cfg_input_set = {
15045         .f = cmd_cfg_input_set_parsed,
15046         .data = NULL,
15047         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15048                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15049         .tokens = {
15050                 (void *)&cmd_cfg_input_set_port,
15051                 (void *)&cmd_cfg_input_set_cfg,
15052                 (void *)&cmd_cfg_input_set_port_id,
15053                 (void *)&cmd_cfg_input_set_pctype,
15054                 (void *)&cmd_cfg_input_set_pctype_id,
15055                 (void *)&cmd_cfg_input_set_inset_type,
15056                 (void *)&cmd_cfg_input_set_opt,
15057                 (void *)&cmd_cfg_input_set_field,
15058                 (void *)&cmd_cfg_input_set_field_idx,
15059                 NULL,
15060         },
15061 };
15062
15063 /* Clear input set */
15064 struct cmd_clear_input_set_result {
15065         cmdline_fixed_string_t port;
15066         cmdline_fixed_string_t cfg;
15067         portid_t port_id;
15068         cmdline_fixed_string_t pctype;
15069         uint8_t pctype_id;
15070         cmdline_fixed_string_t inset_type;
15071         cmdline_fixed_string_t clear;
15072         cmdline_fixed_string_t all;
15073 };
15074
15075 static void
15076 cmd_clear_input_set_parsed(
15077         __rte_unused void *parsed_result,
15078         __rte_unused struct cmdline *cl,
15079         __rte_unused void *data)
15080 {
15081 #ifdef RTE_NET_I40E
15082         struct cmd_clear_input_set_result *res = parsed_result;
15083         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15084         struct rte_pmd_i40e_inset inset;
15085 #endif
15086         int ret = -ENOTSUP;
15087
15088         if (!all_ports_stopped()) {
15089                 fprintf(stderr, "Please stop all ports first\n");
15090                 return;
15091         }
15092
15093 #ifdef RTE_NET_I40E
15094         if (!strcmp(res->inset_type, "hash_inset"))
15095                 inset_type = INSET_HASH;
15096         else if (!strcmp(res->inset_type, "fdir_inset"))
15097                 inset_type = INSET_FDIR;
15098         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15099                 inset_type = INSET_FDIR_FLX;
15100
15101         memset(&inset, 0, sizeof(inset));
15102
15103         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15104                                      &inset, inset_type);
15105         if (ret) {
15106                 fprintf(stderr, "Failed to clear input set.\n");
15107                 return;
15108         }
15109
15110 #endif
15111
15112         if (ret == -ENOTSUP)
15113                 fprintf(stderr, "Function not supported\n");
15114 }
15115
15116 cmdline_parse_token_string_t cmd_clear_input_set_port =
15117         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15118                                  port, "port");
15119 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15120         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15121                                  cfg, "config");
15122 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15123         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15124                               port_id, RTE_UINT16);
15125 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15126         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15127                                  pctype, "pctype");
15128 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15129         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15130                               pctype_id, RTE_UINT8);
15131 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15132         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15133                                  inset_type,
15134                                  "hash_inset#fdir_inset#fdir_flx_inset");
15135 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15136         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15137                                  clear, "clear");
15138 cmdline_parse_token_string_t cmd_clear_input_set_all =
15139         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15140                                  all, "all");
15141
15142 cmdline_parse_inst_t cmd_clear_input_set = {
15143         .f = cmd_clear_input_set_parsed,
15144         .data = NULL,
15145         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15146                     "fdir_inset|fdir_flx_inset clear all",
15147         .tokens = {
15148                 (void *)&cmd_clear_input_set_port,
15149                 (void *)&cmd_clear_input_set_cfg,
15150                 (void *)&cmd_clear_input_set_port_id,
15151                 (void *)&cmd_clear_input_set_pctype,
15152                 (void *)&cmd_clear_input_set_pctype_id,
15153                 (void *)&cmd_clear_input_set_inset_type,
15154                 (void *)&cmd_clear_input_set_clear,
15155                 (void *)&cmd_clear_input_set_all,
15156                 NULL,
15157         },
15158 };
15159
15160 /* show vf stats */
15161
15162 /* Common result structure for show vf stats */
15163 struct cmd_show_vf_stats_result {
15164         cmdline_fixed_string_t show;
15165         cmdline_fixed_string_t vf;
15166         cmdline_fixed_string_t stats;
15167         portid_t port_id;
15168         uint16_t vf_id;
15169 };
15170
15171 /* Common CLI fields show vf stats*/
15172 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15173         TOKEN_STRING_INITIALIZER
15174                 (struct cmd_show_vf_stats_result,
15175                  show, "show");
15176 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15177         TOKEN_STRING_INITIALIZER
15178                 (struct cmd_show_vf_stats_result,
15179                  vf, "vf");
15180 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15181         TOKEN_STRING_INITIALIZER
15182                 (struct cmd_show_vf_stats_result,
15183                  stats, "stats");
15184 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15185         TOKEN_NUM_INITIALIZER
15186                 (struct cmd_show_vf_stats_result,
15187                  port_id, RTE_UINT16);
15188 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15189         TOKEN_NUM_INITIALIZER
15190                 (struct cmd_show_vf_stats_result,
15191                  vf_id, RTE_UINT16);
15192
15193 static void
15194 cmd_show_vf_stats_parsed(
15195         void *parsed_result,
15196         __rte_unused struct cmdline *cl,
15197         __rte_unused void *data)
15198 {
15199         struct cmd_show_vf_stats_result *res = parsed_result;
15200         struct rte_eth_stats stats;
15201         int ret = -ENOTSUP;
15202         static const char *nic_stats_border = "########################";
15203
15204         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15205                 return;
15206
15207         memset(&stats, 0, sizeof(stats));
15208
15209 #ifdef RTE_NET_I40E
15210         if (ret == -ENOTSUP)
15211                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15212                                                 res->vf_id,
15213                                                 &stats);
15214 #endif
15215 #ifdef RTE_NET_BNXT
15216         if (ret == -ENOTSUP)
15217                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15218                                                 res->vf_id,
15219                                                 &stats);
15220 #endif
15221
15222         switch (ret) {
15223         case 0:
15224                 break;
15225         case -EINVAL:
15226                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15227                 break;
15228         case -ENODEV:
15229                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15230                 break;
15231         case -ENOTSUP:
15232                 fprintf(stderr, "function not implemented\n");
15233                 break;
15234         default:
15235                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15236         }
15237
15238         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15239                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15240
15241         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15242                "%-"PRIu64"\n",
15243                stats.ipackets, stats.imissed, stats.ibytes);
15244         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15245         printf("  RX-nombuf:  %-10"PRIu64"\n",
15246                stats.rx_nombuf);
15247         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15248                "%-"PRIu64"\n",
15249                stats.opackets, stats.oerrors, stats.obytes);
15250
15251         printf("  %s############################%s\n",
15252                                nic_stats_border, nic_stats_border);
15253 }
15254
15255 cmdline_parse_inst_t cmd_show_vf_stats = {
15256         .f = cmd_show_vf_stats_parsed,
15257         .data = NULL,
15258         .help_str = "show vf stats <port_id> <vf_id>",
15259         .tokens = {
15260                 (void *)&cmd_show_vf_stats_show,
15261                 (void *)&cmd_show_vf_stats_vf,
15262                 (void *)&cmd_show_vf_stats_stats,
15263                 (void *)&cmd_show_vf_stats_port_id,
15264                 (void *)&cmd_show_vf_stats_vf_id,
15265                 NULL,
15266         },
15267 };
15268
15269 /* clear vf stats */
15270
15271 /* Common result structure for clear vf stats */
15272 struct cmd_clear_vf_stats_result {
15273         cmdline_fixed_string_t clear;
15274         cmdline_fixed_string_t vf;
15275         cmdline_fixed_string_t stats;
15276         portid_t port_id;
15277         uint16_t vf_id;
15278 };
15279
15280 /* Common CLI fields clear vf stats*/
15281 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15282         TOKEN_STRING_INITIALIZER
15283                 (struct cmd_clear_vf_stats_result,
15284                  clear, "clear");
15285 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15286         TOKEN_STRING_INITIALIZER
15287                 (struct cmd_clear_vf_stats_result,
15288                  vf, "vf");
15289 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15290         TOKEN_STRING_INITIALIZER
15291                 (struct cmd_clear_vf_stats_result,
15292                  stats, "stats");
15293 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15294         TOKEN_NUM_INITIALIZER
15295                 (struct cmd_clear_vf_stats_result,
15296                  port_id, RTE_UINT16);
15297 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15298         TOKEN_NUM_INITIALIZER
15299                 (struct cmd_clear_vf_stats_result,
15300                  vf_id, RTE_UINT16);
15301
15302 static void
15303 cmd_clear_vf_stats_parsed(
15304         void *parsed_result,
15305         __rte_unused struct cmdline *cl,
15306         __rte_unused void *data)
15307 {
15308         struct cmd_clear_vf_stats_result *res = parsed_result;
15309         int ret = -ENOTSUP;
15310
15311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15312                 return;
15313
15314 #ifdef RTE_NET_I40E
15315         if (ret == -ENOTSUP)
15316                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15317                                                   res->vf_id);
15318 #endif
15319 #ifdef RTE_NET_BNXT
15320         if (ret == -ENOTSUP)
15321                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15322                                                   res->vf_id);
15323 #endif
15324
15325         switch (ret) {
15326         case 0:
15327                 break;
15328         case -EINVAL:
15329                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15330                 break;
15331         case -ENODEV:
15332                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15333                 break;
15334         case -ENOTSUP:
15335                 fprintf(stderr, "function not implemented\n");
15336                 break;
15337         default:
15338                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15339         }
15340 }
15341
15342 cmdline_parse_inst_t cmd_clear_vf_stats = {
15343         .f = cmd_clear_vf_stats_parsed,
15344         .data = NULL,
15345         .help_str = "clear vf stats <port_id> <vf_id>",
15346         .tokens = {
15347                 (void *)&cmd_clear_vf_stats_clear,
15348                 (void *)&cmd_clear_vf_stats_vf,
15349                 (void *)&cmd_clear_vf_stats_stats,
15350                 (void *)&cmd_clear_vf_stats_port_id,
15351                 (void *)&cmd_clear_vf_stats_vf_id,
15352                 NULL,
15353         },
15354 };
15355
15356 /* port config pctype mapping reset */
15357
15358 /* Common result structure for port config pctype mapping reset */
15359 struct cmd_pctype_mapping_reset_result {
15360         cmdline_fixed_string_t port;
15361         cmdline_fixed_string_t config;
15362         portid_t port_id;
15363         cmdline_fixed_string_t pctype;
15364         cmdline_fixed_string_t mapping;
15365         cmdline_fixed_string_t reset;
15366 };
15367
15368 /* Common CLI fields for port config pctype mapping reset*/
15369 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15370         TOKEN_STRING_INITIALIZER
15371                 (struct cmd_pctype_mapping_reset_result,
15372                  port, "port");
15373 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15374         TOKEN_STRING_INITIALIZER
15375                 (struct cmd_pctype_mapping_reset_result,
15376                  config, "config");
15377 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15378         TOKEN_NUM_INITIALIZER
15379                 (struct cmd_pctype_mapping_reset_result,
15380                  port_id, RTE_UINT16);
15381 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15382         TOKEN_STRING_INITIALIZER
15383                 (struct cmd_pctype_mapping_reset_result,
15384                  pctype, "pctype");
15385 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15386         TOKEN_STRING_INITIALIZER
15387                 (struct cmd_pctype_mapping_reset_result,
15388                  mapping, "mapping");
15389 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15390         TOKEN_STRING_INITIALIZER
15391                 (struct cmd_pctype_mapping_reset_result,
15392                  reset, "reset");
15393
15394 static void
15395 cmd_pctype_mapping_reset_parsed(
15396         void *parsed_result,
15397         __rte_unused struct cmdline *cl,
15398         __rte_unused void *data)
15399 {
15400         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15401         int ret = -ENOTSUP;
15402
15403         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15404                 return;
15405
15406 #ifdef RTE_NET_I40E
15407         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15408 #endif
15409
15410         switch (ret) {
15411         case 0:
15412                 break;
15413         case -ENODEV:
15414                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15415                 break;
15416         case -ENOTSUP:
15417                 fprintf(stderr, "function not implemented\n");
15418                 break;
15419         default:
15420                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15421         }
15422 }
15423
15424 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15425         .f = cmd_pctype_mapping_reset_parsed,
15426         .data = NULL,
15427         .help_str = "port config <port_id> pctype mapping reset",
15428         .tokens = {
15429                 (void *)&cmd_pctype_mapping_reset_port,
15430                 (void *)&cmd_pctype_mapping_reset_config,
15431                 (void *)&cmd_pctype_mapping_reset_port_id,
15432                 (void *)&cmd_pctype_mapping_reset_pctype,
15433                 (void *)&cmd_pctype_mapping_reset_mapping,
15434                 (void *)&cmd_pctype_mapping_reset_reset,
15435                 NULL,
15436         },
15437 };
15438
15439 /* show port pctype mapping */
15440
15441 /* Common result structure for show port pctype mapping */
15442 struct cmd_pctype_mapping_get_result {
15443         cmdline_fixed_string_t show;
15444         cmdline_fixed_string_t port;
15445         portid_t port_id;
15446         cmdline_fixed_string_t pctype;
15447         cmdline_fixed_string_t mapping;
15448 };
15449
15450 /* Common CLI fields for pctype mapping get */
15451 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15452         TOKEN_STRING_INITIALIZER
15453                 (struct cmd_pctype_mapping_get_result,
15454                  show, "show");
15455 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15456         TOKEN_STRING_INITIALIZER
15457                 (struct cmd_pctype_mapping_get_result,
15458                  port, "port");
15459 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15460         TOKEN_NUM_INITIALIZER
15461                 (struct cmd_pctype_mapping_get_result,
15462                  port_id, RTE_UINT16);
15463 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15464         TOKEN_STRING_INITIALIZER
15465                 (struct cmd_pctype_mapping_get_result,
15466                  pctype, "pctype");
15467 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15468         TOKEN_STRING_INITIALIZER
15469                 (struct cmd_pctype_mapping_get_result,
15470                  mapping, "mapping");
15471
15472 static void
15473 cmd_pctype_mapping_get_parsed(
15474         void *parsed_result,
15475         __rte_unused struct cmdline *cl,
15476         __rte_unused void *data)
15477 {
15478         struct cmd_pctype_mapping_get_result *res = parsed_result;
15479         int ret = -ENOTSUP;
15480 #ifdef RTE_NET_I40E
15481         struct rte_pmd_i40e_flow_type_mapping
15482                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15483         int i, j, first_pctype;
15484 #endif
15485
15486         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15487                 return;
15488
15489 #ifdef RTE_NET_I40E
15490         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15491 #endif
15492
15493         switch (ret) {
15494         case 0:
15495                 break;
15496         case -ENODEV:
15497                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15498                 return;
15499         case -ENOTSUP:
15500                 fprintf(stderr, "function not implemented\n");
15501                 return;
15502         default:
15503                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15504                 return;
15505         }
15506
15507 #ifdef RTE_NET_I40E
15508         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15509                 if (mapping[i].pctype != 0ULL) {
15510                         first_pctype = 1;
15511
15512                         printf("pctype: ");
15513                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15514                                 if (mapping[i].pctype & (1ULL << j)) {
15515                                         printf(first_pctype ?
15516                                                "%02d" : ",%02d", j);
15517                                         first_pctype = 0;
15518                                 }
15519                         }
15520                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15521                 }
15522         }
15523 #endif
15524 }
15525
15526 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15527         .f = cmd_pctype_mapping_get_parsed,
15528         .data = NULL,
15529         .help_str = "show port <port_id> pctype mapping",
15530         .tokens = {
15531                 (void *)&cmd_pctype_mapping_get_show,
15532                 (void *)&cmd_pctype_mapping_get_port,
15533                 (void *)&cmd_pctype_mapping_get_port_id,
15534                 (void *)&cmd_pctype_mapping_get_pctype,
15535                 (void *)&cmd_pctype_mapping_get_mapping,
15536                 NULL,
15537         },
15538 };
15539
15540 /* port config pctype mapping update */
15541
15542 /* Common result structure for port config pctype mapping update */
15543 struct cmd_pctype_mapping_update_result {
15544         cmdline_fixed_string_t port;
15545         cmdline_fixed_string_t config;
15546         portid_t port_id;
15547         cmdline_fixed_string_t pctype;
15548         cmdline_fixed_string_t mapping;
15549         cmdline_fixed_string_t update;
15550         cmdline_fixed_string_t pctype_list;
15551         uint16_t flow_type;
15552 };
15553
15554 /* Common CLI fields for pctype mapping update*/
15555 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15556         TOKEN_STRING_INITIALIZER
15557                 (struct cmd_pctype_mapping_update_result,
15558                  port, "port");
15559 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15560         TOKEN_STRING_INITIALIZER
15561                 (struct cmd_pctype_mapping_update_result,
15562                  config, "config");
15563 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15564         TOKEN_NUM_INITIALIZER
15565                 (struct cmd_pctype_mapping_update_result,
15566                  port_id, RTE_UINT16);
15567 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15568         TOKEN_STRING_INITIALIZER
15569                 (struct cmd_pctype_mapping_update_result,
15570                  pctype, "pctype");
15571 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15572         TOKEN_STRING_INITIALIZER
15573                 (struct cmd_pctype_mapping_update_result,
15574                  mapping, "mapping");
15575 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15576         TOKEN_STRING_INITIALIZER
15577                 (struct cmd_pctype_mapping_update_result,
15578                  update, "update");
15579 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15580         TOKEN_STRING_INITIALIZER
15581                 (struct cmd_pctype_mapping_update_result,
15582                  pctype_list, NULL);
15583 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15584         TOKEN_NUM_INITIALIZER
15585                 (struct cmd_pctype_mapping_update_result,
15586                  flow_type, RTE_UINT16);
15587
15588 static void
15589 cmd_pctype_mapping_update_parsed(
15590         void *parsed_result,
15591         __rte_unused struct cmdline *cl,
15592         __rte_unused void *data)
15593 {
15594         struct cmd_pctype_mapping_update_result *res = parsed_result;
15595         int ret = -ENOTSUP;
15596 #ifdef RTE_NET_I40E
15597         struct rte_pmd_i40e_flow_type_mapping mapping;
15598         unsigned int i;
15599         unsigned int nb_item;
15600         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15601 #endif
15602
15603         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15604                 return;
15605
15606 #ifdef RTE_NET_I40E
15607         nb_item = parse_item_list(res->pctype_list, "pctypes",
15608                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15609         mapping.flow_type = res->flow_type;
15610         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15611                 mapping.pctype |= (1ULL << pctype_list[i]);
15612         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15613                                                 &mapping,
15614                                                 1,
15615                                                 0);
15616 #endif
15617
15618         switch (ret) {
15619         case 0:
15620                 break;
15621         case -EINVAL:
15622                 fprintf(stderr, "invalid pctype or flow type\n");
15623                 break;
15624         case -ENODEV:
15625                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15626                 break;
15627         case -ENOTSUP:
15628                 fprintf(stderr, "function not implemented\n");
15629                 break;
15630         default:
15631                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15632         }
15633 }
15634
15635 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15636         .f = cmd_pctype_mapping_update_parsed,
15637         .data = NULL,
15638         .help_str = "port config <port_id> pctype mapping update"
15639         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15640         .tokens = {
15641                 (void *)&cmd_pctype_mapping_update_port,
15642                 (void *)&cmd_pctype_mapping_update_config,
15643                 (void *)&cmd_pctype_mapping_update_port_id,
15644                 (void *)&cmd_pctype_mapping_update_pctype,
15645                 (void *)&cmd_pctype_mapping_update_mapping,
15646                 (void *)&cmd_pctype_mapping_update_update,
15647                 (void *)&cmd_pctype_mapping_update_pc_type,
15648                 (void *)&cmd_pctype_mapping_update_flow_type,
15649                 NULL,
15650         },
15651 };
15652
15653 /* ptype mapping get */
15654
15655 /* Common result structure for ptype mapping get */
15656 struct cmd_ptype_mapping_get_result {
15657         cmdline_fixed_string_t ptype;
15658         cmdline_fixed_string_t mapping;
15659         cmdline_fixed_string_t get;
15660         portid_t port_id;
15661         uint8_t valid_only;
15662 };
15663
15664 /* Common CLI fields for ptype mapping get */
15665 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15666         TOKEN_STRING_INITIALIZER
15667                 (struct cmd_ptype_mapping_get_result,
15668                  ptype, "ptype");
15669 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15670         TOKEN_STRING_INITIALIZER
15671                 (struct cmd_ptype_mapping_get_result,
15672                  mapping, "mapping");
15673 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15674         TOKEN_STRING_INITIALIZER
15675                 (struct cmd_ptype_mapping_get_result,
15676                  get, "get");
15677 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15678         TOKEN_NUM_INITIALIZER
15679                 (struct cmd_ptype_mapping_get_result,
15680                  port_id, RTE_UINT16);
15681 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15682         TOKEN_NUM_INITIALIZER
15683                 (struct cmd_ptype_mapping_get_result,
15684                  valid_only, RTE_UINT8);
15685
15686 static void
15687 cmd_ptype_mapping_get_parsed(
15688         void *parsed_result,
15689         __rte_unused struct cmdline *cl,
15690         __rte_unused void *data)
15691 {
15692         struct cmd_ptype_mapping_get_result *res = parsed_result;
15693         int ret = -ENOTSUP;
15694 #ifdef RTE_NET_I40E
15695         int max_ptype_num = 256;
15696         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15697         uint16_t count;
15698         int i;
15699 #endif
15700
15701         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15702                 return;
15703
15704 #ifdef RTE_NET_I40E
15705         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15706                                         mapping,
15707                                         max_ptype_num,
15708                                         &count,
15709                                         res->valid_only);
15710 #endif
15711
15712         switch (ret) {
15713         case 0:
15714                 break;
15715         case -ENODEV:
15716                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15717                 break;
15718         case -ENOTSUP:
15719                 fprintf(stderr, "function not implemented\n");
15720                 break;
15721         default:
15722                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15723         }
15724
15725 #ifdef RTE_NET_I40E
15726         if (!ret) {
15727                 for (i = 0; i < count; i++)
15728                         printf("%3d\t0x%08x\n",
15729                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15730         }
15731 #endif
15732 }
15733
15734 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15735         .f = cmd_ptype_mapping_get_parsed,
15736         .data = NULL,
15737         .help_str = "ptype mapping get <port_id> <valid_only>",
15738         .tokens = {
15739                 (void *)&cmd_ptype_mapping_get_ptype,
15740                 (void *)&cmd_ptype_mapping_get_mapping,
15741                 (void *)&cmd_ptype_mapping_get_get,
15742                 (void *)&cmd_ptype_mapping_get_port_id,
15743                 (void *)&cmd_ptype_mapping_get_valid_only,
15744                 NULL,
15745         },
15746 };
15747
15748 /* ptype mapping replace */
15749
15750 /* Common result structure for ptype mapping replace */
15751 struct cmd_ptype_mapping_replace_result {
15752         cmdline_fixed_string_t ptype;
15753         cmdline_fixed_string_t mapping;
15754         cmdline_fixed_string_t replace;
15755         portid_t port_id;
15756         uint32_t target;
15757         uint8_t mask;
15758         uint32_t pkt_type;
15759 };
15760
15761 /* Common CLI fields for ptype mapping replace */
15762 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15763         TOKEN_STRING_INITIALIZER
15764                 (struct cmd_ptype_mapping_replace_result,
15765                  ptype, "ptype");
15766 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15767         TOKEN_STRING_INITIALIZER
15768                 (struct cmd_ptype_mapping_replace_result,
15769                  mapping, "mapping");
15770 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15771         TOKEN_STRING_INITIALIZER
15772                 (struct cmd_ptype_mapping_replace_result,
15773                  replace, "replace");
15774 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15775         TOKEN_NUM_INITIALIZER
15776                 (struct cmd_ptype_mapping_replace_result,
15777                  port_id, RTE_UINT16);
15778 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15779         TOKEN_NUM_INITIALIZER
15780                 (struct cmd_ptype_mapping_replace_result,
15781                  target, RTE_UINT32);
15782 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15783         TOKEN_NUM_INITIALIZER
15784                 (struct cmd_ptype_mapping_replace_result,
15785                  mask, RTE_UINT8);
15786 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15787         TOKEN_NUM_INITIALIZER
15788                 (struct cmd_ptype_mapping_replace_result,
15789                  pkt_type, RTE_UINT32);
15790
15791 static void
15792 cmd_ptype_mapping_replace_parsed(
15793         void *parsed_result,
15794         __rte_unused struct cmdline *cl,
15795         __rte_unused void *data)
15796 {
15797         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15798         int ret = -ENOTSUP;
15799
15800         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15801                 return;
15802
15803 #ifdef RTE_NET_I40E
15804         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15805                                         res->target,
15806                                         res->mask,
15807                                         res->pkt_type);
15808 #endif
15809
15810         switch (ret) {
15811         case 0:
15812                 break;
15813         case -EINVAL:
15814                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15815                         res->target, res->pkt_type);
15816                 break;
15817         case -ENODEV:
15818                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15819                 break;
15820         case -ENOTSUP:
15821                 fprintf(stderr, "function not implemented\n");
15822                 break;
15823         default:
15824                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15825         }
15826 }
15827
15828 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15829         .f = cmd_ptype_mapping_replace_parsed,
15830         .data = NULL,
15831         .help_str =
15832                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15833         .tokens = {
15834                 (void *)&cmd_ptype_mapping_replace_ptype,
15835                 (void *)&cmd_ptype_mapping_replace_mapping,
15836                 (void *)&cmd_ptype_mapping_replace_replace,
15837                 (void *)&cmd_ptype_mapping_replace_port_id,
15838                 (void *)&cmd_ptype_mapping_replace_target,
15839                 (void *)&cmd_ptype_mapping_replace_mask,
15840                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15841                 NULL,
15842         },
15843 };
15844
15845 /* ptype mapping reset */
15846
15847 /* Common result structure for ptype mapping reset */
15848 struct cmd_ptype_mapping_reset_result {
15849         cmdline_fixed_string_t ptype;
15850         cmdline_fixed_string_t mapping;
15851         cmdline_fixed_string_t reset;
15852         portid_t port_id;
15853 };
15854
15855 /* Common CLI fields for ptype mapping reset*/
15856 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15857         TOKEN_STRING_INITIALIZER
15858                 (struct cmd_ptype_mapping_reset_result,
15859                  ptype, "ptype");
15860 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15861         TOKEN_STRING_INITIALIZER
15862                 (struct cmd_ptype_mapping_reset_result,
15863                  mapping, "mapping");
15864 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15865         TOKEN_STRING_INITIALIZER
15866                 (struct cmd_ptype_mapping_reset_result,
15867                  reset, "reset");
15868 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15869         TOKEN_NUM_INITIALIZER
15870                 (struct cmd_ptype_mapping_reset_result,
15871                  port_id, RTE_UINT16);
15872
15873 static void
15874 cmd_ptype_mapping_reset_parsed(
15875         void *parsed_result,
15876         __rte_unused struct cmdline *cl,
15877         __rte_unused void *data)
15878 {
15879         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15880         int ret = -ENOTSUP;
15881
15882         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15883                 return;
15884
15885 #ifdef RTE_NET_I40E
15886         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15887 #endif
15888
15889         switch (ret) {
15890         case 0:
15891                 break;
15892         case -ENODEV:
15893                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15894                 break;
15895         case -ENOTSUP:
15896                 fprintf(stderr, "function not implemented\n");
15897                 break;
15898         default:
15899                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15900         }
15901 }
15902
15903 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15904         .f = cmd_ptype_mapping_reset_parsed,
15905         .data = NULL,
15906         .help_str = "ptype mapping reset <port_id>",
15907         .tokens = {
15908                 (void *)&cmd_ptype_mapping_reset_ptype,
15909                 (void *)&cmd_ptype_mapping_reset_mapping,
15910                 (void *)&cmd_ptype_mapping_reset_reset,
15911                 (void *)&cmd_ptype_mapping_reset_port_id,
15912                 NULL,
15913         },
15914 };
15915
15916 /* ptype mapping update */
15917
15918 /* Common result structure for ptype mapping update */
15919 struct cmd_ptype_mapping_update_result {
15920         cmdline_fixed_string_t ptype;
15921         cmdline_fixed_string_t mapping;
15922         cmdline_fixed_string_t reset;
15923         portid_t port_id;
15924         uint8_t hw_ptype;
15925         uint32_t sw_ptype;
15926 };
15927
15928 /* Common CLI fields for ptype mapping update*/
15929 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15930         TOKEN_STRING_INITIALIZER
15931                 (struct cmd_ptype_mapping_update_result,
15932                  ptype, "ptype");
15933 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15934         TOKEN_STRING_INITIALIZER
15935                 (struct cmd_ptype_mapping_update_result,
15936                  mapping, "mapping");
15937 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15938         TOKEN_STRING_INITIALIZER
15939                 (struct cmd_ptype_mapping_update_result,
15940                  reset, "update");
15941 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15942         TOKEN_NUM_INITIALIZER
15943                 (struct cmd_ptype_mapping_update_result,
15944                  port_id, RTE_UINT16);
15945 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15946         TOKEN_NUM_INITIALIZER
15947                 (struct cmd_ptype_mapping_update_result,
15948                  hw_ptype, RTE_UINT8);
15949 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15950         TOKEN_NUM_INITIALIZER
15951                 (struct cmd_ptype_mapping_update_result,
15952                  sw_ptype, RTE_UINT32);
15953
15954 static void
15955 cmd_ptype_mapping_update_parsed(
15956         void *parsed_result,
15957         __rte_unused struct cmdline *cl,
15958         __rte_unused void *data)
15959 {
15960         struct cmd_ptype_mapping_update_result *res = parsed_result;
15961         int ret = -ENOTSUP;
15962 #ifdef RTE_NET_I40E
15963         struct rte_pmd_i40e_ptype_mapping mapping;
15964 #endif
15965         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15966                 return;
15967
15968 #ifdef RTE_NET_I40E
15969         mapping.hw_ptype = res->hw_ptype;
15970         mapping.sw_ptype = res->sw_ptype;
15971         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15972                                                 &mapping,
15973                                                 1,
15974                                                 0);
15975 #endif
15976
15977         switch (ret) {
15978         case 0:
15979                 break;
15980         case -EINVAL:
15981                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15982                 break;
15983         case -ENODEV:
15984                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15985                 break;
15986         case -ENOTSUP:
15987                 fprintf(stderr, "function not implemented\n");
15988                 break;
15989         default:
15990                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15991         }
15992 }
15993
15994 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15995         .f = cmd_ptype_mapping_update_parsed,
15996         .data = NULL,
15997         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15998         .tokens = {
15999                 (void *)&cmd_ptype_mapping_update_ptype,
16000                 (void *)&cmd_ptype_mapping_update_mapping,
16001                 (void *)&cmd_ptype_mapping_update_update,
16002                 (void *)&cmd_ptype_mapping_update_port_id,
16003                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16004                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16005                 NULL,
16006         },
16007 };
16008
16009 /* Common result structure for file commands */
16010 struct cmd_cmdfile_result {
16011         cmdline_fixed_string_t load;
16012         cmdline_fixed_string_t filename;
16013 };
16014
16015 /* Common CLI fields for file commands */
16016 cmdline_parse_token_string_t cmd_load_cmdfile =
16017         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16018 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16019         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16020
16021 static void
16022 cmd_load_from_file_parsed(
16023         void *parsed_result,
16024         __rte_unused struct cmdline *cl,
16025         __rte_unused void *data)
16026 {
16027         struct cmd_cmdfile_result *res = parsed_result;
16028
16029         cmdline_read_from_file(res->filename);
16030 }
16031
16032 cmdline_parse_inst_t cmd_load_from_file = {
16033         .f = cmd_load_from_file_parsed,
16034         .data = NULL,
16035         .help_str = "load <filename>",
16036         .tokens = {
16037                 (void *)&cmd_load_cmdfile,
16038                 (void *)&cmd_load_cmdfile_filename,
16039                 NULL,
16040         },
16041 };
16042
16043 /* Get Rx offloads capabilities */
16044 struct cmd_rx_offload_get_capa_result {
16045         cmdline_fixed_string_t show;
16046         cmdline_fixed_string_t port;
16047         portid_t port_id;
16048         cmdline_fixed_string_t rx_offload;
16049         cmdline_fixed_string_t capabilities;
16050 };
16051
16052 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16053         TOKEN_STRING_INITIALIZER
16054                 (struct cmd_rx_offload_get_capa_result,
16055                  show, "show");
16056 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16057         TOKEN_STRING_INITIALIZER
16058                 (struct cmd_rx_offload_get_capa_result,
16059                  port, "port");
16060 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16061         TOKEN_NUM_INITIALIZER
16062                 (struct cmd_rx_offload_get_capa_result,
16063                  port_id, RTE_UINT16);
16064 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16065         TOKEN_STRING_INITIALIZER
16066                 (struct cmd_rx_offload_get_capa_result,
16067                  rx_offload, "rx_offload");
16068 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16069         TOKEN_STRING_INITIALIZER
16070                 (struct cmd_rx_offload_get_capa_result,
16071                  capabilities, "capabilities");
16072
16073 static void
16074 print_rx_offloads(uint64_t offloads)
16075 {
16076         uint64_t single_offload;
16077         int begin;
16078         int end;
16079         int bit;
16080
16081         if (offloads == 0)
16082                 return;
16083
16084         begin = __builtin_ctzll(offloads);
16085         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16086
16087         single_offload = 1ULL << begin;
16088         for (bit = begin; bit < end; bit++) {
16089                 if (offloads & single_offload)
16090                         printf(" %s",
16091                                rte_eth_dev_rx_offload_name(single_offload));
16092                 single_offload <<= 1;
16093         }
16094 }
16095
16096 static void
16097 cmd_rx_offload_get_capa_parsed(
16098         void *parsed_result,
16099         __rte_unused struct cmdline *cl,
16100         __rte_unused void *data)
16101 {
16102         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16103         struct rte_eth_dev_info dev_info;
16104         portid_t port_id = res->port_id;
16105         uint64_t queue_offloads;
16106         uint64_t port_offloads;
16107         int ret;
16108
16109         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16110         if (ret != 0)
16111                 return;
16112
16113         queue_offloads = dev_info.rx_queue_offload_capa;
16114         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16115
16116         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16117         printf("  Per Queue :");
16118         print_rx_offloads(queue_offloads);
16119
16120         printf("\n");
16121         printf("  Per Port  :");
16122         print_rx_offloads(port_offloads);
16123         printf("\n\n");
16124 }
16125
16126 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16127         .f = cmd_rx_offload_get_capa_parsed,
16128         .data = NULL,
16129         .help_str = "show port <port_id> rx_offload capabilities",
16130         .tokens = {
16131                 (void *)&cmd_rx_offload_get_capa_show,
16132                 (void *)&cmd_rx_offload_get_capa_port,
16133                 (void *)&cmd_rx_offload_get_capa_port_id,
16134                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16135                 (void *)&cmd_rx_offload_get_capa_capabilities,
16136                 NULL,
16137         }
16138 };
16139
16140 /* Get Rx offloads configuration */
16141 struct cmd_rx_offload_get_configuration_result {
16142         cmdline_fixed_string_t show;
16143         cmdline_fixed_string_t port;
16144         portid_t port_id;
16145         cmdline_fixed_string_t rx_offload;
16146         cmdline_fixed_string_t configuration;
16147 };
16148
16149 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16150         TOKEN_STRING_INITIALIZER
16151                 (struct cmd_rx_offload_get_configuration_result,
16152                  show, "show");
16153 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16154         TOKEN_STRING_INITIALIZER
16155                 (struct cmd_rx_offload_get_configuration_result,
16156                  port, "port");
16157 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16158         TOKEN_NUM_INITIALIZER
16159                 (struct cmd_rx_offload_get_configuration_result,
16160                  port_id, RTE_UINT16);
16161 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16162         TOKEN_STRING_INITIALIZER
16163                 (struct cmd_rx_offload_get_configuration_result,
16164                  rx_offload, "rx_offload");
16165 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16166         TOKEN_STRING_INITIALIZER
16167                 (struct cmd_rx_offload_get_configuration_result,
16168                  configuration, "configuration");
16169
16170 static void
16171 cmd_rx_offload_get_configuration_parsed(
16172         void *parsed_result,
16173         __rte_unused struct cmdline *cl,
16174         __rte_unused void *data)
16175 {
16176         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16177         struct rte_eth_dev_info dev_info;
16178         portid_t port_id = res->port_id;
16179         struct rte_port *port = &ports[port_id];
16180         struct rte_eth_conf dev_conf;
16181         uint64_t port_offloads;
16182         uint64_t queue_offloads;
16183         uint16_t nb_rx_queues;
16184         int q;
16185         int ret;
16186
16187         printf("Rx Offloading Configuration of port %d :\n", port_id);
16188
16189         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16190         if (ret != 0)
16191                 return;
16192
16193         port_offloads = dev_conf.rxmode.offloads;
16194         printf("  Port :");
16195         print_rx_offloads(port_offloads);
16196         printf("\n");
16197
16198         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16199         if (ret != 0)
16200                 return;
16201
16202         nb_rx_queues = dev_info.nb_rx_queues;
16203         for (q = 0; q < nb_rx_queues; q++) {
16204                 queue_offloads = port->rx_conf[q].offloads;
16205                 printf("  Queue[%2d] :", q);
16206                 print_rx_offloads(queue_offloads);
16207                 printf("\n");
16208         }
16209         printf("\n");
16210 }
16211
16212 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16213         .f = cmd_rx_offload_get_configuration_parsed,
16214         .data = NULL,
16215         .help_str = "show port <port_id> rx_offload configuration",
16216         .tokens = {
16217                 (void *)&cmd_rx_offload_get_configuration_show,
16218                 (void *)&cmd_rx_offload_get_configuration_port,
16219                 (void *)&cmd_rx_offload_get_configuration_port_id,
16220                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16221                 (void *)&cmd_rx_offload_get_configuration_configuration,
16222                 NULL,
16223         }
16224 };
16225
16226 /* Enable/Disable a per port offloading */
16227 struct cmd_config_per_port_rx_offload_result {
16228         cmdline_fixed_string_t port;
16229         cmdline_fixed_string_t config;
16230         portid_t port_id;
16231         cmdline_fixed_string_t rx_offload;
16232         cmdline_fixed_string_t offload;
16233         cmdline_fixed_string_t on_off;
16234 };
16235
16236 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16237         TOKEN_STRING_INITIALIZER
16238                 (struct cmd_config_per_port_rx_offload_result,
16239                  port, "port");
16240 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16241         TOKEN_STRING_INITIALIZER
16242                 (struct cmd_config_per_port_rx_offload_result,
16243                  config, "config");
16244 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16245         TOKEN_NUM_INITIALIZER
16246                 (struct cmd_config_per_port_rx_offload_result,
16247                  port_id, RTE_UINT16);
16248 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16249         TOKEN_STRING_INITIALIZER
16250                 (struct cmd_config_per_port_rx_offload_result,
16251                  rx_offload, "rx_offload");
16252 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16253         TOKEN_STRING_INITIALIZER
16254                 (struct cmd_config_per_port_rx_offload_result,
16255                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16256                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16257                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16258                            "scatter#buffer_split#timestamp#security#"
16259                            "keep_crc#rss_hash");
16260 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16261         TOKEN_STRING_INITIALIZER
16262                 (struct cmd_config_per_port_rx_offload_result,
16263                  on_off, "on#off");
16264
16265 static uint64_t
16266 search_rx_offload(const char *name)
16267 {
16268         uint64_t single_offload;
16269         const char *single_name;
16270         int found = 0;
16271         unsigned int bit;
16272
16273         single_offload = 1;
16274         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16275                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16276                 if (!strcasecmp(single_name, name)) {
16277                         found = 1;
16278                         break;
16279                 }
16280                 single_offload <<= 1;
16281         }
16282
16283         if (found)
16284                 return single_offload;
16285
16286         return 0;
16287 }
16288
16289 static void
16290 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16291                                 __rte_unused struct cmdline *cl,
16292                                 __rte_unused void *data)
16293 {
16294         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16295         portid_t port_id = res->port_id;
16296         struct rte_eth_dev_info dev_info;
16297         struct rte_port *port = &ports[port_id];
16298         uint64_t single_offload;
16299         uint16_t nb_rx_queues;
16300         int q;
16301         int ret;
16302
16303         if (port->port_status != RTE_PORT_STOPPED) {
16304                 fprintf(stderr,
16305                         "Error: Can't config offload when Port %d is not stopped\n",
16306                         port_id);
16307                 return;
16308         }
16309
16310         single_offload = search_rx_offload(res->offload);
16311         if (single_offload == 0) {
16312                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16313                 return;
16314         }
16315
16316         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16317         if (ret != 0)
16318                 return;
16319
16320         nb_rx_queues = dev_info.nb_rx_queues;
16321         if (!strcmp(res->on_off, "on")) {
16322                 port->dev_conf.rxmode.offloads |= single_offload;
16323                 for (q = 0; q < nb_rx_queues; q++)
16324                         port->rx_conf[q].offloads |= single_offload;
16325         } else {
16326                 port->dev_conf.rxmode.offloads &= ~single_offload;
16327                 for (q = 0; q < nb_rx_queues; q++)
16328                         port->rx_conf[q].offloads &= ~single_offload;
16329         }
16330
16331         cmd_reconfig_device_queue(port_id, 1, 1);
16332 }
16333
16334 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16335         .f = cmd_config_per_port_rx_offload_parsed,
16336         .data = NULL,
16337         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16338                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16339                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16340                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16341                     "keep_crc|rss_hash on|off",
16342         .tokens = {
16343                 (void *)&cmd_config_per_port_rx_offload_result_port,
16344                 (void *)&cmd_config_per_port_rx_offload_result_config,
16345                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16346                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16347                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16348                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16349                 NULL,
16350         }
16351 };
16352
16353 /* Enable/Disable a per queue offloading */
16354 struct cmd_config_per_queue_rx_offload_result {
16355         cmdline_fixed_string_t port;
16356         portid_t port_id;
16357         cmdline_fixed_string_t rxq;
16358         uint16_t queue_id;
16359         cmdline_fixed_string_t rx_offload;
16360         cmdline_fixed_string_t offload;
16361         cmdline_fixed_string_t on_off;
16362 };
16363
16364 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16365         TOKEN_STRING_INITIALIZER
16366                 (struct cmd_config_per_queue_rx_offload_result,
16367                  port, "port");
16368 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16369         TOKEN_NUM_INITIALIZER
16370                 (struct cmd_config_per_queue_rx_offload_result,
16371                  port_id, RTE_UINT16);
16372 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16373         TOKEN_STRING_INITIALIZER
16374                 (struct cmd_config_per_queue_rx_offload_result,
16375                  rxq, "rxq");
16376 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16377         TOKEN_NUM_INITIALIZER
16378                 (struct cmd_config_per_queue_rx_offload_result,
16379                  queue_id, RTE_UINT16);
16380 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16381         TOKEN_STRING_INITIALIZER
16382                 (struct cmd_config_per_queue_rx_offload_result,
16383                  rx_offload, "rx_offload");
16384 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16385         TOKEN_STRING_INITIALIZER
16386                 (struct cmd_config_per_queue_rx_offload_result,
16387                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16388                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16389                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16390                            "scatter#buffer_split#timestamp#security#keep_crc");
16391 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16392         TOKEN_STRING_INITIALIZER
16393                 (struct cmd_config_per_queue_rx_offload_result,
16394                  on_off, "on#off");
16395
16396 static void
16397 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16398                                 __rte_unused struct cmdline *cl,
16399                                 __rte_unused void *data)
16400 {
16401         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16402         struct rte_eth_dev_info dev_info;
16403         portid_t port_id = res->port_id;
16404         uint16_t queue_id = res->queue_id;
16405         struct rte_port *port = &ports[port_id];
16406         uint64_t single_offload;
16407         int ret;
16408
16409         if (port->port_status != RTE_PORT_STOPPED) {
16410                 fprintf(stderr,
16411                         "Error: Can't config offload when Port %d is not stopped\n",
16412                         port_id);
16413                 return;
16414         }
16415
16416         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16417         if (ret != 0)
16418                 return;
16419
16420         if (queue_id >= dev_info.nb_rx_queues) {
16421                 fprintf(stderr,
16422                         "Error: input queue_id should be 0 ... %d\n",
16423                         dev_info.nb_rx_queues - 1);
16424                 return;
16425         }
16426
16427         single_offload = search_rx_offload(res->offload);
16428         if (single_offload == 0) {
16429                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16430                 return;
16431         }
16432
16433         if (!strcmp(res->on_off, "on"))
16434                 port->rx_conf[queue_id].offloads |= single_offload;
16435         else
16436                 port->rx_conf[queue_id].offloads &= ~single_offload;
16437
16438         cmd_reconfig_device_queue(port_id, 1, 1);
16439 }
16440
16441 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16442         .f = cmd_config_per_queue_rx_offload_parsed,
16443         .data = NULL,
16444         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16445                     "vlan_strip|ipv4_cksum|"
16446                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16447                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16448                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16449                     "keep_crc on|off",
16450         .tokens = {
16451                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16452                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16453                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16454                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16455                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16456                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16457                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16458                 NULL,
16459         }
16460 };
16461
16462 /* Get Tx offloads capabilities */
16463 struct cmd_tx_offload_get_capa_result {
16464         cmdline_fixed_string_t show;
16465         cmdline_fixed_string_t port;
16466         portid_t port_id;
16467         cmdline_fixed_string_t tx_offload;
16468         cmdline_fixed_string_t capabilities;
16469 };
16470
16471 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16472         TOKEN_STRING_INITIALIZER
16473                 (struct cmd_tx_offload_get_capa_result,
16474                  show, "show");
16475 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16476         TOKEN_STRING_INITIALIZER
16477                 (struct cmd_tx_offload_get_capa_result,
16478                  port, "port");
16479 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16480         TOKEN_NUM_INITIALIZER
16481                 (struct cmd_tx_offload_get_capa_result,
16482                  port_id, RTE_UINT16);
16483 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16484         TOKEN_STRING_INITIALIZER
16485                 (struct cmd_tx_offload_get_capa_result,
16486                  tx_offload, "tx_offload");
16487 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16488         TOKEN_STRING_INITIALIZER
16489                 (struct cmd_tx_offload_get_capa_result,
16490                  capabilities, "capabilities");
16491
16492 static void
16493 print_tx_offloads(uint64_t offloads)
16494 {
16495         uint64_t single_offload;
16496         int begin;
16497         int end;
16498         int bit;
16499
16500         if (offloads == 0)
16501                 return;
16502
16503         begin = __builtin_ctzll(offloads);
16504         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16505
16506         single_offload = 1ULL << begin;
16507         for (bit = begin; bit < end; bit++) {
16508                 if (offloads & single_offload)
16509                         printf(" %s",
16510                                rte_eth_dev_tx_offload_name(single_offload));
16511                 single_offload <<= 1;
16512         }
16513 }
16514
16515 static void
16516 cmd_tx_offload_get_capa_parsed(
16517         void *parsed_result,
16518         __rte_unused struct cmdline *cl,
16519         __rte_unused void *data)
16520 {
16521         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16522         struct rte_eth_dev_info dev_info;
16523         portid_t port_id = res->port_id;
16524         uint64_t queue_offloads;
16525         uint64_t port_offloads;
16526         int ret;
16527
16528         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16529         if (ret != 0)
16530                 return;
16531
16532         queue_offloads = dev_info.tx_queue_offload_capa;
16533         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16534
16535         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16536         printf("  Per Queue :");
16537         print_tx_offloads(queue_offloads);
16538
16539         printf("\n");
16540         printf("  Per Port  :");
16541         print_tx_offloads(port_offloads);
16542         printf("\n\n");
16543 }
16544
16545 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16546         .f = cmd_tx_offload_get_capa_parsed,
16547         .data = NULL,
16548         .help_str = "show port <port_id> tx_offload capabilities",
16549         .tokens = {
16550                 (void *)&cmd_tx_offload_get_capa_show,
16551                 (void *)&cmd_tx_offload_get_capa_port,
16552                 (void *)&cmd_tx_offload_get_capa_port_id,
16553                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16554                 (void *)&cmd_tx_offload_get_capa_capabilities,
16555                 NULL,
16556         }
16557 };
16558
16559 /* Get Tx offloads configuration */
16560 struct cmd_tx_offload_get_configuration_result {
16561         cmdline_fixed_string_t show;
16562         cmdline_fixed_string_t port;
16563         portid_t port_id;
16564         cmdline_fixed_string_t tx_offload;
16565         cmdline_fixed_string_t configuration;
16566 };
16567
16568 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16569         TOKEN_STRING_INITIALIZER
16570                 (struct cmd_tx_offload_get_configuration_result,
16571                  show, "show");
16572 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16573         TOKEN_STRING_INITIALIZER
16574                 (struct cmd_tx_offload_get_configuration_result,
16575                  port, "port");
16576 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16577         TOKEN_NUM_INITIALIZER
16578                 (struct cmd_tx_offload_get_configuration_result,
16579                  port_id, RTE_UINT16);
16580 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16581         TOKEN_STRING_INITIALIZER
16582                 (struct cmd_tx_offload_get_configuration_result,
16583                  tx_offload, "tx_offload");
16584 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16585         TOKEN_STRING_INITIALIZER
16586                 (struct cmd_tx_offload_get_configuration_result,
16587                  configuration, "configuration");
16588
16589 static void
16590 cmd_tx_offload_get_configuration_parsed(
16591         void *parsed_result,
16592         __rte_unused struct cmdline *cl,
16593         __rte_unused void *data)
16594 {
16595         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16596         struct rte_eth_dev_info dev_info;
16597         portid_t port_id = res->port_id;
16598         struct rte_port *port = &ports[port_id];
16599         struct rte_eth_conf dev_conf;
16600         uint64_t port_offloads;
16601         uint64_t queue_offloads;
16602         uint16_t nb_tx_queues;
16603         int q;
16604         int ret;
16605
16606         printf("Tx Offloading Configuration of port %d :\n", port_id);
16607
16608         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16609         if (ret != 0)
16610                 return;
16611
16612         port_offloads = dev_conf.txmode.offloads;
16613         printf("  Port :");
16614         print_tx_offloads(port_offloads);
16615         printf("\n");
16616
16617         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16618         if (ret != 0)
16619                 return;
16620
16621         nb_tx_queues = dev_info.nb_tx_queues;
16622         for (q = 0; q < nb_tx_queues; q++) {
16623                 queue_offloads = port->tx_conf[q].offloads;
16624                 printf("  Queue[%2d] :", q);
16625                 print_tx_offloads(queue_offloads);
16626                 printf("\n");
16627         }
16628         printf("\n");
16629 }
16630
16631 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16632         .f = cmd_tx_offload_get_configuration_parsed,
16633         .data = NULL,
16634         .help_str = "show port <port_id> tx_offload configuration",
16635         .tokens = {
16636                 (void *)&cmd_tx_offload_get_configuration_show,
16637                 (void *)&cmd_tx_offload_get_configuration_port,
16638                 (void *)&cmd_tx_offload_get_configuration_port_id,
16639                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16640                 (void *)&cmd_tx_offload_get_configuration_configuration,
16641                 NULL,
16642         }
16643 };
16644
16645 /* Enable/Disable a per port offloading */
16646 struct cmd_config_per_port_tx_offload_result {
16647         cmdline_fixed_string_t port;
16648         cmdline_fixed_string_t config;
16649         portid_t port_id;
16650         cmdline_fixed_string_t tx_offload;
16651         cmdline_fixed_string_t offload;
16652         cmdline_fixed_string_t on_off;
16653 };
16654
16655 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16656         TOKEN_STRING_INITIALIZER
16657                 (struct cmd_config_per_port_tx_offload_result,
16658                  port, "port");
16659 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16660         TOKEN_STRING_INITIALIZER
16661                 (struct cmd_config_per_port_tx_offload_result,
16662                  config, "config");
16663 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16664         TOKEN_NUM_INITIALIZER
16665                 (struct cmd_config_per_port_tx_offload_result,
16666                  port_id, RTE_UINT16);
16667 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16668         TOKEN_STRING_INITIALIZER
16669                 (struct cmd_config_per_port_tx_offload_result,
16670                  tx_offload, "tx_offload");
16671 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16672         TOKEN_STRING_INITIALIZER
16673                 (struct cmd_config_per_port_tx_offload_result,
16674                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16675                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16676                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16677                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16678                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16679                           "send_on_timestamp");
16680 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16681         TOKEN_STRING_INITIALIZER
16682                 (struct cmd_config_per_port_tx_offload_result,
16683                  on_off, "on#off");
16684
16685 static uint64_t
16686 search_tx_offload(const char *name)
16687 {
16688         uint64_t single_offload;
16689         const char *single_name;
16690         int found = 0;
16691         unsigned int bit;
16692
16693         single_offload = 1;
16694         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16695                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16696                 if (single_name == NULL)
16697                         break;
16698                 if (!strcasecmp(single_name, name)) {
16699                         found = 1;
16700                         break;
16701                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16702                         break;
16703                 single_offload <<= 1;
16704         }
16705
16706         if (found)
16707                 return single_offload;
16708
16709         return 0;
16710 }
16711
16712 static void
16713 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16714                                 __rte_unused struct cmdline *cl,
16715                                 __rte_unused void *data)
16716 {
16717         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16718         portid_t port_id = res->port_id;
16719         struct rte_eth_dev_info dev_info;
16720         struct rte_port *port = &ports[port_id];
16721         uint64_t single_offload;
16722         uint16_t nb_tx_queues;
16723         int q;
16724         int ret;
16725
16726         if (port->port_status != RTE_PORT_STOPPED) {
16727                 fprintf(stderr,
16728                         "Error: Can't config offload when Port %d is not stopped\n",
16729                         port_id);
16730                 return;
16731         }
16732
16733         single_offload = search_tx_offload(res->offload);
16734         if (single_offload == 0) {
16735                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16736                 return;
16737         }
16738
16739         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16740         if (ret != 0)
16741                 return;
16742
16743         nb_tx_queues = dev_info.nb_tx_queues;
16744         if (!strcmp(res->on_off, "on")) {
16745                 port->dev_conf.txmode.offloads |= single_offload;
16746                 for (q = 0; q < nb_tx_queues; q++)
16747                         port->tx_conf[q].offloads |= single_offload;
16748         } else {
16749                 port->dev_conf.txmode.offloads &= ~single_offload;
16750                 for (q = 0; q < nb_tx_queues; q++)
16751                         port->tx_conf[q].offloads &= ~single_offload;
16752         }
16753
16754         cmd_reconfig_device_queue(port_id, 1, 1);
16755 }
16756
16757 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16758         .f = cmd_config_per_port_tx_offload_parsed,
16759         .data = NULL,
16760         .help_str = "port config <port_id> tx_offload "
16761                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16762                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16763                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16764                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16765                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16766                     "send_on_timestamp on|off",
16767         .tokens = {
16768                 (void *)&cmd_config_per_port_tx_offload_result_port,
16769                 (void *)&cmd_config_per_port_tx_offload_result_config,
16770                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16771                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16772                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16773                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16774                 NULL,
16775         }
16776 };
16777
16778 /* Enable/Disable a per queue offloading */
16779 struct cmd_config_per_queue_tx_offload_result {
16780         cmdline_fixed_string_t port;
16781         portid_t port_id;
16782         cmdline_fixed_string_t txq;
16783         uint16_t queue_id;
16784         cmdline_fixed_string_t tx_offload;
16785         cmdline_fixed_string_t offload;
16786         cmdline_fixed_string_t on_off;
16787 };
16788
16789 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16790         TOKEN_STRING_INITIALIZER
16791                 (struct cmd_config_per_queue_tx_offload_result,
16792                  port, "port");
16793 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16794         TOKEN_NUM_INITIALIZER
16795                 (struct cmd_config_per_queue_tx_offload_result,
16796                  port_id, RTE_UINT16);
16797 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16798         TOKEN_STRING_INITIALIZER
16799                 (struct cmd_config_per_queue_tx_offload_result,
16800                  txq, "txq");
16801 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16802         TOKEN_NUM_INITIALIZER
16803                 (struct cmd_config_per_queue_tx_offload_result,
16804                  queue_id, RTE_UINT16);
16805 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16806         TOKEN_STRING_INITIALIZER
16807                 (struct cmd_config_per_queue_tx_offload_result,
16808                  tx_offload, "tx_offload");
16809 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16810         TOKEN_STRING_INITIALIZER
16811                 (struct cmd_config_per_queue_tx_offload_result,
16812                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16813                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16814                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16815                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16816                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16817 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16818         TOKEN_STRING_INITIALIZER
16819                 (struct cmd_config_per_queue_tx_offload_result,
16820                  on_off, "on#off");
16821
16822 static void
16823 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16824                                 __rte_unused struct cmdline *cl,
16825                                 __rte_unused void *data)
16826 {
16827         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16828         struct rte_eth_dev_info dev_info;
16829         portid_t port_id = res->port_id;
16830         uint16_t queue_id = res->queue_id;
16831         struct rte_port *port = &ports[port_id];
16832         uint64_t single_offload;
16833         int ret;
16834
16835         if (port->port_status != RTE_PORT_STOPPED) {
16836                 fprintf(stderr,
16837                         "Error: Can't config offload when Port %d is not stopped\n",
16838                         port_id);
16839                 return;
16840         }
16841
16842         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16843         if (ret != 0)
16844                 return;
16845
16846         if (queue_id >= dev_info.nb_tx_queues) {
16847                 fprintf(stderr,
16848                         "Error: input queue_id should be 0 ... %d\n",
16849                         dev_info.nb_tx_queues - 1);
16850                 return;
16851         }
16852
16853         single_offload = search_tx_offload(res->offload);
16854         if (single_offload == 0) {
16855                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16856                 return;
16857         }
16858
16859         if (!strcmp(res->on_off, "on"))
16860                 port->tx_conf[queue_id].offloads |= single_offload;
16861         else
16862                 port->tx_conf[queue_id].offloads &= ~single_offload;
16863
16864         cmd_reconfig_device_queue(port_id, 1, 1);
16865 }
16866
16867 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16868         .f = cmd_config_per_queue_tx_offload_parsed,
16869         .data = NULL,
16870         .help_str = "port <port_id> txq <queue_id> tx_offload "
16871                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16872                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16873                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16874                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16875                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16876                     "on|off",
16877         .tokens = {
16878                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16879                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16880                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16881                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16882                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16883                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16884                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16885                 NULL,
16886         }
16887 };
16888
16889 /* *** configure tx_metadata for specific port *** */
16890 struct cmd_config_tx_metadata_specific_result {
16891         cmdline_fixed_string_t port;
16892         cmdline_fixed_string_t keyword;
16893         uint16_t port_id;
16894         cmdline_fixed_string_t item;
16895         uint32_t value;
16896 };
16897
16898 static void
16899 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16900                                 __rte_unused struct cmdline *cl,
16901                                 __rte_unused void *data)
16902 {
16903         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16904
16905         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16906                 return;
16907         ports[res->port_id].tx_metadata = res->value;
16908         /* Add/remove callback to insert valid metadata in every Tx packet. */
16909         if (ports[res->port_id].tx_metadata)
16910                 add_tx_md_callback(res->port_id);
16911         else
16912                 remove_tx_md_callback(res->port_id);
16913         rte_flow_dynf_metadata_register();
16914 }
16915
16916 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16917         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16918                         port, "port");
16919 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16920         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16921                         keyword, "config");
16922 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16923         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16924                         port_id, RTE_UINT16);
16925 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16926         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16927                         item, "tx_metadata");
16928 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16929         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16930                         value, RTE_UINT32);
16931
16932 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16933         .f = cmd_config_tx_metadata_specific_parsed,
16934         .data = NULL,
16935         .help_str = "port config <port_id> tx_metadata <value>",
16936         .tokens = {
16937                 (void *)&cmd_config_tx_metadata_specific_port,
16938                 (void *)&cmd_config_tx_metadata_specific_keyword,
16939                 (void *)&cmd_config_tx_metadata_specific_id,
16940                 (void *)&cmd_config_tx_metadata_specific_item,
16941                 (void *)&cmd_config_tx_metadata_specific_value,
16942                 NULL,
16943         },
16944 };
16945
16946 /* *** set dynf *** */
16947 struct cmd_config_tx_dynf_specific_result {
16948         cmdline_fixed_string_t port;
16949         cmdline_fixed_string_t keyword;
16950         uint16_t port_id;
16951         cmdline_fixed_string_t item;
16952         cmdline_fixed_string_t name;
16953         cmdline_fixed_string_t value;
16954 };
16955
16956 static void
16957 cmd_config_dynf_specific_parsed(void *parsed_result,
16958                                 __rte_unused struct cmdline *cl,
16959                                 __rte_unused void *data)
16960 {
16961         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16962         struct rte_mbuf_dynflag desc_flag;
16963         int flag;
16964         uint64_t old_port_flags;
16965
16966         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16967                 return;
16968         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16969         if (flag <= 0) {
16970                 if (strlcpy(desc_flag.name, res->name,
16971                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16972                         fprintf(stderr, "Flag name too long\n");
16973                         return;
16974                 }
16975                 desc_flag.flags = 0;
16976                 flag = rte_mbuf_dynflag_register(&desc_flag);
16977                 if (flag < 0) {
16978                         fprintf(stderr, "Can't register flag\n");
16979                         return;
16980                 }
16981                 strcpy(dynf_names[flag], desc_flag.name);
16982         }
16983         old_port_flags = ports[res->port_id].mbuf_dynf;
16984         if (!strcmp(res->value, "set")) {
16985                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16986                 if (old_port_flags == 0)
16987                         add_tx_dynf_callback(res->port_id);
16988         } else {
16989                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16990                 if (ports[res->port_id].mbuf_dynf == 0)
16991                         remove_tx_dynf_callback(res->port_id);
16992         }
16993 }
16994
16995 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16996         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16997                         keyword, "port");
16998 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16999         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17000                         keyword, "config");
17001 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17002         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17003                         port_id, RTE_UINT16);
17004 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17005         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17006                         item, "dynf");
17007 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17008         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17009                         name, NULL);
17010 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17011         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17012                         value, "set#clear");
17013
17014 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17015         .f = cmd_config_dynf_specific_parsed,
17016         .data = NULL,
17017         .help_str = "port config <port id> dynf <name> set|clear",
17018         .tokens = {
17019                 (void *)&cmd_config_tx_dynf_specific_port,
17020                 (void *)&cmd_config_tx_dynf_specific_keyword,
17021                 (void *)&cmd_config_tx_dynf_specific_port_id,
17022                 (void *)&cmd_config_tx_dynf_specific_item,
17023                 (void *)&cmd_config_tx_dynf_specific_name,
17024                 (void *)&cmd_config_tx_dynf_specific_value,
17025                 NULL,
17026         },
17027 };
17028
17029 /* *** display tx_metadata per port configuration *** */
17030 struct cmd_show_tx_metadata_result {
17031         cmdline_fixed_string_t cmd_show;
17032         cmdline_fixed_string_t cmd_port;
17033         cmdline_fixed_string_t cmd_keyword;
17034         portid_t cmd_pid;
17035 };
17036
17037 static void
17038 cmd_show_tx_metadata_parsed(void *parsed_result,
17039                 __rte_unused struct cmdline *cl,
17040                 __rte_unused void *data)
17041 {
17042         struct cmd_show_tx_metadata_result *res = parsed_result;
17043
17044         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17045                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17046                 return;
17047         }
17048         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17049                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17050                        ports[res->cmd_pid].tx_metadata);
17051         }
17052 }
17053
17054 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17055         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17056                         cmd_show, "show");
17057 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17058         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17059                         cmd_port, "port");
17060 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17061         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17062                         cmd_pid, RTE_UINT16);
17063 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17064         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17065                         cmd_keyword, "tx_metadata");
17066
17067 cmdline_parse_inst_t cmd_show_tx_metadata = {
17068         .f = cmd_show_tx_metadata_parsed,
17069         .data = NULL,
17070         .help_str = "show port <port_id> tx_metadata",
17071         .tokens = {
17072                 (void *)&cmd_show_tx_metadata_show,
17073                 (void *)&cmd_show_tx_metadata_port,
17074                 (void *)&cmd_show_tx_metadata_pid,
17075                 (void *)&cmd_show_tx_metadata_keyword,
17076                 NULL,
17077         },
17078 };
17079
17080 /* *** show fec capability per port configuration *** */
17081 struct cmd_show_fec_capability_result {
17082         cmdline_fixed_string_t cmd_show;
17083         cmdline_fixed_string_t cmd_port;
17084         cmdline_fixed_string_t cmd_fec;
17085         cmdline_fixed_string_t cmd_keyword;
17086         portid_t cmd_pid;
17087 };
17088
17089 static void
17090 cmd_show_fec_capability_parsed(void *parsed_result,
17091                 __rte_unused struct cmdline *cl,
17092                 __rte_unused void *data)
17093 {
17094         struct cmd_show_fec_capability_result *res = parsed_result;
17095         struct rte_eth_fec_capa *speed_fec_capa;
17096         unsigned int num;
17097         int ret;
17098
17099         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17100                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17101                 return;
17102         }
17103
17104         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
17105         if (ret == -ENOTSUP) {
17106                 fprintf(stderr, "Function not implemented\n");
17107                 return;
17108         } else if (ret < 0) {
17109                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
17110                 return;
17111         }
17112
17113         num = (unsigned int)ret;
17114         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
17115         if (speed_fec_capa == NULL) {
17116                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
17117                 return;
17118         }
17119
17120         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17121         if (ret < 0) {
17122                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
17123                 goto out;
17124         }
17125
17126         show_fec_capability(num, speed_fec_capa);
17127 out:
17128         free(speed_fec_capa);
17129 }
17130
17131 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17132         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17133                         cmd_show, "show");
17134 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17135         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17136                         cmd_port, "port");
17137 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17138         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17139                         cmd_pid, RTE_UINT16);
17140 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17141         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17142                         cmd_fec, "fec");
17143 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17144         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17145                         cmd_keyword, "capabilities");
17146
17147 cmdline_parse_inst_t cmd_show_capability = {
17148         .f = cmd_show_fec_capability_parsed,
17149         .data = NULL,
17150         .help_str = "show port <port_id> fec capabilities",
17151         .tokens = {
17152                 (void *)&cmd_show_fec_capability_show,
17153                 (void *)&cmd_show_fec_capability_port,
17154                 (void *)&cmd_show_fec_capability_pid,
17155                 (void *)&cmd_show_fec_capability_fec,
17156                 (void *)&cmd_show_fec_capability_keyword,
17157                 NULL,
17158         },
17159 };
17160
17161 /* *** show fec mode per port configuration *** */
17162 struct cmd_show_fec_metadata_result {
17163         cmdline_fixed_string_t cmd_show;
17164         cmdline_fixed_string_t cmd_port;
17165         cmdline_fixed_string_t cmd_keyword;
17166         portid_t cmd_pid;
17167 };
17168
17169 static void
17170 cmd_show_fec_mode_parsed(void *parsed_result,
17171                 __rte_unused struct cmdline *cl,
17172                 __rte_unused void *data)
17173 {
17174 #define FEC_NAME_SIZE 16
17175         struct cmd_show_fec_metadata_result *res = parsed_result;
17176         uint32_t mode;
17177         char buf[FEC_NAME_SIZE];
17178         int ret;
17179
17180         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17181                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17182                 return;
17183         }
17184         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17185         if (ret == -ENOTSUP) {
17186                 fprintf(stderr, "Function not implemented\n");
17187                 return;
17188         } else if (ret < 0) {
17189                 fprintf(stderr, "Get FEC mode failed\n");
17190                 return;
17191         }
17192
17193         switch (mode) {
17194         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17195                 strlcpy(buf, "off", sizeof(buf));
17196                 break;
17197         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17198                 strlcpy(buf, "auto", sizeof(buf));
17199                 break;
17200         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17201                 strlcpy(buf, "baser", sizeof(buf));
17202                 break;
17203         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17204                 strlcpy(buf, "rs", sizeof(buf));
17205                 break;
17206         default:
17207                 return;
17208         }
17209
17210         printf("%s\n", buf);
17211 }
17212
17213 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17214         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17215                         cmd_show, "show");
17216 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17217         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17218                         cmd_port, "port");
17219 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17220         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17221                         cmd_pid, RTE_UINT16);
17222 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17223         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17224                         cmd_keyword, "fec_mode");
17225
17226 cmdline_parse_inst_t cmd_show_fec_mode = {
17227         .f = cmd_show_fec_mode_parsed,
17228         .data = NULL,
17229         .help_str = "show port <port_id> fec_mode",
17230         .tokens = {
17231                 (void *)&cmd_show_fec_mode_show,
17232                 (void *)&cmd_show_fec_mode_port,
17233                 (void *)&cmd_show_fec_mode_pid,
17234                 (void *)&cmd_show_fec_mode_keyword,
17235                 NULL,
17236         },
17237 };
17238
17239 /* *** set fec mode per port configuration *** */
17240 struct cmd_set_port_fec_mode {
17241         cmdline_fixed_string_t set;
17242         cmdline_fixed_string_t port;
17243         portid_t port_id;
17244         cmdline_fixed_string_t fec_mode;
17245         cmdline_fixed_string_t fec_value;
17246 };
17247
17248 /* Common CLI fields for set fec mode */
17249 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17250         TOKEN_STRING_INITIALIZER
17251                 (struct cmd_set_port_fec_mode,
17252                  set, "set");
17253 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17254         TOKEN_STRING_INITIALIZER
17255                 (struct cmd_set_port_fec_mode,
17256                  port, "port");
17257 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17258         TOKEN_NUM_INITIALIZER
17259                 (struct cmd_set_port_fec_mode,
17260                  port_id, RTE_UINT16);
17261 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17262         TOKEN_STRING_INITIALIZER
17263                 (struct cmd_set_port_fec_mode,
17264                  fec_mode, "fec_mode");
17265 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17266         TOKEN_STRING_INITIALIZER
17267                 (struct cmd_set_port_fec_mode,
17268                  fec_value, NULL);
17269
17270 static void
17271 cmd_set_port_fec_mode_parsed(
17272         void *parsed_result,
17273         __rte_unused struct cmdline *cl,
17274         __rte_unused void *data)
17275 {
17276         struct cmd_set_port_fec_mode *res = parsed_result;
17277         uint16_t port_id = res->port_id;
17278         uint32_t fec_capa;
17279         int ret;
17280
17281         ret = parse_fec_mode(res->fec_value, &fec_capa);
17282         if (ret < 0) {
17283                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17284                                 res->fec_value, port_id);
17285                 return;
17286         }
17287
17288         ret = rte_eth_fec_set(port_id, fec_capa);
17289         if (ret == -ENOTSUP) {
17290                 fprintf(stderr, "Function not implemented\n");
17291                 return;
17292         } else if (ret < 0) {
17293                 fprintf(stderr, "Set FEC mode failed\n");
17294                 return;
17295         }
17296 }
17297
17298 cmdline_parse_inst_t cmd_set_fec_mode = {
17299         .f = cmd_set_port_fec_mode_parsed,
17300         .data = NULL,
17301         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17302         .tokens = {
17303                 (void *)&cmd_set_port_fec_mode_set,
17304                 (void *)&cmd_set_port_fec_mode_port,
17305                 (void *)&cmd_set_port_fec_mode_port_id,
17306                 (void *)&cmd_set_port_fec_mode_str,
17307                 (void *)&cmd_set_port_fec_mode_value,
17308                 NULL,
17309         },
17310 };
17311
17312 /* show port supported ptypes */
17313
17314 /* Common result structure for show port ptypes */
17315 struct cmd_show_port_supported_ptypes_result {
17316         cmdline_fixed_string_t show;
17317         cmdline_fixed_string_t port;
17318         portid_t port_id;
17319         cmdline_fixed_string_t ptypes;
17320 };
17321
17322 /* Common CLI fields for show port ptypes */
17323 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17324         TOKEN_STRING_INITIALIZER
17325                 (struct cmd_show_port_supported_ptypes_result,
17326                  show, "show");
17327 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17328         TOKEN_STRING_INITIALIZER
17329                 (struct cmd_show_port_supported_ptypes_result,
17330                  port, "port");
17331 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17332         TOKEN_NUM_INITIALIZER
17333                 (struct cmd_show_port_supported_ptypes_result,
17334                  port_id, RTE_UINT16);
17335 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17336         TOKEN_STRING_INITIALIZER
17337                 (struct cmd_show_port_supported_ptypes_result,
17338                  ptypes, "ptypes");
17339
17340 static void
17341 cmd_show_port_supported_ptypes_parsed(
17342         void *parsed_result,
17343         __rte_unused struct cmdline *cl,
17344         __rte_unused void *data)
17345 {
17346 #define RSVD_PTYPE_MASK       0xf0000000
17347 #define MAX_PTYPES_PER_LAYER  16
17348 #define LTYPE_NAMESIZE        32
17349 #define PTYPE_NAMESIZE        256
17350         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17351         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17352         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17353         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17354         uint16_t port_id = res->port_id;
17355         int ret, i;
17356
17357         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17358         if (ret < 0)
17359                 return;
17360
17361         while (ptype_mask != RSVD_PTYPE_MASK) {
17362
17363                 switch (ptype_mask) {
17364                 case RTE_PTYPE_L2_MASK:
17365                         strlcpy(ltype, "L2", sizeof(ltype));
17366                         break;
17367                 case RTE_PTYPE_L3_MASK:
17368                         strlcpy(ltype, "L3", sizeof(ltype));
17369                         break;
17370                 case RTE_PTYPE_L4_MASK:
17371                         strlcpy(ltype, "L4", sizeof(ltype));
17372                         break;
17373                 case RTE_PTYPE_TUNNEL_MASK:
17374                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17375                         break;
17376                 case RTE_PTYPE_INNER_L2_MASK:
17377                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17378                         break;
17379                 case RTE_PTYPE_INNER_L3_MASK:
17380                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17381                         break;
17382                 case RTE_PTYPE_INNER_L4_MASK:
17383                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17384                         break;
17385                 default:
17386                         return;
17387                 }
17388
17389                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17390                                                        ptype_mask, ptypes,
17391                                                        MAX_PTYPES_PER_LAYER);
17392
17393                 if (ret > 0)
17394                         printf("Supported %s ptypes:\n", ltype);
17395                 else
17396                         printf("%s ptypes unsupported\n", ltype);
17397
17398                 for (i = 0; i < ret; ++i) {
17399                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17400                         printf("%s\n", buf);
17401                 }
17402
17403                 ptype_mask <<= 4;
17404         }
17405 }
17406
17407 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17408         .f = cmd_show_port_supported_ptypes_parsed,
17409         .data = NULL,
17410         .help_str = "show port <port_id> ptypes",
17411         .tokens = {
17412                 (void *)&cmd_show_port_supported_ptypes_show,
17413                 (void *)&cmd_show_port_supported_ptypes_port,
17414                 (void *)&cmd_show_port_supported_ptypes_port_id,
17415                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17416                 NULL,
17417         },
17418 };
17419
17420 /* *** display rx/tx descriptor status *** */
17421 struct cmd_show_rx_tx_desc_status_result {
17422         cmdline_fixed_string_t cmd_show;
17423         cmdline_fixed_string_t cmd_port;
17424         cmdline_fixed_string_t cmd_keyword;
17425         cmdline_fixed_string_t cmd_desc;
17426         cmdline_fixed_string_t cmd_status;
17427         portid_t cmd_pid;
17428         portid_t cmd_qid;
17429         portid_t cmd_did;
17430 };
17431
17432 static void
17433 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17434                 __rte_unused struct cmdline *cl,
17435                 __rte_unused void *data)
17436 {
17437         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17438         int rc;
17439
17440         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17441                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17442                 return;
17443         }
17444
17445         if (!strcmp(res->cmd_keyword, "rxq")) {
17446                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17447                                              res->cmd_did);
17448                 if (rc < 0) {
17449                         fprintf(stderr,
17450                                 "Invalid input: queue id = %d, desc id = %d\n",
17451                                 res->cmd_qid, res->cmd_did);
17452                         return;
17453                 }
17454                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17455                         printf("Desc status = AVAILABLE\n");
17456                 else if (rc == RTE_ETH_RX_DESC_DONE)
17457                         printf("Desc status = DONE\n");
17458                 else
17459                         printf("Desc status = UNAVAILABLE\n");
17460         } else if (!strcmp(res->cmd_keyword, "txq")) {
17461                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17462                                              res->cmd_did);
17463                 if (rc < 0) {
17464                         fprintf(stderr,
17465                                 "Invalid input: queue id = %d, desc id = %d\n",
17466                                 res->cmd_qid, res->cmd_did);
17467                         return;
17468                 }
17469                 if (rc == RTE_ETH_TX_DESC_FULL)
17470                         printf("Desc status = FULL\n");
17471                 else if (rc == RTE_ETH_TX_DESC_DONE)
17472                         printf("Desc status = DONE\n");
17473                 else
17474                         printf("Desc status = UNAVAILABLE\n");
17475         }
17476 }
17477
17478 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17479         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17480                         cmd_show, "show");
17481 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17482         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17483                         cmd_port, "port");
17484 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17485         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17486                         cmd_pid, RTE_UINT16);
17487 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17488         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17489                         cmd_keyword, "rxq#txq");
17490 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17491         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17492                         cmd_qid, RTE_UINT16);
17493 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17494         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17495                         cmd_desc, "desc");
17496 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17497         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17498                         cmd_did, RTE_UINT16);
17499 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17500         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17501                         cmd_status, "status");
17502 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17503         .f = cmd_show_rx_tx_desc_status_parsed,
17504         .data = NULL,
17505         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17506                 "status",
17507         .tokens = {
17508                 (void *)&cmd_show_rx_tx_desc_status_show,
17509                 (void *)&cmd_show_rx_tx_desc_status_port,
17510                 (void *)&cmd_show_rx_tx_desc_status_pid,
17511                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17512                 (void *)&cmd_show_rx_tx_desc_status_qid,
17513                 (void *)&cmd_show_rx_tx_desc_status_desc,
17514                 (void *)&cmd_show_rx_tx_desc_status_did,
17515                 (void *)&cmd_show_rx_tx_desc_status_status,
17516                 NULL,
17517         },
17518 };
17519
17520 /* *** display rx queue desc used count *** */
17521 struct cmd_show_rx_queue_desc_used_count_result {
17522         cmdline_fixed_string_t cmd_show;
17523         cmdline_fixed_string_t cmd_port;
17524         cmdline_fixed_string_t cmd_rxq;
17525         cmdline_fixed_string_t cmd_desc;
17526         cmdline_fixed_string_t cmd_used;
17527         cmdline_fixed_string_t cmd_count;
17528         portid_t cmd_pid;
17529         portid_t cmd_qid;
17530 };
17531
17532 static void
17533 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17534                 __rte_unused struct cmdline *cl,
17535                 __rte_unused void *data)
17536 {
17537         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17538         int rc;
17539
17540         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17541                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17542                 return;
17543         }
17544
17545         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17546         if (rc < 0) {
17547                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17548                 return;
17549         }
17550         printf("Used desc count = %d\n", rc);
17551 }
17552
17553 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17554         TOKEN_STRING_INITIALIZER
17555                 (struct cmd_show_rx_queue_desc_used_count_result,
17556                  cmd_show, "show");
17557 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17558         TOKEN_STRING_INITIALIZER
17559                 (struct cmd_show_rx_queue_desc_used_count_result,
17560                  cmd_port, "port");
17561 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17562         TOKEN_NUM_INITIALIZER
17563                 (struct cmd_show_rx_queue_desc_used_count_result,
17564                  cmd_pid, RTE_UINT16);
17565 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17566         TOKEN_STRING_INITIALIZER
17567                 (struct cmd_show_rx_queue_desc_used_count_result,
17568                  cmd_rxq, "rxq");
17569 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17570         TOKEN_NUM_INITIALIZER
17571                 (struct cmd_show_rx_queue_desc_used_count_result,
17572                  cmd_qid, RTE_UINT16);
17573 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17574         TOKEN_STRING_INITIALIZER
17575                 (struct cmd_show_rx_queue_desc_used_count_result,
17576                  cmd_count, "desc");
17577 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17578         TOKEN_STRING_INITIALIZER
17579                 (struct cmd_show_rx_queue_desc_used_count_result,
17580                  cmd_count, "used");
17581 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17582         TOKEN_STRING_INITIALIZER
17583                 (struct cmd_show_rx_queue_desc_used_count_result,
17584                  cmd_count, "count");
17585 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17586         .f = cmd_show_rx_queue_desc_used_count_parsed,
17587         .data = NULL,
17588         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17589         .tokens = {
17590                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17591                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17592                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17593                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17594                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17595                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17596                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17597                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17598                 NULL,
17599         },
17600 };
17601
17602 /* Common result structure for set port ptypes */
17603 struct cmd_set_port_ptypes_result {
17604         cmdline_fixed_string_t set;
17605         cmdline_fixed_string_t port;
17606         portid_t port_id;
17607         cmdline_fixed_string_t ptype_mask;
17608         uint32_t mask;
17609 };
17610
17611 /* Common CLI fields for set port ptypes */
17612 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17613         TOKEN_STRING_INITIALIZER
17614                 (struct cmd_set_port_ptypes_result,
17615                  set, "set");
17616 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17617         TOKEN_STRING_INITIALIZER
17618                 (struct cmd_set_port_ptypes_result,
17619                  port, "port");
17620 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17621         TOKEN_NUM_INITIALIZER
17622                 (struct cmd_set_port_ptypes_result,
17623                  port_id, RTE_UINT16);
17624 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17625         TOKEN_STRING_INITIALIZER
17626                 (struct cmd_set_port_ptypes_result,
17627                  ptype_mask, "ptype_mask");
17628 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17629         TOKEN_NUM_INITIALIZER
17630                 (struct cmd_set_port_ptypes_result,
17631                  mask, RTE_UINT32);
17632
17633 static void
17634 cmd_set_port_ptypes_parsed(
17635         void *parsed_result,
17636         __rte_unused struct cmdline *cl,
17637         __rte_unused void *data)
17638 {
17639         struct cmd_set_port_ptypes_result *res = parsed_result;
17640 #define PTYPE_NAMESIZE        256
17641         char ptype_name[PTYPE_NAMESIZE];
17642         uint16_t port_id = res->port_id;
17643         uint32_t ptype_mask = res->mask;
17644         int ret, i;
17645
17646         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17647                                                NULL, 0);
17648         if (ret <= 0) {
17649                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17650                         port_id);
17651                 return;
17652         }
17653
17654         uint32_t ptypes[ret];
17655
17656         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17657         if (ret < 0) {
17658                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17659                         port_id);
17660                 return;
17661         }
17662
17663         printf("Successfully set following ptypes for Port %d\n", port_id);
17664         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17665                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17666                 printf("%s\n", ptype_name);
17667         }
17668
17669         clear_ptypes = false;
17670 }
17671
17672 cmdline_parse_inst_t cmd_set_port_ptypes = {
17673         .f = cmd_set_port_ptypes_parsed,
17674         .data = NULL,
17675         .help_str = "set port <port_id> ptype_mask <mask>",
17676         .tokens = {
17677                 (void *)&cmd_set_port_ptypes_set,
17678                 (void *)&cmd_set_port_ptypes_port,
17679                 (void *)&cmd_set_port_ptypes_port_id,
17680                 (void *)&cmd_set_port_ptypes_mask_str,
17681                 (void *)&cmd_set_port_ptypes_mask_u32,
17682                 NULL,
17683         },
17684 };
17685
17686 /* *** display mac addresses added to a port *** */
17687 struct cmd_showport_macs_result {
17688         cmdline_fixed_string_t cmd_show;
17689         cmdline_fixed_string_t cmd_port;
17690         cmdline_fixed_string_t cmd_keyword;
17691         portid_t cmd_pid;
17692 };
17693
17694 static void
17695 cmd_showport_macs_parsed(void *parsed_result,
17696                 __rte_unused struct cmdline *cl,
17697                 __rte_unused void *data)
17698 {
17699         struct cmd_showport_macs_result *res = parsed_result;
17700
17701         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17702                 return;
17703
17704         if (!strcmp(res->cmd_keyword, "macs"))
17705                 show_macs(res->cmd_pid);
17706         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17707                 show_mcast_macs(res->cmd_pid);
17708 }
17709
17710 cmdline_parse_token_string_t cmd_showport_macs_show =
17711         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17712                         cmd_show, "show");
17713 cmdline_parse_token_string_t cmd_showport_macs_port =
17714         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17715                         cmd_port, "port");
17716 cmdline_parse_token_num_t cmd_showport_macs_pid =
17717         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17718                         cmd_pid, RTE_UINT16);
17719 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17720         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17721                         cmd_keyword, "macs#mcast_macs");
17722
17723 cmdline_parse_inst_t cmd_showport_macs = {
17724         .f = cmd_showport_macs_parsed,
17725         .data = NULL,
17726         .help_str = "show port <port_id> macs|mcast_macs",
17727         .tokens = {
17728                 (void *)&cmd_showport_macs_show,
17729                 (void *)&cmd_showport_macs_port,
17730                 (void *)&cmd_showport_macs_pid,
17731                 (void *)&cmd_showport_macs_keyword,
17732                 NULL,
17733         },
17734 };
17735
17736 /* *** show flow transfer proxy port ID for the given port *** */
17737 struct cmd_show_port_flow_transfer_proxy_result {
17738         cmdline_fixed_string_t show;
17739         cmdline_fixed_string_t port;
17740         portid_t port_id;
17741         cmdline_fixed_string_t flow;
17742         cmdline_fixed_string_t transfer;
17743         cmdline_fixed_string_t proxy;
17744 };
17745
17746 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_show =
17747         TOKEN_STRING_INITIALIZER
17748                 (struct cmd_show_port_flow_transfer_proxy_result,
17749                  show, "show");
17750 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_port =
17751         TOKEN_STRING_INITIALIZER
17752                 (struct cmd_show_port_flow_transfer_proxy_result,
17753                  port, "port");
17754 cmdline_parse_token_num_t cmd_show_port_flow_transfer_proxy_port_id =
17755         TOKEN_NUM_INITIALIZER
17756                 (struct cmd_show_port_flow_transfer_proxy_result,
17757                  port_id, RTE_UINT16);
17758 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_flow =
17759         TOKEN_STRING_INITIALIZER
17760                 (struct cmd_show_port_flow_transfer_proxy_result,
17761                  flow, "flow");
17762 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_transfer =
17763         TOKEN_STRING_INITIALIZER
17764                 (struct cmd_show_port_flow_transfer_proxy_result,
17765                  transfer, "transfer");
17766 cmdline_parse_token_string_t cmd_show_port_flow_transfer_proxy_proxy =
17767         TOKEN_STRING_INITIALIZER
17768                 (struct cmd_show_port_flow_transfer_proxy_result,
17769                  proxy, "proxy");
17770
17771 static void
17772 cmd_show_port_flow_transfer_proxy_parsed(void *parsed_result,
17773                                          __rte_unused struct cmdline *cl,
17774                                          __rte_unused void *data)
17775 {
17776         struct cmd_show_port_flow_transfer_proxy_result *res = parsed_result;
17777         portid_t proxy_port_id;
17778         int ret;
17779
17780         printf("\n");
17781
17782         ret = rte_flow_pick_transfer_proxy(res->port_id, &proxy_port_id, NULL);
17783         if (ret != 0) {
17784                 fprintf(stderr, "Failed to pick transfer proxy: %s\n",
17785                         rte_strerror(-ret));
17786                 return;
17787         }
17788
17789         printf("Transfer proxy port ID: %u\n\n", proxy_port_id);
17790 }
17791
17792 cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = {
17793         .f = cmd_show_port_flow_transfer_proxy_parsed,
17794         .data = NULL,
17795         .help_str = "show port <port_id> flow transfer proxy",
17796         .tokens = {
17797                 (void *)&cmd_show_port_flow_transfer_proxy_show,
17798                 (void *)&cmd_show_port_flow_transfer_proxy_port,
17799                 (void *)&cmd_show_port_flow_transfer_proxy_port_id,
17800                 (void *)&cmd_show_port_flow_transfer_proxy_flow,
17801                 (void *)&cmd_show_port_flow_transfer_proxy_transfer,
17802                 (void *)&cmd_show_port_flow_transfer_proxy_proxy,
17803                 NULL,
17804         }
17805 };
17806
17807 /* ******************************************************************************** */
17808
17809 /* list of instructions */
17810 cmdline_parse_ctx_t main_ctx[] = {
17811         (cmdline_parse_inst_t *)&cmd_help_brief,
17812         (cmdline_parse_inst_t *)&cmd_help_long,
17813         (cmdline_parse_inst_t *)&cmd_quit,
17814         (cmdline_parse_inst_t *)&cmd_load_from_file,
17815         (cmdline_parse_inst_t *)&cmd_showport,
17816         (cmdline_parse_inst_t *)&cmd_showqueue,
17817         (cmdline_parse_inst_t *)&cmd_showeeprom,
17818         (cmdline_parse_inst_t *)&cmd_showportall,
17819         (cmdline_parse_inst_t *)&cmd_representor_info,
17820         (cmdline_parse_inst_t *)&cmd_showdevice,
17821         (cmdline_parse_inst_t *)&cmd_showcfg,
17822         (cmdline_parse_inst_t *)&cmd_showfwdall,
17823         (cmdline_parse_inst_t *)&cmd_start,
17824         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17825         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17826         (cmdline_parse_inst_t *)&cmd_set_link_up,
17827         (cmdline_parse_inst_t *)&cmd_set_link_down,
17828         (cmdline_parse_inst_t *)&cmd_reset,
17829         (cmdline_parse_inst_t *)&cmd_set_numbers,
17830         (cmdline_parse_inst_t *)&cmd_set_log,
17831         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17832         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17833         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17834         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17835         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17836         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17837         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17838         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17839         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17840         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17841         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17842         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17843         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17844         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17845         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17846         (cmdline_parse_inst_t *)&cmd_set_link_check,
17847         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17848         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17849         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17850         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17851 #ifdef RTE_NET_BOND
17852         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17853         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17854         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17855         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17856         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17857         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17858         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17859         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17860         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17861         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17862         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17863         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17864 #endif
17865         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17866         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17867         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17868         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17869         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17870         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17871         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17872         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17873         (cmdline_parse_inst_t *)&cmd_csum_set,
17874         (cmdline_parse_inst_t *)&cmd_csum_show,
17875         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17876         (cmdline_parse_inst_t *)&cmd_tso_set,
17877         (cmdline_parse_inst_t *)&cmd_tso_show,
17878         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17879         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17880 #ifdef RTE_LIB_GRO
17881         (cmdline_parse_inst_t *)&cmd_gro_enable,
17882         (cmdline_parse_inst_t *)&cmd_gro_flush,
17883         (cmdline_parse_inst_t *)&cmd_gro_show,
17884 #endif
17885 #ifdef RTE_LIB_GSO
17886         (cmdline_parse_inst_t *)&cmd_gso_enable,
17887         (cmdline_parse_inst_t *)&cmd_gso_size,
17888         (cmdline_parse_inst_t *)&cmd_gso_show,
17889 #endif
17890         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17891         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17892         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17893         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17894         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17895         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17896         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17897         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17898         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17899         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17900         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17901         (cmdline_parse_inst_t *)&cmd_queue_priority_flow_control_set,
17902         (cmdline_parse_inst_t *)&cmd_config_dcb,
17903         (cmdline_parse_inst_t *)&cmd_read_reg,
17904         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17905         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17906         (cmdline_parse_inst_t *)&cmd_write_reg,
17907         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17908         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17909         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17910         (cmdline_parse_inst_t *)&cmd_stop,
17911         (cmdline_parse_inst_t *)&cmd_mac_addr,
17912         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17913         (cmdline_parse_inst_t *)&cmd_set_qmap,
17914         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17915         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17916         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17917         (cmdline_parse_inst_t *)&cmd_operate_port,
17918         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17919         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17920         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17921         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17922         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17923         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17924         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17925         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17926         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17927         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17928         (cmdline_parse_inst_t *)&cmd_config_mtu,
17929         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17930         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17931         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17932         (cmdline_parse_inst_t *)&cmd_config_rss,
17933         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17934         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17935         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17936         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17937         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17938         (cmdline_parse_inst_t *)&cmd_showport_reta,
17939         (cmdline_parse_inst_t *)&cmd_showport_macs,
17940         (cmdline_parse_inst_t *)&cmd_show_port_flow_transfer_proxy,
17941         (cmdline_parse_inst_t *)&cmd_config_burst,
17942         (cmdline_parse_inst_t *)&cmd_config_thresh,
17943         (cmdline_parse_inst_t *)&cmd_config_threshold,
17944         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17945         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17946         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17947         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17948         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17949         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17950         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17951         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17952         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17953         (cmdline_parse_inst_t *)&cmd_dump,
17954         (cmdline_parse_inst_t *)&cmd_dump_one,
17955 #ifdef RTE_NET_I40E
17956         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17957 #endif
17958         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17959         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17960         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17961         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17962         (cmdline_parse_inst_t *)&cmd_flow,
17963         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17964         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17965         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17966         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17967         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17968         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17969         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17970         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17971         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17972         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17973         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17974         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17975         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17976         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17977         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17978         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17979         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17980         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17981         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17982         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17983         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17984         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17985         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17986         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17987         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17988         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17989         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17990         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17991         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17992         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17993         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17994         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17995         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17996         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17997         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17998         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17999         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18000         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18001         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18002         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18003         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18004         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18005         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18006         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18007         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18008         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18009         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18010         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18011         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18012         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18013         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18014         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18015         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18016         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18017         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18018         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18019         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
18020         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
18021         (cmdline_parse_inst_t *)&cmd_ddp_add,
18022         (cmdline_parse_inst_t *)&cmd_ddp_del,
18023         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18024         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18025         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18026         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18027         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18028         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18029         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18030         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18031         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18032         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18033         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18034         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18035
18036         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18037         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18038         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18039         (cmdline_parse_inst_t *)&cmd_queue_region,
18040         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18041         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18042         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18043         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18044         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18045         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18046         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18047         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18048         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18049         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18050         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18051         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18052         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18053         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18054         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18055         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18056         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18057         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18058         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18059         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18060         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18061         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18062         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18063         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18064         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18065         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18066         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18067         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18068         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18069         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18070         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18071         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18072         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18073         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18074         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18075         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18076 #ifdef RTE_LIB_BPF
18077         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18078         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18079 #endif
18080         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18081         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18082         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18083         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
18084         (cmdline_parse_inst_t *)&cmd_set_raw,
18085         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18086         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18087         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18088         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18089         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18090         (cmdline_parse_inst_t *)&cmd_show_capability,
18091         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
18092         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
18093         NULL,
18094 };
18095
18096 /* read cmdline commands from file */
18097 void
18098 cmdline_read_from_file(const char *filename)
18099 {
18100         struct cmdline *cl;
18101
18102         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18103         if (cl == NULL) {
18104                 fprintf(stderr,
18105                         "Failed to create file based cmdline context: %s\n",
18106                         filename);
18107                 return;
18108         }
18109
18110         cmdline_interact(cl);
18111         cmdline_quit(cl);
18112
18113         cmdline_free(cl);
18114
18115         printf("Read CLI commands from %s\n", filename);
18116 }
18117
18118 /* prompt function, called from main on MAIN lcore */
18119 void
18120 prompt(void)
18121 {
18122         int ret;
18123         /* initialize non-constant commands */
18124         cmd_set_fwd_mode_init();
18125         cmd_set_fwd_retry_mode_init();
18126
18127         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18128         if (testpmd_cl == NULL)
18129                 return;
18130
18131         ret = atexit(prompt_exit);
18132         if (ret != 0)
18133                 fprintf(stderr, "Cannot set exit function for cmdline\n");
18134
18135         cmdline_interact(testpmd_cl);
18136         if (ret != 0)
18137                 cmdline_stdin_exit(testpmd_cl);
18138 }
18139
18140 void
18141 prompt_exit(void)
18142 {
18143         if (testpmd_cl != NULL) {
18144                 cmdline_quit(testpmd_cl);
18145                 cmdline_stdin_exit(testpmd_cl);
18146         }
18147 }
18148
18149 static void
18150 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18151 {
18152         if (id == (portid_t)RTE_PORT_ALL) {
18153                 portid_t pid;
18154
18155                 RTE_ETH_FOREACH_DEV(pid) {
18156                         /* check if need_reconfig has been set to 1 */
18157                         if (ports[pid].need_reconfig == 0)
18158                                 ports[pid].need_reconfig = dev;
18159                         /* check if need_reconfig_queues has been set to 1 */
18160                         if (ports[pid].need_reconfig_queues == 0)
18161                                 ports[pid].need_reconfig_queues = queue;
18162                 }
18163         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18164                 /* check if need_reconfig has been set to 1 */
18165                 if (ports[id].need_reconfig == 0)
18166                         ports[id].need_reconfig = dev;
18167                 /* check if need_reconfig_queues has been set to 1 */
18168                 if (ports[id].need_reconfig_queues == 0)
18169                         ports[id].need_reconfig_queues = queue;
18170         }
18171 }