app/testpmd: show link flow control 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 <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) rxq (queue_id) desc used count\n"
250                         "    Show current number of filled receive"
251                         " packet descriptors.\n\n"
252
253                         "show port (port_id) macs|mcast_macs"
254                         "       Display list of mac addresses added to port.\n\n"
255
256                         "show port (port_id) fec capabilities"
257                         "       Show fec capabilities of a port.\n\n"
258
259                         "show port (port_id) fec_mode"
260                         "       Show fec mode of a port.\n\n"
261
262                         "show port (port_id) flow_ctrl"
263                         "       Show flow control info of a port.\n\n"
264                 );
265         }
266
267         if (show_all || !strcmp(res->section, "config")) {
268                 cmdline_printf(
269                         cl,
270                         "\n"
271                         "Configuration:\n"
272                         "--------------\n"
273                         "Configuration changes only become active when"
274                         " forwarding is started/restarted.\n\n"
275
276                         "set default\n"
277                         "    Reset forwarding to the default configuration.\n\n"
278
279                         "set verbose (level)\n"
280                         "    Set the debug verbosity level X.\n\n"
281
282                         "set log global|(type) (level)\n"
283                         "    Set the log level.\n\n"
284
285                         "set nbport (num)\n"
286                         "    Set number of ports.\n\n"
287
288                         "set nbcore (num)\n"
289                         "    Set number of cores.\n\n"
290
291                         "set coremask (mask)\n"
292                         "    Set the forwarding cores hexadecimal mask.\n\n"
293
294                         "set portmask (mask)\n"
295                         "    Set the forwarding ports hexadecimal mask.\n\n"
296
297                         "set burst (num)\n"
298                         "    Set number of packets per burst.\n\n"
299
300                         "set burst tx delay (microseconds) retry (num)\n"
301                         "    Set the transmit delay time and number of retries,"
302                         " effective when retry is enabled.\n\n"
303
304                         "set rxoffs (x[,y]*)\n"
305                         "    Set the offset of each packet segment on"
306                         " receiving if split feature is engaged."
307                         " Affects only the queues configured with split"
308                         " offloads.\n\n"
309
310                         "set rxpkts (x[,y]*)\n"
311                         "    Set the length of each segment to scatter"
312                         " packets on receiving if split feature is engaged."
313                         " Affects only the queues configured with split"
314                         " offloads.\n\n"
315
316                         "set txpkts (x[,y]*)\n"
317                         "    Set the length of each segment of TXONLY"
318                         " and optionally CSUM packets.\n\n"
319
320                         "set txsplit (off|on|rand)\n"
321                         "    Set the split policy for the TX packets."
322                         " Right now only applicable for CSUM and TXONLY"
323                         " modes\n\n"
324
325                         "set txtimes (x, y)\n"
326                         "    Set the scheduling on timestamps"
327                         " timings for the TXONLY mode\n\n"
328
329                         "set corelist (x[,y]*)\n"
330                         "    Set the list of forwarding cores.\n\n"
331
332                         "set portlist (x[,y]*)\n"
333                         "    Set the list of forwarding ports.\n\n"
334
335                         "set port setup on (iterator|event)\n"
336                         "    Select how attached port is retrieved for setup.\n\n"
337
338                         "set tx loopback (port_id) (on|off)\n"
339                         "    Enable or disable tx loopback.\n\n"
340
341                         "set all queues drop (port_id) (on|off)\n"
342                         "    Set drop enable bit for all queues.\n\n"
343
344                         "set vf split drop (port_id) (vf_id) (on|off)\n"
345                         "    Set split drop enable bit for a VF from the PF.\n\n"
346
347                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
348                         "    Set MAC antispoof for a VF from the PF.\n\n"
349
350                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
351                         "    Enable MACsec offload.\n\n"
352
353                         "set macsec offload (port_id) off\n"
354                         "    Disable MACsec offload.\n\n"
355
356                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
357                         "    Configure MACsec secure connection (SC).\n\n"
358
359                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
360                         "    Configure MACsec secure association (SA).\n\n"
361
362                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
363                         "    Set VF broadcast for a VF from the PF.\n\n"
364
365                         "vlan set stripq (on|off) (port_id,queue_id)\n"
366                         "    Set the VLAN strip for a queue on a port.\n\n"
367
368                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
369                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
370
371                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
372                         "    Set VLAN insert for a VF from the PF.\n\n"
373
374                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
375                         "    Set VLAN antispoof for a VF from the PF.\n\n"
376
377                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
378                         "    Set VLAN tag for a VF from the PF.\n\n"
379
380                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
381                         "    Set a VF's max bandwidth(Mbps).\n\n"
382
383                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
384                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
385
386                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
387                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
388
389                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
390                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
391
392                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
393                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
394
395                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
396                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
397
398                         "vlan set (inner|outer) tpid (value) (port_id)\n"
399                         "    Set the VLAN TPID for Packet Filtering on"
400                         " a port\n\n"
401
402                         "rx_vlan add (vlan_id|all) (port_id)\n"
403                         "    Add a vlan_id, or all identifiers, to the set"
404                         " of VLAN identifiers filtered by port_id.\n\n"
405
406                         "rx_vlan rm (vlan_id|all) (port_id)\n"
407                         "    Remove a vlan_id, or all identifiers, from the set"
408                         " of VLAN identifiers filtered by port_id.\n\n"
409
410                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
411                         "    Add a vlan_id, to the set of VLAN identifiers"
412                         "filtered for VF(s) from port_id.\n\n"
413
414                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
415                         "    Remove a vlan_id, to the set of VLAN identifiers"
416                         "filtered for VF(s) from port_id.\n\n"
417
418                         "rx_vxlan_port add (udp_port) (port_id)\n"
419                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
420
421                         "rx_vxlan_port rm (udp_port) (port_id)\n"
422                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
423
424                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
425                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
426                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
427
428                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
429                         "    Set port based TX VLAN insertion.\n\n"
430
431                         "tx_vlan reset (port_id)\n"
432                         "    Disable hardware insertion of a VLAN header in"
433                         " packets sent on a port.\n\n"
434
435                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
436                         "    Select hardware or software calculation of the"
437                         " checksum when transmitting a packet using the"
438                         " csum forward engine.\n"
439                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
440                         "    outer-ip concerns the outer IP layer in"
441                         "    outer-udp concerns the outer UDP layer in"
442                         " case the packet is recognized as a tunnel packet by"
443                         " the forward engine (vxlan, gre and ipip are supported)\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "csum parse-tunnel (on|off) (tx_port_id)\n"
447                         "    If disabled, treat tunnel packets as non-tunneled"
448                         " packets (treat inner headers as payload). The port\n"
449                         "    argument is the port used for TX in csum forward"
450                         " engine.\n\n"
451
452                         "csum show (port_id)\n"
453                         "    Display tx checksum offload configuration\n\n"
454
455                         "tso set (segsize) (portid)\n"
456                         "    Enable TCP Segmentation Offload in csum forward"
457                         " engine.\n"
458                         "    Please check the NIC datasheet for HW limits.\n\n"
459
460                         "tso show (portid)"
461                         "    Display the status of TCP Segmentation Offload.\n\n"
462
463                         "set port (port_id) gro on|off\n"
464                         "    Enable or disable Generic Receive Offload in"
465                         " csum forwarding engine.\n\n"
466
467                         "show port (port_id) gro\n"
468                         "    Display GRO configuration.\n\n"
469
470                         "set gro flush (cycles)\n"
471                         "    Set the cycle to flush GROed packets from"
472                         " reassembly tables.\n\n"
473
474                         "set port (port_id) gso (on|off)"
475                         "    Enable or disable Generic Segmentation Offload in"
476                         " csum forwarding engine.\n\n"
477
478                         "set gso segsz (length)\n"
479                         "    Set max packet length for output GSO segments,"
480                         " including packet header and payload.\n\n"
481
482                         "show port (port_id) gso\n"
483                         "    Show GSO configuration.\n\n"
484
485                         "set fwd (%s)\n"
486                         "    Set packet forwarding mode.\n\n"
487
488                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
489                         "    Add a MAC address on port_id.\n\n"
490
491                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Remove a MAC address from port_id.\n\n"
493
494                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
495                         "    Set the default MAC address for port_id.\n\n"
496
497                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
498                         "    Add a MAC address for a VF on the port.\n\n"
499
500                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
501                         "    Set the MAC address for a VF from the PF.\n\n"
502
503                         "set eth-peer (port_id) (peer_addr)\n"
504                         "    set the peer address for certain port.\n\n"
505
506                         "set port (port_id) uta (mac_address|all) (on|off)\n"
507                         "    Add/Remove a or all unicast hash filter(s)"
508                         "from port X.\n\n"
509
510                         "set promisc (port_id|all) (on|off)\n"
511                         "    Set the promiscuous mode on port_id, or all.\n\n"
512
513                         "set allmulti (port_id|all) (on|off)\n"
514                         "    Set the allmulti mode on port_id, or all.\n\n"
515
516                         "set vf promisc (port_id) (vf_id) (on|off)\n"
517                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
518
519                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
520                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
521
522                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
523                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
524                         " (on|off) autoneg (on|off) (port_id)\n"
525                         "set flow_ctrl rx (on|off) (portid)\n"
526                         "set flow_ctrl tx (on|off) (portid)\n"
527                         "set flow_ctrl high_water (high_water) (portid)\n"
528                         "set flow_ctrl low_water (low_water) (portid)\n"
529                         "set flow_ctrl pause_time (pause_time) (portid)\n"
530                         "set flow_ctrl send_xon (send_xon) (portid)\n"
531                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
532                         "set flow_ctrl autoneg (on|off) (port_id)\n"
533                         "    Set the link flow control parameter on a port.\n\n"
534
535                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
536                         " (low_water) (pause_time) (priority) (port_id)\n"
537                         "    Set the priority flow control parameter on a"
538                         " port.\n\n"
539
540                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
541                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
542                         " queue on port.\n"
543                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
544                         " on port 0 to mapping 5.\n\n"
545
546                         "set xstats-hide-zero on|off\n"
547                         "    Set the option to hide the zero values"
548                         " for xstats display.\n"
549
550                         "set record-core-cycles on|off\n"
551                         "    Set the option to enable measurement of CPU cycles.\n"
552
553                         "set record-burst-stats on|off\n"
554                         "    Set the option to enable display of RX and TX bursts.\n"
555
556                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
557                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
558
559                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
560                         "|MPE) (on|off)\n"
561                         "    AUPE:accepts untagged VLAN;"
562                         "ROPE:accept unicast hash\n\n"
563                         "    BAM:accepts broadcast packets;"
564                         "MPE:accepts all multicast packets\n\n"
565                         "    Enable/Disable a VF receive mode of a port\n\n"
566
567                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
568                         "    Set rate limit for a queue of a port\n\n"
569
570                         "set port (port_id) vf (vf_id) rate (rate_num) "
571                         "queue_mask (queue_mask_value)\n"
572                         "    Set rate limit for queues in VF of a port\n\n"
573
574                         "set port (port_id) mirror-rule (rule_id)"
575                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
576                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
577                         "   Set pool or vlan type mirror rule on a port.\n"
578                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
579                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
580                         " to pool 0.\n\n"
581
582                         "set port (port_id) mirror-rule (rule_id)"
583                         " (uplink-mirror|downlink-mirror) dst-pool"
584                         " (pool_id) (on|off)\n"
585                         "   Set uplink or downlink type mirror rule on a port.\n"
586                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
587                         " 0 on' enable mirror income traffic to pool 0.\n\n"
588
589                         "reset port (port_id) mirror-rule (rule_id)\n"
590                         "   Reset a mirror rule.\n\n"
591
592                         "set flush_rx (on|off)\n"
593                         "   Flush (default) or don't flush RX streams before"
594                         " forwarding. Mainly used with PCAP drivers.\n\n"
595
596                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
597                         "   Set the bypass mode for the lowest port on bypass enabled"
598                         " NIC.\n\n"
599
600                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
601                         "mode (normal|bypass|isolate) (port_id)\n"
602                         "   Set the event required to initiate specified bypass mode for"
603                         " the lowest port on a bypass enabled NIC where:\n"
604                         "       timeout   = enable bypass after watchdog timeout.\n"
605                         "       os_on     = enable bypass when OS/board is powered on.\n"
606                         "       os_off    = enable bypass when OS/board is powered off.\n"
607                         "       power_on  = enable bypass when power supply is turned on.\n"
608                         "       power_off = enable bypass when power supply is turned off."
609                         "\n\n"
610
611                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
612                         "   Set the bypass watchdog timeout to 'n' seconds"
613                         " where 0 = instant.\n\n"
614
615                         "show bypass config (port_id)\n"
616                         "   Show the bypass configuration for a bypass enabled NIC"
617                         " using the lowest port on the NIC.\n\n"
618
619 #ifdef RTE_NET_BOND
620                         "create bonded device (mode) (socket)\n"
621                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
622
623                         "add bonding slave (slave_id) (port_id)\n"
624                         "       Add a slave device to a bonded device.\n\n"
625
626                         "remove bonding slave (slave_id) (port_id)\n"
627                         "       Remove a slave device from a bonded device.\n\n"
628
629                         "set bonding mode (value) (port_id)\n"
630                         "       Set the bonding mode on a bonded device.\n\n"
631
632                         "set bonding primary (slave_id) (port_id)\n"
633                         "       Set the primary slave for a bonded device.\n\n"
634
635                         "show bonding config (port_id)\n"
636                         "       Show the bonding config for port_id.\n\n"
637
638                         "set bonding mac_addr (port_id) (address)\n"
639                         "       Set the MAC address of a bonded device.\n\n"
640
641                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
642                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
643
644                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
645                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
646
647                         "set bonding mon_period (port_id) (value)\n"
648                         "       Set the bonding link status monitoring polling period in ms.\n\n"
649
650                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
651                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
652
653 #endif
654                         "set link-up port (port_id)\n"
655                         "       Set link up for a port.\n\n"
656
657                         "set link-down port (port_id)\n"
658                         "       Set link down for a port.\n\n"
659
660                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
661                         "    Load a profile package on a port\n\n"
662
663                         "ddp del (port_id) (backup_profile_path)\n"
664                         "    Delete a profile package from a port\n\n"
665
666                         "ptype mapping get (port_id) (valid_only)\n"
667                         "    Get ptype mapping on a port\n\n"
668
669                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
670                         "    Replace target with the pkt_type in ptype mapping\n\n"
671
672                         "ptype mapping reset (port_id)\n"
673                         "    Reset ptype mapping on a port\n\n"
674
675                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
676                         "    Update a ptype mapping item on a port\n\n"
677
678                         "set port (port_id) ptype_mask (ptype_mask)\n"
679                         "    set packet types classification for a specific port\n\n"
680
681                         "set port (port_id) queue-region region_id (value) "
682                         "queue_start_index (value) queue_num (value)\n"
683                         "    Set a queue region on a port\n\n"
684
685                         "set port (port_id) queue-region region_id (value) "
686                         "flowtype (value)\n"
687                         "    Set a flowtype region index on a port\n\n"
688
689                         "set port (port_id) queue-region UP (value) region_id (value)\n"
690                         "    Set the mapping of User Priority to "
691                         "queue region on a port\n\n"
692
693                         "set port (port_id) queue-region flush (on|off)\n"
694                         "    flush all queue region related configuration\n\n"
695
696                         "show port meter cap (port_id)\n"
697                         "    Show port meter capability information\n\n"
698
699                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
700                         "    meter profile add - srtcm rfc 2697\n\n"
701
702                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
703                         "    meter profile add - trtcm rfc 2698\n\n"
704
705                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
706                         "    meter profile add - trtcm rfc 4115\n\n"
707
708                         "del port meter profile (port_id) (profile_id)\n"
709                         "    meter profile delete\n\n"
710
711                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
712                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
713                         "(dscp_tbl_entry63)]\n"
714                         "    meter create\n\n"
715
716                         "enable port meter (port_id) (mtr_id)\n"
717                         "    meter enable\n\n"
718
719                         "disable port meter (port_id) (mtr_id)\n"
720                         "    meter disable\n\n"
721
722                         "del port meter (port_id) (mtr_id)\n"
723                         "    meter delete\n\n"
724
725                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
726                         "y_actions (actions) r_actions (actions)\n"
727                         "    meter policy add\n\n"
728
729                         "del port meter policy (port_id) (policy_id)\n"
730                         "    meter policy delete\n\n"
731
732                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
733                         "    meter update meter profile\n\n"
734
735                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
736                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
737                         "    update meter dscp table entries\n\n"
738
739                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
740                         "(action0) [(action1) (action2)]\n"
741                         "    meter update policer action\n\n"
742
743                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
744                         "    meter update stats\n\n"
745
746                         "show port (port_id) queue-region\n"
747                         "    show all queue region related configuration info\n\n"
748
749                         "set port (port_id) fec_mode auto|off|rs|baser\n"
750                         "    set fec mode for a specific port\n\n"
751
752                         , list_pkt_forwarding_modes()
753                 );
754         }
755
756         if (show_all || !strcmp(res->section, "ports")) {
757
758                 cmdline_printf(
759                         cl,
760                         "\n"
761                         "Port Operations:\n"
762                         "----------------\n\n"
763
764                         "port start (port_id|all)\n"
765                         "    Start all ports or port_id.\n\n"
766
767                         "port stop (port_id|all)\n"
768                         "    Stop all ports or port_id.\n\n"
769
770                         "port close (port_id|all)\n"
771                         "    Close all ports or port_id.\n\n"
772
773                         "port reset (port_id|all)\n"
774                         "    Reset all ports or port_id.\n\n"
775
776                         "port attach (ident)\n"
777                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
778
779                         "port detach (port_id)\n"
780                         "    Detach physical or virtual dev by port_id\n\n"
781
782                         "port config (port_id|all)"
783                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
784                         " duplex (half|full|auto)\n"
785                         "    Set speed and duplex for all ports or port_id\n\n"
786
787                         "port config (port_id|all) loopback (mode)\n"
788                         "    Set loopback mode for all ports or port_id\n\n"
789
790                         "port config all (rxq|txq|rxd|txd) (value)\n"
791                         "    Set number for rxq/txq/rxd/txd.\n\n"
792
793                         "port config all max-pkt-len (value)\n"
794                         "    Set the max packet length.\n\n"
795
796                         "port config all max-lro-pkt-size (value)\n"
797                         "    Set the max LRO aggregated packet size.\n\n"
798
799                         "port config all drop-en (on|off)\n"
800                         "    Enable or disable packet drop on all RX queues of all ports when no "
801                         "receive buffers available.\n\n"
802
803                         "port config all rss (all|default|ip|tcp|udp|sctp|"
804                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
805                         "level-outer|level-inner|<flowtype_id>)\n"
806                         "    Set the RSS mode.\n\n"
807
808                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
809                         "    Set the RSS redirection table.\n\n"
810
811                         "port config (port_id) dcb vt (on|off) (traffic_class)"
812                         " pfc (on|off)\n"
813                         "    Set the DCB mode.\n\n"
814
815                         "port config all burst (value)\n"
816                         "    Set the number of packets per burst.\n\n"
817
818                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
819                         " (value)\n"
820                         "    Set the ring prefetch/host/writeback threshold"
821                         " for tx/rx queue.\n\n"
822
823                         "port config all (txfreet|txrst|rxfreet) (value)\n"
824                         "    Set free threshold for rx/tx, or set"
825                         " tx rs bit threshold.\n\n"
826                         "port config mtu X value\n"
827                         "    Set the MTU of port X to a given value\n\n"
828
829                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
830                         "    Set a rx/tx queue's ring size configuration, the new"
831                         " value will take effect after command that (re-)start the port"
832                         " or command that setup the specific queue\n\n"
833
834                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
835                         "    Start/stop a rx/tx queue of port X. Only take effect"
836                         " when port X is started\n\n"
837
838                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
839                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
840                         " take effect when port X is stopped.\n\n"
841
842                         "port (port_id) (rxq|txq) (queue_id) setup\n"
843                         "    Setup a rx/tx queue of port X.\n\n"
844
845                         "port config (port_id) pctype mapping reset\n"
846                         "    Reset flow type to pctype mapping on a port\n\n"
847
848                         "port config (port_id) pctype mapping update"
849                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
850                         "    Update a flow type to pctype mapping item on a port\n\n"
851
852                         "port config (port_id) pctype (pctype_id) hash_inset|"
853                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
854                         " (field_idx)\n"
855                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
856
857                         "port config (port_id) pctype (pctype_id) hash_inset|"
858                         "fdir_inset|fdir_flx_inset clear all"
859                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
860
861                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
862                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
863
864                         "port config <port_id> rx_offload vlan_strip|"
865                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
866                         "outer_ipv4_cksum|macsec_strip|header_split|"
867                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
868                         "buffer_split|timestamp|security|keep_crc on|off\n"
869                         "     Enable or disable a per port Rx offloading"
870                         " on all Rx queues of a port\n\n"
871
872                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
873                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
874                         "outer_ipv4_cksum|macsec_strip|header_split|"
875                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
876                         "buffer_split|timestamp|security|keep_crc on|off\n"
877                         "    Enable or disable a per queue Rx offloading"
878                         " only on a specific Rx queue\n\n"
879
880                         "port config (port_id) tx_offload vlan_insert|"
881                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
882                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
883                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
884                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
885                         "security on|off\n"
886                         "    Enable or disable a per port Tx offloading"
887                         " on all Tx queues of a port\n\n"
888
889                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
890                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
891                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
892                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
893                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
894                         " on|off\n"
895                         "    Enable or disable a per queue Tx offloading"
896                         " only on a specific Tx queue\n\n"
897
898                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
899                         "    Load an eBPF program as a callback"
900                         " for particular RX/TX queue\n\n"
901
902                         "bpf-unload rx|tx (port) (queue)\n"
903                         "    Unload previously loaded eBPF program"
904                         " for particular RX/TX queue\n\n"
905
906                         "port config (port_id) tx_metadata (value)\n"
907                         "    Set Tx metadata value per port. Testpmd will add this value"
908                         " to any Tx packet sent from this port\n\n"
909
910                         "port config (port_id) dynf (name) set|clear\n"
911                         "    Register a dynf and Set/clear this flag on Tx. "
912                         "Testpmd will set this value to any Tx packet "
913                         "sent from this port\n\n"
914
915                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
916                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
917                 );
918         }
919
920         if (show_all || !strcmp(res->section, "registers")) {
921
922                 cmdline_printf(
923                         cl,
924                         "\n"
925                         "Registers:\n"
926                         "----------\n\n"
927
928                         "read reg (port_id) (address)\n"
929                         "    Display value of a port register.\n\n"
930
931                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
932                         "    Display a port register bit field.\n\n"
933
934                         "read regbit (port_id) (address) (bit_x)\n"
935                         "    Display a single port register bit.\n\n"
936
937                         "write reg (port_id) (address) (value)\n"
938                         "    Set value of a port register.\n\n"
939
940                         "write regfield (port_id) (address) (bit_x) (bit_y)"
941                         " (value)\n"
942                         "    Set bit field of a port register.\n\n"
943
944                         "write regbit (port_id) (address) (bit_x) (value)\n"
945                         "    Set single bit value of a port register.\n\n"
946                 );
947         }
948         if (show_all || !strcmp(res->section, "filters")) {
949
950                 cmdline_printf(
951                         cl,
952                         "\n"
953                         "filters:\n"
954                         "--------\n\n"
955
956 #ifdef RTE_NET_I40E
957                         "flow_director_filter (port_id) mode raw (add|del|update)"
958                         " flow (flow_id) (drop|fwd) queue (queue_id)"
959                         " fd_id (fd_id_value) packet (packet file name)\n"
960                         "    Add/Del a raw type flow director filter.\n\n"
961 #endif
962
963                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
964                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
965                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
966                         "    Set flow director IP mask.\n\n"
967
968                         "flow_director_mask (port_id) mode MAC-VLAN"
969                         " vlan (vlan_value)\n"
970                         "    Set flow director MAC-VLAN mask.\n\n"
971
972                         "flow_director_mask (port_id) mode Tunnel"
973                         " vlan (vlan_value) mac (mac_value)"
974                         " tunnel-type (tunnel_type_value)"
975                         " tunnel-id (tunnel_id_value)\n"
976                         "    Set flow director Tunnel mask.\n\n"
977
978                         "flow_director_flex_payload (port_id)"
979                         " (raw|l2|l3|l4) (config)\n"
980                         "    Configure flex payload selection.\n\n"
981
982                         "flow validate {port_id}"
983                         " [group {group_id}] [priority {level}]"
984                         " [ingress] [egress]"
985                         " pattern {item} [/ {item} [...]] / end"
986                         " actions {action} [/ {action} [...]] / end\n"
987                         "    Check whether a flow rule can be created.\n\n"
988
989                         "flow create {port_id}"
990                         " [group {group_id}] [priority {level}]"
991                         " [ingress] [egress]"
992                         " pattern {item} [/ {item} [...]] / end"
993                         " actions {action} [/ {action} [...]] / end\n"
994                         "    Create a flow rule.\n\n"
995
996                         "flow destroy {port_id} rule {rule_id} [...]\n"
997                         "    Destroy specific flow rules.\n\n"
998
999                         "flow flush {port_id}\n"
1000                         "    Destroy all flow rules.\n\n"
1001
1002                         "flow query {port_id} {rule_id} {action}\n"
1003                         "    Query an existing flow rule.\n\n"
1004
1005                         "flow list {port_id} [group {group_id}] [...]\n"
1006                         "    List existing flow rules sorted by priority,"
1007                         " filtered by group identifiers.\n\n"
1008
1009                         "flow isolate {port_id} {boolean}\n"
1010                         "    Restrict ingress traffic to the defined"
1011                         " flow rules\n\n"
1012
1013                         "flow aged {port_id} [destroy]\n"
1014                         "    List and destroy aged flows"
1015                         " flow rules\n\n"
1016
1017                         "flow indirect_action {port_id} create"
1018                         " [action_id {indirect_action_id}]"
1019                         " [ingress] [egress]"
1020                         " action {action} / end\n"
1021                         "    Create indirect action.\n\n"
1022
1023                         "flow indirect_action {port_id} update"
1024                         " {indirect_action_id} action {action} / end\n"
1025                         "    Update indirect action.\n\n"
1026
1027                         "flow indirect_action {port_id} destroy"
1028                         " action_id {indirect_action_id} [...]\n"
1029                         "    Destroy specific indirect actions.\n\n"
1030
1031                         "flow indirect_action {port_id} query"
1032                         " {indirect_action_id}\n"
1033                         "    Query an existing indirect action.\n\n"
1034
1035                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1036                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1037                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1038                         "       Configure the VXLAN encapsulation for flows.\n\n"
1039
1040                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1041                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1042                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1043                         " eth-dst (eth-dst)\n"
1044                         "       Configure the VXLAN encapsulation for flows.\n\n"
1045
1046                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1047                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1048                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1049                         " eth-dst (eth-dst)\n"
1050                         "       Configure the VXLAN encapsulation for flows.\n\n"
1051
1052                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1053                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1054                         " (eth-dst)\n"
1055                         "       Configure the NVGRE encapsulation for flows.\n\n"
1056
1057                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1058                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1059                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1060                         "       Configure the NVGRE encapsulation for flows.\n\n"
1061
1062                         "set raw_encap {flow items}\n"
1063                         "       Configure the encapsulation with raw data.\n\n"
1064
1065                         "set raw_decap {flow items}\n"
1066                         "       Configure the decapsulation with raw data.\n\n"
1067
1068                 );
1069         }
1070
1071         if (show_all || !strcmp(res->section, "traffic_management")) {
1072                 cmdline_printf(
1073                         cl,
1074                         "\n"
1075                         "Traffic Management:\n"
1076                         "--------------\n"
1077                         "show port tm cap (port_id)\n"
1078                         "       Display the port TM capability.\n\n"
1079
1080                         "show port tm level cap (port_id) (level_id)\n"
1081                         "       Display the port TM hierarchical level capability.\n\n"
1082
1083                         "show port tm node cap (port_id) (node_id)\n"
1084                         "       Display the port TM node capability.\n\n"
1085
1086                         "show port tm node type (port_id) (node_id)\n"
1087                         "       Display the port TM node type.\n\n"
1088
1089                         "show port tm node stats (port_id) (node_id) (clear)\n"
1090                         "       Display the port TM node stats.\n\n"
1091
1092                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1093                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1094                         " (packet_length_adjust) (packet_mode)\n"
1095                         "       Add port tm node private shaper profile.\n\n"
1096
1097                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1098                         "       Delete port tm node private shaper profile.\n\n"
1099
1100                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1101                         " (shaper_profile_id)\n"
1102                         "       Add/update port tm node shared shaper.\n\n"
1103
1104                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1105                         "       Delete port tm node shared shaper.\n\n"
1106
1107                         "set port tm node shaper profile (port_id) (node_id)"
1108                         " (shaper_profile_id)\n"
1109                         "       Set port tm node shaper profile.\n\n"
1110
1111                         "add port tm node wred profile (port_id) (wred_profile_id)"
1112                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1113                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1114                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1115                         "       Add port tm node wred profile.\n\n"
1116
1117                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1118                         "       Delete port tm node wred profile.\n\n"
1119
1120                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1121                         " (priority) (weight) (level_id) (shaper_profile_id)"
1122                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1123                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1124                         "       Add port tm nonleaf node.\n\n"
1125
1126                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1127                         " (priority) (weight) (level_id) (shaper_profile_id)"
1128                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1129                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1130                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1131
1132                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1133                         " (priority) (weight) (level_id) (shaper_profile_id)"
1134                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1135                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1136                         "       Add port tm leaf node.\n\n"
1137
1138                         "del port tm node (port_id) (node_id)\n"
1139                         "       Delete port tm node.\n\n"
1140
1141                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1142                         " (priority) (weight)\n"
1143                         "       Set port tm node parent.\n\n"
1144
1145                         "suspend port tm node (port_id) (node_id)"
1146                         "       Suspend tm node.\n\n"
1147
1148                         "resume port tm node (port_id) (node_id)"
1149                         "       Resume tm node.\n\n"
1150
1151                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1152                         "       Commit tm hierarchy.\n\n"
1153
1154                         "set port tm mark ip_ecn (port) (green) (yellow)"
1155                         " (red)\n"
1156                         "    Enables/Disables the traffic management marking"
1157                         " for IP ECN (Explicit Congestion Notification)"
1158                         " packets on a given port\n\n"
1159
1160                         "set port tm mark ip_dscp (port) (green) (yellow)"
1161                         " (red)\n"
1162                         "    Enables/Disables the traffic management marking"
1163                         " on the port for IP dscp packets\n\n"
1164
1165                         "set port tm mark vlan_dei (port) (green) (yellow)"
1166                         " (red)\n"
1167                         "    Enables/Disables the traffic management marking"
1168                         " on the port for VLAN packets with DEI enabled\n\n"
1169                 );
1170         }
1171
1172         if (show_all || !strcmp(res->section, "devices")) {
1173                 cmdline_printf(
1174                         cl,
1175                         "\n"
1176                         "Device Operations:\n"
1177                         "--------------\n"
1178                         "device detach (identifier)\n"
1179                         "       Detach device by identifier.\n\n"
1180                 );
1181         }
1182
1183 }
1184
1185 cmdline_parse_token_string_t cmd_help_long_help =
1186         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1187
1188 cmdline_parse_token_string_t cmd_help_long_section =
1189         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1190                         "all#control#display#config#"
1191                         "ports#registers#filters#traffic_management#devices");
1192
1193 cmdline_parse_inst_t cmd_help_long = {
1194         .f = cmd_help_long_parsed,
1195         .data = NULL,
1196         .help_str = "help all|control|display|config|ports|register|"
1197                 "filters|traffic_management|devices: "
1198                 "Show help",
1199         .tokens = {
1200                 (void *)&cmd_help_long_help,
1201                 (void *)&cmd_help_long_section,
1202                 NULL,
1203         },
1204 };
1205
1206
1207 /* *** start/stop/close all ports *** */
1208 struct cmd_operate_port_result {
1209         cmdline_fixed_string_t keyword;
1210         cmdline_fixed_string_t name;
1211         cmdline_fixed_string_t value;
1212 };
1213
1214 static void cmd_operate_port_parsed(void *parsed_result,
1215                                 __rte_unused struct cmdline *cl,
1216                                 __rte_unused void *data)
1217 {
1218         struct cmd_operate_port_result *res = parsed_result;
1219
1220         if (!strcmp(res->name, "start"))
1221                 start_port(RTE_PORT_ALL);
1222         else if (!strcmp(res->name, "stop"))
1223                 stop_port(RTE_PORT_ALL);
1224         else if (!strcmp(res->name, "close"))
1225                 close_port(RTE_PORT_ALL);
1226         else if (!strcmp(res->name, "reset"))
1227                 reset_port(RTE_PORT_ALL);
1228         else
1229                 printf("Unknown parameter\n");
1230 }
1231
1232 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1233         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1234                                                                 "port");
1235 cmdline_parse_token_string_t cmd_operate_port_all_port =
1236         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1237                                                 "start#stop#close#reset");
1238 cmdline_parse_token_string_t cmd_operate_port_all_all =
1239         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1240
1241 cmdline_parse_inst_t cmd_operate_port = {
1242         .f = cmd_operate_port_parsed,
1243         .data = NULL,
1244         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1245         .tokens = {
1246                 (void *)&cmd_operate_port_all_cmd,
1247                 (void *)&cmd_operate_port_all_port,
1248                 (void *)&cmd_operate_port_all_all,
1249                 NULL,
1250         },
1251 };
1252
1253 /* *** start/stop/close specific port *** */
1254 struct cmd_operate_specific_port_result {
1255         cmdline_fixed_string_t keyword;
1256         cmdline_fixed_string_t name;
1257         uint8_t value;
1258 };
1259
1260 static void cmd_operate_specific_port_parsed(void *parsed_result,
1261                         __rte_unused struct cmdline *cl,
1262                                 __rte_unused void *data)
1263 {
1264         struct cmd_operate_specific_port_result *res = parsed_result;
1265
1266         if (!strcmp(res->name, "start"))
1267                 start_port(res->value);
1268         else if (!strcmp(res->name, "stop"))
1269                 stop_port(res->value);
1270         else if (!strcmp(res->name, "close"))
1271                 close_port(res->value);
1272         else if (!strcmp(res->name, "reset"))
1273                 reset_port(res->value);
1274         else
1275                 printf("Unknown parameter\n");
1276 }
1277
1278 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1280                                                         keyword, "port");
1281 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1282         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1283                                                 name, "start#stop#close#reset");
1284 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1285         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1286                                                         value, RTE_UINT8);
1287
1288 cmdline_parse_inst_t cmd_operate_specific_port = {
1289         .f = cmd_operate_specific_port_parsed,
1290         .data = NULL,
1291         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1292         .tokens = {
1293                 (void *)&cmd_operate_specific_port_cmd,
1294                 (void *)&cmd_operate_specific_port_port,
1295                 (void *)&cmd_operate_specific_port_id,
1296                 NULL,
1297         },
1298 };
1299
1300 /* *** enable port setup (after attach) via iterator or event *** */
1301 struct cmd_set_port_setup_on_result {
1302         cmdline_fixed_string_t set;
1303         cmdline_fixed_string_t port;
1304         cmdline_fixed_string_t setup;
1305         cmdline_fixed_string_t on;
1306         cmdline_fixed_string_t mode;
1307 };
1308
1309 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1310                                 __rte_unused struct cmdline *cl,
1311                                 __rte_unused void *data)
1312 {
1313         struct cmd_set_port_setup_on_result *res = parsed_result;
1314
1315         if (strcmp(res->mode, "event") == 0)
1316                 setup_on_probe_event = true;
1317         else if (strcmp(res->mode, "iterator") == 0)
1318                 setup_on_probe_event = false;
1319         else
1320                 printf("Unknown mode\n");
1321 }
1322
1323 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1324         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1325                         set, "set");
1326 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1327         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1328                         port, "port");
1329 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1330         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1331                         setup, "setup");
1332 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1333         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1334                         on, "on");
1335 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1336         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1337                         mode, "iterator#event");
1338
1339 cmdline_parse_inst_t cmd_set_port_setup_on = {
1340         .f = cmd_set_port_setup_on_parsed,
1341         .data = NULL,
1342         .help_str = "set port setup on iterator|event",
1343         .tokens = {
1344                 (void *)&cmd_set_port_setup_on_set,
1345                 (void *)&cmd_set_port_setup_on_port,
1346                 (void *)&cmd_set_port_setup_on_setup,
1347                 (void *)&cmd_set_port_setup_on_on,
1348                 (void *)&cmd_set_port_setup_on_mode,
1349                 NULL,
1350         },
1351 };
1352
1353 /* *** attach a specified port *** */
1354 struct cmd_operate_attach_port_result {
1355         cmdline_fixed_string_t port;
1356         cmdline_fixed_string_t keyword;
1357         cmdline_multi_string_t identifier;
1358 };
1359
1360 static void cmd_operate_attach_port_parsed(void *parsed_result,
1361                                 __rte_unused struct cmdline *cl,
1362                                 __rte_unused void *data)
1363 {
1364         struct cmd_operate_attach_port_result *res = parsed_result;
1365
1366         if (!strcmp(res->keyword, "attach"))
1367                 attach_port(res->identifier);
1368         else
1369                 printf("Unknown parameter\n");
1370 }
1371
1372 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1373         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1374                         port, "port");
1375 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1376         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1377                         keyword, "attach");
1378 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1379         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1380                         identifier, TOKEN_STRING_MULTI);
1381
1382 cmdline_parse_inst_t cmd_operate_attach_port = {
1383         .f = cmd_operate_attach_port_parsed,
1384         .data = NULL,
1385         .help_str = "port attach <identifier>: "
1386                 "(identifier: pci address or virtual dev name)",
1387         .tokens = {
1388                 (void *)&cmd_operate_attach_port_port,
1389                 (void *)&cmd_operate_attach_port_keyword,
1390                 (void *)&cmd_operate_attach_port_identifier,
1391                 NULL,
1392         },
1393 };
1394
1395 /* *** detach a specified port *** */
1396 struct cmd_operate_detach_port_result {
1397         cmdline_fixed_string_t port;
1398         cmdline_fixed_string_t keyword;
1399         portid_t port_id;
1400 };
1401
1402 static void cmd_operate_detach_port_parsed(void *parsed_result,
1403                                 __rte_unused struct cmdline *cl,
1404                                 __rte_unused void *data)
1405 {
1406         struct cmd_operate_detach_port_result *res = parsed_result;
1407
1408         if (!strcmp(res->keyword, "detach")) {
1409                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1410                 detach_port_device(res->port_id);
1411         } else {
1412                 printf("Unknown parameter\n");
1413         }
1414 }
1415
1416 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1417         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1418                         port, "port");
1419 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1420         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1421                         keyword, "detach");
1422 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1423         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1424                         port_id, RTE_UINT16);
1425
1426 cmdline_parse_inst_t cmd_operate_detach_port = {
1427         .f = cmd_operate_detach_port_parsed,
1428         .data = NULL,
1429         .help_str = "port detach <port_id>",
1430         .tokens = {
1431                 (void *)&cmd_operate_detach_port_port,
1432                 (void *)&cmd_operate_detach_port_keyword,
1433                 (void *)&cmd_operate_detach_port_port_id,
1434                 NULL,
1435         },
1436 };
1437
1438 /* *** detach device by identifier *** */
1439 struct cmd_operate_detach_device_result {
1440         cmdline_fixed_string_t device;
1441         cmdline_fixed_string_t keyword;
1442         cmdline_fixed_string_t identifier;
1443 };
1444
1445 static void cmd_operate_detach_device_parsed(void *parsed_result,
1446                                 __rte_unused struct cmdline *cl,
1447                                 __rte_unused void *data)
1448 {
1449         struct cmd_operate_detach_device_result *res = parsed_result;
1450
1451         if (!strcmp(res->keyword, "detach"))
1452                 detach_devargs(res->identifier);
1453         else
1454                 printf("Unknown parameter\n");
1455 }
1456
1457 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1458         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1459                         device, "device");
1460 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1462                         keyword, "detach");
1463 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1464         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1465                         identifier, NULL);
1466
1467 cmdline_parse_inst_t cmd_operate_detach_device = {
1468         .f = cmd_operate_detach_device_parsed,
1469         .data = NULL,
1470         .help_str = "device detach <identifier>:"
1471                 "(identifier: pci address or virtual dev name)",
1472         .tokens = {
1473                 (void *)&cmd_operate_detach_device_device,
1474                 (void *)&cmd_operate_detach_device_keyword,
1475                 (void *)&cmd_operate_detach_device_identifier,
1476                 NULL,
1477         },
1478 };
1479 /* *** configure speed for all ports *** */
1480 struct cmd_config_speed_all {
1481         cmdline_fixed_string_t port;
1482         cmdline_fixed_string_t keyword;
1483         cmdline_fixed_string_t all;
1484         cmdline_fixed_string_t item1;
1485         cmdline_fixed_string_t item2;
1486         cmdline_fixed_string_t value1;
1487         cmdline_fixed_string_t value2;
1488 };
1489
1490 static int
1491 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1492 {
1493
1494         int duplex;
1495
1496         if (!strcmp(duplexstr, "half")) {
1497                 duplex = ETH_LINK_HALF_DUPLEX;
1498         } else if (!strcmp(duplexstr, "full")) {
1499                 duplex = ETH_LINK_FULL_DUPLEX;
1500         } else if (!strcmp(duplexstr, "auto")) {
1501                 duplex = ETH_LINK_FULL_DUPLEX;
1502         } else {
1503                 printf("Unknown duplex parameter\n");
1504                 return -1;
1505         }
1506
1507         if (!strcmp(speedstr, "10")) {
1508                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1509                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1510         } else if (!strcmp(speedstr, "100")) {
1511                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1512                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1513         } else {
1514                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1515                         printf("Invalid speed/duplex parameters\n");
1516                         return -1;
1517                 }
1518                 if (!strcmp(speedstr, "1000")) {
1519                         *speed = ETH_LINK_SPEED_1G;
1520                 } else if (!strcmp(speedstr, "10000")) {
1521                         *speed = ETH_LINK_SPEED_10G;
1522                 } else if (!strcmp(speedstr, "25000")) {
1523                         *speed = ETH_LINK_SPEED_25G;
1524                 } else if (!strcmp(speedstr, "40000")) {
1525                         *speed = ETH_LINK_SPEED_40G;
1526                 } else if (!strcmp(speedstr, "50000")) {
1527                         *speed = ETH_LINK_SPEED_50G;
1528                 } else if (!strcmp(speedstr, "100000")) {
1529                         *speed = ETH_LINK_SPEED_100G;
1530                 } else if (!strcmp(speedstr, "200000")) {
1531                         *speed = ETH_LINK_SPEED_200G;
1532                 } else if (!strcmp(speedstr, "auto")) {
1533                         *speed = ETH_LINK_SPEED_AUTONEG;
1534                 } else {
1535                         printf("Unknown speed parameter\n");
1536                         return -1;
1537                 }
1538         }
1539
1540         if (*speed != ETH_LINK_SPEED_AUTONEG)
1541                 *speed |= ETH_LINK_SPEED_FIXED;
1542
1543         return 0;
1544 }
1545
1546 static void
1547 cmd_config_speed_all_parsed(void *parsed_result,
1548                         __rte_unused struct cmdline *cl,
1549                         __rte_unused void *data)
1550 {
1551         struct cmd_config_speed_all *res = parsed_result;
1552         uint32_t link_speed;
1553         portid_t pid;
1554
1555         if (!all_ports_stopped()) {
1556                 printf("Please stop all ports first\n");
1557                 return;
1558         }
1559
1560         if (parse_and_check_speed_duplex(res->value1, res->value2,
1561                         &link_speed) < 0)
1562                 return;
1563
1564         RTE_ETH_FOREACH_DEV(pid) {
1565                 ports[pid].dev_conf.link_speeds = link_speed;
1566         }
1567
1568         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1569 }
1570
1571 cmdline_parse_token_string_t cmd_config_speed_all_port =
1572         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1573 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1574         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1575                                                         "config");
1576 cmdline_parse_token_string_t cmd_config_speed_all_all =
1577         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1578 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1579         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1580 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1581         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1582                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1583 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1584         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1585 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1586         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1587                                                 "half#full#auto");
1588
1589 cmdline_parse_inst_t cmd_config_speed_all = {
1590         .f = cmd_config_speed_all_parsed,
1591         .data = NULL,
1592         .help_str = "port config all speed "
1593                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1594                                                         "half|full|auto",
1595         .tokens = {
1596                 (void *)&cmd_config_speed_all_port,
1597                 (void *)&cmd_config_speed_all_keyword,
1598                 (void *)&cmd_config_speed_all_all,
1599                 (void *)&cmd_config_speed_all_item1,
1600                 (void *)&cmd_config_speed_all_value1,
1601                 (void *)&cmd_config_speed_all_item2,
1602                 (void *)&cmd_config_speed_all_value2,
1603                 NULL,
1604         },
1605 };
1606
1607 /* *** configure speed for specific port *** */
1608 struct cmd_config_speed_specific {
1609         cmdline_fixed_string_t port;
1610         cmdline_fixed_string_t keyword;
1611         portid_t id;
1612         cmdline_fixed_string_t item1;
1613         cmdline_fixed_string_t item2;
1614         cmdline_fixed_string_t value1;
1615         cmdline_fixed_string_t value2;
1616 };
1617
1618 static void
1619 cmd_config_speed_specific_parsed(void *parsed_result,
1620                                 __rte_unused struct cmdline *cl,
1621                                 __rte_unused void *data)
1622 {
1623         struct cmd_config_speed_specific *res = parsed_result;
1624         uint32_t link_speed;
1625
1626         if (!all_ports_stopped()) {
1627                 printf("Please stop all ports first\n");
1628                 return;
1629         }
1630
1631         if (port_id_is_invalid(res->id, ENABLED_WARN))
1632                 return;
1633
1634         if (parse_and_check_speed_duplex(res->value1, res->value2,
1635                         &link_speed) < 0)
1636                 return;
1637
1638         ports[res->id].dev_conf.link_speeds = link_speed;
1639
1640         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1641 }
1642
1643
1644 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1646                                                                 "port");
1647 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1648         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1649                                                                 "config");
1650 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1651         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1652 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1653         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1654                                                                 "speed");
1655 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1657                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1658 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1660                                                                 "duplex");
1661 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1663                                                         "half#full#auto");
1664
1665 cmdline_parse_inst_t cmd_config_speed_specific = {
1666         .f = cmd_config_speed_specific_parsed,
1667         .data = NULL,
1668         .help_str = "port config <port_id> speed "
1669                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1670                                                         "half|full|auto",
1671         .tokens = {
1672                 (void *)&cmd_config_speed_specific_port,
1673                 (void *)&cmd_config_speed_specific_keyword,
1674                 (void *)&cmd_config_speed_specific_id,
1675                 (void *)&cmd_config_speed_specific_item1,
1676                 (void *)&cmd_config_speed_specific_value1,
1677                 (void *)&cmd_config_speed_specific_item2,
1678                 (void *)&cmd_config_speed_specific_value2,
1679                 NULL,
1680         },
1681 };
1682
1683 /* *** configure loopback for all ports *** */
1684 struct cmd_config_loopback_all {
1685         cmdline_fixed_string_t port;
1686         cmdline_fixed_string_t keyword;
1687         cmdline_fixed_string_t all;
1688         cmdline_fixed_string_t item;
1689         uint32_t mode;
1690 };
1691
1692 static void
1693 cmd_config_loopback_all_parsed(void *parsed_result,
1694                         __rte_unused struct cmdline *cl,
1695                         __rte_unused void *data)
1696 {
1697         struct cmd_config_loopback_all *res = parsed_result;
1698         portid_t pid;
1699
1700         if (!all_ports_stopped()) {
1701                 printf("Please stop all ports first\n");
1702                 return;
1703         }
1704
1705         RTE_ETH_FOREACH_DEV(pid) {
1706                 ports[pid].dev_conf.lpbk_mode = res->mode;
1707         }
1708
1709         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1710 }
1711
1712 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1713         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1714 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1716                                                         "config");
1717 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1719 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1720         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1721                                                         "loopback");
1722 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1723         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1724
1725 cmdline_parse_inst_t cmd_config_loopback_all = {
1726         .f = cmd_config_loopback_all_parsed,
1727         .data = NULL,
1728         .help_str = "port config all loopback <mode>",
1729         .tokens = {
1730                 (void *)&cmd_config_loopback_all_port,
1731                 (void *)&cmd_config_loopback_all_keyword,
1732                 (void *)&cmd_config_loopback_all_all,
1733                 (void *)&cmd_config_loopback_all_item,
1734                 (void *)&cmd_config_loopback_all_mode,
1735                 NULL,
1736         },
1737 };
1738
1739 /* *** configure loopback for specific port *** */
1740 struct cmd_config_loopback_specific {
1741         cmdline_fixed_string_t port;
1742         cmdline_fixed_string_t keyword;
1743         uint16_t port_id;
1744         cmdline_fixed_string_t item;
1745         uint32_t mode;
1746 };
1747
1748 static void
1749 cmd_config_loopback_specific_parsed(void *parsed_result,
1750                                 __rte_unused struct cmdline *cl,
1751                                 __rte_unused void *data)
1752 {
1753         struct cmd_config_loopback_specific *res = parsed_result;
1754
1755         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1756                 return;
1757
1758         if (!port_is_stopped(res->port_id)) {
1759                 printf("Please stop port %u first\n", res->port_id);
1760                 return;
1761         }
1762
1763         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1764
1765         cmd_reconfig_device_queue(res->port_id, 1, 1);
1766 }
1767
1768
1769 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1770         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1771                                                                 "port");
1772 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1773         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1774                                                                 "config");
1775 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1776         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1777                                                                 RTE_UINT16);
1778 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1779         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1780                                                                 "loopback");
1781 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1782         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1783                               RTE_UINT32);
1784
1785 cmdline_parse_inst_t cmd_config_loopback_specific = {
1786         .f = cmd_config_loopback_specific_parsed,
1787         .data = NULL,
1788         .help_str = "port config <port_id> loopback <mode>",
1789         .tokens = {
1790                 (void *)&cmd_config_loopback_specific_port,
1791                 (void *)&cmd_config_loopback_specific_keyword,
1792                 (void *)&cmd_config_loopback_specific_id,
1793                 (void *)&cmd_config_loopback_specific_item,
1794                 (void *)&cmd_config_loopback_specific_mode,
1795                 NULL,
1796         },
1797 };
1798
1799 /* *** configure txq/rxq, txd/rxd *** */
1800 struct cmd_config_rx_tx {
1801         cmdline_fixed_string_t port;
1802         cmdline_fixed_string_t keyword;
1803         cmdline_fixed_string_t all;
1804         cmdline_fixed_string_t name;
1805         uint16_t value;
1806 };
1807
1808 static void
1809 cmd_config_rx_tx_parsed(void *parsed_result,
1810                         __rte_unused struct cmdline *cl,
1811                         __rte_unused void *data)
1812 {
1813         struct cmd_config_rx_tx *res = parsed_result;
1814
1815         if (!all_ports_stopped()) {
1816                 printf("Please stop all ports first\n");
1817                 return;
1818         }
1819         if (!strcmp(res->name, "rxq")) {
1820                 if (!res->value && !nb_txq) {
1821                         printf("Warning: Either rx or tx queues should be non zero\n");
1822                         return;
1823                 }
1824                 if (check_nb_rxq(res->value) != 0)
1825                         return;
1826                 nb_rxq = res->value;
1827         }
1828         else if (!strcmp(res->name, "txq")) {
1829                 if (!res->value && !nb_rxq) {
1830                         printf("Warning: Either rx or tx queues should be non zero\n");
1831                         return;
1832                 }
1833                 if (check_nb_txq(res->value) != 0)
1834                         return;
1835                 nb_txq = res->value;
1836         }
1837         else if (!strcmp(res->name, "rxd")) {
1838                 if (check_nb_rxd(res->value) != 0)
1839                         return;
1840                 nb_rxd = res->value;
1841         } else if (!strcmp(res->name, "txd")) {
1842                 if (check_nb_txd(res->value) != 0)
1843                         return;
1844
1845                 nb_txd = res->value;
1846         } else {
1847                 printf("Unknown parameter\n");
1848                 return;
1849         }
1850
1851         fwd_config_setup();
1852
1853         init_port_config();
1854
1855         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1856 }
1857
1858 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1859         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1860 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1862 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1864 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1865         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1866                                                 "rxq#txq#rxd#txd");
1867 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1868         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1869
1870 cmdline_parse_inst_t cmd_config_rx_tx = {
1871         .f = cmd_config_rx_tx_parsed,
1872         .data = NULL,
1873         .help_str = "port config all rxq|txq|rxd|txd <value>",
1874         .tokens = {
1875                 (void *)&cmd_config_rx_tx_port,
1876                 (void *)&cmd_config_rx_tx_keyword,
1877                 (void *)&cmd_config_rx_tx_all,
1878                 (void *)&cmd_config_rx_tx_name,
1879                 (void *)&cmd_config_rx_tx_value,
1880                 NULL,
1881         },
1882 };
1883
1884 /* *** config max packet length *** */
1885 struct cmd_config_max_pkt_len_result {
1886         cmdline_fixed_string_t port;
1887         cmdline_fixed_string_t keyword;
1888         cmdline_fixed_string_t all;
1889         cmdline_fixed_string_t name;
1890         uint32_t value;
1891 };
1892
1893 static void
1894 cmd_config_max_pkt_len_parsed(void *parsed_result,
1895                                 __rte_unused struct cmdline *cl,
1896                                 __rte_unused void *data)
1897 {
1898         struct cmd_config_max_pkt_len_result *res = parsed_result;
1899         uint32_t max_rx_pkt_len_backup = 0;
1900         portid_t pid;
1901         int ret;
1902
1903         if (!all_ports_stopped()) {
1904                 printf("Please stop all ports first\n");
1905                 return;
1906         }
1907
1908         RTE_ETH_FOREACH_DEV(pid) {
1909                 struct rte_port *port = &ports[pid];
1910
1911                 if (!strcmp(res->name, "max-pkt-len")) {
1912                         if (res->value < RTE_ETHER_MIN_LEN) {
1913                                 printf("max-pkt-len can not be less than %d\n",
1914                                                 RTE_ETHER_MIN_LEN);
1915                                 return;
1916                         }
1917                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1918                                 return;
1919
1920                         ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1921                         if (ret != 0) {
1922                                 printf("rte_eth_dev_info_get() failed for port %u\n",
1923                                         pid);
1924                                 return;
1925                         }
1926
1927                         max_rx_pkt_len_backup = port->dev_conf.rxmode.max_rx_pkt_len;
1928
1929                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1930                         if (update_jumbo_frame_offload(pid) != 0)
1931                                 port->dev_conf.rxmode.max_rx_pkt_len = max_rx_pkt_len_backup;
1932                 } else {
1933                         printf("Unknown parameter\n");
1934                         return;
1935                 }
1936         }
1937
1938         init_port_config();
1939
1940         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1941 }
1942
1943 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1944         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1945                                                                 "port");
1946 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1947         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1948                                                                 "config");
1949 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1950         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1951                                                                 "all");
1952 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1954                                                                 "max-pkt-len");
1955 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1956         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1957                                                                 RTE_UINT32);
1958
1959 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1960         .f = cmd_config_max_pkt_len_parsed,
1961         .data = NULL,
1962         .help_str = "port config all max-pkt-len <value>",
1963         .tokens = {
1964                 (void *)&cmd_config_max_pkt_len_port,
1965                 (void *)&cmd_config_max_pkt_len_keyword,
1966                 (void *)&cmd_config_max_pkt_len_all,
1967                 (void *)&cmd_config_max_pkt_len_name,
1968                 (void *)&cmd_config_max_pkt_len_value,
1969                 NULL,
1970         },
1971 };
1972
1973 /* *** config max LRO aggregated packet size *** */
1974 struct cmd_config_max_lro_pkt_size_result {
1975         cmdline_fixed_string_t port;
1976         cmdline_fixed_string_t keyword;
1977         cmdline_fixed_string_t all;
1978         cmdline_fixed_string_t name;
1979         uint32_t value;
1980 };
1981
1982 static void
1983 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1984                                 __rte_unused struct cmdline *cl,
1985                                 __rte_unused void *data)
1986 {
1987         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1988         portid_t pid;
1989
1990         if (!all_ports_stopped()) {
1991                 printf("Please stop all ports first\n");
1992                 return;
1993         }
1994
1995         RTE_ETH_FOREACH_DEV(pid) {
1996                 struct rte_port *port = &ports[pid];
1997
1998                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1999                         if (res->value ==
2000                                         port->dev_conf.rxmode.max_lro_pkt_size)
2001                                 return;
2002
2003                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2004                 } else {
2005                         printf("Unknown parameter\n");
2006                         return;
2007                 }
2008         }
2009
2010         init_port_config();
2011
2012         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2013 }
2014
2015 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2016         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2017                                  port, "port");
2018 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2019         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2020                                  keyword, "config");
2021 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2022         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2023                                  all, "all");
2024 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2025         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2026                                  name, "max-lro-pkt-size");
2027 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2028         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2029                               value, RTE_UINT32);
2030
2031 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2032         .f = cmd_config_max_lro_pkt_size_parsed,
2033         .data = NULL,
2034         .help_str = "port config all max-lro-pkt-size <value>",
2035         .tokens = {
2036                 (void *)&cmd_config_max_lro_pkt_size_port,
2037                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2038                 (void *)&cmd_config_max_lro_pkt_size_all,
2039                 (void *)&cmd_config_max_lro_pkt_size_name,
2040                 (void *)&cmd_config_max_lro_pkt_size_value,
2041                 NULL,
2042         },
2043 };
2044
2045 /* *** configure port MTU *** */
2046 struct cmd_config_mtu_result {
2047         cmdline_fixed_string_t port;
2048         cmdline_fixed_string_t keyword;
2049         cmdline_fixed_string_t mtu;
2050         portid_t port_id;
2051         uint16_t value;
2052 };
2053
2054 static void
2055 cmd_config_mtu_parsed(void *parsed_result,
2056                       __rte_unused struct cmdline *cl,
2057                       __rte_unused void *data)
2058 {
2059         struct cmd_config_mtu_result *res = parsed_result;
2060
2061         if (res->value < RTE_ETHER_MIN_LEN) {
2062                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2063                 return;
2064         }
2065         port_mtu_set(res->port_id, res->value);
2066 }
2067
2068 cmdline_parse_token_string_t cmd_config_mtu_port =
2069         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2070                                  "port");
2071 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2073                                  "config");
2074 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2075         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2076                                  "mtu");
2077 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2078         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2079                                  RTE_UINT16);
2080 cmdline_parse_token_num_t cmd_config_mtu_value =
2081         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2082                                  RTE_UINT16);
2083
2084 cmdline_parse_inst_t cmd_config_mtu = {
2085         .f = cmd_config_mtu_parsed,
2086         .data = NULL,
2087         .help_str = "port config mtu <port_id> <value>",
2088         .tokens = {
2089                 (void *)&cmd_config_mtu_port,
2090                 (void *)&cmd_config_mtu_keyword,
2091                 (void *)&cmd_config_mtu_mtu,
2092                 (void *)&cmd_config_mtu_port_id,
2093                 (void *)&cmd_config_mtu_value,
2094                 NULL,
2095         },
2096 };
2097
2098 /* *** configure rx mode *** */
2099 struct cmd_config_rx_mode_flag {
2100         cmdline_fixed_string_t port;
2101         cmdline_fixed_string_t keyword;
2102         cmdline_fixed_string_t all;
2103         cmdline_fixed_string_t name;
2104         cmdline_fixed_string_t value;
2105 };
2106
2107 static void
2108 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2109                                 __rte_unused struct cmdline *cl,
2110                                 __rte_unused void *data)
2111 {
2112         struct cmd_config_rx_mode_flag *res = parsed_result;
2113
2114         if (!all_ports_stopped()) {
2115                 printf("Please stop all ports first\n");
2116                 return;
2117         }
2118
2119         if (!strcmp(res->name, "drop-en")) {
2120                 if (!strcmp(res->value, "on"))
2121                         rx_drop_en = 1;
2122                 else if (!strcmp(res->value, "off"))
2123                         rx_drop_en = 0;
2124                 else {
2125                         printf("Unknown parameter\n");
2126                         return;
2127                 }
2128         } else {
2129                 printf("Unknown parameter\n");
2130                 return;
2131         }
2132
2133         init_port_config();
2134
2135         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2136 }
2137
2138 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2140 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2141         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2142                                                                 "config");
2143 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2144         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2145 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2146         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2147                                         "drop-en");
2148 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2150                                                         "on#off");
2151
2152 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2153         .f = cmd_config_rx_mode_flag_parsed,
2154         .data = NULL,
2155         .help_str = "port config all drop-en on|off",
2156         .tokens = {
2157                 (void *)&cmd_config_rx_mode_flag_port,
2158                 (void *)&cmd_config_rx_mode_flag_keyword,
2159                 (void *)&cmd_config_rx_mode_flag_all,
2160                 (void *)&cmd_config_rx_mode_flag_name,
2161                 (void *)&cmd_config_rx_mode_flag_value,
2162                 NULL,
2163         },
2164 };
2165
2166 /* *** configure rss *** */
2167 struct cmd_config_rss {
2168         cmdline_fixed_string_t port;
2169         cmdline_fixed_string_t keyword;
2170         cmdline_fixed_string_t all;
2171         cmdline_fixed_string_t name;
2172         cmdline_fixed_string_t value;
2173 };
2174
2175 static void
2176 cmd_config_rss_parsed(void *parsed_result,
2177                         __rte_unused struct cmdline *cl,
2178                         __rte_unused void *data)
2179 {
2180         struct cmd_config_rss *res = parsed_result;
2181         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2182         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2183         int use_default = 0;
2184         int all_updated = 1;
2185         int diag;
2186         uint16_t i;
2187         int ret;
2188
2189         if (!strcmp(res->value, "all"))
2190                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2191                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2192                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2193                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2194                         ETH_RSS_ECPRI;
2195         else if (!strcmp(res->value, "eth"))
2196                 rss_conf.rss_hf = ETH_RSS_ETH;
2197         else if (!strcmp(res->value, "vlan"))
2198                 rss_conf.rss_hf = ETH_RSS_VLAN;
2199         else if (!strcmp(res->value, "ip"))
2200                 rss_conf.rss_hf = ETH_RSS_IP;
2201         else if (!strcmp(res->value, "udp"))
2202                 rss_conf.rss_hf = ETH_RSS_UDP;
2203         else if (!strcmp(res->value, "tcp"))
2204                 rss_conf.rss_hf = ETH_RSS_TCP;
2205         else if (!strcmp(res->value, "sctp"))
2206                 rss_conf.rss_hf = ETH_RSS_SCTP;
2207         else if (!strcmp(res->value, "ether"))
2208                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2209         else if (!strcmp(res->value, "port"))
2210                 rss_conf.rss_hf = ETH_RSS_PORT;
2211         else if (!strcmp(res->value, "vxlan"))
2212                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2213         else if (!strcmp(res->value, "geneve"))
2214                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2215         else if (!strcmp(res->value, "nvgre"))
2216                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2217         else if (!strcmp(res->value, "l3-pre32"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2219         else if (!strcmp(res->value, "l3-pre40"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2221         else if (!strcmp(res->value, "l3-pre48"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2223         else if (!strcmp(res->value, "l3-pre56"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2225         else if (!strcmp(res->value, "l3-pre64"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2227         else if (!strcmp(res->value, "l3-pre96"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2229         else if (!strcmp(res->value, "l3-src-only"))
2230                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2231         else if (!strcmp(res->value, "l3-dst-only"))
2232                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2233         else if (!strcmp(res->value, "l4-src-only"))
2234                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2235         else if (!strcmp(res->value, "l4-dst-only"))
2236                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2237         else if (!strcmp(res->value, "l2-src-only"))
2238                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2239         else if (!strcmp(res->value, "l2-dst-only"))
2240                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2241         else if (!strcmp(res->value, "l2tpv3"))
2242                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2243         else if (!strcmp(res->value, "esp"))
2244                 rss_conf.rss_hf = ETH_RSS_ESP;
2245         else if (!strcmp(res->value, "ah"))
2246                 rss_conf.rss_hf = ETH_RSS_AH;
2247         else if (!strcmp(res->value, "pfcp"))
2248                 rss_conf.rss_hf = ETH_RSS_PFCP;
2249         else if (!strcmp(res->value, "pppoe"))
2250                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2251         else if (!strcmp(res->value, "gtpu"))
2252                 rss_conf.rss_hf = ETH_RSS_GTPU;
2253         else if (!strcmp(res->value, "ecpri"))
2254                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2255         else if (!strcmp(res->value, "mpls"))
2256                 rss_conf.rss_hf = ETH_RSS_MPLS;
2257         else if (!strcmp(res->value, "none"))
2258                 rss_conf.rss_hf = 0;
2259         else if (!strcmp(res->value, "level-default")) {
2260                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2261                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2262         } else if (!strcmp(res->value, "level-outer")) {
2263                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2264                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2265         } else if (!strcmp(res->value, "level-inner")) {
2266                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2267                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2268         } else if (!strcmp(res->value, "default"))
2269                 use_default = 1;
2270         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2271                                                 atoi(res->value) < 64)
2272                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2273         else {
2274                 printf("Unknown parameter\n");
2275                 return;
2276         }
2277         rss_conf.rss_key = NULL;
2278         /* Update global configuration for RSS types. */
2279         RTE_ETH_FOREACH_DEV(i) {
2280                 struct rte_eth_rss_conf local_rss_conf;
2281
2282                 ret = eth_dev_info_get_print_err(i, &dev_info);
2283                 if (ret != 0)
2284                         return;
2285
2286                 if (use_default)
2287                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2288
2289                 local_rss_conf = rss_conf;
2290                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2291                         dev_info.flow_type_rss_offloads;
2292                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2293                         printf("Port %u modified RSS hash function based on hardware support,"
2294                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2295                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2296                 }
2297                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2298                 if (diag < 0) {
2299                         all_updated = 0;
2300                         printf("Configuration of RSS hash at ethernet port %d "
2301                                 "failed with error (%d): %s.\n",
2302                                 i, -diag, strerror(-diag));
2303                 }
2304         }
2305         if (all_updated && !use_default) {
2306                 rss_hf = rss_conf.rss_hf;
2307                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2308         }
2309 }
2310
2311 cmdline_parse_token_string_t cmd_config_rss_port =
2312         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2313 cmdline_parse_token_string_t cmd_config_rss_keyword =
2314         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2315 cmdline_parse_token_string_t cmd_config_rss_all =
2316         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2317 cmdline_parse_token_string_t cmd_config_rss_name =
2318         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2319 cmdline_parse_token_string_t cmd_config_rss_value =
2320         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2321
2322 cmdline_parse_inst_t cmd_config_rss = {
2323         .f = cmd_config_rss_parsed,
2324         .data = NULL,
2325         .help_str = "port config all rss "
2326                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2327                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2328                 "level-outer|level-inner|<flowtype_id>",
2329         .tokens = {
2330                 (void *)&cmd_config_rss_port,
2331                 (void *)&cmd_config_rss_keyword,
2332                 (void *)&cmd_config_rss_all,
2333                 (void *)&cmd_config_rss_name,
2334                 (void *)&cmd_config_rss_value,
2335                 NULL,
2336         },
2337 };
2338
2339 /* *** configure rss hash key *** */
2340 struct cmd_config_rss_hash_key {
2341         cmdline_fixed_string_t port;
2342         cmdline_fixed_string_t config;
2343         portid_t port_id;
2344         cmdline_fixed_string_t rss_hash_key;
2345         cmdline_fixed_string_t rss_type;
2346         cmdline_fixed_string_t key;
2347 };
2348
2349 static uint8_t
2350 hexa_digit_to_value(char hexa_digit)
2351 {
2352         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2353                 return (uint8_t) (hexa_digit - '0');
2354         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2355                 return (uint8_t) ((hexa_digit - 'a') + 10);
2356         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2357                 return (uint8_t) ((hexa_digit - 'A') + 10);
2358         /* Invalid hexa digit */
2359         return 0xFF;
2360 }
2361
2362 static uint8_t
2363 parse_and_check_key_hexa_digit(char *key, int idx)
2364 {
2365         uint8_t hexa_v;
2366
2367         hexa_v = hexa_digit_to_value(key[idx]);
2368         if (hexa_v == 0xFF)
2369                 printf("invalid key: character %c at position %d is not a "
2370                        "valid hexa digit\n", key[idx], idx);
2371         return hexa_v;
2372 }
2373
2374 static void
2375 cmd_config_rss_hash_key_parsed(void *parsed_result,
2376                                __rte_unused struct cmdline *cl,
2377                                __rte_unused void *data)
2378 {
2379         struct cmd_config_rss_hash_key *res = parsed_result;
2380         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2381         uint8_t xdgt0;
2382         uint8_t xdgt1;
2383         int i;
2384         struct rte_eth_dev_info dev_info;
2385         uint8_t hash_key_size;
2386         uint32_t key_len;
2387         int ret;
2388
2389         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2390         if (ret != 0)
2391                 return;
2392
2393         if (dev_info.hash_key_size > 0 &&
2394                         dev_info.hash_key_size <= sizeof(hash_key))
2395                 hash_key_size = dev_info.hash_key_size;
2396         else {
2397                 printf("dev_info did not provide a valid hash key size\n");
2398                 return;
2399         }
2400         /* Check the length of the RSS hash key */
2401         key_len = strlen(res->key);
2402         if (key_len != (hash_key_size * 2)) {
2403                 printf("key length: %d invalid - key must be a string of %d"
2404                            " hexa-decimal numbers\n",
2405                            (int) key_len, hash_key_size * 2);
2406                 return;
2407         }
2408         /* Translate RSS hash key into binary representation */
2409         for (i = 0; i < hash_key_size; i++) {
2410                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2411                 if (xdgt0 == 0xFF)
2412                         return;
2413                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2414                 if (xdgt1 == 0xFF)
2415                         return;
2416                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2417         }
2418         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2419                         hash_key_size);
2420 }
2421
2422 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2423         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2424 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2425         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2426                                  "config");
2427 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2428         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2429                                  RTE_UINT16);
2430 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2432                                  rss_hash_key, "rss-hash-key");
2433 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2434         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2435                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2436                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2437                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2438                                  "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 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2443         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2444
2445 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2446         .f = cmd_config_rss_hash_key_parsed,
2447         .data = NULL,
2448         .help_str = "port config <port_id> rss-hash-key "
2449                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2450                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2451                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2452                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2453                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2454                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2455                 "<string of hex digits (variable length, NIC dependent)>",
2456         .tokens = {
2457                 (void *)&cmd_config_rss_hash_key_port,
2458                 (void *)&cmd_config_rss_hash_key_config,
2459                 (void *)&cmd_config_rss_hash_key_port_id,
2460                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2461                 (void *)&cmd_config_rss_hash_key_rss_type,
2462                 (void *)&cmd_config_rss_hash_key_value,
2463                 NULL,
2464         },
2465 };
2466
2467 /* *** cleanup txq mbufs *** */
2468 struct cmd_cleanup_txq_mbufs_result {
2469         cmdline_fixed_string_t port;
2470         cmdline_fixed_string_t keyword;
2471         cmdline_fixed_string_t name;
2472         uint16_t port_id;
2473         uint16_t queue_id;
2474         uint32_t free_cnt;
2475 };
2476
2477 static void
2478 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2479                              __rte_unused struct cmdline *cl,
2480                              __rte_unused void *data)
2481 {
2482         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2483         uint16_t port_id = res->port_id;
2484         uint16_t queue_id = res->queue_id;
2485         uint32_t free_cnt = res->free_cnt;
2486         struct rte_eth_txq_info qinfo;
2487         int ret;
2488
2489         if (test_done == 0) {
2490                 printf("Please stop forwarding first\n");
2491                 return;
2492         }
2493
2494         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2495                 printf("Failed to get port %u Tx queue %u info\n",
2496                        port_id, queue_id);
2497                 return;
2498         }
2499
2500         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2501                 printf("Tx queue %u not started\n", queue_id);
2502                 return;
2503         }
2504
2505         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2506         if (ret < 0) {
2507                 printf("Failed to cleanup mbuf for port %u Tx queue %u "
2508                        "error desc: %s(%d)\n",
2509                        port_id, queue_id, strerror(-ret), ret);
2510                 return;
2511         }
2512
2513         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2514                port_id, queue_id, ret);
2515 }
2516
2517 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2518         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2519                                  "port");
2520 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2521         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2522                                  "cleanup");
2523 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2524         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2525                               RTE_UINT16);
2526 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2527         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2528                                  "txq");
2529 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2530         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2531                               RTE_UINT16);
2532 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2533         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2534                               RTE_UINT32);
2535
2536 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2537         .f = cmd_cleanup_txq_mbufs_parsed,
2538         .data = NULL,
2539         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2540         .tokens = {
2541                 (void *)&cmd_cleanup_txq_mbufs_port,
2542                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2543                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2544                 (void *)&cmd_cleanup_txq_mbufs_txq,
2545                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2546                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2547                 NULL,
2548         },
2549 };
2550
2551 /* *** configure port rxq/txq ring size *** */
2552 struct cmd_config_rxtx_ring_size {
2553         cmdline_fixed_string_t port;
2554         cmdline_fixed_string_t config;
2555         portid_t portid;
2556         cmdline_fixed_string_t rxtxq;
2557         uint16_t qid;
2558         cmdline_fixed_string_t rsize;
2559         uint16_t size;
2560 };
2561
2562 static void
2563 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2564                                  __rte_unused struct cmdline *cl,
2565                                  __rte_unused void *data)
2566 {
2567         struct cmd_config_rxtx_ring_size *res = parsed_result;
2568         struct rte_port *port;
2569         uint8_t isrx;
2570
2571         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2572                 return;
2573
2574         if (res->portid == (portid_t)RTE_PORT_ALL) {
2575                 printf("Invalid port id\n");
2576                 return;
2577         }
2578
2579         port = &ports[res->portid];
2580
2581         if (!strcmp(res->rxtxq, "rxq"))
2582                 isrx = 1;
2583         else if (!strcmp(res->rxtxq, "txq"))
2584                 isrx = 0;
2585         else {
2586                 printf("Unknown parameter\n");
2587                 return;
2588         }
2589
2590         if (isrx && rx_queue_id_is_invalid(res->qid))
2591                 return;
2592         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2593                 return;
2594
2595         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2596                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2597                        rx_free_thresh);
2598                 return;
2599         }
2600
2601         if (isrx)
2602                 port->nb_rx_desc[res->qid] = res->size;
2603         else
2604                 port->nb_tx_desc[res->qid] = res->size;
2605
2606         cmd_reconfig_device_queue(res->portid, 0, 1);
2607 }
2608
2609 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2610         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2611                                  port, "port");
2612 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2613         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2614                                  config, "config");
2615 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2616         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2617                                  portid, RTE_UINT16);
2618 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2619         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2620                                  rxtxq, "rxq#txq");
2621 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2622         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2623                               qid, RTE_UINT16);
2624 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2625         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2626                                  rsize, "ring_size");
2627 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2628         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2629                               size, RTE_UINT16);
2630
2631 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2632         .f = cmd_config_rxtx_ring_size_parsed,
2633         .data = NULL,
2634         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2635         .tokens = {
2636                 (void *)&cmd_config_rxtx_ring_size_port,
2637                 (void *)&cmd_config_rxtx_ring_size_config,
2638                 (void *)&cmd_config_rxtx_ring_size_portid,
2639                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2640                 (void *)&cmd_config_rxtx_ring_size_qid,
2641                 (void *)&cmd_config_rxtx_ring_size_rsize,
2642                 (void *)&cmd_config_rxtx_ring_size_size,
2643                 NULL,
2644         },
2645 };
2646
2647 /* *** configure port rxq/txq start/stop *** */
2648 struct cmd_config_rxtx_queue {
2649         cmdline_fixed_string_t port;
2650         portid_t portid;
2651         cmdline_fixed_string_t rxtxq;
2652         uint16_t qid;
2653         cmdline_fixed_string_t opname;
2654 };
2655
2656 static void
2657 cmd_config_rxtx_queue_parsed(void *parsed_result,
2658                         __rte_unused struct cmdline *cl,
2659                         __rte_unused void *data)
2660 {
2661         struct cmd_config_rxtx_queue *res = parsed_result;
2662         uint8_t isrx;
2663         uint8_t isstart;
2664         int ret = 0;
2665
2666         if (test_done == 0) {
2667                 printf("Please stop forwarding first\n");
2668                 return;
2669         }
2670
2671         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2672                 return;
2673
2674         if (port_is_started(res->portid) != 1) {
2675                 printf("Please start port %u first\n", res->portid);
2676                 return;
2677         }
2678
2679         if (!strcmp(res->rxtxq, "rxq"))
2680                 isrx = 1;
2681         else if (!strcmp(res->rxtxq, "txq"))
2682                 isrx = 0;
2683         else {
2684                 printf("Unknown parameter\n");
2685                 return;
2686         }
2687
2688         if (isrx && rx_queue_id_is_invalid(res->qid))
2689                 return;
2690         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2691                 return;
2692
2693         if (!strcmp(res->opname, "start"))
2694                 isstart = 1;
2695         else if (!strcmp(res->opname, "stop"))
2696                 isstart = 0;
2697         else {
2698                 printf("Unknown parameter\n");
2699                 return;
2700         }
2701
2702         if (isstart && isrx)
2703                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2704         else if (!isstart && isrx)
2705                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2706         else if (isstart && !isrx)
2707                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2708         else
2709                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2710
2711         if (ret == -ENOTSUP)
2712                 printf("Function not supported in PMD driver\n");
2713 }
2714
2715 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2716         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2717 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2718         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2719 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2720         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2721 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2722         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2723 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2724         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2725                                                 "start#stop");
2726
2727 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2728         .f = cmd_config_rxtx_queue_parsed,
2729         .data = NULL,
2730         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2731         .tokens = {
2732                 (void *)&cmd_config_rxtx_queue_port,
2733                 (void *)&cmd_config_rxtx_queue_portid,
2734                 (void *)&cmd_config_rxtx_queue_rxtxq,
2735                 (void *)&cmd_config_rxtx_queue_qid,
2736                 (void *)&cmd_config_rxtx_queue_opname,
2737                 NULL,
2738         },
2739 };
2740
2741 /* *** configure port rxq/txq deferred start on/off *** */
2742 struct cmd_config_deferred_start_rxtx_queue {
2743         cmdline_fixed_string_t port;
2744         portid_t port_id;
2745         cmdline_fixed_string_t rxtxq;
2746         uint16_t qid;
2747         cmdline_fixed_string_t opname;
2748         cmdline_fixed_string_t state;
2749 };
2750
2751 static void
2752 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2753                         __rte_unused struct cmdline *cl,
2754                         __rte_unused void *data)
2755 {
2756         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2757         struct rte_port *port;
2758         uint8_t isrx;
2759         uint8_t ison;
2760         uint8_t needreconfig = 0;
2761
2762         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2763                 return;
2764
2765         if (port_is_started(res->port_id) != 0) {
2766                 printf("Please stop port %u first\n", res->port_id);
2767                 return;
2768         }
2769
2770         port = &ports[res->port_id];
2771
2772         isrx = !strcmp(res->rxtxq, "rxq");
2773
2774         if (isrx && rx_queue_id_is_invalid(res->qid))
2775                 return;
2776         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2777                 return;
2778
2779         ison = !strcmp(res->state, "on");
2780
2781         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2782                 port->rx_conf[res->qid].rx_deferred_start = ison;
2783                 needreconfig = 1;
2784         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2785                 port->tx_conf[res->qid].tx_deferred_start = ison;
2786                 needreconfig = 1;
2787         }
2788
2789         if (needreconfig)
2790                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2791 }
2792
2793 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2794         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2795                                                 port, "port");
2796 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2797         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2798                                                 port_id, RTE_UINT16);
2799 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2800         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2801                                                 rxtxq, "rxq#txq");
2802 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2803         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2804                                                 qid, RTE_UINT16);
2805 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2806         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2807                                                 opname, "deferred_start");
2808 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2809         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2810                                                 state, "on#off");
2811
2812 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2813         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2814         .data = NULL,
2815         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2816         .tokens = {
2817                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2818                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2819                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2820                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2821                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2822                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2823                 NULL,
2824         },
2825 };
2826
2827 /* *** configure port rxq/txq setup *** */
2828 struct cmd_setup_rxtx_queue {
2829         cmdline_fixed_string_t port;
2830         portid_t portid;
2831         cmdline_fixed_string_t rxtxq;
2832         uint16_t qid;
2833         cmdline_fixed_string_t setup;
2834 };
2835
2836 /* Common CLI fields for queue setup */
2837 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2838         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2839 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2840         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2841 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2842         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2843 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2844         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2845 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2846         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2847
2848 static void
2849 cmd_setup_rxtx_queue_parsed(
2850         void *parsed_result,
2851         __rte_unused struct cmdline *cl,
2852         __rte_unused void *data)
2853 {
2854         struct cmd_setup_rxtx_queue *res = parsed_result;
2855         struct rte_port *port;
2856         struct rte_mempool *mp;
2857         unsigned int socket_id;
2858         uint8_t isrx = 0;
2859         int ret;
2860
2861         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2862                 return;
2863
2864         if (res->portid == (portid_t)RTE_PORT_ALL) {
2865                 printf("Invalid port id\n");
2866                 return;
2867         }
2868
2869         if (!strcmp(res->rxtxq, "rxq"))
2870                 isrx = 1;
2871         else if (!strcmp(res->rxtxq, "txq"))
2872                 isrx = 0;
2873         else {
2874                 printf("Unknown parameter\n");
2875                 return;
2876         }
2877
2878         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2879                 printf("Invalid rx queue\n");
2880                 return;
2881         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2882                 printf("Invalid tx queue\n");
2883                 return;
2884         }
2885
2886         port = &ports[res->portid];
2887         if (isrx) {
2888                 socket_id = rxring_numa[res->portid];
2889                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2890                         socket_id = port->socket_id;
2891
2892                 mp = mbuf_pool_find(socket_id, 0);
2893                 if (mp == NULL) {
2894                         printf("Failed to setup RX queue: "
2895                                 "No mempool allocation"
2896                                 " on the socket %d\n",
2897                                 rxring_numa[res->portid]);
2898                         return;
2899                 }
2900                 ret = rx_queue_setup(res->portid,
2901                                      res->qid,
2902                                      port->nb_rx_desc[res->qid],
2903                                      socket_id,
2904                                      &port->rx_conf[res->qid],
2905                                      mp);
2906                 if (ret)
2907                         printf("Failed to setup RX queue\n");
2908         } else {
2909                 socket_id = txring_numa[res->portid];
2910                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2911                         socket_id = port->socket_id;
2912
2913                 ret = rte_eth_tx_queue_setup(res->portid,
2914                                              res->qid,
2915                                              port->nb_tx_desc[res->qid],
2916                                              socket_id,
2917                                              &port->tx_conf[res->qid]);
2918                 if (ret)
2919                         printf("Failed to setup TX queue\n");
2920         }
2921 }
2922
2923 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2924         .f = cmd_setup_rxtx_queue_parsed,
2925         .data = NULL,
2926         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2927         .tokens = {
2928                 (void *)&cmd_setup_rxtx_queue_port,
2929                 (void *)&cmd_setup_rxtx_queue_portid,
2930                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2931                 (void *)&cmd_setup_rxtx_queue_qid,
2932                 (void *)&cmd_setup_rxtx_queue_setup,
2933                 NULL,
2934         },
2935 };
2936
2937
2938 /* *** Configure RSS RETA *** */
2939 struct cmd_config_rss_reta {
2940         cmdline_fixed_string_t port;
2941         cmdline_fixed_string_t keyword;
2942         portid_t port_id;
2943         cmdline_fixed_string_t name;
2944         cmdline_fixed_string_t list_name;
2945         cmdline_fixed_string_t list_of_items;
2946 };
2947
2948 static int
2949 parse_reta_config(const char *str,
2950                   struct rte_eth_rss_reta_entry64 *reta_conf,
2951                   uint16_t nb_entries)
2952 {
2953         int i;
2954         unsigned size;
2955         uint16_t hash_index, idx, shift;
2956         uint16_t nb_queue;
2957         char s[256];
2958         const char *p, *p0 = str;
2959         char *end;
2960         enum fieldnames {
2961                 FLD_HASH_INDEX = 0,
2962                 FLD_QUEUE,
2963                 _NUM_FLD
2964         };
2965         unsigned long int_fld[_NUM_FLD];
2966         char *str_fld[_NUM_FLD];
2967
2968         while ((p = strchr(p0,'(')) != NULL) {
2969                 ++p;
2970                 if((p0 = strchr(p,')')) == NULL)
2971                         return -1;
2972
2973                 size = p0 - p;
2974                 if(size >= sizeof(s))
2975                         return -1;
2976
2977                 snprintf(s, sizeof(s), "%.*s", size, p);
2978                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2979                         return -1;
2980                 for (i = 0; i < _NUM_FLD; i++) {
2981                         errno = 0;
2982                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2983                         if (errno != 0 || end == str_fld[i] ||
2984                                         int_fld[i] > 65535)
2985                                 return -1;
2986                 }
2987
2988                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2989                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2990
2991                 if (hash_index >= nb_entries) {
2992                         printf("Invalid RETA hash index=%d\n", hash_index);
2993                         return -1;
2994                 }
2995
2996                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2997                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2998                 reta_conf[idx].mask |= (1ULL << shift);
2999                 reta_conf[idx].reta[shift] = nb_queue;
3000         }
3001
3002         return 0;
3003 }
3004
3005 static void
3006 cmd_set_rss_reta_parsed(void *parsed_result,
3007                         __rte_unused struct cmdline *cl,
3008                         __rte_unused void *data)
3009 {
3010         int ret;
3011         struct rte_eth_dev_info dev_info;
3012         struct rte_eth_rss_reta_entry64 reta_conf[8];
3013         struct cmd_config_rss_reta *res = parsed_result;
3014
3015         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3016         if (ret != 0)
3017                 return;
3018
3019         if (dev_info.reta_size == 0) {
3020                 printf("Redirection table size is 0 which is "
3021                                         "invalid for RSS\n");
3022                 return;
3023         } else
3024                 printf("The reta size of port %d is %u\n",
3025                         res->port_id, dev_info.reta_size);
3026         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3027                 printf("Currently do not support more than %u entries of "
3028                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3029                 return;
3030         }
3031
3032         memset(reta_conf, 0, sizeof(reta_conf));
3033         if (!strcmp(res->list_name, "reta")) {
3034                 if (parse_reta_config(res->list_of_items, reta_conf,
3035                                                 dev_info.reta_size)) {
3036                         printf("Invalid RSS Redirection Table "
3037                                         "config entered\n");
3038                         return;
3039                 }
3040                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3041                                 reta_conf, dev_info.reta_size);
3042                 if (ret != 0)
3043                         printf("Bad redirection table parameter, "
3044                                         "return code = %d \n", ret);
3045         }
3046 }
3047
3048 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3049         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3050 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3051         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3052 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3053         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3054 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3055         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3056 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3057         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3058 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3059         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3060                                  NULL);
3061 cmdline_parse_inst_t cmd_config_rss_reta = {
3062         .f = cmd_set_rss_reta_parsed,
3063         .data = NULL,
3064         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3065         .tokens = {
3066                 (void *)&cmd_config_rss_reta_port,
3067                 (void *)&cmd_config_rss_reta_keyword,
3068                 (void *)&cmd_config_rss_reta_port_id,
3069                 (void *)&cmd_config_rss_reta_name,
3070                 (void *)&cmd_config_rss_reta_list_name,
3071                 (void *)&cmd_config_rss_reta_list_of_items,
3072                 NULL,
3073         },
3074 };
3075
3076 /* *** SHOW PORT RETA INFO *** */
3077 struct cmd_showport_reta {
3078         cmdline_fixed_string_t show;
3079         cmdline_fixed_string_t port;
3080         portid_t port_id;
3081         cmdline_fixed_string_t rss;
3082         cmdline_fixed_string_t reta;
3083         uint16_t size;
3084         cmdline_fixed_string_t list_of_items;
3085 };
3086
3087 static int
3088 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3089                            uint16_t nb_entries,
3090                            char *str)
3091 {
3092         uint32_t size;
3093         const char *p, *p0 = str;
3094         char s[256];
3095         char *end;
3096         char *str_fld[8];
3097         uint16_t i;
3098         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3099                         RTE_RETA_GROUP_SIZE;
3100         int ret;
3101
3102         p = strchr(p0, '(');
3103         if (p == NULL)
3104                 return -1;
3105         p++;
3106         p0 = strchr(p, ')');
3107         if (p0 == NULL)
3108                 return -1;
3109         size = p0 - p;
3110         if (size >= sizeof(s)) {
3111                 printf("The string size exceeds the internal buffer size\n");
3112                 return -1;
3113         }
3114         snprintf(s, sizeof(s), "%.*s", size, p);
3115         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3116         if (ret <= 0 || ret != num) {
3117                 printf("The bits of masks do not match the number of "
3118                                         "reta entries: %u\n", num);
3119                 return -1;
3120         }
3121         for (i = 0; i < ret; i++)
3122                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3123
3124         return 0;
3125 }
3126
3127 static void
3128 cmd_showport_reta_parsed(void *parsed_result,
3129                          __rte_unused struct cmdline *cl,
3130                          __rte_unused void *data)
3131 {
3132         struct cmd_showport_reta *res = parsed_result;
3133         struct rte_eth_rss_reta_entry64 reta_conf[8];
3134         struct rte_eth_dev_info dev_info;
3135         uint16_t max_reta_size;
3136         int ret;
3137
3138         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3139         if (ret != 0)
3140                 return;
3141
3142         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3143         if (res->size == 0 || res->size > max_reta_size) {
3144                 printf("Invalid redirection table size: %u (1-%u)\n",
3145                         res->size, max_reta_size);
3146                 return;
3147         }
3148
3149         memset(reta_conf, 0, sizeof(reta_conf));
3150         if (showport_parse_reta_config(reta_conf, res->size,
3151                                 res->list_of_items) < 0) {
3152                 printf("Invalid string: %s for reta masks\n",
3153                                         res->list_of_items);
3154                 return;
3155         }
3156         port_rss_reta_info(res->port_id, reta_conf, res->size);
3157 }
3158
3159 cmdline_parse_token_string_t cmd_showport_reta_show =
3160         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3161 cmdline_parse_token_string_t cmd_showport_reta_port =
3162         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3163 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3164         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3165 cmdline_parse_token_string_t cmd_showport_reta_rss =
3166         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3167 cmdline_parse_token_string_t cmd_showport_reta_reta =
3168         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3169 cmdline_parse_token_num_t cmd_showport_reta_size =
3170         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3171 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3172         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3173                                         list_of_items, NULL);
3174
3175 cmdline_parse_inst_t cmd_showport_reta = {
3176         .f = cmd_showport_reta_parsed,
3177         .data = NULL,
3178         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3179         .tokens = {
3180                 (void *)&cmd_showport_reta_show,
3181                 (void *)&cmd_showport_reta_port,
3182                 (void *)&cmd_showport_reta_port_id,
3183                 (void *)&cmd_showport_reta_rss,
3184                 (void *)&cmd_showport_reta_reta,
3185                 (void *)&cmd_showport_reta_size,
3186                 (void *)&cmd_showport_reta_list_of_items,
3187                 NULL,
3188         },
3189 };
3190
3191 /* *** Show RSS hash configuration *** */
3192 struct cmd_showport_rss_hash {
3193         cmdline_fixed_string_t show;
3194         cmdline_fixed_string_t port;
3195         portid_t port_id;
3196         cmdline_fixed_string_t rss_hash;
3197         cmdline_fixed_string_t rss_type;
3198         cmdline_fixed_string_t key; /* optional argument */
3199 };
3200
3201 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3202                                 __rte_unused struct cmdline *cl,
3203                                 void *show_rss_key)
3204 {
3205         struct cmd_showport_rss_hash *res = parsed_result;
3206
3207         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3208 }
3209
3210 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3211         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3212 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3213         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3214 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3215         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3216                                  RTE_UINT16);
3217 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3218         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3219                                  "rss-hash");
3220 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3221         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3222
3223 cmdline_parse_inst_t cmd_showport_rss_hash = {
3224         .f = cmd_showport_rss_hash_parsed,
3225         .data = NULL,
3226         .help_str = "show port <port_id> rss-hash",
3227         .tokens = {
3228                 (void *)&cmd_showport_rss_hash_show,
3229                 (void *)&cmd_showport_rss_hash_port,
3230                 (void *)&cmd_showport_rss_hash_port_id,
3231                 (void *)&cmd_showport_rss_hash_rss_hash,
3232                 NULL,
3233         },
3234 };
3235
3236 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3237         .f = cmd_showport_rss_hash_parsed,
3238         .data = (void *)1,
3239         .help_str = "show port <port_id> rss-hash key",
3240         .tokens = {
3241                 (void *)&cmd_showport_rss_hash_show,
3242                 (void *)&cmd_showport_rss_hash_port,
3243                 (void *)&cmd_showport_rss_hash_port_id,
3244                 (void *)&cmd_showport_rss_hash_rss_hash,
3245                 (void *)&cmd_showport_rss_hash_rss_key,
3246                 NULL,
3247         },
3248 };
3249
3250 /* *** Configure DCB *** */
3251 struct cmd_config_dcb {
3252         cmdline_fixed_string_t port;
3253         cmdline_fixed_string_t config;
3254         portid_t port_id;
3255         cmdline_fixed_string_t dcb;
3256         cmdline_fixed_string_t vt;
3257         cmdline_fixed_string_t vt_en;
3258         uint8_t num_tcs;
3259         cmdline_fixed_string_t pfc;
3260         cmdline_fixed_string_t pfc_en;
3261 };
3262
3263 static void
3264 cmd_config_dcb_parsed(void *parsed_result,
3265                         __rte_unused struct cmdline *cl,
3266                         __rte_unused void *data)
3267 {
3268         struct cmd_config_dcb *res = parsed_result;
3269         portid_t port_id = res->port_id;
3270         struct rte_port *port;
3271         uint8_t pfc_en;
3272         int ret;
3273
3274         port = &ports[port_id];
3275         /** Check if the port is not started **/
3276         if (port->port_status != RTE_PORT_STOPPED) {
3277                 printf("Please stop port %d first\n", port_id);
3278                 return;
3279         }
3280
3281         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3282                 printf("The invalid number of traffic class,"
3283                         " only 4 or 8 allowed.\n");
3284                 return;
3285         }
3286
3287         if (nb_fwd_lcores < res->num_tcs) {
3288                 printf("nb_cores shouldn't be less than number of TCs.\n");
3289                 return;
3290         }
3291         if (!strncmp(res->pfc_en, "on", 2))
3292                 pfc_en = 1;
3293         else
3294                 pfc_en = 0;
3295
3296         /* DCB in VT mode */
3297         if (!strncmp(res->vt_en, "on", 2))
3298                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3299                                 (enum rte_eth_nb_tcs)res->num_tcs,
3300                                 pfc_en);
3301         else
3302                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3303                                 (enum rte_eth_nb_tcs)res->num_tcs,
3304                                 pfc_en);
3305
3306
3307         if (ret != 0) {
3308                 printf("Cannot initialize network ports.\n");
3309                 return;
3310         }
3311
3312         cmd_reconfig_device_queue(port_id, 1, 1);
3313 }
3314
3315 cmdline_parse_token_string_t cmd_config_dcb_port =
3316         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3317 cmdline_parse_token_string_t cmd_config_dcb_config =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3319 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3320         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3321 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3322         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3323 cmdline_parse_token_string_t cmd_config_dcb_vt =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3325 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3327 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3328         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3329 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3330         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3331 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3333
3334 cmdline_parse_inst_t cmd_config_dcb = {
3335         .f = cmd_config_dcb_parsed,
3336         .data = NULL,
3337         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3338         .tokens = {
3339                 (void *)&cmd_config_dcb_port,
3340                 (void *)&cmd_config_dcb_config,
3341                 (void *)&cmd_config_dcb_port_id,
3342                 (void *)&cmd_config_dcb_dcb,
3343                 (void *)&cmd_config_dcb_vt,
3344                 (void *)&cmd_config_dcb_vt_en,
3345                 (void *)&cmd_config_dcb_num_tcs,
3346                 (void *)&cmd_config_dcb_pfc,
3347                 (void *)&cmd_config_dcb_pfc_en,
3348                 NULL,
3349         },
3350 };
3351
3352 /* *** configure number of packets per burst *** */
3353 struct cmd_config_burst {
3354         cmdline_fixed_string_t port;
3355         cmdline_fixed_string_t keyword;
3356         cmdline_fixed_string_t all;
3357         cmdline_fixed_string_t name;
3358         uint16_t value;
3359 };
3360
3361 static void
3362 cmd_config_burst_parsed(void *parsed_result,
3363                         __rte_unused struct cmdline *cl,
3364                         __rte_unused void *data)
3365 {
3366         struct cmd_config_burst *res = parsed_result;
3367         struct rte_eth_dev_info dev_info;
3368         uint16_t rec_nb_pkts;
3369         int ret;
3370
3371         if (!all_ports_stopped()) {
3372                 printf("Please stop all ports first\n");
3373                 return;
3374         }
3375
3376         if (!strcmp(res->name, "burst")) {
3377                 if (res->value == 0) {
3378                         /* If user gives a value of zero, query the PMD for
3379                          * its recommended Rx burst size. Testpmd uses a single
3380                          * size for all ports, so assume all ports are the same
3381                          * NIC model and use the values from Port 0.
3382                          */
3383                         ret = eth_dev_info_get_print_err(0, &dev_info);
3384                         if (ret != 0)
3385                                 return;
3386
3387                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3388
3389                         if (rec_nb_pkts == 0) {
3390                                 printf("PMD does not recommend a burst size.\n"
3391                                         "User provided value must be between"
3392                                         " 1 and %d\n", MAX_PKT_BURST);
3393                                 return;
3394                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3395                                 printf("PMD recommended burst size of %d"
3396                                         " exceeds maximum value of %d\n",
3397                                         rec_nb_pkts, MAX_PKT_BURST);
3398                                 return;
3399                         }
3400                         printf("Using PMD-provided burst value of %d\n",
3401                                 rec_nb_pkts);
3402                         nb_pkt_per_burst = rec_nb_pkts;
3403                 } else if (res->value > MAX_PKT_BURST) {
3404                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3405                         return;
3406                 } else
3407                         nb_pkt_per_burst = res->value;
3408         } else {
3409                 printf("Unknown parameter\n");
3410                 return;
3411         }
3412
3413         init_port_config();
3414
3415         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3416 }
3417
3418 cmdline_parse_token_string_t cmd_config_burst_port =
3419         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3420 cmdline_parse_token_string_t cmd_config_burst_keyword =
3421         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3422 cmdline_parse_token_string_t cmd_config_burst_all =
3423         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3424 cmdline_parse_token_string_t cmd_config_burst_name =
3425         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3426 cmdline_parse_token_num_t cmd_config_burst_value =
3427         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3428
3429 cmdline_parse_inst_t cmd_config_burst = {
3430         .f = cmd_config_burst_parsed,
3431         .data = NULL,
3432         .help_str = "port config all burst <value>",
3433         .tokens = {
3434                 (void *)&cmd_config_burst_port,
3435                 (void *)&cmd_config_burst_keyword,
3436                 (void *)&cmd_config_burst_all,
3437                 (void *)&cmd_config_burst_name,
3438                 (void *)&cmd_config_burst_value,
3439                 NULL,
3440         },
3441 };
3442
3443 /* *** configure rx/tx queues *** */
3444 struct cmd_config_thresh {
3445         cmdline_fixed_string_t port;
3446         cmdline_fixed_string_t keyword;
3447         cmdline_fixed_string_t all;
3448         cmdline_fixed_string_t name;
3449         uint8_t value;
3450 };
3451
3452 static void
3453 cmd_config_thresh_parsed(void *parsed_result,
3454                         __rte_unused struct cmdline *cl,
3455                         __rte_unused void *data)
3456 {
3457         struct cmd_config_thresh *res = parsed_result;
3458
3459         if (!all_ports_stopped()) {
3460                 printf("Please stop all ports first\n");
3461                 return;
3462         }
3463
3464         if (!strcmp(res->name, "txpt"))
3465                 tx_pthresh = res->value;
3466         else if(!strcmp(res->name, "txht"))
3467                 tx_hthresh = res->value;
3468         else if(!strcmp(res->name, "txwt"))
3469                 tx_wthresh = res->value;
3470         else if(!strcmp(res->name, "rxpt"))
3471                 rx_pthresh = res->value;
3472         else if(!strcmp(res->name, "rxht"))
3473                 rx_hthresh = res->value;
3474         else if(!strcmp(res->name, "rxwt"))
3475                 rx_wthresh = res->value;
3476         else {
3477                 printf("Unknown parameter\n");
3478                 return;
3479         }
3480
3481         init_port_config();
3482
3483         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3484 }
3485
3486 cmdline_parse_token_string_t cmd_config_thresh_port =
3487         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3488 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3489         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3490 cmdline_parse_token_string_t cmd_config_thresh_all =
3491         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3492 cmdline_parse_token_string_t cmd_config_thresh_name =
3493         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3494                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3495 cmdline_parse_token_num_t cmd_config_thresh_value =
3496         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3497
3498 cmdline_parse_inst_t cmd_config_thresh = {
3499         .f = cmd_config_thresh_parsed,
3500         .data = NULL,
3501         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3502         .tokens = {
3503                 (void *)&cmd_config_thresh_port,
3504                 (void *)&cmd_config_thresh_keyword,
3505                 (void *)&cmd_config_thresh_all,
3506                 (void *)&cmd_config_thresh_name,
3507                 (void *)&cmd_config_thresh_value,
3508                 NULL,
3509         },
3510 };
3511
3512 /* *** configure free/rs threshold *** */
3513 struct cmd_config_threshold {
3514         cmdline_fixed_string_t port;
3515         cmdline_fixed_string_t keyword;
3516         cmdline_fixed_string_t all;
3517         cmdline_fixed_string_t name;
3518         uint16_t value;
3519 };
3520
3521 static void
3522 cmd_config_threshold_parsed(void *parsed_result,
3523                         __rte_unused struct cmdline *cl,
3524                         __rte_unused void *data)
3525 {
3526         struct cmd_config_threshold *res = parsed_result;
3527
3528         if (!all_ports_stopped()) {
3529                 printf("Please stop all ports first\n");
3530                 return;
3531         }
3532
3533         if (!strcmp(res->name, "txfreet"))
3534                 tx_free_thresh = res->value;
3535         else if (!strcmp(res->name, "txrst"))
3536                 tx_rs_thresh = res->value;
3537         else if (!strcmp(res->name, "rxfreet"))
3538                 rx_free_thresh = res->value;
3539         else {
3540                 printf("Unknown parameter\n");
3541                 return;
3542         }
3543
3544         init_port_config();
3545
3546         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3547 }
3548
3549 cmdline_parse_token_string_t cmd_config_threshold_port =
3550         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3551 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3552         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3553                                                                 "config");
3554 cmdline_parse_token_string_t cmd_config_threshold_all =
3555         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3556 cmdline_parse_token_string_t cmd_config_threshold_name =
3557         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3558                                                 "txfreet#txrst#rxfreet");
3559 cmdline_parse_token_num_t cmd_config_threshold_value =
3560         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3561
3562 cmdline_parse_inst_t cmd_config_threshold = {
3563         .f = cmd_config_threshold_parsed,
3564         .data = NULL,
3565         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3566         .tokens = {
3567                 (void *)&cmd_config_threshold_port,
3568                 (void *)&cmd_config_threshold_keyword,
3569                 (void *)&cmd_config_threshold_all,
3570                 (void *)&cmd_config_threshold_name,
3571                 (void *)&cmd_config_threshold_value,
3572                 NULL,
3573         },
3574 };
3575
3576 /* *** stop *** */
3577 struct cmd_stop_result {
3578         cmdline_fixed_string_t stop;
3579 };
3580
3581 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3582                             __rte_unused struct cmdline *cl,
3583                             __rte_unused void *data)
3584 {
3585         stop_packet_forwarding();
3586 }
3587
3588 cmdline_parse_token_string_t cmd_stop_stop =
3589         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3590
3591 cmdline_parse_inst_t cmd_stop = {
3592         .f = cmd_stop_parsed,
3593         .data = NULL,
3594         .help_str = "stop: Stop packet forwarding",
3595         .tokens = {
3596                 (void *)&cmd_stop_stop,
3597                 NULL,
3598         },
3599 };
3600
3601 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3602
3603 unsigned int
3604 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3605                 unsigned int *parsed_items, int check_unique_values)
3606 {
3607         unsigned int nb_item;
3608         unsigned int value;
3609         unsigned int i;
3610         unsigned int j;
3611         int value_ok;
3612         char c;
3613
3614         /*
3615          * First parse all items in the list and store their value.
3616          */
3617         value = 0;
3618         nb_item = 0;
3619         value_ok = 0;
3620         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3621                 c = str[i];
3622                 if ((c >= '0') && (c <= '9')) {
3623                         value = (unsigned int) (value * 10 + (c - '0'));
3624                         value_ok = 1;
3625                         continue;
3626                 }
3627                 if (c != ',') {
3628                         printf("character %c is not a decimal digit\n", c);
3629                         return 0;
3630                 }
3631                 if (! value_ok) {
3632                         printf("No valid value before comma\n");
3633                         return 0;
3634                 }
3635                 if (nb_item < max_items) {
3636                         parsed_items[nb_item] = value;
3637                         value_ok = 0;
3638                         value = 0;
3639                 }
3640                 nb_item++;
3641         }
3642         if (nb_item >= max_items) {
3643                 printf("Number of %s = %u > %u (maximum items)\n",
3644                        item_name, nb_item + 1, max_items);
3645                 return 0;
3646         }
3647         parsed_items[nb_item++] = value;
3648         if (! check_unique_values)
3649                 return nb_item;
3650
3651         /*
3652          * Then, check that all values in the list are differents.
3653          * No optimization here...
3654          */
3655         for (i = 0; i < nb_item; i++) {
3656                 for (j = i + 1; j < nb_item; j++) {
3657                         if (parsed_items[j] == parsed_items[i]) {
3658                                 printf("duplicated %s %u at index %u and %u\n",
3659                                        item_name, parsed_items[i], i, j);
3660                                 return 0;
3661                         }
3662                 }
3663         }
3664         return nb_item;
3665 }
3666
3667 struct cmd_set_list_result {
3668         cmdline_fixed_string_t cmd_keyword;
3669         cmdline_fixed_string_t list_name;
3670         cmdline_fixed_string_t list_of_items;
3671 };
3672
3673 static void cmd_set_list_parsed(void *parsed_result,
3674                                 __rte_unused struct cmdline *cl,
3675                                 __rte_unused void *data)
3676 {
3677         struct cmd_set_list_result *res;
3678         union {
3679                 unsigned int lcorelist[RTE_MAX_LCORE];
3680                 unsigned int portlist[RTE_MAX_ETHPORTS];
3681         } parsed_items;
3682         unsigned int nb_item;
3683
3684         if (test_done == 0) {
3685                 printf("Please stop forwarding first\n");
3686                 return;
3687         }
3688
3689         res = parsed_result;
3690         if (!strcmp(res->list_name, "corelist")) {
3691                 nb_item = parse_item_list(res->list_of_items, "core",
3692                                           RTE_MAX_LCORE,
3693                                           parsed_items.lcorelist, 1);
3694                 if (nb_item > 0) {
3695                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3696                         fwd_config_setup();
3697                 }
3698                 return;
3699         }
3700         if (!strcmp(res->list_name, "portlist")) {
3701                 nb_item = parse_item_list(res->list_of_items, "port",
3702                                           RTE_MAX_ETHPORTS,
3703                                           parsed_items.portlist, 1);
3704                 if (nb_item > 0) {
3705                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3706                         fwd_config_setup();
3707                 }
3708         }
3709 }
3710
3711 cmdline_parse_token_string_t cmd_set_list_keyword =
3712         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3713                                  "set");
3714 cmdline_parse_token_string_t cmd_set_list_name =
3715         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3716                                  "corelist#portlist");
3717 cmdline_parse_token_string_t cmd_set_list_of_items =
3718         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3719                                  NULL);
3720
3721 cmdline_parse_inst_t cmd_set_fwd_list = {
3722         .f = cmd_set_list_parsed,
3723         .data = NULL,
3724         .help_str = "set corelist|portlist <list0[,list1]*>",
3725         .tokens = {
3726                 (void *)&cmd_set_list_keyword,
3727                 (void *)&cmd_set_list_name,
3728                 (void *)&cmd_set_list_of_items,
3729                 NULL,
3730         },
3731 };
3732
3733 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3734
3735 struct cmd_setmask_result {
3736         cmdline_fixed_string_t set;
3737         cmdline_fixed_string_t mask;
3738         uint64_t hexavalue;
3739 };
3740
3741 static void cmd_set_mask_parsed(void *parsed_result,
3742                                 __rte_unused struct cmdline *cl,
3743                                 __rte_unused void *data)
3744 {
3745         struct cmd_setmask_result *res = parsed_result;
3746
3747         if (test_done == 0) {
3748                 printf("Please stop forwarding first\n");
3749                 return;
3750         }
3751         if (!strcmp(res->mask, "coremask")) {
3752                 set_fwd_lcores_mask(res->hexavalue);
3753                 fwd_config_setup();
3754         } else if (!strcmp(res->mask, "portmask")) {
3755                 set_fwd_ports_mask(res->hexavalue);
3756                 fwd_config_setup();
3757         }
3758 }
3759
3760 cmdline_parse_token_string_t cmd_setmask_set =
3761         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3762 cmdline_parse_token_string_t cmd_setmask_mask =
3763         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3764                                  "coremask#portmask");
3765 cmdline_parse_token_num_t cmd_setmask_value =
3766         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3767
3768 cmdline_parse_inst_t cmd_set_fwd_mask = {
3769         .f = cmd_set_mask_parsed,
3770         .data = NULL,
3771         .help_str = "set coremask|portmask <hexadecimal value>",
3772         .tokens = {
3773                 (void *)&cmd_setmask_set,
3774                 (void *)&cmd_setmask_mask,
3775                 (void *)&cmd_setmask_value,
3776                 NULL,
3777         },
3778 };
3779
3780 /*
3781  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3782  */
3783 struct cmd_set_result {
3784         cmdline_fixed_string_t set;
3785         cmdline_fixed_string_t what;
3786         uint16_t value;
3787 };
3788
3789 static void cmd_set_parsed(void *parsed_result,
3790                            __rte_unused struct cmdline *cl,
3791                            __rte_unused void *data)
3792 {
3793         struct cmd_set_result *res = parsed_result;
3794         if (!strcmp(res->what, "nbport")) {
3795                 set_fwd_ports_number(res->value);
3796                 fwd_config_setup();
3797         } else if (!strcmp(res->what, "nbcore")) {
3798                 set_fwd_lcores_number(res->value);
3799                 fwd_config_setup();
3800         } else if (!strcmp(res->what, "burst"))
3801                 set_nb_pkt_per_burst(res->value);
3802         else if (!strcmp(res->what, "verbose"))
3803                 set_verbose_level(res->value);
3804 }
3805
3806 cmdline_parse_token_string_t cmd_set_set =
3807         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3808 cmdline_parse_token_string_t cmd_set_what =
3809         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3810                                  "nbport#nbcore#burst#verbose");
3811 cmdline_parse_token_num_t cmd_set_value =
3812         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3813
3814 cmdline_parse_inst_t cmd_set_numbers = {
3815         .f = cmd_set_parsed,
3816         .data = NULL,
3817         .help_str = "set nbport|nbcore|burst|verbose <value>",
3818         .tokens = {
3819                 (void *)&cmd_set_set,
3820                 (void *)&cmd_set_what,
3821                 (void *)&cmd_set_value,
3822                 NULL,
3823         },
3824 };
3825
3826 /* *** SET LOG LEVEL CONFIGURATION *** */
3827
3828 struct cmd_set_log_result {
3829         cmdline_fixed_string_t set;
3830         cmdline_fixed_string_t log;
3831         cmdline_fixed_string_t type;
3832         uint32_t level;
3833 };
3834
3835 static void
3836 cmd_set_log_parsed(void *parsed_result,
3837                    __rte_unused struct cmdline *cl,
3838                    __rte_unused void *data)
3839 {
3840         struct cmd_set_log_result *res;
3841         int ret;
3842
3843         res = parsed_result;
3844         if (!strcmp(res->type, "global"))
3845                 rte_log_set_global_level(res->level);
3846         else {
3847                 ret = rte_log_set_level_regexp(res->type, res->level);
3848                 if (ret < 0)
3849                         printf("Unable to set log level\n");
3850         }
3851 }
3852
3853 cmdline_parse_token_string_t cmd_set_log_set =
3854         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3855 cmdline_parse_token_string_t cmd_set_log_log =
3856         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3857 cmdline_parse_token_string_t cmd_set_log_type =
3858         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3859 cmdline_parse_token_num_t cmd_set_log_level =
3860         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3861
3862 cmdline_parse_inst_t cmd_set_log = {
3863         .f = cmd_set_log_parsed,
3864         .data = NULL,
3865         .help_str = "set log global|<type> <level>",
3866         .tokens = {
3867                 (void *)&cmd_set_log_set,
3868                 (void *)&cmd_set_log_log,
3869                 (void *)&cmd_set_log_type,
3870                 (void *)&cmd_set_log_level,
3871                 NULL,
3872         },
3873 };
3874
3875 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3876
3877 struct cmd_set_rxoffs_result {
3878         cmdline_fixed_string_t cmd_keyword;
3879         cmdline_fixed_string_t rxoffs;
3880         cmdline_fixed_string_t seg_offsets;
3881 };
3882
3883 static void
3884 cmd_set_rxoffs_parsed(void *parsed_result,
3885                       __rte_unused struct cmdline *cl,
3886                       __rte_unused void *data)
3887 {
3888         struct cmd_set_rxoffs_result *res;
3889         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3890         unsigned int nb_segs;
3891
3892         res = parsed_result;
3893         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3894                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3895         if (nb_segs > 0)
3896                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3897         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3898 }
3899
3900 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3902                                  cmd_keyword, "set");
3903 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3904         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3905                                  rxoffs, "rxoffs");
3906 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3907         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3908                                  seg_offsets, NULL);
3909
3910 cmdline_parse_inst_t cmd_set_rxoffs = {
3911         .f = cmd_set_rxoffs_parsed,
3912         .data = NULL,
3913         .help_str = "set rxoffs <len0[,len1]*>",
3914         .tokens = {
3915                 (void *)&cmd_set_rxoffs_keyword,
3916                 (void *)&cmd_set_rxoffs_name,
3917                 (void *)&cmd_set_rxoffs_offsets,
3918                 NULL,
3919         },
3920 };
3921
3922 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3923
3924 struct cmd_set_rxpkts_result {
3925         cmdline_fixed_string_t cmd_keyword;
3926         cmdline_fixed_string_t rxpkts;
3927         cmdline_fixed_string_t seg_lengths;
3928 };
3929
3930 static void
3931 cmd_set_rxpkts_parsed(void *parsed_result,
3932                       __rte_unused struct cmdline *cl,
3933                       __rte_unused void *data)
3934 {
3935         struct cmd_set_rxpkts_result *res;
3936         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3937         unsigned int nb_segs;
3938
3939         res = parsed_result;
3940         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3941                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3942         if (nb_segs > 0)
3943                 set_rx_pkt_segments(seg_lengths, nb_segs);
3944         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3945 }
3946
3947 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3948         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3949                                  cmd_keyword, "set");
3950 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3951         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3952                                  rxpkts, "rxpkts");
3953 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3954         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3955                                  seg_lengths, NULL);
3956
3957 cmdline_parse_inst_t cmd_set_rxpkts = {
3958         .f = cmd_set_rxpkts_parsed,
3959         .data = NULL,
3960         .help_str = "set rxpkts <len0[,len1]*>",
3961         .tokens = {
3962                 (void *)&cmd_set_rxpkts_keyword,
3963                 (void *)&cmd_set_rxpkts_name,
3964                 (void *)&cmd_set_rxpkts_lengths,
3965                 NULL,
3966         },
3967 };
3968
3969 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3970
3971 struct cmd_set_txpkts_result {
3972         cmdline_fixed_string_t cmd_keyword;
3973         cmdline_fixed_string_t txpkts;
3974         cmdline_fixed_string_t seg_lengths;
3975 };
3976
3977 static void
3978 cmd_set_txpkts_parsed(void *parsed_result,
3979                       __rte_unused struct cmdline *cl,
3980                       __rte_unused void *data)
3981 {
3982         struct cmd_set_txpkts_result *res;
3983         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3984         unsigned int nb_segs;
3985
3986         res = parsed_result;
3987         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3988                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3989         if (nb_segs > 0)
3990                 set_tx_pkt_segments(seg_lengths, nb_segs);
3991 }
3992
3993 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3994         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3995                                  cmd_keyword, "set");
3996 cmdline_parse_token_string_t cmd_set_txpkts_name =
3997         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3998                                  txpkts, "txpkts");
3999 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4000         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4001                                  seg_lengths, NULL);
4002
4003 cmdline_parse_inst_t cmd_set_txpkts = {
4004         .f = cmd_set_txpkts_parsed,
4005         .data = NULL,
4006         .help_str = "set txpkts <len0[,len1]*>",
4007         .tokens = {
4008                 (void *)&cmd_set_txpkts_keyword,
4009                 (void *)&cmd_set_txpkts_name,
4010                 (void *)&cmd_set_txpkts_lengths,
4011                 NULL,
4012         },
4013 };
4014
4015 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4016
4017 struct cmd_set_txsplit_result {
4018         cmdline_fixed_string_t cmd_keyword;
4019         cmdline_fixed_string_t txsplit;
4020         cmdline_fixed_string_t mode;
4021 };
4022
4023 static void
4024 cmd_set_txsplit_parsed(void *parsed_result,
4025                       __rte_unused struct cmdline *cl,
4026                       __rte_unused void *data)
4027 {
4028         struct cmd_set_txsplit_result *res;
4029
4030         res = parsed_result;
4031         set_tx_pkt_split(res->mode);
4032 }
4033
4034 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4035         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4036                                  cmd_keyword, "set");
4037 cmdline_parse_token_string_t cmd_set_txsplit_name =
4038         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4039                                  txsplit, "txsplit");
4040 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4041         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4042                                  mode, NULL);
4043
4044 cmdline_parse_inst_t cmd_set_txsplit = {
4045         .f = cmd_set_txsplit_parsed,
4046         .data = NULL,
4047         .help_str = "set txsplit on|off|rand",
4048         .tokens = {
4049                 (void *)&cmd_set_txsplit_keyword,
4050                 (void *)&cmd_set_txsplit_name,
4051                 (void *)&cmd_set_txsplit_mode,
4052                 NULL,
4053         },
4054 };
4055
4056 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4057
4058 struct cmd_set_txtimes_result {
4059         cmdline_fixed_string_t cmd_keyword;
4060         cmdline_fixed_string_t txtimes;
4061         cmdline_fixed_string_t tx_times;
4062 };
4063
4064 static void
4065 cmd_set_txtimes_parsed(void *parsed_result,
4066                        __rte_unused struct cmdline *cl,
4067                        __rte_unused void *data)
4068 {
4069         struct cmd_set_txtimes_result *res;
4070         unsigned int tx_times[2] = {0, 0};
4071         unsigned int n_times;
4072
4073         res = parsed_result;
4074         n_times = parse_item_list(res->tx_times, "tx times",
4075                                   2, tx_times, 0);
4076         if (n_times == 2)
4077                 set_tx_pkt_times(tx_times);
4078 }
4079
4080 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4081         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4082                                  cmd_keyword, "set");
4083 cmdline_parse_token_string_t cmd_set_txtimes_name =
4084         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4085                                  txtimes, "txtimes");
4086 cmdline_parse_token_string_t cmd_set_txtimes_value =
4087         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4088                                  tx_times, NULL);
4089
4090 cmdline_parse_inst_t cmd_set_txtimes = {
4091         .f = cmd_set_txtimes_parsed,
4092         .data = NULL,
4093         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4094         .tokens = {
4095                 (void *)&cmd_set_txtimes_keyword,
4096                 (void *)&cmd_set_txtimes_name,
4097                 (void *)&cmd_set_txtimes_value,
4098                 NULL,
4099         },
4100 };
4101
4102 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4103 struct cmd_rx_vlan_filter_all_result {
4104         cmdline_fixed_string_t rx_vlan;
4105         cmdline_fixed_string_t what;
4106         cmdline_fixed_string_t all;
4107         portid_t port_id;
4108 };
4109
4110 static void
4111 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4112                               __rte_unused struct cmdline *cl,
4113                               __rte_unused void *data)
4114 {
4115         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4116
4117         if (!strcmp(res->what, "add"))
4118                 rx_vlan_all_filter_set(res->port_id, 1);
4119         else
4120                 rx_vlan_all_filter_set(res->port_id, 0);
4121 }
4122
4123 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4124         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4125                                  rx_vlan, "rx_vlan");
4126 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4127         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4128                                  what, "add#rm");
4129 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4130         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4131                                  all, "all");
4132 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4133         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4134                               port_id, RTE_UINT16);
4135
4136 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4137         .f = cmd_rx_vlan_filter_all_parsed,
4138         .data = NULL,
4139         .help_str = "rx_vlan add|rm all <port_id>: "
4140                 "Add/Remove all identifiers to/from the set of VLAN "
4141                 "identifiers filtered by a port",
4142         .tokens = {
4143                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4144                 (void *)&cmd_rx_vlan_filter_all_what,
4145                 (void *)&cmd_rx_vlan_filter_all_all,
4146                 (void *)&cmd_rx_vlan_filter_all_portid,
4147                 NULL,
4148         },
4149 };
4150
4151 /* *** VLAN OFFLOAD SET ON A PORT *** */
4152 struct cmd_vlan_offload_result {
4153         cmdline_fixed_string_t vlan;
4154         cmdline_fixed_string_t set;
4155         cmdline_fixed_string_t vlan_type;
4156         cmdline_fixed_string_t what;
4157         cmdline_fixed_string_t on;
4158         cmdline_fixed_string_t port_id;
4159 };
4160
4161 static void
4162 cmd_vlan_offload_parsed(void *parsed_result,
4163                           __rte_unused struct cmdline *cl,
4164                           __rte_unused void *data)
4165 {
4166         int on;
4167         struct cmd_vlan_offload_result *res = parsed_result;
4168         char *str;
4169         int i, len = 0;
4170         portid_t port_id = 0;
4171         unsigned int tmp;
4172
4173         str = res->port_id;
4174         len = strnlen(str, STR_TOKEN_SIZE);
4175         i = 0;
4176         /* Get port_id first */
4177         while(i < len){
4178                 if(str[i] == ',')
4179                         break;
4180
4181                 i++;
4182         }
4183         str[i]='\0';
4184         tmp = strtoul(str, NULL, 0);
4185         /* If port_id greater that what portid_t can represent, return */
4186         if(tmp >= RTE_MAX_ETHPORTS)
4187                 return;
4188         port_id = (portid_t)tmp;
4189
4190         if (!strcmp(res->on, "on"))
4191                 on = 1;
4192         else
4193                 on = 0;
4194
4195         if (!strcmp(res->what, "strip"))
4196                 rx_vlan_strip_set(port_id,  on);
4197         else if(!strcmp(res->what, "stripq")){
4198                 uint16_t queue_id = 0;
4199
4200                 /* No queue_id, return */
4201                 if(i + 1 >= len) {
4202                         printf("must specify (port,queue_id)\n");
4203                         return;
4204                 }
4205                 tmp = strtoul(str + i + 1, NULL, 0);
4206                 /* If queue_id greater that what 16-bits can represent, return */
4207                 if(tmp > 0xffff)
4208                         return;
4209
4210                 queue_id = (uint16_t)tmp;
4211                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4212         }
4213         else if (!strcmp(res->what, "filter"))
4214                 rx_vlan_filter_set(port_id, on);
4215         else if (!strcmp(res->what, "qinq_strip"))
4216                 rx_vlan_qinq_strip_set(port_id, on);
4217         else
4218                 vlan_extend_set(port_id, on);
4219
4220         return;
4221 }
4222
4223 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4224         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4225                                  vlan, "vlan");
4226 cmdline_parse_token_string_t cmd_vlan_offload_set =
4227         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4228                                  set, "set");
4229 cmdline_parse_token_string_t cmd_vlan_offload_what =
4230         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4231                                 what, "strip#filter#qinq_strip#extend#stripq");
4232 cmdline_parse_token_string_t cmd_vlan_offload_on =
4233         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4234                               on, "on#off");
4235 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4236         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4237                               port_id, NULL);
4238
4239 cmdline_parse_inst_t cmd_vlan_offload = {
4240         .f = cmd_vlan_offload_parsed,
4241         .data = NULL,
4242         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4243                 "<port_id[,queue_id]>: "
4244                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4245         .tokens = {
4246                 (void *)&cmd_vlan_offload_vlan,
4247                 (void *)&cmd_vlan_offload_set,
4248                 (void *)&cmd_vlan_offload_what,
4249                 (void *)&cmd_vlan_offload_on,
4250                 (void *)&cmd_vlan_offload_portid,
4251                 NULL,
4252         },
4253 };
4254
4255 /* *** VLAN TPID SET ON A PORT *** */
4256 struct cmd_vlan_tpid_result {
4257         cmdline_fixed_string_t vlan;
4258         cmdline_fixed_string_t set;
4259         cmdline_fixed_string_t vlan_type;
4260         cmdline_fixed_string_t what;
4261         uint16_t tp_id;
4262         portid_t port_id;
4263 };
4264
4265 static void
4266 cmd_vlan_tpid_parsed(void *parsed_result,
4267                           __rte_unused struct cmdline *cl,
4268                           __rte_unused void *data)
4269 {
4270         struct cmd_vlan_tpid_result *res = parsed_result;
4271         enum rte_vlan_type vlan_type;
4272
4273         if (!strcmp(res->vlan_type, "inner"))
4274                 vlan_type = ETH_VLAN_TYPE_INNER;
4275         else if (!strcmp(res->vlan_type, "outer"))
4276                 vlan_type = ETH_VLAN_TYPE_OUTER;
4277         else {
4278                 printf("Unknown vlan type\n");
4279                 return;
4280         }
4281         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4282 }
4283
4284 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4285         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4286                                  vlan, "vlan");
4287 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4288         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4289                                  set, "set");
4290 cmdline_parse_token_string_t cmd_vlan_type =
4291         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4292                                  vlan_type, "inner#outer");
4293 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4294         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4295                                  what, "tpid");
4296 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4297         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4298                               tp_id, RTE_UINT16);
4299 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4300         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4301                               port_id, RTE_UINT16);
4302
4303 cmdline_parse_inst_t cmd_vlan_tpid = {
4304         .f = cmd_vlan_tpid_parsed,
4305         .data = NULL,
4306         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4307                 "Set the VLAN Ether type",
4308         .tokens = {
4309                 (void *)&cmd_vlan_tpid_vlan,
4310                 (void *)&cmd_vlan_tpid_set,
4311                 (void *)&cmd_vlan_type,
4312                 (void *)&cmd_vlan_tpid_what,
4313                 (void *)&cmd_vlan_tpid_tpid,
4314                 (void *)&cmd_vlan_tpid_portid,
4315                 NULL,
4316         },
4317 };
4318
4319 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4320 struct cmd_rx_vlan_filter_result {
4321         cmdline_fixed_string_t rx_vlan;
4322         cmdline_fixed_string_t what;
4323         uint16_t vlan_id;
4324         portid_t port_id;
4325 };
4326
4327 static void
4328 cmd_rx_vlan_filter_parsed(void *parsed_result,
4329                           __rte_unused struct cmdline *cl,
4330                           __rte_unused void *data)
4331 {
4332         struct cmd_rx_vlan_filter_result *res = parsed_result;
4333
4334         if (!strcmp(res->what, "add"))
4335                 rx_vft_set(res->port_id, res->vlan_id, 1);
4336         else
4337                 rx_vft_set(res->port_id, res->vlan_id, 0);
4338 }
4339
4340 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4341         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4342                                  rx_vlan, "rx_vlan");
4343 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4344         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4345                                  what, "add#rm");
4346 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4347         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4348                               vlan_id, RTE_UINT16);
4349 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4350         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4351                               port_id, RTE_UINT16);
4352
4353 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4354         .f = cmd_rx_vlan_filter_parsed,
4355         .data = NULL,
4356         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4357                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4358                 "identifiers filtered by a port",
4359         .tokens = {
4360                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4361                 (void *)&cmd_rx_vlan_filter_what,
4362                 (void *)&cmd_rx_vlan_filter_vlanid,
4363                 (void *)&cmd_rx_vlan_filter_portid,
4364                 NULL,
4365         },
4366 };
4367
4368 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4369 struct cmd_tx_vlan_set_result {
4370         cmdline_fixed_string_t tx_vlan;
4371         cmdline_fixed_string_t set;
4372         portid_t port_id;
4373         uint16_t vlan_id;
4374 };
4375
4376 static void
4377 cmd_tx_vlan_set_parsed(void *parsed_result,
4378                        __rte_unused struct cmdline *cl,
4379                        __rte_unused void *data)
4380 {
4381         struct cmd_tx_vlan_set_result *res = parsed_result;
4382
4383         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4384                 return;
4385
4386         if (!port_is_stopped(res->port_id)) {
4387                 printf("Please stop port %d first\n", res->port_id);
4388                 return;
4389         }
4390
4391         tx_vlan_set(res->port_id, res->vlan_id);
4392
4393         cmd_reconfig_device_queue(res->port_id, 1, 1);
4394 }
4395
4396 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4397         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4398                                  tx_vlan, "tx_vlan");
4399 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4400         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4401                                  set, "set");
4402 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4403         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4404                               port_id, RTE_UINT16);
4405 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4406         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4407                               vlan_id, RTE_UINT16);
4408
4409 cmdline_parse_inst_t cmd_tx_vlan_set = {
4410         .f = cmd_tx_vlan_set_parsed,
4411         .data = NULL,
4412         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4413                 "Enable hardware insertion of a single VLAN header "
4414                 "with a given TAG Identifier in packets sent on a port",
4415         .tokens = {
4416                 (void *)&cmd_tx_vlan_set_tx_vlan,
4417                 (void *)&cmd_tx_vlan_set_set,
4418                 (void *)&cmd_tx_vlan_set_portid,
4419                 (void *)&cmd_tx_vlan_set_vlanid,
4420                 NULL,
4421         },
4422 };
4423
4424 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4425 struct cmd_tx_vlan_set_qinq_result {
4426         cmdline_fixed_string_t tx_vlan;
4427         cmdline_fixed_string_t set;
4428         portid_t port_id;
4429         uint16_t vlan_id;
4430         uint16_t vlan_id_outer;
4431 };
4432
4433 static void
4434 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4435                             __rte_unused struct cmdline *cl,
4436                             __rte_unused void *data)
4437 {
4438         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4439
4440         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4441                 return;
4442
4443         if (!port_is_stopped(res->port_id)) {
4444                 printf("Please stop port %d first\n", res->port_id);
4445                 return;
4446         }
4447
4448         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4449
4450         cmd_reconfig_device_queue(res->port_id, 1, 1);
4451 }
4452
4453 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4454         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4455                 tx_vlan, "tx_vlan");
4456 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4457         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4458                 set, "set");
4459 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4460         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4461                 port_id, RTE_UINT16);
4462 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4463         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4464                 vlan_id, RTE_UINT16);
4465 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4466         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4467                 vlan_id_outer, RTE_UINT16);
4468
4469 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4470         .f = cmd_tx_vlan_set_qinq_parsed,
4471         .data = NULL,
4472         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4473                 "Enable hardware insertion of double VLAN header "
4474                 "with given TAG Identifiers in packets sent on a port",
4475         .tokens = {
4476                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4477                 (void *)&cmd_tx_vlan_set_qinq_set,
4478                 (void *)&cmd_tx_vlan_set_qinq_portid,
4479                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4480                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4481                 NULL,
4482         },
4483 };
4484
4485 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4486 struct cmd_tx_vlan_set_pvid_result {
4487         cmdline_fixed_string_t tx_vlan;
4488         cmdline_fixed_string_t set;
4489         cmdline_fixed_string_t pvid;
4490         portid_t port_id;
4491         uint16_t vlan_id;
4492         cmdline_fixed_string_t mode;
4493 };
4494
4495 static void
4496 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4497                             __rte_unused struct cmdline *cl,
4498                             __rte_unused void *data)
4499 {
4500         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4501
4502         if (strcmp(res->mode, "on") == 0)
4503                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4504         else
4505                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4506 }
4507
4508 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4509         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4510                                  tx_vlan, "tx_vlan");
4511 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4512         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4513                                  set, "set");
4514 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4515         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4516                                  pvid, "pvid");
4517 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4518         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4519                              port_id, RTE_UINT16);
4520 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4521         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4522                               vlan_id, RTE_UINT16);
4523 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4524         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4525                                  mode, "on#off");
4526
4527 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4528         .f = cmd_tx_vlan_set_pvid_parsed,
4529         .data = NULL,
4530         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4531         .tokens = {
4532                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4533                 (void *)&cmd_tx_vlan_set_pvid_set,
4534                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4535                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4536                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4537                 (void *)&cmd_tx_vlan_set_pvid_mode,
4538                 NULL,
4539         },
4540 };
4541
4542 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4543 struct cmd_tx_vlan_reset_result {
4544         cmdline_fixed_string_t tx_vlan;
4545         cmdline_fixed_string_t reset;
4546         portid_t port_id;
4547 };
4548
4549 static void
4550 cmd_tx_vlan_reset_parsed(void *parsed_result,
4551                          __rte_unused struct cmdline *cl,
4552                          __rte_unused void *data)
4553 {
4554         struct cmd_tx_vlan_reset_result *res = parsed_result;
4555
4556         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4557                 return;
4558
4559         if (!port_is_stopped(res->port_id)) {
4560                 printf("Please stop port %d first\n", res->port_id);
4561                 return;
4562         }
4563
4564         tx_vlan_reset(res->port_id);
4565
4566         cmd_reconfig_device_queue(res->port_id, 1, 1);
4567 }
4568
4569 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4570         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4571                                  tx_vlan, "tx_vlan");
4572 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4573         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4574                                  reset, "reset");
4575 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4576         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4577                               port_id, RTE_UINT16);
4578
4579 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4580         .f = cmd_tx_vlan_reset_parsed,
4581         .data = NULL,
4582         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4583                 "VLAN header in packets sent on a port",
4584         .tokens = {
4585                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4586                 (void *)&cmd_tx_vlan_reset_reset,
4587                 (void *)&cmd_tx_vlan_reset_portid,
4588                 NULL,
4589         },
4590 };
4591
4592
4593 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4594 struct cmd_csum_result {
4595         cmdline_fixed_string_t csum;
4596         cmdline_fixed_string_t mode;
4597         cmdline_fixed_string_t proto;
4598         cmdline_fixed_string_t hwsw;
4599         portid_t port_id;
4600 };
4601
4602 static void
4603 csum_show(int port_id)
4604 {
4605         struct rte_eth_dev_info dev_info;
4606         uint64_t tx_offloads;
4607         int ret;
4608
4609         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4610         printf("Parse tunnel is %s\n",
4611                 (ports[port_id].parse_tunnel) ? "on" : "off");
4612         printf("IP checksum offload is %s\n",
4613                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4614         printf("UDP checksum offload is %s\n",
4615                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4616         printf("TCP checksum offload is %s\n",
4617                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4618         printf("SCTP checksum offload is %s\n",
4619                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4620         printf("Outer-Ip checksum offload is %s\n",
4621                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4622         printf("Outer-Udp checksum offload is %s\n",
4623                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4624
4625         /* display warnings if configuration is not supported by the NIC */
4626         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4627         if (ret != 0)
4628                 return;
4629
4630         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4631                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4632                 printf("Warning: hardware IP checksum enabled but not "
4633                         "supported by port %d\n", port_id);
4634         }
4635         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4636                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4637                 printf("Warning: hardware UDP checksum enabled but not "
4638                         "supported by port %d\n", port_id);
4639         }
4640         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4641                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4642                 printf("Warning: hardware TCP checksum enabled but not "
4643                         "supported by port %d\n", port_id);
4644         }
4645         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4646                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4647                 printf("Warning: hardware SCTP checksum enabled but not "
4648                         "supported by port %d\n", port_id);
4649         }
4650         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4651                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4652                 printf("Warning: hardware outer IP checksum enabled but not "
4653                         "supported by port %d\n", port_id);
4654         }
4655         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4656                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4657                         == 0) {
4658                 printf("Warning: hardware outer UDP checksum enabled but not "
4659                         "supported by port %d\n", port_id);
4660         }
4661 }
4662
4663 static void
4664 cmd_config_queue_tx_offloads(struct rte_port *port)
4665 {
4666         int k;
4667
4668         /* Apply queue tx offloads configuration */
4669         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4670                 port->tx_conf[k].offloads =
4671                         port->dev_conf.txmode.offloads;
4672 }
4673
4674 static void
4675 cmd_csum_parsed(void *parsed_result,
4676                        __rte_unused struct cmdline *cl,
4677                        __rte_unused void *data)
4678 {
4679         struct cmd_csum_result *res = parsed_result;
4680         int hw = 0;
4681         uint64_t csum_offloads = 0;
4682         struct rte_eth_dev_info dev_info;
4683         int ret;
4684
4685         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4686                 printf("invalid port %d\n", res->port_id);
4687                 return;
4688         }
4689         if (!port_is_stopped(res->port_id)) {
4690                 printf("Please stop port %d first\n", res->port_id);
4691                 return;
4692         }
4693
4694         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4695         if (ret != 0)
4696                 return;
4697
4698         if (!strcmp(res->mode, "set")) {
4699
4700                 if (!strcmp(res->hwsw, "hw"))
4701                         hw = 1;
4702
4703                 if (!strcmp(res->proto, "ip")) {
4704                         if (hw == 0 || (dev_info.tx_offload_capa &
4705                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4706                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4707                         } else {
4708                                 printf("IP checksum offload is not supported "
4709                                        "by port %u\n", res->port_id);
4710                         }
4711                 } else if (!strcmp(res->proto, "udp")) {
4712                         if (hw == 0 || (dev_info.tx_offload_capa &
4713                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4714                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4715                         } else {
4716                                 printf("UDP checksum offload is not supported "
4717                                        "by port %u\n", res->port_id);
4718                         }
4719                 } else if (!strcmp(res->proto, "tcp")) {
4720                         if (hw == 0 || (dev_info.tx_offload_capa &
4721                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4722                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4723                         } else {
4724                                 printf("TCP checksum offload is not supported "
4725                                        "by port %u\n", res->port_id);
4726                         }
4727                 } else if (!strcmp(res->proto, "sctp")) {
4728                         if (hw == 0 || (dev_info.tx_offload_capa &
4729                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4730                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4731                         } else {
4732                                 printf("SCTP checksum offload is not supported "
4733                                        "by port %u\n", res->port_id);
4734                         }
4735                 } else if (!strcmp(res->proto, "outer-ip")) {
4736                         if (hw == 0 || (dev_info.tx_offload_capa &
4737                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4738                                 csum_offloads |=
4739                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4740                         } else {
4741                                 printf("Outer IP checksum offload is not "
4742                                        "supported by port %u\n", res->port_id);
4743                         }
4744                 } else if (!strcmp(res->proto, "outer-udp")) {
4745                         if (hw == 0 || (dev_info.tx_offload_capa &
4746                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4747                                 csum_offloads |=
4748                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4749                         } else {
4750                                 printf("Outer UDP checksum offload is not "
4751                                        "supported by port %u\n", res->port_id);
4752                         }
4753                 }
4754
4755                 if (hw) {
4756                         ports[res->port_id].dev_conf.txmode.offloads |=
4757                                                         csum_offloads;
4758                 } else {
4759                         ports[res->port_id].dev_conf.txmode.offloads &=
4760                                                         (~csum_offloads);
4761                 }
4762                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4763         }
4764         csum_show(res->port_id);
4765
4766         cmd_reconfig_device_queue(res->port_id, 1, 1);
4767 }
4768
4769 cmdline_parse_token_string_t cmd_csum_csum =
4770         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4771                                 csum, "csum");
4772 cmdline_parse_token_string_t cmd_csum_mode =
4773         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4774                                 mode, "set");
4775 cmdline_parse_token_string_t cmd_csum_proto =
4776         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4777                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4778 cmdline_parse_token_string_t cmd_csum_hwsw =
4779         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4780                                 hwsw, "hw#sw");
4781 cmdline_parse_token_num_t cmd_csum_portid =
4782         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4783                                 port_id, RTE_UINT16);
4784
4785 cmdline_parse_inst_t cmd_csum_set = {
4786         .f = cmd_csum_parsed,
4787         .data = NULL,
4788         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4789                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4790                 "using csum forward engine",
4791         .tokens = {
4792                 (void *)&cmd_csum_csum,
4793                 (void *)&cmd_csum_mode,
4794                 (void *)&cmd_csum_proto,
4795                 (void *)&cmd_csum_hwsw,
4796                 (void *)&cmd_csum_portid,
4797                 NULL,
4798         },
4799 };
4800
4801 cmdline_parse_token_string_t cmd_csum_mode_show =
4802         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4803                                 mode, "show");
4804
4805 cmdline_parse_inst_t cmd_csum_show = {
4806         .f = cmd_csum_parsed,
4807         .data = NULL,
4808         .help_str = "csum show <port_id>: Show checksum offload configuration",
4809         .tokens = {
4810                 (void *)&cmd_csum_csum,
4811                 (void *)&cmd_csum_mode_show,
4812                 (void *)&cmd_csum_portid,
4813                 NULL,
4814         },
4815 };
4816
4817 /* Enable/disable tunnel parsing */
4818 struct cmd_csum_tunnel_result {
4819         cmdline_fixed_string_t csum;
4820         cmdline_fixed_string_t parse;
4821         cmdline_fixed_string_t onoff;
4822         portid_t port_id;
4823 };
4824
4825 static void
4826 cmd_csum_tunnel_parsed(void *parsed_result,
4827                        __rte_unused struct cmdline *cl,
4828                        __rte_unused void *data)
4829 {
4830         struct cmd_csum_tunnel_result *res = parsed_result;
4831
4832         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4833                 return;
4834
4835         if (!strcmp(res->onoff, "on"))
4836                 ports[res->port_id].parse_tunnel = 1;
4837         else
4838                 ports[res->port_id].parse_tunnel = 0;
4839
4840         csum_show(res->port_id);
4841 }
4842
4843 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4844         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4845                                 csum, "csum");
4846 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4847         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4848                                 parse, "parse-tunnel");
4849 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4850         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4851                                 onoff, "on#off");
4852 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4853         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4854                                 port_id, RTE_UINT16);
4855
4856 cmdline_parse_inst_t cmd_csum_tunnel = {
4857         .f = cmd_csum_tunnel_parsed,
4858         .data = NULL,
4859         .help_str = "csum parse-tunnel on|off <port_id>: "
4860                 "Enable/Disable parsing of tunnels for csum engine",
4861         .tokens = {
4862                 (void *)&cmd_csum_tunnel_csum,
4863                 (void *)&cmd_csum_tunnel_parse,
4864                 (void *)&cmd_csum_tunnel_onoff,
4865                 (void *)&cmd_csum_tunnel_portid,
4866                 NULL,
4867         },
4868 };
4869
4870 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4871 struct cmd_tso_set_result {
4872         cmdline_fixed_string_t tso;
4873         cmdline_fixed_string_t mode;
4874         uint16_t tso_segsz;
4875         portid_t port_id;
4876 };
4877
4878 static void
4879 cmd_tso_set_parsed(void *parsed_result,
4880                        __rte_unused struct cmdline *cl,
4881                        __rte_unused void *data)
4882 {
4883         struct cmd_tso_set_result *res = parsed_result;
4884         struct rte_eth_dev_info dev_info;
4885         int ret;
4886
4887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4888                 return;
4889         if (!port_is_stopped(res->port_id)) {
4890                 printf("Please stop port %d first\n", res->port_id);
4891                 return;
4892         }
4893
4894         if (!strcmp(res->mode, "set"))
4895                 ports[res->port_id].tso_segsz = res->tso_segsz;
4896
4897         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4898         if (ret != 0)
4899                 return;
4900
4901         if ((ports[res->port_id].tso_segsz != 0) &&
4902                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4903                 printf("Error: TSO is not supported by port %d\n",
4904                        res->port_id);
4905                 return;
4906         }
4907
4908         if (ports[res->port_id].tso_segsz == 0) {
4909                 ports[res->port_id].dev_conf.txmode.offloads &=
4910                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4911                 printf("TSO for non-tunneled packets is disabled\n");
4912         } else {
4913                 ports[res->port_id].dev_conf.txmode.offloads |=
4914                                                 DEV_TX_OFFLOAD_TCP_TSO;
4915                 printf("TSO segment size for non-tunneled packets is %d\n",
4916                         ports[res->port_id].tso_segsz);
4917         }
4918         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4919
4920         /* display warnings if configuration is not supported by the NIC */
4921         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4922         if (ret != 0)
4923                 return;
4924
4925         if ((ports[res->port_id].tso_segsz != 0) &&
4926                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4927                 printf("Warning: TSO enabled but not "
4928                         "supported by port %d\n", res->port_id);
4929         }
4930
4931         cmd_reconfig_device_queue(res->port_id, 1, 1);
4932 }
4933
4934 cmdline_parse_token_string_t cmd_tso_set_tso =
4935         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4936                                 tso, "tso");
4937 cmdline_parse_token_string_t cmd_tso_set_mode =
4938         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4939                                 mode, "set");
4940 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4941         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4942                                 tso_segsz, RTE_UINT16);
4943 cmdline_parse_token_num_t cmd_tso_set_portid =
4944         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4945                                 port_id, RTE_UINT16);
4946
4947 cmdline_parse_inst_t cmd_tso_set = {
4948         .f = cmd_tso_set_parsed,
4949         .data = NULL,
4950         .help_str = "tso set <tso_segsz> <port_id>: "
4951                 "Set TSO segment size of non-tunneled packets for csum engine "
4952                 "(0 to disable)",
4953         .tokens = {
4954                 (void *)&cmd_tso_set_tso,
4955                 (void *)&cmd_tso_set_mode,
4956                 (void *)&cmd_tso_set_tso_segsz,
4957                 (void *)&cmd_tso_set_portid,
4958                 NULL,
4959         },
4960 };
4961
4962 cmdline_parse_token_string_t cmd_tso_show_mode =
4963         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4964                                 mode, "show");
4965
4966
4967 cmdline_parse_inst_t cmd_tso_show = {
4968         .f = cmd_tso_set_parsed,
4969         .data = NULL,
4970         .help_str = "tso show <port_id>: "
4971                 "Show TSO segment size of non-tunneled packets for csum engine",
4972         .tokens = {
4973                 (void *)&cmd_tso_set_tso,
4974                 (void *)&cmd_tso_show_mode,
4975                 (void *)&cmd_tso_set_portid,
4976                 NULL,
4977         },
4978 };
4979
4980 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4981 struct cmd_tunnel_tso_set_result {
4982         cmdline_fixed_string_t tso;
4983         cmdline_fixed_string_t mode;
4984         uint16_t tso_segsz;
4985         portid_t port_id;
4986 };
4987
4988 static struct rte_eth_dev_info
4989 check_tunnel_tso_nic_support(portid_t port_id)
4990 {
4991         struct rte_eth_dev_info dev_info;
4992
4993         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4994                 return dev_info;
4995
4996         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4997                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4998                        "not enabled for port %d\n", port_id);
4999         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5000                 printf("Warning: GRE TUNNEL TSO not supported therefore "
5001                        "not enabled for port %d\n", port_id);
5002         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5003                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
5004                        "not enabled for port %d\n", port_id);
5005         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5006                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5007                        "not enabled for port %d\n", port_id);
5008         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5009                 printf("Warning: IP TUNNEL TSO not supported therefore "
5010                        "not enabled for port %d\n", port_id);
5011         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5012                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5013                        "not enabled for port %d\n", port_id);
5014         return dev_info;
5015 }
5016
5017 static void
5018 cmd_tunnel_tso_set_parsed(void *parsed_result,
5019                           __rte_unused struct cmdline *cl,
5020                           __rte_unused void *data)
5021 {
5022         struct cmd_tunnel_tso_set_result *res = parsed_result;
5023         struct rte_eth_dev_info dev_info;
5024
5025         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5026                 return;
5027         if (!port_is_stopped(res->port_id)) {
5028                 printf("Please stop port %d first\n", res->port_id);
5029                 return;
5030         }
5031
5032         if (!strcmp(res->mode, "set"))
5033                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5034
5035         dev_info = check_tunnel_tso_nic_support(res->port_id);
5036         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5037                 ports[res->port_id].dev_conf.txmode.offloads &=
5038                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5039                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5040                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5041                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5042                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5043                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5044                 printf("TSO for tunneled packets is disabled\n");
5045         } else {
5046                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5047                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5048                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5049                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5050                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5051                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5052
5053                 ports[res->port_id].dev_conf.txmode.offloads |=
5054                         (tso_offloads & dev_info.tx_offload_capa);
5055                 printf("TSO segment size for tunneled packets is %d\n",
5056                         ports[res->port_id].tunnel_tso_segsz);
5057
5058                 /* Below conditions are needed to make it work:
5059                  * (1) tunnel TSO is supported by the NIC;
5060                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5061                  * are recognized;
5062                  * (3) for tunneled pkts with outer L3 of IPv4,
5063                  * "csum set outer-ip" must be set to hw, because after tso,
5064                  * total_len of outer IP header is changed, and the checksum
5065                  * of outer IP header calculated by sw should be wrong; that
5066                  * is not necessary for IPv6 tunneled pkts because there's no
5067                  * checksum in IP header anymore.
5068                  */
5069
5070                 if (!ports[res->port_id].parse_tunnel)
5071                         printf("Warning: csum parse_tunnel must be set "
5072                                 "so that tunneled packets are recognized\n");
5073                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5074                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5075                         printf("Warning: csum set outer-ip must be set to hw "
5076                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5077         }
5078
5079         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5080         cmd_reconfig_device_queue(res->port_id, 1, 1);
5081 }
5082
5083 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5084         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5085                                 tso, "tunnel_tso");
5086 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5087         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5088                                 mode, "set");
5089 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5090         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5091                                 tso_segsz, RTE_UINT16);
5092 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5093         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5094                                 port_id, RTE_UINT16);
5095
5096 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5097         .f = cmd_tunnel_tso_set_parsed,
5098         .data = NULL,
5099         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5100                 "Set TSO segment size of tunneled packets for csum engine "
5101                 "(0 to disable)",
5102         .tokens = {
5103                 (void *)&cmd_tunnel_tso_set_tso,
5104                 (void *)&cmd_tunnel_tso_set_mode,
5105                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5106                 (void *)&cmd_tunnel_tso_set_portid,
5107                 NULL,
5108         },
5109 };
5110
5111 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5112         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5113                                 mode, "show");
5114
5115
5116 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5117         .f = cmd_tunnel_tso_set_parsed,
5118         .data = NULL,
5119         .help_str = "tunnel_tso show <port_id> "
5120                 "Show TSO segment size of tunneled packets for csum engine",
5121         .tokens = {
5122                 (void *)&cmd_tunnel_tso_set_tso,
5123                 (void *)&cmd_tunnel_tso_show_mode,
5124                 (void *)&cmd_tunnel_tso_set_portid,
5125                 NULL,
5126         },
5127 };
5128
5129 /* *** SET GRO FOR A PORT *** */
5130 struct cmd_gro_enable_result {
5131         cmdline_fixed_string_t cmd_set;
5132         cmdline_fixed_string_t cmd_port;
5133         cmdline_fixed_string_t cmd_keyword;
5134         cmdline_fixed_string_t cmd_onoff;
5135         portid_t cmd_pid;
5136 };
5137
5138 static void
5139 cmd_gro_enable_parsed(void *parsed_result,
5140                 __rte_unused struct cmdline *cl,
5141                 __rte_unused void *data)
5142 {
5143         struct cmd_gro_enable_result *res;
5144
5145         res = parsed_result;
5146         if (!strcmp(res->cmd_keyword, "gro"))
5147                 setup_gro(res->cmd_onoff, res->cmd_pid);
5148 }
5149
5150 cmdline_parse_token_string_t cmd_gro_enable_set =
5151         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5152                         cmd_set, "set");
5153 cmdline_parse_token_string_t cmd_gro_enable_port =
5154         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5155                         cmd_keyword, "port");
5156 cmdline_parse_token_num_t cmd_gro_enable_pid =
5157         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5158                         cmd_pid, RTE_UINT16);
5159 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5160         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5161                         cmd_keyword, "gro");
5162 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5163         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5164                         cmd_onoff, "on#off");
5165
5166 cmdline_parse_inst_t cmd_gro_enable = {
5167         .f = cmd_gro_enable_parsed,
5168         .data = NULL,
5169         .help_str = "set port <port_id> gro on|off",
5170         .tokens = {
5171                 (void *)&cmd_gro_enable_set,
5172                 (void *)&cmd_gro_enable_port,
5173                 (void *)&cmd_gro_enable_pid,
5174                 (void *)&cmd_gro_enable_keyword,
5175                 (void *)&cmd_gro_enable_onoff,
5176                 NULL,
5177         },
5178 };
5179
5180 /* *** DISPLAY GRO CONFIGURATION *** */
5181 struct cmd_gro_show_result {
5182         cmdline_fixed_string_t cmd_show;
5183         cmdline_fixed_string_t cmd_port;
5184         cmdline_fixed_string_t cmd_keyword;
5185         portid_t cmd_pid;
5186 };
5187
5188 static void
5189 cmd_gro_show_parsed(void *parsed_result,
5190                 __rte_unused struct cmdline *cl,
5191                 __rte_unused void *data)
5192 {
5193         struct cmd_gro_show_result *res;
5194
5195         res = parsed_result;
5196         if (!strcmp(res->cmd_keyword, "gro"))
5197                 show_gro(res->cmd_pid);
5198 }
5199
5200 cmdline_parse_token_string_t cmd_gro_show_show =
5201         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5202                         cmd_show, "show");
5203 cmdline_parse_token_string_t cmd_gro_show_port =
5204         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5205                         cmd_port, "port");
5206 cmdline_parse_token_num_t cmd_gro_show_pid =
5207         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5208                         cmd_pid, RTE_UINT16);
5209 cmdline_parse_token_string_t cmd_gro_show_keyword =
5210         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5211                         cmd_keyword, "gro");
5212
5213 cmdline_parse_inst_t cmd_gro_show = {
5214         .f = cmd_gro_show_parsed,
5215         .data = NULL,
5216         .help_str = "show port <port_id> gro",
5217         .tokens = {
5218                 (void *)&cmd_gro_show_show,
5219                 (void *)&cmd_gro_show_port,
5220                 (void *)&cmd_gro_show_pid,
5221                 (void *)&cmd_gro_show_keyword,
5222                 NULL,
5223         },
5224 };
5225
5226 /* *** SET FLUSH CYCLES FOR GRO *** */
5227 struct cmd_gro_flush_result {
5228         cmdline_fixed_string_t cmd_set;
5229         cmdline_fixed_string_t cmd_keyword;
5230         cmdline_fixed_string_t cmd_flush;
5231         uint8_t cmd_cycles;
5232 };
5233
5234 static void
5235 cmd_gro_flush_parsed(void *parsed_result,
5236                 __rte_unused struct cmdline *cl,
5237                 __rte_unused void *data)
5238 {
5239         struct cmd_gro_flush_result *res;
5240
5241         res = parsed_result;
5242         if ((!strcmp(res->cmd_keyword, "gro")) &&
5243                         (!strcmp(res->cmd_flush, "flush")))
5244                 setup_gro_flush_cycles(res->cmd_cycles);
5245 }
5246
5247 cmdline_parse_token_string_t cmd_gro_flush_set =
5248         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5249                         cmd_set, "set");
5250 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5251         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5252                         cmd_keyword, "gro");
5253 cmdline_parse_token_string_t cmd_gro_flush_flush =
5254         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5255                         cmd_flush, "flush");
5256 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5257         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5258                         cmd_cycles, RTE_UINT8);
5259
5260 cmdline_parse_inst_t cmd_gro_flush = {
5261         .f = cmd_gro_flush_parsed,
5262         .data = NULL,
5263         .help_str = "set gro flush <cycles>",
5264         .tokens = {
5265                 (void *)&cmd_gro_flush_set,
5266                 (void *)&cmd_gro_flush_keyword,
5267                 (void *)&cmd_gro_flush_flush,
5268                 (void *)&cmd_gro_flush_cycles,
5269                 NULL,
5270         },
5271 };
5272
5273 /* *** ENABLE/DISABLE GSO *** */
5274 struct cmd_gso_enable_result {
5275         cmdline_fixed_string_t cmd_set;
5276         cmdline_fixed_string_t cmd_port;
5277         cmdline_fixed_string_t cmd_keyword;
5278         cmdline_fixed_string_t cmd_mode;
5279         portid_t cmd_pid;
5280 };
5281
5282 static void
5283 cmd_gso_enable_parsed(void *parsed_result,
5284                 __rte_unused struct cmdline *cl,
5285                 __rte_unused void *data)
5286 {
5287         struct cmd_gso_enable_result *res;
5288
5289         res = parsed_result;
5290         if (!strcmp(res->cmd_keyword, "gso"))
5291                 setup_gso(res->cmd_mode, res->cmd_pid);
5292 }
5293
5294 cmdline_parse_token_string_t cmd_gso_enable_set =
5295         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5296                         cmd_set, "set");
5297 cmdline_parse_token_string_t cmd_gso_enable_port =
5298         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5299                         cmd_port, "port");
5300 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5301         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5302                         cmd_keyword, "gso");
5303 cmdline_parse_token_string_t cmd_gso_enable_mode =
5304         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5305                         cmd_mode, "on#off");
5306 cmdline_parse_token_num_t cmd_gso_enable_pid =
5307         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5308                         cmd_pid, RTE_UINT16);
5309
5310 cmdline_parse_inst_t cmd_gso_enable = {
5311         .f = cmd_gso_enable_parsed,
5312         .data = NULL,
5313         .help_str = "set port <port_id> gso on|off",
5314         .tokens = {
5315                 (void *)&cmd_gso_enable_set,
5316                 (void *)&cmd_gso_enable_port,
5317                 (void *)&cmd_gso_enable_pid,
5318                 (void *)&cmd_gso_enable_keyword,
5319                 (void *)&cmd_gso_enable_mode,
5320                 NULL,
5321         },
5322 };
5323
5324 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5325 struct cmd_gso_size_result {
5326         cmdline_fixed_string_t cmd_set;
5327         cmdline_fixed_string_t cmd_keyword;
5328         cmdline_fixed_string_t cmd_segsz;
5329         uint16_t cmd_size;
5330 };
5331
5332 static void
5333 cmd_gso_size_parsed(void *parsed_result,
5334                        __rte_unused struct cmdline *cl,
5335                        __rte_unused void *data)
5336 {
5337         struct cmd_gso_size_result *res = parsed_result;
5338
5339         if (test_done == 0) {
5340                 printf("Before setting GSO segsz, please first"
5341                                 " stop forwarding\n");
5342                 return;
5343         }
5344
5345         if (!strcmp(res->cmd_keyword, "gso") &&
5346                         !strcmp(res->cmd_segsz, "segsz")) {
5347                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5348                         printf("gso_size should be larger than %zu."
5349                                         " Please input a legal value\n",
5350                                         RTE_GSO_SEG_SIZE_MIN);
5351                 else
5352                         gso_max_segment_size = res->cmd_size;
5353         }
5354 }
5355
5356 cmdline_parse_token_string_t cmd_gso_size_set =
5357         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5358                                 cmd_set, "set");
5359 cmdline_parse_token_string_t cmd_gso_size_keyword =
5360         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5361                                 cmd_keyword, "gso");
5362 cmdline_parse_token_string_t cmd_gso_size_segsz =
5363         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5364                                 cmd_segsz, "segsz");
5365 cmdline_parse_token_num_t cmd_gso_size_size =
5366         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5367                                 cmd_size, RTE_UINT16);
5368
5369 cmdline_parse_inst_t cmd_gso_size = {
5370         .f = cmd_gso_size_parsed,
5371         .data = NULL,
5372         .help_str = "set gso segsz <length>",
5373         .tokens = {
5374                 (void *)&cmd_gso_size_set,
5375                 (void *)&cmd_gso_size_keyword,
5376                 (void *)&cmd_gso_size_segsz,
5377                 (void *)&cmd_gso_size_size,
5378                 NULL,
5379         },
5380 };
5381
5382 /* *** SHOW GSO CONFIGURATION *** */
5383 struct cmd_gso_show_result {
5384         cmdline_fixed_string_t cmd_show;
5385         cmdline_fixed_string_t cmd_port;
5386         cmdline_fixed_string_t cmd_keyword;
5387         portid_t cmd_pid;
5388 };
5389
5390 static void
5391 cmd_gso_show_parsed(void *parsed_result,
5392                        __rte_unused struct cmdline *cl,
5393                        __rte_unused void *data)
5394 {
5395         struct cmd_gso_show_result *res = parsed_result;
5396
5397         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5398                 printf("invalid port id %u\n", res->cmd_pid);
5399                 return;
5400         }
5401         if (!strcmp(res->cmd_keyword, "gso")) {
5402                 if (gso_ports[res->cmd_pid].enable) {
5403                         printf("Max GSO'd packet size: %uB\n"
5404                                         "Supported GSO types: TCP/IPv4, "
5405                                         "UDP/IPv4, VxLAN with inner "
5406                                         "TCP/IPv4 packet, GRE with inner "
5407                                         "TCP/IPv4 packet\n",
5408                                         gso_max_segment_size);
5409                 } else
5410                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5411         }
5412 }
5413
5414 cmdline_parse_token_string_t cmd_gso_show_show =
5415 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5416                 cmd_show, "show");
5417 cmdline_parse_token_string_t cmd_gso_show_port =
5418 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5419                 cmd_port, "port");
5420 cmdline_parse_token_string_t cmd_gso_show_keyword =
5421         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5422                                 cmd_keyword, "gso");
5423 cmdline_parse_token_num_t cmd_gso_show_pid =
5424         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5425                                 cmd_pid, RTE_UINT16);
5426
5427 cmdline_parse_inst_t cmd_gso_show = {
5428         .f = cmd_gso_show_parsed,
5429         .data = NULL,
5430         .help_str = "show port <port_id> gso",
5431         .tokens = {
5432                 (void *)&cmd_gso_show_show,
5433                 (void *)&cmd_gso_show_port,
5434                 (void *)&cmd_gso_show_pid,
5435                 (void *)&cmd_gso_show_keyword,
5436                 NULL,
5437         },
5438 };
5439
5440 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5441 struct cmd_set_flush_rx {
5442         cmdline_fixed_string_t set;
5443         cmdline_fixed_string_t flush_rx;
5444         cmdline_fixed_string_t mode;
5445 };
5446
5447 static void
5448 cmd_set_flush_rx_parsed(void *parsed_result,
5449                 __rte_unused struct cmdline *cl,
5450                 __rte_unused void *data)
5451 {
5452         struct cmd_set_flush_rx *res = parsed_result;
5453         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5454 }
5455
5456 cmdline_parse_token_string_t cmd_setflushrx_set =
5457         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5458                         set, "set");
5459 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5460         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5461                         flush_rx, "flush_rx");
5462 cmdline_parse_token_string_t cmd_setflushrx_mode =
5463         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5464                         mode, "on#off");
5465
5466
5467 cmdline_parse_inst_t cmd_set_flush_rx = {
5468         .f = cmd_set_flush_rx_parsed,
5469         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5470         .data = NULL,
5471         .tokens = {
5472                 (void *)&cmd_setflushrx_set,
5473                 (void *)&cmd_setflushrx_flush_rx,
5474                 (void *)&cmd_setflushrx_mode,
5475                 NULL,
5476         },
5477 };
5478
5479 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5480 struct cmd_set_link_check {
5481         cmdline_fixed_string_t set;
5482         cmdline_fixed_string_t link_check;
5483         cmdline_fixed_string_t mode;
5484 };
5485
5486 static void
5487 cmd_set_link_check_parsed(void *parsed_result,
5488                 __rte_unused struct cmdline *cl,
5489                 __rte_unused void *data)
5490 {
5491         struct cmd_set_link_check *res = parsed_result;
5492         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5493 }
5494
5495 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5496         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5497                         set, "set");
5498 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5499         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5500                         link_check, "link_check");
5501 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5502         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5503                         mode, "on#off");
5504
5505
5506 cmdline_parse_inst_t cmd_set_link_check = {
5507         .f = cmd_set_link_check_parsed,
5508         .help_str = "set link_check on|off: Enable/Disable link status check "
5509                     "when starting/stopping a port",
5510         .data = NULL,
5511         .tokens = {
5512                 (void *)&cmd_setlinkcheck_set,
5513                 (void *)&cmd_setlinkcheck_link_check,
5514                 (void *)&cmd_setlinkcheck_mode,
5515                 NULL,
5516         },
5517 };
5518
5519 /* *** SET NIC BYPASS MODE *** */
5520 struct cmd_set_bypass_mode_result {
5521         cmdline_fixed_string_t set;
5522         cmdline_fixed_string_t bypass;
5523         cmdline_fixed_string_t mode;
5524         cmdline_fixed_string_t value;
5525         portid_t port_id;
5526 };
5527
5528 static void
5529 cmd_set_bypass_mode_parsed(void *parsed_result,
5530                 __rte_unused struct cmdline *cl,
5531                 __rte_unused void *data)
5532 {
5533         struct cmd_set_bypass_mode_result *res = parsed_result;
5534         portid_t port_id = res->port_id;
5535         int32_t rc = -EINVAL;
5536
5537 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5538         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5539
5540         if (!strcmp(res->value, "bypass"))
5541                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5542         else if (!strcmp(res->value, "isolate"))
5543                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5544         else
5545                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5546
5547         /* Set the bypass mode for the relevant port. */
5548         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5549 #endif
5550         if (rc != 0)
5551                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5552 }
5553
5554 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5556                         set, "set");
5557 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5559                         bypass, "bypass");
5560 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5561         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5562                         mode, "mode");
5563 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5564         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5565                         value, "normal#bypass#isolate");
5566 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5567         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5568                                 port_id, RTE_UINT16);
5569
5570 cmdline_parse_inst_t cmd_set_bypass_mode = {
5571         .f = cmd_set_bypass_mode_parsed,
5572         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5573                     "Set the NIC bypass mode for port_id",
5574         .data = NULL,
5575         .tokens = {
5576                 (void *)&cmd_setbypass_mode_set,
5577                 (void *)&cmd_setbypass_mode_bypass,
5578                 (void *)&cmd_setbypass_mode_mode,
5579                 (void *)&cmd_setbypass_mode_value,
5580                 (void *)&cmd_setbypass_mode_port,
5581                 NULL,
5582         },
5583 };
5584
5585 /* *** SET NIC BYPASS EVENT *** */
5586 struct cmd_set_bypass_event_result {
5587         cmdline_fixed_string_t set;
5588         cmdline_fixed_string_t bypass;
5589         cmdline_fixed_string_t event;
5590         cmdline_fixed_string_t event_value;
5591         cmdline_fixed_string_t mode;
5592         cmdline_fixed_string_t mode_value;
5593         portid_t port_id;
5594 };
5595
5596 static void
5597 cmd_set_bypass_event_parsed(void *parsed_result,
5598                 __rte_unused struct cmdline *cl,
5599                 __rte_unused void *data)
5600 {
5601         int32_t rc = -EINVAL;
5602         struct cmd_set_bypass_event_result *res = parsed_result;
5603         portid_t port_id = res->port_id;
5604
5605 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5606         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5607         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5608
5609         if (!strcmp(res->event_value, "timeout"))
5610                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5611         else if (!strcmp(res->event_value, "os_on"))
5612                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5613         else if (!strcmp(res->event_value, "os_off"))
5614                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5615         else if (!strcmp(res->event_value, "power_on"))
5616                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5617         else if (!strcmp(res->event_value, "power_off"))
5618                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5619         else
5620                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5621
5622         if (!strcmp(res->mode_value, "bypass"))
5623                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5624         else if (!strcmp(res->mode_value, "isolate"))
5625                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5626         else
5627                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5628
5629         /* Set the watchdog timeout. */
5630         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5631
5632                 rc = -EINVAL;
5633                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5634                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5635                                                            bypass_timeout);
5636                 }
5637                 if (rc != 0) {
5638                         printf("Failed to set timeout value %u "
5639                         "for port %d, errto code: %d.\n",
5640                         bypass_timeout, port_id, rc);
5641                 }
5642         }
5643
5644         /* Set the bypass event to transition to bypass mode. */
5645         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5646                                               bypass_mode);
5647 #endif
5648
5649         if (rc != 0)
5650                 printf("\t Failed to set bypass event for port = %d.\n",
5651                        port_id);
5652 }
5653
5654 cmdline_parse_token_string_t cmd_setbypass_event_set =
5655         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5656                         set, "set");
5657 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5658         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5659                         bypass, "bypass");
5660 cmdline_parse_token_string_t cmd_setbypass_event_event =
5661         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5662                         event, "event");
5663 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5664         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5665                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5666 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5667         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5668                         mode, "mode");
5669 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5670         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5671                         mode_value, "normal#bypass#isolate");
5672 cmdline_parse_token_num_t cmd_setbypass_event_port =
5673         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5674                                 port_id, RTE_UINT16);
5675
5676 cmdline_parse_inst_t cmd_set_bypass_event = {
5677         .f = cmd_set_bypass_event_parsed,
5678         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5679                 "power_off mode normal|bypass|isolate <port_id>: "
5680                 "Set the NIC bypass event mode for port_id",
5681         .data = NULL,
5682         .tokens = {
5683                 (void *)&cmd_setbypass_event_set,
5684                 (void *)&cmd_setbypass_event_bypass,
5685                 (void *)&cmd_setbypass_event_event,
5686                 (void *)&cmd_setbypass_event_event_value,
5687                 (void *)&cmd_setbypass_event_mode,
5688                 (void *)&cmd_setbypass_event_mode_value,
5689                 (void *)&cmd_setbypass_event_port,
5690                 NULL,
5691         },
5692 };
5693
5694
5695 /* *** SET NIC BYPASS TIMEOUT *** */
5696 struct cmd_set_bypass_timeout_result {
5697         cmdline_fixed_string_t set;
5698         cmdline_fixed_string_t bypass;
5699         cmdline_fixed_string_t timeout;
5700         cmdline_fixed_string_t value;
5701 };
5702
5703 static void
5704 cmd_set_bypass_timeout_parsed(void *parsed_result,
5705                 __rte_unused struct cmdline *cl,
5706                 __rte_unused void *data)
5707 {
5708         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5709
5710 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5711         if (!strcmp(res->value, "1.5"))
5712                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5713         else if (!strcmp(res->value, "2"))
5714                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5715         else if (!strcmp(res->value, "3"))
5716                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5717         else if (!strcmp(res->value, "4"))
5718                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5719         else if (!strcmp(res->value, "8"))
5720                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5721         else if (!strcmp(res->value, "16"))
5722                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5723         else if (!strcmp(res->value, "32"))
5724                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5725         else
5726                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5727 #endif
5728 }
5729
5730 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5731         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5732                         set, "set");
5733 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5734         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5735                         bypass, "bypass");
5736 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5737         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5738                         timeout, "timeout");
5739 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5740         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5741                         value, "0#1.5#2#3#4#8#16#32");
5742
5743 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5744         .f = cmd_set_bypass_timeout_parsed,
5745         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5746                 "Set the NIC bypass watchdog timeout in seconds",
5747         .data = NULL,
5748         .tokens = {
5749                 (void *)&cmd_setbypass_timeout_set,
5750                 (void *)&cmd_setbypass_timeout_bypass,
5751                 (void *)&cmd_setbypass_timeout_timeout,
5752                 (void *)&cmd_setbypass_timeout_value,
5753                 NULL,
5754         },
5755 };
5756
5757 /* *** SHOW NIC BYPASS MODE *** */
5758 struct cmd_show_bypass_config_result {
5759         cmdline_fixed_string_t show;
5760         cmdline_fixed_string_t bypass;
5761         cmdline_fixed_string_t config;
5762         portid_t port_id;
5763 };
5764
5765 static void
5766 cmd_show_bypass_config_parsed(void *parsed_result,
5767                 __rte_unused struct cmdline *cl,
5768                 __rte_unused void *data)
5769 {
5770         struct cmd_show_bypass_config_result *res = parsed_result;
5771         portid_t port_id = res->port_id;
5772         int rc = -EINVAL;
5773 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5774         uint32_t event_mode;
5775         uint32_t bypass_mode;
5776         uint32_t timeout = bypass_timeout;
5777         unsigned int i;
5778
5779         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5780                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5781         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5782                 {"UNKNOWN", "normal", "bypass", "isolate"};
5783         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5784                 "NONE",
5785                 "OS/board on",
5786                 "power supply on",
5787                 "OS/board off",
5788                 "power supply off",
5789                 "timeout"};
5790
5791         /* Display the bypass mode.*/
5792         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5793                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5794                 return;
5795         }
5796         else {
5797                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5798                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5799
5800                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5801         }
5802
5803         /* Display the bypass timeout.*/
5804         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5805                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5806
5807         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5808
5809         /* Display the bypass events and associated modes. */
5810         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5811
5812                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5813                         printf("\tFailed to get bypass mode for event = %s\n",
5814                                 events[i]);
5815                 } else {
5816                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5817                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5818
5819                         printf("\tbypass event: %-16s = %s\n", events[i],
5820                                 modes[event_mode]);
5821                 }
5822         }
5823 #endif
5824         if (rc != 0)
5825                 printf("\tFailed to get bypass configuration for port = %d\n",
5826                        port_id);
5827 }
5828
5829 cmdline_parse_token_string_t cmd_showbypass_config_show =
5830         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5831                         show, "show");
5832 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5833         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5834                         bypass, "bypass");
5835 cmdline_parse_token_string_t cmd_showbypass_config_config =
5836         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5837                         config, "config");
5838 cmdline_parse_token_num_t cmd_showbypass_config_port =
5839         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5840                                 port_id, RTE_UINT16);
5841
5842 cmdline_parse_inst_t cmd_show_bypass_config = {
5843         .f = cmd_show_bypass_config_parsed,
5844         .help_str = "show bypass config <port_id>: "
5845                     "Show the NIC bypass config for port_id",
5846         .data = NULL,
5847         .tokens = {
5848                 (void *)&cmd_showbypass_config_show,
5849                 (void *)&cmd_showbypass_config_bypass,
5850                 (void *)&cmd_showbypass_config_config,
5851                 (void *)&cmd_showbypass_config_port,
5852                 NULL,
5853         },
5854 };
5855
5856 #ifdef RTE_NET_BOND
5857 /* *** SET BONDING MODE *** */
5858 struct cmd_set_bonding_mode_result {
5859         cmdline_fixed_string_t set;
5860         cmdline_fixed_string_t bonding;
5861         cmdline_fixed_string_t mode;
5862         uint8_t value;
5863         portid_t port_id;
5864 };
5865
5866 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5867                 __rte_unused  struct cmdline *cl,
5868                 __rte_unused void *data)
5869 {
5870         struct cmd_set_bonding_mode_result *res = parsed_result;
5871         portid_t port_id = res->port_id;
5872
5873         /* Set the bonding mode for the relevant port. */
5874         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5875                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5876 }
5877
5878 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5879 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5880                 set, "set");
5881 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5882 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5883                 bonding, "bonding");
5884 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5885 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5886                 mode, "mode");
5887 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5888 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5889                 value, RTE_UINT8);
5890 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5891 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5892                 port_id, RTE_UINT16);
5893
5894 cmdline_parse_inst_t cmd_set_bonding_mode = {
5895                 .f = cmd_set_bonding_mode_parsed,
5896                 .help_str = "set bonding mode <mode_value> <port_id>: "
5897                         "Set the bonding mode for port_id",
5898                 .data = NULL,
5899                 .tokens = {
5900                                 (void *) &cmd_setbonding_mode_set,
5901                                 (void *) &cmd_setbonding_mode_bonding,
5902                                 (void *) &cmd_setbonding_mode_mode,
5903                                 (void *) &cmd_setbonding_mode_value,
5904                                 (void *) &cmd_setbonding_mode_port,
5905                                 NULL
5906                 }
5907 };
5908
5909 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5910 struct cmd_set_bonding_lacp_dedicated_queues_result {
5911         cmdline_fixed_string_t set;
5912         cmdline_fixed_string_t bonding;
5913         cmdline_fixed_string_t lacp;
5914         cmdline_fixed_string_t dedicated_queues;
5915         portid_t port_id;
5916         cmdline_fixed_string_t mode;
5917 };
5918
5919 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5920                 __rte_unused  struct cmdline *cl,
5921                 __rte_unused void *data)
5922 {
5923         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5924         portid_t port_id = res->port_id;
5925         struct rte_port *port;
5926
5927         port = &ports[port_id];
5928
5929         /** Check if the port is not started **/
5930         if (port->port_status != RTE_PORT_STOPPED) {
5931                 printf("Please stop port %d first\n", port_id);
5932                 return;
5933         }
5934
5935         if (!strcmp(res->mode, "enable")) {
5936                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5937                         printf("Dedicate queues for LACP control packets"
5938                                         " enabled\n");
5939                 else
5940                         printf("Enabling dedicate queues for LACP control "
5941                                         "packets on port %d failed\n", port_id);
5942         } else if (!strcmp(res->mode, "disable")) {
5943                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5944                         printf("Dedicated queues for LACP control packets "
5945                                         "disabled\n");
5946                 else
5947                         printf("Disabling dedicated queues for LACP control "
5948                                         "traffic on port %d failed\n", port_id);
5949         }
5950 }
5951
5952 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5953 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5954                 set, "set");
5955 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5956 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5957                 bonding, "bonding");
5958 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5959 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5960                 lacp, "lacp");
5961 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5962 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5963                 dedicated_queues, "dedicated_queues");
5964 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5965 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5966                 port_id, RTE_UINT16);
5967 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5968 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5969                 mode, "enable#disable");
5970
5971 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5972                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5973                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5974                         "enable|disable: "
5975                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5976                 .data = NULL,
5977                 .tokens = {
5978                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5979                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5980                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5981                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5982                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5983                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5984                         NULL
5985                 }
5986 };
5987
5988 /* *** SET BALANCE XMIT POLICY *** */
5989 struct cmd_set_bonding_balance_xmit_policy_result {
5990         cmdline_fixed_string_t set;
5991         cmdline_fixed_string_t bonding;
5992         cmdline_fixed_string_t balance_xmit_policy;
5993         portid_t port_id;
5994         cmdline_fixed_string_t policy;
5995 };
5996
5997 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5998                 __rte_unused  struct cmdline *cl,
5999                 __rte_unused void *data)
6000 {
6001         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6002         portid_t port_id = res->port_id;
6003         uint8_t policy;
6004
6005         if (!strcmp(res->policy, "l2")) {
6006                 policy = BALANCE_XMIT_POLICY_LAYER2;
6007         } else if (!strcmp(res->policy, "l23")) {
6008                 policy = BALANCE_XMIT_POLICY_LAYER23;
6009         } else if (!strcmp(res->policy, "l34")) {
6010                 policy = BALANCE_XMIT_POLICY_LAYER34;
6011         } else {
6012                 printf("\t Invalid xmit policy selection");
6013                 return;
6014         }
6015
6016         /* Set the bonding mode for the relevant port. */
6017         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6018                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6019                                 port_id);
6020         }
6021 }
6022
6023 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6024 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6025                 set, "set");
6026 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6027 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6028                 bonding, "bonding");
6029 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6030 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6031                 balance_xmit_policy, "balance_xmit_policy");
6032 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6033 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6034                 port_id, RTE_UINT16);
6035 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6036 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6037                 policy, "l2#l23#l34");
6038
6039 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6040                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6041                 .help_str = "set bonding balance_xmit_policy <port_id> "
6042                         "l2|l23|l34: "
6043                         "Set the bonding balance_xmit_policy for port_id",
6044                 .data = NULL,
6045                 .tokens = {
6046                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6047                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6048                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6049                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6050                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6051                                 NULL
6052                 }
6053 };
6054
6055 /* *** SHOW NIC BONDING CONFIGURATION *** */
6056 struct cmd_show_bonding_config_result {
6057         cmdline_fixed_string_t show;
6058         cmdline_fixed_string_t bonding;
6059         cmdline_fixed_string_t config;
6060         portid_t port_id;
6061 };
6062
6063 static void cmd_show_bonding_config_parsed(void *parsed_result,
6064                 __rte_unused  struct cmdline *cl,
6065                 __rte_unused void *data)
6066 {
6067         struct cmd_show_bonding_config_result *res = parsed_result;
6068         int bonding_mode, agg_mode;
6069         portid_t slaves[RTE_MAX_ETHPORTS];
6070         int num_slaves, num_active_slaves;
6071         int primary_id;
6072         int i;
6073         portid_t port_id = res->port_id;
6074
6075         /* Display the bonding mode.*/
6076         bonding_mode = rte_eth_bond_mode_get(port_id);
6077         if (bonding_mode < 0) {
6078                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6079                 return;
6080         } else
6081                 printf("\tBonding mode: %d\n", bonding_mode);
6082
6083         if (bonding_mode == BONDING_MODE_BALANCE) {
6084                 int balance_xmit_policy;
6085
6086                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6087                 if (balance_xmit_policy < 0) {
6088                         printf("\tFailed to get balance xmit policy for port = %d\n",
6089                                         port_id);
6090                         return;
6091                 } else {
6092                         printf("\tBalance Xmit Policy: ");
6093
6094                         switch (balance_xmit_policy) {
6095                         case BALANCE_XMIT_POLICY_LAYER2:
6096                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6097                                 break;
6098                         case BALANCE_XMIT_POLICY_LAYER23:
6099                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6100                                 break;
6101                         case BALANCE_XMIT_POLICY_LAYER34:
6102                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6103                                 break;
6104                         }
6105                         printf("\n");
6106                 }
6107         }
6108
6109         if (bonding_mode == BONDING_MODE_8023AD) {
6110                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6111                 printf("\tIEEE802.3AD Aggregator Mode: ");
6112                 switch (agg_mode) {
6113                 case AGG_BANDWIDTH:
6114                         printf("bandwidth");
6115                         break;
6116                 case AGG_STABLE:
6117                         printf("stable");
6118                         break;
6119                 case AGG_COUNT:
6120                         printf("count");
6121                         break;
6122                 }
6123                 printf("\n");
6124         }
6125
6126         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6127
6128         if (num_slaves < 0) {
6129                 printf("\tFailed to get slave list for port = %d\n", port_id);
6130                 return;
6131         }
6132         if (num_slaves > 0) {
6133                 printf("\tSlaves (%d): [", num_slaves);
6134                 for (i = 0; i < num_slaves - 1; i++)
6135                         printf("%d ", slaves[i]);
6136
6137                 printf("%d]\n", slaves[num_slaves - 1]);
6138         } else {
6139                 printf("\tSlaves: []\n");
6140
6141         }
6142
6143         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6144                         RTE_MAX_ETHPORTS);
6145
6146         if (num_active_slaves < 0) {
6147                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6148                 return;
6149         }
6150         if (num_active_slaves > 0) {
6151                 printf("\tActive Slaves (%d): [", num_active_slaves);
6152                 for (i = 0; i < num_active_slaves - 1; i++)
6153                         printf("%d ", slaves[i]);
6154
6155                 printf("%d]\n", slaves[num_active_slaves - 1]);
6156
6157         } else {
6158                 printf("\tActive Slaves: []\n");
6159
6160         }
6161
6162         primary_id = rte_eth_bond_primary_get(port_id);
6163         if (primary_id < 0) {
6164                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6165                 return;
6166         } else
6167                 printf("\tPrimary: [%d]\n", primary_id);
6168
6169 }
6170
6171 cmdline_parse_token_string_t cmd_showbonding_config_show =
6172 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6173                 show, "show");
6174 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6175 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6176                 bonding, "bonding");
6177 cmdline_parse_token_string_t cmd_showbonding_config_config =
6178 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6179                 config, "config");
6180 cmdline_parse_token_num_t cmd_showbonding_config_port =
6181 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6182                 port_id, RTE_UINT16);
6183
6184 cmdline_parse_inst_t cmd_show_bonding_config = {
6185                 .f = cmd_show_bonding_config_parsed,
6186                 .help_str = "show bonding config <port_id>: "
6187                         "Show the bonding config for port_id",
6188                 .data = NULL,
6189                 .tokens = {
6190                                 (void *)&cmd_showbonding_config_show,
6191                                 (void *)&cmd_showbonding_config_bonding,
6192                                 (void *)&cmd_showbonding_config_config,
6193                                 (void *)&cmd_showbonding_config_port,
6194                                 NULL
6195                 }
6196 };
6197
6198 /* *** SET BONDING PRIMARY *** */
6199 struct cmd_set_bonding_primary_result {
6200         cmdline_fixed_string_t set;
6201         cmdline_fixed_string_t bonding;
6202         cmdline_fixed_string_t primary;
6203         portid_t slave_id;
6204         portid_t port_id;
6205 };
6206
6207 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6208                 __rte_unused  struct cmdline *cl,
6209                 __rte_unused void *data)
6210 {
6211         struct cmd_set_bonding_primary_result *res = parsed_result;
6212         portid_t master_port_id = res->port_id;
6213         portid_t slave_port_id = res->slave_id;
6214
6215         /* Set the primary slave for a bonded device. */
6216         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6217                 printf("\t Failed to set primary slave for port = %d.\n",
6218                                 master_port_id);
6219                 return;
6220         }
6221         init_port_config();
6222 }
6223
6224 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6225 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6226                 set, "set");
6227 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6228 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6229                 bonding, "bonding");
6230 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6231 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6232                 primary, "primary");
6233 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6234 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6235                 slave_id, RTE_UINT16);
6236 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6237 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6238                 port_id, RTE_UINT16);
6239
6240 cmdline_parse_inst_t cmd_set_bonding_primary = {
6241                 .f = cmd_set_bonding_primary_parsed,
6242                 .help_str = "set bonding primary <slave_id> <port_id>: "
6243                         "Set the primary slave for port_id",
6244                 .data = NULL,
6245                 .tokens = {
6246                                 (void *)&cmd_setbonding_primary_set,
6247                                 (void *)&cmd_setbonding_primary_bonding,
6248                                 (void *)&cmd_setbonding_primary_primary,
6249                                 (void *)&cmd_setbonding_primary_slave,
6250                                 (void *)&cmd_setbonding_primary_port,
6251                                 NULL
6252                 }
6253 };
6254
6255 /* *** ADD SLAVE *** */
6256 struct cmd_add_bonding_slave_result {
6257         cmdline_fixed_string_t add;
6258         cmdline_fixed_string_t bonding;
6259         cmdline_fixed_string_t slave;
6260         portid_t slave_id;
6261         portid_t port_id;
6262 };
6263
6264 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6265                 __rte_unused  struct cmdline *cl,
6266                 __rte_unused void *data)
6267 {
6268         struct cmd_add_bonding_slave_result *res = parsed_result;
6269         portid_t master_port_id = res->port_id;
6270         portid_t slave_port_id = res->slave_id;
6271
6272         /* add the slave for a bonded device. */
6273         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6274                 printf("\t Failed to add slave %d to master port = %d.\n",
6275                                 slave_port_id, master_port_id);
6276                 return;
6277         }
6278         init_port_config();
6279         set_port_slave_flag(slave_port_id);
6280 }
6281
6282 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6283 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6284                 add, "add");
6285 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6286 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6287                 bonding, "bonding");
6288 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6289 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6290                 slave, "slave");
6291 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6292 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6293                 slave_id, RTE_UINT16);
6294 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6295 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6296                 port_id, RTE_UINT16);
6297
6298 cmdline_parse_inst_t cmd_add_bonding_slave = {
6299                 .f = cmd_add_bonding_slave_parsed,
6300                 .help_str = "add bonding slave <slave_id> <port_id>: "
6301                         "Add a slave device to a bonded device",
6302                 .data = NULL,
6303                 .tokens = {
6304                                 (void *)&cmd_addbonding_slave_add,
6305                                 (void *)&cmd_addbonding_slave_bonding,
6306                                 (void *)&cmd_addbonding_slave_slave,
6307                                 (void *)&cmd_addbonding_slave_slaveid,
6308                                 (void *)&cmd_addbonding_slave_port,
6309                                 NULL
6310                 }
6311 };
6312
6313 /* *** REMOVE SLAVE *** */
6314 struct cmd_remove_bonding_slave_result {
6315         cmdline_fixed_string_t remove;
6316         cmdline_fixed_string_t bonding;
6317         cmdline_fixed_string_t slave;
6318         portid_t slave_id;
6319         portid_t port_id;
6320 };
6321
6322 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6323                 __rte_unused  struct cmdline *cl,
6324                 __rte_unused void *data)
6325 {
6326         struct cmd_remove_bonding_slave_result *res = parsed_result;
6327         portid_t master_port_id = res->port_id;
6328         portid_t slave_port_id = res->slave_id;
6329
6330         /* remove the slave from a bonded device. */
6331         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6332                 printf("\t Failed to remove slave %d from master port = %d.\n",
6333                                 slave_port_id, master_port_id);
6334                 return;
6335         }
6336         init_port_config();
6337         clear_port_slave_flag(slave_port_id);
6338 }
6339
6340 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6341                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6342                                 remove, "remove");
6343 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6344                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6345                                 bonding, "bonding");
6346 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6347                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6348                                 slave, "slave");
6349 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6350                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6351                                 slave_id, RTE_UINT16);
6352 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6353                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6354                                 port_id, RTE_UINT16);
6355
6356 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6357                 .f = cmd_remove_bonding_slave_parsed,
6358                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6359                         "Remove a slave device from a bonded device",
6360                 .data = NULL,
6361                 .tokens = {
6362                                 (void *)&cmd_removebonding_slave_remove,
6363                                 (void *)&cmd_removebonding_slave_bonding,
6364                                 (void *)&cmd_removebonding_slave_slave,
6365                                 (void *)&cmd_removebonding_slave_slaveid,
6366                                 (void *)&cmd_removebonding_slave_port,
6367                                 NULL
6368                 }
6369 };
6370
6371 /* *** CREATE BONDED DEVICE *** */
6372 struct cmd_create_bonded_device_result {
6373         cmdline_fixed_string_t create;
6374         cmdline_fixed_string_t bonded;
6375         cmdline_fixed_string_t device;
6376         uint8_t mode;
6377         uint8_t socket;
6378 };
6379
6380 static int bond_dev_num = 0;
6381
6382 static void cmd_create_bonded_device_parsed(void *parsed_result,
6383                 __rte_unused  struct cmdline *cl,
6384                 __rte_unused void *data)
6385 {
6386         struct cmd_create_bonded_device_result *res = parsed_result;
6387         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6388         int port_id;
6389         int ret;
6390
6391         if (test_done == 0) {
6392                 printf("Please stop forwarding first\n");
6393                 return;
6394         }
6395
6396         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6397                         bond_dev_num++);
6398
6399         /* Create a new bonded device. */
6400         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6401         if (port_id < 0) {
6402                 printf("\t Failed to create bonded device.\n");
6403                 return;
6404         } else {
6405                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6406                                 port_id);
6407
6408                 /* Update number of ports */
6409                 nb_ports = rte_eth_dev_count_avail();
6410                 reconfig(port_id, res->socket);
6411                 ret = rte_eth_promiscuous_enable(port_id);
6412                 if (ret != 0)
6413                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6414                                 port_id, rte_strerror(-ret));
6415
6416                 ports[port_id].need_setup = 0;
6417                 ports[port_id].port_status = RTE_PORT_STOPPED;
6418         }
6419
6420 }
6421
6422 cmdline_parse_token_string_t cmd_createbonded_device_create =
6423                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6424                                 create, "create");
6425 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6426                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6427                                 bonded, "bonded");
6428 cmdline_parse_token_string_t cmd_createbonded_device_device =
6429                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6430                                 device, "device");
6431 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6432                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6433                                 mode, RTE_UINT8);
6434 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6435                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6436                                 socket, RTE_UINT8);
6437
6438 cmdline_parse_inst_t cmd_create_bonded_device = {
6439                 .f = cmd_create_bonded_device_parsed,
6440                 .help_str = "create bonded device <mode> <socket>: "
6441                         "Create a new bonded device with specific bonding mode and socket",
6442                 .data = NULL,
6443                 .tokens = {
6444                                 (void *)&cmd_createbonded_device_create,
6445                                 (void *)&cmd_createbonded_device_bonded,
6446                                 (void *)&cmd_createbonded_device_device,
6447                                 (void *)&cmd_createbonded_device_mode,
6448                                 (void *)&cmd_createbonded_device_socket,
6449                                 NULL
6450                 }
6451 };
6452
6453 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6454 struct cmd_set_bond_mac_addr_result {
6455         cmdline_fixed_string_t set;
6456         cmdline_fixed_string_t bonding;
6457         cmdline_fixed_string_t mac_addr;
6458         uint16_t port_num;
6459         struct rte_ether_addr address;
6460 };
6461
6462 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6463                 __rte_unused  struct cmdline *cl,
6464                 __rte_unused void *data)
6465 {
6466         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6467         int ret;
6468
6469         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6470                 return;
6471
6472         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6473
6474         /* check the return value and print it if is < 0 */
6475         if (ret < 0)
6476                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6477 }
6478
6479 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6480                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6481 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6482                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6483                                 "bonding");
6484 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6485                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6486                                 "mac_addr");
6487 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6488                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6489                                 port_num, RTE_UINT16);
6490 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6491                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6492
6493 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6494                 .f = cmd_set_bond_mac_addr_parsed,
6495                 .data = (void *) 0,
6496                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6497                 .tokens = {
6498                                 (void *)&cmd_set_bond_mac_addr_set,
6499                                 (void *)&cmd_set_bond_mac_addr_bonding,
6500                                 (void *)&cmd_set_bond_mac_addr_mac,
6501                                 (void *)&cmd_set_bond_mac_addr_portnum,
6502                                 (void *)&cmd_set_bond_mac_addr_addr,
6503                                 NULL
6504                 }
6505 };
6506
6507
6508 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6509 struct cmd_set_bond_mon_period_result {
6510         cmdline_fixed_string_t set;
6511         cmdline_fixed_string_t bonding;
6512         cmdline_fixed_string_t mon_period;
6513         uint16_t port_num;
6514         uint32_t period_ms;
6515 };
6516
6517 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6518                 __rte_unused  struct cmdline *cl,
6519                 __rte_unused void *data)
6520 {
6521         struct cmd_set_bond_mon_period_result *res = parsed_result;
6522         int ret;
6523
6524         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6525
6526         /* check the return value and print it if is < 0 */
6527         if (ret < 0)
6528                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6529 }
6530
6531 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6532                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6533                                 set, "set");
6534 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6535                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6536                                 bonding, "bonding");
6537 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6538                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6539                                 mon_period,     "mon_period");
6540 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6541                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6542                                 port_num, RTE_UINT16);
6543 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6544                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6545                                 period_ms, RTE_UINT32);
6546
6547 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6548                 .f = cmd_set_bond_mon_period_parsed,
6549                 .data = (void *) 0,
6550                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6551                 .tokens = {
6552                                 (void *)&cmd_set_bond_mon_period_set,
6553                                 (void *)&cmd_set_bond_mon_period_bonding,
6554                                 (void *)&cmd_set_bond_mon_period_mon_period,
6555                                 (void *)&cmd_set_bond_mon_period_portnum,
6556                                 (void *)&cmd_set_bond_mon_period_period_ms,
6557                                 NULL
6558                 }
6559 };
6560
6561
6562
6563 struct cmd_set_bonding_agg_mode_policy_result {
6564         cmdline_fixed_string_t set;
6565         cmdline_fixed_string_t bonding;
6566         cmdline_fixed_string_t agg_mode;
6567         uint16_t port_num;
6568         cmdline_fixed_string_t policy;
6569 };
6570
6571
6572 static void
6573 cmd_set_bonding_agg_mode(void *parsed_result,
6574                 __rte_unused struct cmdline *cl,
6575                 __rte_unused void *data)
6576 {
6577         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6578         uint8_t policy = AGG_BANDWIDTH;
6579
6580         if (!strcmp(res->policy, "bandwidth"))
6581                 policy = AGG_BANDWIDTH;
6582         else if (!strcmp(res->policy, "stable"))
6583                 policy = AGG_STABLE;
6584         else if (!strcmp(res->policy, "count"))
6585                 policy = AGG_COUNT;
6586
6587         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6588 }
6589
6590
6591 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6592         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6593                                 set, "set");
6594 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6595         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6596                                 bonding, "bonding");
6597
6598 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6599         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6600                                 agg_mode, "agg_mode");
6601
6602 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6603         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6604                                 port_num, RTE_UINT16);
6605
6606 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6607         TOKEN_STRING_INITIALIZER(
6608                         struct cmd_set_bonding_balance_xmit_policy_result,
6609                 policy, "stable#bandwidth#count");
6610
6611 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6612         .f = cmd_set_bonding_agg_mode,
6613         .data = (void *) 0,
6614         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6615         .tokens = {
6616                         (void *)&cmd_set_bonding_agg_mode_set,
6617                         (void *)&cmd_set_bonding_agg_mode_bonding,
6618                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6619                         (void *)&cmd_set_bonding_agg_mode_portnum,
6620                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6621                         NULL
6622                 }
6623 };
6624
6625
6626 #endif /* RTE_NET_BOND */
6627
6628 /* *** SET FORWARDING MODE *** */
6629 struct cmd_set_fwd_mode_result {
6630         cmdline_fixed_string_t set;
6631         cmdline_fixed_string_t fwd;
6632         cmdline_fixed_string_t mode;
6633 };
6634
6635 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6636                                     __rte_unused struct cmdline *cl,
6637                                     __rte_unused void *data)
6638 {
6639         struct cmd_set_fwd_mode_result *res = parsed_result;
6640
6641         retry_enabled = 0;
6642         set_pkt_forwarding_mode(res->mode);
6643 }
6644
6645 cmdline_parse_token_string_t cmd_setfwd_set =
6646         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6647 cmdline_parse_token_string_t cmd_setfwd_fwd =
6648         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6649 cmdline_parse_token_string_t cmd_setfwd_mode =
6650         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6651                 "" /* defined at init */);
6652
6653 cmdline_parse_inst_t cmd_set_fwd_mode = {
6654         .f = cmd_set_fwd_mode_parsed,
6655         .data = NULL,
6656         .help_str = NULL, /* defined at init */
6657         .tokens = {
6658                 (void *)&cmd_setfwd_set,
6659                 (void *)&cmd_setfwd_fwd,
6660                 (void *)&cmd_setfwd_mode,
6661                 NULL,
6662         },
6663 };
6664
6665 static void cmd_set_fwd_mode_init(void)
6666 {
6667         char *modes, *c;
6668         static char token[128];
6669         static char help[256];
6670         cmdline_parse_token_string_t *token_struct;
6671
6672         modes = list_pkt_forwarding_modes();
6673         snprintf(help, sizeof(help), "set fwd %s: "
6674                 "Set packet forwarding mode", modes);
6675         cmd_set_fwd_mode.help_str = help;
6676
6677         /* string token separator is # */
6678         for (c = token; *modes != '\0'; modes++)
6679                 if (*modes == '|')
6680                         *c++ = '#';
6681                 else
6682                         *c++ = *modes;
6683         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6684         token_struct->string_data.str = token;
6685 }
6686
6687 /* *** SET RETRY FORWARDING MODE *** */
6688 struct cmd_set_fwd_retry_mode_result {
6689         cmdline_fixed_string_t set;
6690         cmdline_fixed_string_t fwd;
6691         cmdline_fixed_string_t mode;
6692         cmdline_fixed_string_t retry;
6693 };
6694
6695 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6696                             __rte_unused struct cmdline *cl,
6697                             __rte_unused void *data)
6698 {
6699         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6700
6701         retry_enabled = 1;
6702         set_pkt_forwarding_mode(res->mode);
6703 }
6704
6705 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6706         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6707                         set, "set");
6708 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6709         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6710                         fwd, "fwd");
6711 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6712         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6713                         mode,
6714                 "" /* defined at init */);
6715 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6716         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6717                         retry, "retry");
6718
6719 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6720         .f = cmd_set_fwd_retry_mode_parsed,
6721         .data = NULL,
6722         .help_str = NULL, /* defined at init */
6723         .tokens = {
6724                 (void *)&cmd_setfwd_retry_set,
6725                 (void *)&cmd_setfwd_retry_fwd,
6726                 (void *)&cmd_setfwd_retry_mode,
6727                 (void *)&cmd_setfwd_retry_retry,
6728                 NULL,
6729         },
6730 };
6731
6732 static void cmd_set_fwd_retry_mode_init(void)
6733 {
6734         char *modes, *c;
6735         static char token[128];
6736         static char help[256];
6737         cmdline_parse_token_string_t *token_struct;
6738
6739         modes = list_pkt_forwarding_retry_modes();
6740         snprintf(help, sizeof(help), "set fwd %s retry: "
6741                 "Set packet forwarding mode with retry", modes);
6742         cmd_set_fwd_retry_mode.help_str = help;
6743
6744         /* string token separator is # */
6745         for (c = token; *modes != '\0'; modes++)
6746                 if (*modes == '|')
6747                         *c++ = '#';
6748                 else
6749                         *c++ = *modes;
6750         token_struct = (cmdline_parse_token_string_t *)
6751                 cmd_set_fwd_retry_mode.tokens[2];
6752         token_struct->string_data.str = token;
6753 }
6754
6755 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6756 struct cmd_set_burst_tx_retry_result {
6757         cmdline_fixed_string_t set;
6758         cmdline_fixed_string_t burst;
6759         cmdline_fixed_string_t tx;
6760         cmdline_fixed_string_t delay;
6761         uint32_t time;
6762         cmdline_fixed_string_t retry;
6763         uint32_t retry_num;
6764 };
6765
6766 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6767                                         __rte_unused struct cmdline *cl,
6768                                         __rte_unused void *data)
6769 {
6770         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6771
6772         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6773                 && !strcmp(res->tx, "tx")) {
6774                 if (!strcmp(res->delay, "delay"))
6775                         burst_tx_delay_time = res->time;
6776                 if (!strcmp(res->retry, "retry"))
6777                         burst_tx_retry_num = res->retry_num;
6778         }
6779
6780 }
6781
6782 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6783         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6784 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6785         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6786                                  "burst");
6787 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6788         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6789 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6790         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6791 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6792         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
6793                                  RTE_UINT32);
6794 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6795         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6796 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6797         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
6798                                  RTE_UINT32);
6799
6800 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6801         .f = cmd_set_burst_tx_retry_parsed,
6802         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6803         .tokens = {
6804                 (void *)&cmd_set_burst_tx_retry_set,
6805                 (void *)&cmd_set_burst_tx_retry_burst,
6806                 (void *)&cmd_set_burst_tx_retry_tx,
6807                 (void *)&cmd_set_burst_tx_retry_delay,
6808                 (void *)&cmd_set_burst_tx_retry_time,
6809                 (void *)&cmd_set_burst_tx_retry_retry,
6810                 (void *)&cmd_set_burst_tx_retry_retry_num,
6811                 NULL,
6812         },
6813 };
6814
6815 /* *** SET PROMISC MODE *** */
6816 struct cmd_set_promisc_mode_result {
6817         cmdline_fixed_string_t set;
6818         cmdline_fixed_string_t promisc;
6819         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6820         uint16_t port_num;               /* valid if "allports" argument == 0 */
6821         cmdline_fixed_string_t mode;
6822 };
6823
6824 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6825                                         __rte_unused struct cmdline *cl,
6826                                         void *allports)
6827 {
6828         struct cmd_set_promisc_mode_result *res = parsed_result;
6829         int enable;
6830         portid_t i;
6831
6832         if (!strcmp(res->mode, "on"))
6833                 enable = 1;
6834         else
6835                 enable = 0;
6836
6837         /* all ports */
6838         if (allports) {
6839                 RTE_ETH_FOREACH_DEV(i)
6840                         eth_set_promisc_mode(i, enable);
6841         } else {
6842                 eth_set_promisc_mode(res->port_num, enable);
6843         }
6844 }
6845
6846 cmdline_parse_token_string_t cmd_setpromisc_set =
6847         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6848 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6849         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6850                                  "promisc");
6851 cmdline_parse_token_string_t cmd_setpromisc_portall =
6852         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6853                                  "all");
6854 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6855         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6856                               RTE_UINT16);
6857 cmdline_parse_token_string_t cmd_setpromisc_mode =
6858         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6859                                  "on#off");
6860
6861 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6862         .f = cmd_set_promisc_mode_parsed,
6863         .data = (void *)1,
6864         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6865         .tokens = {
6866                 (void *)&cmd_setpromisc_set,
6867                 (void *)&cmd_setpromisc_promisc,
6868                 (void *)&cmd_setpromisc_portall,
6869                 (void *)&cmd_setpromisc_mode,
6870                 NULL,
6871         },
6872 };
6873
6874 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6875         .f = cmd_set_promisc_mode_parsed,
6876         .data = (void *)0,
6877         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6878         .tokens = {
6879                 (void *)&cmd_setpromisc_set,
6880                 (void *)&cmd_setpromisc_promisc,
6881                 (void *)&cmd_setpromisc_portnum,
6882                 (void *)&cmd_setpromisc_mode,
6883                 NULL,
6884         },
6885 };
6886
6887 /* *** SET ALLMULTI MODE *** */
6888 struct cmd_set_allmulti_mode_result {
6889         cmdline_fixed_string_t set;
6890         cmdline_fixed_string_t allmulti;
6891         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6892         uint16_t port_num;               /* valid if "allports" argument == 0 */
6893         cmdline_fixed_string_t mode;
6894 };
6895
6896 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6897                                         __rte_unused struct cmdline *cl,
6898                                         void *allports)
6899 {
6900         struct cmd_set_allmulti_mode_result *res = parsed_result;
6901         int enable;
6902         portid_t i;
6903
6904         if (!strcmp(res->mode, "on"))
6905                 enable = 1;
6906         else
6907                 enable = 0;
6908
6909         /* all ports */
6910         if (allports) {
6911                 RTE_ETH_FOREACH_DEV(i) {
6912                         eth_set_allmulticast_mode(i, enable);
6913                 }
6914         }
6915         else {
6916                 eth_set_allmulticast_mode(res->port_num, enable);
6917         }
6918 }
6919
6920 cmdline_parse_token_string_t cmd_setallmulti_set =
6921         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6922 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6923         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6924                                  "allmulti");
6925 cmdline_parse_token_string_t cmd_setallmulti_portall =
6926         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6927                                  "all");
6928 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6929         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6930                               RTE_UINT16);
6931 cmdline_parse_token_string_t cmd_setallmulti_mode =
6932         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6933                                  "on#off");
6934
6935 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6936         .f = cmd_set_allmulti_mode_parsed,
6937         .data = (void *)1,
6938         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6939         .tokens = {
6940                 (void *)&cmd_setallmulti_set,
6941                 (void *)&cmd_setallmulti_allmulti,
6942                 (void *)&cmd_setallmulti_portall,
6943                 (void *)&cmd_setallmulti_mode,
6944                 NULL,
6945         },
6946 };
6947
6948 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6949         .f = cmd_set_allmulti_mode_parsed,
6950         .data = (void *)0,
6951         .help_str = "set allmulti <port_id> on|off: "
6952                 "Set allmulti mode on port_id",
6953         .tokens = {
6954                 (void *)&cmd_setallmulti_set,
6955                 (void *)&cmd_setallmulti_allmulti,
6956                 (void *)&cmd_setallmulti_portnum,
6957                 (void *)&cmd_setallmulti_mode,
6958                 NULL,
6959         },
6960 };
6961
6962 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
6963 struct cmd_link_flow_ctrl_show {
6964         cmdline_fixed_string_t show;
6965         cmdline_fixed_string_t port;
6966         portid_t port_id;
6967         cmdline_fixed_string_t flow_ctrl;
6968 };
6969
6970 cmdline_parse_token_string_t cmd_lfc_show_show =
6971         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
6972                                 show, "show");
6973 cmdline_parse_token_string_t cmd_lfc_show_port =
6974         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
6975                                 port, "port");
6976 cmdline_parse_token_num_t cmd_lfc_show_portid =
6977         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
6978                                 port_id, RTE_UINT16);
6979 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
6980         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
6981                                 flow_ctrl, "flow_ctrl");
6982
6983 static void
6984 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
6985                               __rte_unused struct cmdline *cl,
6986                               __rte_unused void *data)
6987 {
6988         struct cmd_link_flow_ctrl_show *res = parsed_result;
6989         static const char *info_border = "*********************";
6990         struct rte_eth_fc_conf fc_conf;
6991         bool rx_fc_en = false;
6992         bool tx_fc_en = false;
6993         int ret;
6994
6995         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6996         if (ret != 0) {
6997                 printf("Failed to get current flow ctrl information: err = %d\n",
6998                        ret);
6999                 return;
7000         }
7001
7002         if (fc_conf.mode == RTE_FC_RX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7003                 rx_fc_en = true;
7004         if (fc_conf.mode == RTE_FC_TX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7005                 tx_fc_en = true;
7006
7007         printf("\n%s Flow control infos for port %-2d %s\n",
7008                 info_border, res->port_id, info_border);
7009         printf("FC mode:\n");
7010         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7011         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7012         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7013         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7014         printf("High waterline: 0x%x\n", fc_conf.high_water);
7015         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7016         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7017         printf("Forward MAC control frames: %s\n",
7018                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7019         printf("\n%s**************   End  ***********%s\n",
7020                 info_border, info_border);
7021 }
7022
7023 cmdline_parse_inst_t cmd_link_flow_control_show = {
7024         .f = cmd_link_flow_ctrl_show_parsed,
7025         .data = NULL,
7026         .help_str = "show port <port_id> flow_ctrl",
7027         .tokens = {
7028                 (void *)&cmd_lfc_show_show,
7029                 (void *)&cmd_lfc_show_port,
7030                 (void *)&cmd_lfc_show_portid,
7031                 (void *)&cmd_lfc_show_flow_ctrl,
7032                 NULL,
7033         },
7034 };
7035
7036 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7037 struct cmd_link_flow_ctrl_set_result {
7038         cmdline_fixed_string_t set;
7039         cmdline_fixed_string_t flow_ctrl;
7040         cmdline_fixed_string_t rx;
7041         cmdline_fixed_string_t rx_lfc_mode;
7042         cmdline_fixed_string_t tx;
7043         cmdline_fixed_string_t tx_lfc_mode;
7044         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7045         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7046         cmdline_fixed_string_t autoneg_str;
7047         cmdline_fixed_string_t autoneg;
7048         cmdline_fixed_string_t hw_str;
7049         uint32_t high_water;
7050         cmdline_fixed_string_t lw_str;
7051         uint32_t low_water;
7052         cmdline_fixed_string_t pt_str;
7053         uint16_t pause_time;
7054         cmdline_fixed_string_t xon_str;
7055         uint16_t send_xon;
7056         portid_t port_id;
7057 };
7058
7059 cmdline_parse_token_string_t cmd_lfc_set_set =
7060         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7061                                 set, "set");
7062 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7063         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7064                                 flow_ctrl, "flow_ctrl");
7065 cmdline_parse_token_string_t cmd_lfc_set_rx =
7066         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7067                                 rx, "rx");
7068 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7069         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7070                                 rx_lfc_mode, "on#off");
7071 cmdline_parse_token_string_t cmd_lfc_set_tx =
7072         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7073                                 tx, "tx");
7074 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7075         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7076                                 tx_lfc_mode, "on#off");
7077 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7078         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7079                                 hw_str, "high_water");
7080 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7081         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7082                                 high_water, RTE_UINT32);
7083 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7084         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7085                                 lw_str, "low_water");
7086 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7087         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7088                                 low_water, RTE_UINT32);
7089 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7090         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7091                                 pt_str, "pause_time");
7092 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7093         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7094                                 pause_time, RTE_UINT16);
7095 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7096         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7097                                 xon_str, "send_xon");
7098 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7099         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7100                                 send_xon, RTE_UINT16);
7101 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7102         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7103                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7104 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7105         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7106                                 mac_ctrl_frame_fwd_mode, "on#off");
7107 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7108         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7109                                 autoneg_str, "autoneg");
7110 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7111         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7112                                 autoneg, "on#off");
7113 cmdline_parse_token_num_t cmd_lfc_set_portid =
7114         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7115                                 port_id, RTE_UINT16);
7116
7117 /* forward declaration */
7118 static void
7119 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7120                               void *data);
7121
7122 cmdline_parse_inst_t cmd_link_flow_control_set = {
7123         .f = cmd_link_flow_ctrl_set_parsed,
7124         .data = NULL,
7125         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7126                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7127                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7128         .tokens = {
7129                 (void *)&cmd_lfc_set_set,
7130                 (void *)&cmd_lfc_set_flow_ctrl,
7131                 (void *)&cmd_lfc_set_rx,
7132                 (void *)&cmd_lfc_set_rx_mode,
7133                 (void *)&cmd_lfc_set_tx,
7134                 (void *)&cmd_lfc_set_tx_mode,
7135                 (void *)&cmd_lfc_set_high_water,
7136                 (void *)&cmd_lfc_set_low_water,
7137                 (void *)&cmd_lfc_set_pause_time,
7138                 (void *)&cmd_lfc_set_send_xon,
7139                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7140                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7141                 (void *)&cmd_lfc_set_autoneg_str,
7142                 (void *)&cmd_lfc_set_autoneg,
7143                 (void *)&cmd_lfc_set_portid,
7144                 NULL,
7145         },
7146 };
7147
7148 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7149         .f = cmd_link_flow_ctrl_set_parsed,
7150         .data = (void *)&cmd_link_flow_control_set_rx,
7151         .help_str = "set flow_ctrl rx on|off <port_id>: "
7152                 "Change rx flow control parameter",
7153         .tokens = {
7154                 (void *)&cmd_lfc_set_set,
7155                 (void *)&cmd_lfc_set_flow_ctrl,
7156                 (void *)&cmd_lfc_set_rx,
7157                 (void *)&cmd_lfc_set_rx_mode,
7158                 (void *)&cmd_lfc_set_portid,
7159                 NULL,
7160         },
7161 };
7162
7163 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7164         .f = cmd_link_flow_ctrl_set_parsed,
7165         .data = (void *)&cmd_link_flow_control_set_tx,
7166         .help_str = "set flow_ctrl tx on|off <port_id>: "
7167                 "Change tx flow control parameter",
7168         .tokens = {
7169                 (void *)&cmd_lfc_set_set,
7170                 (void *)&cmd_lfc_set_flow_ctrl,
7171                 (void *)&cmd_lfc_set_tx,
7172                 (void *)&cmd_lfc_set_tx_mode,
7173                 (void *)&cmd_lfc_set_portid,
7174                 NULL,
7175         },
7176 };
7177
7178 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7179         .f = cmd_link_flow_ctrl_set_parsed,
7180         .data = (void *)&cmd_link_flow_control_set_hw,
7181         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7182                 "Change high water flow control parameter",
7183         .tokens = {
7184                 (void *)&cmd_lfc_set_set,
7185                 (void *)&cmd_lfc_set_flow_ctrl,
7186                 (void *)&cmd_lfc_set_high_water_str,
7187                 (void *)&cmd_lfc_set_high_water,
7188                 (void *)&cmd_lfc_set_portid,
7189                 NULL,
7190         },
7191 };
7192
7193 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7194         .f = cmd_link_flow_ctrl_set_parsed,
7195         .data = (void *)&cmd_link_flow_control_set_lw,
7196         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7197                 "Change low water flow control parameter",
7198         .tokens = {
7199                 (void *)&cmd_lfc_set_set,
7200                 (void *)&cmd_lfc_set_flow_ctrl,
7201                 (void *)&cmd_lfc_set_low_water_str,
7202                 (void *)&cmd_lfc_set_low_water,
7203                 (void *)&cmd_lfc_set_portid,
7204                 NULL,
7205         },
7206 };
7207
7208 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7209         .f = cmd_link_flow_ctrl_set_parsed,
7210         .data = (void *)&cmd_link_flow_control_set_pt,
7211         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7212                 "Change pause time flow control parameter",
7213         .tokens = {
7214                 (void *)&cmd_lfc_set_set,
7215                 (void *)&cmd_lfc_set_flow_ctrl,
7216                 (void *)&cmd_lfc_set_pause_time_str,
7217                 (void *)&cmd_lfc_set_pause_time,
7218                 (void *)&cmd_lfc_set_portid,
7219                 NULL,
7220         },
7221 };
7222
7223 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7224         .f = cmd_link_flow_ctrl_set_parsed,
7225         .data = (void *)&cmd_link_flow_control_set_xon,
7226         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7227                 "Change send_xon flow control parameter",
7228         .tokens = {
7229                 (void *)&cmd_lfc_set_set,
7230                 (void *)&cmd_lfc_set_flow_ctrl,
7231                 (void *)&cmd_lfc_set_send_xon_str,
7232                 (void *)&cmd_lfc_set_send_xon,
7233                 (void *)&cmd_lfc_set_portid,
7234                 NULL,
7235         },
7236 };
7237
7238 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7239         .f = cmd_link_flow_ctrl_set_parsed,
7240         .data = (void *)&cmd_link_flow_control_set_macfwd,
7241         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7242                 "Change mac ctrl fwd flow control parameter",
7243         .tokens = {
7244                 (void *)&cmd_lfc_set_set,
7245                 (void *)&cmd_lfc_set_flow_ctrl,
7246                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7247                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7248                 (void *)&cmd_lfc_set_portid,
7249                 NULL,
7250         },
7251 };
7252
7253 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7254         .f = cmd_link_flow_ctrl_set_parsed,
7255         .data = (void *)&cmd_link_flow_control_set_autoneg,
7256         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7257                 "Change autoneg flow control parameter",
7258         .tokens = {
7259                 (void *)&cmd_lfc_set_set,
7260                 (void *)&cmd_lfc_set_flow_ctrl,
7261                 (void *)&cmd_lfc_set_autoneg_str,
7262                 (void *)&cmd_lfc_set_autoneg,
7263                 (void *)&cmd_lfc_set_portid,
7264                 NULL,
7265         },
7266 };
7267
7268 static void
7269 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7270                               __rte_unused struct cmdline *cl,
7271                               void *data)
7272 {
7273         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7274         cmdline_parse_inst_t *cmd = data;
7275         struct rte_eth_fc_conf fc_conf;
7276         int rx_fc_en = 0;
7277         int tx_fc_en = 0;
7278         int ret;
7279
7280         /*
7281          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7282          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7283          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7284          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7285          */
7286         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7287                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7288         };
7289
7290         /* Partial command line, retrieve current configuration */
7291         if (cmd) {
7292                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7293                 if (ret != 0) {
7294                         printf("cannot get current flow ctrl parameters, return"
7295                                "code = %d\n", ret);
7296                         return;
7297                 }
7298
7299                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7300                     (fc_conf.mode == RTE_FC_FULL))
7301                         rx_fc_en = 1;
7302                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7303                     (fc_conf.mode == RTE_FC_FULL))
7304                         tx_fc_en = 1;
7305         }
7306
7307         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7308                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7309
7310         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7311                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7312
7313         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7314
7315         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7316                 fc_conf.high_water = res->high_water;
7317
7318         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7319                 fc_conf.low_water = res->low_water;
7320
7321         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7322                 fc_conf.pause_time = res->pause_time;
7323
7324         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7325                 fc_conf.send_xon = res->send_xon;
7326
7327         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7328                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7329                         fc_conf.mac_ctrl_frame_fwd = 1;
7330                 else
7331                         fc_conf.mac_ctrl_frame_fwd = 0;
7332         }
7333
7334         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7335                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7336
7337         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7338         if (ret != 0)
7339                 printf("bad flow contrl parameter, return code = %d \n", ret);
7340 }
7341
7342 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7343 struct cmd_priority_flow_ctrl_set_result {
7344         cmdline_fixed_string_t set;
7345         cmdline_fixed_string_t pfc_ctrl;
7346         cmdline_fixed_string_t rx;
7347         cmdline_fixed_string_t rx_pfc_mode;
7348         cmdline_fixed_string_t tx;
7349         cmdline_fixed_string_t tx_pfc_mode;
7350         uint32_t high_water;
7351         uint32_t low_water;
7352         uint16_t pause_time;
7353         uint8_t  priority;
7354         portid_t port_id;
7355 };
7356
7357 static void
7358 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7359                        __rte_unused struct cmdline *cl,
7360                        __rte_unused void *data)
7361 {
7362         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7363         struct rte_eth_pfc_conf pfc_conf;
7364         int rx_fc_enable, tx_fc_enable;
7365         int ret;
7366
7367         /*
7368          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7369          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7370          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7371          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7372          */
7373         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7374                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7375         };
7376
7377         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7378         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7379         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7380         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7381         pfc_conf.fc.high_water = res->high_water;
7382         pfc_conf.fc.low_water  = res->low_water;
7383         pfc_conf.fc.pause_time = res->pause_time;
7384         pfc_conf.priority      = res->priority;
7385
7386         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7387         if (ret != 0)
7388                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7389 }
7390
7391 cmdline_parse_token_string_t cmd_pfc_set_set =
7392         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7393                                 set, "set");
7394 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7395         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7396                                 pfc_ctrl, "pfc_ctrl");
7397 cmdline_parse_token_string_t cmd_pfc_set_rx =
7398         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7399                                 rx, "rx");
7400 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7401         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7402                                 rx_pfc_mode, "on#off");
7403 cmdline_parse_token_string_t cmd_pfc_set_tx =
7404         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7405                                 tx, "tx");
7406 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7407         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7408                                 tx_pfc_mode, "on#off");
7409 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7410         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7411                                 high_water, RTE_UINT32);
7412 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7413         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7414                                 low_water, RTE_UINT32);
7415 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7416         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7417                                 pause_time, RTE_UINT16);
7418 cmdline_parse_token_num_t cmd_pfc_set_priority =
7419         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7420                                 priority, RTE_UINT8);
7421 cmdline_parse_token_num_t cmd_pfc_set_portid =
7422         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7423                                 port_id, RTE_UINT16);
7424
7425 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7426         .f = cmd_priority_flow_ctrl_set_parsed,
7427         .data = NULL,
7428         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7429                 "<pause_time> <priority> <port_id>: "
7430                 "Configure the Ethernet priority flow control",
7431         .tokens = {
7432                 (void *)&cmd_pfc_set_set,
7433                 (void *)&cmd_pfc_set_flow_ctrl,
7434                 (void *)&cmd_pfc_set_rx,
7435                 (void *)&cmd_pfc_set_rx_mode,
7436                 (void *)&cmd_pfc_set_tx,
7437                 (void *)&cmd_pfc_set_tx_mode,
7438                 (void *)&cmd_pfc_set_high_water,
7439                 (void *)&cmd_pfc_set_low_water,
7440                 (void *)&cmd_pfc_set_pause_time,
7441                 (void *)&cmd_pfc_set_priority,
7442                 (void *)&cmd_pfc_set_portid,
7443                 NULL,
7444         },
7445 };
7446
7447 /* *** RESET CONFIGURATION *** */
7448 struct cmd_reset_result {
7449         cmdline_fixed_string_t reset;
7450         cmdline_fixed_string_t def;
7451 };
7452
7453 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7454                              struct cmdline *cl,
7455                              __rte_unused void *data)
7456 {
7457         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7458         set_def_fwd_config();
7459 }
7460
7461 cmdline_parse_token_string_t cmd_reset_set =
7462         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7463 cmdline_parse_token_string_t cmd_reset_def =
7464         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7465                                  "default");
7466
7467 cmdline_parse_inst_t cmd_reset = {
7468         .f = cmd_reset_parsed,
7469         .data = NULL,
7470         .help_str = "set default: Reset default forwarding configuration",
7471         .tokens = {
7472                 (void *)&cmd_reset_set,
7473                 (void *)&cmd_reset_def,
7474                 NULL,
7475         },
7476 };
7477
7478 /* *** START FORWARDING *** */
7479 struct cmd_start_result {
7480         cmdline_fixed_string_t start;
7481 };
7482
7483 cmdline_parse_token_string_t cmd_start_start =
7484         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7485
7486 static void cmd_start_parsed(__rte_unused void *parsed_result,
7487                              __rte_unused struct cmdline *cl,
7488                              __rte_unused void *data)
7489 {
7490         start_packet_forwarding(0);
7491 }
7492
7493 cmdline_parse_inst_t cmd_start = {
7494         .f = cmd_start_parsed,
7495         .data = NULL,
7496         .help_str = "start: Start packet forwarding",
7497         .tokens = {
7498                 (void *)&cmd_start_start,
7499                 NULL,
7500         },
7501 };
7502
7503 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7504 struct cmd_start_tx_first_result {
7505         cmdline_fixed_string_t start;
7506         cmdline_fixed_string_t tx_first;
7507 };
7508
7509 static void
7510 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7511                           __rte_unused struct cmdline *cl,
7512                           __rte_unused void *data)
7513 {
7514         start_packet_forwarding(1);
7515 }
7516
7517 cmdline_parse_token_string_t cmd_start_tx_first_start =
7518         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7519                                  "start");
7520 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7521         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7522                                  tx_first, "tx_first");
7523
7524 cmdline_parse_inst_t cmd_start_tx_first = {
7525         .f = cmd_start_tx_first_parsed,
7526         .data = NULL,
7527         .help_str = "start tx_first: Start packet forwarding, "
7528                 "after sending 1 burst of packets",
7529         .tokens = {
7530                 (void *)&cmd_start_tx_first_start,
7531                 (void *)&cmd_start_tx_first_tx_first,
7532                 NULL,
7533         },
7534 };
7535
7536 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7537 struct cmd_start_tx_first_n_result {
7538         cmdline_fixed_string_t start;
7539         cmdline_fixed_string_t tx_first;
7540         uint32_t tx_num;
7541 };
7542
7543 static void
7544 cmd_start_tx_first_n_parsed(void *parsed_result,
7545                           __rte_unused struct cmdline *cl,
7546                           __rte_unused void *data)
7547 {
7548         struct cmd_start_tx_first_n_result *res = parsed_result;
7549
7550         start_packet_forwarding(res->tx_num);
7551 }
7552
7553 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7554         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7555                         start, "start");
7556 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7557         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7558                         tx_first, "tx_first");
7559 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7560         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7561                         tx_num, RTE_UINT32);
7562
7563 cmdline_parse_inst_t cmd_start_tx_first_n = {
7564         .f = cmd_start_tx_first_n_parsed,
7565         .data = NULL,
7566         .help_str = "start tx_first <num>: "
7567                 "packet forwarding, after sending <num> bursts of packets",
7568         .tokens = {
7569                 (void *)&cmd_start_tx_first_n_start,
7570                 (void *)&cmd_start_tx_first_n_tx_first,
7571                 (void *)&cmd_start_tx_first_n_tx_num,
7572                 NULL,
7573         },
7574 };
7575
7576 /* *** SET LINK UP *** */
7577 struct cmd_set_link_up_result {
7578         cmdline_fixed_string_t set;
7579         cmdline_fixed_string_t link_up;
7580         cmdline_fixed_string_t port;
7581         portid_t port_id;
7582 };
7583
7584 cmdline_parse_token_string_t cmd_set_link_up_set =
7585         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7586 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7587         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7588                                 "link-up");
7589 cmdline_parse_token_string_t cmd_set_link_up_port =
7590         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7591 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7592         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7593                                 RTE_UINT16);
7594
7595 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7596                              __rte_unused struct cmdline *cl,
7597                              __rte_unused void *data)
7598 {
7599         struct cmd_set_link_up_result *res = parsed_result;
7600         dev_set_link_up(res->port_id);
7601 }
7602
7603 cmdline_parse_inst_t cmd_set_link_up = {
7604         .f = cmd_set_link_up_parsed,
7605         .data = NULL,
7606         .help_str = "set link-up port <port id>",
7607         .tokens = {
7608                 (void *)&cmd_set_link_up_set,
7609                 (void *)&cmd_set_link_up_link_up,
7610                 (void *)&cmd_set_link_up_port,
7611                 (void *)&cmd_set_link_up_port_id,
7612                 NULL,
7613         },
7614 };
7615
7616 /* *** SET LINK DOWN *** */
7617 struct cmd_set_link_down_result {
7618         cmdline_fixed_string_t set;
7619         cmdline_fixed_string_t link_down;
7620         cmdline_fixed_string_t port;
7621         portid_t port_id;
7622 };
7623
7624 cmdline_parse_token_string_t cmd_set_link_down_set =
7625         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7626 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7627         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7628                                 "link-down");
7629 cmdline_parse_token_string_t cmd_set_link_down_port =
7630         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7631 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7632         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7633                                 RTE_UINT16);
7634
7635 static void cmd_set_link_down_parsed(
7636                                 __rte_unused void *parsed_result,
7637                                 __rte_unused struct cmdline *cl,
7638                                 __rte_unused void *data)
7639 {
7640         struct cmd_set_link_down_result *res = parsed_result;
7641         dev_set_link_down(res->port_id);
7642 }
7643
7644 cmdline_parse_inst_t cmd_set_link_down = {
7645         .f = cmd_set_link_down_parsed,
7646         .data = NULL,
7647         .help_str = "set link-down port <port id>",
7648         .tokens = {
7649                 (void *)&cmd_set_link_down_set,
7650                 (void *)&cmd_set_link_down_link_down,
7651                 (void *)&cmd_set_link_down_port,
7652                 (void *)&cmd_set_link_down_port_id,
7653                 NULL,
7654         },
7655 };
7656
7657 /* *** SHOW CFG *** */
7658 struct cmd_showcfg_result {
7659         cmdline_fixed_string_t show;
7660         cmdline_fixed_string_t cfg;
7661         cmdline_fixed_string_t what;
7662 };
7663
7664 static void cmd_showcfg_parsed(void *parsed_result,
7665                                __rte_unused struct cmdline *cl,
7666                                __rte_unused void *data)
7667 {
7668         struct cmd_showcfg_result *res = parsed_result;
7669         if (!strcmp(res->what, "rxtx"))
7670                 rxtx_config_display();
7671         else if (!strcmp(res->what, "cores"))
7672                 fwd_lcores_config_display();
7673         else if (!strcmp(res->what, "fwd"))
7674                 pkt_fwd_config_display(&cur_fwd_config);
7675         else if (!strcmp(res->what, "rxoffs"))
7676                 show_rx_pkt_offsets();
7677         else if (!strcmp(res->what, "rxpkts"))
7678                 show_rx_pkt_segments();
7679         else if (!strcmp(res->what, "txpkts"))
7680                 show_tx_pkt_segments();
7681         else if (!strcmp(res->what, "txtimes"))
7682                 show_tx_pkt_times();
7683 }
7684
7685 cmdline_parse_token_string_t cmd_showcfg_show =
7686         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7687 cmdline_parse_token_string_t cmd_showcfg_port =
7688         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7689 cmdline_parse_token_string_t cmd_showcfg_what =
7690         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7691                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7692
7693 cmdline_parse_inst_t cmd_showcfg = {
7694         .f = cmd_showcfg_parsed,
7695         .data = NULL,
7696         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7697         .tokens = {
7698                 (void *)&cmd_showcfg_show,
7699                 (void *)&cmd_showcfg_port,
7700                 (void *)&cmd_showcfg_what,
7701                 NULL,
7702         },
7703 };
7704
7705 /* *** SHOW ALL PORT INFO *** */
7706 struct cmd_showportall_result {
7707         cmdline_fixed_string_t show;
7708         cmdline_fixed_string_t port;
7709         cmdline_fixed_string_t what;
7710         cmdline_fixed_string_t all;
7711 };
7712
7713 static void cmd_showportall_parsed(void *parsed_result,
7714                                 __rte_unused struct cmdline *cl,
7715                                 __rte_unused void *data)
7716 {
7717         portid_t i;
7718
7719         struct cmd_showportall_result *res = parsed_result;
7720         if (!strcmp(res->show, "clear")) {
7721                 if (!strcmp(res->what, "stats"))
7722                         RTE_ETH_FOREACH_DEV(i)
7723                                 nic_stats_clear(i);
7724                 else if (!strcmp(res->what, "xstats"))
7725                         RTE_ETH_FOREACH_DEV(i)
7726                                 nic_xstats_clear(i);
7727         } else if (!strcmp(res->what, "info"))
7728                 RTE_ETH_FOREACH_DEV(i)
7729                         port_infos_display(i);
7730         else if (!strcmp(res->what, "summary")) {
7731                 port_summary_header_display();
7732                 RTE_ETH_FOREACH_DEV(i)
7733                         port_summary_display(i);
7734         }
7735         else if (!strcmp(res->what, "stats"))
7736                 RTE_ETH_FOREACH_DEV(i)
7737                         nic_stats_display(i);
7738         else if (!strcmp(res->what, "xstats"))
7739                 RTE_ETH_FOREACH_DEV(i)
7740                         nic_xstats_display(i);
7741 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7742         else if (!strcmp(res->what, "fdir"))
7743                 RTE_ETH_FOREACH_DEV(i)
7744                         fdir_get_infos(i);
7745 #endif
7746         else if (!strcmp(res->what, "dcb_tc"))
7747                 RTE_ETH_FOREACH_DEV(i)
7748                         port_dcb_info_display(i);
7749 }
7750
7751 cmdline_parse_token_string_t cmd_showportall_show =
7752         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7753                                  "show#clear");
7754 cmdline_parse_token_string_t cmd_showportall_port =
7755         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7756 cmdline_parse_token_string_t cmd_showportall_what =
7757         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7758                                  "info#summary#stats#xstats#fdir#dcb_tc");
7759 cmdline_parse_token_string_t cmd_showportall_all =
7760         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7761 cmdline_parse_inst_t cmd_showportall = {
7762         .f = cmd_showportall_parsed,
7763         .data = NULL,
7764         .help_str = "show|clear port "
7765                 "info|summary|stats|xstats|fdir|dcb_tc all",
7766         .tokens = {
7767                 (void *)&cmd_showportall_show,
7768                 (void *)&cmd_showportall_port,
7769                 (void *)&cmd_showportall_what,
7770                 (void *)&cmd_showportall_all,
7771                 NULL,
7772         },
7773 };
7774
7775 /* *** SHOW PORT INFO *** */
7776 struct cmd_showport_result {
7777         cmdline_fixed_string_t show;
7778         cmdline_fixed_string_t port;
7779         cmdline_fixed_string_t what;
7780         uint16_t portnum;
7781 };
7782
7783 static void cmd_showport_parsed(void *parsed_result,
7784                                 __rte_unused struct cmdline *cl,
7785                                 __rte_unused void *data)
7786 {
7787         struct cmd_showport_result *res = parsed_result;
7788         if (!strcmp(res->show, "clear")) {
7789                 if (!strcmp(res->what, "stats"))
7790                         nic_stats_clear(res->portnum);
7791                 else if (!strcmp(res->what, "xstats"))
7792                         nic_xstats_clear(res->portnum);
7793         } else if (!strcmp(res->what, "info"))
7794                 port_infos_display(res->portnum);
7795         else if (!strcmp(res->what, "summary")) {
7796                 port_summary_header_display();
7797                 port_summary_display(res->portnum);
7798         }
7799         else if (!strcmp(res->what, "stats"))
7800                 nic_stats_display(res->portnum);
7801         else if (!strcmp(res->what, "xstats"))
7802                 nic_xstats_display(res->portnum);
7803 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7804         else if (!strcmp(res->what, "fdir"))
7805                  fdir_get_infos(res->portnum);
7806 #endif
7807         else if (!strcmp(res->what, "dcb_tc"))
7808                 port_dcb_info_display(res->portnum);
7809 }
7810
7811 cmdline_parse_token_string_t cmd_showport_show =
7812         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7813                                  "show#clear");
7814 cmdline_parse_token_string_t cmd_showport_port =
7815         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7816 cmdline_parse_token_string_t cmd_showport_what =
7817         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7818                                  "info#summary#stats#xstats#fdir#dcb_tc");
7819 cmdline_parse_token_num_t cmd_showport_portnum =
7820         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
7821
7822 cmdline_parse_inst_t cmd_showport = {
7823         .f = cmd_showport_parsed,
7824         .data = NULL,
7825         .help_str = "show|clear port "
7826                 "info|summary|stats|xstats|fdir|dcb_tc "
7827                 "<port_id>",
7828         .tokens = {
7829                 (void *)&cmd_showport_show,
7830                 (void *)&cmd_showport_port,
7831                 (void *)&cmd_showport_what,
7832                 (void *)&cmd_showport_portnum,
7833                 NULL,
7834         },
7835 };
7836
7837 /* *** SHOW DEVICE INFO *** */
7838 struct cmd_showdevice_result {
7839         cmdline_fixed_string_t show;
7840         cmdline_fixed_string_t device;
7841         cmdline_fixed_string_t what;
7842         cmdline_fixed_string_t identifier;
7843 };
7844
7845 static void cmd_showdevice_parsed(void *parsed_result,
7846                                 __rte_unused struct cmdline *cl,
7847                                 __rte_unused void *data)
7848 {
7849         struct cmd_showdevice_result *res = parsed_result;
7850         if (!strcmp(res->what, "info")) {
7851                 if (!strcmp(res->identifier, "all"))
7852                         device_infos_display(NULL);
7853                 else
7854                         device_infos_display(res->identifier);
7855         }
7856 }
7857
7858 cmdline_parse_token_string_t cmd_showdevice_show =
7859         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7860                                  "show");
7861 cmdline_parse_token_string_t cmd_showdevice_device =
7862         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7863 cmdline_parse_token_string_t cmd_showdevice_what =
7864         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7865                                  "info");
7866 cmdline_parse_token_string_t cmd_showdevice_identifier =
7867         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7868                         identifier, NULL);
7869
7870 cmdline_parse_inst_t cmd_showdevice = {
7871         .f = cmd_showdevice_parsed,
7872         .data = NULL,
7873         .help_str = "show device info <identifier>|all",
7874         .tokens = {
7875                 (void *)&cmd_showdevice_show,
7876                 (void *)&cmd_showdevice_device,
7877                 (void *)&cmd_showdevice_what,
7878                 (void *)&cmd_showdevice_identifier,
7879                 NULL,
7880         },
7881 };
7882
7883 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7884 struct cmd_showeeprom_result {
7885         cmdline_fixed_string_t show;
7886         cmdline_fixed_string_t port;
7887         uint16_t portnum;
7888         cmdline_fixed_string_t type;
7889 };
7890
7891 static void cmd_showeeprom_parsed(void *parsed_result,
7892                 __rte_unused struct cmdline *cl,
7893                 __rte_unused void *data)
7894 {
7895         struct cmd_showeeprom_result *res = parsed_result;
7896
7897         if (!strcmp(res->type, "eeprom"))
7898                 port_eeprom_display(res->portnum);
7899         else if (!strcmp(res->type, "module_eeprom"))
7900                 port_module_eeprom_display(res->portnum);
7901         else
7902                 printf("Unknown argument\n");
7903 }
7904
7905 cmdline_parse_token_string_t cmd_showeeprom_show =
7906         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7907 cmdline_parse_token_string_t cmd_showeeprom_port =
7908         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7909 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7910         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
7911                         RTE_UINT16);
7912 cmdline_parse_token_string_t cmd_showeeprom_type =
7913         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7914
7915 cmdline_parse_inst_t cmd_showeeprom = {
7916         .f = cmd_showeeprom_parsed,
7917         .data = NULL,
7918         .help_str = "show port <port_id> module_eeprom|eeprom",
7919         .tokens = {
7920                 (void *)&cmd_showeeprom_show,
7921                 (void *)&cmd_showeeprom_port,
7922                 (void *)&cmd_showeeprom_portnum,
7923                 (void *)&cmd_showeeprom_type,
7924                 NULL,
7925         },
7926 };
7927
7928 /* *** SHOW QUEUE INFO *** */
7929 struct cmd_showqueue_result {
7930         cmdline_fixed_string_t show;
7931         cmdline_fixed_string_t type;
7932         cmdline_fixed_string_t what;
7933         uint16_t portnum;
7934         uint16_t queuenum;
7935 };
7936
7937 static void
7938 cmd_showqueue_parsed(void *parsed_result,
7939         __rte_unused struct cmdline *cl,
7940         __rte_unused void *data)
7941 {
7942         struct cmd_showqueue_result *res = parsed_result;
7943
7944         if (!strcmp(res->type, "rxq"))
7945                 rx_queue_infos_display(res->portnum, res->queuenum);
7946         else if (!strcmp(res->type, "txq"))
7947                 tx_queue_infos_display(res->portnum, res->queuenum);
7948 }
7949
7950 cmdline_parse_token_string_t cmd_showqueue_show =
7951         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7952 cmdline_parse_token_string_t cmd_showqueue_type =
7953         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7954 cmdline_parse_token_string_t cmd_showqueue_what =
7955         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7956 cmdline_parse_token_num_t cmd_showqueue_portnum =
7957         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
7958                 RTE_UINT16);
7959 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7960         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
7961                 RTE_UINT16);
7962
7963 cmdline_parse_inst_t cmd_showqueue = {
7964         .f = cmd_showqueue_parsed,
7965         .data = NULL,
7966         .help_str = "show rxq|txq info <port_id> <queue_id>",
7967         .tokens = {
7968                 (void *)&cmd_showqueue_show,
7969                 (void *)&cmd_showqueue_type,
7970                 (void *)&cmd_showqueue_what,
7971                 (void *)&cmd_showqueue_portnum,
7972                 (void *)&cmd_showqueue_queuenum,
7973                 NULL,
7974         },
7975 };
7976
7977 /* show/clear fwd engine statistics */
7978 struct fwd_result {
7979         cmdline_fixed_string_t action;
7980         cmdline_fixed_string_t fwd;
7981         cmdline_fixed_string_t stats;
7982         cmdline_fixed_string_t all;
7983 };
7984
7985 cmdline_parse_token_string_t cmd_fwd_action =
7986         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7987 cmdline_parse_token_string_t cmd_fwd_fwd =
7988         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7989 cmdline_parse_token_string_t cmd_fwd_stats =
7990         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7991 cmdline_parse_token_string_t cmd_fwd_all =
7992         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7993
7994 static void
7995 cmd_showfwdall_parsed(void *parsed_result,
7996                       __rte_unused struct cmdline *cl,
7997                       __rte_unused void *data)
7998 {
7999         struct fwd_result *res = parsed_result;
8000
8001         if (!strcmp(res->action, "show"))
8002                 fwd_stats_display();
8003         else
8004                 fwd_stats_reset();
8005 }
8006
8007 static cmdline_parse_inst_t cmd_showfwdall = {
8008         .f = cmd_showfwdall_parsed,
8009         .data = NULL,
8010         .help_str = "show|clear fwd stats all",
8011         .tokens = {
8012                 (void *)&cmd_fwd_action,
8013                 (void *)&cmd_fwd_fwd,
8014                 (void *)&cmd_fwd_stats,
8015                 (void *)&cmd_fwd_all,
8016                 NULL,
8017         },
8018 };
8019
8020 /* *** READ PORT REGISTER *** */
8021 struct cmd_read_reg_result {
8022         cmdline_fixed_string_t read;
8023         cmdline_fixed_string_t reg;
8024         portid_t port_id;
8025         uint32_t reg_off;
8026 };
8027
8028 static void
8029 cmd_read_reg_parsed(void *parsed_result,
8030                     __rte_unused struct cmdline *cl,
8031                     __rte_unused void *data)
8032 {
8033         struct cmd_read_reg_result *res = parsed_result;
8034         port_reg_display(res->port_id, res->reg_off);
8035 }
8036
8037 cmdline_parse_token_string_t cmd_read_reg_read =
8038         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8039 cmdline_parse_token_string_t cmd_read_reg_reg =
8040         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8041 cmdline_parse_token_num_t cmd_read_reg_port_id =
8042         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8043 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8044         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8045
8046 cmdline_parse_inst_t cmd_read_reg = {
8047         .f = cmd_read_reg_parsed,
8048         .data = NULL,
8049         .help_str = "read reg <port_id> <reg_off>",
8050         .tokens = {
8051                 (void *)&cmd_read_reg_read,
8052                 (void *)&cmd_read_reg_reg,
8053                 (void *)&cmd_read_reg_port_id,
8054                 (void *)&cmd_read_reg_reg_off,
8055                 NULL,
8056         },
8057 };
8058
8059 /* *** READ PORT REGISTER BIT FIELD *** */
8060 struct cmd_read_reg_bit_field_result {
8061         cmdline_fixed_string_t read;
8062         cmdline_fixed_string_t regfield;
8063         portid_t port_id;
8064         uint32_t reg_off;
8065         uint8_t bit1_pos;
8066         uint8_t bit2_pos;
8067 };
8068
8069 static void
8070 cmd_read_reg_bit_field_parsed(void *parsed_result,
8071                               __rte_unused struct cmdline *cl,
8072                               __rte_unused void *data)
8073 {
8074         struct cmd_read_reg_bit_field_result *res = parsed_result;
8075         port_reg_bit_field_display(res->port_id, res->reg_off,
8076                                    res->bit1_pos, res->bit2_pos);
8077 }
8078
8079 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8080         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8081                                  "read");
8082 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8083         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8084                                  regfield, "regfield");
8085 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8086         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8087                               RTE_UINT16);
8088 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8089         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8090                               RTE_UINT32);
8091 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8092         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8093                               RTE_UINT8);
8094 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8095         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8096                               RTE_UINT8);
8097
8098 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8099         .f = cmd_read_reg_bit_field_parsed,
8100         .data = NULL,
8101         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8102         "Read register bit field between bit_x and bit_y included",
8103         .tokens = {
8104                 (void *)&cmd_read_reg_bit_field_read,
8105                 (void *)&cmd_read_reg_bit_field_regfield,
8106                 (void *)&cmd_read_reg_bit_field_port_id,
8107                 (void *)&cmd_read_reg_bit_field_reg_off,
8108                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8109                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8110                 NULL,
8111         },
8112 };
8113
8114 /* *** READ PORT REGISTER BIT *** */
8115 struct cmd_read_reg_bit_result {
8116         cmdline_fixed_string_t read;
8117         cmdline_fixed_string_t regbit;
8118         portid_t port_id;
8119         uint32_t reg_off;
8120         uint8_t bit_pos;
8121 };
8122
8123 static void
8124 cmd_read_reg_bit_parsed(void *parsed_result,
8125                         __rte_unused struct cmdline *cl,
8126                         __rte_unused void *data)
8127 {
8128         struct cmd_read_reg_bit_result *res = parsed_result;
8129         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8130 }
8131
8132 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8133         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8134 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8135         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8136                                  regbit, "regbit");
8137 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8138         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8139                                  RTE_UINT16);
8140 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8141         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8142                                  RTE_UINT32);
8143 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8144         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8145                                  RTE_UINT8);
8146
8147 cmdline_parse_inst_t cmd_read_reg_bit = {
8148         .f = cmd_read_reg_bit_parsed,
8149         .data = NULL,
8150         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8151         .tokens = {
8152                 (void *)&cmd_read_reg_bit_read,
8153                 (void *)&cmd_read_reg_bit_regbit,
8154                 (void *)&cmd_read_reg_bit_port_id,
8155                 (void *)&cmd_read_reg_bit_reg_off,
8156                 (void *)&cmd_read_reg_bit_bit_pos,
8157                 NULL,
8158         },
8159 };
8160
8161 /* *** WRITE PORT REGISTER *** */
8162 struct cmd_write_reg_result {
8163         cmdline_fixed_string_t write;
8164         cmdline_fixed_string_t reg;
8165         portid_t port_id;
8166         uint32_t reg_off;
8167         uint32_t value;
8168 };
8169
8170 static void
8171 cmd_write_reg_parsed(void *parsed_result,
8172                      __rte_unused struct cmdline *cl,
8173                      __rte_unused void *data)
8174 {
8175         struct cmd_write_reg_result *res = parsed_result;
8176         port_reg_set(res->port_id, res->reg_off, res->value);
8177 }
8178
8179 cmdline_parse_token_string_t cmd_write_reg_write =
8180         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8181 cmdline_parse_token_string_t cmd_write_reg_reg =
8182         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8183 cmdline_parse_token_num_t cmd_write_reg_port_id =
8184         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8185 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8186         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8187 cmdline_parse_token_num_t cmd_write_reg_value =
8188         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8189
8190 cmdline_parse_inst_t cmd_write_reg = {
8191         .f = cmd_write_reg_parsed,
8192         .data = NULL,
8193         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8194         .tokens = {
8195                 (void *)&cmd_write_reg_write,
8196                 (void *)&cmd_write_reg_reg,
8197                 (void *)&cmd_write_reg_port_id,
8198                 (void *)&cmd_write_reg_reg_off,
8199                 (void *)&cmd_write_reg_value,
8200                 NULL,
8201         },
8202 };
8203
8204 /* *** WRITE PORT REGISTER BIT FIELD *** */
8205 struct cmd_write_reg_bit_field_result {
8206         cmdline_fixed_string_t write;
8207         cmdline_fixed_string_t regfield;
8208         portid_t port_id;
8209         uint32_t reg_off;
8210         uint8_t bit1_pos;
8211         uint8_t bit2_pos;
8212         uint32_t value;
8213 };
8214
8215 static void
8216 cmd_write_reg_bit_field_parsed(void *parsed_result,
8217                                __rte_unused struct cmdline *cl,
8218                                __rte_unused void *data)
8219 {
8220         struct cmd_write_reg_bit_field_result *res = parsed_result;
8221         port_reg_bit_field_set(res->port_id, res->reg_off,
8222                           res->bit1_pos, res->bit2_pos, res->value);
8223 }
8224
8225 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8226         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8227                                  "write");
8228 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8229         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8230                                  regfield, "regfield");
8231 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8232         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8233                               RTE_UINT16);
8234 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8235         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8236                               RTE_UINT32);
8237 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8238         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8239                               RTE_UINT8);
8240 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8241         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8242                               RTE_UINT8);
8243 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8244         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8245                               RTE_UINT32);
8246
8247 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8248         .f = cmd_write_reg_bit_field_parsed,
8249         .data = NULL,
8250         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8251                 "<reg_value>: "
8252                 "Set register bit field between bit_x and bit_y included",
8253         .tokens = {
8254                 (void *)&cmd_write_reg_bit_field_write,
8255                 (void *)&cmd_write_reg_bit_field_regfield,
8256                 (void *)&cmd_write_reg_bit_field_port_id,
8257                 (void *)&cmd_write_reg_bit_field_reg_off,
8258                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8259                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8260                 (void *)&cmd_write_reg_bit_field_value,
8261                 NULL,
8262         },
8263 };
8264
8265 /* *** WRITE PORT REGISTER BIT *** */
8266 struct cmd_write_reg_bit_result {
8267         cmdline_fixed_string_t write;
8268         cmdline_fixed_string_t regbit;
8269         portid_t port_id;
8270         uint32_t reg_off;
8271         uint8_t bit_pos;
8272         uint8_t value;
8273 };
8274
8275 static void
8276 cmd_write_reg_bit_parsed(void *parsed_result,
8277                          __rte_unused struct cmdline *cl,
8278                          __rte_unused void *data)
8279 {
8280         struct cmd_write_reg_bit_result *res = parsed_result;
8281         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8282 }
8283
8284 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8285         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8286                                  "write");
8287 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8288         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8289                                  regbit, "regbit");
8290 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8291         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8292                                  RTE_UINT16);
8293 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8294         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8295                                  RTE_UINT32);
8296 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8297         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8298                                  RTE_UINT8);
8299 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8300         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8301                                  RTE_UINT8);
8302
8303 cmdline_parse_inst_t cmd_write_reg_bit = {
8304         .f = cmd_write_reg_bit_parsed,
8305         .data = NULL,
8306         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8307                 "0 <= bit_x <= 31",
8308         .tokens = {
8309                 (void *)&cmd_write_reg_bit_write,
8310                 (void *)&cmd_write_reg_bit_regbit,
8311                 (void *)&cmd_write_reg_bit_port_id,
8312                 (void *)&cmd_write_reg_bit_reg_off,
8313                 (void *)&cmd_write_reg_bit_bit_pos,
8314                 (void *)&cmd_write_reg_bit_value,
8315                 NULL,
8316         },
8317 };
8318
8319 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8320 struct cmd_read_rxd_txd_result {
8321         cmdline_fixed_string_t read;
8322         cmdline_fixed_string_t rxd_txd;
8323         portid_t port_id;
8324         uint16_t queue_id;
8325         uint16_t desc_id;
8326 };
8327
8328 static void
8329 cmd_read_rxd_txd_parsed(void *parsed_result,
8330                         __rte_unused struct cmdline *cl,
8331                         __rte_unused void *data)
8332 {
8333         struct cmd_read_rxd_txd_result *res = parsed_result;
8334
8335         if (!strcmp(res->rxd_txd, "rxd"))
8336                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8337         else if (!strcmp(res->rxd_txd, "txd"))
8338                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8339 }
8340
8341 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8342         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8343 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8344         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8345                                  "rxd#txd");
8346 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8347         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8348                                  RTE_UINT16);
8349 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8350         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8351                                  RTE_UINT16);
8352 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8353         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8354                                  RTE_UINT16);
8355
8356 cmdline_parse_inst_t cmd_read_rxd_txd = {
8357         .f = cmd_read_rxd_txd_parsed,
8358         .data = NULL,
8359         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8360         .tokens = {
8361                 (void *)&cmd_read_rxd_txd_read,
8362                 (void *)&cmd_read_rxd_txd_rxd_txd,
8363                 (void *)&cmd_read_rxd_txd_port_id,
8364                 (void *)&cmd_read_rxd_txd_queue_id,
8365                 (void *)&cmd_read_rxd_txd_desc_id,
8366                 NULL,
8367         },
8368 };
8369
8370 /* *** QUIT *** */
8371 struct cmd_quit_result {
8372         cmdline_fixed_string_t quit;
8373 };
8374
8375 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8376                             struct cmdline *cl,
8377                             __rte_unused void *data)
8378 {
8379         cmdline_quit(cl);
8380 }
8381
8382 cmdline_parse_token_string_t cmd_quit_quit =
8383         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8384
8385 cmdline_parse_inst_t cmd_quit = {
8386         .f = cmd_quit_parsed,
8387         .data = NULL,
8388         .help_str = "quit: Exit application",
8389         .tokens = {
8390                 (void *)&cmd_quit_quit,
8391                 NULL,
8392         },
8393 };
8394
8395 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8396 struct cmd_mac_addr_result {
8397         cmdline_fixed_string_t mac_addr_cmd;
8398         cmdline_fixed_string_t what;
8399         uint16_t port_num;
8400         struct rte_ether_addr address;
8401 };
8402
8403 static void cmd_mac_addr_parsed(void *parsed_result,
8404                 __rte_unused struct cmdline *cl,
8405                 __rte_unused void *data)
8406 {
8407         struct cmd_mac_addr_result *res = parsed_result;
8408         int ret;
8409
8410         if (strcmp(res->what, "add") == 0)
8411                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8412         else if (strcmp(res->what, "set") == 0)
8413                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8414                                                        &res->address);
8415         else
8416                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8417
8418         /* check the return value and print it if is < 0 */
8419         if(ret < 0)
8420                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8421
8422 }
8423
8424 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8425         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8426                                 "mac_addr");
8427 cmdline_parse_token_string_t cmd_mac_addr_what =
8428         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8429                                 "add#remove#set");
8430 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8431                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8432                                         RTE_UINT16);
8433 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8434                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8435
8436 cmdline_parse_inst_t cmd_mac_addr = {
8437         .f = cmd_mac_addr_parsed,
8438         .data = (void *)0,
8439         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8440                         "Add/Remove/Set MAC address on port_id",
8441         .tokens = {
8442                 (void *)&cmd_mac_addr_cmd,
8443                 (void *)&cmd_mac_addr_what,
8444                 (void *)&cmd_mac_addr_portnum,
8445                 (void *)&cmd_mac_addr_addr,
8446                 NULL,
8447         },
8448 };
8449
8450 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8451 struct cmd_eth_peer_result {
8452         cmdline_fixed_string_t set;
8453         cmdline_fixed_string_t eth_peer;
8454         portid_t port_id;
8455         cmdline_fixed_string_t peer_addr;
8456 };
8457
8458 static void cmd_set_eth_peer_parsed(void *parsed_result,
8459                         __rte_unused struct cmdline *cl,
8460                         __rte_unused void *data)
8461 {
8462                 struct cmd_eth_peer_result *res = parsed_result;
8463
8464                 if (test_done == 0) {
8465                         printf("Please stop forwarding first\n");
8466                         return;
8467                 }
8468                 if (!strcmp(res->eth_peer, "eth-peer")) {
8469                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8470                         fwd_config_setup();
8471                 }
8472 }
8473 cmdline_parse_token_string_t cmd_eth_peer_set =
8474         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8475 cmdline_parse_token_string_t cmd_eth_peer =
8476         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8477 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8478         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8479                 RTE_UINT16);
8480 cmdline_parse_token_string_t cmd_eth_peer_addr =
8481         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8482
8483 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8484         .f = cmd_set_eth_peer_parsed,
8485         .data = NULL,
8486         .help_str = "set eth-peer <port_id> <peer_mac>",
8487         .tokens = {
8488                 (void *)&cmd_eth_peer_set,
8489                 (void *)&cmd_eth_peer,
8490                 (void *)&cmd_eth_peer_port_id,
8491                 (void *)&cmd_eth_peer_addr,
8492                 NULL,
8493         },
8494 };
8495
8496 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8497 struct cmd_set_qmap_result {
8498         cmdline_fixed_string_t set;
8499         cmdline_fixed_string_t qmap;
8500         cmdline_fixed_string_t what;
8501         portid_t port_id;
8502         uint16_t queue_id;
8503         uint8_t map_value;
8504 };
8505
8506 static void
8507 cmd_set_qmap_parsed(void *parsed_result,
8508                        __rte_unused struct cmdline *cl,
8509                        __rte_unused void *data)
8510 {
8511         struct cmd_set_qmap_result *res = parsed_result;
8512         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8513
8514         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8515 }
8516
8517 cmdline_parse_token_string_t cmd_setqmap_set =
8518         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8519                                  set, "set");
8520 cmdline_parse_token_string_t cmd_setqmap_qmap =
8521         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8522                                  qmap, "stat_qmap");
8523 cmdline_parse_token_string_t cmd_setqmap_what =
8524         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8525                                  what, "tx#rx");
8526 cmdline_parse_token_num_t cmd_setqmap_portid =
8527         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8528                               port_id, RTE_UINT16);
8529 cmdline_parse_token_num_t cmd_setqmap_queueid =
8530         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8531                               queue_id, RTE_UINT16);
8532 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8533         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8534                               map_value, RTE_UINT8);
8535
8536 cmdline_parse_inst_t cmd_set_qmap = {
8537         .f = cmd_set_qmap_parsed,
8538         .data = NULL,
8539         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8540                 "Set statistics mapping value on tx|rx queue_id of port_id",
8541         .tokens = {
8542                 (void *)&cmd_setqmap_set,
8543                 (void *)&cmd_setqmap_qmap,
8544                 (void *)&cmd_setqmap_what,
8545                 (void *)&cmd_setqmap_portid,
8546                 (void *)&cmd_setqmap_queueid,
8547                 (void *)&cmd_setqmap_mapvalue,
8548                 NULL,
8549         },
8550 };
8551
8552 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8553 struct cmd_set_xstats_hide_zero_result {
8554         cmdline_fixed_string_t keyword;
8555         cmdline_fixed_string_t name;
8556         cmdline_fixed_string_t on_off;
8557 };
8558
8559 static void
8560 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8561                         __rte_unused struct cmdline *cl,
8562                         __rte_unused void *data)
8563 {
8564         struct cmd_set_xstats_hide_zero_result *res;
8565         uint16_t on_off = 0;
8566
8567         res = parsed_result;
8568         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8569         set_xstats_hide_zero(on_off);
8570 }
8571
8572 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8573         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8574                                  keyword, "set");
8575 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8576         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8577                                  name, "xstats-hide-zero");
8578 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8579         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8580                                  on_off, "on#off");
8581
8582 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8583         .f = cmd_set_xstats_hide_zero_parsed,
8584         .data = NULL,
8585         .help_str = "set xstats-hide-zero on|off",
8586         .tokens = {
8587                 (void *)&cmd_set_xstats_hide_zero_keyword,
8588                 (void *)&cmd_set_xstats_hide_zero_name,
8589                 (void *)&cmd_set_xstats_hide_zero_on_off,
8590                 NULL,
8591         },
8592 };
8593
8594 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8595 struct cmd_set_record_core_cycles_result {
8596         cmdline_fixed_string_t keyword;
8597         cmdline_fixed_string_t name;
8598         cmdline_fixed_string_t on_off;
8599 };
8600
8601 static void
8602 cmd_set_record_core_cycles_parsed(void *parsed_result,
8603                         __rte_unused struct cmdline *cl,
8604                         __rte_unused void *data)
8605 {
8606         struct cmd_set_record_core_cycles_result *res;
8607         uint16_t on_off = 0;
8608
8609         res = parsed_result;
8610         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8611         set_record_core_cycles(on_off);
8612 }
8613
8614 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8615         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8616                                  keyword, "set");
8617 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8618         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8619                                  name, "record-core-cycles");
8620 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8621         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8622                                  on_off, "on#off");
8623
8624 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8625         .f = cmd_set_record_core_cycles_parsed,
8626         .data = NULL,
8627         .help_str = "set record-core-cycles on|off",
8628         .tokens = {
8629                 (void *)&cmd_set_record_core_cycles_keyword,
8630                 (void *)&cmd_set_record_core_cycles_name,
8631                 (void *)&cmd_set_record_core_cycles_on_off,
8632                 NULL,
8633         },
8634 };
8635
8636 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8637 struct cmd_set_record_burst_stats_result {
8638         cmdline_fixed_string_t keyword;
8639         cmdline_fixed_string_t name;
8640         cmdline_fixed_string_t on_off;
8641 };
8642
8643 static void
8644 cmd_set_record_burst_stats_parsed(void *parsed_result,
8645                         __rte_unused struct cmdline *cl,
8646                         __rte_unused void *data)
8647 {
8648         struct cmd_set_record_burst_stats_result *res;
8649         uint16_t on_off = 0;
8650
8651         res = parsed_result;
8652         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8653         set_record_burst_stats(on_off);
8654 }
8655
8656 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8657         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8658                                  keyword, "set");
8659 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8660         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8661                                  name, "record-burst-stats");
8662 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8663         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8664                                  on_off, "on#off");
8665
8666 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8667         .f = cmd_set_record_burst_stats_parsed,
8668         .data = NULL,
8669         .help_str = "set record-burst-stats on|off",
8670         .tokens = {
8671                 (void *)&cmd_set_record_burst_stats_keyword,
8672                 (void *)&cmd_set_record_burst_stats_name,
8673                 (void *)&cmd_set_record_burst_stats_on_off,
8674                 NULL,
8675         },
8676 };
8677
8678 /* *** CONFIGURE UNICAST HASH TABLE *** */
8679 struct cmd_set_uc_hash_table {
8680         cmdline_fixed_string_t set;
8681         cmdline_fixed_string_t port;
8682         portid_t port_id;
8683         cmdline_fixed_string_t what;
8684         struct rte_ether_addr address;
8685         cmdline_fixed_string_t mode;
8686 };
8687
8688 static void
8689 cmd_set_uc_hash_parsed(void *parsed_result,
8690                        __rte_unused struct cmdline *cl,
8691                        __rte_unused void *data)
8692 {
8693         int ret=0;
8694         struct cmd_set_uc_hash_table *res = parsed_result;
8695
8696         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8697
8698         if (strcmp(res->what, "uta") == 0)
8699                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8700                                                 &res->address,(uint8_t)is_on);
8701         if (ret < 0)
8702                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8703
8704 }
8705
8706 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8707         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8708                                  set, "set");
8709 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8710         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8711                                  port, "port");
8712 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8713         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8714                               port_id, RTE_UINT16);
8715 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8716         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8717                                  what, "uta");
8718 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8719         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8720                                 address);
8721 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8722         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8723                                  mode, "on#off");
8724
8725 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8726         .f = cmd_set_uc_hash_parsed,
8727         .data = NULL,
8728         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8729         .tokens = {
8730                 (void *)&cmd_set_uc_hash_set,
8731                 (void *)&cmd_set_uc_hash_port,
8732                 (void *)&cmd_set_uc_hash_portid,
8733                 (void *)&cmd_set_uc_hash_what,
8734                 (void *)&cmd_set_uc_hash_mac,
8735                 (void *)&cmd_set_uc_hash_mode,
8736                 NULL,
8737         },
8738 };
8739
8740 struct cmd_set_uc_all_hash_table {
8741         cmdline_fixed_string_t set;
8742         cmdline_fixed_string_t port;
8743         portid_t port_id;
8744         cmdline_fixed_string_t what;
8745         cmdline_fixed_string_t value;
8746         cmdline_fixed_string_t mode;
8747 };
8748
8749 static void
8750 cmd_set_uc_all_hash_parsed(void *parsed_result,
8751                        __rte_unused struct cmdline *cl,
8752                        __rte_unused void *data)
8753 {
8754         int ret=0;
8755         struct cmd_set_uc_all_hash_table *res = parsed_result;
8756
8757         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8758
8759         if ((strcmp(res->what, "uta") == 0) &&
8760                 (strcmp(res->value, "all") == 0))
8761                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8762         if (ret < 0)
8763                 printf("bad unicast hash table parameter,"
8764                         "return code = %d \n", ret);
8765 }
8766
8767 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8768         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8769                                  set, "set");
8770 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8771         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8772                                  port, "port");
8773 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8774         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8775                               port_id, RTE_UINT16);
8776 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8777         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8778                                  what, "uta");
8779 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8780         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8781                                 value,"all");
8782 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8783         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8784                                  mode, "on#off");
8785
8786 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8787         .f = cmd_set_uc_all_hash_parsed,
8788         .data = NULL,
8789         .help_str = "set port <port_id> uta all on|off",
8790         .tokens = {
8791                 (void *)&cmd_set_uc_all_hash_set,
8792                 (void *)&cmd_set_uc_all_hash_port,
8793                 (void *)&cmd_set_uc_all_hash_portid,
8794                 (void *)&cmd_set_uc_all_hash_what,
8795                 (void *)&cmd_set_uc_all_hash_value,
8796                 (void *)&cmd_set_uc_all_hash_mode,
8797                 NULL,
8798         },
8799 };
8800
8801 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8802 struct cmd_set_vf_traffic {
8803         cmdline_fixed_string_t set;
8804         cmdline_fixed_string_t port;
8805         portid_t port_id;
8806         cmdline_fixed_string_t vf;
8807         uint8_t vf_id;
8808         cmdline_fixed_string_t what;
8809         cmdline_fixed_string_t mode;
8810 };
8811
8812 static void
8813 cmd_set_vf_traffic_parsed(void *parsed_result,
8814                        __rte_unused struct cmdline *cl,
8815                        __rte_unused void *data)
8816 {
8817         struct cmd_set_vf_traffic *res = parsed_result;
8818         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8819         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8820
8821         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8822 }
8823
8824 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8825         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8826                                  set, "set");
8827 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8828         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8829                                  port, "port");
8830 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8831         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8832                               port_id, RTE_UINT16);
8833 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8834         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8835                                  vf, "vf");
8836 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8837         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8838                               vf_id, RTE_UINT8);
8839 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8840         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8841                                  what, "tx#rx");
8842 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8843         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8844                                  mode, "on#off");
8845
8846 cmdline_parse_inst_t cmd_set_vf_traffic = {
8847         .f = cmd_set_vf_traffic_parsed,
8848         .data = NULL,
8849         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8850         .tokens = {
8851                 (void *)&cmd_setvf_traffic_set,
8852                 (void *)&cmd_setvf_traffic_port,
8853                 (void *)&cmd_setvf_traffic_portid,
8854                 (void *)&cmd_setvf_traffic_vf,
8855                 (void *)&cmd_setvf_traffic_vfid,
8856                 (void *)&cmd_setvf_traffic_what,
8857                 (void *)&cmd_setvf_traffic_mode,
8858                 NULL,
8859         },
8860 };
8861
8862 /* *** CONFIGURE VF RECEIVE MODE *** */
8863 struct cmd_set_vf_rxmode {
8864         cmdline_fixed_string_t set;
8865         cmdline_fixed_string_t port;
8866         portid_t port_id;
8867         cmdline_fixed_string_t vf;
8868         uint8_t vf_id;
8869         cmdline_fixed_string_t what;
8870         cmdline_fixed_string_t mode;
8871         cmdline_fixed_string_t on;
8872 };
8873
8874 static void
8875 cmd_set_vf_rxmode_parsed(void *parsed_result,
8876                        __rte_unused struct cmdline *cl,
8877                        __rte_unused void *data)
8878 {
8879         int ret = -ENOTSUP;
8880         uint16_t vf_rxmode = 0;
8881         struct cmd_set_vf_rxmode *res = parsed_result;
8882
8883         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8884         if (!strcmp(res->what,"rxmode")) {
8885                 if (!strcmp(res->mode, "AUPE"))
8886                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8887                 else if (!strcmp(res->mode, "ROPE"))
8888                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8889                 else if (!strcmp(res->mode, "BAM"))
8890                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8891                 else if (!strncmp(res->mode, "MPE",3))
8892                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8893         }
8894
8895         RTE_SET_USED(is_on);
8896
8897 #ifdef RTE_NET_IXGBE
8898         if (ret == -ENOTSUP)
8899                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8900                                                   vf_rxmode, (uint8_t)is_on);
8901 #endif
8902 #ifdef RTE_NET_BNXT
8903         if (ret == -ENOTSUP)
8904                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8905                                                  vf_rxmode, (uint8_t)is_on);
8906 #endif
8907         if (ret < 0)
8908                 printf("bad VF receive mode parameter, return code = %d \n",
8909                 ret);
8910 }
8911
8912 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8913         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8914                                  set, "set");
8915 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8916         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8917                                  port, "port");
8918 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8919         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8920                               port_id, RTE_UINT16);
8921 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8922         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8923                                  vf, "vf");
8924 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8925         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8926                               vf_id, RTE_UINT8);
8927 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8928         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8929                                  what, "rxmode");
8930 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8931         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8932                                  mode, "AUPE#ROPE#BAM#MPE");
8933 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8934         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8935                                  on, "on#off");
8936
8937 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8938         .f = cmd_set_vf_rxmode_parsed,
8939         .data = NULL,
8940         .help_str = "set port <port_id> vf <vf_id> rxmode "
8941                 "AUPE|ROPE|BAM|MPE on|off",
8942         .tokens = {
8943                 (void *)&cmd_set_vf_rxmode_set,
8944                 (void *)&cmd_set_vf_rxmode_port,
8945                 (void *)&cmd_set_vf_rxmode_portid,
8946                 (void *)&cmd_set_vf_rxmode_vf,
8947                 (void *)&cmd_set_vf_rxmode_vfid,
8948                 (void *)&cmd_set_vf_rxmode_what,
8949                 (void *)&cmd_set_vf_rxmode_mode,
8950                 (void *)&cmd_set_vf_rxmode_on,
8951                 NULL,
8952         },
8953 };
8954
8955 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8956 struct cmd_vf_mac_addr_result {
8957         cmdline_fixed_string_t mac_addr_cmd;
8958         cmdline_fixed_string_t what;
8959         cmdline_fixed_string_t port;
8960         uint16_t port_num;
8961         cmdline_fixed_string_t vf;
8962         uint8_t vf_num;
8963         struct rte_ether_addr address;
8964 };
8965
8966 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8967                 __rte_unused struct cmdline *cl,
8968                 __rte_unused void *data)
8969 {
8970         struct cmd_vf_mac_addr_result *res = parsed_result;
8971         int ret = -ENOTSUP;
8972
8973         if (strcmp(res->what, "add") != 0)
8974                 return;
8975
8976 #ifdef RTE_NET_I40E
8977         if (ret == -ENOTSUP)
8978                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8979                                                    &res->address);
8980 #endif
8981 #ifdef RTE_NET_BNXT
8982         if (ret == -ENOTSUP)
8983                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8984                                                 res->vf_num);
8985 #endif
8986
8987         if(ret < 0)
8988                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8989
8990 }
8991
8992 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8993         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8994                                 mac_addr_cmd,"mac_addr");
8995 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8996         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8997                                 what,"add");
8998 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8999         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9000                                 port,"port");
9001 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9002         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9003                                 port_num, RTE_UINT16);
9004 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9005         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9006                                 vf,"vf");
9007 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9008         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9009                                 vf_num, RTE_UINT8);
9010 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9011         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9012                                 address);
9013
9014 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9015         .f = cmd_vf_mac_addr_parsed,
9016         .data = (void *)0,
9017         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9018                 "Add MAC address filtering for a VF on port_id",
9019         .tokens = {
9020                 (void *)&cmd_vf_mac_addr_cmd,
9021                 (void *)&cmd_vf_mac_addr_what,
9022                 (void *)&cmd_vf_mac_addr_port,
9023                 (void *)&cmd_vf_mac_addr_portnum,
9024                 (void *)&cmd_vf_mac_addr_vf,
9025                 (void *)&cmd_vf_mac_addr_vfnum,
9026                 (void *)&cmd_vf_mac_addr_addr,
9027                 NULL,
9028         },
9029 };
9030
9031 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9032 struct cmd_vf_rx_vlan_filter {
9033         cmdline_fixed_string_t rx_vlan;
9034         cmdline_fixed_string_t what;
9035         uint16_t vlan_id;
9036         cmdline_fixed_string_t port;
9037         portid_t port_id;
9038         cmdline_fixed_string_t vf;
9039         uint64_t vf_mask;
9040 };
9041
9042 static void
9043 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9044                           __rte_unused struct cmdline *cl,
9045                           __rte_unused void *data)
9046 {
9047         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9048         int ret = -ENOTSUP;
9049
9050         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9051
9052 #ifdef RTE_NET_IXGBE
9053         if (ret == -ENOTSUP)
9054                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9055                                 res->vlan_id, res->vf_mask, is_add);
9056 #endif
9057 #ifdef RTE_NET_I40E
9058         if (ret == -ENOTSUP)
9059                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9060                                 res->vlan_id, res->vf_mask, is_add);
9061 #endif
9062 #ifdef RTE_NET_BNXT
9063         if (ret == -ENOTSUP)
9064                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9065                                 res->vlan_id, res->vf_mask, is_add);
9066 #endif
9067
9068         switch (ret) {
9069         case 0:
9070                 break;
9071         case -EINVAL:
9072                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9073                                 res->vlan_id, res->vf_mask);
9074                 break;
9075         case -ENODEV:
9076                 printf("invalid port_id %d\n", res->port_id);
9077                 break;
9078         case -ENOTSUP:
9079                 printf("function not implemented or supported\n");
9080                 break;
9081         default:
9082                 printf("programming error: (%s)\n", strerror(-ret));
9083         }
9084 }
9085
9086 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9087         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9088                                  rx_vlan, "rx_vlan");
9089 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9090         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9091                                  what, "add#rm");
9092 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9093         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9094                               vlan_id, RTE_UINT16);
9095 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9096         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9097                                  port, "port");
9098 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9099         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9100                               port_id, RTE_UINT16);
9101 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9102         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9103                                  vf, "vf");
9104 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9105         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9106                               vf_mask, RTE_UINT64);
9107
9108 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9109         .f = cmd_vf_rx_vlan_filter_parsed,
9110         .data = NULL,
9111         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9112                 "(vf_mask = hexadecimal VF mask)",
9113         .tokens = {
9114                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9115                 (void *)&cmd_vf_rx_vlan_filter_what,
9116                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9117                 (void *)&cmd_vf_rx_vlan_filter_port,
9118                 (void *)&cmd_vf_rx_vlan_filter_portid,
9119                 (void *)&cmd_vf_rx_vlan_filter_vf,
9120                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9121                 NULL,
9122         },
9123 };
9124
9125 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9126 struct cmd_queue_rate_limit_result {
9127         cmdline_fixed_string_t set;
9128         cmdline_fixed_string_t port;
9129         uint16_t port_num;
9130         cmdline_fixed_string_t queue;
9131         uint8_t queue_num;
9132         cmdline_fixed_string_t rate;
9133         uint16_t rate_num;
9134 };
9135
9136 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9137                 __rte_unused struct cmdline *cl,
9138                 __rte_unused void *data)
9139 {
9140         struct cmd_queue_rate_limit_result *res = parsed_result;
9141         int ret = 0;
9142
9143         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9144                 && (strcmp(res->queue, "queue") == 0)
9145                 && (strcmp(res->rate, "rate") == 0))
9146                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9147                                         res->rate_num);
9148         if (ret < 0)
9149                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9150
9151 }
9152
9153 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9154         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9155                                 set, "set");
9156 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9157         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9158                                 port, "port");
9159 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9160         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9161                                 port_num, RTE_UINT16);
9162 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9163         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9164                                 queue, "queue");
9165 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9166         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9167                                 queue_num, RTE_UINT8);
9168 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9169         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9170                                 rate, "rate");
9171 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9172         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9173                                 rate_num, RTE_UINT16);
9174
9175 cmdline_parse_inst_t cmd_queue_rate_limit = {
9176         .f = cmd_queue_rate_limit_parsed,
9177         .data = (void *)0,
9178         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9179                 "Set rate limit for a queue on port_id",
9180         .tokens = {
9181                 (void *)&cmd_queue_rate_limit_set,
9182                 (void *)&cmd_queue_rate_limit_port,
9183                 (void *)&cmd_queue_rate_limit_portnum,
9184                 (void *)&cmd_queue_rate_limit_queue,
9185                 (void *)&cmd_queue_rate_limit_queuenum,
9186                 (void *)&cmd_queue_rate_limit_rate,
9187                 (void *)&cmd_queue_rate_limit_ratenum,
9188                 NULL,
9189         },
9190 };
9191
9192 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9193 struct cmd_vf_rate_limit_result {
9194         cmdline_fixed_string_t set;
9195         cmdline_fixed_string_t port;
9196         uint16_t port_num;
9197         cmdline_fixed_string_t vf;
9198         uint8_t vf_num;
9199         cmdline_fixed_string_t rate;
9200         uint16_t rate_num;
9201         cmdline_fixed_string_t q_msk;
9202         uint64_t q_msk_val;
9203 };
9204
9205 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9206                 __rte_unused struct cmdline *cl,
9207                 __rte_unused void *data)
9208 {
9209         struct cmd_vf_rate_limit_result *res = parsed_result;
9210         int ret = 0;
9211
9212         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9213                 && (strcmp(res->vf, "vf") == 0)
9214                 && (strcmp(res->rate, "rate") == 0)
9215                 && (strcmp(res->q_msk, "queue_mask") == 0))
9216                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9217                                         res->rate_num, res->q_msk_val);
9218         if (ret < 0)
9219                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9220
9221 }
9222
9223 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9224         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9225                                 set, "set");
9226 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9227         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9228                                 port, "port");
9229 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9230         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9231                                 port_num, RTE_UINT16);
9232 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9233         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9234                                 vf, "vf");
9235 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9236         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9237                                 vf_num, RTE_UINT8);
9238 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9239         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9240                                 rate, "rate");
9241 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9242         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9243                                 rate_num, RTE_UINT16);
9244 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9245         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9246                                 q_msk, "queue_mask");
9247 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9248         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9249                                 q_msk_val, RTE_UINT64);
9250
9251 cmdline_parse_inst_t cmd_vf_rate_limit = {
9252         .f = cmd_vf_rate_limit_parsed,
9253         .data = (void *)0,
9254         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9255                 "queue_mask <queue_mask_value>: "
9256                 "Set rate limit for queues of VF on port_id",
9257         .tokens = {
9258                 (void *)&cmd_vf_rate_limit_set,
9259                 (void *)&cmd_vf_rate_limit_port,
9260                 (void *)&cmd_vf_rate_limit_portnum,
9261                 (void *)&cmd_vf_rate_limit_vf,
9262                 (void *)&cmd_vf_rate_limit_vfnum,
9263                 (void *)&cmd_vf_rate_limit_rate,
9264                 (void *)&cmd_vf_rate_limit_ratenum,
9265                 (void *)&cmd_vf_rate_limit_q_msk,
9266                 (void *)&cmd_vf_rate_limit_q_msk_val,
9267                 NULL,
9268         },
9269 };
9270
9271 /* *** CONFIGURE TUNNEL UDP PORT *** */
9272 struct cmd_tunnel_udp_config {
9273         cmdline_fixed_string_t rx_vxlan_port;
9274         cmdline_fixed_string_t what;
9275         uint16_t udp_port;
9276         portid_t port_id;
9277 };
9278
9279 static void
9280 cmd_tunnel_udp_config_parsed(void *parsed_result,
9281                           __rte_unused struct cmdline *cl,
9282                           __rte_unused void *data)
9283 {
9284         struct cmd_tunnel_udp_config *res = parsed_result;
9285         struct rte_eth_udp_tunnel tunnel_udp;
9286         int ret;
9287
9288         tunnel_udp.udp_port = res->udp_port;
9289         tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9290
9291         if (!strcmp(res->what, "add"))
9292                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9293                                                       &tunnel_udp);
9294         else
9295                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9296                                                          &tunnel_udp);
9297
9298         if (ret < 0)
9299                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9300 }
9301
9302 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9303         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9304                                 rx_vxlan_port, "rx_vxlan_port");
9305 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9306         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9307                                 what, "add#rm");
9308 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9309         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9310                                 udp_port, RTE_UINT16);
9311 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9312         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9313                                 port_id, RTE_UINT16);
9314
9315 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9316         .f = cmd_tunnel_udp_config_parsed,
9317         .data = (void *)0,
9318         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9319                 "Add/Remove a tunneling UDP port filter",
9320         .tokens = {
9321                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9322                 (void *)&cmd_tunnel_udp_config_what,
9323                 (void *)&cmd_tunnel_udp_config_udp_port,
9324                 (void *)&cmd_tunnel_udp_config_port_id,
9325                 NULL,
9326         },
9327 };
9328
9329 struct cmd_config_tunnel_udp_port {
9330         cmdline_fixed_string_t port;
9331         cmdline_fixed_string_t config;
9332         portid_t port_id;
9333         cmdline_fixed_string_t udp_tunnel_port;
9334         cmdline_fixed_string_t action;
9335         cmdline_fixed_string_t tunnel_type;
9336         uint16_t udp_port;
9337 };
9338
9339 static void
9340 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9341                                __rte_unused struct cmdline *cl,
9342                                __rte_unused void *data)
9343 {
9344         struct cmd_config_tunnel_udp_port *res = parsed_result;
9345         struct rte_eth_udp_tunnel tunnel_udp;
9346         int ret = 0;
9347
9348         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9349                 return;
9350
9351         tunnel_udp.udp_port = res->udp_port;
9352
9353         if (!strcmp(res->tunnel_type, "vxlan")) {
9354                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9355         } else if (!strcmp(res->tunnel_type, "geneve")) {
9356                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9357         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9358                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9359         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9360                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9361         } else {
9362                 printf("Invalid tunnel type\n");
9363                 return;
9364         }
9365
9366         if (!strcmp(res->action, "add"))
9367                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9368                                                       &tunnel_udp);
9369         else
9370                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9371                                                          &tunnel_udp);
9372
9373         if (ret < 0)
9374                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9375 }
9376
9377 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9378         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9379                                  "port");
9380 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9381         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9382                                  "config");
9383 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9384         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9385                               RTE_UINT16);
9386 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9387         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9388                                  udp_tunnel_port,
9389                                  "udp_tunnel_port");
9390 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9391         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9392                                  "add#rm");
9393 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9394         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9395                                  "vxlan#geneve#vxlan-gpe#ecpri");
9396 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9397         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9398                               RTE_UINT16);
9399
9400 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9401         .f = cmd_cfg_tunnel_udp_port_parsed,
9402         .data = NULL,
9403         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9404                 "geneve|vxlan-gpe|ecpri <udp_port>",
9405         .tokens = {
9406                 (void *)&cmd_config_tunnel_udp_port_port,
9407                 (void *)&cmd_config_tunnel_udp_port_config,
9408                 (void *)&cmd_config_tunnel_udp_port_port_id,
9409                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9410                 (void *)&cmd_config_tunnel_udp_port_action,
9411                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9412                 (void *)&cmd_config_tunnel_udp_port_value,
9413                 NULL,
9414         },
9415 };
9416
9417 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9418 struct cmd_set_mirror_mask_result {
9419         cmdline_fixed_string_t set;
9420         cmdline_fixed_string_t port;
9421         portid_t port_id;
9422         cmdline_fixed_string_t mirror;
9423         uint8_t rule_id;
9424         cmdline_fixed_string_t what;
9425         cmdline_fixed_string_t value;
9426         cmdline_fixed_string_t dstpool;
9427         uint8_t dstpool_id;
9428         cmdline_fixed_string_t on;
9429 };
9430
9431 cmdline_parse_token_string_t cmd_mirror_mask_set =
9432         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9433                                 set, "set");
9434 cmdline_parse_token_string_t cmd_mirror_mask_port =
9435         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9436                                 port, "port");
9437 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9438         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9439                                 port_id, RTE_UINT16);
9440 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9441         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9442                                 mirror, "mirror-rule");
9443 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9444         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9445                                 rule_id, RTE_UINT8);
9446 cmdline_parse_token_string_t cmd_mirror_mask_what =
9447         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9448                                 what, "pool-mirror-up#pool-mirror-down"
9449                                       "#vlan-mirror");
9450 cmdline_parse_token_string_t cmd_mirror_mask_value =
9451         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9452                                 value, NULL);
9453 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9454         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9455                                 dstpool, "dst-pool");
9456 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9457         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9458                                 dstpool_id, RTE_UINT8);
9459 cmdline_parse_token_string_t cmd_mirror_mask_on =
9460         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9461                                 on, "on#off");
9462
9463 static void
9464 cmd_set_mirror_mask_parsed(void *parsed_result,
9465                        __rte_unused struct cmdline *cl,
9466                        __rte_unused void *data)
9467 {
9468         int ret,nb_item,i;
9469         struct cmd_set_mirror_mask_result *res = parsed_result;
9470         struct rte_eth_mirror_conf mr_conf;
9471
9472         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9473
9474         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9475
9476         mr_conf.dst_pool = res->dstpool_id;
9477
9478         if (!strcmp(res->what, "pool-mirror-up")) {
9479                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9480                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9481         } else if (!strcmp(res->what, "pool-mirror-down")) {
9482                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9483                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9484         } else if (!strcmp(res->what, "vlan-mirror")) {
9485                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9486                 nb_item = parse_item_list(res->value, "vlan",
9487                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9488                 if (nb_item <= 0)
9489                         return;
9490
9491                 for (i = 0; i < nb_item; i++) {
9492                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9493                                 printf("Invalid vlan_id: must be < 4096\n");
9494                                 return;
9495                         }
9496
9497                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9498                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9499                 }
9500         }
9501
9502         if (!strcmp(res->on, "on"))
9503                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9504                                                 res->rule_id, 1);
9505         else
9506                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9507                                                 res->rule_id, 0);
9508         if (ret < 0)
9509                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9510 }
9511
9512 cmdline_parse_inst_t cmd_set_mirror_mask = {
9513                 .f = cmd_set_mirror_mask_parsed,
9514                 .data = NULL,
9515                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9516                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9517                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9518                 .tokens = {
9519                         (void *)&cmd_mirror_mask_set,
9520                         (void *)&cmd_mirror_mask_port,
9521                         (void *)&cmd_mirror_mask_portid,
9522                         (void *)&cmd_mirror_mask_mirror,
9523                         (void *)&cmd_mirror_mask_ruleid,
9524                         (void *)&cmd_mirror_mask_what,
9525                         (void *)&cmd_mirror_mask_value,
9526                         (void *)&cmd_mirror_mask_dstpool,
9527                         (void *)&cmd_mirror_mask_poolid,
9528                         (void *)&cmd_mirror_mask_on,
9529                         NULL,
9530                 },
9531 };
9532
9533 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9534 struct cmd_set_mirror_link_result {
9535         cmdline_fixed_string_t set;
9536         cmdline_fixed_string_t port;
9537         portid_t port_id;
9538         cmdline_fixed_string_t mirror;
9539         uint8_t rule_id;
9540         cmdline_fixed_string_t what;
9541         cmdline_fixed_string_t dstpool;
9542         uint8_t dstpool_id;
9543         cmdline_fixed_string_t on;
9544 };
9545
9546 cmdline_parse_token_string_t cmd_mirror_link_set =
9547         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9548                                  set, "set");
9549 cmdline_parse_token_string_t cmd_mirror_link_port =
9550         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9551                                 port, "port");
9552 cmdline_parse_token_num_t cmd_mirror_link_portid =
9553         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9554                                 port_id, RTE_UINT16);
9555 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9556         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9557                                 mirror, "mirror-rule");
9558 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9559         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9560                             rule_id, RTE_UINT8);
9561 cmdline_parse_token_string_t cmd_mirror_link_what =
9562         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9563                                 what, "uplink-mirror#downlink-mirror");
9564 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9565         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9566                                 dstpool, "dst-pool");
9567 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9568         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9569                                 dstpool_id, RTE_UINT8);
9570 cmdline_parse_token_string_t cmd_mirror_link_on =
9571         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9572                                 on, "on#off");
9573
9574 static void
9575 cmd_set_mirror_link_parsed(void *parsed_result,
9576                        __rte_unused struct cmdline *cl,
9577                        __rte_unused void *data)
9578 {
9579         int ret;
9580         struct cmd_set_mirror_link_result *res = parsed_result;
9581         struct rte_eth_mirror_conf mr_conf;
9582
9583         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9584         if (!strcmp(res->what, "uplink-mirror"))
9585                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9586         else
9587                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9588
9589         mr_conf.dst_pool = res->dstpool_id;
9590
9591         if (!strcmp(res->on, "on"))
9592                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9593                                                 res->rule_id, 1);
9594         else
9595                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9596                                                 res->rule_id, 0);
9597
9598         /* check the return value and print it if is < 0 */
9599         if (ret < 0)
9600                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9601
9602 }
9603
9604 cmdline_parse_inst_t cmd_set_mirror_link = {
9605                 .f = cmd_set_mirror_link_parsed,
9606                 .data = NULL,
9607                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9608                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9609                 .tokens = {
9610                         (void *)&cmd_mirror_link_set,
9611                         (void *)&cmd_mirror_link_port,
9612                         (void *)&cmd_mirror_link_portid,
9613                         (void *)&cmd_mirror_link_mirror,
9614                         (void *)&cmd_mirror_link_ruleid,
9615                         (void *)&cmd_mirror_link_what,
9616                         (void *)&cmd_mirror_link_dstpool,
9617                         (void *)&cmd_mirror_link_poolid,
9618                         (void *)&cmd_mirror_link_on,
9619                         NULL,
9620                 },
9621 };
9622
9623 /* *** RESET VM MIRROR RULE *** */
9624 struct cmd_rm_mirror_rule_result {
9625         cmdline_fixed_string_t reset;
9626         cmdline_fixed_string_t port;
9627         portid_t port_id;
9628         cmdline_fixed_string_t mirror;
9629         uint8_t rule_id;
9630 };
9631
9632 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9633         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9634                                  reset, "reset");
9635 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9636         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9637                                 port, "port");
9638 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9639         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9640                                 port_id, RTE_UINT16);
9641 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9642         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9643                                 mirror, "mirror-rule");
9644 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9645         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9646                                 rule_id, RTE_UINT8);
9647
9648 static void
9649 cmd_reset_mirror_rule_parsed(void *parsed_result,
9650                        __rte_unused struct cmdline *cl,
9651                        __rte_unused void *data)
9652 {
9653         int ret;
9654         struct cmd_set_mirror_link_result *res = parsed_result;
9655         /* check rule_id */
9656         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9657         if(ret < 0)
9658                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9659 }
9660
9661 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9662                 .f = cmd_reset_mirror_rule_parsed,
9663                 .data = NULL,
9664                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9665                 .tokens = {
9666                         (void *)&cmd_rm_mirror_rule_reset,
9667                         (void *)&cmd_rm_mirror_rule_port,
9668                         (void *)&cmd_rm_mirror_rule_portid,
9669                         (void *)&cmd_rm_mirror_rule_mirror,
9670                         (void *)&cmd_rm_mirror_rule_ruleid,
9671                         NULL,
9672                 },
9673 };
9674
9675 /* ******************************************************************************** */
9676
9677 struct cmd_dump_result {
9678         cmdline_fixed_string_t dump;
9679 };
9680
9681 static void
9682 dump_struct_sizes(void)
9683 {
9684 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9685         DUMP_SIZE(struct rte_mbuf);
9686         DUMP_SIZE(struct rte_mempool);
9687         DUMP_SIZE(struct rte_ring);
9688 #undef DUMP_SIZE
9689 }
9690
9691
9692 /* Dump the socket memory statistics on console */
9693 static void
9694 dump_socket_mem(FILE *f)
9695 {
9696         struct rte_malloc_socket_stats socket_stats;
9697         unsigned int i;
9698         size_t total = 0;
9699         size_t alloc = 0;
9700         size_t free = 0;
9701         unsigned int n_alloc = 0;
9702         unsigned int n_free = 0;
9703         static size_t last_allocs;
9704         static size_t last_total;
9705
9706
9707         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9708                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9709                     !socket_stats.heap_totalsz_bytes)
9710                         continue;
9711                 total += socket_stats.heap_totalsz_bytes;
9712                 alloc += socket_stats.heap_allocsz_bytes;
9713                 free += socket_stats.heap_freesz_bytes;
9714                 n_alloc += socket_stats.alloc_count;
9715                 n_free += socket_stats.free_count;
9716                 fprintf(f,
9717                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9718                         i,
9719                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9720                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9721                         (double)socket_stats.heap_allocsz_bytes * 100 /
9722                         (double)socket_stats.heap_totalsz_bytes,
9723                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9724                         socket_stats.alloc_count,
9725                         socket_stats.free_count);
9726         }
9727         fprintf(f,
9728                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9729                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9730                 (double)alloc * 100 / (double)total,
9731                 (double)free / (1024 * 1024),
9732                 n_alloc, n_free);
9733         if (last_allocs)
9734                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9735                         ((double)total - (double)last_total) / (1024 * 1024),
9736                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9737         last_allocs = alloc;
9738         last_total = total;
9739 }
9740
9741 static void cmd_dump_parsed(void *parsed_result,
9742                             __rte_unused struct cmdline *cl,
9743                             __rte_unused void *data)
9744 {
9745         struct cmd_dump_result *res = parsed_result;
9746
9747         if (!strcmp(res->dump, "dump_physmem"))
9748                 rte_dump_physmem_layout(stdout);
9749         else if (!strcmp(res->dump, "dump_socket_mem"))
9750                 dump_socket_mem(stdout);
9751         else if (!strcmp(res->dump, "dump_memzone"))
9752                 rte_memzone_dump(stdout);
9753         else if (!strcmp(res->dump, "dump_struct_sizes"))
9754                 dump_struct_sizes();
9755         else if (!strcmp(res->dump, "dump_ring"))
9756                 rte_ring_list_dump(stdout);
9757         else if (!strcmp(res->dump, "dump_mempool"))
9758                 rte_mempool_list_dump(stdout);
9759         else if (!strcmp(res->dump, "dump_devargs"))
9760                 rte_devargs_dump(stdout);
9761         else if (!strcmp(res->dump, "dump_log_types"))
9762                 rte_log_dump(stdout);
9763 }
9764
9765 cmdline_parse_token_string_t cmd_dump_dump =
9766         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9767                 "dump_physmem#"
9768                 "dump_memzone#"
9769                 "dump_socket_mem#"
9770                 "dump_struct_sizes#"
9771                 "dump_ring#"
9772                 "dump_mempool#"
9773                 "dump_devargs#"
9774                 "dump_log_types");
9775
9776 cmdline_parse_inst_t cmd_dump = {
9777         .f = cmd_dump_parsed,  /* function to call */
9778         .data = NULL,      /* 2nd arg of func */
9779         .help_str = "Dump status",
9780         .tokens = {        /* token list, NULL terminated */
9781                 (void *)&cmd_dump_dump,
9782                 NULL,
9783         },
9784 };
9785
9786 /* ******************************************************************************** */
9787
9788 struct cmd_dump_one_result {
9789         cmdline_fixed_string_t dump;
9790         cmdline_fixed_string_t name;
9791 };
9792
9793 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9794                                 __rte_unused void *data)
9795 {
9796         struct cmd_dump_one_result *res = parsed_result;
9797
9798         if (!strcmp(res->dump, "dump_ring")) {
9799                 struct rte_ring *r;
9800                 r = rte_ring_lookup(res->name);
9801                 if (r == NULL) {
9802                         cmdline_printf(cl, "Cannot find ring\n");
9803                         return;
9804                 }
9805                 rte_ring_dump(stdout, r);
9806         } else if (!strcmp(res->dump, "dump_mempool")) {
9807                 struct rte_mempool *mp;
9808                 mp = rte_mempool_lookup(res->name);
9809                 if (mp == NULL) {
9810                         cmdline_printf(cl, "Cannot find mempool\n");
9811                         return;
9812                 }
9813                 rte_mempool_dump(stdout, mp);
9814         }
9815 }
9816
9817 cmdline_parse_token_string_t cmd_dump_one_dump =
9818         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9819                                  "dump_ring#dump_mempool");
9820
9821 cmdline_parse_token_string_t cmd_dump_one_name =
9822         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9823
9824 cmdline_parse_inst_t cmd_dump_one = {
9825         .f = cmd_dump_one_parsed,  /* function to call */
9826         .data = NULL,      /* 2nd arg of func */
9827         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9828         .tokens = {        /* token list, NULL terminated */
9829                 (void *)&cmd_dump_one_dump,
9830                 (void *)&cmd_dump_one_name,
9831                 NULL,
9832         },
9833 };
9834
9835 /* *** queue region set *** */
9836 struct cmd_queue_region_result {
9837         cmdline_fixed_string_t set;
9838         cmdline_fixed_string_t port;
9839         portid_t port_id;
9840         cmdline_fixed_string_t cmd;
9841         cmdline_fixed_string_t region;
9842         uint8_t  region_id;
9843         cmdline_fixed_string_t queue_start_index;
9844         uint8_t  queue_id;
9845         cmdline_fixed_string_t queue_num;
9846         uint8_t  queue_num_value;
9847 };
9848
9849 static void
9850 cmd_queue_region_parsed(void *parsed_result,
9851                         __rte_unused struct cmdline *cl,
9852                         __rte_unused void *data)
9853 {
9854         struct cmd_queue_region_result *res = parsed_result;
9855         int ret = -ENOTSUP;
9856 #ifdef RTE_NET_I40E
9857         struct rte_pmd_i40e_queue_region_conf region_conf;
9858         enum rte_pmd_i40e_queue_region_op op_type;
9859 #endif
9860
9861         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9862                 return;
9863
9864 #ifdef RTE_NET_I40E
9865         memset(&region_conf, 0, sizeof(region_conf));
9866         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9867         region_conf.region_id = res->region_id;
9868         region_conf.queue_num = res->queue_num_value;
9869         region_conf.queue_start_index = res->queue_id;
9870
9871         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9872                                 op_type, &region_conf);
9873 #endif
9874
9875         switch (ret) {
9876         case 0:
9877                 break;
9878         case -ENOTSUP:
9879                 printf("function not implemented or supported\n");
9880                 break;
9881         default:
9882                 printf("queue region config error: (%s)\n", strerror(-ret));
9883         }
9884 }
9885
9886 cmdline_parse_token_string_t cmd_queue_region_set =
9887 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9888                 set, "set");
9889 cmdline_parse_token_string_t cmd_queue_region_port =
9890         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9891 cmdline_parse_token_num_t cmd_queue_region_port_id =
9892         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9893                                 port_id, RTE_UINT16);
9894 cmdline_parse_token_string_t cmd_queue_region_cmd =
9895         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9896                                  cmd, "queue-region");
9897 cmdline_parse_token_string_t cmd_queue_region_id =
9898         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9899                                 region, "region_id");
9900 cmdline_parse_token_num_t cmd_queue_region_index =
9901         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9902                                 region_id, RTE_UINT8);
9903 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9904         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9905                                 queue_start_index, "queue_start_index");
9906 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9907         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9908                                 queue_id, RTE_UINT8);
9909 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9910         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9911                                 queue_num, "queue_num");
9912 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9913         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9914                                 queue_num_value, RTE_UINT8);
9915
9916 cmdline_parse_inst_t cmd_queue_region = {
9917         .f = cmd_queue_region_parsed,
9918         .data = NULL,
9919         .help_str = "set port <port_id> queue-region region_id <value> "
9920                 "queue_start_index <value> queue_num <value>: Set a queue region",
9921         .tokens = {
9922                 (void *)&cmd_queue_region_set,
9923                 (void *)&cmd_queue_region_port,
9924                 (void *)&cmd_queue_region_port_id,
9925                 (void *)&cmd_queue_region_cmd,
9926                 (void *)&cmd_queue_region_id,
9927                 (void *)&cmd_queue_region_index,
9928                 (void *)&cmd_queue_region_queue_start_index,
9929                 (void *)&cmd_queue_region_queue_id,
9930                 (void *)&cmd_queue_region_queue_num,
9931                 (void *)&cmd_queue_region_queue_num_value,
9932                 NULL,
9933         },
9934 };
9935
9936 /* *** queue region and flowtype set *** */
9937 struct cmd_region_flowtype_result {
9938         cmdline_fixed_string_t set;
9939         cmdline_fixed_string_t port;
9940         portid_t port_id;
9941         cmdline_fixed_string_t cmd;
9942         cmdline_fixed_string_t region;
9943         uint8_t  region_id;
9944         cmdline_fixed_string_t flowtype;
9945         uint8_t  flowtype_id;
9946 };
9947
9948 static void
9949 cmd_region_flowtype_parsed(void *parsed_result,
9950                         __rte_unused struct cmdline *cl,
9951                         __rte_unused void *data)
9952 {
9953         struct cmd_region_flowtype_result *res = parsed_result;
9954         int ret = -ENOTSUP;
9955 #ifdef RTE_NET_I40E
9956         struct rte_pmd_i40e_queue_region_conf region_conf;
9957         enum rte_pmd_i40e_queue_region_op op_type;
9958 #endif
9959
9960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9961                 return;
9962
9963 #ifdef RTE_NET_I40E
9964         memset(&region_conf, 0, sizeof(region_conf));
9965
9966         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9967         region_conf.region_id = res->region_id;
9968         region_conf.hw_flowtype = res->flowtype_id;
9969
9970         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9971                         op_type, &region_conf);
9972 #endif
9973
9974         switch (ret) {
9975         case 0:
9976                 break;
9977         case -ENOTSUP:
9978                 printf("function not implemented or supported\n");
9979                 break;
9980         default:
9981                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9982         }
9983 }
9984
9985 cmdline_parse_token_string_t cmd_region_flowtype_set =
9986 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9987                                 set, "set");
9988 cmdline_parse_token_string_t cmd_region_flowtype_port =
9989         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9990                                 port, "port");
9991 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9992         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9993                                 port_id, RTE_UINT16);
9994 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9995         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9996                                 cmd, "queue-region");
9997 cmdline_parse_token_string_t cmd_region_flowtype_index =
9998         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9999                                 region, "region_id");
10000 cmdline_parse_token_num_t cmd_region_flowtype_id =
10001         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10002                                 region_id, RTE_UINT8);
10003 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10004         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10005                                 flowtype, "flowtype");
10006 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10007         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10008                                 flowtype_id, RTE_UINT8);
10009 cmdline_parse_inst_t cmd_region_flowtype = {
10010         .f = cmd_region_flowtype_parsed,
10011         .data = NULL,
10012         .help_str = "set port <port_id> queue-region region_id <value> "
10013                 "flowtype <value>: Set a flowtype region index",
10014         .tokens = {
10015                 (void *)&cmd_region_flowtype_set,
10016                 (void *)&cmd_region_flowtype_port,
10017                 (void *)&cmd_region_flowtype_port_index,
10018                 (void *)&cmd_region_flowtype_cmd,
10019                 (void *)&cmd_region_flowtype_index,
10020                 (void *)&cmd_region_flowtype_id,
10021                 (void *)&cmd_region_flowtype_flow_index,
10022                 (void *)&cmd_region_flowtype_flow_id,
10023                 NULL,
10024         },
10025 };
10026
10027 /* *** User Priority (UP) to queue region (region_id) set *** */
10028 struct cmd_user_priority_region_result {
10029         cmdline_fixed_string_t set;
10030         cmdline_fixed_string_t port;
10031         portid_t port_id;
10032         cmdline_fixed_string_t cmd;
10033         cmdline_fixed_string_t user_priority;
10034         uint8_t  user_priority_id;
10035         cmdline_fixed_string_t region;
10036         uint8_t  region_id;
10037 };
10038
10039 static void
10040 cmd_user_priority_region_parsed(void *parsed_result,
10041                         __rte_unused struct cmdline *cl,
10042                         __rte_unused void *data)
10043 {
10044         struct cmd_user_priority_region_result *res = parsed_result;
10045         int ret = -ENOTSUP;
10046 #ifdef RTE_NET_I40E
10047         struct rte_pmd_i40e_queue_region_conf region_conf;
10048         enum rte_pmd_i40e_queue_region_op op_type;
10049 #endif
10050
10051         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10052                 return;
10053
10054 #ifdef RTE_NET_I40E
10055         memset(&region_conf, 0, sizeof(region_conf));
10056         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10057         region_conf.user_priority = res->user_priority_id;
10058         region_conf.region_id = res->region_id;
10059
10060         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10061                                 op_type, &region_conf);
10062 #endif
10063
10064         switch (ret) {
10065         case 0:
10066                 break;
10067         case -ENOTSUP:
10068                 printf("function not implemented or supported\n");
10069                 break;
10070         default:
10071                 printf("user_priority region config error: (%s)\n",
10072                                 strerror(-ret));
10073         }
10074 }
10075
10076 cmdline_parse_token_string_t cmd_user_priority_region_set =
10077         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10078                                 set, "set");
10079 cmdline_parse_token_string_t cmd_user_priority_region_port =
10080         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10081                                 port, "port");
10082 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10083         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10084                                 port_id, RTE_UINT16);
10085 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10086         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10087                                 cmd, "queue-region");
10088 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10089         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10090                                 user_priority, "UP");
10091 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10092         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10093                                 user_priority_id, RTE_UINT8);
10094 cmdline_parse_token_string_t cmd_user_priority_region_region =
10095         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10096                                 region, "region_id");
10097 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10098         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10099                                 region_id, RTE_UINT8);
10100
10101 cmdline_parse_inst_t cmd_user_priority_region = {
10102         .f = cmd_user_priority_region_parsed,
10103         .data = NULL,
10104         .help_str = "set port <port_id> queue-region UP <value> "
10105                 "region_id <value>: Set the mapping of User Priority (UP) "
10106                 "to queue region (region_id) ",
10107         .tokens = {
10108                 (void *)&cmd_user_priority_region_set,
10109                 (void *)&cmd_user_priority_region_port,
10110                 (void *)&cmd_user_priority_region_port_index,
10111                 (void *)&cmd_user_priority_region_cmd,
10112                 (void *)&cmd_user_priority_region_UP,
10113                 (void *)&cmd_user_priority_region_UP_id,
10114                 (void *)&cmd_user_priority_region_region,
10115                 (void *)&cmd_user_priority_region_region_id,
10116                 NULL,
10117         },
10118 };
10119
10120 /* *** flush all queue region related configuration *** */
10121 struct cmd_flush_queue_region_result {
10122         cmdline_fixed_string_t set;
10123         cmdline_fixed_string_t port;
10124         portid_t port_id;
10125         cmdline_fixed_string_t cmd;
10126         cmdline_fixed_string_t flush;
10127         cmdline_fixed_string_t what;
10128 };
10129
10130 static void
10131 cmd_flush_queue_region_parsed(void *parsed_result,
10132                         __rte_unused struct cmdline *cl,
10133                         __rte_unused void *data)
10134 {
10135         struct cmd_flush_queue_region_result *res = parsed_result;
10136         int ret = -ENOTSUP;
10137 #ifdef RTE_NET_I40E
10138         struct rte_pmd_i40e_queue_region_conf region_conf;
10139         enum rte_pmd_i40e_queue_region_op op_type;
10140 #endif
10141
10142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10143                 return;
10144
10145 #ifdef RTE_NET_I40E
10146         memset(&region_conf, 0, sizeof(region_conf));
10147
10148         if (strcmp(res->what, "on") == 0)
10149                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10150         else
10151                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10152
10153         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10154                                 op_type, &region_conf);
10155 #endif
10156
10157         switch (ret) {
10158         case 0:
10159                 break;
10160         case -ENOTSUP:
10161                 printf("function not implemented or supported\n");
10162                 break;
10163         default:
10164                 printf("queue region config flush error: (%s)\n",
10165                                 strerror(-ret));
10166         }
10167 }
10168
10169 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10170         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10171                                 set, "set");
10172 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10173         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10174                                 port, "port");
10175 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10176         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10177                                 port_id, RTE_UINT16);
10178 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10179         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10180                                 cmd, "queue-region");
10181 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10182         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10183                                 flush, "flush");
10184 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10185         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10186                                 what, "on#off");
10187
10188 cmdline_parse_inst_t cmd_flush_queue_region = {
10189         .f = cmd_flush_queue_region_parsed,
10190         .data = NULL,
10191         .help_str = "set port <port_id> queue-region flush on|off"
10192                 ": flush all queue region related configuration",
10193         .tokens = {
10194                 (void *)&cmd_flush_queue_region_set,
10195                 (void *)&cmd_flush_queue_region_port,
10196                 (void *)&cmd_flush_queue_region_port_index,
10197                 (void *)&cmd_flush_queue_region_cmd,
10198                 (void *)&cmd_flush_queue_region_flush,
10199                 (void *)&cmd_flush_queue_region_what,
10200                 NULL,
10201         },
10202 };
10203
10204 /* *** get all queue region related configuration info *** */
10205 struct cmd_show_queue_region_info {
10206         cmdline_fixed_string_t show;
10207         cmdline_fixed_string_t port;
10208         portid_t port_id;
10209         cmdline_fixed_string_t cmd;
10210 };
10211
10212 static void
10213 cmd_show_queue_region_info_parsed(void *parsed_result,
10214                         __rte_unused struct cmdline *cl,
10215                         __rte_unused void *data)
10216 {
10217         struct cmd_show_queue_region_info *res = parsed_result;
10218         int ret = -ENOTSUP;
10219 #ifdef RTE_NET_I40E
10220         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10221         enum rte_pmd_i40e_queue_region_op op_type;
10222 #endif
10223
10224         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10225                 return;
10226
10227 #ifdef RTE_NET_I40E
10228         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10229
10230         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10231
10232         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10233                                         op_type, &rte_pmd_regions);
10234
10235         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10236 #endif
10237
10238         switch (ret) {
10239         case 0:
10240                 break;
10241         case -ENOTSUP:
10242                 printf("function not implemented or supported\n");
10243                 break;
10244         default:
10245                 printf("queue region config info show error: (%s)\n",
10246                                 strerror(-ret));
10247         }
10248 }
10249
10250 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10251 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10252                                 show, "show");
10253 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10254         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10255                                 port, "port");
10256 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10257         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10258                                 port_id, RTE_UINT16);
10259 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10260         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10261                                 cmd, "queue-region");
10262
10263 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10264         .f = cmd_show_queue_region_info_parsed,
10265         .data = NULL,
10266         .help_str = "show port <port_id> queue-region"
10267                 ": show all queue region related configuration info",
10268         .tokens = {
10269                 (void *)&cmd_show_queue_region_info_get,
10270                 (void *)&cmd_show_queue_region_info_port,
10271                 (void *)&cmd_show_queue_region_info_port_index,
10272                 (void *)&cmd_show_queue_region_info_cmd,
10273                 NULL,
10274         },
10275 };
10276
10277 /* *** Filters Control *** */
10278
10279 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10280 do { \
10281         if ((ip_addr).family == AF_INET) \
10282                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10283         else { \
10284                 printf("invalid parameter.\n"); \
10285                 return; \
10286         } \
10287 } while (0)
10288
10289 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10290 do { \
10291         if ((ip_addr).family == AF_INET6) \
10292                 rte_memcpy(&(ip), \
10293                                  &((ip_addr).addr.ipv6), \
10294                                  sizeof(struct in6_addr)); \
10295         else { \
10296                 printf("invalid parameter.\n"); \
10297                 return; \
10298         } \
10299 } while (0)
10300
10301 #ifdef RTE_NET_I40E
10302
10303 static uint16_t
10304 str2flowtype(char *string)
10305 {
10306         uint8_t i = 0;
10307         static const struct {
10308                 char str[32];
10309                 uint16_t type;
10310         } flowtype_str[] = {
10311                 {"raw", RTE_ETH_FLOW_RAW},
10312                 {"ipv4", RTE_ETH_FLOW_IPV4},
10313                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10314                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10315                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10316                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10317                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10318                 {"ipv6", RTE_ETH_FLOW_IPV6},
10319                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10320                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10321                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10322                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10323                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10324                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10325         };
10326
10327         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10328                 if (!strcmp(flowtype_str[i].str, string))
10329                         return flowtype_str[i].type;
10330         }
10331
10332         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10333                 return (uint16_t)atoi(string);
10334
10335         return RTE_ETH_FLOW_UNKNOWN;
10336 }
10337
10338 /* *** deal with flow director filter *** */
10339 struct cmd_flow_director_result {
10340         cmdline_fixed_string_t flow_director_filter;
10341         portid_t port_id;
10342         cmdline_fixed_string_t mode;
10343         cmdline_fixed_string_t mode_value;
10344         cmdline_fixed_string_t ops;
10345         cmdline_fixed_string_t flow;
10346         cmdline_fixed_string_t flow_type;
10347         cmdline_fixed_string_t drop;
10348         cmdline_fixed_string_t queue;
10349         uint16_t  queue_id;
10350         cmdline_fixed_string_t fd_id;
10351         uint32_t  fd_id_value;
10352         cmdline_fixed_string_t packet;
10353         char filepath[];
10354 };
10355
10356 static void
10357 cmd_flow_director_filter_parsed(void *parsed_result,
10358                           __rte_unused struct cmdline *cl,
10359                           __rte_unused void *data)
10360 {
10361         struct cmd_flow_director_result *res = parsed_result;
10362         int ret = 0;
10363         struct rte_pmd_i40e_flow_type_mapping
10364                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10365         struct rte_pmd_i40e_pkt_template_conf conf;
10366         uint16_t flow_type = str2flowtype(res->flow_type);
10367         uint16_t i, port = res->port_id;
10368         uint8_t add;
10369
10370         memset(&conf, 0, sizeof(conf));
10371
10372         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10373                 printf("Invalid flow type specified.\n");
10374                 return;
10375         }
10376         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10377                                                  mapping);
10378         if (ret)
10379                 return;
10380         if (mapping[flow_type].pctype == 0ULL) {
10381                 printf("Invalid flow type specified.\n");
10382                 return;
10383         }
10384         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10385                 if (mapping[flow_type].pctype & (1ULL << i)) {
10386                         conf.input.pctype = i;
10387                         break;
10388                 }
10389         }
10390
10391         conf.input.packet = open_file(res->filepath,
10392                                 &conf.input.length);
10393         if (!conf.input.packet)
10394                 return;
10395         if (!strcmp(res->drop, "drop"))
10396                 conf.action.behavior =
10397                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10398         else
10399                 conf.action.behavior =
10400                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10401         conf.action.report_status =
10402                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10403         conf.action.rx_queue = res->queue_id;
10404         conf.soft_id = res->fd_id_value;
10405         add  = strcmp(res->ops, "del") ? 1 : 0;
10406         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10407                                                         &conf,
10408                                                         add);
10409         if (ret < 0)
10410                 printf("flow director config error: (%s)\n",
10411                        strerror(-ret));
10412         close_file(conf.input.packet);
10413 }
10414
10415 cmdline_parse_token_string_t cmd_flow_director_filter =
10416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10417                                  flow_director_filter, "flow_director_filter");
10418 cmdline_parse_token_num_t cmd_flow_director_port_id =
10419         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10420                               port_id, RTE_UINT16);
10421 cmdline_parse_token_string_t cmd_flow_director_ops =
10422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10423                                  ops, "add#del#update");
10424 cmdline_parse_token_string_t cmd_flow_director_flow =
10425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10426                                  flow, "flow");
10427 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10429                 flow_type, NULL);
10430 cmdline_parse_token_string_t cmd_flow_director_drop =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10432                                  drop, "drop#fwd");
10433 cmdline_parse_token_string_t cmd_flow_director_queue =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10435                                  queue, "queue");
10436 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10437         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10438                               queue_id, RTE_UINT16);
10439 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10441                                  fd_id, "fd_id");
10442 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10444                               fd_id_value, RTE_UINT32);
10445
10446 cmdline_parse_token_string_t cmd_flow_director_mode =
10447         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10448                                  mode, "mode");
10449 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10450         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10451                                  mode_value, "raw");
10452 cmdline_parse_token_string_t cmd_flow_director_packet =
10453         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10454                                  packet, "packet");
10455 cmdline_parse_token_string_t cmd_flow_director_filepath =
10456         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10457                                  filepath, NULL);
10458
10459 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10460         .f = cmd_flow_director_filter_parsed,
10461         .data = NULL,
10462         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10463                 "director entry on NIC",
10464         .tokens = {
10465                 (void *)&cmd_flow_director_filter,
10466                 (void *)&cmd_flow_director_port_id,
10467                 (void *)&cmd_flow_director_mode,
10468                 (void *)&cmd_flow_director_mode_raw,
10469                 (void *)&cmd_flow_director_ops,
10470                 (void *)&cmd_flow_director_flow,
10471                 (void *)&cmd_flow_director_flow_type,
10472                 (void *)&cmd_flow_director_drop,
10473                 (void *)&cmd_flow_director_queue,
10474                 (void *)&cmd_flow_director_queue_id,
10475                 (void *)&cmd_flow_director_fd_id,
10476                 (void *)&cmd_flow_director_fd_id_value,
10477                 (void *)&cmd_flow_director_packet,
10478                 (void *)&cmd_flow_director_filepath,
10479                 NULL,
10480         },
10481 };
10482
10483 #endif /* RTE_NET_I40E */
10484
10485 /* *** deal with flow director mask *** */
10486 struct cmd_flow_director_mask_result {
10487         cmdline_fixed_string_t flow_director_mask;
10488         portid_t port_id;
10489         cmdline_fixed_string_t mode;
10490         cmdline_fixed_string_t mode_value;
10491         cmdline_fixed_string_t vlan;
10492         uint16_t vlan_mask;
10493         cmdline_fixed_string_t src_mask;
10494         cmdline_ipaddr_t ipv4_src;
10495         cmdline_ipaddr_t ipv6_src;
10496         uint16_t port_src;
10497         cmdline_fixed_string_t dst_mask;
10498         cmdline_ipaddr_t ipv4_dst;
10499         cmdline_ipaddr_t ipv6_dst;
10500         uint16_t port_dst;
10501         cmdline_fixed_string_t mac;
10502         uint8_t mac_addr_byte_mask;
10503         cmdline_fixed_string_t tunnel_id;
10504         uint32_t tunnel_id_mask;
10505         cmdline_fixed_string_t tunnel_type;
10506         uint8_t tunnel_type_mask;
10507 };
10508
10509 static void
10510 cmd_flow_director_mask_parsed(void *parsed_result,
10511                           __rte_unused struct cmdline *cl,
10512                           __rte_unused void *data)
10513 {
10514         struct cmd_flow_director_mask_result *res = parsed_result;
10515         struct rte_eth_fdir_masks *mask;
10516         struct rte_port *port;
10517
10518         port = &ports[res->port_id];
10519         /** Check if the port is not started **/
10520         if (port->port_status != RTE_PORT_STOPPED) {
10521                 printf("Please stop port %d first\n", res->port_id);
10522                 return;
10523         }
10524
10525         mask = &port->dev_conf.fdir_conf.mask;
10526
10527         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10528                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10529                         printf("Please set mode to MAC-VLAN.\n");
10530                         return;
10531                 }
10532
10533                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10534         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10535                 if (strcmp(res->mode_value, "Tunnel")) {
10536                         printf("Please set mode to Tunnel.\n");
10537                         return;
10538                 }
10539
10540                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10541                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10542                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10543                 mask->tunnel_type_mask = res->tunnel_type_mask;
10544         } else {
10545                 if (strcmp(res->mode_value, "IP")) {
10546                         printf("Please set mode to IP.\n");
10547                         return;
10548                 }
10549
10550                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10551                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10552                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10553                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10554                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10555                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10556                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10557         }
10558
10559         cmd_reconfig_device_queue(res->port_id, 1, 1);
10560 }
10561
10562 cmdline_parse_token_string_t cmd_flow_director_mask =
10563         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10564                                  flow_director_mask, "flow_director_mask");
10565 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10566         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10567                               port_id, RTE_UINT16);
10568 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10570                                  vlan, "vlan");
10571 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10572         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10573                               vlan_mask, RTE_UINT16);
10574 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10575         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10576                                  src_mask, "src_mask");
10577 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10578         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10579                                  ipv4_src);
10580 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10581         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10582                                  ipv6_src);
10583 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10584         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10585                               port_src, RTE_UINT16);
10586 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10587         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10588                                  dst_mask, "dst_mask");
10589 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10590         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10591                                  ipv4_dst);
10592 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10593         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10594                                  ipv6_dst);
10595 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10596         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10597                               port_dst, RTE_UINT16);
10598
10599 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10600         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10601                                  mode, "mode");
10602 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10604                                  mode_value, "IP");
10605 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10607                                  mode_value, "MAC-VLAN");
10608 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10610                                  mode_value, "Tunnel");
10611 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10612         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10613                                  mac, "mac");
10614 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10615         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10616                               mac_addr_byte_mask, RTE_UINT8);
10617 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10618         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10619                                  tunnel_type, "tunnel-type");
10620 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10621         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10622                               tunnel_type_mask, RTE_UINT8);
10623 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10624         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10625                                  tunnel_id, "tunnel-id");
10626 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10627         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10628                               tunnel_id_mask, RTE_UINT32);
10629
10630 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10631         .f = cmd_flow_director_mask_parsed,
10632         .data = NULL,
10633         .help_str = "flow_director_mask ... : "
10634                 "Set IP mode flow director's mask on NIC",
10635         .tokens = {
10636                 (void *)&cmd_flow_director_mask,
10637                 (void *)&cmd_flow_director_mask_port_id,
10638                 (void *)&cmd_flow_director_mask_mode,
10639                 (void *)&cmd_flow_director_mask_mode_ip,
10640                 (void *)&cmd_flow_director_mask_vlan,
10641                 (void *)&cmd_flow_director_mask_vlan_value,
10642                 (void *)&cmd_flow_director_mask_src,
10643                 (void *)&cmd_flow_director_mask_ipv4_src,
10644                 (void *)&cmd_flow_director_mask_ipv6_src,
10645                 (void *)&cmd_flow_director_mask_port_src,
10646                 (void *)&cmd_flow_director_mask_dst,
10647                 (void *)&cmd_flow_director_mask_ipv4_dst,
10648                 (void *)&cmd_flow_director_mask_ipv6_dst,
10649                 (void *)&cmd_flow_director_mask_port_dst,
10650                 NULL,
10651         },
10652 };
10653
10654 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10655         .f = cmd_flow_director_mask_parsed,
10656         .data = NULL,
10657         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10658                 "flow director's mask on NIC",
10659         .tokens = {
10660                 (void *)&cmd_flow_director_mask,
10661                 (void *)&cmd_flow_director_mask_port_id,
10662                 (void *)&cmd_flow_director_mask_mode,
10663                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10664                 (void *)&cmd_flow_director_mask_vlan,
10665                 (void *)&cmd_flow_director_mask_vlan_value,
10666                 NULL,
10667         },
10668 };
10669
10670 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10671         .f = cmd_flow_director_mask_parsed,
10672         .data = NULL,
10673         .help_str = "flow_director_mask ... : Set tunnel mode "
10674                 "flow director's mask on NIC",
10675         .tokens = {
10676                 (void *)&cmd_flow_director_mask,
10677                 (void *)&cmd_flow_director_mask_port_id,
10678                 (void *)&cmd_flow_director_mask_mode,
10679                 (void *)&cmd_flow_director_mask_mode_tunnel,
10680                 (void *)&cmd_flow_director_mask_vlan,
10681                 (void *)&cmd_flow_director_mask_vlan_value,
10682                 (void *)&cmd_flow_director_mask_mac,
10683                 (void *)&cmd_flow_director_mask_mac_value,
10684                 (void *)&cmd_flow_director_mask_tunnel_type,
10685                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10686                 (void *)&cmd_flow_director_mask_tunnel_id,
10687                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10688                 NULL,
10689         },
10690 };
10691
10692 /* *** deal with flow director flexible payload configuration *** */
10693 struct cmd_flow_director_flexpayload_result {
10694         cmdline_fixed_string_t flow_director_flexpayload;
10695         portid_t port_id;
10696         cmdline_fixed_string_t payload_layer;
10697         cmdline_fixed_string_t payload_cfg;
10698 };
10699
10700 static inline int
10701 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10702 {
10703         char s[256];
10704         const char *p, *p0 = q_arg;
10705         char *end;
10706         unsigned long int_fld;
10707         char *str_fld[max_num];
10708         int i;
10709         unsigned size;
10710         int ret = -1;
10711
10712         p = strchr(p0, '(');
10713         if (p == NULL)
10714                 return -1;
10715         ++p;
10716         p0 = strchr(p, ')');
10717         if (p0 == NULL)
10718                 return -1;
10719
10720         size = p0 - p;
10721         if (size >= sizeof(s))
10722                 return -1;
10723
10724         snprintf(s, sizeof(s), "%.*s", size, p);
10725         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10726         if (ret < 0 || ret > max_num)
10727                 return -1;
10728         for (i = 0; i < ret; i++) {
10729                 errno = 0;
10730                 int_fld = strtoul(str_fld[i], &end, 0);
10731                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10732                         return -1;
10733                 offsets[i] = (uint16_t)int_fld;
10734         }
10735         return ret;
10736 }
10737
10738 static void
10739 cmd_flow_director_flxpld_parsed(void *parsed_result,
10740                           __rte_unused struct cmdline *cl,
10741                           __rte_unused void *data)
10742 {
10743         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10744         struct rte_eth_flex_payload_cfg flex_cfg;
10745         struct rte_port *port;
10746         int ret = 0;
10747
10748         port = &ports[res->port_id];
10749         /** Check if the port is not started **/
10750         if (port->port_status != RTE_PORT_STOPPED) {
10751                 printf("Please stop port %d first\n", res->port_id);
10752                 return;
10753         }
10754
10755         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10756
10757         if (!strcmp(res->payload_layer, "raw"))
10758                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10759         else if (!strcmp(res->payload_layer, "l2"))
10760                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10761         else if (!strcmp(res->payload_layer, "l3"))
10762                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10763         else if (!strcmp(res->payload_layer, "l4"))
10764                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10765
10766         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10767                             RTE_ETH_FDIR_MAX_FLEXLEN);
10768         if (ret < 0) {
10769                 printf("error: Cannot parse flex payload input.\n");
10770                 return;
10771         }
10772
10773         fdir_set_flex_payload(res->port_id, &flex_cfg);
10774         cmd_reconfig_device_queue(res->port_id, 1, 1);
10775 }
10776
10777 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10778         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10779                                  flow_director_flexpayload,
10780                                  "flow_director_flex_payload");
10781 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10782         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10783                               port_id, RTE_UINT16);
10784 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10785         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10786                                  payload_layer, "raw#l2#l3#l4");
10787 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10788         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10789                                  payload_cfg, NULL);
10790
10791 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10792         .f = cmd_flow_director_flxpld_parsed,
10793         .data = NULL,
10794         .help_str = "flow_director_flexpayload ... : "
10795                 "Set flow director's flex payload on NIC",
10796         .tokens = {
10797                 (void *)&cmd_flow_director_flexpayload,
10798                 (void *)&cmd_flow_director_flexpayload_port_id,
10799                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10800                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10801                 NULL,
10802         },
10803 };
10804
10805 /* Generic flow interface command. */
10806 extern cmdline_parse_inst_t cmd_flow;
10807
10808 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10809 struct cmd_mcast_addr_result {
10810         cmdline_fixed_string_t mcast_addr_cmd;
10811         cmdline_fixed_string_t what;
10812         uint16_t port_num;
10813         struct rte_ether_addr mc_addr;
10814 };
10815
10816 static void cmd_mcast_addr_parsed(void *parsed_result,
10817                 __rte_unused struct cmdline *cl,
10818                 __rte_unused void *data)
10819 {
10820         struct cmd_mcast_addr_result *res = parsed_result;
10821
10822         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10823                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
10824                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
10825                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
10826                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
10827                 return;
10828         }
10829         if (strcmp(res->what, "add") == 0)
10830                 mcast_addr_add(res->port_num, &res->mc_addr);
10831         else
10832                 mcast_addr_remove(res->port_num, &res->mc_addr);
10833 }
10834
10835 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10836         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10837                                  mcast_addr_cmd, "mcast_addr");
10838 cmdline_parse_token_string_t cmd_mcast_addr_what =
10839         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10840                                  "add#remove");
10841 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10842         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10843                                  RTE_UINT16);
10844 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10845         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10846
10847 cmdline_parse_inst_t cmd_mcast_addr = {
10848         .f = cmd_mcast_addr_parsed,
10849         .data = (void *)0,
10850         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10851                 "Add/Remove multicast MAC address on port_id",
10852         .tokens = {
10853                 (void *)&cmd_mcast_addr_cmd,
10854                 (void *)&cmd_mcast_addr_what,
10855                 (void *)&cmd_mcast_addr_portnum,
10856                 (void *)&cmd_mcast_addr_addr,
10857                 NULL,
10858         },
10859 };
10860
10861 /* vf vlan anti spoof configuration */
10862
10863 /* Common result structure for vf vlan anti spoof */
10864 struct cmd_vf_vlan_anti_spoof_result {
10865         cmdline_fixed_string_t set;
10866         cmdline_fixed_string_t vf;
10867         cmdline_fixed_string_t vlan;
10868         cmdline_fixed_string_t antispoof;
10869         portid_t port_id;
10870         uint32_t vf_id;
10871         cmdline_fixed_string_t on_off;
10872 };
10873
10874 /* Common CLI fields for vf vlan anti spoof enable disable */
10875 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10876         TOKEN_STRING_INITIALIZER
10877                 (struct cmd_vf_vlan_anti_spoof_result,
10878                  set, "set");
10879 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10880         TOKEN_STRING_INITIALIZER
10881                 (struct cmd_vf_vlan_anti_spoof_result,
10882                  vf, "vf");
10883 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10884         TOKEN_STRING_INITIALIZER
10885                 (struct cmd_vf_vlan_anti_spoof_result,
10886                  vlan, "vlan");
10887 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
10888         TOKEN_STRING_INITIALIZER
10889                 (struct cmd_vf_vlan_anti_spoof_result,
10890                  antispoof, "antispoof");
10891 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
10892         TOKEN_NUM_INITIALIZER
10893                 (struct cmd_vf_vlan_anti_spoof_result,
10894                  port_id, RTE_UINT16);
10895 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
10896         TOKEN_NUM_INITIALIZER
10897                 (struct cmd_vf_vlan_anti_spoof_result,
10898                  vf_id, RTE_UINT32);
10899 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
10900         TOKEN_STRING_INITIALIZER
10901                 (struct cmd_vf_vlan_anti_spoof_result,
10902                  on_off, "on#off");
10903
10904 static void
10905 cmd_set_vf_vlan_anti_spoof_parsed(
10906         void *parsed_result,
10907         __rte_unused struct cmdline *cl,
10908         __rte_unused void *data)
10909 {
10910         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
10911         int ret = -ENOTSUP;
10912
10913         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
10914
10915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10916                 return;
10917
10918 #ifdef RTE_NET_IXGBE
10919         if (ret == -ENOTSUP)
10920                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
10921                                 res->vf_id, is_on);
10922 #endif
10923 #ifdef RTE_NET_I40E
10924         if (ret == -ENOTSUP)
10925                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
10926                                 res->vf_id, is_on);
10927 #endif
10928 #ifdef RTE_NET_BNXT
10929         if (ret == -ENOTSUP)
10930                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
10931                                 res->vf_id, is_on);
10932 #endif
10933
10934         switch (ret) {
10935         case 0:
10936                 break;
10937         case -EINVAL:
10938                 printf("invalid vf_id %d\n", res->vf_id);
10939                 break;
10940         case -ENODEV:
10941                 printf("invalid port_id %d\n", res->port_id);
10942                 break;
10943         case -ENOTSUP:
10944                 printf("function not implemented\n");
10945                 break;
10946         default:
10947                 printf("programming error: (%s)\n", strerror(-ret));
10948         }
10949 }
10950
10951 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
10952         .f = cmd_set_vf_vlan_anti_spoof_parsed,
10953         .data = NULL,
10954         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
10955         .tokens = {
10956                 (void *)&cmd_vf_vlan_anti_spoof_set,
10957                 (void *)&cmd_vf_vlan_anti_spoof_vf,
10958                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
10959                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
10960                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
10961                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
10962                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
10963                 NULL,
10964         },
10965 };
10966
10967 /* vf mac anti spoof configuration */
10968
10969 /* Common result structure for vf mac anti spoof */
10970 struct cmd_vf_mac_anti_spoof_result {
10971         cmdline_fixed_string_t set;
10972         cmdline_fixed_string_t vf;
10973         cmdline_fixed_string_t mac;
10974         cmdline_fixed_string_t antispoof;
10975         portid_t port_id;
10976         uint32_t vf_id;
10977         cmdline_fixed_string_t on_off;
10978 };
10979
10980 /* Common CLI fields for vf mac anti spoof enable disable */
10981 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
10982         TOKEN_STRING_INITIALIZER
10983                 (struct cmd_vf_mac_anti_spoof_result,
10984                  set, "set");
10985 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
10986         TOKEN_STRING_INITIALIZER
10987                 (struct cmd_vf_mac_anti_spoof_result,
10988                  vf, "vf");
10989 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
10990         TOKEN_STRING_INITIALIZER
10991                 (struct cmd_vf_mac_anti_spoof_result,
10992                  mac, "mac");
10993 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
10994         TOKEN_STRING_INITIALIZER
10995                 (struct cmd_vf_mac_anti_spoof_result,
10996                  antispoof, "antispoof");
10997 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
10998         TOKEN_NUM_INITIALIZER
10999                 (struct cmd_vf_mac_anti_spoof_result,
11000                  port_id, RTE_UINT16);
11001 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11002         TOKEN_NUM_INITIALIZER
11003                 (struct cmd_vf_mac_anti_spoof_result,
11004                  vf_id, RTE_UINT32);
11005 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11006         TOKEN_STRING_INITIALIZER
11007                 (struct cmd_vf_mac_anti_spoof_result,
11008                  on_off, "on#off");
11009
11010 static void
11011 cmd_set_vf_mac_anti_spoof_parsed(
11012         void *parsed_result,
11013         __rte_unused struct cmdline *cl,
11014         __rte_unused void *data)
11015 {
11016         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11017         int ret = -ENOTSUP;
11018
11019         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11020
11021         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11022                 return;
11023
11024 #ifdef RTE_NET_IXGBE
11025         if (ret == -ENOTSUP)
11026                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11027                         res->vf_id, is_on);
11028 #endif
11029 #ifdef RTE_NET_I40E
11030         if (ret == -ENOTSUP)
11031                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11032                         res->vf_id, is_on);
11033 #endif
11034 #ifdef RTE_NET_BNXT
11035         if (ret == -ENOTSUP)
11036                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11037                         res->vf_id, is_on);
11038 #endif
11039
11040         switch (ret) {
11041         case 0:
11042                 break;
11043         case -EINVAL:
11044                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11045                 break;
11046         case -ENODEV:
11047                 printf("invalid port_id %d\n", res->port_id);
11048                 break;
11049         case -ENOTSUP:
11050                 printf("function not implemented\n");
11051                 break;
11052         default:
11053                 printf("programming error: (%s)\n", strerror(-ret));
11054         }
11055 }
11056
11057 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11058         .f = cmd_set_vf_mac_anti_spoof_parsed,
11059         .data = NULL,
11060         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11061         .tokens = {
11062                 (void *)&cmd_vf_mac_anti_spoof_set,
11063                 (void *)&cmd_vf_mac_anti_spoof_vf,
11064                 (void *)&cmd_vf_mac_anti_spoof_mac,
11065                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11066                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11067                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11068                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11069                 NULL,
11070         },
11071 };
11072
11073 /* vf vlan strip queue configuration */
11074
11075 /* Common result structure for vf mac anti spoof */
11076 struct cmd_vf_vlan_stripq_result {
11077         cmdline_fixed_string_t set;
11078         cmdline_fixed_string_t vf;
11079         cmdline_fixed_string_t vlan;
11080         cmdline_fixed_string_t stripq;
11081         portid_t port_id;
11082         uint16_t vf_id;
11083         cmdline_fixed_string_t on_off;
11084 };
11085
11086 /* Common CLI fields for vf vlan strip enable disable */
11087 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11088         TOKEN_STRING_INITIALIZER
11089                 (struct cmd_vf_vlan_stripq_result,
11090                  set, "set");
11091 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11092         TOKEN_STRING_INITIALIZER
11093                 (struct cmd_vf_vlan_stripq_result,
11094                  vf, "vf");
11095 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11096         TOKEN_STRING_INITIALIZER
11097                 (struct cmd_vf_vlan_stripq_result,
11098                  vlan, "vlan");
11099 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11100         TOKEN_STRING_INITIALIZER
11101                 (struct cmd_vf_vlan_stripq_result,
11102                  stripq, "stripq");
11103 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11104         TOKEN_NUM_INITIALIZER
11105                 (struct cmd_vf_vlan_stripq_result,
11106                  port_id, RTE_UINT16);
11107 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11108         TOKEN_NUM_INITIALIZER
11109                 (struct cmd_vf_vlan_stripq_result,
11110                  vf_id, RTE_UINT16);
11111 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11112         TOKEN_STRING_INITIALIZER
11113                 (struct cmd_vf_vlan_stripq_result,
11114                  on_off, "on#off");
11115
11116 static void
11117 cmd_set_vf_vlan_stripq_parsed(
11118         void *parsed_result,
11119         __rte_unused struct cmdline *cl,
11120         __rte_unused void *data)
11121 {
11122         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11123         int ret = -ENOTSUP;
11124
11125         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11126
11127         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11128                 return;
11129
11130 #ifdef RTE_NET_IXGBE
11131         if (ret == -ENOTSUP)
11132                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11133                         res->vf_id, is_on);
11134 #endif
11135 #ifdef RTE_NET_I40E
11136         if (ret == -ENOTSUP)
11137                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11138                         res->vf_id, is_on);
11139 #endif
11140 #ifdef RTE_NET_BNXT
11141         if (ret == -ENOTSUP)
11142                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11143                         res->vf_id, is_on);
11144 #endif
11145
11146         switch (ret) {
11147         case 0:
11148                 break;
11149         case -EINVAL:
11150                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11151                 break;
11152         case -ENODEV:
11153                 printf("invalid port_id %d\n", res->port_id);
11154                 break;
11155         case -ENOTSUP:
11156                 printf("function not implemented\n");
11157                 break;
11158         default:
11159                 printf("programming error: (%s)\n", strerror(-ret));
11160         }
11161 }
11162
11163 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11164         .f = cmd_set_vf_vlan_stripq_parsed,
11165         .data = NULL,
11166         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11167         .tokens = {
11168                 (void *)&cmd_vf_vlan_stripq_set,
11169                 (void *)&cmd_vf_vlan_stripq_vf,
11170                 (void *)&cmd_vf_vlan_stripq_vlan,
11171                 (void *)&cmd_vf_vlan_stripq_stripq,
11172                 (void *)&cmd_vf_vlan_stripq_port_id,
11173                 (void *)&cmd_vf_vlan_stripq_vf_id,
11174                 (void *)&cmd_vf_vlan_stripq_on_off,
11175                 NULL,
11176         },
11177 };
11178
11179 /* vf vlan insert configuration */
11180
11181 /* Common result structure for vf vlan insert */
11182 struct cmd_vf_vlan_insert_result {
11183         cmdline_fixed_string_t set;
11184         cmdline_fixed_string_t vf;
11185         cmdline_fixed_string_t vlan;
11186         cmdline_fixed_string_t insert;
11187         portid_t port_id;
11188         uint16_t vf_id;
11189         uint16_t vlan_id;
11190 };
11191
11192 /* Common CLI fields for vf vlan insert enable disable */
11193 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11194         TOKEN_STRING_INITIALIZER
11195                 (struct cmd_vf_vlan_insert_result,
11196                  set, "set");
11197 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11198         TOKEN_STRING_INITIALIZER
11199                 (struct cmd_vf_vlan_insert_result,
11200                  vf, "vf");
11201 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11202         TOKEN_STRING_INITIALIZER
11203                 (struct cmd_vf_vlan_insert_result,
11204                  vlan, "vlan");
11205 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11206         TOKEN_STRING_INITIALIZER
11207                 (struct cmd_vf_vlan_insert_result,
11208                  insert, "insert");
11209 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11210         TOKEN_NUM_INITIALIZER
11211                 (struct cmd_vf_vlan_insert_result,
11212                  port_id, RTE_UINT16);
11213 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11214         TOKEN_NUM_INITIALIZER
11215                 (struct cmd_vf_vlan_insert_result,
11216                  vf_id, RTE_UINT16);
11217 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11218         TOKEN_NUM_INITIALIZER
11219                 (struct cmd_vf_vlan_insert_result,
11220                  vlan_id, RTE_UINT16);
11221
11222 static void
11223 cmd_set_vf_vlan_insert_parsed(
11224         void *parsed_result,
11225         __rte_unused struct cmdline *cl,
11226         __rte_unused void *data)
11227 {
11228         struct cmd_vf_vlan_insert_result *res = parsed_result;
11229         int ret = -ENOTSUP;
11230
11231         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11232                 return;
11233
11234 #ifdef RTE_NET_IXGBE
11235         if (ret == -ENOTSUP)
11236                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11237                         res->vlan_id);
11238 #endif
11239 #ifdef RTE_NET_I40E
11240         if (ret == -ENOTSUP)
11241                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11242                         res->vlan_id);
11243 #endif
11244 #ifdef RTE_NET_BNXT
11245         if (ret == -ENOTSUP)
11246                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11247                         res->vlan_id);
11248 #endif
11249
11250         switch (ret) {
11251         case 0:
11252                 break;
11253         case -EINVAL:
11254                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
11255                 break;
11256         case -ENODEV:
11257                 printf("invalid port_id %d\n", res->port_id);
11258                 break;
11259         case -ENOTSUP:
11260                 printf("function not implemented\n");
11261                 break;
11262         default:
11263                 printf("programming error: (%s)\n", strerror(-ret));
11264         }
11265 }
11266
11267 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11268         .f = cmd_set_vf_vlan_insert_parsed,
11269         .data = NULL,
11270         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11271         .tokens = {
11272                 (void *)&cmd_vf_vlan_insert_set,
11273                 (void *)&cmd_vf_vlan_insert_vf,
11274                 (void *)&cmd_vf_vlan_insert_vlan,
11275                 (void *)&cmd_vf_vlan_insert_insert,
11276                 (void *)&cmd_vf_vlan_insert_port_id,
11277                 (void *)&cmd_vf_vlan_insert_vf_id,
11278                 (void *)&cmd_vf_vlan_insert_vlan_id,
11279                 NULL,
11280         },
11281 };
11282
11283 /* tx loopback configuration */
11284
11285 /* Common result structure for tx loopback */
11286 struct cmd_tx_loopback_result {
11287         cmdline_fixed_string_t set;
11288         cmdline_fixed_string_t tx;
11289         cmdline_fixed_string_t loopback;
11290         portid_t port_id;
11291         cmdline_fixed_string_t on_off;
11292 };
11293
11294 /* Common CLI fields for tx loopback enable disable */
11295 cmdline_parse_token_string_t cmd_tx_loopback_set =
11296         TOKEN_STRING_INITIALIZER
11297                 (struct cmd_tx_loopback_result,
11298                  set, "set");
11299 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11300         TOKEN_STRING_INITIALIZER
11301                 (struct cmd_tx_loopback_result,
11302                  tx, "tx");
11303 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11304         TOKEN_STRING_INITIALIZER
11305                 (struct cmd_tx_loopback_result,
11306                  loopback, "loopback");
11307 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11308         TOKEN_NUM_INITIALIZER
11309                 (struct cmd_tx_loopback_result,
11310                  port_id, RTE_UINT16);
11311 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11312         TOKEN_STRING_INITIALIZER
11313                 (struct cmd_tx_loopback_result,
11314                  on_off, "on#off");
11315
11316 static void
11317 cmd_set_tx_loopback_parsed(
11318         void *parsed_result,
11319         __rte_unused struct cmdline *cl,
11320         __rte_unused void *data)
11321 {
11322         struct cmd_tx_loopback_result *res = parsed_result;
11323         int ret = -ENOTSUP;
11324
11325         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11326
11327         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11328                 return;
11329
11330 #ifdef RTE_NET_IXGBE
11331         if (ret == -ENOTSUP)
11332                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11333 #endif
11334 #ifdef RTE_NET_I40E
11335         if (ret == -ENOTSUP)
11336                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11337 #endif
11338 #ifdef RTE_NET_BNXT
11339         if (ret == -ENOTSUP)
11340                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11341 #endif
11342 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11343         if (ret == -ENOTSUP)
11344                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11345 #endif
11346
11347         switch (ret) {
11348         case 0:
11349                 break;
11350         case -EINVAL:
11351                 printf("invalid is_on %d\n", is_on);
11352                 break;
11353         case -ENODEV:
11354                 printf("invalid port_id %d\n", res->port_id);
11355                 break;
11356         case -ENOTSUP:
11357                 printf("function not implemented\n");
11358                 break;
11359         default:
11360                 printf("programming error: (%s)\n", strerror(-ret));
11361         }
11362 }
11363
11364 cmdline_parse_inst_t cmd_set_tx_loopback = {
11365         .f = cmd_set_tx_loopback_parsed,
11366         .data = NULL,
11367         .help_str = "set tx loopback <port_id> on|off",
11368         .tokens = {
11369                 (void *)&cmd_tx_loopback_set,
11370                 (void *)&cmd_tx_loopback_tx,
11371                 (void *)&cmd_tx_loopback_loopback,
11372                 (void *)&cmd_tx_loopback_port_id,
11373                 (void *)&cmd_tx_loopback_on_off,
11374                 NULL,
11375         },
11376 };
11377
11378 /* all queues drop enable configuration */
11379
11380 /* Common result structure for all queues drop enable */
11381 struct cmd_all_queues_drop_en_result {
11382         cmdline_fixed_string_t set;
11383         cmdline_fixed_string_t all;
11384         cmdline_fixed_string_t queues;
11385         cmdline_fixed_string_t drop;
11386         portid_t port_id;
11387         cmdline_fixed_string_t on_off;
11388 };
11389
11390 /* Common CLI fields for tx loopback enable disable */
11391 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11392         TOKEN_STRING_INITIALIZER
11393                 (struct cmd_all_queues_drop_en_result,
11394                  set, "set");
11395 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11396         TOKEN_STRING_INITIALIZER
11397                 (struct cmd_all_queues_drop_en_result,
11398                  all, "all");
11399 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11400         TOKEN_STRING_INITIALIZER
11401                 (struct cmd_all_queues_drop_en_result,
11402                  queues, "queues");
11403 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11404         TOKEN_STRING_INITIALIZER
11405                 (struct cmd_all_queues_drop_en_result,
11406                  drop, "drop");
11407 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11408         TOKEN_NUM_INITIALIZER
11409                 (struct cmd_all_queues_drop_en_result,
11410                  port_id, RTE_UINT16);
11411 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11412         TOKEN_STRING_INITIALIZER
11413                 (struct cmd_all_queues_drop_en_result,
11414                  on_off, "on#off");
11415
11416 static void
11417 cmd_set_all_queues_drop_en_parsed(
11418         void *parsed_result,
11419         __rte_unused struct cmdline *cl,
11420         __rte_unused void *data)
11421 {
11422         struct cmd_all_queues_drop_en_result *res = parsed_result;
11423         int ret = -ENOTSUP;
11424         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11425
11426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11427                 return;
11428
11429 #ifdef RTE_NET_IXGBE
11430         if (ret == -ENOTSUP)
11431                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11432 #endif
11433 #ifdef RTE_NET_BNXT
11434         if (ret == -ENOTSUP)
11435                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11436 #endif
11437         switch (ret) {
11438         case 0:
11439                 break;
11440         case -EINVAL:
11441                 printf("invalid is_on %d\n", is_on);
11442                 break;
11443         case -ENODEV:
11444                 printf("invalid port_id %d\n", res->port_id);
11445                 break;
11446         case -ENOTSUP:
11447                 printf("function not implemented\n");
11448                 break;
11449         default:
11450                 printf("programming error: (%s)\n", strerror(-ret));
11451         }
11452 }
11453
11454 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11455         .f = cmd_set_all_queues_drop_en_parsed,
11456         .data = NULL,
11457         .help_str = "set all queues drop <port_id> on|off",
11458         .tokens = {
11459                 (void *)&cmd_all_queues_drop_en_set,
11460                 (void *)&cmd_all_queues_drop_en_all,
11461                 (void *)&cmd_all_queues_drop_en_queues,
11462                 (void *)&cmd_all_queues_drop_en_drop,
11463                 (void *)&cmd_all_queues_drop_en_port_id,
11464                 (void *)&cmd_all_queues_drop_en_on_off,
11465                 NULL,
11466         },
11467 };
11468
11469 /* vf split drop enable configuration */
11470
11471 /* Common result structure for vf split drop enable */
11472 struct cmd_vf_split_drop_en_result {
11473         cmdline_fixed_string_t set;
11474         cmdline_fixed_string_t vf;
11475         cmdline_fixed_string_t split;
11476         cmdline_fixed_string_t drop;
11477         portid_t port_id;
11478         uint16_t vf_id;
11479         cmdline_fixed_string_t on_off;
11480 };
11481
11482 /* Common CLI fields for vf split drop enable disable */
11483 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11484         TOKEN_STRING_INITIALIZER
11485                 (struct cmd_vf_split_drop_en_result,
11486                  set, "set");
11487 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11488         TOKEN_STRING_INITIALIZER
11489                 (struct cmd_vf_split_drop_en_result,
11490                  vf, "vf");
11491 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11492         TOKEN_STRING_INITIALIZER
11493                 (struct cmd_vf_split_drop_en_result,
11494                  split, "split");
11495 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11496         TOKEN_STRING_INITIALIZER
11497                 (struct cmd_vf_split_drop_en_result,
11498                  drop, "drop");
11499 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11500         TOKEN_NUM_INITIALIZER
11501                 (struct cmd_vf_split_drop_en_result,
11502                  port_id, RTE_UINT16);
11503 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11504         TOKEN_NUM_INITIALIZER
11505                 (struct cmd_vf_split_drop_en_result,
11506                  vf_id, RTE_UINT16);
11507 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11508         TOKEN_STRING_INITIALIZER
11509                 (struct cmd_vf_split_drop_en_result,
11510                  on_off, "on#off");
11511
11512 static void
11513 cmd_set_vf_split_drop_en_parsed(
11514         void *parsed_result,
11515         __rte_unused struct cmdline *cl,
11516         __rte_unused void *data)
11517 {
11518         struct cmd_vf_split_drop_en_result *res = parsed_result;
11519         int ret = -ENOTSUP;
11520         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11521
11522         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11523                 return;
11524
11525 #ifdef RTE_NET_IXGBE
11526         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11527                         is_on);
11528 #endif
11529         switch (ret) {
11530         case 0:
11531                 break;
11532         case -EINVAL:
11533                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
11534                 break;
11535         case -ENODEV:
11536                 printf("invalid port_id %d\n", res->port_id);
11537                 break;
11538         case -ENOTSUP:
11539                 printf("not supported on port %d\n", res->port_id);
11540                 break;
11541         default:
11542                 printf("programming error: (%s)\n", strerror(-ret));
11543         }
11544 }
11545
11546 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11547         .f = cmd_set_vf_split_drop_en_parsed,
11548         .data = NULL,
11549         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11550         .tokens = {
11551                 (void *)&cmd_vf_split_drop_en_set,
11552                 (void *)&cmd_vf_split_drop_en_vf,
11553                 (void *)&cmd_vf_split_drop_en_split,
11554                 (void *)&cmd_vf_split_drop_en_drop,
11555                 (void *)&cmd_vf_split_drop_en_port_id,
11556                 (void *)&cmd_vf_split_drop_en_vf_id,
11557                 (void *)&cmd_vf_split_drop_en_on_off,
11558                 NULL,
11559         },
11560 };
11561
11562 /* vf mac address configuration */
11563
11564 /* Common result structure for vf mac address */
11565 struct cmd_set_vf_mac_addr_result {
11566         cmdline_fixed_string_t set;
11567         cmdline_fixed_string_t vf;
11568         cmdline_fixed_string_t mac;
11569         cmdline_fixed_string_t addr;
11570         portid_t port_id;
11571         uint16_t vf_id;
11572         struct rte_ether_addr mac_addr;
11573
11574 };
11575
11576 /* Common CLI fields for vf split drop enable disable */
11577 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11578         TOKEN_STRING_INITIALIZER
11579                 (struct cmd_set_vf_mac_addr_result,
11580                  set, "set");
11581 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11582         TOKEN_STRING_INITIALIZER
11583                 (struct cmd_set_vf_mac_addr_result,
11584                  vf, "vf");
11585 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11586         TOKEN_STRING_INITIALIZER
11587                 (struct cmd_set_vf_mac_addr_result,
11588                  mac, "mac");
11589 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11590         TOKEN_STRING_INITIALIZER
11591                 (struct cmd_set_vf_mac_addr_result,
11592                  addr, "addr");
11593 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11594         TOKEN_NUM_INITIALIZER
11595                 (struct cmd_set_vf_mac_addr_result,
11596                  port_id, RTE_UINT16);
11597 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11598         TOKEN_NUM_INITIALIZER
11599                 (struct cmd_set_vf_mac_addr_result,
11600                  vf_id, RTE_UINT16);
11601 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11602         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11603                  mac_addr);
11604
11605 static void
11606 cmd_set_vf_mac_addr_parsed(
11607         void *parsed_result,
11608         __rte_unused struct cmdline *cl,
11609         __rte_unused void *data)
11610 {
11611         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11612         int ret = -ENOTSUP;
11613
11614         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11615                 return;
11616
11617 #ifdef RTE_NET_IXGBE
11618         if (ret == -ENOTSUP)
11619                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11620                                 &res->mac_addr);
11621 #endif
11622 #ifdef RTE_NET_I40E
11623         if (ret == -ENOTSUP)
11624                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11625                                 &res->mac_addr);
11626 #endif
11627 #ifdef RTE_NET_BNXT
11628         if (ret == -ENOTSUP)
11629                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11630                                 &res->mac_addr);
11631 #endif
11632
11633         switch (ret) {
11634         case 0:
11635                 break;
11636         case -EINVAL:
11637                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
11638                 break;
11639         case -ENODEV:
11640                 printf("invalid port_id %d\n", res->port_id);
11641                 break;
11642         case -ENOTSUP:
11643                 printf("function not implemented\n");
11644                 break;
11645         default:
11646                 printf("programming error: (%s)\n", strerror(-ret));
11647         }
11648 }
11649
11650 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11651         .f = cmd_set_vf_mac_addr_parsed,
11652         .data = NULL,
11653         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11654         .tokens = {
11655                 (void *)&cmd_set_vf_mac_addr_set,
11656                 (void *)&cmd_set_vf_mac_addr_vf,
11657                 (void *)&cmd_set_vf_mac_addr_mac,
11658                 (void *)&cmd_set_vf_mac_addr_addr,
11659                 (void *)&cmd_set_vf_mac_addr_port_id,
11660                 (void *)&cmd_set_vf_mac_addr_vf_id,
11661                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11662                 NULL,
11663         },
11664 };
11665
11666 /* MACsec configuration */
11667
11668 /* Common result structure for MACsec offload enable */
11669 struct cmd_macsec_offload_on_result {
11670         cmdline_fixed_string_t set;
11671         cmdline_fixed_string_t macsec;
11672         cmdline_fixed_string_t offload;
11673         portid_t port_id;
11674         cmdline_fixed_string_t on;
11675         cmdline_fixed_string_t encrypt;
11676         cmdline_fixed_string_t en_on_off;
11677         cmdline_fixed_string_t replay_protect;
11678         cmdline_fixed_string_t rp_on_off;
11679 };
11680
11681 /* Common CLI fields for MACsec offload disable */
11682 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11683         TOKEN_STRING_INITIALIZER
11684                 (struct cmd_macsec_offload_on_result,
11685                  set, "set");
11686 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11687         TOKEN_STRING_INITIALIZER
11688                 (struct cmd_macsec_offload_on_result,
11689                  macsec, "macsec");
11690 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11691         TOKEN_STRING_INITIALIZER
11692                 (struct cmd_macsec_offload_on_result,
11693                  offload, "offload");
11694 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11695         TOKEN_NUM_INITIALIZER
11696                 (struct cmd_macsec_offload_on_result,
11697                  port_id, RTE_UINT16);
11698 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11699         TOKEN_STRING_INITIALIZER
11700                 (struct cmd_macsec_offload_on_result,
11701                  on, "on");
11702 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11703         TOKEN_STRING_INITIALIZER
11704                 (struct cmd_macsec_offload_on_result,
11705                  encrypt, "encrypt");
11706 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11707         TOKEN_STRING_INITIALIZER
11708                 (struct cmd_macsec_offload_on_result,
11709                  en_on_off, "on#off");
11710 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11711         TOKEN_STRING_INITIALIZER
11712                 (struct cmd_macsec_offload_on_result,
11713                  replay_protect, "replay-protect");
11714 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11715         TOKEN_STRING_INITIALIZER
11716                 (struct cmd_macsec_offload_on_result,
11717                  rp_on_off, "on#off");
11718
11719 static void
11720 cmd_set_macsec_offload_on_parsed(
11721         void *parsed_result,
11722         __rte_unused struct cmdline *cl,
11723         __rte_unused void *data)
11724 {
11725         struct cmd_macsec_offload_on_result *res = parsed_result;
11726         int ret = -ENOTSUP;
11727         portid_t port_id = res->port_id;
11728         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11729         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11730         struct rte_eth_dev_info dev_info;
11731
11732         if (port_id_is_invalid(port_id, ENABLED_WARN))
11733                 return;
11734         if (!port_is_stopped(port_id)) {
11735                 printf("Please stop port %d first\n", port_id);
11736                 return;
11737         }
11738
11739         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11740         if (ret != 0)
11741                 return;
11742
11743         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11744 #ifdef RTE_NET_IXGBE
11745                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11746 #endif
11747         }
11748         RTE_SET_USED(en);
11749         RTE_SET_USED(rp);
11750
11751         switch (ret) {
11752         case 0:
11753                 ports[port_id].dev_conf.txmode.offloads |=
11754                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11755                 cmd_reconfig_device_queue(port_id, 1, 1);
11756                 break;
11757         case -ENODEV:
11758                 printf("invalid port_id %d\n", port_id);
11759                 break;
11760         case -ENOTSUP:
11761                 printf("not supported on port %d\n", port_id);
11762                 break;
11763         default:
11764                 printf("programming error: (%s)\n", strerror(-ret));
11765         }
11766 }
11767
11768 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11769         .f = cmd_set_macsec_offload_on_parsed,
11770         .data = NULL,
11771         .help_str = "set macsec offload <port_id> on "
11772                 "encrypt on|off replay-protect on|off",
11773         .tokens = {
11774                 (void *)&cmd_macsec_offload_on_set,
11775                 (void *)&cmd_macsec_offload_on_macsec,
11776                 (void *)&cmd_macsec_offload_on_offload,
11777                 (void *)&cmd_macsec_offload_on_port_id,
11778                 (void *)&cmd_macsec_offload_on_on,
11779                 (void *)&cmd_macsec_offload_on_encrypt,
11780                 (void *)&cmd_macsec_offload_on_en_on_off,
11781                 (void *)&cmd_macsec_offload_on_replay_protect,
11782                 (void *)&cmd_macsec_offload_on_rp_on_off,
11783                 NULL,
11784         },
11785 };
11786
11787 /* Common result structure for MACsec offload disable */
11788 struct cmd_macsec_offload_off_result {
11789         cmdline_fixed_string_t set;
11790         cmdline_fixed_string_t macsec;
11791         cmdline_fixed_string_t offload;
11792         portid_t port_id;
11793         cmdline_fixed_string_t off;
11794 };
11795
11796 /* Common CLI fields for MACsec offload disable */
11797 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11798         TOKEN_STRING_INITIALIZER
11799                 (struct cmd_macsec_offload_off_result,
11800                  set, "set");
11801 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_macsec_offload_off_result,
11804                  macsec, "macsec");
11805 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_macsec_offload_off_result,
11808                  offload, "offload");
11809 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11810         TOKEN_NUM_INITIALIZER
11811                 (struct cmd_macsec_offload_off_result,
11812                  port_id, RTE_UINT16);
11813 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_macsec_offload_off_result,
11816                  off, "off");
11817
11818 static void
11819 cmd_set_macsec_offload_off_parsed(
11820         void *parsed_result,
11821         __rte_unused struct cmdline *cl,
11822         __rte_unused void *data)
11823 {
11824         struct cmd_macsec_offload_off_result *res = parsed_result;
11825         int ret = -ENOTSUP;
11826         struct rte_eth_dev_info dev_info;
11827         portid_t port_id = res->port_id;
11828
11829         if (port_id_is_invalid(port_id, ENABLED_WARN))
11830                 return;
11831         if (!port_is_stopped(port_id)) {
11832                 printf("Please stop port %d first\n", port_id);
11833                 return;
11834         }
11835
11836         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11837         if (ret != 0)
11838                 return;
11839
11840         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11841 #ifdef RTE_NET_IXGBE
11842                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11843 #endif
11844         }
11845         switch (ret) {
11846         case 0:
11847                 ports[port_id].dev_conf.txmode.offloads &=
11848                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11849                 cmd_reconfig_device_queue(port_id, 1, 1);
11850                 break;
11851         case -ENODEV:
11852                 printf("invalid port_id %d\n", port_id);
11853                 break;
11854         case -ENOTSUP:
11855                 printf("not supported on port %d\n", port_id);
11856                 break;
11857         default:
11858                 printf("programming error: (%s)\n", strerror(-ret));
11859         }
11860 }
11861
11862 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11863         .f = cmd_set_macsec_offload_off_parsed,
11864         .data = NULL,
11865         .help_str = "set macsec offload <port_id> off",
11866         .tokens = {
11867                 (void *)&cmd_macsec_offload_off_set,
11868                 (void *)&cmd_macsec_offload_off_macsec,
11869                 (void *)&cmd_macsec_offload_off_offload,
11870                 (void *)&cmd_macsec_offload_off_port_id,
11871                 (void *)&cmd_macsec_offload_off_off,
11872                 NULL,
11873         },
11874 };
11875
11876 /* Common result structure for MACsec secure connection configure */
11877 struct cmd_macsec_sc_result {
11878         cmdline_fixed_string_t set;
11879         cmdline_fixed_string_t macsec;
11880         cmdline_fixed_string_t sc;
11881         cmdline_fixed_string_t tx_rx;
11882         portid_t port_id;
11883         struct rte_ether_addr mac;
11884         uint16_t pi;
11885 };
11886
11887 /* Common CLI fields for MACsec secure connection configure */
11888 cmdline_parse_token_string_t cmd_macsec_sc_set =
11889         TOKEN_STRING_INITIALIZER
11890                 (struct cmd_macsec_sc_result,
11891                  set, "set");
11892 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
11893         TOKEN_STRING_INITIALIZER
11894                 (struct cmd_macsec_sc_result,
11895                  macsec, "macsec");
11896 cmdline_parse_token_string_t cmd_macsec_sc_sc =
11897         TOKEN_STRING_INITIALIZER
11898                 (struct cmd_macsec_sc_result,
11899                  sc, "sc");
11900 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
11901         TOKEN_STRING_INITIALIZER
11902                 (struct cmd_macsec_sc_result,
11903                  tx_rx, "tx#rx");
11904 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
11905         TOKEN_NUM_INITIALIZER
11906                 (struct cmd_macsec_sc_result,
11907                  port_id, RTE_UINT16);
11908 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
11909         TOKEN_ETHERADDR_INITIALIZER
11910                 (struct cmd_macsec_sc_result,
11911                  mac);
11912 cmdline_parse_token_num_t cmd_macsec_sc_pi =
11913         TOKEN_NUM_INITIALIZER
11914                 (struct cmd_macsec_sc_result,
11915                  pi, RTE_UINT16);
11916
11917 static void
11918 cmd_set_macsec_sc_parsed(
11919         void *parsed_result,
11920         __rte_unused struct cmdline *cl,
11921         __rte_unused void *data)
11922 {
11923         struct cmd_macsec_sc_result *res = parsed_result;
11924         int ret = -ENOTSUP;
11925         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
11926
11927 #ifdef RTE_NET_IXGBE
11928         ret = is_tx ?
11929                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
11930                                 res->mac.addr_bytes) :
11931                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
11932                                 res->mac.addr_bytes, res->pi);
11933 #endif
11934         RTE_SET_USED(is_tx);
11935
11936         switch (ret) {
11937         case 0:
11938                 break;
11939         case -ENODEV:
11940                 printf("invalid port_id %d\n", res->port_id);
11941                 break;
11942         case -ENOTSUP:
11943                 printf("not supported on port %d\n", res->port_id);
11944                 break;
11945         default:
11946                 printf("programming error: (%s)\n", strerror(-ret));
11947         }
11948 }
11949
11950 cmdline_parse_inst_t cmd_set_macsec_sc = {
11951         .f = cmd_set_macsec_sc_parsed,
11952         .data = NULL,
11953         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
11954         .tokens = {
11955                 (void *)&cmd_macsec_sc_set,
11956                 (void *)&cmd_macsec_sc_macsec,
11957                 (void *)&cmd_macsec_sc_sc,
11958                 (void *)&cmd_macsec_sc_tx_rx,
11959                 (void *)&cmd_macsec_sc_port_id,
11960                 (void *)&cmd_macsec_sc_mac,
11961                 (void *)&cmd_macsec_sc_pi,
11962                 NULL,
11963         },
11964 };
11965
11966 /* Common result structure for MACsec secure connection configure */
11967 struct cmd_macsec_sa_result {
11968         cmdline_fixed_string_t set;
11969         cmdline_fixed_string_t macsec;
11970         cmdline_fixed_string_t sa;
11971         cmdline_fixed_string_t tx_rx;
11972         portid_t port_id;
11973         uint8_t idx;
11974         uint8_t an;
11975         uint32_t pn;
11976         cmdline_fixed_string_t key;
11977 };
11978
11979 /* Common CLI fields for MACsec secure connection configure */
11980 cmdline_parse_token_string_t cmd_macsec_sa_set =
11981         TOKEN_STRING_INITIALIZER
11982                 (struct cmd_macsec_sa_result,
11983                  set, "set");
11984 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
11985         TOKEN_STRING_INITIALIZER
11986                 (struct cmd_macsec_sa_result,
11987                  macsec, "macsec");
11988 cmdline_parse_token_string_t cmd_macsec_sa_sa =
11989         TOKEN_STRING_INITIALIZER
11990                 (struct cmd_macsec_sa_result,
11991                  sa, "sa");
11992 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
11993         TOKEN_STRING_INITIALIZER
11994                 (struct cmd_macsec_sa_result,
11995                  tx_rx, "tx#rx");
11996 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
11997         TOKEN_NUM_INITIALIZER
11998                 (struct cmd_macsec_sa_result,
11999                  port_id, RTE_UINT16);
12000 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12001         TOKEN_NUM_INITIALIZER
12002                 (struct cmd_macsec_sa_result,
12003                  idx, RTE_UINT8);
12004 cmdline_parse_token_num_t cmd_macsec_sa_an =
12005         TOKEN_NUM_INITIALIZER
12006                 (struct cmd_macsec_sa_result,
12007                  an, RTE_UINT8);
12008 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12009         TOKEN_NUM_INITIALIZER
12010                 (struct cmd_macsec_sa_result,
12011                  pn, RTE_UINT32);
12012 cmdline_parse_token_string_t cmd_macsec_sa_key =
12013         TOKEN_STRING_INITIALIZER
12014                 (struct cmd_macsec_sa_result,
12015                  key, NULL);
12016
12017 static void
12018 cmd_set_macsec_sa_parsed(
12019         void *parsed_result,
12020         __rte_unused struct cmdline *cl,
12021         __rte_unused void *data)
12022 {
12023         struct cmd_macsec_sa_result *res = parsed_result;
12024         int ret = -ENOTSUP;
12025         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12026         uint8_t key[16] = { 0 };
12027         uint8_t xdgt0;
12028         uint8_t xdgt1;
12029         int key_len;
12030         int i;
12031
12032         key_len = strlen(res->key) / 2;
12033         if (key_len > 16)
12034                 key_len = 16;
12035
12036         for (i = 0; i < key_len; i++) {
12037                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12038                 if (xdgt0 == 0xFF)
12039                         return;
12040                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12041                 if (xdgt1 == 0xFF)
12042                         return;
12043                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12044         }
12045
12046 #ifdef RTE_NET_IXGBE
12047         ret = is_tx ?
12048                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12049                         res->idx, res->an, res->pn, key) :
12050                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12051                         res->idx, res->an, res->pn, key);
12052 #endif
12053         RTE_SET_USED(is_tx);
12054         RTE_SET_USED(key);
12055
12056         switch (ret) {
12057         case 0:
12058                 break;
12059         case -EINVAL:
12060                 printf("invalid idx %d or an %d\n", res->idx, res->an);
12061                 break;
12062         case -ENODEV:
12063                 printf("invalid port_id %d\n", res->port_id);
12064                 break;
12065         case -ENOTSUP:
12066                 printf("not supported on port %d\n", res->port_id);
12067                 break;
12068         default:
12069                 printf("programming error: (%s)\n", strerror(-ret));
12070         }
12071 }
12072
12073 cmdline_parse_inst_t cmd_set_macsec_sa = {
12074         .f = cmd_set_macsec_sa_parsed,
12075         .data = NULL,
12076         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12077         .tokens = {
12078                 (void *)&cmd_macsec_sa_set,
12079                 (void *)&cmd_macsec_sa_macsec,
12080                 (void *)&cmd_macsec_sa_sa,
12081                 (void *)&cmd_macsec_sa_tx_rx,
12082                 (void *)&cmd_macsec_sa_port_id,
12083                 (void *)&cmd_macsec_sa_idx,
12084                 (void *)&cmd_macsec_sa_an,
12085                 (void *)&cmd_macsec_sa_pn,
12086                 (void *)&cmd_macsec_sa_key,
12087                 NULL,
12088         },
12089 };
12090
12091 /* VF unicast promiscuous mode configuration */
12092
12093 /* Common result structure for VF unicast promiscuous mode */
12094 struct cmd_vf_promisc_result {
12095         cmdline_fixed_string_t set;
12096         cmdline_fixed_string_t vf;
12097         cmdline_fixed_string_t promisc;
12098         portid_t port_id;
12099         uint32_t vf_id;
12100         cmdline_fixed_string_t on_off;
12101 };
12102
12103 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12104 cmdline_parse_token_string_t cmd_vf_promisc_set =
12105         TOKEN_STRING_INITIALIZER
12106                 (struct cmd_vf_promisc_result,
12107                  set, "set");
12108 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12109         TOKEN_STRING_INITIALIZER
12110                 (struct cmd_vf_promisc_result,
12111                  vf, "vf");
12112 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12113         TOKEN_STRING_INITIALIZER
12114                 (struct cmd_vf_promisc_result,
12115                  promisc, "promisc");
12116 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12117         TOKEN_NUM_INITIALIZER
12118                 (struct cmd_vf_promisc_result,
12119                  port_id, RTE_UINT16);
12120 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12121         TOKEN_NUM_INITIALIZER
12122                 (struct cmd_vf_promisc_result,
12123                  vf_id, RTE_UINT32);
12124 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12125         TOKEN_STRING_INITIALIZER
12126                 (struct cmd_vf_promisc_result,
12127                  on_off, "on#off");
12128
12129 static void
12130 cmd_set_vf_promisc_parsed(
12131         void *parsed_result,
12132         __rte_unused struct cmdline *cl,
12133         __rte_unused void *data)
12134 {
12135         struct cmd_vf_promisc_result *res = parsed_result;
12136         int ret = -ENOTSUP;
12137
12138         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12139
12140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12141                 return;
12142
12143 #ifdef RTE_NET_I40E
12144         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12145                                                   res->vf_id, is_on);
12146 #endif
12147
12148         switch (ret) {
12149         case 0:
12150                 break;
12151         case -EINVAL:
12152                 printf("invalid vf_id %d\n", res->vf_id);
12153                 break;
12154         case -ENODEV:
12155                 printf("invalid port_id %d\n", res->port_id);
12156                 break;
12157         case -ENOTSUP:
12158                 printf("function not implemented\n");
12159                 break;
12160         default:
12161                 printf("programming error: (%s)\n", strerror(-ret));
12162         }
12163 }
12164
12165 cmdline_parse_inst_t cmd_set_vf_promisc = {
12166         .f = cmd_set_vf_promisc_parsed,
12167         .data = NULL,
12168         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12169                 "Set unicast promiscuous mode for a VF from the PF",
12170         .tokens = {
12171                 (void *)&cmd_vf_promisc_set,
12172                 (void *)&cmd_vf_promisc_vf,
12173                 (void *)&cmd_vf_promisc_promisc,
12174                 (void *)&cmd_vf_promisc_port_id,
12175                 (void *)&cmd_vf_promisc_vf_id,
12176                 (void *)&cmd_vf_promisc_on_off,
12177                 NULL,
12178         },
12179 };
12180
12181 /* VF multicast promiscuous mode configuration */
12182
12183 /* Common result structure for VF multicast promiscuous mode */
12184 struct cmd_vf_allmulti_result {
12185         cmdline_fixed_string_t set;
12186         cmdline_fixed_string_t vf;
12187         cmdline_fixed_string_t allmulti;
12188         portid_t port_id;
12189         uint32_t vf_id;
12190         cmdline_fixed_string_t on_off;
12191 };
12192
12193 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12194 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12195         TOKEN_STRING_INITIALIZER
12196                 (struct cmd_vf_allmulti_result,
12197                  set, "set");
12198 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12199         TOKEN_STRING_INITIALIZER
12200                 (struct cmd_vf_allmulti_result,
12201                  vf, "vf");
12202 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12203         TOKEN_STRING_INITIALIZER
12204                 (struct cmd_vf_allmulti_result,
12205                  allmulti, "allmulti");
12206 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12207         TOKEN_NUM_INITIALIZER
12208                 (struct cmd_vf_allmulti_result,
12209                  port_id, RTE_UINT16);
12210 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12211         TOKEN_NUM_INITIALIZER
12212                 (struct cmd_vf_allmulti_result,
12213                  vf_id, RTE_UINT32);
12214 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12215         TOKEN_STRING_INITIALIZER
12216                 (struct cmd_vf_allmulti_result,
12217                  on_off, "on#off");
12218
12219 static void
12220 cmd_set_vf_allmulti_parsed(
12221         void *parsed_result,
12222         __rte_unused struct cmdline *cl,
12223         __rte_unused void *data)
12224 {
12225         struct cmd_vf_allmulti_result *res = parsed_result;
12226         int ret = -ENOTSUP;
12227
12228         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12229
12230         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12231                 return;
12232
12233 #ifdef RTE_NET_I40E
12234         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12235                                                     res->vf_id, is_on);
12236 #endif
12237
12238         switch (ret) {
12239         case 0:
12240                 break;
12241         case -EINVAL:
12242                 printf("invalid vf_id %d\n", res->vf_id);
12243                 break;
12244         case -ENODEV:
12245                 printf("invalid port_id %d\n", res->port_id);
12246                 break;
12247         case -ENOTSUP:
12248                 printf("function not implemented\n");
12249                 break;
12250         default:
12251                 printf("programming error: (%s)\n", strerror(-ret));
12252         }
12253 }
12254
12255 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12256         .f = cmd_set_vf_allmulti_parsed,
12257         .data = NULL,
12258         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12259                 "Set multicast promiscuous mode for a VF from the PF",
12260         .tokens = {
12261                 (void *)&cmd_vf_allmulti_set,
12262                 (void *)&cmd_vf_allmulti_vf,
12263                 (void *)&cmd_vf_allmulti_allmulti,
12264                 (void *)&cmd_vf_allmulti_port_id,
12265                 (void *)&cmd_vf_allmulti_vf_id,
12266                 (void *)&cmd_vf_allmulti_on_off,
12267                 NULL,
12268         },
12269 };
12270
12271 /* vf broadcast mode configuration */
12272
12273 /* Common result structure for vf broadcast */
12274 struct cmd_set_vf_broadcast_result {
12275         cmdline_fixed_string_t set;
12276         cmdline_fixed_string_t vf;
12277         cmdline_fixed_string_t broadcast;
12278         portid_t port_id;
12279         uint16_t vf_id;
12280         cmdline_fixed_string_t on_off;
12281 };
12282
12283 /* Common CLI fields for vf broadcast enable disable */
12284 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12285         TOKEN_STRING_INITIALIZER
12286                 (struct cmd_set_vf_broadcast_result,
12287                  set, "set");
12288 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12289         TOKEN_STRING_INITIALIZER
12290                 (struct cmd_set_vf_broadcast_result,
12291                  vf, "vf");
12292 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12293         TOKEN_STRING_INITIALIZER
12294                 (struct cmd_set_vf_broadcast_result,
12295                  broadcast, "broadcast");
12296 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12297         TOKEN_NUM_INITIALIZER
12298                 (struct cmd_set_vf_broadcast_result,
12299                  port_id, RTE_UINT16);
12300 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12301         TOKEN_NUM_INITIALIZER
12302                 (struct cmd_set_vf_broadcast_result,
12303                  vf_id, RTE_UINT16);
12304 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12305         TOKEN_STRING_INITIALIZER
12306                 (struct cmd_set_vf_broadcast_result,
12307                  on_off, "on#off");
12308
12309 static void
12310 cmd_set_vf_broadcast_parsed(
12311         void *parsed_result,
12312         __rte_unused struct cmdline *cl,
12313         __rte_unused void *data)
12314 {
12315         struct cmd_set_vf_broadcast_result *res = parsed_result;
12316         int ret = -ENOTSUP;
12317
12318         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12319
12320         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12321                 return;
12322
12323 #ifdef RTE_NET_I40E
12324         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12325                                             res->vf_id, is_on);
12326 #endif
12327
12328         switch (ret) {
12329         case 0:
12330                 break;
12331         case -EINVAL:
12332                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12333                 break;
12334         case -ENODEV:
12335                 printf("invalid port_id %d\n", res->port_id);
12336                 break;
12337         case -ENOTSUP:
12338                 printf("function not implemented\n");
12339                 break;
12340         default:
12341                 printf("programming error: (%s)\n", strerror(-ret));
12342         }
12343 }
12344
12345 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12346         .f = cmd_set_vf_broadcast_parsed,
12347         .data = NULL,
12348         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12349         .tokens = {
12350                 (void *)&cmd_set_vf_broadcast_set,
12351                 (void *)&cmd_set_vf_broadcast_vf,
12352                 (void *)&cmd_set_vf_broadcast_broadcast,
12353                 (void *)&cmd_set_vf_broadcast_port_id,
12354                 (void *)&cmd_set_vf_broadcast_vf_id,
12355                 (void *)&cmd_set_vf_broadcast_on_off,
12356                 NULL,
12357         },
12358 };
12359
12360 /* vf vlan tag configuration */
12361
12362 /* Common result structure for vf vlan tag */
12363 struct cmd_set_vf_vlan_tag_result {
12364         cmdline_fixed_string_t set;
12365         cmdline_fixed_string_t vf;
12366         cmdline_fixed_string_t vlan;
12367         cmdline_fixed_string_t tag;
12368         portid_t port_id;
12369         uint16_t vf_id;
12370         cmdline_fixed_string_t on_off;
12371 };
12372
12373 /* Common CLI fields for vf vlan tag enable disable */
12374 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12375         TOKEN_STRING_INITIALIZER
12376                 (struct cmd_set_vf_vlan_tag_result,
12377                  set, "set");
12378 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12379         TOKEN_STRING_INITIALIZER
12380                 (struct cmd_set_vf_vlan_tag_result,
12381                  vf, "vf");
12382 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12383         TOKEN_STRING_INITIALIZER
12384                 (struct cmd_set_vf_vlan_tag_result,
12385                  vlan, "vlan");
12386 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12387         TOKEN_STRING_INITIALIZER
12388                 (struct cmd_set_vf_vlan_tag_result,
12389                  tag, "tag");
12390 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12391         TOKEN_NUM_INITIALIZER
12392                 (struct cmd_set_vf_vlan_tag_result,
12393                  port_id, RTE_UINT16);
12394 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12395         TOKEN_NUM_INITIALIZER
12396                 (struct cmd_set_vf_vlan_tag_result,
12397                  vf_id, RTE_UINT16);
12398 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12399         TOKEN_STRING_INITIALIZER
12400                 (struct cmd_set_vf_vlan_tag_result,
12401                  on_off, "on#off");
12402
12403 static void
12404 cmd_set_vf_vlan_tag_parsed(
12405         void *parsed_result,
12406         __rte_unused struct cmdline *cl,
12407         __rte_unused void *data)
12408 {
12409         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12410         int ret = -ENOTSUP;
12411
12412         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12413
12414         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12415                 return;
12416
12417 #ifdef RTE_NET_I40E
12418         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12419                                            res->vf_id, is_on);
12420 #endif
12421
12422         switch (ret) {
12423         case 0:
12424                 break;
12425         case -EINVAL:
12426                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12427                 break;
12428         case -ENODEV:
12429                 printf("invalid port_id %d\n", res->port_id);
12430                 break;
12431         case -ENOTSUP:
12432                 printf("function not implemented\n");
12433                 break;
12434         default:
12435                 printf("programming error: (%s)\n", strerror(-ret));
12436         }
12437 }
12438
12439 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12440         .f = cmd_set_vf_vlan_tag_parsed,
12441         .data = NULL,
12442         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12443         .tokens = {
12444                 (void *)&cmd_set_vf_vlan_tag_set,
12445                 (void *)&cmd_set_vf_vlan_tag_vf,
12446                 (void *)&cmd_set_vf_vlan_tag_vlan,
12447                 (void *)&cmd_set_vf_vlan_tag_tag,
12448                 (void *)&cmd_set_vf_vlan_tag_port_id,
12449                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12450                 (void *)&cmd_set_vf_vlan_tag_on_off,
12451                 NULL,
12452         },
12453 };
12454
12455 /* Common definition of VF and TC TX bandwidth configuration */
12456 struct cmd_vf_tc_bw_result {
12457         cmdline_fixed_string_t set;
12458         cmdline_fixed_string_t vf;
12459         cmdline_fixed_string_t tc;
12460         cmdline_fixed_string_t tx;
12461         cmdline_fixed_string_t min_bw;
12462         cmdline_fixed_string_t max_bw;
12463         cmdline_fixed_string_t strict_link_prio;
12464         portid_t port_id;
12465         uint16_t vf_id;
12466         uint8_t tc_no;
12467         uint32_t bw;
12468         cmdline_fixed_string_t bw_list;
12469         uint8_t tc_map;
12470 };
12471
12472 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12473         TOKEN_STRING_INITIALIZER
12474                 (struct cmd_vf_tc_bw_result,
12475                  set, "set");
12476 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12477         TOKEN_STRING_INITIALIZER
12478                 (struct cmd_vf_tc_bw_result,
12479                  vf, "vf");
12480 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12481         TOKEN_STRING_INITIALIZER
12482                 (struct cmd_vf_tc_bw_result,
12483                  tc, "tc");
12484 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12485         TOKEN_STRING_INITIALIZER
12486                 (struct cmd_vf_tc_bw_result,
12487                  tx, "tx");
12488 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12489         TOKEN_STRING_INITIALIZER
12490                 (struct cmd_vf_tc_bw_result,
12491                  strict_link_prio, "strict-link-priority");
12492 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12493         TOKEN_STRING_INITIALIZER
12494                 (struct cmd_vf_tc_bw_result,
12495                  min_bw, "min-bandwidth");
12496 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12497         TOKEN_STRING_INITIALIZER
12498                 (struct cmd_vf_tc_bw_result,
12499                  max_bw, "max-bandwidth");
12500 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12501         TOKEN_NUM_INITIALIZER
12502                 (struct cmd_vf_tc_bw_result,
12503                  port_id, RTE_UINT16);
12504 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12505         TOKEN_NUM_INITIALIZER
12506                 (struct cmd_vf_tc_bw_result,
12507                  vf_id, RTE_UINT16);
12508 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12509         TOKEN_NUM_INITIALIZER
12510                 (struct cmd_vf_tc_bw_result,
12511                  tc_no, RTE_UINT8);
12512 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12513         TOKEN_NUM_INITIALIZER
12514                 (struct cmd_vf_tc_bw_result,
12515                  bw, RTE_UINT32);
12516 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_vf_tc_bw_result,
12519                  bw_list, NULL);
12520 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12521         TOKEN_NUM_INITIALIZER
12522                 (struct cmd_vf_tc_bw_result,
12523                  tc_map, RTE_UINT8);
12524
12525 /* VF max bandwidth setting */
12526 static void
12527 cmd_vf_max_bw_parsed(
12528         void *parsed_result,
12529         __rte_unused struct cmdline *cl,
12530         __rte_unused void *data)
12531 {
12532         struct cmd_vf_tc_bw_result *res = parsed_result;
12533         int ret = -ENOTSUP;
12534
12535         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12536                 return;
12537
12538 #ifdef RTE_NET_I40E
12539         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12540                                          res->vf_id, res->bw);
12541 #endif
12542
12543         switch (ret) {
12544         case 0:
12545                 break;
12546         case -EINVAL:
12547                 printf("invalid vf_id %d or bandwidth %d\n",
12548                        res->vf_id, res->bw);
12549                 break;
12550         case -ENODEV:
12551                 printf("invalid port_id %d\n", res->port_id);
12552                 break;
12553         case -ENOTSUP:
12554                 printf("function not implemented\n");
12555                 break;
12556         default:
12557                 printf("programming error: (%s)\n", strerror(-ret));
12558         }
12559 }
12560
12561 cmdline_parse_inst_t cmd_vf_max_bw = {
12562         .f = cmd_vf_max_bw_parsed,
12563         .data = NULL,
12564         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12565         .tokens = {
12566                 (void *)&cmd_vf_tc_bw_set,
12567                 (void *)&cmd_vf_tc_bw_vf,
12568                 (void *)&cmd_vf_tc_bw_tx,
12569                 (void *)&cmd_vf_tc_bw_max_bw,
12570                 (void *)&cmd_vf_tc_bw_port_id,
12571                 (void *)&cmd_vf_tc_bw_vf_id,
12572                 (void *)&cmd_vf_tc_bw_bw,
12573                 NULL,
12574         },
12575 };
12576
12577 static int
12578 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12579                            uint8_t *tc_num,
12580                            char *str)
12581 {
12582         uint32_t size;
12583         const char *p, *p0 = str;
12584         char s[256];
12585         char *end;
12586         char *str_fld[16];
12587         uint16_t i;
12588         int ret;
12589
12590         p = strchr(p0, '(');
12591         if (p == NULL) {
12592                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12593                 return -1;
12594         }
12595         p++;
12596         p0 = strchr(p, ')');
12597         if (p0 == NULL) {
12598                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
12599                 return -1;
12600         }
12601         size = p0 - p;
12602         if (size >= sizeof(s)) {
12603                 printf("The string size exceeds the internal buffer size\n");
12604                 return -1;
12605         }
12606         snprintf(s, sizeof(s), "%.*s", size, p);
12607         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12608         if (ret <= 0) {
12609                 printf("Failed to get the bandwidth list. ");
12610                 return -1;
12611         }
12612         *tc_num = ret;
12613         for (i = 0; i < ret; i++)
12614                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12615
12616         return 0;
12617 }
12618
12619 /* TC min bandwidth setting */
12620 static void
12621 cmd_vf_tc_min_bw_parsed(
12622         void *parsed_result,
12623         __rte_unused struct cmdline *cl,
12624         __rte_unused void *data)
12625 {
12626         struct cmd_vf_tc_bw_result *res = parsed_result;
12627         uint8_t tc_num;
12628         uint8_t bw[16];
12629         int ret = -ENOTSUP;
12630
12631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12632                 return;
12633
12634         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12635         if (ret)
12636                 return;
12637
12638 #ifdef RTE_NET_I40E
12639         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12640                                               tc_num, bw);
12641 #endif
12642
12643         switch (ret) {
12644         case 0:
12645                 break;
12646         case -EINVAL:
12647                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
12648                 break;
12649         case -ENODEV:
12650                 printf("invalid port_id %d\n", res->port_id);
12651                 break;
12652         case -ENOTSUP:
12653                 printf("function not implemented\n");
12654                 break;
12655         default:
12656                 printf("programming error: (%s)\n", strerror(-ret));
12657         }
12658 }
12659
12660 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12661         .f = cmd_vf_tc_min_bw_parsed,
12662         .data = NULL,
12663         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12664                     " <bw1, bw2, ...>",
12665         .tokens = {
12666                 (void *)&cmd_vf_tc_bw_set,
12667                 (void *)&cmd_vf_tc_bw_vf,
12668                 (void *)&cmd_vf_tc_bw_tc,
12669                 (void *)&cmd_vf_tc_bw_tx,
12670                 (void *)&cmd_vf_tc_bw_min_bw,
12671                 (void *)&cmd_vf_tc_bw_port_id,
12672                 (void *)&cmd_vf_tc_bw_vf_id,
12673                 (void *)&cmd_vf_tc_bw_bw_list,
12674                 NULL,
12675         },
12676 };
12677
12678 static void
12679 cmd_tc_min_bw_parsed(
12680         void *parsed_result,
12681         __rte_unused struct cmdline *cl,
12682         __rte_unused void *data)
12683 {
12684         struct cmd_vf_tc_bw_result *res = parsed_result;
12685         struct rte_port *port;
12686         uint8_t tc_num;
12687         uint8_t bw[16];
12688         int ret = -ENOTSUP;
12689
12690         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12691                 return;
12692
12693         port = &ports[res->port_id];
12694         /** Check if the port is not started **/
12695         if (port->port_status != RTE_PORT_STOPPED) {
12696                 printf("Please stop port %d first\n", res->port_id);
12697                 return;
12698         }
12699
12700         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12701         if (ret)
12702                 return;
12703
12704 #ifdef RTE_NET_IXGBE
12705         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12706 #endif
12707
12708         switch (ret) {
12709         case 0:
12710                 break;
12711         case -EINVAL:
12712                 printf("invalid bandwidth\n");
12713                 break;
12714         case -ENODEV:
12715                 printf("invalid port_id %d\n", res->port_id);
12716                 break;
12717         case -ENOTSUP:
12718                 printf("function not implemented\n");
12719                 break;
12720         default:
12721                 printf("programming error: (%s)\n", strerror(-ret));
12722         }
12723 }
12724
12725 cmdline_parse_inst_t cmd_tc_min_bw = {
12726         .f = cmd_tc_min_bw_parsed,
12727         .data = NULL,
12728         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12729         .tokens = {
12730                 (void *)&cmd_vf_tc_bw_set,
12731                 (void *)&cmd_vf_tc_bw_tc,
12732                 (void *)&cmd_vf_tc_bw_tx,
12733                 (void *)&cmd_vf_tc_bw_min_bw,
12734                 (void *)&cmd_vf_tc_bw_port_id,
12735                 (void *)&cmd_vf_tc_bw_bw_list,
12736                 NULL,
12737         },
12738 };
12739
12740 /* TC max bandwidth setting */
12741 static void
12742 cmd_vf_tc_max_bw_parsed(
12743         void *parsed_result,
12744         __rte_unused struct cmdline *cl,
12745         __rte_unused void *data)
12746 {
12747         struct cmd_vf_tc_bw_result *res = parsed_result;
12748         int ret = -ENOTSUP;
12749
12750         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12751                 return;
12752
12753 #ifdef RTE_NET_I40E
12754         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12755                                             res->tc_no, res->bw);
12756 #endif
12757
12758         switch (ret) {
12759         case 0:
12760                 break;
12761         case -EINVAL:
12762                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
12763                        res->vf_id, res->tc_no, res->bw);
12764                 break;
12765         case -ENODEV:
12766                 printf("invalid port_id %d\n", res->port_id);
12767                 break;
12768         case -ENOTSUP:
12769                 printf("function not implemented\n");
12770                 break;
12771         default:
12772                 printf("programming error: (%s)\n", strerror(-ret));
12773         }
12774 }
12775
12776 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12777         .f = cmd_vf_tc_max_bw_parsed,
12778         .data = NULL,
12779         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12780                     " <bandwidth>",
12781         .tokens = {
12782                 (void *)&cmd_vf_tc_bw_set,
12783                 (void *)&cmd_vf_tc_bw_vf,
12784                 (void *)&cmd_vf_tc_bw_tc,
12785                 (void *)&cmd_vf_tc_bw_tx,
12786                 (void *)&cmd_vf_tc_bw_max_bw,
12787                 (void *)&cmd_vf_tc_bw_port_id,
12788                 (void *)&cmd_vf_tc_bw_vf_id,
12789                 (void *)&cmd_vf_tc_bw_tc_no,
12790                 (void *)&cmd_vf_tc_bw_bw,
12791                 NULL,
12792         },
12793 };
12794
12795 /** Set VXLAN encapsulation details */
12796 struct cmd_set_vxlan_result {
12797         cmdline_fixed_string_t set;
12798         cmdline_fixed_string_t vxlan;
12799         cmdline_fixed_string_t pos_token;
12800         cmdline_fixed_string_t ip_version;
12801         uint32_t vlan_present:1;
12802         uint32_t vni;
12803         uint16_t udp_src;
12804         uint16_t udp_dst;
12805         cmdline_ipaddr_t ip_src;
12806         cmdline_ipaddr_t ip_dst;
12807         uint16_t tci;
12808         uint8_t tos;
12809         uint8_t ttl;
12810         struct rte_ether_addr eth_src;
12811         struct rte_ether_addr eth_dst;
12812 };
12813
12814 cmdline_parse_token_string_t cmd_set_vxlan_set =
12815         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12816 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12817         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12818 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12819         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12820                                  "vxlan-tos-ttl");
12821 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12822         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12823                                  "vxlan-with-vlan");
12824 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12825         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12826                                  "ip-version");
12827 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12828         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12829                                  "ipv4#ipv6");
12830 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12831         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12832                                  "vni");
12833 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12834         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12835 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12836         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12837                                  "udp-src");
12838 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12839         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12840 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12841         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12842                                  "udp-dst");
12843 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12844         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12845 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12846         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12847                                  "ip-tos");
12848 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12849         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12850 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12851         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12852                                  "ip-ttl");
12853 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12854         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12855 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12856         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12857                                  "ip-src");
12858 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12859         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12860 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12861         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12862                                  "ip-dst");
12863 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12864         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12865 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12866         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12867                                  "vlan-tci");
12868 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12869         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12870 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12871         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12872                                  "eth-src");
12873 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12874         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
12875 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
12876         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12877                                  "eth-dst");
12878 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
12879         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
12880
12881 static void cmd_set_vxlan_parsed(void *parsed_result,
12882         __rte_unused struct cmdline *cl,
12883         __rte_unused void *data)
12884 {
12885         struct cmd_set_vxlan_result *res = parsed_result;
12886         union {
12887                 uint32_t vxlan_id;
12888                 uint8_t vni[4];
12889         } id = {
12890                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
12891         };
12892
12893         vxlan_encap_conf.select_tos_ttl = 0;
12894         if (strcmp(res->vxlan, "vxlan") == 0)
12895                 vxlan_encap_conf.select_vlan = 0;
12896         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
12897                 vxlan_encap_conf.select_vlan = 1;
12898         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
12899                 vxlan_encap_conf.select_vlan = 0;
12900                 vxlan_encap_conf.select_tos_ttl = 1;
12901         }
12902         if (strcmp(res->ip_version, "ipv4") == 0)
12903                 vxlan_encap_conf.select_ipv4 = 1;
12904         else if (strcmp(res->ip_version, "ipv6") == 0)
12905                 vxlan_encap_conf.select_ipv4 = 0;
12906         else
12907                 return;
12908         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
12909         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
12910         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
12911         vxlan_encap_conf.ip_tos = res->tos;
12912         vxlan_encap_conf.ip_ttl = res->ttl;
12913         if (vxlan_encap_conf.select_ipv4) {
12914                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
12915                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
12916         } else {
12917                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
12918                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
12919         }
12920         if (vxlan_encap_conf.select_vlan)
12921                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
12922         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
12923                    RTE_ETHER_ADDR_LEN);
12924         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
12925                    RTE_ETHER_ADDR_LEN);
12926 }
12927
12928 cmdline_parse_inst_t cmd_set_vxlan = {
12929         .f = cmd_set_vxlan_parsed,
12930         .data = NULL,
12931         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
12932                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
12933                 " eth-src <eth-src> eth-dst <eth-dst>",
12934         .tokens = {
12935                 (void *)&cmd_set_vxlan_set,
12936                 (void *)&cmd_set_vxlan_vxlan,
12937                 (void *)&cmd_set_vxlan_ip_version,
12938                 (void *)&cmd_set_vxlan_ip_version_value,
12939                 (void *)&cmd_set_vxlan_vni,
12940                 (void *)&cmd_set_vxlan_vni_value,
12941                 (void *)&cmd_set_vxlan_udp_src,
12942                 (void *)&cmd_set_vxlan_udp_src_value,
12943                 (void *)&cmd_set_vxlan_udp_dst,
12944                 (void *)&cmd_set_vxlan_udp_dst_value,
12945                 (void *)&cmd_set_vxlan_ip_src,
12946                 (void *)&cmd_set_vxlan_ip_src_value,
12947                 (void *)&cmd_set_vxlan_ip_dst,
12948                 (void *)&cmd_set_vxlan_ip_dst_value,
12949                 (void *)&cmd_set_vxlan_eth_src,
12950                 (void *)&cmd_set_vxlan_eth_src_value,
12951                 (void *)&cmd_set_vxlan_eth_dst,
12952                 (void *)&cmd_set_vxlan_eth_dst_value,
12953                 NULL,
12954         },
12955 };
12956
12957 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
12958         .f = cmd_set_vxlan_parsed,
12959         .data = NULL,
12960         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
12961                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
12962                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
12963                 " eth-dst <eth-dst>",
12964         .tokens = {
12965                 (void *)&cmd_set_vxlan_set,
12966                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
12967                 (void *)&cmd_set_vxlan_ip_version,
12968                 (void *)&cmd_set_vxlan_ip_version_value,
12969                 (void *)&cmd_set_vxlan_vni,
12970                 (void *)&cmd_set_vxlan_vni_value,
12971                 (void *)&cmd_set_vxlan_udp_src,
12972                 (void *)&cmd_set_vxlan_udp_src_value,
12973                 (void *)&cmd_set_vxlan_udp_dst,
12974                 (void *)&cmd_set_vxlan_udp_dst_value,
12975                 (void *)&cmd_set_vxlan_ip_tos,
12976                 (void *)&cmd_set_vxlan_ip_tos_value,
12977                 (void *)&cmd_set_vxlan_ip_ttl,
12978                 (void *)&cmd_set_vxlan_ip_ttl_value,
12979                 (void *)&cmd_set_vxlan_ip_src,
12980                 (void *)&cmd_set_vxlan_ip_src_value,
12981                 (void *)&cmd_set_vxlan_ip_dst,
12982                 (void *)&cmd_set_vxlan_ip_dst_value,
12983                 (void *)&cmd_set_vxlan_eth_src,
12984                 (void *)&cmd_set_vxlan_eth_src_value,
12985                 (void *)&cmd_set_vxlan_eth_dst,
12986                 (void *)&cmd_set_vxlan_eth_dst_value,
12987                 NULL,
12988         },
12989 };
12990
12991 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
12992         .f = cmd_set_vxlan_parsed,
12993         .data = NULL,
12994         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
12995                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
12996                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
12997                 " <eth-dst>",
12998         .tokens = {
12999                 (void *)&cmd_set_vxlan_set,
13000                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13001                 (void *)&cmd_set_vxlan_ip_version,
13002                 (void *)&cmd_set_vxlan_ip_version_value,
13003                 (void *)&cmd_set_vxlan_vni,
13004                 (void *)&cmd_set_vxlan_vni_value,
13005                 (void *)&cmd_set_vxlan_udp_src,
13006                 (void *)&cmd_set_vxlan_udp_src_value,
13007                 (void *)&cmd_set_vxlan_udp_dst,
13008                 (void *)&cmd_set_vxlan_udp_dst_value,
13009                 (void *)&cmd_set_vxlan_ip_src,
13010                 (void *)&cmd_set_vxlan_ip_src_value,
13011                 (void *)&cmd_set_vxlan_ip_dst,
13012                 (void *)&cmd_set_vxlan_ip_dst_value,
13013                 (void *)&cmd_set_vxlan_vlan,
13014                 (void *)&cmd_set_vxlan_vlan_value,
13015                 (void *)&cmd_set_vxlan_eth_src,
13016                 (void *)&cmd_set_vxlan_eth_src_value,
13017                 (void *)&cmd_set_vxlan_eth_dst,
13018                 (void *)&cmd_set_vxlan_eth_dst_value,
13019                 NULL,
13020         },
13021 };
13022
13023 /** Set NVGRE encapsulation details */
13024 struct cmd_set_nvgre_result {
13025         cmdline_fixed_string_t set;
13026         cmdline_fixed_string_t nvgre;
13027         cmdline_fixed_string_t pos_token;
13028         cmdline_fixed_string_t ip_version;
13029         uint32_t tni;
13030         cmdline_ipaddr_t ip_src;
13031         cmdline_ipaddr_t ip_dst;
13032         uint16_t tci;
13033         struct rte_ether_addr eth_src;
13034         struct rte_ether_addr eth_dst;
13035 };
13036
13037 cmdline_parse_token_string_t cmd_set_nvgre_set =
13038         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13039 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13040         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13041 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13042         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13043                                  "nvgre-with-vlan");
13044 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13045         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13046                                  "ip-version");
13047 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13048         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13049                                  "ipv4#ipv6");
13050 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13051         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13052                                  "tni");
13053 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13054         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13055 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13056         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13057                                  "ip-src");
13058 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13059         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13060 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13061         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13062                                  "ip-dst");
13063 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13064         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13065 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13066         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13067                                  "vlan-tci");
13068 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13069         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13070 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13071         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13072                                  "eth-src");
13073 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13074         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13075 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13076         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13077                                  "eth-dst");
13078 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13079         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13080
13081 static void cmd_set_nvgre_parsed(void *parsed_result,
13082         __rte_unused struct cmdline *cl,
13083         __rte_unused void *data)
13084 {
13085         struct cmd_set_nvgre_result *res = parsed_result;
13086         union {
13087                 uint32_t nvgre_tni;
13088                 uint8_t tni[4];
13089         } id = {
13090                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13091         };
13092
13093         if (strcmp(res->nvgre, "nvgre") == 0)
13094                 nvgre_encap_conf.select_vlan = 0;
13095         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13096                 nvgre_encap_conf.select_vlan = 1;
13097         if (strcmp(res->ip_version, "ipv4") == 0)
13098                 nvgre_encap_conf.select_ipv4 = 1;
13099         else if (strcmp(res->ip_version, "ipv6") == 0)
13100                 nvgre_encap_conf.select_ipv4 = 0;
13101         else
13102                 return;
13103         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13104         if (nvgre_encap_conf.select_ipv4) {
13105                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13106                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13107         } else {
13108                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13109                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13110         }
13111         if (nvgre_encap_conf.select_vlan)
13112                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13113         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13114                    RTE_ETHER_ADDR_LEN);
13115         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13116                    RTE_ETHER_ADDR_LEN);
13117 }
13118
13119 cmdline_parse_inst_t cmd_set_nvgre = {
13120         .f = cmd_set_nvgre_parsed,
13121         .data = NULL,
13122         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13123                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13124                 " eth-dst <eth-dst>",
13125         .tokens = {
13126                 (void *)&cmd_set_nvgre_set,
13127                 (void *)&cmd_set_nvgre_nvgre,
13128                 (void *)&cmd_set_nvgre_ip_version,
13129                 (void *)&cmd_set_nvgre_ip_version_value,
13130                 (void *)&cmd_set_nvgre_tni,
13131                 (void *)&cmd_set_nvgre_tni_value,
13132                 (void *)&cmd_set_nvgre_ip_src,
13133                 (void *)&cmd_set_nvgre_ip_src_value,
13134                 (void *)&cmd_set_nvgre_ip_dst,
13135                 (void *)&cmd_set_nvgre_ip_dst_value,
13136                 (void *)&cmd_set_nvgre_eth_src,
13137                 (void *)&cmd_set_nvgre_eth_src_value,
13138                 (void *)&cmd_set_nvgre_eth_dst,
13139                 (void *)&cmd_set_nvgre_eth_dst_value,
13140                 NULL,
13141         },
13142 };
13143
13144 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13145         .f = cmd_set_nvgre_parsed,
13146         .data = NULL,
13147         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13148                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13149                 " eth-src <eth-src> eth-dst <eth-dst>",
13150         .tokens = {
13151                 (void *)&cmd_set_nvgre_set,
13152                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13153                 (void *)&cmd_set_nvgre_ip_version,
13154                 (void *)&cmd_set_nvgre_ip_version_value,
13155                 (void *)&cmd_set_nvgre_tni,
13156                 (void *)&cmd_set_nvgre_tni_value,
13157                 (void *)&cmd_set_nvgre_ip_src,
13158                 (void *)&cmd_set_nvgre_ip_src_value,
13159                 (void *)&cmd_set_nvgre_ip_dst,
13160                 (void *)&cmd_set_nvgre_ip_dst_value,
13161                 (void *)&cmd_set_nvgre_vlan,
13162                 (void *)&cmd_set_nvgre_vlan_value,
13163                 (void *)&cmd_set_nvgre_eth_src,
13164                 (void *)&cmd_set_nvgre_eth_src_value,
13165                 (void *)&cmd_set_nvgre_eth_dst,
13166                 (void *)&cmd_set_nvgre_eth_dst_value,
13167                 NULL,
13168         },
13169 };
13170
13171 /** Set L2 encapsulation details */
13172 struct cmd_set_l2_encap_result {
13173         cmdline_fixed_string_t set;
13174         cmdline_fixed_string_t l2_encap;
13175         cmdline_fixed_string_t pos_token;
13176         cmdline_fixed_string_t ip_version;
13177         uint32_t vlan_present:1;
13178         uint16_t tci;
13179         struct rte_ether_addr eth_src;
13180         struct rte_ether_addr eth_dst;
13181 };
13182
13183 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13184         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13185 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13187 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13188         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13189                                  "l2_encap-with-vlan");
13190 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13191         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13192                                  "ip-version");
13193 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13194         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13195                                  "ipv4#ipv6");
13196 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13197         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13198                                  "vlan-tci");
13199 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13200         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13201 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13202         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13203                                  "eth-src");
13204 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13205         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13206 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13207         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13208                                  "eth-dst");
13209 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13210         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13211
13212 static void cmd_set_l2_encap_parsed(void *parsed_result,
13213         __rte_unused struct cmdline *cl,
13214         __rte_unused void *data)
13215 {
13216         struct cmd_set_l2_encap_result *res = parsed_result;
13217
13218         if (strcmp(res->l2_encap, "l2_encap") == 0)
13219                 l2_encap_conf.select_vlan = 0;
13220         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13221                 l2_encap_conf.select_vlan = 1;
13222         if (strcmp(res->ip_version, "ipv4") == 0)
13223                 l2_encap_conf.select_ipv4 = 1;
13224         else if (strcmp(res->ip_version, "ipv6") == 0)
13225                 l2_encap_conf.select_ipv4 = 0;
13226         else
13227                 return;
13228         if (l2_encap_conf.select_vlan)
13229                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13230         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13231                    RTE_ETHER_ADDR_LEN);
13232         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13233                    RTE_ETHER_ADDR_LEN);
13234 }
13235
13236 cmdline_parse_inst_t cmd_set_l2_encap = {
13237         .f = cmd_set_l2_encap_parsed,
13238         .data = NULL,
13239         .help_str = "set l2_encap ip-version ipv4|ipv6"
13240                 " eth-src <eth-src> eth-dst <eth-dst>",
13241         .tokens = {
13242                 (void *)&cmd_set_l2_encap_set,
13243                 (void *)&cmd_set_l2_encap_l2_encap,
13244                 (void *)&cmd_set_l2_encap_ip_version,
13245                 (void *)&cmd_set_l2_encap_ip_version_value,
13246                 (void *)&cmd_set_l2_encap_eth_src,
13247                 (void *)&cmd_set_l2_encap_eth_src_value,
13248                 (void *)&cmd_set_l2_encap_eth_dst,
13249                 (void *)&cmd_set_l2_encap_eth_dst_value,
13250                 NULL,
13251         },
13252 };
13253
13254 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13255         .f = cmd_set_l2_encap_parsed,
13256         .data = NULL,
13257         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13258                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13259         .tokens = {
13260                 (void *)&cmd_set_l2_encap_set,
13261                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13262                 (void *)&cmd_set_l2_encap_ip_version,
13263                 (void *)&cmd_set_l2_encap_ip_version_value,
13264                 (void *)&cmd_set_l2_encap_vlan,
13265                 (void *)&cmd_set_l2_encap_vlan_value,
13266                 (void *)&cmd_set_l2_encap_eth_src,
13267                 (void *)&cmd_set_l2_encap_eth_src_value,
13268                 (void *)&cmd_set_l2_encap_eth_dst,
13269                 (void *)&cmd_set_l2_encap_eth_dst_value,
13270                 NULL,
13271         },
13272 };
13273
13274 /** Set L2 decapsulation details */
13275 struct cmd_set_l2_decap_result {
13276         cmdline_fixed_string_t set;
13277         cmdline_fixed_string_t l2_decap;
13278         cmdline_fixed_string_t pos_token;
13279         uint32_t vlan_present:1;
13280 };
13281
13282 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13283         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13284 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13285         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13286                                  "l2_decap");
13287 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13288         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13289                                  "l2_decap-with-vlan");
13290
13291 static void cmd_set_l2_decap_parsed(void *parsed_result,
13292         __rte_unused struct cmdline *cl,
13293         __rte_unused void *data)
13294 {
13295         struct cmd_set_l2_decap_result *res = parsed_result;
13296
13297         if (strcmp(res->l2_decap, "l2_decap") == 0)
13298                 l2_decap_conf.select_vlan = 0;
13299         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13300                 l2_decap_conf.select_vlan = 1;
13301 }
13302
13303 cmdline_parse_inst_t cmd_set_l2_decap = {
13304         .f = cmd_set_l2_decap_parsed,
13305         .data = NULL,
13306         .help_str = "set l2_decap",
13307         .tokens = {
13308                 (void *)&cmd_set_l2_decap_set,
13309                 (void *)&cmd_set_l2_decap_l2_decap,
13310                 NULL,
13311         },
13312 };
13313
13314 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13315         .f = cmd_set_l2_decap_parsed,
13316         .data = NULL,
13317         .help_str = "set l2_decap-with-vlan",
13318         .tokens = {
13319                 (void *)&cmd_set_l2_decap_set,
13320                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13321                 NULL,
13322         },
13323 };
13324
13325 /** Set MPLSoGRE encapsulation details */
13326 struct cmd_set_mplsogre_encap_result {
13327         cmdline_fixed_string_t set;
13328         cmdline_fixed_string_t mplsogre;
13329         cmdline_fixed_string_t pos_token;
13330         cmdline_fixed_string_t ip_version;
13331         uint32_t vlan_present:1;
13332         uint32_t label;
13333         cmdline_ipaddr_t ip_src;
13334         cmdline_ipaddr_t ip_dst;
13335         uint16_t tci;
13336         struct rte_ether_addr eth_src;
13337         struct rte_ether_addr eth_dst;
13338 };
13339
13340 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13341         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13342                                  "set");
13343 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13344         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13345                                  "mplsogre_encap");
13346 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13347         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13348                                  mplsogre, "mplsogre_encap-with-vlan");
13349 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13350         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13351                                  pos_token, "ip-version");
13352 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13353         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13354                                  ip_version, "ipv4#ipv6");
13355 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13356         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13357                                  pos_token, "label");
13358 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13359         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13360                               RTE_UINT32);
13361 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13362         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13363                                  pos_token, "ip-src");
13364 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13365         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13366 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13367         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13368                                  pos_token, "ip-dst");
13369 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13370         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13371 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13372         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13373                                  pos_token, "vlan-tci");
13374 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13375         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13376                               RTE_UINT16);
13377 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13378         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13379                                  pos_token, "eth-src");
13380 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13381         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13382                                     eth_src);
13383 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13384         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13385                                  pos_token, "eth-dst");
13386 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13387         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13388                                     eth_dst);
13389
13390 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13391         __rte_unused struct cmdline *cl,
13392         __rte_unused void *data)
13393 {
13394         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13395         union {
13396                 uint32_t mplsogre_label;
13397                 uint8_t label[4];
13398         } id = {
13399                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13400         };
13401
13402         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13403                 mplsogre_encap_conf.select_vlan = 0;
13404         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13405                 mplsogre_encap_conf.select_vlan = 1;
13406         if (strcmp(res->ip_version, "ipv4") == 0)
13407                 mplsogre_encap_conf.select_ipv4 = 1;
13408         else if (strcmp(res->ip_version, "ipv6") == 0)
13409                 mplsogre_encap_conf.select_ipv4 = 0;
13410         else
13411                 return;
13412         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13413         if (mplsogre_encap_conf.select_ipv4) {
13414                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13415                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13416         } else {
13417                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13418                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13419         }
13420         if (mplsogre_encap_conf.select_vlan)
13421                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13422         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13423                    RTE_ETHER_ADDR_LEN);
13424         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13425                    RTE_ETHER_ADDR_LEN);
13426 }
13427
13428 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13429         .f = cmd_set_mplsogre_encap_parsed,
13430         .data = NULL,
13431         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13432                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13433                 " eth-dst <eth-dst>",
13434         .tokens = {
13435                 (void *)&cmd_set_mplsogre_encap_set,
13436                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13437                 (void *)&cmd_set_mplsogre_encap_ip_version,
13438                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13439                 (void *)&cmd_set_mplsogre_encap_label,
13440                 (void *)&cmd_set_mplsogre_encap_label_value,
13441                 (void *)&cmd_set_mplsogre_encap_ip_src,
13442                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13443                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13444                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13445                 (void *)&cmd_set_mplsogre_encap_eth_src,
13446                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13447                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13448                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13449                 NULL,
13450         },
13451 };
13452
13453 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13454         .f = cmd_set_mplsogre_encap_parsed,
13455         .data = NULL,
13456         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13457                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13458                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13459         .tokens = {
13460                 (void *)&cmd_set_mplsogre_encap_set,
13461                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13462                 (void *)&cmd_set_mplsogre_encap_ip_version,
13463                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13464                 (void *)&cmd_set_mplsogre_encap_label,
13465                 (void *)&cmd_set_mplsogre_encap_label_value,
13466                 (void *)&cmd_set_mplsogre_encap_ip_src,
13467                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13468                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13469                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13470                 (void *)&cmd_set_mplsogre_encap_vlan,
13471                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13472                 (void *)&cmd_set_mplsogre_encap_eth_src,
13473                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13474                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13475                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13476                 NULL,
13477         },
13478 };
13479
13480 /** Set MPLSoGRE decapsulation details */
13481 struct cmd_set_mplsogre_decap_result {
13482         cmdline_fixed_string_t set;
13483         cmdline_fixed_string_t mplsogre;
13484         cmdline_fixed_string_t pos_token;
13485         cmdline_fixed_string_t ip_version;
13486         uint32_t vlan_present:1;
13487 };
13488
13489 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13490         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13491                                  "set");
13492 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13493         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13494                                  "mplsogre_decap");
13495 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13496         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13497                                  mplsogre, "mplsogre_decap-with-vlan");
13498 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13499         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13500                                  pos_token, "ip-version");
13501 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13502         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13503                                  ip_version, "ipv4#ipv6");
13504
13505 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13506         __rte_unused struct cmdline *cl,
13507         __rte_unused void *data)
13508 {
13509         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13510
13511         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13512                 mplsogre_decap_conf.select_vlan = 0;
13513         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13514                 mplsogre_decap_conf.select_vlan = 1;
13515         if (strcmp(res->ip_version, "ipv4") == 0)
13516                 mplsogre_decap_conf.select_ipv4 = 1;
13517         else if (strcmp(res->ip_version, "ipv6") == 0)
13518                 mplsogre_decap_conf.select_ipv4 = 0;
13519 }
13520
13521 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13522         .f = cmd_set_mplsogre_decap_parsed,
13523         .data = NULL,
13524         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13525         .tokens = {
13526                 (void *)&cmd_set_mplsogre_decap_set,
13527                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13528                 (void *)&cmd_set_mplsogre_decap_ip_version,
13529                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13530                 NULL,
13531         },
13532 };
13533
13534 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13535         .f = cmd_set_mplsogre_decap_parsed,
13536         .data = NULL,
13537         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13538         .tokens = {
13539                 (void *)&cmd_set_mplsogre_decap_set,
13540                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13541                 (void *)&cmd_set_mplsogre_decap_ip_version,
13542                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13543                 NULL,
13544         },
13545 };
13546
13547 /** Set MPLSoUDP encapsulation details */
13548 struct cmd_set_mplsoudp_encap_result {
13549         cmdline_fixed_string_t set;
13550         cmdline_fixed_string_t mplsoudp;
13551         cmdline_fixed_string_t pos_token;
13552         cmdline_fixed_string_t ip_version;
13553         uint32_t vlan_present:1;
13554         uint32_t label;
13555         uint16_t udp_src;
13556         uint16_t udp_dst;
13557         cmdline_ipaddr_t ip_src;
13558         cmdline_ipaddr_t ip_dst;
13559         uint16_t tci;
13560         struct rte_ether_addr eth_src;
13561         struct rte_ether_addr eth_dst;
13562 };
13563
13564 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13565         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13566                                  "set");
13567 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13568         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13569                                  "mplsoudp_encap");
13570 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13571         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13572                                  mplsoudp, "mplsoudp_encap-with-vlan");
13573 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13574         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13575                                  pos_token, "ip-version");
13576 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13577         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13578                                  ip_version, "ipv4#ipv6");
13579 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13580         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13581                                  pos_token, "label");
13582 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13583         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13584                               RTE_UINT32);
13585 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13586         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13587                                  pos_token, "udp-src");
13588 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13589         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13590                               RTE_UINT16);
13591 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13592         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13593                                  pos_token, "udp-dst");
13594 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13595         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13596                               RTE_UINT16);
13597 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13598         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13599                                  pos_token, "ip-src");
13600 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13601         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13602 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13603         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13604                                  pos_token, "ip-dst");
13605 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13606         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13607 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13608         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13609                                  pos_token, "vlan-tci");
13610 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13611         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13612                               RTE_UINT16);
13613 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13614         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13615                                  pos_token, "eth-src");
13616 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13617         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13618                                     eth_src);
13619 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13620         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13621                                  pos_token, "eth-dst");
13622 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13623         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13624                                     eth_dst);
13625
13626 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13627         __rte_unused struct cmdline *cl,
13628         __rte_unused void *data)
13629 {
13630         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13631         union {
13632                 uint32_t mplsoudp_label;
13633                 uint8_t label[4];
13634         } id = {
13635                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13636         };
13637
13638         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13639                 mplsoudp_encap_conf.select_vlan = 0;
13640         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13641                 mplsoudp_encap_conf.select_vlan = 1;
13642         if (strcmp(res->ip_version, "ipv4") == 0)
13643                 mplsoudp_encap_conf.select_ipv4 = 1;
13644         else if (strcmp(res->ip_version, "ipv6") == 0)
13645                 mplsoudp_encap_conf.select_ipv4 = 0;
13646         else
13647                 return;
13648         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13649         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13650         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13651         if (mplsoudp_encap_conf.select_ipv4) {
13652                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13653                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13654         } else {
13655                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13656                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13657         }
13658         if (mplsoudp_encap_conf.select_vlan)
13659                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13660         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13661                    RTE_ETHER_ADDR_LEN);
13662         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13663                    RTE_ETHER_ADDR_LEN);
13664 }
13665
13666 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13667         .f = cmd_set_mplsoudp_encap_parsed,
13668         .data = NULL,
13669         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13670                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13671                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13672         .tokens = {
13673                 (void *)&cmd_set_mplsoudp_encap_set,
13674                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13675                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13676                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13677                 (void *)&cmd_set_mplsoudp_encap_label,
13678                 (void *)&cmd_set_mplsoudp_encap_label_value,
13679                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13680                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13681                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13682                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13683                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13684                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13685                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13686                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13687                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13688                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13689                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13690                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13691                 NULL,
13692         },
13693 };
13694
13695 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13696         .f = cmd_set_mplsoudp_encap_parsed,
13697         .data = NULL,
13698         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13699                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13700                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13701                 " eth-src <eth-src> eth-dst <eth-dst>",
13702         .tokens = {
13703                 (void *)&cmd_set_mplsoudp_encap_set,
13704                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13705                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13706                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13707                 (void *)&cmd_set_mplsoudp_encap_label,
13708                 (void *)&cmd_set_mplsoudp_encap_label_value,
13709                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13710                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13711                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13712                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13713                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13714                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13715                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13716                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13717                 (void *)&cmd_set_mplsoudp_encap_vlan,
13718                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13719                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13720                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13721                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13722                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13723                 NULL,
13724         },
13725 };
13726
13727 /** Set MPLSoUDP decapsulation details */
13728 struct cmd_set_mplsoudp_decap_result {
13729         cmdline_fixed_string_t set;
13730         cmdline_fixed_string_t mplsoudp;
13731         cmdline_fixed_string_t pos_token;
13732         cmdline_fixed_string_t ip_version;
13733         uint32_t vlan_present:1;
13734 };
13735
13736 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13737         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13738                                  "set");
13739 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13740         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13741                                  "mplsoudp_decap");
13742 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13743         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13744                                  mplsoudp, "mplsoudp_decap-with-vlan");
13745 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13746         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13747                                  pos_token, "ip-version");
13748 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13749         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13750                                  ip_version, "ipv4#ipv6");
13751
13752 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13753         __rte_unused struct cmdline *cl,
13754         __rte_unused void *data)
13755 {
13756         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13757
13758         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13759                 mplsoudp_decap_conf.select_vlan = 0;
13760         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13761                 mplsoudp_decap_conf.select_vlan = 1;
13762         if (strcmp(res->ip_version, "ipv4") == 0)
13763                 mplsoudp_decap_conf.select_ipv4 = 1;
13764         else if (strcmp(res->ip_version, "ipv6") == 0)
13765                 mplsoudp_decap_conf.select_ipv4 = 0;
13766 }
13767
13768 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13769         .f = cmd_set_mplsoudp_decap_parsed,
13770         .data = NULL,
13771         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13772         .tokens = {
13773                 (void *)&cmd_set_mplsoudp_decap_set,
13774                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13775                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13776                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13777                 NULL,
13778         },
13779 };
13780
13781 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13782         .f = cmd_set_mplsoudp_decap_parsed,
13783         .data = NULL,
13784         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13785         .tokens = {
13786                 (void *)&cmd_set_mplsoudp_decap_set,
13787                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13788                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13789                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13790                 NULL,
13791         },
13792 };
13793
13794 /** Set connection tracking object common details */
13795 struct cmd_set_conntrack_common_result {
13796         cmdline_fixed_string_t set;
13797         cmdline_fixed_string_t conntrack;
13798         cmdline_fixed_string_t common;
13799         cmdline_fixed_string_t peer;
13800         cmdline_fixed_string_t is_orig;
13801         cmdline_fixed_string_t enable;
13802         cmdline_fixed_string_t live;
13803         cmdline_fixed_string_t sack;
13804         cmdline_fixed_string_t cack;
13805         cmdline_fixed_string_t last_dir;
13806         cmdline_fixed_string_t liberal;
13807         cmdline_fixed_string_t state;
13808         cmdline_fixed_string_t max_ack_win;
13809         cmdline_fixed_string_t retrans;
13810         cmdline_fixed_string_t last_win;
13811         cmdline_fixed_string_t last_seq;
13812         cmdline_fixed_string_t last_ack;
13813         cmdline_fixed_string_t last_end;
13814         cmdline_fixed_string_t last_index;
13815         uint8_t stat;
13816         uint8_t factor;
13817         uint16_t peer_port;
13818         uint32_t is_original;
13819         uint32_t en;
13820         uint32_t is_live;
13821         uint32_t s_ack;
13822         uint32_t c_ack;
13823         uint32_t ld;
13824         uint32_t lb;
13825         uint8_t re_num;
13826         uint8_t li;
13827         uint16_t lw;
13828         uint32_t ls;
13829         uint32_t la;
13830         uint32_t le;
13831 };
13832
13833 cmdline_parse_token_string_t cmd_set_conntrack_set =
13834         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13835                                  set, "set");
13836 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13837         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13838                                  conntrack, "conntrack");
13839 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13840         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13841                                  common, "com");
13842 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13843         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13844                                  peer, "peer");
13845 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13846         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13847                               peer_port, RTE_UINT16);
13848 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13849         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13850                                  is_orig, "is_orig");
13851 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13852         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13853                               is_original, RTE_UINT32);
13854 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13855         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13856                                  enable, "enable");
13857 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13858         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13859                               en, RTE_UINT32);
13860 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
13861         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13862                                  live, "live");
13863 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
13864         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13865                               is_live, RTE_UINT32);
13866 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
13867         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13868                                  sack, "sack");
13869 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
13870         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13871                               s_ack, RTE_UINT32);
13872 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
13873         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13874                                  cack, "cack");
13875 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
13876         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13877                               c_ack, RTE_UINT32);
13878 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
13879         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13880                                  last_dir, "last_dir");
13881 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
13882         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13883                               ld, RTE_UINT32);
13884 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
13885         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13886                                  liberal, "liberal");
13887 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
13888         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13889                               lb, RTE_UINT32);
13890 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
13891         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13892                                  state, "state");
13893 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
13894         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13895                               stat, RTE_UINT8);
13896 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
13897         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13898                                  max_ack_win, "max_ack_win");
13899 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
13900         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13901                               factor, RTE_UINT8);
13902 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
13903         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13904                                  retrans, "r_lim");
13905 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
13906         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13907                               re_num, RTE_UINT8);
13908 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
13909         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13910                                  last_win, "last_win");
13911 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
13912         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13913                               lw, RTE_UINT16);
13914 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
13915         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13916                                  last_seq, "last_seq");
13917 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
13918         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13919                               ls, RTE_UINT32);
13920 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
13921         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13922                                  last_ack, "last_ack");
13923 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
13924         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13925                               la, RTE_UINT32);
13926 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
13927         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13928                                  last_end, "last_end");
13929 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
13930         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13931                               le, RTE_UINT32);
13932 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
13933         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13934                                  last_index, "last_index");
13935 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
13936         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13937                               li, RTE_UINT8);
13938
13939 static void cmd_set_conntrack_common_parsed(void *parsed_result,
13940         __rte_unused struct cmdline *cl,
13941         __rte_unused void *data)
13942 {
13943         struct cmd_set_conntrack_common_result *res = parsed_result;
13944
13945         /* No need to swap to big endian. */
13946         conntrack_context.peer_port = res->peer_port;
13947         conntrack_context.is_original_dir = res->is_original;
13948         conntrack_context.enable = res->en;
13949         conntrack_context.live_connection = res->is_live;
13950         conntrack_context.selective_ack = res->s_ack;
13951         conntrack_context.challenge_ack_passed = res->c_ack;
13952         conntrack_context.last_direction = res->ld;
13953         conntrack_context.liberal_mode = res->lb;
13954         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
13955         conntrack_context.max_ack_window = res->factor;
13956         conntrack_context.retransmission_limit = res->re_num;
13957         conntrack_context.last_window = res->lw;
13958         conntrack_context.last_index =
13959                 (enum rte_flow_conntrack_tcp_last_index)res->li;
13960         conntrack_context.last_seq = res->ls;
13961         conntrack_context.last_ack = res->la;
13962         conntrack_context.last_end = res->le;
13963 }
13964
13965 cmdline_parse_inst_t cmd_set_conntrack_common = {
13966         .f = cmd_set_conntrack_common_parsed,
13967         .data = NULL,
13968         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
13969                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
13970                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
13971                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
13972                 " last_index <flag>",
13973         .tokens = {
13974                 (void *)&cmd_set_conntrack_set,
13975                 (void *)&cmd_set_conntrack_conntrack,
13976                 (void *)&cmd_set_conntrack_common_com,
13977                 (void *)&cmd_set_conntrack_common_peer,
13978                 (void *)&cmd_set_conntrack_common_peer_value,
13979                 (void *)&cmd_set_conntrack_common_is_orig,
13980                 (void *)&cmd_set_conntrack_common_is_orig_value,
13981                 (void *)&cmd_set_conntrack_common_enable,
13982                 (void *)&cmd_set_conntrack_common_enable_value,
13983                 (void *)&cmd_set_conntrack_common_live,
13984                 (void *)&cmd_set_conntrack_common_live_value,
13985                 (void *)&cmd_set_conntrack_common_sack,
13986                 (void *)&cmd_set_conntrack_common_sack_value,
13987                 (void *)&cmd_set_conntrack_common_cack,
13988                 (void *)&cmd_set_conntrack_common_cack_value,
13989                 (void *)&cmd_set_conntrack_common_last_dir,
13990                 (void *)&cmd_set_conntrack_common_last_dir_value,
13991                 (void *)&cmd_set_conntrack_common_liberal,
13992                 (void *)&cmd_set_conntrack_common_liberal_value,
13993                 (void *)&cmd_set_conntrack_common_state,
13994                 (void *)&cmd_set_conntrack_common_state_value,
13995                 (void *)&cmd_set_conntrack_common_max_ackwin,
13996                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
13997                 (void *)&cmd_set_conntrack_common_retrans,
13998                 (void *)&cmd_set_conntrack_common_retrans_value,
13999                 (void *)&cmd_set_conntrack_common_last_win,
14000                 (void *)&cmd_set_conntrack_common_last_win_value,
14001                 (void *)&cmd_set_conntrack_common_last_seq,
14002                 (void *)&cmd_set_conntrack_common_last_seq_value,
14003                 (void *)&cmd_set_conntrack_common_last_ack,
14004                 (void *)&cmd_set_conntrack_common_last_ack_value,
14005                 (void *)&cmd_set_conntrack_common_last_end,
14006                 (void *)&cmd_set_conntrack_common_last_end_value,
14007                 (void *)&cmd_set_conntrack_common_last_index,
14008                 (void *)&cmd_set_conntrack_common_last_index_value,
14009                 NULL,
14010         },
14011 };
14012
14013 /** Set connection tracking object both directions' details */
14014 struct cmd_set_conntrack_dir_result {
14015         cmdline_fixed_string_t set;
14016         cmdline_fixed_string_t conntrack;
14017         cmdline_fixed_string_t dir;
14018         cmdline_fixed_string_t scale;
14019         cmdline_fixed_string_t fin;
14020         cmdline_fixed_string_t ack_seen;
14021         cmdline_fixed_string_t unack;
14022         cmdline_fixed_string_t sent_end;
14023         cmdline_fixed_string_t reply_end;
14024         cmdline_fixed_string_t max_win;
14025         cmdline_fixed_string_t max_ack;
14026         uint32_t factor;
14027         uint32_t f;
14028         uint32_t as;
14029         uint32_t un;
14030         uint32_t se;
14031         uint32_t re;
14032         uint32_t mw;
14033         uint32_t ma;
14034 };
14035
14036 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14037         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14038                                  set, "set");
14039 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14040         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14041                                  conntrack, "conntrack");
14042 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14043         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14044                                  dir, "orig#rply");
14045 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14046         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14047                                  scale, "scale");
14048 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14049         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14050                               factor, RTE_UINT32);
14051 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14052         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14053                                  fin, "fin");
14054 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14055         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14056                               f, RTE_UINT32);
14057 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14058         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14059                                  ack_seen, "acked");
14060 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14061         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14062                               as, RTE_UINT32);
14063 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14064         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14065                                  unack, "unack_data");
14066 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14067         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14068                               un, RTE_UINT32);
14069 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14070         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14071                                  sent_end, "sent_end");
14072 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14073         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14074                               se, RTE_UINT32);
14075 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14076         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14077                                  reply_end, "reply_end");
14078 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14079         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14080                               re, RTE_UINT32);
14081 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14082         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14083                                  max_win, "max_win");
14084 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14085         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14086                               mw, RTE_UINT32);
14087 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14088         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14089                                  max_ack, "max_ack");
14090 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14091         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14092                               ma, RTE_UINT32);
14093
14094 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14095         __rte_unused struct cmdline *cl,
14096         __rte_unused void *data)
14097 {
14098         struct cmd_set_conntrack_dir_result *res = parsed_result;
14099         struct rte_flow_tcp_dir_param *dir = NULL;
14100
14101         if (strcmp(res->dir, "orig") == 0)
14102                 dir = &conntrack_context.original_dir;
14103         else if (strcmp(res->dir, "rply") == 0)
14104                 dir = &conntrack_context.reply_dir;
14105         else
14106                 return;
14107         dir->scale = res->factor;
14108         dir->close_initiated = res->f;
14109         dir->last_ack_seen = res->as;
14110         dir->data_unacked = res->un;
14111         dir->sent_end = res->se;
14112         dir->reply_end = res->re;
14113         dir->max_ack = res->ma;
14114         dir->max_win = res->mw;
14115 }
14116
14117 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14118         .f = cmd_set_conntrack_dir_parsed,
14119         .data = NULL,
14120         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14121                     " acked <seen> unack_data <unack> sent_end <sent>"
14122                     " reply_end <reply> max_win <win> max_ack <ack>",
14123         .tokens = {
14124                 (void *)&cmd_set_conntrack_set,
14125                 (void *)&cmd_set_conntrack_conntrack,
14126                 (void *)&cmd_set_conntrack_dir_dir,
14127                 (void *)&cmd_set_conntrack_dir_scale,
14128                 (void *)&cmd_set_conntrack_dir_scale_value,
14129                 (void *)&cmd_set_conntrack_dir_fin,
14130                 (void *)&cmd_set_conntrack_dir_fin_value,
14131                 (void *)&cmd_set_conntrack_dir_ack,
14132                 (void *)&cmd_set_conntrack_dir_ack_value,
14133                 (void *)&cmd_set_conntrack_dir_unack_data,
14134                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14135                 (void *)&cmd_set_conntrack_dir_sent_end,
14136                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14137                 (void *)&cmd_set_conntrack_dir_reply_end,
14138                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14139                 (void *)&cmd_set_conntrack_dir_max_win,
14140                 (void *)&cmd_set_conntrack_dir_max_win_value,
14141                 (void *)&cmd_set_conntrack_dir_max_ack,
14142                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14143                 NULL,
14144         },
14145 };
14146
14147 /* Strict link priority scheduling mode setting */
14148 static void
14149 cmd_strict_link_prio_parsed(
14150         void *parsed_result,
14151         __rte_unused struct cmdline *cl,
14152         __rte_unused void *data)
14153 {
14154         struct cmd_vf_tc_bw_result *res = parsed_result;
14155         int ret = -ENOTSUP;
14156
14157         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14158                 return;
14159
14160 #ifdef RTE_NET_I40E
14161         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14162 #endif
14163
14164         switch (ret) {
14165         case 0:
14166                 break;
14167         case -EINVAL:
14168                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14169                 break;
14170         case -ENODEV:
14171                 printf("invalid port_id %d\n", res->port_id);
14172                 break;
14173         case -ENOTSUP:
14174                 printf("function not implemented\n");
14175                 break;
14176         default:
14177                 printf("programming error: (%s)\n", strerror(-ret));
14178         }
14179 }
14180
14181 cmdline_parse_inst_t cmd_strict_link_prio = {
14182         .f = cmd_strict_link_prio_parsed,
14183         .data = NULL,
14184         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14185         .tokens = {
14186                 (void *)&cmd_vf_tc_bw_set,
14187                 (void *)&cmd_vf_tc_bw_tx,
14188                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14189                 (void *)&cmd_vf_tc_bw_port_id,
14190                 (void *)&cmd_vf_tc_bw_tc_map,
14191                 NULL,
14192         },
14193 };
14194
14195 /* Load dynamic device personalization*/
14196 struct cmd_ddp_add_result {
14197         cmdline_fixed_string_t ddp;
14198         cmdline_fixed_string_t add;
14199         portid_t port_id;
14200         char filepath[];
14201 };
14202
14203 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14204         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14205 cmdline_parse_token_string_t cmd_ddp_add_add =
14206         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14207 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14208         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14209                 RTE_UINT16);
14210 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14211         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14212
14213 static void
14214 cmd_ddp_add_parsed(
14215         void *parsed_result,
14216         __rte_unused struct cmdline *cl,
14217         __rte_unused void *data)
14218 {
14219         struct cmd_ddp_add_result *res = parsed_result;
14220         uint8_t *buff;
14221         uint32_t size;
14222         char *filepath;
14223         char *file_fld[2];
14224         int file_num;
14225         int ret = -ENOTSUP;
14226
14227         if (!all_ports_stopped()) {
14228                 printf("Please stop all ports first\n");
14229                 return;
14230         }
14231
14232         filepath = strdup(res->filepath);
14233         if (filepath == NULL) {
14234                 printf("Failed to allocate memory\n");
14235                 return;
14236         }
14237         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14238
14239         buff = open_file(file_fld[0], &size);
14240         if (!buff) {
14241                 free((void *)filepath);
14242                 return;
14243         }
14244
14245 #ifdef RTE_NET_I40E
14246         if (ret == -ENOTSUP)
14247                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14248                                                buff, size,
14249                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14250 #endif
14251
14252         if (ret == -EEXIST)
14253                 printf("Profile has already existed.\n");
14254         else if (ret < 0)
14255                 printf("Failed to load profile.\n");
14256         else if (file_num == 2)
14257                 save_file(file_fld[1], buff, size);
14258
14259         close_file(buff);
14260         free((void *)filepath);
14261 }
14262
14263 cmdline_parse_inst_t cmd_ddp_add = {
14264         .f = cmd_ddp_add_parsed,
14265         .data = NULL,
14266         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14267         .tokens = {
14268                 (void *)&cmd_ddp_add_ddp,
14269                 (void *)&cmd_ddp_add_add,
14270                 (void *)&cmd_ddp_add_port_id,
14271                 (void *)&cmd_ddp_add_filepath,
14272                 NULL,
14273         },
14274 };
14275
14276 /* Delete dynamic device personalization*/
14277 struct cmd_ddp_del_result {
14278         cmdline_fixed_string_t ddp;
14279         cmdline_fixed_string_t del;
14280         portid_t port_id;
14281         char filepath[];
14282 };
14283
14284 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14285         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14286 cmdline_parse_token_string_t cmd_ddp_del_del =
14287         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14288 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14289         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14290 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14291         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14292
14293 static void
14294 cmd_ddp_del_parsed(
14295         void *parsed_result,
14296         __rte_unused struct cmdline *cl,
14297         __rte_unused void *data)
14298 {
14299         struct cmd_ddp_del_result *res = parsed_result;
14300         uint8_t *buff;
14301         uint32_t size;
14302         int ret = -ENOTSUP;
14303
14304         if (!all_ports_stopped()) {
14305                 printf("Please stop all ports first\n");
14306                 return;
14307         }
14308
14309         buff = open_file(res->filepath, &size);
14310         if (!buff)
14311                 return;
14312
14313 #ifdef RTE_NET_I40E
14314         if (ret == -ENOTSUP)
14315                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14316                                                buff, size,
14317                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14318 #endif
14319
14320         if (ret == -EACCES)
14321                 printf("Profile does not exist.\n");
14322         else if (ret < 0)
14323                 printf("Failed to delete profile.\n");
14324
14325         close_file(buff);
14326 }
14327
14328 cmdline_parse_inst_t cmd_ddp_del = {
14329         .f = cmd_ddp_del_parsed,
14330         .data = NULL,
14331         .help_str = "ddp del <port_id> <backup_profile_path>",
14332         .tokens = {
14333                 (void *)&cmd_ddp_del_ddp,
14334                 (void *)&cmd_ddp_del_del,
14335                 (void *)&cmd_ddp_del_port_id,
14336                 (void *)&cmd_ddp_del_filepath,
14337                 NULL,
14338         },
14339 };
14340
14341 /* Get dynamic device personalization profile info */
14342 struct cmd_ddp_info_result {
14343         cmdline_fixed_string_t ddp;
14344         cmdline_fixed_string_t get;
14345         cmdline_fixed_string_t info;
14346         char filepath[];
14347 };
14348
14349 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14350         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14351 cmdline_parse_token_string_t cmd_ddp_info_get =
14352         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14353 cmdline_parse_token_string_t cmd_ddp_info_info =
14354         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14355 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14356         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14357
14358 static void
14359 cmd_ddp_info_parsed(
14360         void *parsed_result,
14361         __rte_unused struct cmdline *cl,
14362         __rte_unused void *data)
14363 {
14364         struct cmd_ddp_info_result *res = parsed_result;
14365         uint8_t *pkg;
14366         uint32_t pkg_size;
14367         int ret = -ENOTSUP;
14368 #ifdef RTE_NET_I40E
14369         uint32_t i, j, n;
14370         uint8_t *buff;
14371         uint32_t buff_size = 0;
14372         struct rte_pmd_i40e_profile_info info;
14373         uint32_t dev_num = 0;
14374         struct rte_pmd_i40e_ddp_device_id *devs;
14375         uint32_t proto_num = 0;
14376         struct rte_pmd_i40e_proto_info *proto = NULL;
14377         uint32_t pctype_num = 0;
14378         struct rte_pmd_i40e_ptype_info *pctype;
14379         uint32_t ptype_num = 0;
14380         struct rte_pmd_i40e_ptype_info *ptype;
14381         uint8_t proto_id;
14382
14383 #endif
14384
14385         pkg = open_file(res->filepath, &pkg_size);
14386         if (!pkg)
14387                 return;
14388
14389 #ifdef RTE_NET_I40E
14390         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14391                                 (uint8_t *)&info, sizeof(info),
14392                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14393         if (!ret) {
14394                 printf("Global Track id:       0x%x\n", info.track_id);
14395                 printf("Global Version:        %d.%d.%d.%d\n",
14396                         info.version.major,
14397                         info.version.minor,
14398                         info.version.update,
14399                         info.version.draft);
14400                 printf("Global Package name:   %s\n\n", info.name);
14401         }
14402
14403         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14404                                 (uint8_t *)&info, sizeof(info),
14405                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14406         if (!ret) {
14407                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14408                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14409                         info.version.major,
14410                         info.version.minor,
14411                         info.version.update,
14412                         info.version.draft);
14413                 printf("i40e Profile name:     %s\n\n", info.name);
14414         }
14415
14416         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14417                                 (uint8_t *)&buff_size, sizeof(buff_size),
14418                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14419         if (!ret && buff_size) {
14420                 buff = (uint8_t *)malloc(buff_size);
14421                 if (buff) {
14422                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14423                                                 buff, buff_size,
14424                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14425                         if (!ret)
14426                                 printf("Package Notes:\n%s\n\n", buff);
14427                         free(buff);
14428                 }
14429         }
14430
14431         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14432                                 (uint8_t *)&dev_num, sizeof(dev_num),
14433                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14434         if (!ret && dev_num) {
14435                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14436                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14437                 if (devs) {
14438                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14439                                                 (uint8_t *)devs, buff_size,
14440                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14441                         if (!ret) {
14442                                 printf("List of supported devices:\n");
14443                                 for (i = 0; i < dev_num; i++) {
14444                                         printf("  %04X:%04X %04X:%04X\n",
14445                                                 devs[i].vendor_dev_id >> 16,
14446                                                 devs[i].vendor_dev_id & 0xFFFF,
14447                                                 devs[i].sub_vendor_dev_id >> 16,
14448                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14449                                 }
14450                                 printf("\n");
14451                         }
14452                         free(devs);
14453                 }
14454         }
14455
14456         /* get information about protocols and packet types */
14457         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14458                 (uint8_t *)&proto_num, sizeof(proto_num),
14459                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14460         if (ret || !proto_num)
14461                 goto no_print_return;
14462
14463         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14464         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14465         if (!proto)
14466                 goto no_print_return;
14467
14468         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14469                                         buff_size,
14470                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14471         if (!ret) {
14472                 printf("List of used protocols:\n");
14473                 for (i = 0; i < proto_num; i++)
14474                         printf("  %2u: %s\n", proto[i].proto_id,
14475                                proto[i].name);
14476                 printf("\n");
14477         }
14478         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14479                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14480                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14481         if (ret || !pctype_num)
14482                 goto no_print_pctypes;
14483
14484         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14485         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14486         if (!pctype)
14487                 goto no_print_pctypes;
14488
14489         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14490                                         buff_size,
14491                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14492         if (ret) {
14493                 free(pctype);
14494                 goto no_print_pctypes;
14495         }
14496
14497         printf("List of defined packet classification types:\n");
14498         for (i = 0; i < pctype_num; i++) {
14499                 printf("  %2u:", pctype[i].ptype_id);
14500                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14501                         proto_id = pctype[i].protocols[j];
14502                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14503                                 for (n = 0; n < proto_num; n++) {
14504                                         if (proto[n].proto_id == proto_id) {
14505                                                 printf(" %s", proto[n].name);
14506                                                 break;
14507                                         }
14508                                 }
14509                         }
14510                 }
14511                 printf("\n");
14512         }
14513         printf("\n");
14514         free(pctype);
14515
14516 no_print_pctypes:
14517
14518         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14519                                         sizeof(ptype_num),
14520                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14521         if (ret || !ptype_num)
14522                 goto no_print_return;
14523
14524         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14525         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14526         if (!ptype)
14527                 goto no_print_return;
14528
14529         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14530                                         buff_size,
14531                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14532         if (ret) {
14533                 free(ptype);
14534                 goto no_print_return;
14535         }
14536         printf("List of defined packet types:\n");
14537         for (i = 0; i < ptype_num; i++) {
14538                 printf("  %2u:", ptype[i].ptype_id);
14539                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14540                         proto_id = ptype[i].protocols[j];
14541                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14542                                 for (n = 0; n < proto_num; n++) {
14543                                         if (proto[n].proto_id == proto_id) {
14544                                                 printf(" %s", proto[n].name);
14545                                                 break;
14546                                         }
14547                                 }
14548                         }
14549                 }
14550                 printf("\n");
14551         }
14552         free(ptype);
14553         printf("\n");
14554
14555         ret = 0;
14556 no_print_return:
14557         if (proto)
14558                 free(proto);
14559 #endif
14560         if (ret == -ENOTSUP)
14561                 printf("Function not supported in PMD driver\n");
14562         close_file(pkg);
14563 }
14564
14565 cmdline_parse_inst_t cmd_ddp_get_info = {
14566         .f = cmd_ddp_info_parsed,
14567         .data = NULL,
14568         .help_str = "ddp get info <profile_path>",
14569         .tokens = {
14570                 (void *)&cmd_ddp_info_ddp,
14571                 (void *)&cmd_ddp_info_get,
14572                 (void *)&cmd_ddp_info_info,
14573                 (void *)&cmd_ddp_info_filepath,
14574                 NULL,
14575         },
14576 };
14577
14578 /* Get dynamic device personalization profile info list*/
14579 #define PROFILE_INFO_SIZE 48
14580 #define MAX_PROFILE_NUM 16
14581
14582 struct cmd_ddp_get_list_result {
14583         cmdline_fixed_string_t ddp;
14584         cmdline_fixed_string_t get;
14585         cmdline_fixed_string_t list;
14586         portid_t port_id;
14587 };
14588
14589 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14590         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14591 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14592         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14593 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14594         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14595 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14596         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14597                 RTE_UINT16);
14598
14599 static void
14600 cmd_ddp_get_list_parsed(
14601         __rte_unused void *parsed_result,
14602         __rte_unused struct cmdline *cl,
14603         __rte_unused void *data)
14604 {
14605 #ifdef RTE_NET_I40E
14606         struct cmd_ddp_get_list_result *res = parsed_result;
14607         struct rte_pmd_i40e_profile_list *p_list;
14608         struct rte_pmd_i40e_profile_info *p_info;
14609         uint32_t p_num;
14610         uint32_t size;
14611         uint32_t i;
14612 #endif
14613         int ret = -ENOTSUP;
14614
14615 #ifdef RTE_NET_I40E
14616         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14617         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14618         if (!p_list) {
14619                 printf("%s: Failed to malloc buffer\n", __func__);
14620                 return;
14621         }
14622
14623         if (ret == -ENOTSUP)
14624                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14625                                                 (uint8_t *)p_list, size);
14626
14627         if (!ret) {
14628                 p_num = p_list->p_count;
14629                 printf("Profile number is: %d\n\n", p_num);
14630
14631                 for (i = 0; i < p_num; i++) {
14632                         p_info = &p_list->p_info[i];
14633                         printf("Profile %d:\n", i);
14634                         printf("Track id:     0x%x\n", p_info->track_id);
14635                         printf("Version:      %d.%d.%d.%d\n",
14636                                p_info->version.major,
14637                                p_info->version.minor,
14638                                p_info->version.update,
14639                                p_info->version.draft);
14640                         printf("Profile name: %s\n\n", p_info->name);
14641                 }
14642         }
14643
14644         free(p_list);
14645 #endif
14646
14647         if (ret < 0)
14648                 printf("Failed to get ddp list\n");
14649 }
14650
14651 cmdline_parse_inst_t cmd_ddp_get_list = {
14652         .f = cmd_ddp_get_list_parsed,
14653         .data = NULL,
14654         .help_str = "ddp get list <port_id>",
14655         .tokens = {
14656                 (void *)&cmd_ddp_get_list_ddp,
14657                 (void *)&cmd_ddp_get_list_get,
14658                 (void *)&cmd_ddp_get_list_list,
14659                 (void *)&cmd_ddp_get_list_port_id,
14660                 NULL,
14661         },
14662 };
14663
14664 /* Configure input set */
14665 struct cmd_cfg_input_set_result {
14666         cmdline_fixed_string_t port;
14667         cmdline_fixed_string_t cfg;
14668         portid_t port_id;
14669         cmdline_fixed_string_t pctype;
14670         uint8_t pctype_id;
14671         cmdline_fixed_string_t inset_type;
14672         cmdline_fixed_string_t opt;
14673         cmdline_fixed_string_t field;
14674         uint8_t field_idx;
14675 };
14676
14677 static void
14678 cmd_cfg_input_set_parsed(
14679         __rte_unused void *parsed_result,
14680         __rte_unused struct cmdline *cl,
14681         __rte_unused void *data)
14682 {
14683 #ifdef RTE_NET_I40E
14684         struct cmd_cfg_input_set_result *res = parsed_result;
14685         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14686         struct rte_pmd_i40e_inset inset;
14687 #endif
14688         int ret = -ENOTSUP;
14689
14690         if (!all_ports_stopped()) {
14691                 printf("Please stop all ports first\n");
14692                 return;
14693         }
14694
14695 #ifdef RTE_NET_I40E
14696         if (!strcmp(res->inset_type, "hash_inset"))
14697                 inset_type = INSET_HASH;
14698         else if (!strcmp(res->inset_type, "fdir_inset"))
14699                 inset_type = INSET_FDIR;
14700         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14701                 inset_type = INSET_FDIR_FLX;
14702         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14703                                      &inset, inset_type);
14704         if (ret) {
14705                 printf("Failed to get input set.\n");
14706                 return;
14707         }
14708
14709         if (!strcmp(res->opt, "get")) {
14710                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14711                                                    res->field_idx);
14712                 if (ret)
14713                         printf("Field index %d is enabled.\n", res->field_idx);
14714                 else
14715                         printf("Field index %d is disabled.\n", res->field_idx);
14716                 return;
14717         } else if (!strcmp(res->opt, "set"))
14718                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14719                                                    res->field_idx);
14720         else if (!strcmp(res->opt, "clear"))
14721                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14722                                                      res->field_idx);
14723         if (ret) {
14724                 printf("Failed to configure input set field.\n");
14725                 return;
14726         }
14727
14728         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14729                                      &inset, inset_type);
14730         if (ret) {
14731                 printf("Failed to set input set.\n");
14732                 return;
14733         }
14734 #endif
14735
14736         if (ret == -ENOTSUP)
14737                 printf("Function not supported\n");
14738 }
14739
14740 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14741         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14742                                  port, "port");
14743 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14744         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14745                                  cfg, "config");
14746 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14747         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14748                               port_id, RTE_UINT16);
14749 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14750         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14751                                  pctype, "pctype");
14752 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14753         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14754                               pctype_id, RTE_UINT8);
14755 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14756         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14757                                  inset_type,
14758                                  "hash_inset#fdir_inset#fdir_flx_inset");
14759 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14760         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14761                                  opt, "get#set#clear");
14762 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14763         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14764                                  field, "field");
14765 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14766         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14767                               field_idx, RTE_UINT8);
14768
14769 cmdline_parse_inst_t cmd_cfg_input_set = {
14770         .f = cmd_cfg_input_set_parsed,
14771         .data = NULL,
14772         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14773                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14774         .tokens = {
14775                 (void *)&cmd_cfg_input_set_port,
14776                 (void *)&cmd_cfg_input_set_cfg,
14777                 (void *)&cmd_cfg_input_set_port_id,
14778                 (void *)&cmd_cfg_input_set_pctype,
14779                 (void *)&cmd_cfg_input_set_pctype_id,
14780                 (void *)&cmd_cfg_input_set_inset_type,
14781                 (void *)&cmd_cfg_input_set_opt,
14782                 (void *)&cmd_cfg_input_set_field,
14783                 (void *)&cmd_cfg_input_set_field_idx,
14784                 NULL,
14785         },
14786 };
14787
14788 /* Clear input set */
14789 struct cmd_clear_input_set_result {
14790         cmdline_fixed_string_t port;
14791         cmdline_fixed_string_t cfg;
14792         portid_t port_id;
14793         cmdline_fixed_string_t pctype;
14794         uint8_t pctype_id;
14795         cmdline_fixed_string_t inset_type;
14796         cmdline_fixed_string_t clear;
14797         cmdline_fixed_string_t all;
14798 };
14799
14800 static void
14801 cmd_clear_input_set_parsed(
14802         __rte_unused void *parsed_result,
14803         __rte_unused struct cmdline *cl,
14804         __rte_unused void *data)
14805 {
14806 #ifdef RTE_NET_I40E
14807         struct cmd_clear_input_set_result *res = parsed_result;
14808         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14809         struct rte_pmd_i40e_inset inset;
14810 #endif
14811         int ret = -ENOTSUP;
14812
14813         if (!all_ports_stopped()) {
14814                 printf("Please stop all ports first\n");
14815                 return;
14816         }
14817
14818 #ifdef RTE_NET_I40E
14819         if (!strcmp(res->inset_type, "hash_inset"))
14820                 inset_type = INSET_HASH;
14821         else if (!strcmp(res->inset_type, "fdir_inset"))
14822                 inset_type = INSET_FDIR;
14823         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14824                 inset_type = INSET_FDIR_FLX;
14825
14826         memset(&inset, 0, sizeof(inset));
14827
14828         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14829                                      &inset, inset_type);
14830         if (ret) {
14831                 printf("Failed to clear input set.\n");
14832                 return;
14833         }
14834
14835 #endif
14836
14837         if (ret == -ENOTSUP)
14838                 printf("Function not supported\n");
14839 }
14840
14841 cmdline_parse_token_string_t cmd_clear_input_set_port =
14842         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14843                                  port, "port");
14844 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14845         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14846                                  cfg, "config");
14847 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14848         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14849                               port_id, RTE_UINT16);
14850 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14851         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14852                                  pctype, "pctype");
14853 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14854         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14855                               pctype_id, RTE_UINT8);
14856 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14857         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14858                                  inset_type,
14859                                  "hash_inset#fdir_inset#fdir_flx_inset");
14860 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14861         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14862                                  clear, "clear");
14863 cmdline_parse_token_string_t cmd_clear_input_set_all =
14864         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14865                                  all, "all");
14866
14867 cmdline_parse_inst_t cmd_clear_input_set = {
14868         .f = cmd_clear_input_set_parsed,
14869         .data = NULL,
14870         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14871                     "fdir_inset|fdir_flx_inset clear all",
14872         .tokens = {
14873                 (void *)&cmd_clear_input_set_port,
14874                 (void *)&cmd_clear_input_set_cfg,
14875                 (void *)&cmd_clear_input_set_port_id,
14876                 (void *)&cmd_clear_input_set_pctype,
14877                 (void *)&cmd_clear_input_set_pctype_id,
14878                 (void *)&cmd_clear_input_set_inset_type,
14879                 (void *)&cmd_clear_input_set_clear,
14880                 (void *)&cmd_clear_input_set_all,
14881                 NULL,
14882         },
14883 };
14884
14885 /* show vf stats */
14886
14887 /* Common result structure for show vf stats */
14888 struct cmd_show_vf_stats_result {
14889         cmdline_fixed_string_t show;
14890         cmdline_fixed_string_t vf;
14891         cmdline_fixed_string_t stats;
14892         portid_t port_id;
14893         uint16_t vf_id;
14894 };
14895
14896 /* Common CLI fields show vf stats*/
14897 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14898         TOKEN_STRING_INITIALIZER
14899                 (struct cmd_show_vf_stats_result,
14900                  show, "show");
14901 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14902         TOKEN_STRING_INITIALIZER
14903                 (struct cmd_show_vf_stats_result,
14904                  vf, "vf");
14905 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14906         TOKEN_STRING_INITIALIZER
14907                 (struct cmd_show_vf_stats_result,
14908                  stats, "stats");
14909 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14910         TOKEN_NUM_INITIALIZER
14911                 (struct cmd_show_vf_stats_result,
14912                  port_id, RTE_UINT16);
14913 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14914         TOKEN_NUM_INITIALIZER
14915                 (struct cmd_show_vf_stats_result,
14916                  vf_id, RTE_UINT16);
14917
14918 static void
14919 cmd_show_vf_stats_parsed(
14920         void *parsed_result,
14921         __rte_unused struct cmdline *cl,
14922         __rte_unused void *data)
14923 {
14924         struct cmd_show_vf_stats_result *res = parsed_result;
14925         struct rte_eth_stats stats;
14926         int ret = -ENOTSUP;
14927         static const char *nic_stats_border = "########################";
14928
14929         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14930                 return;
14931
14932         memset(&stats, 0, sizeof(stats));
14933
14934 #ifdef RTE_NET_I40E
14935         if (ret == -ENOTSUP)
14936                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14937                                                 res->vf_id,
14938                                                 &stats);
14939 #endif
14940 #ifdef RTE_NET_BNXT
14941         if (ret == -ENOTSUP)
14942                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14943                                                 res->vf_id,
14944                                                 &stats);
14945 #endif
14946
14947         switch (ret) {
14948         case 0:
14949                 break;
14950         case -EINVAL:
14951                 printf("invalid vf_id %d\n", res->vf_id);
14952                 break;
14953         case -ENODEV:
14954                 printf("invalid port_id %d\n", res->port_id);
14955                 break;
14956         case -ENOTSUP:
14957                 printf("function not implemented\n");
14958                 break;
14959         default:
14960                 printf("programming error: (%s)\n", strerror(-ret));
14961         }
14962
14963         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14964                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14965
14966         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14967                "%-"PRIu64"\n",
14968                stats.ipackets, stats.imissed, stats.ibytes);
14969         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14970         printf("  RX-nombuf:  %-10"PRIu64"\n",
14971                stats.rx_nombuf);
14972         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14973                "%-"PRIu64"\n",
14974                stats.opackets, stats.oerrors, stats.obytes);
14975
14976         printf("  %s############################%s\n",
14977                                nic_stats_border, nic_stats_border);
14978 }
14979
14980 cmdline_parse_inst_t cmd_show_vf_stats = {
14981         .f = cmd_show_vf_stats_parsed,
14982         .data = NULL,
14983         .help_str = "show vf stats <port_id> <vf_id>",
14984         .tokens = {
14985                 (void *)&cmd_show_vf_stats_show,
14986                 (void *)&cmd_show_vf_stats_vf,
14987                 (void *)&cmd_show_vf_stats_stats,
14988                 (void *)&cmd_show_vf_stats_port_id,
14989                 (void *)&cmd_show_vf_stats_vf_id,
14990                 NULL,
14991         },
14992 };
14993
14994 /* clear vf stats */
14995
14996 /* Common result structure for clear vf stats */
14997 struct cmd_clear_vf_stats_result {
14998         cmdline_fixed_string_t clear;
14999         cmdline_fixed_string_t vf;
15000         cmdline_fixed_string_t stats;
15001         portid_t port_id;
15002         uint16_t vf_id;
15003 };
15004
15005 /* Common CLI fields clear vf stats*/
15006 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15007         TOKEN_STRING_INITIALIZER
15008                 (struct cmd_clear_vf_stats_result,
15009                  clear, "clear");
15010 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15011         TOKEN_STRING_INITIALIZER
15012                 (struct cmd_clear_vf_stats_result,
15013                  vf, "vf");
15014 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15015         TOKEN_STRING_INITIALIZER
15016                 (struct cmd_clear_vf_stats_result,
15017                  stats, "stats");
15018 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15019         TOKEN_NUM_INITIALIZER
15020                 (struct cmd_clear_vf_stats_result,
15021                  port_id, RTE_UINT16);
15022 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15023         TOKEN_NUM_INITIALIZER
15024                 (struct cmd_clear_vf_stats_result,
15025                  vf_id, RTE_UINT16);
15026
15027 static void
15028 cmd_clear_vf_stats_parsed(
15029         void *parsed_result,
15030         __rte_unused struct cmdline *cl,
15031         __rte_unused void *data)
15032 {
15033         struct cmd_clear_vf_stats_result *res = parsed_result;
15034         int ret = -ENOTSUP;
15035
15036         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15037                 return;
15038
15039 #ifdef RTE_NET_I40E
15040         if (ret == -ENOTSUP)
15041                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15042                                                   res->vf_id);
15043 #endif
15044 #ifdef RTE_NET_BNXT
15045         if (ret == -ENOTSUP)
15046                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15047                                                   res->vf_id);
15048 #endif
15049
15050         switch (ret) {
15051         case 0:
15052                 break;
15053         case -EINVAL:
15054                 printf("invalid vf_id %d\n", res->vf_id);
15055                 break;
15056         case -ENODEV:
15057                 printf("invalid port_id %d\n", res->port_id);
15058                 break;
15059         case -ENOTSUP:
15060                 printf("function not implemented\n");
15061                 break;
15062         default:
15063                 printf("programming error: (%s)\n", strerror(-ret));
15064         }
15065 }
15066
15067 cmdline_parse_inst_t cmd_clear_vf_stats = {
15068         .f = cmd_clear_vf_stats_parsed,
15069         .data = NULL,
15070         .help_str = "clear vf stats <port_id> <vf_id>",
15071         .tokens = {
15072                 (void *)&cmd_clear_vf_stats_clear,
15073                 (void *)&cmd_clear_vf_stats_vf,
15074                 (void *)&cmd_clear_vf_stats_stats,
15075                 (void *)&cmd_clear_vf_stats_port_id,
15076                 (void *)&cmd_clear_vf_stats_vf_id,
15077                 NULL,
15078         },
15079 };
15080
15081 /* port config pctype mapping reset */
15082
15083 /* Common result structure for port config pctype mapping reset */
15084 struct cmd_pctype_mapping_reset_result {
15085         cmdline_fixed_string_t port;
15086         cmdline_fixed_string_t config;
15087         portid_t port_id;
15088         cmdline_fixed_string_t pctype;
15089         cmdline_fixed_string_t mapping;
15090         cmdline_fixed_string_t reset;
15091 };
15092
15093 /* Common CLI fields for port config pctype mapping reset*/
15094 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15095         TOKEN_STRING_INITIALIZER
15096                 (struct cmd_pctype_mapping_reset_result,
15097                  port, "port");
15098 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15099         TOKEN_STRING_INITIALIZER
15100                 (struct cmd_pctype_mapping_reset_result,
15101                  config, "config");
15102 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15103         TOKEN_NUM_INITIALIZER
15104                 (struct cmd_pctype_mapping_reset_result,
15105                  port_id, RTE_UINT16);
15106 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15107         TOKEN_STRING_INITIALIZER
15108                 (struct cmd_pctype_mapping_reset_result,
15109                  pctype, "pctype");
15110 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15111         TOKEN_STRING_INITIALIZER
15112                 (struct cmd_pctype_mapping_reset_result,
15113                  mapping, "mapping");
15114 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15115         TOKEN_STRING_INITIALIZER
15116                 (struct cmd_pctype_mapping_reset_result,
15117                  reset, "reset");
15118
15119 static void
15120 cmd_pctype_mapping_reset_parsed(
15121         void *parsed_result,
15122         __rte_unused struct cmdline *cl,
15123         __rte_unused void *data)
15124 {
15125         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15126         int ret = -ENOTSUP;
15127
15128         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15129                 return;
15130
15131 #ifdef RTE_NET_I40E
15132         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15133 #endif
15134
15135         switch (ret) {
15136         case 0:
15137                 break;
15138         case -ENODEV:
15139                 printf("invalid port_id %d\n", res->port_id);
15140                 break;
15141         case -ENOTSUP:
15142                 printf("function not implemented\n");
15143                 break;
15144         default:
15145                 printf("programming error: (%s)\n", strerror(-ret));
15146         }
15147 }
15148
15149 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15150         .f = cmd_pctype_mapping_reset_parsed,
15151         .data = NULL,
15152         .help_str = "port config <port_id> pctype mapping reset",
15153         .tokens = {
15154                 (void *)&cmd_pctype_mapping_reset_port,
15155                 (void *)&cmd_pctype_mapping_reset_config,
15156                 (void *)&cmd_pctype_mapping_reset_port_id,
15157                 (void *)&cmd_pctype_mapping_reset_pctype,
15158                 (void *)&cmd_pctype_mapping_reset_mapping,
15159                 (void *)&cmd_pctype_mapping_reset_reset,
15160                 NULL,
15161         },
15162 };
15163
15164 /* show port pctype mapping */
15165
15166 /* Common result structure for show port pctype mapping */
15167 struct cmd_pctype_mapping_get_result {
15168         cmdline_fixed_string_t show;
15169         cmdline_fixed_string_t port;
15170         portid_t port_id;
15171         cmdline_fixed_string_t pctype;
15172         cmdline_fixed_string_t mapping;
15173 };
15174
15175 /* Common CLI fields for pctype mapping get */
15176 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15177         TOKEN_STRING_INITIALIZER
15178                 (struct cmd_pctype_mapping_get_result,
15179                  show, "show");
15180 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15181         TOKEN_STRING_INITIALIZER
15182                 (struct cmd_pctype_mapping_get_result,
15183                  port, "port");
15184 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15185         TOKEN_NUM_INITIALIZER
15186                 (struct cmd_pctype_mapping_get_result,
15187                  port_id, RTE_UINT16);
15188 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15189         TOKEN_STRING_INITIALIZER
15190                 (struct cmd_pctype_mapping_get_result,
15191                  pctype, "pctype");
15192 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15193         TOKEN_STRING_INITIALIZER
15194                 (struct cmd_pctype_mapping_get_result,
15195                  mapping, "mapping");
15196
15197 static void
15198 cmd_pctype_mapping_get_parsed(
15199         void *parsed_result,
15200         __rte_unused struct cmdline *cl,
15201         __rte_unused void *data)
15202 {
15203         struct cmd_pctype_mapping_get_result *res = parsed_result;
15204         int ret = -ENOTSUP;
15205 #ifdef RTE_NET_I40E
15206         struct rte_pmd_i40e_flow_type_mapping
15207                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15208         int i, j, first_pctype;
15209 #endif
15210
15211         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15212                 return;
15213
15214 #ifdef RTE_NET_I40E
15215         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15216 #endif
15217
15218         switch (ret) {
15219         case 0:
15220                 break;
15221         case -ENODEV:
15222                 printf("invalid port_id %d\n", res->port_id);
15223                 return;
15224         case -ENOTSUP:
15225                 printf("function not implemented\n");
15226                 return;
15227         default:
15228                 printf("programming error: (%s)\n", strerror(-ret));
15229                 return;
15230         }
15231
15232 #ifdef RTE_NET_I40E
15233         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15234                 if (mapping[i].pctype != 0ULL) {
15235                         first_pctype = 1;
15236
15237                         printf("pctype: ");
15238                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15239                                 if (mapping[i].pctype & (1ULL << j)) {
15240                                         printf(first_pctype ?
15241                                                "%02d" : ",%02d", j);
15242                                         first_pctype = 0;
15243                                 }
15244                         }
15245                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15246                 }
15247         }
15248 #endif
15249 }
15250
15251 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15252         .f = cmd_pctype_mapping_get_parsed,
15253         .data = NULL,
15254         .help_str = "show port <port_id> pctype mapping",
15255         .tokens = {
15256                 (void *)&cmd_pctype_mapping_get_show,
15257                 (void *)&cmd_pctype_mapping_get_port,
15258                 (void *)&cmd_pctype_mapping_get_port_id,
15259                 (void *)&cmd_pctype_mapping_get_pctype,
15260                 (void *)&cmd_pctype_mapping_get_mapping,
15261                 NULL,
15262         },
15263 };
15264
15265 /* port config pctype mapping update */
15266
15267 /* Common result structure for port config pctype mapping update */
15268 struct cmd_pctype_mapping_update_result {
15269         cmdline_fixed_string_t port;
15270         cmdline_fixed_string_t config;
15271         portid_t port_id;
15272         cmdline_fixed_string_t pctype;
15273         cmdline_fixed_string_t mapping;
15274         cmdline_fixed_string_t update;
15275         cmdline_fixed_string_t pctype_list;
15276         uint16_t flow_type;
15277 };
15278
15279 /* Common CLI fields for pctype mapping update*/
15280 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15281         TOKEN_STRING_INITIALIZER
15282                 (struct cmd_pctype_mapping_update_result,
15283                  port, "port");
15284 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15285         TOKEN_STRING_INITIALIZER
15286                 (struct cmd_pctype_mapping_update_result,
15287                  config, "config");
15288 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15289         TOKEN_NUM_INITIALIZER
15290                 (struct cmd_pctype_mapping_update_result,
15291                  port_id, RTE_UINT16);
15292 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15293         TOKEN_STRING_INITIALIZER
15294                 (struct cmd_pctype_mapping_update_result,
15295                  pctype, "pctype");
15296 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15297         TOKEN_STRING_INITIALIZER
15298                 (struct cmd_pctype_mapping_update_result,
15299                  mapping, "mapping");
15300 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15301         TOKEN_STRING_INITIALIZER
15302                 (struct cmd_pctype_mapping_update_result,
15303                  update, "update");
15304 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15305         TOKEN_STRING_INITIALIZER
15306                 (struct cmd_pctype_mapping_update_result,
15307                  pctype_list, NULL);
15308 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15309         TOKEN_NUM_INITIALIZER
15310                 (struct cmd_pctype_mapping_update_result,
15311                  flow_type, RTE_UINT16);
15312
15313 static void
15314 cmd_pctype_mapping_update_parsed(
15315         void *parsed_result,
15316         __rte_unused struct cmdline *cl,
15317         __rte_unused void *data)
15318 {
15319         struct cmd_pctype_mapping_update_result *res = parsed_result;
15320         int ret = -ENOTSUP;
15321 #ifdef RTE_NET_I40E
15322         struct rte_pmd_i40e_flow_type_mapping mapping;
15323         unsigned int i;
15324         unsigned int nb_item;
15325         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15326 #endif
15327
15328         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15329                 return;
15330
15331 #ifdef RTE_NET_I40E
15332         nb_item = parse_item_list(res->pctype_list, "pctypes",
15333                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15334         mapping.flow_type = res->flow_type;
15335         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15336                 mapping.pctype |= (1ULL << pctype_list[i]);
15337         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15338                                                 &mapping,
15339                                                 1,
15340                                                 0);
15341 #endif
15342
15343         switch (ret) {
15344         case 0:
15345                 break;
15346         case -EINVAL:
15347                 printf("invalid pctype or flow type\n");
15348                 break;
15349         case -ENODEV:
15350                 printf("invalid port_id %d\n", res->port_id);
15351                 break;
15352         case -ENOTSUP:
15353                 printf("function not implemented\n");
15354                 break;
15355         default:
15356                 printf("programming error: (%s)\n", strerror(-ret));
15357         }
15358 }
15359
15360 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15361         .f = cmd_pctype_mapping_update_parsed,
15362         .data = NULL,
15363         .help_str = "port config <port_id> pctype mapping update"
15364         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15365         .tokens = {
15366                 (void *)&cmd_pctype_mapping_update_port,
15367                 (void *)&cmd_pctype_mapping_update_config,
15368                 (void *)&cmd_pctype_mapping_update_port_id,
15369                 (void *)&cmd_pctype_mapping_update_pctype,
15370                 (void *)&cmd_pctype_mapping_update_mapping,
15371                 (void *)&cmd_pctype_mapping_update_update,
15372                 (void *)&cmd_pctype_mapping_update_pc_type,
15373                 (void *)&cmd_pctype_mapping_update_flow_type,
15374                 NULL,
15375         },
15376 };
15377
15378 /* ptype mapping get */
15379
15380 /* Common result structure for ptype mapping get */
15381 struct cmd_ptype_mapping_get_result {
15382         cmdline_fixed_string_t ptype;
15383         cmdline_fixed_string_t mapping;
15384         cmdline_fixed_string_t get;
15385         portid_t port_id;
15386         uint8_t valid_only;
15387 };
15388
15389 /* Common CLI fields for ptype mapping get */
15390 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15391         TOKEN_STRING_INITIALIZER
15392                 (struct cmd_ptype_mapping_get_result,
15393                  ptype, "ptype");
15394 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15395         TOKEN_STRING_INITIALIZER
15396                 (struct cmd_ptype_mapping_get_result,
15397                  mapping, "mapping");
15398 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15399         TOKEN_STRING_INITIALIZER
15400                 (struct cmd_ptype_mapping_get_result,
15401                  get, "get");
15402 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15403         TOKEN_NUM_INITIALIZER
15404                 (struct cmd_ptype_mapping_get_result,
15405                  port_id, RTE_UINT16);
15406 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15407         TOKEN_NUM_INITIALIZER
15408                 (struct cmd_ptype_mapping_get_result,
15409                  valid_only, RTE_UINT8);
15410
15411 static void
15412 cmd_ptype_mapping_get_parsed(
15413         void *parsed_result,
15414         __rte_unused struct cmdline *cl,
15415         __rte_unused void *data)
15416 {
15417         struct cmd_ptype_mapping_get_result *res = parsed_result;
15418         int ret = -ENOTSUP;
15419 #ifdef RTE_NET_I40E
15420         int max_ptype_num = 256;
15421         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15422         uint16_t count;
15423         int i;
15424 #endif
15425
15426         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15427                 return;
15428
15429 #ifdef RTE_NET_I40E
15430         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15431                                         mapping,
15432                                         max_ptype_num,
15433                                         &count,
15434                                         res->valid_only);
15435 #endif
15436
15437         switch (ret) {
15438         case 0:
15439                 break;
15440         case -ENODEV:
15441                 printf("invalid port_id %d\n", res->port_id);
15442                 break;
15443         case -ENOTSUP:
15444                 printf("function not implemented\n");
15445                 break;
15446         default:
15447                 printf("programming error: (%s)\n", strerror(-ret));
15448         }
15449
15450 #ifdef RTE_NET_I40E
15451         if (!ret) {
15452                 for (i = 0; i < count; i++)
15453                         printf("%3d\t0x%08x\n",
15454                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15455         }
15456 #endif
15457 }
15458
15459 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15460         .f = cmd_ptype_mapping_get_parsed,
15461         .data = NULL,
15462         .help_str = "ptype mapping get <port_id> <valid_only>",
15463         .tokens = {
15464                 (void *)&cmd_ptype_mapping_get_ptype,
15465                 (void *)&cmd_ptype_mapping_get_mapping,
15466                 (void *)&cmd_ptype_mapping_get_get,
15467                 (void *)&cmd_ptype_mapping_get_port_id,
15468                 (void *)&cmd_ptype_mapping_get_valid_only,
15469                 NULL,
15470         },
15471 };
15472
15473 /* ptype mapping replace */
15474
15475 /* Common result structure for ptype mapping replace */
15476 struct cmd_ptype_mapping_replace_result {
15477         cmdline_fixed_string_t ptype;
15478         cmdline_fixed_string_t mapping;
15479         cmdline_fixed_string_t replace;
15480         portid_t port_id;
15481         uint32_t target;
15482         uint8_t mask;
15483         uint32_t pkt_type;
15484 };
15485
15486 /* Common CLI fields for ptype mapping replace */
15487 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15488         TOKEN_STRING_INITIALIZER
15489                 (struct cmd_ptype_mapping_replace_result,
15490                  ptype, "ptype");
15491 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15492         TOKEN_STRING_INITIALIZER
15493                 (struct cmd_ptype_mapping_replace_result,
15494                  mapping, "mapping");
15495 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15496         TOKEN_STRING_INITIALIZER
15497                 (struct cmd_ptype_mapping_replace_result,
15498                  replace, "replace");
15499 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15500         TOKEN_NUM_INITIALIZER
15501                 (struct cmd_ptype_mapping_replace_result,
15502                  port_id, RTE_UINT16);
15503 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15504         TOKEN_NUM_INITIALIZER
15505                 (struct cmd_ptype_mapping_replace_result,
15506                  target, RTE_UINT32);
15507 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15508         TOKEN_NUM_INITIALIZER
15509                 (struct cmd_ptype_mapping_replace_result,
15510                  mask, RTE_UINT8);
15511 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15512         TOKEN_NUM_INITIALIZER
15513                 (struct cmd_ptype_mapping_replace_result,
15514                  pkt_type, RTE_UINT32);
15515
15516 static void
15517 cmd_ptype_mapping_replace_parsed(
15518         void *parsed_result,
15519         __rte_unused struct cmdline *cl,
15520         __rte_unused void *data)
15521 {
15522         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15523         int ret = -ENOTSUP;
15524
15525         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15526                 return;
15527
15528 #ifdef RTE_NET_I40E
15529         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15530                                         res->target,
15531                                         res->mask,
15532                                         res->pkt_type);
15533 #endif
15534
15535         switch (ret) {
15536         case 0:
15537                 break;
15538         case -EINVAL:
15539                 printf("invalid ptype 0x%8x or 0x%8x\n",
15540                                 res->target, res->pkt_type);
15541                 break;
15542         case -ENODEV:
15543                 printf("invalid port_id %d\n", res->port_id);
15544                 break;
15545         case -ENOTSUP:
15546                 printf("function not implemented\n");
15547                 break;
15548         default:
15549                 printf("programming error: (%s)\n", strerror(-ret));
15550         }
15551 }
15552
15553 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15554         .f = cmd_ptype_mapping_replace_parsed,
15555         .data = NULL,
15556         .help_str =
15557                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15558         .tokens = {
15559                 (void *)&cmd_ptype_mapping_replace_ptype,
15560                 (void *)&cmd_ptype_mapping_replace_mapping,
15561                 (void *)&cmd_ptype_mapping_replace_replace,
15562                 (void *)&cmd_ptype_mapping_replace_port_id,
15563                 (void *)&cmd_ptype_mapping_replace_target,
15564                 (void *)&cmd_ptype_mapping_replace_mask,
15565                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15566                 NULL,
15567         },
15568 };
15569
15570 /* ptype mapping reset */
15571
15572 /* Common result structure for ptype mapping reset */
15573 struct cmd_ptype_mapping_reset_result {
15574         cmdline_fixed_string_t ptype;
15575         cmdline_fixed_string_t mapping;
15576         cmdline_fixed_string_t reset;
15577         portid_t port_id;
15578 };
15579
15580 /* Common CLI fields for ptype mapping reset*/
15581 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15582         TOKEN_STRING_INITIALIZER
15583                 (struct cmd_ptype_mapping_reset_result,
15584                  ptype, "ptype");
15585 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15586         TOKEN_STRING_INITIALIZER
15587                 (struct cmd_ptype_mapping_reset_result,
15588                  mapping, "mapping");
15589 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15590         TOKEN_STRING_INITIALIZER
15591                 (struct cmd_ptype_mapping_reset_result,
15592                  reset, "reset");
15593 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15594         TOKEN_NUM_INITIALIZER
15595                 (struct cmd_ptype_mapping_reset_result,
15596                  port_id, RTE_UINT16);
15597
15598 static void
15599 cmd_ptype_mapping_reset_parsed(
15600         void *parsed_result,
15601         __rte_unused struct cmdline *cl,
15602         __rte_unused void *data)
15603 {
15604         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15605         int ret = -ENOTSUP;
15606
15607         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15608                 return;
15609
15610 #ifdef RTE_NET_I40E
15611         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15612 #endif
15613
15614         switch (ret) {
15615         case 0:
15616                 break;
15617         case -ENODEV:
15618                 printf("invalid port_id %d\n", res->port_id);
15619                 break;
15620         case -ENOTSUP:
15621                 printf("function not implemented\n");
15622                 break;
15623         default:
15624                 printf("programming error: (%s)\n", strerror(-ret));
15625         }
15626 }
15627
15628 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15629         .f = cmd_ptype_mapping_reset_parsed,
15630         .data = NULL,
15631         .help_str = "ptype mapping reset <port_id>",
15632         .tokens = {
15633                 (void *)&cmd_ptype_mapping_reset_ptype,
15634                 (void *)&cmd_ptype_mapping_reset_mapping,
15635                 (void *)&cmd_ptype_mapping_reset_reset,
15636                 (void *)&cmd_ptype_mapping_reset_port_id,
15637                 NULL,
15638         },
15639 };
15640
15641 /* ptype mapping update */
15642
15643 /* Common result structure for ptype mapping update */
15644 struct cmd_ptype_mapping_update_result {
15645         cmdline_fixed_string_t ptype;
15646         cmdline_fixed_string_t mapping;
15647         cmdline_fixed_string_t reset;
15648         portid_t port_id;
15649         uint8_t hw_ptype;
15650         uint32_t sw_ptype;
15651 };
15652
15653 /* Common CLI fields for ptype mapping update*/
15654 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15655         TOKEN_STRING_INITIALIZER
15656                 (struct cmd_ptype_mapping_update_result,
15657                  ptype, "ptype");
15658 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15659         TOKEN_STRING_INITIALIZER
15660                 (struct cmd_ptype_mapping_update_result,
15661                  mapping, "mapping");
15662 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15663         TOKEN_STRING_INITIALIZER
15664                 (struct cmd_ptype_mapping_update_result,
15665                  reset, "update");
15666 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15667         TOKEN_NUM_INITIALIZER
15668                 (struct cmd_ptype_mapping_update_result,
15669                  port_id, RTE_UINT16);
15670 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15671         TOKEN_NUM_INITIALIZER
15672                 (struct cmd_ptype_mapping_update_result,
15673                  hw_ptype, RTE_UINT8);
15674 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15675         TOKEN_NUM_INITIALIZER
15676                 (struct cmd_ptype_mapping_update_result,
15677                  sw_ptype, RTE_UINT32);
15678
15679 static void
15680 cmd_ptype_mapping_update_parsed(
15681         void *parsed_result,
15682         __rte_unused struct cmdline *cl,
15683         __rte_unused void *data)
15684 {
15685         struct cmd_ptype_mapping_update_result *res = parsed_result;
15686         int ret = -ENOTSUP;
15687 #ifdef RTE_NET_I40E
15688         struct rte_pmd_i40e_ptype_mapping mapping;
15689 #endif
15690         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15691                 return;
15692
15693 #ifdef RTE_NET_I40E
15694         mapping.hw_ptype = res->hw_ptype;
15695         mapping.sw_ptype = res->sw_ptype;
15696         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15697                                                 &mapping,
15698                                                 1,
15699                                                 0);
15700 #endif
15701
15702         switch (ret) {
15703         case 0:
15704                 break;
15705         case -EINVAL:
15706                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15707                 break;
15708         case -ENODEV:
15709                 printf("invalid port_id %d\n", res->port_id);
15710                 break;
15711         case -ENOTSUP:
15712                 printf("function not implemented\n");
15713                 break;
15714         default:
15715                 printf("programming error: (%s)\n", strerror(-ret));
15716         }
15717 }
15718
15719 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15720         .f = cmd_ptype_mapping_update_parsed,
15721         .data = NULL,
15722         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15723         .tokens = {
15724                 (void *)&cmd_ptype_mapping_update_ptype,
15725                 (void *)&cmd_ptype_mapping_update_mapping,
15726                 (void *)&cmd_ptype_mapping_update_update,
15727                 (void *)&cmd_ptype_mapping_update_port_id,
15728                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15729                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15730                 NULL,
15731         },
15732 };
15733
15734 /* Common result structure for file commands */
15735 struct cmd_cmdfile_result {
15736         cmdline_fixed_string_t load;
15737         cmdline_fixed_string_t filename;
15738 };
15739
15740 /* Common CLI fields for file commands */
15741 cmdline_parse_token_string_t cmd_load_cmdfile =
15742         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15743 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15744         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15745
15746 static void
15747 cmd_load_from_file_parsed(
15748         void *parsed_result,
15749         __rte_unused struct cmdline *cl,
15750         __rte_unused void *data)
15751 {
15752         struct cmd_cmdfile_result *res = parsed_result;
15753
15754         cmdline_read_from_file(res->filename);
15755 }
15756
15757 cmdline_parse_inst_t cmd_load_from_file = {
15758         .f = cmd_load_from_file_parsed,
15759         .data = NULL,
15760         .help_str = "load <filename>",
15761         .tokens = {
15762                 (void *)&cmd_load_cmdfile,
15763                 (void *)&cmd_load_cmdfile_filename,
15764                 NULL,
15765         },
15766 };
15767
15768 /* Get Rx offloads capabilities */
15769 struct cmd_rx_offload_get_capa_result {
15770         cmdline_fixed_string_t show;
15771         cmdline_fixed_string_t port;
15772         portid_t port_id;
15773         cmdline_fixed_string_t rx_offload;
15774         cmdline_fixed_string_t capabilities;
15775 };
15776
15777 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15778         TOKEN_STRING_INITIALIZER
15779                 (struct cmd_rx_offload_get_capa_result,
15780                  show, "show");
15781 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15782         TOKEN_STRING_INITIALIZER
15783                 (struct cmd_rx_offload_get_capa_result,
15784                  port, "port");
15785 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15786         TOKEN_NUM_INITIALIZER
15787                 (struct cmd_rx_offload_get_capa_result,
15788                  port_id, RTE_UINT16);
15789 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15790         TOKEN_STRING_INITIALIZER
15791                 (struct cmd_rx_offload_get_capa_result,
15792                  rx_offload, "rx_offload");
15793 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15794         TOKEN_STRING_INITIALIZER
15795                 (struct cmd_rx_offload_get_capa_result,
15796                  capabilities, "capabilities");
15797
15798 static void
15799 print_rx_offloads(uint64_t offloads)
15800 {
15801         uint64_t single_offload;
15802         int begin;
15803         int end;
15804         int bit;
15805
15806         if (offloads == 0)
15807                 return;
15808
15809         begin = __builtin_ctzll(offloads);
15810         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15811
15812         single_offload = 1ULL << begin;
15813         for (bit = begin; bit < end; bit++) {
15814                 if (offloads & single_offload)
15815                         printf(" %s",
15816                                rte_eth_dev_rx_offload_name(single_offload));
15817                 single_offload <<= 1;
15818         }
15819 }
15820
15821 static void
15822 cmd_rx_offload_get_capa_parsed(
15823         void *parsed_result,
15824         __rte_unused struct cmdline *cl,
15825         __rte_unused void *data)
15826 {
15827         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15828         struct rte_eth_dev_info dev_info;
15829         portid_t port_id = res->port_id;
15830         uint64_t queue_offloads;
15831         uint64_t port_offloads;
15832         int ret;
15833
15834         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15835         if (ret != 0)
15836                 return;
15837
15838         queue_offloads = dev_info.rx_queue_offload_capa;
15839         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15840
15841         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15842         printf("  Per Queue :");
15843         print_rx_offloads(queue_offloads);
15844
15845         printf("\n");
15846         printf("  Per Port  :");
15847         print_rx_offloads(port_offloads);
15848         printf("\n\n");
15849 }
15850
15851 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15852         .f = cmd_rx_offload_get_capa_parsed,
15853         .data = NULL,
15854         .help_str = "show port <port_id> rx_offload capabilities",
15855         .tokens = {
15856                 (void *)&cmd_rx_offload_get_capa_show,
15857                 (void *)&cmd_rx_offload_get_capa_port,
15858                 (void *)&cmd_rx_offload_get_capa_port_id,
15859                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15860                 (void *)&cmd_rx_offload_get_capa_capabilities,
15861                 NULL,
15862         }
15863 };
15864
15865 /* Get Rx offloads configuration */
15866 struct cmd_rx_offload_get_configuration_result {
15867         cmdline_fixed_string_t show;
15868         cmdline_fixed_string_t port;
15869         portid_t port_id;
15870         cmdline_fixed_string_t rx_offload;
15871         cmdline_fixed_string_t configuration;
15872 };
15873
15874 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
15875         TOKEN_STRING_INITIALIZER
15876                 (struct cmd_rx_offload_get_configuration_result,
15877                  show, "show");
15878 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
15879         TOKEN_STRING_INITIALIZER
15880                 (struct cmd_rx_offload_get_configuration_result,
15881                  port, "port");
15882 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
15883         TOKEN_NUM_INITIALIZER
15884                 (struct cmd_rx_offload_get_configuration_result,
15885                  port_id, RTE_UINT16);
15886 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
15887         TOKEN_STRING_INITIALIZER
15888                 (struct cmd_rx_offload_get_configuration_result,
15889                  rx_offload, "rx_offload");
15890 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
15891         TOKEN_STRING_INITIALIZER
15892                 (struct cmd_rx_offload_get_configuration_result,
15893                  configuration, "configuration");
15894
15895 static void
15896 cmd_rx_offload_get_configuration_parsed(
15897         void *parsed_result,
15898         __rte_unused struct cmdline *cl,
15899         __rte_unused void *data)
15900 {
15901         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
15902         struct rte_eth_dev_info dev_info;
15903         portid_t port_id = res->port_id;
15904         struct rte_port *port = &ports[port_id];
15905         uint64_t port_offloads;
15906         uint64_t queue_offloads;
15907         uint16_t nb_rx_queues;
15908         int q;
15909         int ret;
15910
15911         printf("Rx Offloading Configuration of port %d :\n", port_id);
15912
15913         port_offloads = port->dev_conf.rxmode.offloads;
15914         printf("  Port :");
15915         print_rx_offloads(port_offloads);
15916         printf("\n");
15917
15918         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15919         if (ret != 0)
15920                 return;
15921
15922         nb_rx_queues = dev_info.nb_rx_queues;
15923         for (q = 0; q < nb_rx_queues; q++) {
15924                 queue_offloads = port->rx_conf[q].offloads;
15925                 printf("  Queue[%2d] :", q);
15926                 print_rx_offloads(queue_offloads);
15927                 printf("\n");
15928         }
15929         printf("\n");
15930 }
15931
15932 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
15933         .f = cmd_rx_offload_get_configuration_parsed,
15934         .data = NULL,
15935         .help_str = "show port <port_id> rx_offload configuration",
15936         .tokens = {
15937                 (void *)&cmd_rx_offload_get_configuration_show,
15938                 (void *)&cmd_rx_offload_get_configuration_port,
15939                 (void *)&cmd_rx_offload_get_configuration_port_id,
15940                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
15941                 (void *)&cmd_rx_offload_get_configuration_configuration,
15942                 NULL,
15943         }
15944 };
15945
15946 /* Enable/Disable a per port offloading */
15947 struct cmd_config_per_port_rx_offload_result {
15948         cmdline_fixed_string_t port;
15949         cmdline_fixed_string_t config;
15950         portid_t port_id;
15951         cmdline_fixed_string_t rx_offload;
15952         cmdline_fixed_string_t offload;
15953         cmdline_fixed_string_t on_off;
15954 };
15955
15956 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
15957         TOKEN_STRING_INITIALIZER
15958                 (struct cmd_config_per_port_rx_offload_result,
15959                  port, "port");
15960 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
15961         TOKEN_STRING_INITIALIZER
15962                 (struct cmd_config_per_port_rx_offload_result,
15963                  config, "config");
15964 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
15965         TOKEN_NUM_INITIALIZER
15966                 (struct cmd_config_per_port_rx_offload_result,
15967                  port_id, RTE_UINT16);
15968 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
15969         TOKEN_STRING_INITIALIZER
15970                 (struct cmd_config_per_port_rx_offload_result,
15971                  rx_offload, "rx_offload");
15972 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
15973         TOKEN_STRING_INITIALIZER
15974                 (struct cmd_config_per_port_rx_offload_result,
15975                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
15976                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
15977                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
15978                            "scatter#buffer_split#timestamp#security#"
15979                            "keep_crc#rss_hash");
15980 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
15981         TOKEN_STRING_INITIALIZER
15982                 (struct cmd_config_per_port_rx_offload_result,
15983                  on_off, "on#off");
15984
15985 static uint64_t
15986 search_rx_offload(const char *name)
15987 {
15988         uint64_t single_offload;
15989         const char *single_name;
15990         int found = 0;
15991         unsigned int bit;
15992
15993         single_offload = 1;
15994         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
15995                 single_name = rte_eth_dev_rx_offload_name(single_offload);
15996                 if (!strcasecmp(single_name, name)) {
15997                         found = 1;
15998                         break;
15999                 }
16000                 single_offload <<= 1;
16001         }
16002
16003         if (found)
16004                 return single_offload;
16005
16006         return 0;
16007 }
16008
16009 static void
16010 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16011                                 __rte_unused struct cmdline *cl,
16012                                 __rte_unused void *data)
16013 {
16014         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16015         portid_t port_id = res->port_id;
16016         struct rte_eth_dev_info dev_info;
16017         struct rte_port *port = &ports[port_id];
16018         uint64_t single_offload;
16019         uint16_t nb_rx_queues;
16020         int q;
16021         int ret;
16022
16023         if (port->port_status != RTE_PORT_STOPPED) {
16024                 printf("Error: Can't config offload when Port %d "
16025                        "is not stopped\n", port_id);
16026                 return;
16027         }
16028
16029         single_offload = search_rx_offload(res->offload);
16030         if (single_offload == 0) {
16031                 printf("Unknown offload name: %s\n", res->offload);
16032                 return;
16033         }
16034
16035         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16036         if (ret != 0)
16037                 return;
16038
16039         nb_rx_queues = dev_info.nb_rx_queues;
16040         if (!strcmp(res->on_off, "on")) {
16041                 port->dev_conf.rxmode.offloads |= single_offload;
16042                 for (q = 0; q < nb_rx_queues; q++)
16043                         port->rx_conf[q].offloads |= single_offload;
16044         } else {
16045                 port->dev_conf.rxmode.offloads &= ~single_offload;
16046                 for (q = 0; q < nb_rx_queues; q++)
16047                         port->rx_conf[q].offloads &= ~single_offload;
16048         }
16049
16050         cmd_reconfig_device_queue(port_id, 1, 1);
16051 }
16052
16053 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16054         .f = cmd_config_per_port_rx_offload_parsed,
16055         .data = NULL,
16056         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16057                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16058                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16059                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16060                     "keep_crc|rss_hash on|off",
16061         .tokens = {
16062                 (void *)&cmd_config_per_port_rx_offload_result_port,
16063                 (void *)&cmd_config_per_port_rx_offload_result_config,
16064                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16065                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16066                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16067                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16068                 NULL,
16069         }
16070 };
16071
16072 /* Enable/Disable a per queue offloading */
16073 struct cmd_config_per_queue_rx_offload_result {
16074         cmdline_fixed_string_t port;
16075         portid_t port_id;
16076         cmdline_fixed_string_t rxq;
16077         uint16_t queue_id;
16078         cmdline_fixed_string_t rx_offload;
16079         cmdline_fixed_string_t offload;
16080         cmdline_fixed_string_t on_off;
16081 };
16082
16083 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16084         TOKEN_STRING_INITIALIZER
16085                 (struct cmd_config_per_queue_rx_offload_result,
16086                  port, "port");
16087 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16088         TOKEN_NUM_INITIALIZER
16089                 (struct cmd_config_per_queue_rx_offload_result,
16090                  port_id, RTE_UINT16);
16091 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16092         TOKEN_STRING_INITIALIZER
16093                 (struct cmd_config_per_queue_rx_offload_result,
16094                  rxq, "rxq");
16095 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16096         TOKEN_NUM_INITIALIZER
16097                 (struct cmd_config_per_queue_rx_offload_result,
16098                  queue_id, RTE_UINT16);
16099 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16100         TOKEN_STRING_INITIALIZER
16101                 (struct cmd_config_per_queue_rx_offload_result,
16102                  rx_offload, "rx_offload");
16103 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16104         TOKEN_STRING_INITIALIZER
16105                 (struct cmd_config_per_queue_rx_offload_result,
16106                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16107                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16108                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16109                            "scatter#buffer_split#timestamp#security#keep_crc");
16110 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16111         TOKEN_STRING_INITIALIZER
16112                 (struct cmd_config_per_queue_rx_offload_result,
16113                  on_off, "on#off");
16114
16115 static void
16116 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16117                                 __rte_unused struct cmdline *cl,
16118                                 __rte_unused void *data)
16119 {
16120         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16121         struct rte_eth_dev_info dev_info;
16122         portid_t port_id = res->port_id;
16123         uint16_t queue_id = res->queue_id;
16124         struct rte_port *port = &ports[port_id];
16125         uint64_t single_offload;
16126         int ret;
16127
16128         if (port->port_status != RTE_PORT_STOPPED) {
16129                 printf("Error: Can't config offload when Port %d "
16130                        "is not stopped\n", 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                 printf("Error: input queue_id should be 0 ... "
16140                        "%d\n", dev_info.nb_rx_queues - 1);
16141                 return;
16142         }
16143
16144         single_offload = search_rx_offload(res->offload);
16145         if (single_offload == 0) {
16146                 printf("Unknown offload name: %s\n", res->offload);
16147                 return;
16148         }
16149
16150         if (!strcmp(res->on_off, "on"))
16151                 port->rx_conf[queue_id].offloads |= single_offload;
16152         else
16153                 port->rx_conf[queue_id].offloads &= ~single_offload;
16154
16155         cmd_reconfig_device_queue(port_id, 1, 1);
16156 }
16157
16158 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16159         .f = cmd_config_per_queue_rx_offload_parsed,
16160         .data = NULL,
16161         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16162                     "vlan_strip|ipv4_cksum|"
16163                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16164                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16165                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16166                     "keep_crc on|off",
16167         .tokens = {
16168                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16169                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16170                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16171                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16172                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16173                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16174                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16175                 NULL,
16176         }
16177 };
16178
16179 /* Get Tx offloads capabilities */
16180 struct cmd_tx_offload_get_capa_result {
16181         cmdline_fixed_string_t show;
16182         cmdline_fixed_string_t port;
16183         portid_t port_id;
16184         cmdline_fixed_string_t tx_offload;
16185         cmdline_fixed_string_t capabilities;
16186 };
16187
16188 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16189         TOKEN_STRING_INITIALIZER
16190                 (struct cmd_tx_offload_get_capa_result,
16191                  show, "show");
16192 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16193         TOKEN_STRING_INITIALIZER
16194                 (struct cmd_tx_offload_get_capa_result,
16195                  port, "port");
16196 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16197         TOKEN_NUM_INITIALIZER
16198                 (struct cmd_tx_offload_get_capa_result,
16199                  port_id, RTE_UINT16);
16200 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16201         TOKEN_STRING_INITIALIZER
16202                 (struct cmd_tx_offload_get_capa_result,
16203                  tx_offload, "tx_offload");
16204 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16205         TOKEN_STRING_INITIALIZER
16206                 (struct cmd_tx_offload_get_capa_result,
16207                  capabilities, "capabilities");
16208
16209 static void
16210 print_tx_offloads(uint64_t offloads)
16211 {
16212         uint64_t single_offload;
16213         int begin;
16214         int end;
16215         int bit;
16216
16217         if (offloads == 0)
16218                 return;
16219
16220         begin = __builtin_ctzll(offloads);
16221         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16222
16223         single_offload = 1ULL << begin;
16224         for (bit = begin; bit < end; bit++) {
16225                 if (offloads & single_offload)
16226                         printf(" %s",
16227                                rte_eth_dev_tx_offload_name(single_offload));
16228                 single_offload <<= 1;
16229         }
16230 }
16231
16232 static void
16233 cmd_tx_offload_get_capa_parsed(
16234         void *parsed_result,
16235         __rte_unused struct cmdline *cl,
16236         __rte_unused void *data)
16237 {
16238         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16239         struct rte_eth_dev_info dev_info;
16240         portid_t port_id = res->port_id;
16241         uint64_t queue_offloads;
16242         uint64_t port_offloads;
16243         int ret;
16244
16245         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16246         if (ret != 0)
16247                 return;
16248
16249         queue_offloads = dev_info.tx_queue_offload_capa;
16250         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16251
16252         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16253         printf("  Per Queue :");
16254         print_tx_offloads(queue_offloads);
16255
16256         printf("\n");
16257         printf("  Per Port  :");
16258         print_tx_offloads(port_offloads);
16259         printf("\n\n");
16260 }
16261
16262 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16263         .f = cmd_tx_offload_get_capa_parsed,
16264         .data = NULL,
16265         .help_str = "show port <port_id> tx_offload capabilities",
16266         .tokens = {
16267                 (void *)&cmd_tx_offload_get_capa_show,
16268                 (void *)&cmd_tx_offload_get_capa_port,
16269                 (void *)&cmd_tx_offload_get_capa_port_id,
16270                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16271                 (void *)&cmd_tx_offload_get_capa_capabilities,
16272                 NULL,
16273         }
16274 };
16275
16276 /* Get Tx offloads configuration */
16277 struct cmd_tx_offload_get_configuration_result {
16278         cmdline_fixed_string_t show;
16279         cmdline_fixed_string_t port;
16280         portid_t port_id;
16281         cmdline_fixed_string_t tx_offload;
16282         cmdline_fixed_string_t configuration;
16283 };
16284
16285 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16286         TOKEN_STRING_INITIALIZER
16287                 (struct cmd_tx_offload_get_configuration_result,
16288                  show, "show");
16289 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16290         TOKEN_STRING_INITIALIZER
16291                 (struct cmd_tx_offload_get_configuration_result,
16292                  port, "port");
16293 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16294         TOKEN_NUM_INITIALIZER
16295                 (struct cmd_tx_offload_get_configuration_result,
16296                  port_id, RTE_UINT16);
16297 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16298         TOKEN_STRING_INITIALIZER
16299                 (struct cmd_tx_offload_get_configuration_result,
16300                  tx_offload, "tx_offload");
16301 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16302         TOKEN_STRING_INITIALIZER
16303                 (struct cmd_tx_offload_get_configuration_result,
16304                  configuration, "configuration");
16305
16306 static void
16307 cmd_tx_offload_get_configuration_parsed(
16308         void *parsed_result,
16309         __rte_unused struct cmdline *cl,
16310         __rte_unused void *data)
16311 {
16312         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16313         struct rte_eth_dev_info dev_info;
16314         portid_t port_id = res->port_id;
16315         struct rte_port *port = &ports[port_id];
16316         uint64_t port_offloads;
16317         uint64_t queue_offloads;
16318         uint16_t nb_tx_queues;
16319         int q;
16320         int ret;
16321
16322         printf("Tx Offloading Configuration of port %d :\n", port_id);
16323
16324         port_offloads = port->dev_conf.txmode.offloads;
16325         printf("  Port :");
16326         print_tx_offloads(port_offloads);
16327         printf("\n");
16328
16329         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16330         if (ret != 0)
16331                 return;
16332
16333         nb_tx_queues = dev_info.nb_tx_queues;
16334         for (q = 0; q < nb_tx_queues; q++) {
16335                 queue_offloads = port->tx_conf[q].offloads;
16336                 printf("  Queue[%2d] :", q);
16337                 print_tx_offloads(queue_offloads);
16338                 printf("\n");
16339         }
16340         printf("\n");
16341 }
16342
16343 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16344         .f = cmd_tx_offload_get_configuration_parsed,
16345         .data = NULL,
16346         .help_str = "show port <port_id> tx_offload configuration",
16347         .tokens = {
16348                 (void *)&cmd_tx_offload_get_configuration_show,
16349                 (void *)&cmd_tx_offload_get_configuration_port,
16350                 (void *)&cmd_tx_offload_get_configuration_port_id,
16351                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16352                 (void *)&cmd_tx_offload_get_configuration_configuration,
16353                 NULL,
16354         }
16355 };
16356
16357 /* Enable/Disable a per port offloading */
16358 struct cmd_config_per_port_tx_offload_result {
16359         cmdline_fixed_string_t port;
16360         cmdline_fixed_string_t config;
16361         portid_t port_id;
16362         cmdline_fixed_string_t tx_offload;
16363         cmdline_fixed_string_t offload;
16364         cmdline_fixed_string_t on_off;
16365 };
16366
16367 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16368         TOKEN_STRING_INITIALIZER
16369                 (struct cmd_config_per_port_tx_offload_result,
16370                  port, "port");
16371 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16372         TOKEN_STRING_INITIALIZER
16373                 (struct cmd_config_per_port_tx_offload_result,
16374                  config, "config");
16375 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16376         TOKEN_NUM_INITIALIZER
16377                 (struct cmd_config_per_port_tx_offload_result,
16378                  port_id, RTE_UINT16);
16379 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16380         TOKEN_STRING_INITIALIZER
16381                 (struct cmd_config_per_port_tx_offload_result,
16382                  tx_offload, "tx_offload");
16383 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16384         TOKEN_STRING_INITIALIZER
16385                 (struct cmd_config_per_port_tx_offload_result,
16386                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16387                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16388                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16389                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16390                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16391                           "send_on_timestamp");
16392 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16393         TOKEN_STRING_INITIALIZER
16394                 (struct cmd_config_per_port_tx_offload_result,
16395                  on_off, "on#off");
16396
16397 static uint64_t
16398 search_tx_offload(const char *name)
16399 {
16400         uint64_t single_offload;
16401         const char *single_name;
16402         int found = 0;
16403         unsigned int bit;
16404
16405         single_offload = 1;
16406         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16407                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16408                 if (single_name == NULL)
16409                         break;
16410                 if (!strcasecmp(single_name, name)) {
16411                         found = 1;
16412                         break;
16413                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16414                         break;
16415                 single_offload <<= 1;
16416         }
16417
16418         if (found)
16419                 return single_offload;
16420
16421         return 0;
16422 }
16423
16424 static void
16425 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16426                                 __rte_unused struct cmdline *cl,
16427                                 __rte_unused void *data)
16428 {
16429         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16430         portid_t port_id = res->port_id;
16431         struct rte_eth_dev_info dev_info;
16432         struct rte_port *port = &ports[port_id];
16433         uint64_t single_offload;
16434         uint16_t nb_tx_queues;
16435         int q;
16436         int ret;
16437
16438         if (port->port_status != RTE_PORT_STOPPED) {
16439                 printf("Error: Can't config offload when Port %d "
16440                        "is not stopped\n", port_id);
16441                 return;
16442         }
16443
16444         single_offload = search_tx_offload(res->offload);
16445         if (single_offload == 0) {
16446                 printf("Unknown offload name: %s\n", res->offload);
16447                 return;
16448         }
16449
16450         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16451         if (ret != 0)
16452                 return;
16453
16454         nb_tx_queues = dev_info.nb_tx_queues;
16455         if (!strcmp(res->on_off, "on")) {
16456                 port->dev_conf.txmode.offloads |= single_offload;
16457                 for (q = 0; q < nb_tx_queues; q++)
16458                         port->tx_conf[q].offloads |= single_offload;
16459         } else {
16460                 port->dev_conf.txmode.offloads &= ~single_offload;
16461                 for (q = 0; q < nb_tx_queues; q++)
16462                         port->tx_conf[q].offloads &= ~single_offload;
16463         }
16464
16465         cmd_reconfig_device_queue(port_id, 1, 1);
16466 }
16467
16468 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16469         .f = cmd_config_per_port_tx_offload_parsed,
16470         .data = NULL,
16471         .help_str = "port config <port_id> tx_offload "
16472                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16473                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16474                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16475                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16476                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16477                     "send_on_timestamp on|off",
16478         .tokens = {
16479                 (void *)&cmd_config_per_port_tx_offload_result_port,
16480                 (void *)&cmd_config_per_port_tx_offload_result_config,
16481                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16482                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16483                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16484                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16485                 NULL,
16486         }
16487 };
16488
16489 /* Enable/Disable a per queue offloading */
16490 struct cmd_config_per_queue_tx_offload_result {
16491         cmdline_fixed_string_t port;
16492         portid_t port_id;
16493         cmdline_fixed_string_t txq;
16494         uint16_t queue_id;
16495         cmdline_fixed_string_t tx_offload;
16496         cmdline_fixed_string_t offload;
16497         cmdline_fixed_string_t on_off;
16498 };
16499
16500 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16501         TOKEN_STRING_INITIALIZER
16502                 (struct cmd_config_per_queue_tx_offload_result,
16503                  port, "port");
16504 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16505         TOKEN_NUM_INITIALIZER
16506                 (struct cmd_config_per_queue_tx_offload_result,
16507                  port_id, RTE_UINT16);
16508 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16509         TOKEN_STRING_INITIALIZER
16510                 (struct cmd_config_per_queue_tx_offload_result,
16511                  txq, "txq");
16512 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16513         TOKEN_NUM_INITIALIZER
16514                 (struct cmd_config_per_queue_tx_offload_result,
16515                  queue_id, RTE_UINT16);
16516 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16517         TOKEN_STRING_INITIALIZER
16518                 (struct cmd_config_per_queue_tx_offload_result,
16519                  tx_offload, "tx_offload");
16520 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16521         TOKEN_STRING_INITIALIZER
16522                 (struct cmd_config_per_queue_tx_offload_result,
16523                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16524                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16525                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16526                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16527                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16528 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16529         TOKEN_STRING_INITIALIZER
16530                 (struct cmd_config_per_queue_tx_offload_result,
16531                  on_off, "on#off");
16532
16533 static void
16534 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16535                                 __rte_unused struct cmdline *cl,
16536                                 __rte_unused void *data)
16537 {
16538         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16539         struct rte_eth_dev_info dev_info;
16540         portid_t port_id = res->port_id;
16541         uint16_t queue_id = res->queue_id;
16542         struct rte_port *port = &ports[port_id];
16543         uint64_t single_offload;
16544         int ret;
16545
16546         if (port->port_status != RTE_PORT_STOPPED) {
16547                 printf("Error: Can't config offload when Port %d "
16548                        "is not stopped\n", port_id);
16549                 return;
16550         }
16551
16552         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16553         if (ret != 0)
16554                 return;
16555
16556         if (queue_id >= dev_info.nb_tx_queues) {
16557                 printf("Error: input queue_id should be 0 ... "
16558                        "%d\n", dev_info.nb_tx_queues - 1);
16559                 return;
16560         }
16561
16562         single_offload = search_tx_offload(res->offload);
16563         if (single_offload == 0) {
16564                 printf("Unknown offload name: %s\n", res->offload);
16565                 return;
16566         }
16567
16568         if (!strcmp(res->on_off, "on"))
16569                 port->tx_conf[queue_id].offloads |= single_offload;
16570         else
16571                 port->tx_conf[queue_id].offloads &= ~single_offload;
16572
16573         cmd_reconfig_device_queue(port_id, 1, 1);
16574 }
16575
16576 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16577         .f = cmd_config_per_queue_tx_offload_parsed,
16578         .data = NULL,
16579         .help_str = "port <port_id> txq <queue_id> tx_offload "
16580                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16581                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16582                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16583                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16584                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16585                     "on|off",
16586         .tokens = {
16587                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16588                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16589                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16590                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16591                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16592                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16593                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16594                 NULL,
16595         }
16596 };
16597
16598 /* *** configure tx_metadata for specific port *** */
16599 struct cmd_config_tx_metadata_specific_result {
16600         cmdline_fixed_string_t port;
16601         cmdline_fixed_string_t keyword;
16602         uint16_t port_id;
16603         cmdline_fixed_string_t item;
16604         uint32_t value;
16605 };
16606
16607 static void
16608 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16609                                 __rte_unused struct cmdline *cl,
16610                                 __rte_unused void *data)
16611 {
16612         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16613
16614         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16615                 return;
16616         ports[res->port_id].tx_metadata = res->value;
16617         /* Add/remove callback to insert valid metadata in every Tx packet. */
16618         if (ports[res->port_id].tx_metadata)
16619                 add_tx_md_callback(res->port_id);
16620         else
16621                 remove_tx_md_callback(res->port_id);
16622         rte_flow_dynf_metadata_register();
16623 }
16624
16625 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16626         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16627                         port, "port");
16628 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16629         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16630                         keyword, "config");
16631 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16632         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16633                         port_id, RTE_UINT16);
16634 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16635         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16636                         item, "tx_metadata");
16637 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16638         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16639                         value, RTE_UINT32);
16640
16641 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16642         .f = cmd_config_tx_metadata_specific_parsed,
16643         .data = NULL,
16644         .help_str = "port config <port_id> tx_metadata <value>",
16645         .tokens = {
16646                 (void *)&cmd_config_tx_metadata_specific_port,
16647                 (void *)&cmd_config_tx_metadata_specific_keyword,
16648                 (void *)&cmd_config_tx_metadata_specific_id,
16649                 (void *)&cmd_config_tx_metadata_specific_item,
16650                 (void *)&cmd_config_tx_metadata_specific_value,
16651                 NULL,
16652         },
16653 };
16654
16655 /* *** set dynf *** */
16656 struct cmd_config_tx_dynf_specific_result {
16657         cmdline_fixed_string_t port;
16658         cmdline_fixed_string_t keyword;
16659         uint16_t port_id;
16660         cmdline_fixed_string_t item;
16661         cmdline_fixed_string_t name;
16662         cmdline_fixed_string_t value;
16663 };
16664
16665 static void
16666 cmd_config_dynf_specific_parsed(void *parsed_result,
16667                                 __rte_unused struct cmdline *cl,
16668                                 __rte_unused void *data)
16669 {
16670         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16671         struct rte_mbuf_dynflag desc_flag;
16672         int flag;
16673         uint64_t old_port_flags;
16674
16675         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16676                 return;
16677         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16678         if (flag <= 0) {
16679                 if (strlcpy(desc_flag.name, res->name,
16680                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16681                         printf("Flag name too long\n");
16682                         return;
16683                 }
16684                 desc_flag.flags = 0;
16685                 flag = rte_mbuf_dynflag_register(&desc_flag);
16686                 if (flag < 0) {
16687                         printf("Can't register flag\n");
16688                         return;
16689                 }
16690                 strcpy(dynf_names[flag], desc_flag.name);
16691         }
16692         old_port_flags = ports[res->port_id].mbuf_dynf;
16693         if (!strcmp(res->value, "set")) {
16694                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16695                 if (old_port_flags == 0)
16696                         add_tx_dynf_callback(res->port_id);
16697         } else {
16698                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16699                 if (ports[res->port_id].mbuf_dynf == 0)
16700                         remove_tx_dynf_callback(res->port_id);
16701         }
16702 }
16703
16704 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16705         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16706                         keyword, "port");
16707 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16708         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16709                         keyword, "config");
16710 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16711         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16712                         port_id, RTE_UINT16);
16713 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16714         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16715                         item, "dynf");
16716 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16717         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16718                         name, NULL);
16719 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16720         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16721                         value, "set#clear");
16722
16723 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16724         .f = cmd_config_dynf_specific_parsed,
16725         .data = NULL,
16726         .help_str = "port config <port id> dynf <name> set|clear",
16727         .tokens = {
16728                 (void *)&cmd_config_tx_dynf_specific_port,
16729                 (void *)&cmd_config_tx_dynf_specific_keyword,
16730                 (void *)&cmd_config_tx_dynf_specific_port_id,
16731                 (void *)&cmd_config_tx_dynf_specific_item,
16732                 (void *)&cmd_config_tx_dynf_specific_name,
16733                 (void *)&cmd_config_tx_dynf_specific_value,
16734                 NULL,
16735         },
16736 };
16737
16738 /* *** display tx_metadata per port configuration *** */
16739 struct cmd_show_tx_metadata_result {
16740         cmdline_fixed_string_t cmd_show;
16741         cmdline_fixed_string_t cmd_port;
16742         cmdline_fixed_string_t cmd_keyword;
16743         portid_t cmd_pid;
16744 };
16745
16746 static void
16747 cmd_show_tx_metadata_parsed(void *parsed_result,
16748                 __rte_unused struct cmdline *cl,
16749                 __rte_unused void *data)
16750 {
16751         struct cmd_show_tx_metadata_result *res = parsed_result;
16752
16753         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16754                 printf("invalid port id %u\n", res->cmd_pid);
16755                 return;
16756         }
16757         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16758                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16759                        ports[res->cmd_pid].tx_metadata);
16760         }
16761 }
16762
16763 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16764         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16765                         cmd_show, "show");
16766 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16767         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16768                         cmd_port, "port");
16769 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16770         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16771                         cmd_pid, RTE_UINT16);
16772 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16773         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16774                         cmd_keyword, "tx_metadata");
16775
16776 cmdline_parse_inst_t cmd_show_tx_metadata = {
16777         .f = cmd_show_tx_metadata_parsed,
16778         .data = NULL,
16779         .help_str = "show port <port_id> tx_metadata",
16780         .tokens = {
16781                 (void *)&cmd_show_tx_metadata_show,
16782                 (void *)&cmd_show_tx_metadata_port,
16783                 (void *)&cmd_show_tx_metadata_pid,
16784                 (void *)&cmd_show_tx_metadata_keyword,
16785                 NULL,
16786         },
16787 };
16788
16789 /* *** show fec capability per port configuration *** */
16790 struct cmd_show_fec_capability_result {
16791         cmdline_fixed_string_t cmd_show;
16792         cmdline_fixed_string_t cmd_port;
16793         cmdline_fixed_string_t cmd_fec;
16794         cmdline_fixed_string_t cmd_keyword;
16795         portid_t cmd_pid;
16796 };
16797
16798 static void
16799 cmd_show_fec_capability_parsed(void *parsed_result,
16800                 __rte_unused struct cmdline *cl,
16801                 __rte_unused void *data)
16802 {
16803         struct cmd_show_fec_capability_result *res = parsed_result;
16804         struct rte_eth_fec_capa *speed_fec_capa;
16805         unsigned int num;
16806         int ret;
16807
16808         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16809                 printf("Invalid port id %u\n", res->cmd_pid);
16810                 return;
16811         }
16812
16813         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16814         if (ret == -ENOTSUP) {
16815                 printf("Function not implemented\n");
16816                 return;
16817         } else if (ret < 0) {
16818                 printf("Get FEC capability failed: %d\n", ret);
16819                 return;
16820         }
16821
16822         num = (unsigned int)ret;
16823         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16824         if (speed_fec_capa == NULL) {
16825                 printf("Failed to alloc FEC capability buffer\n");
16826                 return;
16827         }
16828
16829         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16830         if (ret < 0) {
16831                 printf("Error getting FEC capability: %d\n", ret);
16832                 goto out;
16833         }
16834
16835         show_fec_capability(num, speed_fec_capa);
16836 out:
16837         free(speed_fec_capa);
16838 }
16839
16840 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16841         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16842                         cmd_show, "show");
16843 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16844         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16845                         cmd_port, "port");
16846 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16847         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16848                         cmd_pid, RTE_UINT16);
16849 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16850         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16851                         cmd_fec, "fec");
16852 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16853         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16854                         cmd_keyword, "capabilities");
16855
16856 cmdline_parse_inst_t cmd_show_capability = {
16857         .f = cmd_show_fec_capability_parsed,
16858         .data = NULL,
16859         .help_str = "show port <port_id> fec capabilities",
16860         .tokens = {
16861                 (void *)&cmd_show_fec_capability_show,
16862                 (void *)&cmd_show_fec_capability_port,
16863                 (void *)&cmd_show_fec_capability_pid,
16864                 (void *)&cmd_show_fec_capability_fec,
16865                 (void *)&cmd_show_fec_capability_keyword,
16866                 NULL,
16867         },
16868 };
16869
16870 /* *** show fec mode per port configuration *** */
16871 struct cmd_show_fec_metadata_result {
16872         cmdline_fixed_string_t cmd_show;
16873         cmdline_fixed_string_t cmd_port;
16874         cmdline_fixed_string_t cmd_keyword;
16875         portid_t cmd_pid;
16876 };
16877
16878 static void
16879 cmd_show_fec_mode_parsed(void *parsed_result,
16880                 __rte_unused struct cmdline *cl,
16881                 __rte_unused void *data)
16882 {
16883 #define FEC_NAME_SIZE 16
16884         struct cmd_show_fec_metadata_result *res = parsed_result;
16885         uint32_t mode;
16886         char buf[FEC_NAME_SIZE];
16887         int ret;
16888
16889         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16890                 printf("Invalid port id %u\n", res->cmd_pid);
16891                 return;
16892         }
16893         ret = rte_eth_fec_get(res->cmd_pid, &mode);
16894         if (ret == -ENOTSUP) {
16895                 printf("Function not implemented\n");
16896                 return;
16897         } else if (ret < 0) {
16898                 printf("Get FEC mode failed\n");
16899                 return;
16900         }
16901
16902         switch (mode) {
16903         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
16904                 strlcpy(buf, "off", sizeof(buf));
16905                 break;
16906         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
16907                 strlcpy(buf, "auto", sizeof(buf));
16908                 break;
16909         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
16910                 strlcpy(buf, "baser", sizeof(buf));
16911                 break;
16912         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
16913                 strlcpy(buf, "rs", sizeof(buf));
16914                 break;
16915         default:
16916                 return;
16917         }
16918
16919         printf("%s\n", buf);
16920 }
16921
16922 cmdline_parse_token_string_t cmd_show_fec_mode_show =
16923         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16924                         cmd_show, "show");
16925 cmdline_parse_token_string_t cmd_show_fec_mode_port =
16926         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16927                         cmd_port, "port");
16928 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
16929         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
16930                         cmd_pid, RTE_UINT16);
16931 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
16932         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
16933                         cmd_keyword, "fec_mode");
16934
16935 cmdline_parse_inst_t cmd_show_fec_mode = {
16936         .f = cmd_show_fec_mode_parsed,
16937         .data = NULL,
16938         .help_str = "show port <port_id> fec_mode",
16939         .tokens = {
16940                 (void *)&cmd_show_fec_mode_show,
16941                 (void *)&cmd_show_fec_mode_port,
16942                 (void *)&cmd_show_fec_mode_pid,
16943                 (void *)&cmd_show_fec_mode_keyword,
16944                 NULL,
16945         },
16946 };
16947
16948 /* *** set fec mode per port configuration *** */
16949 struct cmd_set_port_fec_mode {
16950         cmdline_fixed_string_t set;
16951         cmdline_fixed_string_t port;
16952         portid_t port_id;
16953         cmdline_fixed_string_t fec_mode;
16954         cmdline_fixed_string_t fec_value;
16955 };
16956
16957 /* Common CLI fields for set fec mode */
16958 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
16959         TOKEN_STRING_INITIALIZER
16960                 (struct cmd_set_port_fec_mode,
16961                  set, "set");
16962 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
16963         TOKEN_STRING_INITIALIZER
16964                 (struct cmd_set_port_fec_mode,
16965                  port, "port");
16966 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
16967         TOKEN_NUM_INITIALIZER
16968                 (struct cmd_set_port_fec_mode,
16969                  port_id, RTE_UINT16);
16970 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
16971         TOKEN_STRING_INITIALIZER
16972                 (struct cmd_set_port_fec_mode,
16973                  fec_mode, "fec_mode");
16974 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
16975         TOKEN_STRING_INITIALIZER
16976                 (struct cmd_set_port_fec_mode,
16977                  fec_value, NULL);
16978
16979 static void
16980 cmd_set_port_fec_mode_parsed(
16981         void *parsed_result,
16982         __rte_unused struct cmdline *cl,
16983         __rte_unused void *data)
16984 {
16985         struct cmd_set_port_fec_mode *res = parsed_result;
16986         uint16_t port_id = res->port_id;
16987         uint32_t mode;
16988         int ret;
16989
16990         ret = parse_fec_mode(res->fec_value, &mode);
16991         if (ret < 0) {
16992                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
16993                         port_id);
16994                 return;
16995         }
16996
16997         ret = rte_eth_fec_set(port_id, mode);
16998         if (ret == -ENOTSUP) {
16999                 printf("Function not implemented\n");
17000                 return;
17001         } else if (ret < 0) {
17002                 printf("Set FEC mode failed\n");
17003                 return;
17004         }
17005 }
17006
17007 cmdline_parse_inst_t cmd_set_fec_mode = {
17008         .f = cmd_set_port_fec_mode_parsed,
17009         .data = NULL,
17010         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17011         .tokens = {
17012                 (void *)&cmd_set_port_fec_mode_set,
17013                 (void *)&cmd_set_port_fec_mode_port,
17014                 (void *)&cmd_set_port_fec_mode_port_id,
17015                 (void *)&cmd_set_port_fec_mode_str,
17016                 (void *)&cmd_set_port_fec_mode_value,
17017                 NULL,
17018         },
17019 };
17020
17021 /* show port supported ptypes */
17022
17023 /* Common result structure for show port ptypes */
17024 struct cmd_show_port_supported_ptypes_result {
17025         cmdline_fixed_string_t show;
17026         cmdline_fixed_string_t port;
17027         portid_t port_id;
17028         cmdline_fixed_string_t ptypes;
17029 };
17030
17031 /* Common CLI fields for show port ptypes */
17032 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17033         TOKEN_STRING_INITIALIZER
17034                 (struct cmd_show_port_supported_ptypes_result,
17035                  show, "show");
17036 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17037         TOKEN_STRING_INITIALIZER
17038                 (struct cmd_show_port_supported_ptypes_result,
17039                  port, "port");
17040 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17041         TOKEN_NUM_INITIALIZER
17042                 (struct cmd_show_port_supported_ptypes_result,
17043                  port_id, RTE_UINT16);
17044 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17045         TOKEN_STRING_INITIALIZER
17046                 (struct cmd_show_port_supported_ptypes_result,
17047                  ptypes, "ptypes");
17048
17049 static void
17050 cmd_show_port_supported_ptypes_parsed(
17051         void *parsed_result,
17052         __rte_unused struct cmdline *cl,
17053         __rte_unused void *data)
17054 {
17055 #define RSVD_PTYPE_MASK       0xf0000000
17056 #define MAX_PTYPES_PER_LAYER  16
17057 #define LTYPE_NAMESIZE        32
17058 #define PTYPE_NAMESIZE        256
17059         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17060         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17061         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17062         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17063         uint16_t port_id = res->port_id;
17064         int ret, i;
17065
17066         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17067         if (ret < 0)
17068                 return;
17069
17070         while (ptype_mask != RSVD_PTYPE_MASK) {
17071
17072                 switch (ptype_mask) {
17073                 case RTE_PTYPE_L2_MASK:
17074                         strlcpy(ltype, "L2", sizeof(ltype));
17075                         break;
17076                 case RTE_PTYPE_L3_MASK:
17077                         strlcpy(ltype, "L3", sizeof(ltype));
17078                         break;
17079                 case RTE_PTYPE_L4_MASK:
17080                         strlcpy(ltype, "L4", sizeof(ltype));
17081                         break;
17082                 case RTE_PTYPE_TUNNEL_MASK:
17083                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17084                         break;
17085                 case RTE_PTYPE_INNER_L2_MASK:
17086                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17087                         break;
17088                 case RTE_PTYPE_INNER_L3_MASK:
17089                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17090                         break;
17091                 case RTE_PTYPE_INNER_L4_MASK:
17092                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17093                         break;
17094                 default:
17095                         return;
17096                 }
17097
17098                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17099                                                        ptype_mask, ptypes,
17100                                                        MAX_PTYPES_PER_LAYER);
17101
17102                 if (ret > 0)
17103                         printf("Supported %s ptypes:\n", ltype);
17104                 else
17105                         printf("%s ptypes unsupported\n", ltype);
17106
17107                 for (i = 0; i < ret; ++i) {
17108                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17109                         printf("%s\n", buf);
17110                 }
17111
17112                 ptype_mask <<= 4;
17113         }
17114 }
17115
17116 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17117         .f = cmd_show_port_supported_ptypes_parsed,
17118         .data = NULL,
17119         .help_str = "show port <port_id> ptypes",
17120         .tokens = {
17121                 (void *)&cmd_show_port_supported_ptypes_show,
17122                 (void *)&cmd_show_port_supported_ptypes_port,
17123                 (void *)&cmd_show_port_supported_ptypes_port_id,
17124                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17125                 NULL,
17126         },
17127 };
17128
17129 /* *** display rx/tx descriptor status *** */
17130 struct cmd_show_rx_tx_desc_status_result {
17131         cmdline_fixed_string_t cmd_show;
17132         cmdline_fixed_string_t cmd_port;
17133         cmdline_fixed_string_t cmd_keyword;
17134         cmdline_fixed_string_t cmd_desc;
17135         cmdline_fixed_string_t cmd_status;
17136         portid_t cmd_pid;
17137         portid_t cmd_qid;
17138         portid_t cmd_did;
17139 };
17140
17141 static void
17142 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17143                 __rte_unused struct cmdline *cl,
17144                 __rte_unused void *data)
17145 {
17146         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17147         int rc;
17148
17149         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17150                 printf("invalid port id %u\n", res->cmd_pid);
17151                 return;
17152         }
17153
17154         if (!strcmp(res->cmd_keyword, "rxq")) {
17155                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17156                                              res->cmd_did);
17157                 if (rc < 0) {
17158                         printf("Invalid input: queue id = %d, desc id = %d\n",
17159                                res->cmd_qid, res->cmd_did);
17160                         return;
17161                 }
17162                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17163                         printf("Desc status = AVAILABLE\n");
17164                 else if (rc == RTE_ETH_RX_DESC_DONE)
17165                         printf("Desc status = DONE\n");
17166                 else
17167                         printf("Desc status = UNAVAILABLE\n");
17168         } else if (!strcmp(res->cmd_keyword, "txq")) {
17169                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17170                                              res->cmd_did);
17171                 if (rc < 0) {
17172                         printf("Invalid input: queue id = %d, desc id = %d\n",
17173                                res->cmd_qid, res->cmd_did);
17174                         return;
17175                 }
17176                 if (rc == RTE_ETH_TX_DESC_FULL)
17177                         printf("Desc status = FULL\n");
17178                 else if (rc == RTE_ETH_TX_DESC_DONE)
17179                         printf("Desc status = DONE\n");
17180                 else
17181                         printf("Desc status = UNAVAILABLE\n");
17182         }
17183 }
17184
17185 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17186         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17187                         cmd_show, "show");
17188 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17189         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17190                         cmd_port, "port");
17191 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17192         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17193                         cmd_pid, RTE_UINT16);
17194 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17195         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17196                         cmd_keyword, "rxq#txq");
17197 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17198         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17199                         cmd_qid, RTE_UINT16);
17200 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17201         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17202                         cmd_desc, "desc");
17203 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17204         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17205                         cmd_did, RTE_UINT16);
17206 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17207         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17208                         cmd_status, "status");
17209 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17210         .f = cmd_show_rx_tx_desc_status_parsed,
17211         .data = NULL,
17212         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17213                 "status",
17214         .tokens = {
17215                 (void *)&cmd_show_rx_tx_desc_status_show,
17216                 (void *)&cmd_show_rx_tx_desc_status_port,
17217                 (void *)&cmd_show_rx_tx_desc_status_pid,
17218                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17219                 (void *)&cmd_show_rx_tx_desc_status_qid,
17220                 (void *)&cmd_show_rx_tx_desc_status_desc,
17221                 (void *)&cmd_show_rx_tx_desc_status_did,
17222                 (void *)&cmd_show_rx_tx_desc_status_status,
17223                 NULL,
17224         },
17225 };
17226
17227 /* *** display rx queue desc used count *** */
17228 struct cmd_show_rx_queue_desc_used_count_result {
17229         cmdline_fixed_string_t cmd_show;
17230         cmdline_fixed_string_t cmd_port;
17231         cmdline_fixed_string_t cmd_rxq;
17232         cmdline_fixed_string_t cmd_desc;
17233         cmdline_fixed_string_t cmd_used;
17234         cmdline_fixed_string_t cmd_count;
17235         portid_t cmd_pid;
17236         portid_t cmd_qid;
17237 };
17238
17239 static void
17240 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17241                 __rte_unused struct cmdline *cl,
17242                 __rte_unused void *data)
17243 {
17244         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17245         int rc;
17246
17247         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17248                 printf("invalid port id %u\n", res->cmd_pid);
17249                 return;
17250         }
17251
17252         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17253         if (rc < 0) {
17254                 printf("Invalid queueid = %d\n", res->cmd_qid);
17255                 return;
17256         }
17257         printf("Used desc count = %d\n", rc);
17258 }
17259
17260 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17261         TOKEN_STRING_INITIALIZER
17262                 (struct cmd_show_rx_queue_desc_used_count_result,
17263                  cmd_show, "show");
17264 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17265         TOKEN_STRING_INITIALIZER
17266                 (struct cmd_show_rx_queue_desc_used_count_result,
17267                  cmd_port, "port");
17268 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17269         TOKEN_NUM_INITIALIZER
17270                 (struct cmd_show_rx_queue_desc_used_count_result,
17271                  cmd_pid, RTE_UINT16);
17272 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17273         TOKEN_STRING_INITIALIZER
17274                 (struct cmd_show_rx_queue_desc_used_count_result,
17275                  cmd_rxq, "rxq");
17276 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17277         TOKEN_NUM_INITIALIZER
17278                 (struct cmd_show_rx_queue_desc_used_count_result,
17279                  cmd_qid, RTE_UINT16);
17280 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17281         TOKEN_STRING_INITIALIZER
17282                 (struct cmd_show_rx_queue_desc_used_count_result,
17283                  cmd_count, "desc");
17284 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17285         TOKEN_STRING_INITIALIZER
17286                 (struct cmd_show_rx_queue_desc_used_count_result,
17287                  cmd_count, "used");
17288 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17289         TOKEN_STRING_INITIALIZER
17290                 (struct cmd_show_rx_queue_desc_used_count_result,
17291                  cmd_count, "count");
17292 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17293         .f = cmd_show_rx_queue_desc_used_count_parsed,
17294         .data = NULL,
17295         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17296         .tokens = {
17297                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17298                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17299                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17300                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17301                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17302                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17303                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17304                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17305                 NULL,
17306         },
17307 };
17308
17309 /* Common result structure for set port ptypes */
17310 struct cmd_set_port_ptypes_result {
17311         cmdline_fixed_string_t set;
17312         cmdline_fixed_string_t port;
17313         portid_t port_id;
17314         cmdline_fixed_string_t ptype_mask;
17315         uint32_t mask;
17316 };
17317
17318 /* Common CLI fields for set port ptypes */
17319 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17320         TOKEN_STRING_INITIALIZER
17321                 (struct cmd_set_port_ptypes_result,
17322                  set, "set");
17323 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17324         TOKEN_STRING_INITIALIZER
17325                 (struct cmd_set_port_ptypes_result,
17326                  port, "port");
17327 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17328         TOKEN_NUM_INITIALIZER
17329                 (struct cmd_set_port_ptypes_result,
17330                  port_id, RTE_UINT16);
17331 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17332         TOKEN_STRING_INITIALIZER
17333                 (struct cmd_set_port_ptypes_result,
17334                  ptype_mask, "ptype_mask");
17335 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17336         TOKEN_NUM_INITIALIZER
17337                 (struct cmd_set_port_ptypes_result,
17338                  mask, RTE_UINT32);
17339
17340 static void
17341 cmd_set_port_ptypes_parsed(
17342         void *parsed_result,
17343         __rte_unused struct cmdline *cl,
17344         __rte_unused void *data)
17345 {
17346         struct cmd_set_port_ptypes_result *res = parsed_result;
17347 #define PTYPE_NAMESIZE        256
17348         char ptype_name[PTYPE_NAMESIZE];
17349         uint16_t port_id = res->port_id;
17350         uint32_t ptype_mask = res->mask;
17351         int ret, i;
17352
17353         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17354                                                NULL, 0);
17355         if (ret <= 0) {
17356                 printf("Port %d doesn't support any ptypes.\n", port_id);
17357                 return;
17358         }
17359
17360         uint32_t ptypes[ret];
17361
17362         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17363         if (ret < 0) {
17364                 printf("Unable to set requested ptypes for Port %d\n", port_id);
17365                 return;
17366         }
17367
17368         printf("Successfully set following ptypes for Port %d\n", port_id);
17369         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17370                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17371                 printf("%s\n", ptype_name);
17372         }
17373
17374         clear_ptypes = false;
17375 }
17376
17377 cmdline_parse_inst_t cmd_set_port_ptypes = {
17378         .f = cmd_set_port_ptypes_parsed,
17379         .data = NULL,
17380         .help_str = "set port <port_id> ptype_mask <mask>",
17381         .tokens = {
17382                 (void *)&cmd_set_port_ptypes_set,
17383                 (void *)&cmd_set_port_ptypes_port,
17384                 (void *)&cmd_set_port_ptypes_port_id,
17385                 (void *)&cmd_set_port_ptypes_mask_str,
17386                 (void *)&cmd_set_port_ptypes_mask_u32,
17387                 NULL,
17388         },
17389 };
17390
17391 /* *** display mac addresses added to a port *** */
17392 struct cmd_showport_macs_result {
17393         cmdline_fixed_string_t cmd_show;
17394         cmdline_fixed_string_t cmd_port;
17395         cmdline_fixed_string_t cmd_keyword;
17396         portid_t cmd_pid;
17397 };
17398
17399 static void
17400 cmd_showport_macs_parsed(void *parsed_result,
17401                 __rte_unused struct cmdline *cl,
17402                 __rte_unused void *data)
17403 {
17404         struct cmd_showport_macs_result *res = parsed_result;
17405
17406         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17407                 return;
17408
17409         if (!strcmp(res->cmd_keyword, "macs"))
17410                 show_macs(res->cmd_pid);
17411         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17412                 show_mcast_macs(res->cmd_pid);
17413 }
17414
17415 cmdline_parse_token_string_t cmd_showport_macs_show =
17416         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17417                         cmd_show, "show");
17418 cmdline_parse_token_string_t cmd_showport_macs_port =
17419         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17420                         cmd_port, "port");
17421 cmdline_parse_token_num_t cmd_showport_macs_pid =
17422         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17423                         cmd_pid, RTE_UINT16);
17424 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17425         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17426                         cmd_keyword, "macs#mcast_macs");
17427
17428 cmdline_parse_inst_t cmd_showport_macs = {
17429         .f = cmd_showport_macs_parsed,
17430         .data = NULL,
17431         .help_str = "show port <port_id> macs|mcast_macs",
17432         .tokens = {
17433                 (void *)&cmd_showport_macs_show,
17434                 (void *)&cmd_showport_macs_port,
17435                 (void *)&cmd_showport_macs_pid,
17436                 (void *)&cmd_showport_macs_keyword,
17437                 NULL,
17438         },
17439 };
17440
17441 /* ******************************************************************************** */
17442
17443 /* list of instructions */
17444 cmdline_parse_ctx_t main_ctx[] = {
17445         (cmdline_parse_inst_t *)&cmd_help_brief,
17446         (cmdline_parse_inst_t *)&cmd_help_long,
17447         (cmdline_parse_inst_t *)&cmd_quit,
17448         (cmdline_parse_inst_t *)&cmd_load_from_file,
17449         (cmdline_parse_inst_t *)&cmd_showport,
17450         (cmdline_parse_inst_t *)&cmd_showqueue,
17451         (cmdline_parse_inst_t *)&cmd_showeeprom,
17452         (cmdline_parse_inst_t *)&cmd_showportall,
17453         (cmdline_parse_inst_t *)&cmd_showdevice,
17454         (cmdline_parse_inst_t *)&cmd_showcfg,
17455         (cmdline_parse_inst_t *)&cmd_showfwdall,
17456         (cmdline_parse_inst_t *)&cmd_start,
17457         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17458         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17459         (cmdline_parse_inst_t *)&cmd_set_link_up,
17460         (cmdline_parse_inst_t *)&cmd_set_link_down,
17461         (cmdline_parse_inst_t *)&cmd_reset,
17462         (cmdline_parse_inst_t *)&cmd_set_numbers,
17463         (cmdline_parse_inst_t *)&cmd_set_log,
17464         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17465         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17466         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17467         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17468         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17469         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17470         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17471         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17472         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17473         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17474         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17475         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17476         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17477         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17478         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17479         (cmdline_parse_inst_t *)&cmd_set_link_check,
17480         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17481         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17482         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17483         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17484 #ifdef RTE_NET_BOND
17485         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17486         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17487         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17488         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17489         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17490         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17491         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17492         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17493         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17494         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17495         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17496 #endif
17497         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17498         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17499         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17500         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17501         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17502         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17503         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17504         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17505         (cmdline_parse_inst_t *)&cmd_csum_set,
17506         (cmdline_parse_inst_t *)&cmd_csum_show,
17507         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17508         (cmdline_parse_inst_t *)&cmd_tso_set,
17509         (cmdline_parse_inst_t *)&cmd_tso_show,
17510         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17511         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17512         (cmdline_parse_inst_t *)&cmd_gro_enable,
17513         (cmdline_parse_inst_t *)&cmd_gro_flush,
17514         (cmdline_parse_inst_t *)&cmd_gro_show,
17515         (cmdline_parse_inst_t *)&cmd_gso_enable,
17516         (cmdline_parse_inst_t *)&cmd_gso_size,
17517         (cmdline_parse_inst_t *)&cmd_gso_show,
17518         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17519         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17520         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17521         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17522         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17523         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17524         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17525         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17526         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17527         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17528         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17529         (cmdline_parse_inst_t *)&cmd_config_dcb,
17530         (cmdline_parse_inst_t *)&cmd_read_reg,
17531         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17532         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17533         (cmdline_parse_inst_t *)&cmd_write_reg,
17534         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17535         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17536         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17537         (cmdline_parse_inst_t *)&cmd_stop,
17538         (cmdline_parse_inst_t *)&cmd_mac_addr,
17539         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17540         (cmdline_parse_inst_t *)&cmd_set_qmap,
17541         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17542         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17543         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17544         (cmdline_parse_inst_t *)&cmd_operate_port,
17545         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17546         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17547         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17548         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17549         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17550         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17551         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17552         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17553         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17554         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17555         (cmdline_parse_inst_t *)&cmd_config_mtu,
17556         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17557         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17558         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17559         (cmdline_parse_inst_t *)&cmd_config_rss,
17560         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17561         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17562         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17563         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17564         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17565         (cmdline_parse_inst_t *)&cmd_showport_reta,
17566         (cmdline_parse_inst_t *)&cmd_showport_macs,
17567         (cmdline_parse_inst_t *)&cmd_config_burst,
17568         (cmdline_parse_inst_t *)&cmd_config_thresh,
17569         (cmdline_parse_inst_t *)&cmd_config_threshold,
17570         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17571         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17572         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17573         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17574         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17575         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
17576         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
17577         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
17578         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17579         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17580         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17581         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17582         (cmdline_parse_inst_t *)&cmd_dump,
17583         (cmdline_parse_inst_t *)&cmd_dump_one,
17584 #ifdef RTE_NET_I40E
17585         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17586 #endif
17587         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17588         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17589         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17590         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17591         (cmdline_parse_inst_t *)&cmd_flow,
17592         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17593         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17594         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17595         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17596         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17597         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17598         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17599         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17600         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17601         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17602         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17603         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17604         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17605         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17606         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17607         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17608         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17609         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17610         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17611         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17612         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17613         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17614         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17615         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17616         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17617         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17618         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17619         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17620         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17621         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17622         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17623         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17624         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17625         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17626         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17627         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17628         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17629         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17630         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17631         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17632         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17633         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17634         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17635         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17636         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17637         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17638         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17639         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17640         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17641         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17642         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17643         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17644         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17645         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17646         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17647         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17648         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17649         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17650         (cmdline_parse_inst_t *)&cmd_ddp_add,
17651         (cmdline_parse_inst_t *)&cmd_ddp_del,
17652         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17653         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17654         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17655         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17656         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17657         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17658         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17659         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17660         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17661         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17662         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17663         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17664
17665         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17666         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17667         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17668         (cmdline_parse_inst_t *)&cmd_queue_region,
17669         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17670         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17671         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17672         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17673         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17674         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17675         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17676         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17677         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17678         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17679         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17680         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17681         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17682         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17683         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17684         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17685         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17686         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17687         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17688         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17689         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17690         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17691         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17692         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17693         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17694         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17695         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17696         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17697         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17698         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17699         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17700         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17701         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17702         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17703         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17704         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17705 #ifdef RTE_LIB_BPF
17706         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17707         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17708 #endif
17709         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17710         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17711         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17712         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17713         (cmdline_parse_inst_t *)&cmd_set_raw,
17714         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17715         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17716         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17717         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17718         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17719         (cmdline_parse_inst_t *)&cmd_show_capability,
17720         NULL,
17721 };
17722
17723 /* read cmdline commands from file */
17724 void
17725 cmdline_read_from_file(const char *filename)
17726 {
17727         struct cmdline *cl;
17728
17729         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17730         if (cl == NULL) {
17731                 printf("Failed to create file based cmdline context: %s\n",
17732                        filename);
17733                 return;
17734         }
17735
17736         cmdline_interact(cl);
17737         cmdline_quit(cl);
17738
17739         cmdline_free(cl);
17740
17741         printf("Read CLI commands from %s\n", filename);
17742 }
17743
17744 /* prompt function, called from main on MAIN lcore */
17745 void
17746 prompt(void)
17747 {
17748         int ret;
17749         /* initialize non-constant commands */
17750         cmd_set_fwd_mode_init();
17751         cmd_set_fwd_retry_mode_init();
17752
17753         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17754         if (testpmd_cl == NULL)
17755                 return;
17756
17757         ret = atexit(prompt_exit);
17758         if (ret != 0)
17759                 printf("Cannot set exit function for cmdline\n");
17760
17761         cmdline_interact(testpmd_cl);
17762         if (ret != 0)
17763                 cmdline_stdin_exit(testpmd_cl);
17764 }
17765
17766 void
17767 prompt_exit(void)
17768 {
17769         if (testpmd_cl != NULL) {
17770                 cmdline_quit(testpmd_cl);
17771                 cmdline_stdin_exit(testpmd_cl);
17772         }
17773 }
17774
17775 static void
17776 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17777 {
17778         if (id == (portid_t)RTE_PORT_ALL) {
17779                 portid_t pid;
17780
17781                 RTE_ETH_FOREACH_DEV(pid) {
17782                         /* check if need_reconfig has been set to 1 */
17783                         if (ports[pid].need_reconfig == 0)
17784                                 ports[pid].need_reconfig = dev;
17785                         /* check if need_reconfig_queues has been set to 1 */
17786                         if (ports[pid].need_reconfig_queues == 0)
17787                                 ports[pid].need_reconfig_queues = queue;
17788                 }
17789         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17790                 /* check if need_reconfig has been set to 1 */
17791                 if (ports[id].need_reconfig == 0)
17792                         ports[id].need_reconfig = dev;
17793                 /* check if need_reconfig_queues has been set to 1 */
17794                 if (ports[id].need_reconfig_queues == 0)
17795                         ports[id].need_reconfig_queues = queue;
17796         }
17797 }