remove unnecessary null checks
[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|none|level-default|"
802                         "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         if (res->value < RTE_ETHER_MIN_LEN) {
2054                 fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2055                 return;
2056         }
2057         port_mtu_set(res->port_id, res->value);
2058 }
2059
2060 cmdline_parse_token_string_t cmd_config_mtu_port =
2061         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2062                                  "port");
2063 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2064         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2065                                  "config");
2066 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2067         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2068                                  "mtu");
2069 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2070         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2071                                  RTE_UINT16);
2072 cmdline_parse_token_num_t cmd_config_mtu_value =
2073         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2074                                  RTE_UINT16);
2075
2076 cmdline_parse_inst_t cmd_config_mtu = {
2077         .f = cmd_config_mtu_parsed,
2078         .data = NULL,
2079         .help_str = "port config mtu <port_id> <value>",
2080         .tokens = {
2081                 (void *)&cmd_config_mtu_port,
2082                 (void *)&cmd_config_mtu_keyword,
2083                 (void *)&cmd_config_mtu_mtu,
2084                 (void *)&cmd_config_mtu_port_id,
2085                 (void *)&cmd_config_mtu_value,
2086                 NULL,
2087         },
2088 };
2089
2090 /* *** configure rx mode *** */
2091 struct cmd_config_rx_mode_flag {
2092         cmdline_fixed_string_t port;
2093         cmdline_fixed_string_t keyword;
2094         cmdline_fixed_string_t all;
2095         cmdline_fixed_string_t name;
2096         cmdline_fixed_string_t value;
2097 };
2098
2099 static void
2100 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2101                                 __rte_unused struct cmdline *cl,
2102                                 __rte_unused void *data)
2103 {
2104         struct cmd_config_rx_mode_flag *res = parsed_result;
2105
2106         if (!all_ports_stopped()) {
2107                 fprintf(stderr, "Please stop all ports first\n");
2108                 return;
2109         }
2110
2111         if (!strcmp(res->name, "drop-en")) {
2112                 if (!strcmp(res->value, "on"))
2113                         rx_drop_en = 1;
2114                 else if (!strcmp(res->value, "off"))
2115                         rx_drop_en = 0;
2116                 else {
2117                         fprintf(stderr, "Unknown parameter\n");
2118                         return;
2119                 }
2120         } else {
2121                 fprintf(stderr, "Unknown parameter\n");
2122                 return;
2123         }
2124
2125         init_port_config();
2126
2127         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2128 }
2129
2130 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2131         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2132 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2133         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2134                                                                 "config");
2135 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2136         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2137 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2138         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2139                                         "drop-en");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2142                                                         "on#off");
2143
2144 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2145         .f = cmd_config_rx_mode_flag_parsed,
2146         .data = NULL,
2147         .help_str = "port config all drop-en on|off",
2148         .tokens = {
2149                 (void *)&cmd_config_rx_mode_flag_port,
2150                 (void *)&cmd_config_rx_mode_flag_keyword,
2151                 (void *)&cmd_config_rx_mode_flag_all,
2152                 (void *)&cmd_config_rx_mode_flag_name,
2153                 (void *)&cmd_config_rx_mode_flag_value,
2154                 NULL,
2155         },
2156 };
2157
2158 /* *** configure rss *** */
2159 struct cmd_config_rss {
2160         cmdline_fixed_string_t port;
2161         cmdline_fixed_string_t keyword;
2162         cmdline_fixed_string_t all;
2163         cmdline_fixed_string_t name;
2164         cmdline_fixed_string_t value;
2165 };
2166
2167 static void
2168 cmd_config_rss_parsed(void *parsed_result,
2169                         __rte_unused struct cmdline *cl,
2170                         __rte_unused void *data)
2171 {
2172         struct cmd_config_rss *res = parsed_result;
2173         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2174         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2175         int use_default = 0;
2176         int all_updated = 1;
2177         int diag;
2178         uint16_t i;
2179         int ret;
2180
2181         if (!strcmp(res->value, "all"))
2182                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2183                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2184                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2185                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2186                         RTE_ETH_RSS_ECPRI;
2187         else if (!strcmp(res->value, "eth"))
2188                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2189         else if (!strcmp(res->value, "vlan"))
2190                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2191         else if (!strcmp(res->value, "ip"))
2192                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2193         else if (!strcmp(res->value, "udp"))
2194                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2195         else if (!strcmp(res->value, "tcp"))
2196                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2197         else if (!strcmp(res->value, "sctp"))
2198                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2199         else if (!strcmp(res->value, "ether"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2201         else if (!strcmp(res->value, "port"))
2202                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2203         else if (!strcmp(res->value, "vxlan"))
2204                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2205         else if (!strcmp(res->value, "geneve"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2207         else if (!strcmp(res->value, "nvgre"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2209         else if (!strcmp(res->value, "l3-pre32"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2211         else if (!strcmp(res->value, "l3-pre40"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2213         else if (!strcmp(res->value, "l3-pre48"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2215         else if (!strcmp(res->value, "l3-pre56"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2217         else if (!strcmp(res->value, "l3-pre64"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2219         else if (!strcmp(res->value, "l3-pre96"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2221         else if (!strcmp(res->value, "l3-src-only"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2223         else if (!strcmp(res->value, "l3-dst-only"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2225         else if (!strcmp(res->value, "l4-src-only"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2227         else if (!strcmp(res->value, "l4-dst-only"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2229         else if (!strcmp(res->value, "l2-src-only"))
2230                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2231         else if (!strcmp(res->value, "l2-dst-only"))
2232                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2233         else if (!strcmp(res->value, "l2tpv3"))
2234                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2235         else if (!strcmp(res->value, "esp"))
2236                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2237         else if (!strcmp(res->value, "ah"))
2238                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2239         else if (!strcmp(res->value, "pfcp"))
2240                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2241         else if (!strcmp(res->value, "pppoe"))
2242                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2243         else if (!strcmp(res->value, "gtpu"))
2244                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2245         else if (!strcmp(res->value, "ecpri"))
2246                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2247         else if (!strcmp(res->value, "mpls"))
2248                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2249         else if (!strcmp(res->value, "ipv4-chksum"))
2250                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2251         else if (!strcmp(res->value, "none"))
2252                 rss_conf.rss_hf = 0;
2253         else if (!strcmp(res->value, "level-default")) {
2254                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2255                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2256         } else if (!strcmp(res->value, "level-outer")) {
2257                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2258                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2259         } else if (!strcmp(res->value, "level-inner")) {
2260                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2261                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2262         } else if (!strcmp(res->value, "default"))
2263                 use_default = 1;
2264         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2265                                                 atoi(res->value) < 64)
2266                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2267         else {
2268                 fprintf(stderr, "Unknown parameter\n");
2269                 return;
2270         }
2271         rss_conf.rss_key = NULL;
2272         /* Update global configuration for RSS types. */
2273         RTE_ETH_FOREACH_DEV(i) {
2274                 struct rte_eth_rss_conf local_rss_conf;
2275
2276                 ret = eth_dev_info_get_print_err(i, &dev_info);
2277                 if (ret != 0)
2278                         return;
2279
2280                 if (use_default)
2281                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2282
2283                 local_rss_conf = rss_conf;
2284                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2285                         dev_info.flow_type_rss_offloads;
2286                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2287                         printf("Port %u modified RSS hash function based on hardware support,"
2288                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2289                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2290                 }
2291                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2292                 if (diag < 0) {
2293                         all_updated = 0;
2294                         fprintf(stderr,
2295                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2296                                 i, -diag, strerror(-diag));
2297                 }
2298         }
2299         if (all_updated && !use_default) {
2300                 rss_hf = rss_conf.rss_hf;
2301                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2302         }
2303 }
2304
2305 cmdline_parse_token_string_t cmd_config_rss_port =
2306         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2307 cmdline_parse_token_string_t cmd_config_rss_keyword =
2308         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2309 cmdline_parse_token_string_t cmd_config_rss_all =
2310         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2311 cmdline_parse_token_string_t cmd_config_rss_name =
2312         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2313 cmdline_parse_token_string_t cmd_config_rss_value =
2314         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2315
2316 cmdline_parse_inst_t cmd_config_rss = {
2317         .f = cmd_config_rss_parsed,
2318         .data = NULL,
2319         .help_str = "port config all rss "
2320                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2321                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2322                 "level-outer|level-inner|ipv4-chksum|<flowtype_id>",
2323         .tokens = {
2324                 (void *)&cmd_config_rss_port,
2325                 (void *)&cmd_config_rss_keyword,
2326                 (void *)&cmd_config_rss_all,
2327                 (void *)&cmd_config_rss_name,
2328                 (void *)&cmd_config_rss_value,
2329                 NULL,
2330         },
2331 };
2332
2333 /* *** configure rss hash key *** */
2334 struct cmd_config_rss_hash_key {
2335         cmdline_fixed_string_t port;
2336         cmdline_fixed_string_t config;
2337         portid_t port_id;
2338         cmdline_fixed_string_t rss_hash_key;
2339         cmdline_fixed_string_t rss_type;
2340         cmdline_fixed_string_t key;
2341 };
2342
2343 static uint8_t
2344 hexa_digit_to_value(char hexa_digit)
2345 {
2346         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2347                 return (uint8_t) (hexa_digit - '0');
2348         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2349                 return (uint8_t) ((hexa_digit - 'a') + 10);
2350         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2351                 return (uint8_t) ((hexa_digit - 'A') + 10);
2352         /* Invalid hexa digit */
2353         return 0xFF;
2354 }
2355
2356 static uint8_t
2357 parse_and_check_key_hexa_digit(char *key, int idx)
2358 {
2359         uint8_t hexa_v;
2360
2361         hexa_v = hexa_digit_to_value(key[idx]);
2362         if (hexa_v == 0xFF)
2363                 fprintf(stderr,
2364                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2365                         key[idx], idx);
2366         return hexa_v;
2367 }
2368
2369 static void
2370 cmd_config_rss_hash_key_parsed(void *parsed_result,
2371                                __rte_unused struct cmdline *cl,
2372                                __rte_unused void *data)
2373 {
2374         struct cmd_config_rss_hash_key *res = parsed_result;
2375         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2376         uint8_t xdgt0;
2377         uint8_t xdgt1;
2378         int i;
2379         struct rte_eth_dev_info dev_info;
2380         uint8_t hash_key_size;
2381         uint32_t key_len;
2382         int ret;
2383
2384         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2385         if (ret != 0)
2386                 return;
2387
2388         if (dev_info.hash_key_size > 0 &&
2389                         dev_info.hash_key_size <= sizeof(hash_key))
2390                 hash_key_size = dev_info.hash_key_size;
2391         else {
2392                 fprintf(stderr,
2393                         "dev_info did not provide a valid hash key size\n");
2394                 return;
2395         }
2396         /* Check the length of the RSS hash key */
2397         key_len = strlen(res->key);
2398         if (key_len != (hash_key_size * 2)) {
2399                 fprintf(stderr,
2400                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2401                         (int)key_len, hash_key_size * 2);
2402                 return;
2403         }
2404         /* Translate RSS hash key into binary representation */
2405         for (i = 0; i < hash_key_size; i++) {
2406                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2407                 if (xdgt0 == 0xFF)
2408                         return;
2409                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2410                 if (xdgt1 == 0xFF)
2411                         return;
2412                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2413         }
2414         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2415                         hash_key_size);
2416 }
2417
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2420 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2421         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2422                                  "config");
2423 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2424         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2425                                  RTE_UINT16);
2426 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2427         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2428                                  rss_hash_key, "rss-hash-key");
2429 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2430         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2431                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2432                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2433                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2434                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2435                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2436                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2437                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2438 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2440
2441 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2442         .f = cmd_config_rss_hash_key_parsed,
2443         .data = NULL,
2444         .help_str = "port config <port_id> rss-hash-key "
2445                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2446                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2447                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2448                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2449                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2450                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2451                 "<string of hex digits (variable length, NIC dependent)>",
2452         .tokens = {
2453                 (void *)&cmd_config_rss_hash_key_port,
2454                 (void *)&cmd_config_rss_hash_key_config,
2455                 (void *)&cmd_config_rss_hash_key_port_id,
2456                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2457                 (void *)&cmd_config_rss_hash_key_rss_type,
2458                 (void *)&cmd_config_rss_hash_key_value,
2459                 NULL,
2460         },
2461 };
2462
2463 /* *** cleanup txq mbufs *** */
2464 struct cmd_cleanup_txq_mbufs_result {
2465         cmdline_fixed_string_t port;
2466         cmdline_fixed_string_t keyword;
2467         cmdline_fixed_string_t name;
2468         uint16_t port_id;
2469         uint16_t queue_id;
2470         uint32_t free_cnt;
2471 };
2472
2473 static void
2474 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2475                              __rte_unused struct cmdline *cl,
2476                              __rte_unused void *data)
2477 {
2478         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2479         uint16_t port_id = res->port_id;
2480         uint16_t queue_id = res->queue_id;
2481         uint32_t free_cnt = res->free_cnt;
2482         struct rte_eth_txq_info qinfo;
2483         int ret;
2484
2485         if (test_done == 0) {
2486                 fprintf(stderr, "Please stop forwarding first\n");
2487                 return;
2488         }
2489
2490         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2491                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2492                         port_id, queue_id);
2493                 return;
2494         }
2495
2496         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2497                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2498                 return;
2499         }
2500
2501         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2502         if (ret < 0) {
2503                 fprintf(stderr,
2504                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2505                         port_id, queue_id, strerror(-ret), ret);
2506                 return;
2507         }
2508
2509         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2510                port_id, queue_id, ret);
2511 }
2512
2513 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2514         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2515                                  "port");
2516 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2517         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2518                                  "cleanup");
2519 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2520         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2521                               RTE_UINT16);
2522 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2523         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2524                                  "txq");
2525 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2526         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2527                               RTE_UINT16);
2528 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2529         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2530                               RTE_UINT32);
2531
2532 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2533         .f = cmd_cleanup_txq_mbufs_parsed,
2534         .data = NULL,
2535         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2536         .tokens = {
2537                 (void *)&cmd_cleanup_txq_mbufs_port,
2538                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2539                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2540                 (void *)&cmd_cleanup_txq_mbufs_txq,
2541                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2542                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2543                 NULL,
2544         },
2545 };
2546
2547 /* *** configure port rxq/txq ring size *** */
2548 struct cmd_config_rxtx_ring_size {
2549         cmdline_fixed_string_t port;
2550         cmdline_fixed_string_t config;
2551         portid_t portid;
2552         cmdline_fixed_string_t rxtxq;
2553         uint16_t qid;
2554         cmdline_fixed_string_t rsize;
2555         uint16_t size;
2556 };
2557
2558 static void
2559 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2560                                  __rte_unused struct cmdline *cl,
2561                                  __rte_unused void *data)
2562 {
2563         struct cmd_config_rxtx_ring_size *res = parsed_result;
2564         struct rte_port *port;
2565         uint8_t isrx;
2566
2567         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2568                 return;
2569
2570         if (res->portid == (portid_t)RTE_PORT_ALL) {
2571                 fprintf(stderr, "Invalid port id\n");
2572                 return;
2573         }
2574
2575         port = &ports[res->portid];
2576
2577         if (!strcmp(res->rxtxq, "rxq"))
2578                 isrx = 1;
2579         else if (!strcmp(res->rxtxq, "txq"))
2580                 isrx = 0;
2581         else {
2582                 fprintf(stderr, "Unknown parameter\n");
2583                 return;
2584         }
2585
2586         if (isrx && rx_queue_id_is_invalid(res->qid))
2587                 return;
2588         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2589                 return;
2590
2591         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2592                 fprintf(stderr,
2593                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2594                         rx_free_thresh);
2595                 return;
2596         }
2597
2598         if (isrx)
2599                 port->nb_rx_desc[res->qid] = res->size;
2600         else
2601                 port->nb_tx_desc[res->qid] = res->size;
2602
2603         cmd_reconfig_device_queue(res->portid, 0, 1);
2604 }
2605
2606 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2607         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2608                                  port, "port");
2609 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2610         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2611                                  config, "config");
2612 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2613         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2614                                  portid, RTE_UINT16);
2615 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2616         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2617                                  rxtxq, "rxq#txq");
2618 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2619         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2620                               qid, RTE_UINT16);
2621 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2622         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2623                                  rsize, "ring_size");
2624 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2625         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2626                               size, RTE_UINT16);
2627
2628 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2629         .f = cmd_config_rxtx_ring_size_parsed,
2630         .data = NULL,
2631         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2632         .tokens = {
2633                 (void *)&cmd_config_rxtx_ring_size_port,
2634                 (void *)&cmd_config_rxtx_ring_size_config,
2635                 (void *)&cmd_config_rxtx_ring_size_portid,
2636                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2637                 (void *)&cmd_config_rxtx_ring_size_qid,
2638                 (void *)&cmd_config_rxtx_ring_size_rsize,
2639                 (void *)&cmd_config_rxtx_ring_size_size,
2640                 NULL,
2641         },
2642 };
2643
2644 /* *** configure port rxq/txq start/stop *** */
2645 struct cmd_config_rxtx_queue {
2646         cmdline_fixed_string_t port;
2647         portid_t portid;
2648         cmdline_fixed_string_t rxtxq;
2649         uint16_t qid;
2650         cmdline_fixed_string_t opname;
2651 };
2652
2653 static void
2654 cmd_config_rxtx_queue_parsed(void *parsed_result,
2655                         __rte_unused struct cmdline *cl,
2656                         __rte_unused void *data)
2657 {
2658         struct cmd_config_rxtx_queue *res = parsed_result;
2659         uint8_t isrx;
2660         uint8_t isstart;
2661         int ret = 0;
2662
2663         if (test_done == 0) {
2664                 fprintf(stderr, "Please stop forwarding first\n");
2665                 return;
2666         }
2667
2668         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2669                 return;
2670
2671         if (port_is_started(res->portid) != 1) {
2672                 fprintf(stderr, "Please start port %u first\n", res->portid);
2673                 return;
2674         }
2675
2676         if (!strcmp(res->rxtxq, "rxq"))
2677                 isrx = 1;
2678         else if (!strcmp(res->rxtxq, "txq"))
2679                 isrx = 0;
2680         else {
2681                 fprintf(stderr, "Unknown parameter\n");
2682                 return;
2683         }
2684
2685         if (isrx && rx_queue_id_is_invalid(res->qid))
2686                 return;
2687         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2688                 return;
2689
2690         if (!strcmp(res->opname, "start"))
2691                 isstart = 1;
2692         else if (!strcmp(res->opname, "stop"))
2693                 isstart = 0;
2694         else {
2695                 fprintf(stderr, "Unknown parameter\n");
2696                 return;
2697         }
2698
2699         if (isstart && isrx)
2700                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2701         else if (!isstart && isrx)
2702                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2703         else if (isstart && !isrx)
2704                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2705         else
2706                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2707
2708         if (ret == -ENOTSUP)
2709                 fprintf(stderr, "Function not supported in PMD\n");
2710 }
2711
2712 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2713         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2714 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2715         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2716 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2717         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2718 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2719         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2720 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2721         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2722                                                 "start#stop");
2723
2724 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2725         .f = cmd_config_rxtx_queue_parsed,
2726         .data = NULL,
2727         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2728         .tokens = {
2729                 (void *)&cmd_config_rxtx_queue_port,
2730                 (void *)&cmd_config_rxtx_queue_portid,
2731                 (void *)&cmd_config_rxtx_queue_rxtxq,
2732                 (void *)&cmd_config_rxtx_queue_qid,
2733                 (void *)&cmd_config_rxtx_queue_opname,
2734                 NULL,
2735         },
2736 };
2737
2738 /* *** configure port rxq/txq deferred start on/off *** */
2739 struct cmd_config_deferred_start_rxtx_queue {
2740         cmdline_fixed_string_t port;
2741         portid_t port_id;
2742         cmdline_fixed_string_t rxtxq;
2743         uint16_t qid;
2744         cmdline_fixed_string_t opname;
2745         cmdline_fixed_string_t state;
2746 };
2747
2748 static void
2749 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2750                         __rte_unused struct cmdline *cl,
2751                         __rte_unused void *data)
2752 {
2753         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2754         struct rte_port *port;
2755         uint8_t isrx;
2756         uint8_t ison;
2757         uint8_t needreconfig = 0;
2758
2759         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2760                 return;
2761
2762         if (port_is_started(res->port_id) != 0) {
2763                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2764                 return;
2765         }
2766
2767         port = &ports[res->port_id];
2768
2769         isrx = !strcmp(res->rxtxq, "rxq");
2770
2771         if (isrx && rx_queue_id_is_invalid(res->qid))
2772                 return;
2773         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2774                 return;
2775
2776         ison = !strcmp(res->state, "on");
2777
2778         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2779                 port->rx_conf[res->qid].rx_deferred_start = ison;
2780                 needreconfig = 1;
2781         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2782                 port->tx_conf[res->qid].tx_deferred_start = ison;
2783                 needreconfig = 1;
2784         }
2785
2786         if (needreconfig)
2787                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2788 }
2789
2790 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2791         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2792                                                 port, "port");
2793 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2794         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2795                                                 port_id, RTE_UINT16);
2796 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2797         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2798                                                 rxtxq, "rxq#txq");
2799 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2800         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2801                                                 qid, RTE_UINT16);
2802 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2803         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2804                                                 opname, "deferred_start");
2805 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2806         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2807                                                 state, "on#off");
2808
2809 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2810         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2811         .data = NULL,
2812         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2813         .tokens = {
2814                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2815                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2816                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2817                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2818                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2819                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2820                 NULL,
2821         },
2822 };
2823
2824 /* *** configure port rxq/txq setup *** */
2825 struct cmd_setup_rxtx_queue {
2826         cmdline_fixed_string_t port;
2827         portid_t portid;
2828         cmdline_fixed_string_t rxtxq;
2829         uint16_t qid;
2830         cmdline_fixed_string_t setup;
2831 };
2832
2833 /* Common CLI fields for queue setup */
2834 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2835         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2836 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2837         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2838 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2839         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2840 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2841         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2842 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2843         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2844
2845 static void
2846 cmd_setup_rxtx_queue_parsed(
2847         void *parsed_result,
2848         __rte_unused struct cmdline *cl,
2849         __rte_unused void *data)
2850 {
2851         struct cmd_setup_rxtx_queue *res = parsed_result;
2852         struct rte_port *port;
2853         struct rte_mempool *mp;
2854         unsigned int socket_id;
2855         uint8_t isrx = 0;
2856         int ret;
2857
2858         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2859                 return;
2860
2861         if (res->portid == (portid_t)RTE_PORT_ALL) {
2862                 fprintf(stderr, "Invalid port id\n");
2863                 return;
2864         }
2865
2866         if (!strcmp(res->rxtxq, "rxq"))
2867                 isrx = 1;
2868         else if (!strcmp(res->rxtxq, "txq"))
2869                 isrx = 0;
2870         else {
2871                 fprintf(stderr, "Unknown parameter\n");
2872                 return;
2873         }
2874
2875         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2876                 fprintf(stderr, "Invalid rx queue\n");
2877                 return;
2878         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2879                 fprintf(stderr, "Invalid tx queue\n");
2880                 return;
2881         }
2882
2883         port = &ports[res->portid];
2884         if (isrx) {
2885                 socket_id = rxring_numa[res->portid];
2886                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2887                         socket_id = port->socket_id;
2888
2889                 mp = mbuf_pool_find(socket_id, 0);
2890                 if (mp == NULL) {
2891                         fprintf(stderr,
2892                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2893                                 rxring_numa[res->portid]);
2894                         return;
2895                 }
2896                 ret = rx_queue_setup(res->portid,
2897                                      res->qid,
2898                                      port->nb_rx_desc[res->qid],
2899                                      socket_id,
2900                                      &port->rx_conf[res->qid],
2901                                      mp);
2902                 if (ret)
2903                         fprintf(stderr, "Failed to setup RX queue\n");
2904         } else {
2905                 socket_id = txring_numa[res->portid];
2906                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2907                         socket_id = port->socket_id;
2908
2909                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2910                         fprintf(stderr,
2911                                 "Failed to setup TX queue: not enough descriptors\n");
2912                         return;
2913                 }
2914                 ret = rte_eth_tx_queue_setup(res->portid,
2915                                              res->qid,
2916                                              port->nb_tx_desc[res->qid],
2917                                              socket_id,
2918                                              &port->tx_conf[res->qid]);
2919                 if (ret)
2920                         fprintf(stderr, "Failed to setup TX queue\n");
2921         }
2922 }
2923
2924 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2925         .f = cmd_setup_rxtx_queue_parsed,
2926         .data = NULL,
2927         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2928         .tokens = {
2929                 (void *)&cmd_setup_rxtx_queue_port,
2930                 (void *)&cmd_setup_rxtx_queue_portid,
2931                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2932                 (void *)&cmd_setup_rxtx_queue_qid,
2933                 (void *)&cmd_setup_rxtx_queue_setup,
2934                 NULL,
2935         },
2936 };
2937
2938
2939 /* *** Configure RSS RETA *** */
2940 struct cmd_config_rss_reta {
2941         cmdline_fixed_string_t port;
2942         cmdline_fixed_string_t keyword;
2943         portid_t port_id;
2944         cmdline_fixed_string_t name;
2945         cmdline_fixed_string_t list_name;
2946         cmdline_fixed_string_t list_of_items;
2947 };
2948
2949 static int
2950 parse_reta_config(const char *str,
2951                   struct rte_eth_rss_reta_entry64 *reta_conf,
2952                   uint16_t nb_entries)
2953 {
2954         int i;
2955         unsigned size;
2956         uint16_t hash_index, idx, shift;
2957         uint16_t nb_queue;
2958         char s[256];
2959         const char *p, *p0 = str;
2960         char *end;
2961         enum fieldnames {
2962                 FLD_HASH_INDEX = 0,
2963                 FLD_QUEUE,
2964                 _NUM_FLD
2965         };
2966         unsigned long int_fld[_NUM_FLD];
2967         char *str_fld[_NUM_FLD];
2968
2969         while ((p = strchr(p0,'(')) != NULL) {
2970                 ++p;
2971                 if((p0 = strchr(p,')')) == NULL)
2972                         return -1;
2973
2974                 size = p0 - p;
2975                 if(size >= sizeof(s))
2976                         return -1;
2977
2978                 snprintf(s, sizeof(s), "%.*s", size, p);
2979                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2980                         return -1;
2981                 for (i = 0; i < _NUM_FLD; i++) {
2982                         errno = 0;
2983                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2984                         if (errno != 0 || end == str_fld[i] ||
2985                                         int_fld[i] > 65535)
2986                                 return -1;
2987                 }
2988
2989                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2990                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2991
2992                 if (hash_index >= nb_entries) {
2993                         fprintf(stderr, "Invalid RETA hash index=%d\n",
2994                                 hash_index);
2995                         return -1;
2996                 }
2997
2998                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
2999                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
3000                 reta_conf[idx].mask |= (1ULL << shift);
3001                 reta_conf[idx].reta[shift] = nb_queue;
3002         }
3003
3004         return 0;
3005 }
3006
3007 static void
3008 cmd_set_rss_reta_parsed(void *parsed_result,
3009                         __rte_unused struct cmdline *cl,
3010                         __rte_unused void *data)
3011 {
3012         int ret;
3013         struct rte_eth_dev_info dev_info;
3014         struct rte_eth_rss_reta_entry64 reta_conf[8];
3015         struct cmd_config_rss_reta *res = parsed_result;
3016
3017         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3018         if (ret != 0)
3019                 return;
3020
3021         if (dev_info.reta_size == 0) {
3022                 fprintf(stderr,
3023                         "Redirection table size is 0 which is invalid for RSS\n");
3024                 return;
3025         } else
3026                 printf("The reta size of port %d is %u\n",
3027                         res->port_id, dev_info.reta_size);
3028         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3029                 fprintf(stderr,
3030                         "Currently do not support more than %u entries of redirection table\n",
3031                         RTE_ETH_RSS_RETA_SIZE_512);
3032                 return;
3033         }
3034
3035         memset(reta_conf, 0, sizeof(reta_conf));
3036         if (!strcmp(res->list_name, "reta")) {
3037                 if (parse_reta_config(res->list_of_items, reta_conf,
3038                                                 dev_info.reta_size)) {
3039                         fprintf(stderr,
3040                                 "Invalid RSS Redirection Table config entered\n");
3041                         return;
3042                 }
3043                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3044                                 reta_conf, dev_info.reta_size);
3045                 if (ret != 0)
3046                         fprintf(stderr,
3047                                 "Bad redirection table parameter, return code = %d\n",
3048                                 ret);
3049         }
3050 }
3051
3052 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3053         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3054 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3055         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3056 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3057         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3058 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3059         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3060 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3061         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3062 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3063         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3064                                  NULL);
3065 cmdline_parse_inst_t cmd_config_rss_reta = {
3066         .f = cmd_set_rss_reta_parsed,
3067         .data = NULL,
3068         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3069         .tokens = {
3070                 (void *)&cmd_config_rss_reta_port,
3071                 (void *)&cmd_config_rss_reta_keyword,
3072                 (void *)&cmd_config_rss_reta_port_id,
3073                 (void *)&cmd_config_rss_reta_name,
3074                 (void *)&cmd_config_rss_reta_list_name,
3075                 (void *)&cmd_config_rss_reta_list_of_items,
3076                 NULL,
3077         },
3078 };
3079
3080 /* *** SHOW PORT RETA INFO *** */
3081 struct cmd_showport_reta {
3082         cmdline_fixed_string_t show;
3083         cmdline_fixed_string_t port;
3084         portid_t port_id;
3085         cmdline_fixed_string_t rss;
3086         cmdline_fixed_string_t reta;
3087         uint16_t size;
3088         cmdline_fixed_string_t list_of_items;
3089 };
3090
3091 static int
3092 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3093                            uint16_t nb_entries,
3094                            char *str)
3095 {
3096         uint32_t size;
3097         const char *p, *p0 = str;
3098         char s[256];
3099         char *end;
3100         char *str_fld[8];
3101         uint16_t i;
3102         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3103                         RTE_ETH_RETA_GROUP_SIZE;
3104         int ret;
3105
3106         p = strchr(p0, '(');
3107         if (p == NULL)
3108                 return -1;
3109         p++;
3110         p0 = strchr(p, ')');
3111         if (p0 == NULL)
3112                 return -1;
3113         size = p0 - p;
3114         if (size >= sizeof(s)) {
3115                 fprintf(stderr,
3116                         "The string size exceeds the internal buffer size\n");
3117                 return -1;
3118         }
3119         snprintf(s, sizeof(s), "%.*s", size, p);
3120         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3121         if (ret <= 0 || ret != num) {
3122                 fprintf(stderr,
3123                         "The bits of masks do not match the number of reta entries: %u\n",
3124                         num);
3125                 return -1;
3126         }
3127         for (i = 0; i < ret; i++)
3128                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3129
3130         return 0;
3131 }
3132
3133 static void
3134 cmd_showport_reta_parsed(void *parsed_result,
3135                          __rte_unused struct cmdline *cl,
3136                          __rte_unused void *data)
3137 {
3138         struct cmd_showport_reta *res = parsed_result;
3139         struct rte_eth_rss_reta_entry64 reta_conf[8];
3140         struct rte_eth_dev_info dev_info;
3141         uint16_t max_reta_size;
3142         int ret;
3143
3144         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3145         if (ret != 0)
3146                 return;
3147
3148         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3149         if (res->size == 0 || res->size > max_reta_size) {
3150                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3151                         res->size, max_reta_size);
3152                 return;
3153         }
3154
3155         memset(reta_conf, 0, sizeof(reta_conf));
3156         if (showport_parse_reta_config(reta_conf, res->size,
3157                                 res->list_of_items) < 0) {
3158                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3159                         res->list_of_items);
3160                 return;
3161         }
3162         port_rss_reta_info(res->port_id, reta_conf, res->size);
3163 }
3164
3165 cmdline_parse_token_string_t cmd_showport_reta_show =
3166         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3167 cmdline_parse_token_string_t cmd_showport_reta_port =
3168         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3169 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3170         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3171 cmdline_parse_token_string_t cmd_showport_reta_rss =
3172         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3173 cmdline_parse_token_string_t cmd_showport_reta_reta =
3174         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3175 cmdline_parse_token_num_t cmd_showport_reta_size =
3176         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3177 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3178         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3179                                         list_of_items, NULL);
3180
3181 cmdline_parse_inst_t cmd_showport_reta = {
3182         .f = cmd_showport_reta_parsed,
3183         .data = NULL,
3184         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3185         .tokens = {
3186                 (void *)&cmd_showport_reta_show,
3187                 (void *)&cmd_showport_reta_port,
3188                 (void *)&cmd_showport_reta_port_id,
3189                 (void *)&cmd_showport_reta_rss,
3190                 (void *)&cmd_showport_reta_reta,
3191                 (void *)&cmd_showport_reta_size,
3192                 (void *)&cmd_showport_reta_list_of_items,
3193                 NULL,
3194         },
3195 };
3196
3197 /* *** Show RSS hash configuration *** */
3198 struct cmd_showport_rss_hash {
3199         cmdline_fixed_string_t show;
3200         cmdline_fixed_string_t port;
3201         portid_t port_id;
3202         cmdline_fixed_string_t rss_hash;
3203         cmdline_fixed_string_t rss_type;
3204         cmdline_fixed_string_t key; /* optional argument */
3205 };
3206
3207 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3208                                 __rte_unused struct cmdline *cl,
3209                                 void *show_rss_key)
3210 {
3211         struct cmd_showport_rss_hash *res = parsed_result;
3212
3213         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3214 }
3215
3216 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3217         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3218 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3219         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3220 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3221         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3222                                  RTE_UINT16);
3223 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3224         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3225                                  "rss-hash");
3226 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3227         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3228
3229 cmdline_parse_inst_t cmd_showport_rss_hash = {
3230         .f = cmd_showport_rss_hash_parsed,
3231         .data = NULL,
3232         .help_str = "show port <port_id> rss-hash",
3233         .tokens = {
3234                 (void *)&cmd_showport_rss_hash_show,
3235                 (void *)&cmd_showport_rss_hash_port,
3236                 (void *)&cmd_showport_rss_hash_port_id,
3237                 (void *)&cmd_showport_rss_hash_rss_hash,
3238                 NULL,
3239         },
3240 };
3241
3242 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3243         .f = cmd_showport_rss_hash_parsed,
3244         .data = (void *)1,
3245         .help_str = "show port <port_id> rss-hash key",
3246         .tokens = {
3247                 (void *)&cmd_showport_rss_hash_show,
3248                 (void *)&cmd_showport_rss_hash_port,
3249                 (void *)&cmd_showport_rss_hash_port_id,
3250                 (void *)&cmd_showport_rss_hash_rss_hash,
3251                 (void *)&cmd_showport_rss_hash_rss_key,
3252                 NULL,
3253         },
3254 };
3255
3256 /* *** Configure DCB *** */
3257 struct cmd_config_dcb {
3258         cmdline_fixed_string_t port;
3259         cmdline_fixed_string_t config;
3260         portid_t port_id;
3261         cmdline_fixed_string_t dcb;
3262         cmdline_fixed_string_t vt;
3263         cmdline_fixed_string_t vt_en;
3264         uint8_t num_tcs;
3265         cmdline_fixed_string_t pfc;
3266         cmdline_fixed_string_t pfc_en;
3267 };
3268
3269 static void
3270 cmd_config_dcb_parsed(void *parsed_result,
3271                         __rte_unused struct cmdline *cl,
3272                         __rte_unused void *data)
3273 {
3274         struct cmd_config_dcb *res = parsed_result;
3275         struct rte_eth_dcb_info dcb_info;
3276         portid_t port_id = res->port_id;
3277         struct rte_port *port;
3278         uint8_t pfc_en;
3279         int ret;
3280
3281         port = &ports[port_id];
3282         /** Check if the port is not started **/
3283         if (port->port_status != RTE_PORT_STOPPED) {
3284                 fprintf(stderr, "Please stop port %d first\n", port_id);
3285                 return;
3286         }
3287
3288         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3289                 fprintf(stderr,
3290                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3291                 return;
3292         }
3293
3294         if (nb_fwd_lcores < res->num_tcs) {
3295                 fprintf(stderr,
3296                         "nb_cores shouldn't be less than number of TCs.\n");
3297                 return;
3298         }
3299
3300         /* Check whether the port supports the report of DCB info. */
3301         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3302         if (ret == -ENOTSUP) {
3303                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3304                 return;
3305         }
3306
3307         if (!strncmp(res->pfc_en, "on", 2))
3308                 pfc_en = 1;
3309         else
3310                 pfc_en = 0;
3311
3312         /* DCB in VT mode */
3313         if (!strncmp(res->vt_en, "on", 2))
3314                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3315                                 (enum rte_eth_nb_tcs)res->num_tcs,
3316                                 pfc_en);
3317         else
3318                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3319                                 (enum rte_eth_nb_tcs)res->num_tcs,
3320                                 pfc_en);
3321         if (ret != 0) {
3322                 fprintf(stderr, "Cannot initialize network ports.\n");
3323                 return;
3324         }
3325
3326         fwd_config_setup();
3327
3328         cmd_reconfig_device_queue(port_id, 1, 1);
3329 }
3330
3331 cmdline_parse_token_string_t cmd_config_dcb_port =
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3333 cmdline_parse_token_string_t cmd_config_dcb_config =
3334         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3335 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3336         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3337 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3338         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3339 cmdline_parse_token_string_t cmd_config_dcb_vt =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3341 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3342         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3343 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3344         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3345 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3346         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3347 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3348         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3349
3350 cmdline_parse_inst_t cmd_config_dcb = {
3351         .f = cmd_config_dcb_parsed,
3352         .data = NULL,
3353         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3354         .tokens = {
3355                 (void *)&cmd_config_dcb_port,
3356                 (void *)&cmd_config_dcb_config,
3357                 (void *)&cmd_config_dcb_port_id,
3358                 (void *)&cmd_config_dcb_dcb,
3359                 (void *)&cmd_config_dcb_vt,
3360                 (void *)&cmd_config_dcb_vt_en,
3361                 (void *)&cmd_config_dcb_num_tcs,
3362                 (void *)&cmd_config_dcb_pfc,
3363                 (void *)&cmd_config_dcb_pfc_en,
3364                 NULL,
3365         },
3366 };
3367
3368 /* *** configure number of packets per burst *** */
3369 struct cmd_config_burst {
3370         cmdline_fixed_string_t port;
3371         cmdline_fixed_string_t keyword;
3372         cmdline_fixed_string_t all;
3373         cmdline_fixed_string_t name;
3374         uint16_t value;
3375 };
3376
3377 static void
3378 cmd_config_burst_parsed(void *parsed_result,
3379                         __rte_unused struct cmdline *cl,
3380                         __rte_unused void *data)
3381 {
3382         struct cmd_config_burst *res = parsed_result;
3383         struct rte_eth_dev_info dev_info;
3384         uint16_t rec_nb_pkts;
3385         int ret;
3386
3387         if (!all_ports_stopped()) {
3388                 fprintf(stderr, "Please stop all ports first\n");
3389                 return;
3390         }
3391
3392         if (!strcmp(res->name, "burst")) {
3393                 if (res->value == 0) {
3394                         /* If user gives a value of zero, query the PMD for
3395                          * its recommended Rx burst size. Testpmd uses a single
3396                          * size for all ports, so assume all ports are the same
3397                          * NIC model and use the values from Port 0.
3398                          */
3399                         ret = eth_dev_info_get_print_err(0, &dev_info);
3400                         if (ret != 0)
3401                                 return;
3402
3403                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3404
3405                         if (rec_nb_pkts == 0) {
3406                                 printf("PMD does not recommend a burst size.\n"
3407                                         "User provided value must be between"
3408                                         " 1 and %d\n", MAX_PKT_BURST);
3409                                 return;
3410                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3411                                 printf("PMD recommended burst size of %d"
3412                                         " exceeds maximum value of %d\n",
3413                                         rec_nb_pkts, MAX_PKT_BURST);
3414                                 return;
3415                         }
3416                         printf("Using PMD-provided burst value of %d\n",
3417                                 rec_nb_pkts);
3418                         nb_pkt_per_burst = rec_nb_pkts;
3419                 } else if (res->value > MAX_PKT_BURST) {
3420                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3421                                 MAX_PKT_BURST);
3422                         return;
3423                 } else
3424                         nb_pkt_per_burst = res->value;
3425         } else {
3426                 fprintf(stderr, "Unknown parameter\n");
3427                 return;
3428         }
3429
3430         init_port_config();
3431
3432         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3433 }
3434
3435 cmdline_parse_token_string_t cmd_config_burst_port =
3436         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3437 cmdline_parse_token_string_t cmd_config_burst_keyword =
3438         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3439 cmdline_parse_token_string_t cmd_config_burst_all =
3440         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3441 cmdline_parse_token_string_t cmd_config_burst_name =
3442         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3443 cmdline_parse_token_num_t cmd_config_burst_value =
3444         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3445
3446 cmdline_parse_inst_t cmd_config_burst = {
3447         .f = cmd_config_burst_parsed,
3448         .data = NULL,
3449         .help_str = "port config all burst <value>",
3450         .tokens = {
3451                 (void *)&cmd_config_burst_port,
3452                 (void *)&cmd_config_burst_keyword,
3453                 (void *)&cmd_config_burst_all,
3454                 (void *)&cmd_config_burst_name,
3455                 (void *)&cmd_config_burst_value,
3456                 NULL,
3457         },
3458 };
3459
3460 /* *** configure rx/tx queues *** */
3461 struct cmd_config_thresh {
3462         cmdline_fixed_string_t port;
3463         cmdline_fixed_string_t keyword;
3464         cmdline_fixed_string_t all;
3465         cmdline_fixed_string_t name;
3466         uint8_t value;
3467 };
3468
3469 static void
3470 cmd_config_thresh_parsed(void *parsed_result,
3471                         __rte_unused struct cmdline *cl,
3472                         __rte_unused void *data)
3473 {
3474         struct cmd_config_thresh *res = parsed_result;
3475
3476         if (!all_ports_stopped()) {
3477                 fprintf(stderr, "Please stop all ports first\n");
3478                 return;
3479         }
3480
3481         if (!strcmp(res->name, "txpt"))
3482                 tx_pthresh = res->value;
3483         else if(!strcmp(res->name, "txht"))
3484                 tx_hthresh = res->value;
3485         else if(!strcmp(res->name, "txwt"))
3486                 tx_wthresh = res->value;
3487         else if(!strcmp(res->name, "rxpt"))
3488                 rx_pthresh = res->value;
3489         else if(!strcmp(res->name, "rxht"))
3490                 rx_hthresh = res->value;
3491         else if(!strcmp(res->name, "rxwt"))
3492                 rx_wthresh = res->value;
3493         else {
3494                 fprintf(stderr, "Unknown parameter\n");
3495                 return;
3496         }
3497
3498         init_port_config();
3499
3500         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3501 }
3502
3503 cmdline_parse_token_string_t cmd_config_thresh_port =
3504         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3505 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3506         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3507 cmdline_parse_token_string_t cmd_config_thresh_all =
3508         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3509 cmdline_parse_token_string_t cmd_config_thresh_name =
3510         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3511                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3512 cmdline_parse_token_num_t cmd_config_thresh_value =
3513         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3514
3515 cmdline_parse_inst_t cmd_config_thresh = {
3516         .f = cmd_config_thresh_parsed,
3517         .data = NULL,
3518         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3519         .tokens = {
3520                 (void *)&cmd_config_thresh_port,
3521                 (void *)&cmd_config_thresh_keyword,
3522                 (void *)&cmd_config_thresh_all,
3523                 (void *)&cmd_config_thresh_name,
3524                 (void *)&cmd_config_thresh_value,
3525                 NULL,
3526         },
3527 };
3528
3529 /* *** configure free/rs threshold *** */
3530 struct cmd_config_threshold {
3531         cmdline_fixed_string_t port;
3532         cmdline_fixed_string_t keyword;
3533         cmdline_fixed_string_t all;
3534         cmdline_fixed_string_t name;
3535         uint16_t value;
3536 };
3537
3538 static void
3539 cmd_config_threshold_parsed(void *parsed_result,
3540                         __rte_unused struct cmdline *cl,
3541                         __rte_unused void *data)
3542 {
3543         struct cmd_config_threshold *res = parsed_result;
3544
3545         if (!all_ports_stopped()) {
3546                 fprintf(stderr, "Please stop all ports first\n");
3547                 return;
3548         }
3549
3550         if (!strcmp(res->name, "txfreet"))
3551                 tx_free_thresh = res->value;
3552         else if (!strcmp(res->name, "txrst"))
3553                 tx_rs_thresh = res->value;
3554         else if (!strcmp(res->name, "rxfreet"))
3555                 rx_free_thresh = res->value;
3556         else {
3557                 fprintf(stderr, "Unknown parameter\n");
3558                 return;
3559         }
3560
3561         init_port_config();
3562
3563         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3564 }
3565
3566 cmdline_parse_token_string_t cmd_config_threshold_port =
3567         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3568 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3569         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3570                                                                 "config");
3571 cmdline_parse_token_string_t cmd_config_threshold_all =
3572         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3573 cmdline_parse_token_string_t cmd_config_threshold_name =
3574         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3575                                                 "txfreet#txrst#rxfreet");
3576 cmdline_parse_token_num_t cmd_config_threshold_value =
3577         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3578
3579 cmdline_parse_inst_t cmd_config_threshold = {
3580         .f = cmd_config_threshold_parsed,
3581         .data = NULL,
3582         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3583         .tokens = {
3584                 (void *)&cmd_config_threshold_port,
3585                 (void *)&cmd_config_threshold_keyword,
3586                 (void *)&cmd_config_threshold_all,
3587                 (void *)&cmd_config_threshold_name,
3588                 (void *)&cmd_config_threshold_value,
3589                 NULL,
3590         },
3591 };
3592
3593 /* *** stop *** */
3594 struct cmd_stop_result {
3595         cmdline_fixed_string_t stop;
3596 };
3597
3598 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3599                             __rte_unused struct cmdline *cl,
3600                             __rte_unused void *data)
3601 {
3602         stop_packet_forwarding();
3603 }
3604
3605 cmdline_parse_token_string_t cmd_stop_stop =
3606         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3607
3608 cmdline_parse_inst_t cmd_stop = {
3609         .f = cmd_stop_parsed,
3610         .data = NULL,
3611         .help_str = "stop: Stop packet forwarding",
3612         .tokens = {
3613                 (void *)&cmd_stop_stop,
3614                 NULL,
3615         },
3616 };
3617
3618 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3619
3620 unsigned int
3621 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3622                 unsigned int *parsed_items, int check_unique_values)
3623 {
3624         unsigned int nb_item;
3625         unsigned int value;
3626         unsigned int i;
3627         unsigned int j;
3628         int value_ok;
3629         char c;
3630
3631         /*
3632          * First parse all items in the list and store their value.
3633          */
3634         value = 0;
3635         nb_item = 0;
3636         value_ok = 0;
3637         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3638                 c = str[i];
3639                 if ((c >= '0') && (c <= '9')) {
3640                         value = (unsigned int) (value * 10 + (c - '0'));
3641                         value_ok = 1;
3642                         continue;
3643                 }
3644                 if (c != ',') {
3645                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3646                         return 0;
3647                 }
3648                 if (! value_ok) {
3649                         fprintf(stderr, "No valid value before comma\n");
3650                         return 0;
3651                 }
3652                 if (nb_item < max_items) {
3653                         parsed_items[nb_item] = value;
3654                         value_ok = 0;
3655                         value = 0;
3656                 }
3657                 nb_item++;
3658         }
3659         if (nb_item >= max_items) {
3660                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3661                         item_name, nb_item + 1, max_items);
3662                 return 0;
3663         }
3664         parsed_items[nb_item++] = value;
3665         if (! check_unique_values)
3666                 return nb_item;
3667
3668         /*
3669          * Then, check that all values in the list are different.
3670          * No optimization here...
3671          */
3672         for (i = 0; i < nb_item; i++) {
3673                 for (j = i + 1; j < nb_item; j++) {
3674                         if (parsed_items[j] == parsed_items[i]) {
3675                                 fprintf(stderr,
3676                                         "duplicated %s %u at index %u and %u\n",
3677                                         item_name, parsed_items[i], i, j);
3678                                 return 0;
3679                         }
3680                 }
3681         }
3682         return nb_item;
3683 }
3684
3685 struct cmd_set_list_result {
3686         cmdline_fixed_string_t cmd_keyword;
3687         cmdline_fixed_string_t list_name;
3688         cmdline_fixed_string_t list_of_items;
3689 };
3690
3691 static void cmd_set_list_parsed(void *parsed_result,
3692                                 __rte_unused struct cmdline *cl,
3693                                 __rte_unused void *data)
3694 {
3695         struct cmd_set_list_result *res;
3696         union {
3697                 unsigned int lcorelist[RTE_MAX_LCORE];
3698                 unsigned int portlist[RTE_MAX_ETHPORTS];
3699         } parsed_items;
3700         unsigned int nb_item;
3701
3702         if (test_done == 0) {
3703                 fprintf(stderr, "Please stop forwarding first\n");
3704                 return;
3705         }
3706
3707         res = parsed_result;
3708         if (!strcmp(res->list_name, "corelist")) {
3709                 nb_item = parse_item_list(res->list_of_items, "core",
3710                                           RTE_MAX_LCORE,
3711                                           parsed_items.lcorelist, 1);
3712                 if (nb_item > 0) {
3713                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3714                         fwd_config_setup();
3715                 }
3716                 return;
3717         }
3718         if (!strcmp(res->list_name, "portlist")) {
3719                 nb_item = parse_item_list(res->list_of_items, "port",
3720                                           RTE_MAX_ETHPORTS,
3721                                           parsed_items.portlist, 1);
3722                 if (nb_item > 0) {
3723                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3724                         fwd_config_setup();
3725                 }
3726         }
3727 }
3728
3729 cmdline_parse_token_string_t cmd_set_list_keyword =
3730         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3731                                  "set");
3732 cmdline_parse_token_string_t cmd_set_list_name =
3733         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3734                                  "corelist#portlist");
3735 cmdline_parse_token_string_t cmd_set_list_of_items =
3736         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3737                                  NULL);
3738
3739 cmdline_parse_inst_t cmd_set_fwd_list = {
3740         .f = cmd_set_list_parsed,
3741         .data = NULL,
3742         .help_str = "set corelist|portlist <list0[,list1]*>",
3743         .tokens = {
3744                 (void *)&cmd_set_list_keyword,
3745                 (void *)&cmd_set_list_name,
3746                 (void *)&cmd_set_list_of_items,
3747                 NULL,
3748         },
3749 };
3750
3751 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3752
3753 struct cmd_setmask_result {
3754         cmdline_fixed_string_t set;
3755         cmdline_fixed_string_t mask;
3756         uint64_t hexavalue;
3757 };
3758
3759 static void cmd_set_mask_parsed(void *parsed_result,
3760                                 __rte_unused struct cmdline *cl,
3761                                 __rte_unused void *data)
3762 {
3763         struct cmd_setmask_result *res = parsed_result;
3764
3765         if (test_done == 0) {
3766                 fprintf(stderr, "Please stop forwarding first\n");
3767                 return;
3768         }
3769         if (!strcmp(res->mask, "coremask")) {
3770                 set_fwd_lcores_mask(res->hexavalue);
3771                 fwd_config_setup();
3772         } else if (!strcmp(res->mask, "portmask")) {
3773                 set_fwd_ports_mask(res->hexavalue);
3774                 fwd_config_setup();
3775         }
3776 }
3777
3778 cmdline_parse_token_string_t cmd_setmask_set =
3779         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3780 cmdline_parse_token_string_t cmd_setmask_mask =
3781         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3782                                  "coremask#portmask");
3783 cmdline_parse_token_num_t cmd_setmask_value =
3784         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3785
3786 cmdline_parse_inst_t cmd_set_fwd_mask = {
3787         .f = cmd_set_mask_parsed,
3788         .data = NULL,
3789         .help_str = "set coremask|portmask <hexadecimal value>",
3790         .tokens = {
3791                 (void *)&cmd_setmask_set,
3792                 (void *)&cmd_setmask_mask,
3793                 (void *)&cmd_setmask_value,
3794                 NULL,
3795         },
3796 };
3797
3798 /*
3799  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3800  */
3801 struct cmd_set_result {
3802         cmdline_fixed_string_t set;
3803         cmdline_fixed_string_t what;
3804         uint16_t value;
3805 };
3806
3807 static void cmd_set_parsed(void *parsed_result,
3808                            __rte_unused struct cmdline *cl,
3809                            __rte_unused void *data)
3810 {
3811         struct cmd_set_result *res = parsed_result;
3812         if (!strcmp(res->what, "nbport")) {
3813                 set_fwd_ports_number(res->value);
3814                 fwd_config_setup();
3815         } else if (!strcmp(res->what, "nbcore")) {
3816                 set_fwd_lcores_number(res->value);
3817                 fwd_config_setup();
3818         } else if (!strcmp(res->what, "burst"))
3819                 set_nb_pkt_per_burst(res->value);
3820         else if (!strcmp(res->what, "verbose"))
3821                 set_verbose_level(res->value);
3822 }
3823
3824 cmdline_parse_token_string_t cmd_set_set =
3825         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3826 cmdline_parse_token_string_t cmd_set_what =
3827         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3828                                  "nbport#nbcore#burst#verbose");
3829 cmdline_parse_token_num_t cmd_set_value =
3830         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3831
3832 cmdline_parse_inst_t cmd_set_numbers = {
3833         .f = cmd_set_parsed,
3834         .data = NULL,
3835         .help_str = "set nbport|nbcore|burst|verbose <value>",
3836         .tokens = {
3837                 (void *)&cmd_set_set,
3838                 (void *)&cmd_set_what,
3839                 (void *)&cmd_set_value,
3840                 NULL,
3841         },
3842 };
3843
3844 /* *** SET LOG LEVEL CONFIGURATION *** */
3845
3846 struct cmd_set_log_result {
3847         cmdline_fixed_string_t set;
3848         cmdline_fixed_string_t log;
3849         cmdline_fixed_string_t type;
3850         uint32_t level;
3851 };
3852
3853 static void
3854 cmd_set_log_parsed(void *parsed_result,
3855                    __rte_unused struct cmdline *cl,
3856                    __rte_unused void *data)
3857 {
3858         struct cmd_set_log_result *res;
3859         int ret;
3860
3861         res = parsed_result;
3862         if (!strcmp(res->type, "global"))
3863                 rte_log_set_global_level(res->level);
3864         else {
3865                 ret = rte_log_set_level_regexp(res->type, res->level);
3866                 if (ret < 0)
3867                         fprintf(stderr, "Unable to set log level\n");
3868         }
3869 }
3870
3871 cmdline_parse_token_string_t cmd_set_log_set =
3872         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3873 cmdline_parse_token_string_t cmd_set_log_log =
3874         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3875 cmdline_parse_token_string_t cmd_set_log_type =
3876         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3877 cmdline_parse_token_num_t cmd_set_log_level =
3878         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3879
3880 cmdline_parse_inst_t cmd_set_log = {
3881         .f = cmd_set_log_parsed,
3882         .data = NULL,
3883         .help_str = "set log global|<type> <level>",
3884         .tokens = {
3885                 (void *)&cmd_set_log_set,
3886                 (void *)&cmd_set_log_log,
3887                 (void *)&cmd_set_log_type,
3888                 (void *)&cmd_set_log_level,
3889                 NULL,
3890         },
3891 };
3892
3893 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3894
3895 struct cmd_set_rxoffs_result {
3896         cmdline_fixed_string_t cmd_keyword;
3897         cmdline_fixed_string_t rxoffs;
3898         cmdline_fixed_string_t seg_offsets;
3899 };
3900
3901 static void
3902 cmd_set_rxoffs_parsed(void *parsed_result,
3903                       __rte_unused struct cmdline *cl,
3904                       __rte_unused void *data)
3905 {
3906         struct cmd_set_rxoffs_result *res;
3907         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3908         unsigned int nb_segs;
3909
3910         res = parsed_result;
3911         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3912                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3913         if (nb_segs > 0)
3914                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3915         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3916 }
3917
3918 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3919         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3920                                  cmd_keyword, "set");
3921 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3922         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3923                                  rxoffs, "rxoffs");
3924 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3925         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3926                                  seg_offsets, NULL);
3927
3928 cmdline_parse_inst_t cmd_set_rxoffs = {
3929         .f = cmd_set_rxoffs_parsed,
3930         .data = NULL,
3931         .help_str = "set rxoffs <len0[,len1]*>",
3932         .tokens = {
3933                 (void *)&cmd_set_rxoffs_keyword,
3934                 (void *)&cmd_set_rxoffs_name,
3935                 (void *)&cmd_set_rxoffs_offsets,
3936                 NULL,
3937         },
3938 };
3939
3940 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3941
3942 struct cmd_set_rxpkts_result {
3943         cmdline_fixed_string_t cmd_keyword;
3944         cmdline_fixed_string_t rxpkts;
3945         cmdline_fixed_string_t seg_lengths;
3946 };
3947
3948 static void
3949 cmd_set_rxpkts_parsed(void *parsed_result,
3950                       __rte_unused struct cmdline *cl,
3951                       __rte_unused void *data)
3952 {
3953         struct cmd_set_rxpkts_result *res;
3954         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3955         unsigned int nb_segs;
3956
3957         res = parsed_result;
3958         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3959                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3960         if (nb_segs > 0)
3961                 set_rx_pkt_segments(seg_lengths, nb_segs);
3962         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3963 }
3964
3965 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3966         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3967                                  cmd_keyword, "set");
3968 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3969         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3970                                  rxpkts, "rxpkts");
3971 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3972         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3973                                  seg_lengths, NULL);
3974
3975 cmdline_parse_inst_t cmd_set_rxpkts = {
3976         .f = cmd_set_rxpkts_parsed,
3977         .data = NULL,
3978         .help_str = "set rxpkts <len0[,len1]*>",
3979         .tokens = {
3980                 (void *)&cmd_set_rxpkts_keyword,
3981                 (void *)&cmd_set_rxpkts_name,
3982                 (void *)&cmd_set_rxpkts_lengths,
3983                 NULL,
3984         },
3985 };
3986
3987 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3988
3989 struct cmd_set_txpkts_result {
3990         cmdline_fixed_string_t cmd_keyword;
3991         cmdline_fixed_string_t txpkts;
3992         cmdline_fixed_string_t seg_lengths;
3993 };
3994
3995 static void
3996 cmd_set_txpkts_parsed(void *parsed_result,
3997                       __rte_unused struct cmdline *cl,
3998                       __rte_unused void *data)
3999 {
4000         struct cmd_set_txpkts_result *res;
4001         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4002         unsigned int nb_segs;
4003
4004         res = parsed_result;
4005         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4006                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4007         if (nb_segs > 0)
4008                 set_tx_pkt_segments(seg_lengths, nb_segs);
4009 }
4010
4011 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4012         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4013                                  cmd_keyword, "set");
4014 cmdline_parse_token_string_t cmd_set_txpkts_name =
4015         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4016                                  txpkts, "txpkts");
4017 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4018         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4019                                  seg_lengths, NULL);
4020
4021 cmdline_parse_inst_t cmd_set_txpkts = {
4022         .f = cmd_set_txpkts_parsed,
4023         .data = NULL,
4024         .help_str = "set txpkts <len0[,len1]*>",
4025         .tokens = {
4026                 (void *)&cmd_set_txpkts_keyword,
4027                 (void *)&cmd_set_txpkts_name,
4028                 (void *)&cmd_set_txpkts_lengths,
4029                 NULL,
4030         },
4031 };
4032
4033 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4034
4035 struct cmd_set_txsplit_result {
4036         cmdline_fixed_string_t cmd_keyword;
4037         cmdline_fixed_string_t txsplit;
4038         cmdline_fixed_string_t mode;
4039 };
4040
4041 static void
4042 cmd_set_txsplit_parsed(void *parsed_result,
4043                       __rte_unused struct cmdline *cl,
4044                       __rte_unused void *data)
4045 {
4046         struct cmd_set_txsplit_result *res;
4047
4048         res = parsed_result;
4049         set_tx_pkt_split(res->mode);
4050 }
4051
4052 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4053         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4054                                  cmd_keyword, "set");
4055 cmdline_parse_token_string_t cmd_set_txsplit_name =
4056         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4057                                  txsplit, "txsplit");
4058 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4059         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4060                                  mode, NULL);
4061
4062 cmdline_parse_inst_t cmd_set_txsplit = {
4063         .f = cmd_set_txsplit_parsed,
4064         .data = NULL,
4065         .help_str = "set txsplit on|off|rand",
4066         .tokens = {
4067                 (void *)&cmd_set_txsplit_keyword,
4068                 (void *)&cmd_set_txsplit_name,
4069                 (void *)&cmd_set_txsplit_mode,
4070                 NULL,
4071         },
4072 };
4073
4074 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4075
4076 struct cmd_set_txtimes_result {
4077         cmdline_fixed_string_t cmd_keyword;
4078         cmdline_fixed_string_t txtimes;
4079         cmdline_fixed_string_t tx_times;
4080 };
4081
4082 static void
4083 cmd_set_txtimes_parsed(void *parsed_result,
4084                        __rte_unused struct cmdline *cl,
4085                        __rte_unused void *data)
4086 {
4087         struct cmd_set_txtimes_result *res;
4088         unsigned int tx_times[2] = {0, 0};
4089         unsigned int n_times;
4090
4091         res = parsed_result;
4092         n_times = parse_item_list(res->tx_times, "tx times",
4093                                   2, tx_times, 0);
4094         if (n_times == 2)
4095                 set_tx_pkt_times(tx_times);
4096 }
4097
4098 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4099         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4100                                  cmd_keyword, "set");
4101 cmdline_parse_token_string_t cmd_set_txtimes_name =
4102         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4103                                  txtimes, "txtimes");
4104 cmdline_parse_token_string_t cmd_set_txtimes_value =
4105         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4106                                  tx_times, NULL);
4107
4108 cmdline_parse_inst_t cmd_set_txtimes = {
4109         .f = cmd_set_txtimes_parsed,
4110         .data = NULL,
4111         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4112         .tokens = {
4113                 (void *)&cmd_set_txtimes_keyword,
4114                 (void *)&cmd_set_txtimes_name,
4115                 (void *)&cmd_set_txtimes_value,
4116                 NULL,
4117         },
4118 };
4119
4120 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4121 struct cmd_rx_vlan_filter_all_result {
4122         cmdline_fixed_string_t rx_vlan;
4123         cmdline_fixed_string_t what;
4124         cmdline_fixed_string_t all;
4125         portid_t port_id;
4126 };
4127
4128 static void
4129 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4130                               __rte_unused struct cmdline *cl,
4131                               __rte_unused void *data)
4132 {
4133         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4134
4135         if (!strcmp(res->what, "add"))
4136                 rx_vlan_all_filter_set(res->port_id, 1);
4137         else
4138                 rx_vlan_all_filter_set(res->port_id, 0);
4139 }
4140
4141 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4142         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4143                                  rx_vlan, "rx_vlan");
4144 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4145         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4146                                  what, "add#rm");
4147 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4148         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4149                                  all, "all");
4150 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4151         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4152                               port_id, RTE_UINT16);
4153
4154 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4155         .f = cmd_rx_vlan_filter_all_parsed,
4156         .data = NULL,
4157         .help_str = "rx_vlan add|rm all <port_id>: "
4158                 "Add/Remove all identifiers to/from the set of VLAN "
4159                 "identifiers filtered by a port",
4160         .tokens = {
4161                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4162                 (void *)&cmd_rx_vlan_filter_all_what,
4163                 (void *)&cmd_rx_vlan_filter_all_all,
4164                 (void *)&cmd_rx_vlan_filter_all_portid,
4165                 NULL,
4166         },
4167 };
4168
4169 /* *** VLAN OFFLOAD SET ON A PORT *** */
4170 struct cmd_vlan_offload_result {
4171         cmdline_fixed_string_t vlan;
4172         cmdline_fixed_string_t set;
4173         cmdline_fixed_string_t vlan_type;
4174         cmdline_fixed_string_t what;
4175         cmdline_fixed_string_t on;
4176         cmdline_fixed_string_t port_id;
4177 };
4178
4179 static void
4180 cmd_vlan_offload_parsed(void *parsed_result,
4181                           __rte_unused struct cmdline *cl,
4182                           __rte_unused void *data)
4183 {
4184         int on;
4185         struct cmd_vlan_offload_result *res = parsed_result;
4186         char *str;
4187         int i, len = 0;
4188         portid_t port_id = 0;
4189         unsigned int tmp;
4190
4191         str = res->port_id;
4192         len = strnlen(str, STR_TOKEN_SIZE);
4193         i = 0;
4194         /* Get port_id first */
4195         while(i < len){
4196                 if(str[i] == ',')
4197                         break;
4198
4199                 i++;
4200         }
4201         str[i]='\0';
4202         tmp = strtoul(str, NULL, 0);
4203         /* If port_id greater that what portid_t can represent, return */
4204         if(tmp >= RTE_MAX_ETHPORTS)
4205                 return;
4206         port_id = (portid_t)tmp;
4207
4208         if (!strcmp(res->on, "on"))
4209                 on = 1;
4210         else
4211                 on = 0;
4212
4213         if (!strcmp(res->what, "strip"))
4214                 rx_vlan_strip_set(port_id,  on);
4215         else if(!strcmp(res->what, "stripq")){
4216                 uint16_t queue_id = 0;
4217
4218                 /* No queue_id, return */
4219                 if(i + 1 >= len) {
4220                         fprintf(stderr, "must specify (port,queue_id)\n");
4221                         return;
4222                 }
4223                 tmp = strtoul(str + i + 1, NULL, 0);
4224                 /* If queue_id greater that what 16-bits can represent, return */
4225                 if(tmp > 0xffff)
4226                         return;
4227
4228                 queue_id = (uint16_t)tmp;
4229                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4230         }
4231         else if (!strcmp(res->what, "filter"))
4232                 rx_vlan_filter_set(port_id, on);
4233         else if (!strcmp(res->what, "qinq_strip"))
4234                 rx_vlan_qinq_strip_set(port_id, on);
4235         else
4236                 vlan_extend_set(port_id, on);
4237
4238         return;
4239 }
4240
4241 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4242         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4243                                  vlan, "vlan");
4244 cmdline_parse_token_string_t cmd_vlan_offload_set =
4245         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4246                                  set, "set");
4247 cmdline_parse_token_string_t cmd_vlan_offload_what =
4248         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4249                                 what, "strip#filter#qinq_strip#extend#stripq");
4250 cmdline_parse_token_string_t cmd_vlan_offload_on =
4251         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4252                               on, "on#off");
4253 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4254         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4255                               port_id, NULL);
4256
4257 cmdline_parse_inst_t cmd_vlan_offload = {
4258         .f = cmd_vlan_offload_parsed,
4259         .data = NULL,
4260         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4261                 "<port_id[,queue_id]>: "
4262                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4263         .tokens = {
4264                 (void *)&cmd_vlan_offload_vlan,
4265                 (void *)&cmd_vlan_offload_set,
4266                 (void *)&cmd_vlan_offload_what,
4267                 (void *)&cmd_vlan_offload_on,
4268                 (void *)&cmd_vlan_offload_portid,
4269                 NULL,
4270         },
4271 };
4272
4273 /* *** VLAN TPID SET ON A PORT *** */
4274 struct cmd_vlan_tpid_result {
4275         cmdline_fixed_string_t vlan;
4276         cmdline_fixed_string_t set;
4277         cmdline_fixed_string_t vlan_type;
4278         cmdline_fixed_string_t what;
4279         uint16_t tp_id;
4280         portid_t port_id;
4281 };
4282
4283 static void
4284 cmd_vlan_tpid_parsed(void *parsed_result,
4285                           __rte_unused struct cmdline *cl,
4286                           __rte_unused void *data)
4287 {
4288         struct cmd_vlan_tpid_result *res = parsed_result;
4289         enum rte_vlan_type vlan_type;
4290
4291         if (!strcmp(res->vlan_type, "inner"))
4292                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4293         else if (!strcmp(res->vlan_type, "outer"))
4294                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4295         else {
4296                 fprintf(stderr, "Unknown vlan type\n");
4297                 return;
4298         }
4299         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4300 }
4301
4302 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4303         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4304                                  vlan, "vlan");
4305 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4306         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4307                                  set, "set");
4308 cmdline_parse_token_string_t cmd_vlan_type =
4309         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4310                                  vlan_type, "inner#outer");
4311 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4312         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4313                                  what, "tpid");
4314 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4315         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4316                               tp_id, RTE_UINT16);
4317 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4318         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4319                               port_id, RTE_UINT16);
4320
4321 cmdline_parse_inst_t cmd_vlan_tpid = {
4322         .f = cmd_vlan_tpid_parsed,
4323         .data = NULL,
4324         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4325                 "Set the VLAN Ether type",
4326         .tokens = {
4327                 (void *)&cmd_vlan_tpid_vlan,
4328                 (void *)&cmd_vlan_tpid_set,
4329                 (void *)&cmd_vlan_type,
4330                 (void *)&cmd_vlan_tpid_what,
4331                 (void *)&cmd_vlan_tpid_tpid,
4332                 (void *)&cmd_vlan_tpid_portid,
4333                 NULL,
4334         },
4335 };
4336
4337 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4338 struct cmd_rx_vlan_filter_result {
4339         cmdline_fixed_string_t rx_vlan;
4340         cmdline_fixed_string_t what;
4341         uint16_t vlan_id;
4342         portid_t port_id;
4343 };
4344
4345 static void
4346 cmd_rx_vlan_filter_parsed(void *parsed_result,
4347                           __rte_unused struct cmdline *cl,
4348                           __rte_unused void *data)
4349 {
4350         struct cmd_rx_vlan_filter_result *res = parsed_result;
4351
4352         if (!strcmp(res->what, "add"))
4353                 rx_vft_set(res->port_id, res->vlan_id, 1);
4354         else
4355                 rx_vft_set(res->port_id, res->vlan_id, 0);
4356 }
4357
4358 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4359         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4360                                  rx_vlan, "rx_vlan");
4361 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4362         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4363                                  what, "add#rm");
4364 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4365         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4366                               vlan_id, RTE_UINT16);
4367 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4368         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4369                               port_id, RTE_UINT16);
4370
4371 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4372         .f = cmd_rx_vlan_filter_parsed,
4373         .data = NULL,
4374         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4375                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4376                 "identifiers filtered by a port",
4377         .tokens = {
4378                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4379                 (void *)&cmd_rx_vlan_filter_what,
4380                 (void *)&cmd_rx_vlan_filter_vlanid,
4381                 (void *)&cmd_rx_vlan_filter_portid,
4382                 NULL,
4383         },
4384 };
4385
4386 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4387 struct cmd_tx_vlan_set_result {
4388         cmdline_fixed_string_t tx_vlan;
4389         cmdline_fixed_string_t set;
4390         portid_t port_id;
4391         uint16_t vlan_id;
4392 };
4393
4394 static void
4395 cmd_tx_vlan_set_parsed(void *parsed_result,
4396                        __rte_unused struct cmdline *cl,
4397                        __rte_unused void *data)
4398 {
4399         struct cmd_tx_vlan_set_result *res = parsed_result;
4400
4401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4402                 return;
4403
4404         if (!port_is_stopped(res->port_id)) {
4405                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4406                 return;
4407         }
4408
4409         tx_vlan_set(res->port_id, res->vlan_id);
4410
4411         cmd_reconfig_device_queue(res->port_id, 1, 1);
4412 }
4413
4414 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4415         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4416                                  tx_vlan, "tx_vlan");
4417 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4418         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4419                                  set, "set");
4420 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4421         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4422                               port_id, RTE_UINT16);
4423 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4424         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4425                               vlan_id, RTE_UINT16);
4426
4427 cmdline_parse_inst_t cmd_tx_vlan_set = {
4428         .f = cmd_tx_vlan_set_parsed,
4429         .data = NULL,
4430         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4431                 "Enable hardware insertion of a single VLAN header "
4432                 "with a given TAG Identifier in packets sent on a port",
4433         .tokens = {
4434                 (void *)&cmd_tx_vlan_set_tx_vlan,
4435                 (void *)&cmd_tx_vlan_set_set,
4436                 (void *)&cmd_tx_vlan_set_portid,
4437                 (void *)&cmd_tx_vlan_set_vlanid,
4438                 NULL,
4439         },
4440 };
4441
4442 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4443 struct cmd_tx_vlan_set_qinq_result {
4444         cmdline_fixed_string_t tx_vlan;
4445         cmdline_fixed_string_t set;
4446         portid_t port_id;
4447         uint16_t vlan_id;
4448         uint16_t vlan_id_outer;
4449 };
4450
4451 static void
4452 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4453                             __rte_unused struct cmdline *cl,
4454                             __rte_unused void *data)
4455 {
4456         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4457
4458         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4459                 return;
4460
4461         if (!port_is_stopped(res->port_id)) {
4462                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4463                 return;
4464         }
4465
4466         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4467
4468         cmd_reconfig_device_queue(res->port_id, 1, 1);
4469 }
4470
4471 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4472         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4473                 tx_vlan, "tx_vlan");
4474 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4475         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4476                 set, "set");
4477 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4478         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4479                 port_id, RTE_UINT16);
4480 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4481         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4482                 vlan_id, RTE_UINT16);
4483 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4484         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4485                 vlan_id_outer, RTE_UINT16);
4486
4487 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4488         .f = cmd_tx_vlan_set_qinq_parsed,
4489         .data = NULL,
4490         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4491                 "Enable hardware insertion of double VLAN header "
4492                 "with given TAG Identifiers in packets sent on a port",
4493         .tokens = {
4494                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4495                 (void *)&cmd_tx_vlan_set_qinq_set,
4496                 (void *)&cmd_tx_vlan_set_qinq_portid,
4497                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4498                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4499                 NULL,
4500         },
4501 };
4502
4503 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4504 struct cmd_tx_vlan_set_pvid_result {
4505         cmdline_fixed_string_t tx_vlan;
4506         cmdline_fixed_string_t set;
4507         cmdline_fixed_string_t pvid;
4508         portid_t port_id;
4509         uint16_t vlan_id;
4510         cmdline_fixed_string_t mode;
4511 };
4512
4513 static void
4514 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4515                             __rte_unused struct cmdline *cl,
4516                             __rte_unused void *data)
4517 {
4518         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4519
4520         if (strcmp(res->mode, "on") == 0)
4521                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4522         else
4523                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4524 }
4525
4526 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4527         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4528                                  tx_vlan, "tx_vlan");
4529 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4530         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4531                                  set, "set");
4532 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4533         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4534                                  pvid, "pvid");
4535 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4536         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4537                              port_id, RTE_UINT16);
4538 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4539         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4540                               vlan_id, RTE_UINT16);
4541 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4542         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4543                                  mode, "on#off");
4544
4545 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4546         .f = cmd_tx_vlan_set_pvid_parsed,
4547         .data = NULL,
4548         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4549         .tokens = {
4550                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4551                 (void *)&cmd_tx_vlan_set_pvid_set,
4552                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4553                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4554                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4555                 (void *)&cmd_tx_vlan_set_pvid_mode,
4556                 NULL,
4557         },
4558 };
4559
4560 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4561 struct cmd_tx_vlan_reset_result {
4562         cmdline_fixed_string_t tx_vlan;
4563         cmdline_fixed_string_t reset;
4564         portid_t port_id;
4565 };
4566
4567 static void
4568 cmd_tx_vlan_reset_parsed(void *parsed_result,
4569                          __rte_unused struct cmdline *cl,
4570                          __rte_unused void *data)
4571 {
4572         struct cmd_tx_vlan_reset_result *res = parsed_result;
4573
4574         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4575                 return;
4576
4577         if (!port_is_stopped(res->port_id)) {
4578                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4579                 return;
4580         }
4581
4582         tx_vlan_reset(res->port_id);
4583
4584         cmd_reconfig_device_queue(res->port_id, 1, 1);
4585 }
4586
4587 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4588         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4589                                  tx_vlan, "tx_vlan");
4590 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4591         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4592                                  reset, "reset");
4593 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4594         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4595                               port_id, RTE_UINT16);
4596
4597 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4598         .f = cmd_tx_vlan_reset_parsed,
4599         .data = NULL,
4600         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4601                 "VLAN header in packets sent on a port",
4602         .tokens = {
4603                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4604                 (void *)&cmd_tx_vlan_reset_reset,
4605                 (void *)&cmd_tx_vlan_reset_portid,
4606                 NULL,
4607         },
4608 };
4609
4610
4611 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4612 struct cmd_csum_result {
4613         cmdline_fixed_string_t csum;
4614         cmdline_fixed_string_t mode;
4615         cmdline_fixed_string_t proto;
4616         cmdline_fixed_string_t hwsw;
4617         portid_t port_id;
4618 };
4619
4620 static void
4621 csum_show(int port_id)
4622 {
4623         struct rte_eth_dev_info dev_info;
4624         uint64_t tx_offloads;
4625         int ret;
4626
4627         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4628         printf("Parse tunnel is %s\n",
4629                 (ports[port_id].parse_tunnel) ? "on" : "off");
4630         printf("IP checksum offload is %s\n",
4631                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4632         printf("UDP checksum offload is %s\n",
4633                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4634         printf("TCP checksum offload is %s\n",
4635                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4636         printf("SCTP checksum offload is %s\n",
4637                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4638         printf("Outer-Ip checksum offload is %s\n",
4639                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4640         printf("Outer-Udp checksum offload is %s\n",
4641                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4642
4643         /* display warnings if configuration is not supported by the NIC */
4644         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4645         if (ret != 0)
4646                 return;
4647
4648         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4649                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4650                 fprintf(stderr,
4651                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4652                         port_id);
4653         }
4654         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4655                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4656                 fprintf(stderr,
4657                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4658                         port_id);
4659         }
4660         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4661                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4662                 fprintf(stderr,
4663                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4664                         port_id);
4665         }
4666         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4667                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4668                 fprintf(stderr,
4669                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4670                         port_id);
4671         }
4672         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4673                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4674                 fprintf(stderr,
4675                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4676                         port_id);
4677         }
4678         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4679                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4680                         == 0) {
4681                 fprintf(stderr,
4682                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4683                         port_id);
4684         }
4685 }
4686
4687 static void
4688 cmd_config_queue_tx_offloads(struct rte_port *port)
4689 {
4690         int k;
4691
4692         /* Apply queue tx offloads configuration */
4693         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4694                 port->tx_conf[k].offloads =
4695                         port->dev_conf.txmode.offloads;
4696 }
4697
4698 static void
4699 cmd_csum_parsed(void *parsed_result,
4700                        __rte_unused struct cmdline *cl,
4701                        __rte_unused void *data)
4702 {
4703         struct cmd_csum_result *res = parsed_result;
4704         int hw = 0;
4705         uint64_t csum_offloads = 0;
4706         struct rte_eth_dev_info dev_info;
4707         int ret;
4708
4709         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4710                 fprintf(stderr, "invalid port %d\n", res->port_id);
4711                 return;
4712         }
4713         if (!port_is_stopped(res->port_id)) {
4714                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4715                 return;
4716         }
4717
4718         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4719         if (ret != 0)
4720                 return;
4721
4722         if (!strcmp(res->mode, "set")) {
4723
4724                 if (!strcmp(res->hwsw, "hw"))
4725                         hw = 1;
4726
4727                 if (!strcmp(res->proto, "ip")) {
4728                         if (hw == 0 || (dev_info.tx_offload_capa &
4729                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4730                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4731                         } else {
4732                                 fprintf(stderr,
4733                                         "IP checksum offload is not supported by port %u\n",
4734                                         res->port_id);
4735                         }
4736                 } else if (!strcmp(res->proto, "udp")) {
4737                         if (hw == 0 || (dev_info.tx_offload_capa &
4738                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4739                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4740                         } else {
4741                                 fprintf(stderr,
4742                                         "UDP checksum offload is not supported by port %u\n",
4743                                         res->port_id);
4744                         }
4745                 } else if (!strcmp(res->proto, "tcp")) {
4746                         if (hw == 0 || (dev_info.tx_offload_capa &
4747                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4748                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4749                         } else {
4750                                 fprintf(stderr,
4751                                         "TCP checksum offload is not supported by port %u\n",
4752                                         res->port_id);
4753                         }
4754                 } else if (!strcmp(res->proto, "sctp")) {
4755                         if (hw == 0 || (dev_info.tx_offload_capa &
4756                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4757                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4758                         } else {
4759                                 fprintf(stderr,
4760                                         "SCTP checksum offload is not supported by port %u\n",
4761                                         res->port_id);
4762                         }
4763                 } else if (!strcmp(res->proto, "outer-ip")) {
4764                         if (hw == 0 || (dev_info.tx_offload_capa &
4765                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4766                                 csum_offloads |=
4767                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4768                         } else {
4769                                 fprintf(stderr,
4770                                         "Outer IP checksum offload is not supported by port %u\n",
4771                                         res->port_id);
4772                         }
4773                 } else if (!strcmp(res->proto, "outer-udp")) {
4774                         if (hw == 0 || (dev_info.tx_offload_capa &
4775                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4776                                 csum_offloads |=
4777                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4778                         } else {
4779                                 fprintf(stderr,
4780                                         "Outer UDP checksum offload is not supported by port %u\n",
4781                                         res->port_id);
4782                         }
4783                 }
4784
4785                 if (hw) {
4786                         ports[res->port_id].dev_conf.txmode.offloads |=
4787                                                         csum_offloads;
4788                 } else {
4789                         ports[res->port_id].dev_conf.txmode.offloads &=
4790                                                         (~csum_offloads);
4791                 }
4792                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4793         }
4794         csum_show(res->port_id);
4795
4796         cmd_reconfig_device_queue(res->port_id, 1, 1);
4797 }
4798
4799 cmdline_parse_token_string_t cmd_csum_csum =
4800         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4801                                 csum, "csum");
4802 cmdline_parse_token_string_t cmd_csum_mode =
4803         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4804                                 mode, "set");
4805 cmdline_parse_token_string_t cmd_csum_proto =
4806         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4807                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4808 cmdline_parse_token_string_t cmd_csum_hwsw =
4809         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4810                                 hwsw, "hw#sw");
4811 cmdline_parse_token_num_t cmd_csum_portid =
4812         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4813                                 port_id, RTE_UINT16);
4814
4815 cmdline_parse_inst_t cmd_csum_set = {
4816         .f = cmd_csum_parsed,
4817         .data = NULL,
4818         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4819                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4820                 "using csum forward engine",
4821         .tokens = {
4822                 (void *)&cmd_csum_csum,
4823                 (void *)&cmd_csum_mode,
4824                 (void *)&cmd_csum_proto,
4825                 (void *)&cmd_csum_hwsw,
4826                 (void *)&cmd_csum_portid,
4827                 NULL,
4828         },
4829 };
4830
4831 cmdline_parse_token_string_t cmd_csum_mode_show =
4832         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4833                                 mode, "show");
4834
4835 cmdline_parse_inst_t cmd_csum_show = {
4836         .f = cmd_csum_parsed,
4837         .data = NULL,
4838         .help_str = "csum show <port_id>: Show checksum offload configuration",
4839         .tokens = {
4840                 (void *)&cmd_csum_csum,
4841                 (void *)&cmd_csum_mode_show,
4842                 (void *)&cmd_csum_portid,
4843                 NULL,
4844         },
4845 };
4846
4847 /* Enable/disable tunnel parsing */
4848 struct cmd_csum_tunnel_result {
4849         cmdline_fixed_string_t csum;
4850         cmdline_fixed_string_t parse;
4851         cmdline_fixed_string_t onoff;
4852         portid_t port_id;
4853 };
4854
4855 static void
4856 cmd_csum_tunnel_parsed(void *parsed_result,
4857                        __rte_unused struct cmdline *cl,
4858                        __rte_unused void *data)
4859 {
4860         struct cmd_csum_tunnel_result *res = parsed_result;
4861
4862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4863                 return;
4864
4865         if (!strcmp(res->onoff, "on"))
4866                 ports[res->port_id].parse_tunnel = 1;
4867         else
4868                 ports[res->port_id].parse_tunnel = 0;
4869
4870         csum_show(res->port_id);
4871 }
4872
4873 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4874         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4875                                 csum, "csum");
4876 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4877         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4878                                 parse, "parse-tunnel");
4879 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4880         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4881                                 onoff, "on#off");
4882 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4883         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4884                                 port_id, RTE_UINT16);
4885
4886 cmdline_parse_inst_t cmd_csum_tunnel = {
4887         .f = cmd_csum_tunnel_parsed,
4888         .data = NULL,
4889         .help_str = "csum parse-tunnel on|off <port_id>: "
4890                 "Enable/Disable parsing of tunnels for csum engine",
4891         .tokens = {
4892                 (void *)&cmd_csum_tunnel_csum,
4893                 (void *)&cmd_csum_tunnel_parse,
4894                 (void *)&cmd_csum_tunnel_onoff,
4895                 (void *)&cmd_csum_tunnel_portid,
4896                 NULL,
4897         },
4898 };
4899
4900 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4901 struct cmd_tso_set_result {
4902         cmdline_fixed_string_t tso;
4903         cmdline_fixed_string_t mode;
4904         uint16_t tso_segsz;
4905         portid_t port_id;
4906 };
4907
4908 static void
4909 cmd_tso_set_parsed(void *parsed_result,
4910                        __rte_unused struct cmdline *cl,
4911                        __rte_unused void *data)
4912 {
4913         struct cmd_tso_set_result *res = parsed_result;
4914         struct rte_eth_dev_info dev_info;
4915         int ret;
4916
4917         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4918                 return;
4919         if (!port_is_stopped(res->port_id)) {
4920                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4921                 return;
4922         }
4923
4924         if (!strcmp(res->mode, "set"))
4925                 ports[res->port_id].tso_segsz = res->tso_segsz;
4926
4927         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4928         if (ret != 0)
4929                 return;
4930
4931         if ((ports[res->port_id].tso_segsz != 0) &&
4932                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4933                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4934                         res->port_id);
4935                 return;
4936         }
4937
4938         if (ports[res->port_id].tso_segsz == 0) {
4939                 ports[res->port_id].dev_conf.txmode.offloads &=
4940                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4941                 printf("TSO for non-tunneled packets is disabled\n");
4942         } else {
4943                 ports[res->port_id].dev_conf.txmode.offloads |=
4944                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4945                 printf("TSO segment size for non-tunneled packets is %d\n",
4946                         ports[res->port_id].tso_segsz);
4947         }
4948         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4949
4950         /* display warnings if configuration is not supported by the NIC */
4951         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4952         if (ret != 0)
4953                 return;
4954
4955         if ((ports[res->port_id].tso_segsz != 0) &&
4956                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4957                 fprintf(stderr,
4958                         "Warning: TSO enabled but not supported by port %d\n",
4959                         res->port_id);
4960         }
4961
4962         cmd_reconfig_device_queue(res->port_id, 1, 1);
4963 }
4964
4965 cmdline_parse_token_string_t cmd_tso_set_tso =
4966         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4967                                 tso, "tso");
4968 cmdline_parse_token_string_t cmd_tso_set_mode =
4969         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4970                                 mode, "set");
4971 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4972         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4973                                 tso_segsz, RTE_UINT16);
4974 cmdline_parse_token_num_t cmd_tso_set_portid =
4975         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4976                                 port_id, RTE_UINT16);
4977
4978 cmdline_parse_inst_t cmd_tso_set = {
4979         .f = cmd_tso_set_parsed,
4980         .data = NULL,
4981         .help_str = "tso set <tso_segsz> <port_id>: "
4982                 "Set TSO segment size of non-tunneled packets for csum engine "
4983                 "(0 to disable)",
4984         .tokens = {
4985                 (void *)&cmd_tso_set_tso,
4986                 (void *)&cmd_tso_set_mode,
4987                 (void *)&cmd_tso_set_tso_segsz,
4988                 (void *)&cmd_tso_set_portid,
4989                 NULL,
4990         },
4991 };
4992
4993 cmdline_parse_token_string_t cmd_tso_show_mode =
4994         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4995                                 mode, "show");
4996
4997
4998 cmdline_parse_inst_t cmd_tso_show = {
4999         .f = cmd_tso_set_parsed,
5000         .data = NULL,
5001         .help_str = "tso show <port_id>: "
5002                 "Show TSO segment size of non-tunneled packets for csum engine",
5003         .tokens = {
5004                 (void *)&cmd_tso_set_tso,
5005                 (void *)&cmd_tso_show_mode,
5006                 (void *)&cmd_tso_set_portid,
5007                 NULL,
5008         },
5009 };
5010
5011 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5012 struct cmd_tunnel_tso_set_result {
5013         cmdline_fixed_string_t tso;
5014         cmdline_fixed_string_t mode;
5015         uint16_t tso_segsz;
5016         portid_t port_id;
5017 };
5018
5019 static struct rte_eth_dev_info
5020 check_tunnel_tso_nic_support(portid_t port_id)
5021 {
5022         struct rte_eth_dev_info dev_info;
5023
5024         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5025                 return dev_info;
5026
5027         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5028                 fprintf(stderr,
5029                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5030                         port_id);
5031         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5032                 fprintf(stderr,
5033                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5034                         port_id);
5035         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5036                 fprintf(stderr,
5037                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5038                         port_id);
5039         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5040                 fprintf(stderr,
5041                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5042                         port_id);
5043         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5044                 fprintf(stderr,
5045                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5046                         port_id);
5047         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5048                 fprintf(stderr,
5049                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5050                         port_id);
5051         return dev_info;
5052 }
5053
5054 static void
5055 cmd_tunnel_tso_set_parsed(void *parsed_result,
5056                           __rte_unused struct cmdline *cl,
5057                           __rte_unused void *data)
5058 {
5059         struct cmd_tunnel_tso_set_result *res = parsed_result;
5060         struct rte_eth_dev_info dev_info;
5061
5062         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5063                 return;
5064         if (!port_is_stopped(res->port_id)) {
5065                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5066                 return;
5067         }
5068
5069         if (!strcmp(res->mode, "set"))
5070                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5071
5072         dev_info = check_tunnel_tso_nic_support(res->port_id);
5073         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5074                 ports[res->port_id].dev_conf.txmode.offloads &=
5075                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5076                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5077                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5078                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5079                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5080                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5081                 printf("TSO for tunneled packets is disabled\n");
5082         } else {
5083                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5084                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5085                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5086                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5087                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5088                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5089
5090                 ports[res->port_id].dev_conf.txmode.offloads |=
5091                         (tso_offloads & dev_info.tx_offload_capa);
5092                 printf("TSO segment size for tunneled packets is %d\n",
5093                         ports[res->port_id].tunnel_tso_segsz);
5094
5095                 /* Below conditions are needed to make it work:
5096                  * (1) tunnel TSO is supported by the NIC;
5097                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5098                  * are recognized;
5099                  * (3) for tunneled pkts with outer L3 of IPv4,
5100                  * "csum set outer-ip" must be set to hw, because after tso,
5101                  * total_len of outer IP header is changed, and the checksum
5102                  * of outer IP header calculated by sw should be wrong; that
5103                  * is not necessary for IPv6 tunneled pkts because there's no
5104                  * checksum in IP header anymore.
5105                  */
5106
5107                 if (!ports[res->port_id].parse_tunnel)
5108                         fprintf(stderr,
5109                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5110                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5111                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5112                         fprintf(stderr,
5113                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5114         }
5115
5116         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5117         cmd_reconfig_device_queue(res->port_id, 1, 1);
5118 }
5119
5120 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5121         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5122                                 tso, "tunnel_tso");
5123 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5124         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5125                                 mode, "set");
5126 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5127         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5128                                 tso_segsz, RTE_UINT16);
5129 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5130         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5131                                 port_id, RTE_UINT16);
5132
5133 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5134         .f = cmd_tunnel_tso_set_parsed,
5135         .data = NULL,
5136         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5137                 "Set TSO segment size of tunneled packets for csum engine "
5138                 "(0 to disable)",
5139         .tokens = {
5140                 (void *)&cmd_tunnel_tso_set_tso,
5141                 (void *)&cmd_tunnel_tso_set_mode,
5142                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5143                 (void *)&cmd_tunnel_tso_set_portid,
5144                 NULL,
5145         },
5146 };
5147
5148 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5149         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5150                                 mode, "show");
5151
5152
5153 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5154         .f = cmd_tunnel_tso_set_parsed,
5155         .data = NULL,
5156         .help_str = "tunnel_tso show <port_id> "
5157                 "Show TSO segment size of tunneled packets for csum engine",
5158         .tokens = {
5159                 (void *)&cmd_tunnel_tso_set_tso,
5160                 (void *)&cmd_tunnel_tso_show_mode,
5161                 (void *)&cmd_tunnel_tso_set_portid,
5162                 NULL,
5163         },
5164 };
5165
5166 #ifdef RTE_LIB_GRO
5167 /* *** SET GRO FOR A PORT *** */
5168 struct cmd_gro_enable_result {
5169         cmdline_fixed_string_t cmd_set;
5170         cmdline_fixed_string_t cmd_port;
5171         cmdline_fixed_string_t cmd_keyword;
5172         cmdline_fixed_string_t cmd_onoff;
5173         portid_t cmd_pid;
5174 };
5175
5176 static void
5177 cmd_gro_enable_parsed(void *parsed_result,
5178                 __rte_unused struct cmdline *cl,
5179                 __rte_unused void *data)
5180 {
5181         struct cmd_gro_enable_result *res;
5182
5183         res = parsed_result;
5184         if (!strcmp(res->cmd_keyword, "gro"))
5185                 setup_gro(res->cmd_onoff, res->cmd_pid);
5186 }
5187
5188 cmdline_parse_token_string_t cmd_gro_enable_set =
5189         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5190                         cmd_set, "set");
5191 cmdline_parse_token_string_t cmd_gro_enable_port =
5192         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5193                         cmd_keyword, "port");
5194 cmdline_parse_token_num_t cmd_gro_enable_pid =
5195         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5196                         cmd_pid, RTE_UINT16);
5197 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5198         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5199                         cmd_keyword, "gro");
5200 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5201         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5202                         cmd_onoff, "on#off");
5203
5204 cmdline_parse_inst_t cmd_gro_enable = {
5205         .f = cmd_gro_enable_parsed,
5206         .data = NULL,
5207         .help_str = "set port <port_id> gro on|off",
5208         .tokens = {
5209                 (void *)&cmd_gro_enable_set,
5210                 (void *)&cmd_gro_enable_port,
5211                 (void *)&cmd_gro_enable_pid,
5212                 (void *)&cmd_gro_enable_keyword,
5213                 (void *)&cmd_gro_enable_onoff,
5214                 NULL,
5215         },
5216 };
5217
5218 /* *** DISPLAY GRO CONFIGURATION *** */
5219 struct cmd_gro_show_result {
5220         cmdline_fixed_string_t cmd_show;
5221         cmdline_fixed_string_t cmd_port;
5222         cmdline_fixed_string_t cmd_keyword;
5223         portid_t cmd_pid;
5224 };
5225
5226 static void
5227 cmd_gro_show_parsed(void *parsed_result,
5228                 __rte_unused struct cmdline *cl,
5229                 __rte_unused void *data)
5230 {
5231         struct cmd_gro_show_result *res;
5232
5233         res = parsed_result;
5234         if (!strcmp(res->cmd_keyword, "gro"))
5235                 show_gro(res->cmd_pid);
5236 }
5237
5238 cmdline_parse_token_string_t cmd_gro_show_show =
5239         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5240                         cmd_show, "show");
5241 cmdline_parse_token_string_t cmd_gro_show_port =
5242         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5243                         cmd_port, "port");
5244 cmdline_parse_token_num_t cmd_gro_show_pid =
5245         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5246                         cmd_pid, RTE_UINT16);
5247 cmdline_parse_token_string_t cmd_gro_show_keyword =
5248         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5249                         cmd_keyword, "gro");
5250
5251 cmdline_parse_inst_t cmd_gro_show = {
5252         .f = cmd_gro_show_parsed,
5253         .data = NULL,
5254         .help_str = "show port <port_id> gro",
5255         .tokens = {
5256                 (void *)&cmd_gro_show_show,
5257                 (void *)&cmd_gro_show_port,
5258                 (void *)&cmd_gro_show_pid,
5259                 (void *)&cmd_gro_show_keyword,
5260                 NULL,
5261         },
5262 };
5263
5264 /* *** SET FLUSH CYCLES FOR GRO *** */
5265 struct cmd_gro_flush_result {
5266         cmdline_fixed_string_t cmd_set;
5267         cmdline_fixed_string_t cmd_keyword;
5268         cmdline_fixed_string_t cmd_flush;
5269         uint8_t cmd_cycles;
5270 };
5271
5272 static void
5273 cmd_gro_flush_parsed(void *parsed_result,
5274                 __rte_unused struct cmdline *cl,
5275                 __rte_unused void *data)
5276 {
5277         struct cmd_gro_flush_result *res;
5278
5279         res = parsed_result;
5280         if ((!strcmp(res->cmd_keyword, "gro")) &&
5281                         (!strcmp(res->cmd_flush, "flush")))
5282                 setup_gro_flush_cycles(res->cmd_cycles);
5283 }
5284
5285 cmdline_parse_token_string_t cmd_gro_flush_set =
5286         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5287                         cmd_set, "set");
5288 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5289         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5290                         cmd_keyword, "gro");
5291 cmdline_parse_token_string_t cmd_gro_flush_flush =
5292         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5293                         cmd_flush, "flush");
5294 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5295         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5296                         cmd_cycles, RTE_UINT8);
5297
5298 cmdline_parse_inst_t cmd_gro_flush = {
5299         .f = cmd_gro_flush_parsed,
5300         .data = NULL,
5301         .help_str = "set gro flush <cycles>",
5302         .tokens = {
5303                 (void *)&cmd_gro_flush_set,
5304                 (void *)&cmd_gro_flush_keyword,
5305                 (void *)&cmd_gro_flush_flush,
5306                 (void *)&cmd_gro_flush_cycles,
5307                 NULL,
5308         },
5309 };
5310 #endif /* RTE_LIB_GRO */
5311
5312 #ifdef RTE_LIB_GSO
5313 /* *** ENABLE/DISABLE GSO *** */
5314 struct cmd_gso_enable_result {
5315         cmdline_fixed_string_t cmd_set;
5316         cmdline_fixed_string_t cmd_port;
5317         cmdline_fixed_string_t cmd_keyword;
5318         cmdline_fixed_string_t cmd_mode;
5319         portid_t cmd_pid;
5320 };
5321
5322 static void
5323 cmd_gso_enable_parsed(void *parsed_result,
5324                 __rte_unused struct cmdline *cl,
5325                 __rte_unused void *data)
5326 {
5327         struct cmd_gso_enable_result *res;
5328
5329         res = parsed_result;
5330         if (!strcmp(res->cmd_keyword, "gso"))
5331                 setup_gso(res->cmd_mode, res->cmd_pid);
5332 }
5333
5334 cmdline_parse_token_string_t cmd_gso_enable_set =
5335         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5336                         cmd_set, "set");
5337 cmdline_parse_token_string_t cmd_gso_enable_port =
5338         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5339                         cmd_port, "port");
5340 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5341         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5342                         cmd_keyword, "gso");
5343 cmdline_parse_token_string_t cmd_gso_enable_mode =
5344         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5345                         cmd_mode, "on#off");
5346 cmdline_parse_token_num_t cmd_gso_enable_pid =
5347         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5348                         cmd_pid, RTE_UINT16);
5349
5350 cmdline_parse_inst_t cmd_gso_enable = {
5351         .f = cmd_gso_enable_parsed,
5352         .data = NULL,
5353         .help_str = "set port <port_id> gso on|off",
5354         .tokens = {
5355                 (void *)&cmd_gso_enable_set,
5356                 (void *)&cmd_gso_enable_port,
5357                 (void *)&cmd_gso_enable_pid,
5358                 (void *)&cmd_gso_enable_keyword,
5359                 (void *)&cmd_gso_enable_mode,
5360                 NULL,
5361         },
5362 };
5363
5364 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5365 struct cmd_gso_size_result {
5366         cmdline_fixed_string_t cmd_set;
5367         cmdline_fixed_string_t cmd_keyword;
5368         cmdline_fixed_string_t cmd_segsz;
5369         uint16_t cmd_size;
5370 };
5371
5372 static void
5373 cmd_gso_size_parsed(void *parsed_result,
5374                        __rte_unused struct cmdline *cl,
5375                        __rte_unused void *data)
5376 {
5377         struct cmd_gso_size_result *res = parsed_result;
5378
5379         if (test_done == 0) {
5380                 fprintf(stderr,
5381                         "Before setting GSO segsz, please first stop forwarding\n");
5382                 return;
5383         }
5384
5385         if (!strcmp(res->cmd_keyword, "gso") &&
5386                         !strcmp(res->cmd_segsz, "segsz")) {
5387                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5388                         fprintf(stderr,
5389                                 "gso_size should be larger than %zu. Please input a legal value\n",
5390                                 RTE_GSO_SEG_SIZE_MIN);
5391                 else
5392                         gso_max_segment_size = res->cmd_size;
5393         }
5394 }
5395
5396 cmdline_parse_token_string_t cmd_gso_size_set =
5397         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5398                                 cmd_set, "set");
5399 cmdline_parse_token_string_t cmd_gso_size_keyword =
5400         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5401                                 cmd_keyword, "gso");
5402 cmdline_parse_token_string_t cmd_gso_size_segsz =
5403         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5404                                 cmd_segsz, "segsz");
5405 cmdline_parse_token_num_t cmd_gso_size_size =
5406         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5407                                 cmd_size, RTE_UINT16);
5408
5409 cmdline_parse_inst_t cmd_gso_size = {
5410         .f = cmd_gso_size_parsed,
5411         .data = NULL,
5412         .help_str = "set gso segsz <length>",
5413         .tokens = {
5414                 (void *)&cmd_gso_size_set,
5415                 (void *)&cmd_gso_size_keyword,
5416                 (void *)&cmd_gso_size_segsz,
5417                 (void *)&cmd_gso_size_size,
5418                 NULL,
5419         },
5420 };
5421
5422 /* *** SHOW GSO CONFIGURATION *** */
5423 struct cmd_gso_show_result {
5424         cmdline_fixed_string_t cmd_show;
5425         cmdline_fixed_string_t cmd_port;
5426         cmdline_fixed_string_t cmd_keyword;
5427         portid_t cmd_pid;
5428 };
5429
5430 static void
5431 cmd_gso_show_parsed(void *parsed_result,
5432                        __rte_unused struct cmdline *cl,
5433                        __rte_unused void *data)
5434 {
5435         struct cmd_gso_show_result *res = parsed_result;
5436
5437         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5438                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5439                 return;
5440         }
5441         if (!strcmp(res->cmd_keyword, "gso")) {
5442                 if (gso_ports[res->cmd_pid].enable) {
5443                         printf("Max GSO'd packet size: %uB\n"
5444                                         "Supported GSO types: TCP/IPv4, "
5445                                         "UDP/IPv4, VxLAN with inner "
5446                                         "TCP/IPv4 packet, GRE with inner "
5447                                         "TCP/IPv4 packet\n",
5448                                         gso_max_segment_size);
5449                 } else
5450                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5451         }
5452 }
5453
5454 cmdline_parse_token_string_t cmd_gso_show_show =
5455 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5456                 cmd_show, "show");
5457 cmdline_parse_token_string_t cmd_gso_show_port =
5458 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5459                 cmd_port, "port");
5460 cmdline_parse_token_string_t cmd_gso_show_keyword =
5461         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5462                                 cmd_keyword, "gso");
5463 cmdline_parse_token_num_t cmd_gso_show_pid =
5464         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5465                                 cmd_pid, RTE_UINT16);
5466
5467 cmdline_parse_inst_t cmd_gso_show = {
5468         .f = cmd_gso_show_parsed,
5469         .data = NULL,
5470         .help_str = "show port <port_id> gso",
5471         .tokens = {
5472                 (void *)&cmd_gso_show_show,
5473                 (void *)&cmd_gso_show_port,
5474                 (void *)&cmd_gso_show_pid,
5475                 (void *)&cmd_gso_show_keyword,
5476                 NULL,
5477         },
5478 };
5479 #endif /* RTE_LIB_GSO */
5480
5481 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5482 struct cmd_set_flush_rx {
5483         cmdline_fixed_string_t set;
5484         cmdline_fixed_string_t flush_rx;
5485         cmdline_fixed_string_t mode;
5486 };
5487
5488 static void
5489 cmd_set_flush_rx_parsed(void *parsed_result,
5490                 __rte_unused struct cmdline *cl,
5491                 __rte_unused void *data)
5492 {
5493         struct cmd_set_flush_rx *res = parsed_result;
5494
5495         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5496                 printf("multi-process doesn't support to flush Rx queues.\n");
5497                 return;
5498         }
5499
5500         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5501 }
5502
5503 cmdline_parse_token_string_t cmd_setflushrx_set =
5504         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5505                         set, "set");
5506 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5507         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5508                         flush_rx, "flush_rx");
5509 cmdline_parse_token_string_t cmd_setflushrx_mode =
5510         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5511                         mode, "on#off");
5512
5513
5514 cmdline_parse_inst_t cmd_set_flush_rx = {
5515         .f = cmd_set_flush_rx_parsed,
5516         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5517         .data = NULL,
5518         .tokens = {
5519                 (void *)&cmd_setflushrx_set,
5520                 (void *)&cmd_setflushrx_flush_rx,
5521                 (void *)&cmd_setflushrx_mode,
5522                 NULL,
5523         },
5524 };
5525
5526 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5527 struct cmd_set_link_check {
5528         cmdline_fixed_string_t set;
5529         cmdline_fixed_string_t link_check;
5530         cmdline_fixed_string_t mode;
5531 };
5532
5533 static void
5534 cmd_set_link_check_parsed(void *parsed_result,
5535                 __rte_unused struct cmdline *cl,
5536                 __rte_unused void *data)
5537 {
5538         struct cmd_set_link_check *res = parsed_result;
5539         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5540 }
5541
5542 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5543         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5544                         set, "set");
5545 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5547                         link_check, "link_check");
5548 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5550                         mode, "on#off");
5551
5552
5553 cmdline_parse_inst_t cmd_set_link_check = {
5554         .f = cmd_set_link_check_parsed,
5555         .help_str = "set link_check on|off: Enable/Disable link status check "
5556                     "when starting/stopping a port",
5557         .data = NULL,
5558         .tokens = {
5559                 (void *)&cmd_setlinkcheck_set,
5560                 (void *)&cmd_setlinkcheck_link_check,
5561                 (void *)&cmd_setlinkcheck_mode,
5562                 NULL,
5563         },
5564 };
5565
5566 /* *** SET NIC BYPASS MODE *** */
5567 struct cmd_set_bypass_mode_result {
5568         cmdline_fixed_string_t set;
5569         cmdline_fixed_string_t bypass;
5570         cmdline_fixed_string_t mode;
5571         cmdline_fixed_string_t value;
5572         portid_t port_id;
5573 };
5574
5575 static void
5576 cmd_set_bypass_mode_parsed(void *parsed_result,
5577                 __rte_unused struct cmdline *cl,
5578                 __rte_unused void *data)
5579 {
5580         struct cmd_set_bypass_mode_result *res = parsed_result;
5581         portid_t port_id = res->port_id;
5582         int32_t rc = -EINVAL;
5583
5584 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5585         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5586
5587         if (!strcmp(res->value, "bypass"))
5588                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5589         else if (!strcmp(res->value, "isolate"))
5590                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5591         else
5592                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5593
5594         /* Set the bypass mode for the relevant port. */
5595         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5596 #endif
5597         if (rc != 0)
5598                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5599                         port_id);
5600 }
5601
5602 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5603         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5604                         set, "set");
5605 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5606         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5607                         bypass, "bypass");
5608 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5609         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5610                         mode, "mode");
5611 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5612         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5613                         value, "normal#bypass#isolate");
5614 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5615         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5616                                 port_id, RTE_UINT16);
5617
5618 cmdline_parse_inst_t cmd_set_bypass_mode = {
5619         .f = cmd_set_bypass_mode_parsed,
5620         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5621                     "Set the NIC bypass mode for port_id",
5622         .data = NULL,
5623         .tokens = {
5624                 (void *)&cmd_setbypass_mode_set,
5625                 (void *)&cmd_setbypass_mode_bypass,
5626                 (void *)&cmd_setbypass_mode_mode,
5627                 (void *)&cmd_setbypass_mode_value,
5628                 (void *)&cmd_setbypass_mode_port,
5629                 NULL,
5630         },
5631 };
5632
5633 /* *** SET NIC BYPASS EVENT *** */
5634 struct cmd_set_bypass_event_result {
5635         cmdline_fixed_string_t set;
5636         cmdline_fixed_string_t bypass;
5637         cmdline_fixed_string_t event;
5638         cmdline_fixed_string_t event_value;
5639         cmdline_fixed_string_t mode;
5640         cmdline_fixed_string_t mode_value;
5641         portid_t port_id;
5642 };
5643
5644 static void
5645 cmd_set_bypass_event_parsed(void *parsed_result,
5646                 __rte_unused struct cmdline *cl,
5647                 __rte_unused void *data)
5648 {
5649         int32_t rc = -EINVAL;
5650         struct cmd_set_bypass_event_result *res = parsed_result;
5651         portid_t port_id = res->port_id;
5652
5653 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5654         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5655         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5656
5657         if (!strcmp(res->event_value, "timeout"))
5658                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5659         else if (!strcmp(res->event_value, "os_on"))
5660                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5661         else if (!strcmp(res->event_value, "os_off"))
5662                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5663         else if (!strcmp(res->event_value, "power_on"))
5664                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5665         else if (!strcmp(res->event_value, "power_off"))
5666                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5667         else
5668                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5669
5670         if (!strcmp(res->mode_value, "bypass"))
5671                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5672         else if (!strcmp(res->mode_value, "isolate"))
5673                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5674         else
5675                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5676
5677         /* Set the watchdog timeout. */
5678         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5679
5680                 rc = -EINVAL;
5681                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5682                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5683                                                            bypass_timeout);
5684                 }
5685                 if (rc != 0) {
5686                         fprintf(stderr,
5687                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5688                                 bypass_timeout, port_id, rc);
5689                 }
5690         }
5691
5692         /* Set the bypass event to transition to bypass mode. */
5693         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5694                                               bypass_mode);
5695 #endif
5696
5697         if (rc != 0)
5698                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5699                         port_id);
5700 }
5701
5702 cmdline_parse_token_string_t cmd_setbypass_event_set =
5703         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5704                         set, "set");
5705 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5706         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5707                         bypass, "bypass");
5708 cmdline_parse_token_string_t cmd_setbypass_event_event =
5709         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5710                         event, "event");
5711 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5712         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5713                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5714 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5715         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5716                         mode, "mode");
5717 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5718         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5719                         mode_value, "normal#bypass#isolate");
5720 cmdline_parse_token_num_t cmd_setbypass_event_port =
5721         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5722                                 port_id, RTE_UINT16);
5723
5724 cmdline_parse_inst_t cmd_set_bypass_event = {
5725         .f = cmd_set_bypass_event_parsed,
5726         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5727                 "power_off mode normal|bypass|isolate <port_id>: "
5728                 "Set the NIC bypass event mode for port_id",
5729         .data = NULL,
5730         .tokens = {
5731                 (void *)&cmd_setbypass_event_set,
5732                 (void *)&cmd_setbypass_event_bypass,
5733                 (void *)&cmd_setbypass_event_event,
5734                 (void *)&cmd_setbypass_event_event_value,
5735                 (void *)&cmd_setbypass_event_mode,
5736                 (void *)&cmd_setbypass_event_mode_value,
5737                 (void *)&cmd_setbypass_event_port,
5738                 NULL,
5739         },
5740 };
5741
5742
5743 /* *** SET NIC BYPASS TIMEOUT *** */
5744 struct cmd_set_bypass_timeout_result {
5745         cmdline_fixed_string_t set;
5746         cmdline_fixed_string_t bypass;
5747         cmdline_fixed_string_t timeout;
5748         cmdline_fixed_string_t value;
5749 };
5750
5751 static void
5752 cmd_set_bypass_timeout_parsed(void *parsed_result,
5753                 __rte_unused struct cmdline *cl,
5754                 __rte_unused void *data)
5755 {
5756         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5757
5758 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5759         if (!strcmp(res->value, "1.5"))
5760                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5761         else if (!strcmp(res->value, "2"))
5762                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5763         else if (!strcmp(res->value, "3"))
5764                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5765         else if (!strcmp(res->value, "4"))
5766                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5767         else if (!strcmp(res->value, "8"))
5768                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5769         else if (!strcmp(res->value, "16"))
5770                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5771         else if (!strcmp(res->value, "32"))
5772                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5773         else
5774                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5775 #endif
5776 }
5777
5778 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5779         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5780                         set, "set");
5781 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5782         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5783                         bypass, "bypass");
5784 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5785         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5786                         timeout, "timeout");
5787 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5788         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5789                         value, "0#1.5#2#3#4#8#16#32");
5790
5791 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5792         .f = cmd_set_bypass_timeout_parsed,
5793         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5794                 "Set the NIC bypass watchdog timeout in seconds",
5795         .data = NULL,
5796         .tokens = {
5797                 (void *)&cmd_setbypass_timeout_set,
5798                 (void *)&cmd_setbypass_timeout_bypass,
5799                 (void *)&cmd_setbypass_timeout_timeout,
5800                 (void *)&cmd_setbypass_timeout_value,
5801                 NULL,
5802         },
5803 };
5804
5805 /* *** SHOW NIC BYPASS MODE *** */
5806 struct cmd_show_bypass_config_result {
5807         cmdline_fixed_string_t show;
5808         cmdline_fixed_string_t bypass;
5809         cmdline_fixed_string_t config;
5810         portid_t port_id;
5811 };
5812
5813 static void
5814 cmd_show_bypass_config_parsed(void *parsed_result,
5815                 __rte_unused struct cmdline *cl,
5816                 __rte_unused void *data)
5817 {
5818         struct cmd_show_bypass_config_result *res = parsed_result;
5819         portid_t port_id = res->port_id;
5820         int rc = -EINVAL;
5821 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5822         uint32_t event_mode;
5823         uint32_t bypass_mode;
5824         uint32_t timeout = bypass_timeout;
5825         unsigned int i;
5826
5827         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5828                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5829         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5830                 {"UNKNOWN", "normal", "bypass", "isolate"};
5831         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5832                 "NONE",
5833                 "OS/board on",
5834                 "power supply on",
5835                 "OS/board off",
5836                 "power supply off",
5837                 "timeout"};
5838
5839         /* Display the bypass mode.*/
5840         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5841                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5842                         port_id);
5843                 return;
5844         }
5845         else {
5846                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5847                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5848
5849                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5850         }
5851
5852         /* Display the bypass timeout.*/
5853         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5854                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5855
5856         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5857
5858         /* Display the bypass events and associated modes. */
5859         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5860
5861                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5862                         fprintf(stderr,
5863                                 "\tFailed to get bypass mode for event = %s\n",
5864                                 events[i]);
5865                 } else {
5866                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5867                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5868
5869                         printf("\tbypass event: %-16s = %s\n", events[i],
5870                                 modes[event_mode]);
5871                 }
5872         }
5873 #endif
5874         if (rc != 0)
5875                 fprintf(stderr,
5876                         "\tFailed to get bypass configuration for port = %d\n",
5877                        port_id);
5878 }
5879
5880 cmdline_parse_token_string_t cmd_showbypass_config_show =
5881         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5882                         show, "show");
5883 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5884         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5885                         bypass, "bypass");
5886 cmdline_parse_token_string_t cmd_showbypass_config_config =
5887         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5888                         config, "config");
5889 cmdline_parse_token_num_t cmd_showbypass_config_port =
5890         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5891                                 port_id, RTE_UINT16);
5892
5893 cmdline_parse_inst_t cmd_show_bypass_config = {
5894         .f = cmd_show_bypass_config_parsed,
5895         .help_str = "show bypass config <port_id>: "
5896                     "Show the NIC bypass config for port_id",
5897         .data = NULL,
5898         .tokens = {
5899                 (void *)&cmd_showbypass_config_show,
5900                 (void *)&cmd_showbypass_config_bypass,
5901                 (void *)&cmd_showbypass_config_config,
5902                 (void *)&cmd_showbypass_config_port,
5903                 NULL,
5904         },
5905 };
5906
5907 #ifdef RTE_NET_BOND
5908 /* *** SET BONDING MODE *** */
5909 struct cmd_set_bonding_mode_result {
5910         cmdline_fixed_string_t set;
5911         cmdline_fixed_string_t bonding;
5912         cmdline_fixed_string_t mode;
5913         uint8_t value;
5914         portid_t port_id;
5915 };
5916
5917 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5918                 __rte_unused  struct cmdline *cl,
5919                 __rte_unused void *data)
5920 {
5921         struct cmd_set_bonding_mode_result *res = parsed_result;
5922         portid_t port_id = res->port_id;
5923         struct rte_port *port = &ports[port_id];
5924
5925         /*
5926          * Bonding mode changed means resources of device changed, like whether
5927          * started rte timer or not. Device should be restarted when resources
5928          * of device changed.
5929          */
5930         if (port->port_status != RTE_PORT_STOPPED) {
5931                 fprintf(stderr,
5932                         "\t Error: Can't set bonding mode when port %d is not stopped\n",
5933                         port_id);
5934                 return;
5935         }
5936
5937         /* Set the bonding mode for the relevant port. */
5938         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5939                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5940                         port_id);
5941 }
5942
5943 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5944 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5945                 set, "set");
5946 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5947 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5948                 bonding, "bonding");
5949 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5950 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5951                 mode, "mode");
5952 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5953 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5954                 value, RTE_UINT8);
5955 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5956 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5957                 port_id, RTE_UINT16);
5958
5959 cmdline_parse_inst_t cmd_set_bonding_mode = {
5960                 .f = cmd_set_bonding_mode_parsed,
5961                 .help_str = "set bonding mode <mode_value> <port_id>: "
5962                         "Set the bonding mode for port_id",
5963                 .data = NULL,
5964                 .tokens = {
5965                                 (void *) &cmd_setbonding_mode_set,
5966                                 (void *) &cmd_setbonding_mode_bonding,
5967                                 (void *) &cmd_setbonding_mode_mode,
5968                                 (void *) &cmd_setbonding_mode_value,
5969                                 (void *) &cmd_setbonding_mode_port,
5970                                 NULL
5971                 }
5972 };
5973
5974 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5975 struct cmd_set_bonding_lacp_dedicated_queues_result {
5976         cmdline_fixed_string_t set;
5977         cmdline_fixed_string_t bonding;
5978         cmdline_fixed_string_t lacp;
5979         cmdline_fixed_string_t dedicated_queues;
5980         portid_t port_id;
5981         cmdline_fixed_string_t mode;
5982 };
5983
5984 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5985                 __rte_unused  struct cmdline *cl,
5986                 __rte_unused void *data)
5987 {
5988         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5989         portid_t port_id = res->port_id;
5990         struct rte_port *port;
5991
5992         port = &ports[port_id];
5993
5994         /** Check if the port is not started **/
5995         if (port->port_status != RTE_PORT_STOPPED) {
5996                 fprintf(stderr, "Please stop port %d first\n", port_id);
5997                 return;
5998         }
5999
6000         if (!strcmp(res->mode, "enable")) {
6001                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
6002                         printf("Dedicate queues for LACP control packets"
6003                                         " enabled\n");
6004                 else
6005                         printf("Enabling dedicate queues for LACP control "
6006                                         "packets on port %d failed\n", port_id);
6007         } else if (!strcmp(res->mode, "disable")) {
6008                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
6009                         printf("Dedicated queues for LACP control packets "
6010                                         "disabled\n");
6011                 else
6012                         printf("Disabling dedicated queues for LACP control "
6013                                         "traffic on port %d failed\n", port_id);
6014         }
6015 }
6016
6017 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
6018 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6019                 set, "set");
6020 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6021 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6022                 bonding, "bonding");
6023 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6024 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6025                 lacp, "lacp");
6026 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6027 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6028                 dedicated_queues, "dedicated_queues");
6029 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6030 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6031                 port_id, RTE_UINT16);
6032 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6033 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6034                 mode, "enable#disable");
6035
6036 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6037                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6038                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6039                         "enable|disable: "
6040                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6041                 .data = NULL,
6042                 .tokens = {
6043                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6044                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6045                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6046                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6047                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6048                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6049                         NULL
6050                 }
6051 };
6052
6053 /* *** SET BALANCE XMIT POLICY *** */
6054 struct cmd_set_bonding_balance_xmit_policy_result {
6055         cmdline_fixed_string_t set;
6056         cmdline_fixed_string_t bonding;
6057         cmdline_fixed_string_t balance_xmit_policy;
6058         portid_t port_id;
6059         cmdline_fixed_string_t policy;
6060 };
6061
6062 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6063                 __rte_unused  struct cmdline *cl,
6064                 __rte_unused void *data)
6065 {
6066         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6067         portid_t port_id = res->port_id;
6068         uint8_t policy;
6069
6070         if (!strcmp(res->policy, "l2")) {
6071                 policy = BALANCE_XMIT_POLICY_LAYER2;
6072         } else if (!strcmp(res->policy, "l23")) {
6073                 policy = BALANCE_XMIT_POLICY_LAYER23;
6074         } else if (!strcmp(res->policy, "l34")) {
6075                 policy = BALANCE_XMIT_POLICY_LAYER34;
6076         } else {
6077                 fprintf(stderr, "\t Invalid xmit policy selection");
6078                 return;
6079         }
6080
6081         /* Set the bonding mode for the relevant port. */
6082         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6083                 fprintf(stderr,
6084                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6085                         port_id);
6086         }
6087 }
6088
6089 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6090 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6091                 set, "set");
6092 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6093 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6094                 bonding, "bonding");
6095 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6096 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6097                 balance_xmit_policy, "balance_xmit_policy");
6098 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6099 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6100                 port_id, RTE_UINT16);
6101 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6102 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6103                 policy, "l2#l23#l34");
6104
6105 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6106                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6107                 .help_str = "set bonding balance_xmit_policy <port_id> "
6108                         "l2|l23|l34: "
6109                         "Set the bonding balance_xmit_policy for port_id",
6110                 .data = NULL,
6111                 .tokens = {
6112                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6113                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6114                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6115                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6116                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6117                                 NULL
6118                 }
6119 };
6120
6121 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6122 struct cmd_show_bonding_lacp_info_result {
6123         cmdline_fixed_string_t show;
6124         cmdline_fixed_string_t bonding;
6125         cmdline_fixed_string_t lacp;
6126         cmdline_fixed_string_t info;
6127         portid_t port_id;
6128 };
6129
6130 static void port_param_show(struct port_params *params)
6131 {
6132         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6133
6134         printf("\t\tsystem priority: %u\n", params->system_priority);
6135         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6136         printf("\t\tsystem mac address: %s\n", buf);
6137         printf("\t\tport key: %u\n", params->key);
6138         printf("\t\tport priority: %u\n", params->port_priority);
6139         printf("\t\tport number: %u\n", params->port_number);
6140 }
6141
6142 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6143 {
6144         char a_state[256] = { 0 };
6145         char p_state[256] = { 0 };
6146         int a_len = 0;
6147         int p_len = 0;
6148         uint32_t i;
6149
6150         static const char * const state[] = {
6151                 "ACTIVE",
6152                 "TIMEOUT",
6153                 "AGGREGATION",
6154                 "SYNCHRONIZATION",
6155                 "COLLECTING",
6156                 "DISTRIBUTING",
6157                 "DEFAULTED",
6158                 "EXPIRED"
6159         };
6160         static const char * const selection[] = {
6161                 "UNSELECTED",
6162                 "STANDBY",
6163                 "SELECTED"
6164         };
6165
6166         for (i = 0; i < RTE_DIM(state); i++) {
6167                 if ((info->actor_state >> i) & 1)
6168                         a_len += snprintf(&a_state[a_len],
6169                                                 RTE_DIM(a_state) - a_len, "%s ",
6170                                                 state[i]);
6171
6172                 if ((info->partner_state >> i) & 1)
6173                         p_len += snprintf(&p_state[p_len],
6174                                                 RTE_DIM(p_state) - p_len, "%s ",
6175                                                 state[i]);
6176         }
6177         printf("\tAggregator port id: %u\n", info->agg_port_id);
6178         printf("\tselection: %s\n", selection[info->selected]);
6179         printf("\tActor detail info:\n");
6180         port_param_show(&info->actor);
6181         printf("\t\tport state: %s\n", a_state);
6182         printf("\tPartner detail info:\n");
6183         port_param_show(&info->partner);
6184         printf("\t\tport state: %s\n", p_state);
6185         printf("\n");
6186 }
6187
6188 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6189 {
6190         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6191         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6192         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6193         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6194         printf("\taggregate wait timeout: %u ms\n",
6195                         conf->aggregate_wait_timeout_ms);
6196         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6197         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6198         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6199         switch (conf->agg_selection) {
6200         case AGG_BANDWIDTH:
6201                 printf("\taggregation mode: bandwidth\n");
6202                 break;
6203         case AGG_STABLE:
6204                 printf("\taggregation mode: stable\n");
6205                 break;
6206         case AGG_COUNT:
6207                 printf("\taggregation mode: count\n");
6208                 break;
6209         default:
6210                 printf("\taggregation mode: invalid\n");
6211                 break;
6212         }
6213
6214         printf("\n");
6215 }
6216
6217 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6218                 __rte_unused  struct cmdline *cl,
6219                 __rte_unused void *data)
6220 {
6221         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6222         struct rte_eth_bond_8023ad_slave_info slave_info;
6223         struct rte_eth_bond_8023ad_conf port_conf;
6224         portid_t slaves[RTE_MAX_ETHPORTS];
6225         portid_t port_id = res->port_id;
6226         int num_active_slaves;
6227         int bonding_mode;
6228         int i;
6229         int ret;
6230
6231         bonding_mode = rte_eth_bond_mode_get(port_id);
6232         if (bonding_mode != BONDING_MODE_8023AD) {
6233                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6234                 return;
6235         }
6236
6237         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6238                         RTE_MAX_ETHPORTS);
6239         if (num_active_slaves < 0) {
6240                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6241                                 port_id);
6242                 return;
6243         }
6244         if (num_active_slaves == 0)
6245                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6246                         port_id);
6247
6248         printf("\tIEEE802.3 port: %u\n", port_id);
6249         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6250         if (ret) {
6251                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6252                         port_id);
6253                 return;
6254         }
6255         lacp_conf_show(&port_conf);
6256
6257         for (i = 0; i < num_active_slaves; i++) {
6258                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6259                                 &slave_info);
6260                 if (ret) {
6261                         fprintf(stderr, "\tGet slave device %u info failed\n",
6262                                 slaves[i]);
6263                         return;
6264                 }
6265                 printf("\tSlave Port: %u\n", slaves[i]);
6266                 lacp_slave_info_show(&slave_info);
6267         }
6268 }
6269
6270 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6271 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6272                 show, "show");
6273 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6274 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6275                 bonding, "bonding");
6276 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6277 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6278                 bonding, "lacp");
6279 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6280 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6281                 info, "info");
6282 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6283 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6284                 port_id, RTE_UINT16);
6285
6286 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6287                 .f = cmd_show_bonding_lacp_info_parsed,
6288                 .help_str = "show bonding lacp info <port_id> : "
6289                         "Show bonding IEEE802.3 information for port_id",
6290                 .data = NULL,
6291                 .tokens = {
6292                         (void *)&cmd_show_bonding_lacp_info_show,
6293                         (void *)&cmd_show_bonding_lacp_info_bonding,
6294                         (void *)&cmd_show_bonding_lacp_info_lacp,
6295                         (void *)&cmd_show_bonding_lacp_info_info,
6296                         (void *)&cmd_show_bonding_lacp_info_port_id,
6297                         NULL
6298                 }
6299 };
6300
6301 /* *** SHOW NIC BONDING CONFIGURATION *** */
6302 struct cmd_show_bonding_config_result {
6303         cmdline_fixed_string_t show;
6304         cmdline_fixed_string_t bonding;
6305         cmdline_fixed_string_t config;
6306         portid_t port_id;
6307 };
6308
6309 static void cmd_show_bonding_config_parsed(void *parsed_result,
6310                 __rte_unused  struct cmdline *cl,
6311                 __rte_unused void *data)
6312 {
6313         struct cmd_show_bonding_config_result *res = parsed_result;
6314         int bonding_mode, agg_mode;
6315         portid_t slaves[RTE_MAX_ETHPORTS];
6316         int num_slaves, num_active_slaves;
6317         int primary_id;
6318         int i;
6319         portid_t port_id = res->port_id;
6320
6321         /* Display the bonding mode.*/
6322         bonding_mode = rte_eth_bond_mode_get(port_id);
6323         if (bonding_mode < 0) {
6324                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6325                         port_id);
6326                 return;
6327         } else
6328                 printf("\tBonding mode: %d\n", bonding_mode);
6329
6330         if (bonding_mode == BONDING_MODE_BALANCE ||
6331                 bonding_mode == BONDING_MODE_8023AD) {
6332                 int balance_xmit_policy;
6333
6334                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6335                 if (balance_xmit_policy < 0) {
6336                         fprintf(stderr,
6337                                 "\tFailed to get balance xmit policy for port = %d\n",
6338                                 port_id);
6339                         return;
6340                 } else {
6341                         printf("\tBalance Xmit Policy: ");
6342
6343                         switch (balance_xmit_policy) {
6344                         case BALANCE_XMIT_POLICY_LAYER2:
6345                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6346                                 break;
6347                         case BALANCE_XMIT_POLICY_LAYER23:
6348                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6349                                 break;
6350                         case BALANCE_XMIT_POLICY_LAYER34:
6351                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6352                                 break;
6353                         }
6354                         printf("\n");
6355                 }
6356         }
6357
6358         if (bonding_mode == BONDING_MODE_8023AD) {
6359                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6360                 printf("\tIEEE802.3AD Aggregator Mode: ");
6361                 switch (agg_mode) {
6362                 case AGG_BANDWIDTH:
6363                         printf("bandwidth");
6364                         break;
6365                 case AGG_STABLE:
6366                         printf("stable");
6367                         break;
6368                 case AGG_COUNT:
6369                         printf("count");
6370                         break;
6371                 }
6372                 printf("\n");
6373         }
6374
6375         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6376
6377         if (num_slaves < 0) {
6378                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6379                         port_id);
6380                 return;
6381         }
6382         if (num_slaves > 0) {
6383                 printf("\tSlaves (%d): [", num_slaves);
6384                 for (i = 0; i < num_slaves - 1; i++)
6385                         printf("%d ", slaves[i]);
6386
6387                 printf("%d]\n", slaves[num_slaves - 1]);
6388         } else {
6389                 printf("\tSlaves: []\n");
6390
6391         }
6392
6393         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6394                         RTE_MAX_ETHPORTS);
6395
6396         if (num_active_slaves < 0) {
6397                 fprintf(stderr,
6398                         "\tFailed to get active slave list for port = %d\n",
6399                         port_id);
6400                 return;
6401         }
6402         if (num_active_slaves > 0) {
6403                 printf("\tActive Slaves (%d): [", num_active_slaves);
6404                 for (i = 0; i < num_active_slaves - 1; i++)
6405                         printf("%d ", slaves[i]);
6406
6407                 printf("%d]\n", slaves[num_active_slaves - 1]);
6408
6409         } else {
6410                 printf("\tActive Slaves: []\n");
6411
6412         }
6413
6414         primary_id = rte_eth_bond_primary_get(port_id);
6415         if (primary_id < 0) {
6416                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6417                         port_id);
6418                 return;
6419         } else
6420                 printf("\tPrimary: [%d]\n", primary_id);
6421
6422 }
6423
6424 cmdline_parse_token_string_t cmd_showbonding_config_show =
6425 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6426                 show, "show");
6427 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6428 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6429                 bonding, "bonding");
6430 cmdline_parse_token_string_t cmd_showbonding_config_config =
6431 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6432                 config, "config");
6433 cmdline_parse_token_num_t cmd_showbonding_config_port =
6434 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6435                 port_id, RTE_UINT16);
6436
6437 cmdline_parse_inst_t cmd_show_bonding_config = {
6438                 .f = cmd_show_bonding_config_parsed,
6439                 .help_str = "show bonding config <port_id>: "
6440                         "Show the bonding config for port_id",
6441                 .data = NULL,
6442                 .tokens = {
6443                                 (void *)&cmd_showbonding_config_show,
6444                                 (void *)&cmd_showbonding_config_bonding,
6445                                 (void *)&cmd_showbonding_config_config,
6446                                 (void *)&cmd_showbonding_config_port,
6447                                 NULL
6448                 }
6449 };
6450
6451 /* *** SET BONDING PRIMARY *** */
6452 struct cmd_set_bonding_primary_result {
6453         cmdline_fixed_string_t set;
6454         cmdline_fixed_string_t bonding;
6455         cmdline_fixed_string_t primary;
6456         portid_t slave_id;
6457         portid_t port_id;
6458 };
6459
6460 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6461                 __rte_unused  struct cmdline *cl,
6462                 __rte_unused void *data)
6463 {
6464         struct cmd_set_bonding_primary_result *res = parsed_result;
6465         portid_t master_port_id = res->port_id;
6466         portid_t slave_port_id = res->slave_id;
6467
6468         /* Set the primary slave for a bonded device. */
6469         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6470                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6471                         master_port_id);
6472                 return;
6473         }
6474         init_port_config();
6475 }
6476
6477 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6478 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6479                 set, "set");
6480 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6481 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6482                 bonding, "bonding");
6483 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6484 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6485                 primary, "primary");
6486 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6487 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6488                 slave_id, RTE_UINT16);
6489 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6490 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6491                 port_id, RTE_UINT16);
6492
6493 cmdline_parse_inst_t cmd_set_bonding_primary = {
6494                 .f = cmd_set_bonding_primary_parsed,
6495                 .help_str = "set bonding primary <slave_id> <port_id>: "
6496                         "Set the primary slave for port_id",
6497                 .data = NULL,
6498                 .tokens = {
6499                                 (void *)&cmd_setbonding_primary_set,
6500                                 (void *)&cmd_setbonding_primary_bonding,
6501                                 (void *)&cmd_setbonding_primary_primary,
6502                                 (void *)&cmd_setbonding_primary_slave,
6503                                 (void *)&cmd_setbonding_primary_port,
6504                                 NULL
6505                 }
6506 };
6507
6508 /* *** ADD SLAVE *** */
6509 struct cmd_add_bonding_slave_result {
6510         cmdline_fixed_string_t add;
6511         cmdline_fixed_string_t bonding;
6512         cmdline_fixed_string_t slave;
6513         portid_t slave_id;
6514         portid_t port_id;
6515 };
6516
6517 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6518                 __rte_unused  struct cmdline *cl,
6519                 __rte_unused void *data)
6520 {
6521         struct cmd_add_bonding_slave_result *res = parsed_result;
6522         portid_t master_port_id = res->port_id;
6523         portid_t slave_port_id = res->slave_id;
6524
6525         /* add the slave for a bonded device. */
6526         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6527                 fprintf(stderr,
6528                         "\t Failed to add slave %d to master port = %d.\n",
6529                         slave_port_id, master_port_id);
6530                 return;
6531         }
6532         init_port_config();
6533         set_port_slave_flag(slave_port_id);
6534 }
6535
6536 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6537 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6538                 add, "add");
6539 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6540 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6541                 bonding, "bonding");
6542 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6543 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6544                 slave, "slave");
6545 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6546 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6547                 slave_id, RTE_UINT16);
6548 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6549 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6550                 port_id, RTE_UINT16);
6551
6552 cmdline_parse_inst_t cmd_add_bonding_slave = {
6553                 .f = cmd_add_bonding_slave_parsed,
6554                 .help_str = "add bonding slave <slave_id> <port_id>: "
6555                         "Add a slave device to a bonded device",
6556                 .data = NULL,
6557                 .tokens = {
6558                                 (void *)&cmd_addbonding_slave_add,
6559                                 (void *)&cmd_addbonding_slave_bonding,
6560                                 (void *)&cmd_addbonding_slave_slave,
6561                                 (void *)&cmd_addbonding_slave_slaveid,
6562                                 (void *)&cmd_addbonding_slave_port,
6563                                 NULL
6564                 }
6565 };
6566
6567 /* *** REMOVE SLAVE *** */
6568 struct cmd_remove_bonding_slave_result {
6569         cmdline_fixed_string_t remove;
6570         cmdline_fixed_string_t bonding;
6571         cmdline_fixed_string_t slave;
6572         portid_t slave_id;
6573         portid_t port_id;
6574 };
6575
6576 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6577                 __rte_unused  struct cmdline *cl,
6578                 __rte_unused void *data)
6579 {
6580         struct cmd_remove_bonding_slave_result *res = parsed_result;
6581         portid_t master_port_id = res->port_id;
6582         portid_t slave_port_id = res->slave_id;
6583
6584         /* remove the slave from a bonded device. */
6585         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6586                 fprintf(stderr,
6587                         "\t Failed to remove slave %d from master port = %d.\n",
6588                         slave_port_id, master_port_id);
6589                 return;
6590         }
6591         init_port_config();
6592         clear_port_slave_flag(slave_port_id);
6593 }
6594
6595 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6596                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6597                                 remove, "remove");
6598 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6599                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6600                                 bonding, "bonding");
6601 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6602                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6603                                 slave, "slave");
6604 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6605                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6606                                 slave_id, RTE_UINT16);
6607 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6608                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6609                                 port_id, RTE_UINT16);
6610
6611 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6612                 .f = cmd_remove_bonding_slave_parsed,
6613                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6614                         "Remove a slave device from a bonded device",
6615                 .data = NULL,
6616                 .tokens = {
6617                                 (void *)&cmd_removebonding_slave_remove,
6618                                 (void *)&cmd_removebonding_slave_bonding,
6619                                 (void *)&cmd_removebonding_slave_slave,
6620                                 (void *)&cmd_removebonding_slave_slaveid,
6621                                 (void *)&cmd_removebonding_slave_port,
6622                                 NULL
6623                 }
6624 };
6625
6626 /* *** CREATE BONDED DEVICE *** */
6627 struct cmd_create_bonded_device_result {
6628         cmdline_fixed_string_t create;
6629         cmdline_fixed_string_t bonded;
6630         cmdline_fixed_string_t device;
6631         uint8_t mode;
6632         uint8_t socket;
6633 };
6634
6635 static int bond_dev_num = 0;
6636
6637 static void cmd_create_bonded_device_parsed(void *parsed_result,
6638                 __rte_unused  struct cmdline *cl,
6639                 __rte_unused void *data)
6640 {
6641         struct cmd_create_bonded_device_result *res = parsed_result;
6642         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6643         int port_id;
6644         int ret;
6645
6646         if (test_done == 0) {
6647                 fprintf(stderr, "Please stop forwarding first\n");
6648                 return;
6649         }
6650
6651         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6652                         bond_dev_num++);
6653
6654         /* Create a new bonded device. */
6655         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6656         if (port_id < 0) {
6657                 fprintf(stderr, "\t Failed to create bonded device.\n");
6658                 return;
6659         } else {
6660                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6661                                 port_id);
6662
6663                 /* Update number of ports */
6664                 nb_ports = rte_eth_dev_count_avail();
6665                 reconfig(port_id, res->socket);
6666                 ret = rte_eth_promiscuous_enable(port_id);
6667                 if (ret != 0)
6668                         fprintf(stderr,
6669                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6670                                 port_id, rte_strerror(-ret));
6671
6672                 ports[port_id].need_setup = 0;
6673                 ports[port_id].port_status = RTE_PORT_STOPPED;
6674         }
6675
6676 }
6677
6678 cmdline_parse_token_string_t cmd_createbonded_device_create =
6679                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6680                                 create, "create");
6681 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6682                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6683                                 bonded, "bonded");
6684 cmdline_parse_token_string_t cmd_createbonded_device_device =
6685                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6686                                 device, "device");
6687 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6688                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6689                                 mode, RTE_UINT8);
6690 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6691                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6692                                 socket, RTE_UINT8);
6693
6694 cmdline_parse_inst_t cmd_create_bonded_device = {
6695                 .f = cmd_create_bonded_device_parsed,
6696                 .help_str = "create bonded device <mode> <socket>: "
6697                         "Create a new bonded device with specific bonding mode and socket",
6698                 .data = NULL,
6699                 .tokens = {
6700                                 (void *)&cmd_createbonded_device_create,
6701                                 (void *)&cmd_createbonded_device_bonded,
6702                                 (void *)&cmd_createbonded_device_device,
6703                                 (void *)&cmd_createbonded_device_mode,
6704                                 (void *)&cmd_createbonded_device_socket,
6705                                 NULL
6706                 }
6707 };
6708
6709 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6710 struct cmd_set_bond_mac_addr_result {
6711         cmdline_fixed_string_t set;
6712         cmdline_fixed_string_t bonding;
6713         cmdline_fixed_string_t mac_addr;
6714         uint16_t port_num;
6715         struct rte_ether_addr address;
6716 };
6717
6718 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6719                 __rte_unused  struct cmdline *cl,
6720                 __rte_unused void *data)
6721 {
6722         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6723         int ret;
6724
6725         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6726                 return;
6727
6728         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6729
6730         /* check the return value and print it if is < 0 */
6731         if (ret < 0)
6732                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6733                         strerror(-ret));
6734 }
6735
6736 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6737                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6738 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6739                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6740                                 "bonding");
6741 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6742                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6743                                 "mac_addr");
6744 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6745                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6746                                 port_num, RTE_UINT16);
6747 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6748                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6749
6750 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6751                 .f = cmd_set_bond_mac_addr_parsed,
6752                 .data = (void *) 0,
6753                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6754                 .tokens = {
6755                                 (void *)&cmd_set_bond_mac_addr_set,
6756                                 (void *)&cmd_set_bond_mac_addr_bonding,
6757                                 (void *)&cmd_set_bond_mac_addr_mac,
6758                                 (void *)&cmd_set_bond_mac_addr_portnum,
6759                                 (void *)&cmd_set_bond_mac_addr_addr,
6760                                 NULL
6761                 }
6762 };
6763
6764
6765 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6766 struct cmd_set_bond_mon_period_result {
6767         cmdline_fixed_string_t set;
6768         cmdline_fixed_string_t bonding;
6769         cmdline_fixed_string_t mon_period;
6770         uint16_t port_num;
6771         uint32_t period_ms;
6772 };
6773
6774 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6775                 __rte_unused  struct cmdline *cl,
6776                 __rte_unused void *data)
6777 {
6778         struct cmd_set_bond_mon_period_result *res = parsed_result;
6779         int ret;
6780
6781         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6782
6783         /* check the return value and print it if is < 0 */
6784         if (ret < 0)
6785                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6786                         strerror(-ret));
6787 }
6788
6789 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6790                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6791                                 set, "set");
6792 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6793                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6794                                 bonding, "bonding");
6795 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6796                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6797                                 mon_period,     "mon_period");
6798 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6799                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6800                                 port_num, RTE_UINT16);
6801 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6802                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6803                                 period_ms, RTE_UINT32);
6804
6805 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6806                 .f = cmd_set_bond_mon_period_parsed,
6807                 .data = (void *) 0,
6808                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6809                 .tokens = {
6810                                 (void *)&cmd_set_bond_mon_period_set,
6811                                 (void *)&cmd_set_bond_mon_period_bonding,
6812                                 (void *)&cmd_set_bond_mon_period_mon_period,
6813                                 (void *)&cmd_set_bond_mon_period_portnum,
6814                                 (void *)&cmd_set_bond_mon_period_period_ms,
6815                                 NULL
6816                 }
6817 };
6818
6819
6820
6821 struct cmd_set_bonding_agg_mode_policy_result {
6822         cmdline_fixed_string_t set;
6823         cmdline_fixed_string_t bonding;
6824         cmdline_fixed_string_t agg_mode;
6825         uint16_t port_num;
6826         cmdline_fixed_string_t policy;
6827 };
6828
6829
6830 static void
6831 cmd_set_bonding_agg_mode(void *parsed_result,
6832                 __rte_unused struct cmdline *cl,
6833                 __rte_unused void *data)
6834 {
6835         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6836         uint8_t policy = AGG_BANDWIDTH;
6837
6838         if (!strcmp(res->policy, "bandwidth"))
6839                 policy = AGG_BANDWIDTH;
6840         else if (!strcmp(res->policy, "stable"))
6841                 policy = AGG_STABLE;
6842         else if (!strcmp(res->policy, "count"))
6843                 policy = AGG_COUNT;
6844
6845         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6846 }
6847
6848
6849 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6850         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6851                                 set, "set");
6852 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6853         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6854                                 bonding, "bonding");
6855
6856 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6857         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6858                                 agg_mode, "agg_mode");
6859
6860 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6861         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6862                                 port_num, RTE_UINT16);
6863
6864 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6865         TOKEN_STRING_INITIALIZER(
6866                         struct cmd_set_bonding_balance_xmit_policy_result,
6867                 policy, "stable#bandwidth#count");
6868
6869 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6870         .f = cmd_set_bonding_agg_mode,
6871         .data = (void *) 0,
6872         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6873         .tokens = {
6874                         (void *)&cmd_set_bonding_agg_mode_set,
6875                         (void *)&cmd_set_bonding_agg_mode_bonding,
6876                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6877                         (void *)&cmd_set_bonding_agg_mode_portnum,
6878                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6879                         NULL
6880                 }
6881 };
6882
6883
6884 #endif /* RTE_NET_BOND */
6885
6886 /* *** SET FORWARDING MODE *** */
6887 struct cmd_set_fwd_mode_result {
6888         cmdline_fixed_string_t set;
6889         cmdline_fixed_string_t fwd;
6890         cmdline_fixed_string_t mode;
6891 };
6892
6893 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6894                                     __rte_unused struct cmdline *cl,
6895                                     __rte_unused void *data)
6896 {
6897         struct cmd_set_fwd_mode_result *res = parsed_result;
6898
6899         retry_enabled = 0;
6900         set_pkt_forwarding_mode(res->mode);
6901 }
6902
6903 cmdline_parse_token_string_t cmd_setfwd_set =
6904         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6905 cmdline_parse_token_string_t cmd_setfwd_fwd =
6906         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6907 cmdline_parse_token_string_t cmd_setfwd_mode =
6908         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6909                 "" /* defined at init */);
6910
6911 cmdline_parse_inst_t cmd_set_fwd_mode = {
6912         .f = cmd_set_fwd_mode_parsed,
6913         .data = NULL,
6914         .help_str = NULL, /* defined at init */
6915         .tokens = {
6916                 (void *)&cmd_setfwd_set,
6917                 (void *)&cmd_setfwd_fwd,
6918                 (void *)&cmd_setfwd_mode,
6919                 NULL,
6920         },
6921 };
6922
6923 static void cmd_set_fwd_mode_init(void)
6924 {
6925         char *modes, *c;
6926         static char token[128];
6927         static char help[256];
6928         cmdline_parse_token_string_t *token_struct;
6929
6930         modes = list_pkt_forwarding_modes();
6931         snprintf(help, sizeof(help), "set fwd %s: "
6932                 "Set packet forwarding mode", modes);
6933         cmd_set_fwd_mode.help_str = help;
6934
6935         /* string token separator is # */
6936         for (c = token; *modes != '\0'; modes++)
6937                 if (*modes == '|')
6938                         *c++ = '#';
6939                 else
6940                         *c++ = *modes;
6941         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6942         token_struct->string_data.str = token;
6943 }
6944
6945 /* *** SET RETRY FORWARDING MODE *** */
6946 struct cmd_set_fwd_retry_mode_result {
6947         cmdline_fixed_string_t set;
6948         cmdline_fixed_string_t fwd;
6949         cmdline_fixed_string_t mode;
6950         cmdline_fixed_string_t retry;
6951 };
6952
6953 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6954                             __rte_unused struct cmdline *cl,
6955                             __rte_unused void *data)
6956 {
6957         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6958
6959         retry_enabled = 1;
6960         set_pkt_forwarding_mode(res->mode);
6961 }
6962
6963 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6964         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6965                         set, "set");
6966 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6967         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6968                         fwd, "fwd");
6969 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6970         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6971                         mode,
6972                 "" /* defined at init */);
6973 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6974         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6975                         retry, "retry");
6976
6977 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6978         .f = cmd_set_fwd_retry_mode_parsed,
6979         .data = NULL,
6980         .help_str = NULL, /* defined at init */
6981         .tokens = {
6982                 (void *)&cmd_setfwd_retry_set,
6983                 (void *)&cmd_setfwd_retry_fwd,
6984                 (void *)&cmd_setfwd_retry_mode,
6985                 (void *)&cmd_setfwd_retry_retry,
6986                 NULL,
6987         },
6988 };
6989
6990 static void cmd_set_fwd_retry_mode_init(void)
6991 {
6992         char *modes, *c;
6993         static char token[128];
6994         static char help[256];
6995         cmdline_parse_token_string_t *token_struct;
6996
6997         modes = list_pkt_forwarding_retry_modes();
6998         snprintf(help, sizeof(help), "set fwd %s retry: "
6999                 "Set packet forwarding mode with retry", modes);
7000         cmd_set_fwd_retry_mode.help_str = help;
7001
7002         /* string token separator is # */
7003         for (c = token; *modes != '\0'; modes++)
7004                 if (*modes == '|')
7005                         *c++ = '#';
7006                 else
7007                         *c++ = *modes;
7008         token_struct = (cmdline_parse_token_string_t *)
7009                 cmd_set_fwd_retry_mode.tokens[2];
7010         token_struct->string_data.str = token;
7011 }
7012
7013 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
7014 struct cmd_set_burst_tx_retry_result {
7015         cmdline_fixed_string_t set;
7016         cmdline_fixed_string_t burst;
7017         cmdline_fixed_string_t tx;
7018         cmdline_fixed_string_t delay;
7019         uint32_t time;
7020         cmdline_fixed_string_t retry;
7021         uint32_t retry_num;
7022 };
7023
7024 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7025                                         __rte_unused struct cmdline *cl,
7026                                         __rte_unused void *data)
7027 {
7028         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7029
7030         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7031                 && !strcmp(res->tx, "tx")) {
7032                 if (!strcmp(res->delay, "delay"))
7033                         burst_tx_delay_time = res->time;
7034                 if (!strcmp(res->retry, "retry"))
7035                         burst_tx_retry_num = res->retry_num;
7036         }
7037
7038 }
7039
7040 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7041         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7042 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7043         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7044                                  "burst");
7045 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7046         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7047 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7048         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7049 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7050         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7051                                  RTE_UINT32);
7052 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7053         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7054 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7055         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7056                                  RTE_UINT32);
7057
7058 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7059         .f = cmd_set_burst_tx_retry_parsed,
7060         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7061         .tokens = {
7062                 (void *)&cmd_set_burst_tx_retry_set,
7063                 (void *)&cmd_set_burst_tx_retry_burst,
7064                 (void *)&cmd_set_burst_tx_retry_tx,
7065                 (void *)&cmd_set_burst_tx_retry_delay,
7066                 (void *)&cmd_set_burst_tx_retry_time,
7067                 (void *)&cmd_set_burst_tx_retry_retry,
7068                 (void *)&cmd_set_burst_tx_retry_retry_num,
7069                 NULL,
7070         },
7071 };
7072
7073 /* *** SET PROMISC MODE *** */
7074 struct cmd_set_promisc_mode_result {
7075         cmdline_fixed_string_t set;
7076         cmdline_fixed_string_t promisc;
7077         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7078         uint16_t port_num;               /* valid if "allports" argument == 0 */
7079         cmdline_fixed_string_t mode;
7080 };
7081
7082 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7083                                         __rte_unused struct cmdline *cl,
7084                                         void *allports)
7085 {
7086         struct cmd_set_promisc_mode_result *res = parsed_result;
7087         int enable;
7088         portid_t i;
7089
7090         if (!strcmp(res->mode, "on"))
7091                 enable = 1;
7092         else
7093                 enable = 0;
7094
7095         /* all ports */
7096         if (allports) {
7097                 RTE_ETH_FOREACH_DEV(i)
7098                         eth_set_promisc_mode(i, enable);
7099         } else {
7100                 eth_set_promisc_mode(res->port_num, enable);
7101         }
7102 }
7103
7104 cmdline_parse_token_string_t cmd_setpromisc_set =
7105         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7106 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7107         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7108                                  "promisc");
7109 cmdline_parse_token_string_t cmd_setpromisc_portall =
7110         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7111                                  "all");
7112 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7113         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7114                               RTE_UINT16);
7115 cmdline_parse_token_string_t cmd_setpromisc_mode =
7116         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7117                                  "on#off");
7118
7119 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7120         .f = cmd_set_promisc_mode_parsed,
7121         .data = (void *)1,
7122         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7123         .tokens = {
7124                 (void *)&cmd_setpromisc_set,
7125                 (void *)&cmd_setpromisc_promisc,
7126                 (void *)&cmd_setpromisc_portall,
7127                 (void *)&cmd_setpromisc_mode,
7128                 NULL,
7129         },
7130 };
7131
7132 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7133         .f = cmd_set_promisc_mode_parsed,
7134         .data = (void *)0,
7135         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7136         .tokens = {
7137                 (void *)&cmd_setpromisc_set,
7138                 (void *)&cmd_setpromisc_promisc,
7139                 (void *)&cmd_setpromisc_portnum,
7140                 (void *)&cmd_setpromisc_mode,
7141                 NULL,
7142         },
7143 };
7144
7145 /* *** SET ALLMULTI MODE *** */
7146 struct cmd_set_allmulti_mode_result {
7147         cmdline_fixed_string_t set;
7148         cmdline_fixed_string_t allmulti;
7149         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7150         uint16_t port_num;               /* valid if "allports" argument == 0 */
7151         cmdline_fixed_string_t mode;
7152 };
7153
7154 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7155                                         __rte_unused struct cmdline *cl,
7156                                         void *allports)
7157 {
7158         struct cmd_set_allmulti_mode_result *res = parsed_result;
7159         int enable;
7160         portid_t i;
7161
7162         if (!strcmp(res->mode, "on"))
7163                 enable = 1;
7164         else
7165                 enable = 0;
7166
7167         /* all ports */
7168         if (allports) {
7169                 RTE_ETH_FOREACH_DEV(i) {
7170                         eth_set_allmulticast_mode(i, enable);
7171                 }
7172         }
7173         else {
7174                 eth_set_allmulticast_mode(res->port_num, enable);
7175         }
7176 }
7177
7178 cmdline_parse_token_string_t cmd_setallmulti_set =
7179         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7180 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7181         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7182                                  "allmulti");
7183 cmdline_parse_token_string_t cmd_setallmulti_portall =
7184         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7185                                  "all");
7186 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7187         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7188                               RTE_UINT16);
7189 cmdline_parse_token_string_t cmd_setallmulti_mode =
7190         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7191                                  "on#off");
7192
7193 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7194         .f = cmd_set_allmulti_mode_parsed,
7195         .data = (void *)1,
7196         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7197         .tokens = {
7198                 (void *)&cmd_setallmulti_set,
7199                 (void *)&cmd_setallmulti_allmulti,
7200                 (void *)&cmd_setallmulti_portall,
7201                 (void *)&cmd_setallmulti_mode,
7202                 NULL,
7203         },
7204 };
7205
7206 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7207         .f = cmd_set_allmulti_mode_parsed,
7208         .data = (void *)0,
7209         .help_str = "set allmulti <port_id> on|off: "
7210                 "Set allmulti mode on port_id",
7211         .tokens = {
7212                 (void *)&cmd_setallmulti_set,
7213                 (void *)&cmd_setallmulti_allmulti,
7214                 (void *)&cmd_setallmulti_portnum,
7215                 (void *)&cmd_setallmulti_mode,
7216                 NULL,
7217         },
7218 };
7219
7220 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7221 struct cmd_link_flow_ctrl_show {
7222         cmdline_fixed_string_t show;
7223         cmdline_fixed_string_t port;
7224         portid_t port_id;
7225         cmdline_fixed_string_t flow_ctrl;
7226 };
7227
7228 cmdline_parse_token_string_t cmd_lfc_show_show =
7229         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7230                                 show, "show");
7231 cmdline_parse_token_string_t cmd_lfc_show_port =
7232         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7233                                 port, "port");
7234 cmdline_parse_token_num_t cmd_lfc_show_portid =
7235         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7236                                 port_id, RTE_UINT16);
7237 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7238         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7239                                 flow_ctrl, "flow_ctrl");
7240
7241 static void
7242 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7243                               __rte_unused struct cmdline *cl,
7244                               __rte_unused void *data)
7245 {
7246         struct cmd_link_flow_ctrl_show *res = parsed_result;
7247         static const char *info_border = "*********************";
7248         struct rte_eth_fc_conf fc_conf;
7249         bool rx_fc_en = false;
7250         bool tx_fc_en = false;
7251         int ret;
7252
7253         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7254         if (ret != 0) {
7255                 fprintf(stderr,
7256                         "Failed to get current flow ctrl information: err = %d\n",
7257                         ret);
7258                 return;
7259         }
7260
7261         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7262                 rx_fc_en = true;
7263         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7264                 tx_fc_en = true;
7265
7266         printf("\n%s Flow control infos for port %-2d %s\n",
7267                 info_border, res->port_id, info_border);
7268         printf("FC mode:\n");
7269         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7270         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7271         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7272         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7273         printf("High waterline: 0x%x\n", fc_conf.high_water);
7274         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7275         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7276         printf("Forward MAC control frames: %s\n",
7277                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7278         printf("\n%s**************   End  ***********%s\n",
7279                 info_border, info_border);
7280 }
7281
7282 cmdline_parse_inst_t cmd_link_flow_control_show = {
7283         .f = cmd_link_flow_ctrl_show_parsed,
7284         .data = NULL,
7285         .help_str = "show port <port_id> flow_ctrl",
7286         .tokens = {
7287                 (void *)&cmd_lfc_show_show,
7288                 (void *)&cmd_lfc_show_port,
7289                 (void *)&cmd_lfc_show_portid,
7290                 (void *)&cmd_lfc_show_flow_ctrl,
7291                 NULL,
7292         },
7293 };
7294
7295 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7296 struct cmd_link_flow_ctrl_set_result {
7297         cmdline_fixed_string_t set;
7298         cmdline_fixed_string_t flow_ctrl;
7299         cmdline_fixed_string_t rx;
7300         cmdline_fixed_string_t rx_lfc_mode;
7301         cmdline_fixed_string_t tx;
7302         cmdline_fixed_string_t tx_lfc_mode;
7303         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7304         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7305         cmdline_fixed_string_t autoneg_str;
7306         cmdline_fixed_string_t autoneg;
7307         cmdline_fixed_string_t hw_str;
7308         uint32_t high_water;
7309         cmdline_fixed_string_t lw_str;
7310         uint32_t low_water;
7311         cmdline_fixed_string_t pt_str;
7312         uint16_t pause_time;
7313         cmdline_fixed_string_t xon_str;
7314         uint16_t send_xon;
7315         portid_t port_id;
7316 };
7317
7318 cmdline_parse_token_string_t cmd_lfc_set_set =
7319         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7320                                 set, "set");
7321 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7322         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7323                                 flow_ctrl, "flow_ctrl");
7324 cmdline_parse_token_string_t cmd_lfc_set_rx =
7325         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7326                                 rx, "rx");
7327 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7328         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7329                                 rx_lfc_mode, "on#off");
7330 cmdline_parse_token_string_t cmd_lfc_set_tx =
7331         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7332                                 tx, "tx");
7333 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7334         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7335                                 tx_lfc_mode, "on#off");
7336 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7337         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7338                                 hw_str, "high_water");
7339 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7340         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7341                                 high_water, RTE_UINT32);
7342 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7343         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7344                                 lw_str, "low_water");
7345 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7346         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7347                                 low_water, RTE_UINT32);
7348 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7349         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7350                                 pt_str, "pause_time");
7351 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7352         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7353                                 pause_time, RTE_UINT16);
7354 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7355         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7356                                 xon_str, "send_xon");
7357 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7358         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7359                                 send_xon, RTE_UINT16);
7360 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7361         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7362                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7363 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7364         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7365                                 mac_ctrl_frame_fwd_mode, "on#off");
7366 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7367         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7368                                 autoneg_str, "autoneg");
7369 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7370         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7371                                 autoneg, "on#off");
7372 cmdline_parse_token_num_t cmd_lfc_set_portid =
7373         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7374                                 port_id, RTE_UINT16);
7375
7376 /* forward declaration */
7377 static void
7378 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7379                               void *data);
7380
7381 cmdline_parse_inst_t cmd_link_flow_control_set = {
7382         .f = cmd_link_flow_ctrl_set_parsed,
7383         .data = NULL,
7384         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7385                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7386                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7387         .tokens = {
7388                 (void *)&cmd_lfc_set_set,
7389                 (void *)&cmd_lfc_set_flow_ctrl,
7390                 (void *)&cmd_lfc_set_rx,
7391                 (void *)&cmd_lfc_set_rx_mode,
7392                 (void *)&cmd_lfc_set_tx,
7393                 (void *)&cmd_lfc_set_tx_mode,
7394                 (void *)&cmd_lfc_set_high_water,
7395                 (void *)&cmd_lfc_set_low_water,
7396                 (void *)&cmd_lfc_set_pause_time,
7397                 (void *)&cmd_lfc_set_send_xon,
7398                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7399                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7400                 (void *)&cmd_lfc_set_autoneg_str,
7401                 (void *)&cmd_lfc_set_autoneg,
7402                 (void *)&cmd_lfc_set_portid,
7403                 NULL,
7404         },
7405 };
7406
7407 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7408         .f = cmd_link_flow_ctrl_set_parsed,
7409         .data = (void *)&cmd_link_flow_control_set_rx,
7410         .help_str = "set flow_ctrl rx on|off <port_id>: "
7411                 "Change rx flow control parameter",
7412         .tokens = {
7413                 (void *)&cmd_lfc_set_set,
7414                 (void *)&cmd_lfc_set_flow_ctrl,
7415                 (void *)&cmd_lfc_set_rx,
7416                 (void *)&cmd_lfc_set_rx_mode,
7417                 (void *)&cmd_lfc_set_portid,
7418                 NULL,
7419         },
7420 };
7421
7422 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7423         .f = cmd_link_flow_ctrl_set_parsed,
7424         .data = (void *)&cmd_link_flow_control_set_tx,
7425         .help_str = "set flow_ctrl tx on|off <port_id>: "
7426                 "Change tx flow control parameter",
7427         .tokens = {
7428                 (void *)&cmd_lfc_set_set,
7429                 (void *)&cmd_lfc_set_flow_ctrl,
7430                 (void *)&cmd_lfc_set_tx,
7431                 (void *)&cmd_lfc_set_tx_mode,
7432                 (void *)&cmd_lfc_set_portid,
7433                 NULL,
7434         },
7435 };
7436
7437 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7438         .f = cmd_link_flow_ctrl_set_parsed,
7439         .data = (void *)&cmd_link_flow_control_set_hw,
7440         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7441                 "Change high water flow control parameter",
7442         .tokens = {
7443                 (void *)&cmd_lfc_set_set,
7444                 (void *)&cmd_lfc_set_flow_ctrl,
7445                 (void *)&cmd_lfc_set_high_water_str,
7446                 (void *)&cmd_lfc_set_high_water,
7447                 (void *)&cmd_lfc_set_portid,
7448                 NULL,
7449         },
7450 };
7451
7452 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7453         .f = cmd_link_flow_ctrl_set_parsed,
7454         .data = (void *)&cmd_link_flow_control_set_lw,
7455         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7456                 "Change low water flow control parameter",
7457         .tokens = {
7458                 (void *)&cmd_lfc_set_set,
7459                 (void *)&cmd_lfc_set_flow_ctrl,
7460                 (void *)&cmd_lfc_set_low_water_str,
7461                 (void *)&cmd_lfc_set_low_water,
7462                 (void *)&cmd_lfc_set_portid,
7463                 NULL,
7464         },
7465 };
7466
7467 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7468         .f = cmd_link_flow_ctrl_set_parsed,
7469         .data = (void *)&cmd_link_flow_control_set_pt,
7470         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7471                 "Change pause time flow control parameter",
7472         .tokens = {
7473                 (void *)&cmd_lfc_set_set,
7474                 (void *)&cmd_lfc_set_flow_ctrl,
7475                 (void *)&cmd_lfc_set_pause_time_str,
7476                 (void *)&cmd_lfc_set_pause_time,
7477                 (void *)&cmd_lfc_set_portid,
7478                 NULL,
7479         },
7480 };
7481
7482 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7483         .f = cmd_link_flow_ctrl_set_parsed,
7484         .data = (void *)&cmd_link_flow_control_set_xon,
7485         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7486                 "Change send_xon flow control parameter",
7487         .tokens = {
7488                 (void *)&cmd_lfc_set_set,
7489                 (void *)&cmd_lfc_set_flow_ctrl,
7490                 (void *)&cmd_lfc_set_send_xon_str,
7491                 (void *)&cmd_lfc_set_send_xon,
7492                 (void *)&cmd_lfc_set_portid,
7493                 NULL,
7494         },
7495 };
7496
7497 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7498         .f = cmd_link_flow_ctrl_set_parsed,
7499         .data = (void *)&cmd_link_flow_control_set_macfwd,
7500         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7501                 "Change mac ctrl fwd flow control parameter",
7502         .tokens = {
7503                 (void *)&cmd_lfc_set_set,
7504                 (void *)&cmd_lfc_set_flow_ctrl,
7505                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7506                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7507                 (void *)&cmd_lfc_set_portid,
7508                 NULL,
7509         },
7510 };
7511
7512 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7513         .f = cmd_link_flow_ctrl_set_parsed,
7514         .data = (void *)&cmd_link_flow_control_set_autoneg,
7515         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7516                 "Change autoneg flow control parameter",
7517         .tokens = {
7518                 (void *)&cmd_lfc_set_set,
7519                 (void *)&cmd_lfc_set_flow_ctrl,
7520                 (void *)&cmd_lfc_set_autoneg_str,
7521                 (void *)&cmd_lfc_set_autoneg,
7522                 (void *)&cmd_lfc_set_portid,
7523                 NULL,
7524         },
7525 };
7526
7527 static void
7528 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7529                               __rte_unused struct cmdline *cl,
7530                               void *data)
7531 {
7532         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7533         cmdline_parse_inst_t *cmd = data;
7534         struct rte_eth_fc_conf fc_conf;
7535         int rx_fc_en = 0;
7536         int tx_fc_en = 0;
7537         int ret;
7538
7539         /*
7540          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7541          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7542          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7543          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7544          */
7545         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7546                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7547         };
7548
7549         /* Partial command line, retrieve current configuration */
7550         if (cmd) {
7551                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7552                 if (ret != 0) {
7553                         fprintf(stderr,
7554                                 "cannot get current flow ctrl parameters, return code = %d\n",
7555                                 ret);
7556                         return;
7557                 }
7558
7559                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7560                     (fc_conf.mode == RTE_ETH_FC_FULL))
7561                         rx_fc_en = 1;
7562                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7563                     (fc_conf.mode == RTE_ETH_FC_FULL))
7564                         tx_fc_en = 1;
7565         }
7566
7567         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7568                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7569
7570         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7571                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7572
7573         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7574
7575         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7576                 fc_conf.high_water = res->high_water;
7577
7578         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7579                 fc_conf.low_water = res->low_water;
7580
7581         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7582                 fc_conf.pause_time = res->pause_time;
7583
7584         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7585                 fc_conf.send_xon = res->send_xon;
7586
7587         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7588                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7589                         fc_conf.mac_ctrl_frame_fwd = 1;
7590                 else
7591                         fc_conf.mac_ctrl_frame_fwd = 0;
7592         }
7593
7594         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7595                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7596
7597         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7598         if (ret != 0)
7599                 fprintf(stderr,
7600                         "bad flow control parameter, return code = %d\n",
7601                         ret);
7602 }
7603
7604 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7605 struct cmd_priority_flow_ctrl_set_result {
7606         cmdline_fixed_string_t set;
7607         cmdline_fixed_string_t pfc_ctrl;
7608         cmdline_fixed_string_t rx;
7609         cmdline_fixed_string_t rx_pfc_mode;
7610         cmdline_fixed_string_t tx;
7611         cmdline_fixed_string_t tx_pfc_mode;
7612         uint32_t high_water;
7613         uint32_t low_water;
7614         uint16_t pause_time;
7615         uint8_t  priority;
7616         portid_t port_id;
7617 };
7618
7619 static void
7620 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7621                        __rte_unused struct cmdline *cl,
7622                        __rte_unused void *data)
7623 {
7624         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7625         struct rte_eth_pfc_conf pfc_conf;
7626         int rx_fc_enable, tx_fc_enable;
7627         int ret;
7628
7629         /*
7630          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7631          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7632          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7633          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7634          */
7635         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7636                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7637         };
7638
7639         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7640         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7641         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7642         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7643         pfc_conf.fc.high_water = res->high_water;
7644         pfc_conf.fc.low_water  = res->low_water;
7645         pfc_conf.fc.pause_time = res->pause_time;
7646         pfc_conf.priority      = res->priority;
7647
7648         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7649         if (ret != 0)
7650                 fprintf(stderr,
7651                         "bad priority flow control parameter, return code = %d\n",
7652                         ret);
7653 }
7654
7655 cmdline_parse_token_string_t cmd_pfc_set_set =
7656         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7657                                 set, "set");
7658 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7659         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7660                                 pfc_ctrl, "pfc_ctrl");
7661 cmdline_parse_token_string_t cmd_pfc_set_rx =
7662         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7663                                 rx, "rx");
7664 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7665         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7666                                 rx_pfc_mode, "on#off");
7667 cmdline_parse_token_string_t cmd_pfc_set_tx =
7668         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7669                                 tx, "tx");
7670 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7671         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7672                                 tx_pfc_mode, "on#off");
7673 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7674         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7675                                 high_water, RTE_UINT32);
7676 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7677         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7678                                 low_water, RTE_UINT32);
7679 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7680         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7681                                 pause_time, RTE_UINT16);
7682 cmdline_parse_token_num_t cmd_pfc_set_priority =
7683         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7684                                 priority, RTE_UINT8);
7685 cmdline_parse_token_num_t cmd_pfc_set_portid =
7686         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7687                                 port_id, RTE_UINT16);
7688
7689 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7690         .f = cmd_priority_flow_ctrl_set_parsed,
7691         .data = NULL,
7692         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7693                 "<pause_time> <priority> <port_id>: "
7694                 "Configure the Ethernet priority flow control",
7695         .tokens = {
7696                 (void *)&cmd_pfc_set_set,
7697                 (void *)&cmd_pfc_set_flow_ctrl,
7698                 (void *)&cmd_pfc_set_rx,
7699                 (void *)&cmd_pfc_set_rx_mode,
7700                 (void *)&cmd_pfc_set_tx,
7701                 (void *)&cmd_pfc_set_tx_mode,
7702                 (void *)&cmd_pfc_set_high_water,
7703                 (void *)&cmd_pfc_set_low_water,
7704                 (void *)&cmd_pfc_set_pause_time,
7705                 (void *)&cmd_pfc_set_priority,
7706                 (void *)&cmd_pfc_set_portid,
7707                 NULL,
7708         },
7709 };
7710
7711 struct cmd_queue_priority_flow_ctrl_set_result {
7712         cmdline_fixed_string_t set;
7713         cmdline_fixed_string_t pfc_queue_ctrl;
7714         portid_t port_id;
7715         cmdline_fixed_string_t rx;
7716         cmdline_fixed_string_t rx_pfc_mode;
7717         uint16_t tx_qid;
7718         uint8_t  tx_tc;
7719         cmdline_fixed_string_t tx;
7720         cmdline_fixed_string_t tx_pfc_mode;
7721         uint16_t rx_qid;
7722         uint8_t  rx_tc;
7723         uint16_t pause_time;
7724 };
7725
7726 static void
7727 cmd_queue_priority_flow_ctrl_set_parsed(void *parsed_result,
7728                                         __rte_unused struct cmdline *cl,
7729                                         __rte_unused void *data)
7730 {
7731         struct cmd_queue_priority_flow_ctrl_set_result *res = parsed_result;
7732         struct rte_eth_pfc_queue_conf pfc_queue_conf;
7733         int rx_fc_enable, tx_fc_enable;
7734         int ret;
7735
7736         /*
7737          * Rx on/off, flow control is enabled/disabled on RX side. This can
7738          * indicate the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx
7739          * side. Tx on/off, flow control is enabled/disabled on TX side. This
7740          * can indicate the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at
7741          * the Tx side.
7742          */
7743         static enum rte_eth_fc_mode rx_tx_onoff_2_mode[2][2] = {
7744                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE},
7745                 {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7746         };
7747
7748         memset(&pfc_queue_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
7749         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on", 2)) ? 1 : 0;
7750         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on", 2)) ? 1 : 0;
7751         pfc_queue_conf.mode = rx_tx_onoff_2_mode[rx_fc_enable][tx_fc_enable];
7752         pfc_queue_conf.rx_pause.tc  = res->tx_tc;
7753         pfc_queue_conf.rx_pause.tx_qid = res->tx_qid;
7754         pfc_queue_conf.tx_pause.tc  = res->rx_tc;
7755         pfc_queue_conf.tx_pause.rx_qid  = res->rx_qid;
7756         pfc_queue_conf.tx_pause.pause_time = res->pause_time;
7757
7758         ret = rte_eth_dev_priority_flow_ctrl_queue_configure(res->port_id,
7759                                                              &pfc_queue_conf);
7760         if (ret != 0) {
7761                 fprintf(stderr,
7762                         "bad queue priority flow control parameter, rc = %d\n",
7763                         ret);
7764         }
7765 }
7766
7767 cmdline_parse_token_string_t cmd_q_pfc_set_set =
7768         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7769                                 set, "set");
7770 cmdline_parse_token_string_t cmd_q_pfc_set_flow_ctrl =
7771         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7772                                 pfc_queue_ctrl, "pfc_queue_ctrl");
7773 cmdline_parse_token_num_t cmd_q_pfc_set_portid =
7774         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7775                                 port_id, RTE_UINT16);
7776 cmdline_parse_token_string_t cmd_q_pfc_set_rx =
7777         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7778                                 rx, "rx");
7779 cmdline_parse_token_string_t cmd_q_pfc_set_rx_mode =
7780         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7781                                 rx_pfc_mode, "on#off");
7782 cmdline_parse_token_num_t cmd_q_pfc_set_tx_qid =
7783         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7784                                 tx_qid, RTE_UINT16);
7785 cmdline_parse_token_num_t cmd_q_pfc_set_tx_tc =
7786         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7787                                 tx_tc, RTE_UINT8);
7788 cmdline_parse_token_string_t cmd_q_pfc_set_tx =
7789         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7790                                 tx, "tx");
7791 cmdline_parse_token_string_t cmd_q_pfc_set_tx_mode =
7792         TOKEN_STRING_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7793                                 tx_pfc_mode, "on#off");
7794 cmdline_parse_token_num_t cmd_q_pfc_set_rx_qid =
7795         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7796                                 rx_qid, RTE_UINT16);
7797 cmdline_parse_token_num_t cmd_q_pfc_set_rx_tc =
7798         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7799                                 rx_tc, RTE_UINT8);
7800 cmdline_parse_token_num_t cmd_q_pfc_set_pause_time =
7801         TOKEN_NUM_INITIALIZER(struct cmd_queue_priority_flow_ctrl_set_result,
7802                                 pause_time, RTE_UINT16);
7803
7804 cmdline_parse_inst_t cmd_queue_priority_flow_control_set = {
7805         .f = cmd_queue_priority_flow_ctrl_set_parsed,
7806         .data = NULL,
7807         .help_str = "set pfc_queue_ctrl <port_id> rx <on|off> <tx_qid> <tx_tc> "
7808                 "tx <on|off> <rx_qid> <rx_tc> <pause_time>: "
7809                 "Configure the Ethernet queue priority flow control",
7810         .tokens = {
7811                 (void *)&cmd_q_pfc_set_set,
7812                 (void *)&cmd_q_pfc_set_flow_ctrl,
7813                 (void *)&cmd_q_pfc_set_portid,
7814                 (void *)&cmd_q_pfc_set_rx,
7815                 (void *)&cmd_q_pfc_set_rx_mode,
7816                 (void *)&cmd_q_pfc_set_tx_qid,
7817                 (void *)&cmd_q_pfc_set_tx_tc,
7818                 (void *)&cmd_q_pfc_set_tx,
7819                 (void *)&cmd_q_pfc_set_tx_mode,
7820                 (void *)&cmd_q_pfc_set_rx_qid,
7821                 (void *)&cmd_q_pfc_set_rx_tc,
7822                 (void *)&cmd_q_pfc_set_pause_time,
7823                 NULL,
7824         },
7825 };
7826
7827 /* *** RESET CONFIGURATION *** */
7828 struct cmd_reset_result {
7829         cmdline_fixed_string_t reset;
7830         cmdline_fixed_string_t def;
7831 };
7832
7833 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7834                              struct cmdline *cl,
7835                              __rte_unused void *data)
7836 {
7837         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7838         set_def_fwd_config();
7839 }
7840
7841 cmdline_parse_token_string_t cmd_reset_set =
7842         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7843 cmdline_parse_token_string_t cmd_reset_def =
7844         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7845                                  "default");
7846
7847 cmdline_parse_inst_t cmd_reset = {
7848         .f = cmd_reset_parsed,
7849         .data = NULL,
7850         .help_str = "set default: Reset default forwarding configuration",
7851         .tokens = {
7852                 (void *)&cmd_reset_set,
7853                 (void *)&cmd_reset_def,
7854                 NULL,
7855         },
7856 };
7857
7858 /* *** START FORWARDING *** */
7859 struct cmd_start_result {
7860         cmdline_fixed_string_t start;
7861 };
7862
7863 cmdline_parse_token_string_t cmd_start_start =
7864         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7865
7866 static void cmd_start_parsed(__rte_unused void *parsed_result,
7867                              __rte_unused struct cmdline *cl,
7868                              __rte_unused void *data)
7869 {
7870         start_packet_forwarding(0);
7871 }
7872
7873 cmdline_parse_inst_t cmd_start = {
7874         .f = cmd_start_parsed,
7875         .data = NULL,
7876         .help_str = "start: Start packet forwarding",
7877         .tokens = {
7878                 (void *)&cmd_start_start,
7879                 NULL,
7880         },
7881 };
7882
7883 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7884 struct cmd_start_tx_first_result {
7885         cmdline_fixed_string_t start;
7886         cmdline_fixed_string_t tx_first;
7887 };
7888
7889 static void
7890 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7891                           __rte_unused struct cmdline *cl,
7892                           __rte_unused void *data)
7893 {
7894         start_packet_forwarding(1);
7895 }
7896
7897 cmdline_parse_token_string_t cmd_start_tx_first_start =
7898         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7899                                  "start");
7900 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7901         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7902                                  tx_first, "tx_first");
7903
7904 cmdline_parse_inst_t cmd_start_tx_first = {
7905         .f = cmd_start_tx_first_parsed,
7906         .data = NULL,
7907         .help_str = "start tx_first: Start packet forwarding, "
7908                 "after sending 1 burst of packets",
7909         .tokens = {
7910                 (void *)&cmd_start_tx_first_start,
7911                 (void *)&cmd_start_tx_first_tx_first,
7912                 NULL,
7913         },
7914 };
7915
7916 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7917 struct cmd_start_tx_first_n_result {
7918         cmdline_fixed_string_t start;
7919         cmdline_fixed_string_t tx_first;
7920         uint32_t tx_num;
7921 };
7922
7923 static void
7924 cmd_start_tx_first_n_parsed(void *parsed_result,
7925                           __rte_unused struct cmdline *cl,
7926                           __rte_unused void *data)
7927 {
7928         struct cmd_start_tx_first_n_result *res = parsed_result;
7929
7930         start_packet_forwarding(res->tx_num);
7931 }
7932
7933 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7934         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7935                         start, "start");
7936 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7937         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7938                         tx_first, "tx_first");
7939 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7940         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7941                         tx_num, RTE_UINT32);
7942
7943 cmdline_parse_inst_t cmd_start_tx_first_n = {
7944         .f = cmd_start_tx_first_n_parsed,
7945         .data = NULL,
7946         .help_str = "start tx_first <num>: "
7947                 "packet forwarding, after sending <num> bursts of packets",
7948         .tokens = {
7949                 (void *)&cmd_start_tx_first_n_start,
7950                 (void *)&cmd_start_tx_first_n_tx_first,
7951                 (void *)&cmd_start_tx_first_n_tx_num,
7952                 NULL,
7953         },
7954 };
7955
7956 /* *** SET LINK UP *** */
7957 struct cmd_set_link_up_result {
7958         cmdline_fixed_string_t set;
7959         cmdline_fixed_string_t link_up;
7960         cmdline_fixed_string_t port;
7961         portid_t port_id;
7962 };
7963
7964 cmdline_parse_token_string_t cmd_set_link_up_set =
7965         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7966 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7967         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7968                                 "link-up");
7969 cmdline_parse_token_string_t cmd_set_link_up_port =
7970         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7971 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7972         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7973                                 RTE_UINT16);
7974
7975 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7976                              __rte_unused struct cmdline *cl,
7977                              __rte_unused void *data)
7978 {
7979         struct cmd_set_link_up_result *res = parsed_result;
7980         dev_set_link_up(res->port_id);
7981 }
7982
7983 cmdline_parse_inst_t cmd_set_link_up = {
7984         .f = cmd_set_link_up_parsed,
7985         .data = NULL,
7986         .help_str = "set link-up port <port id>",
7987         .tokens = {
7988                 (void *)&cmd_set_link_up_set,
7989                 (void *)&cmd_set_link_up_link_up,
7990                 (void *)&cmd_set_link_up_port,
7991                 (void *)&cmd_set_link_up_port_id,
7992                 NULL,
7993         },
7994 };
7995
7996 /* *** SET LINK DOWN *** */
7997 struct cmd_set_link_down_result {
7998         cmdline_fixed_string_t set;
7999         cmdline_fixed_string_t link_down;
8000         cmdline_fixed_string_t port;
8001         portid_t port_id;
8002 };
8003
8004 cmdline_parse_token_string_t cmd_set_link_down_set =
8005         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
8006 cmdline_parse_token_string_t cmd_set_link_down_link_down =
8007         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
8008                                 "link-down");
8009 cmdline_parse_token_string_t cmd_set_link_down_port =
8010         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
8011 cmdline_parse_token_num_t cmd_set_link_down_port_id =
8012         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
8013                                 RTE_UINT16);
8014
8015 static void cmd_set_link_down_parsed(
8016                                 __rte_unused void *parsed_result,
8017                                 __rte_unused struct cmdline *cl,
8018                                 __rte_unused void *data)
8019 {
8020         struct cmd_set_link_down_result *res = parsed_result;
8021         dev_set_link_down(res->port_id);
8022 }
8023
8024 cmdline_parse_inst_t cmd_set_link_down = {
8025         .f = cmd_set_link_down_parsed,
8026         .data = NULL,
8027         .help_str = "set link-down port <port id>",
8028         .tokens = {
8029                 (void *)&cmd_set_link_down_set,
8030                 (void *)&cmd_set_link_down_link_down,
8031                 (void *)&cmd_set_link_down_port,
8032                 (void *)&cmd_set_link_down_port_id,
8033                 NULL,
8034         },
8035 };
8036
8037 /* *** SHOW CFG *** */
8038 struct cmd_showcfg_result {
8039         cmdline_fixed_string_t show;
8040         cmdline_fixed_string_t cfg;
8041         cmdline_fixed_string_t what;
8042 };
8043
8044 static void cmd_showcfg_parsed(void *parsed_result,
8045                                __rte_unused struct cmdline *cl,
8046                                __rte_unused void *data)
8047 {
8048         struct cmd_showcfg_result *res = parsed_result;
8049         if (!strcmp(res->what, "rxtx"))
8050                 rxtx_config_display();
8051         else if (!strcmp(res->what, "cores"))
8052                 fwd_lcores_config_display();
8053         else if (!strcmp(res->what, "fwd"))
8054                 pkt_fwd_config_display(&cur_fwd_config);
8055         else if (!strcmp(res->what, "rxoffs"))
8056                 show_rx_pkt_offsets();
8057         else if (!strcmp(res->what, "rxpkts"))
8058                 show_rx_pkt_segments();
8059         else if (!strcmp(res->what, "txpkts"))
8060                 show_tx_pkt_segments();
8061         else if (!strcmp(res->what, "txtimes"))
8062                 show_tx_pkt_times();
8063 }
8064
8065 cmdline_parse_token_string_t cmd_showcfg_show =
8066         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
8067 cmdline_parse_token_string_t cmd_showcfg_port =
8068         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
8069 cmdline_parse_token_string_t cmd_showcfg_what =
8070         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
8071                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
8072
8073 cmdline_parse_inst_t cmd_showcfg = {
8074         .f = cmd_showcfg_parsed,
8075         .data = NULL,
8076         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
8077         .tokens = {
8078                 (void *)&cmd_showcfg_show,
8079                 (void *)&cmd_showcfg_port,
8080                 (void *)&cmd_showcfg_what,
8081                 NULL,
8082         },
8083 };
8084
8085 /* *** SHOW ALL PORT INFO *** */
8086 struct cmd_showportall_result {
8087         cmdline_fixed_string_t show;
8088         cmdline_fixed_string_t port;
8089         cmdline_fixed_string_t what;
8090         cmdline_fixed_string_t all;
8091 };
8092
8093 static void cmd_showportall_parsed(void *parsed_result,
8094                                 __rte_unused struct cmdline *cl,
8095                                 __rte_unused void *data)
8096 {
8097         portid_t i;
8098
8099         struct cmd_showportall_result *res = parsed_result;
8100         if (!strcmp(res->show, "clear")) {
8101                 if (!strcmp(res->what, "stats"))
8102                         RTE_ETH_FOREACH_DEV(i)
8103                                 nic_stats_clear(i);
8104                 else if (!strcmp(res->what, "xstats"))
8105                         RTE_ETH_FOREACH_DEV(i)
8106                                 nic_xstats_clear(i);
8107         } else if (!strcmp(res->what, "info"))
8108                 RTE_ETH_FOREACH_DEV(i)
8109                         port_infos_display(i);
8110         else if (!strcmp(res->what, "summary")) {
8111                 port_summary_header_display();
8112                 RTE_ETH_FOREACH_DEV(i)
8113                         port_summary_display(i);
8114         }
8115         else if (!strcmp(res->what, "stats"))
8116                 RTE_ETH_FOREACH_DEV(i)
8117                         nic_stats_display(i);
8118         else if (!strcmp(res->what, "xstats"))
8119                 RTE_ETH_FOREACH_DEV(i)
8120                         nic_xstats_display(i);
8121 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8122         else if (!strcmp(res->what, "fdir"))
8123                 RTE_ETH_FOREACH_DEV(i)
8124                         fdir_get_infos(i);
8125 #endif
8126         else if (!strcmp(res->what, "dcb_tc"))
8127                 RTE_ETH_FOREACH_DEV(i)
8128                         port_dcb_info_display(i);
8129 }
8130
8131 cmdline_parse_token_string_t cmd_showportall_show =
8132         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
8133                                  "show#clear");
8134 cmdline_parse_token_string_t cmd_showportall_port =
8135         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
8136 cmdline_parse_token_string_t cmd_showportall_what =
8137         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8138                                  "info#summary#stats#xstats#fdir#dcb_tc");
8139 cmdline_parse_token_string_t cmd_showportall_all =
8140         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8141 cmdline_parse_inst_t cmd_showportall = {
8142         .f = cmd_showportall_parsed,
8143         .data = NULL,
8144         .help_str = "show|clear port "
8145                 "info|summary|stats|xstats|fdir|dcb_tc all",
8146         .tokens = {
8147                 (void *)&cmd_showportall_show,
8148                 (void *)&cmd_showportall_port,
8149                 (void *)&cmd_showportall_what,
8150                 (void *)&cmd_showportall_all,
8151                 NULL,
8152         },
8153 };
8154
8155 /* *** SHOW PORT INFO *** */
8156 struct cmd_showport_result {
8157         cmdline_fixed_string_t show;
8158         cmdline_fixed_string_t port;
8159         cmdline_fixed_string_t what;
8160         uint16_t portnum;
8161 };
8162
8163 static void cmd_showport_parsed(void *parsed_result,
8164                                 __rte_unused struct cmdline *cl,
8165                                 __rte_unused void *data)
8166 {
8167         struct cmd_showport_result *res = parsed_result;
8168         if (!strcmp(res->show, "clear")) {
8169                 if (!strcmp(res->what, "stats"))
8170                         nic_stats_clear(res->portnum);
8171                 else if (!strcmp(res->what, "xstats"))
8172                         nic_xstats_clear(res->portnum);
8173         } else if (!strcmp(res->what, "info"))
8174                 port_infos_display(res->portnum);
8175         else if (!strcmp(res->what, "summary")) {
8176                 port_summary_header_display();
8177                 port_summary_display(res->portnum);
8178         }
8179         else if (!strcmp(res->what, "stats"))
8180                 nic_stats_display(res->portnum);
8181         else if (!strcmp(res->what, "xstats"))
8182                 nic_xstats_display(res->portnum);
8183 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8184         else if (!strcmp(res->what, "fdir"))
8185                  fdir_get_infos(res->portnum);
8186 #endif
8187         else if (!strcmp(res->what, "dcb_tc"))
8188                 port_dcb_info_display(res->portnum);
8189 }
8190
8191 cmdline_parse_token_string_t cmd_showport_show =
8192         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8193                                  "show#clear");
8194 cmdline_parse_token_string_t cmd_showport_port =
8195         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8196 cmdline_parse_token_string_t cmd_showport_what =
8197         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8198                                  "info#summary#stats#xstats#fdir#dcb_tc");
8199 cmdline_parse_token_num_t cmd_showport_portnum =
8200         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8201
8202 cmdline_parse_inst_t cmd_showport = {
8203         .f = cmd_showport_parsed,
8204         .data = NULL,
8205         .help_str = "show|clear port "
8206                 "info|summary|stats|xstats|fdir|dcb_tc "
8207                 "<port_id>",
8208         .tokens = {
8209                 (void *)&cmd_showport_show,
8210                 (void *)&cmd_showport_port,
8211                 (void *)&cmd_showport_what,
8212                 (void *)&cmd_showport_portnum,
8213                 NULL,
8214         },
8215 };
8216
8217 /* *** show port representors information *** */
8218 struct cmd_representor_info_result {
8219         cmdline_fixed_string_t cmd_show;
8220         cmdline_fixed_string_t cmd_port;
8221         cmdline_fixed_string_t cmd_info;
8222         cmdline_fixed_string_t cmd_keyword;
8223         portid_t cmd_pid;
8224 };
8225
8226 static void
8227 cmd_representor_info_parsed(void *parsed_result,
8228                 __rte_unused struct cmdline *cl,
8229                 __rte_unused void *data)
8230 {
8231         struct cmd_representor_info_result *res = parsed_result;
8232         struct rte_eth_representor_info *info;
8233         struct rte_eth_representor_range *range;
8234         uint32_t range_diff;
8235         uint32_t i;
8236         int ret;
8237         int num;
8238
8239         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8240                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8241                 return;
8242         }
8243
8244         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8245         if (ret < 0) {
8246                 fprintf(stderr,
8247                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8248                         res->cmd_pid, rte_strerror(-ret));
8249                 return;
8250         }
8251         num = ret;
8252
8253         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8254         if (info == NULL) {
8255                 fprintf(stderr,
8256                         "Failed to allocate memory for representor info for port %hu\n",
8257                         res->cmd_pid);
8258                 return;
8259         }
8260         info->nb_ranges_alloc = num;
8261
8262         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8263         if (ret < 0) {
8264                 fprintf(stderr,
8265                         "Failed to get the representor info for port %hu: %s\n",
8266                         res->cmd_pid, rte_strerror(-ret));
8267                 free(info);
8268                 return;
8269         }
8270
8271         printf("Port controller: %hu\n", info->controller);
8272         printf("Port PF: %hu\n", info->pf);
8273
8274         printf("Ranges: %u\n", info->nb_ranges);
8275         for (i = 0; i < info->nb_ranges; i++) {
8276                 range = &info->ranges[i];
8277                 range_diff = range->id_end - range->id_base;
8278
8279                 printf("%u. ", i + 1);
8280                 printf("'%s' ", range->name);
8281                 if (range_diff > 0)
8282                         printf("[%u-%u]: ", range->id_base, range->id_end);
8283                 else
8284                         printf("[%u]: ", range->id_base);
8285
8286                 printf("Controller %d, PF %d", range->controller, range->pf);
8287
8288                 switch (range->type) {
8289                 case RTE_ETH_REPRESENTOR_NONE:
8290                         printf(", NONE\n");
8291                         break;
8292                 case RTE_ETH_REPRESENTOR_VF:
8293                         if (range_diff > 0)
8294                                 printf(", VF %d..%d\n", range->vf,
8295                                        range->vf + range_diff);
8296                         else
8297                                 printf(", VF %d\n", range->vf);
8298                         break;
8299                 case RTE_ETH_REPRESENTOR_SF:
8300                         printf(", SF %d\n", range->sf);
8301                         break;
8302                 case RTE_ETH_REPRESENTOR_PF:
8303                         if (range_diff > 0)
8304                                 printf("..%d\n", range->pf + range_diff);
8305                         else
8306                                 printf("\n");
8307                         break;
8308                 default:
8309                         printf(", UNKNOWN TYPE %d\n", range->type);
8310                         break;
8311                 }
8312         }
8313
8314         free(info);
8315 }
8316
8317 cmdline_parse_token_string_t cmd_representor_info_show =
8318         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8319                         cmd_show, "show");
8320 cmdline_parse_token_string_t cmd_representor_info_port =
8321         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8322                         cmd_port, "port");
8323 cmdline_parse_token_string_t cmd_representor_info_info =
8324         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8325                         cmd_info, "info");
8326 cmdline_parse_token_num_t cmd_representor_info_pid =
8327         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8328                         cmd_pid, RTE_UINT16);
8329 cmdline_parse_token_string_t cmd_representor_info_keyword =
8330         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8331                         cmd_keyword, "representor");
8332
8333 cmdline_parse_inst_t cmd_representor_info = {
8334         .f = cmd_representor_info_parsed,
8335         .data = NULL,
8336         .help_str = "show port info <port_id> representor",
8337         .tokens = {
8338                 (void *)&cmd_representor_info_show,
8339                 (void *)&cmd_representor_info_port,
8340                 (void *)&cmd_representor_info_info,
8341                 (void *)&cmd_representor_info_pid,
8342                 (void *)&cmd_representor_info_keyword,
8343                 NULL,
8344         },
8345 };
8346
8347
8348 /* *** SHOW DEVICE INFO *** */
8349 struct cmd_showdevice_result {
8350         cmdline_fixed_string_t show;
8351         cmdline_fixed_string_t device;
8352         cmdline_fixed_string_t what;
8353         cmdline_fixed_string_t identifier;
8354 };
8355
8356 static void cmd_showdevice_parsed(void *parsed_result,
8357                                 __rte_unused struct cmdline *cl,
8358                                 __rte_unused void *data)
8359 {
8360         struct cmd_showdevice_result *res = parsed_result;
8361         if (!strcmp(res->what, "info")) {
8362                 if (!strcmp(res->identifier, "all"))
8363                         device_infos_display(NULL);
8364                 else
8365                         device_infos_display(res->identifier);
8366         }
8367 }
8368
8369 cmdline_parse_token_string_t cmd_showdevice_show =
8370         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8371                                  "show");
8372 cmdline_parse_token_string_t cmd_showdevice_device =
8373         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8374 cmdline_parse_token_string_t cmd_showdevice_what =
8375         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8376                                  "info");
8377 cmdline_parse_token_string_t cmd_showdevice_identifier =
8378         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8379                         identifier, NULL);
8380
8381 cmdline_parse_inst_t cmd_showdevice = {
8382         .f = cmd_showdevice_parsed,
8383         .data = NULL,
8384         .help_str = "show device info <identifier>|all",
8385         .tokens = {
8386                 (void *)&cmd_showdevice_show,
8387                 (void *)&cmd_showdevice_device,
8388                 (void *)&cmd_showdevice_what,
8389                 (void *)&cmd_showdevice_identifier,
8390                 NULL,
8391         },
8392 };
8393
8394 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8395 struct cmd_showeeprom_result {
8396         cmdline_fixed_string_t show;
8397         cmdline_fixed_string_t port;
8398         uint16_t portnum;
8399         cmdline_fixed_string_t type;
8400 };
8401
8402 static void cmd_showeeprom_parsed(void *parsed_result,
8403                 __rte_unused struct cmdline *cl,
8404                 __rte_unused void *data)
8405 {
8406         struct cmd_showeeprom_result *res = parsed_result;
8407
8408         if (!strcmp(res->type, "eeprom"))
8409                 port_eeprom_display(res->portnum);
8410         else if (!strcmp(res->type, "module_eeprom"))
8411                 port_module_eeprom_display(res->portnum);
8412         else
8413                 fprintf(stderr, "Unknown argument\n");
8414 }
8415
8416 cmdline_parse_token_string_t cmd_showeeprom_show =
8417         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8418 cmdline_parse_token_string_t cmd_showeeprom_port =
8419         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8420 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8421         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8422                         RTE_UINT16);
8423 cmdline_parse_token_string_t cmd_showeeprom_type =
8424         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8425
8426 cmdline_parse_inst_t cmd_showeeprom = {
8427         .f = cmd_showeeprom_parsed,
8428         .data = NULL,
8429         .help_str = "show port <port_id> module_eeprom|eeprom",
8430         .tokens = {
8431                 (void *)&cmd_showeeprom_show,
8432                 (void *)&cmd_showeeprom_port,
8433                 (void *)&cmd_showeeprom_portnum,
8434                 (void *)&cmd_showeeprom_type,
8435                 NULL,
8436         },
8437 };
8438
8439 /* *** SHOW QUEUE INFO *** */
8440 struct cmd_showqueue_result {
8441         cmdline_fixed_string_t show;
8442         cmdline_fixed_string_t type;
8443         cmdline_fixed_string_t what;
8444         uint16_t portnum;
8445         uint16_t queuenum;
8446 };
8447
8448 static void
8449 cmd_showqueue_parsed(void *parsed_result,
8450         __rte_unused struct cmdline *cl,
8451         __rte_unused void *data)
8452 {
8453         struct cmd_showqueue_result *res = parsed_result;
8454
8455         if (!strcmp(res->type, "rxq"))
8456                 rx_queue_infos_display(res->portnum, res->queuenum);
8457         else if (!strcmp(res->type, "txq"))
8458                 tx_queue_infos_display(res->portnum, res->queuenum);
8459 }
8460
8461 cmdline_parse_token_string_t cmd_showqueue_show =
8462         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8463 cmdline_parse_token_string_t cmd_showqueue_type =
8464         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8465 cmdline_parse_token_string_t cmd_showqueue_what =
8466         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8467 cmdline_parse_token_num_t cmd_showqueue_portnum =
8468         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8469                 RTE_UINT16);
8470 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8471         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8472                 RTE_UINT16);
8473
8474 cmdline_parse_inst_t cmd_showqueue = {
8475         .f = cmd_showqueue_parsed,
8476         .data = NULL,
8477         .help_str = "show rxq|txq info <port_id> <queue_id>",
8478         .tokens = {
8479                 (void *)&cmd_showqueue_show,
8480                 (void *)&cmd_showqueue_type,
8481                 (void *)&cmd_showqueue_what,
8482                 (void *)&cmd_showqueue_portnum,
8483                 (void *)&cmd_showqueue_queuenum,
8484                 NULL,
8485         },
8486 };
8487
8488 /* show/clear fwd engine statistics */
8489 struct fwd_result {
8490         cmdline_fixed_string_t action;
8491         cmdline_fixed_string_t fwd;
8492         cmdline_fixed_string_t stats;
8493         cmdline_fixed_string_t all;
8494 };
8495
8496 cmdline_parse_token_string_t cmd_fwd_action =
8497         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8498 cmdline_parse_token_string_t cmd_fwd_fwd =
8499         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8500 cmdline_parse_token_string_t cmd_fwd_stats =
8501         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8502 cmdline_parse_token_string_t cmd_fwd_all =
8503         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8504
8505 static void
8506 cmd_showfwdall_parsed(void *parsed_result,
8507                       __rte_unused struct cmdline *cl,
8508                       __rte_unused void *data)
8509 {
8510         struct fwd_result *res = parsed_result;
8511
8512         if (!strcmp(res->action, "show"))
8513                 fwd_stats_display();
8514         else
8515                 fwd_stats_reset();
8516 }
8517
8518 static cmdline_parse_inst_t cmd_showfwdall = {
8519         .f = cmd_showfwdall_parsed,
8520         .data = NULL,
8521         .help_str = "show|clear fwd stats all",
8522         .tokens = {
8523                 (void *)&cmd_fwd_action,
8524                 (void *)&cmd_fwd_fwd,
8525                 (void *)&cmd_fwd_stats,
8526                 (void *)&cmd_fwd_all,
8527                 NULL,
8528         },
8529 };
8530
8531 /* *** READ PORT REGISTER *** */
8532 struct cmd_read_reg_result {
8533         cmdline_fixed_string_t read;
8534         cmdline_fixed_string_t reg;
8535         portid_t port_id;
8536         uint32_t reg_off;
8537 };
8538
8539 static void
8540 cmd_read_reg_parsed(void *parsed_result,
8541                     __rte_unused struct cmdline *cl,
8542                     __rte_unused void *data)
8543 {
8544         struct cmd_read_reg_result *res = parsed_result;
8545         port_reg_display(res->port_id, res->reg_off);
8546 }
8547
8548 cmdline_parse_token_string_t cmd_read_reg_read =
8549         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8550 cmdline_parse_token_string_t cmd_read_reg_reg =
8551         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8552 cmdline_parse_token_num_t cmd_read_reg_port_id =
8553         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8554 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8555         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8556
8557 cmdline_parse_inst_t cmd_read_reg = {
8558         .f = cmd_read_reg_parsed,
8559         .data = NULL,
8560         .help_str = "read reg <port_id> <reg_off>",
8561         .tokens = {
8562                 (void *)&cmd_read_reg_read,
8563                 (void *)&cmd_read_reg_reg,
8564                 (void *)&cmd_read_reg_port_id,
8565                 (void *)&cmd_read_reg_reg_off,
8566                 NULL,
8567         },
8568 };
8569
8570 /* *** READ PORT REGISTER BIT FIELD *** */
8571 struct cmd_read_reg_bit_field_result {
8572         cmdline_fixed_string_t read;
8573         cmdline_fixed_string_t regfield;
8574         portid_t port_id;
8575         uint32_t reg_off;
8576         uint8_t bit1_pos;
8577         uint8_t bit2_pos;
8578 };
8579
8580 static void
8581 cmd_read_reg_bit_field_parsed(void *parsed_result,
8582                               __rte_unused struct cmdline *cl,
8583                               __rte_unused void *data)
8584 {
8585         struct cmd_read_reg_bit_field_result *res = parsed_result;
8586         port_reg_bit_field_display(res->port_id, res->reg_off,
8587                                    res->bit1_pos, res->bit2_pos);
8588 }
8589
8590 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8591         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8592                                  "read");
8593 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8594         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8595                                  regfield, "regfield");
8596 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8597         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8598                               RTE_UINT16);
8599 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8600         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8601                               RTE_UINT32);
8602 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8603         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8604                               RTE_UINT8);
8605 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8606         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8607                               RTE_UINT8);
8608
8609 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8610         .f = cmd_read_reg_bit_field_parsed,
8611         .data = NULL,
8612         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8613         "Read register bit field between bit_x and bit_y included",
8614         .tokens = {
8615                 (void *)&cmd_read_reg_bit_field_read,
8616                 (void *)&cmd_read_reg_bit_field_regfield,
8617                 (void *)&cmd_read_reg_bit_field_port_id,
8618                 (void *)&cmd_read_reg_bit_field_reg_off,
8619                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8620                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8621                 NULL,
8622         },
8623 };
8624
8625 /* *** READ PORT REGISTER BIT *** */
8626 struct cmd_read_reg_bit_result {
8627         cmdline_fixed_string_t read;
8628         cmdline_fixed_string_t regbit;
8629         portid_t port_id;
8630         uint32_t reg_off;
8631         uint8_t bit_pos;
8632 };
8633
8634 static void
8635 cmd_read_reg_bit_parsed(void *parsed_result,
8636                         __rte_unused struct cmdline *cl,
8637                         __rte_unused void *data)
8638 {
8639         struct cmd_read_reg_bit_result *res = parsed_result;
8640         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8641 }
8642
8643 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8644         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8645 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8646         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8647                                  regbit, "regbit");
8648 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8649         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8650                                  RTE_UINT16);
8651 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8652         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8653                                  RTE_UINT32);
8654 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8655         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8656                                  RTE_UINT8);
8657
8658 cmdline_parse_inst_t cmd_read_reg_bit = {
8659         .f = cmd_read_reg_bit_parsed,
8660         .data = NULL,
8661         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8662         .tokens = {
8663                 (void *)&cmd_read_reg_bit_read,
8664                 (void *)&cmd_read_reg_bit_regbit,
8665                 (void *)&cmd_read_reg_bit_port_id,
8666                 (void *)&cmd_read_reg_bit_reg_off,
8667                 (void *)&cmd_read_reg_bit_bit_pos,
8668                 NULL,
8669         },
8670 };
8671
8672 /* *** WRITE PORT REGISTER *** */
8673 struct cmd_write_reg_result {
8674         cmdline_fixed_string_t write;
8675         cmdline_fixed_string_t reg;
8676         portid_t port_id;
8677         uint32_t reg_off;
8678         uint32_t value;
8679 };
8680
8681 static void
8682 cmd_write_reg_parsed(void *parsed_result,
8683                      __rte_unused struct cmdline *cl,
8684                      __rte_unused void *data)
8685 {
8686         struct cmd_write_reg_result *res = parsed_result;
8687         port_reg_set(res->port_id, res->reg_off, res->value);
8688 }
8689
8690 cmdline_parse_token_string_t cmd_write_reg_write =
8691         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8692 cmdline_parse_token_string_t cmd_write_reg_reg =
8693         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8694 cmdline_parse_token_num_t cmd_write_reg_port_id =
8695         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8696 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8697         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8698 cmdline_parse_token_num_t cmd_write_reg_value =
8699         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8700
8701 cmdline_parse_inst_t cmd_write_reg = {
8702         .f = cmd_write_reg_parsed,
8703         .data = NULL,
8704         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8705         .tokens = {
8706                 (void *)&cmd_write_reg_write,
8707                 (void *)&cmd_write_reg_reg,
8708                 (void *)&cmd_write_reg_port_id,
8709                 (void *)&cmd_write_reg_reg_off,
8710                 (void *)&cmd_write_reg_value,
8711                 NULL,
8712         },
8713 };
8714
8715 /* *** WRITE PORT REGISTER BIT FIELD *** */
8716 struct cmd_write_reg_bit_field_result {
8717         cmdline_fixed_string_t write;
8718         cmdline_fixed_string_t regfield;
8719         portid_t port_id;
8720         uint32_t reg_off;
8721         uint8_t bit1_pos;
8722         uint8_t bit2_pos;
8723         uint32_t value;
8724 };
8725
8726 static void
8727 cmd_write_reg_bit_field_parsed(void *parsed_result,
8728                                __rte_unused struct cmdline *cl,
8729                                __rte_unused void *data)
8730 {
8731         struct cmd_write_reg_bit_field_result *res = parsed_result;
8732         port_reg_bit_field_set(res->port_id, res->reg_off,
8733                           res->bit1_pos, res->bit2_pos, res->value);
8734 }
8735
8736 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8737         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8738                                  "write");
8739 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8740         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8741                                  regfield, "regfield");
8742 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8743         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8744                               RTE_UINT16);
8745 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8746         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8747                               RTE_UINT32);
8748 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8749         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8750                               RTE_UINT8);
8751 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8752         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8753                               RTE_UINT8);
8754 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8755         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8756                               RTE_UINT32);
8757
8758 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8759         .f = cmd_write_reg_bit_field_parsed,
8760         .data = NULL,
8761         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8762                 "<reg_value>: "
8763                 "Set register bit field between bit_x and bit_y included",
8764         .tokens = {
8765                 (void *)&cmd_write_reg_bit_field_write,
8766                 (void *)&cmd_write_reg_bit_field_regfield,
8767                 (void *)&cmd_write_reg_bit_field_port_id,
8768                 (void *)&cmd_write_reg_bit_field_reg_off,
8769                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8770                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8771                 (void *)&cmd_write_reg_bit_field_value,
8772                 NULL,
8773         },
8774 };
8775
8776 /* *** WRITE PORT REGISTER BIT *** */
8777 struct cmd_write_reg_bit_result {
8778         cmdline_fixed_string_t write;
8779         cmdline_fixed_string_t regbit;
8780         portid_t port_id;
8781         uint32_t reg_off;
8782         uint8_t bit_pos;
8783         uint8_t value;
8784 };
8785
8786 static void
8787 cmd_write_reg_bit_parsed(void *parsed_result,
8788                          __rte_unused struct cmdline *cl,
8789                          __rte_unused void *data)
8790 {
8791         struct cmd_write_reg_bit_result *res = parsed_result;
8792         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8793 }
8794
8795 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8796         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8797                                  "write");
8798 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8799         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8800                                  regbit, "regbit");
8801 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8802         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8803                                  RTE_UINT16);
8804 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8805         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8806                                  RTE_UINT32);
8807 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8808         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8809                                  RTE_UINT8);
8810 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8811         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8812                                  RTE_UINT8);
8813
8814 cmdline_parse_inst_t cmd_write_reg_bit = {
8815         .f = cmd_write_reg_bit_parsed,
8816         .data = NULL,
8817         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8818                 "0 <= bit_x <= 31",
8819         .tokens = {
8820                 (void *)&cmd_write_reg_bit_write,
8821                 (void *)&cmd_write_reg_bit_regbit,
8822                 (void *)&cmd_write_reg_bit_port_id,
8823                 (void *)&cmd_write_reg_bit_reg_off,
8824                 (void *)&cmd_write_reg_bit_bit_pos,
8825                 (void *)&cmd_write_reg_bit_value,
8826                 NULL,
8827         },
8828 };
8829
8830 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8831 struct cmd_read_rxd_txd_result {
8832         cmdline_fixed_string_t read;
8833         cmdline_fixed_string_t rxd_txd;
8834         portid_t port_id;
8835         uint16_t queue_id;
8836         uint16_t desc_id;
8837 };
8838
8839 static void
8840 cmd_read_rxd_txd_parsed(void *parsed_result,
8841                         __rte_unused struct cmdline *cl,
8842                         __rte_unused void *data)
8843 {
8844         struct cmd_read_rxd_txd_result *res = parsed_result;
8845
8846         if (!strcmp(res->rxd_txd, "rxd"))
8847                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8848         else if (!strcmp(res->rxd_txd, "txd"))
8849                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8850 }
8851
8852 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8853         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8854 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8855         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8856                                  "rxd#txd");
8857 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8858         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8859                                  RTE_UINT16);
8860 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8861         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8862                                  RTE_UINT16);
8863 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8864         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8865                                  RTE_UINT16);
8866
8867 cmdline_parse_inst_t cmd_read_rxd_txd = {
8868         .f = cmd_read_rxd_txd_parsed,
8869         .data = NULL,
8870         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8871         .tokens = {
8872                 (void *)&cmd_read_rxd_txd_read,
8873                 (void *)&cmd_read_rxd_txd_rxd_txd,
8874                 (void *)&cmd_read_rxd_txd_port_id,
8875                 (void *)&cmd_read_rxd_txd_queue_id,
8876                 (void *)&cmd_read_rxd_txd_desc_id,
8877                 NULL,
8878         },
8879 };
8880
8881 /* *** QUIT *** */
8882 struct cmd_quit_result {
8883         cmdline_fixed_string_t quit;
8884 };
8885
8886 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8887                             struct cmdline *cl,
8888                             __rte_unused void *data)
8889 {
8890         cmdline_quit(cl);
8891 }
8892
8893 cmdline_parse_token_string_t cmd_quit_quit =
8894         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8895
8896 cmdline_parse_inst_t cmd_quit = {
8897         .f = cmd_quit_parsed,
8898         .data = NULL,
8899         .help_str = "quit: Exit application",
8900         .tokens = {
8901                 (void *)&cmd_quit_quit,
8902                 NULL,
8903         },
8904 };
8905
8906 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8907 struct cmd_mac_addr_result {
8908         cmdline_fixed_string_t mac_addr_cmd;
8909         cmdline_fixed_string_t what;
8910         uint16_t port_num;
8911         struct rte_ether_addr address;
8912 };
8913
8914 static void cmd_mac_addr_parsed(void *parsed_result,
8915                 __rte_unused struct cmdline *cl,
8916                 __rte_unused void *data)
8917 {
8918         struct cmd_mac_addr_result *res = parsed_result;
8919         int ret;
8920
8921         if (strcmp(res->what, "add") == 0)
8922                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8923         else if (strcmp(res->what, "set") == 0)
8924                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8925                                                        &res->address);
8926         else
8927                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8928
8929         /* check the return value and print it if is < 0 */
8930         if(ret < 0)
8931                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8932
8933 }
8934
8935 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8936         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8937                                 "mac_addr");
8938 cmdline_parse_token_string_t cmd_mac_addr_what =
8939         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8940                                 "add#remove#set");
8941 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8942                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8943                                         RTE_UINT16);
8944 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8945                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8946
8947 cmdline_parse_inst_t cmd_mac_addr = {
8948         .f = cmd_mac_addr_parsed,
8949         .data = (void *)0,
8950         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8951                         "Add/Remove/Set MAC address on port_id",
8952         .tokens = {
8953                 (void *)&cmd_mac_addr_cmd,
8954                 (void *)&cmd_mac_addr_what,
8955                 (void *)&cmd_mac_addr_portnum,
8956                 (void *)&cmd_mac_addr_addr,
8957                 NULL,
8958         },
8959 };
8960
8961 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8962 struct cmd_eth_peer_result {
8963         cmdline_fixed_string_t set;
8964         cmdline_fixed_string_t eth_peer;
8965         portid_t port_id;
8966         cmdline_fixed_string_t peer_addr;
8967 };
8968
8969 static void cmd_set_eth_peer_parsed(void *parsed_result,
8970                         __rte_unused struct cmdline *cl,
8971                         __rte_unused void *data)
8972 {
8973                 struct cmd_eth_peer_result *res = parsed_result;
8974
8975                 if (test_done == 0) {
8976                         fprintf(stderr, "Please stop forwarding first\n");
8977                         return;
8978                 }
8979                 if (!strcmp(res->eth_peer, "eth-peer")) {
8980                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8981                         fwd_config_setup();
8982                 }
8983 }
8984 cmdline_parse_token_string_t cmd_eth_peer_set =
8985         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8986 cmdline_parse_token_string_t cmd_eth_peer =
8987         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8988 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8989         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8990                 RTE_UINT16);
8991 cmdline_parse_token_string_t cmd_eth_peer_addr =
8992         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8993
8994 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8995         .f = cmd_set_eth_peer_parsed,
8996         .data = NULL,
8997         .help_str = "set eth-peer <port_id> <peer_mac>",
8998         .tokens = {
8999                 (void *)&cmd_eth_peer_set,
9000                 (void *)&cmd_eth_peer,
9001                 (void *)&cmd_eth_peer_port_id,
9002                 (void *)&cmd_eth_peer_addr,
9003                 NULL,
9004         },
9005 };
9006
9007 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
9008 struct cmd_set_qmap_result {
9009         cmdline_fixed_string_t set;
9010         cmdline_fixed_string_t qmap;
9011         cmdline_fixed_string_t what;
9012         portid_t port_id;
9013         uint16_t queue_id;
9014         uint8_t map_value;
9015 };
9016
9017 static void
9018 cmd_set_qmap_parsed(void *parsed_result,
9019                        __rte_unused struct cmdline *cl,
9020                        __rte_unused void *data)
9021 {
9022         struct cmd_set_qmap_result *res = parsed_result;
9023         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
9024
9025         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
9026 }
9027
9028 cmdline_parse_token_string_t cmd_setqmap_set =
9029         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9030                                  set, "set");
9031 cmdline_parse_token_string_t cmd_setqmap_qmap =
9032         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9033                                  qmap, "stat_qmap");
9034 cmdline_parse_token_string_t cmd_setqmap_what =
9035         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
9036                                  what, "tx#rx");
9037 cmdline_parse_token_num_t cmd_setqmap_portid =
9038         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9039                               port_id, RTE_UINT16);
9040 cmdline_parse_token_num_t cmd_setqmap_queueid =
9041         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9042                               queue_id, RTE_UINT16);
9043 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
9044         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
9045                               map_value, RTE_UINT8);
9046
9047 cmdline_parse_inst_t cmd_set_qmap = {
9048         .f = cmd_set_qmap_parsed,
9049         .data = NULL,
9050         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
9051                 "Set statistics mapping value on tx|rx queue_id of port_id",
9052         .tokens = {
9053                 (void *)&cmd_setqmap_set,
9054                 (void *)&cmd_setqmap_qmap,
9055                 (void *)&cmd_setqmap_what,
9056                 (void *)&cmd_setqmap_portid,
9057                 (void *)&cmd_setqmap_queueid,
9058                 (void *)&cmd_setqmap_mapvalue,
9059                 NULL,
9060         },
9061 };
9062
9063 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
9064 struct cmd_set_xstats_hide_zero_result {
9065         cmdline_fixed_string_t keyword;
9066         cmdline_fixed_string_t name;
9067         cmdline_fixed_string_t on_off;
9068 };
9069
9070 static void
9071 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
9072                         __rte_unused struct cmdline *cl,
9073                         __rte_unused void *data)
9074 {
9075         struct cmd_set_xstats_hide_zero_result *res;
9076         uint16_t on_off = 0;
9077
9078         res = parsed_result;
9079         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9080         set_xstats_hide_zero(on_off);
9081 }
9082
9083 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
9084         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9085                                  keyword, "set");
9086 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
9087         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9088                                  name, "xstats-hide-zero");
9089 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
9090         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
9091                                  on_off, "on#off");
9092
9093 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
9094         .f = cmd_set_xstats_hide_zero_parsed,
9095         .data = NULL,
9096         .help_str = "set xstats-hide-zero on|off",
9097         .tokens = {
9098                 (void *)&cmd_set_xstats_hide_zero_keyword,
9099                 (void *)&cmd_set_xstats_hide_zero_name,
9100                 (void *)&cmd_set_xstats_hide_zero_on_off,
9101                 NULL,
9102         },
9103 };
9104
9105 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
9106 struct cmd_set_record_core_cycles_result {
9107         cmdline_fixed_string_t keyword;
9108         cmdline_fixed_string_t name;
9109         cmdline_fixed_string_t on_off;
9110 };
9111
9112 static void
9113 cmd_set_record_core_cycles_parsed(void *parsed_result,
9114                         __rte_unused struct cmdline *cl,
9115                         __rte_unused void *data)
9116 {
9117         struct cmd_set_record_core_cycles_result *res;
9118         uint16_t on_off = 0;
9119
9120         res = parsed_result;
9121         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9122         set_record_core_cycles(on_off);
9123 }
9124
9125 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
9126         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9127                                  keyword, "set");
9128 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
9129         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9130                                  name, "record-core-cycles");
9131 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
9132         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
9133                                  on_off, "on#off");
9134
9135 cmdline_parse_inst_t cmd_set_record_core_cycles = {
9136         .f = cmd_set_record_core_cycles_parsed,
9137         .data = NULL,
9138         .help_str = "set record-core-cycles on|off",
9139         .tokens = {
9140                 (void *)&cmd_set_record_core_cycles_keyword,
9141                 (void *)&cmd_set_record_core_cycles_name,
9142                 (void *)&cmd_set_record_core_cycles_on_off,
9143                 NULL,
9144         },
9145 };
9146
9147 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9148 struct cmd_set_record_burst_stats_result {
9149         cmdline_fixed_string_t keyword;
9150         cmdline_fixed_string_t name;
9151         cmdline_fixed_string_t on_off;
9152 };
9153
9154 static void
9155 cmd_set_record_burst_stats_parsed(void *parsed_result,
9156                         __rte_unused struct cmdline *cl,
9157                         __rte_unused void *data)
9158 {
9159         struct cmd_set_record_burst_stats_result *res;
9160         uint16_t on_off = 0;
9161
9162         res = parsed_result;
9163         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9164         set_record_burst_stats(on_off);
9165 }
9166
9167 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9168         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9169                                  keyword, "set");
9170 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9171         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9172                                  name, "record-burst-stats");
9173 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9174         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9175                                  on_off, "on#off");
9176
9177 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9178         .f = cmd_set_record_burst_stats_parsed,
9179         .data = NULL,
9180         .help_str = "set record-burst-stats on|off",
9181         .tokens = {
9182                 (void *)&cmd_set_record_burst_stats_keyword,
9183                 (void *)&cmd_set_record_burst_stats_name,
9184                 (void *)&cmd_set_record_burst_stats_on_off,
9185                 NULL,
9186         },
9187 };
9188
9189 /* *** CONFIGURE UNICAST HASH TABLE *** */
9190 struct cmd_set_uc_hash_table {
9191         cmdline_fixed_string_t set;
9192         cmdline_fixed_string_t port;
9193         portid_t port_id;
9194         cmdline_fixed_string_t what;
9195         struct rte_ether_addr address;
9196         cmdline_fixed_string_t mode;
9197 };
9198
9199 static void
9200 cmd_set_uc_hash_parsed(void *parsed_result,
9201                        __rte_unused struct cmdline *cl,
9202                        __rte_unused void *data)
9203 {
9204         int ret=0;
9205         struct cmd_set_uc_hash_table *res = parsed_result;
9206
9207         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9208
9209         if (strcmp(res->what, "uta") == 0)
9210                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9211                                                 &res->address,(uint8_t)is_on);
9212         if (ret < 0)
9213                 fprintf(stderr,
9214                         "bad unicast hash table parameter, return code = %d\n",
9215                         ret);
9216
9217 }
9218
9219 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9220         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9221                                  set, "set");
9222 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9223         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9224                                  port, "port");
9225 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9226         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9227                               port_id, RTE_UINT16);
9228 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9229         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9230                                  what, "uta");
9231 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9232         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9233                                 address);
9234 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9235         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9236                                  mode, "on#off");
9237
9238 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9239         .f = cmd_set_uc_hash_parsed,
9240         .data = NULL,
9241         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9242         .tokens = {
9243                 (void *)&cmd_set_uc_hash_set,
9244                 (void *)&cmd_set_uc_hash_port,
9245                 (void *)&cmd_set_uc_hash_portid,
9246                 (void *)&cmd_set_uc_hash_what,
9247                 (void *)&cmd_set_uc_hash_mac,
9248                 (void *)&cmd_set_uc_hash_mode,
9249                 NULL,
9250         },
9251 };
9252
9253 struct cmd_set_uc_all_hash_table {
9254         cmdline_fixed_string_t set;
9255         cmdline_fixed_string_t port;
9256         portid_t port_id;
9257         cmdline_fixed_string_t what;
9258         cmdline_fixed_string_t value;
9259         cmdline_fixed_string_t mode;
9260 };
9261
9262 static void
9263 cmd_set_uc_all_hash_parsed(void *parsed_result,
9264                        __rte_unused struct cmdline *cl,
9265                        __rte_unused void *data)
9266 {
9267         int ret=0;
9268         struct cmd_set_uc_all_hash_table *res = parsed_result;
9269
9270         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9271
9272         if ((strcmp(res->what, "uta") == 0) &&
9273                 (strcmp(res->value, "all") == 0))
9274                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9275         if (ret < 0)
9276                 fprintf(stderr,
9277                         "bad unicast hash table parameter, return code = %d\n",
9278                         ret);
9279 }
9280
9281 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9282         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9283                                  set, "set");
9284 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9285         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9286                                  port, "port");
9287 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9288         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9289                               port_id, RTE_UINT16);
9290 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9291         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9292                                  what, "uta");
9293 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9294         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9295                                 value,"all");
9296 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9297         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9298                                  mode, "on#off");
9299
9300 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9301         .f = cmd_set_uc_all_hash_parsed,
9302         .data = NULL,
9303         .help_str = "set port <port_id> uta all on|off",
9304         .tokens = {
9305                 (void *)&cmd_set_uc_all_hash_set,
9306                 (void *)&cmd_set_uc_all_hash_port,
9307                 (void *)&cmd_set_uc_all_hash_portid,
9308                 (void *)&cmd_set_uc_all_hash_what,
9309                 (void *)&cmd_set_uc_all_hash_value,
9310                 (void *)&cmd_set_uc_all_hash_mode,
9311                 NULL,
9312         },
9313 };
9314
9315 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9316 struct cmd_set_vf_traffic {
9317         cmdline_fixed_string_t set;
9318         cmdline_fixed_string_t port;
9319         portid_t port_id;
9320         cmdline_fixed_string_t vf;
9321         uint8_t vf_id;
9322         cmdline_fixed_string_t what;
9323         cmdline_fixed_string_t mode;
9324 };
9325
9326 static void
9327 cmd_set_vf_traffic_parsed(void *parsed_result,
9328                        __rte_unused struct cmdline *cl,
9329                        __rte_unused void *data)
9330 {
9331         struct cmd_set_vf_traffic *res = parsed_result;
9332         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9333         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9334
9335         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9336 }
9337
9338 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9339         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9340                                  set, "set");
9341 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9342         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9343                                  port, "port");
9344 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9345         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9346                               port_id, RTE_UINT16);
9347 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9348         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9349                                  vf, "vf");
9350 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9351         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9352                               vf_id, RTE_UINT8);
9353 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9354         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9355                                  what, "tx#rx");
9356 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9357         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9358                                  mode, "on#off");
9359
9360 cmdline_parse_inst_t cmd_set_vf_traffic = {
9361         .f = cmd_set_vf_traffic_parsed,
9362         .data = NULL,
9363         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9364         .tokens = {
9365                 (void *)&cmd_setvf_traffic_set,
9366                 (void *)&cmd_setvf_traffic_port,
9367                 (void *)&cmd_setvf_traffic_portid,
9368                 (void *)&cmd_setvf_traffic_vf,
9369                 (void *)&cmd_setvf_traffic_vfid,
9370                 (void *)&cmd_setvf_traffic_what,
9371                 (void *)&cmd_setvf_traffic_mode,
9372                 NULL,
9373         },
9374 };
9375
9376 /* *** CONFIGURE VF RECEIVE MODE *** */
9377 struct cmd_set_vf_rxmode {
9378         cmdline_fixed_string_t set;
9379         cmdline_fixed_string_t port;
9380         portid_t port_id;
9381         cmdline_fixed_string_t vf;
9382         uint8_t vf_id;
9383         cmdline_fixed_string_t what;
9384         cmdline_fixed_string_t mode;
9385         cmdline_fixed_string_t on;
9386 };
9387
9388 static void
9389 cmd_set_vf_rxmode_parsed(void *parsed_result,
9390                        __rte_unused struct cmdline *cl,
9391                        __rte_unused void *data)
9392 {
9393         int ret = -ENOTSUP;
9394         uint16_t vf_rxmode = 0;
9395         struct cmd_set_vf_rxmode *res = parsed_result;
9396
9397         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9398         if (!strcmp(res->what,"rxmode")) {
9399                 if (!strcmp(res->mode, "AUPE"))
9400                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9401                 else if (!strcmp(res->mode, "ROPE"))
9402                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9403                 else if (!strcmp(res->mode, "BAM"))
9404                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9405                 else if (!strncmp(res->mode, "MPE",3))
9406                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9407         }
9408
9409         RTE_SET_USED(is_on);
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 }