app/testpmd: add command to show LACP bonding info
[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_atomic.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_ring.h>
30 #include <rte_mempool.h>
31 #include <rte_interrupts.h>
32 #include <rte_pci.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_string_fns.h>
36 #include <rte_devargs.h>
37 #include <rte_flow.h>
38 #include <rte_gro.h>
39 #include <rte_mbuf_dyn.h>
40
41 #include <cmdline_rdline.h>
42 #include <cmdline_parse.h>
43 #include <cmdline_parse_num.h>
44 #include <cmdline_parse_string.h>
45 #include <cmdline_parse_ipaddr.h>
46 #include <cmdline_parse_etheraddr.h>
47 #include <cmdline_socket.h>
48 #include <cmdline.h>
49 #ifdef RTE_NET_BOND
50 #include <rte_eth_bond.h>
51 #include <rte_eth_bond_8023ad.h>
52 #endif
53 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
54 #include <rte_pmd_dpaa.h>
55 #endif
56 #ifdef RTE_NET_IXGBE
57 #include <rte_pmd_ixgbe.h>
58 #endif
59 #ifdef RTE_NET_I40E
60 #include <rte_pmd_i40e.h>
61 #endif
62 #ifdef RTE_NET_BNXT
63 #include <rte_pmd_bnxt.h>
64 #endif
65 #include "testpmd.h"
66 #include "cmdline_mtr.h"
67 #include "cmdline_tm.h"
68 #include "bpf_cmd.h"
69
70 static struct cmdline *testpmd_cl;
71
72 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
73
74 /* *** Help command with introduction. *** */
75 struct cmd_help_brief_result {
76         cmdline_fixed_string_t help;
77 };
78
79 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
80                                   struct cmdline *cl,
81                                   __rte_unused void *data)
82 {
83         cmdline_printf(
84                 cl,
85                 "\n"
86                 "Help is available for the following sections:\n\n"
87                 "    help control                    : Start and stop forwarding.\n"
88                 "    help display                    : Displaying port, stats and config "
89                 "information.\n"
90                 "    help config                     : Configuration information.\n"
91                 "    help ports                      : Configuring ports.\n"
92                 "    help registers                  : Reading and setting port registers.\n"
93                 "    help filters                    : Filters configuration help.\n"
94                 "    help traffic_management         : Traffic Management commands.\n"
95                 "    help devices                    : Device related cmds.\n"
96                 "    help all                        : All of the above sections.\n\n"
97         );
98
99 }
100
101 cmdline_parse_token_string_t cmd_help_brief_help =
102         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
103
104 cmdline_parse_inst_t cmd_help_brief = {
105         .f = cmd_help_brief_parsed,
106         .data = NULL,
107         .help_str = "help: Show help",
108         .tokens = {
109                 (void *)&cmd_help_brief_help,
110                 NULL,
111         },
112 };
113
114 /* *** Help command with help sections. *** */
115 struct cmd_help_long_result {
116         cmdline_fixed_string_t help;
117         cmdline_fixed_string_t section;
118 };
119
120 static void cmd_help_long_parsed(void *parsed_result,
121                                  struct cmdline *cl,
122                                  __rte_unused void *data)
123 {
124         int show_all = 0;
125         struct cmd_help_long_result *res = parsed_result;
126
127         if (!strcmp(res->section, "all"))
128                 show_all = 1;
129
130         if (show_all || !strcmp(res->section, "control")) {
131
132                 cmdline_printf(
133                         cl,
134                         "\n"
135                         "Control forwarding:\n"
136                         "-------------------\n\n"
137
138                         "start\n"
139                         "    Start packet forwarding with current configuration.\n\n"
140
141                         "start tx_first\n"
142                         "    Start packet forwarding with current config"
143                         " after sending one burst of packets.\n\n"
144
145                         "stop\n"
146                         "    Stop packet forwarding, and display accumulated"
147                         " statistics.\n\n"
148
149                         "quit\n"
150                         "    Quit to prompt.\n\n"
151                 );
152         }
153
154         if (show_all || !strcmp(res->section, "display")) {
155
156                 cmdline_printf(
157                         cl,
158                         "\n"
159                         "Display:\n"
160                         "--------\n\n"
161
162                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
163                         "    Display information for port_id, or all.\n\n"
164
165                         "show port port_id (module_eeprom|eeprom)\n"
166                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
167
168                         "show port X rss reta (size) (mask0,mask1,...)\n"
169                         "    Display the rss redirection table entry indicated"
170                         " by masks on port X. size is used to indicate the"
171                         " hardware supported reta size\n\n"
172
173                         "show port (port_id) rss-hash [key]\n"
174                         "    Display the RSS hash functions and RSS hash key of port\n\n"
175
176                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
177                         "    Clear information for port_id, or all.\n\n"
178
179                         "show (rxq|txq) info (port_id) (queue_id)\n"
180                         "    Display information for configured RX/TX queue.\n\n"
181
182                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
183                         "    Display the given configuration.\n\n"
184
185                         "read rxd (port_id) (queue_id) (rxd_id)\n"
186                         "    Display an RX descriptor of a port RX queue.\n\n"
187
188                         "read txd (port_id) (queue_id) (txd_id)\n"
189                         "    Display a TX descriptor of a port TX queue.\n\n"
190
191                         "ddp get list (port_id)\n"
192                         "    Get ddp profile info list\n\n"
193
194                         "ddp get info (profile_path)\n"
195                         "    Get ddp profile information.\n\n"
196
197                         "show vf stats (port_id) (vf_id)\n"
198                         "    Display a VF's statistics.\n\n"
199
200                         "clear vf stats (port_id) (vf_id)\n"
201                         "    Reset a VF's statistics.\n\n"
202
203                         "show port (port_id) pctype mapping\n"
204                         "    Get flow ptype to pctype mapping on a port\n\n"
205
206                         "show port meter stats (port_id) (meter_id) (clear)\n"
207                         "    Get meter stats on a port\n\n"
208
209                         "show fwd stats all\n"
210                         "    Display statistics for all fwd engines.\n\n"
211
212                         "clear fwd stats all\n"
213                         "    Clear statistics for all fwd engines.\n\n"
214
215                         "show port (port_id) rx_offload capabilities\n"
216                         "    List all per queue and per port Rx offloading"
217                         " capabilities of a port\n\n"
218
219                         "show port (port_id) rx_offload configuration\n"
220                         "    List port level and all queue level"
221                         " Rx offloading configuration\n\n"
222
223                         "show port (port_id) tx_offload capabilities\n"
224                         "    List all per queue and per port"
225                         " Tx offloading capabilities of a port\n\n"
226
227                         "show port (port_id) tx_offload configuration\n"
228                         "    List port level and all queue level"
229                         " Tx offloading configuration\n\n"
230
231                         "show port (port_id) tx_metadata\n"
232                         "    Show Tx metadata value set"
233                         " for a specific port\n\n"
234
235                         "show port (port_id) ptypes\n"
236                         "    Show port supported ptypes"
237                         " for a specific port\n\n"
238
239                         "show device info (<identifier>|all)"
240                         "       Show general information about devices probed.\n\n"
241
242                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
243                         "       Show status of rx|tx descriptor.\n\n"
244
245                         "show port (port_id) rxq (queue_id) desc used count\n"
246                         "    Show current number of filled receive"
247                         " packet descriptors.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257
258                         "show port (port_id) flow_ctrl"
259                         "       Show flow control info of a port.\n\n"
260                 );
261         }
262
263         if (show_all || !strcmp(res->section, "config")) {
264                 cmdline_printf(
265                         cl,
266                         "\n"
267                         "Configuration:\n"
268                         "--------------\n"
269                         "Configuration changes only become active when"
270                         " forwarding is started/restarted.\n\n"
271
272                         "set default\n"
273                         "    Reset forwarding to the default configuration.\n\n"
274
275                         "set verbose (level)\n"
276                         "    Set the debug verbosity level X.\n\n"
277
278                         "set log global|(type) (level)\n"
279                         "    Set the log level.\n\n"
280
281                         "set nbport (num)\n"
282                         "    Set number of ports.\n\n"
283
284                         "set nbcore (num)\n"
285                         "    Set number of cores.\n\n"
286
287                         "set coremask (mask)\n"
288                         "    Set the forwarding cores hexadecimal mask.\n\n"
289
290                         "set portmask (mask)\n"
291                         "    Set the forwarding ports hexadecimal mask.\n\n"
292
293                         "set burst (num)\n"
294                         "    Set number of packets per burst.\n\n"
295
296                         "set burst tx delay (microseconds) retry (num)\n"
297                         "    Set the transmit delay time and number of retries,"
298                         " effective when retry is enabled.\n\n"
299
300                         "set rxoffs (x[,y]*)\n"
301                         "    Set the offset of each packet segment on"
302                         " receiving if split feature is engaged."
303                         " Affects only the queues configured with split"
304                         " offloads.\n\n"
305
306                         "set rxpkts (x[,y]*)\n"
307                         "    Set the length of each segment to scatter"
308                         " packets on receiving if split feature is engaged."
309                         " Affects only the queues configured with split"
310                         " offloads.\n\n"
311
312                         "set txpkts (x[,y]*)\n"
313                         "    Set the length of each segment of TXONLY"
314                         " and optionally CSUM packets.\n\n"
315
316                         "set txsplit (off|on|rand)\n"
317                         "    Set the split policy for the TX packets."
318                         " Right now only applicable for CSUM and TXONLY"
319                         " modes\n\n"
320
321                         "set txtimes (x, y)\n"
322                         "    Set the scheduling on timestamps"
323                         " timings for the TXONLY mode\n\n"
324
325                         "set corelist (x[,y]*)\n"
326                         "    Set the list of forwarding cores.\n\n"
327
328                         "set portlist (x[,y]*)\n"
329                         "    Set the list of forwarding ports.\n\n"
330
331                         "set port setup on (iterator|event)\n"
332                         "    Select how attached port is retrieved for setup.\n\n"
333
334                         "set tx loopback (port_id) (on|off)\n"
335                         "    Enable or disable tx loopback.\n\n"
336
337                         "set all queues drop (port_id) (on|off)\n"
338                         "    Set drop enable bit for all queues.\n\n"
339
340                         "set vf split drop (port_id) (vf_id) (on|off)\n"
341                         "    Set split drop enable bit for a VF from the PF.\n\n"
342
343                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
344                         "    Set MAC antispoof for a VF from the PF.\n\n"
345
346                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
347                         "    Enable MACsec offload.\n\n"
348
349                         "set macsec offload (port_id) off\n"
350                         "    Disable MACsec offload.\n\n"
351
352                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
353                         "    Configure MACsec secure connection (SC).\n\n"
354
355                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
356                         "    Configure MACsec secure association (SA).\n\n"
357
358                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
359                         "    Set VF broadcast for a VF from the PF.\n\n"
360
361                         "vlan set stripq (on|off) (port_id,queue_id)\n"
362                         "    Set the VLAN strip for a queue on a port.\n\n"
363
364                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
365                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
366
367                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
368                         "    Set VLAN insert for a VF from the PF.\n\n"
369
370                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN antispoof for a VF from the PF.\n\n"
372
373                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
374                         "    Set VLAN tag for a VF from the PF.\n\n"
375
376                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
377                         "    Set a VF's max bandwidth(Mbps).\n\n"
378
379                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
380                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
381
382                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
383                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
384
385                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
386                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
387
388                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
389                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
390
391                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
392                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
393
394                         "vlan set (inner|outer) tpid (value) (port_id)\n"
395                         "    Set the VLAN TPID for Packet Filtering on"
396                         " a port\n\n"
397
398                         "rx_vlan add (vlan_id|all) (port_id)\n"
399                         "    Add a vlan_id, or all identifiers, to the set"
400                         " of VLAN identifiers filtered by port_id.\n\n"
401
402                         "rx_vlan rm (vlan_id|all) (port_id)\n"
403                         "    Remove a vlan_id, or all identifiers, from the set"
404                         " of VLAN identifiers filtered by port_id.\n\n"
405
406                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
407                         "    Add a vlan_id, to the set of VLAN identifiers"
408                         "filtered for VF(s) from port_id.\n\n"
409
410                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
411                         "    Remove a vlan_id, to the set of VLAN identifiers"
412                         "filtered for VF(s) from port_id.\n\n"
413
414                         "rx_vxlan_port add (udp_port) (port_id)\n"
415                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "rx_vxlan_port rm (udp_port) (port_id)\n"
418                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
419
420                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
421                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
422                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
423
424                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
425                         "    Set port based TX VLAN insertion.\n\n"
426
427                         "tx_vlan reset (port_id)\n"
428                         "    Disable hardware insertion of a VLAN header in"
429                         " packets sent on a port.\n\n"
430
431                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
432                         "    Select hardware or software calculation of the"
433                         " checksum when transmitting a packet using the"
434                         " csum forward engine.\n"
435                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
436                         "    outer-ip concerns the outer IP layer in"
437                         "    outer-udp concerns the outer UDP layer in"
438                         " case the packet is recognized as a tunnel packet by"
439                         " the forward engine (vxlan, gre and ipip are supported)\n"
440                         "    Please check the NIC datasheet for HW limits.\n\n"
441
442                         "csum parse-tunnel (on|off) (tx_port_id)\n"
443                         "    If disabled, treat tunnel packets as non-tunneled"
444                         " packets (treat inner headers as payload). The port\n"
445                         "    argument is the port used for TX in csum forward"
446                         " engine.\n\n"
447
448                         "csum show (port_id)\n"
449                         "    Display tx checksum offload configuration\n\n"
450
451                         "tso set (segsize) (portid)\n"
452                         "    Enable TCP Segmentation Offload in csum forward"
453                         " engine.\n"
454                         "    Please check the NIC datasheet for HW limits.\n\n"
455
456                         "tso show (portid)"
457                         "    Display the status of TCP Segmentation Offload.\n\n"
458
459                         "set port (port_id) gro on|off\n"
460                         "    Enable or disable Generic Receive Offload in"
461                         " csum forwarding engine.\n\n"
462
463                         "show port (port_id) gro\n"
464                         "    Display GRO configuration.\n\n"
465
466                         "set gro flush (cycles)\n"
467                         "    Set the cycle to flush GROed packets from"
468                         " reassembly tables.\n\n"
469
470                         "set port (port_id) gso (on|off)"
471                         "    Enable or disable Generic Segmentation Offload in"
472                         " csum forwarding engine.\n\n"
473
474                         "set gso segsz (length)\n"
475                         "    Set max packet length for output GSO segments,"
476                         " including packet header and payload.\n\n"
477
478                         "show port (port_id) gso\n"
479                         "    Show GSO configuration.\n\n"
480
481                         "set fwd (%s)\n"
482                         "    Set packet forwarding mode.\n\n"
483
484                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
485                         "    Add a MAC address on port_id.\n\n"
486
487                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Remove a MAC address from port_id.\n\n"
489
490                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
491                         "    Set the default MAC address for port_id.\n\n"
492
493                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
494                         "    Add a MAC address for a VF on the port.\n\n"
495
496                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
497                         "    Set the MAC address for a VF from the PF.\n\n"
498
499                         "set eth-peer (port_id) (peer_addr)\n"
500                         "    set the peer address for certain port.\n\n"
501
502                         "set port (port_id) uta (mac_address|all) (on|off)\n"
503                         "    Add/Remove a or all unicast hash filter(s)"
504                         "from port X.\n\n"
505
506                         "set promisc (port_id|all) (on|off)\n"
507                         "    Set the promiscuous mode on port_id, or all.\n\n"
508
509                         "set allmulti (port_id|all) (on|off)\n"
510                         "    Set the allmulti mode on port_id, or all.\n\n"
511
512                         "set vf promisc (port_id) (vf_id) (on|off)\n"
513                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
514
515                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
516                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
517
518                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
520                         " (on|off) autoneg (on|off) (port_id)\n"
521                         "set flow_ctrl rx (on|off) (portid)\n"
522                         "set flow_ctrl tx (on|off) (portid)\n"
523                         "set flow_ctrl high_water (high_water) (portid)\n"
524                         "set flow_ctrl low_water (low_water) (portid)\n"
525                         "set flow_ctrl pause_time (pause_time) (portid)\n"
526                         "set flow_ctrl send_xon (send_xon) (portid)\n"
527                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
528                         "set flow_ctrl autoneg (on|off) (port_id)\n"
529                         "    Set the link flow control parameter on a port.\n\n"
530
531                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
532                         " (low_water) (pause_time) (priority) (port_id)\n"
533                         "    Set the priority flow control parameter on a"
534                         " port.\n\n"
535
536                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
537                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
538                         " queue on port.\n"
539                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
540                         " on port 0 to mapping 5.\n\n"
541
542                         "set xstats-hide-zero on|off\n"
543                         "    Set the option to hide the zero values"
544                         " for xstats display.\n"
545
546                         "set record-core-cycles on|off\n"
547                         "    Set the option to enable measurement of CPU cycles.\n"
548
549                         "set record-burst-stats on|off\n"
550                         "    Set the option to enable display of RX and TX bursts.\n"
551
552                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
553                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
554
555                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
556                         "|MPE) (on|off)\n"
557                         "    AUPE:accepts untagged VLAN;"
558                         "ROPE:accept unicast hash\n\n"
559                         "    BAM:accepts broadcast packets;"
560                         "MPE:accepts all multicast packets\n\n"
561                         "    Enable/Disable a VF receive mode of a port\n\n"
562
563                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
564                         "    Set rate limit for a queue of a port\n\n"
565
566                         "set port (port_id) vf (vf_id) rate (rate_num) "
567                         "queue_mask (queue_mask_value)\n"
568                         "    Set rate limit for queues in VF of a port\n\n"
569
570                         "set flush_rx (on|off)\n"
571                         "   Flush (default) or don't flush RX streams before"
572                         " forwarding. Mainly used with PCAP drivers.\n\n"
573
574                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
575                         "   Set the bypass mode for the lowest port on bypass enabled"
576                         " NIC.\n\n"
577
578                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
579                         "mode (normal|bypass|isolate) (port_id)\n"
580                         "   Set the event required to initiate specified bypass mode for"
581                         " the lowest port on a bypass enabled NIC where:\n"
582                         "       timeout   = enable bypass after watchdog timeout.\n"
583                         "       os_on     = enable bypass when OS/board is powered on.\n"
584                         "       os_off    = enable bypass when OS/board is powered off.\n"
585                         "       power_on  = enable bypass when power supply is turned on.\n"
586                         "       power_off = enable bypass when power supply is turned off."
587                         "\n\n"
588
589                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
590                         "   Set the bypass watchdog timeout to 'n' seconds"
591                         " where 0 = instant.\n\n"
592
593                         "show bypass config (port_id)\n"
594                         "   Show the bypass configuration for a bypass enabled NIC"
595                         " using the lowest port on the NIC.\n\n"
596
597 #ifdef RTE_NET_BOND
598                         "create bonded device (mode) (socket)\n"
599                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
600
601                         "add bonding slave (slave_id) (port_id)\n"
602                         "       Add a slave device to a bonded device.\n\n"
603
604                         "remove bonding slave (slave_id) (port_id)\n"
605                         "       Remove a slave device from a bonded device.\n\n"
606
607                         "set bonding mode (value) (port_id)\n"
608                         "       Set the bonding mode on a bonded device.\n\n"
609
610                         "set bonding primary (slave_id) (port_id)\n"
611                         "       Set the primary slave for a bonded device.\n\n"
612
613                         "show bonding config (port_id)\n"
614                         "       Show the bonding config for port_id.\n\n"
615
616                         "show bonding lacp info (port_id)\n"
617                         "       Show the bonding lacp information for port_id.\n\n"
618
619                         "set bonding mac_addr (port_id) (address)\n"
620                         "       Set the MAC address of a bonded device.\n\n"
621
622                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
623                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
624
625                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
626                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
627
628                         "set bonding mon_period (port_id) (value)\n"
629                         "       Set the bonding link status monitoring polling period in ms.\n\n"
630
631                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
632                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
633
634 #endif
635                         "set link-up port (port_id)\n"
636                         "       Set link up for a port.\n\n"
637
638                         "set link-down port (port_id)\n"
639                         "       Set link down for a port.\n\n"
640
641                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
642                         "    Load a profile package on a port\n\n"
643
644                         "ddp del (port_id) (backup_profile_path)\n"
645                         "    Delete a profile package from a port\n\n"
646
647                         "ptype mapping get (port_id) (valid_only)\n"
648                         "    Get ptype mapping on a port\n\n"
649
650                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
651                         "    Replace target with the pkt_type in ptype mapping\n\n"
652
653                         "ptype mapping reset (port_id)\n"
654                         "    Reset ptype mapping on a port\n\n"
655
656                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
657                         "    Update a ptype mapping item on a port\n\n"
658
659                         "set port (port_id) ptype_mask (ptype_mask)\n"
660                         "    set packet types classification for a specific port\n\n"
661
662                         "set port (port_id) queue-region region_id (value) "
663                         "queue_start_index (value) queue_num (value)\n"
664                         "    Set a queue region on a port\n\n"
665
666                         "set port (port_id) queue-region region_id (value) "
667                         "flowtype (value)\n"
668                         "    Set a flowtype region index on a port\n\n"
669
670                         "set port (port_id) queue-region UP (value) region_id (value)\n"
671                         "    Set the mapping of User Priority to "
672                         "queue region on a port\n\n"
673
674                         "set port (port_id) queue-region flush (on|off)\n"
675                         "    flush all queue region related configuration\n\n"
676
677                         "show port meter cap (port_id)\n"
678                         "    Show port meter capability information\n\n"
679
680                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
681                         "    meter profile add - srtcm rfc 2697\n\n"
682
683                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
684                         "    meter profile add - trtcm rfc 2698\n\n"
685
686                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
687                         "    meter profile add - trtcm rfc 4115\n\n"
688
689                         "del port meter profile (port_id) (profile_id)\n"
690                         "    meter profile delete\n\n"
691
692                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
693                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
694                         "(dscp_tbl_entry63)]\n"
695                         "    meter create\n\n"
696
697                         "enable port meter (port_id) (mtr_id)\n"
698                         "    meter enable\n\n"
699
700                         "disable port meter (port_id) (mtr_id)\n"
701                         "    meter disable\n\n"
702
703                         "del port meter (port_id) (mtr_id)\n"
704                         "    meter delete\n\n"
705
706                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
707                         "y_actions (actions) r_actions (actions)\n"
708                         "    meter policy add\n\n"
709
710                         "del port meter policy (port_id) (policy_id)\n"
711                         "    meter policy delete\n\n"
712
713                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
714                         "    meter update meter profile\n\n"
715
716                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
717                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
718                         "    update meter dscp table entries\n\n"
719
720                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
721                         "(action0) [(action1) (action2)]\n"
722                         "    meter update policer action\n\n"
723
724                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
725                         "    meter update stats\n\n"
726
727                         "show port (port_id) queue-region\n"
728                         "    show all queue region related configuration info\n\n"
729
730                         "set port (port_id) fec_mode auto|off|rs|baser\n"
731                         "    set fec mode for a specific port\n\n"
732
733                         , list_pkt_forwarding_modes()
734                 );
735         }
736
737         if (show_all || !strcmp(res->section, "ports")) {
738
739                 cmdline_printf(
740                         cl,
741                         "\n"
742                         "Port Operations:\n"
743                         "----------------\n\n"
744
745                         "port start (port_id|all)\n"
746                         "    Start all ports or port_id.\n\n"
747
748                         "port stop (port_id|all)\n"
749                         "    Stop all ports or port_id.\n\n"
750
751                         "port close (port_id|all)\n"
752                         "    Close all ports or port_id.\n\n"
753
754                         "port reset (port_id|all)\n"
755                         "    Reset all ports or port_id.\n\n"
756
757                         "port attach (ident)\n"
758                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
759
760                         "port detach (port_id)\n"
761                         "    Detach physical or virtual dev by port_id\n\n"
762
763                         "port config (port_id|all)"
764                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
765                         " duplex (half|full|auto)\n"
766                         "    Set speed and duplex for all ports or port_id\n\n"
767
768                         "port config (port_id|all) loopback (mode)\n"
769                         "    Set loopback mode for all ports or port_id\n\n"
770
771                         "port config all (rxq|txq|rxd|txd) (value)\n"
772                         "    Set number for rxq/txq/rxd/txd.\n\n"
773
774                         "port config all max-pkt-len (value)\n"
775                         "    Set the max packet length.\n\n"
776
777                         "port config all max-lro-pkt-size (value)\n"
778                         "    Set the max LRO aggregated packet size.\n\n"
779
780                         "port config all drop-en (on|off)\n"
781                         "    Enable or disable packet drop on all RX queues of all ports when no "
782                         "receive buffers available.\n\n"
783
784                         "port config all rss (all|default|ip|tcp|udp|sctp|"
785                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
786                         "level-outer|level-inner|<flowtype_id>)\n"
787                         "    Set the RSS mode.\n\n"
788
789                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
790                         "    Set the RSS redirection table.\n\n"
791
792                         "port config (port_id) dcb vt (on|off) (traffic_class)"
793                         " pfc (on|off)\n"
794                         "    Set the DCB mode.\n\n"
795
796                         "port config all burst (value)\n"
797                         "    Set the number of packets per burst.\n\n"
798
799                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
800                         " (value)\n"
801                         "    Set the ring prefetch/host/writeback threshold"
802                         " for tx/rx queue.\n\n"
803
804                         "port config all (txfreet|txrst|rxfreet) (value)\n"
805                         "    Set free threshold for rx/tx, or set"
806                         " tx rs bit threshold.\n\n"
807                         "port config mtu X value\n"
808                         "    Set the MTU of port X to a given value\n\n"
809
810                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
811                         "    Set a rx/tx queue's ring size configuration, the new"
812                         " value will take effect after command that (re-)start the port"
813                         " or command that setup the specific queue\n\n"
814
815                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
816                         "    Start/stop a rx/tx queue of port X. Only take effect"
817                         " when port X is started\n\n"
818
819                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
820                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
821                         " take effect when port X is stopped.\n\n"
822
823                         "port (port_id) (rxq|txq) (queue_id) setup\n"
824                         "    Setup a rx/tx queue of port X.\n\n"
825
826                         "port config (port_id) pctype mapping reset\n"
827                         "    Reset flow type to pctype mapping on a port\n\n"
828
829                         "port config (port_id) pctype mapping update"
830                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
831                         "    Update a flow type to pctype mapping item on a port\n\n"
832
833                         "port config (port_id) pctype (pctype_id) hash_inset|"
834                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
835                         " (field_idx)\n"
836                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
837
838                         "port config (port_id) pctype (pctype_id) hash_inset|"
839                         "fdir_inset|fdir_flx_inset clear all"
840                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
841
842                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
843                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
844
845                         "port config <port_id> rx_offload vlan_strip|"
846                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
847                         "outer_ipv4_cksum|macsec_strip|header_split|"
848                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
849                         "buffer_split|timestamp|security|keep_crc on|off\n"
850                         "     Enable or disable a per port Rx offloading"
851                         " on all Rx queues of a port\n\n"
852
853                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
854                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
855                         "outer_ipv4_cksum|macsec_strip|header_split|"
856                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
857                         "buffer_split|timestamp|security|keep_crc on|off\n"
858                         "    Enable or disable a per queue Rx offloading"
859                         " only on a specific Rx queue\n\n"
860
861                         "port config (port_id) tx_offload vlan_insert|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
863                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
864                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
865                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
866                         "security on|off\n"
867                         "    Enable or disable a per port Tx offloading"
868                         " on all Tx queues of a port\n\n"
869
870                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
871                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
872                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
873                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
874                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
875                         " on|off\n"
876                         "    Enable or disable a per queue Tx offloading"
877                         " only on a specific Tx queue\n\n"
878
879                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
880                         "    Load an eBPF program as a callback"
881                         " for particular RX/TX queue\n\n"
882
883                         "bpf-unload rx|tx (port) (queue)\n"
884                         "    Unload previously loaded eBPF program"
885                         " for particular RX/TX queue\n\n"
886
887                         "port config (port_id) tx_metadata (value)\n"
888                         "    Set Tx metadata value per port. Testpmd will add this value"
889                         " to any Tx packet sent from this port\n\n"
890
891                         "port config (port_id) dynf (name) set|clear\n"
892                         "    Register a dynf and Set/clear this flag on Tx. "
893                         "Testpmd will set this value to any Tx packet "
894                         "sent from this port\n\n"
895
896                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
897                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
898                 );
899         }
900
901         if (show_all || !strcmp(res->section, "registers")) {
902
903                 cmdline_printf(
904                         cl,
905                         "\n"
906                         "Registers:\n"
907                         "----------\n\n"
908
909                         "read reg (port_id) (address)\n"
910                         "    Display value of a port register.\n\n"
911
912                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
913                         "    Display a port register bit field.\n\n"
914
915                         "read regbit (port_id) (address) (bit_x)\n"
916                         "    Display a single port register bit.\n\n"
917
918                         "write reg (port_id) (address) (value)\n"
919                         "    Set value of a port register.\n\n"
920
921                         "write regfield (port_id) (address) (bit_x) (bit_y)"
922                         " (value)\n"
923                         "    Set bit field of a port register.\n\n"
924
925                         "write regbit (port_id) (address) (bit_x) (value)\n"
926                         "    Set single bit value of a port register.\n\n"
927                 );
928         }
929         if (show_all || !strcmp(res->section, "filters")) {
930
931                 cmdline_printf(
932                         cl,
933                         "\n"
934                         "filters:\n"
935                         "--------\n\n"
936
937 #ifdef RTE_NET_I40E
938                         "flow_director_filter (port_id) mode raw (add|del|update)"
939                         " flow (flow_id) (drop|fwd) queue (queue_id)"
940                         " fd_id (fd_id_value) packet (packet file name)\n"
941                         "    Add/Del a raw type flow director filter.\n\n"
942 #endif
943
944                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
945                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
946                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
947                         "    Set flow director IP mask.\n\n"
948
949                         "flow_director_mask (port_id) mode MAC-VLAN"
950                         " vlan (vlan_value)\n"
951                         "    Set flow director MAC-VLAN mask.\n\n"
952
953                         "flow_director_mask (port_id) mode Tunnel"
954                         " vlan (vlan_value) mac (mac_value)"
955                         " tunnel-type (tunnel_type_value)"
956                         " tunnel-id (tunnel_id_value)\n"
957                         "    Set flow director Tunnel mask.\n\n"
958
959                         "flow_director_flex_payload (port_id)"
960                         " (raw|l2|l3|l4) (config)\n"
961                         "    Configure flex payload selection.\n\n"
962
963                         "flow validate {port_id}"
964                         " [group {group_id}] [priority {level}]"
965                         " [ingress] [egress]"
966                         " pattern {item} [/ {item} [...]] / end"
967                         " actions {action} [/ {action} [...]] / end\n"
968                         "    Check whether a flow rule can be created.\n\n"
969
970                         "flow create {port_id}"
971                         " [group {group_id}] [priority {level}]"
972                         " [ingress] [egress]"
973                         " pattern {item} [/ {item} [...]] / end"
974                         " actions {action} [/ {action} [...]] / end\n"
975                         "    Create a flow rule.\n\n"
976
977                         "flow destroy {port_id} rule {rule_id} [...]\n"
978                         "    Destroy specific flow rules.\n\n"
979
980                         "flow flush {port_id}\n"
981                         "    Destroy all flow rules.\n\n"
982
983                         "flow query {port_id} {rule_id} {action}\n"
984                         "    Query an existing flow rule.\n\n"
985
986                         "flow list {port_id} [group {group_id}] [...]\n"
987                         "    List existing flow rules sorted by priority,"
988                         " filtered by group identifiers.\n\n"
989
990                         "flow isolate {port_id} {boolean}\n"
991                         "    Restrict ingress traffic to the defined"
992                         " flow rules\n\n"
993
994                         "flow aged {port_id} [destroy]\n"
995                         "    List and destroy aged flows"
996                         " flow rules\n\n"
997
998                         "flow indirect_action {port_id} create"
999                         " [action_id {indirect_action_id}]"
1000                         " [ingress] [egress]"
1001                         " action {action} / end\n"
1002                         "    Create indirect action.\n\n"
1003
1004                         "flow indirect_action {port_id} update"
1005                         " {indirect_action_id} action {action} / end\n"
1006                         "    Update indirect action.\n\n"
1007
1008                         "flow indirect_action {port_id} destroy"
1009                         " action_id {indirect_action_id} [...]\n"
1010                         "    Destroy specific indirect actions.\n\n"
1011
1012                         "flow indirect_action {port_id} query"
1013                         " {indirect_action_id}\n"
1014                         "    Query an existing indirect action.\n\n"
1015
1016                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1017                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1018                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1019                         "       Configure the VXLAN encapsulation for flows.\n\n"
1020
1021                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1022                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1023                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1024                         " eth-dst (eth-dst)\n"
1025                         "       Configure the VXLAN encapsulation for flows.\n\n"
1026
1027                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1028                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1029                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1030                         " eth-dst (eth-dst)\n"
1031                         "       Configure the VXLAN encapsulation for flows.\n\n"
1032
1033                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1034                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1035                         " (eth-dst)\n"
1036                         "       Configure the NVGRE encapsulation for flows.\n\n"
1037
1038                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1039                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1040                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1041                         "       Configure the NVGRE encapsulation for flows.\n\n"
1042
1043                         "set raw_encap {flow items}\n"
1044                         "       Configure the encapsulation with raw data.\n\n"
1045
1046                         "set raw_decap {flow items}\n"
1047                         "       Configure the decapsulation with raw data.\n\n"
1048
1049                 );
1050         }
1051
1052         if (show_all || !strcmp(res->section, "traffic_management")) {
1053                 cmdline_printf(
1054                         cl,
1055                         "\n"
1056                         "Traffic Management:\n"
1057                         "--------------\n"
1058                         "show port tm cap (port_id)\n"
1059                         "       Display the port TM capability.\n\n"
1060
1061                         "show port tm level cap (port_id) (level_id)\n"
1062                         "       Display the port TM hierarchical level capability.\n\n"
1063
1064                         "show port tm node cap (port_id) (node_id)\n"
1065                         "       Display the port TM node capability.\n\n"
1066
1067                         "show port tm node type (port_id) (node_id)\n"
1068                         "       Display the port TM node type.\n\n"
1069
1070                         "show port tm node stats (port_id) (node_id) (clear)\n"
1071                         "       Display the port TM node stats.\n\n"
1072
1073                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1074                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1075                         " (packet_length_adjust) (packet_mode)\n"
1076                         "       Add port tm node private shaper profile.\n\n"
1077
1078                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1079                         "       Delete port tm node private shaper profile.\n\n"
1080
1081                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1082                         " (shaper_profile_id)\n"
1083                         "       Add/update port tm node shared shaper.\n\n"
1084
1085                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1086                         "       Delete port tm node shared shaper.\n\n"
1087
1088                         "set port tm node shaper profile (port_id) (node_id)"
1089                         " (shaper_profile_id)\n"
1090                         "       Set port tm node shaper profile.\n\n"
1091
1092                         "add port tm node wred profile (port_id) (wred_profile_id)"
1093                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1094                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1095                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1096                         "       Add port tm node wred profile.\n\n"
1097
1098                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1099                         "       Delete port tm node wred profile.\n\n"
1100
1101                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1102                         " (priority) (weight) (level_id) (shaper_profile_id)"
1103                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1104                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1105                         "       Add port tm nonleaf node.\n\n"
1106
1107                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1108                         " (priority) (weight) (level_id) (shaper_profile_id)"
1109                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1110                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1111                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1112
1113                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1114                         " (priority) (weight) (level_id) (shaper_profile_id)"
1115                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1116                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1117                         "       Add port tm leaf node.\n\n"
1118
1119                         "del port tm node (port_id) (node_id)\n"
1120                         "       Delete port tm node.\n\n"
1121
1122                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1123                         " (priority) (weight)\n"
1124                         "       Set port tm node parent.\n\n"
1125
1126                         "suspend port tm node (port_id) (node_id)"
1127                         "       Suspend tm node.\n\n"
1128
1129                         "resume port tm node (port_id) (node_id)"
1130                         "       Resume tm node.\n\n"
1131
1132                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1133                         "       Commit tm hierarchy.\n\n"
1134
1135                         "set port tm mark ip_ecn (port) (green) (yellow)"
1136                         " (red)\n"
1137                         "    Enables/Disables the traffic management marking"
1138                         " for IP ECN (Explicit Congestion Notification)"
1139                         " packets on a given port\n\n"
1140
1141                         "set port tm mark ip_dscp (port) (green) (yellow)"
1142                         " (red)\n"
1143                         "    Enables/Disables the traffic management marking"
1144                         " on the port for IP dscp packets\n\n"
1145
1146                         "set port tm mark vlan_dei (port) (green) (yellow)"
1147                         " (red)\n"
1148                         "    Enables/Disables the traffic management marking"
1149                         " on the port for VLAN packets with DEI enabled\n\n"
1150                 );
1151         }
1152
1153         if (show_all || !strcmp(res->section, "devices")) {
1154                 cmdline_printf(
1155                         cl,
1156                         "\n"
1157                         "Device Operations:\n"
1158                         "--------------\n"
1159                         "device detach (identifier)\n"
1160                         "       Detach device by identifier.\n\n"
1161                 );
1162         }
1163
1164 }
1165
1166 cmdline_parse_token_string_t cmd_help_long_help =
1167         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1168
1169 cmdline_parse_token_string_t cmd_help_long_section =
1170         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1171                         "all#control#display#config#"
1172                         "ports#registers#filters#traffic_management#devices");
1173
1174 cmdline_parse_inst_t cmd_help_long = {
1175         .f = cmd_help_long_parsed,
1176         .data = NULL,
1177         .help_str = "help all|control|display|config|ports|register|"
1178                 "filters|traffic_management|devices: "
1179                 "Show help",
1180         .tokens = {
1181                 (void *)&cmd_help_long_help,
1182                 (void *)&cmd_help_long_section,
1183                 NULL,
1184         },
1185 };
1186
1187
1188 /* *** start/stop/close all ports *** */
1189 struct cmd_operate_port_result {
1190         cmdline_fixed_string_t keyword;
1191         cmdline_fixed_string_t name;
1192         cmdline_fixed_string_t value;
1193 };
1194
1195 static void cmd_operate_port_parsed(void *parsed_result,
1196                                 __rte_unused struct cmdline *cl,
1197                                 __rte_unused void *data)
1198 {
1199         struct cmd_operate_port_result *res = parsed_result;
1200
1201         if (!strcmp(res->name, "start"))
1202                 start_port(RTE_PORT_ALL);
1203         else if (!strcmp(res->name, "stop"))
1204                 stop_port(RTE_PORT_ALL);
1205         else if (!strcmp(res->name, "close"))
1206                 close_port(RTE_PORT_ALL);
1207         else if (!strcmp(res->name, "reset"))
1208                 reset_port(RTE_PORT_ALL);
1209         else
1210                 fprintf(stderr, "Unknown parameter\n");
1211 }
1212
1213 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1214         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1215                                                                 "port");
1216 cmdline_parse_token_string_t cmd_operate_port_all_port =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1218                                                 "start#stop#close#reset");
1219 cmdline_parse_token_string_t cmd_operate_port_all_all =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1221
1222 cmdline_parse_inst_t cmd_operate_port = {
1223         .f = cmd_operate_port_parsed,
1224         .data = NULL,
1225         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1226         .tokens = {
1227                 (void *)&cmd_operate_port_all_cmd,
1228                 (void *)&cmd_operate_port_all_port,
1229                 (void *)&cmd_operate_port_all_all,
1230                 NULL,
1231         },
1232 };
1233
1234 /* *** start/stop/close specific port *** */
1235 struct cmd_operate_specific_port_result {
1236         cmdline_fixed_string_t keyword;
1237         cmdline_fixed_string_t name;
1238         uint8_t value;
1239 };
1240
1241 static void cmd_operate_specific_port_parsed(void *parsed_result,
1242                         __rte_unused struct cmdline *cl,
1243                                 __rte_unused void *data)
1244 {
1245         struct cmd_operate_specific_port_result *res = parsed_result;
1246
1247         if (!strcmp(res->name, "start"))
1248                 start_port(res->value);
1249         else if (!strcmp(res->name, "stop"))
1250                 stop_port(res->value);
1251         else if (!strcmp(res->name, "close"))
1252                 close_port(res->value);
1253         else if (!strcmp(res->name, "reset"))
1254                 reset_port(res->value);
1255         else
1256                 fprintf(stderr, "Unknown parameter\n");
1257 }
1258
1259 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1260         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1261                                                         keyword, "port");
1262 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1264                                                 name, "start#stop#close#reset");
1265 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1266         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1267                                                         value, RTE_UINT8);
1268
1269 cmdline_parse_inst_t cmd_operate_specific_port = {
1270         .f = cmd_operate_specific_port_parsed,
1271         .data = NULL,
1272         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1273         .tokens = {
1274                 (void *)&cmd_operate_specific_port_cmd,
1275                 (void *)&cmd_operate_specific_port_port,
1276                 (void *)&cmd_operate_specific_port_id,
1277                 NULL,
1278         },
1279 };
1280
1281 /* *** enable port setup (after attach) via iterator or event *** */
1282 struct cmd_set_port_setup_on_result {
1283         cmdline_fixed_string_t set;
1284         cmdline_fixed_string_t port;
1285         cmdline_fixed_string_t setup;
1286         cmdline_fixed_string_t on;
1287         cmdline_fixed_string_t mode;
1288 };
1289
1290 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1291                                 __rte_unused struct cmdline *cl,
1292                                 __rte_unused void *data)
1293 {
1294         struct cmd_set_port_setup_on_result *res = parsed_result;
1295
1296         if (strcmp(res->mode, "event") == 0)
1297                 setup_on_probe_event = true;
1298         else if (strcmp(res->mode, "iterator") == 0)
1299                 setup_on_probe_event = false;
1300         else
1301                 fprintf(stderr, "Unknown mode\n");
1302 }
1303
1304 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1305         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1306                         set, "set");
1307 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1308         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1309                         port, "port");
1310 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1311         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1312                         setup, "setup");
1313 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1314         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1315                         on, "on");
1316 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1317         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1318                         mode, "iterator#event");
1319
1320 cmdline_parse_inst_t cmd_set_port_setup_on = {
1321         .f = cmd_set_port_setup_on_parsed,
1322         .data = NULL,
1323         .help_str = "set port setup on iterator|event",
1324         .tokens = {
1325                 (void *)&cmd_set_port_setup_on_set,
1326                 (void *)&cmd_set_port_setup_on_port,
1327                 (void *)&cmd_set_port_setup_on_setup,
1328                 (void *)&cmd_set_port_setup_on_on,
1329                 (void *)&cmd_set_port_setup_on_mode,
1330                 NULL,
1331         },
1332 };
1333
1334 /* *** attach a specified port *** */
1335 struct cmd_operate_attach_port_result {
1336         cmdline_fixed_string_t port;
1337         cmdline_fixed_string_t keyword;
1338         cmdline_multi_string_t identifier;
1339 };
1340
1341 static void cmd_operate_attach_port_parsed(void *parsed_result,
1342                                 __rte_unused struct cmdline *cl,
1343                                 __rte_unused void *data)
1344 {
1345         struct cmd_operate_attach_port_result *res = parsed_result;
1346
1347         if (!strcmp(res->keyword, "attach"))
1348                 attach_port(res->identifier);
1349         else
1350                 fprintf(stderr, "Unknown parameter\n");
1351 }
1352
1353 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1354         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1355                         port, "port");
1356 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1357         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1358                         keyword, "attach");
1359 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1360         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1361                         identifier, TOKEN_STRING_MULTI);
1362
1363 cmdline_parse_inst_t cmd_operate_attach_port = {
1364         .f = cmd_operate_attach_port_parsed,
1365         .data = NULL,
1366         .help_str = "port attach <identifier>: "
1367                 "(identifier: pci address or virtual dev name)",
1368         .tokens = {
1369                 (void *)&cmd_operate_attach_port_port,
1370                 (void *)&cmd_operate_attach_port_keyword,
1371                 (void *)&cmd_operate_attach_port_identifier,
1372                 NULL,
1373         },
1374 };
1375
1376 /* *** detach a specified port *** */
1377 struct cmd_operate_detach_port_result {
1378         cmdline_fixed_string_t port;
1379         cmdline_fixed_string_t keyword;
1380         portid_t port_id;
1381 };
1382
1383 static void cmd_operate_detach_port_parsed(void *parsed_result,
1384                                 __rte_unused struct cmdline *cl,
1385                                 __rte_unused void *data)
1386 {
1387         struct cmd_operate_detach_port_result *res = parsed_result;
1388
1389         if (!strcmp(res->keyword, "detach")) {
1390                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1391                 detach_port_device(res->port_id);
1392         } else {
1393                 fprintf(stderr, "Unknown parameter\n");
1394         }
1395 }
1396
1397 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1398         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1399                         port, "port");
1400 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1401         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1402                         keyword, "detach");
1403 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1404         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1405                         port_id, RTE_UINT16);
1406
1407 cmdline_parse_inst_t cmd_operate_detach_port = {
1408         .f = cmd_operate_detach_port_parsed,
1409         .data = NULL,
1410         .help_str = "port detach <port_id>",
1411         .tokens = {
1412                 (void *)&cmd_operate_detach_port_port,
1413                 (void *)&cmd_operate_detach_port_keyword,
1414                 (void *)&cmd_operate_detach_port_port_id,
1415                 NULL,
1416         },
1417 };
1418
1419 /* *** detach device by identifier *** */
1420 struct cmd_operate_detach_device_result {
1421         cmdline_fixed_string_t device;
1422         cmdline_fixed_string_t keyword;
1423         cmdline_fixed_string_t identifier;
1424 };
1425
1426 static void cmd_operate_detach_device_parsed(void *parsed_result,
1427                                 __rte_unused struct cmdline *cl,
1428                                 __rte_unused void *data)
1429 {
1430         struct cmd_operate_detach_device_result *res = parsed_result;
1431
1432         if (!strcmp(res->keyword, "detach"))
1433                 detach_devargs(res->identifier);
1434         else
1435                 fprintf(stderr, "Unknown parameter\n");
1436 }
1437
1438 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1439         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1440                         device, "device");
1441 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1442         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1443                         keyword, "detach");
1444 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1445         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1446                         identifier, NULL);
1447
1448 cmdline_parse_inst_t cmd_operate_detach_device = {
1449         .f = cmd_operate_detach_device_parsed,
1450         .data = NULL,
1451         .help_str = "device detach <identifier>:"
1452                 "(identifier: pci address or virtual dev name)",
1453         .tokens = {
1454                 (void *)&cmd_operate_detach_device_device,
1455                 (void *)&cmd_operate_detach_device_keyword,
1456                 (void *)&cmd_operate_detach_device_identifier,
1457                 NULL,
1458         },
1459 };
1460 /* *** configure speed for all ports *** */
1461 struct cmd_config_speed_all {
1462         cmdline_fixed_string_t port;
1463         cmdline_fixed_string_t keyword;
1464         cmdline_fixed_string_t all;
1465         cmdline_fixed_string_t item1;
1466         cmdline_fixed_string_t item2;
1467         cmdline_fixed_string_t value1;
1468         cmdline_fixed_string_t value2;
1469 };
1470
1471 static int
1472 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1473 {
1474
1475         int duplex;
1476
1477         if (!strcmp(duplexstr, "half")) {
1478                 duplex = ETH_LINK_HALF_DUPLEX;
1479         } else if (!strcmp(duplexstr, "full")) {
1480                 duplex = ETH_LINK_FULL_DUPLEX;
1481         } else if (!strcmp(duplexstr, "auto")) {
1482                 duplex = ETH_LINK_FULL_DUPLEX;
1483         } else {
1484                 fprintf(stderr, "Unknown duplex parameter\n");
1485                 return -1;
1486         }
1487
1488         if (!strcmp(speedstr, "10")) {
1489                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1490                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1491         } else if (!strcmp(speedstr, "100")) {
1492                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1493                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1494         } else {
1495                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1496                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1497                         return -1;
1498                 }
1499                 if (!strcmp(speedstr, "1000")) {
1500                         *speed = ETH_LINK_SPEED_1G;
1501                 } else if (!strcmp(speedstr, "10000")) {
1502                         *speed = ETH_LINK_SPEED_10G;
1503                 } else if (!strcmp(speedstr, "25000")) {
1504                         *speed = ETH_LINK_SPEED_25G;
1505                 } else if (!strcmp(speedstr, "40000")) {
1506                         *speed = ETH_LINK_SPEED_40G;
1507                 } else if (!strcmp(speedstr, "50000")) {
1508                         *speed = ETH_LINK_SPEED_50G;
1509                 } else if (!strcmp(speedstr, "100000")) {
1510                         *speed = ETH_LINK_SPEED_100G;
1511                 } else if (!strcmp(speedstr, "200000")) {
1512                         *speed = ETH_LINK_SPEED_200G;
1513                 } else if (!strcmp(speedstr, "auto")) {
1514                         *speed = ETH_LINK_SPEED_AUTONEG;
1515                 } else {
1516                         fprintf(stderr, "Unknown speed parameter\n");
1517                         return -1;
1518                 }
1519         }
1520
1521         if (*speed != ETH_LINK_SPEED_AUTONEG)
1522                 *speed |= ETH_LINK_SPEED_FIXED;
1523
1524         return 0;
1525 }
1526
1527 static void
1528 cmd_config_speed_all_parsed(void *parsed_result,
1529                         __rte_unused struct cmdline *cl,
1530                         __rte_unused void *data)
1531 {
1532         struct cmd_config_speed_all *res = parsed_result;
1533         uint32_t link_speed;
1534         portid_t pid;
1535
1536         if (!all_ports_stopped()) {
1537                 fprintf(stderr, "Please stop all ports first\n");
1538                 return;
1539         }
1540
1541         if (parse_and_check_speed_duplex(res->value1, res->value2,
1542                         &link_speed) < 0)
1543                 return;
1544
1545         RTE_ETH_FOREACH_DEV(pid) {
1546                 ports[pid].dev_conf.link_speeds = link_speed;
1547         }
1548
1549         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1550 }
1551
1552 cmdline_parse_token_string_t cmd_config_speed_all_port =
1553         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1554 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1556                                                         "config");
1557 cmdline_parse_token_string_t cmd_config_speed_all_all =
1558         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1559 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1561 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1563                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1564 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1566 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1568                                                 "half#full#auto");
1569
1570 cmdline_parse_inst_t cmd_config_speed_all = {
1571         .f = cmd_config_speed_all_parsed,
1572         .data = NULL,
1573         .help_str = "port config all speed "
1574                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1575                                                         "half|full|auto",
1576         .tokens = {
1577                 (void *)&cmd_config_speed_all_port,
1578                 (void *)&cmd_config_speed_all_keyword,
1579                 (void *)&cmd_config_speed_all_all,
1580                 (void *)&cmd_config_speed_all_item1,
1581                 (void *)&cmd_config_speed_all_value1,
1582                 (void *)&cmd_config_speed_all_item2,
1583                 (void *)&cmd_config_speed_all_value2,
1584                 NULL,
1585         },
1586 };
1587
1588 /* *** configure speed for specific port *** */
1589 struct cmd_config_speed_specific {
1590         cmdline_fixed_string_t port;
1591         cmdline_fixed_string_t keyword;
1592         portid_t id;
1593         cmdline_fixed_string_t item1;
1594         cmdline_fixed_string_t item2;
1595         cmdline_fixed_string_t value1;
1596         cmdline_fixed_string_t value2;
1597 };
1598
1599 static void
1600 cmd_config_speed_specific_parsed(void *parsed_result,
1601                                 __rte_unused struct cmdline *cl,
1602                                 __rte_unused void *data)
1603 {
1604         struct cmd_config_speed_specific *res = parsed_result;
1605         uint32_t link_speed;
1606
1607         if (port_id_is_invalid(res->id, ENABLED_WARN))
1608                 return;
1609
1610         if (!port_is_stopped(res->id)) {
1611                 fprintf(stderr, "Please stop port %d first\n", res->id);
1612                 return;
1613         }
1614
1615         if (parse_and_check_speed_duplex(res->value1, res->value2,
1616                         &link_speed) < 0)
1617                 return;
1618
1619         ports[res->id].dev_conf.link_speeds = link_speed;
1620
1621         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1622 }
1623
1624
1625 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1626         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1627                                                                 "port");
1628 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1629         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1630                                                                 "config");
1631 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1632         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1633 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1635                                                                 "speed");
1636 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1638                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1639 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1641                                                                 "duplex");
1642 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1644                                                         "half#full#auto");
1645
1646 cmdline_parse_inst_t cmd_config_speed_specific = {
1647         .f = cmd_config_speed_specific_parsed,
1648         .data = NULL,
1649         .help_str = "port config <port_id> speed "
1650                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1651                                                         "half|full|auto",
1652         .tokens = {
1653                 (void *)&cmd_config_speed_specific_port,
1654                 (void *)&cmd_config_speed_specific_keyword,
1655                 (void *)&cmd_config_speed_specific_id,
1656                 (void *)&cmd_config_speed_specific_item1,
1657                 (void *)&cmd_config_speed_specific_value1,
1658                 (void *)&cmd_config_speed_specific_item2,
1659                 (void *)&cmd_config_speed_specific_value2,
1660                 NULL,
1661         },
1662 };
1663
1664 /* *** configure loopback for all ports *** */
1665 struct cmd_config_loopback_all {
1666         cmdline_fixed_string_t port;
1667         cmdline_fixed_string_t keyword;
1668         cmdline_fixed_string_t all;
1669         cmdline_fixed_string_t item;
1670         uint32_t mode;
1671 };
1672
1673 static void
1674 cmd_config_loopback_all_parsed(void *parsed_result,
1675                         __rte_unused struct cmdline *cl,
1676                         __rte_unused void *data)
1677 {
1678         struct cmd_config_loopback_all *res = parsed_result;
1679         portid_t pid;
1680
1681         if (!all_ports_stopped()) {
1682                 fprintf(stderr, "Please stop all ports first\n");
1683                 return;
1684         }
1685
1686         RTE_ETH_FOREACH_DEV(pid) {
1687                 ports[pid].dev_conf.lpbk_mode = res->mode;
1688         }
1689
1690         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1691 }
1692
1693 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1694         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1695 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1697                                                         "config");
1698 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1700 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1702                                                         "loopback");
1703 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1704         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1705
1706 cmdline_parse_inst_t cmd_config_loopback_all = {
1707         .f = cmd_config_loopback_all_parsed,
1708         .data = NULL,
1709         .help_str = "port config all loopback <mode>",
1710         .tokens = {
1711                 (void *)&cmd_config_loopback_all_port,
1712                 (void *)&cmd_config_loopback_all_keyword,
1713                 (void *)&cmd_config_loopback_all_all,
1714                 (void *)&cmd_config_loopback_all_item,
1715                 (void *)&cmd_config_loopback_all_mode,
1716                 NULL,
1717         },
1718 };
1719
1720 /* *** configure loopback for specific port *** */
1721 struct cmd_config_loopback_specific {
1722         cmdline_fixed_string_t port;
1723         cmdline_fixed_string_t keyword;
1724         uint16_t port_id;
1725         cmdline_fixed_string_t item;
1726         uint32_t mode;
1727 };
1728
1729 static void
1730 cmd_config_loopback_specific_parsed(void *parsed_result,
1731                                 __rte_unused struct cmdline *cl,
1732                                 __rte_unused void *data)
1733 {
1734         struct cmd_config_loopback_specific *res = parsed_result;
1735
1736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1737                 return;
1738
1739         if (!port_is_stopped(res->port_id)) {
1740                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1741                 return;
1742         }
1743
1744         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1745
1746         cmd_reconfig_device_queue(res->port_id, 1, 1);
1747 }
1748
1749
1750 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1751         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1752                                                                 "port");
1753 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1754         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1755                                                                 "config");
1756 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1757         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1758                                                                 RTE_UINT16);
1759 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1761                                                                 "loopback");
1762 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1763         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1764                               RTE_UINT32);
1765
1766 cmdline_parse_inst_t cmd_config_loopback_specific = {
1767         .f = cmd_config_loopback_specific_parsed,
1768         .data = NULL,
1769         .help_str = "port config <port_id> loopback <mode>",
1770         .tokens = {
1771                 (void *)&cmd_config_loopback_specific_port,
1772                 (void *)&cmd_config_loopback_specific_keyword,
1773                 (void *)&cmd_config_loopback_specific_id,
1774                 (void *)&cmd_config_loopback_specific_item,
1775                 (void *)&cmd_config_loopback_specific_mode,
1776                 NULL,
1777         },
1778 };
1779
1780 /* *** configure txq/rxq, txd/rxd *** */
1781 struct cmd_config_rx_tx {
1782         cmdline_fixed_string_t port;
1783         cmdline_fixed_string_t keyword;
1784         cmdline_fixed_string_t all;
1785         cmdline_fixed_string_t name;
1786         uint16_t value;
1787 };
1788
1789 static void
1790 cmd_config_rx_tx_parsed(void *parsed_result,
1791                         __rte_unused struct cmdline *cl,
1792                         __rte_unused void *data)
1793 {
1794         struct cmd_config_rx_tx *res = parsed_result;
1795
1796         if (!all_ports_stopped()) {
1797                 fprintf(stderr, "Please stop all ports first\n");
1798                 return;
1799         }
1800         if (!strcmp(res->name, "rxq")) {
1801                 if (!res->value && !nb_txq) {
1802                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1803                         return;
1804                 }
1805                 if (check_nb_rxq(res->value) != 0)
1806                         return;
1807                 nb_rxq = res->value;
1808         }
1809         else if (!strcmp(res->name, "txq")) {
1810                 if (!res->value && !nb_rxq) {
1811                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1812                         return;
1813                 }
1814                 if (check_nb_txq(res->value) != 0)
1815                         return;
1816                 nb_txq = res->value;
1817         }
1818         else if (!strcmp(res->name, "rxd")) {
1819                 if (check_nb_rxd(res->value) != 0)
1820                         return;
1821                 nb_rxd = res->value;
1822         } else if (!strcmp(res->name, "txd")) {
1823                 if (check_nb_txd(res->value) != 0)
1824                         return;
1825
1826                 nb_txd = res->value;
1827         } else {
1828                 fprintf(stderr, "Unknown parameter\n");
1829                 return;
1830         }
1831
1832         fwd_config_setup();
1833
1834         init_port_config();
1835
1836         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1837 }
1838
1839 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1840         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1841 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1843 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1845 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1847                                                 "rxq#txq#rxd#txd");
1848 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1849         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1850
1851 cmdline_parse_inst_t cmd_config_rx_tx = {
1852         .f = cmd_config_rx_tx_parsed,
1853         .data = NULL,
1854         .help_str = "port config all rxq|txq|rxd|txd <value>",
1855         .tokens = {
1856                 (void *)&cmd_config_rx_tx_port,
1857                 (void *)&cmd_config_rx_tx_keyword,
1858                 (void *)&cmd_config_rx_tx_all,
1859                 (void *)&cmd_config_rx_tx_name,
1860                 (void *)&cmd_config_rx_tx_value,
1861                 NULL,
1862         },
1863 };
1864
1865 /* *** config max packet length *** */
1866 struct cmd_config_max_pkt_len_result {
1867         cmdline_fixed_string_t port;
1868         cmdline_fixed_string_t keyword;
1869         cmdline_fixed_string_t all;
1870         cmdline_fixed_string_t name;
1871         uint32_t value;
1872 };
1873
1874 static void
1875 cmd_config_max_pkt_len_parsed(void *parsed_result,
1876                                 __rte_unused struct cmdline *cl,
1877                                 __rte_unused void *data)
1878 {
1879         struct cmd_config_max_pkt_len_result *res = parsed_result;
1880         uint32_t max_rx_pkt_len_backup = 0;
1881         portid_t pid;
1882         int ret;
1883
1884         if (!all_ports_stopped()) {
1885                 fprintf(stderr, "Please stop all ports first\n");
1886                 return;
1887         }
1888
1889         RTE_ETH_FOREACH_DEV(pid) {
1890                 struct rte_port *port = &ports[pid];
1891
1892                 if (!strcmp(res->name, "max-pkt-len")) {
1893                         if (res->value < RTE_ETHER_MIN_LEN) {
1894                                 fprintf(stderr,
1895                                         "max-pkt-len can not be less than %d\n",
1896                                         RTE_ETHER_MIN_LEN);
1897                                 return;
1898                         }
1899                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1900                                 return;
1901
1902                         ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1903                         if (ret != 0) {
1904                                 fprintf(stderr,
1905                                         "rte_eth_dev_info_get() failed for port %u\n",
1906                                         pid);
1907                                 return;
1908                         }
1909
1910                         max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1911
1912                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1913                         if (update_jumbo_frame_offload(pid) != 0)
1914                                 port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1915                 } else {
1916                         fprintf(stderr, "Unknown parameter\n");
1917                         return;
1918                 }
1919         }
1920
1921         init_port_config();
1922
1923         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1924 }
1925
1926 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1927         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1928                                                                 "port");
1929 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1930         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1931                                                                 "config");
1932 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1933         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1934                                                                 "all");
1935 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1936         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1937                                                                 "max-pkt-len");
1938 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1939         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1940                                                                 RTE_UINT32);
1941
1942 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1943         .f = cmd_config_max_pkt_len_parsed,
1944         .data = NULL,
1945         .help_str = "port config all max-pkt-len <value>",
1946         .tokens = {
1947                 (void *)&cmd_config_max_pkt_len_port,
1948                 (void *)&cmd_config_max_pkt_len_keyword,
1949                 (void *)&cmd_config_max_pkt_len_all,
1950                 (void *)&cmd_config_max_pkt_len_name,
1951                 (void *)&cmd_config_max_pkt_len_value,
1952                 NULL,
1953         },
1954 };
1955
1956 /* *** config max LRO aggregated packet size *** */
1957 struct cmd_config_max_lro_pkt_size_result {
1958         cmdline_fixed_string_t port;
1959         cmdline_fixed_string_t keyword;
1960         cmdline_fixed_string_t all;
1961         cmdline_fixed_string_t name;
1962         uint32_t value;
1963 };
1964
1965 static void
1966 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1967                                 __rte_unused struct cmdline *cl,
1968                                 __rte_unused void *data)
1969 {
1970         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1971         portid_t pid;
1972
1973         if (!all_ports_stopped()) {
1974                 fprintf(stderr, "Please stop all ports first\n");
1975                 return;
1976         }
1977
1978         RTE_ETH_FOREACH_DEV(pid) {
1979                 struct rte_port *port = &ports[pid];
1980
1981                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1982                         if (res->value ==
1983                                         port->dev_conf.rxmode.max_lro_pkt_size)
1984                                 return;
1985
1986                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1987                 } else {
1988                         fprintf(stderr, "Unknown parameter\n");
1989                         return;
1990                 }
1991         }
1992
1993         init_port_config();
1994
1995         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1996 }
1997
1998 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1999         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2000                                  port, "port");
2001 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2003                                  keyword, "config");
2004 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2005         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2006                                  all, "all");
2007 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2009                                  name, "max-lro-pkt-size");
2010 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2011         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2012                               value, RTE_UINT32);
2013
2014 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2015         .f = cmd_config_max_lro_pkt_size_parsed,
2016         .data = NULL,
2017         .help_str = "port config all max-lro-pkt-size <value>",
2018         .tokens = {
2019                 (void *)&cmd_config_max_lro_pkt_size_port,
2020                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2021                 (void *)&cmd_config_max_lro_pkt_size_all,
2022                 (void *)&cmd_config_max_lro_pkt_size_name,
2023                 (void *)&cmd_config_max_lro_pkt_size_value,
2024                 NULL,
2025         },
2026 };
2027
2028 /* *** configure port MTU *** */
2029 struct cmd_config_mtu_result {
2030         cmdline_fixed_string_t port;
2031         cmdline_fixed_string_t keyword;
2032         cmdline_fixed_string_t mtu;
2033         portid_t port_id;
2034         uint16_t value;
2035 };
2036
2037 static void
2038 cmd_config_mtu_parsed(void *parsed_result,
2039                       __rte_unused struct cmdline *cl,
2040                       __rte_unused void *data)
2041 {
2042         struct cmd_config_mtu_result *res = parsed_result;
2043
2044         if (res->value < RTE_ETHER_MIN_LEN) {
2045                 fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2046                 return;
2047         }
2048         port_mtu_set(res->port_id, res->value);
2049 }
2050
2051 cmdline_parse_token_string_t cmd_config_mtu_port =
2052         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2053                                  "port");
2054 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2055         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2056                                  "config");
2057 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2058         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2059                                  "mtu");
2060 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2061         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2062                                  RTE_UINT16);
2063 cmdline_parse_token_num_t cmd_config_mtu_value =
2064         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2065                                  RTE_UINT16);
2066
2067 cmdline_parse_inst_t cmd_config_mtu = {
2068         .f = cmd_config_mtu_parsed,
2069         .data = NULL,
2070         .help_str = "port config mtu <port_id> <value>",
2071         .tokens = {
2072                 (void *)&cmd_config_mtu_port,
2073                 (void *)&cmd_config_mtu_keyword,
2074                 (void *)&cmd_config_mtu_mtu,
2075                 (void *)&cmd_config_mtu_port_id,
2076                 (void *)&cmd_config_mtu_value,
2077                 NULL,
2078         },
2079 };
2080
2081 /* *** configure rx mode *** */
2082 struct cmd_config_rx_mode_flag {
2083         cmdline_fixed_string_t port;
2084         cmdline_fixed_string_t keyword;
2085         cmdline_fixed_string_t all;
2086         cmdline_fixed_string_t name;
2087         cmdline_fixed_string_t value;
2088 };
2089
2090 static void
2091 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2092                                 __rte_unused struct cmdline *cl,
2093                                 __rte_unused void *data)
2094 {
2095         struct cmd_config_rx_mode_flag *res = parsed_result;
2096
2097         if (!all_ports_stopped()) {
2098                 fprintf(stderr, "Please stop all ports first\n");
2099                 return;
2100         }
2101
2102         if (!strcmp(res->name, "drop-en")) {
2103                 if (!strcmp(res->value, "on"))
2104                         rx_drop_en = 1;
2105                 else if (!strcmp(res->value, "off"))
2106                         rx_drop_en = 0;
2107                 else {
2108                         fprintf(stderr, "Unknown parameter\n");
2109                         return;
2110                 }
2111         } else {
2112                 fprintf(stderr, "Unknown parameter\n");
2113                 return;
2114         }
2115
2116         init_port_config();
2117
2118         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2119 }
2120
2121 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2122         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2123 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2124         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2125                                                                 "config");
2126 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2127         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2128 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2129         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2130                                         "drop-en");
2131 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2132         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2133                                                         "on#off");
2134
2135 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2136         .f = cmd_config_rx_mode_flag_parsed,
2137         .data = NULL,
2138         .help_str = "port config all drop-en on|off",
2139         .tokens = {
2140                 (void *)&cmd_config_rx_mode_flag_port,
2141                 (void *)&cmd_config_rx_mode_flag_keyword,
2142                 (void *)&cmd_config_rx_mode_flag_all,
2143                 (void *)&cmd_config_rx_mode_flag_name,
2144                 (void *)&cmd_config_rx_mode_flag_value,
2145                 NULL,
2146         },
2147 };
2148
2149 /* *** configure rss *** */
2150 struct cmd_config_rss {
2151         cmdline_fixed_string_t port;
2152         cmdline_fixed_string_t keyword;
2153         cmdline_fixed_string_t all;
2154         cmdline_fixed_string_t name;
2155         cmdline_fixed_string_t value;
2156 };
2157
2158 static void
2159 cmd_config_rss_parsed(void *parsed_result,
2160                         __rte_unused struct cmdline *cl,
2161                         __rte_unused void *data)
2162 {
2163         struct cmd_config_rss *res = parsed_result;
2164         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2165         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2166         int use_default = 0;
2167         int all_updated = 1;
2168         int diag;
2169         uint16_t i;
2170         int ret;
2171
2172         if (!strcmp(res->value, "all"))
2173                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2174                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2175                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2176                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2177                         ETH_RSS_ECPRI;
2178         else if (!strcmp(res->value, "eth"))
2179                 rss_conf.rss_hf = ETH_RSS_ETH;
2180         else if (!strcmp(res->value, "vlan"))
2181                 rss_conf.rss_hf = ETH_RSS_VLAN;
2182         else if (!strcmp(res->value, "ip"))
2183                 rss_conf.rss_hf = ETH_RSS_IP;
2184         else if (!strcmp(res->value, "udp"))
2185                 rss_conf.rss_hf = ETH_RSS_UDP;
2186         else if (!strcmp(res->value, "tcp"))
2187                 rss_conf.rss_hf = ETH_RSS_TCP;
2188         else if (!strcmp(res->value, "sctp"))
2189                 rss_conf.rss_hf = ETH_RSS_SCTP;
2190         else if (!strcmp(res->value, "ether"))
2191                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2192         else if (!strcmp(res->value, "port"))
2193                 rss_conf.rss_hf = ETH_RSS_PORT;
2194         else if (!strcmp(res->value, "vxlan"))
2195                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2196         else if (!strcmp(res->value, "geneve"))
2197                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2198         else if (!strcmp(res->value, "nvgre"))
2199                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2200         else if (!strcmp(res->value, "l3-pre32"))
2201                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2202         else if (!strcmp(res->value, "l3-pre40"))
2203                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2204         else if (!strcmp(res->value, "l3-pre48"))
2205                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2206         else if (!strcmp(res->value, "l3-pre56"))
2207                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2208         else if (!strcmp(res->value, "l3-pre64"))
2209                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2210         else if (!strcmp(res->value, "l3-pre96"))
2211                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2212         else if (!strcmp(res->value, "l3-src-only"))
2213                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2214         else if (!strcmp(res->value, "l3-dst-only"))
2215                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2216         else if (!strcmp(res->value, "l4-src-only"))
2217                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2218         else if (!strcmp(res->value, "l4-dst-only"))
2219                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2220         else if (!strcmp(res->value, "l2-src-only"))
2221                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2222         else if (!strcmp(res->value, "l2-dst-only"))
2223                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2224         else if (!strcmp(res->value, "l2tpv3"))
2225                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2226         else if (!strcmp(res->value, "esp"))
2227                 rss_conf.rss_hf = ETH_RSS_ESP;
2228         else if (!strcmp(res->value, "ah"))
2229                 rss_conf.rss_hf = ETH_RSS_AH;
2230         else if (!strcmp(res->value, "pfcp"))
2231                 rss_conf.rss_hf = ETH_RSS_PFCP;
2232         else if (!strcmp(res->value, "pppoe"))
2233                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2234         else if (!strcmp(res->value, "gtpu"))
2235                 rss_conf.rss_hf = ETH_RSS_GTPU;
2236         else if (!strcmp(res->value, "ecpri"))
2237                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2238         else if (!strcmp(res->value, "mpls"))
2239                 rss_conf.rss_hf = ETH_RSS_MPLS;
2240         else if (!strcmp(res->value, "ipv4-chksum"))
2241                 rss_conf.rss_hf = ETH_RSS_IPV4_CHKSUM;
2242         else if (!strcmp(res->value, "none"))
2243                 rss_conf.rss_hf = 0;
2244         else if (!strcmp(res->value, "level-default")) {
2245                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2246                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2247         } else if (!strcmp(res->value, "level-outer")) {
2248                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2249                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2250         } else if (!strcmp(res->value, "level-inner")) {
2251                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2252                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2253         } else if (!strcmp(res->value, "default"))
2254                 use_default = 1;
2255         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2256                                                 atoi(res->value) < 64)
2257                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2258         else {
2259                 fprintf(stderr, "Unknown parameter\n");
2260                 return;
2261         }
2262         rss_conf.rss_key = NULL;
2263         /* Update global configuration for RSS types. */
2264         RTE_ETH_FOREACH_DEV(i) {
2265                 struct rte_eth_rss_conf local_rss_conf;
2266
2267                 ret = eth_dev_info_get_print_err(i, &dev_info);
2268                 if (ret != 0)
2269                         return;
2270
2271                 if (use_default)
2272                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2273
2274                 local_rss_conf = rss_conf;
2275                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2276                         dev_info.flow_type_rss_offloads;
2277                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2278                         printf("Port %u modified RSS hash function based on hardware support,"
2279                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2280                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2281                 }
2282                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2283                 if (diag < 0) {
2284                         all_updated = 0;
2285                         fprintf(stderr,
2286                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2287                                 i, -diag, strerror(-diag));
2288                 }
2289         }
2290         if (all_updated && !use_default) {
2291                 rss_hf = rss_conf.rss_hf;
2292                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2293         }
2294 }
2295
2296 cmdline_parse_token_string_t cmd_config_rss_port =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2298 cmdline_parse_token_string_t cmd_config_rss_keyword =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2300 cmdline_parse_token_string_t cmd_config_rss_all =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2302 cmdline_parse_token_string_t cmd_config_rss_name =
2303         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2304 cmdline_parse_token_string_t cmd_config_rss_value =
2305         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2306
2307 cmdline_parse_inst_t cmd_config_rss = {
2308         .f = cmd_config_rss_parsed,
2309         .data = NULL,
2310         .help_str = "port config all rss "
2311                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2312                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2313                 "level-outer|level-inner|ipv4-chksum|<flowtype_id>",
2314         .tokens = {
2315                 (void *)&cmd_config_rss_port,
2316                 (void *)&cmd_config_rss_keyword,
2317                 (void *)&cmd_config_rss_all,
2318                 (void *)&cmd_config_rss_name,
2319                 (void *)&cmd_config_rss_value,
2320                 NULL,
2321         },
2322 };
2323
2324 /* *** configure rss hash key *** */
2325 struct cmd_config_rss_hash_key {
2326         cmdline_fixed_string_t port;
2327         cmdline_fixed_string_t config;
2328         portid_t port_id;
2329         cmdline_fixed_string_t rss_hash_key;
2330         cmdline_fixed_string_t rss_type;
2331         cmdline_fixed_string_t key;
2332 };
2333
2334 static uint8_t
2335 hexa_digit_to_value(char hexa_digit)
2336 {
2337         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2338                 return (uint8_t) (hexa_digit - '0');
2339         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2340                 return (uint8_t) ((hexa_digit - 'a') + 10);
2341         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2342                 return (uint8_t) ((hexa_digit - 'A') + 10);
2343         /* Invalid hexa digit */
2344         return 0xFF;
2345 }
2346
2347 static uint8_t
2348 parse_and_check_key_hexa_digit(char *key, int idx)
2349 {
2350         uint8_t hexa_v;
2351
2352         hexa_v = hexa_digit_to_value(key[idx]);
2353         if (hexa_v == 0xFF)
2354                 fprintf(stderr,
2355                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2356                         key[idx], idx);
2357         return hexa_v;
2358 }
2359
2360 static void
2361 cmd_config_rss_hash_key_parsed(void *parsed_result,
2362                                __rte_unused struct cmdline *cl,
2363                                __rte_unused void *data)
2364 {
2365         struct cmd_config_rss_hash_key *res = parsed_result;
2366         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2367         uint8_t xdgt0;
2368         uint8_t xdgt1;
2369         int i;
2370         struct rte_eth_dev_info dev_info;
2371         uint8_t hash_key_size;
2372         uint32_t key_len;
2373         int ret;
2374
2375         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2376         if (ret != 0)
2377                 return;
2378
2379         if (dev_info.hash_key_size > 0 &&
2380                         dev_info.hash_key_size <= sizeof(hash_key))
2381                 hash_key_size = dev_info.hash_key_size;
2382         else {
2383                 fprintf(stderr,
2384                         "dev_info did not provide a valid hash key size\n");
2385                 return;
2386         }
2387         /* Check the length of the RSS hash key */
2388         key_len = strlen(res->key);
2389         if (key_len != (hash_key_size * 2)) {
2390                 fprintf(stderr,
2391                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2392                         (int)key_len, hash_key_size * 2);
2393                 return;
2394         }
2395         /* Translate RSS hash key into binary representation */
2396         for (i = 0; i < hash_key_size; i++) {
2397                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2398                 if (xdgt0 == 0xFF)
2399                         return;
2400                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2401                 if (xdgt1 == 0xFF)
2402                         return;
2403                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2404         }
2405         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2406                         hash_key_size);
2407 }
2408
2409 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2410         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2411 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2412         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2413                                  "config");
2414 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2415         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2416                                  RTE_UINT16);
2417 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2418         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2419                                  rss_hash_key, "rss-hash-key");
2420 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2421         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2422                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2423                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2424                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2425                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2426                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2427                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2428                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2429 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2430         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2431
2432 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2433         .f = cmd_config_rss_hash_key_parsed,
2434         .data = NULL,
2435         .help_str = "port config <port_id> rss-hash-key "
2436                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2437                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2438                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2439                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2440                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2441                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2442                 "<string of hex digits (variable length, NIC dependent)>",
2443         .tokens = {
2444                 (void *)&cmd_config_rss_hash_key_port,
2445                 (void *)&cmd_config_rss_hash_key_config,
2446                 (void *)&cmd_config_rss_hash_key_port_id,
2447                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2448                 (void *)&cmd_config_rss_hash_key_rss_type,
2449                 (void *)&cmd_config_rss_hash_key_value,
2450                 NULL,
2451         },
2452 };
2453
2454 /* *** cleanup txq mbufs *** */
2455 struct cmd_cleanup_txq_mbufs_result {
2456         cmdline_fixed_string_t port;
2457         cmdline_fixed_string_t keyword;
2458         cmdline_fixed_string_t name;
2459         uint16_t port_id;
2460         uint16_t queue_id;
2461         uint32_t free_cnt;
2462 };
2463
2464 static void
2465 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2466                              __rte_unused struct cmdline *cl,
2467                              __rte_unused void *data)
2468 {
2469         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2470         uint16_t port_id = res->port_id;
2471         uint16_t queue_id = res->queue_id;
2472         uint32_t free_cnt = res->free_cnt;
2473         struct rte_eth_txq_info qinfo;
2474         int ret;
2475
2476         if (test_done == 0) {
2477                 fprintf(stderr, "Please stop forwarding first\n");
2478                 return;
2479         }
2480
2481         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2482                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2483                         port_id, queue_id);
2484                 return;
2485         }
2486
2487         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2488                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2489                 return;
2490         }
2491
2492         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2493         if (ret < 0) {
2494                 fprintf(stderr,
2495                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2496                         port_id, queue_id, strerror(-ret), ret);
2497                 return;
2498         }
2499
2500         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2501                port_id, queue_id, ret);
2502 }
2503
2504 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2505         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2506                                  "port");
2507 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2508         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2509                                  "cleanup");
2510 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2511         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2512                               RTE_UINT16);
2513 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2514         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2515                                  "txq");
2516 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2517         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2518                               RTE_UINT16);
2519 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2520         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2521                               RTE_UINT32);
2522
2523 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2524         .f = cmd_cleanup_txq_mbufs_parsed,
2525         .data = NULL,
2526         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2527         .tokens = {
2528                 (void *)&cmd_cleanup_txq_mbufs_port,
2529                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2530                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2531                 (void *)&cmd_cleanup_txq_mbufs_txq,
2532                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2533                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2534                 NULL,
2535         },
2536 };
2537
2538 /* *** configure port rxq/txq ring size *** */
2539 struct cmd_config_rxtx_ring_size {
2540         cmdline_fixed_string_t port;
2541         cmdline_fixed_string_t config;
2542         portid_t portid;
2543         cmdline_fixed_string_t rxtxq;
2544         uint16_t qid;
2545         cmdline_fixed_string_t rsize;
2546         uint16_t size;
2547 };
2548
2549 static void
2550 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2551                                  __rte_unused struct cmdline *cl,
2552                                  __rte_unused void *data)
2553 {
2554         struct cmd_config_rxtx_ring_size *res = parsed_result;
2555         struct rte_port *port;
2556         uint8_t isrx;
2557
2558         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2559                 return;
2560
2561         if (res->portid == (portid_t)RTE_PORT_ALL) {
2562                 fprintf(stderr, "Invalid port id\n");
2563                 return;
2564         }
2565
2566         port = &ports[res->portid];
2567
2568         if (!strcmp(res->rxtxq, "rxq"))
2569                 isrx = 1;
2570         else if (!strcmp(res->rxtxq, "txq"))
2571                 isrx = 0;
2572         else {
2573                 fprintf(stderr, "Unknown parameter\n");
2574                 return;
2575         }
2576
2577         if (isrx && rx_queue_id_is_invalid(res->qid))
2578                 return;
2579         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2580                 return;
2581
2582         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2583                 fprintf(stderr,
2584                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2585                         rx_free_thresh);
2586                 return;
2587         }
2588
2589         if (isrx)
2590                 port->nb_rx_desc[res->qid] = res->size;
2591         else
2592                 port->nb_tx_desc[res->qid] = res->size;
2593
2594         cmd_reconfig_device_queue(res->portid, 0, 1);
2595 }
2596
2597 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2599                                  port, "port");
2600 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2601         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2602                                  config, "config");
2603 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2604         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2605                                  portid, RTE_UINT16);
2606 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2607         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2608                                  rxtxq, "rxq#txq");
2609 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2610         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2611                               qid, RTE_UINT16);
2612 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2613         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2614                                  rsize, "ring_size");
2615 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2616         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2617                               size, RTE_UINT16);
2618
2619 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2620         .f = cmd_config_rxtx_ring_size_parsed,
2621         .data = NULL,
2622         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2623         .tokens = {
2624                 (void *)&cmd_config_rxtx_ring_size_port,
2625                 (void *)&cmd_config_rxtx_ring_size_config,
2626                 (void *)&cmd_config_rxtx_ring_size_portid,
2627                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2628                 (void *)&cmd_config_rxtx_ring_size_qid,
2629                 (void *)&cmd_config_rxtx_ring_size_rsize,
2630                 (void *)&cmd_config_rxtx_ring_size_size,
2631                 NULL,
2632         },
2633 };
2634
2635 /* *** configure port rxq/txq start/stop *** */
2636 struct cmd_config_rxtx_queue {
2637         cmdline_fixed_string_t port;
2638         portid_t portid;
2639         cmdline_fixed_string_t rxtxq;
2640         uint16_t qid;
2641         cmdline_fixed_string_t opname;
2642 };
2643
2644 static void
2645 cmd_config_rxtx_queue_parsed(void *parsed_result,
2646                         __rte_unused struct cmdline *cl,
2647                         __rte_unused void *data)
2648 {
2649         struct cmd_config_rxtx_queue *res = parsed_result;
2650         uint8_t isrx;
2651         uint8_t isstart;
2652         int ret = 0;
2653
2654         if (test_done == 0) {
2655                 fprintf(stderr, "Please stop forwarding first\n");
2656                 return;
2657         }
2658
2659         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2660                 return;
2661
2662         if (port_is_started(res->portid) != 1) {
2663                 fprintf(stderr, "Please start port %u first\n", res->portid);
2664                 return;
2665         }
2666
2667         if (!strcmp(res->rxtxq, "rxq"))
2668                 isrx = 1;
2669         else if (!strcmp(res->rxtxq, "txq"))
2670                 isrx = 0;
2671         else {
2672                 fprintf(stderr, "Unknown parameter\n");
2673                 return;
2674         }
2675
2676         if (isrx && rx_queue_id_is_invalid(res->qid))
2677                 return;
2678         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2679                 return;
2680
2681         if (!strcmp(res->opname, "start"))
2682                 isstart = 1;
2683         else if (!strcmp(res->opname, "stop"))
2684                 isstart = 0;
2685         else {
2686                 fprintf(stderr, "Unknown parameter\n");
2687                 return;
2688         }
2689
2690         if (isstart && isrx)
2691                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2692         else if (!isstart && isrx)
2693                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2694         else if (isstart && !isrx)
2695                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2696         else
2697                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2698
2699         if (ret == -ENOTSUP)
2700                 fprintf(stderr, "Function not supported in PMD driver\n");
2701 }
2702
2703 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2705 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2706         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2707 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2708         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2709 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2710         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2711 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2712         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2713                                                 "start#stop");
2714
2715 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2716         .f = cmd_config_rxtx_queue_parsed,
2717         .data = NULL,
2718         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2719         .tokens = {
2720                 (void *)&cmd_config_rxtx_queue_port,
2721                 (void *)&cmd_config_rxtx_queue_portid,
2722                 (void *)&cmd_config_rxtx_queue_rxtxq,
2723                 (void *)&cmd_config_rxtx_queue_qid,
2724                 (void *)&cmd_config_rxtx_queue_opname,
2725                 NULL,
2726         },
2727 };
2728
2729 /* *** configure port rxq/txq deferred start on/off *** */
2730 struct cmd_config_deferred_start_rxtx_queue {
2731         cmdline_fixed_string_t port;
2732         portid_t port_id;
2733         cmdline_fixed_string_t rxtxq;
2734         uint16_t qid;
2735         cmdline_fixed_string_t opname;
2736         cmdline_fixed_string_t state;
2737 };
2738
2739 static void
2740 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2741                         __rte_unused struct cmdline *cl,
2742                         __rte_unused void *data)
2743 {
2744         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2745         struct rte_port *port;
2746         uint8_t isrx;
2747         uint8_t ison;
2748         uint8_t needreconfig = 0;
2749
2750         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2751                 return;
2752
2753         if (port_is_started(res->port_id) != 0) {
2754                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2755                 return;
2756         }
2757
2758         port = &ports[res->port_id];
2759
2760         isrx = !strcmp(res->rxtxq, "rxq");
2761
2762         if (isrx && rx_queue_id_is_invalid(res->qid))
2763                 return;
2764         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2765                 return;
2766
2767         ison = !strcmp(res->state, "on");
2768
2769         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2770                 port->rx_conf[res->qid].rx_deferred_start = ison;
2771                 needreconfig = 1;
2772         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2773                 port->tx_conf[res->qid].tx_deferred_start = ison;
2774                 needreconfig = 1;
2775         }
2776
2777         if (needreconfig)
2778                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2779 }
2780
2781 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2782         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2783                                                 port, "port");
2784 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2785         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2786                                                 port_id, RTE_UINT16);
2787 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2788         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2789                                                 rxtxq, "rxq#txq");
2790 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2791         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2792                                                 qid, RTE_UINT16);
2793 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2794         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2795                                                 opname, "deferred_start");
2796 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2797         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2798                                                 state, "on#off");
2799
2800 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2801         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2802         .data = NULL,
2803         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2804         .tokens = {
2805                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2806                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2807                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2808                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2809                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2810                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2811                 NULL,
2812         },
2813 };
2814
2815 /* *** configure port rxq/txq setup *** */
2816 struct cmd_setup_rxtx_queue {
2817         cmdline_fixed_string_t port;
2818         portid_t portid;
2819         cmdline_fixed_string_t rxtxq;
2820         uint16_t qid;
2821         cmdline_fixed_string_t setup;
2822 };
2823
2824 /* Common CLI fields for queue setup */
2825 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2826         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2827 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2828         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2829 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2830         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2831 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2832         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2833 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2834         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2835
2836 static void
2837 cmd_setup_rxtx_queue_parsed(
2838         void *parsed_result,
2839         __rte_unused struct cmdline *cl,
2840         __rte_unused void *data)
2841 {
2842         struct cmd_setup_rxtx_queue *res = parsed_result;
2843         struct rte_port *port;
2844         struct rte_mempool *mp;
2845         unsigned int socket_id;
2846         uint8_t isrx = 0;
2847         int ret;
2848
2849         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2850                 return;
2851
2852         if (res->portid == (portid_t)RTE_PORT_ALL) {
2853                 fprintf(stderr, "Invalid port id\n");
2854                 return;
2855         }
2856
2857         if (!strcmp(res->rxtxq, "rxq"))
2858                 isrx = 1;
2859         else if (!strcmp(res->rxtxq, "txq"))
2860                 isrx = 0;
2861         else {
2862                 fprintf(stderr, "Unknown parameter\n");
2863                 return;
2864         }
2865
2866         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2867                 fprintf(stderr, "Invalid rx queue\n");
2868                 return;
2869         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2870                 fprintf(stderr, "Invalid tx queue\n");
2871                 return;
2872         }
2873
2874         port = &ports[res->portid];
2875         if (isrx) {
2876                 socket_id = rxring_numa[res->portid];
2877                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2878                         socket_id = port->socket_id;
2879
2880                 mp = mbuf_pool_find(socket_id, 0);
2881                 if (mp == NULL) {
2882                         fprintf(stderr,
2883                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2884                                 rxring_numa[res->portid]);
2885                         return;
2886                 }
2887                 ret = rx_queue_setup(res->portid,
2888                                      res->qid,
2889                                      port->nb_rx_desc[res->qid],
2890                                      socket_id,
2891                                      &port->rx_conf[res->qid],
2892                                      mp);
2893                 if (ret)
2894                         fprintf(stderr, "Failed to setup RX queue\n");
2895         } else {
2896                 socket_id = txring_numa[res->portid];
2897                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2898                         socket_id = port->socket_id;
2899
2900                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2901                         fprintf(stderr,
2902                                 "Failed to setup TX queue: not enough descriptors\n");
2903                         return;
2904                 }
2905                 ret = rte_eth_tx_queue_setup(res->portid,
2906                                              res->qid,
2907                                              port->nb_tx_desc[res->qid],
2908                                              socket_id,
2909                                              &port->tx_conf[res->qid]);
2910                 if (ret)
2911                         fprintf(stderr, "Failed to setup TX queue\n");
2912         }
2913 }
2914
2915 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2916         .f = cmd_setup_rxtx_queue_parsed,
2917         .data = NULL,
2918         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2919         .tokens = {
2920                 (void *)&cmd_setup_rxtx_queue_port,
2921                 (void *)&cmd_setup_rxtx_queue_portid,
2922                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2923                 (void *)&cmd_setup_rxtx_queue_qid,
2924                 (void *)&cmd_setup_rxtx_queue_setup,
2925                 NULL,
2926         },
2927 };
2928
2929
2930 /* *** Configure RSS RETA *** */
2931 struct cmd_config_rss_reta {
2932         cmdline_fixed_string_t port;
2933         cmdline_fixed_string_t keyword;
2934         portid_t port_id;
2935         cmdline_fixed_string_t name;
2936         cmdline_fixed_string_t list_name;
2937         cmdline_fixed_string_t list_of_items;
2938 };
2939
2940 static int
2941 parse_reta_config(const char *str,
2942                   struct rte_eth_rss_reta_entry64 *reta_conf,
2943                   uint16_t nb_entries)
2944 {
2945         int i;
2946         unsigned size;
2947         uint16_t hash_index, idx, shift;
2948         uint16_t nb_queue;
2949         char s[256];
2950         const char *p, *p0 = str;
2951         char *end;
2952         enum fieldnames {
2953                 FLD_HASH_INDEX = 0,
2954                 FLD_QUEUE,
2955                 _NUM_FLD
2956         };
2957         unsigned long int_fld[_NUM_FLD];
2958         char *str_fld[_NUM_FLD];
2959
2960         while ((p = strchr(p0,'(')) != NULL) {
2961                 ++p;
2962                 if((p0 = strchr(p,')')) == NULL)
2963                         return -1;
2964
2965                 size = p0 - p;
2966                 if(size >= sizeof(s))
2967                         return -1;
2968
2969                 snprintf(s, sizeof(s), "%.*s", size, p);
2970                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2971                         return -1;
2972                 for (i = 0; i < _NUM_FLD; i++) {
2973                         errno = 0;
2974                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2975                         if (errno != 0 || end == str_fld[i] ||
2976                                         int_fld[i] > 65535)
2977                                 return -1;
2978                 }
2979
2980                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2981                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2982
2983                 if (hash_index >= nb_entries) {
2984                         fprintf(stderr, "Invalid RETA hash index=%d\n",
2985                                 hash_index);
2986                         return -1;
2987                 }
2988
2989                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2990                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2991                 reta_conf[idx].mask |= (1ULL << shift);
2992                 reta_conf[idx].reta[shift] = nb_queue;
2993         }
2994
2995         return 0;
2996 }
2997
2998 static void
2999 cmd_set_rss_reta_parsed(void *parsed_result,
3000                         __rte_unused struct cmdline *cl,
3001                         __rte_unused void *data)
3002 {
3003         int ret;
3004         struct rte_eth_dev_info dev_info;
3005         struct rte_eth_rss_reta_entry64 reta_conf[8];
3006         struct cmd_config_rss_reta *res = parsed_result;
3007
3008         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3009         if (ret != 0)
3010                 return;
3011
3012         if (dev_info.reta_size == 0) {
3013                 fprintf(stderr,
3014                         "Redirection table size is 0 which is invalid for RSS\n");
3015                 return;
3016         } else
3017                 printf("The reta size of port %d is %u\n",
3018                         res->port_id, dev_info.reta_size);
3019         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3020                 fprintf(stderr,
3021                         "Currently do not support more than %u entries of redirection table\n",
3022                         ETH_RSS_RETA_SIZE_512);
3023                 return;
3024         }
3025
3026         memset(reta_conf, 0, sizeof(reta_conf));
3027         if (!strcmp(res->list_name, "reta")) {
3028                 if (parse_reta_config(res->list_of_items, reta_conf,
3029                                                 dev_info.reta_size)) {
3030                         fprintf(stderr,
3031                                 "Invalid RSS Redirection Table config entered\n");
3032                         return;
3033                 }
3034                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3035                                 reta_conf, dev_info.reta_size);
3036                 if (ret != 0)
3037                         fprintf(stderr,
3038                                 "Bad redirection table parameter, return code = %d\n",
3039                                 ret);
3040         }
3041 }
3042
3043 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3044         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3045 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3046         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3047 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3048         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3049 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3050         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3051 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3052         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3053 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3054         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3055                                  NULL);
3056 cmdline_parse_inst_t cmd_config_rss_reta = {
3057         .f = cmd_set_rss_reta_parsed,
3058         .data = NULL,
3059         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3060         .tokens = {
3061                 (void *)&cmd_config_rss_reta_port,
3062                 (void *)&cmd_config_rss_reta_keyword,
3063                 (void *)&cmd_config_rss_reta_port_id,
3064                 (void *)&cmd_config_rss_reta_name,
3065                 (void *)&cmd_config_rss_reta_list_name,
3066                 (void *)&cmd_config_rss_reta_list_of_items,
3067                 NULL,
3068         },
3069 };
3070
3071 /* *** SHOW PORT RETA INFO *** */
3072 struct cmd_showport_reta {
3073         cmdline_fixed_string_t show;
3074         cmdline_fixed_string_t port;
3075         portid_t port_id;
3076         cmdline_fixed_string_t rss;
3077         cmdline_fixed_string_t reta;
3078         uint16_t size;
3079         cmdline_fixed_string_t list_of_items;
3080 };
3081
3082 static int
3083 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3084                            uint16_t nb_entries,
3085                            char *str)
3086 {
3087         uint32_t size;
3088         const char *p, *p0 = str;
3089         char s[256];
3090         char *end;
3091         char *str_fld[8];
3092         uint16_t i;
3093         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3094                         RTE_RETA_GROUP_SIZE;
3095         int ret;
3096
3097         p = strchr(p0, '(');
3098         if (p == NULL)
3099                 return -1;
3100         p++;
3101         p0 = strchr(p, ')');
3102         if (p0 == NULL)
3103                 return -1;
3104         size = p0 - p;
3105         if (size >= sizeof(s)) {
3106                 fprintf(stderr,
3107                         "The string size exceeds the internal buffer size\n");
3108                 return -1;
3109         }
3110         snprintf(s, sizeof(s), "%.*s", size, p);
3111         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3112         if (ret <= 0 || ret != num) {
3113                 fprintf(stderr,
3114                         "The bits of masks do not match the number of reta entries: %u\n",
3115                         num);
3116                 return -1;
3117         }
3118         for (i = 0; i < ret; i++)
3119                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3120
3121         return 0;
3122 }
3123
3124 static void
3125 cmd_showport_reta_parsed(void *parsed_result,
3126                          __rte_unused struct cmdline *cl,
3127                          __rte_unused void *data)
3128 {
3129         struct cmd_showport_reta *res = parsed_result;
3130         struct rte_eth_rss_reta_entry64 reta_conf[8];
3131         struct rte_eth_dev_info dev_info;
3132         uint16_t max_reta_size;
3133         int ret;
3134
3135         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3136         if (ret != 0)
3137                 return;
3138
3139         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3140         if (res->size == 0 || res->size > max_reta_size) {
3141                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3142                         res->size, max_reta_size);
3143                 return;
3144         }
3145
3146         memset(reta_conf, 0, sizeof(reta_conf));
3147         if (showport_parse_reta_config(reta_conf, res->size,
3148                                 res->list_of_items) < 0) {
3149                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3150                         res->list_of_items);
3151                 return;
3152         }
3153         port_rss_reta_info(res->port_id, reta_conf, res->size);
3154 }
3155
3156 cmdline_parse_token_string_t cmd_showport_reta_show =
3157         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3158 cmdline_parse_token_string_t cmd_showport_reta_port =
3159         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3160 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3161         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3162 cmdline_parse_token_string_t cmd_showport_reta_rss =
3163         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3164 cmdline_parse_token_string_t cmd_showport_reta_reta =
3165         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3166 cmdline_parse_token_num_t cmd_showport_reta_size =
3167         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3168 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3169         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3170                                         list_of_items, NULL);
3171
3172 cmdline_parse_inst_t cmd_showport_reta = {
3173         .f = cmd_showport_reta_parsed,
3174         .data = NULL,
3175         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3176         .tokens = {
3177                 (void *)&cmd_showport_reta_show,
3178                 (void *)&cmd_showport_reta_port,
3179                 (void *)&cmd_showport_reta_port_id,
3180                 (void *)&cmd_showport_reta_rss,
3181                 (void *)&cmd_showport_reta_reta,
3182                 (void *)&cmd_showport_reta_size,
3183                 (void *)&cmd_showport_reta_list_of_items,
3184                 NULL,
3185         },
3186 };
3187
3188 /* *** Show RSS hash configuration *** */
3189 struct cmd_showport_rss_hash {
3190         cmdline_fixed_string_t show;
3191         cmdline_fixed_string_t port;
3192         portid_t port_id;
3193         cmdline_fixed_string_t rss_hash;
3194         cmdline_fixed_string_t rss_type;
3195         cmdline_fixed_string_t key; /* optional argument */
3196 };
3197
3198 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3199                                 __rte_unused struct cmdline *cl,
3200                                 void *show_rss_key)
3201 {
3202         struct cmd_showport_rss_hash *res = parsed_result;
3203
3204         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3205 }
3206
3207 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3208         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3209 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3210         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3211 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3212         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3213                                  RTE_UINT16);
3214 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3215         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3216                                  "rss-hash");
3217 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3218         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3219
3220 cmdline_parse_inst_t cmd_showport_rss_hash = {
3221         .f = cmd_showport_rss_hash_parsed,
3222         .data = NULL,
3223         .help_str = "show port <port_id> rss-hash",
3224         .tokens = {
3225                 (void *)&cmd_showport_rss_hash_show,
3226                 (void *)&cmd_showport_rss_hash_port,
3227                 (void *)&cmd_showport_rss_hash_port_id,
3228                 (void *)&cmd_showport_rss_hash_rss_hash,
3229                 NULL,
3230         },
3231 };
3232
3233 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3234         .f = cmd_showport_rss_hash_parsed,
3235         .data = (void *)1,
3236         .help_str = "show port <port_id> rss-hash key",
3237         .tokens = {
3238                 (void *)&cmd_showport_rss_hash_show,
3239                 (void *)&cmd_showport_rss_hash_port,
3240                 (void *)&cmd_showport_rss_hash_port_id,
3241                 (void *)&cmd_showport_rss_hash_rss_hash,
3242                 (void *)&cmd_showport_rss_hash_rss_key,
3243                 NULL,
3244         },
3245 };
3246
3247 /* *** Configure DCB *** */
3248 struct cmd_config_dcb {
3249         cmdline_fixed_string_t port;
3250         cmdline_fixed_string_t config;
3251         portid_t port_id;
3252         cmdline_fixed_string_t dcb;
3253         cmdline_fixed_string_t vt;
3254         cmdline_fixed_string_t vt_en;
3255         uint8_t num_tcs;
3256         cmdline_fixed_string_t pfc;
3257         cmdline_fixed_string_t pfc_en;
3258 };
3259
3260 static void
3261 cmd_config_dcb_parsed(void *parsed_result,
3262                         __rte_unused struct cmdline *cl,
3263                         __rte_unused void *data)
3264 {
3265         struct cmd_config_dcb *res = parsed_result;
3266         struct rte_eth_dcb_info dcb_info;
3267         portid_t port_id = res->port_id;
3268         struct rte_port *port;
3269         uint8_t pfc_en;
3270         int ret;
3271
3272         port = &ports[port_id];
3273         /** Check if the port is not started **/
3274         if (port->port_status != RTE_PORT_STOPPED) {
3275                 fprintf(stderr, "Please stop port %d first\n", port_id);
3276                 return;
3277         }
3278
3279         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3280                 fprintf(stderr,
3281                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3282                 return;
3283         }
3284
3285         if (nb_fwd_lcores < res->num_tcs) {
3286                 fprintf(stderr,
3287                         "nb_cores shouldn't be less than number of TCs.\n");
3288                 return;
3289         }
3290
3291         /* Check whether the port supports the report of DCB info. */
3292         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3293         if (ret == -ENOTSUP) {
3294                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3295                 return;
3296         }
3297
3298         if (!strncmp(res->pfc_en, "on", 2))
3299                 pfc_en = 1;
3300         else
3301                 pfc_en = 0;
3302
3303         /* DCB in VT mode */
3304         if (!strncmp(res->vt_en, "on", 2))
3305                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3306                                 (enum rte_eth_nb_tcs)res->num_tcs,
3307                                 pfc_en);
3308         else
3309                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3310                                 (enum rte_eth_nb_tcs)res->num_tcs,
3311                                 pfc_en);
3312         if (ret != 0) {
3313                 fprintf(stderr, "Cannot initialize network ports.\n");
3314                 return;
3315         }
3316
3317         fwd_config_setup();
3318
3319         cmd_reconfig_device_queue(port_id, 1, 1);
3320 }
3321
3322 cmdline_parse_token_string_t cmd_config_dcb_port =
3323         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3324 cmdline_parse_token_string_t cmd_config_dcb_config =
3325         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3326 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3327         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3328 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3329         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3330 cmdline_parse_token_string_t cmd_config_dcb_vt =
3331         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3332 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3334 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3335         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3336 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3337         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3338 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3339         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3340
3341 cmdline_parse_inst_t cmd_config_dcb = {
3342         .f = cmd_config_dcb_parsed,
3343         .data = NULL,
3344         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3345         .tokens = {
3346                 (void *)&cmd_config_dcb_port,
3347                 (void *)&cmd_config_dcb_config,
3348                 (void *)&cmd_config_dcb_port_id,
3349                 (void *)&cmd_config_dcb_dcb,
3350                 (void *)&cmd_config_dcb_vt,
3351                 (void *)&cmd_config_dcb_vt_en,
3352                 (void *)&cmd_config_dcb_num_tcs,
3353                 (void *)&cmd_config_dcb_pfc,
3354                 (void *)&cmd_config_dcb_pfc_en,
3355                 NULL,
3356         },
3357 };
3358
3359 /* *** configure number of packets per burst *** */
3360 struct cmd_config_burst {
3361         cmdline_fixed_string_t port;
3362         cmdline_fixed_string_t keyword;
3363         cmdline_fixed_string_t all;
3364         cmdline_fixed_string_t name;
3365         uint16_t value;
3366 };
3367
3368 static void
3369 cmd_config_burst_parsed(void *parsed_result,
3370                         __rte_unused struct cmdline *cl,
3371                         __rte_unused void *data)
3372 {
3373         struct cmd_config_burst *res = parsed_result;
3374         struct rte_eth_dev_info dev_info;
3375         uint16_t rec_nb_pkts;
3376         int ret;
3377
3378         if (!all_ports_stopped()) {
3379                 fprintf(stderr, "Please stop all ports first\n");
3380                 return;
3381         }
3382
3383         if (!strcmp(res->name, "burst")) {
3384                 if (res->value == 0) {
3385                         /* If user gives a value of zero, query the PMD for
3386                          * its recommended Rx burst size. Testpmd uses a single
3387                          * size for all ports, so assume all ports are the same
3388                          * NIC model and use the values from Port 0.
3389                          */
3390                         ret = eth_dev_info_get_print_err(0, &dev_info);
3391                         if (ret != 0)
3392                                 return;
3393
3394                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3395
3396                         if (rec_nb_pkts == 0) {
3397                                 printf("PMD does not recommend a burst size.\n"
3398                                         "User provided value must be between"
3399                                         " 1 and %d\n", MAX_PKT_BURST);
3400                                 return;
3401                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3402                                 printf("PMD recommended burst size of %d"
3403                                         " exceeds maximum value of %d\n",
3404                                         rec_nb_pkts, MAX_PKT_BURST);
3405                                 return;
3406                         }
3407                         printf("Using PMD-provided burst value of %d\n",
3408                                 rec_nb_pkts);
3409                         nb_pkt_per_burst = rec_nb_pkts;
3410                 } else if (res->value > MAX_PKT_BURST) {
3411                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3412                                 MAX_PKT_BURST);
3413                         return;
3414                 } else
3415                         nb_pkt_per_burst = res->value;
3416         } else {
3417                 fprintf(stderr, "Unknown parameter\n");
3418                 return;
3419         }
3420
3421         init_port_config();
3422
3423         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3424 }
3425
3426 cmdline_parse_token_string_t cmd_config_burst_port =
3427         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3428 cmdline_parse_token_string_t cmd_config_burst_keyword =
3429         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3430 cmdline_parse_token_string_t cmd_config_burst_all =
3431         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3432 cmdline_parse_token_string_t cmd_config_burst_name =
3433         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3434 cmdline_parse_token_num_t cmd_config_burst_value =
3435         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3436
3437 cmdline_parse_inst_t cmd_config_burst = {
3438         .f = cmd_config_burst_parsed,
3439         .data = NULL,
3440         .help_str = "port config all burst <value>",
3441         .tokens = {
3442                 (void *)&cmd_config_burst_port,
3443                 (void *)&cmd_config_burst_keyword,
3444                 (void *)&cmd_config_burst_all,
3445                 (void *)&cmd_config_burst_name,
3446                 (void *)&cmd_config_burst_value,
3447                 NULL,
3448         },
3449 };
3450
3451 /* *** configure rx/tx queues *** */
3452 struct cmd_config_thresh {
3453         cmdline_fixed_string_t port;
3454         cmdline_fixed_string_t keyword;
3455         cmdline_fixed_string_t all;
3456         cmdline_fixed_string_t name;
3457         uint8_t value;
3458 };
3459
3460 static void
3461 cmd_config_thresh_parsed(void *parsed_result,
3462                         __rte_unused struct cmdline *cl,
3463                         __rte_unused void *data)
3464 {
3465         struct cmd_config_thresh *res = parsed_result;
3466
3467         if (!all_ports_stopped()) {
3468                 fprintf(stderr, "Please stop all ports first\n");
3469                 return;
3470         }
3471
3472         if (!strcmp(res->name, "txpt"))
3473                 tx_pthresh = res->value;
3474         else if(!strcmp(res->name, "txht"))
3475                 tx_hthresh = res->value;
3476         else if(!strcmp(res->name, "txwt"))
3477                 tx_wthresh = res->value;
3478         else if(!strcmp(res->name, "rxpt"))
3479                 rx_pthresh = res->value;
3480         else if(!strcmp(res->name, "rxht"))
3481                 rx_hthresh = res->value;
3482         else if(!strcmp(res->name, "rxwt"))
3483                 rx_wthresh = res->value;
3484         else {
3485                 fprintf(stderr, "Unknown parameter\n");
3486                 return;
3487         }
3488
3489         init_port_config();
3490
3491         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3492 }
3493
3494 cmdline_parse_token_string_t cmd_config_thresh_port =
3495         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3496 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3497         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3498 cmdline_parse_token_string_t cmd_config_thresh_all =
3499         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3500 cmdline_parse_token_string_t cmd_config_thresh_name =
3501         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3502                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3503 cmdline_parse_token_num_t cmd_config_thresh_value =
3504         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3505
3506 cmdline_parse_inst_t cmd_config_thresh = {
3507         .f = cmd_config_thresh_parsed,
3508         .data = NULL,
3509         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3510         .tokens = {
3511                 (void *)&cmd_config_thresh_port,
3512                 (void *)&cmd_config_thresh_keyword,
3513                 (void *)&cmd_config_thresh_all,
3514                 (void *)&cmd_config_thresh_name,
3515                 (void *)&cmd_config_thresh_value,
3516                 NULL,
3517         },
3518 };
3519
3520 /* *** configure free/rs threshold *** */
3521 struct cmd_config_threshold {
3522         cmdline_fixed_string_t port;
3523         cmdline_fixed_string_t keyword;
3524         cmdline_fixed_string_t all;
3525         cmdline_fixed_string_t name;
3526         uint16_t value;
3527 };
3528
3529 static void
3530 cmd_config_threshold_parsed(void *parsed_result,
3531                         __rte_unused struct cmdline *cl,
3532                         __rte_unused void *data)
3533 {
3534         struct cmd_config_threshold *res = parsed_result;
3535
3536         if (!all_ports_stopped()) {
3537                 fprintf(stderr, "Please stop all ports first\n");
3538                 return;
3539         }
3540
3541         if (!strcmp(res->name, "txfreet"))
3542                 tx_free_thresh = res->value;
3543         else if (!strcmp(res->name, "txrst"))
3544                 tx_rs_thresh = res->value;
3545         else if (!strcmp(res->name, "rxfreet"))
3546                 rx_free_thresh = res->value;
3547         else {
3548                 fprintf(stderr, "Unknown parameter\n");
3549                 return;
3550         }
3551
3552         init_port_config();
3553
3554         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3555 }
3556
3557 cmdline_parse_token_string_t cmd_config_threshold_port =
3558         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3559 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3560         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3561                                                                 "config");
3562 cmdline_parse_token_string_t cmd_config_threshold_all =
3563         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3564 cmdline_parse_token_string_t cmd_config_threshold_name =
3565         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3566                                                 "txfreet#txrst#rxfreet");
3567 cmdline_parse_token_num_t cmd_config_threshold_value =
3568         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3569
3570 cmdline_parse_inst_t cmd_config_threshold = {
3571         .f = cmd_config_threshold_parsed,
3572         .data = NULL,
3573         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3574         .tokens = {
3575                 (void *)&cmd_config_threshold_port,
3576                 (void *)&cmd_config_threshold_keyword,
3577                 (void *)&cmd_config_threshold_all,
3578                 (void *)&cmd_config_threshold_name,
3579                 (void *)&cmd_config_threshold_value,
3580                 NULL,
3581         },
3582 };
3583
3584 /* *** stop *** */
3585 struct cmd_stop_result {
3586         cmdline_fixed_string_t stop;
3587 };
3588
3589 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3590                             __rte_unused struct cmdline *cl,
3591                             __rte_unused void *data)
3592 {
3593         stop_packet_forwarding();
3594 }
3595
3596 cmdline_parse_token_string_t cmd_stop_stop =
3597         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3598
3599 cmdline_parse_inst_t cmd_stop = {
3600         .f = cmd_stop_parsed,
3601         .data = NULL,
3602         .help_str = "stop: Stop packet forwarding",
3603         .tokens = {
3604                 (void *)&cmd_stop_stop,
3605                 NULL,
3606         },
3607 };
3608
3609 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3610
3611 unsigned int
3612 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3613                 unsigned int *parsed_items, int check_unique_values)
3614 {
3615         unsigned int nb_item;
3616         unsigned int value;
3617         unsigned int i;
3618         unsigned int j;
3619         int value_ok;
3620         char c;
3621
3622         /*
3623          * First parse all items in the list and store their value.
3624          */
3625         value = 0;
3626         nb_item = 0;
3627         value_ok = 0;
3628         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3629                 c = str[i];
3630                 if ((c >= '0') && (c <= '9')) {
3631                         value = (unsigned int) (value * 10 + (c - '0'));
3632                         value_ok = 1;
3633                         continue;
3634                 }
3635                 if (c != ',') {
3636                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3637                         return 0;
3638                 }
3639                 if (! value_ok) {
3640                         fprintf(stderr, "No valid value before comma\n");
3641                         return 0;
3642                 }
3643                 if (nb_item < max_items) {
3644                         parsed_items[nb_item] = value;
3645                         value_ok = 0;
3646                         value = 0;
3647                 }
3648                 nb_item++;
3649         }
3650         if (nb_item >= max_items) {
3651                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3652                         item_name, nb_item + 1, max_items);
3653                 return 0;
3654         }
3655         parsed_items[nb_item++] = value;
3656         if (! check_unique_values)
3657                 return nb_item;
3658
3659         /*
3660          * Then, check that all values in the list are differents.
3661          * No optimization here...
3662          */
3663         for (i = 0; i < nb_item; i++) {
3664                 for (j = i + 1; j < nb_item; j++) {
3665                         if (parsed_items[j] == parsed_items[i]) {
3666                                 fprintf(stderr,
3667                                         "duplicated %s %u at index %u and %u\n",
3668                                         item_name, parsed_items[i], i, j);
3669                                 return 0;
3670                         }
3671                 }
3672         }
3673         return nb_item;
3674 }
3675
3676 struct cmd_set_list_result {
3677         cmdline_fixed_string_t cmd_keyword;
3678         cmdline_fixed_string_t list_name;
3679         cmdline_fixed_string_t list_of_items;
3680 };
3681
3682 static void cmd_set_list_parsed(void *parsed_result,
3683                                 __rte_unused struct cmdline *cl,
3684                                 __rte_unused void *data)
3685 {
3686         struct cmd_set_list_result *res;
3687         union {
3688                 unsigned int lcorelist[RTE_MAX_LCORE];
3689                 unsigned int portlist[RTE_MAX_ETHPORTS];
3690         } parsed_items;
3691         unsigned int nb_item;
3692
3693         if (test_done == 0) {
3694                 fprintf(stderr, "Please stop forwarding first\n");
3695                 return;
3696         }
3697
3698         res = parsed_result;
3699         if (!strcmp(res->list_name, "corelist")) {
3700                 nb_item = parse_item_list(res->list_of_items, "core",
3701                                           RTE_MAX_LCORE,
3702                                           parsed_items.lcorelist, 1);
3703                 if (nb_item > 0) {
3704                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3705                         fwd_config_setup();
3706                 }
3707                 return;
3708         }
3709         if (!strcmp(res->list_name, "portlist")) {
3710                 nb_item = parse_item_list(res->list_of_items, "port",
3711                                           RTE_MAX_ETHPORTS,
3712                                           parsed_items.portlist, 1);
3713                 if (nb_item > 0) {
3714                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3715                         fwd_config_setup();
3716                 }
3717         }
3718 }
3719
3720 cmdline_parse_token_string_t cmd_set_list_keyword =
3721         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3722                                  "set");
3723 cmdline_parse_token_string_t cmd_set_list_name =
3724         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3725                                  "corelist#portlist");
3726 cmdline_parse_token_string_t cmd_set_list_of_items =
3727         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3728                                  NULL);
3729
3730 cmdline_parse_inst_t cmd_set_fwd_list = {
3731         .f = cmd_set_list_parsed,
3732         .data = NULL,
3733         .help_str = "set corelist|portlist <list0[,list1]*>",
3734         .tokens = {
3735                 (void *)&cmd_set_list_keyword,
3736                 (void *)&cmd_set_list_name,
3737                 (void *)&cmd_set_list_of_items,
3738                 NULL,
3739         },
3740 };
3741
3742 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3743
3744 struct cmd_setmask_result {
3745         cmdline_fixed_string_t set;
3746         cmdline_fixed_string_t mask;
3747         uint64_t hexavalue;
3748 };
3749
3750 static void cmd_set_mask_parsed(void *parsed_result,
3751                                 __rte_unused struct cmdline *cl,
3752                                 __rte_unused void *data)
3753 {
3754         struct cmd_setmask_result *res = parsed_result;
3755
3756         if (test_done == 0) {
3757                 fprintf(stderr, "Please stop forwarding first\n");
3758                 return;
3759         }
3760         if (!strcmp(res->mask, "coremask")) {
3761                 set_fwd_lcores_mask(res->hexavalue);
3762                 fwd_config_setup();
3763         } else if (!strcmp(res->mask, "portmask")) {
3764                 set_fwd_ports_mask(res->hexavalue);
3765                 fwd_config_setup();
3766         }
3767 }
3768
3769 cmdline_parse_token_string_t cmd_setmask_set =
3770         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3771 cmdline_parse_token_string_t cmd_setmask_mask =
3772         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3773                                  "coremask#portmask");
3774 cmdline_parse_token_num_t cmd_setmask_value =
3775         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3776
3777 cmdline_parse_inst_t cmd_set_fwd_mask = {
3778         .f = cmd_set_mask_parsed,
3779         .data = NULL,
3780         .help_str = "set coremask|portmask <hexadecimal value>",
3781         .tokens = {
3782                 (void *)&cmd_setmask_set,
3783                 (void *)&cmd_setmask_mask,
3784                 (void *)&cmd_setmask_value,
3785                 NULL,
3786         },
3787 };
3788
3789 /*
3790  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3791  */
3792 struct cmd_set_result {
3793         cmdline_fixed_string_t set;
3794         cmdline_fixed_string_t what;
3795         uint16_t value;
3796 };
3797
3798 static void cmd_set_parsed(void *parsed_result,
3799                            __rte_unused struct cmdline *cl,
3800                            __rte_unused void *data)
3801 {
3802         struct cmd_set_result *res = parsed_result;
3803         if (!strcmp(res->what, "nbport")) {
3804                 set_fwd_ports_number(res->value);
3805                 fwd_config_setup();
3806         } else if (!strcmp(res->what, "nbcore")) {
3807                 set_fwd_lcores_number(res->value);
3808                 fwd_config_setup();
3809         } else if (!strcmp(res->what, "burst"))
3810                 set_nb_pkt_per_burst(res->value);
3811         else if (!strcmp(res->what, "verbose"))
3812                 set_verbose_level(res->value);
3813 }
3814
3815 cmdline_parse_token_string_t cmd_set_set =
3816         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3817 cmdline_parse_token_string_t cmd_set_what =
3818         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3819                                  "nbport#nbcore#burst#verbose");
3820 cmdline_parse_token_num_t cmd_set_value =
3821         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3822
3823 cmdline_parse_inst_t cmd_set_numbers = {
3824         .f = cmd_set_parsed,
3825         .data = NULL,
3826         .help_str = "set nbport|nbcore|burst|verbose <value>",
3827         .tokens = {
3828                 (void *)&cmd_set_set,
3829                 (void *)&cmd_set_what,
3830                 (void *)&cmd_set_value,
3831                 NULL,
3832         },
3833 };
3834
3835 /* *** SET LOG LEVEL CONFIGURATION *** */
3836
3837 struct cmd_set_log_result {
3838         cmdline_fixed_string_t set;
3839         cmdline_fixed_string_t log;
3840         cmdline_fixed_string_t type;
3841         uint32_t level;
3842 };
3843
3844 static void
3845 cmd_set_log_parsed(void *parsed_result,
3846                    __rte_unused struct cmdline *cl,
3847                    __rte_unused void *data)
3848 {
3849         struct cmd_set_log_result *res;
3850         int ret;
3851
3852         res = parsed_result;
3853         if (!strcmp(res->type, "global"))
3854                 rte_log_set_global_level(res->level);
3855         else {
3856                 ret = rte_log_set_level_regexp(res->type, res->level);
3857                 if (ret < 0)
3858                         fprintf(stderr, "Unable to set log level\n");
3859         }
3860 }
3861
3862 cmdline_parse_token_string_t cmd_set_log_set =
3863         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3864 cmdline_parse_token_string_t cmd_set_log_log =
3865         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3866 cmdline_parse_token_string_t cmd_set_log_type =
3867         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3868 cmdline_parse_token_num_t cmd_set_log_level =
3869         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3870
3871 cmdline_parse_inst_t cmd_set_log = {
3872         .f = cmd_set_log_parsed,
3873         .data = NULL,
3874         .help_str = "set log global|<type> <level>",
3875         .tokens = {
3876                 (void *)&cmd_set_log_set,
3877                 (void *)&cmd_set_log_log,
3878                 (void *)&cmd_set_log_type,
3879                 (void *)&cmd_set_log_level,
3880                 NULL,
3881         },
3882 };
3883
3884 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3885
3886 struct cmd_set_rxoffs_result {
3887         cmdline_fixed_string_t cmd_keyword;
3888         cmdline_fixed_string_t rxoffs;
3889         cmdline_fixed_string_t seg_offsets;
3890 };
3891
3892 static void
3893 cmd_set_rxoffs_parsed(void *parsed_result,
3894                       __rte_unused struct cmdline *cl,
3895                       __rte_unused void *data)
3896 {
3897         struct cmd_set_rxoffs_result *res;
3898         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3899         unsigned int nb_segs;
3900
3901         res = parsed_result;
3902         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3903                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3904         if (nb_segs > 0)
3905                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3906         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3907 }
3908
3909 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3910         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3911                                  cmd_keyword, "set");
3912 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3913         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3914                                  rxoffs, "rxoffs");
3915 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3916         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3917                                  seg_offsets, NULL);
3918
3919 cmdline_parse_inst_t cmd_set_rxoffs = {
3920         .f = cmd_set_rxoffs_parsed,
3921         .data = NULL,
3922         .help_str = "set rxoffs <len0[,len1]*>",
3923         .tokens = {
3924                 (void *)&cmd_set_rxoffs_keyword,
3925                 (void *)&cmd_set_rxoffs_name,
3926                 (void *)&cmd_set_rxoffs_offsets,
3927                 NULL,
3928         },
3929 };
3930
3931 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3932
3933 struct cmd_set_rxpkts_result {
3934         cmdline_fixed_string_t cmd_keyword;
3935         cmdline_fixed_string_t rxpkts;
3936         cmdline_fixed_string_t seg_lengths;
3937 };
3938
3939 static void
3940 cmd_set_rxpkts_parsed(void *parsed_result,
3941                       __rte_unused struct cmdline *cl,
3942                       __rte_unused void *data)
3943 {
3944         struct cmd_set_rxpkts_result *res;
3945         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3946         unsigned int nb_segs;
3947
3948         res = parsed_result;
3949         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3950                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3951         if (nb_segs > 0)
3952                 set_rx_pkt_segments(seg_lengths, nb_segs);
3953         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3954 }
3955
3956 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3957         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3958                                  cmd_keyword, "set");
3959 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3960         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3961                                  rxpkts, "rxpkts");
3962 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3963         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3964                                  seg_lengths, NULL);
3965
3966 cmdline_parse_inst_t cmd_set_rxpkts = {
3967         .f = cmd_set_rxpkts_parsed,
3968         .data = NULL,
3969         .help_str = "set rxpkts <len0[,len1]*>",
3970         .tokens = {
3971                 (void *)&cmd_set_rxpkts_keyword,
3972                 (void *)&cmd_set_rxpkts_name,
3973                 (void *)&cmd_set_rxpkts_lengths,
3974                 NULL,
3975         },
3976 };
3977
3978 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3979
3980 struct cmd_set_txpkts_result {
3981         cmdline_fixed_string_t cmd_keyword;
3982         cmdline_fixed_string_t txpkts;
3983         cmdline_fixed_string_t seg_lengths;
3984 };
3985
3986 static void
3987 cmd_set_txpkts_parsed(void *parsed_result,
3988                       __rte_unused struct cmdline *cl,
3989                       __rte_unused void *data)
3990 {
3991         struct cmd_set_txpkts_result *res;
3992         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3993         unsigned int nb_segs;
3994
3995         res = parsed_result;
3996         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3997                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3998         if (nb_segs > 0)
3999                 set_tx_pkt_segments(seg_lengths, nb_segs);
4000 }
4001
4002 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4003         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4004                                  cmd_keyword, "set");
4005 cmdline_parse_token_string_t cmd_set_txpkts_name =
4006         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4007                                  txpkts, "txpkts");
4008 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4009         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4010                                  seg_lengths, NULL);
4011
4012 cmdline_parse_inst_t cmd_set_txpkts = {
4013         .f = cmd_set_txpkts_parsed,
4014         .data = NULL,
4015         .help_str = "set txpkts <len0[,len1]*>",
4016         .tokens = {
4017                 (void *)&cmd_set_txpkts_keyword,
4018                 (void *)&cmd_set_txpkts_name,
4019                 (void *)&cmd_set_txpkts_lengths,
4020                 NULL,
4021         },
4022 };
4023
4024 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4025
4026 struct cmd_set_txsplit_result {
4027         cmdline_fixed_string_t cmd_keyword;
4028         cmdline_fixed_string_t txsplit;
4029         cmdline_fixed_string_t mode;
4030 };
4031
4032 static void
4033 cmd_set_txsplit_parsed(void *parsed_result,
4034                       __rte_unused struct cmdline *cl,
4035                       __rte_unused void *data)
4036 {
4037         struct cmd_set_txsplit_result *res;
4038
4039         res = parsed_result;
4040         set_tx_pkt_split(res->mode);
4041 }
4042
4043 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4044         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4045                                  cmd_keyword, "set");
4046 cmdline_parse_token_string_t cmd_set_txsplit_name =
4047         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4048                                  txsplit, "txsplit");
4049 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4050         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4051                                  mode, NULL);
4052
4053 cmdline_parse_inst_t cmd_set_txsplit = {
4054         .f = cmd_set_txsplit_parsed,
4055         .data = NULL,
4056         .help_str = "set txsplit on|off|rand",
4057         .tokens = {
4058                 (void *)&cmd_set_txsplit_keyword,
4059                 (void *)&cmd_set_txsplit_name,
4060                 (void *)&cmd_set_txsplit_mode,
4061                 NULL,
4062         },
4063 };
4064
4065 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4066
4067 struct cmd_set_txtimes_result {
4068         cmdline_fixed_string_t cmd_keyword;
4069         cmdline_fixed_string_t txtimes;
4070         cmdline_fixed_string_t tx_times;
4071 };
4072
4073 static void
4074 cmd_set_txtimes_parsed(void *parsed_result,
4075                        __rte_unused struct cmdline *cl,
4076                        __rte_unused void *data)
4077 {
4078         struct cmd_set_txtimes_result *res;
4079         unsigned int tx_times[2] = {0, 0};
4080         unsigned int n_times;
4081
4082         res = parsed_result;
4083         n_times = parse_item_list(res->tx_times, "tx times",
4084                                   2, tx_times, 0);
4085         if (n_times == 2)
4086                 set_tx_pkt_times(tx_times);
4087 }
4088
4089 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4090         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4091                                  cmd_keyword, "set");
4092 cmdline_parse_token_string_t cmd_set_txtimes_name =
4093         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4094                                  txtimes, "txtimes");
4095 cmdline_parse_token_string_t cmd_set_txtimes_value =
4096         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4097                                  tx_times, NULL);
4098
4099 cmdline_parse_inst_t cmd_set_txtimes = {
4100         .f = cmd_set_txtimes_parsed,
4101         .data = NULL,
4102         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4103         .tokens = {
4104                 (void *)&cmd_set_txtimes_keyword,
4105                 (void *)&cmd_set_txtimes_name,
4106                 (void *)&cmd_set_txtimes_value,
4107                 NULL,
4108         },
4109 };
4110
4111 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4112 struct cmd_rx_vlan_filter_all_result {
4113         cmdline_fixed_string_t rx_vlan;
4114         cmdline_fixed_string_t what;
4115         cmdline_fixed_string_t all;
4116         portid_t port_id;
4117 };
4118
4119 static void
4120 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4121                               __rte_unused struct cmdline *cl,
4122                               __rte_unused void *data)
4123 {
4124         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4125
4126         if (!strcmp(res->what, "add"))
4127                 rx_vlan_all_filter_set(res->port_id, 1);
4128         else
4129                 rx_vlan_all_filter_set(res->port_id, 0);
4130 }
4131
4132 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4133         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4134                                  rx_vlan, "rx_vlan");
4135 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4136         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4137                                  what, "add#rm");
4138 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4139         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4140                                  all, "all");
4141 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4142         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4143                               port_id, RTE_UINT16);
4144
4145 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4146         .f = cmd_rx_vlan_filter_all_parsed,
4147         .data = NULL,
4148         .help_str = "rx_vlan add|rm all <port_id>: "
4149                 "Add/Remove all identifiers to/from the set of VLAN "
4150                 "identifiers filtered by a port",
4151         .tokens = {
4152                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4153                 (void *)&cmd_rx_vlan_filter_all_what,
4154                 (void *)&cmd_rx_vlan_filter_all_all,
4155                 (void *)&cmd_rx_vlan_filter_all_portid,
4156                 NULL,
4157         },
4158 };
4159
4160 /* *** VLAN OFFLOAD SET ON A PORT *** */
4161 struct cmd_vlan_offload_result {
4162         cmdline_fixed_string_t vlan;
4163         cmdline_fixed_string_t set;
4164         cmdline_fixed_string_t vlan_type;
4165         cmdline_fixed_string_t what;
4166         cmdline_fixed_string_t on;
4167         cmdline_fixed_string_t port_id;
4168 };
4169
4170 static void
4171 cmd_vlan_offload_parsed(void *parsed_result,
4172                           __rte_unused struct cmdline *cl,
4173                           __rte_unused void *data)
4174 {
4175         int on;
4176         struct cmd_vlan_offload_result *res = parsed_result;
4177         char *str;
4178         int i, len = 0;
4179         portid_t port_id = 0;
4180         unsigned int tmp;
4181
4182         str = res->port_id;
4183         len = strnlen(str, STR_TOKEN_SIZE);
4184         i = 0;
4185         /* Get port_id first */
4186         while(i < len){
4187                 if(str[i] == ',')
4188                         break;
4189
4190                 i++;
4191         }
4192         str[i]='\0';
4193         tmp = strtoul(str, NULL, 0);
4194         /* If port_id greater that what portid_t can represent, return */
4195         if(tmp >= RTE_MAX_ETHPORTS)
4196                 return;
4197         port_id = (portid_t)tmp;
4198
4199         if (!strcmp(res->on, "on"))
4200                 on = 1;
4201         else
4202                 on = 0;
4203
4204         if (!strcmp(res->what, "strip"))
4205                 rx_vlan_strip_set(port_id,  on);
4206         else if(!strcmp(res->what, "stripq")){
4207                 uint16_t queue_id = 0;
4208
4209                 /* No queue_id, return */
4210                 if(i + 1 >= len) {
4211                         fprintf(stderr, "must specify (port,queue_id)\n");
4212                         return;
4213                 }
4214                 tmp = strtoul(str + i + 1, NULL, 0);
4215                 /* If queue_id greater that what 16-bits can represent, return */
4216                 if(tmp > 0xffff)
4217                         return;
4218
4219                 queue_id = (uint16_t)tmp;
4220                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4221         }
4222         else if (!strcmp(res->what, "filter"))
4223                 rx_vlan_filter_set(port_id, on);
4224         else if (!strcmp(res->what, "qinq_strip"))
4225                 rx_vlan_qinq_strip_set(port_id, on);
4226         else
4227                 vlan_extend_set(port_id, on);
4228
4229         return;
4230 }
4231
4232 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4233         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4234                                  vlan, "vlan");
4235 cmdline_parse_token_string_t cmd_vlan_offload_set =
4236         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4237                                  set, "set");
4238 cmdline_parse_token_string_t cmd_vlan_offload_what =
4239         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4240                                 what, "strip#filter#qinq_strip#extend#stripq");
4241 cmdline_parse_token_string_t cmd_vlan_offload_on =
4242         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4243                               on, "on#off");
4244 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4245         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4246                               port_id, NULL);
4247
4248 cmdline_parse_inst_t cmd_vlan_offload = {
4249         .f = cmd_vlan_offload_parsed,
4250         .data = NULL,
4251         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4252                 "<port_id[,queue_id]>: "
4253                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4254         .tokens = {
4255                 (void *)&cmd_vlan_offload_vlan,
4256                 (void *)&cmd_vlan_offload_set,
4257                 (void *)&cmd_vlan_offload_what,
4258                 (void *)&cmd_vlan_offload_on,
4259                 (void *)&cmd_vlan_offload_portid,
4260                 NULL,
4261         },
4262 };
4263
4264 /* *** VLAN TPID SET ON A PORT *** */
4265 struct cmd_vlan_tpid_result {
4266         cmdline_fixed_string_t vlan;
4267         cmdline_fixed_string_t set;
4268         cmdline_fixed_string_t vlan_type;
4269         cmdline_fixed_string_t what;
4270         uint16_t tp_id;
4271         portid_t port_id;
4272 };
4273
4274 static void
4275 cmd_vlan_tpid_parsed(void *parsed_result,
4276                           __rte_unused struct cmdline *cl,
4277                           __rte_unused void *data)
4278 {
4279         struct cmd_vlan_tpid_result *res = parsed_result;
4280         enum rte_vlan_type vlan_type;
4281
4282         if (!strcmp(res->vlan_type, "inner"))
4283                 vlan_type = ETH_VLAN_TYPE_INNER;
4284         else if (!strcmp(res->vlan_type, "outer"))
4285                 vlan_type = ETH_VLAN_TYPE_OUTER;
4286         else {
4287                 fprintf(stderr, "Unknown vlan type\n");
4288                 return;
4289         }
4290         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4291 }
4292
4293 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4294         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4295                                  vlan, "vlan");
4296 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4297         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4298                                  set, "set");
4299 cmdline_parse_token_string_t cmd_vlan_type =
4300         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4301                                  vlan_type, "inner#outer");
4302 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4303         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4304                                  what, "tpid");
4305 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4306         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4307                               tp_id, RTE_UINT16);
4308 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4309         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4310                               port_id, RTE_UINT16);
4311
4312 cmdline_parse_inst_t cmd_vlan_tpid = {
4313         .f = cmd_vlan_tpid_parsed,
4314         .data = NULL,
4315         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4316                 "Set the VLAN Ether type",
4317         .tokens = {
4318                 (void *)&cmd_vlan_tpid_vlan,
4319                 (void *)&cmd_vlan_tpid_set,
4320                 (void *)&cmd_vlan_type,
4321                 (void *)&cmd_vlan_tpid_what,
4322                 (void *)&cmd_vlan_tpid_tpid,
4323                 (void *)&cmd_vlan_tpid_portid,
4324                 NULL,
4325         },
4326 };
4327
4328 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4329 struct cmd_rx_vlan_filter_result {
4330         cmdline_fixed_string_t rx_vlan;
4331         cmdline_fixed_string_t what;
4332         uint16_t vlan_id;
4333         portid_t port_id;
4334 };
4335
4336 static void
4337 cmd_rx_vlan_filter_parsed(void *parsed_result,
4338                           __rte_unused struct cmdline *cl,
4339                           __rte_unused void *data)
4340 {
4341         struct cmd_rx_vlan_filter_result *res = parsed_result;
4342
4343         if (!strcmp(res->what, "add"))
4344                 rx_vft_set(res->port_id, res->vlan_id, 1);
4345         else
4346                 rx_vft_set(res->port_id, res->vlan_id, 0);
4347 }
4348
4349 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4350         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4351                                  rx_vlan, "rx_vlan");
4352 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4353         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4354                                  what, "add#rm");
4355 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4356         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4357                               vlan_id, RTE_UINT16);
4358 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4359         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4360                               port_id, RTE_UINT16);
4361
4362 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4363         .f = cmd_rx_vlan_filter_parsed,
4364         .data = NULL,
4365         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4366                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4367                 "identifiers filtered by a port",
4368         .tokens = {
4369                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4370                 (void *)&cmd_rx_vlan_filter_what,
4371                 (void *)&cmd_rx_vlan_filter_vlanid,
4372                 (void *)&cmd_rx_vlan_filter_portid,
4373                 NULL,
4374         },
4375 };
4376
4377 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4378 struct cmd_tx_vlan_set_result {
4379         cmdline_fixed_string_t tx_vlan;
4380         cmdline_fixed_string_t set;
4381         portid_t port_id;
4382         uint16_t vlan_id;
4383 };
4384
4385 static void
4386 cmd_tx_vlan_set_parsed(void *parsed_result,
4387                        __rte_unused struct cmdline *cl,
4388                        __rte_unused void *data)
4389 {
4390         struct cmd_tx_vlan_set_result *res = parsed_result;
4391
4392         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4393                 return;
4394
4395         if (!port_is_stopped(res->port_id)) {
4396                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4397                 return;
4398         }
4399
4400         tx_vlan_set(res->port_id, res->vlan_id);
4401
4402         cmd_reconfig_device_queue(res->port_id, 1, 1);
4403 }
4404
4405 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4406         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4407                                  tx_vlan, "tx_vlan");
4408 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4409         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4410                                  set, "set");
4411 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4412         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4413                               port_id, RTE_UINT16);
4414 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4415         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4416                               vlan_id, RTE_UINT16);
4417
4418 cmdline_parse_inst_t cmd_tx_vlan_set = {
4419         .f = cmd_tx_vlan_set_parsed,
4420         .data = NULL,
4421         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4422                 "Enable hardware insertion of a single VLAN header "
4423                 "with a given TAG Identifier in packets sent on a port",
4424         .tokens = {
4425                 (void *)&cmd_tx_vlan_set_tx_vlan,
4426                 (void *)&cmd_tx_vlan_set_set,
4427                 (void *)&cmd_tx_vlan_set_portid,
4428                 (void *)&cmd_tx_vlan_set_vlanid,
4429                 NULL,
4430         },
4431 };
4432
4433 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4434 struct cmd_tx_vlan_set_qinq_result {
4435         cmdline_fixed_string_t tx_vlan;
4436         cmdline_fixed_string_t set;
4437         portid_t port_id;
4438         uint16_t vlan_id;
4439         uint16_t vlan_id_outer;
4440 };
4441
4442 static void
4443 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4444                             __rte_unused struct cmdline *cl,
4445                             __rte_unused void *data)
4446 {
4447         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4448
4449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4450                 return;
4451
4452         if (!port_is_stopped(res->port_id)) {
4453                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4454                 return;
4455         }
4456
4457         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4458
4459         cmd_reconfig_device_queue(res->port_id, 1, 1);
4460 }
4461
4462 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4463         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4464                 tx_vlan, "tx_vlan");
4465 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4466         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4467                 set, "set");
4468 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4469         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4470                 port_id, RTE_UINT16);
4471 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4472         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4473                 vlan_id, RTE_UINT16);
4474 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4475         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4476                 vlan_id_outer, RTE_UINT16);
4477
4478 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4479         .f = cmd_tx_vlan_set_qinq_parsed,
4480         .data = NULL,
4481         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4482                 "Enable hardware insertion of double VLAN header "
4483                 "with given TAG Identifiers in packets sent on a port",
4484         .tokens = {
4485                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4486                 (void *)&cmd_tx_vlan_set_qinq_set,
4487                 (void *)&cmd_tx_vlan_set_qinq_portid,
4488                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4489                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4490                 NULL,
4491         },
4492 };
4493
4494 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4495 struct cmd_tx_vlan_set_pvid_result {
4496         cmdline_fixed_string_t tx_vlan;
4497         cmdline_fixed_string_t set;
4498         cmdline_fixed_string_t pvid;
4499         portid_t port_id;
4500         uint16_t vlan_id;
4501         cmdline_fixed_string_t mode;
4502 };
4503
4504 static void
4505 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4506                             __rte_unused struct cmdline *cl,
4507                             __rte_unused void *data)
4508 {
4509         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4510
4511         if (strcmp(res->mode, "on") == 0)
4512                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4513         else
4514                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4515 }
4516
4517 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4518         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4519                                  tx_vlan, "tx_vlan");
4520 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4521         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4522                                  set, "set");
4523 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4524         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4525                                  pvid, "pvid");
4526 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4527         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4528                              port_id, RTE_UINT16);
4529 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4530         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4531                               vlan_id, RTE_UINT16);
4532 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4533         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4534                                  mode, "on#off");
4535
4536 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4537         .f = cmd_tx_vlan_set_pvid_parsed,
4538         .data = NULL,
4539         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4540         .tokens = {
4541                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4542                 (void *)&cmd_tx_vlan_set_pvid_set,
4543                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4544                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4545                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4546                 (void *)&cmd_tx_vlan_set_pvid_mode,
4547                 NULL,
4548         },
4549 };
4550
4551 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4552 struct cmd_tx_vlan_reset_result {
4553         cmdline_fixed_string_t tx_vlan;
4554         cmdline_fixed_string_t reset;
4555         portid_t port_id;
4556 };
4557
4558 static void
4559 cmd_tx_vlan_reset_parsed(void *parsed_result,
4560                          __rte_unused struct cmdline *cl,
4561                          __rte_unused void *data)
4562 {
4563         struct cmd_tx_vlan_reset_result *res = parsed_result;
4564
4565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4566                 return;
4567
4568         if (!port_is_stopped(res->port_id)) {
4569                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4570                 return;
4571         }
4572
4573         tx_vlan_reset(res->port_id);
4574
4575         cmd_reconfig_device_queue(res->port_id, 1, 1);
4576 }
4577
4578 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4579         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4580                                  tx_vlan, "tx_vlan");
4581 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4582         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4583                                  reset, "reset");
4584 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4585         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4586                               port_id, RTE_UINT16);
4587
4588 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4589         .f = cmd_tx_vlan_reset_parsed,
4590         .data = NULL,
4591         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4592                 "VLAN header in packets sent on a port",
4593         .tokens = {
4594                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4595                 (void *)&cmd_tx_vlan_reset_reset,
4596                 (void *)&cmd_tx_vlan_reset_portid,
4597                 NULL,
4598         },
4599 };
4600
4601
4602 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4603 struct cmd_csum_result {
4604         cmdline_fixed_string_t csum;
4605         cmdline_fixed_string_t mode;
4606         cmdline_fixed_string_t proto;
4607         cmdline_fixed_string_t hwsw;
4608         portid_t port_id;
4609 };
4610
4611 static void
4612 csum_show(int port_id)
4613 {
4614         struct rte_eth_dev_info dev_info;
4615         uint64_t tx_offloads;
4616         int ret;
4617
4618         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4619         printf("Parse tunnel is %s\n",
4620                 (ports[port_id].parse_tunnel) ? "on" : "off");
4621         printf("IP checksum offload is %s\n",
4622                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4623         printf("UDP checksum offload is %s\n",
4624                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4625         printf("TCP checksum offload is %s\n",
4626                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4627         printf("SCTP checksum offload is %s\n",
4628                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4629         printf("Outer-Ip checksum offload is %s\n",
4630                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4631         printf("Outer-Udp checksum offload is %s\n",
4632                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4633
4634         /* display warnings if configuration is not supported by the NIC */
4635         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4636         if (ret != 0)
4637                 return;
4638
4639         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4640                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4641                 fprintf(stderr,
4642                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4643                         port_id);
4644         }
4645         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4646                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4647                 fprintf(stderr,
4648                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4649                         port_id);
4650         }
4651         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4652                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4653                 fprintf(stderr,
4654                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4655                         port_id);
4656         }
4657         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4658                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4659                 fprintf(stderr,
4660                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4661                         port_id);
4662         }
4663         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4664                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4665                 fprintf(stderr,
4666                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4667                         port_id);
4668         }
4669         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4670                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4671                         == 0) {
4672                 fprintf(stderr,
4673                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4674                         port_id);
4675         }
4676 }
4677
4678 static void
4679 cmd_config_queue_tx_offloads(struct rte_port *port)
4680 {
4681         int k;
4682
4683         /* Apply queue tx offloads configuration */
4684         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4685                 port->tx_conf[k].offloads =
4686                         port->dev_conf.txmode.offloads;
4687 }
4688
4689 static void
4690 cmd_csum_parsed(void *parsed_result,
4691                        __rte_unused struct cmdline *cl,
4692                        __rte_unused void *data)
4693 {
4694         struct cmd_csum_result *res = parsed_result;
4695         int hw = 0;
4696         uint64_t csum_offloads = 0;
4697         struct rte_eth_dev_info dev_info;
4698         int ret;
4699
4700         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4701                 fprintf(stderr, "invalid port %d\n", res->port_id);
4702                 return;
4703         }
4704         if (!port_is_stopped(res->port_id)) {
4705                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4706                 return;
4707         }
4708
4709         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4710         if (ret != 0)
4711                 return;
4712
4713         if (!strcmp(res->mode, "set")) {
4714
4715                 if (!strcmp(res->hwsw, "hw"))
4716                         hw = 1;
4717
4718                 if (!strcmp(res->proto, "ip")) {
4719                         if (hw == 0 || (dev_info.tx_offload_capa &
4720                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4721                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4722                         } else {
4723                                 fprintf(stderr,
4724                                         "IP checksum offload is not supported by port %u\n",
4725                                         res->port_id);
4726                         }
4727                 } else if (!strcmp(res->proto, "udp")) {
4728                         if (hw == 0 || (dev_info.tx_offload_capa &
4729                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4730                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4731                         } else {
4732                                 fprintf(stderr,
4733                                         "UDP checksum offload is not supported by port %u\n",
4734                                         res->port_id);
4735                         }
4736                 } else if (!strcmp(res->proto, "tcp")) {
4737                         if (hw == 0 || (dev_info.tx_offload_capa &
4738                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4739                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4740                         } else {
4741                                 fprintf(stderr,
4742                                         "TCP checksum offload is not supported by port %u\n",
4743                                         res->port_id);
4744                         }
4745                 } else if (!strcmp(res->proto, "sctp")) {
4746                         if (hw == 0 || (dev_info.tx_offload_capa &
4747                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4748                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4749                         } else {
4750                                 fprintf(stderr,
4751                                         "SCTP checksum offload is not supported by port %u\n",
4752                                         res->port_id);
4753                         }
4754                 } else if (!strcmp(res->proto, "outer-ip")) {
4755                         if (hw == 0 || (dev_info.tx_offload_capa &
4756                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4757                                 csum_offloads |=
4758                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4759                         } else {
4760                                 fprintf(stderr,
4761                                         "Outer IP checksum offload is not supported by port %u\n",
4762                                         res->port_id);
4763                         }
4764                 } else if (!strcmp(res->proto, "outer-udp")) {
4765                         if (hw == 0 || (dev_info.tx_offload_capa &
4766                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4767                                 csum_offloads |=
4768                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4769                         } else {
4770                                 fprintf(stderr,
4771                                         "Outer UDP checksum offload is not supported by port %u\n",
4772                                         res->port_id);
4773                         }
4774                 }
4775
4776                 if (hw) {
4777                         ports[res->port_id].dev_conf.txmode.offloads |=
4778                                                         csum_offloads;
4779                 } else {
4780                         ports[res->port_id].dev_conf.txmode.offloads &=
4781                                                         (~csum_offloads);
4782                 }
4783                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4784         }
4785         csum_show(res->port_id);
4786
4787         cmd_reconfig_device_queue(res->port_id, 1, 1);
4788 }
4789
4790 cmdline_parse_token_string_t cmd_csum_csum =
4791         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4792                                 csum, "csum");
4793 cmdline_parse_token_string_t cmd_csum_mode =
4794         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4795                                 mode, "set");
4796 cmdline_parse_token_string_t cmd_csum_proto =
4797         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4798                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4799 cmdline_parse_token_string_t cmd_csum_hwsw =
4800         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4801                                 hwsw, "hw#sw");
4802 cmdline_parse_token_num_t cmd_csum_portid =
4803         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4804                                 port_id, RTE_UINT16);
4805
4806 cmdline_parse_inst_t cmd_csum_set = {
4807         .f = cmd_csum_parsed,
4808         .data = NULL,
4809         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4810                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4811                 "using csum forward engine",
4812         .tokens = {
4813                 (void *)&cmd_csum_csum,
4814                 (void *)&cmd_csum_mode,
4815                 (void *)&cmd_csum_proto,
4816                 (void *)&cmd_csum_hwsw,
4817                 (void *)&cmd_csum_portid,
4818                 NULL,
4819         },
4820 };
4821
4822 cmdline_parse_token_string_t cmd_csum_mode_show =
4823         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4824                                 mode, "show");
4825
4826 cmdline_parse_inst_t cmd_csum_show = {
4827         .f = cmd_csum_parsed,
4828         .data = NULL,
4829         .help_str = "csum show <port_id>: Show checksum offload configuration",
4830         .tokens = {
4831                 (void *)&cmd_csum_csum,
4832                 (void *)&cmd_csum_mode_show,
4833                 (void *)&cmd_csum_portid,
4834                 NULL,
4835         },
4836 };
4837
4838 /* Enable/disable tunnel parsing */
4839 struct cmd_csum_tunnel_result {
4840         cmdline_fixed_string_t csum;
4841         cmdline_fixed_string_t parse;
4842         cmdline_fixed_string_t onoff;
4843         portid_t port_id;
4844 };
4845
4846 static void
4847 cmd_csum_tunnel_parsed(void *parsed_result,
4848                        __rte_unused struct cmdline *cl,
4849                        __rte_unused void *data)
4850 {
4851         struct cmd_csum_tunnel_result *res = parsed_result;
4852
4853         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4854                 return;
4855
4856         if (!strcmp(res->onoff, "on"))
4857                 ports[res->port_id].parse_tunnel = 1;
4858         else
4859                 ports[res->port_id].parse_tunnel = 0;
4860
4861         csum_show(res->port_id);
4862 }
4863
4864 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4865         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4866                                 csum, "csum");
4867 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4868         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4869                                 parse, "parse-tunnel");
4870 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4871         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4872                                 onoff, "on#off");
4873 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4874         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4875                                 port_id, RTE_UINT16);
4876
4877 cmdline_parse_inst_t cmd_csum_tunnel = {
4878         .f = cmd_csum_tunnel_parsed,
4879         .data = NULL,
4880         .help_str = "csum parse-tunnel on|off <port_id>: "
4881                 "Enable/Disable parsing of tunnels for csum engine",
4882         .tokens = {
4883                 (void *)&cmd_csum_tunnel_csum,
4884                 (void *)&cmd_csum_tunnel_parse,
4885                 (void *)&cmd_csum_tunnel_onoff,
4886                 (void *)&cmd_csum_tunnel_portid,
4887                 NULL,
4888         },
4889 };
4890
4891 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4892 struct cmd_tso_set_result {
4893         cmdline_fixed_string_t tso;
4894         cmdline_fixed_string_t mode;
4895         uint16_t tso_segsz;
4896         portid_t port_id;
4897 };
4898
4899 static void
4900 cmd_tso_set_parsed(void *parsed_result,
4901                        __rte_unused struct cmdline *cl,
4902                        __rte_unused void *data)
4903 {
4904         struct cmd_tso_set_result *res = parsed_result;
4905         struct rte_eth_dev_info dev_info;
4906         int ret;
4907
4908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4909                 return;
4910         if (!port_is_stopped(res->port_id)) {
4911                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4912                 return;
4913         }
4914
4915         if (!strcmp(res->mode, "set"))
4916                 ports[res->port_id].tso_segsz = res->tso_segsz;
4917
4918         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4919         if (ret != 0)
4920                 return;
4921
4922         if ((ports[res->port_id].tso_segsz != 0) &&
4923                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4924                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4925                         res->port_id);
4926                 return;
4927         }
4928
4929         if (ports[res->port_id].tso_segsz == 0) {
4930                 ports[res->port_id].dev_conf.txmode.offloads &=
4931                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4932                 printf("TSO for non-tunneled packets is disabled\n");
4933         } else {
4934                 ports[res->port_id].dev_conf.txmode.offloads |=
4935                                                 DEV_TX_OFFLOAD_TCP_TSO;
4936                 printf("TSO segment size for non-tunneled packets is %d\n",
4937                         ports[res->port_id].tso_segsz);
4938         }
4939         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4940
4941         /* display warnings if configuration is not supported by the NIC */
4942         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4943         if (ret != 0)
4944                 return;
4945
4946         if ((ports[res->port_id].tso_segsz != 0) &&
4947                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4948                 fprintf(stderr,
4949                         "Warning: TSO enabled but not supported by port %d\n",
4950                         res->port_id);
4951         }
4952
4953         cmd_reconfig_device_queue(res->port_id, 1, 1);
4954 }
4955
4956 cmdline_parse_token_string_t cmd_tso_set_tso =
4957         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4958                                 tso, "tso");
4959 cmdline_parse_token_string_t cmd_tso_set_mode =
4960         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4961                                 mode, "set");
4962 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4963         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4964                                 tso_segsz, RTE_UINT16);
4965 cmdline_parse_token_num_t cmd_tso_set_portid =
4966         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4967                                 port_id, RTE_UINT16);
4968
4969 cmdline_parse_inst_t cmd_tso_set = {
4970         .f = cmd_tso_set_parsed,
4971         .data = NULL,
4972         .help_str = "tso set <tso_segsz> <port_id>: "
4973                 "Set TSO segment size of non-tunneled packets for csum engine "
4974                 "(0 to disable)",
4975         .tokens = {
4976                 (void *)&cmd_tso_set_tso,
4977                 (void *)&cmd_tso_set_mode,
4978                 (void *)&cmd_tso_set_tso_segsz,
4979                 (void *)&cmd_tso_set_portid,
4980                 NULL,
4981         },
4982 };
4983
4984 cmdline_parse_token_string_t cmd_tso_show_mode =
4985         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4986                                 mode, "show");
4987
4988
4989 cmdline_parse_inst_t cmd_tso_show = {
4990         .f = cmd_tso_set_parsed,
4991         .data = NULL,
4992         .help_str = "tso show <port_id>: "
4993                 "Show TSO segment size of non-tunneled packets for csum engine",
4994         .tokens = {
4995                 (void *)&cmd_tso_set_tso,
4996                 (void *)&cmd_tso_show_mode,
4997                 (void *)&cmd_tso_set_portid,
4998                 NULL,
4999         },
5000 };
5001
5002 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5003 struct cmd_tunnel_tso_set_result {
5004         cmdline_fixed_string_t tso;
5005         cmdline_fixed_string_t mode;
5006         uint16_t tso_segsz;
5007         portid_t port_id;
5008 };
5009
5010 static struct rte_eth_dev_info
5011 check_tunnel_tso_nic_support(portid_t port_id)
5012 {
5013         struct rte_eth_dev_info dev_info;
5014
5015         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5016                 return dev_info;
5017
5018         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5019                 fprintf(stderr,
5020                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5021                         port_id);
5022         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5023                 fprintf(stderr,
5024                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5025                         port_id);
5026         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5027                 fprintf(stderr,
5028                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5029                         port_id);
5030         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5031                 fprintf(stderr,
5032                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5033                         port_id);
5034         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5035                 fprintf(stderr,
5036                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5037                         port_id);
5038         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5039                 fprintf(stderr,
5040                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5041                         port_id);
5042         return dev_info;
5043 }
5044
5045 static void
5046 cmd_tunnel_tso_set_parsed(void *parsed_result,
5047                           __rte_unused struct cmdline *cl,
5048                           __rte_unused void *data)
5049 {
5050         struct cmd_tunnel_tso_set_result *res = parsed_result;
5051         struct rte_eth_dev_info dev_info;
5052
5053         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5054                 return;
5055         if (!port_is_stopped(res->port_id)) {
5056                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5057                 return;
5058         }
5059
5060         if (!strcmp(res->mode, "set"))
5061                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5062
5063         dev_info = check_tunnel_tso_nic_support(res->port_id);
5064         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5065                 ports[res->port_id].dev_conf.txmode.offloads &=
5066                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5067                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5068                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5069                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5070                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5071                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5072                 printf("TSO for tunneled packets is disabled\n");
5073         } else {
5074                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5075                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5076                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5077                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5078                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5079                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5080
5081                 ports[res->port_id].dev_conf.txmode.offloads |=
5082                         (tso_offloads & dev_info.tx_offload_capa);
5083                 printf("TSO segment size for tunneled packets is %d\n",
5084                         ports[res->port_id].tunnel_tso_segsz);
5085
5086                 /* Below conditions are needed to make it work:
5087                  * (1) tunnel TSO is supported by the NIC;
5088                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5089                  * are recognized;
5090                  * (3) for tunneled pkts with outer L3 of IPv4,
5091                  * "csum set outer-ip" must be set to hw, because after tso,
5092                  * total_len of outer IP header is changed, and the checksum
5093                  * of outer IP header calculated by sw should be wrong; that
5094                  * is not necessary for IPv6 tunneled pkts because there's no
5095                  * checksum in IP header anymore.
5096                  */
5097
5098                 if (!ports[res->port_id].parse_tunnel)
5099                         fprintf(stderr,
5100                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5101                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5102                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5103                         fprintf(stderr,
5104                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5105         }
5106
5107         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5108         cmd_reconfig_device_queue(res->port_id, 1, 1);
5109 }
5110
5111 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5112         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5113                                 tso, "tunnel_tso");
5114 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5115         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5116                                 mode, "set");
5117 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5118         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5119                                 tso_segsz, RTE_UINT16);
5120 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5121         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5122                                 port_id, RTE_UINT16);
5123
5124 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5125         .f = cmd_tunnel_tso_set_parsed,
5126         .data = NULL,
5127         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5128                 "Set TSO segment size of tunneled packets for csum engine "
5129                 "(0 to disable)",
5130         .tokens = {
5131                 (void *)&cmd_tunnel_tso_set_tso,
5132                 (void *)&cmd_tunnel_tso_set_mode,
5133                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5134                 (void *)&cmd_tunnel_tso_set_portid,
5135                 NULL,
5136         },
5137 };
5138
5139 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5140         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5141                                 mode, "show");
5142
5143
5144 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5145         .f = cmd_tunnel_tso_set_parsed,
5146         .data = NULL,
5147         .help_str = "tunnel_tso show <port_id> "
5148                 "Show TSO segment size of tunneled packets for csum engine",
5149         .tokens = {
5150                 (void *)&cmd_tunnel_tso_set_tso,
5151                 (void *)&cmd_tunnel_tso_show_mode,
5152                 (void *)&cmd_tunnel_tso_set_portid,
5153                 NULL,
5154         },
5155 };
5156
5157 /* *** SET GRO FOR A PORT *** */
5158 struct cmd_gro_enable_result {
5159         cmdline_fixed_string_t cmd_set;
5160         cmdline_fixed_string_t cmd_port;
5161         cmdline_fixed_string_t cmd_keyword;
5162         cmdline_fixed_string_t cmd_onoff;
5163         portid_t cmd_pid;
5164 };
5165
5166 static void
5167 cmd_gro_enable_parsed(void *parsed_result,
5168                 __rte_unused struct cmdline *cl,
5169                 __rte_unused void *data)
5170 {
5171         struct cmd_gro_enable_result *res;
5172
5173         res = parsed_result;
5174         if (!strcmp(res->cmd_keyword, "gro"))
5175                 setup_gro(res->cmd_onoff, res->cmd_pid);
5176 }
5177
5178 cmdline_parse_token_string_t cmd_gro_enable_set =
5179         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5180                         cmd_set, "set");
5181 cmdline_parse_token_string_t cmd_gro_enable_port =
5182         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5183                         cmd_keyword, "port");
5184 cmdline_parse_token_num_t cmd_gro_enable_pid =
5185         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5186                         cmd_pid, RTE_UINT16);
5187 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5188         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5189                         cmd_keyword, "gro");
5190 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5191         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5192                         cmd_onoff, "on#off");
5193
5194 cmdline_parse_inst_t cmd_gro_enable = {
5195         .f = cmd_gro_enable_parsed,
5196         .data = NULL,
5197         .help_str = "set port <port_id> gro on|off",
5198         .tokens = {
5199                 (void *)&cmd_gro_enable_set,
5200                 (void *)&cmd_gro_enable_port,
5201                 (void *)&cmd_gro_enable_pid,
5202                 (void *)&cmd_gro_enable_keyword,
5203                 (void *)&cmd_gro_enable_onoff,
5204                 NULL,
5205         },
5206 };
5207
5208 /* *** DISPLAY GRO CONFIGURATION *** */
5209 struct cmd_gro_show_result {
5210         cmdline_fixed_string_t cmd_show;
5211         cmdline_fixed_string_t cmd_port;
5212         cmdline_fixed_string_t cmd_keyword;
5213         portid_t cmd_pid;
5214 };
5215
5216 static void
5217 cmd_gro_show_parsed(void *parsed_result,
5218                 __rte_unused struct cmdline *cl,
5219                 __rte_unused void *data)
5220 {
5221         struct cmd_gro_show_result *res;
5222
5223         res = parsed_result;
5224         if (!strcmp(res->cmd_keyword, "gro"))
5225                 show_gro(res->cmd_pid);
5226 }
5227
5228 cmdline_parse_token_string_t cmd_gro_show_show =
5229         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5230                         cmd_show, "show");
5231 cmdline_parse_token_string_t cmd_gro_show_port =
5232         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5233                         cmd_port, "port");
5234 cmdline_parse_token_num_t cmd_gro_show_pid =
5235         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5236                         cmd_pid, RTE_UINT16);
5237 cmdline_parse_token_string_t cmd_gro_show_keyword =
5238         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5239                         cmd_keyword, "gro");
5240
5241 cmdline_parse_inst_t cmd_gro_show = {
5242         .f = cmd_gro_show_parsed,
5243         .data = NULL,
5244         .help_str = "show port <port_id> gro",
5245         .tokens = {
5246                 (void *)&cmd_gro_show_show,
5247                 (void *)&cmd_gro_show_port,
5248                 (void *)&cmd_gro_show_pid,
5249                 (void *)&cmd_gro_show_keyword,
5250                 NULL,
5251         },
5252 };
5253
5254 /* *** SET FLUSH CYCLES FOR GRO *** */
5255 struct cmd_gro_flush_result {
5256         cmdline_fixed_string_t cmd_set;
5257         cmdline_fixed_string_t cmd_keyword;
5258         cmdline_fixed_string_t cmd_flush;
5259         uint8_t cmd_cycles;
5260 };
5261
5262 static void
5263 cmd_gro_flush_parsed(void *parsed_result,
5264                 __rte_unused struct cmdline *cl,
5265                 __rte_unused void *data)
5266 {
5267         struct cmd_gro_flush_result *res;
5268
5269         res = parsed_result;
5270         if ((!strcmp(res->cmd_keyword, "gro")) &&
5271                         (!strcmp(res->cmd_flush, "flush")))
5272                 setup_gro_flush_cycles(res->cmd_cycles);
5273 }
5274
5275 cmdline_parse_token_string_t cmd_gro_flush_set =
5276         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5277                         cmd_set, "set");
5278 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5279         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5280                         cmd_keyword, "gro");
5281 cmdline_parse_token_string_t cmd_gro_flush_flush =
5282         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5283                         cmd_flush, "flush");
5284 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5285         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5286                         cmd_cycles, RTE_UINT8);
5287
5288 cmdline_parse_inst_t cmd_gro_flush = {
5289         .f = cmd_gro_flush_parsed,
5290         .data = NULL,
5291         .help_str = "set gro flush <cycles>",
5292         .tokens = {
5293                 (void *)&cmd_gro_flush_set,
5294                 (void *)&cmd_gro_flush_keyword,
5295                 (void *)&cmd_gro_flush_flush,
5296                 (void *)&cmd_gro_flush_cycles,
5297                 NULL,
5298         },
5299 };
5300
5301 /* *** ENABLE/DISABLE GSO *** */
5302 struct cmd_gso_enable_result {
5303         cmdline_fixed_string_t cmd_set;
5304         cmdline_fixed_string_t cmd_port;
5305         cmdline_fixed_string_t cmd_keyword;
5306         cmdline_fixed_string_t cmd_mode;
5307         portid_t cmd_pid;
5308 };
5309
5310 static void
5311 cmd_gso_enable_parsed(void *parsed_result,
5312                 __rte_unused struct cmdline *cl,
5313                 __rte_unused void *data)
5314 {
5315         struct cmd_gso_enable_result *res;
5316
5317         res = parsed_result;
5318         if (!strcmp(res->cmd_keyword, "gso"))
5319                 setup_gso(res->cmd_mode, res->cmd_pid);
5320 }
5321
5322 cmdline_parse_token_string_t cmd_gso_enable_set =
5323         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5324                         cmd_set, "set");
5325 cmdline_parse_token_string_t cmd_gso_enable_port =
5326         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5327                         cmd_port, "port");
5328 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5329         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5330                         cmd_keyword, "gso");
5331 cmdline_parse_token_string_t cmd_gso_enable_mode =
5332         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5333                         cmd_mode, "on#off");
5334 cmdline_parse_token_num_t cmd_gso_enable_pid =
5335         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5336                         cmd_pid, RTE_UINT16);
5337
5338 cmdline_parse_inst_t cmd_gso_enable = {
5339         .f = cmd_gso_enable_parsed,
5340         .data = NULL,
5341         .help_str = "set port <port_id> gso on|off",
5342         .tokens = {
5343                 (void *)&cmd_gso_enable_set,
5344                 (void *)&cmd_gso_enable_port,
5345                 (void *)&cmd_gso_enable_pid,
5346                 (void *)&cmd_gso_enable_keyword,
5347                 (void *)&cmd_gso_enable_mode,
5348                 NULL,
5349         },
5350 };
5351
5352 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5353 struct cmd_gso_size_result {
5354         cmdline_fixed_string_t cmd_set;
5355         cmdline_fixed_string_t cmd_keyword;
5356         cmdline_fixed_string_t cmd_segsz;
5357         uint16_t cmd_size;
5358 };
5359
5360 static void
5361 cmd_gso_size_parsed(void *parsed_result,
5362                        __rte_unused struct cmdline *cl,
5363                        __rte_unused void *data)
5364 {
5365         struct cmd_gso_size_result *res = parsed_result;
5366
5367         if (test_done == 0) {
5368                 fprintf(stderr,
5369                         "Before setting GSO segsz, please first stop forwarding\n");
5370                 return;
5371         }
5372
5373         if (!strcmp(res->cmd_keyword, "gso") &&
5374                         !strcmp(res->cmd_segsz, "segsz")) {
5375                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5376                         fprintf(stderr,
5377                                 "gso_size should be larger than %zu. Please input a legal value\n",
5378                                 RTE_GSO_SEG_SIZE_MIN);
5379                 else
5380                         gso_max_segment_size = res->cmd_size;
5381         }
5382 }
5383
5384 cmdline_parse_token_string_t cmd_gso_size_set =
5385         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5386                                 cmd_set, "set");
5387 cmdline_parse_token_string_t cmd_gso_size_keyword =
5388         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5389                                 cmd_keyword, "gso");
5390 cmdline_parse_token_string_t cmd_gso_size_segsz =
5391         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5392                                 cmd_segsz, "segsz");
5393 cmdline_parse_token_num_t cmd_gso_size_size =
5394         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5395                                 cmd_size, RTE_UINT16);
5396
5397 cmdline_parse_inst_t cmd_gso_size = {
5398         .f = cmd_gso_size_parsed,
5399         .data = NULL,
5400         .help_str = "set gso segsz <length>",
5401         .tokens = {
5402                 (void *)&cmd_gso_size_set,
5403                 (void *)&cmd_gso_size_keyword,
5404                 (void *)&cmd_gso_size_segsz,
5405                 (void *)&cmd_gso_size_size,
5406                 NULL,
5407         },
5408 };
5409
5410 /* *** SHOW GSO CONFIGURATION *** */
5411 struct cmd_gso_show_result {
5412         cmdline_fixed_string_t cmd_show;
5413         cmdline_fixed_string_t cmd_port;
5414         cmdline_fixed_string_t cmd_keyword;
5415         portid_t cmd_pid;
5416 };
5417
5418 static void
5419 cmd_gso_show_parsed(void *parsed_result,
5420                        __rte_unused struct cmdline *cl,
5421                        __rte_unused void *data)
5422 {
5423         struct cmd_gso_show_result *res = parsed_result;
5424
5425         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5426                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5427                 return;
5428         }
5429         if (!strcmp(res->cmd_keyword, "gso")) {
5430                 if (gso_ports[res->cmd_pid].enable) {
5431                         printf("Max GSO'd packet size: %uB\n"
5432                                         "Supported GSO types: TCP/IPv4, "
5433                                         "UDP/IPv4, VxLAN with inner "
5434                                         "TCP/IPv4 packet, GRE with inner "
5435                                         "TCP/IPv4 packet\n",
5436                                         gso_max_segment_size);
5437                 } else
5438                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5439         }
5440 }
5441
5442 cmdline_parse_token_string_t cmd_gso_show_show =
5443 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5444                 cmd_show, "show");
5445 cmdline_parse_token_string_t cmd_gso_show_port =
5446 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5447                 cmd_port, "port");
5448 cmdline_parse_token_string_t cmd_gso_show_keyword =
5449         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5450                                 cmd_keyword, "gso");
5451 cmdline_parse_token_num_t cmd_gso_show_pid =
5452         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5453                                 cmd_pid, RTE_UINT16);
5454
5455 cmdline_parse_inst_t cmd_gso_show = {
5456         .f = cmd_gso_show_parsed,
5457         .data = NULL,
5458         .help_str = "show port <port_id> gso",
5459         .tokens = {
5460                 (void *)&cmd_gso_show_show,
5461                 (void *)&cmd_gso_show_port,
5462                 (void *)&cmd_gso_show_pid,
5463                 (void *)&cmd_gso_show_keyword,
5464                 NULL,
5465         },
5466 };
5467
5468 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5469 struct cmd_set_flush_rx {
5470         cmdline_fixed_string_t set;
5471         cmdline_fixed_string_t flush_rx;
5472         cmdline_fixed_string_t mode;
5473 };
5474
5475 static void
5476 cmd_set_flush_rx_parsed(void *parsed_result,
5477                 __rte_unused struct cmdline *cl,
5478                 __rte_unused void *data)
5479 {
5480         struct cmd_set_flush_rx *res = parsed_result;
5481
5482         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5483                 printf("multi-process doesn't support to flush Rx queues.\n");
5484                 return;
5485         }
5486
5487         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5488 }
5489
5490 cmdline_parse_token_string_t cmd_setflushrx_set =
5491         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5492                         set, "set");
5493 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5494         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5495                         flush_rx, "flush_rx");
5496 cmdline_parse_token_string_t cmd_setflushrx_mode =
5497         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5498                         mode, "on#off");
5499
5500
5501 cmdline_parse_inst_t cmd_set_flush_rx = {
5502         .f = cmd_set_flush_rx_parsed,
5503         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5504         .data = NULL,
5505         .tokens = {
5506                 (void *)&cmd_setflushrx_set,
5507                 (void *)&cmd_setflushrx_flush_rx,
5508                 (void *)&cmd_setflushrx_mode,
5509                 NULL,
5510         },
5511 };
5512
5513 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5514 struct cmd_set_link_check {
5515         cmdline_fixed_string_t set;
5516         cmdline_fixed_string_t link_check;
5517         cmdline_fixed_string_t mode;
5518 };
5519
5520 static void
5521 cmd_set_link_check_parsed(void *parsed_result,
5522                 __rte_unused struct cmdline *cl,
5523                 __rte_unused void *data)
5524 {
5525         struct cmd_set_link_check *res = parsed_result;
5526         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5527 }
5528
5529 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5530         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5531                         set, "set");
5532 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5533         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5534                         link_check, "link_check");
5535 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5537                         mode, "on#off");
5538
5539
5540 cmdline_parse_inst_t cmd_set_link_check = {
5541         .f = cmd_set_link_check_parsed,
5542         .help_str = "set link_check on|off: Enable/Disable link status check "
5543                     "when starting/stopping a port",
5544         .data = NULL,
5545         .tokens = {
5546                 (void *)&cmd_setlinkcheck_set,
5547                 (void *)&cmd_setlinkcheck_link_check,
5548                 (void *)&cmd_setlinkcheck_mode,
5549                 NULL,
5550         },
5551 };
5552
5553 /* *** SET NIC BYPASS MODE *** */
5554 struct cmd_set_bypass_mode_result {
5555         cmdline_fixed_string_t set;
5556         cmdline_fixed_string_t bypass;
5557         cmdline_fixed_string_t mode;
5558         cmdline_fixed_string_t value;
5559         portid_t port_id;
5560 };
5561
5562 static void
5563 cmd_set_bypass_mode_parsed(void *parsed_result,
5564                 __rte_unused struct cmdline *cl,
5565                 __rte_unused void *data)
5566 {
5567         struct cmd_set_bypass_mode_result *res = parsed_result;
5568         portid_t port_id = res->port_id;
5569         int32_t rc = -EINVAL;
5570
5571 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5572         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5573
5574         if (!strcmp(res->value, "bypass"))
5575                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5576         else if (!strcmp(res->value, "isolate"))
5577                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5578         else
5579                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5580
5581         /* Set the bypass mode for the relevant port. */
5582         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5583 #endif
5584         if (rc != 0)
5585                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5586                         port_id);
5587 }
5588
5589 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5590         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5591                         set, "set");
5592 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5593         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5594                         bypass, "bypass");
5595 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5596         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5597                         mode, "mode");
5598 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5599         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5600                         value, "normal#bypass#isolate");
5601 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5602         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5603                                 port_id, RTE_UINT16);
5604
5605 cmdline_parse_inst_t cmd_set_bypass_mode = {
5606         .f = cmd_set_bypass_mode_parsed,
5607         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5608                     "Set the NIC bypass mode for port_id",
5609         .data = NULL,
5610         .tokens = {
5611                 (void *)&cmd_setbypass_mode_set,
5612                 (void *)&cmd_setbypass_mode_bypass,
5613                 (void *)&cmd_setbypass_mode_mode,
5614                 (void *)&cmd_setbypass_mode_value,
5615                 (void *)&cmd_setbypass_mode_port,
5616                 NULL,
5617         },
5618 };
5619
5620 /* *** SET NIC BYPASS EVENT *** */
5621 struct cmd_set_bypass_event_result {
5622         cmdline_fixed_string_t set;
5623         cmdline_fixed_string_t bypass;
5624         cmdline_fixed_string_t event;
5625         cmdline_fixed_string_t event_value;
5626         cmdline_fixed_string_t mode;
5627         cmdline_fixed_string_t mode_value;
5628         portid_t port_id;
5629 };
5630
5631 static void
5632 cmd_set_bypass_event_parsed(void *parsed_result,
5633                 __rte_unused struct cmdline *cl,
5634                 __rte_unused void *data)
5635 {
5636         int32_t rc = -EINVAL;
5637         struct cmd_set_bypass_event_result *res = parsed_result;
5638         portid_t port_id = res->port_id;
5639
5640 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5641         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5642         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5643
5644         if (!strcmp(res->event_value, "timeout"))
5645                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5646         else if (!strcmp(res->event_value, "os_on"))
5647                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5648         else if (!strcmp(res->event_value, "os_off"))
5649                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5650         else if (!strcmp(res->event_value, "power_on"))
5651                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5652         else if (!strcmp(res->event_value, "power_off"))
5653                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5654         else
5655                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5656
5657         if (!strcmp(res->mode_value, "bypass"))
5658                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5659         else if (!strcmp(res->mode_value, "isolate"))
5660                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5661         else
5662                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5663
5664         /* Set the watchdog timeout. */
5665         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5666
5667                 rc = -EINVAL;
5668                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5669                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5670                                                            bypass_timeout);
5671                 }
5672                 if (rc != 0) {
5673                         fprintf(stderr,
5674                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5675                                 bypass_timeout, port_id, rc);
5676                 }
5677         }
5678
5679         /* Set the bypass event to transition to bypass mode. */
5680         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5681                                               bypass_mode);
5682 #endif
5683
5684         if (rc != 0)
5685                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5686                         port_id);
5687 }
5688
5689 cmdline_parse_token_string_t cmd_setbypass_event_set =
5690         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5691                         set, "set");
5692 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5693         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5694                         bypass, "bypass");
5695 cmdline_parse_token_string_t cmd_setbypass_event_event =
5696         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5697                         event, "event");
5698 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5699         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5700                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5701 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5702         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5703                         mode, "mode");
5704 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5705         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5706                         mode_value, "normal#bypass#isolate");
5707 cmdline_parse_token_num_t cmd_setbypass_event_port =
5708         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5709                                 port_id, RTE_UINT16);
5710
5711 cmdline_parse_inst_t cmd_set_bypass_event = {
5712         .f = cmd_set_bypass_event_parsed,
5713         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5714                 "power_off mode normal|bypass|isolate <port_id>: "
5715                 "Set the NIC bypass event mode for port_id",
5716         .data = NULL,
5717         .tokens = {
5718                 (void *)&cmd_setbypass_event_set,
5719                 (void *)&cmd_setbypass_event_bypass,
5720                 (void *)&cmd_setbypass_event_event,
5721                 (void *)&cmd_setbypass_event_event_value,
5722                 (void *)&cmd_setbypass_event_mode,
5723                 (void *)&cmd_setbypass_event_mode_value,
5724                 (void *)&cmd_setbypass_event_port,
5725                 NULL,
5726         },
5727 };
5728
5729
5730 /* *** SET NIC BYPASS TIMEOUT *** */
5731 struct cmd_set_bypass_timeout_result {
5732         cmdline_fixed_string_t set;
5733         cmdline_fixed_string_t bypass;
5734         cmdline_fixed_string_t timeout;
5735         cmdline_fixed_string_t value;
5736 };
5737
5738 static void
5739 cmd_set_bypass_timeout_parsed(void *parsed_result,
5740                 __rte_unused struct cmdline *cl,
5741                 __rte_unused void *data)
5742 {
5743         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5744
5745 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5746         if (!strcmp(res->value, "1.5"))
5747                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5748         else if (!strcmp(res->value, "2"))
5749                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5750         else if (!strcmp(res->value, "3"))
5751                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5752         else if (!strcmp(res->value, "4"))
5753                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5754         else if (!strcmp(res->value, "8"))
5755                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5756         else if (!strcmp(res->value, "16"))
5757                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5758         else if (!strcmp(res->value, "32"))
5759                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5760         else
5761                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5762 #endif
5763 }
5764
5765 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5766         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5767                         set, "set");
5768 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5769         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5770                         bypass, "bypass");
5771 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5772         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5773                         timeout, "timeout");
5774 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5775         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5776                         value, "0#1.5#2#3#4#8#16#32");
5777
5778 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5779         .f = cmd_set_bypass_timeout_parsed,
5780         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5781                 "Set the NIC bypass watchdog timeout in seconds",
5782         .data = NULL,
5783         .tokens = {
5784                 (void *)&cmd_setbypass_timeout_set,
5785                 (void *)&cmd_setbypass_timeout_bypass,
5786                 (void *)&cmd_setbypass_timeout_timeout,
5787                 (void *)&cmd_setbypass_timeout_value,
5788                 NULL,
5789         },
5790 };
5791
5792 /* *** SHOW NIC BYPASS MODE *** */
5793 struct cmd_show_bypass_config_result {
5794         cmdline_fixed_string_t show;
5795         cmdline_fixed_string_t bypass;
5796         cmdline_fixed_string_t config;
5797         portid_t port_id;
5798 };
5799
5800 static void
5801 cmd_show_bypass_config_parsed(void *parsed_result,
5802                 __rte_unused struct cmdline *cl,
5803                 __rte_unused void *data)
5804 {
5805         struct cmd_show_bypass_config_result *res = parsed_result;
5806         portid_t port_id = res->port_id;
5807         int rc = -EINVAL;
5808 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5809         uint32_t event_mode;
5810         uint32_t bypass_mode;
5811         uint32_t timeout = bypass_timeout;
5812         unsigned int i;
5813
5814         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5815                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5816         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5817                 {"UNKNOWN", "normal", "bypass", "isolate"};
5818         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5819                 "NONE",
5820                 "OS/board on",
5821                 "power supply on",
5822                 "OS/board off",
5823                 "power supply off",
5824                 "timeout"};
5825
5826         /* Display the bypass mode.*/
5827         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5828                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5829                         port_id);
5830                 return;
5831         }
5832         else {
5833                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5834                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5835
5836                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5837         }
5838
5839         /* Display the bypass timeout.*/
5840         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5841                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5842
5843         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5844
5845         /* Display the bypass events and associated modes. */
5846         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5847
5848                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5849                         fprintf(stderr,
5850                                 "\tFailed to get bypass mode for event = %s\n",
5851                                 events[i]);
5852                 } else {
5853                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5854                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5855
5856                         printf("\tbypass event: %-16s = %s\n", events[i],
5857                                 modes[event_mode]);
5858                 }
5859         }
5860 #endif
5861         if (rc != 0)
5862                 fprintf(stderr,
5863                         "\tFailed to get bypass configuration for port = %d\n",
5864                        port_id);
5865 }
5866
5867 cmdline_parse_token_string_t cmd_showbypass_config_show =
5868         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5869                         show, "show");
5870 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5871         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5872                         bypass, "bypass");
5873 cmdline_parse_token_string_t cmd_showbypass_config_config =
5874         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5875                         config, "config");
5876 cmdline_parse_token_num_t cmd_showbypass_config_port =
5877         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5878                                 port_id, RTE_UINT16);
5879
5880 cmdline_parse_inst_t cmd_show_bypass_config = {
5881         .f = cmd_show_bypass_config_parsed,
5882         .help_str = "show bypass config <port_id>: "
5883                     "Show the NIC bypass config for port_id",
5884         .data = NULL,
5885         .tokens = {
5886                 (void *)&cmd_showbypass_config_show,
5887                 (void *)&cmd_showbypass_config_bypass,
5888                 (void *)&cmd_showbypass_config_config,
5889                 (void *)&cmd_showbypass_config_port,
5890                 NULL,
5891         },
5892 };
5893
5894 #ifdef RTE_NET_BOND
5895 /* *** SET BONDING MODE *** */
5896 struct cmd_set_bonding_mode_result {
5897         cmdline_fixed_string_t set;
5898         cmdline_fixed_string_t bonding;
5899         cmdline_fixed_string_t mode;
5900         uint8_t value;
5901         portid_t port_id;
5902 };
5903
5904 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5905                 __rte_unused  struct cmdline *cl,
5906                 __rte_unused void *data)
5907 {
5908         struct cmd_set_bonding_mode_result *res = parsed_result;
5909         portid_t port_id = res->port_id;
5910
5911         /* Set the bonding mode for the relevant port. */
5912         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5913                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5914                         port_id);
5915 }
5916
5917 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5918 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5919                 set, "set");
5920 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5922                 bonding, "bonding");
5923 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5925                 mode, "mode");
5926 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5927 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5928                 value, RTE_UINT8);
5929 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5930 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5931                 port_id, RTE_UINT16);
5932
5933 cmdline_parse_inst_t cmd_set_bonding_mode = {
5934                 .f = cmd_set_bonding_mode_parsed,
5935                 .help_str = "set bonding mode <mode_value> <port_id>: "
5936                         "Set the bonding mode for port_id",
5937                 .data = NULL,
5938                 .tokens = {
5939                                 (void *) &cmd_setbonding_mode_set,
5940                                 (void *) &cmd_setbonding_mode_bonding,
5941                                 (void *) &cmd_setbonding_mode_mode,
5942                                 (void *) &cmd_setbonding_mode_value,
5943                                 (void *) &cmd_setbonding_mode_port,
5944                                 NULL
5945                 }
5946 };
5947
5948 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5949 struct cmd_set_bonding_lacp_dedicated_queues_result {
5950         cmdline_fixed_string_t set;
5951         cmdline_fixed_string_t bonding;
5952         cmdline_fixed_string_t lacp;
5953         cmdline_fixed_string_t dedicated_queues;
5954         portid_t port_id;
5955         cmdline_fixed_string_t mode;
5956 };
5957
5958 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5959                 __rte_unused  struct cmdline *cl,
5960                 __rte_unused void *data)
5961 {
5962         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5963         portid_t port_id = res->port_id;
5964         struct rte_port *port;
5965
5966         port = &ports[port_id];
5967
5968         /** Check if the port is not started **/
5969         if (port->port_status != RTE_PORT_STOPPED) {
5970                 fprintf(stderr, "Please stop port %d first\n", port_id);
5971                 return;
5972         }
5973
5974         if (!strcmp(res->mode, "enable")) {
5975                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5976                         printf("Dedicate queues for LACP control packets"
5977                                         " enabled\n");
5978                 else
5979                         printf("Enabling dedicate queues for LACP control "
5980                                         "packets on port %d failed\n", port_id);
5981         } else if (!strcmp(res->mode, "disable")) {
5982                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5983                         printf("Dedicated queues for LACP control packets "
5984                                         "disabled\n");
5985                 else
5986                         printf("Disabling dedicated queues for LACP control "
5987                                         "traffic on port %d failed\n", port_id);
5988         }
5989 }
5990
5991 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5992 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5993                 set, "set");
5994 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5995 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5996                 bonding, "bonding");
5997 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5998 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5999                 lacp, "lacp");
6000 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6001 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6002                 dedicated_queues, "dedicated_queues");
6003 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6004 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6005                 port_id, RTE_UINT16);
6006 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6007 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6008                 mode, "enable#disable");
6009
6010 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6011                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6012                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6013                         "enable|disable: "
6014                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6015                 .data = NULL,
6016                 .tokens = {
6017                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6018                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6019                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6020                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6021                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6022                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6023                         NULL
6024                 }
6025 };
6026
6027 /* *** SET BALANCE XMIT POLICY *** */
6028 struct cmd_set_bonding_balance_xmit_policy_result {
6029         cmdline_fixed_string_t set;
6030         cmdline_fixed_string_t bonding;
6031         cmdline_fixed_string_t balance_xmit_policy;
6032         portid_t port_id;
6033         cmdline_fixed_string_t policy;
6034 };
6035
6036 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6037                 __rte_unused  struct cmdline *cl,
6038                 __rte_unused void *data)
6039 {
6040         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6041         portid_t port_id = res->port_id;
6042         uint8_t policy;
6043
6044         if (!strcmp(res->policy, "l2")) {
6045                 policy = BALANCE_XMIT_POLICY_LAYER2;
6046         } else if (!strcmp(res->policy, "l23")) {
6047                 policy = BALANCE_XMIT_POLICY_LAYER23;
6048         } else if (!strcmp(res->policy, "l34")) {
6049                 policy = BALANCE_XMIT_POLICY_LAYER34;
6050         } else {
6051                 fprintf(stderr, "\t Invalid xmit policy selection");
6052                 return;
6053         }
6054
6055         /* Set the bonding mode for the relevant port. */
6056         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6057                 fprintf(stderr,
6058                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6059                         port_id);
6060         }
6061 }
6062
6063 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6064 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6065                 set, "set");
6066 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6067 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6068                 bonding, "bonding");
6069 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6070 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6071                 balance_xmit_policy, "balance_xmit_policy");
6072 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6073 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6074                 port_id, RTE_UINT16);
6075 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6076 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6077                 policy, "l2#l23#l34");
6078
6079 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6080                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6081                 .help_str = "set bonding balance_xmit_policy <port_id> "
6082                         "l2|l23|l34: "
6083                         "Set the bonding balance_xmit_policy for port_id",
6084                 .data = NULL,
6085                 .tokens = {
6086                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6087                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6088                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6089                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6090                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6091                                 NULL
6092                 }
6093 };
6094
6095 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6096 struct cmd_show_bonding_lacp_info_result {
6097         cmdline_fixed_string_t show;
6098         cmdline_fixed_string_t bonding;
6099         cmdline_fixed_string_t lacp;
6100         cmdline_fixed_string_t info;
6101         portid_t port_id;
6102 };
6103
6104 static void port_param_show(struct port_params *params)
6105 {
6106         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6107
6108         printf("\t\tsystem priority: %u\n", params->system_priority);
6109         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6110         printf("\t\tsystem mac address: %s\n", buf);
6111         printf("\t\tport key: %u\n", params->key);
6112         printf("\t\tport priority: %u\n", params->port_priority);
6113         printf("\t\tport number: %u\n", params->port_number);
6114 }
6115
6116 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6117 {
6118         char a_state[256] = { 0 };
6119         char p_state[256] = { 0 };
6120         int a_len = 0;
6121         int p_len = 0;
6122         uint32_t i;
6123
6124         static const char * const state[] = {
6125                 "ACTIVE",
6126                 "TIMEOUT",
6127                 "AGGREGATION",
6128                 "SYNCHRONIZATION",
6129                 "COLLECTING",
6130                 "DISTRIBUTING",
6131                 "DEFAULTED",
6132                 "EXPIRED"
6133         };
6134         static const char * const selection[] = {
6135                 "UNSELECTED",
6136                 "STANDBY",
6137                 "SELECTED"
6138         };
6139
6140         for (i = 0; i < RTE_DIM(state); i++) {
6141                 if ((info->actor_state >> i) & 1)
6142                         a_len += snprintf(&a_state[a_len],
6143                                                 RTE_DIM(a_state) - a_len, "%s ",
6144                                                 state[i]);
6145
6146                 if ((info->partner_state >> i) & 1)
6147                         p_len += snprintf(&p_state[p_len],
6148                                                 RTE_DIM(p_state) - p_len, "%s ",
6149                                                 state[i]);
6150         }
6151         printf("\tAggregator port id: %u\n", info->agg_port_id);
6152         printf("\tselection: %s\n", selection[info->selected]);
6153         printf("\tActor detail info:\n");
6154         port_param_show(&info->actor);
6155         printf("\t\tport state: %s\n", a_state);
6156         printf("\tPartner detail info:\n");
6157         port_param_show(&info->partner);
6158         printf("\t\tport state: %s\n", p_state);
6159         printf("\n");
6160 }
6161
6162 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6163 {
6164         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6165         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6166         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6167         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6168         printf("\taggregate wait timeout: %u ms\n",
6169                         conf->aggregate_wait_timeout_ms);
6170         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6171         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6172         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6173         switch (conf->agg_selection) {
6174         case AGG_BANDWIDTH:
6175                 printf("\taggregation mode: bandwidth\n");
6176                 break;
6177         case AGG_STABLE:
6178                 printf("\taggregation mode: stable\n");
6179                 break;
6180         case AGG_COUNT:
6181                 printf("\taggregation mode: count\n");
6182                 break;
6183         default:
6184                 printf("\taggregation mode: invalid\n");
6185                 break;
6186         }
6187
6188         printf("\n");
6189 }
6190
6191 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6192                 __rte_unused  struct cmdline *cl,
6193                 __rte_unused void *data)
6194 {
6195         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6196         struct rte_eth_bond_8023ad_slave_info slave_info;
6197         struct rte_eth_bond_8023ad_conf port_conf;
6198         portid_t slaves[RTE_MAX_ETHPORTS];
6199         portid_t port_id = res->port_id;
6200         int num_active_slaves;
6201         int bonding_mode;
6202         int i;
6203         int ret;
6204
6205         bonding_mode = rte_eth_bond_mode_get(port_id);
6206         if (bonding_mode != BONDING_MODE_8023AD) {
6207                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6208                 return;
6209         }
6210
6211         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6212                         RTE_MAX_ETHPORTS);
6213         if (num_active_slaves < 0) {
6214                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6215                                 port_id);
6216                 return;
6217         }
6218         if (num_active_slaves == 0)
6219                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6220                         port_id);
6221
6222         printf("\tIEEE802.3 port: %u\n", port_id);
6223         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6224         if (ret) {
6225                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6226                         port_id);
6227                 return;
6228         }
6229         lacp_conf_show(&port_conf);
6230
6231         for (i = 0; i < num_active_slaves; i++) {
6232                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6233                                 &slave_info);
6234                 if (ret) {
6235                         fprintf(stderr, "\tGet slave device %u info failed\n",
6236                                 slaves[i]);
6237                         return;
6238                 }
6239                 printf("\tSlave Port: %u\n", slaves[i]);
6240                 lacp_slave_info_show(&slave_info);
6241         }
6242 }
6243
6244 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6245 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6246                 show, "show");
6247 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6248 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6249                 bonding, "bonding");
6250 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6251 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6252                 bonding, "lacp");
6253 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6254 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6255                 info, "info");
6256 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6257 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6258                 port_id, RTE_UINT16);
6259
6260 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6261                 .f = cmd_show_bonding_lacp_info_parsed,
6262                 .help_str = "show bonding lacp info <port_id> : "
6263                         "Show bonding IEEE802.3 information for port_id",
6264                 .data = NULL,
6265                 .tokens = {
6266                         (void *)&cmd_show_bonding_lacp_info_show,
6267                         (void *)&cmd_show_bonding_lacp_info_bonding,
6268                         (void *)&cmd_show_bonding_lacp_info_lacp,
6269                         (void *)&cmd_show_bonding_lacp_info_info,
6270                         (void *)&cmd_show_bonding_lacp_info_port_id,
6271                         NULL
6272                 }
6273 };
6274
6275 /* *** SHOW NIC BONDING CONFIGURATION *** */
6276 struct cmd_show_bonding_config_result {
6277         cmdline_fixed_string_t show;
6278         cmdline_fixed_string_t bonding;
6279         cmdline_fixed_string_t config;
6280         portid_t port_id;
6281 };
6282
6283 static void cmd_show_bonding_config_parsed(void *parsed_result,
6284                 __rte_unused  struct cmdline *cl,
6285                 __rte_unused void *data)
6286 {
6287         struct cmd_show_bonding_config_result *res = parsed_result;
6288         int bonding_mode, agg_mode;
6289         portid_t slaves[RTE_MAX_ETHPORTS];
6290         int num_slaves, num_active_slaves;
6291         int primary_id;
6292         int i;
6293         portid_t port_id = res->port_id;
6294
6295         /* Display the bonding mode.*/
6296         bonding_mode = rte_eth_bond_mode_get(port_id);
6297         if (bonding_mode < 0) {
6298                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6299                         port_id);
6300                 return;
6301         } else
6302                 printf("\tBonding mode: %d\n", bonding_mode);
6303
6304         if (bonding_mode == BONDING_MODE_BALANCE) {
6305                 int balance_xmit_policy;
6306
6307                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6308                 if (balance_xmit_policy < 0) {
6309                         fprintf(stderr,
6310                                 "\tFailed to get balance xmit policy for port = %d\n",
6311                                 port_id);
6312                         return;
6313                 } else {
6314                         printf("\tBalance Xmit Policy: ");
6315
6316                         switch (balance_xmit_policy) {
6317                         case BALANCE_XMIT_POLICY_LAYER2:
6318                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6319                                 break;
6320                         case BALANCE_XMIT_POLICY_LAYER23:
6321                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6322                                 break;
6323                         case BALANCE_XMIT_POLICY_LAYER34:
6324                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6325                                 break;
6326                         }
6327                         printf("\n");
6328                 }
6329         }
6330
6331         if (bonding_mode == BONDING_MODE_8023AD) {
6332                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6333                 printf("\tIEEE802.3AD Aggregator Mode: ");
6334                 switch (agg_mode) {
6335                 case AGG_BANDWIDTH:
6336                         printf("bandwidth");
6337                         break;
6338                 case AGG_STABLE:
6339                         printf("stable");
6340                         break;
6341                 case AGG_COUNT:
6342                         printf("count");
6343                         break;
6344                 }
6345                 printf("\n");
6346         }
6347
6348         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6349
6350         if (num_slaves < 0) {
6351                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6352                         port_id);
6353                 return;
6354         }
6355         if (num_slaves > 0) {
6356                 printf("\tSlaves (%d): [", num_slaves);
6357                 for (i = 0; i < num_slaves - 1; i++)
6358                         printf("%d ", slaves[i]);
6359
6360                 printf("%d]\n", slaves[num_slaves - 1]);
6361         } else {
6362                 printf("\tSlaves: []\n");
6363
6364         }
6365
6366         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6367                         RTE_MAX_ETHPORTS);
6368
6369         if (num_active_slaves < 0) {
6370                 fprintf(stderr,
6371                         "\tFailed to get active slave list for port = %d\n",
6372                         port_id);
6373                 return;
6374         }
6375         if (num_active_slaves > 0) {
6376                 printf("\tActive Slaves (%d): [", num_active_slaves);
6377                 for (i = 0; i < num_active_slaves - 1; i++)
6378                         printf("%d ", slaves[i]);
6379
6380                 printf("%d]\n", slaves[num_active_slaves - 1]);
6381
6382         } else {
6383                 printf("\tActive Slaves: []\n");
6384
6385         }
6386
6387         primary_id = rte_eth_bond_primary_get(port_id);
6388         if (primary_id < 0) {
6389                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6390                         port_id);
6391                 return;
6392         } else
6393                 printf("\tPrimary: [%d]\n", primary_id);
6394
6395 }
6396
6397 cmdline_parse_token_string_t cmd_showbonding_config_show =
6398 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6399                 show, "show");
6400 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6401 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6402                 bonding, "bonding");
6403 cmdline_parse_token_string_t cmd_showbonding_config_config =
6404 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6405                 config, "config");
6406 cmdline_parse_token_num_t cmd_showbonding_config_port =
6407 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6408                 port_id, RTE_UINT16);
6409
6410 cmdline_parse_inst_t cmd_show_bonding_config = {
6411                 .f = cmd_show_bonding_config_parsed,
6412                 .help_str = "show bonding config <port_id>: "
6413                         "Show the bonding config for port_id",
6414                 .data = NULL,
6415                 .tokens = {
6416                                 (void *)&cmd_showbonding_config_show,
6417                                 (void *)&cmd_showbonding_config_bonding,
6418                                 (void *)&cmd_showbonding_config_config,
6419                                 (void *)&cmd_showbonding_config_port,
6420                                 NULL
6421                 }
6422 };
6423
6424 /* *** SET BONDING PRIMARY *** */
6425 struct cmd_set_bonding_primary_result {
6426         cmdline_fixed_string_t set;
6427         cmdline_fixed_string_t bonding;
6428         cmdline_fixed_string_t primary;
6429         portid_t slave_id;
6430         portid_t port_id;
6431 };
6432
6433 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6434                 __rte_unused  struct cmdline *cl,
6435                 __rte_unused void *data)
6436 {
6437         struct cmd_set_bonding_primary_result *res = parsed_result;
6438         portid_t master_port_id = res->port_id;
6439         portid_t slave_port_id = res->slave_id;
6440
6441         /* Set the primary slave for a bonded device. */
6442         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6443                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6444                         master_port_id);
6445                 return;
6446         }
6447         init_port_config();
6448 }
6449
6450 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6451 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6452                 set, "set");
6453 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6454 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6455                 bonding, "bonding");
6456 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6457 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6458                 primary, "primary");
6459 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6460 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6461                 slave_id, RTE_UINT16);
6462 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6463 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6464                 port_id, RTE_UINT16);
6465
6466 cmdline_parse_inst_t cmd_set_bonding_primary = {
6467                 .f = cmd_set_bonding_primary_parsed,
6468                 .help_str = "set bonding primary <slave_id> <port_id>: "
6469                         "Set the primary slave for port_id",
6470                 .data = NULL,
6471                 .tokens = {
6472                                 (void *)&cmd_setbonding_primary_set,
6473                                 (void *)&cmd_setbonding_primary_bonding,
6474                                 (void *)&cmd_setbonding_primary_primary,
6475                                 (void *)&cmd_setbonding_primary_slave,
6476                                 (void *)&cmd_setbonding_primary_port,
6477                                 NULL
6478                 }
6479 };
6480
6481 /* *** ADD SLAVE *** */
6482 struct cmd_add_bonding_slave_result {
6483         cmdline_fixed_string_t add;
6484         cmdline_fixed_string_t bonding;
6485         cmdline_fixed_string_t slave;
6486         portid_t slave_id;
6487         portid_t port_id;
6488 };
6489
6490 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6491                 __rte_unused  struct cmdline *cl,
6492                 __rte_unused void *data)
6493 {
6494         struct cmd_add_bonding_slave_result *res = parsed_result;
6495         portid_t master_port_id = res->port_id;
6496         portid_t slave_port_id = res->slave_id;
6497
6498         /* add the slave for a bonded device. */
6499         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6500                 fprintf(stderr,
6501                         "\t Failed to add slave %d to master port = %d.\n",
6502                         slave_port_id, master_port_id);
6503                 return;
6504         }
6505         init_port_config();
6506         set_port_slave_flag(slave_port_id);
6507 }
6508
6509 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6510 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6511                 add, "add");
6512 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6513 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6514                 bonding, "bonding");
6515 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6516 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6517                 slave, "slave");
6518 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6519 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6520                 slave_id, RTE_UINT16);
6521 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6522 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6523                 port_id, RTE_UINT16);
6524
6525 cmdline_parse_inst_t cmd_add_bonding_slave = {
6526                 .f = cmd_add_bonding_slave_parsed,
6527                 .help_str = "add bonding slave <slave_id> <port_id>: "
6528                         "Add a slave device to a bonded device",
6529                 .data = NULL,
6530                 .tokens = {
6531                                 (void *)&cmd_addbonding_slave_add,
6532                                 (void *)&cmd_addbonding_slave_bonding,
6533                                 (void *)&cmd_addbonding_slave_slave,
6534                                 (void *)&cmd_addbonding_slave_slaveid,
6535                                 (void *)&cmd_addbonding_slave_port,
6536                                 NULL
6537                 }
6538 };
6539
6540 /* *** REMOVE SLAVE *** */
6541 struct cmd_remove_bonding_slave_result {
6542         cmdline_fixed_string_t remove;
6543         cmdline_fixed_string_t bonding;
6544         cmdline_fixed_string_t slave;
6545         portid_t slave_id;
6546         portid_t port_id;
6547 };
6548
6549 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6550                 __rte_unused  struct cmdline *cl,
6551                 __rte_unused void *data)
6552 {
6553         struct cmd_remove_bonding_slave_result *res = parsed_result;
6554         portid_t master_port_id = res->port_id;
6555         portid_t slave_port_id = res->slave_id;
6556
6557         /* remove the slave from a bonded device. */
6558         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6559                 fprintf(stderr,
6560                         "\t Failed to remove slave %d from master port = %d.\n",
6561                         slave_port_id, master_port_id);
6562                 return;
6563         }
6564         init_port_config();
6565         clear_port_slave_flag(slave_port_id);
6566 }
6567
6568 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6569                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6570                                 remove, "remove");
6571 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6572                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6573                                 bonding, "bonding");
6574 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6575                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6576                                 slave, "slave");
6577 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6578                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6579                                 slave_id, RTE_UINT16);
6580 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6581                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6582                                 port_id, RTE_UINT16);
6583
6584 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6585                 .f = cmd_remove_bonding_slave_parsed,
6586                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6587                         "Remove a slave device from a bonded device",
6588                 .data = NULL,
6589                 .tokens = {
6590                                 (void *)&cmd_removebonding_slave_remove,
6591                                 (void *)&cmd_removebonding_slave_bonding,
6592                                 (void *)&cmd_removebonding_slave_slave,
6593                                 (void *)&cmd_removebonding_slave_slaveid,
6594                                 (void *)&cmd_removebonding_slave_port,
6595                                 NULL
6596                 }
6597 };
6598
6599 /* *** CREATE BONDED DEVICE *** */
6600 struct cmd_create_bonded_device_result {
6601         cmdline_fixed_string_t create;
6602         cmdline_fixed_string_t bonded;
6603         cmdline_fixed_string_t device;
6604         uint8_t mode;
6605         uint8_t socket;
6606 };
6607
6608 static int bond_dev_num = 0;
6609
6610 static void cmd_create_bonded_device_parsed(void *parsed_result,
6611                 __rte_unused  struct cmdline *cl,
6612                 __rte_unused void *data)
6613 {
6614         struct cmd_create_bonded_device_result *res = parsed_result;
6615         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6616         int port_id;
6617         int ret;
6618
6619         if (test_done == 0) {
6620                 fprintf(stderr, "Please stop forwarding first\n");
6621                 return;
6622         }
6623
6624         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6625                         bond_dev_num++);
6626
6627         /* Create a new bonded device. */
6628         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6629         if (port_id < 0) {
6630                 fprintf(stderr, "\t Failed to create bonded device.\n");
6631                 return;
6632         } else {
6633                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6634                                 port_id);
6635
6636                 /* Update number of ports */
6637                 nb_ports = rte_eth_dev_count_avail();
6638                 reconfig(port_id, res->socket);
6639                 ret = rte_eth_promiscuous_enable(port_id);
6640                 if (ret != 0)
6641                         fprintf(stderr,
6642                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6643                                 port_id, rte_strerror(-ret));
6644
6645                 ports[port_id].need_setup = 0;
6646                 ports[port_id].port_status = RTE_PORT_STOPPED;
6647         }
6648
6649 }
6650
6651 cmdline_parse_token_string_t cmd_createbonded_device_create =
6652                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6653                                 create, "create");
6654 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6655                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6656                                 bonded, "bonded");
6657 cmdline_parse_token_string_t cmd_createbonded_device_device =
6658                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6659                                 device, "device");
6660 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6661                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6662                                 mode, RTE_UINT8);
6663 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6664                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6665                                 socket, RTE_UINT8);
6666
6667 cmdline_parse_inst_t cmd_create_bonded_device = {
6668                 .f = cmd_create_bonded_device_parsed,
6669                 .help_str = "create bonded device <mode> <socket>: "
6670                         "Create a new bonded device with specific bonding mode and socket",
6671                 .data = NULL,
6672                 .tokens = {
6673                                 (void *)&cmd_createbonded_device_create,
6674                                 (void *)&cmd_createbonded_device_bonded,
6675                                 (void *)&cmd_createbonded_device_device,
6676                                 (void *)&cmd_createbonded_device_mode,
6677                                 (void *)&cmd_createbonded_device_socket,
6678                                 NULL
6679                 }
6680 };
6681
6682 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6683 struct cmd_set_bond_mac_addr_result {
6684         cmdline_fixed_string_t set;
6685         cmdline_fixed_string_t bonding;
6686         cmdline_fixed_string_t mac_addr;
6687         uint16_t port_num;
6688         struct rte_ether_addr address;
6689 };
6690
6691 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6692                 __rte_unused  struct cmdline *cl,
6693                 __rte_unused void *data)
6694 {
6695         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6696         int ret;
6697
6698         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6699                 return;
6700
6701         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6702
6703         /* check the return value and print it if is < 0 */
6704         if (ret < 0)
6705                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6706                         strerror(-ret));
6707 }
6708
6709 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6710                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6711 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6712                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6713                                 "bonding");
6714 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6715                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6716                                 "mac_addr");
6717 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6718                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6719                                 port_num, RTE_UINT16);
6720 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6721                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6722
6723 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6724                 .f = cmd_set_bond_mac_addr_parsed,
6725                 .data = (void *) 0,
6726                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6727                 .tokens = {
6728                                 (void *)&cmd_set_bond_mac_addr_set,
6729                                 (void *)&cmd_set_bond_mac_addr_bonding,
6730                                 (void *)&cmd_set_bond_mac_addr_mac,
6731                                 (void *)&cmd_set_bond_mac_addr_portnum,
6732                                 (void *)&cmd_set_bond_mac_addr_addr,
6733                                 NULL
6734                 }
6735 };
6736
6737
6738 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6739 struct cmd_set_bond_mon_period_result {
6740         cmdline_fixed_string_t set;
6741         cmdline_fixed_string_t bonding;
6742         cmdline_fixed_string_t mon_period;
6743         uint16_t port_num;
6744         uint32_t period_ms;
6745 };
6746
6747 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6748                 __rte_unused  struct cmdline *cl,
6749                 __rte_unused void *data)
6750 {
6751         struct cmd_set_bond_mon_period_result *res = parsed_result;
6752         int ret;
6753
6754         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6755
6756         /* check the return value and print it if is < 0 */
6757         if (ret < 0)
6758                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6759                         strerror(-ret));
6760 }
6761
6762 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6763                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6764                                 set, "set");
6765 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6766                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6767                                 bonding, "bonding");
6768 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6769                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6770                                 mon_period,     "mon_period");
6771 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6772                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6773                                 port_num, RTE_UINT16);
6774 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6775                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6776                                 period_ms, RTE_UINT32);
6777
6778 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6779                 .f = cmd_set_bond_mon_period_parsed,
6780                 .data = (void *) 0,
6781                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6782                 .tokens = {
6783                                 (void *)&cmd_set_bond_mon_period_set,
6784                                 (void *)&cmd_set_bond_mon_period_bonding,
6785                                 (void *)&cmd_set_bond_mon_period_mon_period,
6786                                 (void *)&cmd_set_bond_mon_period_portnum,
6787                                 (void *)&cmd_set_bond_mon_period_period_ms,
6788                                 NULL
6789                 }
6790 };
6791
6792
6793
6794 struct cmd_set_bonding_agg_mode_policy_result {
6795         cmdline_fixed_string_t set;
6796         cmdline_fixed_string_t bonding;
6797         cmdline_fixed_string_t agg_mode;
6798         uint16_t port_num;
6799         cmdline_fixed_string_t policy;
6800 };
6801
6802
6803 static void
6804 cmd_set_bonding_agg_mode(void *parsed_result,
6805                 __rte_unused struct cmdline *cl,
6806                 __rte_unused void *data)
6807 {
6808         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6809         uint8_t policy = AGG_BANDWIDTH;
6810
6811         if (!strcmp(res->policy, "bandwidth"))
6812                 policy = AGG_BANDWIDTH;
6813         else if (!strcmp(res->policy, "stable"))
6814                 policy = AGG_STABLE;
6815         else if (!strcmp(res->policy, "count"))
6816                 policy = AGG_COUNT;
6817
6818         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6819 }
6820
6821
6822 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6823         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6824                                 set, "set");
6825 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6826         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6827                                 bonding, "bonding");
6828
6829 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6830         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6831                                 agg_mode, "agg_mode");
6832
6833 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6834         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6835                                 port_num, RTE_UINT16);
6836
6837 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6838         TOKEN_STRING_INITIALIZER(
6839                         struct cmd_set_bonding_balance_xmit_policy_result,
6840                 policy, "stable#bandwidth#count");
6841
6842 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6843         .f = cmd_set_bonding_agg_mode,
6844         .data = (void *) 0,
6845         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6846         .tokens = {
6847                         (void *)&cmd_set_bonding_agg_mode_set,
6848                         (void *)&cmd_set_bonding_agg_mode_bonding,
6849                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6850                         (void *)&cmd_set_bonding_agg_mode_portnum,
6851                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6852                         NULL
6853                 }
6854 };
6855
6856
6857 #endif /* RTE_NET_BOND */
6858
6859 /* *** SET FORWARDING MODE *** */
6860 struct cmd_set_fwd_mode_result {
6861         cmdline_fixed_string_t set;
6862         cmdline_fixed_string_t fwd;
6863         cmdline_fixed_string_t mode;
6864 };
6865
6866 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6867                                     __rte_unused struct cmdline *cl,
6868                                     __rte_unused void *data)
6869 {
6870         struct cmd_set_fwd_mode_result *res = parsed_result;
6871
6872         retry_enabled = 0;
6873         set_pkt_forwarding_mode(res->mode);
6874 }
6875
6876 cmdline_parse_token_string_t cmd_setfwd_set =
6877         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6878 cmdline_parse_token_string_t cmd_setfwd_fwd =
6879         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6880 cmdline_parse_token_string_t cmd_setfwd_mode =
6881         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6882                 "" /* defined at init */);
6883
6884 cmdline_parse_inst_t cmd_set_fwd_mode = {
6885         .f = cmd_set_fwd_mode_parsed,
6886         .data = NULL,
6887         .help_str = NULL, /* defined at init */
6888         .tokens = {
6889                 (void *)&cmd_setfwd_set,
6890                 (void *)&cmd_setfwd_fwd,
6891                 (void *)&cmd_setfwd_mode,
6892                 NULL,
6893         },
6894 };
6895
6896 static void cmd_set_fwd_mode_init(void)
6897 {
6898         char *modes, *c;
6899         static char token[128];
6900         static char help[256];
6901         cmdline_parse_token_string_t *token_struct;
6902
6903         modes = list_pkt_forwarding_modes();
6904         snprintf(help, sizeof(help), "set fwd %s: "
6905                 "Set packet forwarding mode", modes);
6906         cmd_set_fwd_mode.help_str = help;
6907
6908         /* string token separator is # */
6909         for (c = token; *modes != '\0'; modes++)
6910                 if (*modes == '|')
6911                         *c++ = '#';
6912                 else
6913                         *c++ = *modes;
6914         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6915         token_struct->string_data.str = token;
6916 }
6917
6918 /* *** SET RETRY FORWARDING MODE *** */
6919 struct cmd_set_fwd_retry_mode_result {
6920         cmdline_fixed_string_t set;
6921         cmdline_fixed_string_t fwd;
6922         cmdline_fixed_string_t mode;
6923         cmdline_fixed_string_t retry;
6924 };
6925
6926 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6927                             __rte_unused struct cmdline *cl,
6928                             __rte_unused void *data)
6929 {
6930         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6931
6932         retry_enabled = 1;
6933         set_pkt_forwarding_mode(res->mode);
6934 }
6935
6936 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6937         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6938                         set, "set");
6939 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6940         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6941                         fwd, "fwd");
6942 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6943         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6944                         mode,
6945                 "" /* defined at init */);
6946 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6947         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6948                         retry, "retry");
6949
6950 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6951         .f = cmd_set_fwd_retry_mode_parsed,
6952         .data = NULL,
6953         .help_str = NULL, /* defined at init */
6954         .tokens = {
6955                 (void *)&cmd_setfwd_retry_set,
6956                 (void *)&cmd_setfwd_retry_fwd,
6957                 (void *)&cmd_setfwd_retry_mode,
6958                 (void *)&cmd_setfwd_retry_retry,
6959                 NULL,
6960         },
6961 };
6962
6963 static void cmd_set_fwd_retry_mode_init(void)
6964 {
6965         char *modes, *c;
6966         static char token[128];
6967         static char help[256];
6968         cmdline_parse_token_string_t *token_struct;
6969
6970         modes = list_pkt_forwarding_retry_modes();
6971         snprintf(help, sizeof(help), "set fwd %s retry: "
6972                 "Set packet forwarding mode with retry", modes);
6973         cmd_set_fwd_retry_mode.help_str = help;
6974
6975         /* string token separator is # */
6976         for (c = token; *modes != '\0'; modes++)
6977                 if (*modes == '|')
6978                         *c++ = '#';
6979                 else
6980                         *c++ = *modes;
6981         token_struct = (cmdline_parse_token_string_t *)
6982                 cmd_set_fwd_retry_mode.tokens[2];
6983         token_struct->string_data.str = token;
6984 }
6985
6986 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6987 struct cmd_set_burst_tx_retry_result {
6988         cmdline_fixed_string_t set;
6989         cmdline_fixed_string_t burst;
6990         cmdline_fixed_string_t tx;
6991         cmdline_fixed_string_t delay;
6992         uint32_t time;
6993         cmdline_fixed_string_t retry;
6994         uint32_t retry_num;
6995 };
6996
6997 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6998                                         __rte_unused struct cmdline *cl,
6999                                         __rte_unused void *data)
7000 {
7001         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7002
7003         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7004                 && !strcmp(res->tx, "tx")) {
7005                 if (!strcmp(res->delay, "delay"))
7006                         burst_tx_delay_time = res->time;
7007                 if (!strcmp(res->retry, "retry"))
7008                         burst_tx_retry_num = res->retry_num;
7009         }
7010
7011 }
7012
7013 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7014         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7015 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7016         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7017                                  "burst");
7018 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7019         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7020 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7021         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7022 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7023         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7024                                  RTE_UINT32);
7025 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7026         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7027 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7028         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7029                                  RTE_UINT32);
7030
7031 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7032         .f = cmd_set_burst_tx_retry_parsed,
7033         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7034         .tokens = {
7035                 (void *)&cmd_set_burst_tx_retry_set,
7036                 (void *)&cmd_set_burst_tx_retry_burst,
7037                 (void *)&cmd_set_burst_tx_retry_tx,
7038                 (void *)&cmd_set_burst_tx_retry_delay,
7039                 (void *)&cmd_set_burst_tx_retry_time,
7040                 (void *)&cmd_set_burst_tx_retry_retry,
7041                 (void *)&cmd_set_burst_tx_retry_retry_num,
7042                 NULL,
7043         },
7044 };
7045
7046 /* *** SET PROMISC MODE *** */
7047 struct cmd_set_promisc_mode_result {
7048         cmdline_fixed_string_t set;
7049         cmdline_fixed_string_t promisc;
7050         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7051         uint16_t port_num;               /* valid if "allports" argument == 0 */
7052         cmdline_fixed_string_t mode;
7053 };
7054
7055 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7056                                         __rte_unused struct cmdline *cl,
7057                                         void *allports)
7058 {
7059         struct cmd_set_promisc_mode_result *res = parsed_result;
7060         int enable;
7061         portid_t i;
7062
7063         if (!strcmp(res->mode, "on"))
7064                 enable = 1;
7065         else
7066                 enable = 0;
7067
7068         /* all ports */
7069         if (allports) {
7070                 RTE_ETH_FOREACH_DEV(i)
7071                         eth_set_promisc_mode(i, enable);
7072         } else {
7073                 eth_set_promisc_mode(res->port_num, enable);
7074         }
7075 }
7076
7077 cmdline_parse_token_string_t cmd_setpromisc_set =
7078         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7079 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7080         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7081                                  "promisc");
7082 cmdline_parse_token_string_t cmd_setpromisc_portall =
7083         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7084                                  "all");
7085 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7086         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7087                               RTE_UINT16);
7088 cmdline_parse_token_string_t cmd_setpromisc_mode =
7089         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7090                                  "on#off");
7091
7092 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7093         .f = cmd_set_promisc_mode_parsed,
7094         .data = (void *)1,
7095         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7096         .tokens = {
7097                 (void *)&cmd_setpromisc_set,
7098                 (void *)&cmd_setpromisc_promisc,
7099                 (void *)&cmd_setpromisc_portall,
7100                 (void *)&cmd_setpromisc_mode,
7101                 NULL,
7102         },
7103 };
7104
7105 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7106         .f = cmd_set_promisc_mode_parsed,
7107         .data = (void *)0,
7108         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7109         .tokens = {
7110                 (void *)&cmd_setpromisc_set,
7111                 (void *)&cmd_setpromisc_promisc,
7112                 (void *)&cmd_setpromisc_portnum,
7113                 (void *)&cmd_setpromisc_mode,
7114                 NULL,
7115         },
7116 };
7117
7118 /* *** SET ALLMULTI MODE *** */
7119 struct cmd_set_allmulti_mode_result {
7120         cmdline_fixed_string_t set;
7121         cmdline_fixed_string_t allmulti;
7122         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7123         uint16_t port_num;               /* valid if "allports" argument == 0 */
7124         cmdline_fixed_string_t mode;
7125 };
7126
7127 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7128                                         __rte_unused struct cmdline *cl,
7129                                         void *allports)
7130 {
7131         struct cmd_set_allmulti_mode_result *res = parsed_result;
7132         int enable;
7133         portid_t i;
7134
7135         if (!strcmp(res->mode, "on"))
7136                 enable = 1;
7137         else
7138                 enable = 0;
7139
7140         /* all ports */
7141         if (allports) {
7142                 RTE_ETH_FOREACH_DEV(i) {
7143                         eth_set_allmulticast_mode(i, enable);
7144                 }
7145         }
7146         else {
7147                 eth_set_allmulticast_mode(res->port_num, enable);
7148         }
7149 }
7150
7151 cmdline_parse_token_string_t cmd_setallmulti_set =
7152         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7153 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7154         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7155                                  "allmulti");
7156 cmdline_parse_token_string_t cmd_setallmulti_portall =
7157         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7158                                  "all");
7159 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7160         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7161                               RTE_UINT16);
7162 cmdline_parse_token_string_t cmd_setallmulti_mode =
7163         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7164                                  "on#off");
7165
7166 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7167         .f = cmd_set_allmulti_mode_parsed,
7168         .data = (void *)1,
7169         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7170         .tokens = {
7171                 (void *)&cmd_setallmulti_set,
7172                 (void *)&cmd_setallmulti_allmulti,
7173                 (void *)&cmd_setallmulti_portall,
7174                 (void *)&cmd_setallmulti_mode,
7175                 NULL,
7176         },
7177 };
7178
7179 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7180         .f = cmd_set_allmulti_mode_parsed,
7181         .data = (void *)0,
7182         .help_str = "set allmulti <port_id> on|off: "
7183                 "Set allmulti mode on port_id",
7184         .tokens = {
7185                 (void *)&cmd_setallmulti_set,
7186                 (void *)&cmd_setallmulti_allmulti,
7187                 (void *)&cmd_setallmulti_portnum,
7188                 (void *)&cmd_setallmulti_mode,
7189                 NULL,
7190         },
7191 };
7192
7193 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7194 struct cmd_link_flow_ctrl_show {
7195         cmdline_fixed_string_t show;
7196         cmdline_fixed_string_t port;
7197         portid_t port_id;
7198         cmdline_fixed_string_t flow_ctrl;
7199 };
7200
7201 cmdline_parse_token_string_t cmd_lfc_show_show =
7202         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7203                                 show, "show");
7204 cmdline_parse_token_string_t cmd_lfc_show_port =
7205         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7206                                 port, "port");
7207 cmdline_parse_token_num_t cmd_lfc_show_portid =
7208         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7209                                 port_id, RTE_UINT16);
7210 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7211         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7212                                 flow_ctrl, "flow_ctrl");
7213
7214 static void
7215 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7216                               __rte_unused struct cmdline *cl,
7217                               __rte_unused void *data)
7218 {
7219         struct cmd_link_flow_ctrl_show *res = parsed_result;
7220         static const char *info_border = "*********************";
7221         struct rte_eth_fc_conf fc_conf;
7222         bool rx_fc_en = false;
7223         bool tx_fc_en = false;
7224         int ret;
7225
7226         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7227         if (ret != 0) {
7228                 fprintf(stderr,
7229                         "Failed to get current flow ctrl information: err = %d\n",
7230                         ret);
7231                 return;
7232         }
7233
7234         if (fc_conf.mode == RTE_FC_RX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7235                 rx_fc_en = true;
7236         if (fc_conf.mode == RTE_FC_TX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7237                 tx_fc_en = true;
7238
7239         printf("\n%s Flow control infos for port %-2d %s\n",
7240                 info_border, res->port_id, info_border);
7241         printf("FC mode:\n");
7242         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7243         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7244         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7245         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7246         printf("High waterline: 0x%x\n", fc_conf.high_water);
7247         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7248         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7249         printf("Forward MAC control frames: %s\n",
7250                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7251         printf("\n%s**************   End  ***********%s\n",
7252                 info_border, info_border);
7253 }
7254
7255 cmdline_parse_inst_t cmd_link_flow_control_show = {
7256         .f = cmd_link_flow_ctrl_show_parsed,
7257         .data = NULL,
7258         .help_str = "show port <port_id> flow_ctrl",
7259         .tokens = {
7260                 (void *)&cmd_lfc_show_show,
7261                 (void *)&cmd_lfc_show_port,
7262                 (void *)&cmd_lfc_show_portid,
7263                 (void *)&cmd_lfc_show_flow_ctrl,
7264                 NULL,
7265         },
7266 };
7267
7268 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7269 struct cmd_link_flow_ctrl_set_result {
7270         cmdline_fixed_string_t set;
7271         cmdline_fixed_string_t flow_ctrl;
7272         cmdline_fixed_string_t rx;
7273         cmdline_fixed_string_t rx_lfc_mode;
7274         cmdline_fixed_string_t tx;
7275         cmdline_fixed_string_t tx_lfc_mode;
7276         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7277         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7278         cmdline_fixed_string_t autoneg_str;
7279         cmdline_fixed_string_t autoneg;
7280         cmdline_fixed_string_t hw_str;
7281         uint32_t high_water;
7282         cmdline_fixed_string_t lw_str;
7283         uint32_t low_water;
7284         cmdline_fixed_string_t pt_str;
7285         uint16_t pause_time;
7286         cmdline_fixed_string_t xon_str;
7287         uint16_t send_xon;
7288         portid_t port_id;
7289 };
7290
7291 cmdline_parse_token_string_t cmd_lfc_set_set =
7292         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7293                                 set, "set");
7294 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7295         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7296                                 flow_ctrl, "flow_ctrl");
7297 cmdline_parse_token_string_t cmd_lfc_set_rx =
7298         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7299                                 rx, "rx");
7300 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7301         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7302                                 rx_lfc_mode, "on#off");
7303 cmdline_parse_token_string_t cmd_lfc_set_tx =
7304         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7305                                 tx, "tx");
7306 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7307         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7308                                 tx_lfc_mode, "on#off");
7309 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7310         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7311                                 hw_str, "high_water");
7312 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7313         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7314                                 high_water, RTE_UINT32);
7315 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7316         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7317                                 lw_str, "low_water");
7318 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7319         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7320                                 low_water, RTE_UINT32);
7321 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7322         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7323                                 pt_str, "pause_time");
7324 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7325         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7326                                 pause_time, RTE_UINT16);
7327 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7328         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7329                                 xon_str, "send_xon");
7330 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7331         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7332                                 send_xon, RTE_UINT16);
7333 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7334         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7335                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7336 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7337         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7338                                 mac_ctrl_frame_fwd_mode, "on#off");
7339 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7340         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7341                                 autoneg_str, "autoneg");
7342 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7343         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7344                                 autoneg, "on#off");
7345 cmdline_parse_token_num_t cmd_lfc_set_portid =
7346         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7347                                 port_id, RTE_UINT16);
7348
7349 /* forward declaration */
7350 static void
7351 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7352                               void *data);
7353
7354 cmdline_parse_inst_t cmd_link_flow_control_set = {
7355         .f = cmd_link_flow_ctrl_set_parsed,
7356         .data = NULL,
7357         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7358                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7359                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7360         .tokens = {
7361                 (void *)&cmd_lfc_set_set,
7362                 (void *)&cmd_lfc_set_flow_ctrl,
7363                 (void *)&cmd_lfc_set_rx,
7364                 (void *)&cmd_lfc_set_rx_mode,
7365                 (void *)&cmd_lfc_set_tx,
7366                 (void *)&cmd_lfc_set_tx_mode,
7367                 (void *)&cmd_lfc_set_high_water,
7368                 (void *)&cmd_lfc_set_low_water,
7369                 (void *)&cmd_lfc_set_pause_time,
7370                 (void *)&cmd_lfc_set_send_xon,
7371                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7372                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7373                 (void *)&cmd_lfc_set_autoneg_str,
7374                 (void *)&cmd_lfc_set_autoneg,
7375                 (void *)&cmd_lfc_set_portid,
7376                 NULL,
7377         },
7378 };
7379
7380 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7381         .f = cmd_link_flow_ctrl_set_parsed,
7382         .data = (void *)&cmd_link_flow_control_set_rx,
7383         .help_str = "set flow_ctrl rx on|off <port_id>: "
7384                 "Change rx flow control parameter",
7385         .tokens = {
7386                 (void *)&cmd_lfc_set_set,
7387                 (void *)&cmd_lfc_set_flow_ctrl,
7388                 (void *)&cmd_lfc_set_rx,
7389                 (void *)&cmd_lfc_set_rx_mode,
7390                 (void *)&cmd_lfc_set_portid,
7391                 NULL,
7392         },
7393 };
7394
7395 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7396         .f = cmd_link_flow_ctrl_set_parsed,
7397         .data = (void *)&cmd_link_flow_control_set_tx,
7398         .help_str = "set flow_ctrl tx on|off <port_id>: "
7399                 "Change tx flow control parameter",
7400         .tokens = {
7401                 (void *)&cmd_lfc_set_set,
7402                 (void *)&cmd_lfc_set_flow_ctrl,
7403                 (void *)&cmd_lfc_set_tx,
7404                 (void *)&cmd_lfc_set_tx_mode,
7405                 (void *)&cmd_lfc_set_portid,
7406                 NULL,
7407         },
7408 };
7409
7410 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7411         .f = cmd_link_flow_ctrl_set_parsed,
7412         .data = (void *)&cmd_link_flow_control_set_hw,
7413         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7414                 "Change high water flow control parameter",
7415         .tokens = {
7416                 (void *)&cmd_lfc_set_set,
7417                 (void *)&cmd_lfc_set_flow_ctrl,
7418                 (void *)&cmd_lfc_set_high_water_str,
7419                 (void *)&cmd_lfc_set_high_water,
7420                 (void *)&cmd_lfc_set_portid,
7421                 NULL,
7422         },
7423 };
7424
7425 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7426         .f = cmd_link_flow_ctrl_set_parsed,
7427         .data = (void *)&cmd_link_flow_control_set_lw,
7428         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7429                 "Change low water flow control parameter",
7430         .tokens = {
7431                 (void *)&cmd_lfc_set_set,
7432                 (void *)&cmd_lfc_set_flow_ctrl,
7433                 (void *)&cmd_lfc_set_low_water_str,
7434                 (void *)&cmd_lfc_set_low_water,
7435                 (void *)&cmd_lfc_set_portid,
7436                 NULL,
7437         },
7438 };
7439
7440 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7441         .f = cmd_link_flow_ctrl_set_parsed,
7442         .data = (void *)&cmd_link_flow_control_set_pt,
7443         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7444                 "Change pause time flow control parameter",
7445         .tokens = {
7446                 (void *)&cmd_lfc_set_set,
7447                 (void *)&cmd_lfc_set_flow_ctrl,
7448                 (void *)&cmd_lfc_set_pause_time_str,
7449                 (void *)&cmd_lfc_set_pause_time,
7450                 (void *)&cmd_lfc_set_portid,
7451                 NULL,
7452         },
7453 };
7454
7455 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7456         .f = cmd_link_flow_ctrl_set_parsed,
7457         .data = (void *)&cmd_link_flow_control_set_xon,
7458         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7459                 "Change send_xon flow control parameter",
7460         .tokens = {
7461                 (void *)&cmd_lfc_set_set,
7462                 (void *)&cmd_lfc_set_flow_ctrl,
7463                 (void *)&cmd_lfc_set_send_xon_str,
7464                 (void *)&cmd_lfc_set_send_xon,
7465                 (void *)&cmd_lfc_set_portid,
7466                 NULL,
7467         },
7468 };
7469
7470 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7471         .f = cmd_link_flow_ctrl_set_parsed,
7472         .data = (void *)&cmd_link_flow_control_set_macfwd,
7473         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7474                 "Change mac ctrl fwd flow control parameter",
7475         .tokens = {
7476                 (void *)&cmd_lfc_set_set,
7477                 (void *)&cmd_lfc_set_flow_ctrl,
7478                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7479                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7480                 (void *)&cmd_lfc_set_portid,
7481                 NULL,
7482         },
7483 };
7484
7485 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7486         .f = cmd_link_flow_ctrl_set_parsed,
7487         .data = (void *)&cmd_link_flow_control_set_autoneg,
7488         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7489                 "Change autoneg flow control parameter",
7490         .tokens = {
7491                 (void *)&cmd_lfc_set_set,
7492                 (void *)&cmd_lfc_set_flow_ctrl,
7493                 (void *)&cmd_lfc_set_autoneg_str,
7494                 (void *)&cmd_lfc_set_autoneg,
7495                 (void *)&cmd_lfc_set_portid,
7496                 NULL,
7497         },
7498 };
7499
7500 static void
7501 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7502                               __rte_unused struct cmdline *cl,
7503                               void *data)
7504 {
7505         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7506         cmdline_parse_inst_t *cmd = data;
7507         struct rte_eth_fc_conf fc_conf;
7508         int rx_fc_en = 0;
7509         int tx_fc_en = 0;
7510         int ret;
7511
7512         /*
7513          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7514          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7515          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7516          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7517          */
7518         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7519                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7520         };
7521
7522         /* Partial command line, retrieve current configuration */
7523         if (cmd) {
7524                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7525                 if (ret != 0) {
7526                         fprintf(stderr,
7527                                 "cannot get current flow ctrl parameters, return code = %d\n",
7528                                 ret);
7529                         return;
7530                 }
7531
7532                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7533                     (fc_conf.mode == RTE_FC_FULL))
7534                         rx_fc_en = 1;
7535                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7536                     (fc_conf.mode == RTE_FC_FULL))
7537                         tx_fc_en = 1;
7538         }
7539
7540         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7541                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7542
7543         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7544                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7545
7546         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7547
7548         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7549                 fc_conf.high_water = res->high_water;
7550
7551         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7552                 fc_conf.low_water = res->low_water;
7553
7554         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7555                 fc_conf.pause_time = res->pause_time;
7556
7557         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7558                 fc_conf.send_xon = res->send_xon;
7559
7560         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7561                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7562                         fc_conf.mac_ctrl_frame_fwd = 1;
7563                 else
7564                         fc_conf.mac_ctrl_frame_fwd = 0;
7565         }
7566
7567         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7568                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7569
7570         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7571         if (ret != 0)
7572                 fprintf(stderr,
7573                         "bad flow control parameter, return code = %d\n",
7574                         ret);
7575 }
7576
7577 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7578 struct cmd_priority_flow_ctrl_set_result {
7579         cmdline_fixed_string_t set;
7580         cmdline_fixed_string_t pfc_ctrl;
7581         cmdline_fixed_string_t rx;
7582         cmdline_fixed_string_t rx_pfc_mode;
7583         cmdline_fixed_string_t tx;
7584         cmdline_fixed_string_t tx_pfc_mode;
7585         uint32_t high_water;
7586         uint32_t low_water;
7587         uint16_t pause_time;
7588         uint8_t  priority;
7589         portid_t port_id;
7590 };
7591
7592 static void
7593 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7594                        __rte_unused struct cmdline *cl,
7595                        __rte_unused void *data)
7596 {
7597         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7598         struct rte_eth_pfc_conf pfc_conf;
7599         int rx_fc_enable, tx_fc_enable;
7600         int ret;
7601
7602         /*
7603          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7604          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7605          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7606          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7607          */
7608         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7609                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7610         };
7611
7612         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7613         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7614         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7615         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7616         pfc_conf.fc.high_water = res->high_water;
7617         pfc_conf.fc.low_water  = res->low_water;
7618         pfc_conf.fc.pause_time = res->pause_time;
7619         pfc_conf.priority      = res->priority;
7620
7621         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7622         if (ret != 0)
7623                 fprintf(stderr,
7624                         "bad priority flow control parameter, return code = %d\n",
7625                         ret);
7626 }
7627
7628 cmdline_parse_token_string_t cmd_pfc_set_set =
7629         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7630                                 set, "set");
7631 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7632         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7633                                 pfc_ctrl, "pfc_ctrl");
7634 cmdline_parse_token_string_t cmd_pfc_set_rx =
7635         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7636                                 rx, "rx");
7637 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7638         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7639                                 rx_pfc_mode, "on#off");
7640 cmdline_parse_token_string_t cmd_pfc_set_tx =
7641         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7642                                 tx, "tx");
7643 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7644         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7645                                 tx_pfc_mode, "on#off");
7646 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7647         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7648                                 high_water, RTE_UINT32);
7649 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7650         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7651                                 low_water, RTE_UINT32);
7652 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7653         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7654                                 pause_time, RTE_UINT16);
7655 cmdline_parse_token_num_t cmd_pfc_set_priority =
7656         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7657                                 priority, RTE_UINT8);
7658 cmdline_parse_token_num_t cmd_pfc_set_portid =
7659         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7660                                 port_id, RTE_UINT16);
7661
7662 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7663         .f = cmd_priority_flow_ctrl_set_parsed,
7664         .data = NULL,
7665         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7666                 "<pause_time> <priority> <port_id>: "
7667                 "Configure the Ethernet priority flow control",
7668         .tokens = {
7669                 (void *)&cmd_pfc_set_set,
7670                 (void *)&cmd_pfc_set_flow_ctrl,
7671                 (void *)&cmd_pfc_set_rx,
7672                 (void *)&cmd_pfc_set_rx_mode,
7673                 (void *)&cmd_pfc_set_tx,
7674                 (void *)&cmd_pfc_set_tx_mode,
7675                 (void *)&cmd_pfc_set_high_water,
7676                 (void *)&cmd_pfc_set_low_water,
7677                 (void *)&cmd_pfc_set_pause_time,
7678                 (void *)&cmd_pfc_set_priority,
7679                 (void *)&cmd_pfc_set_portid,
7680                 NULL,
7681         },
7682 };
7683
7684 /* *** RESET CONFIGURATION *** */
7685 struct cmd_reset_result {
7686         cmdline_fixed_string_t reset;
7687         cmdline_fixed_string_t def;
7688 };
7689
7690 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7691                              struct cmdline *cl,
7692                              __rte_unused void *data)
7693 {
7694         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7695         set_def_fwd_config();
7696 }
7697
7698 cmdline_parse_token_string_t cmd_reset_set =
7699         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7700 cmdline_parse_token_string_t cmd_reset_def =
7701         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7702                                  "default");
7703
7704 cmdline_parse_inst_t cmd_reset = {
7705         .f = cmd_reset_parsed,
7706         .data = NULL,
7707         .help_str = "set default: Reset default forwarding configuration",
7708         .tokens = {
7709                 (void *)&cmd_reset_set,
7710                 (void *)&cmd_reset_def,
7711                 NULL,
7712         },
7713 };
7714
7715 /* *** START FORWARDING *** */
7716 struct cmd_start_result {
7717         cmdline_fixed_string_t start;
7718 };
7719
7720 cmdline_parse_token_string_t cmd_start_start =
7721         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7722
7723 static void cmd_start_parsed(__rte_unused void *parsed_result,
7724                              __rte_unused struct cmdline *cl,
7725                              __rte_unused void *data)
7726 {
7727         start_packet_forwarding(0);
7728 }
7729
7730 cmdline_parse_inst_t cmd_start = {
7731         .f = cmd_start_parsed,
7732         .data = NULL,
7733         .help_str = "start: Start packet forwarding",
7734         .tokens = {
7735                 (void *)&cmd_start_start,
7736                 NULL,
7737         },
7738 };
7739
7740 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7741 struct cmd_start_tx_first_result {
7742         cmdline_fixed_string_t start;
7743         cmdline_fixed_string_t tx_first;
7744 };
7745
7746 static void
7747 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7748                           __rte_unused struct cmdline *cl,
7749                           __rte_unused void *data)
7750 {
7751         start_packet_forwarding(1);
7752 }
7753
7754 cmdline_parse_token_string_t cmd_start_tx_first_start =
7755         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7756                                  "start");
7757 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7758         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7759                                  tx_first, "tx_first");
7760
7761 cmdline_parse_inst_t cmd_start_tx_first = {
7762         .f = cmd_start_tx_first_parsed,
7763         .data = NULL,
7764         .help_str = "start tx_first: Start packet forwarding, "
7765                 "after sending 1 burst of packets",
7766         .tokens = {
7767                 (void *)&cmd_start_tx_first_start,
7768                 (void *)&cmd_start_tx_first_tx_first,
7769                 NULL,
7770         },
7771 };
7772
7773 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7774 struct cmd_start_tx_first_n_result {
7775         cmdline_fixed_string_t start;
7776         cmdline_fixed_string_t tx_first;
7777         uint32_t tx_num;
7778 };
7779
7780 static void
7781 cmd_start_tx_first_n_parsed(void *parsed_result,
7782                           __rte_unused struct cmdline *cl,
7783                           __rte_unused void *data)
7784 {
7785         struct cmd_start_tx_first_n_result *res = parsed_result;
7786
7787         start_packet_forwarding(res->tx_num);
7788 }
7789
7790 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7791         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7792                         start, "start");
7793 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7794         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7795                         tx_first, "tx_first");
7796 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7797         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7798                         tx_num, RTE_UINT32);
7799
7800 cmdline_parse_inst_t cmd_start_tx_first_n = {
7801         .f = cmd_start_tx_first_n_parsed,
7802         .data = NULL,
7803         .help_str = "start tx_first <num>: "
7804                 "packet forwarding, after sending <num> bursts of packets",
7805         .tokens = {
7806                 (void *)&cmd_start_tx_first_n_start,
7807                 (void *)&cmd_start_tx_first_n_tx_first,
7808                 (void *)&cmd_start_tx_first_n_tx_num,
7809                 NULL,
7810         },
7811 };
7812
7813 /* *** SET LINK UP *** */
7814 struct cmd_set_link_up_result {
7815         cmdline_fixed_string_t set;
7816         cmdline_fixed_string_t link_up;
7817         cmdline_fixed_string_t port;
7818         portid_t port_id;
7819 };
7820
7821 cmdline_parse_token_string_t cmd_set_link_up_set =
7822         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7823 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7824         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7825                                 "link-up");
7826 cmdline_parse_token_string_t cmd_set_link_up_port =
7827         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7828 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7829         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7830                                 RTE_UINT16);
7831
7832 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7833                              __rte_unused struct cmdline *cl,
7834                              __rte_unused void *data)
7835 {
7836         struct cmd_set_link_up_result *res = parsed_result;
7837         dev_set_link_up(res->port_id);
7838 }
7839
7840 cmdline_parse_inst_t cmd_set_link_up = {
7841         .f = cmd_set_link_up_parsed,
7842         .data = NULL,
7843         .help_str = "set link-up port <port id>",
7844         .tokens = {
7845                 (void *)&cmd_set_link_up_set,
7846                 (void *)&cmd_set_link_up_link_up,
7847                 (void *)&cmd_set_link_up_port,
7848                 (void *)&cmd_set_link_up_port_id,
7849                 NULL,
7850         },
7851 };
7852
7853 /* *** SET LINK DOWN *** */
7854 struct cmd_set_link_down_result {
7855         cmdline_fixed_string_t set;
7856         cmdline_fixed_string_t link_down;
7857         cmdline_fixed_string_t port;
7858         portid_t port_id;
7859 };
7860
7861 cmdline_parse_token_string_t cmd_set_link_down_set =
7862         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7863 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7864         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7865                                 "link-down");
7866 cmdline_parse_token_string_t cmd_set_link_down_port =
7867         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7868 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7869         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7870                                 RTE_UINT16);
7871
7872 static void cmd_set_link_down_parsed(
7873                                 __rte_unused void *parsed_result,
7874                                 __rte_unused struct cmdline *cl,
7875                                 __rte_unused void *data)
7876 {
7877         struct cmd_set_link_down_result *res = parsed_result;
7878         dev_set_link_down(res->port_id);
7879 }
7880
7881 cmdline_parse_inst_t cmd_set_link_down = {
7882         .f = cmd_set_link_down_parsed,
7883         .data = NULL,
7884         .help_str = "set link-down port <port id>",
7885         .tokens = {
7886                 (void *)&cmd_set_link_down_set,
7887                 (void *)&cmd_set_link_down_link_down,
7888                 (void *)&cmd_set_link_down_port,
7889                 (void *)&cmd_set_link_down_port_id,
7890                 NULL,
7891         },
7892 };
7893
7894 /* *** SHOW CFG *** */
7895 struct cmd_showcfg_result {
7896         cmdline_fixed_string_t show;
7897         cmdline_fixed_string_t cfg;
7898         cmdline_fixed_string_t what;
7899 };
7900
7901 static void cmd_showcfg_parsed(void *parsed_result,
7902                                __rte_unused struct cmdline *cl,
7903                                __rte_unused void *data)
7904 {
7905         struct cmd_showcfg_result *res = parsed_result;
7906         if (!strcmp(res->what, "rxtx"))
7907                 rxtx_config_display();
7908         else if (!strcmp(res->what, "cores"))
7909                 fwd_lcores_config_display();
7910         else if (!strcmp(res->what, "fwd"))
7911                 pkt_fwd_config_display(&cur_fwd_config);
7912         else if (!strcmp(res->what, "rxoffs"))
7913                 show_rx_pkt_offsets();
7914         else if (!strcmp(res->what, "rxpkts"))
7915                 show_rx_pkt_segments();
7916         else if (!strcmp(res->what, "txpkts"))
7917                 show_tx_pkt_segments();
7918         else if (!strcmp(res->what, "txtimes"))
7919                 show_tx_pkt_times();
7920 }
7921
7922 cmdline_parse_token_string_t cmd_showcfg_show =
7923         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7924 cmdline_parse_token_string_t cmd_showcfg_port =
7925         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7926 cmdline_parse_token_string_t cmd_showcfg_what =
7927         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7928                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7929
7930 cmdline_parse_inst_t cmd_showcfg = {
7931         .f = cmd_showcfg_parsed,
7932         .data = NULL,
7933         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7934         .tokens = {
7935                 (void *)&cmd_showcfg_show,
7936                 (void *)&cmd_showcfg_port,
7937                 (void *)&cmd_showcfg_what,
7938                 NULL,
7939         },
7940 };
7941
7942 /* *** SHOW ALL PORT INFO *** */
7943 struct cmd_showportall_result {
7944         cmdline_fixed_string_t show;
7945         cmdline_fixed_string_t port;
7946         cmdline_fixed_string_t what;
7947         cmdline_fixed_string_t all;
7948 };
7949
7950 static void cmd_showportall_parsed(void *parsed_result,
7951                                 __rte_unused struct cmdline *cl,
7952                                 __rte_unused void *data)
7953 {
7954         portid_t i;
7955
7956         struct cmd_showportall_result *res = parsed_result;
7957         if (!strcmp(res->show, "clear")) {
7958                 if (!strcmp(res->what, "stats"))
7959                         RTE_ETH_FOREACH_DEV(i)
7960                                 nic_stats_clear(i);
7961                 else if (!strcmp(res->what, "xstats"))
7962                         RTE_ETH_FOREACH_DEV(i)
7963                                 nic_xstats_clear(i);
7964         } else if (!strcmp(res->what, "info"))
7965                 RTE_ETH_FOREACH_DEV(i)
7966                         port_infos_display(i);
7967         else if (!strcmp(res->what, "summary")) {
7968                 port_summary_header_display();
7969                 RTE_ETH_FOREACH_DEV(i)
7970                         port_summary_display(i);
7971         }
7972         else if (!strcmp(res->what, "stats"))
7973                 RTE_ETH_FOREACH_DEV(i)
7974                         nic_stats_display(i);
7975         else if (!strcmp(res->what, "xstats"))
7976                 RTE_ETH_FOREACH_DEV(i)
7977                         nic_xstats_display(i);
7978 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7979         else if (!strcmp(res->what, "fdir"))
7980                 RTE_ETH_FOREACH_DEV(i)
7981                         fdir_get_infos(i);
7982 #endif
7983         else if (!strcmp(res->what, "dcb_tc"))
7984                 RTE_ETH_FOREACH_DEV(i)
7985                         port_dcb_info_display(i);
7986 }
7987
7988 cmdline_parse_token_string_t cmd_showportall_show =
7989         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7990                                  "show#clear");
7991 cmdline_parse_token_string_t cmd_showportall_port =
7992         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7993 cmdline_parse_token_string_t cmd_showportall_what =
7994         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7995                                  "info#summary#stats#xstats#fdir#dcb_tc");
7996 cmdline_parse_token_string_t cmd_showportall_all =
7997         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7998 cmdline_parse_inst_t cmd_showportall = {
7999         .f = cmd_showportall_parsed,
8000         .data = NULL,
8001         .help_str = "show|clear port "
8002                 "info|summary|stats|xstats|fdir|dcb_tc all",
8003         .tokens = {
8004                 (void *)&cmd_showportall_show,
8005                 (void *)&cmd_showportall_port,
8006                 (void *)&cmd_showportall_what,
8007                 (void *)&cmd_showportall_all,
8008                 NULL,
8009         },
8010 };
8011
8012 /* *** SHOW PORT INFO *** */
8013 struct cmd_showport_result {
8014         cmdline_fixed_string_t show;
8015         cmdline_fixed_string_t port;
8016         cmdline_fixed_string_t what;
8017         uint16_t portnum;
8018 };
8019
8020 static void cmd_showport_parsed(void *parsed_result,
8021                                 __rte_unused struct cmdline *cl,
8022                                 __rte_unused void *data)
8023 {
8024         struct cmd_showport_result *res = parsed_result;
8025         if (!strcmp(res->show, "clear")) {
8026                 if (!strcmp(res->what, "stats"))
8027                         nic_stats_clear(res->portnum);
8028                 else if (!strcmp(res->what, "xstats"))
8029                         nic_xstats_clear(res->portnum);
8030         } else if (!strcmp(res->what, "info"))
8031                 port_infos_display(res->portnum);
8032         else if (!strcmp(res->what, "summary")) {
8033                 port_summary_header_display();
8034                 port_summary_display(res->portnum);
8035         }
8036         else if (!strcmp(res->what, "stats"))
8037                 nic_stats_display(res->portnum);
8038         else if (!strcmp(res->what, "xstats"))
8039                 nic_xstats_display(res->portnum);
8040 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8041         else if (!strcmp(res->what, "fdir"))
8042                  fdir_get_infos(res->portnum);
8043 #endif
8044         else if (!strcmp(res->what, "dcb_tc"))
8045                 port_dcb_info_display(res->portnum);
8046 }
8047
8048 cmdline_parse_token_string_t cmd_showport_show =
8049         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8050                                  "show#clear");
8051 cmdline_parse_token_string_t cmd_showport_port =
8052         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8053 cmdline_parse_token_string_t cmd_showport_what =
8054         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8055                                  "info#summary#stats#xstats#fdir#dcb_tc");
8056 cmdline_parse_token_num_t cmd_showport_portnum =
8057         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8058
8059 cmdline_parse_inst_t cmd_showport = {
8060         .f = cmd_showport_parsed,
8061         .data = NULL,
8062         .help_str = "show|clear port "
8063                 "info|summary|stats|xstats|fdir|dcb_tc "
8064                 "<port_id>",
8065         .tokens = {
8066                 (void *)&cmd_showport_show,
8067                 (void *)&cmd_showport_port,
8068                 (void *)&cmd_showport_what,
8069                 (void *)&cmd_showport_portnum,
8070                 NULL,
8071         },
8072 };
8073
8074 /* *** SHOW DEVICE INFO *** */
8075 struct cmd_showdevice_result {
8076         cmdline_fixed_string_t show;
8077         cmdline_fixed_string_t device;
8078         cmdline_fixed_string_t what;
8079         cmdline_fixed_string_t identifier;
8080 };
8081
8082 static void cmd_showdevice_parsed(void *parsed_result,
8083                                 __rte_unused struct cmdline *cl,
8084                                 __rte_unused void *data)
8085 {
8086         struct cmd_showdevice_result *res = parsed_result;
8087         if (!strcmp(res->what, "info")) {
8088                 if (!strcmp(res->identifier, "all"))
8089                         device_infos_display(NULL);
8090                 else
8091                         device_infos_display(res->identifier);
8092         }
8093 }
8094
8095 cmdline_parse_token_string_t cmd_showdevice_show =
8096         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8097                                  "show");
8098 cmdline_parse_token_string_t cmd_showdevice_device =
8099         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8100 cmdline_parse_token_string_t cmd_showdevice_what =
8101         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8102                                  "info");
8103 cmdline_parse_token_string_t cmd_showdevice_identifier =
8104         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8105                         identifier, NULL);
8106
8107 cmdline_parse_inst_t cmd_showdevice = {
8108         .f = cmd_showdevice_parsed,
8109         .data = NULL,
8110         .help_str = "show device info <identifier>|all",
8111         .tokens = {
8112                 (void *)&cmd_showdevice_show,
8113                 (void *)&cmd_showdevice_device,
8114                 (void *)&cmd_showdevice_what,
8115                 (void *)&cmd_showdevice_identifier,
8116                 NULL,
8117         },
8118 };
8119
8120 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8121 struct cmd_showeeprom_result {
8122         cmdline_fixed_string_t show;
8123         cmdline_fixed_string_t port;
8124         uint16_t portnum;
8125         cmdline_fixed_string_t type;
8126 };
8127
8128 static void cmd_showeeprom_parsed(void *parsed_result,
8129                 __rte_unused struct cmdline *cl,
8130                 __rte_unused void *data)
8131 {
8132         struct cmd_showeeprom_result *res = parsed_result;
8133
8134         if (!strcmp(res->type, "eeprom"))
8135                 port_eeprom_display(res->portnum);
8136         else if (!strcmp(res->type, "module_eeprom"))
8137                 port_module_eeprom_display(res->portnum);
8138         else
8139                 fprintf(stderr, "Unknown argument\n");
8140 }
8141
8142 cmdline_parse_token_string_t cmd_showeeprom_show =
8143         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8144 cmdline_parse_token_string_t cmd_showeeprom_port =
8145         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8146 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8147         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8148                         RTE_UINT16);
8149 cmdline_parse_token_string_t cmd_showeeprom_type =
8150         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8151
8152 cmdline_parse_inst_t cmd_showeeprom = {
8153         .f = cmd_showeeprom_parsed,
8154         .data = NULL,
8155         .help_str = "show port <port_id> module_eeprom|eeprom",
8156         .tokens = {
8157                 (void *)&cmd_showeeprom_show,
8158                 (void *)&cmd_showeeprom_port,
8159                 (void *)&cmd_showeeprom_portnum,
8160                 (void *)&cmd_showeeprom_type,
8161                 NULL,
8162         },
8163 };
8164
8165 /* *** SHOW QUEUE INFO *** */
8166 struct cmd_showqueue_result {
8167         cmdline_fixed_string_t show;
8168         cmdline_fixed_string_t type;
8169         cmdline_fixed_string_t what;
8170         uint16_t portnum;
8171         uint16_t queuenum;
8172 };
8173
8174 static void
8175 cmd_showqueue_parsed(void *parsed_result,
8176         __rte_unused struct cmdline *cl,
8177         __rte_unused void *data)
8178 {
8179         struct cmd_showqueue_result *res = parsed_result;
8180
8181         if (!strcmp(res->type, "rxq"))
8182                 rx_queue_infos_display(res->portnum, res->queuenum);
8183         else if (!strcmp(res->type, "txq"))
8184                 tx_queue_infos_display(res->portnum, res->queuenum);
8185 }
8186
8187 cmdline_parse_token_string_t cmd_showqueue_show =
8188         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8189 cmdline_parse_token_string_t cmd_showqueue_type =
8190         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8191 cmdline_parse_token_string_t cmd_showqueue_what =
8192         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8193 cmdline_parse_token_num_t cmd_showqueue_portnum =
8194         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8195                 RTE_UINT16);
8196 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8197         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8198                 RTE_UINT16);
8199
8200 cmdline_parse_inst_t cmd_showqueue = {
8201         .f = cmd_showqueue_parsed,
8202         .data = NULL,
8203         .help_str = "show rxq|txq info <port_id> <queue_id>",
8204         .tokens = {
8205                 (void *)&cmd_showqueue_show,
8206                 (void *)&cmd_showqueue_type,
8207                 (void *)&cmd_showqueue_what,
8208                 (void *)&cmd_showqueue_portnum,
8209                 (void *)&cmd_showqueue_queuenum,
8210                 NULL,
8211         },
8212 };
8213
8214 /* show/clear fwd engine statistics */
8215 struct fwd_result {
8216         cmdline_fixed_string_t action;
8217         cmdline_fixed_string_t fwd;
8218         cmdline_fixed_string_t stats;
8219         cmdline_fixed_string_t all;
8220 };
8221
8222 cmdline_parse_token_string_t cmd_fwd_action =
8223         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8224 cmdline_parse_token_string_t cmd_fwd_fwd =
8225         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8226 cmdline_parse_token_string_t cmd_fwd_stats =
8227         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8228 cmdline_parse_token_string_t cmd_fwd_all =
8229         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8230
8231 static void
8232 cmd_showfwdall_parsed(void *parsed_result,
8233                       __rte_unused struct cmdline *cl,
8234                       __rte_unused void *data)
8235 {
8236         struct fwd_result *res = parsed_result;
8237
8238         if (!strcmp(res->action, "show"))
8239                 fwd_stats_display();
8240         else
8241                 fwd_stats_reset();
8242 }
8243
8244 static cmdline_parse_inst_t cmd_showfwdall = {
8245         .f = cmd_showfwdall_parsed,
8246         .data = NULL,
8247         .help_str = "show|clear fwd stats all",
8248         .tokens = {
8249                 (void *)&cmd_fwd_action,
8250                 (void *)&cmd_fwd_fwd,
8251                 (void *)&cmd_fwd_stats,
8252                 (void *)&cmd_fwd_all,
8253                 NULL,
8254         },
8255 };
8256
8257 /* *** READ PORT REGISTER *** */
8258 struct cmd_read_reg_result {
8259         cmdline_fixed_string_t read;
8260         cmdline_fixed_string_t reg;
8261         portid_t port_id;
8262         uint32_t reg_off;
8263 };
8264
8265 static void
8266 cmd_read_reg_parsed(void *parsed_result,
8267                     __rte_unused struct cmdline *cl,
8268                     __rte_unused void *data)
8269 {
8270         struct cmd_read_reg_result *res = parsed_result;
8271         port_reg_display(res->port_id, res->reg_off);
8272 }
8273
8274 cmdline_parse_token_string_t cmd_read_reg_read =
8275         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8276 cmdline_parse_token_string_t cmd_read_reg_reg =
8277         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8278 cmdline_parse_token_num_t cmd_read_reg_port_id =
8279         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8280 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8281         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8282
8283 cmdline_parse_inst_t cmd_read_reg = {
8284         .f = cmd_read_reg_parsed,
8285         .data = NULL,
8286         .help_str = "read reg <port_id> <reg_off>",
8287         .tokens = {
8288                 (void *)&cmd_read_reg_read,
8289                 (void *)&cmd_read_reg_reg,
8290                 (void *)&cmd_read_reg_port_id,
8291                 (void *)&cmd_read_reg_reg_off,
8292                 NULL,
8293         },
8294 };
8295
8296 /* *** READ PORT REGISTER BIT FIELD *** */
8297 struct cmd_read_reg_bit_field_result {
8298         cmdline_fixed_string_t read;
8299         cmdline_fixed_string_t regfield;
8300         portid_t port_id;
8301         uint32_t reg_off;
8302         uint8_t bit1_pos;
8303         uint8_t bit2_pos;
8304 };
8305
8306 static void
8307 cmd_read_reg_bit_field_parsed(void *parsed_result,
8308                               __rte_unused struct cmdline *cl,
8309                               __rte_unused void *data)
8310 {
8311         struct cmd_read_reg_bit_field_result *res = parsed_result;
8312         port_reg_bit_field_display(res->port_id, res->reg_off,
8313                                    res->bit1_pos, res->bit2_pos);
8314 }
8315
8316 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8317         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8318                                  "read");
8319 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8320         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8321                                  regfield, "regfield");
8322 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8323         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8324                               RTE_UINT16);
8325 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8326         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8327                               RTE_UINT32);
8328 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8329         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8330                               RTE_UINT8);
8331 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8332         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8333                               RTE_UINT8);
8334
8335 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8336         .f = cmd_read_reg_bit_field_parsed,
8337         .data = NULL,
8338         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8339         "Read register bit field between bit_x and bit_y included",
8340         .tokens = {
8341                 (void *)&cmd_read_reg_bit_field_read,
8342                 (void *)&cmd_read_reg_bit_field_regfield,
8343                 (void *)&cmd_read_reg_bit_field_port_id,
8344                 (void *)&cmd_read_reg_bit_field_reg_off,
8345                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8346                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8347                 NULL,
8348         },
8349 };
8350
8351 /* *** READ PORT REGISTER BIT *** */
8352 struct cmd_read_reg_bit_result {
8353         cmdline_fixed_string_t read;
8354         cmdline_fixed_string_t regbit;
8355         portid_t port_id;
8356         uint32_t reg_off;
8357         uint8_t bit_pos;
8358 };
8359
8360 static void
8361 cmd_read_reg_bit_parsed(void *parsed_result,
8362                         __rte_unused struct cmdline *cl,
8363                         __rte_unused void *data)
8364 {
8365         struct cmd_read_reg_bit_result *res = parsed_result;
8366         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8367 }
8368
8369 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8370         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8371 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8372         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8373                                  regbit, "regbit");
8374 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8375         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8376                                  RTE_UINT16);
8377 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8378         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8379                                  RTE_UINT32);
8380 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8381         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8382                                  RTE_UINT8);
8383
8384 cmdline_parse_inst_t cmd_read_reg_bit = {
8385         .f = cmd_read_reg_bit_parsed,
8386         .data = NULL,
8387         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8388         .tokens = {
8389                 (void *)&cmd_read_reg_bit_read,
8390                 (void *)&cmd_read_reg_bit_regbit,
8391                 (void *)&cmd_read_reg_bit_port_id,
8392                 (void *)&cmd_read_reg_bit_reg_off,
8393                 (void *)&cmd_read_reg_bit_bit_pos,
8394                 NULL,
8395         },
8396 };
8397
8398 /* *** WRITE PORT REGISTER *** */
8399 struct cmd_write_reg_result {
8400         cmdline_fixed_string_t write;
8401         cmdline_fixed_string_t reg;
8402         portid_t port_id;
8403         uint32_t reg_off;
8404         uint32_t value;
8405 };
8406
8407 static void
8408 cmd_write_reg_parsed(void *parsed_result,
8409                      __rte_unused struct cmdline *cl,
8410                      __rte_unused void *data)
8411 {
8412         struct cmd_write_reg_result *res = parsed_result;
8413         port_reg_set(res->port_id, res->reg_off, res->value);
8414 }
8415
8416 cmdline_parse_token_string_t cmd_write_reg_write =
8417         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8418 cmdline_parse_token_string_t cmd_write_reg_reg =
8419         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8420 cmdline_parse_token_num_t cmd_write_reg_port_id =
8421         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8422 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8423         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8424 cmdline_parse_token_num_t cmd_write_reg_value =
8425         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8426
8427 cmdline_parse_inst_t cmd_write_reg = {
8428         .f = cmd_write_reg_parsed,
8429         .data = NULL,
8430         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8431         .tokens = {
8432                 (void *)&cmd_write_reg_write,
8433                 (void *)&cmd_write_reg_reg,
8434                 (void *)&cmd_write_reg_port_id,
8435                 (void *)&cmd_write_reg_reg_off,
8436                 (void *)&cmd_write_reg_value,
8437                 NULL,
8438         },
8439 };
8440
8441 /* *** WRITE PORT REGISTER BIT FIELD *** */
8442 struct cmd_write_reg_bit_field_result {
8443         cmdline_fixed_string_t write;
8444         cmdline_fixed_string_t regfield;
8445         portid_t port_id;
8446         uint32_t reg_off;
8447         uint8_t bit1_pos;
8448         uint8_t bit2_pos;
8449         uint32_t value;
8450 };
8451
8452 static void
8453 cmd_write_reg_bit_field_parsed(void *parsed_result,
8454                                __rte_unused struct cmdline *cl,
8455                                __rte_unused void *data)
8456 {
8457         struct cmd_write_reg_bit_field_result *res = parsed_result;
8458         port_reg_bit_field_set(res->port_id, res->reg_off,
8459                           res->bit1_pos, res->bit2_pos, res->value);
8460 }
8461
8462 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8463         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8464                                  "write");
8465 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8466         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8467                                  regfield, "regfield");
8468 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8469         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8470                               RTE_UINT16);
8471 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8472         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8473                               RTE_UINT32);
8474 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8475         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8476                               RTE_UINT8);
8477 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8478         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8479                               RTE_UINT8);
8480 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8481         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8482                               RTE_UINT32);
8483
8484 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8485         .f = cmd_write_reg_bit_field_parsed,
8486         .data = NULL,
8487         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8488                 "<reg_value>: "
8489                 "Set register bit field between bit_x and bit_y included",
8490         .tokens = {
8491                 (void *)&cmd_write_reg_bit_field_write,
8492                 (void *)&cmd_write_reg_bit_field_regfield,
8493                 (void *)&cmd_write_reg_bit_field_port_id,
8494                 (void *)&cmd_write_reg_bit_field_reg_off,
8495                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8496                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8497                 (void *)&cmd_write_reg_bit_field_value,
8498                 NULL,
8499         },
8500 };
8501
8502 /* *** WRITE PORT REGISTER BIT *** */
8503 struct cmd_write_reg_bit_result {
8504         cmdline_fixed_string_t write;
8505         cmdline_fixed_string_t regbit;
8506         portid_t port_id;
8507         uint32_t reg_off;
8508         uint8_t bit_pos;
8509         uint8_t value;
8510 };
8511
8512 static void
8513 cmd_write_reg_bit_parsed(void *parsed_result,
8514                          __rte_unused struct cmdline *cl,
8515                          __rte_unused void *data)
8516 {
8517         struct cmd_write_reg_bit_result *res = parsed_result;
8518         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8519 }
8520
8521 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8522         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8523                                  "write");
8524 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8525         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8526                                  regbit, "regbit");
8527 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8528         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8529                                  RTE_UINT16);
8530 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8531         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8532                                  RTE_UINT32);
8533 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8534         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8535                                  RTE_UINT8);
8536 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8537         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8538                                  RTE_UINT8);
8539
8540 cmdline_parse_inst_t cmd_write_reg_bit = {
8541         .f = cmd_write_reg_bit_parsed,
8542         .data = NULL,
8543         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8544                 "0 <= bit_x <= 31",
8545         .tokens = {
8546                 (void *)&cmd_write_reg_bit_write,
8547                 (void *)&cmd_write_reg_bit_regbit,
8548                 (void *)&cmd_write_reg_bit_port_id,
8549                 (void *)&cmd_write_reg_bit_reg_off,
8550                 (void *)&cmd_write_reg_bit_bit_pos,
8551                 (void *)&cmd_write_reg_bit_value,
8552                 NULL,
8553         },
8554 };
8555
8556 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8557 struct cmd_read_rxd_txd_result {
8558         cmdline_fixed_string_t read;
8559         cmdline_fixed_string_t rxd_txd;
8560         portid_t port_id;
8561         uint16_t queue_id;
8562         uint16_t desc_id;
8563 };
8564
8565 static void
8566 cmd_read_rxd_txd_parsed(void *parsed_result,
8567                         __rte_unused struct cmdline *cl,
8568                         __rte_unused void *data)
8569 {
8570         struct cmd_read_rxd_txd_result *res = parsed_result;
8571
8572         if (!strcmp(res->rxd_txd, "rxd"))
8573                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8574         else if (!strcmp(res->rxd_txd, "txd"))
8575                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8576 }
8577
8578 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8579         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8580 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8581         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8582                                  "rxd#txd");
8583 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8584         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8585                                  RTE_UINT16);
8586 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8587         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8588                                  RTE_UINT16);
8589 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8590         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8591                                  RTE_UINT16);
8592
8593 cmdline_parse_inst_t cmd_read_rxd_txd = {
8594         .f = cmd_read_rxd_txd_parsed,
8595         .data = NULL,
8596         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8597         .tokens = {
8598                 (void *)&cmd_read_rxd_txd_read,
8599                 (void *)&cmd_read_rxd_txd_rxd_txd,
8600                 (void *)&cmd_read_rxd_txd_port_id,
8601                 (void *)&cmd_read_rxd_txd_queue_id,
8602                 (void *)&cmd_read_rxd_txd_desc_id,
8603                 NULL,
8604         },
8605 };
8606
8607 /* *** QUIT *** */
8608 struct cmd_quit_result {
8609         cmdline_fixed_string_t quit;
8610 };
8611
8612 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8613                             struct cmdline *cl,
8614                             __rte_unused void *data)
8615 {
8616         cmdline_quit(cl);
8617 }
8618
8619 cmdline_parse_token_string_t cmd_quit_quit =
8620         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8621
8622 cmdline_parse_inst_t cmd_quit = {
8623         .f = cmd_quit_parsed,
8624         .data = NULL,
8625         .help_str = "quit: Exit application",
8626         .tokens = {
8627                 (void *)&cmd_quit_quit,
8628                 NULL,
8629         },
8630 };
8631
8632 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8633 struct cmd_mac_addr_result {
8634         cmdline_fixed_string_t mac_addr_cmd;
8635         cmdline_fixed_string_t what;
8636         uint16_t port_num;
8637         struct rte_ether_addr address;
8638 };
8639
8640 static void cmd_mac_addr_parsed(void *parsed_result,
8641                 __rte_unused struct cmdline *cl,
8642                 __rte_unused void *data)
8643 {
8644         struct cmd_mac_addr_result *res = parsed_result;
8645         int ret;
8646
8647         if (strcmp(res->what, "add") == 0)
8648                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8649         else if (strcmp(res->what, "set") == 0)
8650                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8651                                                        &res->address);
8652         else
8653                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8654
8655         /* check the return value and print it if is < 0 */
8656         if(ret < 0)
8657                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8658
8659 }
8660
8661 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8662         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8663                                 "mac_addr");
8664 cmdline_parse_token_string_t cmd_mac_addr_what =
8665         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8666                                 "add#remove#set");
8667 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8668                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8669                                         RTE_UINT16);
8670 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8671                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8672
8673 cmdline_parse_inst_t cmd_mac_addr = {
8674         .f = cmd_mac_addr_parsed,
8675         .data = (void *)0,
8676         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8677                         "Add/Remove/Set MAC address on port_id",
8678         .tokens = {
8679                 (void *)&cmd_mac_addr_cmd,
8680                 (void *)&cmd_mac_addr_what,
8681                 (void *)&cmd_mac_addr_portnum,
8682                 (void *)&cmd_mac_addr_addr,
8683                 NULL,
8684         },
8685 };
8686
8687 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8688 struct cmd_eth_peer_result {
8689         cmdline_fixed_string_t set;
8690         cmdline_fixed_string_t eth_peer;
8691         portid_t port_id;
8692         cmdline_fixed_string_t peer_addr;
8693 };
8694
8695 static void cmd_set_eth_peer_parsed(void *parsed_result,
8696                         __rte_unused struct cmdline *cl,
8697                         __rte_unused void *data)
8698 {
8699                 struct cmd_eth_peer_result *res = parsed_result;
8700
8701                 if (test_done == 0) {
8702                         fprintf(stderr, "Please stop forwarding first\n");
8703                         return;
8704                 }
8705                 if (!strcmp(res->eth_peer, "eth-peer")) {
8706                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8707                         fwd_config_setup();
8708                 }
8709 }
8710 cmdline_parse_token_string_t cmd_eth_peer_set =
8711         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8712 cmdline_parse_token_string_t cmd_eth_peer =
8713         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8714 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8715         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8716                 RTE_UINT16);
8717 cmdline_parse_token_string_t cmd_eth_peer_addr =
8718         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8719
8720 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8721         .f = cmd_set_eth_peer_parsed,
8722         .data = NULL,
8723         .help_str = "set eth-peer <port_id> <peer_mac>",
8724         .tokens = {
8725                 (void *)&cmd_eth_peer_set,
8726                 (void *)&cmd_eth_peer,
8727                 (void *)&cmd_eth_peer_port_id,
8728                 (void *)&cmd_eth_peer_addr,
8729                 NULL,
8730         },
8731 };
8732
8733 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8734 struct cmd_set_qmap_result {
8735         cmdline_fixed_string_t set;
8736         cmdline_fixed_string_t qmap;
8737         cmdline_fixed_string_t what;
8738         portid_t port_id;
8739         uint16_t queue_id;
8740         uint8_t map_value;
8741 };
8742
8743 static void
8744 cmd_set_qmap_parsed(void *parsed_result,
8745                        __rte_unused struct cmdline *cl,
8746                        __rte_unused void *data)
8747 {
8748         struct cmd_set_qmap_result *res = parsed_result;
8749         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8750
8751         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8752 }
8753
8754 cmdline_parse_token_string_t cmd_setqmap_set =
8755         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8756                                  set, "set");
8757 cmdline_parse_token_string_t cmd_setqmap_qmap =
8758         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8759                                  qmap, "stat_qmap");
8760 cmdline_parse_token_string_t cmd_setqmap_what =
8761         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8762                                  what, "tx#rx");
8763 cmdline_parse_token_num_t cmd_setqmap_portid =
8764         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8765                               port_id, RTE_UINT16);
8766 cmdline_parse_token_num_t cmd_setqmap_queueid =
8767         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8768                               queue_id, RTE_UINT16);
8769 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8770         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8771                               map_value, RTE_UINT8);
8772
8773 cmdline_parse_inst_t cmd_set_qmap = {
8774         .f = cmd_set_qmap_parsed,
8775         .data = NULL,
8776         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8777                 "Set statistics mapping value on tx|rx queue_id of port_id",
8778         .tokens = {
8779                 (void *)&cmd_setqmap_set,
8780                 (void *)&cmd_setqmap_qmap,
8781                 (void *)&cmd_setqmap_what,
8782                 (void *)&cmd_setqmap_portid,
8783                 (void *)&cmd_setqmap_queueid,
8784                 (void *)&cmd_setqmap_mapvalue,
8785                 NULL,
8786         },
8787 };
8788
8789 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8790 struct cmd_set_xstats_hide_zero_result {
8791         cmdline_fixed_string_t keyword;
8792         cmdline_fixed_string_t name;
8793         cmdline_fixed_string_t on_off;
8794 };
8795
8796 static void
8797 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8798                         __rte_unused struct cmdline *cl,
8799                         __rte_unused void *data)
8800 {
8801         struct cmd_set_xstats_hide_zero_result *res;
8802         uint16_t on_off = 0;
8803
8804         res = parsed_result;
8805         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8806         set_xstats_hide_zero(on_off);
8807 }
8808
8809 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8810         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8811                                  keyword, "set");
8812 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8813         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8814                                  name, "xstats-hide-zero");
8815 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8816         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8817                                  on_off, "on#off");
8818
8819 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8820         .f = cmd_set_xstats_hide_zero_parsed,
8821         .data = NULL,
8822         .help_str = "set xstats-hide-zero on|off",
8823         .tokens = {
8824                 (void *)&cmd_set_xstats_hide_zero_keyword,
8825                 (void *)&cmd_set_xstats_hide_zero_name,
8826                 (void *)&cmd_set_xstats_hide_zero_on_off,
8827                 NULL,
8828         },
8829 };
8830
8831 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8832 struct cmd_set_record_core_cycles_result {
8833         cmdline_fixed_string_t keyword;
8834         cmdline_fixed_string_t name;
8835         cmdline_fixed_string_t on_off;
8836 };
8837
8838 static void
8839 cmd_set_record_core_cycles_parsed(void *parsed_result,
8840                         __rte_unused struct cmdline *cl,
8841                         __rte_unused void *data)
8842 {
8843         struct cmd_set_record_core_cycles_result *res;
8844         uint16_t on_off = 0;
8845
8846         res = parsed_result;
8847         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8848         set_record_core_cycles(on_off);
8849 }
8850
8851 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8852         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8853                                  keyword, "set");
8854 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8855         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8856                                  name, "record-core-cycles");
8857 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8858         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8859                                  on_off, "on#off");
8860
8861 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8862         .f = cmd_set_record_core_cycles_parsed,
8863         .data = NULL,
8864         .help_str = "set record-core-cycles on|off",
8865         .tokens = {
8866                 (void *)&cmd_set_record_core_cycles_keyword,
8867                 (void *)&cmd_set_record_core_cycles_name,
8868                 (void *)&cmd_set_record_core_cycles_on_off,
8869                 NULL,
8870         },
8871 };
8872
8873 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8874 struct cmd_set_record_burst_stats_result {
8875         cmdline_fixed_string_t keyword;
8876         cmdline_fixed_string_t name;
8877         cmdline_fixed_string_t on_off;
8878 };
8879
8880 static void
8881 cmd_set_record_burst_stats_parsed(void *parsed_result,
8882                         __rte_unused struct cmdline *cl,
8883                         __rte_unused void *data)
8884 {
8885         struct cmd_set_record_burst_stats_result *res;
8886         uint16_t on_off = 0;
8887
8888         res = parsed_result;
8889         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8890         set_record_burst_stats(on_off);
8891 }
8892
8893 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8894         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8895                                  keyword, "set");
8896 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8897         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8898                                  name, "record-burst-stats");
8899 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8900         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8901                                  on_off, "on#off");
8902
8903 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8904         .f = cmd_set_record_burst_stats_parsed,
8905         .data = NULL,
8906         .help_str = "set record-burst-stats on|off",
8907         .tokens = {
8908                 (void *)&cmd_set_record_burst_stats_keyword,
8909                 (void *)&cmd_set_record_burst_stats_name,
8910                 (void *)&cmd_set_record_burst_stats_on_off,
8911                 NULL,
8912         },
8913 };
8914
8915 /* *** CONFIGURE UNICAST HASH TABLE *** */
8916 struct cmd_set_uc_hash_table {
8917         cmdline_fixed_string_t set;
8918         cmdline_fixed_string_t port;
8919         portid_t port_id;
8920         cmdline_fixed_string_t what;
8921         struct rte_ether_addr address;
8922         cmdline_fixed_string_t mode;
8923 };
8924
8925 static void
8926 cmd_set_uc_hash_parsed(void *parsed_result,
8927                        __rte_unused struct cmdline *cl,
8928                        __rte_unused void *data)
8929 {
8930         int ret=0;
8931         struct cmd_set_uc_hash_table *res = parsed_result;
8932
8933         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8934
8935         if (strcmp(res->what, "uta") == 0)
8936                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8937                                                 &res->address,(uint8_t)is_on);
8938         if (ret < 0)
8939                 fprintf(stderr,
8940                         "bad unicast hash table parameter, return code = %d\n",
8941                         ret);
8942
8943 }
8944
8945 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8946         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8947                                  set, "set");
8948 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8949         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8950                                  port, "port");
8951 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8952         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8953                               port_id, RTE_UINT16);
8954 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8955         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8956                                  what, "uta");
8957 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8958         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8959                                 address);
8960 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8961         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8962                                  mode, "on#off");
8963
8964 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8965         .f = cmd_set_uc_hash_parsed,
8966         .data = NULL,
8967         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8968         .tokens = {
8969                 (void *)&cmd_set_uc_hash_set,
8970                 (void *)&cmd_set_uc_hash_port,
8971                 (void *)&cmd_set_uc_hash_portid,
8972                 (void *)&cmd_set_uc_hash_what,
8973                 (void *)&cmd_set_uc_hash_mac,
8974                 (void *)&cmd_set_uc_hash_mode,
8975                 NULL,
8976         },
8977 };
8978
8979 struct cmd_set_uc_all_hash_table {
8980         cmdline_fixed_string_t set;
8981         cmdline_fixed_string_t port;
8982         portid_t port_id;
8983         cmdline_fixed_string_t what;
8984         cmdline_fixed_string_t value;
8985         cmdline_fixed_string_t mode;
8986 };
8987
8988 static void
8989 cmd_set_uc_all_hash_parsed(void *parsed_result,
8990                        __rte_unused struct cmdline *cl,
8991                        __rte_unused void *data)
8992 {
8993         int ret=0;
8994         struct cmd_set_uc_all_hash_table *res = parsed_result;
8995
8996         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8997
8998         if ((strcmp(res->what, "uta") == 0) &&
8999                 (strcmp(res->value, "all") == 0))
9000                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9001         if (ret < 0)
9002                 fprintf(stderr,
9003                         "bad unicast hash table parameter, return code = %d\n",
9004                         ret);
9005 }
9006
9007 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9008         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9009                                  set, "set");
9010 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9011         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9012                                  port, "port");
9013 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9014         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9015                               port_id, RTE_UINT16);
9016 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9017         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9018                                  what, "uta");
9019 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9020         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9021                                 value,"all");
9022 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9023         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9024                                  mode, "on#off");
9025
9026 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9027         .f = cmd_set_uc_all_hash_parsed,
9028         .data = NULL,
9029         .help_str = "set port <port_id> uta all on|off",
9030         .tokens = {
9031                 (void *)&cmd_set_uc_all_hash_set,
9032                 (void *)&cmd_set_uc_all_hash_port,
9033                 (void *)&cmd_set_uc_all_hash_portid,
9034                 (void *)&cmd_set_uc_all_hash_what,
9035                 (void *)&cmd_set_uc_all_hash_value,
9036                 (void *)&cmd_set_uc_all_hash_mode,
9037                 NULL,
9038         },
9039 };
9040
9041 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9042 struct cmd_set_vf_traffic {
9043         cmdline_fixed_string_t set;
9044         cmdline_fixed_string_t port;
9045         portid_t port_id;
9046         cmdline_fixed_string_t vf;
9047         uint8_t vf_id;
9048         cmdline_fixed_string_t what;
9049         cmdline_fixed_string_t mode;
9050 };
9051
9052 static void
9053 cmd_set_vf_traffic_parsed(void *parsed_result,
9054                        __rte_unused struct cmdline *cl,
9055                        __rte_unused void *data)
9056 {
9057         struct cmd_set_vf_traffic *res = parsed_result;
9058         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9059         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9060
9061         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9062 }
9063
9064 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9065         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9066                                  set, "set");
9067 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9068         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9069                                  port, "port");
9070 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9071         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9072                               port_id, RTE_UINT16);
9073 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9074         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9075                                  vf, "vf");
9076 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9077         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9078                               vf_id, RTE_UINT8);
9079 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9080         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9081                                  what, "tx#rx");
9082 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9083         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9084                                  mode, "on#off");
9085
9086 cmdline_parse_inst_t cmd_set_vf_traffic = {
9087         .f = cmd_set_vf_traffic_parsed,
9088         .data = NULL,
9089         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9090         .tokens = {
9091                 (void *)&cmd_setvf_traffic_set,
9092                 (void *)&cmd_setvf_traffic_port,
9093                 (void *)&cmd_setvf_traffic_portid,
9094                 (void *)&cmd_setvf_traffic_vf,
9095                 (void *)&cmd_setvf_traffic_vfid,
9096                 (void *)&cmd_setvf_traffic_what,
9097                 (void *)&cmd_setvf_traffic_mode,
9098                 NULL,
9099         },
9100 };
9101
9102 /* *** CONFIGURE VF RECEIVE MODE *** */
9103 struct cmd_set_vf_rxmode {
9104         cmdline_fixed_string_t set;
9105         cmdline_fixed_string_t port;
9106         portid_t port_id;
9107         cmdline_fixed_string_t vf;
9108         uint8_t vf_id;
9109         cmdline_fixed_string_t what;
9110         cmdline_fixed_string_t mode;
9111         cmdline_fixed_string_t on;
9112 };
9113
9114 static void
9115 cmd_set_vf_rxmode_parsed(void *parsed_result,
9116                        __rte_unused struct cmdline *cl,
9117                        __rte_unused void *data)
9118 {
9119         int ret = -ENOTSUP;
9120         uint16_t vf_rxmode = 0;
9121         struct cmd_set_vf_rxmode *res = parsed_result;
9122
9123         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9124         if (!strcmp(res->what,"rxmode")) {
9125                 if (!strcmp(res->mode, "AUPE"))
9126                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
9127                 else if (!strcmp(res->mode, "ROPE"))
9128                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
9129                 else if (!strcmp(res->mode, "BAM"))
9130                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
9131                 else if (!strncmp(res->mode, "MPE",3))
9132                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
9133         }
9134
9135         RTE_SET_USED(is_on);
9136
9137 #ifdef RTE_NET_IXGBE
9138         if (ret == -ENOTSUP)
9139                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9140                                                   vf_rxmode, (uint8_t)is_on);
9141 #endif
9142 #ifdef RTE_NET_BNXT
9143         if (ret == -ENOTSUP)
9144                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9145                                                  vf_rxmode, (uint8_t)is_on);
9146 #endif
9147         if (ret < 0)
9148                 fprintf(stderr,
9149                         "bad VF receive mode parameter, return code = %d\n",
9150                         ret);
9151 }
9152
9153 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9154         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9155                                  set, "set");
9156 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9157         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9158                                  port, "port");
9159 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9160         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9161                               port_id, RTE_UINT16);
9162 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9163         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9164                                  vf, "vf");
9165 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9166         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9167                               vf_id, RTE_UINT8);
9168 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9169         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9170                                  what, "rxmode");
9171 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9172         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9173                                  mode, "AUPE#ROPE#BAM#MPE");
9174 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9175         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9176                                  on, "on#off");
9177
9178 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9179         .f = cmd_set_vf_rxmode_parsed,
9180         .data = NULL,
9181         .help_str = "set port <port_id> vf <vf_id> rxmode "
9182                 "AUPE|ROPE|BAM|MPE on|off",
9183         .tokens = {
9184                 (void *)&cmd_set_vf_rxmode_set,
9185                 (void *)&cmd_set_vf_rxmode_port,
9186                 (void *)&cmd_set_vf_rxmode_portid,
9187                 (void *)&cmd_set_vf_rxmode_vf,
9188                 (void *)&cmd_set_vf_rxmode_vfid,
9189                 (void *)&cmd_set_vf_rxmode_what,
9190                 (void *)&cmd_set_vf_rxmode_mode,
9191                 (void *)&cmd_set_vf_rxmode_on,
9192                 NULL,
9193         },
9194 };
9195
9196 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9197 struct cmd_vf_mac_addr_result {
9198         cmdline_fixed_string_t mac_addr_cmd;
9199         cmdline_fixed_string_t what;
9200         cmdline_fixed_string_t port;
9201         uint16_t port_num;
9202         cmdline_fixed_string_t vf;
9203         uint8_t vf_num;
9204         struct rte_ether_addr address;
9205 };
9206
9207 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9208                 __rte_unused struct cmdline *cl,
9209                 __rte_unused void *data)
9210 {
9211         struct cmd_vf_mac_addr_result *res = parsed_result;
9212         int ret = -ENOTSUP;
9213
9214         if (strcmp(res->what, "add") != 0)
9215                 return;
9216
9217 #ifdef RTE_NET_I40E
9218         if (ret == -ENOTSUP)
9219                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9220                                                    &res->address);
9221 #endif
9222 #ifdef RTE_NET_BNXT
9223         if (ret == -ENOTSUP)
9224                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9225                                                 res->vf_num);
9226 #endif
9227
9228         if(ret < 0)
9229                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9230
9231 }
9232
9233 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9234         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9235                                 mac_addr_cmd,"mac_addr");
9236 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9237         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9238                                 what,"add");
9239 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9240         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9241                                 port,"port");
9242 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9243         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9244                                 port_num, RTE_UINT16);
9245 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9246         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9247                                 vf,"vf");
9248 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9249         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9250                                 vf_num, RTE_UINT8);
9251 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9252         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9253                                 address);
9254
9255 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9256         .f = cmd_vf_mac_addr_parsed,
9257         .data = (void *)0,
9258         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9259                 "Add MAC address filtering for a VF on port_id",
9260         .tokens = {
9261                 (void *)&cmd_vf_mac_addr_cmd,
9262                 (void *)&cmd_vf_mac_addr_what,
9263                 (void *)&cmd_vf_mac_addr_port,
9264                 (void *)&cmd_vf_mac_addr_portnum,
9265                 (void *)&cmd_vf_mac_addr_vf,
9266                 (void *)&cmd_vf_mac_addr_vfnum,
9267                 (void *)&cmd_vf_mac_addr_addr,
9268                 NULL,
9269         },
9270 };
9271
9272 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9273 struct cmd_vf_rx_vlan_filter {
9274         cmdline_fixed_string_t rx_vlan;
9275         cmdline_fixed_string_t what;
9276         uint16_t vlan_id;
9277         cmdline_fixed_string_t port;
9278         portid_t port_id;
9279         cmdline_fixed_string_t vf;
9280         uint64_t vf_mask;
9281 };
9282
9283 static void
9284 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9285                           __rte_unused struct cmdline *cl,
9286                           __rte_unused void *data)
9287 {
9288         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9289         int ret = -ENOTSUP;
9290
9291         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9292
9293 #ifdef RTE_NET_IXGBE
9294         if (ret == -ENOTSUP)
9295                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9296                                 res->vlan_id, res->vf_mask, is_add);
9297 #endif
9298 #ifdef RTE_NET_I40E
9299         if (ret == -ENOTSUP)
9300                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9301                                 res->vlan_id, res->vf_mask, is_add);
9302 #endif
9303 #ifdef RTE_NET_BNXT
9304         if (ret == -ENOTSUP)
9305                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9306                                 res->vlan_id, res->vf_mask, is_add);
9307 #endif
9308
9309         switch (ret) {
9310         case 0:
9311                 break;
9312         case -EINVAL:
9313                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9314                         res->vlan_id, res->vf_mask);
9315                 break;
9316         case -ENODEV:
9317                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9318                 break;
9319         case -ENOTSUP:
9320                 fprintf(stderr, "function not implemented or supported\n");
9321                 break;
9322         default:
9323                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9324         }
9325 }
9326
9327 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9328         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9329                                  rx_vlan, "rx_vlan");
9330 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9331         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9332                                  what, "add#rm");
9333 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9334         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9335                               vlan_id, RTE_UINT16);
9336 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9337         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9338                                  port, "port");
9339 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9340         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9341                               port_id, RTE_UINT16);
9342 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9343         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9344                                  vf, "vf");
9345 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9346         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9347                               vf_mask, RTE_UINT64);
9348
9349 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9350         .f = cmd_vf_rx_vlan_filter_parsed,
9351         .data = NULL,
9352         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9353                 "(vf_mask = hexadecimal VF mask)",
9354         .tokens = {
9355                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9356                 (void *)&cmd_vf_rx_vlan_filter_what,
9357                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9358                 (void *)&cmd_vf_rx_vlan_filter_port,
9359                 (void *)&cmd_vf_rx_vlan_filter_portid,
9360                 (void *)&cmd_vf_rx_vlan_filter_vf,
9361                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9362                 NULL,
9363         },
9364 };
9365
9366 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9367 struct cmd_queue_rate_limit_result {
9368         cmdline_fixed_string_t set;
9369         cmdline_fixed_string_t port;
9370         uint16_t port_num;
9371         cmdline_fixed_string_t queue;
9372         uint8_t queue_num;
9373         cmdline_fixed_string_t rate;
9374         uint16_t rate_num;
9375 };
9376
9377 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9378                 __rte_unused struct cmdline *cl,
9379                 __rte_unused void *data)
9380 {
9381         struct cmd_queue_rate_limit_result *res = parsed_result;
9382         int ret = 0;
9383
9384         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9385                 && (strcmp(res->queue, "queue") == 0)
9386                 && (strcmp(res->rate, "rate") == 0))
9387                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9388                                         res->rate_num);
9389         if (ret < 0)
9390                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9391                         strerror(-ret));
9392
9393 }
9394
9395 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9396         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9397                                 set, "set");
9398 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9399         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9400                                 port, "port");
9401 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9402         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9403                                 port_num, RTE_UINT16);
9404 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9405         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9406                                 queue, "queue");
9407 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9408         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9409                                 queue_num, RTE_UINT8);
9410 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9411         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9412                                 rate, "rate");
9413 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9414         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9415                                 rate_num, RTE_UINT16);
9416
9417 cmdline_parse_inst_t cmd_queue_rate_limit = {
9418         .f = cmd_queue_rate_limit_parsed,
9419         .data = (void *)0,
9420         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9421                 "Set rate limit for a queue on port_id",
9422         .tokens = {
9423                 (void *)&cmd_queue_rate_limit_set,
9424                 (void *)&cmd_queue_rate_limit_port,
9425                 (void *)&cmd_queue_rate_limit_portnum,
9426                 (void *)&cmd_queue_rate_limit_queue,
9427                 (void *)&cmd_queue_rate_limit_queuenum,
9428                 (void *)&cmd_queue_rate_limit_rate,
9429                 (void *)&cmd_queue_rate_limit_ratenum,
9430                 NULL,
9431         },
9432 };
9433
9434 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9435 struct cmd_vf_rate_limit_result {
9436         cmdline_fixed_string_t set;
9437         cmdline_fixed_string_t port;
9438         uint16_t port_num;
9439         cmdline_fixed_string_t vf;
9440         uint8_t vf_num;
9441         cmdline_fixed_string_t rate;
9442         uint16_t rate_num;
9443         cmdline_fixed_string_t q_msk;
9444         uint64_t q_msk_val;
9445 };
9446
9447 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9448                 __rte_unused struct cmdline *cl,
9449                 __rte_unused void *data)
9450 {
9451         struct cmd_vf_rate_limit_result *res = parsed_result;
9452         int ret = 0;
9453
9454         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9455                 && (strcmp(res->vf, "vf") == 0)
9456                 && (strcmp(res->rate, "rate") == 0)
9457                 && (strcmp(res->q_msk, "queue_mask") == 0))
9458                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9459                                         res->rate_num, res->q_msk_val);
9460         if (ret < 0)
9461                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9462                         strerror(-ret));
9463
9464 }
9465
9466 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9467         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9468                                 set, "set");
9469 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9470         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9471                                 port, "port");
9472 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9473         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9474                                 port_num, RTE_UINT16);
9475 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9476         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9477                                 vf, "vf");
9478 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9479         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9480                                 vf_num, RTE_UINT8);
9481 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9482         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9483                                 rate, "rate");
9484 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9485         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9486                                 rate_num, RTE_UINT16);
9487 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9488         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9489                                 q_msk, "queue_mask");
9490 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9491         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9492                                 q_msk_val, RTE_UINT64);
9493
9494 cmdline_parse_inst_t cmd_vf_rate_limit = {
9495         .f = cmd_vf_rate_limit_parsed,
9496         .data = (void *)0,
9497         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9498                 "queue_mask <queue_mask_value>: "
9499                 "Set rate limit for queues of VF on port_id",
9500         .tokens = {
9501                 (void *)&cmd_vf_rate_limit_set,
9502                 (void *)&cmd_vf_rate_limit_port,
9503                 (void *)&cmd_vf_rate_limit_portnum,
9504                 (void *)&cmd_vf_rate_limit_vf,
9505                 (void *)&cmd_vf_rate_limit_vfnum,
9506                 (void *)&cmd_vf_rate_limit_rate,
9507                 (void *)&cmd_vf_rate_limit_ratenum,
9508                 (void *)&cmd_vf_rate_limit_q_msk,
9509                 (void *)&cmd_vf_rate_limit_q_msk_val,
9510                 NULL,
9511         },
9512 };
9513
9514 /* *** CONFIGURE TUNNEL UDP PORT *** */
9515 struct cmd_tunnel_udp_config {
9516         cmdline_fixed_string_t rx_vxlan_port;
9517         cmdline_fixed_string_t what;
9518         uint16_t udp_port;
9519         portid_t port_id;
9520 };
9521
9522 static void
9523 cmd_tunnel_udp_config_parsed(void *parsed_result,
9524                           __rte_unused struct cmdline *cl,
9525                           __rte_unused void *data)
9526 {
9527         struct cmd_tunnel_udp_config *res = parsed_result;
9528         struct rte_eth_udp_tunnel tunnel_udp;
9529         int ret;
9530
9531         tunnel_udp.udp_port = res->udp_port;
9532         tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9533
9534         if (!strcmp(res->what, "add"))
9535                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9536                                                       &tunnel_udp);
9537         else
9538                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9539                                                          &tunnel_udp);
9540
9541         if (ret < 0)
9542                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9543                         strerror(-ret));
9544 }
9545
9546 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9547         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9548                                 rx_vxlan_port, "rx_vxlan_port");
9549 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9550         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9551                                 what, "add#rm");
9552 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9553         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9554                                 udp_port, RTE_UINT16);
9555 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9556         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9557                                 port_id, RTE_UINT16);
9558
9559 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9560         .f = cmd_tunnel_udp_config_parsed,
9561         .data = (void *)0,
9562         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9563                 "Add/Remove a tunneling UDP port filter",
9564         .tokens = {
9565                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9566                 (void *)&cmd_tunnel_udp_config_what,
9567                 (void *)&cmd_tunnel_udp_config_udp_port,
9568                 (void *)&cmd_tunnel_udp_config_port_id,
9569                 NULL,
9570         },
9571 };
9572
9573 struct cmd_config_tunnel_udp_port {
9574         cmdline_fixed_string_t port;
9575         cmdline_fixed_string_t config;
9576         portid_t port_id;
9577         cmdline_fixed_string_t udp_tunnel_port;
9578         cmdline_fixed_string_t action;
9579         cmdline_fixed_string_t tunnel_type;
9580         uint16_t udp_port;
9581 };
9582
9583 static void
9584 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9585                                __rte_unused struct cmdline *cl,
9586                                __rte_unused void *data)
9587 {
9588         struct cmd_config_tunnel_udp_port *res = parsed_result;
9589         struct rte_eth_udp_tunnel tunnel_udp;
9590         int ret = 0;
9591
9592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9593                 return;
9594
9595         tunnel_udp.udp_port = res->udp_port;
9596
9597         if (!strcmp(res->tunnel_type, "vxlan")) {
9598                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9599         } else if (!strcmp(res->tunnel_type, "geneve")) {
9600                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9601         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9602                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9603         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9604                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9605         } else {
9606                 fprintf(stderr, "Invalid tunnel type\n");
9607                 return;
9608         }
9609
9610         if (!strcmp(res->action, "add"))
9611                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9612                                                       &tunnel_udp);
9613         else
9614                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9615                                                          &tunnel_udp);
9616
9617         if (ret < 0)
9618                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9619                         strerror(-ret));
9620 }
9621
9622 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9623         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9624                                  "port");
9625 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9626         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9627                                  "config");
9628 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9629         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9630                               RTE_UINT16);
9631 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9632         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9633                                  udp_tunnel_port,
9634                                  "udp_tunnel_port");
9635 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9636         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9637                                  "add#rm");
9638 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9639         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9640                                  "vxlan#geneve#vxlan-gpe#ecpri");
9641 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9642         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9643                               RTE_UINT16);
9644
9645 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9646         .f = cmd_cfg_tunnel_udp_port_parsed,
9647         .data = NULL,
9648         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9649                 "geneve|vxlan-gpe|ecpri <udp_port>",
9650         .tokens = {
9651                 (void *)&cmd_config_tunnel_udp_port_port,
9652                 (void *)&cmd_config_tunnel_udp_port_config,
9653                 (void *)&cmd_config_tunnel_udp_port_port_id,
9654                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9655                 (void *)&cmd_config_tunnel_udp_port_action,
9656                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9657                 (void *)&cmd_config_tunnel_udp_port_value,
9658                 NULL,
9659         },
9660 };
9661
9662 /* ******************************************************************************** */
9663
9664 struct cmd_dump_result {
9665         cmdline_fixed_string_t dump;
9666 };
9667
9668 static void
9669 dump_struct_sizes(void)
9670 {
9671 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9672         DUMP_SIZE(struct rte_mbuf);
9673         DUMP_SIZE(struct rte_mempool);
9674         DUMP_SIZE(struct rte_ring);
9675 #undef DUMP_SIZE
9676 }
9677
9678
9679 /* Dump the socket memory statistics on console */
9680 static void
9681 dump_socket_mem(FILE *f)
9682 {
9683         struct rte_malloc_socket_stats socket_stats;
9684         unsigned int i;
9685         size_t total = 0;
9686         size_t alloc = 0;
9687         size_t free = 0;
9688         unsigned int n_alloc = 0;
9689         unsigned int n_free = 0;
9690         static size_t last_allocs;
9691         static size_t last_total;
9692
9693
9694         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9695                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9696                     !socket_stats.heap_totalsz_bytes)
9697                         continue;
9698                 total += socket_stats.heap_totalsz_bytes;
9699                 alloc += socket_stats.heap_allocsz_bytes;
9700                 free += socket_stats.heap_freesz_bytes;
9701                 n_alloc += socket_stats.alloc_count;
9702                 n_free += socket_stats.free_count;
9703                 fprintf(f,
9704                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9705                         i,
9706                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9707                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9708                         (double)socket_stats.heap_allocsz_bytes * 100 /
9709                         (double)socket_stats.heap_totalsz_bytes,
9710                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9711                         socket_stats.alloc_count,
9712                         socket_stats.free_count);
9713         }
9714         fprintf(f,
9715                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9716                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9717                 total ? ((double)alloc * 100 / (double)total) : 0,
9718                 (double)free / (1024 * 1024),
9719                 n_alloc, n_free);
9720         if (last_allocs)
9721                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9722                         ((double)total - (double)last_total) / (1024 * 1024),
9723                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9724         last_allocs = alloc;
9725         last_total = total;
9726 }
9727
9728 static void cmd_dump_parsed(void *parsed_result,
9729                             __rte_unused struct cmdline *cl,
9730                             __rte_unused void *data)
9731 {
9732         struct cmd_dump_result *res = parsed_result;
9733
9734         if (!strcmp(res->dump, "dump_physmem"))
9735                 rte_dump_physmem_layout(stdout);
9736         else if (!strcmp(res->dump, "dump_socket_mem"))
9737                 dump_socket_mem(stdout);
9738         else if (!strcmp(res->dump, "dump_memzone"))
9739                 rte_memzone_dump(stdout);
9740         else if (!strcmp(res->dump, "dump_struct_sizes"))
9741                 dump_struct_sizes();
9742         else if (!strcmp(res->dump, "dump_ring"))
9743                 rte_ring_list_dump(stdout);
9744         else if (!strcmp(res->dump, "dump_mempool"))
9745                 rte_mempool_list_dump(stdout);
9746         else if (!strcmp(res->dump, "dump_devargs"))
9747                 rte_devargs_dump(stdout);
9748         else if (!strcmp(res->dump, "dump_log_types"))
9749                 rte_log_dump(stdout);
9750 }
9751
9752 cmdline_parse_token_string_t cmd_dump_dump =
9753         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9754                 "dump_physmem#"
9755                 "dump_memzone#"
9756                 "dump_socket_mem#"
9757                 "dump_struct_sizes#"
9758                 "dump_ring#"
9759                 "dump_mempool#"
9760                 "dump_devargs#"
9761                 "dump_log_types");
9762
9763 cmdline_parse_inst_t cmd_dump = {
9764         .f = cmd_dump_parsed,  /* function to call */
9765         .data = NULL,      /* 2nd arg of func */
9766         .help_str = "Dump status",
9767         .tokens = {        /* token list, NULL terminated */
9768                 (void *)&cmd_dump_dump,
9769                 NULL,
9770         },
9771 };
9772
9773 /* ******************************************************************************** */
9774
9775 struct cmd_dump_one_result {
9776         cmdline_fixed_string_t dump;
9777         cmdline_fixed_string_t name;
9778 };
9779
9780 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9781                                 __rte_unused void *data)
9782 {
9783         struct cmd_dump_one_result *res = parsed_result;
9784
9785         if (!strcmp(res->dump, "dump_ring")) {
9786                 struct rte_ring *r;
9787                 r = rte_ring_lookup(res->name);
9788                 if (r == NULL) {
9789                         cmdline_printf(cl, "Cannot find ring\n");
9790                         return;
9791                 }
9792                 rte_ring_dump(stdout, r);
9793         } else if (!strcmp(res->dump, "dump_mempool")) {
9794                 struct rte_mempool *mp;
9795                 mp = rte_mempool_lookup(res->name);
9796                 if (mp == NULL) {
9797                         cmdline_printf(cl, "Cannot find mempool\n");
9798                         return;
9799                 }
9800                 rte_mempool_dump(stdout, mp);
9801         }
9802 }
9803
9804 cmdline_parse_token_string_t cmd_dump_one_dump =
9805         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9806                                  "dump_ring#dump_mempool");
9807
9808 cmdline_parse_token_string_t cmd_dump_one_name =
9809         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9810
9811 cmdline_parse_inst_t cmd_dump_one = {
9812         .f = cmd_dump_one_parsed,  /* function to call */
9813         .data = NULL,      /* 2nd arg of func */
9814         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9815         .tokens = {        /* token list, NULL terminated */
9816                 (void *)&cmd_dump_one_dump,
9817                 (void *)&cmd_dump_one_name,
9818                 NULL,
9819         },
9820 };
9821
9822 /* *** queue region set *** */
9823 struct cmd_queue_region_result {
9824         cmdline_fixed_string_t set;
9825         cmdline_fixed_string_t port;
9826         portid_t port_id;
9827         cmdline_fixed_string_t cmd;
9828         cmdline_fixed_string_t region;
9829         uint8_t  region_id;
9830         cmdline_fixed_string_t queue_start_index;
9831         uint8_t  queue_id;
9832         cmdline_fixed_string_t queue_num;
9833         uint8_t  queue_num_value;
9834 };
9835
9836 static void
9837 cmd_queue_region_parsed(void *parsed_result,
9838                         __rte_unused struct cmdline *cl,
9839                         __rte_unused void *data)
9840 {
9841         struct cmd_queue_region_result *res = parsed_result;
9842         int ret = -ENOTSUP;
9843 #ifdef RTE_NET_I40E
9844         struct rte_pmd_i40e_queue_region_conf region_conf;
9845         enum rte_pmd_i40e_queue_region_op op_type;
9846 #endif
9847
9848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9849                 return;
9850
9851 #ifdef RTE_NET_I40E
9852         memset(&region_conf, 0, sizeof(region_conf));
9853         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9854         region_conf.region_id = res->region_id;
9855         region_conf.queue_num = res->queue_num_value;
9856         region_conf.queue_start_index = res->queue_id;
9857
9858         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9859                                 op_type, &region_conf);
9860 #endif
9861
9862         switch (ret) {
9863         case 0:
9864                 break;
9865         case -ENOTSUP:
9866                 fprintf(stderr, "function not implemented or supported\n");
9867                 break;
9868         default:
9869                 fprintf(stderr, "queue region config error: (%s)\n",
9870                         strerror(-ret));
9871         }
9872 }
9873
9874 cmdline_parse_token_string_t cmd_queue_region_set =
9875 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9876                 set, "set");
9877 cmdline_parse_token_string_t cmd_queue_region_port =
9878         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9879 cmdline_parse_token_num_t cmd_queue_region_port_id =
9880         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9881                                 port_id, RTE_UINT16);
9882 cmdline_parse_token_string_t cmd_queue_region_cmd =
9883         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9884                                  cmd, "queue-region");
9885 cmdline_parse_token_string_t cmd_queue_region_id =
9886         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9887                                 region, "region_id");
9888 cmdline_parse_token_num_t cmd_queue_region_index =
9889         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9890                                 region_id, RTE_UINT8);
9891 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9892         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9893                                 queue_start_index, "queue_start_index");
9894 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9895         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9896                                 queue_id, RTE_UINT8);
9897 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9898         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9899                                 queue_num, "queue_num");
9900 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9901         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9902                                 queue_num_value, RTE_UINT8);
9903
9904 cmdline_parse_inst_t cmd_queue_region = {
9905         .f = cmd_queue_region_parsed,
9906         .data = NULL,
9907         .help_str = "set port <port_id> queue-region region_id <value> "
9908                 "queue_start_index <value> queue_num <value>: Set a queue region",
9909         .tokens = {
9910                 (void *)&cmd_queue_region_set,
9911                 (void *)&cmd_queue_region_port,
9912                 (void *)&cmd_queue_region_port_id,
9913                 (void *)&cmd_queue_region_cmd,
9914                 (void *)&cmd_queue_region_id,
9915                 (void *)&cmd_queue_region_index,
9916                 (void *)&cmd_queue_region_queue_start_index,
9917                 (void *)&cmd_queue_region_queue_id,
9918                 (void *)&cmd_queue_region_queue_num,
9919                 (void *)&cmd_queue_region_queue_num_value,
9920                 NULL,
9921         },
9922 };
9923
9924 /* *** queue region and flowtype set *** */
9925 struct cmd_region_flowtype_result {
9926         cmdline_fixed_string_t set;
9927         cmdline_fixed_string_t port;
9928         portid_t port_id;
9929         cmdline_fixed_string_t cmd;
9930         cmdline_fixed_string_t region;
9931         uint8_t  region_id;
9932         cmdline_fixed_string_t flowtype;
9933         uint8_t  flowtype_id;
9934 };
9935
9936 static void
9937 cmd_region_flowtype_parsed(void *parsed_result,
9938                         __rte_unused struct cmdline *cl,
9939                         __rte_unused void *data)
9940 {
9941         struct cmd_region_flowtype_result *res = parsed_result;
9942         int ret = -ENOTSUP;
9943 #ifdef RTE_NET_I40E
9944         struct rte_pmd_i40e_queue_region_conf region_conf;
9945         enum rte_pmd_i40e_queue_region_op op_type;
9946 #endif
9947
9948         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9949                 return;
9950
9951 #ifdef RTE_NET_I40E
9952         memset(&region_conf, 0, sizeof(region_conf));
9953
9954         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9955         region_conf.region_id = res->region_id;
9956         region_conf.hw_flowtype = res->flowtype_id;
9957
9958         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9959                         op_type, &region_conf);
9960 #endif
9961
9962         switch (ret) {
9963         case 0:
9964                 break;
9965         case -ENOTSUP:
9966                 fprintf(stderr, "function not implemented or supported\n");
9967                 break;
9968         default:
9969                 fprintf(stderr, "region flowtype config error: (%s)\n",
9970                         strerror(-ret));
9971         }
9972 }
9973
9974 cmdline_parse_token_string_t cmd_region_flowtype_set =
9975 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9976                                 set, "set");
9977 cmdline_parse_token_string_t cmd_region_flowtype_port =
9978         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9979                                 port, "port");
9980 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9981         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9982                                 port_id, RTE_UINT16);
9983 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9984         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9985                                 cmd, "queue-region");
9986 cmdline_parse_token_string_t cmd_region_flowtype_index =
9987         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9988                                 region, "region_id");
9989 cmdline_parse_token_num_t cmd_region_flowtype_id =
9990         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9991                                 region_id, RTE_UINT8);
9992 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9993         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9994                                 flowtype, "flowtype");
9995 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9996         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9997                                 flowtype_id, RTE_UINT8);
9998 cmdline_parse_inst_t cmd_region_flowtype = {
9999         .f = cmd_region_flowtype_parsed,
10000         .data = NULL,
10001         .help_str = "set port <port_id> queue-region region_id <value> "
10002                 "flowtype <value>: Set a flowtype region index",
10003         .tokens = {
10004                 (void *)&cmd_region_flowtype_set,
10005                 (void *)&cmd_region_flowtype_port,
10006                 (void *)&cmd_region_flowtype_port_index,
10007                 (void *)&cmd_region_flowtype_cmd,
10008                 (void *)&cmd_region_flowtype_index,
10009                 (void *)&cmd_region_flowtype_id,
10010                 (void *)&cmd_region_flowtype_flow_index,
10011                 (void *)&cmd_region_flowtype_flow_id,
10012                 NULL,
10013         },
10014 };
10015
10016 /* *** User Priority (UP) to queue region (region_id) set *** */
10017 struct cmd_user_priority_region_result {
10018         cmdline_fixed_string_t set;
10019         cmdline_fixed_string_t port;
10020         portid_t port_id;
10021         cmdline_fixed_string_t cmd;
10022         cmdline_fixed_string_t user_priority;
10023         uint8_t  user_priority_id;
10024         cmdline_fixed_string_t region;
10025         uint8_t  region_id;
10026 };
10027
10028 static void
10029 cmd_user_priority_region_parsed(void *parsed_result,
10030                         __rte_unused struct cmdline *cl,
10031                         __rte_unused void *data)
10032 {
10033         struct cmd_user_priority_region_result *res = parsed_result;
10034         int ret = -ENOTSUP;
10035 #ifdef RTE_NET_I40E
10036         struct rte_pmd_i40e_queue_region_conf region_conf;
10037         enum rte_pmd_i40e_queue_region_op op_type;
10038 #endif
10039
10040         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10041                 return;
10042
10043 #ifdef RTE_NET_I40E
10044         memset(&region_conf, 0, sizeof(region_conf));
10045         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10046         region_conf.user_priority = res->user_priority_id;
10047         region_conf.region_id = res->region_id;
10048
10049         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10050                                 op_type, &region_conf);
10051 #endif
10052
10053         switch (ret) {
10054         case 0:
10055                 break;
10056         case -ENOTSUP:
10057                 fprintf(stderr, "function not implemented or supported\n");
10058                 break;
10059         default:
10060                 fprintf(stderr, "user_priority region config error: (%s)\n",
10061                         strerror(-ret));
10062         }
10063 }
10064
10065 cmdline_parse_token_string_t cmd_user_priority_region_set =
10066         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10067                                 set, "set");
10068 cmdline_parse_token_string_t cmd_user_priority_region_port =
10069         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10070                                 port, "port");
10071 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10072         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10073                                 port_id, RTE_UINT16);
10074 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10075         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10076                                 cmd, "queue-region");
10077 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10078         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10079                                 user_priority, "UP");
10080 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10081         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10082                                 user_priority_id, RTE_UINT8);
10083 cmdline_parse_token_string_t cmd_user_priority_region_region =
10084         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10085                                 region, "region_id");
10086 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10087         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10088                                 region_id, RTE_UINT8);
10089
10090 cmdline_parse_inst_t cmd_user_priority_region = {
10091         .f = cmd_user_priority_region_parsed,
10092         .data = NULL,
10093         .help_str = "set port <port_id> queue-region UP <value> "
10094                 "region_id <value>: Set the mapping of User Priority (UP) "
10095                 "to queue region (region_id) ",
10096         .tokens = {
10097                 (void *)&cmd_user_priority_region_set,
10098                 (void *)&cmd_user_priority_region_port,
10099                 (void *)&cmd_user_priority_region_port_index,
10100                 (void *)&cmd_user_priority_region_cmd,
10101                 (void *)&cmd_user_priority_region_UP,
10102                 (void *)&cmd_user_priority_region_UP_id,
10103                 (void *)&cmd_user_priority_region_region,
10104                 (void *)&cmd_user_priority_region_region_id,
10105                 NULL,
10106         },
10107 };
10108
10109 /* *** flush all queue region related configuration *** */
10110 struct cmd_flush_queue_region_result {
10111         cmdline_fixed_string_t set;
10112         cmdline_fixed_string_t port;
10113         portid_t port_id;
10114         cmdline_fixed_string_t cmd;
10115         cmdline_fixed_string_t flush;
10116         cmdline_fixed_string_t what;
10117 };
10118
10119 static void
10120 cmd_flush_queue_region_parsed(void *parsed_result,
10121                         __rte_unused struct cmdline *cl,
10122                         __rte_unused void *data)
10123 {
10124         struct cmd_flush_queue_region_result *res = parsed_result;
10125         int ret = -ENOTSUP;
10126 #ifdef RTE_NET_I40E
10127         struct rte_pmd_i40e_queue_region_conf region_conf;
10128         enum rte_pmd_i40e_queue_region_op op_type;
10129 #endif
10130
10131         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10132                 return;
10133
10134 #ifdef RTE_NET_I40E
10135         memset(&region_conf, 0, sizeof(region_conf));
10136
10137         if (strcmp(res->what, "on") == 0)
10138                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10139         else
10140                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10141
10142         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10143                                 op_type, &region_conf);
10144 #endif
10145
10146         switch (ret) {
10147         case 0:
10148                 break;
10149         case -ENOTSUP:
10150                 fprintf(stderr, "function not implemented or supported\n");
10151                 break;
10152         default:
10153                 fprintf(stderr, "queue region config flush error: (%s)\n",
10154                         strerror(-ret));
10155         }
10156 }
10157
10158 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10159         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10160                                 set, "set");
10161 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10162         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10163                                 port, "port");
10164 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10165         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10166                                 port_id, RTE_UINT16);
10167 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10168         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10169                                 cmd, "queue-region");
10170 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10171         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10172                                 flush, "flush");
10173 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10174         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10175                                 what, "on#off");
10176
10177 cmdline_parse_inst_t cmd_flush_queue_region = {
10178         .f = cmd_flush_queue_region_parsed,
10179         .data = NULL,
10180         .help_str = "set port <port_id> queue-region flush on|off"
10181                 ": flush all queue region related configuration",
10182         .tokens = {
10183                 (void *)&cmd_flush_queue_region_set,
10184                 (void *)&cmd_flush_queue_region_port,
10185                 (void *)&cmd_flush_queue_region_port_index,
10186                 (void *)&cmd_flush_queue_region_cmd,
10187                 (void *)&cmd_flush_queue_region_flush,
10188                 (void *)&cmd_flush_queue_region_what,
10189                 NULL,
10190         },
10191 };
10192
10193 /* *** get all queue region related configuration info *** */
10194 struct cmd_show_queue_region_info {
10195         cmdline_fixed_string_t show;
10196         cmdline_fixed_string_t port;
10197         portid_t port_id;
10198         cmdline_fixed_string_t cmd;
10199 };
10200
10201 static void
10202 cmd_show_queue_region_info_parsed(void *parsed_result,
10203                         __rte_unused struct cmdline *cl,
10204                         __rte_unused void *data)
10205 {
10206         struct cmd_show_queue_region_info *res = parsed_result;
10207         int ret = -ENOTSUP;
10208 #ifdef RTE_NET_I40E
10209         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10210         enum rte_pmd_i40e_queue_region_op op_type;
10211 #endif
10212
10213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10214                 return;
10215
10216 #ifdef RTE_NET_I40E
10217         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10218
10219         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10220
10221         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10222                                         op_type, &rte_pmd_regions);
10223
10224         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10225 #endif
10226
10227         switch (ret) {
10228         case 0:
10229                 break;
10230         case -ENOTSUP:
10231                 fprintf(stderr, "function not implemented or supported\n");
10232                 break;
10233         default:
10234                 fprintf(stderr, "queue region config info show error: (%s)\n",
10235                         strerror(-ret));
10236         }
10237 }
10238
10239 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10240 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10241                                 show, "show");
10242 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10243         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10244                                 port, "port");
10245 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10246         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10247                                 port_id, RTE_UINT16);
10248 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10249         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10250                                 cmd, "queue-region");
10251
10252 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10253         .f = cmd_show_queue_region_info_parsed,
10254         .data = NULL,
10255         .help_str = "show port <port_id> queue-region"
10256                 ": show all queue region related configuration info",
10257         .tokens = {
10258                 (void *)&cmd_show_queue_region_info_get,
10259                 (void *)&cmd_show_queue_region_info_port,
10260                 (void *)&cmd_show_queue_region_info_port_index,
10261                 (void *)&cmd_show_queue_region_info_cmd,
10262                 NULL,
10263         },
10264 };
10265
10266 /* *** Filters Control *** */
10267
10268 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10269 do { \
10270         if ((ip_addr).family == AF_INET) \
10271                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10272         else { \
10273                 fprintf(stderr, "invalid parameter.\n"); \
10274                 return; \
10275         } \
10276 } while (0)
10277
10278 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10279 do { \
10280         if ((ip_addr).family == AF_INET6) \
10281                 rte_memcpy(&(ip), \
10282                                  &((ip_addr).addr.ipv6), \
10283                                  sizeof(struct in6_addr)); \
10284         else { \
10285                 fprintf(stderr, "invalid parameter.\n"); \
10286                 return; \
10287         } \
10288 } while (0)
10289
10290 #ifdef RTE_NET_I40E
10291
10292 static uint16_t
10293 str2flowtype(char *string)
10294 {
10295         uint8_t i = 0;
10296         static const struct {
10297                 char str[32];
10298                 uint16_t type;
10299         } flowtype_str[] = {
10300                 {"raw", RTE_ETH_FLOW_RAW},
10301                 {"ipv4", RTE_ETH_FLOW_IPV4},
10302                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10303                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10304                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10305                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10306                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10307                 {"ipv6", RTE_ETH_FLOW_IPV6},
10308                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10309                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10310                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10311                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10312                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10313                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10314         };
10315
10316         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10317                 if (!strcmp(flowtype_str[i].str, string))
10318                         return flowtype_str[i].type;
10319         }
10320
10321         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10322                 return (uint16_t)atoi(string);
10323
10324         return RTE_ETH_FLOW_UNKNOWN;
10325 }
10326
10327 /* *** deal with flow director filter *** */
10328 struct cmd_flow_director_result {
10329         cmdline_fixed_string_t flow_director_filter;
10330         portid_t port_id;
10331         cmdline_fixed_string_t mode;
10332         cmdline_fixed_string_t mode_value;
10333         cmdline_fixed_string_t ops;
10334         cmdline_fixed_string_t flow;
10335         cmdline_fixed_string_t flow_type;
10336         cmdline_fixed_string_t drop;
10337         cmdline_fixed_string_t queue;
10338         uint16_t  queue_id;
10339         cmdline_fixed_string_t fd_id;
10340         uint32_t  fd_id_value;
10341         cmdline_fixed_string_t packet;
10342         char filepath[];
10343 };
10344
10345 static void
10346 cmd_flow_director_filter_parsed(void *parsed_result,
10347                           __rte_unused struct cmdline *cl,
10348                           __rte_unused void *data)
10349 {
10350         struct cmd_flow_director_result *res = parsed_result;
10351         int ret = 0;
10352         struct rte_pmd_i40e_flow_type_mapping
10353                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10354         struct rte_pmd_i40e_pkt_template_conf conf;
10355         uint16_t flow_type = str2flowtype(res->flow_type);
10356         uint16_t i, port = res->port_id;
10357         uint8_t add;
10358
10359         memset(&conf, 0, sizeof(conf));
10360
10361         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10362                 fprintf(stderr, "Invalid flow type specified.\n");
10363                 return;
10364         }
10365         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10366                                                  mapping);
10367         if (ret)
10368                 return;
10369         if (mapping[flow_type].pctype == 0ULL) {
10370                 fprintf(stderr, "Invalid flow type specified.\n");
10371                 return;
10372         }
10373         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10374                 if (mapping[flow_type].pctype & (1ULL << i)) {
10375                         conf.input.pctype = i;
10376                         break;
10377                 }
10378         }
10379
10380         conf.input.packet = open_file(res->filepath,
10381                                 &conf.input.length);
10382         if (!conf.input.packet)
10383                 return;
10384         if (!strcmp(res->drop, "drop"))
10385                 conf.action.behavior =
10386                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10387         else
10388                 conf.action.behavior =
10389                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10390         conf.action.report_status =
10391                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10392         conf.action.rx_queue = res->queue_id;
10393         conf.soft_id = res->fd_id_value;
10394         add  = strcmp(res->ops, "del") ? 1 : 0;
10395         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10396                                                         &conf,
10397                                                         add);
10398         if (ret < 0)
10399                 fprintf(stderr, "flow director config error: (%s)\n",
10400                         strerror(-ret));
10401         close_file(conf.input.packet);
10402 }
10403
10404 cmdline_parse_token_string_t cmd_flow_director_filter =
10405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10406                                  flow_director_filter, "flow_director_filter");
10407 cmdline_parse_token_num_t cmd_flow_director_port_id =
10408         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10409                               port_id, RTE_UINT16);
10410 cmdline_parse_token_string_t cmd_flow_director_ops =
10411         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10412                                  ops, "add#del#update");
10413 cmdline_parse_token_string_t cmd_flow_director_flow =
10414         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10415                                  flow, "flow");
10416 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10417         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10418                 flow_type, NULL);
10419 cmdline_parse_token_string_t cmd_flow_director_drop =
10420         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10421                                  drop, "drop#fwd");
10422 cmdline_parse_token_string_t cmd_flow_director_queue =
10423         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10424                                  queue, "queue");
10425 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10426         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10427                               queue_id, RTE_UINT16);
10428 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10429         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10430                                  fd_id, "fd_id");
10431 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10432         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10433                               fd_id_value, RTE_UINT32);
10434
10435 cmdline_parse_token_string_t cmd_flow_director_mode =
10436         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10437                                  mode, "mode");
10438 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10439         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10440                                  mode_value, "raw");
10441 cmdline_parse_token_string_t cmd_flow_director_packet =
10442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10443                                  packet, "packet");
10444 cmdline_parse_token_string_t cmd_flow_director_filepath =
10445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10446                                  filepath, NULL);
10447
10448 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10449         .f = cmd_flow_director_filter_parsed,
10450         .data = NULL,
10451         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10452                 "director entry on NIC",
10453         .tokens = {
10454                 (void *)&cmd_flow_director_filter,
10455                 (void *)&cmd_flow_director_port_id,
10456                 (void *)&cmd_flow_director_mode,
10457                 (void *)&cmd_flow_director_mode_raw,
10458                 (void *)&cmd_flow_director_ops,
10459                 (void *)&cmd_flow_director_flow,
10460                 (void *)&cmd_flow_director_flow_type,
10461                 (void *)&cmd_flow_director_drop,
10462                 (void *)&cmd_flow_director_queue,
10463                 (void *)&cmd_flow_director_queue_id,
10464                 (void *)&cmd_flow_director_fd_id,
10465                 (void *)&cmd_flow_director_fd_id_value,
10466                 (void *)&cmd_flow_director_packet,
10467                 (void *)&cmd_flow_director_filepath,
10468                 NULL,
10469         },
10470 };
10471
10472 #endif /* RTE_NET_I40E */
10473
10474 /* *** deal with flow director mask *** */
10475 struct cmd_flow_director_mask_result {
10476         cmdline_fixed_string_t flow_director_mask;
10477         portid_t port_id;
10478         cmdline_fixed_string_t mode;
10479         cmdline_fixed_string_t mode_value;
10480         cmdline_fixed_string_t vlan;
10481         uint16_t vlan_mask;
10482         cmdline_fixed_string_t src_mask;
10483         cmdline_ipaddr_t ipv4_src;
10484         cmdline_ipaddr_t ipv6_src;
10485         uint16_t port_src;
10486         cmdline_fixed_string_t dst_mask;
10487         cmdline_ipaddr_t ipv4_dst;
10488         cmdline_ipaddr_t ipv6_dst;
10489         uint16_t port_dst;
10490         cmdline_fixed_string_t mac;
10491         uint8_t mac_addr_byte_mask;
10492         cmdline_fixed_string_t tunnel_id;
10493         uint32_t tunnel_id_mask;
10494         cmdline_fixed_string_t tunnel_type;
10495         uint8_t tunnel_type_mask;
10496 };
10497
10498 static void
10499 cmd_flow_director_mask_parsed(void *parsed_result,
10500                           __rte_unused struct cmdline *cl,
10501                           __rte_unused void *data)
10502 {
10503         struct cmd_flow_director_mask_result *res = parsed_result;
10504         struct rte_eth_fdir_masks *mask;
10505         struct rte_port *port;
10506
10507         port = &ports[res->port_id];
10508         /** Check if the port is not started **/
10509         if (port->port_status != RTE_PORT_STOPPED) {
10510                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10511                 return;
10512         }
10513
10514         mask = &port->dev_conf.fdir_conf.mask;
10515
10516         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10517                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10518                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10519                         return;
10520                 }
10521
10522                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10523         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10524                 if (strcmp(res->mode_value, "Tunnel")) {
10525                         fprintf(stderr, "Please set mode to Tunnel.\n");
10526                         return;
10527                 }
10528
10529                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10530                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10531                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10532                 mask->tunnel_type_mask = res->tunnel_type_mask;
10533         } else {
10534                 if (strcmp(res->mode_value, "IP")) {
10535                         fprintf(stderr, "Please set mode to IP.\n");
10536                         return;
10537                 }
10538
10539                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10540                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10541                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10542                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10543                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10544                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10545                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10546         }
10547
10548         cmd_reconfig_device_queue(res->port_id, 1, 1);
10549 }
10550
10551 cmdline_parse_token_string_t cmd_flow_director_mask =
10552         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10553                                  flow_director_mask, "flow_director_mask");
10554 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10555         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10556                               port_id, RTE_UINT16);
10557 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10558         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10559                                  vlan, "vlan");
10560 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10561         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10562                               vlan_mask, RTE_UINT16);
10563 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10564         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10565                                  src_mask, "src_mask");
10566 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10567         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10568                                  ipv4_src);
10569 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10570         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10571                                  ipv6_src);
10572 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10573         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10574                               port_src, RTE_UINT16);
10575 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10576         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10577                                  dst_mask, "dst_mask");
10578 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10579         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10580                                  ipv4_dst);
10581 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10582         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10583                                  ipv6_dst);
10584 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10585         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10586                               port_dst, RTE_UINT16);
10587
10588 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10589         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10590                                  mode, "mode");
10591 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10592         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10593                                  mode_value, "IP");
10594 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10595         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10596                                  mode_value, "MAC-VLAN");
10597 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10598         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10599                                  mode_value, "Tunnel");
10600 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10601         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10602                                  mac, "mac");
10603 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10604         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10605                               mac_addr_byte_mask, RTE_UINT8);
10606 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10607         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10608                                  tunnel_type, "tunnel-type");
10609 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10610         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10611                               tunnel_type_mask, RTE_UINT8);
10612 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10613         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10614                                  tunnel_id, "tunnel-id");
10615 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10616         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10617                               tunnel_id_mask, RTE_UINT32);
10618
10619 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10620         .f = cmd_flow_director_mask_parsed,
10621         .data = NULL,
10622         .help_str = "flow_director_mask ... : "
10623                 "Set IP mode flow director's mask on NIC",
10624         .tokens = {
10625                 (void *)&cmd_flow_director_mask,
10626                 (void *)&cmd_flow_director_mask_port_id,
10627                 (void *)&cmd_flow_director_mask_mode,
10628                 (void *)&cmd_flow_director_mask_mode_ip,
10629                 (void *)&cmd_flow_director_mask_vlan,
10630                 (void *)&cmd_flow_director_mask_vlan_value,
10631                 (void *)&cmd_flow_director_mask_src,
10632                 (void *)&cmd_flow_director_mask_ipv4_src,
10633                 (void *)&cmd_flow_director_mask_ipv6_src,
10634                 (void *)&cmd_flow_director_mask_port_src,
10635                 (void *)&cmd_flow_director_mask_dst,
10636                 (void *)&cmd_flow_director_mask_ipv4_dst,
10637                 (void *)&cmd_flow_director_mask_ipv6_dst,
10638                 (void *)&cmd_flow_director_mask_port_dst,
10639                 NULL,
10640         },
10641 };
10642
10643 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10644         .f = cmd_flow_director_mask_parsed,
10645         .data = NULL,
10646         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10647                 "flow director's mask on NIC",
10648         .tokens = {
10649                 (void *)&cmd_flow_director_mask,
10650                 (void *)&cmd_flow_director_mask_port_id,
10651                 (void *)&cmd_flow_director_mask_mode,
10652                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10653                 (void *)&cmd_flow_director_mask_vlan,
10654                 (void *)&cmd_flow_director_mask_vlan_value,
10655                 NULL,
10656         },
10657 };
10658
10659 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10660         .f = cmd_flow_director_mask_parsed,
10661         .data = NULL,
10662         .help_str = "flow_director_mask ... : Set tunnel mode "
10663                 "flow director's mask on NIC",
10664         .tokens = {
10665                 (void *)&cmd_flow_director_mask,
10666                 (void *)&cmd_flow_director_mask_port_id,
10667                 (void *)&cmd_flow_director_mask_mode,
10668                 (void *)&cmd_flow_director_mask_mode_tunnel,
10669                 (void *)&cmd_flow_director_mask_vlan,
10670                 (void *)&cmd_flow_director_mask_vlan_value,
10671                 (void *)&cmd_flow_director_mask_mac,
10672                 (void *)&cmd_flow_director_mask_mac_value,
10673                 (void *)&cmd_flow_director_mask_tunnel_type,
10674                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10675                 (void *)&cmd_flow_director_mask_tunnel_id,
10676                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10677                 NULL,
10678         },
10679 };
10680
10681 /* *** deal with flow director flexible payload configuration *** */
10682 struct cmd_flow_director_flexpayload_result {
10683         cmdline_fixed_string_t flow_director_flexpayload;
10684         portid_t port_id;
10685         cmdline_fixed_string_t payload_layer;
10686         cmdline_fixed_string_t payload_cfg;
10687 };
10688
10689 static inline int
10690 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10691 {
10692         char s[256];
10693         const char *p, *p0 = q_arg;
10694         char *end;
10695         unsigned long int_fld;
10696         char *str_fld[max_num];
10697         int i;
10698         unsigned size;
10699         int ret = -1;
10700
10701         p = strchr(p0, '(');
10702         if (p == NULL)
10703                 return -1;
10704         ++p;
10705         p0 = strchr(p, ')');
10706         if (p0 == NULL)
10707                 return -1;
10708
10709         size = p0 - p;
10710         if (size >= sizeof(s))
10711                 return -1;
10712
10713         snprintf(s, sizeof(s), "%.*s", size, p);
10714         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10715         if (ret < 0 || ret > max_num)
10716                 return -1;
10717         for (i = 0; i < ret; i++) {
10718                 errno = 0;
10719                 int_fld = strtoul(str_fld[i], &end, 0);
10720                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10721                         return -1;
10722                 offsets[i] = (uint16_t)int_fld;
10723         }
10724         return ret;
10725 }
10726
10727 static void
10728 cmd_flow_director_flxpld_parsed(void *parsed_result,
10729                           __rte_unused struct cmdline *cl,
10730                           __rte_unused void *data)
10731 {
10732         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10733         struct rte_eth_flex_payload_cfg flex_cfg;
10734         struct rte_port *port;
10735         int ret = 0;
10736
10737         port = &ports[res->port_id];
10738         /** Check if the port is not started **/
10739         if (port->port_status != RTE_PORT_STOPPED) {
10740                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10741                 return;
10742         }
10743
10744         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10745
10746         if (!strcmp(res->payload_layer, "raw"))
10747                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10748         else if (!strcmp(res->payload_layer, "l2"))
10749                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10750         else if (!strcmp(res->payload_layer, "l3"))
10751                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10752         else if (!strcmp(res->payload_layer, "l4"))
10753                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10754
10755         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10756                             RTE_ETH_FDIR_MAX_FLEXLEN);
10757         if (ret < 0) {
10758                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
10759                 return;
10760         }
10761
10762         fdir_set_flex_payload(res->port_id, &flex_cfg);
10763         cmd_reconfig_device_queue(res->port_id, 1, 1);
10764 }
10765
10766 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10768                                  flow_director_flexpayload,
10769                                  "flow_director_flex_payload");
10770 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10771         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10772                               port_id, RTE_UINT16);
10773 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10775                                  payload_layer, "raw#l2#l3#l4");
10776 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10778                                  payload_cfg, NULL);
10779
10780 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10781         .f = cmd_flow_director_flxpld_parsed,
10782         .data = NULL,
10783         .help_str = "flow_director_flexpayload ... : "
10784                 "Set flow director's flex payload on NIC",
10785         .tokens = {
10786                 (void *)&cmd_flow_director_flexpayload,
10787                 (void *)&cmd_flow_director_flexpayload_port_id,
10788                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10789                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10790                 NULL,
10791         },
10792 };
10793
10794 /* Generic flow interface command. */
10795 extern cmdline_parse_inst_t cmd_flow;
10796
10797 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10798 struct cmd_mcast_addr_result {
10799         cmdline_fixed_string_t mcast_addr_cmd;
10800         cmdline_fixed_string_t what;
10801         uint16_t port_num;
10802         struct rte_ether_addr mc_addr;
10803 };
10804
10805 static void cmd_mcast_addr_parsed(void *parsed_result,
10806                 __rte_unused struct cmdline *cl,
10807                 __rte_unused void *data)
10808 {
10809         struct cmd_mcast_addr_result *res = parsed_result;
10810
10811         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10812                 fprintf(stderr,
10813                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
10814                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
10815                 return;
10816         }
10817         if (strcmp(res->what, "add") == 0)
10818                 mcast_addr_add(res->port_num, &res->mc_addr);
10819         else
10820                 mcast_addr_remove(res->port_num, &res->mc_addr);
10821 }
10822
10823 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10824         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10825                                  mcast_addr_cmd, "mcast_addr");
10826 cmdline_parse_token_string_t cmd_mcast_addr_what =
10827         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10828                                  "add#remove");
10829 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10830         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10831                                  RTE_UINT16);
10832 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10833         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10834
10835 cmdline_parse_inst_t cmd_mcast_addr = {
10836         .f = cmd_mcast_addr_parsed,
10837         .data = (void *)0,
10838         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10839                 "Add/Remove multicast MAC address on port_id",
10840         .tokens = {
10841                 (void *)&cmd_mcast_addr_cmd,
10842                 (void *)&cmd_mcast_addr_what,
10843                 (void *)&cmd_mcast_addr_portnum,
10844                 (void *)&cmd_mcast_addr_addr,
10845                 NULL,
10846         },
10847 };
10848
10849 /* vf vlan anti spoof configuration */
10850
10851 /* Common result structure for vf vlan anti spoof */
10852 struct cmd_vf_vlan_anti_spoof_result {
10853         cmdline_fixed_string_t set;
10854         cmdline_fixed_string_t vf;
10855         cmdline_fixed_string_t vlan;
10856         cmdline_fixed_string_t antispoof;
10857         portid_t port_id;
10858         uint32_t vf_id;
10859         cmdline_fixed_string_t on_off;
10860 };
10861
10862 /* Common CLI fields for vf vlan anti spoof enable disable */
10863 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10864         TOKEN_STRING_INITIALIZER
10865                 (struct cmd_vf_vlan_anti_spoof_result,
10866                  set, "set");
10867 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10868         TOKEN_STRING_INITIALIZER
10869                 (struct cmd_vf_vlan_anti_spoof_result,
10870                  vf, "vf");
10871 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10872         TOKEN_STRING_INITIALIZER
10873                 (struct cmd_vf_vlan_anti_spoof_result,
10874                  vlan, "vlan");
10875 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10876         TOKEN_STRING_INITIALIZER
10877                 (struct cmd_vf_vlan_anti_spoof_result,
10878                  antispoof, "antispoof");
10879 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10880         TOKEN_NUM_INITIALIZER
10881                 (struct cmd_vf_vlan_anti_spoof_result,
10882                  port_id, RTE_UINT16);
10883 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10884         TOKEN_NUM_INITIALIZER
10885                 (struct cmd_vf_vlan_anti_spoof_result,
10886                  vf_id, RTE_UINT32);
10887 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10888         TOKEN_STRING_INITIALIZER
10889                 (struct cmd_vf_vlan_anti_spoof_result,
10890                  on_off, "on#off");
10891
10892 static void
10893 cmd_set_vf_vlan_anti_spoof_parsed(
10894         void *parsed_result,
10895         __rte_unused struct cmdline *cl,
10896         __rte_unused void *data)
10897 {
10898         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10899         int ret = -ENOTSUP;
10900
10901         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10902
10903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10904                 return;
10905
10906 #ifdef RTE_NET_IXGBE
10907         if (ret == -ENOTSUP)
10908                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10909                                 res->vf_id, is_on);
10910 #endif
10911 #ifdef RTE_NET_I40E
10912         if (ret == -ENOTSUP)
10913                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10914                                 res->vf_id, is_on);
10915 #endif
10916 #ifdef RTE_NET_BNXT
10917         if (ret == -ENOTSUP)
10918                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10919                                 res->vf_id, is_on);
10920 #endif
10921
10922         switch (ret) {
10923         case 0:
10924                 break;
10925         case -EINVAL:
10926                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
10927                 break;
10928         case -ENODEV:
10929                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
10930                 break;
10931         case -ENOTSUP:
10932                 fprintf(stderr, "function not implemented\n");
10933                 break;
10934         default:
10935                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
10936         }
10937 }
10938
10939 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10940         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10941         .data = NULL,
10942         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10943         .tokens = {
10944                 (void *)&cmd_vf_vlan_anti_spoof_set,
10945                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10946                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10947                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10948                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10949                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10950                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10951                 NULL,
10952         },
10953 };
10954
10955 /* vf mac anti spoof configuration */
10956
10957 /* Common result structure for vf mac anti spoof */
10958 struct cmd_vf_mac_anti_spoof_result {
10959         cmdline_fixed_string_t set;
10960         cmdline_fixed_string_t vf;
10961         cmdline_fixed_string_t mac;
10962         cmdline_fixed_string_t antispoof;
10963         portid_t port_id;
10964         uint32_t vf_id;
10965         cmdline_fixed_string_t on_off;
10966 };
10967
10968 /* Common CLI fields for vf mac anti spoof enable disable */
10969 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10970         TOKEN_STRING_INITIALIZER
10971                 (struct cmd_vf_mac_anti_spoof_result,
10972                  set, "set");
10973 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10974         TOKEN_STRING_INITIALIZER
10975                 (struct cmd_vf_mac_anti_spoof_result,
10976                  vf, "vf");
10977 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10978         TOKEN_STRING_INITIALIZER
10979                 (struct cmd_vf_mac_anti_spoof_result,
10980                  mac, "mac");
10981 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10982         TOKEN_STRING_INITIALIZER
10983                 (struct cmd_vf_mac_anti_spoof_result,
10984                  antispoof, "antispoof");
10985 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10986         TOKEN_NUM_INITIALIZER
10987                 (struct cmd_vf_mac_anti_spoof_result,
10988                  port_id, RTE_UINT16);
10989 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
10990         TOKEN_NUM_INITIALIZER
10991                 (struct cmd_vf_mac_anti_spoof_result,
10992                  vf_id, RTE_UINT32);
10993 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
10994         TOKEN_STRING_INITIALIZER
10995                 (struct cmd_vf_mac_anti_spoof_result,
10996                  on_off, "on#off");
10997
10998 static void
10999 cmd_set_vf_mac_anti_spoof_parsed(
11000         void *parsed_result,
11001         __rte_unused struct cmdline *cl,
11002         __rte_unused void *data)
11003 {
11004         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11005         int ret = -ENOTSUP;
11006
11007         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11008
11009         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11010                 return;
11011
11012 #ifdef RTE_NET_IXGBE
11013         if (ret == -ENOTSUP)
11014                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11015                         res->vf_id, is_on);
11016 #endif
11017 #ifdef RTE_NET_I40E
11018         if (ret == -ENOTSUP)
11019                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11020                         res->vf_id, is_on);
11021 #endif
11022 #ifdef RTE_NET_BNXT
11023         if (ret == -ENOTSUP)
11024                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11025                         res->vf_id, is_on);
11026 #endif
11027
11028         switch (ret) {
11029         case 0:
11030                 break;
11031         case -EINVAL:
11032                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11033                         res->vf_id, is_on);
11034                 break;
11035         case -ENODEV:
11036                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11037                 break;
11038         case -ENOTSUP:
11039                 fprintf(stderr, "function not implemented\n");
11040                 break;
11041         default:
11042                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11043         }
11044 }
11045
11046 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11047         .f = cmd_set_vf_mac_anti_spoof_parsed,
11048         .data = NULL,
11049         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11050         .tokens = {
11051                 (void *)&cmd_vf_mac_anti_spoof_set,
11052                 (void *)&cmd_vf_mac_anti_spoof_vf,
11053                 (void *)&cmd_vf_mac_anti_spoof_mac,
11054                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11055                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11056                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11057                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11058                 NULL,
11059         },
11060 };
11061
11062 /* vf vlan strip queue configuration */
11063
11064 /* Common result structure for vf mac anti spoof */
11065 struct cmd_vf_vlan_stripq_result {
11066         cmdline_fixed_string_t set;
11067         cmdline_fixed_string_t vf;
11068         cmdline_fixed_string_t vlan;
11069         cmdline_fixed_string_t stripq;
11070         portid_t port_id;
11071         uint16_t vf_id;
11072         cmdline_fixed_string_t on_off;
11073 };
11074
11075 /* Common CLI fields for vf vlan strip enable disable */
11076 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11077         TOKEN_STRING_INITIALIZER
11078                 (struct cmd_vf_vlan_stripq_result,
11079                  set, "set");
11080 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11081         TOKEN_STRING_INITIALIZER
11082                 (struct cmd_vf_vlan_stripq_result,
11083                  vf, "vf");
11084 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11085         TOKEN_STRING_INITIALIZER
11086                 (struct cmd_vf_vlan_stripq_result,
11087                  vlan, "vlan");
11088 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11089         TOKEN_STRING_INITIALIZER
11090                 (struct cmd_vf_vlan_stripq_result,
11091                  stripq, "stripq");
11092 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11093         TOKEN_NUM_INITIALIZER
11094                 (struct cmd_vf_vlan_stripq_result,
11095                  port_id, RTE_UINT16);
11096 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11097         TOKEN_NUM_INITIALIZER
11098                 (struct cmd_vf_vlan_stripq_result,
11099                  vf_id, RTE_UINT16);
11100 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11101         TOKEN_STRING_INITIALIZER
11102                 (struct cmd_vf_vlan_stripq_result,
11103                  on_off, "on#off");
11104
11105 static void
11106 cmd_set_vf_vlan_stripq_parsed(
11107         void *parsed_result,
11108         __rte_unused struct cmdline *cl,
11109         __rte_unused void *data)
11110 {
11111         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11112         int ret = -ENOTSUP;
11113
11114         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11115
11116         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11117                 return;
11118
11119 #ifdef RTE_NET_IXGBE
11120         if (ret == -ENOTSUP)
11121                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11122                         res->vf_id, is_on);
11123 #endif
11124 #ifdef RTE_NET_I40E
11125         if (ret == -ENOTSUP)
11126                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11127                         res->vf_id, is_on);
11128 #endif
11129 #ifdef RTE_NET_BNXT
11130         if (ret == -ENOTSUP)
11131                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11132                         res->vf_id, is_on);
11133 #endif
11134
11135         switch (ret) {
11136         case 0:
11137                 break;
11138         case -EINVAL:
11139                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11140                         res->vf_id, is_on);
11141                 break;
11142         case -ENODEV:
11143                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11144                 break;
11145         case -ENOTSUP:
11146                 fprintf(stderr, "function not implemented\n");
11147                 break;
11148         default:
11149                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11150         }
11151 }
11152
11153 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11154         .f = cmd_set_vf_vlan_stripq_parsed,
11155         .data = NULL,
11156         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11157         .tokens = {
11158                 (void *)&cmd_vf_vlan_stripq_set,
11159                 (void *)&cmd_vf_vlan_stripq_vf,
11160                 (void *)&cmd_vf_vlan_stripq_vlan,
11161                 (void *)&cmd_vf_vlan_stripq_stripq,
11162                 (void *)&cmd_vf_vlan_stripq_port_id,
11163                 (void *)&cmd_vf_vlan_stripq_vf_id,
11164                 (void *)&cmd_vf_vlan_stripq_on_off,
11165                 NULL,
11166         },
11167 };
11168
11169 /* vf vlan insert configuration */
11170
11171 /* Common result structure for vf vlan insert */
11172 struct cmd_vf_vlan_insert_result {
11173         cmdline_fixed_string_t set;
11174         cmdline_fixed_string_t vf;
11175         cmdline_fixed_string_t vlan;
11176         cmdline_fixed_string_t insert;
11177         portid_t port_id;
11178         uint16_t vf_id;
11179         uint16_t vlan_id;
11180 };
11181
11182 /* Common CLI fields for vf vlan insert enable disable */
11183 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11184         TOKEN_STRING_INITIALIZER
11185                 (struct cmd_vf_vlan_insert_result,
11186                  set, "set");
11187 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11188         TOKEN_STRING_INITIALIZER
11189                 (struct cmd_vf_vlan_insert_result,
11190                  vf, "vf");
11191 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11192         TOKEN_STRING_INITIALIZER
11193                 (struct cmd_vf_vlan_insert_result,
11194                  vlan, "vlan");
11195 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11196         TOKEN_STRING_INITIALIZER
11197                 (struct cmd_vf_vlan_insert_result,
11198                  insert, "insert");
11199 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11200         TOKEN_NUM_INITIALIZER
11201                 (struct cmd_vf_vlan_insert_result,
11202                  port_id, RTE_UINT16);
11203 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11204         TOKEN_NUM_INITIALIZER
11205                 (struct cmd_vf_vlan_insert_result,
11206                  vf_id, RTE_UINT16);
11207 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11208         TOKEN_NUM_INITIALIZER
11209                 (struct cmd_vf_vlan_insert_result,
11210                  vlan_id, RTE_UINT16);
11211
11212 static void
11213 cmd_set_vf_vlan_insert_parsed(
11214         void *parsed_result,
11215         __rte_unused struct cmdline *cl,
11216         __rte_unused void *data)
11217 {
11218         struct cmd_vf_vlan_insert_result *res = parsed_result;
11219         int ret = -ENOTSUP;
11220
11221         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11222                 return;
11223
11224 #ifdef RTE_NET_IXGBE
11225         if (ret == -ENOTSUP)
11226                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11227                         res->vlan_id);
11228 #endif
11229 #ifdef RTE_NET_I40E
11230         if (ret == -ENOTSUP)
11231                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11232                         res->vlan_id);
11233 #endif
11234 #ifdef RTE_NET_BNXT
11235         if (ret == -ENOTSUP)
11236                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11237                         res->vlan_id);
11238 #endif
11239
11240         switch (ret) {
11241         case 0:
11242                 break;
11243         case -EINVAL:
11244                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11245                         res->vf_id, res->vlan_id);
11246                 break;
11247         case -ENODEV:
11248                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11249                 break;
11250         case -ENOTSUP:
11251                 fprintf(stderr, "function not implemented\n");
11252                 break;
11253         default:
11254                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11255         }
11256 }
11257
11258 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11259         .f = cmd_set_vf_vlan_insert_parsed,
11260         .data = NULL,
11261         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11262         .tokens = {
11263                 (void *)&cmd_vf_vlan_insert_set,
11264                 (void *)&cmd_vf_vlan_insert_vf,
11265                 (void *)&cmd_vf_vlan_insert_vlan,
11266                 (void *)&cmd_vf_vlan_insert_insert,
11267                 (void *)&cmd_vf_vlan_insert_port_id,
11268                 (void *)&cmd_vf_vlan_insert_vf_id,
11269                 (void *)&cmd_vf_vlan_insert_vlan_id,
11270                 NULL,
11271         },
11272 };
11273
11274 /* tx loopback configuration */
11275
11276 /* Common result structure for tx loopback */
11277 struct cmd_tx_loopback_result {
11278         cmdline_fixed_string_t set;
11279         cmdline_fixed_string_t tx;
11280         cmdline_fixed_string_t loopback;
11281         portid_t port_id;
11282         cmdline_fixed_string_t on_off;
11283 };
11284
11285 /* Common CLI fields for tx loopback enable disable */
11286 cmdline_parse_token_string_t cmd_tx_loopback_set =
11287         TOKEN_STRING_INITIALIZER
11288                 (struct cmd_tx_loopback_result,
11289                  set, "set");
11290 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11291         TOKEN_STRING_INITIALIZER
11292                 (struct cmd_tx_loopback_result,
11293                  tx, "tx");
11294 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11295         TOKEN_STRING_INITIALIZER
11296                 (struct cmd_tx_loopback_result,
11297                  loopback, "loopback");
11298 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11299         TOKEN_NUM_INITIALIZER
11300                 (struct cmd_tx_loopback_result,
11301                  port_id, RTE_UINT16);
11302 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11303         TOKEN_STRING_INITIALIZER
11304                 (struct cmd_tx_loopback_result,
11305                  on_off, "on#off");
11306
11307 static void
11308 cmd_set_tx_loopback_parsed(
11309         void *parsed_result,
11310         __rte_unused struct cmdline *cl,
11311         __rte_unused void *data)
11312 {
11313         struct cmd_tx_loopback_result *res = parsed_result;
11314         int ret = -ENOTSUP;
11315
11316         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11317
11318         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11319                 return;
11320
11321 #ifdef RTE_NET_IXGBE
11322         if (ret == -ENOTSUP)
11323                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11324 #endif
11325 #ifdef RTE_NET_I40E
11326         if (ret == -ENOTSUP)
11327                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11328 #endif
11329 #ifdef RTE_NET_BNXT
11330         if (ret == -ENOTSUP)
11331                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11332 #endif
11333 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11334         if (ret == -ENOTSUP)
11335                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11336 #endif
11337
11338         switch (ret) {
11339         case 0:
11340                 break;
11341         case -EINVAL:
11342                 fprintf(stderr, "invalid is_on %d\n", is_on);
11343                 break;
11344         case -ENODEV:
11345                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11346                 break;
11347         case -ENOTSUP:
11348                 fprintf(stderr, "function not implemented\n");
11349                 break;
11350         default:
11351                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11352         }
11353 }
11354
11355 cmdline_parse_inst_t cmd_set_tx_loopback = {
11356         .f = cmd_set_tx_loopback_parsed,
11357         .data = NULL,
11358         .help_str = "set tx loopback <port_id> on|off",
11359         .tokens = {
11360                 (void *)&cmd_tx_loopback_set,
11361                 (void *)&cmd_tx_loopback_tx,
11362                 (void *)&cmd_tx_loopback_loopback,
11363                 (void *)&cmd_tx_loopback_port_id,
11364                 (void *)&cmd_tx_loopback_on_off,
11365                 NULL,
11366         },
11367 };
11368
11369 /* all queues drop enable configuration */
11370
11371 /* Common result structure for all queues drop enable */
11372 struct cmd_all_queues_drop_en_result {
11373         cmdline_fixed_string_t set;
11374         cmdline_fixed_string_t all;
11375         cmdline_fixed_string_t queues;
11376         cmdline_fixed_string_t drop;
11377         portid_t port_id;
11378         cmdline_fixed_string_t on_off;
11379 };
11380
11381 /* Common CLI fields for tx loopback enable disable */
11382 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11383         TOKEN_STRING_INITIALIZER
11384                 (struct cmd_all_queues_drop_en_result,
11385                  set, "set");
11386 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11387         TOKEN_STRING_INITIALIZER
11388                 (struct cmd_all_queues_drop_en_result,
11389                  all, "all");
11390 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11391         TOKEN_STRING_INITIALIZER
11392                 (struct cmd_all_queues_drop_en_result,
11393                  queues, "queues");
11394 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11395         TOKEN_STRING_INITIALIZER
11396                 (struct cmd_all_queues_drop_en_result,
11397                  drop, "drop");
11398 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11399         TOKEN_NUM_INITIALIZER
11400                 (struct cmd_all_queues_drop_en_result,
11401                  port_id, RTE_UINT16);
11402 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11403         TOKEN_STRING_INITIALIZER
11404                 (struct cmd_all_queues_drop_en_result,
11405                  on_off, "on#off");
11406
11407 static void
11408 cmd_set_all_queues_drop_en_parsed(
11409         void *parsed_result,
11410         __rte_unused struct cmdline *cl,
11411         __rte_unused void *data)
11412 {
11413         struct cmd_all_queues_drop_en_result *res = parsed_result;
11414         int ret = -ENOTSUP;
11415         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11416
11417         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11418                 return;
11419
11420 #ifdef RTE_NET_IXGBE
11421         if (ret == -ENOTSUP)
11422                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11423 #endif
11424 #ifdef RTE_NET_BNXT
11425         if (ret == -ENOTSUP)
11426                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11427 #endif
11428         switch (ret) {
11429         case 0:
11430                 break;
11431         case -EINVAL:
11432                 fprintf(stderr, "invalid is_on %d\n", is_on);
11433                 break;
11434         case -ENODEV:
11435                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11436                 break;
11437         case -ENOTSUP:
11438                 fprintf(stderr, "function not implemented\n");
11439                 break;
11440         default:
11441                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11442         }
11443 }
11444
11445 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11446         .f = cmd_set_all_queues_drop_en_parsed,
11447         .data = NULL,
11448         .help_str = "set all queues drop <port_id> on|off",
11449         .tokens = {
11450                 (void *)&cmd_all_queues_drop_en_set,
11451                 (void *)&cmd_all_queues_drop_en_all,
11452                 (void *)&cmd_all_queues_drop_en_queues,
11453                 (void *)&cmd_all_queues_drop_en_drop,
11454                 (void *)&cmd_all_queues_drop_en_port_id,
11455                 (void *)&cmd_all_queues_drop_en_on_off,
11456                 NULL,
11457         },
11458 };
11459
11460 /* vf split drop enable configuration */
11461
11462 /* Common result structure for vf split drop enable */
11463 struct cmd_vf_split_drop_en_result {
11464         cmdline_fixed_string_t set;
11465         cmdline_fixed_string_t vf;
11466         cmdline_fixed_string_t split;
11467         cmdline_fixed_string_t drop;
11468         portid_t port_id;
11469         uint16_t vf_id;
11470         cmdline_fixed_string_t on_off;
11471 };
11472
11473 /* Common CLI fields for vf split drop enable disable */
11474 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11475         TOKEN_STRING_INITIALIZER
11476                 (struct cmd_vf_split_drop_en_result,
11477                  set, "set");
11478 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11479         TOKEN_STRING_INITIALIZER
11480                 (struct cmd_vf_split_drop_en_result,
11481                  vf, "vf");
11482 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11483         TOKEN_STRING_INITIALIZER
11484                 (struct cmd_vf_split_drop_en_result,
11485                  split, "split");
11486 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11487         TOKEN_STRING_INITIALIZER
11488                 (struct cmd_vf_split_drop_en_result,
11489                  drop, "drop");
11490 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11491         TOKEN_NUM_INITIALIZER
11492                 (struct cmd_vf_split_drop_en_result,
11493                  port_id, RTE_UINT16);
11494 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11495         TOKEN_NUM_INITIALIZER
11496                 (struct cmd_vf_split_drop_en_result,
11497                  vf_id, RTE_UINT16);
11498 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11499         TOKEN_STRING_INITIALIZER
11500                 (struct cmd_vf_split_drop_en_result,
11501                  on_off, "on#off");
11502
11503 static void
11504 cmd_set_vf_split_drop_en_parsed(
11505         void *parsed_result,
11506         __rte_unused struct cmdline *cl,
11507         __rte_unused void *data)
11508 {
11509         struct cmd_vf_split_drop_en_result *res = parsed_result;
11510         int ret = -ENOTSUP;
11511         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11512
11513         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11514                 return;
11515
11516 #ifdef RTE_NET_IXGBE
11517         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11518                         is_on);
11519 #endif
11520         switch (ret) {
11521         case 0:
11522                 break;
11523         case -EINVAL:
11524                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11525                         res->vf_id, is_on);
11526                 break;
11527         case -ENODEV:
11528                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11529                 break;
11530         case -ENOTSUP:
11531                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11532                 break;
11533         default:
11534                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11535         }
11536 }
11537
11538 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11539         .f = cmd_set_vf_split_drop_en_parsed,
11540         .data = NULL,
11541         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11542         .tokens = {
11543                 (void *)&cmd_vf_split_drop_en_set,
11544                 (void *)&cmd_vf_split_drop_en_vf,
11545                 (void *)&cmd_vf_split_drop_en_split,
11546                 (void *)&cmd_vf_split_drop_en_drop,
11547                 (void *)&cmd_vf_split_drop_en_port_id,
11548                 (void *)&cmd_vf_split_drop_en_vf_id,
11549                 (void *)&cmd_vf_split_drop_en_on_off,
11550                 NULL,
11551         },
11552 };
11553
11554 /* vf mac address configuration */
11555
11556 /* Common result structure for vf mac address */
11557 struct cmd_set_vf_mac_addr_result {
11558         cmdline_fixed_string_t set;
11559         cmdline_fixed_string_t vf;
11560         cmdline_fixed_string_t mac;
11561         cmdline_fixed_string_t addr;
11562         portid_t port_id;
11563         uint16_t vf_id;
11564         struct rte_ether_addr mac_addr;
11565
11566 };
11567
11568 /* Common CLI fields for vf split drop enable disable */
11569 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11570         TOKEN_STRING_INITIALIZER
11571                 (struct cmd_set_vf_mac_addr_result,
11572                  set, "set");
11573 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11574         TOKEN_STRING_INITIALIZER
11575                 (struct cmd_set_vf_mac_addr_result,
11576                  vf, "vf");
11577 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11578         TOKEN_STRING_INITIALIZER
11579                 (struct cmd_set_vf_mac_addr_result,
11580                  mac, "mac");
11581 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11582         TOKEN_STRING_INITIALIZER
11583                 (struct cmd_set_vf_mac_addr_result,
11584                  addr, "addr");
11585 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11586         TOKEN_NUM_INITIALIZER
11587                 (struct cmd_set_vf_mac_addr_result,
11588                  port_id, RTE_UINT16);
11589 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11590         TOKEN_NUM_INITIALIZER
11591                 (struct cmd_set_vf_mac_addr_result,
11592                  vf_id, RTE_UINT16);
11593 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11594         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11595                  mac_addr);
11596
11597 static void
11598 cmd_set_vf_mac_addr_parsed(
11599         void *parsed_result,
11600         __rte_unused struct cmdline *cl,
11601         __rte_unused void *data)
11602 {
11603         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11604         int ret = -ENOTSUP;
11605
11606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11607                 return;
11608
11609 #ifdef RTE_NET_IXGBE
11610         if (ret == -ENOTSUP)
11611                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11612                                 &res->mac_addr);
11613 #endif
11614 #ifdef RTE_NET_I40E
11615         if (ret == -ENOTSUP)
11616                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11617                                 &res->mac_addr);
11618 #endif
11619 #ifdef RTE_NET_BNXT
11620         if (ret == -ENOTSUP)
11621                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11622                                 &res->mac_addr);
11623 #endif
11624
11625         switch (ret) {
11626         case 0:
11627                 break;
11628         case -EINVAL:
11629                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11630                 break;
11631         case -ENODEV:
11632                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11633                 break;
11634         case -ENOTSUP:
11635                 fprintf(stderr, "function not implemented\n");
11636                 break;
11637         default:
11638                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11639         }
11640 }
11641
11642 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11643         .f = cmd_set_vf_mac_addr_parsed,
11644         .data = NULL,
11645         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11646         .tokens = {
11647                 (void *)&cmd_set_vf_mac_addr_set,
11648                 (void *)&cmd_set_vf_mac_addr_vf,
11649                 (void *)&cmd_set_vf_mac_addr_mac,
11650                 (void *)&cmd_set_vf_mac_addr_addr,
11651                 (void *)&cmd_set_vf_mac_addr_port_id,
11652                 (void *)&cmd_set_vf_mac_addr_vf_id,
11653                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11654                 NULL,
11655         },
11656 };
11657
11658 /* MACsec configuration */
11659
11660 /* Common result structure for MACsec offload enable */
11661 struct cmd_macsec_offload_on_result {
11662         cmdline_fixed_string_t set;
11663         cmdline_fixed_string_t macsec;
11664         cmdline_fixed_string_t offload;
11665         portid_t port_id;
11666         cmdline_fixed_string_t on;
11667         cmdline_fixed_string_t encrypt;
11668         cmdline_fixed_string_t en_on_off;
11669         cmdline_fixed_string_t replay_protect;
11670         cmdline_fixed_string_t rp_on_off;
11671 };
11672
11673 /* Common CLI fields for MACsec offload disable */
11674 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11675         TOKEN_STRING_INITIALIZER
11676                 (struct cmd_macsec_offload_on_result,
11677                  set, "set");
11678 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11679         TOKEN_STRING_INITIALIZER
11680                 (struct cmd_macsec_offload_on_result,
11681                  macsec, "macsec");
11682 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11683         TOKEN_STRING_INITIALIZER
11684                 (struct cmd_macsec_offload_on_result,
11685                  offload, "offload");
11686 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11687         TOKEN_NUM_INITIALIZER
11688                 (struct cmd_macsec_offload_on_result,
11689                  port_id, RTE_UINT16);
11690 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11691         TOKEN_STRING_INITIALIZER
11692                 (struct cmd_macsec_offload_on_result,
11693                  on, "on");
11694 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11695         TOKEN_STRING_INITIALIZER
11696                 (struct cmd_macsec_offload_on_result,
11697                  encrypt, "encrypt");
11698 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11699         TOKEN_STRING_INITIALIZER
11700                 (struct cmd_macsec_offload_on_result,
11701                  en_on_off, "on#off");
11702 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11703         TOKEN_STRING_INITIALIZER
11704                 (struct cmd_macsec_offload_on_result,
11705                  replay_protect, "replay-protect");
11706 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11707         TOKEN_STRING_INITIALIZER
11708                 (struct cmd_macsec_offload_on_result,
11709                  rp_on_off, "on#off");
11710
11711 static void
11712 cmd_set_macsec_offload_on_parsed(
11713         void *parsed_result,
11714         __rte_unused struct cmdline *cl,
11715         __rte_unused void *data)
11716 {
11717         struct cmd_macsec_offload_on_result *res = parsed_result;
11718         int ret = -ENOTSUP;
11719         portid_t port_id = res->port_id;
11720         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11721         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11722         struct rte_eth_dev_info dev_info;
11723
11724         if (port_id_is_invalid(port_id, ENABLED_WARN))
11725                 return;
11726         if (!port_is_stopped(port_id)) {
11727                 fprintf(stderr, "Please stop port %d first\n", port_id);
11728                 return;
11729         }
11730
11731         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11732         if (ret != 0)
11733                 return;
11734
11735         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11736 #ifdef RTE_NET_IXGBE
11737                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11738 #endif
11739         }
11740         RTE_SET_USED(en);
11741         RTE_SET_USED(rp);
11742
11743         switch (ret) {
11744         case 0:
11745                 ports[port_id].dev_conf.txmode.offloads |=
11746                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11747                 cmd_reconfig_device_queue(port_id, 1, 1);
11748                 break;
11749         case -ENODEV:
11750                 fprintf(stderr, "invalid port_id %d\n", port_id);
11751                 break;
11752         case -ENOTSUP:
11753                 fprintf(stderr, "not supported on port %d\n", port_id);
11754                 break;
11755         default:
11756                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11757         }
11758 }
11759
11760 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11761         .f = cmd_set_macsec_offload_on_parsed,
11762         .data = NULL,
11763         .help_str = "set macsec offload <port_id> on "
11764                 "encrypt on|off replay-protect on|off",
11765         .tokens = {
11766                 (void *)&cmd_macsec_offload_on_set,
11767                 (void *)&cmd_macsec_offload_on_macsec,
11768                 (void *)&cmd_macsec_offload_on_offload,
11769                 (void *)&cmd_macsec_offload_on_port_id,
11770                 (void *)&cmd_macsec_offload_on_on,
11771                 (void *)&cmd_macsec_offload_on_encrypt,
11772                 (void *)&cmd_macsec_offload_on_en_on_off,
11773                 (void *)&cmd_macsec_offload_on_replay_protect,
11774                 (void *)&cmd_macsec_offload_on_rp_on_off,
11775                 NULL,
11776         },
11777 };
11778
11779 /* Common result structure for MACsec offload disable */
11780 struct cmd_macsec_offload_off_result {
11781         cmdline_fixed_string_t set;
11782         cmdline_fixed_string_t macsec;
11783         cmdline_fixed_string_t offload;
11784         portid_t port_id;
11785         cmdline_fixed_string_t off;
11786 };
11787
11788 /* Common CLI fields for MACsec offload disable */
11789 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11790         TOKEN_STRING_INITIALIZER
11791                 (struct cmd_macsec_offload_off_result,
11792                  set, "set");
11793 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11794         TOKEN_STRING_INITIALIZER
11795                 (struct cmd_macsec_offload_off_result,
11796                  macsec, "macsec");
11797 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11798         TOKEN_STRING_INITIALIZER
11799                 (struct cmd_macsec_offload_off_result,
11800                  offload, "offload");
11801 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11802         TOKEN_NUM_INITIALIZER
11803                 (struct cmd_macsec_offload_off_result,
11804                  port_id, RTE_UINT16);
11805 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_macsec_offload_off_result,
11808                  off, "off");
11809
11810 static void
11811 cmd_set_macsec_offload_off_parsed(
11812         void *parsed_result,
11813         __rte_unused struct cmdline *cl,
11814         __rte_unused void *data)
11815 {
11816         struct cmd_macsec_offload_off_result *res = parsed_result;
11817         int ret = -ENOTSUP;
11818         struct rte_eth_dev_info dev_info;
11819         portid_t port_id = res->port_id;
11820
11821         if (port_id_is_invalid(port_id, ENABLED_WARN))
11822                 return;
11823         if (!port_is_stopped(port_id)) {
11824                 fprintf(stderr, "Please stop port %d first\n", port_id);
11825                 return;
11826         }
11827
11828         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11829         if (ret != 0)
11830                 return;
11831
11832         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11833 #ifdef RTE_NET_IXGBE
11834                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11835 #endif
11836         }
11837         switch (ret) {
11838         case 0:
11839                 ports[port_id].dev_conf.txmode.offloads &=
11840                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11841                 cmd_reconfig_device_queue(port_id, 1, 1);
11842                 break;
11843         case -ENODEV:
11844                 fprintf(stderr, "invalid port_id %d\n", port_id);
11845                 break;
11846         case -ENOTSUP:
11847                 fprintf(stderr, "not supported on port %d\n", port_id);
11848                 break;
11849         default:
11850                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11851         }
11852 }
11853
11854 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11855         .f = cmd_set_macsec_offload_off_parsed,
11856         .data = NULL,
11857         .help_str = "set macsec offload <port_id> off",
11858         .tokens = {
11859                 (void *)&cmd_macsec_offload_off_set,
11860                 (void *)&cmd_macsec_offload_off_macsec,
11861                 (void *)&cmd_macsec_offload_off_offload,
11862                 (void *)&cmd_macsec_offload_off_port_id,
11863                 (void *)&cmd_macsec_offload_off_off,
11864                 NULL,
11865         },
11866 };
11867
11868 /* Common result structure for MACsec secure connection configure */
11869 struct cmd_macsec_sc_result {
11870         cmdline_fixed_string_t set;
11871         cmdline_fixed_string_t macsec;
11872         cmdline_fixed_string_t sc;
11873         cmdline_fixed_string_t tx_rx;
11874         portid_t port_id;
11875         struct rte_ether_addr mac;
11876         uint16_t pi;
11877 };
11878
11879 /* Common CLI fields for MACsec secure connection configure */
11880 cmdline_parse_token_string_t cmd_macsec_sc_set =
11881         TOKEN_STRING_INITIALIZER
11882                 (struct cmd_macsec_sc_result,
11883                  set, "set");
11884 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11885         TOKEN_STRING_INITIALIZER
11886                 (struct cmd_macsec_sc_result,
11887                  macsec, "macsec");
11888 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11889         TOKEN_STRING_INITIALIZER
11890                 (struct cmd_macsec_sc_result,
11891                  sc, "sc");
11892 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11893         TOKEN_STRING_INITIALIZER
11894                 (struct cmd_macsec_sc_result,
11895                  tx_rx, "tx#rx");
11896 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11897         TOKEN_NUM_INITIALIZER
11898                 (struct cmd_macsec_sc_result,
11899                  port_id, RTE_UINT16);
11900 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11901         TOKEN_ETHERADDR_INITIALIZER
11902                 (struct cmd_macsec_sc_result,
11903                  mac);
11904 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11905         TOKEN_NUM_INITIALIZER
11906                 (struct cmd_macsec_sc_result,
11907                  pi, RTE_UINT16);
11908
11909 static void
11910 cmd_set_macsec_sc_parsed(
11911         void *parsed_result,
11912         __rte_unused struct cmdline *cl,
11913         __rte_unused void *data)
11914 {
11915         struct cmd_macsec_sc_result *res = parsed_result;
11916         int ret = -ENOTSUP;
11917         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11918
11919 #ifdef RTE_NET_IXGBE
11920         ret = is_tx ?
11921                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11922                                 res->mac.addr_bytes) :
11923                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11924                                 res->mac.addr_bytes, res->pi);
11925 #endif
11926         RTE_SET_USED(is_tx);
11927
11928         switch (ret) {
11929         case 0:
11930                 break;
11931         case -ENODEV:
11932                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11933                 break;
11934         case -ENOTSUP:
11935                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11936                 break;
11937         default:
11938                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11939         }
11940 }
11941
11942 cmdline_parse_inst_t cmd_set_macsec_sc = {
11943         .f = cmd_set_macsec_sc_parsed,
11944         .data = NULL,
11945         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11946         .tokens = {
11947                 (void *)&cmd_macsec_sc_set,
11948                 (void *)&cmd_macsec_sc_macsec,
11949                 (void *)&cmd_macsec_sc_sc,
11950                 (void *)&cmd_macsec_sc_tx_rx,
11951                 (void *)&cmd_macsec_sc_port_id,
11952                 (void *)&cmd_macsec_sc_mac,
11953                 (void *)&cmd_macsec_sc_pi,
11954                 NULL,
11955         },
11956 };
11957
11958 /* Common result structure for MACsec secure connection configure */
11959 struct cmd_macsec_sa_result {
11960         cmdline_fixed_string_t set;
11961         cmdline_fixed_string_t macsec;
11962         cmdline_fixed_string_t sa;
11963         cmdline_fixed_string_t tx_rx;
11964         portid_t port_id;
11965         uint8_t idx;
11966         uint8_t an;
11967         uint32_t pn;
11968         cmdline_fixed_string_t key;
11969 };
11970
11971 /* Common CLI fields for MACsec secure connection configure */
11972 cmdline_parse_token_string_t cmd_macsec_sa_set =
11973         TOKEN_STRING_INITIALIZER
11974                 (struct cmd_macsec_sa_result,
11975                  set, "set");
11976 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11977         TOKEN_STRING_INITIALIZER
11978                 (struct cmd_macsec_sa_result,
11979                  macsec, "macsec");
11980 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11981         TOKEN_STRING_INITIALIZER
11982                 (struct cmd_macsec_sa_result,
11983                  sa, "sa");
11984 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11985         TOKEN_STRING_INITIALIZER
11986                 (struct cmd_macsec_sa_result,
11987                  tx_rx, "tx#rx");
11988 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11989         TOKEN_NUM_INITIALIZER
11990                 (struct cmd_macsec_sa_result,
11991                  port_id, RTE_UINT16);
11992 cmdline_parse_token_num_t cmd_macsec_sa_idx =
11993         TOKEN_NUM_INITIALIZER
11994                 (struct cmd_macsec_sa_result,
11995                  idx, RTE_UINT8);
11996 cmdline_parse_token_num_t cmd_macsec_sa_an =
11997         TOKEN_NUM_INITIALIZER
11998                 (struct cmd_macsec_sa_result,
11999                  an, RTE_UINT8);
12000 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12001         TOKEN_NUM_INITIALIZER
12002                 (struct cmd_macsec_sa_result,
12003                  pn, RTE_UINT32);
12004 cmdline_parse_token_string_t cmd_macsec_sa_key =
12005         TOKEN_STRING_INITIALIZER
12006                 (struct cmd_macsec_sa_result,
12007                  key, NULL);
12008
12009 static void
12010 cmd_set_macsec_sa_parsed(
12011         void *parsed_result,
12012         __rte_unused struct cmdline *cl,
12013         __rte_unused void *data)
12014 {
12015         struct cmd_macsec_sa_result *res = parsed_result;
12016         int ret = -ENOTSUP;
12017         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12018         uint8_t key[16] = { 0 };
12019         uint8_t xdgt0;
12020         uint8_t xdgt1;
12021         int key_len;
12022         int i;
12023
12024         key_len = strlen(res->key) / 2;
12025         if (key_len > 16)
12026                 key_len = 16;
12027
12028         for (i = 0; i < key_len; i++) {
12029                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12030                 if (xdgt0 == 0xFF)
12031                         return;
12032                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12033                 if (xdgt1 == 0xFF)
12034                         return;
12035                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12036         }
12037
12038 #ifdef RTE_NET_IXGBE
12039         ret = is_tx ?
12040                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12041                         res->idx, res->an, res->pn, key) :
12042                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12043                         res->idx, res->an, res->pn, key);
12044 #endif
12045         RTE_SET_USED(is_tx);
12046         RTE_SET_USED(key);
12047
12048         switch (ret) {
12049         case 0:
12050                 break;
12051         case -EINVAL:
12052                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12053                 break;
12054         case -ENODEV:
12055                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12056                 break;
12057         case -ENOTSUP:
12058                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12059                 break;
12060         default:
12061                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12062         }
12063 }
12064
12065 cmdline_parse_inst_t cmd_set_macsec_sa = {
12066         .f = cmd_set_macsec_sa_parsed,
12067         .data = NULL,
12068         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12069         .tokens = {
12070                 (void *)&cmd_macsec_sa_set,
12071                 (void *)&cmd_macsec_sa_macsec,
12072                 (void *)&cmd_macsec_sa_sa,
12073                 (void *)&cmd_macsec_sa_tx_rx,
12074                 (void *)&cmd_macsec_sa_port_id,
12075                 (void *)&cmd_macsec_sa_idx,
12076                 (void *)&cmd_macsec_sa_an,
12077                 (void *)&cmd_macsec_sa_pn,
12078                 (void *)&cmd_macsec_sa_key,
12079                 NULL,
12080         },
12081 };
12082
12083 /* VF unicast promiscuous mode configuration */
12084
12085 /* Common result structure for VF unicast promiscuous mode */
12086 struct cmd_vf_promisc_result {
12087         cmdline_fixed_string_t set;
12088         cmdline_fixed_string_t vf;
12089         cmdline_fixed_string_t promisc;
12090         portid_t port_id;
12091         uint32_t vf_id;
12092         cmdline_fixed_string_t on_off;
12093 };
12094
12095 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12096 cmdline_parse_token_string_t cmd_vf_promisc_set =
12097         TOKEN_STRING_INITIALIZER
12098                 (struct cmd_vf_promisc_result,
12099                  set, "set");
12100 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12101         TOKEN_STRING_INITIALIZER
12102                 (struct cmd_vf_promisc_result,
12103                  vf, "vf");
12104 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12105         TOKEN_STRING_INITIALIZER
12106                 (struct cmd_vf_promisc_result,
12107                  promisc, "promisc");
12108 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12109         TOKEN_NUM_INITIALIZER
12110                 (struct cmd_vf_promisc_result,
12111                  port_id, RTE_UINT16);
12112 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12113         TOKEN_NUM_INITIALIZER
12114                 (struct cmd_vf_promisc_result,
12115                  vf_id, RTE_UINT32);
12116 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12117         TOKEN_STRING_INITIALIZER
12118                 (struct cmd_vf_promisc_result,
12119                  on_off, "on#off");
12120
12121 static void
12122 cmd_set_vf_promisc_parsed(
12123         void *parsed_result,
12124         __rte_unused struct cmdline *cl,
12125         __rte_unused void *data)
12126 {
12127         struct cmd_vf_promisc_result *res = parsed_result;
12128         int ret = -ENOTSUP;
12129
12130         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12131
12132         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12133                 return;
12134
12135 #ifdef RTE_NET_I40E
12136         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12137                                                   res->vf_id, is_on);
12138 #endif
12139
12140         switch (ret) {
12141         case 0:
12142                 break;
12143         case -EINVAL:
12144                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12145                 break;
12146         case -ENODEV:
12147                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12148                 break;
12149         case -ENOTSUP:
12150                 fprintf(stderr, "function not implemented\n");
12151                 break;
12152         default:
12153                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12154         }
12155 }
12156
12157 cmdline_parse_inst_t cmd_set_vf_promisc = {
12158         .f = cmd_set_vf_promisc_parsed,
12159         .data = NULL,
12160         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12161                 "Set unicast promiscuous mode for a VF from the PF",
12162         .tokens = {
12163                 (void *)&cmd_vf_promisc_set,
12164                 (void *)&cmd_vf_promisc_vf,
12165                 (void *)&cmd_vf_promisc_promisc,
12166                 (void *)&cmd_vf_promisc_port_id,
12167                 (void *)&cmd_vf_promisc_vf_id,
12168                 (void *)&cmd_vf_promisc_on_off,
12169                 NULL,
12170         },
12171 };
12172
12173 /* VF multicast promiscuous mode configuration */
12174
12175 /* Common result structure for VF multicast promiscuous mode */
12176 struct cmd_vf_allmulti_result {
12177         cmdline_fixed_string_t set;
12178         cmdline_fixed_string_t vf;
12179         cmdline_fixed_string_t allmulti;
12180         portid_t port_id;
12181         uint32_t vf_id;
12182         cmdline_fixed_string_t on_off;
12183 };
12184
12185 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12186 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12187         TOKEN_STRING_INITIALIZER
12188                 (struct cmd_vf_allmulti_result,
12189                  set, "set");
12190 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12191         TOKEN_STRING_INITIALIZER
12192                 (struct cmd_vf_allmulti_result,
12193                  vf, "vf");
12194 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_vf_allmulti_result,
12197                  allmulti, "allmulti");
12198 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12199         TOKEN_NUM_INITIALIZER
12200                 (struct cmd_vf_allmulti_result,
12201                  port_id, RTE_UINT16);
12202 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12203         TOKEN_NUM_INITIALIZER
12204                 (struct cmd_vf_allmulti_result,
12205                  vf_id, RTE_UINT32);
12206 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12207         TOKEN_STRING_INITIALIZER
12208                 (struct cmd_vf_allmulti_result,
12209                  on_off, "on#off");
12210
12211 static void
12212 cmd_set_vf_allmulti_parsed(
12213         void *parsed_result,
12214         __rte_unused struct cmdline *cl,
12215         __rte_unused void *data)
12216 {
12217         struct cmd_vf_allmulti_result *res = parsed_result;
12218         int ret = -ENOTSUP;
12219
12220         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12221
12222         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12223                 return;
12224
12225 #ifdef RTE_NET_I40E
12226         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12227                                                     res->vf_id, is_on);
12228 #endif
12229
12230         switch (ret) {
12231         case 0:
12232                 break;
12233         case -EINVAL:
12234                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12235                 break;
12236         case -ENODEV:
12237                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12238                 break;
12239         case -ENOTSUP:
12240                 fprintf(stderr, "function not implemented\n");
12241                 break;
12242         default:
12243                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12244         }
12245 }
12246
12247 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12248         .f = cmd_set_vf_allmulti_parsed,
12249         .data = NULL,
12250         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12251                 "Set multicast promiscuous mode for a VF from the PF",
12252         .tokens = {
12253                 (void *)&cmd_vf_allmulti_set,
12254                 (void *)&cmd_vf_allmulti_vf,
12255                 (void *)&cmd_vf_allmulti_allmulti,
12256                 (void *)&cmd_vf_allmulti_port_id,
12257                 (void *)&cmd_vf_allmulti_vf_id,
12258                 (void *)&cmd_vf_allmulti_on_off,
12259                 NULL,
12260         },
12261 };
12262
12263 /* vf broadcast mode configuration */
12264
12265 /* Common result structure for vf broadcast */
12266 struct cmd_set_vf_broadcast_result {
12267         cmdline_fixed_string_t set;
12268         cmdline_fixed_string_t vf;
12269         cmdline_fixed_string_t broadcast;
12270         portid_t port_id;
12271         uint16_t vf_id;
12272         cmdline_fixed_string_t on_off;
12273 };
12274
12275 /* Common CLI fields for vf broadcast enable disable */
12276 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12277         TOKEN_STRING_INITIALIZER
12278                 (struct cmd_set_vf_broadcast_result,
12279                  set, "set");
12280 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12281         TOKEN_STRING_INITIALIZER
12282                 (struct cmd_set_vf_broadcast_result,
12283                  vf, "vf");
12284 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12285         TOKEN_STRING_INITIALIZER
12286                 (struct cmd_set_vf_broadcast_result,
12287                  broadcast, "broadcast");
12288 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12289         TOKEN_NUM_INITIALIZER
12290                 (struct cmd_set_vf_broadcast_result,
12291                  port_id, RTE_UINT16);
12292 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12293         TOKEN_NUM_INITIALIZER
12294                 (struct cmd_set_vf_broadcast_result,
12295                  vf_id, RTE_UINT16);
12296 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12297         TOKEN_STRING_INITIALIZER
12298                 (struct cmd_set_vf_broadcast_result,
12299                  on_off, "on#off");
12300
12301 static void
12302 cmd_set_vf_broadcast_parsed(
12303         void *parsed_result,
12304         __rte_unused struct cmdline *cl,
12305         __rte_unused void *data)
12306 {
12307         struct cmd_set_vf_broadcast_result *res = parsed_result;
12308         int ret = -ENOTSUP;
12309
12310         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12311
12312         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12313                 return;
12314
12315 #ifdef RTE_NET_I40E
12316         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12317                                             res->vf_id, is_on);
12318 #endif
12319
12320         switch (ret) {
12321         case 0:
12322                 break;
12323         case -EINVAL:
12324                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12325                         res->vf_id, is_on);
12326                 break;
12327         case -ENODEV:
12328                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12329                 break;
12330         case -ENOTSUP:
12331                 fprintf(stderr, "function not implemented\n");
12332                 break;
12333         default:
12334                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12335         }
12336 }
12337
12338 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12339         .f = cmd_set_vf_broadcast_parsed,
12340         .data = NULL,
12341         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12342         .tokens = {
12343                 (void *)&cmd_set_vf_broadcast_set,
12344                 (void *)&cmd_set_vf_broadcast_vf,
12345                 (void *)&cmd_set_vf_broadcast_broadcast,
12346                 (void *)&cmd_set_vf_broadcast_port_id,
12347                 (void *)&cmd_set_vf_broadcast_vf_id,
12348                 (void *)&cmd_set_vf_broadcast_on_off,
12349                 NULL,
12350         },
12351 };
12352
12353 /* vf vlan tag configuration */
12354
12355 /* Common result structure for vf vlan tag */
12356 struct cmd_set_vf_vlan_tag_result {
12357         cmdline_fixed_string_t set;
12358         cmdline_fixed_string_t vf;
12359         cmdline_fixed_string_t vlan;
12360         cmdline_fixed_string_t tag;
12361         portid_t port_id;
12362         uint16_t vf_id;
12363         cmdline_fixed_string_t on_off;
12364 };
12365
12366 /* Common CLI fields for vf vlan tag enable disable */
12367 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12368         TOKEN_STRING_INITIALIZER
12369                 (struct cmd_set_vf_vlan_tag_result,
12370                  set, "set");
12371 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12372         TOKEN_STRING_INITIALIZER
12373                 (struct cmd_set_vf_vlan_tag_result,
12374                  vf, "vf");
12375 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12376         TOKEN_STRING_INITIALIZER
12377                 (struct cmd_set_vf_vlan_tag_result,
12378                  vlan, "vlan");
12379 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12380         TOKEN_STRING_INITIALIZER
12381                 (struct cmd_set_vf_vlan_tag_result,
12382                  tag, "tag");
12383 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12384         TOKEN_NUM_INITIALIZER
12385                 (struct cmd_set_vf_vlan_tag_result,
12386                  port_id, RTE_UINT16);
12387 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12388         TOKEN_NUM_INITIALIZER
12389                 (struct cmd_set_vf_vlan_tag_result,
12390                  vf_id, RTE_UINT16);
12391 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12392         TOKEN_STRING_INITIALIZER
12393                 (struct cmd_set_vf_vlan_tag_result,
12394                  on_off, "on#off");
12395
12396 static void
12397 cmd_set_vf_vlan_tag_parsed(
12398         void *parsed_result,
12399         __rte_unused struct cmdline *cl,
12400         __rte_unused void *data)
12401 {
12402         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12403         int ret = -ENOTSUP;
12404
12405         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12406
12407         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12408                 return;
12409
12410 #ifdef RTE_NET_I40E
12411         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12412                                            res->vf_id, is_on);
12413 #endif
12414
12415         switch (ret) {
12416         case 0:
12417                 break;
12418         case -EINVAL:
12419                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12420                         res->vf_id, is_on);
12421                 break;
12422         case -ENODEV:
12423                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12424                 break;
12425         case -ENOTSUP:
12426                 fprintf(stderr, "function not implemented\n");
12427                 break;
12428         default:
12429                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12430         }
12431 }
12432
12433 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12434         .f = cmd_set_vf_vlan_tag_parsed,
12435         .data = NULL,
12436         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12437         .tokens = {
12438                 (void *)&cmd_set_vf_vlan_tag_set,
12439                 (void *)&cmd_set_vf_vlan_tag_vf,
12440                 (void *)&cmd_set_vf_vlan_tag_vlan,
12441                 (void *)&cmd_set_vf_vlan_tag_tag,
12442                 (void *)&cmd_set_vf_vlan_tag_port_id,
12443                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12444                 (void *)&cmd_set_vf_vlan_tag_on_off,
12445                 NULL,
12446         },
12447 };
12448
12449 /* Common definition of VF and TC TX bandwidth configuration */
12450 struct cmd_vf_tc_bw_result {
12451         cmdline_fixed_string_t set;
12452         cmdline_fixed_string_t vf;
12453         cmdline_fixed_string_t tc;
12454         cmdline_fixed_string_t tx;
12455         cmdline_fixed_string_t min_bw;
12456         cmdline_fixed_string_t max_bw;
12457         cmdline_fixed_string_t strict_link_prio;
12458         portid_t port_id;
12459         uint16_t vf_id;
12460         uint8_t tc_no;
12461         uint32_t bw;
12462         cmdline_fixed_string_t bw_list;
12463         uint8_t tc_map;
12464 };
12465
12466 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12467         TOKEN_STRING_INITIALIZER
12468                 (struct cmd_vf_tc_bw_result,
12469                  set, "set");
12470 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12471         TOKEN_STRING_INITIALIZER
12472                 (struct cmd_vf_tc_bw_result,
12473                  vf, "vf");
12474 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12475         TOKEN_STRING_INITIALIZER
12476                 (struct cmd_vf_tc_bw_result,
12477                  tc, "tc");
12478 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_vf_tc_bw_result,
12481                  tx, "tx");
12482 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_vf_tc_bw_result,
12485                  strict_link_prio, "strict-link-priority");
12486 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_vf_tc_bw_result,
12489                  min_bw, "min-bandwidth");
12490 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_vf_tc_bw_result,
12493                  max_bw, "max-bandwidth");
12494 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12495         TOKEN_NUM_INITIALIZER
12496                 (struct cmd_vf_tc_bw_result,
12497                  port_id, RTE_UINT16);
12498 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12499         TOKEN_NUM_INITIALIZER
12500                 (struct cmd_vf_tc_bw_result,
12501                  vf_id, RTE_UINT16);
12502 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12503         TOKEN_NUM_INITIALIZER
12504                 (struct cmd_vf_tc_bw_result,
12505                  tc_no, RTE_UINT8);
12506 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12507         TOKEN_NUM_INITIALIZER
12508                 (struct cmd_vf_tc_bw_result,
12509                  bw, RTE_UINT32);
12510 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12511         TOKEN_STRING_INITIALIZER
12512                 (struct cmd_vf_tc_bw_result,
12513                  bw_list, NULL);
12514 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12515         TOKEN_NUM_INITIALIZER
12516                 (struct cmd_vf_tc_bw_result,
12517                  tc_map, RTE_UINT8);
12518
12519 /* VF max bandwidth setting */
12520 static void
12521 cmd_vf_max_bw_parsed(
12522         void *parsed_result,
12523         __rte_unused struct cmdline *cl,
12524         __rte_unused void *data)
12525 {
12526         struct cmd_vf_tc_bw_result *res = parsed_result;
12527         int ret = -ENOTSUP;
12528
12529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12530                 return;
12531
12532 #ifdef RTE_NET_I40E
12533         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12534                                          res->vf_id, res->bw);
12535 #endif
12536
12537         switch (ret) {
12538         case 0:
12539                 break;
12540         case -EINVAL:
12541                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12542                         res->vf_id, res->bw);
12543                 break;
12544         case -ENODEV:
12545                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12546                 break;
12547         case -ENOTSUP:
12548                 fprintf(stderr, "function not implemented\n");
12549                 break;
12550         default:
12551                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12552         }
12553 }
12554
12555 cmdline_parse_inst_t cmd_vf_max_bw = {
12556         .f = cmd_vf_max_bw_parsed,
12557         .data = NULL,
12558         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12559         .tokens = {
12560                 (void *)&cmd_vf_tc_bw_set,
12561                 (void *)&cmd_vf_tc_bw_vf,
12562                 (void *)&cmd_vf_tc_bw_tx,
12563                 (void *)&cmd_vf_tc_bw_max_bw,
12564                 (void *)&cmd_vf_tc_bw_port_id,
12565                 (void *)&cmd_vf_tc_bw_vf_id,
12566                 (void *)&cmd_vf_tc_bw_bw,
12567                 NULL,
12568         },
12569 };
12570
12571 static int
12572 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12573                            uint8_t *tc_num,
12574                            char *str)
12575 {
12576         uint32_t size;
12577         const char *p, *p0 = str;
12578         char s[256];
12579         char *end;
12580         char *str_fld[16];
12581         uint16_t i;
12582         int ret;
12583
12584         p = strchr(p0, '(');
12585         if (p == NULL) {
12586                 fprintf(stderr,
12587                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12588                 return -1;
12589         }
12590         p++;
12591         p0 = strchr(p, ')');
12592         if (p0 == NULL) {
12593                 fprintf(stderr,
12594                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12595                 return -1;
12596         }
12597         size = p0 - p;
12598         if (size >= sizeof(s)) {
12599                 fprintf(stderr,
12600                         "The string size exceeds the internal buffer size\n");
12601                 return -1;
12602         }
12603         snprintf(s, sizeof(s), "%.*s", size, p);
12604         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12605         if (ret <= 0) {
12606                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12607                 return -1;
12608         }
12609         *tc_num = ret;
12610         for (i = 0; i < ret; i++)
12611                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12612
12613         return 0;
12614 }
12615
12616 /* TC min bandwidth setting */
12617 static void
12618 cmd_vf_tc_min_bw_parsed(
12619         void *parsed_result,
12620         __rte_unused struct cmdline *cl,
12621         __rte_unused void *data)
12622 {
12623         struct cmd_vf_tc_bw_result *res = parsed_result;
12624         uint8_t tc_num;
12625         uint8_t bw[16];
12626         int ret = -ENOTSUP;
12627
12628         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12629                 return;
12630
12631         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12632         if (ret)
12633                 return;
12634
12635 #ifdef RTE_NET_I40E
12636         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12637                                               tc_num, bw);
12638 #endif
12639
12640         switch (ret) {
12641         case 0:
12642                 break;
12643         case -EINVAL:
12644                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12645                 break;
12646         case -ENODEV:
12647                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12648                 break;
12649         case -ENOTSUP:
12650                 fprintf(stderr, "function not implemented\n");
12651                 break;
12652         default:
12653                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12654         }
12655 }
12656
12657 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12658         .f = cmd_vf_tc_min_bw_parsed,
12659         .data = NULL,
12660         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12661                     " <bw1, bw2, ...>",
12662         .tokens = {
12663                 (void *)&cmd_vf_tc_bw_set,
12664                 (void *)&cmd_vf_tc_bw_vf,
12665                 (void *)&cmd_vf_tc_bw_tc,
12666                 (void *)&cmd_vf_tc_bw_tx,
12667                 (void *)&cmd_vf_tc_bw_min_bw,
12668                 (void *)&cmd_vf_tc_bw_port_id,
12669                 (void *)&cmd_vf_tc_bw_vf_id,
12670                 (void *)&cmd_vf_tc_bw_bw_list,
12671                 NULL,
12672         },
12673 };
12674
12675 static void
12676 cmd_tc_min_bw_parsed(
12677         void *parsed_result,
12678         __rte_unused struct cmdline *cl,
12679         __rte_unused void *data)
12680 {
12681         struct cmd_vf_tc_bw_result *res = parsed_result;
12682         struct rte_port *port;
12683         uint8_t tc_num;
12684         uint8_t bw[16];
12685         int ret = -ENOTSUP;
12686
12687         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12688                 return;
12689
12690         port = &ports[res->port_id];
12691         /** Check if the port is not started **/
12692         if (port->port_status != RTE_PORT_STOPPED) {
12693                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
12694                 return;
12695         }
12696
12697         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12698         if (ret)
12699                 return;
12700
12701 #ifdef RTE_NET_IXGBE
12702         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12703 #endif
12704
12705         switch (ret) {
12706         case 0:
12707                 break;
12708         case -EINVAL:
12709                 fprintf(stderr, "invalid bandwidth\n");
12710                 break;
12711         case -ENODEV:
12712                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12713                 break;
12714         case -ENOTSUP:
12715                 fprintf(stderr, "function not implemented\n");
12716                 break;
12717         default:
12718                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12719         }
12720 }
12721
12722 cmdline_parse_inst_t cmd_tc_min_bw = {
12723         .f = cmd_tc_min_bw_parsed,
12724         .data = NULL,
12725         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12726         .tokens = {
12727                 (void *)&cmd_vf_tc_bw_set,
12728                 (void *)&cmd_vf_tc_bw_tc,
12729                 (void *)&cmd_vf_tc_bw_tx,
12730                 (void *)&cmd_vf_tc_bw_min_bw,
12731                 (void *)&cmd_vf_tc_bw_port_id,
12732                 (void *)&cmd_vf_tc_bw_bw_list,
12733                 NULL,
12734         },
12735 };
12736
12737 /* TC max bandwidth setting */
12738 static void
12739 cmd_vf_tc_max_bw_parsed(
12740         void *parsed_result,
12741         __rte_unused struct cmdline *cl,
12742         __rte_unused void *data)
12743 {
12744         struct cmd_vf_tc_bw_result *res = parsed_result;
12745         int ret = -ENOTSUP;
12746
12747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12748                 return;
12749
12750 #ifdef RTE_NET_I40E
12751         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12752                                             res->tc_no, res->bw);
12753 #endif
12754
12755         switch (ret) {
12756         case 0:
12757                 break;
12758         case -EINVAL:
12759                 fprintf(stderr,
12760                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
12761                         res->vf_id, res->tc_no, res->bw);
12762                 break;
12763         case -ENODEV:
12764                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12765                 break;
12766         case -ENOTSUP:
12767                 fprintf(stderr, "function not implemented\n");
12768                 break;
12769         default:
12770                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12771         }
12772 }
12773
12774 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12775         .f = cmd_vf_tc_max_bw_parsed,
12776         .data = NULL,
12777         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12778                     " <bandwidth>",
12779         .tokens = {
12780                 (void *)&cmd_vf_tc_bw_set,
12781                 (void *)&cmd_vf_tc_bw_vf,
12782                 (void *)&cmd_vf_tc_bw_tc,
12783                 (void *)&cmd_vf_tc_bw_tx,
12784                 (void *)&cmd_vf_tc_bw_max_bw,
12785                 (void *)&cmd_vf_tc_bw_port_id,
12786                 (void *)&cmd_vf_tc_bw_vf_id,
12787                 (void *)&cmd_vf_tc_bw_tc_no,
12788                 (void *)&cmd_vf_tc_bw_bw,
12789                 NULL,
12790         },
12791 };
12792
12793 /** Set VXLAN encapsulation details */
12794 struct cmd_set_vxlan_result {
12795         cmdline_fixed_string_t set;
12796         cmdline_fixed_string_t vxlan;
12797         cmdline_fixed_string_t pos_token;
12798         cmdline_fixed_string_t ip_version;
12799         uint32_t vlan_present:1;
12800         uint32_t vni;
12801         uint16_t udp_src;
12802         uint16_t udp_dst;
12803         cmdline_ipaddr_t ip_src;
12804         cmdline_ipaddr_t ip_dst;
12805         uint16_t tci;
12806         uint8_t tos;
12807         uint8_t ttl;
12808         struct rte_ether_addr eth_src;
12809         struct rte_ether_addr eth_dst;
12810 };
12811
12812 cmdline_parse_token_string_t cmd_set_vxlan_set =
12813         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12814 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12815         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12816 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12817         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12818                                  "vxlan-tos-ttl");
12819 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12820         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12821                                  "vxlan-with-vlan");
12822 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12823         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12824                                  "ip-version");
12825 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12826         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12827                                  "ipv4#ipv6");
12828 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12829         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12830                                  "vni");
12831 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12832         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12833 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12834         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12835                                  "udp-src");
12836 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12837         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12838 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12839         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12840                                  "udp-dst");
12841 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12842         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12843 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12844         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12845                                  "ip-tos");
12846 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12847         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12848 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12849         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12850                                  "ip-ttl");
12851 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12852         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12853 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12854         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12855                                  "ip-src");
12856 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12857         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12858 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12859         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12860                                  "ip-dst");
12861 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12862         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12863 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12864         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12865                                  "vlan-tci");
12866 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12867         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12868 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12869         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12870                                  "eth-src");
12871 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12872         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12873 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12874         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12875                                  "eth-dst");
12876 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12877         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12878
12879 static void cmd_set_vxlan_parsed(void *parsed_result,
12880         __rte_unused struct cmdline *cl,
12881         __rte_unused void *data)
12882 {
12883         struct cmd_set_vxlan_result *res = parsed_result;
12884         union {
12885                 uint32_t vxlan_id;
12886                 uint8_t vni[4];
12887         } id = {
12888                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12889         };
12890
12891         vxlan_encap_conf.select_tos_ttl = 0;
12892         if (strcmp(res->vxlan, "vxlan") == 0)
12893                 vxlan_encap_conf.select_vlan = 0;
12894         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12895                 vxlan_encap_conf.select_vlan = 1;
12896         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12897                 vxlan_encap_conf.select_vlan = 0;
12898                 vxlan_encap_conf.select_tos_ttl = 1;
12899         }
12900         if (strcmp(res->ip_version, "ipv4") == 0)
12901                 vxlan_encap_conf.select_ipv4 = 1;
12902         else if (strcmp(res->ip_version, "ipv6") == 0)
12903                 vxlan_encap_conf.select_ipv4 = 0;
12904         else
12905                 return;
12906         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12907         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12908         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12909         vxlan_encap_conf.ip_tos = res->tos;
12910         vxlan_encap_conf.ip_ttl = res->ttl;
12911         if (vxlan_encap_conf.select_ipv4) {
12912                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12913                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12914         } else {
12915                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12916                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12917         }
12918         if (vxlan_encap_conf.select_vlan)
12919                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12920         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12921                    RTE_ETHER_ADDR_LEN);
12922         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12923                    RTE_ETHER_ADDR_LEN);
12924 }
12925
12926 cmdline_parse_inst_t cmd_set_vxlan = {
12927         .f = cmd_set_vxlan_parsed,
12928         .data = NULL,
12929         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12930                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12931                 " eth-src <eth-src> eth-dst <eth-dst>",
12932         .tokens = {
12933                 (void *)&cmd_set_vxlan_set,
12934                 (void *)&cmd_set_vxlan_vxlan,
12935                 (void *)&cmd_set_vxlan_ip_version,
12936                 (void *)&cmd_set_vxlan_ip_version_value,
12937                 (void *)&cmd_set_vxlan_vni,
12938                 (void *)&cmd_set_vxlan_vni_value,
12939                 (void *)&cmd_set_vxlan_udp_src,
12940                 (void *)&cmd_set_vxlan_udp_src_value,
12941                 (void *)&cmd_set_vxlan_udp_dst,
12942                 (void *)&cmd_set_vxlan_udp_dst_value,
12943                 (void *)&cmd_set_vxlan_ip_src,
12944                 (void *)&cmd_set_vxlan_ip_src_value,
12945                 (void *)&cmd_set_vxlan_ip_dst,
12946                 (void *)&cmd_set_vxlan_ip_dst_value,
12947                 (void *)&cmd_set_vxlan_eth_src,
12948                 (void *)&cmd_set_vxlan_eth_src_value,
12949                 (void *)&cmd_set_vxlan_eth_dst,
12950                 (void *)&cmd_set_vxlan_eth_dst_value,
12951                 NULL,
12952         },
12953 };
12954
12955 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12956         .f = cmd_set_vxlan_parsed,
12957         .data = NULL,
12958         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12959                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12960                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12961                 " eth-dst <eth-dst>",
12962         .tokens = {
12963                 (void *)&cmd_set_vxlan_set,
12964                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12965                 (void *)&cmd_set_vxlan_ip_version,
12966                 (void *)&cmd_set_vxlan_ip_version_value,
12967                 (void *)&cmd_set_vxlan_vni,
12968                 (void *)&cmd_set_vxlan_vni_value,
12969                 (void *)&cmd_set_vxlan_udp_src,
12970                 (void *)&cmd_set_vxlan_udp_src_value,
12971                 (void *)&cmd_set_vxlan_udp_dst,
12972                 (void *)&cmd_set_vxlan_udp_dst_value,
12973                 (void *)&cmd_set_vxlan_ip_tos,
12974                 (void *)&cmd_set_vxlan_ip_tos_value,
12975                 (void *)&cmd_set_vxlan_ip_ttl,
12976                 (void *)&cmd_set_vxlan_ip_ttl_value,
12977                 (void *)&cmd_set_vxlan_ip_src,
12978                 (void *)&cmd_set_vxlan_ip_src_value,
12979                 (void *)&cmd_set_vxlan_ip_dst,
12980                 (void *)&cmd_set_vxlan_ip_dst_value,
12981                 (void *)&cmd_set_vxlan_eth_src,
12982                 (void *)&cmd_set_vxlan_eth_src_value,
12983                 (void *)&cmd_set_vxlan_eth_dst,
12984                 (void *)&cmd_set_vxlan_eth_dst_value,
12985                 NULL,
12986         },
12987 };
12988
12989 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12990         .f = cmd_set_vxlan_parsed,
12991         .data = NULL,
12992         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12993                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12994                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12995                 " <eth-dst>",
12996         .tokens = {
12997                 (void *)&cmd_set_vxlan_set,
12998                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
12999                 (void *)&cmd_set_vxlan_ip_version,
13000                 (void *)&cmd_set_vxlan_ip_version_value,
13001                 (void *)&cmd_set_vxlan_vni,
13002                 (void *)&cmd_set_vxlan_vni_value,
13003                 (void *)&cmd_set_vxlan_udp_src,
13004                 (void *)&cmd_set_vxlan_udp_src_value,
13005                 (void *)&cmd_set_vxlan_udp_dst,
13006                 (void *)&cmd_set_vxlan_udp_dst_value,
13007                 (void *)&cmd_set_vxlan_ip_src,
13008                 (void *)&cmd_set_vxlan_ip_src_value,
13009                 (void *)&cmd_set_vxlan_ip_dst,
13010                 (void *)&cmd_set_vxlan_ip_dst_value,
13011                 (void *)&cmd_set_vxlan_vlan,
13012                 (void *)&cmd_set_vxlan_vlan_value,
13013                 (void *)&cmd_set_vxlan_eth_src,
13014                 (void *)&cmd_set_vxlan_eth_src_value,
13015                 (void *)&cmd_set_vxlan_eth_dst,
13016                 (void *)&cmd_set_vxlan_eth_dst_value,
13017                 NULL,
13018         },
13019 };
13020
13021 /** Set NVGRE encapsulation details */
13022 struct cmd_set_nvgre_result {
13023         cmdline_fixed_string_t set;
13024         cmdline_fixed_string_t nvgre;
13025         cmdline_fixed_string_t pos_token;
13026         cmdline_fixed_string_t ip_version;
13027         uint32_t tni;
13028         cmdline_ipaddr_t ip_src;
13029         cmdline_ipaddr_t ip_dst;
13030         uint16_t tci;
13031         struct rte_ether_addr eth_src;
13032         struct rte_ether_addr eth_dst;
13033 };
13034
13035 cmdline_parse_token_string_t cmd_set_nvgre_set =
13036         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13037 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13038         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13039 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13040         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13041                                  "nvgre-with-vlan");
13042 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13043         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13044                                  "ip-version");
13045 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13046         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13047                                  "ipv4#ipv6");
13048 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13049         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13050                                  "tni");
13051 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13052         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13053 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13054         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13055                                  "ip-src");
13056 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13057         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13058 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13059         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13060                                  "ip-dst");
13061 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13062         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13063 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13064         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13065                                  "vlan-tci");
13066 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13067         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13068 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13069         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13070                                  "eth-src");
13071 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13072         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13073 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13074         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13075                                  "eth-dst");
13076 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13077         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13078
13079 static void cmd_set_nvgre_parsed(void *parsed_result,
13080         __rte_unused struct cmdline *cl,
13081         __rte_unused void *data)
13082 {
13083         struct cmd_set_nvgre_result *res = parsed_result;
13084         union {
13085                 uint32_t nvgre_tni;
13086                 uint8_t tni[4];
13087         } id = {
13088                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13089         };
13090
13091         if (strcmp(res->nvgre, "nvgre") == 0)
13092                 nvgre_encap_conf.select_vlan = 0;
13093         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13094                 nvgre_encap_conf.select_vlan = 1;
13095         if (strcmp(res->ip_version, "ipv4") == 0)
13096                 nvgre_encap_conf.select_ipv4 = 1;
13097         else if (strcmp(res->ip_version, "ipv6") == 0)
13098                 nvgre_encap_conf.select_ipv4 = 0;
13099         else
13100                 return;
13101         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13102         if (nvgre_encap_conf.select_ipv4) {
13103                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13104                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13105         } else {
13106                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13107                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13108         }
13109         if (nvgre_encap_conf.select_vlan)
13110                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13111         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13112                    RTE_ETHER_ADDR_LEN);
13113         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13114                    RTE_ETHER_ADDR_LEN);
13115 }
13116
13117 cmdline_parse_inst_t cmd_set_nvgre = {
13118         .f = cmd_set_nvgre_parsed,
13119         .data = NULL,
13120         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13121                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13122                 " eth-dst <eth-dst>",
13123         .tokens = {
13124                 (void *)&cmd_set_nvgre_set,
13125                 (void *)&cmd_set_nvgre_nvgre,
13126                 (void *)&cmd_set_nvgre_ip_version,
13127                 (void *)&cmd_set_nvgre_ip_version_value,
13128                 (void *)&cmd_set_nvgre_tni,
13129                 (void *)&cmd_set_nvgre_tni_value,
13130                 (void *)&cmd_set_nvgre_ip_src,
13131                 (void *)&cmd_set_nvgre_ip_src_value,
13132                 (void *)&cmd_set_nvgre_ip_dst,
13133                 (void *)&cmd_set_nvgre_ip_dst_value,
13134                 (void *)&cmd_set_nvgre_eth_src,
13135                 (void *)&cmd_set_nvgre_eth_src_value,
13136                 (void *)&cmd_set_nvgre_eth_dst,
13137                 (void *)&cmd_set_nvgre_eth_dst_value,
13138                 NULL,
13139         },
13140 };
13141
13142 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13143         .f = cmd_set_nvgre_parsed,
13144         .data = NULL,
13145         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13146                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13147                 " eth-src <eth-src> eth-dst <eth-dst>",
13148         .tokens = {
13149                 (void *)&cmd_set_nvgre_set,
13150                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13151                 (void *)&cmd_set_nvgre_ip_version,
13152                 (void *)&cmd_set_nvgre_ip_version_value,
13153                 (void *)&cmd_set_nvgre_tni,
13154                 (void *)&cmd_set_nvgre_tni_value,
13155                 (void *)&cmd_set_nvgre_ip_src,
13156                 (void *)&cmd_set_nvgre_ip_src_value,
13157                 (void *)&cmd_set_nvgre_ip_dst,
13158                 (void *)&cmd_set_nvgre_ip_dst_value,
13159                 (void *)&cmd_set_nvgre_vlan,
13160                 (void *)&cmd_set_nvgre_vlan_value,
13161                 (void *)&cmd_set_nvgre_eth_src,
13162                 (void *)&cmd_set_nvgre_eth_src_value,
13163                 (void *)&cmd_set_nvgre_eth_dst,
13164                 (void *)&cmd_set_nvgre_eth_dst_value,
13165                 NULL,
13166         },
13167 };
13168
13169 /** Set L2 encapsulation details */
13170 struct cmd_set_l2_encap_result {
13171         cmdline_fixed_string_t set;
13172         cmdline_fixed_string_t l2_encap;
13173         cmdline_fixed_string_t pos_token;
13174         cmdline_fixed_string_t ip_version;
13175         uint32_t vlan_present:1;
13176         uint16_t tci;
13177         struct rte_ether_addr eth_src;
13178         struct rte_ether_addr eth_dst;
13179 };
13180
13181 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13182         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13183 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13184         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13185 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13187                                  "l2_encap-with-vlan");
13188 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13189         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13190                                  "ip-version");
13191 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13192         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13193                                  "ipv4#ipv6");
13194 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13195         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13196                                  "vlan-tci");
13197 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13198         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13199 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13200         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13201                                  "eth-src");
13202 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13203         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13204 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13205         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13206                                  "eth-dst");
13207 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13209
13210 static void cmd_set_l2_encap_parsed(void *parsed_result,
13211         __rte_unused struct cmdline *cl,
13212         __rte_unused void *data)
13213 {
13214         struct cmd_set_l2_encap_result *res = parsed_result;
13215
13216         if (strcmp(res->l2_encap, "l2_encap") == 0)
13217                 l2_encap_conf.select_vlan = 0;
13218         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13219                 l2_encap_conf.select_vlan = 1;
13220         if (strcmp(res->ip_version, "ipv4") == 0)
13221                 l2_encap_conf.select_ipv4 = 1;
13222         else if (strcmp(res->ip_version, "ipv6") == 0)
13223                 l2_encap_conf.select_ipv4 = 0;
13224         else
13225                 return;
13226         if (l2_encap_conf.select_vlan)
13227                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13228         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13229                    RTE_ETHER_ADDR_LEN);
13230         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13231                    RTE_ETHER_ADDR_LEN);
13232 }
13233
13234 cmdline_parse_inst_t cmd_set_l2_encap = {
13235         .f = cmd_set_l2_encap_parsed,
13236         .data = NULL,
13237         .help_str = "set l2_encap ip-version ipv4|ipv6"
13238                 " eth-src <eth-src> eth-dst <eth-dst>",
13239         .tokens = {
13240                 (void *)&cmd_set_l2_encap_set,
13241                 (void *)&cmd_set_l2_encap_l2_encap,
13242                 (void *)&cmd_set_l2_encap_ip_version,
13243                 (void *)&cmd_set_l2_encap_ip_version_value,
13244                 (void *)&cmd_set_l2_encap_eth_src,
13245                 (void *)&cmd_set_l2_encap_eth_src_value,
13246                 (void *)&cmd_set_l2_encap_eth_dst,
13247                 (void *)&cmd_set_l2_encap_eth_dst_value,
13248                 NULL,
13249         },
13250 };
13251
13252 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13253         .f = cmd_set_l2_encap_parsed,
13254         .data = NULL,
13255         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13256                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13257         .tokens = {
13258                 (void *)&cmd_set_l2_encap_set,
13259                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13260                 (void *)&cmd_set_l2_encap_ip_version,
13261                 (void *)&cmd_set_l2_encap_ip_version_value,
13262                 (void *)&cmd_set_l2_encap_vlan,
13263                 (void *)&cmd_set_l2_encap_vlan_value,
13264                 (void *)&cmd_set_l2_encap_eth_src,
13265                 (void *)&cmd_set_l2_encap_eth_src_value,
13266                 (void *)&cmd_set_l2_encap_eth_dst,
13267                 (void *)&cmd_set_l2_encap_eth_dst_value,
13268                 NULL,
13269         },
13270 };
13271
13272 /** Set L2 decapsulation details */
13273 struct cmd_set_l2_decap_result {
13274         cmdline_fixed_string_t set;
13275         cmdline_fixed_string_t l2_decap;
13276         cmdline_fixed_string_t pos_token;
13277         uint32_t vlan_present:1;
13278 };
13279
13280 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13281         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13282 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13283         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13284                                  "l2_decap");
13285 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13286         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13287                                  "l2_decap-with-vlan");
13288
13289 static void cmd_set_l2_decap_parsed(void *parsed_result,
13290         __rte_unused struct cmdline *cl,
13291         __rte_unused void *data)
13292 {
13293         struct cmd_set_l2_decap_result *res = parsed_result;
13294
13295         if (strcmp(res->l2_decap, "l2_decap") == 0)
13296                 l2_decap_conf.select_vlan = 0;
13297         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13298                 l2_decap_conf.select_vlan = 1;
13299 }
13300
13301 cmdline_parse_inst_t cmd_set_l2_decap = {
13302         .f = cmd_set_l2_decap_parsed,
13303         .data = NULL,
13304         .help_str = "set l2_decap",
13305         .tokens = {
13306                 (void *)&cmd_set_l2_decap_set,
13307                 (void *)&cmd_set_l2_decap_l2_decap,
13308                 NULL,
13309         },
13310 };
13311
13312 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13313         .f = cmd_set_l2_decap_parsed,
13314         .data = NULL,
13315         .help_str = "set l2_decap-with-vlan",
13316         .tokens = {
13317                 (void *)&cmd_set_l2_decap_set,
13318                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13319                 NULL,
13320         },
13321 };
13322
13323 /** Set MPLSoGRE encapsulation details */
13324 struct cmd_set_mplsogre_encap_result {
13325         cmdline_fixed_string_t set;
13326         cmdline_fixed_string_t mplsogre;
13327         cmdline_fixed_string_t pos_token;
13328         cmdline_fixed_string_t ip_version;
13329         uint32_t vlan_present:1;
13330         uint32_t label;
13331         cmdline_ipaddr_t ip_src;
13332         cmdline_ipaddr_t ip_dst;
13333         uint16_t tci;
13334         struct rte_ether_addr eth_src;
13335         struct rte_ether_addr eth_dst;
13336 };
13337
13338 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13339         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13340                                  "set");
13341 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13342         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13343                                  "mplsogre_encap");
13344 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13345         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13346                                  mplsogre, "mplsogre_encap-with-vlan");
13347 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13348         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13349                                  pos_token, "ip-version");
13350 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13351         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13352                                  ip_version, "ipv4#ipv6");
13353 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13354         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13355                                  pos_token, "label");
13356 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13357         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13358                               RTE_UINT32);
13359 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13360         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13361                                  pos_token, "ip-src");
13362 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13363         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13364 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13365         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13366                                  pos_token, "ip-dst");
13367 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13368         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13369 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13370         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13371                                  pos_token, "vlan-tci");
13372 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13373         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13374                               RTE_UINT16);
13375 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13376         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13377                                  pos_token, "eth-src");
13378 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13379         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13380                                     eth_src);
13381 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13382         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13383                                  pos_token, "eth-dst");
13384 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13385         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13386                                     eth_dst);
13387
13388 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13389         __rte_unused struct cmdline *cl,
13390         __rte_unused void *data)
13391 {
13392         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13393         union {
13394                 uint32_t mplsogre_label;
13395                 uint8_t label[4];
13396         } id = {
13397                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13398         };
13399
13400         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13401                 mplsogre_encap_conf.select_vlan = 0;
13402         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13403                 mplsogre_encap_conf.select_vlan = 1;
13404         if (strcmp(res->ip_version, "ipv4") == 0)
13405                 mplsogre_encap_conf.select_ipv4 = 1;
13406         else if (strcmp(res->ip_version, "ipv6") == 0)
13407                 mplsogre_encap_conf.select_ipv4 = 0;
13408         else
13409                 return;
13410         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13411         if (mplsogre_encap_conf.select_ipv4) {
13412                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13413                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13414         } else {
13415                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13416                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13417         }
13418         if (mplsogre_encap_conf.select_vlan)
13419                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13420         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13421                    RTE_ETHER_ADDR_LEN);
13422         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13423                    RTE_ETHER_ADDR_LEN);
13424 }
13425
13426 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13427         .f = cmd_set_mplsogre_encap_parsed,
13428         .data = NULL,
13429         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13430                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13431                 " eth-dst <eth-dst>",
13432         .tokens = {
13433                 (void *)&cmd_set_mplsogre_encap_set,
13434                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13435                 (void *)&cmd_set_mplsogre_encap_ip_version,
13436                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13437                 (void *)&cmd_set_mplsogre_encap_label,
13438                 (void *)&cmd_set_mplsogre_encap_label_value,
13439                 (void *)&cmd_set_mplsogre_encap_ip_src,
13440                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13441                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13442                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13443                 (void *)&cmd_set_mplsogre_encap_eth_src,
13444                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13445                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13446                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13447                 NULL,
13448         },
13449 };
13450
13451 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13452         .f = cmd_set_mplsogre_encap_parsed,
13453         .data = NULL,
13454         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13455                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13456                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13457         .tokens = {
13458                 (void *)&cmd_set_mplsogre_encap_set,
13459                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13460                 (void *)&cmd_set_mplsogre_encap_ip_version,
13461                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13462                 (void *)&cmd_set_mplsogre_encap_label,
13463                 (void *)&cmd_set_mplsogre_encap_label_value,
13464                 (void *)&cmd_set_mplsogre_encap_ip_src,
13465                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13466                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13467                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13468                 (void *)&cmd_set_mplsogre_encap_vlan,
13469                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13470                 (void *)&cmd_set_mplsogre_encap_eth_src,
13471                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13472                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13473                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13474                 NULL,
13475         },
13476 };
13477
13478 /** Set MPLSoGRE decapsulation details */
13479 struct cmd_set_mplsogre_decap_result {
13480         cmdline_fixed_string_t set;
13481         cmdline_fixed_string_t mplsogre;
13482         cmdline_fixed_string_t pos_token;
13483         cmdline_fixed_string_t ip_version;
13484         uint32_t vlan_present:1;
13485 };
13486
13487 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13488         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13489                                  "set");
13490 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13491         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13492                                  "mplsogre_decap");
13493 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13494         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13495                                  mplsogre, "mplsogre_decap-with-vlan");
13496 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13497         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13498                                  pos_token, "ip-version");
13499 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13500         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13501                                  ip_version, "ipv4#ipv6");
13502
13503 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13504         __rte_unused struct cmdline *cl,
13505         __rte_unused void *data)
13506 {
13507         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13508
13509         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13510                 mplsogre_decap_conf.select_vlan = 0;
13511         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13512                 mplsogre_decap_conf.select_vlan = 1;
13513         if (strcmp(res->ip_version, "ipv4") == 0)
13514                 mplsogre_decap_conf.select_ipv4 = 1;
13515         else if (strcmp(res->ip_version, "ipv6") == 0)
13516                 mplsogre_decap_conf.select_ipv4 = 0;
13517 }
13518
13519 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13520         .f = cmd_set_mplsogre_decap_parsed,
13521         .data = NULL,
13522         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13523         .tokens = {
13524                 (void *)&cmd_set_mplsogre_decap_set,
13525                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13526                 (void *)&cmd_set_mplsogre_decap_ip_version,
13527                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13528                 NULL,
13529         },
13530 };
13531
13532 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13533         .f = cmd_set_mplsogre_decap_parsed,
13534         .data = NULL,
13535         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13536         .tokens = {
13537                 (void *)&cmd_set_mplsogre_decap_set,
13538                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13539                 (void *)&cmd_set_mplsogre_decap_ip_version,
13540                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13541                 NULL,
13542         },
13543 };
13544
13545 /** Set MPLSoUDP encapsulation details */
13546 struct cmd_set_mplsoudp_encap_result {
13547         cmdline_fixed_string_t set;
13548         cmdline_fixed_string_t mplsoudp;
13549         cmdline_fixed_string_t pos_token;
13550         cmdline_fixed_string_t ip_version;
13551         uint32_t vlan_present:1;
13552         uint32_t label;
13553         uint16_t udp_src;
13554         uint16_t udp_dst;
13555         cmdline_ipaddr_t ip_src;
13556         cmdline_ipaddr_t ip_dst;
13557         uint16_t tci;
13558         struct rte_ether_addr eth_src;
13559         struct rte_ether_addr eth_dst;
13560 };
13561
13562 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13563         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13564                                  "set");
13565 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13566         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13567                                  "mplsoudp_encap");
13568 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13569         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13570                                  mplsoudp, "mplsoudp_encap-with-vlan");
13571 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13572         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13573                                  pos_token, "ip-version");
13574 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13575         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13576                                  ip_version, "ipv4#ipv6");
13577 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13578         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13579                                  pos_token, "label");
13580 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13581         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13582                               RTE_UINT32);
13583 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13584         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13585                                  pos_token, "udp-src");
13586 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13587         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13588                               RTE_UINT16);
13589 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13590         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13591                                  pos_token, "udp-dst");
13592 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13593         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13594                               RTE_UINT16);
13595 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13596         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13597                                  pos_token, "ip-src");
13598 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13599         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13600 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13601         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13602                                  pos_token, "ip-dst");
13603 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13604         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13605 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13606         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13607                                  pos_token, "vlan-tci");
13608 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13609         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13610                               RTE_UINT16);
13611 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13612         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13613                                  pos_token, "eth-src");
13614 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13615         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13616                                     eth_src);
13617 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13618         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13619                                  pos_token, "eth-dst");
13620 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13621         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13622                                     eth_dst);
13623
13624 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13625         __rte_unused struct cmdline *cl,
13626         __rte_unused void *data)
13627 {
13628         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13629         union {
13630                 uint32_t mplsoudp_label;
13631                 uint8_t label[4];
13632         } id = {
13633                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13634         };
13635
13636         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13637                 mplsoudp_encap_conf.select_vlan = 0;
13638         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13639                 mplsoudp_encap_conf.select_vlan = 1;
13640         if (strcmp(res->ip_version, "ipv4") == 0)
13641                 mplsoudp_encap_conf.select_ipv4 = 1;
13642         else if (strcmp(res->ip_version, "ipv6") == 0)
13643                 mplsoudp_encap_conf.select_ipv4 = 0;
13644         else
13645                 return;
13646         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13647         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13648         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13649         if (mplsoudp_encap_conf.select_ipv4) {
13650                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13651                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13652         } else {
13653                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13654                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13655         }
13656         if (mplsoudp_encap_conf.select_vlan)
13657                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13658         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13659                    RTE_ETHER_ADDR_LEN);
13660         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13661                    RTE_ETHER_ADDR_LEN);
13662 }
13663
13664 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13665         .f = cmd_set_mplsoudp_encap_parsed,
13666         .data = NULL,
13667         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13668                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13669                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13670         .tokens = {
13671                 (void *)&cmd_set_mplsoudp_encap_set,
13672                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13673                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13674                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13675                 (void *)&cmd_set_mplsoudp_encap_label,
13676                 (void *)&cmd_set_mplsoudp_encap_label_value,
13677                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13678                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13679                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13680                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13681                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13682                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13683                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13684                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13685                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13686                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13687                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13688                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13689                 NULL,
13690         },
13691 };
13692
13693 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13694         .f = cmd_set_mplsoudp_encap_parsed,
13695         .data = NULL,
13696         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13697                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13698                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13699                 " eth-src <eth-src> eth-dst <eth-dst>",
13700         .tokens = {
13701                 (void *)&cmd_set_mplsoudp_encap_set,
13702                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13703                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13704                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13705                 (void *)&cmd_set_mplsoudp_encap_label,
13706                 (void *)&cmd_set_mplsoudp_encap_label_value,
13707                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13708                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13709                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13710                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13711                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13712                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13713                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13714                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13715                 (void *)&cmd_set_mplsoudp_encap_vlan,
13716                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13717                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13718                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13719                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13720                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13721                 NULL,
13722         },
13723 };
13724
13725 /** Set MPLSoUDP decapsulation details */
13726 struct cmd_set_mplsoudp_decap_result {
13727         cmdline_fixed_string_t set;
13728         cmdline_fixed_string_t mplsoudp;
13729         cmdline_fixed_string_t pos_token;
13730         cmdline_fixed_string_t ip_version;
13731         uint32_t vlan_present:1;
13732 };
13733
13734 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13735         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13736                                  "set");
13737 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13738         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13739                                  "mplsoudp_decap");
13740 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13741         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13742                                  mplsoudp, "mplsoudp_decap-with-vlan");
13743 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13744         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13745                                  pos_token, "ip-version");
13746 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13747         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13748                                  ip_version, "ipv4#ipv6");
13749
13750 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13751         __rte_unused struct cmdline *cl,
13752         __rte_unused void *data)
13753 {
13754         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13755
13756         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13757                 mplsoudp_decap_conf.select_vlan = 0;
13758         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13759                 mplsoudp_decap_conf.select_vlan = 1;
13760         if (strcmp(res->ip_version, "ipv4") == 0)
13761                 mplsoudp_decap_conf.select_ipv4 = 1;
13762         else if (strcmp(res->ip_version, "ipv6") == 0)
13763                 mplsoudp_decap_conf.select_ipv4 = 0;
13764 }
13765
13766 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13767         .f = cmd_set_mplsoudp_decap_parsed,
13768         .data = NULL,
13769         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13770         .tokens = {
13771                 (void *)&cmd_set_mplsoudp_decap_set,
13772                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13773                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13774                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13775                 NULL,
13776         },
13777 };
13778
13779 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13780         .f = cmd_set_mplsoudp_decap_parsed,
13781         .data = NULL,
13782         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13783         .tokens = {
13784                 (void *)&cmd_set_mplsoudp_decap_set,
13785                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13786                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13787                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13788                 NULL,
13789         },
13790 };
13791
13792 /** Set connection tracking object common details */
13793 struct cmd_set_conntrack_common_result {
13794         cmdline_fixed_string_t set;
13795         cmdline_fixed_string_t conntrack;
13796         cmdline_fixed_string_t common;
13797         cmdline_fixed_string_t peer;
13798         cmdline_fixed_string_t is_orig;
13799         cmdline_fixed_string_t enable;
13800         cmdline_fixed_string_t live;
13801         cmdline_fixed_string_t sack;
13802         cmdline_fixed_string_t cack;
13803         cmdline_fixed_string_t last_dir;
13804         cmdline_fixed_string_t liberal;
13805         cmdline_fixed_string_t state;
13806         cmdline_fixed_string_t max_ack_win;
13807         cmdline_fixed_string_t retrans;
13808         cmdline_fixed_string_t last_win;
13809         cmdline_fixed_string_t last_seq;
13810         cmdline_fixed_string_t last_ack;
13811         cmdline_fixed_string_t last_end;
13812         cmdline_fixed_string_t last_index;
13813         uint8_t stat;
13814         uint8_t factor;
13815         uint16_t peer_port;
13816         uint32_t is_original;
13817         uint32_t en;
13818         uint32_t is_live;
13819         uint32_t s_ack;
13820         uint32_t c_ack;
13821         uint32_t ld;
13822         uint32_t lb;
13823         uint8_t re_num;
13824         uint8_t li;
13825         uint16_t lw;
13826         uint32_t ls;
13827         uint32_t la;
13828         uint32_t le;
13829 };
13830
13831 cmdline_parse_token_string_t cmd_set_conntrack_set =
13832         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13833                                  set, "set");
13834 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13835         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13836                                  conntrack, "conntrack");
13837 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13838         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13839                                  common, "com");
13840 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13841         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13842                                  peer, "peer");
13843 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13844         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13845                               peer_port, RTE_UINT16);
13846 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13847         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13848                                  is_orig, "is_orig");
13849 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13850         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13851                               is_original, RTE_UINT32);
13852 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13853         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13854                                  enable, "enable");
13855 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13856         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13857                               en, RTE_UINT32);
13858 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
13859         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13860                                  live, "live");
13861 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
13862         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13863                               is_live, RTE_UINT32);
13864 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
13865         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13866                                  sack, "sack");
13867 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
13868         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13869                               s_ack, RTE_UINT32);
13870 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
13871         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13872                                  cack, "cack");
13873 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
13874         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13875                               c_ack, RTE_UINT32);
13876 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
13877         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13878                                  last_dir, "last_dir");
13879 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
13880         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13881                               ld, RTE_UINT32);
13882 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
13883         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13884                                  liberal, "liberal");
13885 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
13886         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13887                               lb, RTE_UINT32);
13888 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
13889         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13890                                  state, "state");
13891 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
13892         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13893                               stat, RTE_UINT8);
13894 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
13895         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13896                                  max_ack_win, "max_ack_win");
13897 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
13898         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13899                               factor, RTE_UINT8);
13900 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
13901         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13902                                  retrans, "r_lim");
13903 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
13904         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13905                               re_num, RTE_UINT8);
13906 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
13907         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13908                                  last_win, "last_win");
13909 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
13910         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13911                               lw, RTE_UINT16);
13912 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
13913         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13914                                  last_seq, "last_seq");
13915 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
13916         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13917                               ls, RTE_UINT32);
13918 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
13919         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13920                                  last_ack, "last_ack");
13921 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
13922         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13923                               la, RTE_UINT32);
13924 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
13925         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13926                                  last_end, "last_end");
13927 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
13928         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13929                               le, RTE_UINT32);
13930 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
13931         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13932                                  last_index, "last_index");
13933 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
13934         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13935                               li, RTE_UINT8);
13936
13937 static void cmd_set_conntrack_common_parsed(void *parsed_result,
13938         __rte_unused struct cmdline *cl,
13939         __rte_unused void *data)
13940 {
13941         struct cmd_set_conntrack_common_result *res = parsed_result;
13942
13943         /* No need to swap to big endian. */
13944         conntrack_context.peer_port = res->peer_port;
13945         conntrack_context.is_original_dir = res->is_original;
13946         conntrack_context.enable = res->en;
13947         conntrack_context.live_connection = res->is_live;
13948         conntrack_context.selective_ack = res->s_ack;
13949         conntrack_context.challenge_ack_passed = res->c_ack;
13950         conntrack_context.last_direction = res->ld;
13951         conntrack_context.liberal_mode = res->lb;
13952         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
13953         conntrack_context.max_ack_window = res->factor;
13954         conntrack_context.retransmission_limit = res->re_num;
13955         conntrack_context.last_window = res->lw;
13956         conntrack_context.last_index =
13957                 (enum rte_flow_conntrack_tcp_last_index)res->li;
13958         conntrack_context.last_seq = res->ls;
13959         conntrack_context.last_ack = res->la;
13960         conntrack_context.last_end = res->le;
13961 }
13962
13963 cmdline_parse_inst_t cmd_set_conntrack_common = {
13964         .f = cmd_set_conntrack_common_parsed,
13965         .data = NULL,
13966         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
13967                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
13968                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
13969                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
13970                 " last_index <flag>",
13971         .tokens = {
13972                 (void *)&cmd_set_conntrack_set,
13973                 (void *)&cmd_set_conntrack_conntrack,
13974                 (void *)&cmd_set_conntrack_common_com,
13975                 (void *)&cmd_set_conntrack_common_peer,
13976                 (void *)&cmd_set_conntrack_common_peer_value,
13977                 (void *)&cmd_set_conntrack_common_is_orig,
13978                 (void *)&cmd_set_conntrack_common_is_orig_value,
13979                 (void *)&cmd_set_conntrack_common_enable,
13980                 (void *)&cmd_set_conntrack_common_enable_value,
13981                 (void *)&cmd_set_conntrack_common_live,
13982                 (void *)&cmd_set_conntrack_common_live_value,
13983                 (void *)&cmd_set_conntrack_common_sack,
13984                 (void *)&cmd_set_conntrack_common_sack_value,
13985                 (void *)&cmd_set_conntrack_common_cack,
13986                 (void *)&cmd_set_conntrack_common_cack_value,
13987                 (void *)&cmd_set_conntrack_common_last_dir,
13988                 (void *)&cmd_set_conntrack_common_last_dir_value,
13989                 (void *)&cmd_set_conntrack_common_liberal,
13990                 (void *)&cmd_set_conntrack_common_liberal_value,
13991                 (void *)&cmd_set_conntrack_common_state,
13992                 (void *)&cmd_set_conntrack_common_state_value,
13993                 (void *)&cmd_set_conntrack_common_max_ackwin,
13994                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
13995                 (void *)&cmd_set_conntrack_common_retrans,
13996                 (void *)&cmd_set_conntrack_common_retrans_value,
13997                 (void *)&cmd_set_conntrack_common_last_win,
13998                 (void *)&cmd_set_conntrack_common_last_win_value,
13999                 (void *)&cmd_set_conntrack_common_last_seq,
14000                 (void *)&cmd_set_conntrack_common_last_seq_value,
14001                 (void *)&cmd_set_conntrack_common_last_ack,
14002                 (void *)&cmd_set_conntrack_common_last_ack_value,
14003                 (void *)&cmd_set_conntrack_common_last_end,
14004                 (void *)&cmd_set_conntrack_common_last_end_value,
14005                 (void *)&cmd_set_conntrack_common_last_index,
14006                 (void *)&cmd_set_conntrack_common_last_index_value,
14007                 NULL,
14008         },
14009 };
14010
14011 /** Set connection tracking object both directions' details */
14012 struct cmd_set_conntrack_dir_result {
14013         cmdline_fixed_string_t set;
14014         cmdline_fixed_string_t conntrack;
14015         cmdline_fixed_string_t dir;
14016         cmdline_fixed_string_t scale;
14017         cmdline_fixed_string_t fin;
14018         cmdline_fixed_string_t ack_seen;
14019         cmdline_fixed_string_t unack;
14020         cmdline_fixed_string_t sent_end;
14021         cmdline_fixed_string_t reply_end;
14022         cmdline_fixed_string_t max_win;
14023         cmdline_fixed_string_t max_ack;
14024         uint32_t factor;
14025         uint32_t f;
14026         uint32_t as;
14027         uint32_t un;
14028         uint32_t se;
14029         uint32_t re;
14030         uint32_t mw;
14031         uint32_t ma;
14032 };
14033
14034 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14035         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14036                                  set, "set");
14037 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14038         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14039                                  conntrack, "conntrack");
14040 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14041         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14042                                  dir, "orig#rply");
14043 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14044         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14045                                  scale, "scale");
14046 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14047         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14048                               factor, RTE_UINT32);
14049 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14050         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14051                                  fin, "fin");
14052 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14053         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14054                               f, RTE_UINT32);
14055 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14056         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14057                                  ack_seen, "acked");
14058 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14059         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14060                               as, RTE_UINT32);
14061 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14062         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14063                                  unack, "unack_data");
14064 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14065         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14066                               un, RTE_UINT32);
14067 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14068         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14069                                  sent_end, "sent_end");
14070 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14071         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14072                               se, RTE_UINT32);
14073 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14074         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14075                                  reply_end, "reply_end");
14076 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14077         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14078                               re, RTE_UINT32);
14079 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14080         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14081                                  max_win, "max_win");
14082 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14083         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14084                               mw, RTE_UINT32);
14085 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14086         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14087                                  max_ack, "max_ack");
14088 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14089         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14090                               ma, RTE_UINT32);
14091
14092 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14093         __rte_unused struct cmdline *cl,
14094         __rte_unused void *data)
14095 {
14096         struct cmd_set_conntrack_dir_result *res = parsed_result;
14097         struct rte_flow_tcp_dir_param *dir = NULL;
14098
14099         if (strcmp(res->dir, "orig") == 0)
14100                 dir = &conntrack_context.original_dir;
14101         else if (strcmp(res->dir, "rply") == 0)
14102                 dir = &conntrack_context.reply_dir;
14103         else
14104                 return;
14105         dir->scale = res->factor;
14106         dir->close_initiated = res->f;
14107         dir->last_ack_seen = res->as;
14108         dir->data_unacked = res->un;
14109         dir->sent_end = res->se;
14110         dir->reply_end = res->re;
14111         dir->max_ack = res->ma;
14112         dir->max_win = res->mw;
14113 }
14114
14115 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14116         .f = cmd_set_conntrack_dir_parsed,
14117         .data = NULL,
14118         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14119                     " acked <seen> unack_data <unack> sent_end <sent>"
14120                     " reply_end <reply> max_win <win> max_ack <ack>",
14121         .tokens = {
14122                 (void *)&cmd_set_conntrack_set,
14123                 (void *)&cmd_set_conntrack_conntrack,
14124                 (void *)&cmd_set_conntrack_dir_dir,
14125                 (void *)&cmd_set_conntrack_dir_scale,
14126                 (void *)&cmd_set_conntrack_dir_scale_value,
14127                 (void *)&cmd_set_conntrack_dir_fin,
14128                 (void *)&cmd_set_conntrack_dir_fin_value,
14129                 (void *)&cmd_set_conntrack_dir_ack,
14130                 (void *)&cmd_set_conntrack_dir_ack_value,
14131                 (void *)&cmd_set_conntrack_dir_unack_data,
14132                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14133                 (void *)&cmd_set_conntrack_dir_sent_end,
14134                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14135                 (void *)&cmd_set_conntrack_dir_reply_end,
14136                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14137                 (void *)&cmd_set_conntrack_dir_max_win,
14138                 (void *)&cmd_set_conntrack_dir_max_win_value,
14139                 (void *)&cmd_set_conntrack_dir_max_ack,
14140                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14141                 NULL,
14142         },
14143 };
14144
14145 /* Strict link priority scheduling mode setting */
14146 static void
14147 cmd_strict_link_prio_parsed(
14148         void *parsed_result,
14149         __rte_unused struct cmdline *cl,
14150         __rte_unused void *data)
14151 {
14152         struct cmd_vf_tc_bw_result *res = parsed_result;
14153         int ret = -ENOTSUP;
14154
14155         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14156                 return;
14157
14158 #ifdef RTE_NET_I40E
14159         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14160 #endif
14161
14162         switch (ret) {
14163         case 0:
14164                 break;
14165         case -EINVAL:
14166                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14167                 break;
14168         case -ENODEV:
14169                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14170                 break;
14171         case -ENOTSUP:
14172                 fprintf(stderr, "function not implemented\n");
14173                 break;
14174         default:
14175                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14176         }
14177 }
14178
14179 cmdline_parse_inst_t cmd_strict_link_prio = {
14180         .f = cmd_strict_link_prio_parsed,
14181         .data = NULL,
14182         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14183         .tokens = {
14184                 (void *)&cmd_vf_tc_bw_set,
14185                 (void *)&cmd_vf_tc_bw_tx,
14186                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14187                 (void *)&cmd_vf_tc_bw_port_id,
14188                 (void *)&cmd_vf_tc_bw_tc_map,
14189                 NULL,
14190         },
14191 };
14192
14193 /* Load dynamic device personalization*/
14194 struct cmd_ddp_add_result {
14195         cmdline_fixed_string_t ddp;
14196         cmdline_fixed_string_t add;
14197         portid_t port_id;
14198         char filepath[];
14199 };
14200
14201 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14202         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14203 cmdline_parse_token_string_t cmd_ddp_add_add =
14204         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14205 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14206         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14207                 RTE_UINT16);
14208 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14209         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14210
14211 static void
14212 cmd_ddp_add_parsed(
14213         void *parsed_result,
14214         __rte_unused struct cmdline *cl,
14215         __rte_unused void *data)
14216 {
14217         struct cmd_ddp_add_result *res = parsed_result;
14218         uint8_t *buff;
14219         uint32_t size;
14220         char *filepath;
14221         char *file_fld[2];
14222         int file_num;
14223         int ret = -ENOTSUP;
14224
14225         if (!all_ports_stopped()) {
14226                 fprintf(stderr, "Please stop all ports first\n");
14227                 return;
14228         }
14229
14230         filepath = strdup(res->filepath);
14231         if (filepath == NULL) {
14232                 fprintf(stderr, "Failed to allocate memory\n");
14233                 return;
14234         }
14235         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14236
14237         buff = open_file(file_fld[0], &size);
14238         if (!buff) {
14239                 free((void *)filepath);
14240                 return;
14241         }
14242
14243 #ifdef RTE_NET_I40E
14244         if (ret == -ENOTSUP)
14245                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14246                                                buff, size,
14247                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14248 #endif
14249
14250         if (ret == -EEXIST)
14251                 fprintf(stderr, "Profile has already existed.\n");
14252         else if (ret < 0)
14253                 fprintf(stderr, "Failed to load profile.\n");
14254         else if (file_num == 2)
14255                 save_file(file_fld[1], buff, size);
14256
14257         close_file(buff);
14258         free((void *)filepath);
14259 }
14260
14261 cmdline_parse_inst_t cmd_ddp_add = {
14262         .f = cmd_ddp_add_parsed,
14263         .data = NULL,
14264         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14265         .tokens = {
14266                 (void *)&cmd_ddp_add_ddp,
14267                 (void *)&cmd_ddp_add_add,
14268                 (void *)&cmd_ddp_add_port_id,
14269                 (void *)&cmd_ddp_add_filepath,
14270                 NULL,
14271         },
14272 };
14273
14274 /* Delete dynamic device personalization*/
14275 struct cmd_ddp_del_result {
14276         cmdline_fixed_string_t ddp;
14277         cmdline_fixed_string_t del;
14278         portid_t port_id;
14279         char filepath[];
14280 };
14281
14282 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14283         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14284 cmdline_parse_token_string_t cmd_ddp_del_del =
14285         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14286 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14287         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14288 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14289         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14290
14291 static void
14292 cmd_ddp_del_parsed(
14293         void *parsed_result,
14294         __rte_unused struct cmdline *cl,
14295         __rte_unused void *data)
14296 {
14297         struct cmd_ddp_del_result *res = parsed_result;
14298         uint8_t *buff;
14299         uint32_t size;
14300         int ret = -ENOTSUP;
14301
14302         if (!all_ports_stopped()) {
14303                 fprintf(stderr, "Please stop all ports first\n");
14304                 return;
14305         }
14306
14307         buff = open_file(res->filepath, &size);
14308         if (!buff)
14309                 return;
14310
14311 #ifdef RTE_NET_I40E
14312         if (ret == -ENOTSUP)
14313                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14314                                                buff, size,
14315                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14316 #endif
14317
14318         if (ret == -EACCES)
14319                 fprintf(stderr, "Profile does not exist.\n");
14320         else if (ret < 0)
14321                 fprintf(stderr, "Failed to delete profile.\n");
14322
14323         close_file(buff);
14324 }
14325
14326 cmdline_parse_inst_t cmd_ddp_del = {
14327         .f = cmd_ddp_del_parsed,
14328         .data = NULL,
14329         .help_str = "ddp del <port_id> <backup_profile_path>",
14330         .tokens = {
14331                 (void *)&cmd_ddp_del_ddp,
14332                 (void *)&cmd_ddp_del_del,
14333                 (void *)&cmd_ddp_del_port_id,
14334                 (void *)&cmd_ddp_del_filepath,
14335                 NULL,
14336         },
14337 };
14338
14339 /* Get dynamic device personalization profile info */
14340 struct cmd_ddp_info_result {
14341         cmdline_fixed_string_t ddp;
14342         cmdline_fixed_string_t get;
14343         cmdline_fixed_string_t info;
14344         char filepath[];
14345 };
14346
14347 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14348         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14349 cmdline_parse_token_string_t cmd_ddp_info_get =
14350         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14351 cmdline_parse_token_string_t cmd_ddp_info_info =
14352         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14353 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14354         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14355
14356 static void
14357 cmd_ddp_info_parsed(
14358         void *parsed_result,
14359         __rte_unused struct cmdline *cl,
14360         __rte_unused void *data)
14361 {
14362         struct cmd_ddp_info_result *res = parsed_result;
14363         uint8_t *pkg;
14364         uint32_t pkg_size;
14365         int ret = -ENOTSUP;
14366 #ifdef RTE_NET_I40E
14367         uint32_t i, j, n;
14368         uint8_t *buff;
14369         uint32_t buff_size = 0;
14370         struct rte_pmd_i40e_profile_info info;
14371         uint32_t dev_num = 0;
14372         struct rte_pmd_i40e_ddp_device_id *devs;
14373         uint32_t proto_num = 0;
14374         struct rte_pmd_i40e_proto_info *proto = NULL;
14375         uint32_t pctype_num = 0;
14376         struct rte_pmd_i40e_ptype_info *pctype;
14377         uint32_t ptype_num = 0;
14378         struct rte_pmd_i40e_ptype_info *ptype;
14379         uint8_t proto_id;
14380
14381 #endif
14382
14383         pkg = open_file(res->filepath, &pkg_size);
14384         if (!pkg)
14385                 return;
14386
14387 #ifdef RTE_NET_I40E
14388         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14389                                 (uint8_t *)&info, sizeof(info),
14390                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14391         if (!ret) {
14392                 printf("Global Track id:       0x%x\n", info.track_id);
14393                 printf("Global Version:        %d.%d.%d.%d\n",
14394                         info.version.major,
14395                         info.version.minor,
14396                         info.version.update,
14397                         info.version.draft);
14398                 printf("Global Package name:   %s\n\n", info.name);
14399         }
14400
14401         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14402                                 (uint8_t *)&info, sizeof(info),
14403                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14404         if (!ret) {
14405                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14406                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14407                         info.version.major,
14408                         info.version.minor,
14409                         info.version.update,
14410                         info.version.draft);
14411                 printf("i40e Profile name:     %s\n\n", info.name);
14412         }
14413
14414         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14415                                 (uint8_t *)&buff_size, sizeof(buff_size),
14416                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14417         if (!ret && buff_size) {
14418                 buff = (uint8_t *)malloc(buff_size);
14419                 if (buff) {
14420                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14421                                                 buff, buff_size,
14422                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14423                         if (!ret)
14424                                 printf("Package Notes:\n%s\n\n", buff);
14425                         free(buff);
14426                 }
14427         }
14428
14429         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14430                                 (uint8_t *)&dev_num, sizeof(dev_num),
14431                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14432         if (!ret && dev_num) {
14433                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14434                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14435                 if (devs) {
14436                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14437                                                 (uint8_t *)devs, buff_size,
14438                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14439                         if (!ret) {
14440                                 printf("List of supported devices:\n");
14441                                 for (i = 0; i < dev_num; i++) {
14442                                         printf("  %04X:%04X %04X:%04X\n",
14443                                                 devs[i].vendor_dev_id >> 16,
14444                                                 devs[i].vendor_dev_id & 0xFFFF,
14445                                                 devs[i].sub_vendor_dev_id >> 16,
14446                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14447                                 }
14448                                 printf("\n");
14449                         }
14450                         free(devs);
14451                 }
14452         }
14453
14454         /* get information about protocols and packet types */
14455         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14456                 (uint8_t *)&proto_num, sizeof(proto_num),
14457                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14458         if (ret || !proto_num)
14459                 goto no_print_return;
14460
14461         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14462         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14463         if (!proto)
14464                 goto no_print_return;
14465
14466         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14467                                         buff_size,
14468                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14469         if (!ret) {
14470                 printf("List of used protocols:\n");
14471                 for (i = 0; i < proto_num; i++)
14472                         printf("  %2u: %s\n", proto[i].proto_id,
14473                                proto[i].name);
14474                 printf("\n");
14475         }
14476         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14477                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14478                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14479         if (ret || !pctype_num)
14480                 goto no_print_pctypes;
14481
14482         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14483         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14484         if (!pctype)
14485                 goto no_print_pctypes;
14486
14487         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14488                                         buff_size,
14489                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14490         if (ret) {
14491                 free(pctype);
14492                 goto no_print_pctypes;
14493         }
14494
14495         printf("List of defined packet classification types:\n");
14496         for (i = 0; i < pctype_num; i++) {
14497                 printf("  %2u:", pctype[i].ptype_id);
14498                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14499                         proto_id = pctype[i].protocols[j];
14500                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14501                                 for (n = 0; n < proto_num; n++) {
14502                                         if (proto[n].proto_id == proto_id) {
14503                                                 printf(" %s", proto[n].name);
14504                                                 break;
14505                                         }
14506                                 }
14507                         }
14508                 }
14509                 printf("\n");
14510         }
14511         printf("\n");
14512         free(pctype);
14513
14514 no_print_pctypes:
14515
14516         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14517                                         sizeof(ptype_num),
14518                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14519         if (ret || !ptype_num)
14520                 goto no_print_return;
14521
14522         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14523         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14524         if (!ptype)
14525                 goto no_print_return;
14526
14527         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14528                                         buff_size,
14529                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14530         if (ret) {
14531                 free(ptype);
14532                 goto no_print_return;
14533         }
14534         printf("List of defined packet types:\n");
14535         for (i = 0; i < ptype_num; i++) {
14536                 printf("  %2u:", ptype[i].ptype_id);
14537                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14538                         proto_id = ptype[i].protocols[j];
14539                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14540                                 for (n = 0; n < proto_num; n++) {
14541                                         if (proto[n].proto_id == proto_id) {
14542                                                 printf(" %s", proto[n].name);
14543                                                 break;
14544                                         }
14545                                 }
14546                         }
14547                 }
14548                 printf("\n");
14549         }
14550         free(ptype);
14551         printf("\n");
14552
14553         ret = 0;
14554 no_print_return:
14555         if (proto)
14556                 free(proto);
14557 #endif
14558         if (ret == -ENOTSUP)
14559                 fprintf(stderr, "Function not supported in PMD driver\n");
14560         close_file(pkg);
14561 }
14562
14563 cmdline_parse_inst_t cmd_ddp_get_info = {
14564         .f = cmd_ddp_info_parsed,
14565         .data = NULL,
14566         .help_str = "ddp get info <profile_path>",
14567         .tokens = {
14568                 (void *)&cmd_ddp_info_ddp,
14569                 (void *)&cmd_ddp_info_get,
14570                 (void *)&cmd_ddp_info_info,
14571                 (void *)&cmd_ddp_info_filepath,
14572                 NULL,
14573         },
14574 };
14575
14576 /* Get dynamic device personalization profile info list*/
14577 #define PROFILE_INFO_SIZE 48
14578 #define MAX_PROFILE_NUM 16
14579
14580 struct cmd_ddp_get_list_result {
14581         cmdline_fixed_string_t ddp;
14582         cmdline_fixed_string_t get;
14583         cmdline_fixed_string_t list;
14584         portid_t port_id;
14585 };
14586
14587 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14588         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14589 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14590         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14591 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14592         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14593 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14594         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14595                 RTE_UINT16);
14596
14597 static void
14598 cmd_ddp_get_list_parsed(
14599         __rte_unused void *parsed_result,
14600         __rte_unused struct cmdline *cl,
14601         __rte_unused void *data)
14602 {
14603 #ifdef RTE_NET_I40E
14604         struct cmd_ddp_get_list_result *res = parsed_result;
14605         struct rte_pmd_i40e_profile_list *p_list;
14606         struct rte_pmd_i40e_profile_info *p_info;
14607         uint32_t p_num;
14608         uint32_t size;
14609         uint32_t i;
14610 #endif
14611         int ret = -ENOTSUP;
14612
14613 #ifdef RTE_NET_I40E
14614         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14615         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14616         if (!p_list) {
14617                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14618                 return;
14619         }
14620
14621         if (ret == -ENOTSUP)
14622                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14623                                                 (uint8_t *)p_list, size);
14624
14625         if (!ret) {
14626                 p_num = p_list->p_count;
14627                 printf("Profile number is: %d\n\n", p_num);
14628
14629                 for (i = 0; i < p_num; i++) {
14630                         p_info = &p_list->p_info[i];
14631                         printf("Profile %d:\n", i);
14632                         printf("Track id:     0x%x\n", p_info->track_id);
14633                         printf("Version:      %d.%d.%d.%d\n",
14634                                p_info->version.major,
14635                                p_info->version.minor,
14636                                p_info->version.update,
14637                                p_info->version.draft);
14638                         printf("Profile name: %s\n\n", p_info->name);
14639                 }
14640         }
14641
14642         free(p_list);
14643 #endif
14644
14645         if (ret < 0)
14646                 fprintf(stderr, "Failed to get ddp list\n");
14647 }
14648
14649 cmdline_parse_inst_t cmd_ddp_get_list = {
14650         .f = cmd_ddp_get_list_parsed,
14651         .data = NULL,
14652         .help_str = "ddp get list <port_id>",
14653         .tokens = {
14654                 (void *)&cmd_ddp_get_list_ddp,
14655                 (void *)&cmd_ddp_get_list_get,
14656                 (void *)&cmd_ddp_get_list_list,
14657                 (void *)&cmd_ddp_get_list_port_id,
14658                 NULL,
14659         },
14660 };
14661
14662 /* Configure input set */
14663 struct cmd_cfg_input_set_result {
14664         cmdline_fixed_string_t port;
14665         cmdline_fixed_string_t cfg;
14666         portid_t port_id;
14667         cmdline_fixed_string_t pctype;
14668         uint8_t pctype_id;
14669         cmdline_fixed_string_t inset_type;
14670         cmdline_fixed_string_t opt;
14671         cmdline_fixed_string_t field;
14672         uint8_t field_idx;
14673 };
14674
14675 static void
14676 cmd_cfg_input_set_parsed(
14677         __rte_unused void *parsed_result,
14678         __rte_unused struct cmdline *cl,
14679         __rte_unused void *data)
14680 {
14681 #ifdef RTE_NET_I40E
14682         struct cmd_cfg_input_set_result *res = parsed_result;
14683         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14684         struct rte_pmd_i40e_inset inset;
14685 #endif
14686         int ret = -ENOTSUP;
14687
14688         if (!all_ports_stopped()) {
14689                 fprintf(stderr, "Please stop all ports first\n");
14690                 return;
14691         }
14692
14693 #ifdef RTE_NET_I40E
14694         if (!strcmp(res->inset_type, "hash_inset"))
14695                 inset_type = INSET_HASH;
14696         else if (!strcmp(res->inset_type, "fdir_inset"))
14697                 inset_type = INSET_FDIR;
14698         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14699                 inset_type = INSET_FDIR_FLX;
14700         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14701                                      &inset, inset_type);
14702         if (ret) {
14703                 fprintf(stderr, "Failed to get input set.\n");
14704                 return;
14705         }
14706
14707         if (!strcmp(res->opt, "get")) {
14708                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14709                                                    res->field_idx);
14710                 if (ret)
14711                         printf("Field index %d is enabled.\n", res->field_idx);
14712                 else
14713                         printf("Field index %d is disabled.\n", res->field_idx);
14714                 return;
14715         } else if (!strcmp(res->opt, "set"))
14716                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14717                                                    res->field_idx);
14718         else if (!strcmp(res->opt, "clear"))
14719                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14720                                                      res->field_idx);
14721         if (ret) {
14722                 fprintf(stderr, "Failed to configure input set field.\n");
14723                 return;
14724         }
14725
14726         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14727                                      &inset, inset_type);
14728         if (ret) {
14729                 fprintf(stderr, "Failed to set input set.\n");
14730                 return;
14731         }
14732 #endif
14733
14734         if (ret == -ENOTSUP)
14735                 fprintf(stderr, "Function not supported\n");
14736 }
14737
14738 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14739         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14740                                  port, "port");
14741 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14742         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14743                                  cfg, "config");
14744 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14745         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14746                               port_id, RTE_UINT16);
14747 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14748         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14749                                  pctype, "pctype");
14750 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14751         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14752                               pctype_id, RTE_UINT8);
14753 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14754         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14755                                  inset_type,
14756                                  "hash_inset#fdir_inset#fdir_flx_inset");
14757 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14758         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14759                                  opt, "get#set#clear");
14760 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14761         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14762                                  field, "field");
14763 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14764         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14765                               field_idx, RTE_UINT8);
14766
14767 cmdline_parse_inst_t cmd_cfg_input_set = {
14768         .f = cmd_cfg_input_set_parsed,
14769         .data = NULL,
14770         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14771                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14772         .tokens = {
14773                 (void *)&cmd_cfg_input_set_port,
14774                 (void *)&cmd_cfg_input_set_cfg,
14775                 (void *)&cmd_cfg_input_set_port_id,
14776                 (void *)&cmd_cfg_input_set_pctype,
14777                 (void *)&cmd_cfg_input_set_pctype_id,
14778                 (void *)&cmd_cfg_input_set_inset_type,
14779                 (void *)&cmd_cfg_input_set_opt,
14780                 (void *)&cmd_cfg_input_set_field,
14781                 (void *)&cmd_cfg_input_set_field_idx,
14782                 NULL,
14783         },
14784 };
14785
14786 /* Clear input set */
14787 struct cmd_clear_input_set_result {
14788         cmdline_fixed_string_t port;
14789         cmdline_fixed_string_t cfg;
14790         portid_t port_id;
14791         cmdline_fixed_string_t pctype;
14792         uint8_t pctype_id;
14793         cmdline_fixed_string_t inset_type;
14794         cmdline_fixed_string_t clear;
14795         cmdline_fixed_string_t all;
14796 };
14797
14798 static void
14799 cmd_clear_input_set_parsed(
14800         __rte_unused void *parsed_result,
14801         __rte_unused struct cmdline *cl,
14802         __rte_unused void *data)
14803 {
14804 #ifdef RTE_NET_I40E
14805         struct cmd_clear_input_set_result *res = parsed_result;
14806         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14807         struct rte_pmd_i40e_inset inset;
14808 #endif
14809         int ret = -ENOTSUP;
14810
14811         if (!all_ports_stopped()) {
14812                 fprintf(stderr, "Please stop all ports first\n");
14813                 return;
14814         }
14815
14816 #ifdef RTE_NET_I40E
14817         if (!strcmp(res->inset_type, "hash_inset"))
14818                 inset_type = INSET_HASH;
14819         else if (!strcmp(res->inset_type, "fdir_inset"))
14820                 inset_type = INSET_FDIR;
14821         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14822                 inset_type = INSET_FDIR_FLX;
14823
14824         memset(&inset, 0, sizeof(inset));
14825
14826         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14827                                      &inset, inset_type);
14828         if (ret) {
14829                 fprintf(stderr, "Failed to clear input set.\n");
14830                 return;
14831         }
14832
14833 #endif
14834
14835         if (ret == -ENOTSUP)
14836                 fprintf(stderr, "Function not supported\n");
14837 }
14838
14839 cmdline_parse_token_string_t cmd_clear_input_set_port =
14840         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14841                                  port, "port");
14842 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14843         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14844                                  cfg, "config");
14845 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14846         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14847                               port_id, RTE_UINT16);
14848 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14849         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14850                                  pctype, "pctype");
14851 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14852         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14853                               pctype_id, RTE_UINT8);
14854 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14855         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14856                                  inset_type,
14857                                  "hash_inset#fdir_inset#fdir_flx_inset");
14858 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14859         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14860                                  clear, "clear");
14861 cmdline_parse_token_string_t cmd_clear_input_set_all =
14862         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14863                                  all, "all");
14864
14865 cmdline_parse_inst_t cmd_clear_input_set = {
14866         .f = cmd_clear_input_set_parsed,
14867         .data = NULL,
14868         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14869                     "fdir_inset|fdir_flx_inset clear all",
14870         .tokens = {
14871                 (void *)&cmd_clear_input_set_port,
14872                 (void *)&cmd_clear_input_set_cfg,
14873                 (void *)&cmd_clear_input_set_port_id,
14874                 (void *)&cmd_clear_input_set_pctype,
14875                 (void *)&cmd_clear_input_set_pctype_id,
14876                 (void *)&cmd_clear_input_set_inset_type,
14877                 (void *)&cmd_clear_input_set_clear,
14878                 (void *)&cmd_clear_input_set_all,
14879                 NULL,
14880         },
14881 };
14882
14883 /* show vf stats */
14884
14885 /* Common result structure for show vf stats */
14886 struct cmd_show_vf_stats_result {
14887         cmdline_fixed_string_t show;
14888         cmdline_fixed_string_t vf;
14889         cmdline_fixed_string_t stats;
14890         portid_t port_id;
14891         uint16_t vf_id;
14892 };
14893
14894 /* Common CLI fields show vf stats*/
14895 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14896         TOKEN_STRING_INITIALIZER
14897                 (struct cmd_show_vf_stats_result,
14898                  show, "show");
14899 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14900         TOKEN_STRING_INITIALIZER
14901                 (struct cmd_show_vf_stats_result,
14902                  vf, "vf");
14903 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14904         TOKEN_STRING_INITIALIZER
14905                 (struct cmd_show_vf_stats_result,
14906                  stats, "stats");
14907 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14908         TOKEN_NUM_INITIALIZER
14909                 (struct cmd_show_vf_stats_result,
14910                  port_id, RTE_UINT16);
14911 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14912         TOKEN_NUM_INITIALIZER
14913                 (struct cmd_show_vf_stats_result,
14914                  vf_id, RTE_UINT16);
14915
14916 static void
14917 cmd_show_vf_stats_parsed(
14918         void *parsed_result,
14919         __rte_unused struct cmdline *cl,
14920         __rte_unused void *data)
14921 {
14922         struct cmd_show_vf_stats_result *res = parsed_result;
14923         struct rte_eth_stats stats;
14924         int ret = -ENOTSUP;
14925         static const char *nic_stats_border = "########################";
14926
14927         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14928                 return;
14929
14930         memset(&stats, 0, sizeof(stats));
14931
14932 #ifdef RTE_NET_I40E
14933         if (ret == -ENOTSUP)
14934                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14935                                                 res->vf_id,
14936                                                 &stats);
14937 #endif
14938 #ifdef RTE_NET_BNXT
14939         if (ret == -ENOTSUP)
14940                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14941                                                 res->vf_id,
14942                                                 &stats);
14943 #endif
14944
14945         switch (ret) {
14946         case 0:
14947                 break;
14948         case -EINVAL:
14949                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
14950                 break;
14951         case -ENODEV:
14952                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14953                 break;
14954         case -ENOTSUP:
14955                 fprintf(stderr, "function not implemented\n");
14956                 break;
14957         default:
14958                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14959         }
14960
14961         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14962                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14963
14964         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14965                "%-"PRIu64"\n",
14966                stats.ipackets, stats.imissed, stats.ibytes);
14967         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14968         printf("  RX-nombuf:  %-10"PRIu64"\n",
14969                stats.rx_nombuf);
14970         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14971                "%-"PRIu64"\n",
14972                stats.opackets, stats.oerrors, stats.obytes);
14973
14974         printf("  %s############################%s\n",
14975                                nic_stats_border, nic_stats_border);
14976 }
14977
14978 cmdline_parse_inst_t cmd_show_vf_stats = {
14979         .f = cmd_show_vf_stats_parsed,
14980         .data = NULL,
14981         .help_str = "show vf stats <port_id> <vf_id>",
14982         .tokens = {
14983                 (void *)&cmd_show_vf_stats_show,
14984                 (void *)&cmd_show_vf_stats_vf,
14985                 (void *)&cmd_show_vf_stats_stats,
14986                 (void *)&cmd_show_vf_stats_port_id,
14987                 (void *)&cmd_show_vf_stats_vf_id,
14988                 NULL,
14989         },
14990 };
14991
14992 /* clear vf stats */
14993
14994 /* Common result structure for clear vf stats */
14995 struct cmd_clear_vf_stats_result {
14996         cmdline_fixed_string_t clear;
14997         cmdline_fixed_string_t vf;
14998         cmdline_fixed_string_t stats;
14999         portid_t port_id;
15000         uint16_t vf_id;
15001 };
15002
15003 /* Common CLI fields clear vf stats*/
15004 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15005         TOKEN_STRING_INITIALIZER
15006                 (struct cmd_clear_vf_stats_result,
15007                  clear, "clear");
15008 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15009         TOKEN_STRING_INITIALIZER
15010                 (struct cmd_clear_vf_stats_result,
15011                  vf, "vf");
15012 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_clear_vf_stats_result,
15015                  stats, "stats");
15016 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15017         TOKEN_NUM_INITIALIZER
15018                 (struct cmd_clear_vf_stats_result,
15019                  port_id, RTE_UINT16);
15020 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15021         TOKEN_NUM_INITIALIZER
15022                 (struct cmd_clear_vf_stats_result,
15023                  vf_id, RTE_UINT16);
15024
15025 static void
15026 cmd_clear_vf_stats_parsed(
15027         void *parsed_result,
15028         __rte_unused struct cmdline *cl,
15029         __rte_unused void *data)
15030 {
15031         struct cmd_clear_vf_stats_result *res = parsed_result;
15032         int ret = -ENOTSUP;
15033
15034         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15035                 return;
15036
15037 #ifdef RTE_NET_I40E
15038         if (ret == -ENOTSUP)
15039                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15040                                                   res->vf_id);
15041 #endif
15042 #ifdef RTE_NET_BNXT
15043         if (ret == -ENOTSUP)
15044                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15045                                                   res->vf_id);
15046 #endif
15047
15048         switch (ret) {
15049         case 0:
15050                 break;
15051         case -EINVAL:
15052                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15053                 break;
15054         case -ENODEV:
15055                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15056                 break;
15057         case -ENOTSUP:
15058                 fprintf(stderr, "function not implemented\n");
15059                 break;
15060         default:
15061                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15062         }
15063 }
15064
15065 cmdline_parse_inst_t cmd_clear_vf_stats = {
15066         .f = cmd_clear_vf_stats_parsed,
15067         .data = NULL,
15068         .help_str = "clear vf stats <port_id> <vf_id>",
15069         .tokens = {
15070                 (void *)&cmd_clear_vf_stats_clear,
15071                 (void *)&cmd_clear_vf_stats_vf,
15072                 (void *)&cmd_clear_vf_stats_stats,
15073                 (void *)&cmd_clear_vf_stats_port_id,
15074                 (void *)&cmd_clear_vf_stats_vf_id,
15075                 NULL,
15076         },
15077 };
15078
15079 /* port config pctype mapping reset */
15080
15081 /* Common result structure for port config pctype mapping reset */
15082 struct cmd_pctype_mapping_reset_result {
15083         cmdline_fixed_string_t port;
15084         cmdline_fixed_string_t config;
15085         portid_t port_id;
15086         cmdline_fixed_string_t pctype;
15087         cmdline_fixed_string_t mapping;
15088         cmdline_fixed_string_t reset;
15089 };
15090
15091 /* Common CLI fields for port config pctype mapping reset*/
15092 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15093         TOKEN_STRING_INITIALIZER
15094                 (struct cmd_pctype_mapping_reset_result,
15095                  port, "port");
15096 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15097         TOKEN_STRING_INITIALIZER
15098                 (struct cmd_pctype_mapping_reset_result,
15099                  config, "config");
15100 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15101         TOKEN_NUM_INITIALIZER
15102                 (struct cmd_pctype_mapping_reset_result,
15103                  port_id, RTE_UINT16);
15104 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15105         TOKEN_STRING_INITIALIZER
15106                 (struct cmd_pctype_mapping_reset_result,
15107                  pctype, "pctype");
15108 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15109         TOKEN_STRING_INITIALIZER
15110                 (struct cmd_pctype_mapping_reset_result,
15111                  mapping, "mapping");
15112 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15113         TOKEN_STRING_INITIALIZER
15114                 (struct cmd_pctype_mapping_reset_result,
15115                  reset, "reset");
15116
15117 static void
15118 cmd_pctype_mapping_reset_parsed(
15119         void *parsed_result,
15120         __rte_unused struct cmdline *cl,
15121         __rte_unused void *data)
15122 {
15123         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15124         int ret = -ENOTSUP;
15125
15126         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15127                 return;
15128
15129 #ifdef RTE_NET_I40E
15130         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15131 #endif
15132
15133         switch (ret) {
15134         case 0:
15135                 break;
15136         case -ENODEV:
15137                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15138                 break;
15139         case -ENOTSUP:
15140                 fprintf(stderr, "function not implemented\n");
15141                 break;
15142         default:
15143                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15144         }
15145 }
15146
15147 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15148         .f = cmd_pctype_mapping_reset_parsed,
15149         .data = NULL,
15150         .help_str = "port config <port_id> pctype mapping reset",
15151         .tokens = {
15152                 (void *)&cmd_pctype_mapping_reset_port,
15153                 (void *)&cmd_pctype_mapping_reset_config,
15154                 (void *)&cmd_pctype_mapping_reset_port_id,
15155                 (void *)&cmd_pctype_mapping_reset_pctype,
15156                 (void *)&cmd_pctype_mapping_reset_mapping,
15157                 (void *)&cmd_pctype_mapping_reset_reset,
15158                 NULL,
15159         },
15160 };
15161
15162 /* show port pctype mapping */
15163
15164 /* Common result structure for show port pctype mapping */
15165 struct cmd_pctype_mapping_get_result {
15166         cmdline_fixed_string_t show;
15167         cmdline_fixed_string_t port;
15168         portid_t port_id;
15169         cmdline_fixed_string_t pctype;
15170         cmdline_fixed_string_t mapping;
15171 };
15172
15173 /* Common CLI fields for pctype mapping get */
15174 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15175         TOKEN_STRING_INITIALIZER
15176                 (struct cmd_pctype_mapping_get_result,
15177                  show, "show");
15178 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15179         TOKEN_STRING_INITIALIZER
15180                 (struct cmd_pctype_mapping_get_result,
15181                  port, "port");
15182 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15183         TOKEN_NUM_INITIALIZER
15184                 (struct cmd_pctype_mapping_get_result,
15185                  port_id, RTE_UINT16);
15186 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15187         TOKEN_STRING_INITIALIZER
15188                 (struct cmd_pctype_mapping_get_result,
15189                  pctype, "pctype");
15190 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15191         TOKEN_STRING_INITIALIZER
15192                 (struct cmd_pctype_mapping_get_result,
15193                  mapping, "mapping");
15194
15195 static void
15196 cmd_pctype_mapping_get_parsed(
15197         void *parsed_result,
15198         __rte_unused struct cmdline *cl,
15199         __rte_unused void *data)
15200 {
15201         struct cmd_pctype_mapping_get_result *res = parsed_result;
15202         int ret = -ENOTSUP;
15203 #ifdef RTE_NET_I40E
15204         struct rte_pmd_i40e_flow_type_mapping
15205                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15206         int i, j, first_pctype;
15207 #endif
15208
15209         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15210                 return;
15211
15212 #ifdef RTE_NET_I40E
15213         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15214 #endif
15215
15216         switch (ret) {
15217         case 0:
15218                 break;
15219         case -ENODEV:
15220                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15221                 return;
15222         case -ENOTSUP:
15223                 fprintf(stderr, "function not implemented\n");
15224                 return;
15225         default:
15226                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15227                 return;
15228         }
15229
15230 #ifdef RTE_NET_I40E
15231         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15232                 if (mapping[i].pctype != 0ULL) {
15233                         first_pctype = 1;
15234
15235                         printf("pctype: ");
15236                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15237                                 if (mapping[i].pctype & (1ULL << j)) {
15238                                         printf(first_pctype ?
15239                                                "%02d" : ",%02d", j);
15240                                         first_pctype = 0;
15241                                 }
15242                         }
15243                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15244                 }
15245         }
15246 #endif
15247 }
15248
15249 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15250         .f = cmd_pctype_mapping_get_parsed,
15251         .data = NULL,
15252         .help_str = "show port <port_id> pctype mapping",
15253         .tokens = {
15254                 (void *)&cmd_pctype_mapping_get_show,
15255                 (void *)&cmd_pctype_mapping_get_port,
15256                 (void *)&cmd_pctype_mapping_get_port_id,
15257                 (void *)&cmd_pctype_mapping_get_pctype,
15258                 (void *)&cmd_pctype_mapping_get_mapping,
15259                 NULL,
15260         },
15261 };
15262
15263 /* port config pctype mapping update */
15264
15265 /* Common result structure for port config pctype mapping update */
15266 struct cmd_pctype_mapping_update_result {
15267         cmdline_fixed_string_t port;
15268         cmdline_fixed_string_t config;
15269         portid_t port_id;
15270         cmdline_fixed_string_t pctype;
15271         cmdline_fixed_string_t mapping;
15272         cmdline_fixed_string_t update;
15273         cmdline_fixed_string_t pctype_list;
15274         uint16_t flow_type;
15275 };
15276
15277 /* Common CLI fields for pctype mapping update*/
15278 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15279         TOKEN_STRING_INITIALIZER
15280                 (struct cmd_pctype_mapping_update_result,
15281                  port, "port");
15282 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15283         TOKEN_STRING_INITIALIZER
15284                 (struct cmd_pctype_mapping_update_result,
15285                  config, "config");
15286 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15287         TOKEN_NUM_INITIALIZER
15288                 (struct cmd_pctype_mapping_update_result,
15289                  port_id, RTE_UINT16);
15290 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15291         TOKEN_STRING_INITIALIZER
15292                 (struct cmd_pctype_mapping_update_result,
15293                  pctype, "pctype");
15294 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15295         TOKEN_STRING_INITIALIZER
15296                 (struct cmd_pctype_mapping_update_result,
15297                  mapping, "mapping");
15298 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15299         TOKEN_STRING_INITIALIZER
15300                 (struct cmd_pctype_mapping_update_result,
15301                  update, "update");
15302 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15303         TOKEN_STRING_INITIALIZER
15304                 (struct cmd_pctype_mapping_update_result,
15305                  pctype_list, NULL);
15306 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15307         TOKEN_NUM_INITIALIZER
15308                 (struct cmd_pctype_mapping_update_result,
15309                  flow_type, RTE_UINT16);
15310
15311 static void
15312 cmd_pctype_mapping_update_parsed(
15313         void *parsed_result,
15314         __rte_unused struct cmdline *cl,
15315         __rte_unused void *data)
15316 {
15317         struct cmd_pctype_mapping_update_result *res = parsed_result;
15318         int ret = -ENOTSUP;
15319 #ifdef RTE_NET_I40E
15320         struct rte_pmd_i40e_flow_type_mapping mapping;
15321         unsigned int i;
15322         unsigned int nb_item;
15323         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15324 #endif
15325
15326         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15327                 return;
15328
15329 #ifdef RTE_NET_I40E
15330         nb_item = parse_item_list(res->pctype_list, "pctypes",
15331                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15332         mapping.flow_type = res->flow_type;
15333         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15334                 mapping.pctype |= (1ULL << pctype_list[i]);
15335         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15336                                                 &mapping,
15337                                                 1,
15338                                                 0);
15339 #endif
15340
15341         switch (ret) {
15342         case 0:
15343                 break;
15344         case -EINVAL:
15345                 fprintf(stderr, "invalid pctype or flow type\n");
15346                 break;
15347         case -ENODEV:
15348                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15349                 break;
15350         case -ENOTSUP:
15351                 fprintf(stderr, "function not implemented\n");
15352                 break;
15353         default:
15354                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15355         }
15356 }
15357
15358 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15359         .f = cmd_pctype_mapping_update_parsed,
15360         .data = NULL,
15361         .help_str = "port config <port_id> pctype mapping update"
15362         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15363         .tokens = {
15364                 (void *)&cmd_pctype_mapping_update_port,
15365                 (void *)&cmd_pctype_mapping_update_config,
15366                 (void *)&cmd_pctype_mapping_update_port_id,
15367                 (void *)&cmd_pctype_mapping_update_pctype,
15368                 (void *)&cmd_pctype_mapping_update_mapping,
15369                 (void *)&cmd_pctype_mapping_update_update,
15370                 (void *)&cmd_pctype_mapping_update_pc_type,
15371                 (void *)&cmd_pctype_mapping_update_flow_type,
15372                 NULL,
15373         },
15374 };
15375
15376 /* ptype mapping get */
15377
15378 /* Common result structure for ptype mapping get */
15379 struct cmd_ptype_mapping_get_result {
15380         cmdline_fixed_string_t ptype;
15381         cmdline_fixed_string_t mapping;
15382         cmdline_fixed_string_t get;
15383         portid_t port_id;
15384         uint8_t valid_only;
15385 };
15386
15387 /* Common CLI fields for ptype mapping get */
15388 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15389         TOKEN_STRING_INITIALIZER
15390                 (struct cmd_ptype_mapping_get_result,
15391                  ptype, "ptype");
15392 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15393         TOKEN_STRING_INITIALIZER
15394                 (struct cmd_ptype_mapping_get_result,
15395                  mapping, "mapping");
15396 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15397         TOKEN_STRING_INITIALIZER
15398                 (struct cmd_ptype_mapping_get_result,
15399                  get, "get");
15400 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15401         TOKEN_NUM_INITIALIZER
15402                 (struct cmd_ptype_mapping_get_result,
15403                  port_id, RTE_UINT16);
15404 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15405         TOKEN_NUM_INITIALIZER
15406                 (struct cmd_ptype_mapping_get_result,
15407                  valid_only, RTE_UINT8);
15408
15409 static void
15410 cmd_ptype_mapping_get_parsed(
15411         void *parsed_result,
15412         __rte_unused struct cmdline *cl,
15413         __rte_unused void *data)
15414 {
15415         struct cmd_ptype_mapping_get_result *res = parsed_result;
15416         int ret = -ENOTSUP;
15417 #ifdef RTE_NET_I40E
15418         int max_ptype_num = 256;
15419         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15420         uint16_t count;
15421         int i;
15422 #endif
15423
15424         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15425                 return;
15426
15427 #ifdef RTE_NET_I40E
15428         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15429                                         mapping,
15430                                         max_ptype_num,
15431                                         &count,
15432                                         res->valid_only);
15433 #endif
15434
15435         switch (ret) {
15436         case 0:
15437                 break;
15438         case -ENODEV:
15439                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15440                 break;
15441         case -ENOTSUP:
15442                 fprintf(stderr, "function not implemented\n");
15443                 break;
15444         default:
15445                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15446         }
15447
15448 #ifdef RTE_NET_I40E
15449         if (!ret) {
15450                 for (i = 0; i < count; i++)
15451                         printf("%3d\t0x%08x\n",
15452                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15453         }
15454 #endif
15455 }
15456
15457 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15458         .f = cmd_ptype_mapping_get_parsed,
15459         .data = NULL,
15460         .help_str = "ptype mapping get <port_id> <valid_only>",
15461         .tokens = {
15462                 (void *)&cmd_ptype_mapping_get_ptype,
15463                 (void *)&cmd_ptype_mapping_get_mapping,
15464                 (void *)&cmd_ptype_mapping_get_get,
15465                 (void *)&cmd_ptype_mapping_get_port_id,
15466                 (void *)&cmd_ptype_mapping_get_valid_only,
15467                 NULL,
15468         },
15469 };
15470
15471 /* ptype mapping replace */
15472
15473 /* Common result structure for ptype mapping replace */
15474 struct cmd_ptype_mapping_replace_result {
15475         cmdline_fixed_string_t ptype;
15476         cmdline_fixed_string_t mapping;
15477         cmdline_fixed_string_t replace;
15478         portid_t port_id;
15479         uint32_t target;
15480         uint8_t mask;
15481         uint32_t pkt_type;
15482 };
15483
15484 /* Common CLI fields for ptype mapping replace */
15485 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15486         TOKEN_STRING_INITIALIZER
15487                 (struct cmd_ptype_mapping_replace_result,
15488                  ptype, "ptype");
15489 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15490         TOKEN_STRING_INITIALIZER
15491                 (struct cmd_ptype_mapping_replace_result,
15492                  mapping, "mapping");
15493 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15494         TOKEN_STRING_INITIALIZER
15495                 (struct cmd_ptype_mapping_replace_result,
15496                  replace, "replace");
15497 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15498         TOKEN_NUM_INITIALIZER
15499                 (struct cmd_ptype_mapping_replace_result,
15500                  port_id, RTE_UINT16);
15501 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15502         TOKEN_NUM_INITIALIZER
15503                 (struct cmd_ptype_mapping_replace_result,
15504                  target, RTE_UINT32);
15505 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15506         TOKEN_NUM_INITIALIZER
15507                 (struct cmd_ptype_mapping_replace_result,
15508                  mask, RTE_UINT8);
15509 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15510         TOKEN_NUM_INITIALIZER
15511                 (struct cmd_ptype_mapping_replace_result,
15512                  pkt_type, RTE_UINT32);
15513
15514 static void
15515 cmd_ptype_mapping_replace_parsed(
15516         void *parsed_result,
15517         __rte_unused struct cmdline *cl,
15518         __rte_unused void *data)
15519 {
15520         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15521         int ret = -ENOTSUP;
15522
15523         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15524                 return;
15525
15526 #ifdef RTE_NET_I40E
15527         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15528                                         res->target,
15529                                         res->mask,
15530                                         res->pkt_type);
15531 #endif
15532
15533         switch (ret) {
15534         case 0:
15535                 break;
15536         case -EINVAL:
15537                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15538                         res->target, res->pkt_type);
15539                 break;
15540         case -ENODEV:
15541                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15542                 break;
15543         case -ENOTSUP:
15544                 fprintf(stderr, "function not implemented\n");
15545                 break;
15546         default:
15547                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15548         }
15549 }
15550
15551 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15552         .f = cmd_ptype_mapping_replace_parsed,
15553         .data = NULL,
15554         .help_str =
15555                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15556         .tokens = {
15557                 (void *)&cmd_ptype_mapping_replace_ptype,
15558                 (void *)&cmd_ptype_mapping_replace_mapping,
15559                 (void *)&cmd_ptype_mapping_replace_replace,
15560                 (void *)&cmd_ptype_mapping_replace_port_id,
15561                 (void *)&cmd_ptype_mapping_replace_target,
15562                 (void *)&cmd_ptype_mapping_replace_mask,
15563                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15564                 NULL,
15565         },
15566 };
15567
15568 /* ptype mapping reset */
15569
15570 /* Common result structure for ptype mapping reset */
15571 struct cmd_ptype_mapping_reset_result {
15572         cmdline_fixed_string_t ptype;
15573         cmdline_fixed_string_t mapping;
15574         cmdline_fixed_string_t reset;
15575         portid_t port_id;
15576 };
15577
15578 /* Common CLI fields for ptype mapping reset*/
15579 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15580         TOKEN_STRING_INITIALIZER
15581                 (struct cmd_ptype_mapping_reset_result,
15582                  ptype, "ptype");
15583 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15584         TOKEN_STRING_INITIALIZER
15585                 (struct cmd_ptype_mapping_reset_result,
15586                  mapping, "mapping");
15587 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15588         TOKEN_STRING_INITIALIZER
15589                 (struct cmd_ptype_mapping_reset_result,
15590                  reset, "reset");
15591 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15592         TOKEN_NUM_INITIALIZER
15593                 (struct cmd_ptype_mapping_reset_result,
15594                  port_id, RTE_UINT16);
15595
15596 static void
15597 cmd_ptype_mapping_reset_parsed(
15598         void *parsed_result,
15599         __rte_unused struct cmdline *cl,
15600         __rte_unused void *data)
15601 {
15602         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15603         int ret = -ENOTSUP;
15604
15605         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15606                 return;
15607
15608 #ifdef RTE_NET_I40E
15609         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15610 #endif
15611
15612         switch (ret) {
15613         case 0:
15614                 break;
15615         case -ENODEV:
15616                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15617                 break;
15618         case -ENOTSUP:
15619                 fprintf(stderr, "function not implemented\n");
15620                 break;
15621         default:
15622                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15623         }
15624 }
15625
15626 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15627         .f = cmd_ptype_mapping_reset_parsed,
15628         .data = NULL,
15629         .help_str = "ptype mapping reset <port_id>",
15630         .tokens = {
15631                 (void *)&cmd_ptype_mapping_reset_ptype,
15632                 (void *)&cmd_ptype_mapping_reset_mapping,
15633                 (void *)&cmd_ptype_mapping_reset_reset,
15634                 (void *)&cmd_ptype_mapping_reset_port_id,
15635                 NULL,
15636         },
15637 };
15638
15639 /* ptype mapping update */
15640
15641 /* Common result structure for ptype mapping update */
15642 struct cmd_ptype_mapping_update_result {
15643         cmdline_fixed_string_t ptype;
15644         cmdline_fixed_string_t mapping;
15645         cmdline_fixed_string_t reset;
15646         portid_t port_id;
15647         uint8_t hw_ptype;
15648         uint32_t sw_ptype;
15649 };
15650
15651 /* Common CLI fields for ptype mapping update*/
15652 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15653         TOKEN_STRING_INITIALIZER
15654                 (struct cmd_ptype_mapping_update_result,
15655                  ptype, "ptype");
15656 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15657         TOKEN_STRING_INITIALIZER
15658                 (struct cmd_ptype_mapping_update_result,
15659                  mapping, "mapping");
15660 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15661         TOKEN_STRING_INITIALIZER
15662                 (struct cmd_ptype_mapping_update_result,
15663                  reset, "update");
15664 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15665         TOKEN_NUM_INITIALIZER
15666                 (struct cmd_ptype_mapping_update_result,
15667                  port_id, RTE_UINT16);
15668 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15669         TOKEN_NUM_INITIALIZER
15670                 (struct cmd_ptype_mapping_update_result,
15671                  hw_ptype, RTE_UINT8);
15672 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15673         TOKEN_NUM_INITIALIZER
15674                 (struct cmd_ptype_mapping_update_result,
15675                  sw_ptype, RTE_UINT32);
15676
15677 static void
15678 cmd_ptype_mapping_update_parsed(
15679         void *parsed_result,
15680         __rte_unused struct cmdline *cl,
15681         __rte_unused void *data)
15682 {
15683         struct cmd_ptype_mapping_update_result *res = parsed_result;
15684         int ret = -ENOTSUP;
15685 #ifdef RTE_NET_I40E
15686         struct rte_pmd_i40e_ptype_mapping mapping;
15687 #endif
15688         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15689                 return;
15690
15691 #ifdef RTE_NET_I40E
15692         mapping.hw_ptype = res->hw_ptype;
15693         mapping.sw_ptype = res->sw_ptype;
15694         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15695                                                 &mapping,
15696                                                 1,
15697                                                 0);
15698 #endif
15699
15700         switch (ret) {
15701         case 0:
15702                 break;
15703         case -EINVAL:
15704                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15705                 break;
15706         case -ENODEV:
15707                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15708                 break;
15709         case -ENOTSUP:
15710                 fprintf(stderr, "function not implemented\n");
15711                 break;
15712         default:
15713                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15714         }
15715 }
15716
15717 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15718         .f = cmd_ptype_mapping_update_parsed,
15719         .data = NULL,
15720         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15721         .tokens = {
15722                 (void *)&cmd_ptype_mapping_update_ptype,
15723                 (void *)&cmd_ptype_mapping_update_mapping,
15724                 (void *)&cmd_ptype_mapping_update_update,
15725                 (void *)&cmd_ptype_mapping_update_port_id,
15726                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15727                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15728                 NULL,
15729         },
15730 };
15731
15732 /* Common result structure for file commands */
15733 struct cmd_cmdfile_result {
15734         cmdline_fixed_string_t load;
15735         cmdline_fixed_string_t filename;
15736 };
15737
15738 /* Common CLI fields for file commands */
15739 cmdline_parse_token_string_t cmd_load_cmdfile =
15740         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15741 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15742         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15743
15744 static void
15745 cmd_load_from_file_parsed(
15746         void *parsed_result,
15747         __rte_unused struct cmdline *cl,
15748         __rte_unused void *data)
15749 {
15750         struct cmd_cmdfile_result *res = parsed_result;
15751
15752         cmdline_read_from_file(res->filename);
15753 }
15754
15755 cmdline_parse_inst_t cmd_load_from_file = {
15756         .f = cmd_load_from_file_parsed,
15757         .data = NULL,
15758         .help_str = "load <filename>",
15759         .tokens = {
15760                 (void *)&cmd_load_cmdfile,
15761                 (void *)&cmd_load_cmdfile_filename,
15762                 NULL,
15763         },
15764 };
15765
15766 /* Get Rx offloads capabilities */
15767 struct cmd_rx_offload_get_capa_result {
15768         cmdline_fixed_string_t show;
15769         cmdline_fixed_string_t port;
15770         portid_t port_id;
15771         cmdline_fixed_string_t rx_offload;
15772         cmdline_fixed_string_t capabilities;
15773 };
15774
15775 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15776         TOKEN_STRING_INITIALIZER
15777                 (struct cmd_rx_offload_get_capa_result,
15778                  show, "show");
15779 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15780         TOKEN_STRING_INITIALIZER
15781                 (struct cmd_rx_offload_get_capa_result,
15782                  port, "port");
15783 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15784         TOKEN_NUM_INITIALIZER
15785                 (struct cmd_rx_offload_get_capa_result,
15786                  port_id, RTE_UINT16);
15787 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15788         TOKEN_STRING_INITIALIZER
15789                 (struct cmd_rx_offload_get_capa_result,
15790                  rx_offload, "rx_offload");
15791 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15792         TOKEN_STRING_INITIALIZER
15793                 (struct cmd_rx_offload_get_capa_result,
15794                  capabilities, "capabilities");
15795
15796 static void
15797 print_rx_offloads(uint64_t offloads)
15798 {
15799         uint64_t single_offload;
15800         int begin;
15801         int end;
15802         int bit;
15803
15804         if (offloads == 0)
15805                 return;
15806
15807         begin = __builtin_ctzll(offloads);
15808         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15809
15810         single_offload = 1ULL << begin;
15811         for (bit = begin; bit < end; bit++) {
15812                 if (offloads & single_offload)
15813                         printf(" %s",
15814                                rte_eth_dev_rx_offload_name(single_offload));
15815                 single_offload <<= 1;
15816         }
15817 }
15818
15819 static void
15820 cmd_rx_offload_get_capa_parsed(
15821         void *parsed_result,
15822         __rte_unused struct cmdline *cl,
15823         __rte_unused void *data)
15824 {
15825         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15826         struct rte_eth_dev_info dev_info;
15827         portid_t port_id = res->port_id;
15828         uint64_t queue_offloads;
15829         uint64_t port_offloads;
15830         int ret;
15831
15832         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15833         if (ret != 0)
15834                 return;
15835
15836         queue_offloads = dev_info.rx_queue_offload_capa;
15837         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15838
15839         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15840         printf("  Per Queue :");
15841         print_rx_offloads(queue_offloads);
15842
15843         printf("\n");
15844         printf("  Per Port  :");
15845         print_rx_offloads(port_offloads);
15846         printf("\n\n");
15847 }
15848
15849 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15850         .f = cmd_rx_offload_get_capa_parsed,
15851         .data = NULL,
15852         .help_str = "show port <port_id> rx_offload capabilities",
15853         .tokens = {
15854                 (void *)&cmd_rx_offload_get_capa_show,
15855                 (void *)&cmd_rx_offload_get_capa_port,
15856                 (void *)&cmd_rx_offload_get_capa_port_id,
15857                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15858                 (void *)&cmd_rx_offload_get_capa_capabilities,
15859                 NULL,
15860         }
15861 };
15862
15863 /* Get Rx offloads configuration */
15864 struct cmd_rx_offload_get_configuration_result {
15865         cmdline_fixed_string_t show;
15866         cmdline_fixed_string_t port;
15867         portid_t port_id;
15868         cmdline_fixed_string_t rx_offload;
15869         cmdline_fixed_string_t configuration;
15870 };
15871
15872 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15873         TOKEN_STRING_INITIALIZER
15874                 (struct cmd_rx_offload_get_configuration_result,
15875                  show, "show");
15876 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15877         TOKEN_STRING_INITIALIZER
15878                 (struct cmd_rx_offload_get_configuration_result,
15879                  port, "port");
15880 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15881         TOKEN_NUM_INITIALIZER
15882                 (struct cmd_rx_offload_get_configuration_result,
15883                  port_id, RTE_UINT16);
15884 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15885         TOKEN_STRING_INITIALIZER
15886                 (struct cmd_rx_offload_get_configuration_result,
15887                  rx_offload, "rx_offload");
15888 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15889         TOKEN_STRING_INITIALIZER
15890                 (struct cmd_rx_offload_get_configuration_result,
15891                  configuration, "configuration");
15892
15893 static void
15894 cmd_rx_offload_get_configuration_parsed(
15895         void *parsed_result,
15896         __rte_unused struct cmdline *cl,
15897         __rte_unused void *data)
15898 {
15899         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15900         struct rte_eth_dev_info dev_info;
15901         portid_t port_id = res->port_id;
15902         struct rte_port *port = &ports[port_id];
15903         uint64_t port_offloads;
15904         uint64_t queue_offloads;
15905         uint16_t nb_rx_queues;
15906         int q;
15907         int ret;
15908
15909         printf("Rx Offloading Configuration of port %d :\n", port_id);
15910
15911         port_offloads = port->dev_conf.rxmode.offloads;
15912         printf("  Port :");
15913         print_rx_offloads(port_offloads);
15914         printf("\n");
15915
15916         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15917         if (ret != 0)
15918                 return;
15919
15920         nb_rx_queues = dev_info.nb_rx_queues;
15921         for (q = 0; q < nb_rx_queues; q++) {
15922                 queue_offloads = port->rx_conf[q].offloads;
15923                 printf("  Queue[%2d] :", q);
15924                 print_rx_offloads(queue_offloads);
15925                 printf("\n");
15926         }
15927         printf("\n");
15928 }
15929
15930 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15931         .f = cmd_rx_offload_get_configuration_parsed,
15932         .data = NULL,
15933         .help_str = "show port <port_id> rx_offload configuration",
15934         .tokens = {
15935                 (void *)&cmd_rx_offload_get_configuration_show,
15936                 (void *)&cmd_rx_offload_get_configuration_port,
15937                 (void *)&cmd_rx_offload_get_configuration_port_id,
15938                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15939                 (void *)&cmd_rx_offload_get_configuration_configuration,
15940                 NULL,
15941         }
15942 };
15943
15944 /* Enable/Disable a per port offloading */
15945 struct cmd_config_per_port_rx_offload_result {
15946         cmdline_fixed_string_t port;
15947         cmdline_fixed_string_t config;
15948         portid_t port_id;
15949         cmdline_fixed_string_t rx_offload;
15950         cmdline_fixed_string_t offload;
15951         cmdline_fixed_string_t on_off;
15952 };
15953
15954 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15955         TOKEN_STRING_INITIALIZER
15956                 (struct cmd_config_per_port_rx_offload_result,
15957                  port, "port");
15958 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15959         TOKEN_STRING_INITIALIZER
15960                 (struct cmd_config_per_port_rx_offload_result,
15961                  config, "config");
15962 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15963         TOKEN_NUM_INITIALIZER
15964                 (struct cmd_config_per_port_rx_offload_result,
15965                  port_id, RTE_UINT16);
15966 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15967         TOKEN_STRING_INITIALIZER
15968                 (struct cmd_config_per_port_rx_offload_result,
15969                  rx_offload, "rx_offload");
15970 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15971         TOKEN_STRING_INITIALIZER
15972                 (struct cmd_config_per_port_rx_offload_result,
15973                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15974                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15975                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15976                            "scatter#buffer_split#timestamp#security#"
15977                            "keep_crc#rss_hash");
15978 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15979         TOKEN_STRING_INITIALIZER
15980                 (struct cmd_config_per_port_rx_offload_result,
15981                  on_off, "on#off");
15982
15983 static uint64_t
15984 search_rx_offload(const char *name)
15985 {
15986         uint64_t single_offload;
15987         const char *single_name;
15988         int found = 0;
15989         unsigned int bit;
15990
15991         single_offload = 1;
15992         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15993                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15994                 if (!strcasecmp(single_name, name)) {
15995                         found = 1;
15996                         break;
15997                 }
15998                 single_offload <<= 1;
15999         }
16000
16001         if (found)
16002                 return single_offload;
16003
16004         return 0;
16005 }
16006
16007 static void
16008 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16009                                 __rte_unused struct cmdline *cl,
16010                                 __rte_unused void *data)
16011 {
16012         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16013         portid_t port_id = res->port_id;
16014         struct rte_eth_dev_info dev_info;
16015         struct rte_port *port = &ports[port_id];
16016         uint64_t single_offload;
16017         uint16_t nb_rx_queues;
16018         int q;
16019         int ret;
16020
16021         if (port->port_status != RTE_PORT_STOPPED) {
16022                 fprintf(stderr,
16023                         "Error: Can't config offload when Port %d is not stopped\n",
16024                         port_id);
16025                 return;
16026         }
16027
16028         single_offload = search_rx_offload(res->offload);
16029         if (single_offload == 0) {
16030                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16031                 return;
16032         }
16033
16034         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16035         if (ret != 0)
16036                 return;
16037
16038         nb_rx_queues = dev_info.nb_rx_queues;
16039         if (!strcmp(res->on_off, "on")) {
16040                 port->dev_conf.rxmode.offloads |= single_offload;
16041                 for (q = 0; q < nb_rx_queues; q++)
16042                         port->rx_conf[q].offloads |= single_offload;
16043         } else {
16044                 port->dev_conf.rxmode.offloads &= ~single_offload;
16045                 for (q = 0; q < nb_rx_queues; q++)
16046                         port->rx_conf[q].offloads &= ~single_offload;
16047         }
16048
16049         cmd_reconfig_device_queue(port_id, 1, 1);
16050 }
16051
16052 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16053         .f = cmd_config_per_port_rx_offload_parsed,
16054         .data = NULL,
16055         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16056                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16057                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16058                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16059                     "keep_crc|rss_hash on|off",
16060         .tokens = {
16061                 (void *)&cmd_config_per_port_rx_offload_result_port,
16062                 (void *)&cmd_config_per_port_rx_offload_result_config,
16063                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16064                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16065                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16066                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16067                 NULL,
16068         }
16069 };
16070
16071 /* Enable/Disable a per queue offloading */
16072 struct cmd_config_per_queue_rx_offload_result {
16073         cmdline_fixed_string_t port;
16074         portid_t port_id;
16075         cmdline_fixed_string_t rxq;
16076         uint16_t queue_id;
16077         cmdline_fixed_string_t rx_offload;
16078         cmdline_fixed_string_t offload;
16079         cmdline_fixed_string_t on_off;
16080 };
16081
16082 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16083         TOKEN_STRING_INITIALIZER
16084                 (struct cmd_config_per_queue_rx_offload_result,
16085                  port, "port");
16086 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16087         TOKEN_NUM_INITIALIZER
16088                 (struct cmd_config_per_queue_rx_offload_result,
16089                  port_id, RTE_UINT16);
16090 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16091         TOKEN_STRING_INITIALIZER
16092                 (struct cmd_config_per_queue_rx_offload_result,
16093                  rxq, "rxq");
16094 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16095         TOKEN_NUM_INITIALIZER
16096                 (struct cmd_config_per_queue_rx_offload_result,
16097                  queue_id, RTE_UINT16);
16098 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16099         TOKEN_STRING_INITIALIZER
16100                 (struct cmd_config_per_queue_rx_offload_result,
16101                  rx_offload, "rx_offload");
16102 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16103         TOKEN_STRING_INITIALIZER
16104                 (struct cmd_config_per_queue_rx_offload_result,
16105                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16106                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16107                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16108                            "scatter#buffer_split#timestamp#security#keep_crc");
16109 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16110         TOKEN_STRING_INITIALIZER
16111                 (struct cmd_config_per_queue_rx_offload_result,
16112                  on_off, "on#off");
16113
16114 static void
16115 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16116                                 __rte_unused struct cmdline *cl,
16117                                 __rte_unused void *data)
16118 {
16119         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16120         struct rte_eth_dev_info dev_info;
16121         portid_t port_id = res->port_id;
16122         uint16_t queue_id = res->queue_id;
16123         struct rte_port *port = &ports[port_id];
16124         uint64_t single_offload;
16125         int ret;
16126
16127         if (port->port_status != RTE_PORT_STOPPED) {
16128                 fprintf(stderr,
16129                         "Error: Can't config offload when Port %d is not stopped\n",
16130                         port_id);
16131                 return;
16132         }
16133
16134         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16135         if (ret != 0)
16136                 return;
16137
16138         if (queue_id >= dev_info.nb_rx_queues) {
16139                 fprintf(stderr,
16140                         "Error: input queue_id should be 0 ... %d\n",
16141                         dev_info.nb_rx_queues - 1);
16142                 return;
16143         }
16144
16145         single_offload = search_rx_offload(res->offload);
16146         if (single_offload == 0) {
16147                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16148                 return;
16149         }
16150
16151         if (!strcmp(res->on_off, "on"))
16152                 port->rx_conf[queue_id].offloads |= single_offload;
16153         else
16154                 port->rx_conf[queue_id].offloads &= ~single_offload;
16155
16156         cmd_reconfig_device_queue(port_id, 1, 1);
16157 }
16158
16159 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16160         .f = cmd_config_per_queue_rx_offload_parsed,
16161         .data = NULL,
16162         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16163                     "vlan_strip|ipv4_cksum|"
16164                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16165                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16166                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16167                     "keep_crc on|off",
16168         .tokens = {
16169                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16170                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16171                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16172                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16173                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16174                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16175                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16176                 NULL,
16177         }
16178 };
16179
16180 /* Get Tx offloads capabilities */
16181 struct cmd_tx_offload_get_capa_result {
16182         cmdline_fixed_string_t show;
16183         cmdline_fixed_string_t port;
16184         portid_t port_id;
16185         cmdline_fixed_string_t tx_offload;
16186         cmdline_fixed_string_t capabilities;
16187 };
16188
16189 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16190         TOKEN_STRING_INITIALIZER
16191                 (struct cmd_tx_offload_get_capa_result,
16192                  show, "show");
16193 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16194         TOKEN_STRING_INITIALIZER
16195                 (struct cmd_tx_offload_get_capa_result,
16196                  port, "port");
16197 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16198         TOKEN_NUM_INITIALIZER
16199                 (struct cmd_tx_offload_get_capa_result,
16200                  port_id, RTE_UINT16);
16201 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16202         TOKEN_STRING_INITIALIZER
16203                 (struct cmd_tx_offload_get_capa_result,
16204                  tx_offload, "tx_offload");
16205 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16206         TOKEN_STRING_INITIALIZER
16207                 (struct cmd_tx_offload_get_capa_result,
16208                  capabilities, "capabilities");
16209
16210 static void
16211 print_tx_offloads(uint64_t offloads)
16212 {
16213         uint64_t single_offload;
16214         int begin;
16215         int end;
16216         int bit;
16217
16218         if (offloads == 0)
16219                 return;
16220
16221         begin = __builtin_ctzll(offloads);
16222         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16223
16224         single_offload = 1ULL << begin;
16225         for (bit = begin; bit < end; bit++) {
16226                 if (offloads & single_offload)
16227                         printf(" %s",
16228                                rte_eth_dev_tx_offload_name(single_offload));
16229                 single_offload <<= 1;
16230         }
16231 }
16232
16233 static void
16234 cmd_tx_offload_get_capa_parsed(
16235         void *parsed_result,
16236         __rte_unused struct cmdline *cl,
16237         __rte_unused void *data)
16238 {
16239         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16240         struct rte_eth_dev_info dev_info;
16241         portid_t port_id = res->port_id;
16242         uint64_t queue_offloads;
16243         uint64_t port_offloads;
16244         int ret;
16245
16246         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16247         if (ret != 0)
16248                 return;
16249
16250         queue_offloads = dev_info.tx_queue_offload_capa;
16251         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16252
16253         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16254         printf("  Per Queue :");
16255         print_tx_offloads(queue_offloads);
16256
16257         printf("\n");
16258         printf("  Per Port  :");
16259         print_tx_offloads(port_offloads);
16260         printf("\n\n");
16261 }
16262
16263 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16264         .f = cmd_tx_offload_get_capa_parsed,
16265         .data = NULL,
16266         .help_str = "show port <port_id> tx_offload capabilities",
16267         .tokens = {
16268                 (void *)&cmd_tx_offload_get_capa_show,
16269                 (void *)&cmd_tx_offload_get_capa_port,
16270                 (void *)&cmd_tx_offload_get_capa_port_id,
16271                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16272                 (void *)&cmd_tx_offload_get_capa_capabilities,
16273                 NULL,
16274         }
16275 };
16276
16277 /* Get Tx offloads configuration */
16278 struct cmd_tx_offload_get_configuration_result {
16279         cmdline_fixed_string_t show;
16280         cmdline_fixed_string_t port;
16281         portid_t port_id;
16282         cmdline_fixed_string_t tx_offload;
16283         cmdline_fixed_string_t configuration;
16284 };
16285
16286 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16287         TOKEN_STRING_INITIALIZER
16288                 (struct cmd_tx_offload_get_configuration_result,
16289                  show, "show");
16290 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16291         TOKEN_STRING_INITIALIZER
16292                 (struct cmd_tx_offload_get_configuration_result,
16293                  port, "port");
16294 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16295         TOKEN_NUM_INITIALIZER
16296                 (struct cmd_tx_offload_get_configuration_result,
16297                  port_id, RTE_UINT16);
16298 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16299         TOKEN_STRING_INITIALIZER
16300                 (struct cmd_tx_offload_get_configuration_result,
16301                  tx_offload, "tx_offload");
16302 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16303         TOKEN_STRING_INITIALIZER
16304                 (struct cmd_tx_offload_get_configuration_result,
16305                  configuration, "configuration");
16306
16307 static void
16308 cmd_tx_offload_get_configuration_parsed(
16309         void *parsed_result,
16310         __rte_unused struct cmdline *cl,
16311         __rte_unused void *data)
16312 {
16313         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16314         struct rte_eth_dev_info dev_info;
16315         portid_t port_id = res->port_id;
16316         struct rte_port *port = &ports[port_id];
16317         uint64_t port_offloads;
16318         uint64_t queue_offloads;
16319         uint16_t nb_tx_queues;
16320         int q;
16321         int ret;
16322
16323         printf("Tx Offloading Configuration of port %d :\n", port_id);
16324
16325         port_offloads = port->dev_conf.txmode.offloads;
16326         printf("  Port :");
16327         print_tx_offloads(port_offloads);
16328         printf("\n");
16329
16330         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16331         if (ret != 0)
16332                 return;
16333
16334         nb_tx_queues = dev_info.nb_tx_queues;
16335         for (q = 0; q < nb_tx_queues; q++) {
16336                 queue_offloads = port->tx_conf[q].offloads;
16337                 printf("  Queue[%2d] :", q);
16338                 print_tx_offloads(queue_offloads);
16339                 printf("\n");
16340         }
16341         printf("\n");
16342 }
16343
16344 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16345         .f = cmd_tx_offload_get_configuration_parsed,
16346         .data = NULL,
16347         .help_str = "show port <port_id> tx_offload configuration",
16348         .tokens = {
16349                 (void *)&cmd_tx_offload_get_configuration_show,
16350                 (void *)&cmd_tx_offload_get_configuration_port,
16351                 (void *)&cmd_tx_offload_get_configuration_port_id,
16352                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16353                 (void *)&cmd_tx_offload_get_configuration_configuration,
16354                 NULL,
16355         }
16356 };
16357
16358 /* Enable/Disable a per port offloading */
16359 struct cmd_config_per_port_tx_offload_result {
16360         cmdline_fixed_string_t port;
16361         cmdline_fixed_string_t config;
16362         portid_t port_id;
16363         cmdline_fixed_string_t tx_offload;
16364         cmdline_fixed_string_t offload;
16365         cmdline_fixed_string_t on_off;
16366 };
16367
16368 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16369         TOKEN_STRING_INITIALIZER
16370                 (struct cmd_config_per_port_tx_offload_result,
16371                  port, "port");
16372 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16373         TOKEN_STRING_INITIALIZER
16374                 (struct cmd_config_per_port_tx_offload_result,
16375                  config, "config");
16376 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16377         TOKEN_NUM_INITIALIZER
16378                 (struct cmd_config_per_port_tx_offload_result,
16379                  port_id, RTE_UINT16);
16380 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16381         TOKEN_STRING_INITIALIZER
16382                 (struct cmd_config_per_port_tx_offload_result,
16383                  tx_offload, "tx_offload");
16384 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16385         TOKEN_STRING_INITIALIZER
16386                 (struct cmd_config_per_port_tx_offload_result,
16387                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16388                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16389                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16390                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16391                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16392                           "send_on_timestamp");
16393 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16394         TOKEN_STRING_INITIALIZER
16395                 (struct cmd_config_per_port_tx_offload_result,
16396                  on_off, "on#off");
16397
16398 static uint64_t
16399 search_tx_offload(const char *name)
16400 {
16401         uint64_t single_offload;
16402         const char *single_name;
16403         int found = 0;
16404         unsigned int bit;
16405
16406         single_offload = 1;
16407         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16408                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16409                 if (single_name == NULL)
16410                         break;
16411                 if (!strcasecmp(single_name, name)) {
16412                         found = 1;
16413                         break;
16414                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16415                         break;
16416                 single_offload <<= 1;
16417         }
16418
16419         if (found)
16420                 return single_offload;
16421
16422         return 0;
16423 }
16424
16425 static void
16426 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16427                                 __rte_unused struct cmdline *cl,
16428                                 __rte_unused void *data)
16429 {
16430         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16431         portid_t port_id = res->port_id;
16432         struct rte_eth_dev_info dev_info;
16433         struct rte_port *port = &ports[port_id];
16434         uint64_t single_offload;
16435         uint16_t nb_tx_queues;
16436         int q;
16437         int ret;
16438
16439         if (port->port_status != RTE_PORT_STOPPED) {
16440                 fprintf(stderr,
16441                         "Error: Can't config offload when Port %d is not stopped\n",
16442                         port_id);
16443                 return;
16444         }
16445
16446         single_offload = search_tx_offload(res->offload);
16447         if (single_offload == 0) {
16448                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16449                 return;
16450         }
16451
16452         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16453         if (ret != 0)
16454                 return;
16455
16456         nb_tx_queues = dev_info.nb_tx_queues;
16457         if (!strcmp(res->on_off, "on")) {
16458                 port->dev_conf.txmode.offloads |= single_offload;
16459                 for (q = 0; q < nb_tx_queues; q++)
16460                         port->tx_conf[q].offloads |= single_offload;
16461         } else {
16462                 port->dev_conf.txmode.offloads &= ~single_offload;
16463                 for (q = 0; q < nb_tx_queues; q++)
16464                         port->tx_conf[q].offloads &= ~single_offload;
16465         }
16466
16467         cmd_reconfig_device_queue(port_id, 1, 1);
16468 }
16469
16470 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16471         .f = cmd_config_per_port_tx_offload_parsed,
16472         .data = NULL,
16473         .help_str = "port config <port_id> tx_offload "
16474                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16475                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16476                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16477                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16478                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16479                     "send_on_timestamp on|off",
16480         .tokens = {
16481                 (void *)&cmd_config_per_port_tx_offload_result_port,
16482                 (void *)&cmd_config_per_port_tx_offload_result_config,
16483                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16484                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16485                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16486                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16487                 NULL,
16488         }
16489 };
16490
16491 /* Enable/Disable a per queue offloading */
16492 struct cmd_config_per_queue_tx_offload_result {
16493         cmdline_fixed_string_t port;
16494         portid_t port_id;
16495         cmdline_fixed_string_t txq;
16496         uint16_t queue_id;
16497         cmdline_fixed_string_t tx_offload;
16498         cmdline_fixed_string_t offload;
16499         cmdline_fixed_string_t on_off;
16500 };
16501
16502 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16503         TOKEN_STRING_INITIALIZER
16504                 (struct cmd_config_per_queue_tx_offload_result,
16505                  port, "port");
16506 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16507         TOKEN_NUM_INITIALIZER
16508                 (struct cmd_config_per_queue_tx_offload_result,
16509                  port_id, RTE_UINT16);
16510 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16511         TOKEN_STRING_INITIALIZER
16512                 (struct cmd_config_per_queue_tx_offload_result,
16513                  txq, "txq");
16514 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16515         TOKEN_NUM_INITIALIZER
16516                 (struct cmd_config_per_queue_tx_offload_result,
16517                  queue_id, RTE_UINT16);
16518 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16519         TOKEN_STRING_INITIALIZER
16520                 (struct cmd_config_per_queue_tx_offload_result,
16521                  tx_offload, "tx_offload");
16522 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16523         TOKEN_STRING_INITIALIZER
16524                 (struct cmd_config_per_queue_tx_offload_result,
16525                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16526                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16527                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16528                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16529                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16530 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16531         TOKEN_STRING_INITIALIZER
16532                 (struct cmd_config_per_queue_tx_offload_result,
16533                  on_off, "on#off");
16534
16535 static void
16536 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16537                                 __rte_unused struct cmdline *cl,
16538                                 __rte_unused void *data)
16539 {
16540         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16541         struct rte_eth_dev_info dev_info;
16542         portid_t port_id = res->port_id;
16543         uint16_t queue_id = res->queue_id;
16544         struct rte_port *port = &ports[port_id];
16545         uint64_t single_offload;
16546         int ret;
16547
16548         if (port->port_status != RTE_PORT_STOPPED) {
16549                 fprintf(stderr,
16550                         "Error: Can't config offload when Port %d is not stopped\n",
16551                         port_id);
16552                 return;
16553         }
16554
16555         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16556         if (ret != 0)
16557                 return;
16558
16559         if (queue_id >= dev_info.nb_tx_queues) {
16560                 fprintf(stderr,
16561                         "Error: input queue_id should be 0 ... %d\n",
16562                         dev_info.nb_tx_queues - 1);
16563                 return;
16564         }
16565
16566         single_offload = search_tx_offload(res->offload);
16567         if (single_offload == 0) {
16568                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16569                 return;
16570         }
16571
16572         if (!strcmp(res->on_off, "on"))
16573                 port->tx_conf[queue_id].offloads |= single_offload;
16574         else
16575                 port->tx_conf[queue_id].offloads &= ~single_offload;
16576
16577         cmd_reconfig_device_queue(port_id, 1, 1);
16578 }
16579
16580 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16581         .f = cmd_config_per_queue_tx_offload_parsed,
16582         .data = NULL,
16583         .help_str = "port <port_id> txq <queue_id> tx_offload "
16584                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16585                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16586                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16587                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16588                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16589                     "on|off",
16590         .tokens = {
16591                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16592                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16593                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16594                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16595                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16596                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16597                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16598                 NULL,
16599         }
16600 };
16601
16602 /* *** configure tx_metadata for specific port *** */
16603 struct cmd_config_tx_metadata_specific_result {
16604         cmdline_fixed_string_t port;
16605         cmdline_fixed_string_t keyword;
16606         uint16_t port_id;
16607         cmdline_fixed_string_t item;
16608         uint32_t value;
16609 };
16610
16611 static void
16612 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16613                                 __rte_unused struct cmdline *cl,
16614                                 __rte_unused void *data)
16615 {
16616         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16617
16618         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16619                 return;
16620         ports[res->port_id].tx_metadata = res->value;
16621         /* Add/remove callback to insert valid metadata in every Tx packet. */
16622         if (ports[res->port_id].tx_metadata)
16623                 add_tx_md_callback(res->port_id);
16624         else
16625                 remove_tx_md_callback(res->port_id);
16626         rte_flow_dynf_metadata_register();
16627 }
16628
16629 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16630         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16631                         port, "port");
16632 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16633         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16634                         keyword, "config");
16635 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16636         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16637                         port_id, RTE_UINT16);
16638 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16639         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16640                         item, "tx_metadata");
16641 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16642         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16643                         value, RTE_UINT32);
16644
16645 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16646         .f = cmd_config_tx_metadata_specific_parsed,
16647         .data = NULL,
16648         .help_str = "port config <port_id> tx_metadata <value>",
16649         .tokens = {
16650                 (void *)&cmd_config_tx_metadata_specific_port,
16651                 (void *)&cmd_config_tx_metadata_specific_keyword,
16652                 (void *)&cmd_config_tx_metadata_specific_id,
16653                 (void *)&cmd_config_tx_metadata_specific_item,
16654                 (void *)&cmd_config_tx_metadata_specific_value,
16655                 NULL,
16656         },
16657 };
16658
16659 /* *** set dynf *** */
16660 struct cmd_config_tx_dynf_specific_result {
16661         cmdline_fixed_string_t port;
16662         cmdline_fixed_string_t keyword;
16663         uint16_t port_id;
16664         cmdline_fixed_string_t item;
16665         cmdline_fixed_string_t name;
16666         cmdline_fixed_string_t value;
16667 };
16668
16669 static void
16670 cmd_config_dynf_specific_parsed(void *parsed_result,
16671                                 __rte_unused struct cmdline *cl,
16672                                 __rte_unused void *data)
16673 {
16674         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16675         struct rte_mbuf_dynflag desc_flag;
16676         int flag;
16677         uint64_t old_port_flags;
16678
16679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16680                 return;
16681         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16682         if (flag <= 0) {
16683                 if (strlcpy(desc_flag.name, res->name,
16684                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16685                         fprintf(stderr, "Flag name too long\n");
16686                         return;
16687                 }
16688                 desc_flag.flags = 0;
16689                 flag = rte_mbuf_dynflag_register(&desc_flag);
16690                 if (flag < 0) {
16691                         fprintf(stderr, "Can't register flag\n");
16692                         return;
16693                 }
16694                 strcpy(dynf_names[flag], desc_flag.name);
16695         }
16696         old_port_flags = ports[res->port_id].mbuf_dynf;
16697         if (!strcmp(res->value, "set")) {
16698                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16699                 if (old_port_flags == 0)
16700                         add_tx_dynf_callback(res->port_id);
16701         } else {
16702                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16703                 if (ports[res->port_id].mbuf_dynf == 0)
16704                         remove_tx_dynf_callback(res->port_id);
16705         }
16706 }
16707
16708 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16709         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16710                         keyword, "port");
16711 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16712         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16713                         keyword, "config");
16714 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16715         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16716                         port_id, RTE_UINT16);
16717 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16718         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16719                         item, "dynf");
16720 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16721         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16722                         name, NULL);
16723 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16724         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16725                         value, "set#clear");
16726
16727 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16728         .f = cmd_config_dynf_specific_parsed,
16729         .data = NULL,
16730         .help_str = "port config <port id> dynf <name> set|clear",
16731         .tokens = {
16732                 (void *)&cmd_config_tx_dynf_specific_port,
16733                 (void *)&cmd_config_tx_dynf_specific_keyword,
16734                 (void *)&cmd_config_tx_dynf_specific_port_id,
16735                 (void *)&cmd_config_tx_dynf_specific_item,
16736                 (void *)&cmd_config_tx_dynf_specific_name,
16737                 (void *)&cmd_config_tx_dynf_specific_value,
16738                 NULL,
16739         },
16740 };
16741
16742 /* *** display tx_metadata per port configuration *** */
16743 struct cmd_show_tx_metadata_result {
16744         cmdline_fixed_string_t cmd_show;
16745         cmdline_fixed_string_t cmd_port;
16746         cmdline_fixed_string_t cmd_keyword;
16747         portid_t cmd_pid;
16748 };
16749
16750 static void
16751 cmd_show_tx_metadata_parsed(void *parsed_result,
16752                 __rte_unused struct cmdline *cl,
16753                 __rte_unused void *data)
16754 {
16755         struct cmd_show_tx_metadata_result *res = parsed_result;
16756
16757         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16758                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
16759                 return;
16760         }
16761         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16762                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16763                        ports[res->cmd_pid].tx_metadata);
16764         }
16765 }
16766
16767 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16768         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16769                         cmd_show, "show");
16770 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16771         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16772                         cmd_port, "port");
16773 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16774         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16775                         cmd_pid, RTE_UINT16);
16776 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16777         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16778                         cmd_keyword, "tx_metadata");
16779
16780 cmdline_parse_inst_t cmd_show_tx_metadata = {
16781         .f = cmd_show_tx_metadata_parsed,
16782         .data = NULL,
16783         .help_str = "show port <port_id> tx_metadata",
16784         .tokens = {
16785                 (void *)&cmd_show_tx_metadata_show,
16786                 (void *)&cmd_show_tx_metadata_port,
16787                 (void *)&cmd_show_tx_metadata_pid,
16788                 (void *)&cmd_show_tx_metadata_keyword,
16789                 NULL,
16790         },
16791 };
16792
16793 /* *** show fec capability per port configuration *** */
16794 struct cmd_show_fec_capability_result {
16795         cmdline_fixed_string_t cmd_show;
16796         cmdline_fixed_string_t cmd_port;
16797         cmdline_fixed_string_t cmd_fec;
16798         cmdline_fixed_string_t cmd_keyword;
16799         portid_t cmd_pid;
16800 };
16801
16802 static void
16803 cmd_show_fec_capability_parsed(void *parsed_result,
16804                 __rte_unused struct cmdline *cl,
16805                 __rte_unused void *data)
16806 {
16807         struct cmd_show_fec_capability_result *res = parsed_result;
16808         struct rte_eth_fec_capa *speed_fec_capa;
16809         unsigned int num;
16810         int ret;
16811
16812         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16813                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16814                 return;
16815         }
16816
16817         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16818         if (ret == -ENOTSUP) {
16819                 fprintf(stderr, "Function not implemented\n");
16820                 return;
16821         } else if (ret < 0) {
16822                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
16823                 return;
16824         }
16825
16826         num = (unsigned int)ret;
16827         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16828         if (speed_fec_capa == NULL) {
16829                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
16830                 return;
16831         }
16832
16833         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16834         if (ret < 0) {
16835                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
16836                 goto out;
16837         }
16838
16839         show_fec_capability(num, speed_fec_capa);
16840 out:
16841         free(speed_fec_capa);
16842 }
16843
16844 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16845         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16846                         cmd_show, "show");
16847 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16848         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16849                         cmd_port, "port");
16850 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16851         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16852                         cmd_pid, RTE_UINT16);
16853 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16854         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16855                         cmd_fec, "fec");
16856 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16857         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16858                         cmd_keyword, "capabilities");
16859
16860 cmdline_parse_inst_t cmd_show_capability = {
16861         .f = cmd_show_fec_capability_parsed,
16862         .data = NULL,
16863         .help_str = "show port <port_id> fec capabilities",
16864         .tokens = {
16865                 (void *)&cmd_show_fec_capability_show,
16866                 (void *)&cmd_show_fec_capability_port,
16867                 (void *)&cmd_show_fec_capability_pid,
16868                 (void *)&cmd_show_fec_capability_fec,
16869                 (void *)&cmd_show_fec_capability_keyword,
16870                 NULL,
16871         },
16872 };
16873
16874 /* *** show fec mode per port configuration *** */
16875 struct cmd_show_fec_metadata_result {
16876         cmdline_fixed_string_t cmd_show;
16877         cmdline_fixed_string_t cmd_port;
16878         cmdline_fixed_string_t cmd_keyword;
16879         portid_t cmd_pid;
16880 };
16881
16882 static void
16883 cmd_show_fec_mode_parsed(void *parsed_result,
16884                 __rte_unused struct cmdline *cl,
16885                 __rte_unused void *data)
16886 {
16887 #define FEC_NAME_SIZE 16
16888         struct cmd_show_fec_metadata_result *res = parsed_result;
16889         uint32_t mode;
16890         char buf[FEC_NAME_SIZE];
16891         int ret;
16892
16893         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16894                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16895                 return;
16896         }
16897         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16898         if (ret == -ENOTSUP) {
16899                 fprintf(stderr, "Function not implemented\n");
16900                 return;
16901         } else if (ret < 0) {
16902                 fprintf(stderr, "Get FEC mode failed\n");
16903                 return;
16904         }
16905
16906         switch (mode) {
16907         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16908                 strlcpy(buf, "off", sizeof(buf));
16909                 break;
16910         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16911                 strlcpy(buf, "auto", sizeof(buf));
16912                 break;
16913         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16914                 strlcpy(buf, "baser", sizeof(buf));
16915                 break;
16916         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16917                 strlcpy(buf, "rs", sizeof(buf));
16918                 break;
16919         default:
16920                 return;
16921         }
16922
16923         printf("%s\n", buf);
16924 }
16925
16926 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16927         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16928                         cmd_show, "show");
16929 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16930         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16931                         cmd_port, "port");
16932 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16933         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16934                         cmd_pid, RTE_UINT16);
16935 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16936         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16937                         cmd_keyword, "fec_mode");
16938
16939 cmdline_parse_inst_t cmd_show_fec_mode = {
16940         .f = cmd_show_fec_mode_parsed,
16941         .data = NULL,
16942         .help_str = "show port <port_id> fec_mode",
16943         .tokens = {
16944                 (void *)&cmd_show_fec_mode_show,
16945                 (void *)&cmd_show_fec_mode_port,
16946                 (void *)&cmd_show_fec_mode_pid,
16947                 (void *)&cmd_show_fec_mode_keyword,
16948                 NULL,
16949         },
16950 };
16951
16952 /* *** set fec mode per port configuration *** */
16953 struct cmd_set_port_fec_mode {
16954         cmdline_fixed_string_t set;
16955         cmdline_fixed_string_t port;
16956         portid_t port_id;
16957         cmdline_fixed_string_t fec_mode;
16958         cmdline_fixed_string_t fec_value;
16959 };
16960
16961 /* Common CLI fields for set fec mode */
16962 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16963         TOKEN_STRING_INITIALIZER
16964                 (struct cmd_set_port_fec_mode,
16965                  set, "set");
16966 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16967         TOKEN_STRING_INITIALIZER
16968                 (struct cmd_set_port_fec_mode,
16969                  port, "port");
16970 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16971         TOKEN_NUM_INITIALIZER
16972                 (struct cmd_set_port_fec_mode,
16973                  port_id, RTE_UINT16);
16974 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16975         TOKEN_STRING_INITIALIZER
16976                 (struct cmd_set_port_fec_mode,
16977                  fec_mode, "fec_mode");
16978 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16979         TOKEN_STRING_INITIALIZER
16980                 (struct cmd_set_port_fec_mode,
16981                  fec_value, NULL);
16982
16983 static void
16984 cmd_set_port_fec_mode_parsed(
16985         void *parsed_result,
16986         __rte_unused struct cmdline *cl,
16987         __rte_unused void *data)
16988 {
16989         struct cmd_set_port_fec_mode *res = parsed_result;
16990         uint16_t port_id = res->port_id;
16991         uint32_t fec_capa;
16992         int ret;
16993
16994         ret = parse_fec_mode(res->fec_value, &fec_capa);
16995         if (ret < 0) {
16996                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
16997                                 res->fec_value, port_id);
16998                 return;
16999         }
17000
17001         ret = rte_eth_fec_set(port_id, fec_capa);
17002         if (ret == -ENOTSUP) {
17003                 fprintf(stderr, "Function not implemented\n");
17004                 return;
17005         } else if (ret < 0) {
17006                 fprintf(stderr, "Set FEC mode failed\n");
17007                 return;
17008         }
17009 }
17010
17011 cmdline_parse_inst_t cmd_set_fec_mode = {
17012         .f = cmd_set_port_fec_mode_parsed,
17013         .data = NULL,
17014         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17015         .tokens = {
17016                 (void *)&cmd_set_port_fec_mode_set,
17017                 (void *)&cmd_set_port_fec_mode_port,
17018                 (void *)&cmd_set_port_fec_mode_port_id,
17019                 (void *)&cmd_set_port_fec_mode_str,
17020                 (void *)&cmd_set_port_fec_mode_value,
17021                 NULL,
17022         },
17023 };
17024
17025 /* show port supported ptypes */
17026
17027 /* Common result structure for show port ptypes */
17028 struct cmd_show_port_supported_ptypes_result {
17029         cmdline_fixed_string_t show;
17030         cmdline_fixed_string_t port;
17031         portid_t port_id;
17032         cmdline_fixed_string_t ptypes;
17033 };
17034
17035 /* Common CLI fields for show port ptypes */
17036 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17037         TOKEN_STRING_INITIALIZER
17038                 (struct cmd_show_port_supported_ptypes_result,
17039                  show, "show");
17040 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17041         TOKEN_STRING_INITIALIZER
17042                 (struct cmd_show_port_supported_ptypes_result,
17043                  port, "port");
17044 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17045         TOKEN_NUM_INITIALIZER
17046                 (struct cmd_show_port_supported_ptypes_result,
17047                  port_id, RTE_UINT16);
17048 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17049         TOKEN_STRING_INITIALIZER
17050                 (struct cmd_show_port_supported_ptypes_result,
17051                  ptypes, "ptypes");
17052
17053 static void
17054 cmd_show_port_supported_ptypes_parsed(
17055         void *parsed_result,
17056         __rte_unused struct cmdline *cl,
17057         __rte_unused void *data)
17058 {
17059 #define RSVD_PTYPE_MASK       0xf0000000
17060 #define MAX_PTYPES_PER_LAYER  16
17061 #define LTYPE_NAMESIZE        32
17062 #define PTYPE_NAMESIZE        256
17063         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17064         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17065         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17066         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17067         uint16_t port_id = res->port_id;
17068         int ret, i;
17069
17070         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17071         if (ret < 0)
17072                 return;
17073
17074         while (ptype_mask != RSVD_PTYPE_MASK) {
17075
17076                 switch (ptype_mask) {
17077                 case RTE_PTYPE_L2_MASK:
17078                         strlcpy(ltype, "L2", sizeof(ltype));
17079                         break;
17080                 case RTE_PTYPE_L3_MASK:
17081                         strlcpy(ltype, "L3", sizeof(ltype));
17082                         break;
17083                 case RTE_PTYPE_L4_MASK:
17084                         strlcpy(ltype, "L4", sizeof(ltype));
17085                         break;
17086                 case RTE_PTYPE_TUNNEL_MASK:
17087                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17088                         break;
17089                 case RTE_PTYPE_INNER_L2_MASK:
17090                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17091                         break;
17092                 case RTE_PTYPE_INNER_L3_MASK:
17093                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17094                         break;
17095                 case RTE_PTYPE_INNER_L4_MASK:
17096                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17097                         break;
17098                 default:
17099                         return;
17100                 }
17101
17102                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17103                                                        ptype_mask, ptypes,
17104                                                        MAX_PTYPES_PER_LAYER);
17105
17106                 if (ret > 0)
17107                         printf("Supported %s ptypes:\n", ltype);
17108                 else
17109                         printf("%s ptypes unsupported\n", ltype);
17110
17111                 for (i = 0; i < ret; ++i) {
17112                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17113                         printf("%s\n", buf);
17114                 }
17115
17116                 ptype_mask <<= 4;
17117         }
17118 }
17119
17120 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17121         .f = cmd_show_port_supported_ptypes_parsed,
17122         .data = NULL,
17123         .help_str = "show port <port_id> ptypes",
17124         .tokens = {
17125                 (void *)&cmd_show_port_supported_ptypes_show,
17126                 (void *)&cmd_show_port_supported_ptypes_port,
17127                 (void *)&cmd_show_port_supported_ptypes_port_id,
17128                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17129                 NULL,
17130         },
17131 };
17132
17133 /* *** display rx/tx descriptor status *** */
17134 struct cmd_show_rx_tx_desc_status_result {
17135         cmdline_fixed_string_t cmd_show;
17136         cmdline_fixed_string_t cmd_port;
17137         cmdline_fixed_string_t cmd_keyword;
17138         cmdline_fixed_string_t cmd_desc;
17139         cmdline_fixed_string_t cmd_status;
17140         portid_t cmd_pid;
17141         portid_t cmd_qid;
17142         portid_t cmd_did;
17143 };
17144
17145 static void
17146 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17147                 __rte_unused struct cmdline *cl,
17148                 __rte_unused void *data)
17149 {
17150         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17151         int rc;
17152
17153         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17154                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17155                 return;
17156         }
17157
17158         if (!strcmp(res->cmd_keyword, "rxq")) {
17159                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17160                                              res->cmd_did);
17161                 if (rc < 0) {
17162                         fprintf(stderr,
17163                                 "Invalid input: queue id = %d, desc id = %d\n",
17164                                 res->cmd_qid, res->cmd_did);
17165                         return;
17166                 }
17167                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17168                         printf("Desc status = AVAILABLE\n");
17169                 else if (rc == RTE_ETH_RX_DESC_DONE)
17170                         printf("Desc status = DONE\n");
17171                 else
17172                         printf("Desc status = UNAVAILABLE\n");
17173         } else if (!strcmp(res->cmd_keyword, "txq")) {
17174                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17175                                              res->cmd_did);
17176                 if (rc < 0) {
17177                         fprintf(stderr,
17178                                 "Invalid input: queue id = %d, desc id = %d\n",
17179                                 res->cmd_qid, res->cmd_did);
17180                         return;
17181                 }
17182                 if (rc == RTE_ETH_TX_DESC_FULL)
17183                         printf("Desc status = FULL\n");
17184                 else if (rc == RTE_ETH_TX_DESC_DONE)
17185                         printf("Desc status = DONE\n");
17186                 else
17187                         printf("Desc status = UNAVAILABLE\n");
17188         }
17189 }
17190
17191 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17192         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17193                         cmd_show, "show");
17194 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17195         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17196                         cmd_port, "port");
17197 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17198         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17199                         cmd_pid, RTE_UINT16);
17200 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17201         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17202                         cmd_keyword, "rxq#txq");
17203 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17204         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17205                         cmd_qid, RTE_UINT16);
17206 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17207         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17208                         cmd_desc, "desc");
17209 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17210         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17211                         cmd_did, RTE_UINT16);
17212 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17213         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17214                         cmd_status, "status");
17215 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17216         .f = cmd_show_rx_tx_desc_status_parsed,
17217         .data = NULL,
17218         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17219                 "status",
17220         .tokens = {
17221                 (void *)&cmd_show_rx_tx_desc_status_show,
17222                 (void *)&cmd_show_rx_tx_desc_status_port,
17223                 (void *)&cmd_show_rx_tx_desc_status_pid,
17224                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17225                 (void *)&cmd_show_rx_tx_desc_status_qid,
17226                 (void *)&cmd_show_rx_tx_desc_status_desc,
17227                 (void *)&cmd_show_rx_tx_desc_status_did,
17228                 (void *)&cmd_show_rx_tx_desc_status_status,
17229                 NULL,
17230         },
17231 };
17232
17233 /* *** display rx queue desc used count *** */
17234 struct cmd_show_rx_queue_desc_used_count_result {
17235         cmdline_fixed_string_t cmd_show;
17236         cmdline_fixed_string_t cmd_port;
17237         cmdline_fixed_string_t cmd_rxq;
17238         cmdline_fixed_string_t cmd_desc;
17239         cmdline_fixed_string_t cmd_used;
17240         cmdline_fixed_string_t cmd_count;
17241         portid_t cmd_pid;
17242         portid_t cmd_qid;
17243 };
17244
17245 static void
17246 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17247                 __rte_unused struct cmdline *cl,
17248                 __rte_unused void *data)
17249 {
17250         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17251         int rc;
17252
17253         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17254                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17255                 return;
17256         }
17257
17258         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17259         if (rc < 0) {
17260                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17261                 return;
17262         }
17263         printf("Used desc count = %d\n", rc);
17264 }
17265
17266 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17267         TOKEN_STRING_INITIALIZER
17268                 (struct cmd_show_rx_queue_desc_used_count_result,
17269                  cmd_show, "show");
17270 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17271         TOKEN_STRING_INITIALIZER
17272                 (struct cmd_show_rx_queue_desc_used_count_result,
17273                  cmd_port, "port");
17274 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17275         TOKEN_NUM_INITIALIZER
17276                 (struct cmd_show_rx_queue_desc_used_count_result,
17277                  cmd_pid, RTE_UINT16);
17278 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17279         TOKEN_STRING_INITIALIZER
17280                 (struct cmd_show_rx_queue_desc_used_count_result,
17281                  cmd_rxq, "rxq");
17282 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17283         TOKEN_NUM_INITIALIZER
17284                 (struct cmd_show_rx_queue_desc_used_count_result,
17285                  cmd_qid, RTE_UINT16);
17286 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17287         TOKEN_STRING_INITIALIZER
17288                 (struct cmd_show_rx_queue_desc_used_count_result,
17289                  cmd_count, "desc");
17290 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17291         TOKEN_STRING_INITIALIZER
17292                 (struct cmd_show_rx_queue_desc_used_count_result,
17293                  cmd_count, "used");
17294 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17295         TOKEN_STRING_INITIALIZER
17296                 (struct cmd_show_rx_queue_desc_used_count_result,
17297                  cmd_count, "count");
17298 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17299         .f = cmd_show_rx_queue_desc_used_count_parsed,
17300         .data = NULL,
17301         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17302         .tokens = {
17303                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17304                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17305                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17306                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17307                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17308                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17309                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17310                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17311                 NULL,
17312         },
17313 };
17314
17315 /* Common result structure for set port ptypes */
17316 struct cmd_set_port_ptypes_result {
17317         cmdline_fixed_string_t set;
17318         cmdline_fixed_string_t port;
17319         portid_t port_id;
17320         cmdline_fixed_string_t ptype_mask;
17321         uint32_t mask;
17322 };
17323
17324 /* Common CLI fields for set port ptypes */
17325 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17326         TOKEN_STRING_INITIALIZER
17327                 (struct cmd_set_port_ptypes_result,
17328                  set, "set");
17329 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17330         TOKEN_STRING_INITIALIZER
17331                 (struct cmd_set_port_ptypes_result,
17332                  port, "port");
17333 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17334         TOKEN_NUM_INITIALIZER
17335                 (struct cmd_set_port_ptypes_result,
17336                  port_id, RTE_UINT16);
17337 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17338         TOKEN_STRING_INITIALIZER
17339                 (struct cmd_set_port_ptypes_result,
17340                  ptype_mask, "ptype_mask");
17341 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17342         TOKEN_NUM_INITIALIZER
17343                 (struct cmd_set_port_ptypes_result,
17344                  mask, RTE_UINT32);
17345
17346 static void
17347 cmd_set_port_ptypes_parsed(
17348         void *parsed_result,
17349         __rte_unused struct cmdline *cl,
17350         __rte_unused void *data)
17351 {
17352         struct cmd_set_port_ptypes_result *res = parsed_result;
17353 #define PTYPE_NAMESIZE        256
17354         char ptype_name[PTYPE_NAMESIZE];
17355         uint16_t port_id = res->port_id;
17356         uint32_t ptype_mask = res->mask;
17357         int ret, i;
17358
17359         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17360                                                NULL, 0);
17361         if (ret <= 0) {
17362                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17363                         port_id);
17364                 return;
17365         }
17366
17367         uint32_t ptypes[ret];
17368
17369         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17370         if (ret < 0) {
17371                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17372                         port_id);
17373                 return;
17374         }
17375
17376         printf("Successfully set following ptypes for Port %d\n", port_id);
17377         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17378                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17379                 printf("%s\n", ptype_name);
17380         }
17381
17382         clear_ptypes = false;
17383 }
17384
17385 cmdline_parse_inst_t cmd_set_port_ptypes = {
17386         .f = cmd_set_port_ptypes_parsed,
17387         .data = NULL,
17388         .help_str = "set port <port_id> ptype_mask <mask>",
17389         .tokens = {
17390                 (void *)&cmd_set_port_ptypes_set,
17391                 (void *)&cmd_set_port_ptypes_port,
17392                 (void *)&cmd_set_port_ptypes_port_id,
17393                 (void *)&cmd_set_port_ptypes_mask_str,
17394                 (void *)&cmd_set_port_ptypes_mask_u32,
17395                 NULL,
17396         },
17397 };
17398
17399 /* *** display mac addresses added to a port *** */
17400 struct cmd_showport_macs_result {
17401         cmdline_fixed_string_t cmd_show;
17402         cmdline_fixed_string_t cmd_port;
17403         cmdline_fixed_string_t cmd_keyword;
17404         portid_t cmd_pid;
17405 };
17406
17407 static void
17408 cmd_showport_macs_parsed(void *parsed_result,
17409                 __rte_unused struct cmdline *cl,
17410                 __rte_unused void *data)
17411 {
17412         struct cmd_showport_macs_result *res = parsed_result;
17413
17414         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17415                 return;
17416
17417         if (!strcmp(res->cmd_keyword, "macs"))
17418                 show_macs(res->cmd_pid);
17419         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17420                 show_mcast_macs(res->cmd_pid);
17421 }
17422
17423 cmdline_parse_token_string_t cmd_showport_macs_show =
17424         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17425                         cmd_show, "show");
17426 cmdline_parse_token_string_t cmd_showport_macs_port =
17427         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17428                         cmd_port, "port");
17429 cmdline_parse_token_num_t cmd_showport_macs_pid =
17430         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17431                         cmd_pid, RTE_UINT16);
17432 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17433         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17434                         cmd_keyword, "macs#mcast_macs");
17435
17436 cmdline_parse_inst_t cmd_showport_macs = {
17437         .f = cmd_showport_macs_parsed,
17438         .data = NULL,
17439         .help_str = "show port <port_id> macs|mcast_macs",
17440         .tokens = {
17441                 (void *)&cmd_showport_macs_show,
17442                 (void *)&cmd_showport_macs_port,
17443                 (void *)&cmd_showport_macs_pid,
17444                 (void *)&cmd_showport_macs_keyword,
17445                 NULL,
17446         },
17447 };
17448
17449 /* ******************************************************************************** */
17450
17451 /* list of instructions */
17452 cmdline_parse_ctx_t main_ctx[] = {
17453         (cmdline_parse_inst_t *)&cmd_help_brief,
17454         (cmdline_parse_inst_t *)&cmd_help_long,
17455         (cmdline_parse_inst_t *)&cmd_quit,
17456         (cmdline_parse_inst_t *)&cmd_load_from_file,
17457         (cmdline_parse_inst_t *)&cmd_showport,
17458         (cmdline_parse_inst_t *)&cmd_showqueue,
17459         (cmdline_parse_inst_t *)&cmd_showeeprom,
17460         (cmdline_parse_inst_t *)&cmd_showportall,
17461         (cmdline_parse_inst_t *)&cmd_showdevice,
17462         (cmdline_parse_inst_t *)&cmd_showcfg,
17463         (cmdline_parse_inst_t *)&cmd_showfwdall,
17464         (cmdline_parse_inst_t *)&cmd_start,
17465         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17466         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17467         (cmdline_parse_inst_t *)&cmd_set_link_up,
17468         (cmdline_parse_inst_t *)&cmd_set_link_down,
17469         (cmdline_parse_inst_t *)&cmd_reset,
17470         (cmdline_parse_inst_t *)&cmd_set_numbers,
17471         (cmdline_parse_inst_t *)&cmd_set_log,
17472         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17473         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17474         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17475         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17476         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17477         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17478         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17479         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17480         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17481         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17482         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17483         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17484         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17485         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17486         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17487         (cmdline_parse_inst_t *)&cmd_set_link_check,
17488         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17489         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17490         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17491         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17492 #ifdef RTE_NET_BOND
17493         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17494         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17495         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17496         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17497         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17498         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17499         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17500         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17501         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17502         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17503         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17504         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17505 #endif
17506         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17507         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17508         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17509         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17510         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17511         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17512         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17513         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17514         (cmdline_parse_inst_t *)&cmd_csum_set,
17515         (cmdline_parse_inst_t *)&cmd_csum_show,
17516         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17517         (cmdline_parse_inst_t *)&cmd_tso_set,
17518         (cmdline_parse_inst_t *)&cmd_tso_show,
17519         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17520         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17521         (cmdline_parse_inst_t *)&cmd_gro_enable,
17522         (cmdline_parse_inst_t *)&cmd_gro_flush,
17523         (cmdline_parse_inst_t *)&cmd_gro_show,
17524         (cmdline_parse_inst_t *)&cmd_gso_enable,
17525         (cmdline_parse_inst_t *)&cmd_gso_size,
17526         (cmdline_parse_inst_t *)&cmd_gso_show,
17527         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17528         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17529         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17530         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17531         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17532         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17533         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17534         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17535         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17536         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17537         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17538         (cmdline_parse_inst_t *)&cmd_config_dcb,
17539         (cmdline_parse_inst_t *)&cmd_read_reg,
17540         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17541         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17542         (cmdline_parse_inst_t *)&cmd_write_reg,
17543         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17544         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17545         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17546         (cmdline_parse_inst_t *)&cmd_stop,
17547         (cmdline_parse_inst_t *)&cmd_mac_addr,
17548         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17549         (cmdline_parse_inst_t *)&cmd_set_qmap,
17550         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17551         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17552         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17553         (cmdline_parse_inst_t *)&cmd_operate_port,
17554         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17555         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17556         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17557         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17558         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17559         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17560         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17561         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17562         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17563         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17564         (cmdline_parse_inst_t *)&cmd_config_mtu,
17565         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17566         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17567         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17568         (cmdline_parse_inst_t *)&cmd_config_rss,
17569         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17570         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17571         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17572         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17573         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17574         (cmdline_parse_inst_t *)&cmd_showport_reta,
17575         (cmdline_parse_inst_t *)&cmd_showport_macs,
17576         (cmdline_parse_inst_t *)&cmd_config_burst,
17577         (cmdline_parse_inst_t *)&cmd_config_thresh,
17578         (cmdline_parse_inst_t *)&cmd_config_threshold,
17579         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17580         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17581         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17582         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17583         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17584         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17585         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17586         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17587         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17588         (cmdline_parse_inst_t *)&cmd_dump,
17589         (cmdline_parse_inst_t *)&cmd_dump_one,
17590 #ifdef RTE_NET_I40E
17591         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17592 #endif
17593         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17594         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17595         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17596         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17597         (cmdline_parse_inst_t *)&cmd_flow,
17598         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17599         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17600         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17601         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17602         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17603         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17604         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17605         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17606         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17607         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17608         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17609         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17610         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17611         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17612         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17613         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17614         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17615         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17616         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17617         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17618         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17619         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17620         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17621         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17622         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17623         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17624         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17625         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17626         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17627         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17628         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17629         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17630         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17631         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17632         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17633         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17634         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17635         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17636         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17637         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17638         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17639         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17640         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17641         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17642         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17643         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17644         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17645         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17646         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17647         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17648         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17649         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17650         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17651         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17652         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17653         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17654         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17655         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17656         (cmdline_parse_inst_t *)&cmd_ddp_add,
17657         (cmdline_parse_inst_t *)&cmd_ddp_del,
17658         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17659         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17660         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17661         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17662         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17663         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17664         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17665         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17666         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17667         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17668         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17669         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17670
17671         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17672         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17673         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17674         (cmdline_parse_inst_t *)&cmd_queue_region,
17675         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17676         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17677         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17678         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17679         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17680         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17681         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17682         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17683         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17684         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17685         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17686         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17687         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17688         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17689         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17690         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17691         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17692         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17693         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17694         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17695         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17696         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17697         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17698         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17699         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17700         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17701         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17702         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17703         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17704         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17705         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17706         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17707         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17708         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17709         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17710         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17711 #ifdef RTE_LIB_BPF
17712         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17713         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17714 #endif
17715         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17716         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17717         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17718         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17719         (cmdline_parse_inst_t *)&cmd_set_raw,
17720         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17721         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17722         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17723         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17724         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17725         (cmdline_parse_inst_t *)&cmd_show_capability,
17726         NULL,
17727 };
17728
17729 /* read cmdline commands from file */
17730 void
17731 cmdline_read_from_file(const char *filename)
17732 {
17733         struct cmdline *cl;
17734
17735         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17736         if (cl == NULL) {
17737                 fprintf(stderr,
17738                         "Failed to create file based cmdline context: %s\n",
17739                         filename);
17740                 return;
17741         }
17742
17743         cmdline_interact(cl);
17744         cmdline_quit(cl);
17745
17746         cmdline_free(cl);
17747
17748         printf("Read CLI commands from %s\n", filename);
17749 }
17750
17751 /* prompt function, called from main on MAIN lcore */
17752 void
17753 prompt(void)
17754 {
17755         int ret;
17756         /* initialize non-constant commands */
17757         cmd_set_fwd_mode_init();
17758         cmd_set_fwd_retry_mode_init();
17759
17760         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17761         if (testpmd_cl == NULL)
17762                 return;
17763
17764         ret = atexit(prompt_exit);
17765         if (ret != 0)
17766                 fprintf(stderr, "Cannot set exit function for cmdline\n");
17767
17768         cmdline_interact(testpmd_cl);
17769         if (ret != 0)
17770                 cmdline_stdin_exit(testpmd_cl);
17771 }
17772
17773 void
17774 prompt_exit(void)
17775 {
17776         if (testpmd_cl != NULL) {
17777                 cmdline_quit(testpmd_cl);
17778                 cmdline_stdin_exit(testpmd_cl);
17779         }
17780 }
17781
17782 static void
17783 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17784 {
17785         if (id == (portid_t)RTE_PORT_ALL) {
17786                 portid_t pid;
17787
17788                 RTE_ETH_FOREACH_DEV(pid) {
17789                         /* check if need_reconfig has been set to 1 */
17790                         if (ports[pid].need_reconfig == 0)
17791                                 ports[pid].need_reconfig = dev;
17792                         /* check if need_reconfig_queues has been set to 1 */
17793                         if (ports[pid].need_reconfig_queues == 0)
17794                                 ports[pid].need_reconfig_queues = queue;
17795                 }
17796         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17797                 /* check if need_reconfig has been set to 1 */
17798                 if (ports[id].need_reconfig == 0)
17799                         ports[id].need_reconfig = dev;
17800                 /* check if need_reconfig_queues has been set to 1 */
17801                 if (ports[id].need_reconfig_queues == 0)
17802                         ports[id].need_reconfig_queues = queue;
17803         }
17804 }