f777cc453836a103f65049d573f45bd6f521f350
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <inttypes.h>
13 #include <sys/queue.h>
14
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_debug.h>
19 #include <rte_cycles.h>
20 #include <rte_memory.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_atomic.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_ring.h>
30 #include <rte_mempool.h>
31 #include <rte_interrupts.h>
32 #include <rte_pci.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_string_fns.h>
36 #include <rte_devargs.h>
37 #include <rte_flow.h>
38 #include <rte_gro.h>
39 #include <rte_mbuf_dyn.h>
40
41 #include <cmdline_rdline.h>
42 #include <cmdline_parse.h>
43 #include <cmdline_parse_num.h>
44 #include <cmdline_parse_string.h>
45 #include <cmdline_parse_ipaddr.h>
46 #include <cmdline_parse_etheraddr.h>
47 #include <cmdline_socket.h>
48 #include <cmdline.h>
49 #ifdef RTE_NET_BOND
50 #include <rte_eth_bond.h>
51 #include <rte_eth_bond_8023ad.h>
52 #endif
53 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
54 #include <rte_pmd_dpaa.h>
55 #endif
56 #ifdef RTE_NET_IXGBE
57 #include <rte_pmd_ixgbe.h>
58 #endif
59 #ifdef RTE_NET_I40E
60 #include <rte_pmd_i40e.h>
61 #endif
62 #ifdef RTE_NET_BNXT
63 #include <rte_pmd_bnxt.h>
64 #endif
65 #include "testpmd.h"
66 #include "cmdline_mtr.h"
67 #include "cmdline_tm.h"
68 #include "bpf_cmd.h"
69
70 static struct cmdline *testpmd_cl;
71
72 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
73
74 /* *** Help command with introduction. *** */
75 struct cmd_help_brief_result {
76         cmdline_fixed_string_t help;
77 };
78
79 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
80                                   struct cmdline *cl,
81                                   __rte_unused void *data)
82 {
83         cmdline_printf(
84                 cl,
85                 "\n"
86                 "Help is available for the following sections:\n\n"
87                 "    help control                    : Start and stop forwarding.\n"
88                 "    help display                    : Displaying port, stats and config "
89                 "information.\n"
90                 "    help config                     : Configuration information.\n"
91                 "    help ports                      : Configuring ports.\n"
92                 "    help registers                  : Reading and setting port registers.\n"
93                 "    help filters                    : Filters configuration help.\n"
94                 "    help traffic_management         : Traffic Management commands.\n"
95                 "    help devices                    : Device related cmds.\n"
96                 "    help all                        : All of the above sections.\n\n"
97         );
98
99 }
100
101 cmdline_parse_token_string_t cmd_help_brief_help =
102         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
103
104 cmdline_parse_inst_t cmd_help_brief = {
105         .f = cmd_help_brief_parsed,
106         .data = NULL,
107         .help_str = "help: Show help",
108         .tokens = {
109                 (void *)&cmd_help_brief_help,
110                 NULL,
111         },
112 };
113
114 /* *** Help command with help sections. *** */
115 struct cmd_help_long_result {
116         cmdline_fixed_string_t help;
117         cmdline_fixed_string_t section;
118 };
119
120 static void cmd_help_long_parsed(void *parsed_result,
121                                  struct cmdline *cl,
122                                  __rte_unused void *data)
123 {
124         int show_all = 0;
125         struct cmd_help_long_result *res = parsed_result;
126
127         if (!strcmp(res->section, "all"))
128                 show_all = 1;
129
130         if (show_all || !strcmp(res->section, "control")) {
131
132                 cmdline_printf(
133                         cl,
134                         "\n"
135                         "Control forwarding:\n"
136                         "-------------------\n\n"
137
138                         "start\n"
139                         "    Start packet forwarding with current configuration.\n\n"
140
141                         "start tx_first\n"
142                         "    Start packet forwarding with current config"
143                         " after sending one burst of packets.\n\n"
144
145                         "stop\n"
146                         "    Stop packet forwarding, and display accumulated"
147                         " statistics.\n\n"
148
149                         "quit\n"
150                         "    Quit to prompt.\n\n"
151                 );
152         }
153
154         if (show_all || !strcmp(res->section, "display")) {
155
156                 cmdline_printf(
157                         cl,
158                         "\n"
159                         "Display:\n"
160                         "--------\n\n"
161
162                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
163                         "    Display information for port_id, or all.\n\n"
164
165                         "show port info (port_id) representor\n"
166                         "    Show supported representors for a specific port\n\n"
167
168                         "show port port_id (module_eeprom|eeprom)\n"
169                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
170
171                         "show port X rss reta (size) (mask0,mask1,...)\n"
172                         "    Display the rss redirection table entry indicated"
173                         " by masks on port X. size is used to indicate the"
174                         " hardware supported reta size\n\n"
175
176                         "show port (port_id) rss-hash [key]\n"
177                         "    Display the RSS hash functions and RSS hash key of port\n\n"
178
179                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
180                         "    Clear information for port_id, or all.\n\n"
181
182                         "show (rxq|txq) info (port_id) (queue_id)\n"
183                         "    Display information for configured RX/TX queue.\n\n"
184
185                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
186                         "    Display the given configuration.\n\n"
187
188                         "read rxd (port_id) (queue_id) (rxd_id)\n"
189                         "    Display an RX descriptor of a port RX queue.\n\n"
190
191                         "read txd (port_id) (queue_id) (txd_id)\n"
192                         "    Display a TX descriptor of a port TX queue.\n\n"
193
194                         "ddp get list (port_id)\n"
195                         "    Get ddp profile info list\n\n"
196
197                         "ddp get info (profile_path)\n"
198                         "    Get ddp profile information.\n\n"
199
200                         "show vf stats (port_id) (vf_id)\n"
201                         "    Display a VF's statistics.\n\n"
202
203                         "clear vf stats (port_id) (vf_id)\n"
204                         "    Reset a VF's statistics.\n\n"
205
206                         "show port (port_id) pctype mapping\n"
207                         "    Get flow ptype to pctype mapping on a port\n\n"
208
209                         "show port meter stats (port_id) (meter_id) (clear)\n"
210                         "    Get meter stats on a port\n\n"
211
212                         "show fwd stats all\n"
213                         "    Display statistics for all fwd engines.\n\n"
214
215                         "clear fwd stats all\n"
216                         "    Clear statistics for all fwd engines.\n\n"
217
218                         "show port (port_id) rx_offload capabilities\n"
219                         "    List all per queue and per port Rx offloading"
220                         " capabilities of a port\n\n"
221
222                         "show port (port_id) rx_offload configuration\n"
223                         "    List port level and all queue level"
224                         " Rx offloading configuration\n\n"
225
226                         "show port (port_id) tx_offload capabilities\n"
227                         "    List all per queue and per port"
228                         " Tx offloading capabilities of a port\n\n"
229
230                         "show port (port_id) tx_offload configuration\n"
231                         "    List port level and all queue level"
232                         " Tx offloading configuration\n\n"
233
234                         "show port (port_id) tx_metadata\n"
235                         "    Show Tx metadata value set"
236                         " for a specific port\n\n"
237
238                         "show port (port_id) ptypes\n"
239                         "    Show port supported ptypes"
240                         " for a specific port\n\n"
241
242                         "show device info (<identifier>|all)"
243                         "       Show general information about devices probed.\n\n"
244
245                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
246                         "       Show status of rx|tx descriptor.\n\n"
247
248                         "show port (port_id) rxq (queue_id) desc used count\n"
249                         "    Show current number of filled receive"
250                         " packet descriptors.\n\n"
251
252                         "show port (port_id) macs|mcast_macs"
253                         "       Display list of mac addresses added to port.\n\n"
254
255                         "show port (port_id) fec capabilities"
256                         "       Show fec capabilities of a port.\n\n"
257
258                         "show port (port_id) fec_mode"
259                         "       Show fec mode of a port.\n\n"
260
261                         "show port (port_id) flow_ctrl"
262                         "       Show flow control info of a port.\n\n"
263                 );
264         }
265
266         if (show_all || !strcmp(res->section, "config")) {
267                 cmdline_printf(
268                         cl,
269                         "\n"
270                         "Configuration:\n"
271                         "--------------\n"
272                         "Configuration changes only become active when"
273                         " forwarding is started/restarted.\n\n"
274
275                         "set default\n"
276                         "    Reset forwarding to the default configuration.\n\n"
277
278                         "set verbose (level)\n"
279                         "    Set the debug verbosity level X.\n\n"
280
281                         "set log global|(type) (level)\n"
282                         "    Set the log level.\n\n"
283
284                         "set nbport (num)\n"
285                         "    Set number of ports.\n\n"
286
287                         "set nbcore (num)\n"
288                         "    Set number of cores.\n\n"
289
290                         "set coremask (mask)\n"
291                         "    Set the forwarding cores hexadecimal mask.\n\n"
292
293                         "set portmask (mask)\n"
294                         "    Set the forwarding ports hexadecimal mask.\n\n"
295
296                         "set burst (num)\n"
297                         "    Set number of packets per burst.\n\n"
298
299                         "set burst tx delay (microseconds) retry (num)\n"
300                         "    Set the transmit delay time and number of retries,"
301                         " effective when retry is enabled.\n\n"
302
303                         "set rxoffs (x[,y]*)\n"
304                         "    Set the offset of each packet segment on"
305                         " receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set rxpkts (x[,y]*)\n"
310                         "    Set the length of each segment to scatter"
311                         " packets on receiving if split feature is engaged."
312                         " Affects only the queues configured with split"
313                         " offloads.\n\n"
314
315                         "set txpkts (x[,y]*)\n"
316                         "    Set the length of each segment of TXONLY"
317                         " and optionally CSUM packets.\n\n"
318
319                         "set txsplit (off|on|rand)\n"
320                         "    Set the split policy for the TX packets."
321                         " Right now only applicable for CSUM and TXONLY"
322                         " modes\n\n"
323
324                         "set txtimes (x, y)\n"
325                         "    Set the scheduling on timestamps"
326                         " timings for the TXONLY mode\n\n"
327
328                         "set corelist (x[,y]*)\n"
329                         "    Set the list of forwarding cores.\n\n"
330
331                         "set portlist (x[,y]*)\n"
332                         "    Set the list of forwarding ports.\n\n"
333
334                         "set port setup on (iterator|event)\n"
335                         "    Select how attached port is retrieved for setup.\n\n"
336
337                         "set tx loopback (port_id) (on|off)\n"
338                         "    Enable or disable tx loopback.\n\n"
339
340                         "set all queues drop (port_id) (on|off)\n"
341                         "    Set drop enable bit for all queues.\n\n"
342
343                         "set vf split drop (port_id) (vf_id) (on|off)\n"
344                         "    Set split drop enable bit for a VF from the PF.\n\n"
345
346                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
347                         "    Set MAC antispoof for a VF from the PF.\n\n"
348
349                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
350                         "    Enable MACsec offload.\n\n"
351
352                         "set macsec offload (port_id) off\n"
353                         "    Disable MACsec offload.\n\n"
354
355                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
356                         "    Configure MACsec secure connection (SC).\n\n"
357
358                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
359                         "    Configure MACsec secure association (SA).\n\n"
360
361                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
362                         "    Set VF broadcast for a VF from the PF.\n\n"
363
364                         "vlan set stripq (on|off) (port_id,queue_id)\n"
365                         "    Set the VLAN strip for a queue on a port.\n\n"
366
367                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
368                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
369
370                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
371                         "    Set VLAN insert for a VF from the PF.\n\n"
372
373                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
374                         "    Set VLAN antispoof for a VF from the PF.\n\n"
375
376                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
377                         "    Set VLAN tag for a VF from the PF.\n\n"
378
379                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
380                         "    Set a VF's max bandwidth(Mbps).\n\n"
381
382                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
383                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
384
385                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
386                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
387
388                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
389                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
390
391                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
392                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
393
394                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
395                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
396
397                         "vlan set (inner|outer) tpid (value) (port_id)\n"
398                         "    Set the VLAN TPID for Packet Filtering on"
399                         " a port\n\n"
400
401                         "rx_vlan add (vlan_id|all) (port_id)\n"
402                         "    Add a vlan_id, or all identifiers, to the set"
403                         " of VLAN identifiers filtered by port_id.\n\n"
404
405                         "rx_vlan rm (vlan_id|all) (port_id)\n"
406                         "    Remove a vlan_id, or all identifiers, from the set"
407                         " of VLAN identifiers filtered by port_id.\n\n"
408
409                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
410                         "    Add a vlan_id, to the set of VLAN identifiers"
411                         "filtered for VF(s) from port_id.\n\n"
412
413                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
414                         "    Remove a vlan_id, to the set of VLAN identifiers"
415                         "filtered for VF(s) from port_id.\n\n"
416
417                         "rx_vxlan_port add (udp_port) (port_id)\n"
418                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
419
420                         "rx_vxlan_port rm (udp_port) (port_id)\n"
421                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
422
423                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
424                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
425                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
426
427                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
428                         "    Set port based TX VLAN insertion.\n\n"
429
430                         "tx_vlan reset (port_id)\n"
431                         "    Disable hardware insertion of a VLAN header in"
432                         " packets sent on a port.\n\n"
433
434                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
435                         "    Select hardware or software calculation of the"
436                         " checksum when transmitting a packet using the"
437                         " csum forward engine.\n"
438                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
439                         "    outer-ip concerns the outer IP layer in"
440                         "    outer-udp concerns the outer UDP layer in"
441                         " case the packet is recognized as a tunnel packet by"
442                         " the forward engine (vxlan, gre and ipip are supported)\n"
443                         "    Please check the NIC datasheet for HW limits.\n\n"
444
445                         "csum parse-tunnel (on|off) (tx_port_id)\n"
446                         "    If disabled, treat tunnel packets as non-tunneled"
447                         " packets (treat inner headers as payload). The port\n"
448                         "    argument is the port used for TX in csum forward"
449                         " engine.\n\n"
450
451                         "csum show (port_id)\n"
452                         "    Display tx checksum offload configuration\n\n"
453
454                         "tso set (segsize) (portid)\n"
455                         "    Enable TCP Segmentation Offload in csum forward"
456                         " engine.\n"
457                         "    Please check the NIC datasheet for HW limits.\n\n"
458
459                         "tso show (portid)"
460                         "    Display the status of TCP Segmentation Offload.\n\n"
461
462                         "set port (port_id) gro on|off\n"
463                         "    Enable or disable Generic Receive Offload in"
464                         " csum forwarding engine.\n\n"
465
466                         "show port (port_id) gro\n"
467                         "    Display GRO configuration.\n\n"
468
469                         "set gro flush (cycles)\n"
470                         "    Set the cycle to flush GROed packets from"
471                         " reassembly tables.\n\n"
472
473                         "set port (port_id) gso (on|off)"
474                         "    Enable or disable Generic Segmentation Offload in"
475                         " csum forwarding engine.\n\n"
476
477                         "set gso segsz (length)\n"
478                         "    Set max packet length for output GSO segments,"
479                         " including packet header and payload.\n\n"
480
481                         "show port (port_id) gso\n"
482                         "    Show GSO configuration.\n\n"
483
484                         "set fwd (%s)\n"
485                         "    Set packet forwarding mode.\n\n"
486
487                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Add a MAC address on port_id.\n\n"
489
490                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
491                         "    Remove a MAC address from port_id.\n\n"
492
493                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
494                         "    Set the default MAC address for port_id.\n\n"
495
496                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
497                         "    Add a MAC address for a VF on the port.\n\n"
498
499                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
500                         "    Set the MAC address for a VF from the PF.\n\n"
501
502                         "set eth-peer (port_id) (peer_addr)\n"
503                         "    set the peer address for certain port.\n\n"
504
505                         "set port (port_id) uta (mac_address|all) (on|off)\n"
506                         "    Add/Remove a or all unicast hash filter(s)"
507                         "from port X.\n\n"
508
509                         "set promisc (port_id|all) (on|off)\n"
510                         "    Set the promiscuous mode on port_id, or all.\n\n"
511
512                         "set allmulti (port_id|all) (on|off)\n"
513                         "    Set the allmulti mode on port_id, or all.\n\n"
514
515                         "set vf promisc (port_id) (vf_id) (on|off)\n"
516                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
517
518                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
519                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
520
521                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
522                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
523                         " (on|off) autoneg (on|off) (port_id)\n"
524                         "set flow_ctrl rx (on|off) (portid)\n"
525                         "set flow_ctrl tx (on|off) (portid)\n"
526                         "set flow_ctrl high_water (high_water) (portid)\n"
527                         "set flow_ctrl low_water (low_water) (portid)\n"
528                         "set flow_ctrl pause_time (pause_time) (portid)\n"
529                         "set flow_ctrl send_xon (send_xon) (portid)\n"
530                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
531                         "set flow_ctrl autoneg (on|off) (port_id)\n"
532                         "    Set the link flow control parameter on a port.\n\n"
533
534                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
535                         " (low_water) (pause_time) (priority) (port_id)\n"
536                         "    Set the priority flow control parameter on a"
537                         " port.\n\n"
538
539                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
540                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
541                         " queue on port.\n"
542                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
543                         " on port 0 to mapping 5.\n\n"
544
545                         "set xstats-hide-zero on|off\n"
546                         "    Set the option to hide the zero values"
547                         " for xstats display.\n"
548
549                         "set record-core-cycles on|off\n"
550                         "    Set the option to enable measurement of CPU cycles.\n"
551
552                         "set record-burst-stats on|off\n"
553                         "    Set the option to enable display of RX and TX bursts.\n"
554
555                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
556                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
557
558                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
559                         "|MPE) (on|off)\n"
560                         "    AUPE:accepts untagged VLAN;"
561                         "ROPE:accept unicast hash\n\n"
562                         "    BAM:accepts broadcast packets;"
563                         "MPE:accepts all multicast packets\n\n"
564                         "    Enable/Disable a VF receive mode of a port\n\n"
565
566                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
567                         "    Set rate limit for a queue of a port\n\n"
568
569                         "set port (port_id) vf (vf_id) rate (rate_num) "
570                         "queue_mask (queue_mask_value)\n"
571                         "    Set rate limit for queues in VF of a port\n\n"
572
573                         "set flush_rx (on|off)\n"
574                         "   Flush (default) or don't flush RX streams before"
575                         " forwarding. Mainly used with PCAP drivers.\n\n"
576
577                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
578                         "   Set the bypass mode for the lowest port on bypass enabled"
579                         " NIC.\n\n"
580
581                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
582                         "mode (normal|bypass|isolate) (port_id)\n"
583                         "   Set the event required to initiate specified bypass mode for"
584                         " the lowest port on a bypass enabled NIC where:\n"
585                         "       timeout   = enable bypass after watchdog timeout.\n"
586                         "       os_on     = enable bypass when OS/board is powered on.\n"
587                         "       os_off    = enable bypass when OS/board is powered off.\n"
588                         "       power_on  = enable bypass when power supply is turned on.\n"
589                         "       power_off = enable bypass when power supply is turned off."
590                         "\n\n"
591
592                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
593                         "   Set the bypass watchdog timeout to 'n' seconds"
594                         " where 0 = instant.\n\n"
595
596                         "show bypass config (port_id)\n"
597                         "   Show the bypass configuration for a bypass enabled NIC"
598                         " using the lowest port on the NIC.\n\n"
599
600 #ifdef RTE_NET_BOND
601                         "create bonded device (mode) (socket)\n"
602                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
603
604                         "add bonding slave (slave_id) (port_id)\n"
605                         "       Add a slave device to a bonded device.\n\n"
606
607                         "remove bonding slave (slave_id) (port_id)\n"
608                         "       Remove a slave device from a bonded device.\n\n"
609
610                         "set bonding mode (value) (port_id)\n"
611                         "       Set the bonding mode on a bonded device.\n\n"
612
613                         "set bonding primary (slave_id) (port_id)\n"
614                         "       Set the primary slave for a bonded device.\n\n"
615
616                         "show bonding config (port_id)\n"
617                         "       Show the bonding config for port_id.\n\n"
618
619                         "show bonding lacp info (port_id)\n"
620                         "       Show the bonding lacp information for port_id.\n\n"
621
622                         "set bonding mac_addr (port_id) (address)\n"
623                         "       Set the MAC address of a bonded device.\n\n"
624
625                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
626                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
627
628                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
629                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
630
631                         "set bonding mon_period (port_id) (value)\n"
632                         "       Set the bonding link status monitoring polling period in ms.\n\n"
633
634                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
635                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
636
637 #endif
638                         "set link-up port (port_id)\n"
639                         "       Set link up for a port.\n\n"
640
641                         "set link-down port (port_id)\n"
642                         "       Set link down for a port.\n\n"
643
644                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
645                         "    Load a profile package on a port\n\n"
646
647                         "ddp del (port_id) (backup_profile_path)\n"
648                         "    Delete a profile package from a port\n\n"
649
650                         "ptype mapping get (port_id) (valid_only)\n"
651                         "    Get ptype mapping on a port\n\n"
652
653                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
654                         "    Replace target with the pkt_type in ptype mapping\n\n"
655
656                         "ptype mapping reset (port_id)\n"
657                         "    Reset ptype mapping on a port\n\n"
658
659                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
660                         "    Update a ptype mapping item on a port\n\n"
661
662                         "set port (port_id) ptype_mask (ptype_mask)\n"
663                         "    set packet types classification for a specific port\n\n"
664
665                         "set port (port_id) queue-region region_id (value) "
666                         "queue_start_index (value) queue_num (value)\n"
667                         "    Set a queue region on a port\n\n"
668
669                         "set port (port_id) queue-region region_id (value) "
670                         "flowtype (value)\n"
671                         "    Set a flowtype region index on a port\n\n"
672
673                         "set port (port_id) queue-region UP (value) region_id (value)\n"
674                         "    Set the mapping of User Priority to "
675                         "queue region on a port\n\n"
676
677                         "set port (port_id) queue-region flush (on|off)\n"
678                         "    flush all queue region related configuration\n\n"
679
680                         "show port meter cap (port_id)\n"
681                         "    Show port meter capability information\n\n"
682
683                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
684                         "    meter profile add - srtcm rfc 2697\n\n"
685
686                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
687                         "    meter profile add - trtcm rfc 2698\n\n"
688
689                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
690                         "    meter profile add - trtcm rfc 4115\n\n"
691
692                         "del port meter profile (port_id) (profile_id)\n"
693                         "    meter profile delete\n\n"
694
695                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
696                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
697                         "(dscp_tbl_entry63)]\n"
698                         "    meter create\n\n"
699
700                         "enable port meter (port_id) (mtr_id)\n"
701                         "    meter enable\n\n"
702
703                         "disable port meter (port_id) (mtr_id)\n"
704                         "    meter disable\n\n"
705
706                         "del port meter (port_id) (mtr_id)\n"
707                         "    meter delete\n\n"
708
709                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
710                         "y_actions (actions) r_actions (actions)\n"
711                         "    meter policy add\n\n"
712
713                         "del port meter policy (port_id) (policy_id)\n"
714                         "    meter policy delete\n\n"
715
716                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
717                         "    meter update meter profile\n\n"
718
719                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
720                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
721                         "    update meter dscp table entries\n\n"
722
723                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
724                         "(action0) [(action1) (action2)]\n"
725                         "    meter update policer action\n\n"
726
727                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
728                         "    meter update stats\n\n"
729
730                         "show port (port_id) queue-region\n"
731                         "    show all queue region related configuration info\n\n"
732
733                         "set port (port_id) fec_mode auto|off|rs|baser\n"
734                         "    set fec mode for a specific port\n\n"
735
736                         , list_pkt_forwarding_modes()
737                 );
738         }
739
740         if (show_all || !strcmp(res->section, "ports")) {
741
742                 cmdline_printf(
743                         cl,
744                         "\n"
745                         "Port Operations:\n"
746                         "----------------\n\n"
747
748                         "port start (port_id|all)\n"
749                         "    Start all ports or port_id.\n\n"
750
751                         "port stop (port_id|all)\n"
752                         "    Stop all ports or port_id.\n\n"
753
754                         "port close (port_id|all)\n"
755                         "    Close all ports or port_id.\n\n"
756
757                         "port reset (port_id|all)\n"
758                         "    Reset all ports or port_id.\n\n"
759
760                         "port attach (ident)\n"
761                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
762
763                         "port detach (port_id)\n"
764                         "    Detach physical or virtual dev by port_id\n\n"
765
766                         "port config (port_id|all)"
767                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
768                         " duplex (half|full|auto)\n"
769                         "    Set speed and duplex for all ports or port_id\n\n"
770
771                         "port config (port_id|all) loopback (mode)\n"
772                         "    Set loopback mode for all ports or port_id\n\n"
773
774                         "port config all (rxq|txq|rxd|txd) (value)\n"
775                         "    Set number for rxq/txq/rxd/txd.\n\n"
776
777                         "port config all max-pkt-len (value)\n"
778                         "    Set the max packet length.\n\n"
779
780                         "port config all max-lro-pkt-size (value)\n"
781                         "    Set the max LRO aggregated packet size.\n\n"
782
783                         "port config all drop-en (on|off)\n"
784                         "    Enable or disable packet drop on all RX queues of all ports when no "
785                         "receive buffers available.\n\n"
786
787                         "port config all rss (all|default|ip|tcp|udp|sctp|"
788                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
789                         "level-outer|level-inner|<flowtype_id>)\n"
790                         "    Set the RSS mode.\n\n"
791
792                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
793                         "    Set the RSS redirection table.\n\n"
794
795                         "port config (port_id) dcb vt (on|off) (traffic_class)"
796                         " pfc (on|off)\n"
797                         "    Set the DCB mode.\n\n"
798
799                         "port config all burst (value)\n"
800                         "    Set the number of packets per burst.\n\n"
801
802                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
803                         " (value)\n"
804                         "    Set the ring prefetch/host/writeback threshold"
805                         " for tx/rx queue.\n\n"
806
807                         "port config all (txfreet|txrst|rxfreet) (value)\n"
808                         "    Set free threshold for rx/tx, or set"
809                         " tx rs bit threshold.\n\n"
810                         "port config mtu X value\n"
811                         "    Set the MTU of port X to a given value\n\n"
812
813                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
814                         "    Set a rx/tx queue's ring size configuration, the new"
815                         " value will take effect after command that (re-)start the port"
816                         " or command that setup the specific queue\n\n"
817
818                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
819                         "    Start/stop a rx/tx queue of port X. Only take effect"
820                         " when port X is started\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
823                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
824                         " take effect when port X is stopped.\n\n"
825
826                         "port (port_id) (rxq|txq) (queue_id) setup\n"
827                         "    Setup a rx/tx queue of port X.\n\n"
828
829                         "port config (port_id) pctype mapping reset\n"
830                         "    Reset flow type to pctype mapping on a port\n\n"
831
832                         "port config (port_id) pctype mapping update"
833                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
834                         "    Update a flow type to pctype mapping item on a port\n\n"
835
836                         "port config (port_id) pctype (pctype_id) hash_inset|"
837                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
838                         " (field_idx)\n"
839                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
840
841                         "port config (port_id) pctype (pctype_id) hash_inset|"
842                         "fdir_inset|fdir_flx_inset clear all"
843                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
844
845                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
846                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
847
848                         "port config <port_id> rx_offload vlan_strip|"
849                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
850                         "outer_ipv4_cksum|macsec_strip|header_split|"
851                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
852                         "buffer_split|timestamp|security|keep_crc on|off\n"
853                         "     Enable or disable a per port Rx offloading"
854                         " on all Rx queues of a port\n\n"
855
856                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
857                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
858                         "outer_ipv4_cksum|macsec_strip|header_split|"
859                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
860                         "buffer_split|timestamp|security|keep_crc on|off\n"
861                         "    Enable or disable a per queue Rx offloading"
862                         " only on a specific Rx queue\n\n"
863
864                         "port config (port_id) tx_offload vlan_insert|"
865                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
866                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
867                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
868                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
869                         "security on|off\n"
870                         "    Enable or disable a per port Tx offloading"
871                         " on all Tx queues of a port\n\n"
872
873                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
874                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
875                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
876                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
877                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
878                         " on|off\n"
879                         "    Enable or disable a per queue Tx offloading"
880                         " only on a specific Tx queue\n\n"
881
882                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
883                         "    Load an eBPF program as a callback"
884                         " for particular RX/TX queue\n\n"
885
886                         "bpf-unload rx|tx (port) (queue)\n"
887                         "    Unload previously loaded eBPF program"
888                         " for particular RX/TX queue\n\n"
889
890                         "port config (port_id) tx_metadata (value)\n"
891                         "    Set Tx metadata value per port. Testpmd will add this value"
892                         " to any Tx packet sent from this port\n\n"
893
894                         "port config (port_id) dynf (name) set|clear\n"
895                         "    Register a dynf and Set/clear this flag on Tx. "
896                         "Testpmd will set this value to any Tx packet "
897                         "sent from this port\n\n"
898
899                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
900                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
901                 );
902         }
903
904         if (show_all || !strcmp(res->section, "registers")) {
905
906                 cmdline_printf(
907                         cl,
908                         "\n"
909                         "Registers:\n"
910                         "----------\n\n"
911
912                         "read reg (port_id) (address)\n"
913                         "    Display value of a port register.\n\n"
914
915                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
916                         "    Display a port register bit field.\n\n"
917
918                         "read regbit (port_id) (address) (bit_x)\n"
919                         "    Display a single port register bit.\n\n"
920
921                         "write reg (port_id) (address) (value)\n"
922                         "    Set value of a port register.\n\n"
923
924                         "write regfield (port_id) (address) (bit_x) (bit_y)"
925                         " (value)\n"
926                         "    Set bit field of a port register.\n\n"
927
928                         "write regbit (port_id) (address) (bit_x) (value)\n"
929                         "    Set single bit value of a port register.\n\n"
930                 );
931         }
932         if (show_all || !strcmp(res->section, "filters")) {
933
934                 cmdline_printf(
935                         cl,
936                         "\n"
937                         "filters:\n"
938                         "--------\n\n"
939
940 #ifdef RTE_NET_I40E
941                         "flow_director_filter (port_id) mode raw (add|del|update)"
942                         " flow (flow_id) (drop|fwd) queue (queue_id)"
943                         " fd_id (fd_id_value) packet (packet file name)\n"
944                         "    Add/Del a raw type flow director filter.\n\n"
945 #endif
946
947                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
948                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
949                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
950                         "    Set flow director IP mask.\n\n"
951
952                         "flow_director_mask (port_id) mode MAC-VLAN"
953                         " vlan (vlan_value)\n"
954                         "    Set flow director MAC-VLAN mask.\n\n"
955
956                         "flow_director_mask (port_id) mode Tunnel"
957                         " vlan (vlan_value) mac (mac_value)"
958                         " tunnel-type (tunnel_type_value)"
959                         " tunnel-id (tunnel_id_value)\n"
960                         "    Set flow director Tunnel mask.\n\n"
961
962                         "flow_director_flex_payload (port_id)"
963                         " (raw|l2|l3|l4) (config)\n"
964                         "    Configure flex payload selection.\n\n"
965
966                         "flow validate {port_id}"
967                         " [group {group_id}] [priority {level}]"
968                         " [ingress] [egress]"
969                         " pattern {item} [/ {item} [...]] / end"
970                         " actions {action} [/ {action} [...]] / end\n"
971                         "    Check whether a flow rule can be created.\n\n"
972
973                         "flow create {port_id}"
974                         " [group {group_id}] [priority {level}]"
975                         " [ingress] [egress]"
976                         " pattern {item} [/ {item} [...]] / end"
977                         " actions {action} [/ {action} [...]] / end\n"
978                         "    Create a flow rule.\n\n"
979
980                         "flow destroy {port_id} rule {rule_id} [...]\n"
981                         "    Destroy specific flow rules.\n\n"
982
983                         "flow flush {port_id}\n"
984                         "    Destroy all flow rules.\n\n"
985
986                         "flow query {port_id} {rule_id} {action}\n"
987                         "    Query an existing flow rule.\n\n"
988
989                         "flow list {port_id} [group {group_id}] [...]\n"
990                         "    List existing flow rules sorted by priority,"
991                         " filtered by group identifiers.\n\n"
992
993                         "flow isolate {port_id} {boolean}\n"
994                         "    Restrict ingress traffic to the defined"
995                         " flow rules\n\n"
996
997                         "flow aged {port_id} [destroy]\n"
998                         "    List and destroy aged flows"
999                         " flow rules\n\n"
1000
1001                         "flow indirect_action {port_id} create"
1002                         " [action_id {indirect_action_id}]"
1003                         " [ingress] [egress]"
1004                         " action {action} / end\n"
1005                         "    Create indirect action.\n\n"
1006
1007                         "flow indirect_action {port_id} update"
1008                         " {indirect_action_id} action {action} / end\n"
1009                         "    Update indirect action.\n\n"
1010
1011                         "flow indirect_action {port_id} destroy"
1012                         " action_id {indirect_action_id} [...]\n"
1013                         "    Destroy specific indirect actions.\n\n"
1014
1015                         "flow indirect_action {port_id} query"
1016                         " {indirect_action_id}\n"
1017                         "    Query an existing indirect action.\n\n"
1018
1019                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1020                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1021                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1022                         "       Configure the VXLAN encapsulation for flows.\n\n"
1023
1024                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1025                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1026                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1027                         " eth-dst (eth-dst)\n"
1028                         "       Configure the VXLAN encapsulation for flows.\n\n"
1029
1030                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1031                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1032                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1033                         " eth-dst (eth-dst)\n"
1034                         "       Configure the VXLAN encapsulation for flows.\n\n"
1035
1036                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1037                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1038                         " (eth-dst)\n"
1039                         "       Configure the NVGRE encapsulation for flows.\n\n"
1040
1041                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1042                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1043                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1044                         "       Configure the NVGRE encapsulation for flows.\n\n"
1045
1046                         "set raw_encap {flow items}\n"
1047                         "       Configure the encapsulation with raw data.\n\n"
1048
1049                         "set raw_decap {flow items}\n"
1050                         "       Configure the decapsulation with raw data.\n\n"
1051
1052                 );
1053         }
1054
1055         if (show_all || !strcmp(res->section, "traffic_management")) {
1056                 cmdline_printf(
1057                         cl,
1058                         "\n"
1059                         "Traffic Management:\n"
1060                         "--------------\n"
1061                         "show port tm cap (port_id)\n"
1062                         "       Display the port TM capability.\n\n"
1063
1064                         "show port tm level cap (port_id) (level_id)\n"
1065                         "       Display the port TM hierarchical level capability.\n\n"
1066
1067                         "show port tm node cap (port_id) (node_id)\n"
1068                         "       Display the port TM node capability.\n\n"
1069
1070                         "show port tm node type (port_id) (node_id)\n"
1071                         "       Display the port TM node type.\n\n"
1072
1073                         "show port tm node stats (port_id) (node_id) (clear)\n"
1074                         "       Display the port TM node stats.\n\n"
1075
1076                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1077                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1078                         " (packet_length_adjust) (packet_mode)\n"
1079                         "       Add port tm node private shaper profile.\n\n"
1080
1081                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1082                         "       Delete port tm node private shaper profile.\n\n"
1083
1084                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1085                         " (shaper_profile_id)\n"
1086                         "       Add/update port tm node shared shaper.\n\n"
1087
1088                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1089                         "       Delete port tm node shared shaper.\n\n"
1090
1091                         "set port tm node shaper profile (port_id) (node_id)"
1092                         " (shaper_profile_id)\n"
1093                         "       Set port tm node shaper profile.\n\n"
1094
1095                         "add port tm node wred profile (port_id) (wred_profile_id)"
1096                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1097                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1098                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1099                         "       Add port tm node wred profile.\n\n"
1100
1101                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1102                         "       Delete port tm node wred profile.\n\n"
1103
1104                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1105                         " (priority) (weight) (level_id) (shaper_profile_id)"
1106                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1107                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1108                         "       Add port tm nonleaf node.\n\n"
1109
1110                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1111                         " (priority) (weight) (level_id) (shaper_profile_id)"
1112                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1113                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1114                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1115
1116                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1117                         " (priority) (weight) (level_id) (shaper_profile_id)"
1118                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1119                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1120                         "       Add port tm leaf node.\n\n"
1121
1122                         "del port tm node (port_id) (node_id)\n"
1123                         "       Delete port tm node.\n\n"
1124
1125                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1126                         " (priority) (weight)\n"
1127                         "       Set port tm node parent.\n\n"
1128
1129                         "suspend port tm node (port_id) (node_id)"
1130                         "       Suspend tm node.\n\n"
1131
1132                         "resume port tm node (port_id) (node_id)"
1133                         "       Resume tm node.\n\n"
1134
1135                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1136                         "       Commit tm hierarchy.\n\n"
1137
1138                         "set port tm mark ip_ecn (port) (green) (yellow)"
1139                         " (red)\n"
1140                         "    Enables/Disables the traffic management marking"
1141                         " for IP ECN (Explicit Congestion Notification)"
1142                         " packets on a given port\n\n"
1143
1144                         "set port tm mark ip_dscp (port) (green) (yellow)"
1145                         " (red)\n"
1146                         "    Enables/Disables the traffic management marking"
1147                         " on the port for IP dscp packets\n\n"
1148
1149                         "set port tm mark vlan_dei (port) (green) (yellow)"
1150                         " (red)\n"
1151                         "    Enables/Disables the traffic management marking"
1152                         " on the port for VLAN packets with DEI enabled\n\n"
1153                 );
1154         }
1155
1156         if (show_all || !strcmp(res->section, "devices")) {
1157                 cmdline_printf(
1158                         cl,
1159                         "\n"
1160                         "Device Operations:\n"
1161                         "--------------\n"
1162                         "device detach (identifier)\n"
1163                         "       Detach device by identifier.\n\n"
1164                 );
1165         }
1166
1167 }
1168
1169 cmdline_parse_token_string_t cmd_help_long_help =
1170         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1171
1172 cmdline_parse_token_string_t cmd_help_long_section =
1173         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1174                         "all#control#display#config#"
1175                         "ports#registers#filters#traffic_management#devices");
1176
1177 cmdline_parse_inst_t cmd_help_long = {
1178         .f = cmd_help_long_parsed,
1179         .data = NULL,
1180         .help_str = "help all|control|display|config|ports|register|"
1181                 "filters|traffic_management|devices: "
1182                 "Show help",
1183         .tokens = {
1184                 (void *)&cmd_help_long_help,
1185                 (void *)&cmd_help_long_section,
1186                 NULL,
1187         },
1188 };
1189
1190
1191 /* *** start/stop/close all ports *** */
1192 struct cmd_operate_port_result {
1193         cmdline_fixed_string_t keyword;
1194         cmdline_fixed_string_t name;
1195         cmdline_fixed_string_t value;
1196 };
1197
1198 static void cmd_operate_port_parsed(void *parsed_result,
1199                                 __rte_unused struct cmdline *cl,
1200                                 __rte_unused void *data)
1201 {
1202         struct cmd_operate_port_result *res = parsed_result;
1203
1204         if (!strcmp(res->name, "start"))
1205                 start_port(RTE_PORT_ALL);
1206         else if (!strcmp(res->name, "stop"))
1207                 stop_port(RTE_PORT_ALL);
1208         else if (!strcmp(res->name, "close"))
1209                 close_port(RTE_PORT_ALL);
1210         else if (!strcmp(res->name, "reset"))
1211                 reset_port(RTE_PORT_ALL);
1212         else
1213                 fprintf(stderr, "Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1218                                                                 "port");
1219 cmdline_parse_token_string_t cmd_operate_port_all_port =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1221                                                 "start#stop#close#reset");
1222 cmdline_parse_token_string_t cmd_operate_port_all_all =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1224
1225 cmdline_parse_inst_t cmd_operate_port = {
1226         .f = cmd_operate_port_parsed,
1227         .data = NULL,
1228         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1229         .tokens = {
1230                 (void *)&cmd_operate_port_all_cmd,
1231                 (void *)&cmd_operate_port_all_port,
1232                 (void *)&cmd_operate_port_all_all,
1233                 NULL,
1234         },
1235 };
1236
1237 /* *** start/stop/close specific port *** */
1238 struct cmd_operate_specific_port_result {
1239         cmdline_fixed_string_t keyword;
1240         cmdline_fixed_string_t name;
1241         uint8_t value;
1242 };
1243
1244 static void cmd_operate_specific_port_parsed(void *parsed_result,
1245                         __rte_unused struct cmdline *cl,
1246                                 __rte_unused void *data)
1247 {
1248         struct cmd_operate_specific_port_result *res = parsed_result;
1249
1250         if (!strcmp(res->name, "start"))
1251                 start_port(res->value);
1252         else if (!strcmp(res->name, "stop"))
1253                 stop_port(res->value);
1254         else if (!strcmp(res->name, "close"))
1255                 close_port(res->value);
1256         else if (!strcmp(res->name, "reset"))
1257                 reset_port(res->value);
1258         else
1259                 fprintf(stderr, "Unknown parameter\n");
1260 }
1261
1262 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1263         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1264                                                         keyword, "port");
1265 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1266         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1267                                                 name, "start#stop#close#reset");
1268 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1269         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1270                                                         value, RTE_UINT8);
1271
1272 cmdline_parse_inst_t cmd_operate_specific_port = {
1273         .f = cmd_operate_specific_port_parsed,
1274         .data = NULL,
1275         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1276         .tokens = {
1277                 (void *)&cmd_operate_specific_port_cmd,
1278                 (void *)&cmd_operate_specific_port_port,
1279                 (void *)&cmd_operate_specific_port_id,
1280                 NULL,
1281         },
1282 };
1283
1284 /* *** enable port setup (after attach) via iterator or event *** */
1285 struct cmd_set_port_setup_on_result {
1286         cmdline_fixed_string_t set;
1287         cmdline_fixed_string_t port;
1288         cmdline_fixed_string_t setup;
1289         cmdline_fixed_string_t on;
1290         cmdline_fixed_string_t mode;
1291 };
1292
1293 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1294                                 __rte_unused struct cmdline *cl,
1295                                 __rte_unused void *data)
1296 {
1297         struct cmd_set_port_setup_on_result *res = parsed_result;
1298
1299         if (strcmp(res->mode, "event") == 0)
1300                 setup_on_probe_event = true;
1301         else if (strcmp(res->mode, "iterator") == 0)
1302                 setup_on_probe_event = false;
1303         else
1304                 fprintf(stderr, "Unknown mode\n");
1305 }
1306
1307 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1308         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1309                         set, "set");
1310 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1311         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1312                         port, "port");
1313 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1314         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1315                         setup, "setup");
1316 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1317         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1318                         on, "on");
1319 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1320         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1321                         mode, "iterator#event");
1322
1323 cmdline_parse_inst_t cmd_set_port_setup_on = {
1324         .f = cmd_set_port_setup_on_parsed,
1325         .data = NULL,
1326         .help_str = "set port setup on iterator|event",
1327         .tokens = {
1328                 (void *)&cmd_set_port_setup_on_set,
1329                 (void *)&cmd_set_port_setup_on_port,
1330                 (void *)&cmd_set_port_setup_on_setup,
1331                 (void *)&cmd_set_port_setup_on_on,
1332                 (void *)&cmd_set_port_setup_on_mode,
1333                 NULL,
1334         },
1335 };
1336
1337 /* *** attach a specified port *** */
1338 struct cmd_operate_attach_port_result {
1339         cmdline_fixed_string_t port;
1340         cmdline_fixed_string_t keyword;
1341         cmdline_multi_string_t identifier;
1342 };
1343
1344 static void cmd_operate_attach_port_parsed(void *parsed_result,
1345                                 __rte_unused struct cmdline *cl,
1346                                 __rte_unused void *data)
1347 {
1348         struct cmd_operate_attach_port_result *res = parsed_result;
1349
1350         if (!strcmp(res->keyword, "attach"))
1351                 attach_port(res->identifier);
1352         else
1353                 fprintf(stderr, "Unknown parameter\n");
1354 }
1355
1356 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1357         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1358                         port, "port");
1359 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1360         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1361                         keyword, "attach");
1362 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1363         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1364                         identifier, TOKEN_STRING_MULTI);
1365
1366 cmdline_parse_inst_t cmd_operate_attach_port = {
1367         .f = cmd_operate_attach_port_parsed,
1368         .data = NULL,
1369         .help_str = "port attach <identifier>: "
1370                 "(identifier: pci address or virtual dev name)",
1371         .tokens = {
1372                 (void *)&cmd_operate_attach_port_port,
1373                 (void *)&cmd_operate_attach_port_keyword,
1374                 (void *)&cmd_operate_attach_port_identifier,
1375                 NULL,
1376         },
1377 };
1378
1379 /* *** detach a specified port *** */
1380 struct cmd_operate_detach_port_result {
1381         cmdline_fixed_string_t port;
1382         cmdline_fixed_string_t keyword;
1383         portid_t port_id;
1384 };
1385
1386 static void cmd_operate_detach_port_parsed(void *parsed_result,
1387                                 __rte_unused struct cmdline *cl,
1388                                 __rte_unused void *data)
1389 {
1390         struct cmd_operate_detach_port_result *res = parsed_result;
1391
1392         if (!strcmp(res->keyword, "detach")) {
1393                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1394                 detach_port_device(res->port_id);
1395         } else {
1396                 fprintf(stderr, "Unknown parameter\n");
1397         }
1398 }
1399
1400 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1401         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1402                         port, "port");
1403 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1404         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1405                         keyword, "detach");
1406 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1407         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1408                         port_id, RTE_UINT16);
1409
1410 cmdline_parse_inst_t cmd_operate_detach_port = {
1411         .f = cmd_operate_detach_port_parsed,
1412         .data = NULL,
1413         .help_str = "port detach <port_id>",
1414         .tokens = {
1415                 (void *)&cmd_operate_detach_port_port,
1416                 (void *)&cmd_operate_detach_port_keyword,
1417                 (void *)&cmd_operate_detach_port_port_id,
1418                 NULL,
1419         },
1420 };
1421
1422 /* *** detach device by identifier *** */
1423 struct cmd_operate_detach_device_result {
1424         cmdline_fixed_string_t device;
1425         cmdline_fixed_string_t keyword;
1426         cmdline_fixed_string_t identifier;
1427 };
1428
1429 static void cmd_operate_detach_device_parsed(void *parsed_result,
1430                                 __rte_unused struct cmdline *cl,
1431                                 __rte_unused void *data)
1432 {
1433         struct cmd_operate_detach_device_result *res = parsed_result;
1434
1435         if (!strcmp(res->keyword, "detach"))
1436                 detach_devargs(res->identifier);
1437         else
1438                 fprintf(stderr, "Unknown parameter\n");
1439 }
1440
1441 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1442         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1443                         device, "device");
1444 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1445         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1446                         keyword, "detach");
1447 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1448         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1449                         identifier, NULL);
1450
1451 cmdline_parse_inst_t cmd_operate_detach_device = {
1452         .f = cmd_operate_detach_device_parsed,
1453         .data = NULL,
1454         .help_str = "device detach <identifier>:"
1455                 "(identifier: pci address or virtual dev name)",
1456         .tokens = {
1457                 (void *)&cmd_operate_detach_device_device,
1458                 (void *)&cmd_operate_detach_device_keyword,
1459                 (void *)&cmd_operate_detach_device_identifier,
1460                 NULL,
1461         },
1462 };
1463 /* *** configure speed for all ports *** */
1464 struct cmd_config_speed_all {
1465         cmdline_fixed_string_t port;
1466         cmdline_fixed_string_t keyword;
1467         cmdline_fixed_string_t all;
1468         cmdline_fixed_string_t item1;
1469         cmdline_fixed_string_t item2;
1470         cmdline_fixed_string_t value1;
1471         cmdline_fixed_string_t value2;
1472 };
1473
1474 static int
1475 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1476 {
1477
1478         int duplex;
1479
1480         if (!strcmp(duplexstr, "half")) {
1481                 duplex = ETH_LINK_HALF_DUPLEX;
1482         } else if (!strcmp(duplexstr, "full")) {
1483                 duplex = ETH_LINK_FULL_DUPLEX;
1484         } else if (!strcmp(duplexstr, "auto")) {
1485                 duplex = ETH_LINK_FULL_DUPLEX;
1486         } else {
1487                 fprintf(stderr, "Unknown duplex parameter\n");
1488                 return -1;
1489         }
1490
1491         if (!strcmp(speedstr, "10")) {
1492                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1493                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1494         } else if (!strcmp(speedstr, "100")) {
1495                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1496                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1497         } else {
1498                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1499                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1500                         return -1;
1501                 }
1502                 if (!strcmp(speedstr, "1000")) {
1503                         *speed = ETH_LINK_SPEED_1G;
1504                 } else if (!strcmp(speedstr, "10000")) {
1505                         *speed = ETH_LINK_SPEED_10G;
1506                 } else if (!strcmp(speedstr, "25000")) {
1507                         *speed = ETH_LINK_SPEED_25G;
1508                 } else if (!strcmp(speedstr, "40000")) {
1509                         *speed = ETH_LINK_SPEED_40G;
1510                 } else if (!strcmp(speedstr, "50000")) {
1511                         *speed = ETH_LINK_SPEED_50G;
1512                 } else if (!strcmp(speedstr, "100000")) {
1513                         *speed = ETH_LINK_SPEED_100G;
1514                 } else if (!strcmp(speedstr, "200000")) {
1515                         *speed = ETH_LINK_SPEED_200G;
1516                 } else if (!strcmp(speedstr, "auto")) {
1517                         *speed = ETH_LINK_SPEED_AUTONEG;
1518                 } else {
1519                         fprintf(stderr, "Unknown speed parameter\n");
1520                         return -1;
1521                 }
1522         }
1523
1524         if (*speed != ETH_LINK_SPEED_AUTONEG)
1525                 *speed |= ETH_LINK_SPEED_FIXED;
1526
1527         return 0;
1528 }
1529
1530 static void
1531 cmd_config_speed_all_parsed(void *parsed_result,
1532                         __rte_unused struct cmdline *cl,
1533                         __rte_unused void *data)
1534 {
1535         struct cmd_config_speed_all *res = parsed_result;
1536         uint32_t link_speed;
1537         portid_t pid;
1538
1539         if (!all_ports_stopped()) {
1540                 fprintf(stderr, "Please stop all ports first\n");
1541                 return;
1542         }
1543
1544         if (parse_and_check_speed_duplex(res->value1, res->value2,
1545                         &link_speed) < 0)
1546                 return;
1547
1548         RTE_ETH_FOREACH_DEV(pid) {
1549                 ports[pid].dev_conf.link_speeds = link_speed;
1550         }
1551
1552         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1553 }
1554
1555 cmdline_parse_token_string_t cmd_config_speed_all_port =
1556         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1557 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1558         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1559                                                         "config");
1560 cmdline_parse_token_string_t cmd_config_speed_all_all =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1562 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1564 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1565         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1566                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1567 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1568         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1569 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1571                                                 "half#full#auto");
1572
1573 cmdline_parse_inst_t cmd_config_speed_all = {
1574         .f = cmd_config_speed_all_parsed,
1575         .data = NULL,
1576         .help_str = "port config all speed "
1577                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1578                                                         "half|full|auto",
1579         .tokens = {
1580                 (void *)&cmd_config_speed_all_port,
1581                 (void *)&cmd_config_speed_all_keyword,
1582                 (void *)&cmd_config_speed_all_all,
1583                 (void *)&cmd_config_speed_all_item1,
1584                 (void *)&cmd_config_speed_all_value1,
1585                 (void *)&cmd_config_speed_all_item2,
1586                 (void *)&cmd_config_speed_all_value2,
1587                 NULL,
1588         },
1589 };
1590
1591 /* *** configure speed for specific port *** */
1592 struct cmd_config_speed_specific {
1593         cmdline_fixed_string_t port;
1594         cmdline_fixed_string_t keyword;
1595         portid_t id;
1596         cmdline_fixed_string_t item1;
1597         cmdline_fixed_string_t item2;
1598         cmdline_fixed_string_t value1;
1599         cmdline_fixed_string_t value2;
1600 };
1601
1602 static void
1603 cmd_config_speed_specific_parsed(void *parsed_result,
1604                                 __rte_unused struct cmdline *cl,
1605                                 __rte_unused void *data)
1606 {
1607         struct cmd_config_speed_specific *res = parsed_result;
1608         uint32_t link_speed;
1609
1610         if (port_id_is_invalid(res->id, ENABLED_WARN))
1611                 return;
1612
1613         if (!port_is_stopped(res->id)) {
1614                 fprintf(stderr, "Please stop port %d first\n", res->id);
1615                 return;
1616         }
1617
1618         if (parse_and_check_speed_duplex(res->value1, res->value2,
1619                         &link_speed) < 0)
1620                 return;
1621
1622         ports[res->id].dev_conf.link_speeds = link_speed;
1623
1624         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1625 }
1626
1627
1628 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1629         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1630                                                                 "port");
1631 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1632         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1633                                                                 "config");
1634 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1635         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1636 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1638                                                                 "speed");
1639 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1640         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1641                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1642 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1644                                                                 "duplex");
1645 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1646         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1647                                                         "half#full#auto");
1648
1649 cmdline_parse_inst_t cmd_config_speed_specific = {
1650         .f = cmd_config_speed_specific_parsed,
1651         .data = NULL,
1652         .help_str = "port config <port_id> speed "
1653                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1654                                                         "half|full|auto",
1655         .tokens = {
1656                 (void *)&cmd_config_speed_specific_port,
1657                 (void *)&cmd_config_speed_specific_keyword,
1658                 (void *)&cmd_config_speed_specific_id,
1659                 (void *)&cmd_config_speed_specific_item1,
1660                 (void *)&cmd_config_speed_specific_value1,
1661                 (void *)&cmd_config_speed_specific_item2,
1662                 (void *)&cmd_config_speed_specific_value2,
1663                 NULL,
1664         },
1665 };
1666
1667 /* *** configure loopback for all ports *** */
1668 struct cmd_config_loopback_all {
1669         cmdline_fixed_string_t port;
1670         cmdline_fixed_string_t keyword;
1671         cmdline_fixed_string_t all;
1672         cmdline_fixed_string_t item;
1673         uint32_t mode;
1674 };
1675
1676 static void
1677 cmd_config_loopback_all_parsed(void *parsed_result,
1678                         __rte_unused struct cmdline *cl,
1679                         __rte_unused void *data)
1680 {
1681         struct cmd_config_loopback_all *res = parsed_result;
1682         portid_t pid;
1683
1684         if (!all_ports_stopped()) {
1685                 fprintf(stderr, "Please stop all ports first\n");
1686                 return;
1687         }
1688
1689         RTE_ETH_FOREACH_DEV(pid) {
1690                 ports[pid].dev_conf.lpbk_mode = res->mode;
1691         }
1692
1693         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1694 }
1695
1696 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1697         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1698 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1699         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1700                                                         "config");
1701 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1702         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1703 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1704         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1705                                                         "loopback");
1706 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1707         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1708
1709 cmdline_parse_inst_t cmd_config_loopback_all = {
1710         .f = cmd_config_loopback_all_parsed,
1711         .data = NULL,
1712         .help_str = "port config all loopback <mode>",
1713         .tokens = {
1714                 (void *)&cmd_config_loopback_all_port,
1715                 (void *)&cmd_config_loopback_all_keyword,
1716                 (void *)&cmd_config_loopback_all_all,
1717                 (void *)&cmd_config_loopback_all_item,
1718                 (void *)&cmd_config_loopback_all_mode,
1719                 NULL,
1720         },
1721 };
1722
1723 /* *** configure loopback for specific port *** */
1724 struct cmd_config_loopback_specific {
1725         cmdline_fixed_string_t port;
1726         cmdline_fixed_string_t keyword;
1727         uint16_t port_id;
1728         cmdline_fixed_string_t item;
1729         uint32_t mode;
1730 };
1731
1732 static void
1733 cmd_config_loopback_specific_parsed(void *parsed_result,
1734                                 __rte_unused struct cmdline *cl,
1735                                 __rte_unused void *data)
1736 {
1737         struct cmd_config_loopback_specific *res = parsed_result;
1738
1739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1740                 return;
1741
1742         if (!port_is_stopped(res->port_id)) {
1743                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1744                 return;
1745         }
1746
1747         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1748
1749         cmd_reconfig_device_queue(res->port_id, 1, 1);
1750 }
1751
1752
1753 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1754         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1755                                                                 "port");
1756 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1757         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1758                                                                 "config");
1759 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1760         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1761                                                                 RTE_UINT16);
1762 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1763         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1764                                                                 "loopback");
1765 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1766         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1767                               RTE_UINT32);
1768
1769 cmdline_parse_inst_t cmd_config_loopback_specific = {
1770         .f = cmd_config_loopback_specific_parsed,
1771         .data = NULL,
1772         .help_str = "port config <port_id> loopback <mode>",
1773         .tokens = {
1774                 (void *)&cmd_config_loopback_specific_port,
1775                 (void *)&cmd_config_loopback_specific_keyword,
1776                 (void *)&cmd_config_loopback_specific_id,
1777                 (void *)&cmd_config_loopback_specific_item,
1778                 (void *)&cmd_config_loopback_specific_mode,
1779                 NULL,
1780         },
1781 };
1782
1783 /* *** configure txq/rxq, txd/rxd *** */
1784 struct cmd_config_rx_tx {
1785         cmdline_fixed_string_t port;
1786         cmdline_fixed_string_t keyword;
1787         cmdline_fixed_string_t all;
1788         cmdline_fixed_string_t name;
1789         uint16_t value;
1790 };
1791
1792 static void
1793 cmd_config_rx_tx_parsed(void *parsed_result,
1794                         __rte_unused struct cmdline *cl,
1795                         __rte_unused void *data)
1796 {
1797         struct cmd_config_rx_tx *res = parsed_result;
1798
1799         if (!all_ports_stopped()) {
1800                 fprintf(stderr, "Please stop all ports first\n");
1801                 return;
1802         }
1803         if (!strcmp(res->name, "rxq")) {
1804                 if (!res->value && !nb_txq) {
1805                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1806                         return;
1807                 }
1808                 if (check_nb_rxq(res->value) != 0)
1809                         return;
1810                 nb_rxq = res->value;
1811         }
1812         else if (!strcmp(res->name, "txq")) {
1813                 if (!res->value && !nb_rxq) {
1814                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1815                         return;
1816                 }
1817                 if (check_nb_txq(res->value) != 0)
1818                         return;
1819                 nb_txq = res->value;
1820         }
1821         else if (!strcmp(res->name, "rxd")) {
1822                 if (check_nb_rxd(res->value) != 0)
1823                         return;
1824                 nb_rxd = res->value;
1825         } else if (!strcmp(res->name, "txd")) {
1826                 if (check_nb_txd(res->value) != 0)
1827                         return;
1828
1829                 nb_txd = res->value;
1830         } else {
1831                 fprintf(stderr, "Unknown parameter\n");
1832                 return;
1833         }
1834
1835         fwd_config_setup();
1836
1837         init_port_config();
1838
1839         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1840 }
1841
1842 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1843         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1844 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1845         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1846 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1848 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1849         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1850                                                 "rxq#txq#rxd#txd");
1851 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1852         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1853
1854 cmdline_parse_inst_t cmd_config_rx_tx = {
1855         .f = cmd_config_rx_tx_parsed,
1856         .data = NULL,
1857         .help_str = "port config all rxq|txq|rxd|txd <value>",
1858         .tokens = {
1859                 (void *)&cmd_config_rx_tx_port,
1860                 (void *)&cmd_config_rx_tx_keyword,
1861                 (void *)&cmd_config_rx_tx_all,
1862                 (void *)&cmd_config_rx_tx_name,
1863                 (void *)&cmd_config_rx_tx_value,
1864                 NULL,
1865         },
1866 };
1867
1868 /* *** config max packet length *** */
1869 struct cmd_config_max_pkt_len_result {
1870         cmdline_fixed_string_t port;
1871         cmdline_fixed_string_t keyword;
1872         cmdline_fixed_string_t all;
1873         cmdline_fixed_string_t name;
1874         uint32_t value;
1875 };
1876
1877 static void
1878 cmd_config_max_pkt_len_parsed(void *parsed_result,
1879                                 __rte_unused struct cmdline *cl,
1880                                 __rte_unused void *data)
1881 {
1882         struct cmd_config_max_pkt_len_result *res = parsed_result;
1883         portid_t port_id;
1884         int ret;
1885
1886         if (strcmp(res->name, "max-pkt-len") != 0) {
1887                 printf("Unknown parameter\n");
1888                 return;
1889         }
1890
1891         if (!all_ports_stopped()) {
1892                 fprintf(stderr, "Please stop all ports first\n");
1893                 return;
1894         }
1895
1896         RTE_ETH_FOREACH_DEV(port_id) {
1897                 struct rte_port *port = &ports[port_id];
1898
1899                 if (res->value < RTE_ETHER_MIN_LEN) {
1900                         fprintf(stderr,
1901                                 "max-pkt-len can not be less than %d\n",
1902                                 RTE_ETHER_MIN_LEN);
1903                         return;
1904                 }
1905
1906                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1907                 if (ret != 0) {
1908                         fprintf(stderr,
1909                                 "rte_eth_dev_info_get() failed for port %u\n",
1910                                 port_id);
1911                         return;
1912                 }
1913
1914                 update_jumbo_frame_offload(port_id, res->value);
1915         }
1916
1917         init_port_config();
1918
1919         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1920 }
1921
1922 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1923         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1924                                                                 "port");
1925 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1926         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1927                                                                 "config");
1928 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1929         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1930                                                                 "all");
1931 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1932         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1933                                                                 "max-pkt-len");
1934 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1935         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1936                                                                 RTE_UINT32);
1937
1938 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1939         .f = cmd_config_max_pkt_len_parsed,
1940         .data = NULL,
1941         .help_str = "port config all max-pkt-len <value>",
1942         .tokens = {
1943                 (void *)&cmd_config_max_pkt_len_port,
1944                 (void *)&cmd_config_max_pkt_len_keyword,
1945                 (void *)&cmd_config_max_pkt_len_all,
1946                 (void *)&cmd_config_max_pkt_len_name,
1947                 (void *)&cmd_config_max_pkt_len_value,
1948                 NULL,
1949         },
1950 };
1951
1952 /* *** config max LRO aggregated packet size *** */
1953 struct cmd_config_max_lro_pkt_size_result {
1954         cmdline_fixed_string_t port;
1955         cmdline_fixed_string_t keyword;
1956         cmdline_fixed_string_t all;
1957         cmdline_fixed_string_t name;
1958         uint32_t value;
1959 };
1960
1961 static void
1962 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1963                                 __rte_unused struct cmdline *cl,
1964                                 __rte_unused void *data)
1965 {
1966         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1967         portid_t pid;
1968
1969         if (!all_ports_stopped()) {
1970                 fprintf(stderr, "Please stop all ports first\n");
1971                 return;
1972         }
1973
1974         RTE_ETH_FOREACH_DEV(pid) {
1975                 struct rte_port *port = &ports[pid];
1976
1977                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1978                         if (res->value ==
1979                                         port->dev_conf.rxmode.max_lro_pkt_size)
1980                                 return;
1981
1982                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1983                 } else {
1984                         fprintf(stderr, "Unknown parameter\n");
1985                         return;
1986                 }
1987         }
1988
1989         init_port_config();
1990
1991         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1992 }
1993
1994 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1995         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1996                                  port, "port");
1997 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
1998         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1999                                  keyword, "config");
2000 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2001         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2002                                  all, "all");
2003 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2004         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2005                                  name, "max-lro-pkt-size");
2006 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2007         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2008                               value, RTE_UINT32);
2009
2010 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2011         .f = cmd_config_max_lro_pkt_size_parsed,
2012         .data = NULL,
2013         .help_str = "port config all max-lro-pkt-size <value>",
2014         .tokens = {
2015                 (void *)&cmd_config_max_lro_pkt_size_port,
2016                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2017                 (void *)&cmd_config_max_lro_pkt_size_all,
2018                 (void *)&cmd_config_max_lro_pkt_size_name,
2019                 (void *)&cmd_config_max_lro_pkt_size_value,
2020                 NULL,
2021         },
2022 };
2023
2024 /* *** configure port MTU *** */
2025 struct cmd_config_mtu_result {
2026         cmdline_fixed_string_t port;
2027         cmdline_fixed_string_t keyword;
2028         cmdline_fixed_string_t mtu;
2029         portid_t port_id;
2030         uint16_t value;
2031 };
2032
2033 static void
2034 cmd_config_mtu_parsed(void *parsed_result,
2035                       __rte_unused struct cmdline *cl,
2036                       __rte_unused void *data)
2037 {
2038         struct cmd_config_mtu_result *res = parsed_result;
2039
2040         if (res->value < RTE_ETHER_MIN_LEN) {
2041                 fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2042                 return;
2043         }
2044         port_mtu_set(res->port_id, res->value);
2045 }
2046
2047 cmdline_parse_token_string_t cmd_config_mtu_port =
2048         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2049                                  "port");
2050 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2051         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2052                                  "config");
2053 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2054         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2055                                  "mtu");
2056 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2057         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2058                                  RTE_UINT16);
2059 cmdline_parse_token_num_t cmd_config_mtu_value =
2060         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2061                                  RTE_UINT16);
2062
2063 cmdline_parse_inst_t cmd_config_mtu = {
2064         .f = cmd_config_mtu_parsed,
2065         .data = NULL,
2066         .help_str = "port config mtu <port_id> <value>",
2067         .tokens = {
2068                 (void *)&cmd_config_mtu_port,
2069                 (void *)&cmd_config_mtu_keyword,
2070                 (void *)&cmd_config_mtu_mtu,
2071                 (void *)&cmd_config_mtu_port_id,
2072                 (void *)&cmd_config_mtu_value,
2073                 NULL,
2074         },
2075 };
2076
2077 /* *** configure rx mode *** */
2078 struct cmd_config_rx_mode_flag {
2079         cmdline_fixed_string_t port;
2080         cmdline_fixed_string_t keyword;
2081         cmdline_fixed_string_t all;
2082         cmdline_fixed_string_t name;
2083         cmdline_fixed_string_t value;
2084 };
2085
2086 static void
2087 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2088                                 __rte_unused struct cmdline *cl,
2089                                 __rte_unused void *data)
2090 {
2091         struct cmd_config_rx_mode_flag *res = parsed_result;
2092
2093         if (!all_ports_stopped()) {
2094                 fprintf(stderr, "Please stop all ports first\n");
2095                 return;
2096         }
2097
2098         if (!strcmp(res->name, "drop-en")) {
2099                 if (!strcmp(res->value, "on"))
2100                         rx_drop_en = 1;
2101                 else if (!strcmp(res->value, "off"))
2102                         rx_drop_en = 0;
2103                 else {
2104                         fprintf(stderr, "Unknown parameter\n");
2105                         return;
2106                 }
2107         } else {
2108                 fprintf(stderr, "Unknown parameter\n");
2109                 return;
2110         }
2111
2112         init_port_config();
2113
2114         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2115 }
2116
2117 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2119 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2120         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2121                                                                 "config");
2122 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2124 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2125         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2126                                         "drop-en");
2127 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2128         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2129                                                         "on#off");
2130
2131 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2132         .f = cmd_config_rx_mode_flag_parsed,
2133         .data = NULL,
2134         .help_str = "port config all drop-en on|off",
2135         .tokens = {
2136                 (void *)&cmd_config_rx_mode_flag_port,
2137                 (void *)&cmd_config_rx_mode_flag_keyword,
2138                 (void *)&cmd_config_rx_mode_flag_all,
2139                 (void *)&cmd_config_rx_mode_flag_name,
2140                 (void *)&cmd_config_rx_mode_flag_value,
2141                 NULL,
2142         },
2143 };
2144
2145 /* *** configure rss *** */
2146 struct cmd_config_rss {
2147         cmdline_fixed_string_t port;
2148         cmdline_fixed_string_t keyword;
2149         cmdline_fixed_string_t all;
2150         cmdline_fixed_string_t name;
2151         cmdline_fixed_string_t value;
2152 };
2153
2154 static void
2155 cmd_config_rss_parsed(void *parsed_result,
2156                         __rte_unused struct cmdline *cl,
2157                         __rte_unused void *data)
2158 {
2159         struct cmd_config_rss *res = parsed_result;
2160         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2161         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2162         int use_default = 0;
2163         int all_updated = 1;
2164         int diag;
2165         uint16_t i;
2166         int ret;
2167
2168         if (!strcmp(res->value, "all"))
2169                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2170                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2171                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2172                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU |
2173                         ETH_RSS_ECPRI;
2174         else if (!strcmp(res->value, "eth"))
2175                 rss_conf.rss_hf = ETH_RSS_ETH;
2176         else if (!strcmp(res->value, "vlan"))
2177                 rss_conf.rss_hf = ETH_RSS_VLAN;
2178         else if (!strcmp(res->value, "ip"))
2179                 rss_conf.rss_hf = ETH_RSS_IP;
2180         else if (!strcmp(res->value, "udp"))
2181                 rss_conf.rss_hf = ETH_RSS_UDP;
2182         else if (!strcmp(res->value, "tcp"))
2183                 rss_conf.rss_hf = ETH_RSS_TCP;
2184         else if (!strcmp(res->value, "sctp"))
2185                 rss_conf.rss_hf = ETH_RSS_SCTP;
2186         else if (!strcmp(res->value, "ether"))
2187                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2188         else if (!strcmp(res->value, "port"))
2189                 rss_conf.rss_hf = ETH_RSS_PORT;
2190         else if (!strcmp(res->value, "vxlan"))
2191                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2192         else if (!strcmp(res->value, "geneve"))
2193                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2194         else if (!strcmp(res->value, "nvgre"))
2195                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2196         else if (!strcmp(res->value, "l3-pre32"))
2197                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2198         else if (!strcmp(res->value, "l3-pre40"))
2199                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2200         else if (!strcmp(res->value, "l3-pre48"))
2201                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2202         else if (!strcmp(res->value, "l3-pre56"))
2203                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2204         else if (!strcmp(res->value, "l3-pre64"))
2205                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2206         else if (!strcmp(res->value, "l3-pre96"))
2207                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2208         else if (!strcmp(res->value, "l3-src-only"))
2209                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2210         else if (!strcmp(res->value, "l3-dst-only"))
2211                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2212         else if (!strcmp(res->value, "l4-src-only"))
2213                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2214         else if (!strcmp(res->value, "l4-dst-only"))
2215                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2216         else if (!strcmp(res->value, "l2-src-only"))
2217                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2218         else if (!strcmp(res->value, "l2-dst-only"))
2219                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2220         else if (!strcmp(res->value, "l2tpv3"))
2221                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2222         else if (!strcmp(res->value, "esp"))
2223                 rss_conf.rss_hf = ETH_RSS_ESP;
2224         else if (!strcmp(res->value, "ah"))
2225                 rss_conf.rss_hf = ETH_RSS_AH;
2226         else if (!strcmp(res->value, "pfcp"))
2227                 rss_conf.rss_hf = ETH_RSS_PFCP;
2228         else if (!strcmp(res->value, "pppoe"))
2229                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2230         else if (!strcmp(res->value, "gtpu"))
2231                 rss_conf.rss_hf = ETH_RSS_GTPU;
2232         else if (!strcmp(res->value, "ecpri"))
2233                 rss_conf.rss_hf = ETH_RSS_ECPRI;
2234         else if (!strcmp(res->value, "mpls"))
2235                 rss_conf.rss_hf = ETH_RSS_MPLS;
2236         else if (!strcmp(res->value, "ipv4-chksum"))
2237                 rss_conf.rss_hf = ETH_RSS_IPV4_CHKSUM;
2238         else if (!strcmp(res->value, "none"))
2239                 rss_conf.rss_hf = 0;
2240         else if (!strcmp(res->value, "level-default")) {
2241                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2242                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2243         } else if (!strcmp(res->value, "level-outer")) {
2244                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2245                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2246         } else if (!strcmp(res->value, "level-inner")) {
2247                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2248                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2249         } else if (!strcmp(res->value, "default"))
2250                 use_default = 1;
2251         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2252                                                 atoi(res->value) < 64)
2253                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2254         else {
2255                 fprintf(stderr, "Unknown parameter\n");
2256                 return;
2257         }
2258         rss_conf.rss_key = NULL;
2259         /* Update global configuration for RSS types. */
2260         RTE_ETH_FOREACH_DEV(i) {
2261                 struct rte_eth_rss_conf local_rss_conf;
2262
2263                 ret = eth_dev_info_get_print_err(i, &dev_info);
2264                 if (ret != 0)
2265                         return;
2266
2267                 if (use_default)
2268                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2269
2270                 local_rss_conf = rss_conf;
2271                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2272                         dev_info.flow_type_rss_offloads;
2273                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2274                         printf("Port %u modified RSS hash function based on hardware support,"
2275                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2276                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2277                 }
2278                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2279                 if (diag < 0) {
2280                         all_updated = 0;
2281                         fprintf(stderr,
2282                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2283                                 i, -diag, strerror(-diag));
2284                 }
2285         }
2286         if (all_updated && !use_default) {
2287                 rss_hf = rss_conf.rss_hf;
2288                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2289         }
2290 }
2291
2292 cmdline_parse_token_string_t cmd_config_rss_port =
2293         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2294 cmdline_parse_token_string_t cmd_config_rss_keyword =
2295         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2296 cmdline_parse_token_string_t cmd_config_rss_all =
2297         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2298 cmdline_parse_token_string_t cmd_config_rss_name =
2299         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2300 cmdline_parse_token_string_t cmd_config_rss_value =
2301         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2302
2303 cmdline_parse_inst_t cmd_config_rss = {
2304         .f = cmd_config_rss_parsed,
2305         .data = NULL,
2306         .help_str = "port config all rss "
2307                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2308                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2309                 "level-outer|level-inner|ipv4-chksum|<flowtype_id>",
2310         .tokens = {
2311                 (void *)&cmd_config_rss_port,
2312                 (void *)&cmd_config_rss_keyword,
2313                 (void *)&cmd_config_rss_all,
2314                 (void *)&cmd_config_rss_name,
2315                 (void *)&cmd_config_rss_value,
2316                 NULL,
2317         },
2318 };
2319
2320 /* *** configure rss hash key *** */
2321 struct cmd_config_rss_hash_key {
2322         cmdline_fixed_string_t port;
2323         cmdline_fixed_string_t config;
2324         portid_t port_id;
2325         cmdline_fixed_string_t rss_hash_key;
2326         cmdline_fixed_string_t rss_type;
2327         cmdline_fixed_string_t key;
2328 };
2329
2330 static uint8_t
2331 hexa_digit_to_value(char hexa_digit)
2332 {
2333         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2334                 return (uint8_t) (hexa_digit - '0');
2335         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2336                 return (uint8_t) ((hexa_digit - 'a') + 10);
2337         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2338                 return (uint8_t) ((hexa_digit - 'A') + 10);
2339         /* Invalid hexa digit */
2340         return 0xFF;
2341 }
2342
2343 static uint8_t
2344 parse_and_check_key_hexa_digit(char *key, int idx)
2345 {
2346         uint8_t hexa_v;
2347
2348         hexa_v = hexa_digit_to_value(key[idx]);
2349         if (hexa_v == 0xFF)
2350                 fprintf(stderr,
2351                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2352                         key[idx], idx);
2353         return hexa_v;
2354 }
2355
2356 static void
2357 cmd_config_rss_hash_key_parsed(void *parsed_result,
2358                                __rte_unused struct cmdline *cl,
2359                                __rte_unused void *data)
2360 {
2361         struct cmd_config_rss_hash_key *res = parsed_result;
2362         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2363         uint8_t xdgt0;
2364         uint8_t xdgt1;
2365         int i;
2366         struct rte_eth_dev_info dev_info;
2367         uint8_t hash_key_size;
2368         uint32_t key_len;
2369         int ret;
2370
2371         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2372         if (ret != 0)
2373                 return;
2374
2375         if (dev_info.hash_key_size > 0 &&
2376                         dev_info.hash_key_size <= sizeof(hash_key))
2377                 hash_key_size = dev_info.hash_key_size;
2378         else {
2379                 fprintf(stderr,
2380                         "dev_info did not provide a valid hash key size\n");
2381                 return;
2382         }
2383         /* Check the length of the RSS hash key */
2384         key_len = strlen(res->key);
2385         if (key_len != (hash_key_size * 2)) {
2386                 fprintf(stderr,
2387                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2388                         (int)key_len, hash_key_size * 2);
2389                 return;
2390         }
2391         /* Translate RSS hash key into binary representation */
2392         for (i = 0; i < hash_key_size; i++) {
2393                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2394                 if (xdgt0 == 0xFF)
2395                         return;
2396                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2397                 if (xdgt1 == 0xFF)
2398                         return;
2399                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2400         }
2401         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2402                         hash_key_size);
2403 }
2404
2405 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2406         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2407 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2408         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2409                                  "config");
2410 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2411         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2412                                  RTE_UINT16);
2413 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2414         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2415                                  rss_hash_key, "rss-hash-key");
2416 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2417         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2418                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2419                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2420                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2421                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2422                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2423                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2424                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2425 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2426         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2427
2428 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2429         .f = cmd_config_rss_hash_key_parsed,
2430         .data = NULL,
2431         .help_str = "port config <port_id> rss-hash-key "
2432                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2433                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2434                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2435                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2436                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2437                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2438                 "<string of hex digits (variable length, NIC dependent)>",
2439         .tokens = {
2440                 (void *)&cmd_config_rss_hash_key_port,
2441                 (void *)&cmd_config_rss_hash_key_config,
2442                 (void *)&cmd_config_rss_hash_key_port_id,
2443                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2444                 (void *)&cmd_config_rss_hash_key_rss_type,
2445                 (void *)&cmd_config_rss_hash_key_value,
2446                 NULL,
2447         },
2448 };
2449
2450 /* *** cleanup txq mbufs *** */
2451 struct cmd_cleanup_txq_mbufs_result {
2452         cmdline_fixed_string_t port;
2453         cmdline_fixed_string_t keyword;
2454         cmdline_fixed_string_t name;
2455         uint16_t port_id;
2456         uint16_t queue_id;
2457         uint32_t free_cnt;
2458 };
2459
2460 static void
2461 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2462                              __rte_unused struct cmdline *cl,
2463                              __rte_unused void *data)
2464 {
2465         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2466         uint16_t port_id = res->port_id;
2467         uint16_t queue_id = res->queue_id;
2468         uint32_t free_cnt = res->free_cnt;
2469         struct rte_eth_txq_info qinfo;
2470         int ret;
2471
2472         if (test_done == 0) {
2473                 fprintf(stderr, "Please stop forwarding first\n");
2474                 return;
2475         }
2476
2477         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2478                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2479                         port_id, queue_id);
2480                 return;
2481         }
2482
2483         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2484                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2485                 return;
2486         }
2487
2488         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2489         if (ret < 0) {
2490                 fprintf(stderr,
2491                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2492                         port_id, queue_id, strerror(-ret), ret);
2493                 return;
2494         }
2495
2496         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2497                port_id, queue_id, ret);
2498 }
2499
2500 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2501         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2502                                  "port");
2503 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2504         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2505                                  "cleanup");
2506 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2507         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2508                               RTE_UINT16);
2509 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2510         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2511                                  "txq");
2512 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2513         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2514                               RTE_UINT16);
2515 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2516         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2517                               RTE_UINT32);
2518
2519 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2520         .f = cmd_cleanup_txq_mbufs_parsed,
2521         .data = NULL,
2522         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2523         .tokens = {
2524                 (void *)&cmd_cleanup_txq_mbufs_port,
2525                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2526                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2527                 (void *)&cmd_cleanup_txq_mbufs_txq,
2528                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2529                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2530                 NULL,
2531         },
2532 };
2533
2534 /* *** configure port rxq/txq ring size *** */
2535 struct cmd_config_rxtx_ring_size {
2536         cmdline_fixed_string_t port;
2537         cmdline_fixed_string_t config;
2538         portid_t portid;
2539         cmdline_fixed_string_t rxtxq;
2540         uint16_t qid;
2541         cmdline_fixed_string_t rsize;
2542         uint16_t size;
2543 };
2544
2545 static void
2546 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2547                                  __rte_unused struct cmdline *cl,
2548                                  __rte_unused void *data)
2549 {
2550         struct cmd_config_rxtx_ring_size *res = parsed_result;
2551         struct rte_port *port;
2552         uint8_t isrx;
2553
2554         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2555                 return;
2556
2557         if (res->portid == (portid_t)RTE_PORT_ALL) {
2558                 fprintf(stderr, "Invalid port id\n");
2559                 return;
2560         }
2561
2562         port = &ports[res->portid];
2563
2564         if (!strcmp(res->rxtxq, "rxq"))
2565                 isrx = 1;
2566         else if (!strcmp(res->rxtxq, "txq"))
2567                 isrx = 0;
2568         else {
2569                 fprintf(stderr, "Unknown parameter\n");
2570                 return;
2571         }
2572
2573         if (isrx && rx_queue_id_is_invalid(res->qid))
2574                 return;
2575         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2576                 return;
2577
2578         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2579                 fprintf(stderr,
2580                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2581                         rx_free_thresh);
2582                 return;
2583         }
2584
2585         if (isrx)
2586                 port->nb_rx_desc[res->qid] = res->size;
2587         else
2588                 port->nb_tx_desc[res->qid] = res->size;
2589
2590         cmd_reconfig_device_queue(res->portid, 0, 1);
2591 }
2592
2593 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2594         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2595                                  port, "port");
2596 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2597         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2598                                  config, "config");
2599 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2601                                  portid, RTE_UINT16);
2602 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2603         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2604                                  rxtxq, "rxq#txq");
2605 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2606         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2607                               qid, RTE_UINT16);
2608 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2609         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2610                                  rsize, "ring_size");
2611 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2612         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2613                               size, RTE_UINT16);
2614
2615 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2616         .f = cmd_config_rxtx_ring_size_parsed,
2617         .data = NULL,
2618         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2619         .tokens = {
2620                 (void *)&cmd_config_rxtx_ring_size_port,
2621                 (void *)&cmd_config_rxtx_ring_size_config,
2622                 (void *)&cmd_config_rxtx_ring_size_portid,
2623                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2624                 (void *)&cmd_config_rxtx_ring_size_qid,
2625                 (void *)&cmd_config_rxtx_ring_size_rsize,
2626                 (void *)&cmd_config_rxtx_ring_size_size,
2627                 NULL,
2628         },
2629 };
2630
2631 /* *** configure port rxq/txq start/stop *** */
2632 struct cmd_config_rxtx_queue {
2633         cmdline_fixed_string_t port;
2634         portid_t portid;
2635         cmdline_fixed_string_t rxtxq;
2636         uint16_t qid;
2637         cmdline_fixed_string_t opname;
2638 };
2639
2640 static void
2641 cmd_config_rxtx_queue_parsed(void *parsed_result,
2642                         __rte_unused struct cmdline *cl,
2643                         __rte_unused void *data)
2644 {
2645         struct cmd_config_rxtx_queue *res = parsed_result;
2646         uint8_t isrx;
2647         uint8_t isstart;
2648         int ret = 0;
2649
2650         if (test_done == 0) {
2651                 fprintf(stderr, "Please stop forwarding first\n");
2652                 return;
2653         }
2654
2655         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2656                 return;
2657
2658         if (port_is_started(res->portid) != 1) {
2659                 fprintf(stderr, "Please start port %u first\n", res->portid);
2660                 return;
2661         }
2662
2663         if (!strcmp(res->rxtxq, "rxq"))
2664                 isrx = 1;
2665         else if (!strcmp(res->rxtxq, "txq"))
2666                 isrx = 0;
2667         else {
2668                 fprintf(stderr, "Unknown parameter\n");
2669                 return;
2670         }
2671
2672         if (isrx && rx_queue_id_is_invalid(res->qid))
2673                 return;
2674         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2675                 return;
2676
2677         if (!strcmp(res->opname, "start"))
2678                 isstart = 1;
2679         else if (!strcmp(res->opname, "stop"))
2680                 isstart = 0;
2681         else {
2682                 fprintf(stderr, "Unknown parameter\n");
2683                 return;
2684         }
2685
2686         if (isstart && isrx)
2687                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2688         else if (!isstart && isrx)
2689                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2690         else if (isstart && !isrx)
2691                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2692         else
2693                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2694
2695         if (ret == -ENOTSUP)
2696                 fprintf(stderr, "Function not supported in PMD driver\n");
2697 }
2698
2699 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2700         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2701 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2702         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2703 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2705 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2706         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2707 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2708         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2709                                                 "start#stop");
2710
2711 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2712         .f = cmd_config_rxtx_queue_parsed,
2713         .data = NULL,
2714         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2715         .tokens = {
2716                 (void *)&cmd_config_rxtx_queue_port,
2717                 (void *)&cmd_config_rxtx_queue_portid,
2718                 (void *)&cmd_config_rxtx_queue_rxtxq,
2719                 (void *)&cmd_config_rxtx_queue_qid,
2720                 (void *)&cmd_config_rxtx_queue_opname,
2721                 NULL,
2722         },
2723 };
2724
2725 /* *** configure port rxq/txq deferred start on/off *** */
2726 struct cmd_config_deferred_start_rxtx_queue {
2727         cmdline_fixed_string_t port;
2728         portid_t port_id;
2729         cmdline_fixed_string_t rxtxq;
2730         uint16_t qid;
2731         cmdline_fixed_string_t opname;
2732         cmdline_fixed_string_t state;
2733 };
2734
2735 static void
2736 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2737                         __rte_unused struct cmdline *cl,
2738                         __rte_unused void *data)
2739 {
2740         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2741         struct rte_port *port;
2742         uint8_t isrx;
2743         uint8_t ison;
2744         uint8_t needreconfig = 0;
2745
2746         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2747                 return;
2748
2749         if (port_is_started(res->port_id) != 0) {
2750                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2751                 return;
2752         }
2753
2754         port = &ports[res->port_id];
2755
2756         isrx = !strcmp(res->rxtxq, "rxq");
2757
2758         if (isrx && rx_queue_id_is_invalid(res->qid))
2759                 return;
2760         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2761                 return;
2762
2763         ison = !strcmp(res->state, "on");
2764
2765         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2766                 port->rx_conf[res->qid].rx_deferred_start = ison;
2767                 needreconfig = 1;
2768         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2769                 port->tx_conf[res->qid].tx_deferred_start = ison;
2770                 needreconfig = 1;
2771         }
2772
2773         if (needreconfig)
2774                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2775 }
2776
2777 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2778         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2779                                                 port, "port");
2780 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2781         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2782                                                 port_id, RTE_UINT16);
2783 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2784         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2785                                                 rxtxq, "rxq#txq");
2786 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2787         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2788                                                 qid, RTE_UINT16);
2789 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2790         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2791                                                 opname, "deferred_start");
2792 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2793         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2794                                                 state, "on#off");
2795
2796 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2797         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2798         .data = NULL,
2799         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2800         .tokens = {
2801                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2802                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2803                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2804                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2805                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2806                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2807                 NULL,
2808         },
2809 };
2810
2811 /* *** configure port rxq/txq setup *** */
2812 struct cmd_setup_rxtx_queue {
2813         cmdline_fixed_string_t port;
2814         portid_t portid;
2815         cmdline_fixed_string_t rxtxq;
2816         uint16_t qid;
2817         cmdline_fixed_string_t setup;
2818 };
2819
2820 /* Common CLI fields for queue setup */
2821 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2822         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2823 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2824         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2825 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2826         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2827 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2828         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2829 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2830         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2831
2832 static void
2833 cmd_setup_rxtx_queue_parsed(
2834         void *parsed_result,
2835         __rte_unused struct cmdline *cl,
2836         __rte_unused void *data)
2837 {
2838         struct cmd_setup_rxtx_queue *res = parsed_result;
2839         struct rte_port *port;
2840         struct rte_mempool *mp;
2841         unsigned int socket_id;
2842         uint8_t isrx = 0;
2843         int ret;
2844
2845         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2846                 return;
2847
2848         if (res->portid == (portid_t)RTE_PORT_ALL) {
2849                 fprintf(stderr, "Invalid port id\n");
2850                 return;
2851         }
2852
2853         if (!strcmp(res->rxtxq, "rxq"))
2854                 isrx = 1;
2855         else if (!strcmp(res->rxtxq, "txq"))
2856                 isrx = 0;
2857         else {
2858                 fprintf(stderr, "Unknown parameter\n");
2859                 return;
2860         }
2861
2862         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2863                 fprintf(stderr, "Invalid rx queue\n");
2864                 return;
2865         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2866                 fprintf(stderr, "Invalid tx queue\n");
2867                 return;
2868         }
2869
2870         port = &ports[res->portid];
2871         if (isrx) {
2872                 socket_id = rxring_numa[res->portid];
2873                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2874                         socket_id = port->socket_id;
2875
2876                 mp = mbuf_pool_find(socket_id, 0);
2877                 if (mp == NULL) {
2878                         fprintf(stderr,
2879                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2880                                 rxring_numa[res->portid]);
2881                         return;
2882                 }
2883                 ret = rx_queue_setup(res->portid,
2884                                      res->qid,
2885                                      port->nb_rx_desc[res->qid],
2886                                      socket_id,
2887                                      &port->rx_conf[res->qid],
2888                                      mp);
2889                 if (ret)
2890                         fprintf(stderr, "Failed to setup RX queue\n");
2891         } else {
2892                 socket_id = txring_numa[res->portid];
2893                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2894                         socket_id = port->socket_id;
2895
2896                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2897                         fprintf(stderr,
2898                                 "Failed to setup TX queue: not enough descriptors\n");
2899                         return;
2900                 }
2901                 ret = rte_eth_tx_queue_setup(res->portid,
2902                                              res->qid,
2903                                              port->nb_tx_desc[res->qid],
2904                                              socket_id,
2905                                              &port->tx_conf[res->qid]);
2906                 if (ret)
2907                         fprintf(stderr, "Failed to setup TX queue\n");
2908         }
2909 }
2910
2911 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2912         .f = cmd_setup_rxtx_queue_parsed,
2913         .data = NULL,
2914         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2915         .tokens = {
2916                 (void *)&cmd_setup_rxtx_queue_port,
2917                 (void *)&cmd_setup_rxtx_queue_portid,
2918                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2919                 (void *)&cmd_setup_rxtx_queue_qid,
2920                 (void *)&cmd_setup_rxtx_queue_setup,
2921                 NULL,
2922         },
2923 };
2924
2925
2926 /* *** Configure RSS RETA *** */
2927 struct cmd_config_rss_reta {
2928         cmdline_fixed_string_t port;
2929         cmdline_fixed_string_t keyword;
2930         portid_t port_id;
2931         cmdline_fixed_string_t name;
2932         cmdline_fixed_string_t list_name;
2933         cmdline_fixed_string_t list_of_items;
2934 };
2935
2936 static int
2937 parse_reta_config(const char *str,
2938                   struct rte_eth_rss_reta_entry64 *reta_conf,
2939                   uint16_t nb_entries)
2940 {
2941         int i;
2942         unsigned size;
2943         uint16_t hash_index, idx, shift;
2944         uint16_t nb_queue;
2945         char s[256];
2946         const char *p, *p0 = str;
2947         char *end;
2948         enum fieldnames {
2949                 FLD_HASH_INDEX = 0,
2950                 FLD_QUEUE,
2951                 _NUM_FLD
2952         };
2953         unsigned long int_fld[_NUM_FLD];
2954         char *str_fld[_NUM_FLD];
2955
2956         while ((p = strchr(p0,'(')) != NULL) {
2957                 ++p;
2958                 if((p0 = strchr(p,')')) == NULL)
2959                         return -1;
2960
2961                 size = p0 - p;
2962                 if(size >= sizeof(s))
2963                         return -1;
2964
2965                 snprintf(s, sizeof(s), "%.*s", size, p);
2966                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2967                         return -1;
2968                 for (i = 0; i < _NUM_FLD; i++) {
2969                         errno = 0;
2970                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2971                         if (errno != 0 || end == str_fld[i] ||
2972                                         int_fld[i] > 65535)
2973                                 return -1;
2974                 }
2975
2976                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2977                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2978
2979                 if (hash_index >= nb_entries) {
2980                         fprintf(stderr, "Invalid RETA hash index=%d\n",
2981                                 hash_index);
2982                         return -1;
2983                 }
2984
2985                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2986                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2987                 reta_conf[idx].mask |= (1ULL << shift);
2988                 reta_conf[idx].reta[shift] = nb_queue;
2989         }
2990
2991         return 0;
2992 }
2993
2994 static void
2995 cmd_set_rss_reta_parsed(void *parsed_result,
2996                         __rte_unused struct cmdline *cl,
2997                         __rte_unused void *data)
2998 {
2999         int ret;
3000         struct rte_eth_dev_info dev_info;
3001         struct rte_eth_rss_reta_entry64 reta_conf[8];
3002         struct cmd_config_rss_reta *res = parsed_result;
3003
3004         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3005         if (ret != 0)
3006                 return;
3007
3008         if (dev_info.reta_size == 0) {
3009                 fprintf(stderr,
3010                         "Redirection table size is 0 which is invalid for RSS\n");
3011                 return;
3012         } else
3013                 printf("The reta size of port %d is %u\n",
3014                         res->port_id, dev_info.reta_size);
3015         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3016                 fprintf(stderr,
3017                         "Currently do not support more than %u entries of redirection table\n",
3018                         ETH_RSS_RETA_SIZE_512);
3019                 return;
3020         }
3021
3022         memset(reta_conf, 0, sizeof(reta_conf));
3023         if (!strcmp(res->list_name, "reta")) {
3024                 if (parse_reta_config(res->list_of_items, reta_conf,
3025                                                 dev_info.reta_size)) {
3026                         fprintf(stderr,
3027                                 "Invalid RSS Redirection Table config entered\n");
3028                         return;
3029                 }
3030                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3031                                 reta_conf, dev_info.reta_size);
3032                 if (ret != 0)
3033                         fprintf(stderr,
3034                                 "Bad redirection table parameter, return code = %d\n",
3035                                 ret);
3036         }
3037 }
3038
3039 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3040         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3041 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3042         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3043 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3044         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3045 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3046         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3047 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3048         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3049 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3050         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3051                                  NULL);
3052 cmdline_parse_inst_t cmd_config_rss_reta = {
3053         .f = cmd_set_rss_reta_parsed,
3054         .data = NULL,
3055         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3056         .tokens = {
3057                 (void *)&cmd_config_rss_reta_port,
3058                 (void *)&cmd_config_rss_reta_keyword,
3059                 (void *)&cmd_config_rss_reta_port_id,
3060                 (void *)&cmd_config_rss_reta_name,
3061                 (void *)&cmd_config_rss_reta_list_name,
3062                 (void *)&cmd_config_rss_reta_list_of_items,
3063                 NULL,
3064         },
3065 };
3066
3067 /* *** SHOW PORT RETA INFO *** */
3068 struct cmd_showport_reta {
3069         cmdline_fixed_string_t show;
3070         cmdline_fixed_string_t port;
3071         portid_t port_id;
3072         cmdline_fixed_string_t rss;
3073         cmdline_fixed_string_t reta;
3074         uint16_t size;
3075         cmdline_fixed_string_t list_of_items;
3076 };
3077
3078 static int
3079 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3080                            uint16_t nb_entries,
3081                            char *str)
3082 {
3083         uint32_t size;
3084         const char *p, *p0 = str;
3085         char s[256];
3086         char *end;
3087         char *str_fld[8];
3088         uint16_t i;
3089         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3090                         RTE_RETA_GROUP_SIZE;
3091         int ret;
3092
3093         p = strchr(p0, '(');
3094         if (p == NULL)
3095                 return -1;
3096         p++;
3097         p0 = strchr(p, ')');
3098         if (p0 == NULL)
3099                 return -1;
3100         size = p0 - p;
3101         if (size >= sizeof(s)) {
3102                 fprintf(stderr,
3103                         "The string size exceeds the internal buffer size\n");
3104                 return -1;
3105         }
3106         snprintf(s, sizeof(s), "%.*s", size, p);
3107         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3108         if (ret <= 0 || ret != num) {
3109                 fprintf(stderr,
3110                         "The bits of masks do not match the number of reta entries: %u\n",
3111                         num);
3112                 return -1;
3113         }
3114         for (i = 0; i < ret; i++)
3115                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3116
3117         return 0;
3118 }
3119
3120 static void
3121 cmd_showport_reta_parsed(void *parsed_result,
3122                          __rte_unused struct cmdline *cl,
3123                          __rte_unused void *data)
3124 {
3125         struct cmd_showport_reta *res = parsed_result;
3126         struct rte_eth_rss_reta_entry64 reta_conf[8];
3127         struct rte_eth_dev_info dev_info;
3128         uint16_t max_reta_size;
3129         int ret;
3130
3131         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3132         if (ret != 0)
3133                 return;
3134
3135         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3136         if (res->size == 0 || res->size > max_reta_size) {
3137                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3138                         res->size, max_reta_size);
3139                 return;
3140         }
3141
3142         memset(reta_conf, 0, sizeof(reta_conf));
3143         if (showport_parse_reta_config(reta_conf, res->size,
3144                                 res->list_of_items) < 0) {
3145                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3146                         res->list_of_items);
3147                 return;
3148         }
3149         port_rss_reta_info(res->port_id, reta_conf, res->size);
3150 }
3151
3152 cmdline_parse_token_string_t cmd_showport_reta_show =
3153         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3154 cmdline_parse_token_string_t cmd_showport_reta_port =
3155         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3156 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3157         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3158 cmdline_parse_token_string_t cmd_showport_reta_rss =
3159         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3160 cmdline_parse_token_string_t cmd_showport_reta_reta =
3161         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3162 cmdline_parse_token_num_t cmd_showport_reta_size =
3163         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3164 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3165         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3166                                         list_of_items, NULL);
3167
3168 cmdline_parse_inst_t cmd_showport_reta = {
3169         .f = cmd_showport_reta_parsed,
3170         .data = NULL,
3171         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3172         .tokens = {
3173                 (void *)&cmd_showport_reta_show,
3174                 (void *)&cmd_showport_reta_port,
3175                 (void *)&cmd_showport_reta_port_id,
3176                 (void *)&cmd_showport_reta_rss,
3177                 (void *)&cmd_showport_reta_reta,
3178                 (void *)&cmd_showport_reta_size,
3179                 (void *)&cmd_showport_reta_list_of_items,
3180                 NULL,
3181         },
3182 };
3183
3184 /* *** Show RSS hash configuration *** */
3185 struct cmd_showport_rss_hash {
3186         cmdline_fixed_string_t show;
3187         cmdline_fixed_string_t port;
3188         portid_t port_id;
3189         cmdline_fixed_string_t rss_hash;
3190         cmdline_fixed_string_t rss_type;
3191         cmdline_fixed_string_t key; /* optional argument */
3192 };
3193
3194 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3195                                 __rte_unused struct cmdline *cl,
3196                                 void *show_rss_key)
3197 {
3198         struct cmd_showport_rss_hash *res = parsed_result;
3199
3200         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3201 }
3202
3203 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3204         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3205 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3206         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3207 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3208         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3209                                  RTE_UINT16);
3210 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3211         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3212                                  "rss-hash");
3213 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3214         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3215
3216 cmdline_parse_inst_t cmd_showport_rss_hash = {
3217         .f = cmd_showport_rss_hash_parsed,
3218         .data = NULL,
3219         .help_str = "show port <port_id> rss-hash",
3220         .tokens = {
3221                 (void *)&cmd_showport_rss_hash_show,
3222                 (void *)&cmd_showport_rss_hash_port,
3223                 (void *)&cmd_showport_rss_hash_port_id,
3224                 (void *)&cmd_showport_rss_hash_rss_hash,
3225                 NULL,
3226         },
3227 };
3228
3229 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3230         .f = cmd_showport_rss_hash_parsed,
3231         .data = (void *)1,
3232         .help_str = "show port <port_id> rss-hash key",
3233         .tokens = {
3234                 (void *)&cmd_showport_rss_hash_show,
3235                 (void *)&cmd_showport_rss_hash_port,
3236                 (void *)&cmd_showport_rss_hash_port_id,
3237                 (void *)&cmd_showport_rss_hash_rss_hash,
3238                 (void *)&cmd_showport_rss_hash_rss_key,
3239                 NULL,
3240         },
3241 };
3242
3243 /* *** Configure DCB *** */
3244 struct cmd_config_dcb {
3245         cmdline_fixed_string_t port;
3246         cmdline_fixed_string_t config;
3247         portid_t port_id;
3248         cmdline_fixed_string_t dcb;
3249         cmdline_fixed_string_t vt;
3250         cmdline_fixed_string_t vt_en;
3251         uint8_t num_tcs;
3252         cmdline_fixed_string_t pfc;
3253         cmdline_fixed_string_t pfc_en;
3254 };
3255
3256 static void
3257 cmd_config_dcb_parsed(void *parsed_result,
3258                         __rte_unused struct cmdline *cl,
3259                         __rte_unused void *data)
3260 {
3261         struct cmd_config_dcb *res = parsed_result;
3262         struct rte_eth_dcb_info dcb_info;
3263         portid_t port_id = res->port_id;
3264         struct rte_port *port;
3265         uint8_t pfc_en;
3266         int ret;
3267
3268         port = &ports[port_id];
3269         /** Check if the port is not started **/
3270         if (port->port_status != RTE_PORT_STOPPED) {
3271                 fprintf(stderr, "Please stop port %d first\n", port_id);
3272                 return;
3273         }
3274
3275         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3276                 fprintf(stderr,
3277                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3278                 return;
3279         }
3280
3281         if (nb_fwd_lcores < res->num_tcs) {
3282                 fprintf(stderr,
3283                         "nb_cores shouldn't be less than number of TCs.\n");
3284                 return;
3285         }
3286
3287         /* Check whether the port supports the report of DCB info. */
3288         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3289         if (ret == -ENOTSUP) {
3290                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3291                 return;
3292         }
3293
3294         if (!strncmp(res->pfc_en, "on", 2))
3295                 pfc_en = 1;
3296         else
3297                 pfc_en = 0;
3298
3299         /* DCB in VT mode */
3300         if (!strncmp(res->vt_en, "on", 2))
3301                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3302                                 (enum rte_eth_nb_tcs)res->num_tcs,
3303                                 pfc_en);
3304         else
3305                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3306                                 (enum rte_eth_nb_tcs)res->num_tcs,
3307                                 pfc_en);
3308         if (ret != 0) {
3309                 fprintf(stderr, "Cannot initialize network ports.\n");
3310                 return;
3311         }
3312
3313         fwd_config_setup();
3314
3315         cmd_reconfig_device_queue(port_id, 1, 1);
3316 }
3317
3318 cmdline_parse_token_string_t cmd_config_dcb_port =
3319         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3320 cmdline_parse_token_string_t cmd_config_dcb_config =
3321         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3322 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3323         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3324 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3325         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3326 cmdline_parse_token_string_t cmd_config_dcb_vt =
3327         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3328 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3329         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3330 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3331         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3332 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3333         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3334 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3335         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3336
3337 cmdline_parse_inst_t cmd_config_dcb = {
3338         .f = cmd_config_dcb_parsed,
3339         .data = NULL,
3340         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3341         .tokens = {
3342                 (void *)&cmd_config_dcb_port,
3343                 (void *)&cmd_config_dcb_config,
3344                 (void *)&cmd_config_dcb_port_id,
3345                 (void *)&cmd_config_dcb_dcb,
3346                 (void *)&cmd_config_dcb_vt,
3347                 (void *)&cmd_config_dcb_vt_en,
3348                 (void *)&cmd_config_dcb_num_tcs,
3349                 (void *)&cmd_config_dcb_pfc,
3350                 (void *)&cmd_config_dcb_pfc_en,
3351                 NULL,
3352         },
3353 };
3354
3355 /* *** configure number of packets per burst *** */
3356 struct cmd_config_burst {
3357         cmdline_fixed_string_t port;
3358         cmdline_fixed_string_t keyword;
3359         cmdline_fixed_string_t all;
3360         cmdline_fixed_string_t name;
3361         uint16_t value;
3362 };
3363
3364 static void
3365 cmd_config_burst_parsed(void *parsed_result,
3366                         __rte_unused struct cmdline *cl,
3367                         __rte_unused void *data)
3368 {
3369         struct cmd_config_burst *res = parsed_result;
3370         struct rte_eth_dev_info dev_info;
3371         uint16_t rec_nb_pkts;
3372         int ret;
3373
3374         if (!all_ports_stopped()) {
3375                 fprintf(stderr, "Please stop all ports first\n");
3376                 return;
3377         }
3378
3379         if (!strcmp(res->name, "burst")) {
3380                 if (res->value == 0) {
3381                         /* If user gives a value of zero, query the PMD for
3382                          * its recommended Rx burst size. Testpmd uses a single
3383                          * size for all ports, so assume all ports are the same
3384                          * NIC model and use the values from Port 0.
3385                          */
3386                         ret = eth_dev_info_get_print_err(0, &dev_info);
3387                         if (ret != 0)
3388                                 return;
3389
3390                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3391
3392                         if (rec_nb_pkts == 0) {
3393                                 printf("PMD does not recommend a burst size.\n"
3394                                         "User provided value must be between"
3395                                         " 1 and %d\n", MAX_PKT_BURST);
3396                                 return;
3397                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3398                                 printf("PMD recommended burst size of %d"
3399                                         " exceeds maximum value of %d\n",
3400                                         rec_nb_pkts, MAX_PKT_BURST);
3401                                 return;
3402                         }
3403                         printf("Using PMD-provided burst value of %d\n",
3404                                 rec_nb_pkts);
3405                         nb_pkt_per_burst = rec_nb_pkts;
3406                 } else if (res->value > MAX_PKT_BURST) {
3407                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3408                                 MAX_PKT_BURST);
3409                         return;
3410                 } else
3411                         nb_pkt_per_burst = res->value;
3412         } else {
3413                 fprintf(stderr, "Unknown parameter\n");
3414                 return;
3415         }
3416
3417         init_port_config();
3418
3419         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3420 }
3421
3422 cmdline_parse_token_string_t cmd_config_burst_port =
3423         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3424 cmdline_parse_token_string_t cmd_config_burst_keyword =
3425         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3426 cmdline_parse_token_string_t cmd_config_burst_all =
3427         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3428 cmdline_parse_token_string_t cmd_config_burst_name =
3429         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3430 cmdline_parse_token_num_t cmd_config_burst_value =
3431         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3432
3433 cmdline_parse_inst_t cmd_config_burst = {
3434         .f = cmd_config_burst_parsed,
3435         .data = NULL,
3436         .help_str = "port config all burst <value>",
3437         .tokens = {
3438                 (void *)&cmd_config_burst_port,
3439                 (void *)&cmd_config_burst_keyword,
3440                 (void *)&cmd_config_burst_all,
3441                 (void *)&cmd_config_burst_name,
3442                 (void *)&cmd_config_burst_value,
3443                 NULL,
3444         },
3445 };
3446
3447 /* *** configure rx/tx queues *** */
3448 struct cmd_config_thresh {
3449         cmdline_fixed_string_t port;
3450         cmdline_fixed_string_t keyword;
3451         cmdline_fixed_string_t all;
3452         cmdline_fixed_string_t name;
3453         uint8_t value;
3454 };
3455
3456 static void
3457 cmd_config_thresh_parsed(void *parsed_result,
3458                         __rte_unused struct cmdline *cl,
3459                         __rte_unused void *data)
3460 {
3461         struct cmd_config_thresh *res = parsed_result;
3462
3463         if (!all_ports_stopped()) {
3464                 fprintf(stderr, "Please stop all ports first\n");
3465                 return;
3466         }
3467
3468         if (!strcmp(res->name, "txpt"))
3469                 tx_pthresh = res->value;
3470         else if(!strcmp(res->name, "txht"))
3471                 tx_hthresh = res->value;
3472         else if(!strcmp(res->name, "txwt"))
3473                 tx_wthresh = res->value;
3474         else if(!strcmp(res->name, "rxpt"))
3475                 rx_pthresh = res->value;
3476         else if(!strcmp(res->name, "rxht"))
3477                 rx_hthresh = res->value;
3478         else if(!strcmp(res->name, "rxwt"))
3479                 rx_wthresh = res->value;
3480         else {
3481                 fprintf(stderr, "Unknown parameter\n");
3482                 return;
3483         }
3484
3485         init_port_config();
3486
3487         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3488 }
3489
3490 cmdline_parse_token_string_t cmd_config_thresh_port =
3491         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3492 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3493         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3494 cmdline_parse_token_string_t cmd_config_thresh_all =
3495         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3496 cmdline_parse_token_string_t cmd_config_thresh_name =
3497         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3498                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3499 cmdline_parse_token_num_t cmd_config_thresh_value =
3500         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3501
3502 cmdline_parse_inst_t cmd_config_thresh = {
3503         .f = cmd_config_thresh_parsed,
3504         .data = NULL,
3505         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3506         .tokens = {
3507                 (void *)&cmd_config_thresh_port,
3508                 (void *)&cmd_config_thresh_keyword,
3509                 (void *)&cmd_config_thresh_all,
3510                 (void *)&cmd_config_thresh_name,
3511                 (void *)&cmd_config_thresh_value,
3512                 NULL,
3513         },
3514 };
3515
3516 /* *** configure free/rs threshold *** */
3517 struct cmd_config_threshold {
3518         cmdline_fixed_string_t port;
3519         cmdline_fixed_string_t keyword;
3520         cmdline_fixed_string_t all;
3521         cmdline_fixed_string_t name;
3522         uint16_t value;
3523 };
3524
3525 static void
3526 cmd_config_threshold_parsed(void *parsed_result,
3527                         __rte_unused struct cmdline *cl,
3528                         __rte_unused void *data)
3529 {
3530         struct cmd_config_threshold *res = parsed_result;
3531
3532         if (!all_ports_stopped()) {
3533                 fprintf(stderr, "Please stop all ports first\n");
3534                 return;
3535         }
3536
3537         if (!strcmp(res->name, "txfreet"))
3538                 tx_free_thresh = res->value;
3539         else if (!strcmp(res->name, "txrst"))
3540                 tx_rs_thresh = res->value;
3541         else if (!strcmp(res->name, "rxfreet"))
3542                 rx_free_thresh = res->value;
3543         else {
3544                 fprintf(stderr, "Unknown parameter\n");
3545                 return;
3546         }
3547
3548         init_port_config();
3549
3550         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3551 }
3552
3553 cmdline_parse_token_string_t cmd_config_threshold_port =
3554         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3555 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3556         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3557                                                                 "config");
3558 cmdline_parse_token_string_t cmd_config_threshold_all =
3559         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3560 cmdline_parse_token_string_t cmd_config_threshold_name =
3561         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3562                                                 "txfreet#txrst#rxfreet");
3563 cmdline_parse_token_num_t cmd_config_threshold_value =
3564         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3565
3566 cmdline_parse_inst_t cmd_config_threshold = {
3567         .f = cmd_config_threshold_parsed,
3568         .data = NULL,
3569         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3570         .tokens = {
3571                 (void *)&cmd_config_threshold_port,
3572                 (void *)&cmd_config_threshold_keyword,
3573                 (void *)&cmd_config_threshold_all,
3574                 (void *)&cmd_config_threshold_name,
3575                 (void *)&cmd_config_threshold_value,
3576                 NULL,
3577         },
3578 };
3579
3580 /* *** stop *** */
3581 struct cmd_stop_result {
3582         cmdline_fixed_string_t stop;
3583 };
3584
3585 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3586                             __rte_unused struct cmdline *cl,
3587                             __rte_unused void *data)
3588 {
3589         stop_packet_forwarding();
3590 }
3591
3592 cmdline_parse_token_string_t cmd_stop_stop =
3593         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3594
3595 cmdline_parse_inst_t cmd_stop = {
3596         .f = cmd_stop_parsed,
3597         .data = NULL,
3598         .help_str = "stop: Stop packet forwarding",
3599         .tokens = {
3600                 (void *)&cmd_stop_stop,
3601                 NULL,
3602         },
3603 };
3604
3605 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3606
3607 unsigned int
3608 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3609                 unsigned int *parsed_items, int check_unique_values)
3610 {
3611         unsigned int nb_item;
3612         unsigned int value;
3613         unsigned int i;
3614         unsigned int j;
3615         int value_ok;
3616         char c;
3617
3618         /*
3619          * First parse all items in the list and store their value.
3620          */
3621         value = 0;
3622         nb_item = 0;
3623         value_ok = 0;
3624         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3625                 c = str[i];
3626                 if ((c >= '0') && (c <= '9')) {
3627                         value = (unsigned int) (value * 10 + (c - '0'));
3628                         value_ok = 1;
3629                         continue;
3630                 }
3631                 if (c != ',') {
3632                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3633                         return 0;
3634                 }
3635                 if (! value_ok) {
3636                         fprintf(stderr, "No valid value before comma\n");
3637                         return 0;
3638                 }
3639                 if (nb_item < max_items) {
3640                         parsed_items[nb_item] = value;
3641                         value_ok = 0;
3642                         value = 0;
3643                 }
3644                 nb_item++;
3645         }
3646         if (nb_item >= max_items) {
3647                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3648                         item_name, nb_item + 1, max_items);
3649                 return 0;
3650         }
3651         parsed_items[nb_item++] = value;
3652         if (! check_unique_values)
3653                 return nb_item;
3654
3655         /*
3656          * Then, check that all values in the list are differents.
3657          * No optimization here...
3658          */
3659         for (i = 0; i < nb_item; i++) {
3660                 for (j = i + 1; j < nb_item; j++) {
3661                         if (parsed_items[j] == parsed_items[i]) {
3662                                 fprintf(stderr,
3663                                         "duplicated %s %u at index %u and %u\n",
3664                                         item_name, parsed_items[i], i, j);
3665                                 return 0;
3666                         }
3667                 }
3668         }
3669         return nb_item;
3670 }
3671
3672 struct cmd_set_list_result {
3673         cmdline_fixed_string_t cmd_keyword;
3674         cmdline_fixed_string_t list_name;
3675         cmdline_fixed_string_t list_of_items;
3676 };
3677
3678 static void cmd_set_list_parsed(void *parsed_result,
3679                                 __rte_unused struct cmdline *cl,
3680                                 __rte_unused void *data)
3681 {
3682         struct cmd_set_list_result *res;
3683         union {
3684                 unsigned int lcorelist[RTE_MAX_LCORE];
3685                 unsigned int portlist[RTE_MAX_ETHPORTS];
3686         } parsed_items;
3687         unsigned int nb_item;
3688
3689         if (test_done == 0) {
3690                 fprintf(stderr, "Please stop forwarding first\n");
3691                 return;
3692         }
3693
3694         res = parsed_result;
3695         if (!strcmp(res->list_name, "corelist")) {
3696                 nb_item = parse_item_list(res->list_of_items, "core",
3697                                           RTE_MAX_LCORE,
3698                                           parsed_items.lcorelist, 1);
3699                 if (nb_item > 0) {
3700                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3701                         fwd_config_setup();
3702                 }
3703                 return;
3704         }
3705         if (!strcmp(res->list_name, "portlist")) {
3706                 nb_item = parse_item_list(res->list_of_items, "port",
3707                                           RTE_MAX_ETHPORTS,
3708                                           parsed_items.portlist, 1);
3709                 if (nb_item > 0) {
3710                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3711                         fwd_config_setup();
3712                 }
3713         }
3714 }
3715
3716 cmdline_parse_token_string_t cmd_set_list_keyword =
3717         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3718                                  "set");
3719 cmdline_parse_token_string_t cmd_set_list_name =
3720         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3721                                  "corelist#portlist");
3722 cmdline_parse_token_string_t cmd_set_list_of_items =
3723         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3724                                  NULL);
3725
3726 cmdline_parse_inst_t cmd_set_fwd_list = {
3727         .f = cmd_set_list_parsed,
3728         .data = NULL,
3729         .help_str = "set corelist|portlist <list0[,list1]*>",
3730         .tokens = {
3731                 (void *)&cmd_set_list_keyword,
3732                 (void *)&cmd_set_list_name,
3733                 (void *)&cmd_set_list_of_items,
3734                 NULL,
3735         },
3736 };
3737
3738 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3739
3740 struct cmd_setmask_result {
3741         cmdline_fixed_string_t set;
3742         cmdline_fixed_string_t mask;
3743         uint64_t hexavalue;
3744 };
3745
3746 static void cmd_set_mask_parsed(void *parsed_result,
3747                                 __rte_unused struct cmdline *cl,
3748                                 __rte_unused void *data)
3749 {
3750         struct cmd_setmask_result *res = parsed_result;
3751
3752         if (test_done == 0) {
3753                 fprintf(stderr, "Please stop forwarding first\n");
3754                 return;
3755         }
3756         if (!strcmp(res->mask, "coremask")) {
3757                 set_fwd_lcores_mask(res->hexavalue);
3758                 fwd_config_setup();
3759         } else if (!strcmp(res->mask, "portmask")) {
3760                 set_fwd_ports_mask(res->hexavalue);
3761                 fwd_config_setup();
3762         }
3763 }
3764
3765 cmdline_parse_token_string_t cmd_setmask_set =
3766         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3767 cmdline_parse_token_string_t cmd_setmask_mask =
3768         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3769                                  "coremask#portmask");
3770 cmdline_parse_token_num_t cmd_setmask_value =
3771         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3772
3773 cmdline_parse_inst_t cmd_set_fwd_mask = {
3774         .f = cmd_set_mask_parsed,
3775         .data = NULL,
3776         .help_str = "set coremask|portmask <hexadecimal value>",
3777         .tokens = {
3778                 (void *)&cmd_setmask_set,
3779                 (void *)&cmd_setmask_mask,
3780                 (void *)&cmd_setmask_value,
3781                 NULL,
3782         },
3783 };
3784
3785 /*
3786  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3787  */
3788 struct cmd_set_result {
3789         cmdline_fixed_string_t set;
3790         cmdline_fixed_string_t what;
3791         uint16_t value;
3792 };
3793
3794 static void cmd_set_parsed(void *parsed_result,
3795                            __rte_unused struct cmdline *cl,
3796                            __rte_unused void *data)
3797 {
3798         struct cmd_set_result *res = parsed_result;
3799         if (!strcmp(res->what, "nbport")) {
3800                 set_fwd_ports_number(res->value);
3801                 fwd_config_setup();
3802         } else if (!strcmp(res->what, "nbcore")) {
3803                 set_fwd_lcores_number(res->value);
3804                 fwd_config_setup();
3805         } else if (!strcmp(res->what, "burst"))
3806                 set_nb_pkt_per_burst(res->value);
3807         else if (!strcmp(res->what, "verbose"))
3808                 set_verbose_level(res->value);
3809 }
3810
3811 cmdline_parse_token_string_t cmd_set_set =
3812         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3813 cmdline_parse_token_string_t cmd_set_what =
3814         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3815                                  "nbport#nbcore#burst#verbose");
3816 cmdline_parse_token_num_t cmd_set_value =
3817         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3818
3819 cmdline_parse_inst_t cmd_set_numbers = {
3820         .f = cmd_set_parsed,
3821         .data = NULL,
3822         .help_str = "set nbport|nbcore|burst|verbose <value>",
3823         .tokens = {
3824                 (void *)&cmd_set_set,
3825                 (void *)&cmd_set_what,
3826                 (void *)&cmd_set_value,
3827                 NULL,
3828         },
3829 };
3830
3831 /* *** SET LOG LEVEL CONFIGURATION *** */
3832
3833 struct cmd_set_log_result {
3834         cmdline_fixed_string_t set;
3835         cmdline_fixed_string_t log;
3836         cmdline_fixed_string_t type;
3837         uint32_t level;
3838 };
3839
3840 static void
3841 cmd_set_log_parsed(void *parsed_result,
3842                    __rte_unused struct cmdline *cl,
3843                    __rte_unused void *data)
3844 {
3845         struct cmd_set_log_result *res;
3846         int ret;
3847
3848         res = parsed_result;
3849         if (!strcmp(res->type, "global"))
3850                 rte_log_set_global_level(res->level);
3851         else {
3852                 ret = rte_log_set_level_regexp(res->type, res->level);
3853                 if (ret < 0)
3854                         fprintf(stderr, "Unable to set log level\n");
3855         }
3856 }
3857
3858 cmdline_parse_token_string_t cmd_set_log_set =
3859         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3860 cmdline_parse_token_string_t cmd_set_log_log =
3861         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3862 cmdline_parse_token_string_t cmd_set_log_type =
3863         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3864 cmdline_parse_token_num_t cmd_set_log_level =
3865         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3866
3867 cmdline_parse_inst_t cmd_set_log = {
3868         .f = cmd_set_log_parsed,
3869         .data = NULL,
3870         .help_str = "set log global|<type> <level>",
3871         .tokens = {
3872                 (void *)&cmd_set_log_set,
3873                 (void *)&cmd_set_log_log,
3874                 (void *)&cmd_set_log_type,
3875                 (void *)&cmd_set_log_level,
3876                 NULL,
3877         },
3878 };
3879
3880 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3881
3882 struct cmd_set_rxoffs_result {
3883         cmdline_fixed_string_t cmd_keyword;
3884         cmdline_fixed_string_t rxoffs;
3885         cmdline_fixed_string_t seg_offsets;
3886 };
3887
3888 static void
3889 cmd_set_rxoffs_parsed(void *parsed_result,
3890                       __rte_unused struct cmdline *cl,
3891                       __rte_unused void *data)
3892 {
3893         struct cmd_set_rxoffs_result *res;
3894         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3895         unsigned int nb_segs;
3896
3897         res = parsed_result;
3898         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3899                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3900         if (nb_segs > 0)
3901                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3902         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3903 }
3904
3905 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3906         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3907                                  cmd_keyword, "set");
3908 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3909         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3910                                  rxoffs, "rxoffs");
3911 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3912         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3913                                  seg_offsets, NULL);
3914
3915 cmdline_parse_inst_t cmd_set_rxoffs = {
3916         .f = cmd_set_rxoffs_parsed,
3917         .data = NULL,
3918         .help_str = "set rxoffs <len0[,len1]*>",
3919         .tokens = {
3920                 (void *)&cmd_set_rxoffs_keyword,
3921                 (void *)&cmd_set_rxoffs_name,
3922                 (void *)&cmd_set_rxoffs_offsets,
3923                 NULL,
3924         },
3925 };
3926
3927 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3928
3929 struct cmd_set_rxpkts_result {
3930         cmdline_fixed_string_t cmd_keyword;
3931         cmdline_fixed_string_t rxpkts;
3932         cmdline_fixed_string_t seg_lengths;
3933 };
3934
3935 static void
3936 cmd_set_rxpkts_parsed(void *parsed_result,
3937                       __rte_unused struct cmdline *cl,
3938                       __rte_unused void *data)
3939 {
3940         struct cmd_set_rxpkts_result *res;
3941         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3942         unsigned int nb_segs;
3943
3944         res = parsed_result;
3945         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3946                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3947         if (nb_segs > 0)
3948                 set_rx_pkt_segments(seg_lengths, nb_segs);
3949         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3950 }
3951
3952 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3953         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3954                                  cmd_keyword, "set");
3955 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3956         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3957                                  rxpkts, "rxpkts");
3958 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3959         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3960                                  seg_lengths, NULL);
3961
3962 cmdline_parse_inst_t cmd_set_rxpkts = {
3963         .f = cmd_set_rxpkts_parsed,
3964         .data = NULL,
3965         .help_str = "set rxpkts <len0[,len1]*>",
3966         .tokens = {
3967                 (void *)&cmd_set_rxpkts_keyword,
3968                 (void *)&cmd_set_rxpkts_name,
3969                 (void *)&cmd_set_rxpkts_lengths,
3970                 NULL,
3971         },
3972 };
3973
3974 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3975
3976 struct cmd_set_txpkts_result {
3977         cmdline_fixed_string_t cmd_keyword;
3978         cmdline_fixed_string_t txpkts;
3979         cmdline_fixed_string_t seg_lengths;
3980 };
3981
3982 static void
3983 cmd_set_txpkts_parsed(void *parsed_result,
3984                       __rte_unused struct cmdline *cl,
3985                       __rte_unused void *data)
3986 {
3987         struct cmd_set_txpkts_result *res;
3988         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3989         unsigned int nb_segs;
3990
3991         res = parsed_result;
3992         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3993                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3994         if (nb_segs > 0)
3995                 set_tx_pkt_segments(seg_lengths, nb_segs);
3996 }
3997
3998 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3999         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4000                                  cmd_keyword, "set");
4001 cmdline_parse_token_string_t cmd_set_txpkts_name =
4002         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4003                                  txpkts, "txpkts");
4004 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4005         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4006                                  seg_lengths, NULL);
4007
4008 cmdline_parse_inst_t cmd_set_txpkts = {
4009         .f = cmd_set_txpkts_parsed,
4010         .data = NULL,
4011         .help_str = "set txpkts <len0[,len1]*>",
4012         .tokens = {
4013                 (void *)&cmd_set_txpkts_keyword,
4014                 (void *)&cmd_set_txpkts_name,
4015                 (void *)&cmd_set_txpkts_lengths,
4016                 NULL,
4017         },
4018 };
4019
4020 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4021
4022 struct cmd_set_txsplit_result {
4023         cmdline_fixed_string_t cmd_keyword;
4024         cmdline_fixed_string_t txsplit;
4025         cmdline_fixed_string_t mode;
4026 };
4027
4028 static void
4029 cmd_set_txsplit_parsed(void *parsed_result,
4030                       __rte_unused struct cmdline *cl,
4031                       __rte_unused void *data)
4032 {
4033         struct cmd_set_txsplit_result *res;
4034
4035         res = parsed_result;
4036         set_tx_pkt_split(res->mode);
4037 }
4038
4039 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4040         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4041                                  cmd_keyword, "set");
4042 cmdline_parse_token_string_t cmd_set_txsplit_name =
4043         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4044                                  txsplit, "txsplit");
4045 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4046         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4047                                  mode, NULL);
4048
4049 cmdline_parse_inst_t cmd_set_txsplit = {
4050         .f = cmd_set_txsplit_parsed,
4051         .data = NULL,
4052         .help_str = "set txsplit on|off|rand",
4053         .tokens = {
4054                 (void *)&cmd_set_txsplit_keyword,
4055                 (void *)&cmd_set_txsplit_name,
4056                 (void *)&cmd_set_txsplit_mode,
4057                 NULL,
4058         },
4059 };
4060
4061 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4062
4063 struct cmd_set_txtimes_result {
4064         cmdline_fixed_string_t cmd_keyword;
4065         cmdline_fixed_string_t txtimes;
4066         cmdline_fixed_string_t tx_times;
4067 };
4068
4069 static void
4070 cmd_set_txtimes_parsed(void *parsed_result,
4071                        __rte_unused struct cmdline *cl,
4072                        __rte_unused void *data)
4073 {
4074         struct cmd_set_txtimes_result *res;
4075         unsigned int tx_times[2] = {0, 0};
4076         unsigned int n_times;
4077
4078         res = parsed_result;
4079         n_times = parse_item_list(res->tx_times, "tx times",
4080                                   2, tx_times, 0);
4081         if (n_times == 2)
4082                 set_tx_pkt_times(tx_times);
4083 }
4084
4085 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4086         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4087                                  cmd_keyword, "set");
4088 cmdline_parse_token_string_t cmd_set_txtimes_name =
4089         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4090                                  txtimes, "txtimes");
4091 cmdline_parse_token_string_t cmd_set_txtimes_value =
4092         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4093                                  tx_times, NULL);
4094
4095 cmdline_parse_inst_t cmd_set_txtimes = {
4096         .f = cmd_set_txtimes_parsed,
4097         .data = NULL,
4098         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4099         .tokens = {
4100                 (void *)&cmd_set_txtimes_keyword,
4101                 (void *)&cmd_set_txtimes_name,
4102                 (void *)&cmd_set_txtimes_value,
4103                 NULL,
4104         },
4105 };
4106
4107 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4108 struct cmd_rx_vlan_filter_all_result {
4109         cmdline_fixed_string_t rx_vlan;
4110         cmdline_fixed_string_t what;
4111         cmdline_fixed_string_t all;
4112         portid_t port_id;
4113 };
4114
4115 static void
4116 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4117                               __rte_unused struct cmdline *cl,
4118                               __rte_unused void *data)
4119 {
4120         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4121
4122         if (!strcmp(res->what, "add"))
4123                 rx_vlan_all_filter_set(res->port_id, 1);
4124         else
4125                 rx_vlan_all_filter_set(res->port_id, 0);
4126 }
4127
4128 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4129         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4130                                  rx_vlan, "rx_vlan");
4131 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4132         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4133                                  what, "add#rm");
4134 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4135         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4136                                  all, "all");
4137 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4138         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4139                               port_id, RTE_UINT16);
4140
4141 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4142         .f = cmd_rx_vlan_filter_all_parsed,
4143         .data = NULL,
4144         .help_str = "rx_vlan add|rm all <port_id>: "
4145                 "Add/Remove all identifiers to/from the set of VLAN "
4146                 "identifiers filtered by a port",
4147         .tokens = {
4148                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4149                 (void *)&cmd_rx_vlan_filter_all_what,
4150                 (void *)&cmd_rx_vlan_filter_all_all,
4151                 (void *)&cmd_rx_vlan_filter_all_portid,
4152                 NULL,
4153         },
4154 };
4155
4156 /* *** VLAN OFFLOAD SET ON A PORT *** */
4157 struct cmd_vlan_offload_result {
4158         cmdline_fixed_string_t vlan;
4159         cmdline_fixed_string_t set;
4160         cmdline_fixed_string_t vlan_type;
4161         cmdline_fixed_string_t what;
4162         cmdline_fixed_string_t on;
4163         cmdline_fixed_string_t port_id;
4164 };
4165
4166 static void
4167 cmd_vlan_offload_parsed(void *parsed_result,
4168                           __rte_unused struct cmdline *cl,
4169                           __rte_unused void *data)
4170 {
4171         int on;
4172         struct cmd_vlan_offload_result *res = parsed_result;
4173         char *str;
4174         int i, len = 0;
4175         portid_t port_id = 0;
4176         unsigned int tmp;
4177
4178         str = res->port_id;
4179         len = strnlen(str, STR_TOKEN_SIZE);
4180         i = 0;
4181         /* Get port_id first */
4182         while(i < len){
4183                 if(str[i] == ',')
4184                         break;
4185
4186                 i++;
4187         }
4188         str[i]='\0';
4189         tmp = strtoul(str, NULL, 0);
4190         /* If port_id greater that what portid_t can represent, return */
4191         if(tmp >= RTE_MAX_ETHPORTS)
4192                 return;
4193         port_id = (portid_t)tmp;
4194
4195         if (!strcmp(res->on, "on"))
4196                 on = 1;
4197         else
4198                 on = 0;
4199
4200         if (!strcmp(res->what, "strip"))
4201                 rx_vlan_strip_set(port_id,  on);
4202         else if(!strcmp(res->what, "stripq")){
4203                 uint16_t queue_id = 0;
4204
4205                 /* No queue_id, return */
4206                 if(i + 1 >= len) {
4207                         fprintf(stderr, "must specify (port,queue_id)\n");
4208                         return;
4209                 }
4210                 tmp = strtoul(str + i + 1, NULL, 0);
4211                 /* If queue_id greater that what 16-bits can represent, return */
4212                 if(tmp > 0xffff)
4213                         return;
4214
4215                 queue_id = (uint16_t)tmp;
4216                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4217         }
4218         else if (!strcmp(res->what, "filter"))
4219                 rx_vlan_filter_set(port_id, on);
4220         else if (!strcmp(res->what, "qinq_strip"))
4221                 rx_vlan_qinq_strip_set(port_id, on);
4222         else
4223                 vlan_extend_set(port_id, on);
4224
4225         return;
4226 }
4227
4228 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4229         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4230                                  vlan, "vlan");
4231 cmdline_parse_token_string_t cmd_vlan_offload_set =
4232         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4233                                  set, "set");
4234 cmdline_parse_token_string_t cmd_vlan_offload_what =
4235         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4236                                 what, "strip#filter#qinq_strip#extend#stripq");
4237 cmdline_parse_token_string_t cmd_vlan_offload_on =
4238         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4239                               on, "on#off");
4240 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4241         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4242                               port_id, NULL);
4243
4244 cmdline_parse_inst_t cmd_vlan_offload = {
4245         .f = cmd_vlan_offload_parsed,
4246         .data = NULL,
4247         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4248                 "<port_id[,queue_id]>: "
4249                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4250         .tokens = {
4251                 (void *)&cmd_vlan_offload_vlan,
4252                 (void *)&cmd_vlan_offload_set,
4253                 (void *)&cmd_vlan_offload_what,
4254                 (void *)&cmd_vlan_offload_on,
4255                 (void *)&cmd_vlan_offload_portid,
4256                 NULL,
4257         },
4258 };
4259
4260 /* *** VLAN TPID SET ON A PORT *** */
4261 struct cmd_vlan_tpid_result {
4262         cmdline_fixed_string_t vlan;
4263         cmdline_fixed_string_t set;
4264         cmdline_fixed_string_t vlan_type;
4265         cmdline_fixed_string_t what;
4266         uint16_t tp_id;
4267         portid_t port_id;
4268 };
4269
4270 static void
4271 cmd_vlan_tpid_parsed(void *parsed_result,
4272                           __rte_unused struct cmdline *cl,
4273                           __rte_unused void *data)
4274 {
4275         struct cmd_vlan_tpid_result *res = parsed_result;
4276         enum rte_vlan_type vlan_type;
4277
4278         if (!strcmp(res->vlan_type, "inner"))
4279                 vlan_type = ETH_VLAN_TYPE_INNER;
4280         else if (!strcmp(res->vlan_type, "outer"))
4281                 vlan_type = ETH_VLAN_TYPE_OUTER;
4282         else {
4283                 fprintf(stderr, "Unknown vlan type\n");
4284                 return;
4285         }
4286         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4287 }
4288
4289 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4290         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4291                                  vlan, "vlan");
4292 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4293         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4294                                  set, "set");
4295 cmdline_parse_token_string_t cmd_vlan_type =
4296         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4297                                  vlan_type, "inner#outer");
4298 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4299         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4300                                  what, "tpid");
4301 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4302         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4303                               tp_id, RTE_UINT16);
4304 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4305         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4306                               port_id, RTE_UINT16);
4307
4308 cmdline_parse_inst_t cmd_vlan_tpid = {
4309         .f = cmd_vlan_tpid_parsed,
4310         .data = NULL,
4311         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4312                 "Set the VLAN Ether type",
4313         .tokens = {
4314                 (void *)&cmd_vlan_tpid_vlan,
4315                 (void *)&cmd_vlan_tpid_set,
4316                 (void *)&cmd_vlan_type,
4317                 (void *)&cmd_vlan_tpid_what,
4318                 (void *)&cmd_vlan_tpid_tpid,
4319                 (void *)&cmd_vlan_tpid_portid,
4320                 NULL,
4321         },
4322 };
4323
4324 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4325 struct cmd_rx_vlan_filter_result {
4326         cmdline_fixed_string_t rx_vlan;
4327         cmdline_fixed_string_t what;
4328         uint16_t vlan_id;
4329         portid_t port_id;
4330 };
4331
4332 static void
4333 cmd_rx_vlan_filter_parsed(void *parsed_result,
4334                           __rte_unused struct cmdline *cl,
4335                           __rte_unused void *data)
4336 {
4337         struct cmd_rx_vlan_filter_result *res = parsed_result;
4338
4339         if (!strcmp(res->what, "add"))
4340                 rx_vft_set(res->port_id, res->vlan_id, 1);
4341         else
4342                 rx_vft_set(res->port_id, res->vlan_id, 0);
4343 }
4344
4345 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4346         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4347                                  rx_vlan, "rx_vlan");
4348 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4349         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4350                                  what, "add#rm");
4351 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4352         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4353                               vlan_id, RTE_UINT16);
4354 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4355         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4356                               port_id, RTE_UINT16);
4357
4358 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4359         .f = cmd_rx_vlan_filter_parsed,
4360         .data = NULL,
4361         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4362                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4363                 "identifiers filtered by a port",
4364         .tokens = {
4365                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4366                 (void *)&cmd_rx_vlan_filter_what,
4367                 (void *)&cmd_rx_vlan_filter_vlanid,
4368                 (void *)&cmd_rx_vlan_filter_portid,
4369                 NULL,
4370         },
4371 };
4372
4373 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4374 struct cmd_tx_vlan_set_result {
4375         cmdline_fixed_string_t tx_vlan;
4376         cmdline_fixed_string_t set;
4377         portid_t port_id;
4378         uint16_t vlan_id;
4379 };
4380
4381 static void
4382 cmd_tx_vlan_set_parsed(void *parsed_result,
4383                        __rte_unused struct cmdline *cl,
4384                        __rte_unused void *data)
4385 {
4386         struct cmd_tx_vlan_set_result *res = parsed_result;
4387
4388         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4389                 return;
4390
4391         if (!port_is_stopped(res->port_id)) {
4392                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4393                 return;
4394         }
4395
4396         tx_vlan_set(res->port_id, res->vlan_id);
4397
4398         cmd_reconfig_device_queue(res->port_id, 1, 1);
4399 }
4400
4401 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4402         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4403                                  tx_vlan, "tx_vlan");
4404 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4405         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4406                                  set, "set");
4407 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4408         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4409                               port_id, RTE_UINT16);
4410 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4411         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4412                               vlan_id, RTE_UINT16);
4413
4414 cmdline_parse_inst_t cmd_tx_vlan_set = {
4415         .f = cmd_tx_vlan_set_parsed,
4416         .data = NULL,
4417         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4418                 "Enable hardware insertion of a single VLAN header "
4419                 "with a given TAG Identifier in packets sent on a port",
4420         .tokens = {
4421                 (void *)&cmd_tx_vlan_set_tx_vlan,
4422                 (void *)&cmd_tx_vlan_set_set,
4423                 (void *)&cmd_tx_vlan_set_portid,
4424                 (void *)&cmd_tx_vlan_set_vlanid,
4425                 NULL,
4426         },
4427 };
4428
4429 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4430 struct cmd_tx_vlan_set_qinq_result {
4431         cmdline_fixed_string_t tx_vlan;
4432         cmdline_fixed_string_t set;
4433         portid_t port_id;
4434         uint16_t vlan_id;
4435         uint16_t vlan_id_outer;
4436 };
4437
4438 static void
4439 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4440                             __rte_unused struct cmdline *cl,
4441                             __rte_unused void *data)
4442 {
4443         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4444
4445         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4446                 return;
4447
4448         if (!port_is_stopped(res->port_id)) {
4449                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4450                 return;
4451         }
4452
4453         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4454
4455         cmd_reconfig_device_queue(res->port_id, 1, 1);
4456 }
4457
4458 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4459         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4460                 tx_vlan, "tx_vlan");
4461 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4462         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4463                 set, "set");
4464 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4465         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4466                 port_id, RTE_UINT16);
4467 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4468         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4469                 vlan_id, RTE_UINT16);
4470 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4471         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4472                 vlan_id_outer, RTE_UINT16);
4473
4474 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4475         .f = cmd_tx_vlan_set_qinq_parsed,
4476         .data = NULL,
4477         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4478                 "Enable hardware insertion of double VLAN header "
4479                 "with given TAG Identifiers in packets sent on a port",
4480         .tokens = {
4481                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4482                 (void *)&cmd_tx_vlan_set_qinq_set,
4483                 (void *)&cmd_tx_vlan_set_qinq_portid,
4484                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4485                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4486                 NULL,
4487         },
4488 };
4489
4490 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4491 struct cmd_tx_vlan_set_pvid_result {
4492         cmdline_fixed_string_t tx_vlan;
4493         cmdline_fixed_string_t set;
4494         cmdline_fixed_string_t pvid;
4495         portid_t port_id;
4496         uint16_t vlan_id;
4497         cmdline_fixed_string_t mode;
4498 };
4499
4500 static void
4501 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4502                             __rte_unused struct cmdline *cl,
4503                             __rte_unused void *data)
4504 {
4505         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4506
4507         if (strcmp(res->mode, "on") == 0)
4508                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4509         else
4510                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4511 }
4512
4513 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4514         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4515                                  tx_vlan, "tx_vlan");
4516 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4517         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4518                                  set, "set");
4519 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4520         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4521                                  pvid, "pvid");
4522 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4523         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4524                              port_id, RTE_UINT16);
4525 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4526         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4527                               vlan_id, RTE_UINT16);
4528 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4529         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4530                                  mode, "on#off");
4531
4532 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4533         .f = cmd_tx_vlan_set_pvid_parsed,
4534         .data = NULL,
4535         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4536         .tokens = {
4537                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4538                 (void *)&cmd_tx_vlan_set_pvid_set,
4539                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4540                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4541                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4542                 (void *)&cmd_tx_vlan_set_pvid_mode,
4543                 NULL,
4544         },
4545 };
4546
4547 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4548 struct cmd_tx_vlan_reset_result {
4549         cmdline_fixed_string_t tx_vlan;
4550         cmdline_fixed_string_t reset;
4551         portid_t port_id;
4552 };
4553
4554 static void
4555 cmd_tx_vlan_reset_parsed(void *parsed_result,
4556                          __rte_unused struct cmdline *cl,
4557                          __rte_unused void *data)
4558 {
4559         struct cmd_tx_vlan_reset_result *res = parsed_result;
4560
4561         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4562                 return;
4563
4564         if (!port_is_stopped(res->port_id)) {
4565                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4566                 return;
4567         }
4568
4569         tx_vlan_reset(res->port_id);
4570
4571         cmd_reconfig_device_queue(res->port_id, 1, 1);
4572 }
4573
4574 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4575         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4576                                  tx_vlan, "tx_vlan");
4577 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4578         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4579                                  reset, "reset");
4580 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4581         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4582                               port_id, RTE_UINT16);
4583
4584 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4585         .f = cmd_tx_vlan_reset_parsed,
4586         .data = NULL,
4587         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4588                 "VLAN header in packets sent on a port",
4589         .tokens = {
4590                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4591                 (void *)&cmd_tx_vlan_reset_reset,
4592                 (void *)&cmd_tx_vlan_reset_portid,
4593                 NULL,
4594         },
4595 };
4596
4597
4598 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4599 struct cmd_csum_result {
4600         cmdline_fixed_string_t csum;
4601         cmdline_fixed_string_t mode;
4602         cmdline_fixed_string_t proto;
4603         cmdline_fixed_string_t hwsw;
4604         portid_t port_id;
4605 };
4606
4607 static void
4608 csum_show(int port_id)
4609 {
4610         struct rte_eth_dev_info dev_info;
4611         uint64_t tx_offloads;
4612         int ret;
4613
4614         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4615         printf("Parse tunnel is %s\n",
4616                 (ports[port_id].parse_tunnel) ? "on" : "off");
4617         printf("IP checksum offload is %s\n",
4618                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4619         printf("UDP checksum offload is %s\n",
4620                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4621         printf("TCP checksum offload is %s\n",
4622                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4623         printf("SCTP checksum offload is %s\n",
4624                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4625         printf("Outer-Ip checksum offload is %s\n",
4626                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4627         printf("Outer-Udp checksum offload is %s\n",
4628                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4629
4630         /* display warnings if configuration is not supported by the NIC */
4631         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4632         if (ret != 0)
4633                 return;
4634
4635         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4636                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4637                 fprintf(stderr,
4638                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4639                         port_id);
4640         }
4641         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4642                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4643                 fprintf(stderr,
4644                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4645                         port_id);
4646         }
4647         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4648                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4649                 fprintf(stderr,
4650                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4651                         port_id);
4652         }
4653         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4654                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4655                 fprintf(stderr,
4656                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4657                         port_id);
4658         }
4659         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4660                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4661                 fprintf(stderr,
4662                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4663                         port_id);
4664         }
4665         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4666                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4667                         == 0) {
4668                 fprintf(stderr,
4669                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4670                         port_id);
4671         }
4672 }
4673
4674 static void
4675 cmd_config_queue_tx_offloads(struct rte_port *port)
4676 {
4677         int k;
4678
4679         /* Apply queue tx offloads configuration */
4680         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4681                 port->tx_conf[k].offloads =
4682                         port->dev_conf.txmode.offloads;
4683 }
4684
4685 static void
4686 cmd_csum_parsed(void *parsed_result,
4687                        __rte_unused struct cmdline *cl,
4688                        __rte_unused void *data)
4689 {
4690         struct cmd_csum_result *res = parsed_result;
4691         int hw = 0;
4692         uint64_t csum_offloads = 0;
4693         struct rte_eth_dev_info dev_info;
4694         int ret;
4695
4696         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4697                 fprintf(stderr, "invalid port %d\n", res->port_id);
4698                 return;
4699         }
4700         if (!port_is_stopped(res->port_id)) {
4701                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4702                 return;
4703         }
4704
4705         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4706         if (ret != 0)
4707                 return;
4708
4709         if (!strcmp(res->mode, "set")) {
4710
4711                 if (!strcmp(res->hwsw, "hw"))
4712                         hw = 1;
4713
4714                 if (!strcmp(res->proto, "ip")) {
4715                         if (hw == 0 || (dev_info.tx_offload_capa &
4716                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4717                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4718                         } else {
4719                                 fprintf(stderr,
4720                                         "IP checksum offload is not supported by port %u\n",
4721                                         res->port_id);
4722                         }
4723                 } else if (!strcmp(res->proto, "udp")) {
4724                         if (hw == 0 || (dev_info.tx_offload_capa &
4725                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4726                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4727                         } else {
4728                                 fprintf(stderr,
4729                                         "UDP checksum offload is not supported by port %u\n",
4730                                         res->port_id);
4731                         }
4732                 } else if (!strcmp(res->proto, "tcp")) {
4733                         if (hw == 0 || (dev_info.tx_offload_capa &
4734                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4735                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4736                         } else {
4737                                 fprintf(stderr,
4738                                         "TCP checksum offload is not supported by port %u\n",
4739                                         res->port_id);
4740                         }
4741                 } else if (!strcmp(res->proto, "sctp")) {
4742                         if (hw == 0 || (dev_info.tx_offload_capa &
4743                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4744                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4745                         } else {
4746                                 fprintf(stderr,
4747                                         "SCTP checksum offload is not supported by port %u\n",
4748                                         res->port_id);
4749                         }
4750                 } else if (!strcmp(res->proto, "outer-ip")) {
4751                         if (hw == 0 || (dev_info.tx_offload_capa &
4752                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4753                                 csum_offloads |=
4754                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4755                         } else {
4756                                 fprintf(stderr,
4757                                         "Outer IP checksum offload is not supported by port %u\n",
4758                                         res->port_id);
4759                         }
4760                 } else if (!strcmp(res->proto, "outer-udp")) {
4761                         if (hw == 0 || (dev_info.tx_offload_capa &
4762                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4763                                 csum_offloads |=
4764                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4765                         } else {
4766                                 fprintf(stderr,
4767                                         "Outer UDP checksum offload is not supported by port %u\n",
4768                                         res->port_id);
4769                         }
4770                 }
4771
4772                 if (hw) {
4773                         ports[res->port_id].dev_conf.txmode.offloads |=
4774                                                         csum_offloads;
4775                 } else {
4776                         ports[res->port_id].dev_conf.txmode.offloads &=
4777                                                         (~csum_offloads);
4778                 }
4779                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4780         }
4781         csum_show(res->port_id);
4782
4783         cmd_reconfig_device_queue(res->port_id, 1, 1);
4784 }
4785
4786 cmdline_parse_token_string_t cmd_csum_csum =
4787         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4788                                 csum, "csum");
4789 cmdline_parse_token_string_t cmd_csum_mode =
4790         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4791                                 mode, "set");
4792 cmdline_parse_token_string_t cmd_csum_proto =
4793         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4794                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4795 cmdline_parse_token_string_t cmd_csum_hwsw =
4796         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4797                                 hwsw, "hw#sw");
4798 cmdline_parse_token_num_t cmd_csum_portid =
4799         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4800                                 port_id, RTE_UINT16);
4801
4802 cmdline_parse_inst_t cmd_csum_set = {
4803         .f = cmd_csum_parsed,
4804         .data = NULL,
4805         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4806                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4807                 "using csum forward engine",
4808         .tokens = {
4809                 (void *)&cmd_csum_csum,
4810                 (void *)&cmd_csum_mode,
4811                 (void *)&cmd_csum_proto,
4812                 (void *)&cmd_csum_hwsw,
4813                 (void *)&cmd_csum_portid,
4814                 NULL,
4815         },
4816 };
4817
4818 cmdline_parse_token_string_t cmd_csum_mode_show =
4819         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4820                                 mode, "show");
4821
4822 cmdline_parse_inst_t cmd_csum_show = {
4823         .f = cmd_csum_parsed,
4824         .data = NULL,
4825         .help_str = "csum show <port_id>: Show checksum offload configuration",
4826         .tokens = {
4827                 (void *)&cmd_csum_csum,
4828                 (void *)&cmd_csum_mode_show,
4829                 (void *)&cmd_csum_portid,
4830                 NULL,
4831         },
4832 };
4833
4834 /* Enable/disable tunnel parsing */
4835 struct cmd_csum_tunnel_result {
4836         cmdline_fixed_string_t csum;
4837         cmdline_fixed_string_t parse;
4838         cmdline_fixed_string_t onoff;
4839         portid_t port_id;
4840 };
4841
4842 static void
4843 cmd_csum_tunnel_parsed(void *parsed_result,
4844                        __rte_unused struct cmdline *cl,
4845                        __rte_unused void *data)
4846 {
4847         struct cmd_csum_tunnel_result *res = parsed_result;
4848
4849         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4850                 return;
4851
4852         if (!strcmp(res->onoff, "on"))
4853                 ports[res->port_id].parse_tunnel = 1;
4854         else
4855                 ports[res->port_id].parse_tunnel = 0;
4856
4857         csum_show(res->port_id);
4858 }
4859
4860 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4861         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4862                                 csum, "csum");
4863 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4864         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4865                                 parse, "parse-tunnel");
4866 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4867         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4868                                 onoff, "on#off");
4869 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4870         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4871                                 port_id, RTE_UINT16);
4872
4873 cmdline_parse_inst_t cmd_csum_tunnel = {
4874         .f = cmd_csum_tunnel_parsed,
4875         .data = NULL,
4876         .help_str = "csum parse-tunnel on|off <port_id>: "
4877                 "Enable/Disable parsing of tunnels for csum engine",
4878         .tokens = {
4879                 (void *)&cmd_csum_tunnel_csum,
4880                 (void *)&cmd_csum_tunnel_parse,
4881                 (void *)&cmd_csum_tunnel_onoff,
4882                 (void *)&cmd_csum_tunnel_portid,
4883                 NULL,
4884         },
4885 };
4886
4887 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4888 struct cmd_tso_set_result {
4889         cmdline_fixed_string_t tso;
4890         cmdline_fixed_string_t mode;
4891         uint16_t tso_segsz;
4892         portid_t port_id;
4893 };
4894
4895 static void
4896 cmd_tso_set_parsed(void *parsed_result,
4897                        __rte_unused struct cmdline *cl,
4898                        __rte_unused void *data)
4899 {
4900         struct cmd_tso_set_result *res = parsed_result;
4901         struct rte_eth_dev_info dev_info;
4902         int ret;
4903
4904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4905                 return;
4906         if (!port_is_stopped(res->port_id)) {
4907                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4908                 return;
4909         }
4910
4911         if (!strcmp(res->mode, "set"))
4912                 ports[res->port_id].tso_segsz = res->tso_segsz;
4913
4914         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4915         if (ret != 0)
4916                 return;
4917
4918         if ((ports[res->port_id].tso_segsz != 0) &&
4919                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4920                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4921                         res->port_id);
4922                 return;
4923         }
4924
4925         if (ports[res->port_id].tso_segsz == 0) {
4926                 ports[res->port_id].dev_conf.txmode.offloads &=
4927                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4928                 printf("TSO for non-tunneled packets is disabled\n");
4929         } else {
4930                 ports[res->port_id].dev_conf.txmode.offloads |=
4931                                                 DEV_TX_OFFLOAD_TCP_TSO;
4932                 printf("TSO segment size for non-tunneled packets is %d\n",
4933                         ports[res->port_id].tso_segsz);
4934         }
4935         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4936
4937         /* display warnings if configuration is not supported by the NIC */
4938         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4939         if (ret != 0)
4940                 return;
4941
4942         if ((ports[res->port_id].tso_segsz != 0) &&
4943                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4944                 fprintf(stderr,
4945                         "Warning: TSO enabled but not supported by port %d\n",
4946                         res->port_id);
4947         }
4948
4949         cmd_reconfig_device_queue(res->port_id, 1, 1);
4950 }
4951
4952 cmdline_parse_token_string_t cmd_tso_set_tso =
4953         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4954                                 tso, "tso");
4955 cmdline_parse_token_string_t cmd_tso_set_mode =
4956         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4957                                 mode, "set");
4958 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4959         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4960                                 tso_segsz, RTE_UINT16);
4961 cmdline_parse_token_num_t cmd_tso_set_portid =
4962         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4963                                 port_id, RTE_UINT16);
4964
4965 cmdline_parse_inst_t cmd_tso_set = {
4966         .f = cmd_tso_set_parsed,
4967         .data = NULL,
4968         .help_str = "tso set <tso_segsz> <port_id>: "
4969                 "Set TSO segment size of non-tunneled packets for csum engine "
4970                 "(0 to disable)",
4971         .tokens = {
4972                 (void *)&cmd_tso_set_tso,
4973                 (void *)&cmd_tso_set_mode,
4974                 (void *)&cmd_tso_set_tso_segsz,
4975                 (void *)&cmd_tso_set_portid,
4976                 NULL,
4977         },
4978 };
4979
4980 cmdline_parse_token_string_t cmd_tso_show_mode =
4981         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4982                                 mode, "show");
4983
4984
4985 cmdline_parse_inst_t cmd_tso_show = {
4986         .f = cmd_tso_set_parsed,
4987         .data = NULL,
4988         .help_str = "tso show <port_id>: "
4989                 "Show TSO segment size of non-tunneled packets for csum engine",
4990         .tokens = {
4991                 (void *)&cmd_tso_set_tso,
4992                 (void *)&cmd_tso_show_mode,
4993                 (void *)&cmd_tso_set_portid,
4994                 NULL,
4995         },
4996 };
4997
4998 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4999 struct cmd_tunnel_tso_set_result {
5000         cmdline_fixed_string_t tso;
5001         cmdline_fixed_string_t mode;
5002         uint16_t tso_segsz;
5003         portid_t port_id;
5004 };
5005
5006 static struct rte_eth_dev_info
5007 check_tunnel_tso_nic_support(portid_t port_id)
5008 {
5009         struct rte_eth_dev_info dev_info;
5010
5011         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5012                 return dev_info;
5013
5014         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5015                 fprintf(stderr,
5016                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5017                         port_id);
5018         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5019                 fprintf(stderr,
5020                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5021                         port_id);
5022         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5023                 fprintf(stderr,
5024                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5025                         port_id);
5026         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5027                 fprintf(stderr,
5028                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5029                         port_id);
5030         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5031                 fprintf(stderr,
5032                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5033                         port_id);
5034         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5035                 fprintf(stderr,
5036                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5037                         port_id);
5038         return dev_info;
5039 }
5040
5041 static void
5042 cmd_tunnel_tso_set_parsed(void *parsed_result,
5043                           __rte_unused struct cmdline *cl,
5044                           __rte_unused void *data)
5045 {
5046         struct cmd_tunnel_tso_set_result *res = parsed_result;
5047         struct rte_eth_dev_info dev_info;
5048
5049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5050                 return;
5051         if (!port_is_stopped(res->port_id)) {
5052                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5053                 return;
5054         }
5055
5056         if (!strcmp(res->mode, "set"))
5057                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5058
5059         dev_info = check_tunnel_tso_nic_support(res->port_id);
5060         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5061                 ports[res->port_id].dev_conf.txmode.offloads &=
5062                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5063                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5064                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5065                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5066                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5067                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5068                 printf("TSO for tunneled packets is disabled\n");
5069         } else {
5070                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5071                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5072                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5073                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5074                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5075                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5076
5077                 ports[res->port_id].dev_conf.txmode.offloads |=
5078                         (tso_offloads & dev_info.tx_offload_capa);
5079                 printf("TSO segment size for tunneled packets is %d\n",
5080                         ports[res->port_id].tunnel_tso_segsz);
5081
5082                 /* Below conditions are needed to make it work:
5083                  * (1) tunnel TSO is supported by the NIC;
5084                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5085                  * are recognized;
5086                  * (3) for tunneled pkts with outer L3 of IPv4,
5087                  * "csum set outer-ip" must be set to hw, because after tso,
5088                  * total_len of outer IP header is changed, and the checksum
5089                  * of outer IP header calculated by sw should be wrong; that
5090                  * is not necessary for IPv6 tunneled pkts because there's no
5091                  * checksum in IP header anymore.
5092                  */
5093
5094                 if (!ports[res->port_id].parse_tunnel)
5095                         fprintf(stderr,
5096                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5097                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5098                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5099                         fprintf(stderr,
5100                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5101         }
5102
5103         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5104         cmd_reconfig_device_queue(res->port_id, 1, 1);
5105 }
5106
5107 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5108         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5109                                 tso, "tunnel_tso");
5110 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5111         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5112                                 mode, "set");
5113 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5114         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5115                                 tso_segsz, RTE_UINT16);
5116 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5117         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5118                                 port_id, RTE_UINT16);
5119
5120 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5121         .f = cmd_tunnel_tso_set_parsed,
5122         .data = NULL,
5123         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5124                 "Set TSO segment size of tunneled packets for csum engine "
5125                 "(0 to disable)",
5126         .tokens = {
5127                 (void *)&cmd_tunnel_tso_set_tso,
5128                 (void *)&cmd_tunnel_tso_set_mode,
5129                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5130                 (void *)&cmd_tunnel_tso_set_portid,
5131                 NULL,
5132         },
5133 };
5134
5135 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5136         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5137                                 mode, "show");
5138
5139
5140 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5141         .f = cmd_tunnel_tso_set_parsed,
5142         .data = NULL,
5143         .help_str = "tunnel_tso show <port_id> "
5144                 "Show TSO segment size of tunneled packets for csum engine",
5145         .tokens = {
5146                 (void *)&cmd_tunnel_tso_set_tso,
5147                 (void *)&cmd_tunnel_tso_show_mode,
5148                 (void *)&cmd_tunnel_tso_set_portid,
5149                 NULL,
5150         },
5151 };
5152
5153 /* *** SET GRO FOR A PORT *** */
5154 struct cmd_gro_enable_result {
5155         cmdline_fixed_string_t cmd_set;
5156         cmdline_fixed_string_t cmd_port;
5157         cmdline_fixed_string_t cmd_keyword;
5158         cmdline_fixed_string_t cmd_onoff;
5159         portid_t cmd_pid;
5160 };
5161
5162 static void
5163 cmd_gro_enable_parsed(void *parsed_result,
5164                 __rte_unused struct cmdline *cl,
5165                 __rte_unused void *data)
5166 {
5167         struct cmd_gro_enable_result *res;
5168
5169         res = parsed_result;
5170         if (!strcmp(res->cmd_keyword, "gro"))
5171                 setup_gro(res->cmd_onoff, res->cmd_pid);
5172 }
5173
5174 cmdline_parse_token_string_t cmd_gro_enable_set =
5175         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5176                         cmd_set, "set");
5177 cmdline_parse_token_string_t cmd_gro_enable_port =
5178         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5179                         cmd_keyword, "port");
5180 cmdline_parse_token_num_t cmd_gro_enable_pid =
5181         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5182                         cmd_pid, RTE_UINT16);
5183 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5184         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5185                         cmd_keyword, "gro");
5186 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5187         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5188                         cmd_onoff, "on#off");
5189
5190 cmdline_parse_inst_t cmd_gro_enable = {
5191         .f = cmd_gro_enable_parsed,
5192         .data = NULL,
5193         .help_str = "set port <port_id> gro on|off",
5194         .tokens = {
5195                 (void *)&cmd_gro_enable_set,
5196                 (void *)&cmd_gro_enable_port,
5197                 (void *)&cmd_gro_enable_pid,
5198                 (void *)&cmd_gro_enable_keyword,
5199                 (void *)&cmd_gro_enable_onoff,
5200                 NULL,
5201         },
5202 };
5203
5204 /* *** DISPLAY GRO CONFIGURATION *** */
5205 struct cmd_gro_show_result {
5206         cmdline_fixed_string_t cmd_show;
5207         cmdline_fixed_string_t cmd_port;
5208         cmdline_fixed_string_t cmd_keyword;
5209         portid_t cmd_pid;
5210 };
5211
5212 static void
5213 cmd_gro_show_parsed(void *parsed_result,
5214                 __rte_unused struct cmdline *cl,
5215                 __rte_unused void *data)
5216 {
5217         struct cmd_gro_show_result *res;
5218
5219         res = parsed_result;
5220         if (!strcmp(res->cmd_keyword, "gro"))
5221                 show_gro(res->cmd_pid);
5222 }
5223
5224 cmdline_parse_token_string_t cmd_gro_show_show =
5225         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5226                         cmd_show, "show");
5227 cmdline_parse_token_string_t cmd_gro_show_port =
5228         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5229                         cmd_port, "port");
5230 cmdline_parse_token_num_t cmd_gro_show_pid =
5231         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5232                         cmd_pid, RTE_UINT16);
5233 cmdline_parse_token_string_t cmd_gro_show_keyword =
5234         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5235                         cmd_keyword, "gro");
5236
5237 cmdline_parse_inst_t cmd_gro_show = {
5238         .f = cmd_gro_show_parsed,
5239         .data = NULL,
5240         .help_str = "show port <port_id> gro",
5241         .tokens = {
5242                 (void *)&cmd_gro_show_show,
5243                 (void *)&cmd_gro_show_port,
5244                 (void *)&cmd_gro_show_pid,
5245                 (void *)&cmd_gro_show_keyword,
5246                 NULL,
5247         },
5248 };
5249
5250 /* *** SET FLUSH CYCLES FOR GRO *** */
5251 struct cmd_gro_flush_result {
5252         cmdline_fixed_string_t cmd_set;
5253         cmdline_fixed_string_t cmd_keyword;
5254         cmdline_fixed_string_t cmd_flush;
5255         uint8_t cmd_cycles;
5256 };
5257
5258 static void
5259 cmd_gro_flush_parsed(void *parsed_result,
5260                 __rte_unused struct cmdline *cl,
5261                 __rte_unused void *data)
5262 {
5263         struct cmd_gro_flush_result *res;
5264
5265         res = parsed_result;
5266         if ((!strcmp(res->cmd_keyword, "gro")) &&
5267                         (!strcmp(res->cmd_flush, "flush")))
5268                 setup_gro_flush_cycles(res->cmd_cycles);
5269 }
5270
5271 cmdline_parse_token_string_t cmd_gro_flush_set =
5272         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5273                         cmd_set, "set");
5274 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5275         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5276                         cmd_keyword, "gro");
5277 cmdline_parse_token_string_t cmd_gro_flush_flush =
5278         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5279                         cmd_flush, "flush");
5280 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5281         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5282                         cmd_cycles, RTE_UINT8);
5283
5284 cmdline_parse_inst_t cmd_gro_flush = {
5285         .f = cmd_gro_flush_parsed,
5286         .data = NULL,
5287         .help_str = "set gro flush <cycles>",
5288         .tokens = {
5289                 (void *)&cmd_gro_flush_set,
5290                 (void *)&cmd_gro_flush_keyword,
5291                 (void *)&cmd_gro_flush_flush,
5292                 (void *)&cmd_gro_flush_cycles,
5293                 NULL,
5294         },
5295 };
5296
5297 /* *** ENABLE/DISABLE GSO *** */
5298 struct cmd_gso_enable_result {
5299         cmdline_fixed_string_t cmd_set;
5300         cmdline_fixed_string_t cmd_port;
5301         cmdline_fixed_string_t cmd_keyword;
5302         cmdline_fixed_string_t cmd_mode;
5303         portid_t cmd_pid;
5304 };
5305
5306 static void
5307 cmd_gso_enable_parsed(void *parsed_result,
5308                 __rte_unused struct cmdline *cl,
5309                 __rte_unused void *data)
5310 {
5311         struct cmd_gso_enable_result *res;
5312
5313         res = parsed_result;
5314         if (!strcmp(res->cmd_keyword, "gso"))
5315                 setup_gso(res->cmd_mode, res->cmd_pid);
5316 }
5317
5318 cmdline_parse_token_string_t cmd_gso_enable_set =
5319         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5320                         cmd_set, "set");
5321 cmdline_parse_token_string_t cmd_gso_enable_port =
5322         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5323                         cmd_port, "port");
5324 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5325         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5326                         cmd_keyword, "gso");
5327 cmdline_parse_token_string_t cmd_gso_enable_mode =
5328         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5329                         cmd_mode, "on#off");
5330 cmdline_parse_token_num_t cmd_gso_enable_pid =
5331         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5332                         cmd_pid, RTE_UINT16);
5333
5334 cmdline_parse_inst_t cmd_gso_enable = {
5335         .f = cmd_gso_enable_parsed,
5336         .data = NULL,
5337         .help_str = "set port <port_id> gso on|off",
5338         .tokens = {
5339                 (void *)&cmd_gso_enable_set,
5340                 (void *)&cmd_gso_enable_port,
5341                 (void *)&cmd_gso_enable_pid,
5342                 (void *)&cmd_gso_enable_keyword,
5343                 (void *)&cmd_gso_enable_mode,
5344                 NULL,
5345         },
5346 };
5347
5348 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5349 struct cmd_gso_size_result {
5350         cmdline_fixed_string_t cmd_set;
5351         cmdline_fixed_string_t cmd_keyword;
5352         cmdline_fixed_string_t cmd_segsz;
5353         uint16_t cmd_size;
5354 };
5355
5356 static void
5357 cmd_gso_size_parsed(void *parsed_result,
5358                        __rte_unused struct cmdline *cl,
5359                        __rte_unused void *data)
5360 {
5361         struct cmd_gso_size_result *res = parsed_result;
5362
5363         if (test_done == 0) {
5364                 fprintf(stderr,
5365                         "Before setting GSO segsz, please first stop forwarding\n");
5366                 return;
5367         }
5368
5369         if (!strcmp(res->cmd_keyword, "gso") &&
5370                         !strcmp(res->cmd_segsz, "segsz")) {
5371                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5372                         fprintf(stderr,
5373                                 "gso_size should be larger than %zu. Please input a legal value\n",
5374                                 RTE_GSO_SEG_SIZE_MIN);
5375                 else
5376                         gso_max_segment_size = res->cmd_size;
5377         }
5378 }
5379
5380 cmdline_parse_token_string_t cmd_gso_size_set =
5381         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5382                                 cmd_set, "set");
5383 cmdline_parse_token_string_t cmd_gso_size_keyword =
5384         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5385                                 cmd_keyword, "gso");
5386 cmdline_parse_token_string_t cmd_gso_size_segsz =
5387         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5388                                 cmd_segsz, "segsz");
5389 cmdline_parse_token_num_t cmd_gso_size_size =
5390         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5391                                 cmd_size, RTE_UINT16);
5392
5393 cmdline_parse_inst_t cmd_gso_size = {
5394         .f = cmd_gso_size_parsed,
5395         .data = NULL,
5396         .help_str = "set gso segsz <length>",
5397         .tokens = {
5398                 (void *)&cmd_gso_size_set,
5399                 (void *)&cmd_gso_size_keyword,
5400                 (void *)&cmd_gso_size_segsz,
5401                 (void *)&cmd_gso_size_size,
5402                 NULL,
5403         },
5404 };
5405
5406 /* *** SHOW GSO CONFIGURATION *** */
5407 struct cmd_gso_show_result {
5408         cmdline_fixed_string_t cmd_show;
5409         cmdline_fixed_string_t cmd_port;
5410         cmdline_fixed_string_t cmd_keyword;
5411         portid_t cmd_pid;
5412 };
5413
5414 static void
5415 cmd_gso_show_parsed(void *parsed_result,
5416                        __rte_unused struct cmdline *cl,
5417                        __rte_unused void *data)
5418 {
5419         struct cmd_gso_show_result *res = parsed_result;
5420
5421         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5422                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5423                 return;
5424         }
5425         if (!strcmp(res->cmd_keyword, "gso")) {
5426                 if (gso_ports[res->cmd_pid].enable) {
5427                         printf("Max GSO'd packet size: %uB\n"
5428                                         "Supported GSO types: TCP/IPv4, "
5429                                         "UDP/IPv4, VxLAN with inner "
5430                                         "TCP/IPv4 packet, GRE with inner "
5431                                         "TCP/IPv4 packet\n",
5432                                         gso_max_segment_size);
5433                 } else
5434                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5435         }
5436 }
5437
5438 cmdline_parse_token_string_t cmd_gso_show_show =
5439 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5440                 cmd_show, "show");
5441 cmdline_parse_token_string_t cmd_gso_show_port =
5442 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5443                 cmd_port, "port");
5444 cmdline_parse_token_string_t cmd_gso_show_keyword =
5445         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5446                                 cmd_keyword, "gso");
5447 cmdline_parse_token_num_t cmd_gso_show_pid =
5448         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5449                                 cmd_pid, RTE_UINT16);
5450
5451 cmdline_parse_inst_t cmd_gso_show = {
5452         .f = cmd_gso_show_parsed,
5453         .data = NULL,
5454         .help_str = "show port <port_id> gso",
5455         .tokens = {
5456                 (void *)&cmd_gso_show_show,
5457                 (void *)&cmd_gso_show_port,
5458                 (void *)&cmd_gso_show_pid,
5459                 (void *)&cmd_gso_show_keyword,
5460                 NULL,
5461         },
5462 };
5463
5464 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5465 struct cmd_set_flush_rx {
5466         cmdline_fixed_string_t set;
5467         cmdline_fixed_string_t flush_rx;
5468         cmdline_fixed_string_t mode;
5469 };
5470
5471 static void
5472 cmd_set_flush_rx_parsed(void *parsed_result,
5473                 __rte_unused struct cmdline *cl,
5474                 __rte_unused void *data)
5475 {
5476         struct cmd_set_flush_rx *res = parsed_result;
5477
5478         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5479                 printf("multi-process doesn't support to flush Rx queues.\n");
5480                 return;
5481         }
5482
5483         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5484 }
5485
5486 cmdline_parse_token_string_t cmd_setflushrx_set =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5488                         set, "set");
5489 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5490         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5491                         flush_rx, "flush_rx");
5492 cmdline_parse_token_string_t cmd_setflushrx_mode =
5493         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5494                         mode, "on#off");
5495
5496
5497 cmdline_parse_inst_t cmd_set_flush_rx = {
5498         .f = cmd_set_flush_rx_parsed,
5499         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5500         .data = NULL,
5501         .tokens = {
5502                 (void *)&cmd_setflushrx_set,
5503                 (void *)&cmd_setflushrx_flush_rx,
5504                 (void *)&cmd_setflushrx_mode,
5505                 NULL,
5506         },
5507 };
5508
5509 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5510 struct cmd_set_link_check {
5511         cmdline_fixed_string_t set;
5512         cmdline_fixed_string_t link_check;
5513         cmdline_fixed_string_t mode;
5514 };
5515
5516 static void
5517 cmd_set_link_check_parsed(void *parsed_result,
5518                 __rte_unused struct cmdline *cl,
5519                 __rte_unused void *data)
5520 {
5521         struct cmd_set_link_check *res = parsed_result;
5522         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5523 }
5524
5525 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5526         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5527                         set, "set");
5528 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5529         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5530                         link_check, "link_check");
5531 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5532         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5533                         mode, "on#off");
5534
5535
5536 cmdline_parse_inst_t cmd_set_link_check = {
5537         .f = cmd_set_link_check_parsed,
5538         .help_str = "set link_check on|off: Enable/Disable link status check "
5539                     "when starting/stopping a port",
5540         .data = NULL,
5541         .tokens = {
5542                 (void *)&cmd_setlinkcheck_set,
5543                 (void *)&cmd_setlinkcheck_link_check,
5544                 (void *)&cmd_setlinkcheck_mode,
5545                 NULL,
5546         },
5547 };
5548
5549 /* *** SET NIC BYPASS MODE *** */
5550 struct cmd_set_bypass_mode_result {
5551         cmdline_fixed_string_t set;
5552         cmdline_fixed_string_t bypass;
5553         cmdline_fixed_string_t mode;
5554         cmdline_fixed_string_t value;
5555         portid_t port_id;
5556 };
5557
5558 static void
5559 cmd_set_bypass_mode_parsed(void *parsed_result,
5560                 __rte_unused struct cmdline *cl,
5561                 __rte_unused void *data)
5562 {
5563         struct cmd_set_bypass_mode_result *res = parsed_result;
5564         portid_t port_id = res->port_id;
5565         int32_t rc = -EINVAL;
5566
5567 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5568         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5569
5570         if (!strcmp(res->value, "bypass"))
5571                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5572         else if (!strcmp(res->value, "isolate"))
5573                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5574         else
5575                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5576
5577         /* Set the bypass mode for the relevant port. */
5578         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5579 #endif
5580         if (rc != 0)
5581                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5582                         port_id);
5583 }
5584
5585 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5586         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5587                         set, "set");
5588 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5589         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5590                         bypass, "bypass");
5591 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5592         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5593                         mode, "mode");
5594 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5595         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5596                         value, "normal#bypass#isolate");
5597 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5598         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5599                                 port_id, RTE_UINT16);
5600
5601 cmdline_parse_inst_t cmd_set_bypass_mode = {
5602         .f = cmd_set_bypass_mode_parsed,
5603         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5604                     "Set the NIC bypass mode for port_id",
5605         .data = NULL,
5606         .tokens = {
5607                 (void *)&cmd_setbypass_mode_set,
5608                 (void *)&cmd_setbypass_mode_bypass,
5609                 (void *)&cmd_setbypass_mode_mode,
5610                 (void *)&cmd_setbypass_mode_value,
5611                 (void *)&cmd_setbypass_mode_port,
5612                 NULL,
5613         },
5614 };
5615
5616 /* *** SET NIC BYPASS EVENT *** */
5617 struct cmd_set_bypass_event_result {
5618         cmdline_fixed_string_t set;
5619         cmdline_fixed_string_t bypass;
5620         cmdline_fixed_string_t event;
5621         cmdline_fixed_string_t event_value;
5622         cmdline_fixed_string_t mode;
5623         cmdline_fixed_string_t mode_value;
5624         portid_t port_id;
5625 };
5626
5627 static void
5628 cmd_set_bypass_event_parsed(void *parsed_result,
5629                 __rte_unused struct cmdline *cl,
5630                 __rte_unused void *data)
5631 {
5632         int32_t rc = -EINVAL;
5633         struct cmd_set_bypass_event_result *res = parsed_result;
5634         portid_t port_id = res->port_id;
5635
5636 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5637         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5638         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5639
5640         if (!strcmp(res->event_value, "timeout"))
5641                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5642         else if (!strcmp(res->event_value, "os_on"))
5643                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5644         else if (!strcmp(res->event_value, "os_off"))
5645                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5646         else if (!strcmp(res->event_value, "power_on"))
5647                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5648         else if (!strcmp(res->event_value, "power_off"))
5649                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5650         else
5651                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5652
5653         if (!strcmp(res->mode_value, "bypass"))
5654                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5655         else if (!strcmp(res->mode_value, "isolate"))
5656                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5657         else
5658                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5659
5660         /* Set the watchdog timeout. */
5661         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5662
5663                 rc = -EINVAL;
5664                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5665                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5666                                                            bypass_timeout);
5667                 }
5668                 if (rc != 0) {
5669                         fprintf(stderr,
5670                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5671                                 bypass_timeout, port_id, rc);
5672                 }
5673         }
5674
5675         /* Set the bypass event to transition to bypass mode. */
5676         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5677                                               bypass_mode);
5678 #endif
5679
5680         if (rc != 0)
5681                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5682                         port_id);
5683 }
5684
5685 cmdline_parse_token_string_t cmd_setbypass_event_set =
5686         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5687                         set, "set");
5688 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5689         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5690                         bypass, "bypass");
5691 cmdline_parse_token_string_t cmd_setbypass_event_event =
5692         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5693                         event, "event");
5694 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5695         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5696                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5697 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5698         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5699                         mode, "mode");
5700 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5701         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5702                         mode_value, "normal#bypass#isolate");
5703 cmdline_parse_token_num_t cmd_setbypass_event_port =
5704         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5705                                 port_id, RTE_UINT16);
5706
5707 cmdline_parse_inst_t cmd_set_bypass_event = {
5708         .f = cmd_set_bypass_event_parsed,
5709         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5710                 "power_off mode normal|bypass|isolate <port_id>: "
5711                 "Set the NIC bypass event mode for port_id",
5712         .data = NULL,
5713         .tokens = {
5714                 (void *)&cmd_setbypass_event_set,
5715                 (void *)&cmd_setbypass_event_bypass,
5716                 (void *)&cmd_setbypass_event_event,
5717                 (void *)&cmd_setbypass_event_event_value,
5718                 (void *)&cmd_setbypass_event_mode,
5719                 (void *)&cmd_setbypass_event_mode_value,
5720                 (void *)&cmd_setbypass_event_port,
5721                 NULL,
5722         },
5723 };
5724
5725
5726 /* *** SET NIC BYPASS TIMEOUT *** */
5727 struct cmd_set_bypass_timeout_result {
5728         cmdline_fixed_string_t set;
5729         cmdline_fixed_string_t bypass;
5730         cmdline_fixed_string_t timeout;
5731         cmdline_fixed_string_t value;
5732 };
5733
5734 static void
5735 cmd_set_bypass_timeout_parsed(void *parsed_result,
5736                 __rte_unused struct cmdline *cl,
5737                 __rte_unused void *data)
5738 {
5739         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5740
5741 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5742         if (!strcmp(res->value, "1.5"))
5743                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5744         else if (!strcmp(res->value, "2"))
5745                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5746         else if (!strcmp(res->value, "3"))
5747                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5748         else if (!strcmp(res->value, "4"))
5749                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5750         else if (!strcmp(res->value, "8"))
5751                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5752         else if (!strcmp(res->value, "16"))
5753                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5754         else if (!strcmp(res->value, "32"))
5755                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5756         else
5757                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5758 #endif
5759 }
5760
5761 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5762         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5763                         set, "set");
5764 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5765         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5766                         bypass, "bypass");
5767 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5768         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5769                         timeout, "timeout");
5770 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5771         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5772                         value, "0#1.5#2#3#4#8#16#32");
5773
5774 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5775         .f = cmd_set_bypass_timeout_parsed,
5776         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5777                 "Set the NIC bypass watchdog timeout in seconds",
5778         .data = NULL,
5779         .tokens = {
5780                 (void *)&cmd_setbypass_timeout_set,
5781                 (void *)&cmd_setbypass_timeout_bypass,
5782                 (void *)&cmd_setbypass_timeout_timeout,
5783                 (void *)&cmd_setbypass_timeout_value,
5784                 NULL,
5785         },
5786 };
5787
5788 /* *** SHOW NIC BYPASS MODE *** */
5789 struct cmd_show_bypass_config_result {
5790         cmdline_fixed_string_t show;
5791         cmdline_fixed_string_t bypass;
5792         cmdline_fixed_string_t config;
5793         portid_t port_id;
5794 };
5795
5796 static void
5797 cmd_show_bypass_config_parsed(void *parsed_result,
5798                 __rte_unused struct cmdline *cl,
5799                 __rte_unused void *data)
5800 {
5801         struct cmd_show_bypass_config_result *res = parsed_result;
5802         portid_t port_id = res->port_id;
5803         int rc = -EINVAL;
5804 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5805         uint32_t event_mode;
5806         uint32_t bypass_mode;
5807         uint32_t timeout = bypass_timeout;
5808         unsigned int i;
5809
5810         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5811                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5812         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5813                 {"UNKNOWN", "normal", "bypass", "isolate"};
5814         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5815                 "NONE",
5816                 "OS/board on",
5817                 "power supply on",
5818                 "OS/board off",
5819                 "power supply off",
5820                 "timeout"};
5821
5822         /* Display the bypass mode.*/
5823         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5824                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5825                         port_id);
5826                 return;
5827         }
5828         else {
5829                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5830                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5831
5832                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5833         }
5834
5835         /* Display the bypass timeout.*/
5836         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5837                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5838
5839         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5840
5841         /* Display the bypass events and associated modes. */
5842         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5843
5844                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5845                         fprintf(stderr,
5846                                 "\tFailed to get bypass mode for event = %s\n",
5847                                 events[i]);
5848                 } else {
5849                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5850                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5851
5852                         printf("\tbypass event: %-16s = %s\n", events[i],
5853                                 modes[event_mode]);
5854                 }
5855         }
5856 #endif
5857         if (rc != 0)
5858                 fprintf(stderr,
5859                         "\tFailed to get bypass configuration for port = %d\n",
5860                        port_id);
5861 }
5862
5863 cmdline_parse_token_string_t cmd_showbypass_config_show =
5864         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5865                         show, "show");
5866 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5867         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5868                         bypass, "bypass");
5869 cmdline_parse_token_string_t cmd_showbypass_config_config =
5870         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5871                         config, "config");
5872 cmdline_parse_token_num_t cmd_showbypass_config_port =
5873         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5874                                 port_id, RTE_UINT16);
5875
5876 cmdline_parse_inst_t cmd_show_bypass_config = {
5877         .f = cmd_show_bypass_config_parsed,
5878         .help_str = "show bypass config <port_id>: "
5879                     "Show the NIC bypass config for port_id",
5880         .data = NULL,
5881         .tokens = {
5882                 (void *)&cmd_showbypass_config_show,
5883                 (void *)&cmd_showbypass_config_bypass,
5884                 (void *)&cmd_showbypass_config_config,
5885                 (void *)&cmd_showbypass_config_port,
5886                 NULL,
5887         },
5888 };
5889
5890 #ifdef RTE_NET_BOND
5891 /* *** SET BONDING MODE *** */
5892 struct cmd_set_bonding_mode_result {
5893         cmdline_fixed_string_t set;
5894         cmdline_fixed_string_t bonding;
5895         cmdline_fixed_string_t mode;
5896         uint8_t value;
5897         portid_t port_id;
5898 };
5899
5900 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5901                 __rte_unused  struct cmdline *cl,
5902                 __rte_unused void *data)
5903 {
5904         struct cmd_set_bonding_mode_result *res = parsed_result;
5905         portid_t port_id = res->port_id;
5906
5907         /* Set the bonding mode for the relevant port. */
5908         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5909                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5910                         port_id);
5911 }
5912
5913 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5914 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5915                 set, "set");
5916 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5917 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5918                 bonding, "bonding");
5919 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5920 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5921                 mode, "mode");
5922 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5923 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5924                 value, RTE_UINT8);
5925 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5926 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5927                 port_id, RTE_UINT16);
5928
5929 cmdline_parse_inst_t cmd_set_bonding_mode = {
5930                 .f = cmd_set_bonding_mode_parsed,
5931                 .help_str = "set bonding mode <mode_value> <port_id>: "
5932                         "Set the bonding mode for port_id",
5933                 .data = NULL,
5934                 .tokens = {
5935                                 (void *) &cmd_setbonding_mode_set,
5936                                 (void *) &cmd_setbonding_mode_bonding,
5937                                 (void *) &cmd_setbonding_mode_mode,
5938                                 (void *) &cmd_setbonding_mode_value,
5939                                 (void *) &cmd_setbonding_mode_port,
5940                                 NULL
5941                 }
5942 };
5943
5944 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5945 struct cmd_set_bonding_lacp_dedicated_queues_result {
5946         cmdline_fixed_string_t set;
5947         cmdline_fixed_string_t bonding;
5948         cmdline_fixed_string_t lacp;
5949         cmdline_fixed_string_t dedicated_queues;
5950         portid_t port_id;
5951         cmdline_fixed_string_t mode;
5952 };
5953
5954 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5955                 __rte_unused  struct cmdline *cl,
5956                 __rte_unused void *data)
5957 {
5958         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5959         portid_t port_id = res->port_id;
5960         struct rte_port *port;
5961
5962         port = &ports[port_id];
5963
5964         /** Check if the port is not started **/
5965         if (port->port_status != RTE_PORT_STOPPED) {
5966                 fprintf(stderr, "Please stop port %d first\n", port_id);
5967                 return;
5968         }
5969
5970         if (!strcmp(res->mode, "enable")) {
5971                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5972                         printf("Dedicate queues for LACP control packets"
5973                                         " enabled\n");
5974                 else
5975                         printf("Enabling dedicate queues for LACP control "
5976                                         "packets on port %d failed\n", port_id);
5977         } else if (!strcmp(res->mode, "disable")) {
5978                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5979                         printf("Dedicated queues for LACP control packets "
5980                                         "disabled\n");
5981                 else
5982                         printf("Disabling dedicated queues for LACP control "
5983                                         "traffic on port %d failed\n", port_id);
5984         }
5985 }
5986
5987 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5988 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5989                 set, "set");
5990 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5991 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5992                 bonding, "bonding");
5993 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5994 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5995                 lacp, "lacp");
5996 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5997 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5998                 dedicated_queues, "dedicated_queues");
5999 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6000 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6001                 port_id, RTE_UINT16);
6002 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6003 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6004                 mode, "enable#disable");
6005
6006 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6007                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6008                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6009                         "enable|disable: "
6010                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6011                 .data = NULL,
6012                 .tokens = {
6013                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6014                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6015                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6016                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6017                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6018                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6019                         NULL
6020                 }
6021 };
6022
6023 /* *** SET BALANCE XMIT POLICY *** */
6024 struct cmd_set_bonding_balance_xmit_policy_result {
6025         cmdline_fixed_string_t set;
6026         cmdline_fixed_string_t bonding;
6027         cmdline_fixed_string_t balance_xmit_policy;
6028         portid_t port_id;
6029         cmdline_fixed_string_t policy;
6030 };
6031
6032 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6033                 __rte_unused  struct cmdline *cl,
6034                 __rte_unused void *data)
6035 {
6036         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6037         portid_t port_id = res->port_id;
6038         uint8_t policy;
6039
6040         if (!strcmp(res->policy, "l2")) {
6041                 policy = BALANCE_XMIT_POLICY_LAYER2;
6042         } else if (!strcmp(res->policy, "l23")) {
6043                 policy = BALANCE_XMIT_POLICY_LAYER23;
6044         } else if (!strcmp(res->policy, "l34")) {
6045                 policy = BALANCE_XMIT_POLICY_LAYER34;
6046         } else {
6047                 fprintf(stderr, "\t Invalid xmit policy selection");
6048                 return;
6049         }
6050
6051         /* Set the bonding mode for the relevant port. */
6052         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6053                 fprintf(stderr,
6054                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6055                         port_id);
6056         }
6057 }
6058
6059 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6060 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6061                 set, "set");
6062 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6063 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6064                 bonding, "bonding");
6065 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6066 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6067                 balance_xmit_policy, "balance_xmit_policy");
6068 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6069 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6070                 port_id, RTE_UINT16);
6071 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6072 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6073                 policy, "l2#l23#l34");
6074
6075 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6076                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6077                 .help_str = "set bonding balance_xmit_policy <port_id> "
6078                         "l2|l23|l34: "
6079                         "Set the bonding balance_xmit_policy for port_id",
6080                 .data = NULL,
6081                 .tokens = {
6082                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6083                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6084                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6085                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6086                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6087                                 NULL
6088                 }
6089 };
6090
6091 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6092 struct cmd_show_bonding_lacp_info_result {
6093         cmdline_fixed_string_t show;
6094         cmdline_fixed_string_t bonding;
6095         cmdline_fixed_string_t lacp;
6096         cmdline_fixed_string_t info;
6097         portid_t port_id;
6098 };
6099
6100 static void port_param_show(struct port_params *params)
6101 {
6102         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6103
6104         printf("\t\tsystem priority: %u\n", params->system_priority);
6105         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6106         printf("\t\tsystem mac address: %s\n", buf);
6107         printf("\t\tport key: %u\n", params->key);
6108         printf("\t\tport priority: %u\n", params->port_priority);
6109         printf("\t\tport number: %u\n", params->port_number);
6110 }
6111
6112 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6113 {
6114         char a_state[256] = { 0 };
6115         char p_state[256] = { 0 };
6116         int a_len = 0;
6117         int p_len = 0;
6118         uint32_t i;
6119
6120         static const char * const state[] = {
6121                 "ACTIVE",
6122                 "TIMEOUT",
6123                 "AGGREGATION",
6124                 "SYNCHRONIZATION",
6125                 "COLLECTING",
6126                 "DISTRIBUTING",
6127                 "DEFAULTED",
6128                 "EXPIRED"
6129         };
6130         static const char * const selection[] = {
6131                 "UNSELECTED",
6132                 "STANDBY",
6133                 "SELECTED"
6134         };
6135
6136         for (i = 0; i < RTE_DIM(state); i++) {
6137                 if ((info->actor_state >> i) & 1)
6138                         a_len += snprintf(&a_state[a_len],
6139                                                 RTE_DIM(a_state) - a_len, "%s ",
6140                                                 state[i]);
6141
6142                 if ((info->partner_state >> i) & 1)
6143                         p_len += snprintf(&p_state[p_len],
6144                                                 RTE_DIM(p_state) - p_len, "%s ",
6145                                                 state[i]);
6146         }
6147         printf("\tAggregator port id: %u\n", info->agg_port_id);
6148         printf("\tselection: %s\n", selection[info->selected]);
6149         printf("\tActor detail info:\n");
6150         port_param_show(&info->actor);
6151         printf("\t\tport state: %s\n", a_state);
6152         printf("\tPartner detail info:\n");
6153         port_param_show(&info->partner);
6154         printf("\t\tport state: %s\n", p_state);
6155         printf("\n");
6156 }
6157
6158 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6159 {
6160         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6161         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6162         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6163         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6164         printf("\taggregate wait timeout: %u ms\n",
6165                         conf->aggregate_wait_timeout_ms);
6166         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6167         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6168         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6169         switch (conf->agg_selection) {
6170         case AGG_BANDWIDTH:
6171                 printf("\taggregation mode: bandwidth\n");
6172                 break;
6173         case AGG_STABLE:
6174                 printf("\taggregation mode: stable\n");
6175                 break;
6176         case AGG_COUNT:
6177                 printf("\taggregation mode: count\n");
6178                 break;
6179         default:
6180                 printf("\taggregation mode: invalid\n");
6181                 break;
6182         }
6183
6184         printf("\n");
6185 }
6186
6187 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6188                 __rte_unused  struct cmdline *cl,
6189                 __rte_unused void *data)
6190 {
6191         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6192         struct rte_eth_bond_8023ad_slave_info slave_info;
6193         struct rte_eth_bond_8023ad_conf port_conf;
6194         portid_t slaves[RTE_MAX_ETHPORTS];
6195         portid_t port_id = res->port_id;
6196         int num_active_slaves;
6197         int bonding_mode;
6198         int i;
6199         int ret;
6200
6201         bonding_mode = rte_eth_bond_mode_get(port_id);
6202         if (bonding_mode != BONDING_MODE_8023AD) {
6203                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6204                 return;
6205         }
6206
6207         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6208                         RTE_MAX_ETHPORTS);
6209         if (num_active_slaves < 0) {
6210                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6211                                 port_id);
6212                 return;
6213         }
6214         if (num_active_slaves == 0)
6215                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6216                         port_id);
6217
6218         printf("\tIEEE802.3 port: %u\n", port_id);
6219         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6220         if (ret) {
6221                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6222                         port_id);
6223                 return;
6224         }
6225         lacp_conf_show(&port_conf);
6226
6227         for (i = 0; i < num_active_slaves; i++) {
6228                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6229                                 &slave_info);
6230                 if (ret) {
6231                         fprintf(stderr, "\tGet slave device %u info failed\n",
6232                                 slaves[i]);
6233                         return;
6234                 }
6235                 printf("\tSlave Port: %u\n", slaves[i]);
6236                 lacp_slave_info_show(&slave_info);
6237         }
6238 }
6239
6240 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6241 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6242                 show, "show");
6243 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6244 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6245                 bonding, "bonding");
6246 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6247 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6248                 bonding, "lacp");
6249 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6250 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6251                 info, "info");
6252 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6253 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6254                 port_id, RTE_UINT16);
6255
6256 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6257                 .f = cmd_show_bonding_lacp_info_parsed,
6258                 .help_str = "show bonding lacp info <port_id> : "
6259                         "Show bonding IEEE802.3 information for port_id",
6260                 .data = NULL,
6261                 .tokens = {
6262                         (void *)&cmd_show_bonding_lacp_info_show,
6263                         (void *)&cmd_show_bonding_lacp_info_bonding,
6264                         (void *)&cmd_show_bonding_lacp_info_lacp,
6265                         (void *)&cmd_show_bonding_lacp_info_info,
6266                         (void *)&cmd_show_bonding_lacp_info_port_id,
6267                         NULL
6268                 }
6269 };
6270
6271 /* *** SHOW NIC BONDING CONFIGURATION *** */
6272 struct cmd_show_bonding_config_result {
6273         cmdline_fixed_string_t show;
6274         cmdline_fixed_string_t bonding;
6275         cmdline_fixed_string_t config;
6276         portid_t port_id;
6277 };
6278
6279 static void cmd_show_bonding_config_parsed(void *parsed_result,
6280                 __rte_unused  struct cmdline *cl,
6281                 __rte_unused void *data)
6282 {
6283         struct cmd_show_bonding_config_result *res = parsed_result;
6284         int bonding_mode, agg_mode;
6285         portid_t slaves[RTE_MAX_ETHPORTS];
6286         int num_slaves, num_active_slaves;
6287         int primary_id;
6288         int i;
6289         portid_t port_id = res->port_id;
6290
6291         /* Display the bonding mode.*/
6292         bonding_mode = rte_eth_bond_mode_get(port_id);
6293         if (bonding_mode < 0) {
6294                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6295                         port_id);
6296                 return;
6297         } else
6298                 printf("\tBonding mode: %d\n", bonding_mode);
6299
6300         if (bonding_mode == BONDING_MODE_BALANCE) {
6301                 int balance_xmit_policy;
6302
6303                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6304                 if (balance_xmit_policy < 0) {
6305                         fprintf(stderr,
6306                                 "\tFailed to get balance xmit policy for port = %d\n",
6307                                 port_id);
6308                         return;
6309                 } else {
6310                         printf("\tBalance Xmit Policy: ");
6311
6312                         switch (balance_xmit_policy) {
6313                         case BALANCE_XMIT_POLICY_LAYER2:
6314                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6315                                 break;
6316                         case BALANCE_XMIT_POLICY_LAYER23:
6317                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6318                                 break;
6319                         case BALANCE_XMIT_POLICY_LAYER34:
6320                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6321                                 break;
6322                         }
6323                         printf("\n");
6324                 }
6325         }
6326
6327         if (bonding_mode == BONDING_MODE_8023AD) {
6328                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6329                 printf("\tIEEE802.3AD Aggregator Mode: ");
6330                 switch (agg_mode) {
6331                 case AGG_BANDWIDTH:
6332                         printf("bandwidth");
6333                         break;
6334                 case AGG_STABLE:
6335                         printf("stable");
6336                         break;
6337                 case AGG_COUNT:
6338                         printf("count");
6339                         break;
6340                 }
6341                 printf("\n");
6342         }
6343
6344         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6345
6346         if (num_slaves < 0) {
6347                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6348                         port_id);
6349                 return;
6350         }
6351         if (num_slaves > 0) {
6352                 printf("\tSlaves (%d): [", num_slaves);
6353                 for (i = 0; i < num_slaves - 1; i++)
6354                         printf("%d ", slaves[i]);
6355
6356                 printf("%d]\n", slaves[num_slaves - 1]);
6357         } else {
6358                 printf("\tSlaves: []\n");
6359
6360         }
6361
6362         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6363                         RTE_MAX_ETHPORTS);
6364
6365         if (num_active_slaves < 0) {
6366                 fprintf(stderr,
6367                         "\tFailed to get active slave list for port = %d\n",
6368                         port_id);
6369                 return;
6370         }
6371         if (num_active_slaves > 0) {
6372                 printf("\tActive Slaves (%d): [", num_active_slaves);
6373                 for (i = 0; i < num_active_slaves - 1; i++)
6374                         printf("%d ", slaves[i]);
6375
6376                 printf("%d]\n", slaves[num_active_slaves - 1]);
6377
6378         } else {
6379                 printf("\tActive Slaves: []\n");
6380
6381         }
6382
6383         primary_id = rte_eth_bond_primary_get(port_id);
6384         if (primary_id < 0) {
6385                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6386                         port_id);
6387                 return;
6388         } else
6389                 printf("\tPrimary: [%d]\n", primary_id);
6390
6391 }
6392
6393 cmdline_parse_token_string_t cmd_showbonding_config_show =
6394 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6395                 show, "show");
6396 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6397 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6398                 bonding, "bonding");
6399 cmdline_parse_token_string_t cmd_showbonding_config_config =
6400 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6401                 config, "config");
6402 cmdline_parse_token_num_t cmd_showbonding_config_port =
6403 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6404                 port_id, RTE_UINT16);
6405
6406 cmdline_parse_inst_t cmd_show_bonding_config = {
6407                 .f = cmd_show_bonding_config_parsed,
6408                 .help_str = "show bonding config <port_id>: "
6409                         "Show the bonding config for port_id",
6410                 .data = NULL,
6411                 .tokens = {
6412                                 (void *)&cmd_showbonding_config_show,
6413                                 (void *)&cmd_showbonding_config_bonding,
6414                                 (void *)&cmd_showbonding_config_config,
6415                                 (void *)&cmd_showbonding_config_port,
6416                                 NULL
6417                 }
6418 };
6419
6420 /* *** SET BONDING PRIMARY *** */
6421 struct cmd_set_bonding_primary_result {
6422         cmdline_fixed_string_t set;
6423         cmdline_fixed_string_t bonding;
6424         cmdline_fixed_string_t primary;
6425         portid_t slave_id;
6426         portid_t port_id;
6427 };
6428
6429 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6430                 __rte_unused  struct cmdline *cl,
6431                 __rte_unused void *data)
6432 {
6433         struct cmd_set_bonding_primary_result *res = parsed_result;
6434         portid_t master_port_id = res->port_id;
6435         portid_t slave_port_id = res->slave_id;
6436
6437         /* Set the primary slave for a bonded device. */
6438         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6439                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6440                         master_port_id);
6441                 return;
6442         }
6443         init_port_config();
6444 }
6445
6446 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6447 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6448                 set, "set");
6449 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6450 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6451                 bonding, "bonding");
6452 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6453 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6454                 primary, "primary");
6455 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6456 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6457                 slave_id, RTE_UINT16);
6458 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6459 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6460                 port_id, RTE_UINT16);
6461
6462 cmdline_parse_inst_t cmd_set_bonding_primary = {
6463                 .f = cmd_set_bonding_primary_parsed,
6464                 .help_str = "set bonding primary <slave_id> <port_id>: "
6465                         "Set the primary slave for port_id",
6466                 .data = NULL,
6467                 .tokens = {
6468                                 (void *)&cmd_setbonding_primary_set,
6469                                 (void *)&cmd_setbonding_primary_bonding,
6470                                 (void *)&cmd_setbonding_primary_primary,
6471                                 (void *)&cmd_setbonding_primary_slave,
6472                                 (void *)&cmd_setbonding_primary_port,
6473                                 NULL
6474                 }
6475 };
6476
6477 /* *** ADD SLAVE *** */
6478 struct cmd_add_bonding_slave_result {
6479         cmdline_fixed_string_t add;
6480         cmdline_fixed_string_t bonding;
6481         cmdline_fixed_string_t slave;
6482         portid_t slave_id;
6483         portid_t port_id;
6484 };
6485
6486 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6487                 __rte_unused  struct cmdline *cl,
6488                 __rte_unused void *data)
6489 {
6490         struct cmd_add_bonding_slave_result *res = parsed_result;
6491         portid_t master_port_id = res->port_id;
6492         portid_t slave_port_id = res->slave_id;
6493
6494         /* add the slave for a bonded device. */
6495         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6496                 fprintf(stderr,
6497                         "\t Failed to add slave %d to master port = %d.\n",
6498                         slave_port_id, master_port_id);
6499                 return;
6500         }
6501         init_port_config();
6502         set_port_slave_flag(slave_port_id);
6503 }
6504
6505 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6506 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6507                 add, "add");
6508 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6509 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6510                 bonding, "bonding");
6511 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6512 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6513                 slave, "slave");
6514 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6515 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6516                 slave_id, RTE_UINT16);
6517 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6518 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6519                 port_id, RTE_UINT16);
6520
6521 cmdline_parse_inst_t cmd_add_bonding_slave = {
6522                 .f = cmd_add_bonding_slave_parsed,
6523                 .help_str = "add bonding slave <slave_id> <port_id>: "
6524                         "Add a slave device to a bonded device",
6525                 .data = NULL,
6526                 .tokens = {
6527                                 (void *)&cmd_addbonding_slave_add,
6528                                 (void *)&cmd_addbonding_slave_bonding,
6529                                 (void *)&cmd_addbonding_slave_slave,
6530                                 (void *)&cmd_addbonding_slave_slaveid,
6531                                 (void *)&cmd_addbonding_slave_port,
6532                                 NULL
6533                 }
6534 };
6535
6536 /* *** REMOVE SLAVE *** */
6537 struct cmd_remove_bonding_slave_result {
6538         cmdline_fixed_string_t remove;
6539         cmdline_fixed_string_t bonding;
6540         cmdline_fixed_string_t slave;
6541         portid_t slave_id;
6542         portid_t port_id;
6543 };
6544
6545 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6546                 __rte_unused  struct cmdline *cl,
6547                 __rte_unused void *data)
6548 {
6549         struct cmd_remove_bonding_slave_result *res = parsed_result;
6550         portid_t master_port_id = res->port_id;
6551         portid_t slave_port_id = res->slave_id;
6552
6553         /* remove the slave from a bonded device. */
6554         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6555                 fprintf(stderr,
6556                         "\t Failed to remove slave %d from master port = %d.\n",
6557                         slave_port_id, master_port_id);
6558                 return;
6559         }
6560         init_port_config();
6561         clear_port_slave_flag(slave_port_id);
6562 }
6563
6564 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6565                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6566                                 remove, "remove");
6567 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6568                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6569                                 bonding, "bonding");
6570 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6571                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6572                                 slave, "slave");
6573 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6574                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6575                                 slave_id, RTE_UINT16);
6576 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6577                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6578                                 port_id, RTE_UINT16);
6579
6580 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6581                 .f = cmd_remove_bonding_slave_parsed,
6582                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6583                         "Remove a slave device from a bonded device",
6584                 .data = NULL,
6585                 .tokens = {
6586                                 (void *)&cmd_removebonding_slave_remove,
6587                                 (void *)&cmd_removebonding_slave_bonding,
6588                                 (void *)&cmd_removebonding_slave_slave,
6589                                 (void *)&cmd_removebonding_slave_slaveid,
6590                                 (void *)&cmd_removebonding_slave_port,
6591                                 NULL
6592                 }
6593 };
6594
6595 /* *** CREATE BONDED DEVICE *** */
6596 struct cmd_create_bonded_device_result {
6597         cmdline_fixed_string_t create;
6598         cmdline_fixed_string_t bonded;
6599         cmdline_fixed_string_t device;
6600         uint8_t mode;
6601         uint8_t socket;
6602 };
6603
6604 static int bond_dev_num = 0;
6605
6606 static void cmd_create_bonded_device_parsed(void *parsed_result,
6607                 __rte_unused  struct cmdline *cl,
6608                 __rte_unused void *data)
6609 {
6610         struct cmd_create_bonded_device_result *res = parsed_result;
6611         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6612         int port_id;
6613         int ret;
6614
6615         if (test_done == 0) {
6616                 fprintf(stderr, "Please stop forwarding first\n");
6617                 return;
6618         }
6619
6620         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6621                         bond_dev_num++);
6622
6623         /* Create a new bonded device. */
6624         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6625         if (port_id < 0) {
6626                 fprintf(stderr, "\t Failed to create bonded device.\n");
6627                 return;
6628         } else {
6629                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6630                                 port_id);
6631
6632                 /* Update number of ports */
6633                 nb_ports = rte_eth_dev_count_avail();
6634                 reconfig(port_id, res->socket);
6635                 ret = rte_eth_promiscuous_enable(port_id);
6636                 if (ret != 0)
6637                         fprintf(stderr,
6638                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6639                                 port_id, rte_strerror(-ret));
6640
6641                 ports[port_id].need_setup = 0;
6642                 ports[port_id].port_status = RTE_PORT_STOPPED;
6643         }
6644
6645 }
6646
6647 cmdline_parse_token_string_t cmd_createbonded_device_create =
6648                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6649                                 create, "create");
6650 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6651                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6652                                 bonded, "bonded");
6653 cmdline_parse_token_string_t cmd_createbonded_device_device =
6654                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6655                                 device, "device");
6656 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6657                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6658                                 mode, RTE_UINT8);
6659 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6660                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6661                                 socket, RTE_UINT8);
6662
6663 cmdline_parse_inst_t cmd_create_bonded_device = {
6664                 .f = cmd_create_bonded_device_parsed,
6665                 .help_str = "create bonded device <mode> <socket>: "
6666                         "Create a new bonded device with specific bonding mode and socket",
6667                 .data = NULL,
6668                 .tokens = {
6669                                 (void *)&cmd_createbonded_device_create,
6670                                 (void *)&cmd_createbonded_device_bonded,
6671                                 (void *)&cmd_createbonded_device_device,
6672                                 (void *)&cmd_createbonded_device_mode,
6673                                 (void *)&cmd_createbonded_device_socket,
6674                                 NULL
6675                 }
6676 };
6677
6678 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6679 struct cmd_set_bond_mac_addr_result {
6680         cmdline_fixed_string_t set;
6681         cmdline_fixed_string_t bonding;
6682         cmdline_fixed_string_t mac_addr;
6683         uint16_t port_num;
6684         struct rte_ether_addr address;
6685 };
6686
6687 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6688                 __rte_unused  struct cmdline *cl,
6689                 __rte_unused void *data)
6690 {
6691         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6692         int ret;
6693
6694         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6695                 return;
6696
6697         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6698
6699         /* check the return value and print it if is < 0 */
6700         if (ret < 0)
6701                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6702                         strerror(-ret));
6703 }
6704
6705 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6706                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6707 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6708                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6709                                 "bonding");
6710 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6711                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6712                                 "mac_addr");
6713 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6714                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6715                                 port_num, RTE_UINT16);
6716 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6717                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6718
6719 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6720                 .f = cmd_set_bond_mac_addr_parsed,
6721                 .data = (void *) 0,
6722                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6723                 .tokens = {
6724                                 (void *)&cmd_set_bond_mac_addr_set,
6725                                 (void *)&cmd_set_bond_mac_addr_bonding,
6726                                 (void *)&cmd_set_bond_mac_addr_mac,
6727                                 (void *)&cmd_set_bond_mac_addr_portnum,
6728                                 (void *)&cmd_set_bond_mac_addr_addr,
6729                                 NULL
6730                 }
6731 };
6732
6733
6734 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6735 struct cmd_set_bond_mon_period_result {
6736         cmdline_fixed_string_t set;
6737         cmdline_fixed_string_t bonding;
6738         cmdline_fixed_string_t mon_period;
6739         uint16_t port_num;
6740         uint32_t period_ms;
6741 };
6742
6743 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6744                 __rte_unused  struct cmdline *cl,
6745                 __rte_unused void *data)
6746 {
6747         struct cmd_set_bond_mon_period_result *res = parsed_result;
6748         int ret;
6749
6750         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6751
6752         /* check the return value and print it if is < 0 */
6753         if (ret < 0)
6754                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6755                         strerror(-ret));
6756 }
6757
6758 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6759                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6760                                 set, "set");
6761 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6762                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6763                                 bonding, "bonding");
6764 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6765                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6766                                 mon_period,     "mon_period");
6767 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6768                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6769                                 port_num, RTE_UINT16);
6770 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6771                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6772                                 period_ms, RTE_UINT32);
6773
6774 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6775                 .f = cmd_set_bond_mon_period_parsed,
6776                 .data = (void *) 0,
6777                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6778                 .tokens = {
6779                                 (void *)&cmd_set_bond_mon_period_set,
6780                                 (void *)&cmd_set_bond_mon_period_bonding,
6781                                 (void *)&cmd_set_bond_mon_period_mon_period,
6782                                 (void *)&cmd_set_bond_mon_period_portnum,
6783                                 (void *)&cmd_set_bond_mon_period_period_ms,
6784                                 NULL
6785                 }
6786 };
6787
6788
6789
6790 struct cmd_set_bonding_agg_mode_policy_result {
6791         cmdline_fixed_string_t set;
6792         cmdline_fixed_string_t bonding;
6793         cmdline_fixed_string_t agg_mode;
6794         uint16_t port_num;
6795         cmdline_fixed_string_t policy;
6796 };
6797
6798
6799 static void
6800 cmd_set_bonding_agg_mode(void *parsed_result,
6801                 __rte_unused struct cmdline *cl,
6802                 __rte_unused void *data)
6803 {
6804         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6805         uint8_t policy = AGG_BANDWIDTH;
6806
6807         if (!strcmp(res->policy, "bandwidth"))
6808                 policy = AGG_BANDWIDTH;
6809         else if (!strcmp(res->policy, "stable"))
6810                 policy = AGG_STABLE;
6811         else if (!strcmp(res->policy, "count"))
6812                 policy = AGG_COUNT;
6813
6814         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6815 }
6816
6817
6818 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6819         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6820                                 set, "set");
6821 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6822         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6823                                 bonding, "bonding");
6824
6825 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6826         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6827                                 agg_mode, "agg_mode");
6828
6829 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6830         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6831                                 port_num, RTE_UINT16);
6832
6833 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6834         TOKEN_STRING_INITIALIZER(
6835                         struct cmd_set_bonding_balance_xmit_policy_result,
6836                 policy, "stable#bandwidth#count");
6837
6838 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6839         .f = cmd_set_bonding_agg_mode,
6840         .data = (void *) 0,
6841         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6842         .tokens = {
6843                         (void *)&cmd_set_bonding_agg_mode_set,
6844                         (void *)&cmd_set_bonding_agg_mode_bonding,
6845                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6846                         (void *)&cmd_set_bonding_agg_mode_portnum,
6847                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6848                         NULL
6849                 }
6850 };
6851
6852
6853 #endif /* RTE_NET_BOND */
6854
6855 /* *** SET FORWARDING MODE *** */
6856 struct cmd_set_fwd_mode_result {
6857         cmdline_fixed_string_t set;
6858         cmdline_fixed_string_t fwd;
6859         cmdline_fixed_string_t mode;
6860 };
6861
6862 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6863                                     __rte_unused struct cmdline *cl,
6864                                     __rte_unused void *data)
6865 {
6866         struct cmd_set_fwd_mode_result *res = parsed_result;
6867
6868         retry_enabled = 0;
6869         set_pkt_forwarding_mode(res->mode);
6870 }
6871
6872 cmdline_parse_token_string_t cmd_setfwd_set =
6873         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6874 cmdline_parse_token_string_t cmd_setfwd_fwd =
6875         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6876 cmdline_parse_token_string_t cmd_setfwd_mode =
6877         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6878                 "" /* defined at init */);
6879
6880 cmdline_parse_inst_t cmd_set_fwd_mode = {
6881         .f = cmd_set_fwd_mode_parsed,
6882         .data = NULL,
6883         .help_str = NULL, /* defined at init */
6884         .tokens = {
6885                 (void *)&cmd_setfwd_set,
6886                 (void *)&cmd_setfwd_fwd,
6887                 (void *)&cmd_setfwd_mode,
6888                 NULL,
6889         },
6890 };
6891
6892 static void cmd_set_fwd_mode_init(void)
6893 {
6894         char *modes, *c;
6895         static char token[128];
6896         static char help[256];
6897         cmdline_parse_token_string_t *token_struct;
6898
6899         modes = list_pkt_forwarding_modes();
6900         snprintf(help, sizeof(help), "set fwd %s: "
6901                 "Set packet forwarding mode", modes);
6902         cmd_set_fwd_mode.help_str = help;
6903
6904         /* string token separator is # */
6905         for (c = token; *modes != '\0'; modes++)
6906                 if (*modes == '|')
6907                         *c++ = '#';
6908                 else
6909                         *c++ = *modes;
6910         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6911         token_struct->string_data.str = token;
6912 }
6913
6914 /* *** SET RETRY FORWARDING MODE *** */
6915 struct cmd_set_fwd_retry_mode_result {
6916         cmdline_fixed_string_t set;
6917         cmdline_fixed_string_t fwd;
6918         cmdline_fixed_string_t mode;
6919         cmdline_fixed_string_t retry;
6920 };
6921
6922 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6923                             __rte_unused struct cmdline *cl,
6924                             __rte_unused void *data)
6925 {
6926         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6927
6928         retry_enabled = 1;
6929         set_pkt_forwarding_mode(res->mode);
6930 }
6931
6932 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6933         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6934                         set, "set");
6935 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6936         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6937                         fwd, "fwd");
6938 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6939         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6940                         mode,
6941                 "" /* defined at init */);
6942 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6943         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6944                         retry, "retry");
6945
6946 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6947         .f = cmd_set_fwd_retry_mode_parsed,
6948         .data = NULL,
6949         .help_str = NULL, /* defined at init */
6950         .tokens = {
6951                 (void *)&cmd_setfwd_retry_set,
6952                 (void *)&cmd_setfwd_retry_fwd,
6953                 (void *)&cmd_setfwd_retry_mode,
6954                 (void *)&cmd_setfwd_retry_retry,
6955                 NULL,
6956         },
6957 };
6958
6959 static void cmd_set_fwd_retry_mode_init(void)
6960 {
6961         char *modes, *c;
6962         static char token[128];
6963         static char help[256];
6964         cmdline_parse_token_string_t *token_struct;
6965
6966         modes = list_pkt_forwarding_retry_modes();
6967         snprintf(help, sizeof(help), "set fwd %s retry: "
6968                 "Set packet forwarding mode with retry", modes);
6969         cmd_set_fwd_retry_mode.help_str = help;
6970
6971         /* string token separator is # */
6972         for (c = token; *modes != '\0'; modes++)
6973                 if (*modes == '|')
6974                         *c++ = '#';
6975                 else
6976                         *c++ = *modes;
6977         token_struct = (cmdline_parse_token_string_t *)
6978                 cmd_set_fwd_retry_mode.tokens[2];
6979         token_struct->string_data.str = token;
6980 }
6981
6982 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6983 struct cmd_set_burst_tx_retry_result {
6984         cmdline_fixed_string_t set;
6985         cmdline_fixed_string_t burst;
6986         cmdline_fixed_string_t tx;
6987         cmdline_fixed_string_t delay;
6988         uint32_t time;
6989         cmdline_fixed_string_t retry;
6990         uint32_t retry_num;
6991 };
6992
6993 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6994                                         __rte_unused struct cmdline *cl,
6995                                         __rte_unused void *data)
6996 {
6997         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6998
6999         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7000                 && !strcmp(res->tx, "tx")) {
7001                 if (!strcmp(res->delay, "delay"))
7002                         burst_tx_delay_time = res->time;
7003                 if (!strcmp(res->retry, "retry"))
7004                         burst_tx_retry_num = res->retry_num;
7005         }
7006
7007 }
7008
7009 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7010         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7011 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7012         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7013                                  "burst");
7014 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7015         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7016 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7017         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7018 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7019         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7020                                  RTE_UINT32);
7021 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7022         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7023 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7024         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7025                                  RTE_UINT32);
7026
7027 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7028         .f = cmd_set_burst_tx_retry_parsed,
7029         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7030         .tokens = {
7031                 (void *)&cmd_set_burst_tx_retry_set,
7032                 (void *)&cmd_set_burst_tx_retry_burst,
7033                 (void *)&cmd_set_burst_tx_retry_tx,
7034                 (void *)&cmd_set_burst_tx_retry_delay,
7035                 (void *)&cmd_set_burst_tx_retry_time,
7036                 (void *)&cmd_set_burst_tx_retry_retry,
7037                 (void *)&cmd_set_burst_tx_retry_retry_num,
7038                 NULL,
7039         },
7040 };
7041
7042 /* *** SET PROMISC MODE *** */
7043 struct cmd_set_promisc_mode_result {
7044         cmdline_fixed_string_t set;
7045         cmdline_fixed_string_t promisc;
7046         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7047         uint16_t port_num;               /* valid if "allports" argument == 0 */
7048         cmdline_fixed_string_t mode;
7049 };
7050
7051 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7052                                         __rte_unused struct cmdline *cl,
7053                                         void *allports)
7054 {
7055         struct cmd_set_promisc_mode_result *res = parsed_result;
7056         int enable;
7057         portid_t i;
7058
7059         if (!strcmp(res->mode, "on"))
7060                 enable = 1;
7061         else
7062                 enable = 0;
7063
7064         /* all ports */
7065         if (allports) {
7066                 RTE_ETH_FOREACH_DEV(i)
7067                         eth_set_promisc_mode(i, enable);
7068         } else {
7069                 eth_set_promisc_mode(res->port_num, enable);
7070         }
7071 }
7072
7073 cmdline_parse_token_string_t cmd_setpromisc_set =
7074         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7075 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7076         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7077                                  "promisc");
7078 cmdline_parse_token_string_t cmd_setpromisc_portall =
7079         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7080                                  "all");
7081 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7082         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7083                               RTE_UINT16);
7084 cmdline_parse_token_string_t cmd_setpromisc_mode =
7085         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7086                                  "on#off");
7087
7088 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7089         .f = cmd_set_promisc_mode_parsed,
7090         .data = (void *)1,
7091         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7092         .tokens = {
7093                 (void *)&cmd_setpromisc_set,
7094                 (void *)&cmd_setpromisc_promisc,
7095                 (void *)&cmd_setpromisc_portall,
7096                 (void *)&cmd_setpromisc_mode,
7097                 NULL,
7098         },
7099 };
7100
7101 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7102         .f = cmd_set_promisc_mode_parsed,
7103         .data = (void *)0,
7104         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7105         .tokens = {
7106                 (void *)&cmd_setpromisc_set,
7107                 (void *)&cmd_setpromisc_promisc,
7108                 (void *)&cmd_setpromisc_portnum,
7109                 (void *)&cmd_setpromisc_mode,
7110                 NULL,
7111         },
7112 };
7113
7114 /* *** SET ALLMULTI MODE *** */
7115 struct cmd_set_allmulti_mode_result {
7116         cmdline_fixed_string_t set;
7117         cmdline_fixed_string_t allmulti;
7118         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7119         uint16_t port_num;               /* valid if "allports" argument == 0 */
7120         cmdline_fixed_string_t mode;
7121 };
7122
7123 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7124                                         __rte_unused struct cmdline *cl,
7125                                         void *allports)
7126 {
7127         struct cmd_set_allmulti_mode_result *res = parsed_result;
7128         int enable;
7129         portid_t i;
7130
7131         if (!strcmp(res->mode, "on"))
7132                 enable = 1;
7133         else
7134                 enable = 0;
7135
7136         /* all ports */
7137         if (allports) {
7138                 RTE_ETH_FOREACH_DEV(i) {
7139                         eth_set_allmulticast_mode(i, enable);
7140                 }
7141         }
7142         else {
7143                 eth_set_allmulticast_mode(res->port_num, enable);
7144         }
7145 }
7146
7147 cmdline_parse_token_string_t cmd_setallmulti_set =
7148         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7149 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7150         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7151                                  "allmulti");
7152 cmdline_parse_token_string_t cmd_setallmulti_portall =
7153         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7154                                  "all");
7155 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7156         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7157                               RTE_UINT16);
7158 cmdline_parse_token_string_t cmd_setallmulti_mode =
7159         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7160                                  "on#off");
7161
7162 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7163         .f = cmd_set_allmulti_mode_parsed,
7164         .data = (void *)1,
7165         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7166         .tokens = {
7167                 (void *)&cmd_setallmulti_set,
7168                 (void *)&cmd_setallmulti_allmulti,
7169                 (void *)&cmd_setallmulti_portall,
7170                 (void *)&cmd_setallmulti_mode,
7171                 NULL,
7172         },
7173 };
7174
7175 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7176         .f = cmd_set_allmulti_mode_parsed,
7177         .data = (void *)0,
7178         .help_str = "set allmulti <port_id> on|off: "
7179                 "Set allmulti mode on port_id",
7180         .tokens = {
7181                 (void *)&cmd_setallmulti_set,
7182                 (void *)&cmd_setallmulti_allmulti,
7183                 (void *)&cmd_setallmulti_portnum,
7184                 (void *)&cmd_setallmulti_mode,
7185                 NULL,
7186         },
7187 };
7188
7189 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7190 struct cmd_link_flow_ctrl_show {
7191         cmdline_fixed_string_t show;
7192         cmdline_fixed_string_t port;
7193         portid_t port_id;
7194         cmdline_fixed_string_t flow_ctrl;
7195 };
7196
7197 cmdline_parse_token_string_t cmd_lfc_show_show =
7198         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7199                                 show, "show");
7200 cmdline_parse_token_string_t cmd_lfc_show_port =
7201         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7202                                 port, "port");
7203 cmdline_parse_token_num_t cmd_lfc_show_portid =
7204         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7205                                 port_id, RTE_UINT16);
7206 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7207         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7208                                 flow_ctrl, "flow_ctrl");
7209
7210 static void
7211 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7212                               __rte_unused struct cmdline *cl,
7213                               __rte_unused void *data)
7214 {
7215         struct cmd_link_flow_ctrl_show *res = parsed_result;
7216         static const char *info_border = "*********************";
7217         struct rte_eth_fc_conf fc_conf;
7218         bool rx_fc_en = false;
7219         bool tx_fc_en = false;
7220         int ret;
7221
7222         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7223         if (ret != 0) {
7224                 fprintf(stderr,
7225                         "Failed to get current flow ctrl information: err = %d\n",
7226                         ret);
7227                 return;
7228         }
7229
7230         if (fc_conf.mode == RTE_FC_RX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7231                 rx_fc_en = true;
7232         if (fc_conf.mode == RTE_FC_TX_PAUSE || fc_conf.mode == RTE_FC_FULL)
7233                 tx_fc_en = true;
7234
7235         printf("\n%s Flow control infos for port %-2d %s\n",
7236                 info_border, res->port_id, info_border);
7237         printf("FC mode:\n");
7238         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7239         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7240         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7241         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7242         printf("High waterline: 0x%x\n", fc_conf.high_water);
7243         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7244         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7245         printf("Forward MAC control frames: %s\n",
7246                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7247         printf("\n%s**************   End  ***********%s\n",
7248                 info_border, info_border);
7249 }
7250
7251 cmdline_parse_inst_t cmd_link_flow_control_show = {
7252         .f = cmd_link_flow_ctrl_show_parsed,
7253         .data = NULL,
7254         .help_str = "show port <port_id> flow_ctrl",
7255         .tokens = {
7256                 (void *)&cmd_lfc_show_show,
7257                 (void *)&cmd_lfc_show_port,
7258                 (void *)&cmd_lfc_show_portid,
7259                 (void *)&cmd_lfc_show_flow_ctrl,
7260                 NULL,
7261         },
7262 };
7263
7264 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7265 struct cmd_link_flow_ctrl_set_result {
7266         cmdline_fixed_string_t set;
7267         cmdline_fixed_string_t flow_ctrl;
7268         cmdline_fixed_string_t rx;
7269         cmdline_fixed_string_t rx_lfc_mode;
7270         cmdline_fixed_string_t tx;
7271         cmdline_fixed_string_t tx_lfc_mode;
7272         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7273         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7274         cmdline_fixed_string_t autoneg_str;
7275         cmdline_fixed_string_t autoneg;
7276         cmdline_fixed_string_t hw_str;
7277         uint32_t high_water;
7278         cmdline_fixed_string_t lw_str;
7279         uint32_t low_water;
7280         cmdline_fixed_string_t pt_str;
7281         uint16_t pause_time;
7282         cmdline_fixed_string_t xon_str;
7283         uint16_t send_xon;
7284         portid_t port_id;
7285 };
7286
7287 cmdline_parse_token_string_t cmd_lfc_set_set =
7288         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7289                                 set, "set");
7290 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7291         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7292                                 flow_ctrl, "flow_ctrl");
7293 cmdline_parse_token_string_t cmd_lfc_set_rx =
7294         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7295                                 rx, "rx");
7296 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7297         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7298                                 rx_lfc_mode, "on#off");
7299 cmdline_parse_token_string_t cmd_lfc_set_tx =
7300         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7301                                 tx, "tx");
7302 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7303         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7304                                 tx_lfc_mode, "on#off");
7305 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7306         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7307                                 hw_str, "high_water");
7308 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7309         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7310                                 high_water, RTE_UINT32);
7311 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7312         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7313                                 lw_str, "low_water");
7314 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7315         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7316                                 low_water, RTE_UINT32);
7317 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7318         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7319                                 pt_str, "pause_time");
7320 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7321         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7322                                 pause_time, RTE_UINT16);
7323 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7324         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7325                                 xon_str, "send_xon");
7326 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7327         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7328                                 send_xon, RTE_UINT16);
7329 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7330         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7331                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7332 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7333         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7334                                 mac_ctrl_frame_fwd_mode, "on#off");
7335 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7336         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7337                                 autoneg_str, "autoneg");
7338 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7339         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7340                                 autoneg, "on#off");
7341 cmdline_parse_token_num_t cmd_lfc_set_portid =
7342         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7343                                 port_id, RTE_UINT16);
7344
7345 /* forward declaration */
7346 static void
7347 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7348                               void *data);
7349
7350 cmdline_parse_inst_t cmd_link_flow_control_set = {
7351         .f = cmd_link_flow_ctrl_set_parsed,
7352         .data = NULL,
7353         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7354                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7355                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7356         .tokens = {
7357                 (void *)&cmd_lfc_set_set,
7358                 (void *)&cmd_lfc_set_flow_ctrl,
7359                 (void *)&cmd_lfc_set_rx,
7360                 (void *)&cmd_lfc_set_rx_mode,
7361                 (void *)&cmd_lfc_set_tx,
7362                 (void *)&cmd_lfc_set_tx_mode,
7363                 (void *)&cmd_lfc_set_high_water,
7364                 (void *)&cmd_lfc_set_low_water,
7365                 (void *)&cmd_lfc_set_pause_time,
7366                 (void *)&cmd_lfc_set_send_xon,
7367                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7368                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7369                 (void *)&cmd_lfc_set_autoneg_str,
7370                 (void *)&cmd_lfc_set_autoneg,
7371                 (void *)&cmd_lfc_set_portid,
7372                 NULL,
7373         },
7374 };
7375
7376 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7377         .f = cmd_link_flow_ctrl_set_parsed,
7378         .data = (void *)&cmd_link_flow_control_set_rx,
7379         .help_str = "set flow_ctrl rx on|off <port_id>: "
7380                 "Change rx flow control parameter",
7381         .tokens = {
7382                 (void *)&cmd_lfc_set_set,
7383                 (void *)&cmd_lfc_set_flow_ctrl,
7384                 (void *)&cmd_lfc_set_rx,
7385                 (void *)&cmd_lfc_set_rx_mode,
7386                 (void *)&cmd_lfc_set_portid,
7387                 NULL,
7388         },
7389 };
7390
7391 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7392         .f = cmd_link_flow_ctrl_set_parsed,
7393         .data = (void *)&cmd_link_flow_control_set_tx,
7394         .help_str = "set flow_ctrl tx on|off <port_id>: "
7395                 "Change tx flow control parameter",
7396         .tokens = {
7397                 (void *)&cmd_lfc_set_set,
7398                 (void *)&cmd_lfc_set_flow_ctrl,
7399                 (void *)&cmd_lfc_set_tx,
7400                 (void *)&cmd_lfc_set_tx_mode,
7401                 (void *)&cmd_lfc_set_portid,
7402                 NULL,
7403         },
7404 };
7405
7406 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7407         .f = cmd_link_flow_ctrl_set_parsed,
7408         .data = (void *)&cmd_link_flow_control_set_hw,
7409         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7410                 "Change high water flow control parameter",
7411         .tokens = {
7412                 (void *)&cmd_lfc_set_set,
7413                 (void *)&cmd_lfc_set_flow_ctrl,
7414                 (void *)&cmd_lfc_set_high_water_str,
7415                 (void *)&cmd_lfc_set_high_water,
7416                 (void *)&cmd_lfc_set_portid,
7417                 NULL,
7418         },
7419 };
7420
7421 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7422         .f = cmd_link_flow_ctrl_set_parsed,
7423         .data = (void *)&cmd_link_flow_control_set_lw,
7424         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7425                 "Change low water flow control parameter",
7426         .tokens = {
7427                 (void *)&cmd_lfc_set_set,
7428                 (void *)&cmd_lfc_set_flow_ctrl,
7429                 (void *)&cmd_lfc_set_low_water_str,
7430                 (void *)&cmd_lfc_set_low_water,
7431                 (void *)&cmd_lfc_set_portid,
7432                 NULL,
7433         },
7434 };
7435
7436 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7437         .f = cmd_link_flow_ctrl_set_parsed,
7438         .data = (void *)&cmd_link_flow_control_set_pt,
7439         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7440                 "Change pause time flow control parameter",
7441         .tokens = {
7442                 (void *)&cmd_lfc_set_set,
7443                 (void *)&cmd_lfc_set_flow_ctrl,
7444                 (void *)&cmd_lfc_set_pause_time_str,
7445                 (void *)&cmd_lfc_set_pause_time,
7446                 (void *)&cmd_lfc_set_portid,
7447                 NULL,
7448         },
7449 };
7450
7451 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7452         .f = cmd_link_flow_ctrl_set_parsed,
7453         .data = (void *)&cmd_link_flow_control_set_xon,
7454         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7455                 "Change send_xon flow control parameter",
7456         .tokens = {
7457                 (void *)&cmd_lfc_set_set,
7458                 (void *)&cmd_lfc_set_flow_ctrl,
7459                 (void *)&cmd_lfc_set_send_xon_str,
7460                 (void *)&cmd_lfc_set_send_xon,
7461                 (void *)&cmd_lfc_set_portid,
7462                 NULL,
7463         },
7464 };
7465
7466 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7467         .f = cmd_link_flow_ctrl_set_parsed,
7468         .data = (void *)&cmd_link_flow_control_set_macfwd,
7469         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7470                 "Change mac ctrl fwd flow control parameter",
7471         .tokens = {
7472                 (void *)&cmd_lfc_set_set,
7473                 (void *)&cmd_lfc_set_flow_ctrl,
7474                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7475                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7476                 (void *)&cmd_lfc_set_portid,
7477                 NULL,
7478         },
7479 };
7480
7481 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7482         .f = cmd_link_flow_ctrl_set_parsed,
7483         .data = (void *)&cmd_link_flow_control_set_autoneg,
7484         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7485                 "Change autoneg flow control parameter",
7486         .tokens = {
7487                 (void *)&cmd_lfc_set_set,
7488                 (void *)&cmd_lfc_set_flow_ctrl,
7489                 (void *)&cmd_lfc_set_autoneg_str,
7490                 (void *)&cmd_lfc_set_autoneg,
7491                 (void *)&cmd_lfc_set_portid,
7492                 NULL,
7493         },
7494 };
7495
7496 static void
7497 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7498                               __rte_unused struct cmdline *cl,
7499                               void *data)
7500 {
7501         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7502         cmdline_parse_inst_t *cmd = data;
7503         struct rte_eth_fc_conf fc_conf;
7504         int rx_fc_en = 0;
7505         int tx_fc_en = 0;
7506         int ret;
7507
7508         /*
7509          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7510          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7511          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7512          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7513          */
7514         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7515                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7516         };
7517
7518         /* Partial command line, retrieve current configuration */
7519         if (cmd) {
7520                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7521                 if (ret != 0) {
7522                         fprintf(stderr,
7523                                 "cannot get current flow ctrl parameters, return code = %d\n",
7524                                 ret);
7525                         return;
7526                 }
7527
7528                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7529                     (fc_conf.mode == RTE_FC_FULL))
7530                         rx_fc_en = 1;
7531                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7532                     (fc_conf.mode == RTE_FC_FULL))
7533                         tx_fc_en = 1;
7534         }
7535
7536         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7537                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7538
7539         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7540                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7541
7542         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7543
7544         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7545                 fc_conf.high_water = res->high_water;
7546
7547         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7548                 fc_conf.low_water = res->low_water;
7549
7550         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7551                 fc_conf.pause_time = res->pause_time;
7552
7553         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7554                 fc_conf.send_xon = res->send_xon;
7555
7556         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7557                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7558                         fc_conf.mac_ctrl_frame_fwd = 1;
7559                 else
7560                         fc_conf.mac_ctrl_frame_fwd = 0;
7561         }
7562
7563         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7564                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7565
7566         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7567         if (ret != 0)
7568                 fprintf(stderr,
7569                         "bad flow control parameter, return code = %d\n",
7570                         ret);
7571 }
7572
7573 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7574 struct cmd_priority_flow_ctrl_set_result {
7575         cmdline_fixed_string_t set;
7576         cmdline_fixed_string_t pfc_ctrl;
7577         cmdline_fixed_string_t rx;
7578         cmdline_fixed_string_t rx_pfc_mode;
7579         cmdline_fixed_string_t tx;
7580         cmdline_fixed_string_t tx_pfc_mode;
7581         uint32_t high_water;
7582         uint32_t low_water;
7583         uint16_t pause_time;
7584         uint8_t  priority;
7585         portid_t port_id;
7586 };
7587
7588 static void
7589 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7590                        __rte_unused struct cmdline *cl,
7591                        __rte_unused void *data)
7592 {
7593         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7594         struct rte_eth_pfc_conf pfc_conf;
7595         int rx_fc_enable, tx_fc_enable;
7596         int ret;
7597
7598         /*
7599          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7600          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7601          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7602          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7603          */
7604         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7605                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7606         };
7607
7608         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7609         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7610         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7611         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7612         pfc_conf.fc.high_water = res->high_water;
7613         pfc_conf.fc.low_water  = res->low_water;
7614         pfc_conf.fc.pause_time = res->pause_time;
7615         pfc_conf.priority      = res->priority;
7616
7617         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7618         if (ret != 0)
7619                 fprintf(stderr,
7620                         "bad priority flow control parameter, return code = %d\n",
7621                         ret);
7622 }
7623
7624 cmdline_parse_token_string_t cmd_pfc_set_set =
7625         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7626                                 set, "set");
7627 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7628         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7629                                 pfc_ctrl, "pfc_ctrl");
7630 cmdline_parse_token_string_t cmd_pfc_set_rx =
7631         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7632                                 rx, "rx");
7633 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7634         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7635                                 rx_pfc_mode, "on#off");
7636 cmdline_parse_token_string_t cmd_pfc_set_tx =
7637         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7638                                 tx, "tx");
7639 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7640         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7641                                 tx_pfc_mode, "on#off");
7642 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7643         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7644                                 high_water, RTE_UINT32);
7645 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7646         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7647                                 low_water, RTE_UINT32);
7648 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7649         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7650                                 pause_time, RTE_UINT16);
7651 cmdline_parse_token_num_t cmd_pfc_set_priority =
7652         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7653                                 priority, RTE_UINT8);
7654 cmdline_parse_token_num_t cmd_pfc_set_portid =
7655         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7656                                 port_id, RTE_UINT16);
7657
7658 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7659         .f = cmd_priority_flow_ctrl_set_parsed,
7660         .data = NULL,
7661         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7662                 "<pause_time> <priority> <port_id>: "
7663                 "Configure the Ethernet priority flow control",
7664         .tokens = {
7665                 (void *)&cmd_pfc_set_set,
7666                 (void *)&cmd_pfc_set_flow_ctrl,
7667                 (void *)&cmd_pfc_set_rx,
7668                 (void *)&cmd_pfc_set_rx_mode,
7669                 (void *)&cmd_pfc_set_tx,
7670                 (void *)&cmd_pfc_set_tx_mode,
7671                 (void *)&cmd_pfc_set_high_water,
7672                 (void *)&cmd_pfc_set_low_water,
7673                 (void *)&cmd_pfc_set_pause_time,
7674                 (void *)&cmd_pfc_set_priority,
7675                 (void *)&cmd_pfc_set_portid,
7676                 NULL,
7677         },
7678 };
7679
7680 /* *** RESET CONFIGURATION *** */
7681 struct cmd_reset_result {
7682         cmdline_fixed_string_t reset;
7683         cmdline_fixed_string_t def;
7684 };
7685
7686 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7687                              struct cmdline *cl,
7688                              __rte_unused void *data)
7689 {
7690         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7691         set_def_fwd_config();
7692 }
7693
7694 cmdline_parse_token_string_t cmd_reset_set =
7695         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7696 cmdline_parse_token_string_t cmd_reset_def =
7697         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7698                                  "default");
7699
7700 cmdline_parse_inst_t cmd_reset = {
7701         .f = cmd_reset_parsed,
7702         .data = NULL,
7703         .help_str = "set default: Reset default forwarding configuration",
7704         .tokens = {
7705                 (void *)&cmd_reset_set,
7706                 (void *)&cmd_reset_def,
7707                 NULL,
7708         },
7709 };
7710
7711 /* *** START FORWARDING *** */
7712 struct cmd_start_result {
7713         cmdline_fixed_string_t start;
7714 };
7715
7716 cmdline_parse_token_string_t cmd_start_start =
7717         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7718
7719 static void cmd_start_parsed(__rte_unused void *parsed_result,
7720                              __rte_unused struct cmdline *cl,
7721                              __rte_unused void *data)
7722 {
7723         start_packet_forwarding(0);
7724 }
7725
7726 cmdline_parse_inst_t cmd_start = {
7727         .f = cmd_start_parsed,
7728         .data = NULL,
7729         .help_str = "start: Start packet forwarding",
7730         .tokens = {
7731                 (void *)&cmd_start_start,
7732                 NULL,
7733         },
7734 };
7735
7736 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7737 struct cmd_start_tx_first_result {
7738         cmdline_fixed_string_t start;
7739         cmdline_fixed_string_t tx_first;
7740 };
7741
7742 static void
7743 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7744                           __rte_unused struct cmdline *cl,
7745                           __rte_unused void *data)
7746 {
7747         start_packet_forwarding(1);
7748 }
7749
7750 cmdline_parse_token_string_t cmd_start_tx_first_start =
7751         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7752                                  "start");
7753 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7754         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7755                                  tx_first, "tx_first");
7756
7757 cmdline_parse_inst_t cmd_start_tx_first = {
7758         .f = cmd_start_tx_first_parsed,
7759         .data = NULL,
7760         .help_str = "start tx_first: Start packet forwarding, "
7761                 "after sending 1 burst of packets",
7762         .tokens = {
7763                 (void *)&cmd_start_tx_first_start,
7764                 (void *)&cmd_start_tx_first_tx_first,
7765                 NULL,
7766         },
7767 };
7768
7769 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7770 struct cmd_start_tx_first_n_result {
7771         cmdline_fixed_string_t start;
7772         cmdline_fixed_string_t tx_first;
7773         uint32_t tx_num;
7774 };
7775
7776 static void
7777 cmd_start_tx_first_n_parsed(void *parsed_result,
7778                           __rte_unused struct cmdline *cl,
7779                           __rte_unused void *data)
7780 {
7781         struct cmd_start_tx_first_n_result *res = parsed_result;
7782
7783         start_packet_forwarding(res->tx_num);
7784 }
7785
7786 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7787         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7788                         start, "start");
7789 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7790         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7791                         tx_first, "tx_first");
7792 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7793         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7794                         tx_num, RTE_UINT32);
7795
7796 cmdline_parse_inst_t cmd_start_tx_first_n = {
7797         .f = cmd_start_tx_first_n_parsed,
7798         .data = NULL,
7799         .help_str = "start tx_first <num>: "
7800                 "packet forwarding, after sending <num> bursts of packets",
7801         .tokens = {
7802                 (void *)&cmd_start_tx_first_n_start,
7803                 (void *)&cmd_start_tx_first_n_tx_first,
7804                 (void *)&cmd_start_tx_first_n_tx_num,
7805                 NULL,
7806         },
7807 };
7808
7809 /* *** SET LINK UP *** */
7810 struct cmd_set_link_up_result {
7811         cmdline_fixed_string_t set;
7812         cmdline_fixed_string_t link_up;
7813         cmdline_fixed_string_t port;
7814         portid_t port_id;
7815 };
7816
7817 cmdline_parse_token_string_t cmd_set_link_up_set =
7818         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7819 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7820         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7821                                 "link-up");
7822 cmdline_parse_token_string_t cmd_set_link_up_port =
7823         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7824 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7825         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7826                                 RTE_UINT16);
7827
7828 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7829                              __rte_unused struct cmdline *cl,
7830                              __rte_unused void *data)
7831 {
7832         struct cmd_set_link_up_result *res = parsed_result;
7833         dev_set_link_up(res->port_id);
7834 }
7835
7836 cmdline_parse_inst_t cmd_set_link_up = {
7837         .f = cmd_set_link_up_parsed,
7838         .data = NULL,
7839         .help_str = "set link-up port <port id>",
7840         .tokens = {
7841                 (void *)&cmd_set_link_up_set,
7842                 (void *)&cmd_set_link_up_link_up,
7843                 (void *)&cmd_set_link_up_port,
7844                 (void *)&cmd_set_link_up_port_id,
7845                 NULL,
7846         },
7847 };
7848
7849 /* *** SET LINK DOWN *** */
7850 struct cmd_set_link_down_result {
7851         cmdline_fixed_string_t set;
7852         cmdline_fixed_string_t link_down;
7853         cmdline_fixed_string_t port;
7854         portid_t port_id;
7855 };
7856
7857 cmdline_parse_token_string_t cmd_set_link_down_set =
7858         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7859 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7860         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7861                                 "link-down");
7862 cmdline_parse_token_string_t cmd_set_link_down_port =
7863         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7864 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7865         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7866                                 RTE_UINT16);
7867
7868 static void cmd_set_link_down_parsed(
7869                                 __rte_unused void *parsed_result,
7870                                 __rte_unused struct cmdline *cl,
7871                                 __rte_unused void *data)
7872 {
7873         struct cmd_set_link_down_result *res = parsed_result;
7874         dev_set_link_down(res->port_id);
7875 }
7876
7877 cmdline_parse_inst_t cmd_set_link_down = {
7878         .f = cmd_set_link_down_parsed,
7879         .data = NULL,
7880         .help_str = "set link-down port <port id>",
7881         .tokens = {
7882                 (void *)&cmd_set_link_down_set,
7883                 (void *)&cmd_set_link_down_link_down,
7884                 (void *)&cmd_set_link_down_port,
7885                 (void *)&cmd_set_link_down_port_id,
7886                 NULL,
7887         },
7888 };
7889
7890 /* *** SHOW CFG *** */
7891 struct cmd_showcfg_result {
7892         cmdline_fixed_string_t show;
7893         cmdline_fixed_string_t cfg;
7894         cmdline_fixed_string_t what;
7895 };
7896
7897 static void cmd_showcfg_parsed(void *parsed_result,
7898                                __rte_unused struct cmdline *cl,
7899                                __rte_unused void *data)
7900 {
7901         struct cmd_showcfg_result *res = parsed_result;
7902         if (!strcmp(res->what, "rxtx"))
7903                 rxtx_config_display();
7904         else if (!strcmp(res->what, "cores"))
7905                 fwd_lcores_config_display();
7906         else if (!strcmp(res->what, "fwd"))
7907                 pkt_fwd_config_display(&cur_fwd_config);
7908         else if (!strcmp(res->what, "rxoffs"))
7909                 show_rx_pkt_offsets();
7910         else if (!strcmp(res->what, "rxpkts"))
7911                 show_rx_pkt_segments();
7912         else if (!strcmp(res->what, "txpkts"))
7913                 show_tx_pkt_segments();
7914         else if (!strcmp(res->what, "txtimes"))
7915                 show_tx_pkt_times();
7916 }
7917
7918 cmdline_parse_token_string_t cmd_showcfg_show =
7919         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7920 cmdline_parse_token_string_t cmd_showcfg_port =
7921         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7922 cmdline_parse_token_string_t cmd_showcfg_what =
7923         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7924                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7925
7926 cmdline_parse_inst_t cmd_showcfg = {
7927         .f = cmd_showcfg_parsed,
7928         .data = NULL,
7929         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7930         .tokens = {
7931                 (void *)&cmd_showcfg_show,
7932                 (void *)&cmd_showcfg_port,
7933                 (void *)&cmd_showcfg_what,
7934                 NULL,
7935         },
7936 };
7937
7938 /* *** SHOW ALL PORT INFO *** */
7939 struct cmd_showportall_result {
7940         cmdline_fixed_string_t show;
7941         cmdline_fixed_string_t port;
7942         cmdline_fixed_string_t what;
7943         cmdline_fixed_string_t all;
7944 };
7945
7946 static void cmd_showportall_parsed(void *parsed_result,
7947                                 __rte_unused struct cmdline *cl,
7948                                 __rte_unused void *data)
7949 {
7950         portid_t i;
7951
7952         struct cmd_showportall_result *res = parsed_result;
7953         if (!strcmp(res->show, "clear")) {
7954                 if (!strcmp(res->what, "stats"))
7955                         RTE_ETH_FOREACH_DEV(i)
7956                                 nic_stats_clear(i);
7957                 else if (!strcmp(res->what, "xstats"))
7958                         RTE_ETH_FOREACH_DEV(i)
7959                                 nic_xstats_clear(i);
7960         } else if (!strcmp(res->what, "info"))
7961                 RTE_ETH_FOREACH_DEV(i)
7962                         port_infos_display(i);
7963         else if (!strcmp(res->what, "summary")) {
7964                 port_summary_header_display();
7965                 RTE_ETH_FOREACH_DEV(i)
7966                         port_summary_display(i);
7967         }
7968         else if (!strcmp(res->what, "stats"))
7969                 RTE_ETH_FOREACH_DEV(i)
7970                         nic_stats_display(i);
7971         else if (!strcmp(res->what, "xstats"))
7972                 RTE_ETH_FOREACH_DEV(i)
7973                         nic_xstats_display(i);
7974 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7975         else if (!strcmp(res->what, "fdir"))
7976                 RTE_ETH_FOREACH_DEV(i)
7977                         fdir_get_infos(i);
7978 #endif
7979         else if (!strcmp(res->what, "dcb_tc"))
7980                 RTE_ETH_FOREACH_DEV(i)
7981                         port_dcb_info_display(i);
7982 }
7983
7984 cmdline_parse_token_string_t cmd_showportall_show =
7985         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7986                                  "show#clear");
7987 cmdline_parse_token_string_t cmd_showportall_port =
7988         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7989 cmdline_parse_token_string_t cmd_showportall_what =
7990         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7991                                  "info#summary#stats#xstats#fdir#dcb_tc");
7992 cmdline_parse_token_string_t cmd_showportall_all =
7993         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7994 cmdline_parse_inst_t cmd_showportall = {
7995         .f = cmd_showportall_parsed,
7996         .data = NULL,
7997         .help_str = "show|clear port "
7998                 "info|summary|stats|xstats|fdir|dcb_tc all",
7999         .tokens = {
8000                 (void *)&cmd_showportall_show,
8001                 (void *)&cmd_showportall_port,
8002                 (void *)&cmd_showportall_what,
8003                 (void *)&cmd_showportall_all,
8004                 NULL,
8005         },
8006 };
8007
8008 /* *** SHOW PORT INFO *** */
8009 struct cmd_showport_result {
8010         cmdline_fixed_string_t show;
8011         cmdline_fixed_string_t port;
8012         cmdline_fixed_string_t what;
8013         uint16_t portnum;
8014 };
8015
8016 static void cmd_showport_parsed(void *parsed_result,
8017                                 __rte_unused struct cmdline *cl,
8018                                 __rte_unused void *data)
8019 {
8020         struct cmd_showport_result *res = parsed_result;
8021         if (!strcmp(res->show, "clear")) {
8022                 if (!strcmp(res->what, "stats"))
8023                         nic_stats_clear(res->portnum);
8024                 else if (!strcmp(res->what, "xstats"))
8025                         nic_xstats_clear(res->portnum);
8026         } else if (!strcmp(res->what, "info"))
8027                 port_infos_display(res->portnum);
8028         else if (!strcmp(res->what, "summary")) {
8029                 port_summary_header_display();
8030                 port_summary_display(res->portnum);
8031         }
8032         else if (!strcmp(res->what, "stats"))
8033                 nic_stats_display(res->portnum);
8034         else if (!strcmp(res->what, "xstats"))
8035                 nic_xstats_display(res->portnum);
8036 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8037         else if (!strcmp(res->what, "fdir"))
8038                  fdir_get_infos(res->portnum);
8039 #endif
8040         else if (!strcmp(res->what, "dcb_tc"))
8041                 port_dcb_info_display(res->portnum);
8042 }
8043
8044 cmdline_parse_token_string_t cmd_showport_show =
8045         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8046                                  "show#clear");
8047 cmdline_parse_token_string_t cmd_showport_port =
8048         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8049 cmdline_parse_token_string_t cmd_showport_what =
8050         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8051                                  "info#summary#stats#xstats#fdir#dcb_tc");
8052 cmdline_parse_token_num_t cmd_showport_portnum =
8053         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8054
8055 cmdline_parse_inst_t cmd_showport = {
8056         .f = cmd_showport_parsed,
8057         .data = NULL,
8058         .help_str = "show|clear port "
8059                 "info|summary|stats|xstats|fdir|dcb_tc "
8060                 "<port_id>",
8061         .tokens = {
8062                 (void *)&cmd_showport_show,
8063                 (void *)&cmd_showport_port,
8064                 (void *)&cmd_showport_what,
8065                 (void *)&cmd_showport_portnum,
8066                 NULL,
8067         },
8068 };
8069
8070 /* *** show port representors information *** */
8071 struct cmd_representor_info_result {
8072         cmdline_fixed_string_t cmd_show;
8073         cmdline_fixed_string_t cmd_port;
8074         cmdline_fixed_string_t cmd_info;
8075         cmdline_fixed_string_t cmd_keyword;
8076         portid_t cmd_pid;
8077 };
8078
8079 static void
8080 cmd_representor_info_parsed(void *parsed_result,
8081                 __rte_unused struct cmdline *cl,
8082                 __rte_unused void *data)
8083 {
8084         struct cmd_representor_info_result *res = parsed_result;
8085         struct rte_eth_representor_info *info;
8086         struct rte_eth_representor_range *range;
8087         uint32_t range_diff;
8088         uint32_t i;
8089         int ret;
8090         int num;
8091
8092         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8093                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8094                 return;
8095         }
8096
8097         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8098         if (ret < 0) {
8099                 fprintf(stderr,
8100                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8101                         res->cmd_pid, rte_strerror(-ret));
8102                 return;
8103         }
8104         num = ret;
8105
8106         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8107         if (info == NULL) {
8108                 fprintf(stderr,
8109                         "Failed to allocate memory for representor info for port %hu\n",
8110                         res->cmd_pid);
8111                 return;
8112         }
8113         info->nb_ranges_alloc = num;
8114
8115         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8116         if (ret < 0) {
8117                 fprintf(stderr,
8118                         "Failed to get the representor info for port %hu: %s\n",
8119                         res->cmd_pid, rte_strerror(-ret));
8120                 free(info);
8121                 return;
8122         }
8123
8124         printf("Port controller: %hu\n", info->controller);
8125         printf("Port PF: %hu\n", info->pf);
8126
8127         printf("Ranges: %u\n", info->nb_ranges);
8128         for (i = 0; i < info->nb_ranges; i++) {
8129                 range = &info->ranges[i];
8130                 range_diff = range->id_end - range->id_base;
8131
8132                 printf("%u. ", i + 1);
8133                 printf("'%s' ", range->name);
8134                 if (range_diff > 0)
8135                         printf("[%u-%u]: ", range->id_base, range->id_end);
8136                 else
8137                         printf("[%u]: ", range->id_base);
8138
8139                 printf("Controller %d, PF %d", range->controller, range->pf);
8140
8141                 switch (range->type) {
8142                 case RTE_ETH_REPRESENTOR_NONE:
8143                         printf(", NONE\n");
8144                         break;
8145                 case RTE_ETH_REPRESENTOR_VF:
8146                         if (range_diff > 0)
8147                                 printf(", VF %d..%d\n", range->vf,
8148                                        range->vf + range_diff);
8149                         else
8150                                 printf(", VF %d\n", range->vf);
8151                         break;
8152                 case RTE_ETH_REPRESENTOR_SF:
8153                         printf(", SF %d\n", range->sf);
8154                         break;
8155                 case RTE_ETH_REPRESENTOR_PF:
8156                         if (range_diff > 0)
8157                                 printf("..%d\n", range->pf + range_diff);
8158                         else
8159                                 printf("\n");
8160                         break;
8161                 default:
8162                         printf(", UNKNOWN TYPE %d\n", range->type);
8163                         break;
8164                 }
8165         }
8166
8167         free(info);
8168 }
8169
8170 cmdline_parse_token_string_t cmd_representor_info_show =
8171         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8172                         cmd_show, "show");
8173 cmdline_parse_token_string_t cmd_representor_info_port =
8174         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8175                         cmd_port, "port");
8176 cmdline_parse_token_string_t cmd_representor_info_info =
8177         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8178                         cmd_info, "info");
8179 cmdline_parse_token_num_t cmd_representor_info_pid =
8180         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8181                         cmd_pid, RTE_UINT16);
8182 cmdline_parse_token_string_t cmd_representor_info_keyword =
8183         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8184                         cmd_keyword, "representor");
8185
8186 cmdline_parse_inst_t cmd_representor_info = {
8187         .f = cmd_representor_info_parsed,
8188         .data = NULL,
8189         .help_str = "show port info <port_id> representor",
8190         .tokens = {
8191                 (void *)&cmd_representor_info_show,
8192                 (void *)&cmd_representor_info_port,
8193                 (void *)&cmd_representor_info_info,
8194                 (void *)&cmd_representor_info_pid,
8195                 (void *)&cmd_representor_info_keyword,
8196                 NULL,
8197         },
8198 };
8199
8200
8201 /* *** SHOW DEVICE INFO *** */
8202 struct cmd_showdevice_result {
8203         cmdline_fixed_string_t show;
8204         cmdline_fixed_string_t device;
8205         cmdline_fixed_string_t what;
8206         cmdline_fixed_string_t identifier;
8207 };
8208
8209 static void cmd_showdevice_parsed(void *parsed_result,
8210                                 __rte_unused struct cmdline *cl,
8211                                 __rte_unused void *data)
8212 {
8213         struct cmd_showdevice_result *res = parsed_result;
8214         if (!strcmp(res->what, "info")) {
8215                 if (!strcmp(res->identifier, "all"))
8216                         device_infos_display(NULL);
8217                 else
8218                         device_infos_display(res->identifier);
8219         }
8220 }
8221
8222 cmdline_parse_token_string_t cmd_showdevice_show =
8223         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8224                                  "show");
8225 cmdline_parse_token_string_t cmd_showdevice_device =
8226         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8227 cmdline_parse_token_string_t cmd_showdevice_what =
8228         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8229                                  "info");
8230 cmdline_parse_token_string_t cmd_showdevice_identifier =
8231         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8232                         identifier, NULL);
8233
8234 cmdline_parse_inst_t cmd_showdevice = {
8235         .f = cmd_showdevice_parsed,
8236         .data = NULL,
8237         .help_str = "show device info <identifier>|all",
8238         .tokens = {
8239                 (void *)&cmd_showdevice_show,
8240                 (void *)&cmd_showdevice_device,
8241                 (void *)&cmd_showdevice_what,
8242                 (void *)&cmd_showdevice_identifier,
8243                 NULL,
8244         },
8245 };
8246
8247 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8248 struct cmd_showeeprom_result {
8249         cmdline_fixed_string_t show;
8250         cmdline_fixed_string_t port;
8251         uint16_t portnum;
8252         cmdline_fixed_string_t type;
8253 };
8254
8255 static void cmd_showeeprom_parsed(void *parsed_result,
8256                 __rte_unused struct cmdline *cl,
8257                 __rte_unused void *data)
8258 {
8259         struct cmd_showeeprom_result *res = parsed_result;
8260
8261         if (!strcmp(res->type, "eeprom"))
8262                 port_eeprom_display(res->portnum);
8263         else if (!strcmp(res->type, "module_eeprom"))
8264                 port_module_eeprom_display(res->portnum);
8265         else
8266                 fprintf(stderr, "Unknown argument\n");
8267 }
8268
8269 cmdline_parse_token_string_t cmd_showeeprom_show =
8270         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8271 cmdline_parse_token_string_t cmd_showeeprom_port =
8272         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8273 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8274         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8275                         RTE_UINT16);
8276 cmdline_parse_token_string_t cmd_showeeprom_type =
8277         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8278
8279 cmdline_parse_inst_t cmd_showeeprom = {
8280         .f = cmd_showeeprom_parsed,
8281         .data = NULL,
8282         .help_str = "show port <port_id> module_eeprom|eeprom",
8283         .tokens = {
8284                 (void *)&cmd_showeeprom_show,
8285                 (void *)&cmd_showeeprom_port,
8286                 (void *)&cmd_showeeprom_portnum,
8287                 (void *)&cmd_showeeprom_type,
8288                 NULL,
8289         },
8290 };
8291
8292 /* *** SHOW QUEUE INFO *** */
8293 struct cmd_showqueue_result {
8294         cmdline_fixed_string_t show;
8295         cmdline_fixed_string_t type;
8296         cmdline_fixed_string_t what;
8297         uint16_t portnum;
8298         uint16_t queuenum;
8299 };
8300
8301 static void
8302 cmd_showqueue_parsed(void *parsed_result,
8303         __rte_unused struct cmdline *cl,
8304         __rte_unused void *data)
8305 {
8306         struct cmd_showqueue_result *res = parsed_result;
8307
8308         if (!strcmp(res->type, "rxq"))
8309                 rx_queue_infos_display(res->portnum, res->queuenum);
8310         else if (!strcmp(res->type, "txq"))
8311                 tx_queue_infos_display(res->portnum, res->queuenum);
8312 }
8313
8314 cmdline_parse_token_string_t cmd_showqueue_show =
8315         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8316 cmdline_parse_token_string_t cmd_showqueue_type =
8317         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8318 cmdline_parse_token_string_t cmd_showqueue_what =
8319         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8320 cmdline_parse_token_num_t cmd_showqueue_portnum =
8321         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8322                 RTE_UINT16);
8323 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8324         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8325                 RTE_UINT16);
8326
8327 cmdline_parse_inst_t cmd_showqueue = {
8328         .f = cmd_showqueue_parsed,
8329         .data = NULL,
8330         .help_str = "show rxq|txq info <port_id> <queue_id>",
8331         .tokens = {
8332                 (void *)&cmd_showqueue_show,
8333                 (void *)&cmd_showqueue_type,
8334                 (void *)&cmd_showqueue_what,
8335                 (void *)&cmd_showqueue_portnum,
8336                 (void *)&cmd_showqueue_queuenum,
8337                 NULL,
8338         },
8339 };
8340
8341 /* show/clear fwd engine statistics */
8342 struct fwd_result {
8343         cmdline_fixed_string_t action;
8344         cmdline_fixed_string_t fwd;
8345         cmdline_fixed_string_t stats;
8346         cmdline_fixed_string_t all;
8347 };
8348
8349 cmdline_parse_token_string_t cmd_fwd_action =
8350         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8351 cmdline_parse_token_string_t cmd_fwd_fwd =
8352         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8353 cmdline_parse_token_string_t cmd_fwd_stats =
8354         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8355 cmdline_parse_token_string_t cmd_fwd_all =
8356         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8357
8358 static void
8359 cmd_showfwdall_parsed(void *parsed_result,
8360                       __rte_unused struct cmdline *cl,
8361                       __rte_unused void *data)
8362 {
8363         struct fwd_result *res = parsed_result;
8364
8365         if (!strcmp(res->action, "show"))
8366                 fwd_stats_display();
8367         else
8368                 fwd_stats_reset();
8369 }
8370
8371 static cmdline_parse_inst_t cmd_showfwdall = {
8372         .f = cmd_showfwdall_parsed,
8373         .data = NULL,
8374         .help_str = "show|clear fwd stats all",
8375         .tokens = {
8376                 (void *)&cmd_fwd_action,
8377                 (void *)&cmd_fwd_fwd,
8378                 (void *)&cmd_fwd_stats,
8379                 (void *)&cmd_fwd_all,
8380                 NULL,
8381         },
8382 };
8383
8384 /* *** READ PORT REGISTER *** */
8385 struct cmd_read_reg_result {
8386         cmdline_fixed_string_t read;
8387         cmdline_fixed_string_t reg;
8388         portid_t port_id;
8389         uint32_t reg_off;
8390 };
8391
8392 static void
8393 cmd_read_reg_parsed(void *parsed_result,
8394                     __rte_unused struct cmdline *cl,
8395                     __rte_unused void *data)
8396 {
8397         struct cmd_read_reg_result *res = parsed_result;
8398         port_reg_display(res->port_id, res->reg_off);
8399 }
8400
8401 cmdline_parse_token_string_t cmd_read_reg_read =
8402         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8403 cmdline_parse_token_string_t cmd_read_reg_reg =
8404         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8405 cmdline_parse_token_num_t cmd_read_reg_port_id =
8406         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8407 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8408         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8409
8410 cmdline_parse_inst_t cmd_read_reg = {
8411         .f = cmd_read_reg_parsed,
8412         .data = NULL,
8413         .help_str = "read reg <port_id> <reg_off>",
8414         .tokens = {
8415                 (void *)&cmd_read_reg_read,
8416                 (void *)&cmd_read_reg_reg,
8417                 (void *)&cmd_read_reg_port_id,
8418                 (void *)&cmd_read_reg_reg_off,
8419                 NULL,
8420         },
8421 };
8422
8423 /* *** READ PORT REGISTER BIT FIELD *** */
8424 struct cmd_read_reg_bit_field_result {
8425         cmdline_fixed_string_t read;
8426         cmdline_fixed_string_t regfield;
8427         portid_t port_id;
8428         uint32_t reg_off;
8429         uint8_t bit1_pos;
8430         uint8_t bit2_pos;
8431 };
8432
8433 static void
8434 cmd_read_reg_bit_field_parsed(void *parsed_result,
8435                               __rte_unused struct cmdline *cl,
8436                               __rte_unused void *data)
8437 {
8438         struct cmd_read_reg_bit_field_result *res = parsed_result;
8439         port_reg_bit_field_display(res->port_id, res->reg_off,
8440                                    res->bit1_pos, res->bit2_pos);
8441 }
8442
8443 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8444         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8445                                  "read");
8446 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8447         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8448                                  regfield, "regfield");
8449 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8450         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8451                               RTE_UINT16);
8452 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8453         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8454                               RTE_UINT32);
8455 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8456         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8457                               RTE_UINT8);
8458 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8459         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8460                               RTE_UINT8);
8461
8462 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8463         .f = cmd_read_reg_bit_field_parsed,
8464         .data = NULL,
8465         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8466         "Read register bit field between bit_x and bit_y included",
8467         .tokens = {
8468                 (void *)&cmd_read_reg_bit_field_read,
8469                 (void *)&cmd_read_reg_bit_field_regfield,
8470                 (void *)&cmd_read_reg_bit_field_port_id,
8471                 (void *)&cmd_read_reg_bit_field_reg_off,
8472                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8473                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8474                 NULL,
8475         },
8476 };
8477
8478 /* *** READ PORT REGISTER BIT *** */
8479 struct cmd_read_reg_bit_result {
8480         cmdline_fixed_string_t read;
8481         cmdline_fixed_string_t regbit;
8482         portid_t port_id;
8483         uint32_t reg_off;
8484         uint8_t bit_pos;
8485 };
8486
8487 static void
8488 cmd_read_reg_bit_parsed(void *parsed_result,
8489                         __rte_unused struct cmdline *cl,
8490                         __rte_unused void *data)
8491 {
8492         struct cmd_read_reg_bit_result *res = parsed_result;
8493         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8494 }
8495
8496 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8497         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8498 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8499         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8500                                  regbit, "regbit");
8501 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8502         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8503                                  RTE_UINT16);
8504 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8505         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8506                                  RTE_UINT32);
8507 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8508         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8509                                  RTE_UINT8);
8510
8511 cmdline_parse_inst_t cmd_read_reg_bit = {
8512         .f = cmd_read_reg_bit_parsed,
8513         .data = NULL,
8514         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8515         .tokens = {
8516                 (void *)&cmd_read_reg_bit_read,
8517                 (void *)&cmd_read_reg_bit_regbit,
8518                 (void *)&cmd_read_reg_bit_port_id,
8519                 (void *)&cmd_read_reg_bit_reg_off,
8520                 (void *)&cmd_read_reg_bit_bit_pos,
8521                 NULL,
8522         },
8523 };
8524
8525 /* *** WRITE PORT REGISTER *** */
8526 struct cmd_write_reg_result {
8527         cmdline_fixed_string_t write;
8528         cmdline_fixed_string_t reg;
8529         portid_t port_id;
8530         uint32_t reg_off;
8531         uint32_t value;
8532 };
8533
8534 static void
8535 cmd_write_reg_parsed(void *parsed_result,
8536                      __rte_unused struct cmdline *cl,
8537                      __rte_unused void *data)
8538 {
8539         struct cmd_write_reg_result *res = parsed_result;
8540         port_reg_set(res->port_id, res->reg_off, res->value);
8541 }
8542
8543 cmdline_parse_token_string_t cmd_write_reg_write =
8544         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8545 cmdline_parse_token_string_t cmd_write_reg_reg =
8546         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8547 cmdline_parse_token_num_t cmd_write_reg_port_id =
8548         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8549 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8550         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8551 cmdline_parse_token_num_t cmd_write_reg_value =
8552         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8553
8554 cmdline_parse_inst_t cmd_write_reg = {
8555         .f = cmd_write_reg_parsed,
8556         .data = NULL,
8557         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8558         .tokens = {
8559                 (void *)&cmd_write_reg_write,
8560                 (void *)&cmd_write_reg_reg,
8561                 (void *)&cmd_write_reg_port_id,
8562                 (void *)&cmd_write_reg_reg_off,
8563                 (void *)&cmd_write_reg_value,
8564                 NULL,
8565         },
8566 };
8567
8568 /* *** WRITE PORT REGISTER BIT FIELD *** */
8569 struct cmd_write_reg_bit_field_result {
8570         cmdline_fixed_string_t write;
8571         cmdline_fixed_string_t regfield;
8572         portid_t port_id;
8573         uint32_t reg_off;
8574         uint8_t bit1_pos;
8575         uint8_t bit2_pos;
8576         uint32_t value;
8577 };
8578
8579 static void
8580 cmd_write_reg_bit_field_parsed(void *parsed_result,
8581                                __rte_unused struct cmdline *cl,
8582                                __rte_unused void *data)
8583 {
8584         struct cmd_write_reg_bit_field_result *res = parsed_result;
8585         port_reg_bit_field_set(res->port_id, res->reg_off,
8586                           res->bit1_pos, res->bit2_pos, res->value);
8587 }
8588
8589 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8590         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8591                                  "write");
8592 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8593         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8594                                  regfield, "regfield");
8595 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8596         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8597                               RTE_UINT16);
8598 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8599         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8600                               RTE_UINT32);
8601 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8602         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8603                               RTE_UINT8);
8604 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8605         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8606                               RTE_UINT8);
8607 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8608         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8609                               RTE_UINT32);
8610
8611 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8612         .f = cmd_write_reg_bit_field_parsed,
8613         .data = NULL,
8614         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8615                 "<reg_value>: "
8616                 "Set register bit field between bit_x and bit_y included",
8617         .tokens = {
8618                 (void *)&cmd_write_reg_bit_field_write,
8619                 (void *)&cmd_write_reg_bit_field_regfield,
8620                 (void *)&cmd_write_reg_bit_field_port_id,
8621                 (void *)&cmd_write_reg_bit_field_reg_off,
8622                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8623                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8624                 (void *)&cmd_write_reg_bit_field_value,
8625                 NULL,
8626         },
8627 };
8628
8629 /* *** WRITE PORT REGISTER BIT *** */
8630 struct cmd_write_reg_bit_result {
8631         cmdline_fixed_string_t write;
8632         cmdline_fixed_string_t regbit;
8633         portid_t port_id;
8634         uint32_t reg_off;
8635         uint8_t bit_pos;
8636         uint8_t value;
8637 };
8638
8639 static void
8640 cmd_write_reg_bit_parsed(void *parsed_result,
8641                          __rte_unused struct cmdline *cl,
8642                          __rte_unused void *data)
8643 {
8644         struct cmd_write_reg_bit_result *res = parsed_result;
8645         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8646 }
8647
8648 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8649         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8650                                  "write");
8651 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8652         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8653                                  regbit, "regbit");
8654 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8655         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8656                                  RTE_UINT16);
8657 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8658         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8659                                  RTE_UINT32);
8660 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8661         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8662                                  RTE_UINT8);
8663 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8664         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8665                                  RTE_UINT8);
8666
8667 cmdline_parse_inst_t cmd_write_reg_bit = {
8668         .f = cmd_write_reg_bit_parsed,
8669         .data = NULL,
8670         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8671                 "0 <= bit_x <= 31",
8672         .tokens = {
8673                 (void *)&cmd_write_reg_bit_write,
8674                 (void *)&cmd_write_reg_bit_regbit,
8675                 (void *)&cmd_write_reg_bit_port_id,
8676                 (void *)&cmd_write_reg_bit_reg_off,
8677                 (void *)&cmd_write_reg_bit_bit_pos,
8678                 (void *)&cmd_write_reg_bit_value,
8679                 NULL,
8680         },
8681 };
8682
8683 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8684 struct cmd_read_rxd_txd_result {
8685         cmdline_fixed_string_t read;
8686         cmdline_fixed_string_t rxd_txd;
8687         portid_t port_id;
8688         uint16_t queue_id;
8689         uint16_t desc_id;
8690 };
8691
8692 static void
8693 cmd_read_rxd_txd_parsed(void *parsed_result,
8694                         __rte_unused struct cmdline *cl,
8695                         __rte_unused void *data)
8696 {
8697         struct cmd_read_rxd_txd_result *res = parsed_result;
8698
8699         if (!strcmp(res->rxd_txd, "rxd"))
8700                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8701         else if (!strcmp(res->rxd_txd, "txd"))
8702                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8703 }
8704
8705 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8706         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8707 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8708         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8709                                  "rxd#txd");
8710 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8711         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8712                                  RTE_UINT16);
8713 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8714         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8715                                  RTE_UINT16);
8716 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8717         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8718                                  RTE_UINT16);
8719
8720 cmdline_parse_inst_t cmd_read_rxd_txd = {
8721         .f = cmd_read_rxd_txd_parsed,
8722         .data = NULL,
8723         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8724         .tokens = {
8725                 (void *)&cmd_read_rxd_txd_read,
8726                 (void *)&cmd_read_rxd_txd_rxd_txd,
8727                 (void *)&cmd_read_rxd_txd_port_id,
8728                 (void *)&cmd_read_rxd_txd_queue_id,
8729                 (void *)&cmd_read_rxd_txd_desc_id,
8730                 NULL,
8731         },
8732 };
8733
8734 /* *** QUIT *** */
8735 struct cmd_quit_result {
8736         cmdline_fixed_string_t quit;
8737 };
8738
8739 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8740                             struct cmdline *cl,
8741                             __rte_unused void *data)
8742 {
8743         cmdline_quit(cl);
8744 }
8745
8746 cmdline_parse_token_string_t cmd_quit_quit =
8747         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8748
8749 cmdline_parse_inst_t cmd_quit = {
8750         .f = cmd_quit_parsed,
8751         .data = NULL,
8752         .help_str = "quit: Exit application",
8753         .tokens = {
8754                 (void *)&cmd_quit_quit,
8755                 NULL,
8756         },
8757 };
8758
8759 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8760 struct cmd_mac_addr_result {
8761         cmdline_fixed_string_t mac_addr_cmd;
8762         cmdline_fixed_string_t what;
8763         uint16_t port_num;
8764         struct rte_ether_addr address;
8765 };
8766
8767 static void cmd_mac_addr_parsed(void *parsed_result,
8768                 __rte_unused struct cmdline *cl,
8769                 __rte_unused void *data)
8770 {
8771         struct cmd_mac_addr_result *res = parsed_result;
8772         int ret;
8773
8774         if (strcmp(res->what, "add") == 0)
8775                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8776         else if (strcmp(res->what, "set") == 0)
8777                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8778                                                        &res->address);
8779         else
8780                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8781
8782         /* check the return value and print it if is < 0 */
8783         if(ret < 0)
8784                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8785
8786 }
8787
8788 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8789         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8790                                 "mac_addr");
8791 cmdline_parse_token_string_t cmd_mac_addr_what =
8792         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8793                                 "add#remove#set");
8794 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8795                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8796                                         RTE_UINT16);
8797 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8798                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8799
8800 cmdline_parse_inst_t cmd_mac_addr = {
8801         .f = cmd_mac_addr_parsed,
8802         .data = (void *)0,
8803         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8804                         "Add/Remove/Set MAC address on port_id",
8805         .tokens = {
8806                 (void *)&cmd_mac_addr_cmd,
8807                 (void *)&cmd_mac_addr_what,
8808                 (void *)&cmd_mac_addr_portnum,
8809                 (void *)&cmd_mac_addr_addr,
8810                 NULL,
8811         },
8812 };
8813
8814 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8815 struct cmd_eth_peer_result {
8816         cmdline_fixed_string_t set;
8817         cmdline_fixed_string_t eth_peer;
8818         portid_t port_id;
8819         cmdline_fixed_string_t peer_addr;
8820 };
8821
8822 static void cmd_set_eth_peer_parsed(void *parsed_result,
8823                         __rte_unused struct cmdline *cl,
8824                         __rte_unused void *data)
8825 {
8826                 struct cmd_eth_peer_result *res = parsed_result;
8827
8828                 if (test_done == 0) {
8829                         fprintf(stderr, "Please stop forwarding first\n");
8830                         return;
8831                 }
8832                 if (!strcmp(res->eth_peer, "eth-peer")) {
8833                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8834                         fwd_config_setup();
8835                 }
8836 }
8837 cmdline_parse_token_string_t cmd_eth_peer_set =
8838         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8839 cmdline_parse_token_string_t cmd_eth_peer =
8840         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8841 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8842         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8843                 RTE_UINT16);
8844 cmdline_parse_token_string_t cmd_eth_peer_addr =
8845         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8846
8847 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8848         .f = cmd_set_eth_peer_parsed,
8849         .data = NULL,
8850         .help_str = "set eth-peer <port_id> <peer_mac>",
8851         .tokens = {
8852                 (void *)&cmd_eth_peer_set,
8853                 (void *)&cmd_eth_peer,
8854                 (void *)&cmd_eth_peer_port_id,
8855                 (void *)&cmd_eth_peer_addr,
8856                 NULL,
8857         },
8858 };
8859
8860 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8861 struct cmd_set_qmap_result {
8862         cmdline_fixed_string_t set;
8863         cmdline_fixed_string_t qmap;
8864         cmdline_fixed_string_t what;
8865         portid_t port_id;
8866         uint16_t queue_id;
8867         uint8_t map_value;
8868 };
8869
8870 static void
8871 cmd_set_qmap_parsed(void *parsed_result,
8872                        __rte_unused struct cmdline *cl,
8873                        __rte_unused void *data)
8874 {
8875         struct cmd_set_qmap_result *res = parsed_result;
8876         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8877
8878         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8879 }
8880
8881 cmdline_parse_token_string_t cmd_setqmap_set =
8882         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8883                                  set, "set");
8884 cmdline_parse_token_string_t cmd_setqmap_qmap =
8885         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8886                                  qmap, "stat_qmap");
8887 cmdline_parse_token_string_t cmd_setqmap_what =
8888         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8889                                  what, "tx#rx");
8890 cmdline_parse_token_num_t cmd_setqmap_portid =
8891         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8892                               port_id, RTE_UINT16);
8893 cmdline_parse_token_num_t cmd_setqmap_queueid =
8894         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8895                               queue_id, RTE_UINT16);
8896 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8897         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8898                               map_value, RTE_UINT8);
8899
8900 cmdline_parse_inst_t cmd_set_qmap = {
8901         .f = cmd_set_qmap_parsed,
8902         .data = NULL,
8903         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8904                 "Set statistics mapping value on tx|rx queue_id of port_id",
8905         .tokens = {
8906                 (void *)&cmd_setqmap_set,
8907                 (void *)&cmd_setqmap_qmap,
8908                 (void *)&cmd_setqmap_what,
8909                 (void *)&cmd_setqmap_portid,
8910                 (void *)&cmd_setqmap_queueid,
8911                 (void *)&cmd_setqmap_mapvalue,
8912                 NULL,
8913         },
8914 };
8915
8916 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8917 struct cmd_set_xstats_hide_zero_result {
8918         cmdline_fixed_string_t keyword;
8919         cmdline_fixed_string_t name;
8920         cmdline_fixed_string_t on_off;
8921 };
8922
8923 static void
8924 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8925                         __rte_unused struct cmdline *cl,
8926                         __rte_unused void *data)
8927 {
8928         struct cmd_set_xstats_hide_zero_result *res;
8929         uint16_t on_off = 0;
8930
8931         res = parsed_result;
8932         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8933         set_xstats_hide_zero(on_off);
8934 }
8935
8936 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8937         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8938                                  keyword, "set");
8939 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8940         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8941                                  name, "xstats-hide-zero");
8942 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8943         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8944                                  on_off, "on#off");
8945
8946 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8947         .f = cmd_set_xstats_hide_zero_parsed,
8948         .data = NULL,
8949         .help_str = "set xstats-hide-zero on|off",
8950         .tokens = {
8951                 (void *)&cmd_set_xstats_hide_zero_keyword,
8952                 (void *)&cmd_set_xstats_hide_zero_name,
8953                 (void *)&cmd_set_xstats_hide_zero_on_off,
8954                 NULL,
8955         },
8956 };
8957
8958 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8959 struct cmd_set_record_core_cycles_result {
8960         cmdline_fixed_string_t keyword;
8961         cmdline_fixed_string_t name;
8962         cmdline_fixed_string_t on_off;
8963 };
8964
8965 static void
8966 cmd_set_record_core_cycles_parsed(void *parsed_result,
8967                         __rte_unused struct cmdline *cl,
8968                         __rte_unused void *data)
8969 {
8970         struct cmd_set_record_core_cycles_result *res;
8971         uint16_t on_off = 0;
8972
8973         res = parsed_result;
8974         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8975         set_record_core_cycles(on_off);
8976 }
8977
8978 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8979         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8980                                  keyword, "set");
8981 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8982         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8983                                  name, "record-core-cycles");
8984 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8985         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8986                                  on_off, "on#off");
8987
8988 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8989         .f = cmd_set_record_core_cycles_parsed,
8990         .data = NULL,
8991         .help_str = "set record-core-cycles on|off",
8992         .tokens = {
8993                 (void *)&cmd_set_record_core_cycles_keyword,
8994                 (void *)&cmd_set_record_core_cycles_name,
8995                 (void *)&cmd_set_record_core_cycles_on_off,
8996                 NULL,
8997         },
8998 };
8999
9000 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9001 struct cmd_set_record_burst_stats_result {
9002         cmdline_fixed_string_t keyword;
9003         cmdline_fixed_string_t name;
9004         cmdline_fixed_string_t on_off;
9005 };
9006
9007 static void
9008 cmd_set_record_burst_stats_parsed(void *parsed_result,
9009                         __rte_unused struct cmdline *cl,
9010                         __rte_unused void *data)
9011 {
9012         struct cmd_set_record_burst_stats_result *res;
9013         uint16_t on_off = 0;
9014
9015         res = parsed_result;
9016         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9017         set_record_burst_stats(on_off);
9018 }
9019
9020 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9021         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9022                                  keyword, "set");
9023 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9024         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9025                                  name, "record-burst-stats");
9026 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9027         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9028                                  on_off, "on#off");
9029
9030 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9031         .f = cmd_set_record_burst_stats_parsed,
9032         .data = NULL,
9033         .help_str = "set record-burst-stats on|off",
9034         .tokens = {
9035                 (void *)&cmd_set_record_burst_stats_keyword,
9036                 (void *)&cmd_set_record_burst_stats_name,
9037                 (void *)&cmd_set_record_burst_stats_on_off,
9038                 NULL,
9039         },
9040 };
9041
9042 /* *** CONFIGURE UNICAST HASH TABLE *** */
9043 struct cmd_set_uc_hash_table {
9044         cmdline_fixed_string_t set;
9045         cmdline_fixed_string_t port;
9046         portid_t port_id;
9047         cmdline_fixed_string_t what;
9048         struct rte_ether_addr address;
9049         cmdline_fixed_string_t mode;
9050 };
9051
9052 static void
9053 cmd_set_uc_hash_parsed(void *parsed_result,
9054                        __rte_unused struct cmdline *cl,
9055                        __rte_unused void *data)
9056 {
9057         int ret=0;
9058         struct cmd_set_uc_hash_table *res = parsed_result;
9059
9060         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9061
9062         if (strcmp(res->what, "uta") == 0)
9063                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9064                                                 &res->address,(uint8_t)is_on);
9065         if (ret < 0)
9066                 fprintf(stderr,
9067                         "bad unicast hash table parameter, return code = %d\n",
9068                         ret);
9069
9070 }
9071
9072 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9073         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9074                                  set, "set");
9075 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9076         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9077                                  port, "port");
9078 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9079         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9080                               port_id, RTE_UINT16);
9081 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9082         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9083                                  what, "uta");
9084 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9085         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9086                                 address);
9087 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9088         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9089                                  mode, "on#off");
9090
9091 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9092         .f = cmd_set_uc_hash_parsed,
9093         .data = NULL,
9094         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9095         .tokens = {
9096                 (void *)&cmd_set_uc_hash_set,
9097                 (void *)&cmd_set_uc_hash_port,
9098                 (void *)&cmd_set_uc_hash_portid,
9099                 (void *)&cmd_set_uc_hash_what,
9100                 (void *)&cmd_set_uc_hash_mac,
9101                 (void *)&cmd_set_uc_hash_mode,
9102                 NULL,
9103         },
9104 };
9105
9106 struct cmd_set_uc_all_hash_table {
9107         cmdline_fixed_string_t set;
9108         cmdline_fixed_string_t port;
9109         portid_t port_id;
9110         cmdline_fixed_string_t what;
9111         cmdline_fixed_string_t value;
9112         cmdline_fixed_string_t mode;
9113 };
9114
9115 static void
9116 cmd_set_uc_all_hash_parsed(void *parsed_result,
9117                        __rte_unused struct cmdline *cl,
9118                        __rte_unused void *data)
9119 {
9120         int ret=0;
9121         struct cmd_set_uc_all_hash_table *res = parsed_result;
9122
9123         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9124
9125         if ((strcmp(res->what, "uta") == 0) &&
9126                 (strcmp(res->value, "all") == 0))
9127                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9128         if (ret < 0)
9129                 fprintf(stderr,
9130                         "bad unicast hash table parameter, return code = %d\n",
9131                         ret);
9132 }
9133
9134 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9135         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9136                                  set, "set");
9137 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9138         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9139                                  port, "port");
9140 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9141         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9142                               port_id, RTE_UINT16);
9143 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9144         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9145                                  what, "uta");
9146 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9147         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9148                                 value,"all");
9149 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9150         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9151                                  mode, "on#off");
9152
9153 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9154         .f = cmd_set_uc_all_hash_parsed,
9155         .data = NULL,
9156         .help_str = "set port <port_id> uta all on|off",
9157         .tokens = {
9158                 (void *)&cmd_set_uc_all_hash_set,
9159                 (void *)&cmd_set_uc_all_hash_port,
9160                 (void *)&cmd_set_uc_all_hash_portid,
9161                 (void *)&cmd_set_uc_all_hash_what,
9162                 (void *)&cmd_set_uc_all_hash_value,
9163                 (void *)&cmd_set_uc_all_hash_mode,
9164                 NULL,
9165         },
9166 };
9167
9168 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9169 struct cmd_set_vf_traffic {
9170         cmdline_fixed_string_t set;
9171         cmdline_fixed_string_t port;
9172         portid_t port_id;
9173         cmdline_fixed_string_t vf;
9174         uint8_t vf_id;
9175         cmdline_fixed_string_t what;
9176         cmdline_fixed_string_t mode;
9177 };
9178
9179 static void
9180 cmd_set_vf_traffic_parsed(void *parsed_result,
9181                        __rte_unused struct cmdline *cl,
9182                        __rte_unused void *data)
9183 {
9184         struct cmd_set_vf_traffic *res = parsed_result;
9185         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9186         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9187
9188         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9189 }
9190
9191 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9192         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9193                                  set, "set");
9194 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9195         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9196                                  port, "port");
9197 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9198         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9199                               port_id, RTE_UINT16);
9200 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9201         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9202                                  vf, "vf");
9203 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9204         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9205                               vf_id, RTE_UINT8);
9206 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9207         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9208                                  what, "tx#rx");
9209 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9210         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9211                                  mode, "on#off");
9212
9213 cmdline_parse_inst_t cmd_set_vf_traffic = {
9214         .f = cmd_set_vf_traffic_parsed,
9215         .data = NULL,
9216         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9217         .tokens = {
9218                 (void *)&cmd_setvf_traffic_set,
9219                 (void *)&cmd_setvf_traffic_port,
9220                 (void *)&cmd_setvf_traffic_portid,
9221                 (void *)&cmd_setvf_traffic_vf,
9222                 (void *)&cmd_setvf_traffic_vfid,
9223                 (void *)&cmd_setvf_traffic_what,
9224                 (void *)&cmd_setvf_traffic_mode,
9225                 NULL,
9226         },
9227 };
9228
9229 /* *** CONFIGURE VF RECEIVE MODE *** */
9230 struct cmd_set_vf_rxmode {
9231         cmdline_fixed_string_t set;
9232         cmdline_fixed_string_t port;
9233         portid_t port_id;
9234         cmdline_fixed_string_t vf;
9235         uint8_t vf_id;
9236         cmdline_fixed_string_t what;
9237         cmdline_fixed_string_t mode;
9238         cmdline_fixed_string_t on;
9239 };
9240
9241 static void
9242 cmd_set_vf_rxmode_parsed(void *parsed_result,
9243                        __rte_unused struct cmdline *cl,
9244                        __rte_unused void *data)
9245 {
9246         int ret = -ENOTSUP;
9247         uint16_t vf_rxmode = 0;
9248         struct cmd_set_vf_rxmode *res = parsed_result;
9249
9250         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9251         if (!strcmp(res->what,"rxmode")) {
9252                 if (!strcmp(res->mode, "AUPE"))
9253                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
9254                 else if (!strcmp(res->mode, "ROPE"))
9255                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
9256                 else if (!strcmp(res->mode, "BAM"))
9257                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
9258                 else if (!strncmp(res->mode, "MPE",3))
9259                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
9260         }
9261
9262         RTE_SET_USED(is_on);
9263
9264 #ifdef RTE_NET_IXGBE
9265         if (ret == -ENOTSUP)
9266                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9267                                                   vf_rxmode, (uint8_t)is_on);
9268 #endif
9269 #ifdef RTE_NET_BNXT
9270         if (ret == -ENOTSUP)
9271                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9272                                                  vf_rxmode, (uint8_t)is_on);
9273 #endif
9274         if (ret < 0)
9275                 fprintf(stderr,
9276                         "bad VF receive mode parameter, return code = %d\n",
9277                         ret);
9278 }
9279
9280 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9281         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9282                                  set, "set");
9283 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9284         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9285                                  port, "port");
9286 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9287         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9288                               port_id, RTE_UINT16);
9289 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9290         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9291                                  vf, "vf");
9292 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9293         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9294                               vf_id, RTE_UINT8);
9295 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9296         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9297                                  what, "rxmode");
9298 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9299         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9300                                  mode, "AUPE#ROPE#BAM#MPE");
9301 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9302         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9303                                  on, "on#off");
9304
9305 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9306         .f = cmd_set_vf_rxmode_parsed,
9307         .data = NULL,
9308         .help_str = "set port <port_id> vf <vf_id> rxmode "
9309                 "AUPE|ROPE|BAM|MPE on|off",
9310         .tokens = {
9311                 (void *)&cmd_set_vf_rxmode_set,
9312                 (void *)&cmd_set_vf_rxmode_port,
9313                 (void *)&cmd_set_vf_rxmode_portid,
9314                 (void *)&cmd_set_vf_rxmode_vf,
9315                 (void *)&cmd_set_vf_rxmode_vfid,
9316                 (void *)&cmd_set_vf_rxmode_what,
9317                 (void *)&cmd_set_vf_rxmode_mode,
9318                 (void *)&cmd_set_vf_rxmode_on,
9319                 NULL,
9320         },
9321 };
9322
9323 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9324 struct cmd_vf_mac_addr_result {
9325         cmdline_fixed_string_t mac_addr_cmd;
9326         cmdline_fixed_string_t what;
9327         cmdline_fixed_string_t port;
9328         uint16_t port_num;
9329         cmdline_fixed_string_t vf;
9330         uint8_t vf_num;
9331         struct rte_ether_addr address;
9332 };
9333
9334 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9335                 __rte_unused struct cmdline *cl,
9336                 __rte_unused void *data)
9337 {
9338         struct cmd_vf_mac_addr_result *res = parsed_result;
9339         int ret = -ENOTSUP;
9340
9341         if (strcmp(res->what, "add") != 0)
9342                 return;
9343
9344 #ifdef RTE_NET_I40E
9345         if (ret == -ENOTSUP)
9346                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9347                                                    &res->address);
9348 #endif
9349 #ifdef RTE_NET_BNXT
9350         if (ret == -ENOTSUP)
9351                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9352                                                 res->vf_num);
9353 #endif
9354
9355         if(ret < 0)
9356                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9357
9358 }
9359
9360 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9361         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9362                                 mac_addr_cmd,"mac_addr");
9363 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9364         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9365                                 what,"add");
9366 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9367         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9368                                 port,"port");
9369 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9370         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9371                                 port_num, RTE_UINT16);
9372 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9373         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9374                                 vf,"vf");
9375 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9376         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9377                                 vf_num, RTE_UINT8);
9378 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9379         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9380                                 address);
9381
9382 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9383         .f = cmd_vf_mac_addr_parsed,
9384         .data = (void *)0,
9385         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9386                 "Add MAC address filtering for a VF on port_id",
9387         .tokens = {
9388                 (void *)&cmd_vf_mac_addr_cmd,
9389                 (void *)&cmd_vf_mac_addr_what,
9390                 (void *)&cmd_vf_mac_addr_port,
9391                 (void *)&cmd_vf_mac_addr_portnum,
9392                 (void *)&cmd_vf_mac_addr_vf,
9393                 (void *)&cmd_vf_mac_addr_vfnum,
9394                 (void *)&cmd_vf_mac_addr_addr,
9395                 NULL,
9396         },
9397 };
9398
9399 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9400 struct cmd_vf_rx_vlan_filter {
9401         cmdline_fixed_string_t rx_vlan;
9402         cmdline_fixed_string_t what;
9403         uint16_t vlan_id;
9404         cmdline_fixed_string_t port;
9405         portid_t port_id;
9406         cmdline_fixed_string_t vf;
9407         uint64_t vf_mask;
9408 };
9409
9410 static void
9411 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9412                           __rte_unused struct cmdline *cl,
9413                           __rte_unused void *data)
9414 {
9415         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9416         int ret = -ENOTSUP;
9417
9418         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9419
9420 #ifdef RTE_NET_IXGBE
9421         if (ret == -ENOTSUP)
9422                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9423                                 res->vlan_id, res->vf_mask, is_add);
9424 #endif
9425 #ifdef RTE_NET_I40E
9426         if (ret == -ENOTSUP)
9427                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9428                                 res->vlan_id, res->vf_mask, is_add);
9429 #endif
9430 #ifdef RTE_NET_BNXT
9431         if (ret == -ENOTSUP)
9432                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9433                                 res->vlan_id, res->vf_mask, is_add);
9434 #endif
9435
9436         switch (ret) {
9437         case 0:
9438                 break;
9439         case -EINVAL:
9440                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9441                         res->vlan_id, res->vf_mask);
9442                 break;
9443         case -ENODEV:
9444                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9445                 break;
9446         case -ENOTSUP:
9447                 fprintf(stderr, "function not implemented or supported\n");
9448                 break;
9449         default:
9450                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9451         }
9452 }
9453
9454 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9455         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9456                                  rx_vlan, "rx_vlan");
9457 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9458         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9459                                  what, "add#rm");
9460 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9461         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9462                               vlan_id, RTE_UINT16);
9463 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9464         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9465                                  port, "port");
9466 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9467         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9468                               port_id, RTE_UINT16);
9469 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9470         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9471                                  vf, "vf");
9472 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9473         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9474                               vf_mask, RTE_UINT64);
9475
9476 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9477         .f = cmd_vf_rx_vlan_filter_parsed,
9478         .data = NULL,
9479         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9480                 "(vf_mask = hexadecimal VF mask)",
9481         .tokens = {
9482                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9483                 (void *)&cmd_vf_rx_vlan_filter_what,
9484                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9485                 (void *)&cmd_vf_rx_vlan_filter_port,
9486                 (void *)&cmd_vf_rx_vlan_filter_portid,
9487                 (void *)&cmd_vf_rx_vlan_filter_vf,
9488                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9489                 NULL,
9490         },
9491 };
9492
9493 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9494 struct cmd_queue_rate_limit_result {
9495         cmdline_fixed_string_t set;
9496         cmdline_fixed_string_t port;
9497         uint16_t port_num;
9498         cmdline_fixed_string_t queue;
9499         uint8_t queue_num;
9500         cmdline_fixed_string_t rate;
9501         uint16_t rate_num;
9502 };
9503
9504 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9505                 __rte_unused struct cmdline *cl,
9506                 __rte_unused void *data)
9507 {
9508         struct cmd_queue_rate_limit_result *res = parsed_result;
9509         int ret = 0;
9510
9511         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9512                 && (strcmp(res->queue, "queue") == 0)
9513                 && (strcmp(res->rate, "rate") == 0))
9514                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9515                                         res->rate_num);
9516         if (ret < 0)
9517                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9518                         strerror(-ret));
9519
9520 }
9521
9522 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9523         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9524                                 set, "set");
9525 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9526         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9527                                 port, "port");
9528 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9529         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9530                                 port_num, RTE_UINT16);
9531 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9532         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9533                                 queue, "queue");
9534 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9535         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9536                                 queue_num, RTE_UINT8);
9537 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9538         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9539                                 rate, "rate");
9540 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9541         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9542                                 rate_num, RTE_UINT16);
9543
9544 cmdline_parse_inst_t cmd_queue_rate_limit = {
9545         .f = cmd_queue_rate_limit_parsed,
9546         .data = (void *)0,
9547         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9548                 "Set rate limit for a queue on port_id",
9549         .tokens = {
9550                 (void *)&cmd_queue_rate_limit_set,
9551                 (void *)&cmd_queue_rate_limit_port,
9552                 (void *)&cmd_queue_rate_limit_portnum,
9553                 (void *)&cmd_queue_rate_limit_queue,
9554                 (void *)&cmd_queue_rate_limit_queuenum,
9555                 (void *)&cmd_queue_rate_limit_rate,
9556                 (void *)&cmd_queue_rate_limit_ratenum,
9557                 NULL,
9558         },
9559 };
9560
9561 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9562 struct cmd_vf_rate_limit_result {
9563         cmdline_fixed_string_t set;
9564         cmdline_fixed_string_t port;
9565         uint16_t port_num;
9566         cmdline_fixed_string_t vf;
9567         uint8_t vf_num;
9568         cmdline_fixed_string_t rate;
9569         uint16_t rate_num;
9570         cmdline_fixed_string_t q_msk;
9571         uint64_t q_msk_val;
9572 };
9573
9574 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9575                 __rte_unused struct cmdline *cl,
9576                 __rte_unused void *data)
9577 {
9578         struct cmd_vf_rate_limit_result *res = parsed_result;
9579         int ret = 0;
9580
9581         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9582                 && (strcmp(res->vf, "vf") == 0)
9583                 && (strcmp(res->rate, "rate") == 0)
9584                 && (strcmp(res->q_msk, "queue_mask") == 0))
9585                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9586                                         res->rate_num, res->q_msk_val);
9587         if (ret < 0)
9588                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9589                         strerror(-ret));
9590
9591 }
9592
9593 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9594         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9595                                 set, "set");
9596 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9597         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9598                                 port, "port");
9599 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9600         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9601                                 port_num, RTE_UINT16);
9602 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9603         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9604                                 vf, "vf");
9605 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9606         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9607                                 vf_num, RTE_UINT8);
9608 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9609         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9610                                 rate, "rate");
9611 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9612         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9613                                 rate_num, RTE_UINT16);
9614 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9615         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9616                                 q_msk, "queue_mask");
9617 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9618         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9619                                 q_msk_val, RTE_UINT64);
9620
9621 cmdline_parse_inst_t cmd_vf_rate_limit = {
9622         .f = cmd_vf_rate_limit_parsed,
9623         .data = (void *)0,
9624         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9625                 "queue_mask <queue_mask_value>: "
9626                 "Set rate limit for queues of VF on port_id",
9627         .tokens = {
9628                 (void *)&cmd_vf_rate_limit_set,
9629                 (void *)&cmd_vf_rate_limit_port,
9630                 (void *)&cmd_vf_rate_limit_portnum,
9631                 (void *)&cmd_vf_rate_limit_vf,
9632                 (void *)&cmd_vf_rate_limit_vfnum,
9633                 (void *)&cmd_vf_rate_limit_rate,
9634                 (void *)&cmd_vf_rate_limit_ratenum,
9635                 (void *)&cmd_vf_rate_limit_q_msk,
9636                 (void *)&cmd_vf_rate_limit_q_msk_val,
9637                 NULL,
9638         },
9639 };
9640
9641 /* *** CONFIGURE TUNNEL UDP PORT *** */
9642 struct cmd_tunnel_udp_config {
9643         cmdline_fixed_string_t rx_vxlan_port;
9644         cmdline_fixed_string_t what;
9645         uint16_t udp_port;
9646         portid_t port_id;
9647 };
9648
9649 static void
9650 cmd_tunnel_udp_config_parsed(void *parsed_result,
9651                           __rte_unused struct cmdline *cl,
9652                           __rte_unused void *data)
9653 {
9654         struct cmd_tunnel_udp_config *res = parsed_result;
9655         struct rte_eth_udp_tunnel tunnel_udp;
9656         int ret;
9657
9658         tunnel_udp.udp_port = res->udp_port;
9659         tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9660
9661         if (!strcmp(res->what, "add"))
9662                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9663                                                       &tunnel_udp);
9664         else
9665                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9666                                                          &tunnel_udp);
9667
9668         if (ret < 0)
9669                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9670                         strerror(-ret));
9671 }
9672
9673 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9674         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9675                                 rx_vxlan_port, "rx_vxlan_port");
9676 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9677         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9678                                 what, "add#rm");
9679 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9680         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9681                                 udp_port, RTE_UINT16);
9682 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9683         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9684                                 port_id, RTE_UINT16);
9685
9686 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9687         .f = cmd_tunnel_udp_config_parsed,
9688         .data = (void *)0,
9689         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9690                 "Add/Remove a tunneling UDP port filter",
9691         .tokens = {
9692                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9693                 (void *)&cmd_tunnel_udp_config_what,
9694                 (void *)&cmd_tunnel_udp_config_udp_port,
9695                 (void *)&cmd_tunnel_udp_config_port_id,
9696                 NULL,
9697         },
9698 };
9699
9700 struct cmd_config_tunnel_udp_port {
9701         cmdline_fixed_string_t port;
9702         cmdline_fixed_string_t config;
9703         portid_t port_id;
9704         cmdline_fixed_string_t udp_tunnel_port;
9705         cmdline_fixed_string_t action;
9706         cmdline_fixed_string_t tunnel_type;
9707         uint16_t udp_port;
9708 };
9709
9710 static void
9711 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9712                                __rte_unused struct cmdline *cl,
9713                                __rte_unused void *data)
9714 {
9715         struct cmd_config_tunnel_udp_port *res = parsed_result;
9716         struct rte_eth_udp_tunnel tunnel_udp;
9717         int ret = 0;
9718
9719         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9720                 return;
9721
9722         tunnel_udp.udp_port = res->udp_port;
9723
9724         if (!strcmp(res->tunnel_type, "vxlan")) {
9725                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9726         } else if (!strcmp(res->tunnel_type, "geneve")) {
9727                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9728         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9729                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9730         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9731                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_ECPRI;
9732         } else {
9733                 fprintf(stderr, "Invalid tunnel type\n");
9734                 return;
9735         }
9736
9737         if (!strcmp(res->action, "add"))
9738                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9739                                                       &tunnel_udp);
9740         else
9741                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9742                                                          &tunnel_udp);
9743
9744         if (ret < 0)
9745                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9746                         strerror(-ret));
9747 }
9748
9749 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9750         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9751                                  "port");
9752 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9753         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9754                                  "config");
9755 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9756         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9757                               RTE_UINT16);
9758 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9759         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9760                                  udp_tunnel_port,
9761                                  "udp_tunnel_port");
9762 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9763         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9764                                  "add#rm");
9765 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9766         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9767                                  "vxlan#geneve#vxlan-gpe#ecpri");
9768 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9769         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9770                               RTE_UINT16);
9771
9772 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9773         .f = cmd_cfg_tunnel_udp_port_parsed,
9774         .data = NULL,
9775         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9776                 "geneve|vxlan-gpe|ecpri <udp_port>",
9777         .tokens = {
9778                 (void *)&cmd_config_tunnel_udp_port_port,
9779                 (void *)&cmd_config_tunnel_udp_port_config,
9780                 (void *)&cmd_config_tunnel_udp_port_port_id,
9781                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9782                 (void *)&cmd_config_tunnel_udp_port_action,
9783                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9784                 (void *)&cmd_config_tunnel_udp_port_value,
9785                 NULL,
9786         },
9787 };
9788
9789 /* ******************************************************************************** */
9790
9791 struct cmd_dump_result {
9792         cmdline_fixed_string_t dump;
9793 };
9794
9795 static void
9796 dump_struct_sizes(void)
9797 {
9798 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9799         DUMP_SIZE(struct rte_mbuf);
9800         DUMP_SIZE(struct rte_mempool);
9801         DUMP_SIZE(struct rte_ring);
9802 #undef DUMP_SIZE
9803 }
9804
9805
9806 /* Dump the socket memory statistics on console */
9807 static void
9808 dump_socket_mem(FILE *f)
9809 {
9810         struct rte_malloc_socket_stats socket_stats;
9811         unsigned int i;
9812         size_t total = 0;
9813         size_t alloc = 0;
9814         size_t free = 0;
9815         unsigned int n_alloc = 0;
9816         unsigned int n_free = 0;
9817         static size_t last_allocs;
9818         static size_t last_total;
9819
9820
9821         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9822                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9823                     !socket_stats.heap_totalsz_bytes)
9824                         continue;
9825                 total += socket_stats.heap_totalsz_bytes;
9826                 alloc += socket_stats.heap_allocsz_bytes;
9827                 free += socket_stats.heap_freesz_bytes;
9828                 n_alloc += socket_stats.alloc_count;
9829                 n_free += socket_stats.free_count;
9830                 fprintf(f,
9831                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9832                         i,
9833                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9834                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9835                         (double)socket_stats.heap_allocsz_bytes * 100 /
9836                         (double)socket_stats.heap_totalsz_bytes,
9837                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9838                         socket_stats.alloc_count,
9839                         socket_stats.free_count);
9840         }
9841         fprintf(f,
9842                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9843                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9844                 total ? ((double)alloc * 100 / (double)total) : 0,
9845                 (double)free / (1024 * 1024),
9846                 n_alloc, n_free);
9847         if (last_allocs)
9848                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9849                         ((double)total - (double)last_total) / (1024 * 1024),
9850                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9851         last_allocs = alloc;
9852         last_total = total;
9853 }
9854
9855 static void cmd_dump_parsed(void *parsed_result,
9856                             __rte_unused struct cmdline *cl,
9857                             __rte_unused void *data)
9858 {
9859         struct cmd_dump_result *res = parsed_result;
9860
9861         if (!strcmp(res->dump, "dump_physmem"))
9862                 rte_dump_physmem_layout(stdout);
9863         else if (!strcmp(res->dump, "dump_socket_mem"))
9864                 dump_socket_mem(stdout);
9865         else if (!strcmp(res->dump, "dump_memzone"))
9866                 rte_memzone_dump(stdout);
9867         else if (!strcmp(res->dump, "dump_struct_sizes"))
9868                 dump_struct_sizes();
9869         else if (!strcmp(res->dump, "dump_ring"))
9870                 rte_ring_list_dump(stdout);
9871         else if (!strcmp(res->dump, "dump_mempool"))
9872                 rte_mempool_list_dump(stdout);
9873         else if (!strcmp(res->dump, "dump_devargs"))
9874                 rte_devargs_dump(stdout);
9875         else if (!strcmp(res->dump, "dump_log_types"))
9876                 rte_log_dump(stdout);
9877 }
9878
9879 cmdline_parse_token_string_t cmd_dump_dump =
9880         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9881                 "dump_physmem#"
9882                 "dump_memzone#"
9883                 "dump_socket_mem#"
9884                 "dump_struct_sizes#"
9885                 "dump_ring#"
9886                 "dump_mempool#"
9887                 "dump_devargs#"
9888                 "dump_log_types");
9889
9890 cmdline_parse_inst_t cmd_dump = {
9891         .f = cmd_dump_parsed,  /* function to call */
9892         .data = NULL,      /* 2nd arg of func */
9893         .help_str = "Dump status",
9894         .tokens = {        /* token list, NULL terminated */
9895                 (void *)&cmd_dump_dump,
9896                 NULL,
9897         },
9898 };
9899
9900 /* ******************************************************************************** */
9901
9902 struct cmd_dump_one_result {
9903         cmdline_fixed_string_t dump;
9904         cmdline_fixed_string_t name;
9905 };
9906
9907 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9908                                 __rte_unused void *data)
9909 {
9910         struct cmd_dump_one_result *res = parsed_result;
9911
9912         if (!strcmp(res->dump, "dump_ring")) {
9913                 struct rte_ring *r;
9914                 r = rte_ring_lookup(res->name);
9915                 if (r == NULL) {
9916                         cmdline_printf(cl, "Cannot find ring\n");
9917                         return;
9918                 }
9919                 rte_ring_dump(stdout, r);
9920         } else if (!strcmp(res->dump, "dump_mempool")) {
9921                 struct rte_mempool *mp;
9922                 mp = rte_mempool_lookup(res->name);
9923                 if (mp == NULL) {
9924                         cmdline_printf(cl, "Cannot find mempool\n");
9925                         return;
9926                 }
9927                 rte_mempool_dump(stdout, mp);
9928         }
9929 }
9930
9931 cmdline_parse_token_string_t cmd_dump_one_dump =
9932         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9933                                  "dump_ring#dump_mempool");
9934
9935 cmdline_parse_token_string_t cmd_dump_one_name =
9936         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9937
9938 cmdline_parse_inst_t cmd_dump_one = {
9939         .f = cmd_dump_one_parsed,  /* function to call */
9940         .data = NULL,      /* 2nd arg of func */
9941         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9942         .tokens = {        /* token list, NULL terminated */
9943                 (void *)&cmd_dump_one_dump,
9944                 (void *)&cmd_dump_one_name,
9945                 NULL,
9946         },
9947 };
9948
9949 /* *** queue region set *** */
9950 struct cmd_queue_region_result {
9951         cmdline_fixed_string_t set;
9952         cmdline_fixed_string_t port;
9953         portid_t port_id;
9954         cmdline_fixed_string_t cmd;
9955         cmdline_fixed_string_t region;
9956         uint8_t  region_id;
9957         cmdline_fixed_string_t queue_start_index;
9958         uint8_t  queue_id;
9959         cmdline_fixed_string_t queue_num;
9960         uint8_t  queue_num_value;
9961 };
9962
9963 static void
9964 cmd_queue_region_parsed(void *parsed_result,
9965                         __rte_unused struct cmdline *cl,
9966                         __rte_unused void *data)
9967 {
9968         struct cmd_queue_region_result *res = parsed_result;
9969         int ret = -ENOTSUP;
9970 #ifdef RTE_NET_I40E
9971         struct rte_pmd_i40e_queue_region_conf region_conf;
9972         enum rte_pmd_i40e_queue_region_op op_type;
9973 #endif
9974
9975         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9976                 return;
9977
9978 #ifdef RTE_NET_I40E
9979         memset(&region_conf, 0, sizeof(region_conf));
9980         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9981         region_conf.region_id = res->region_id;
9982         region_conf.queue_num = res->queue_num_value;
9983         region_conf.queue_start_index = res->queue_id;
9984
9985         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9986                                 op_type, &region_conf);
9987 #endif
9988
9989         switch (ret) {
9990         case 0:
9991                 break;
9992         case -ENOTSUP:
9993                 fprintf(stderr, "function not implemented or supported\n");
9994                 break;
9995         default:
9996                 fprintf(stderr, "queue region config error: (%s)\n",
9997                         strerror(-ret));
9998         }
9999 }
10000
10001 cmdline_parse_token_string_t cmd_queue_region_set =
10002 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10003                 set, "set");
10004 cmdline_parse_token_string_t cmd_queue_region_port =
10005         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10006 cmdline_parse_token_num_t cmd_queue_region_port_id =
10007         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10008                                 port_id, RTE_UINT16);
10009 cmdline_parse_token_string_t cmd_queue_region_cmd =
10010         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10011                                  cmd, "queue-region");
10012 cmdline_parse_token_string_t cmd_queue_region_id =
10013         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10014                                 region, "region_id");
10015 cmdline_parse_token_num_t cmd_queue_region_index =
10016         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10017                                 region_id, RTE_UINT8);
10018 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10019         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10020                                 queue_start_index, "queue_start_index");
10021 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10022         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10023                                 queue_id, RTE_UINT8);
10024 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10025         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10026                                 queue_num, "queue_num");
10027 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10028         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10029                                 queue_num_value, RTE_UINT8);
10030
10031 cmdline_parse_inst_t cmd_queue_region = {
10032         .f = cmd_queue_region_parsed,
10033         .data = NULL,
10034         .help_str = "set port <port_id> queue-region region_id <value> "
10035                 "queue_start_index <value> queue_num <value>: Set a queue region",
10036         .tokens = {
10037                 (void *)&cmd_queue_region_set,
10038                 (void *)&cmd_queue_region_port,
10039                 (void *)&cmd_queue_region_port_id,
10040                 (void *)&cmd_queue_region_cmd,
10041                 (void *)&cmd_queue_region_id,
10042                 (void *)&cmd_queue_region_index,
10043                 (void *)&cmd_queue_region_queue_start_index,
10044                 (void *)&cmd_queue_region_queue_id,
10045                 (void *)&cmd_queue_region_queue_num,
10046                 (void *)&cmd_queue_region_queue_num_value,
10047                 NULL,
10048         },
10049 };
10050
10051 /* *** queue region and flowtype set *** */
10052 struct cmd_region_flowtype_result {
10053         cmdline_fixed_string_t set;
10054         cmdline_fixed_string_t port;
10055         portid_t port_id;
10056         cmdline_fixed_string_t cmd;
10057         cmdline_fixed_string_t region;
10058         uint8_t  region_id;
10059         cmdline_fixed_string_t flowtype;
10060         uint8_t  flowtype_id;
10061 };
10062
10063 static void
10064 cmd_region_flowtype_parsed(void *parsed_result,
10065                         __rte_unused struct cmdline *cl,
10066                         __rte_unused void *data)
10067 {
10068         struct cmd_region_flowtype_result *res = parsed_result;
10069         int ret = -ENOTSUP;
10070 #ifdef RTE_NET_I40E
10071         struct rte_pmd_i40e_queue_region_conf region_conf;
10072         enum rte_pmd_i40e_queue_region_op op_type;
10073 #endif
10074
10075         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10076                 return;
10077
10078 #ifdef RTE_NET_I40E
10079         memset(&region_conf, 0, sizeof(region_conf));
10080
10081         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10082         region_conf.region_id = res->region_id;
10083         region_conf.hw_flowtype = res->flowtype_id;
10084
10085         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10086                         op_type, &region_conf);
10087 #endif
10088
10089         switch (ret) {
10090         case 0:
10091                 break;
10092         case -ENOTSUP:
10093                 fprintf(stderr, "function not implemented or supported\n");
10094                 break;
10095         default:
10096                 fprintf(stderr, "region flowtype config error: (%s)\n",
10097                         strerror(-ret));
10098         }
10099 }
10100
10101 cmdline_parse_token_string_t cmd_region_flowtype_set =
10102 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10103                                 set, "set");
10104 cmdline_parse_token_string_t cmd_region_flowtype_port =
10105         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10106                                 port, "port");
10107 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10108         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10109                                 port_id, RTE_UINT16);
10110 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10111         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10112                                 cmd, "queue-region");
10113 cmdline_parse_token_string_t cmd_region_flowtype_index =
10114         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10115                                 region, "region_id");
10116 cmdline_parse_token_num_t cmd_region_flowtype_id =
10117         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10118                                 region_id, RTE_UINT8);
10119 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10120         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10121                                 flowtype, "flowtype");
10122 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10123         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10124                                 flowtype_id, RTE_UINT8);
10125 cmdline_parse_inst_t cmd_region_flowtype = {
10126         .f = cmd_region_flowtype_parsed,
10127         .data = NULL,
10128         .help_str = "set port <port_id> queue-region region_id <value> "
10129                 "flowtype <value>: Set a flowtype region index",
10130         .tokens = {
10131                 (void *)&cmd_region_flowtype_set,
10132                 (void *)&cmd_region_flowtype_port,
10133                 (void *)&cmd_region_flowtype_port_index,
10134                 (void *)&cmd_region_flowtype_cmd,
10135                 (void *)&cmd_region_flowtype_index,
10136                 (void *)&cmd_region_flowtype_id,
10137                 (void *)&cmd_region_flowtype_flow_index,
10138                 (void *)&cmd_region_flowtype_flow_id,
10139                 NULL,
10140         },
10141 };
10142
10143 /* *** User Priority (UP) to queue region (region_id) set *** */
10144 struct cmd_user_priority_region_result {
10145         cmdline_fixed_string_t set;
10146         cmdline_fixed_string_t port;
10147         portid_t port_id;
10148         cmdline_fixed_string_t cmd;
10149         cmdline_fixed_string_t user_priority;
10150         uint8_t  user_priority_id;
10151         cmdline_fixed_string_t region;
10152         uint8_t  region_id;
10153 };
10154
10155 static void
10156 cmd_user_priority_region_parsed(void *parsed_result,
10157                         __rte_unused struct cmdline *cl,
10158                         __rte_unused void *data)
10159 {
10160         struct cmd_user_priority_region_result *res = parsed_result;
10161         int ret = -ENOTSUP;
10162 #ifdef RTE_NET_I40E
10163         struct rte_pmd_i40e_queue_region_conf region_conf;
10164         enum rte_pmd_i40e_queue_region_op op_type;
10165 #endif
10166
10167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10168                 return;
10169
10170 #ifdef RTE_NET_I40E
10171         memset(&region_conf, 0, sizeof(region_conf));
10172         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10173         region_conf.user_priority = res->user_priority_id;
10174         region_conf.region_id = res->region_id;
10175
10176         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10177                                 op_type, &region_conf);
10178 #endif
10179
10180         switch (ret) {
10181         case 0:
10182                 break;
10183         case -ENOTSUP:
10184                 fprintf(stderr, "function not implemented or supported\n");
10185                 break;
10186         default:
10187                 fprintf(stderr, "user_priority region config error: (%s)\n",
10188                         strerror(-ret));
10189         }
10190 }
10191
10192 cmdline_parse_token_string_t cmd_user_priority_region_set =
10193         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10194                                 set, "set");
10195 cmdline_parse_token_string_t cmd_user_priority_region_port =
10196         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10197                                 port, "port");
10198 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10199         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10200                                 port_id, RTE_UINT16);
10201 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10202         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10203                                 cmd, "queue-region");
10204 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10205         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10206                                 user_priority, "UP");
10207 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10208         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10209                                 user_priority_id, RTE_UINT8);
10210 cmdline_parse_token_string_t cmd_user_priority_region_region =
10211         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10212                                 region, "region_id");
10213 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10214         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10215                                 region_id, RTE_UINT8);
10216
10217 cmdline_parse_inst_t cmd_user_priority_region = {
10218         .f = cmd_user_priority_region_parsed,
10219         .data = NULL,
10220         .help_str = "set port <port_id> queue-region UP <value> "
10221                 "region_id <value>: Set the mapping of User Priority (UP) "
10222                 "to queue region (region_id) ",
10223         .tokens = {
10224                 (void *)&cmd_user_priority_region_set,
10225                 (void *)&cmd_user_priority_region_port,
10226                 (void *)&cmd_user_priority_region_port_index,
10227                 (void *)&cmd_user_priority_region_cmd,
10228                 (void *)&cmd_user_priority_region_UP,
10229                 (void *)&cmd_user_priority_region_UP_id,
10230                 (void *)&cmd_user_priority_region_region,
10231                 (void *)&cmd_user_priority_region_region_id,
10232                 NULL,
10233         },
10234 };
10235
10236 /* *** flush all queue region related configuration *** */
10237 struct cmd_flush_queue_region_result {
10238         cmdline_fixed_string_t set;
10239         cmdline_fixed_string_t port;
10240         portid_t port_id;
10241         cmdline_fixed_string_t cmd;
10242         cmdline_fixed_string_t flush;
10243         cmdline_fixed_string_t what;
10244 };
10245
10246 static void
10247 cmd_flush_queue_region_parsed(void *parsed_result,
10248                         __rte_unused struct cmdline *cl,
10249                         __rte_unused void *data)
10250 {
10251         struct cmd_flush_queue_region_result *res = parsed_result;
10252         int ret = -ENOTSUP;
10253 #ifdef RTE_NET_I40E
10254         struct rte_pmd_i40e_queue_region_conf region_conf;
10255         enum rte_pmd_i40e_queue_region_op op_type;
10256 #endif
10257
10258         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10259                 return;
10260
10261 #ifdef RTE_NET_I40E
10262         memset(&region_conf, 0, sizeof(region_conf));
10263
10264         if (strcmp(res->what, "on") == 0)
10265                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10266         else
10267                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10268
10269         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10270                                 op_type, &region_conf);
10271 #endif
10272
10273         switch (ret) {
10274         case 0:
10275                 break;
10276         case -ENOTSUP:
10277                 fprintf(stderr, "function not implemented or supported\n");
10278                 break;
10279         default:
10280                 fprintf(stderr, "queue region config flush error: (%s)\n",
10281                         strerror(-ret));
10282         }
10283 }
10284
10285 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10286         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10287                                 set, "set");
10288 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10289         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10290                                 port, "port");
10291 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10292         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10293                                 port_id, RTE_UINT16);
10294 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10295         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10296                                 cmd, "queue-region");
10297 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10298         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10299                                 flush, "flush");
10300 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10301         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10302                                 what, "on#off");
10303
10304 cmdline_parse_inst_t cmd_flush_queue_region = {
10305         .f = cmd_flush_queue_region_parsed,
10306         .data = NULL,
10307         .help_str = "set port <port_id> queue-region flush on|off"
10308                 ": flush all queue region related configuration",
10309         .tokens = {
10310                 (void *)&cmd_flush_queue_region_set,
10311                 (void *)&cmd_flush_queue_region_port,
10312                 (void *)&cmd_flush_queue_region_port_index,
10313                 (void *)&cmd_flush_queue_region_cmd,
10314                 (void *)&cmd_flush_queue_region_flush,
10315                 (void *)&cmd_flush_queue_region_what,
10316                 NULL,
10317         },
10318 };
10319
10320 /* *** get all queue region related configuration info *** */
10321 struct cmd_show_queue_region_info {
10322         cmdline_fixed_string_t show;
10323         cmdline_fixed_string_t port;
10324         portid_t port_id;
10325         cmdline_fixed_string_t cmd;
10326 };
10327
10328 static void
10329 cmd_show_queue_region_info_parsed(void *parsed_result,
10330                         __rte_unused struct cmdline *cl,
10331                         __rte_unused void *data)
10332 {
10333         struct cmd_show_queue_region_info *res = parsed_result;
10334         int ret = -ENOTSUP;
10335 #ifdef RTE_NET_I40E
10336         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10337         enum rte_pmd_i40e_queue_region_op op_type;
10338 #endif
10339
10340         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10341                 return;
10342
10343 #ifdef RTE_NET_I40E
10344         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10345
10346         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10347
10348         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10349                                         op_type, &rte_pmd_regions);
10350
10351         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10352 #endif
10353
10354         switch (ret) {
10355         case 0:
10356                 break;
10357         case -ENOTSUP:
10358                 fprintf(stderr, "function not implemented or supported\n");
10359                 break;
10360         default:
10361                 fprintf(stderr, "queue region config info show error: (%s)\n",
10362                         strerror(-ret));
10363         }
10364 }
10365
10366 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10367 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10368                                 show, "show");
10369 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10370         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10371                                 port, "port");
10372 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10373         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10374                                 port_id, RTE_UINT16);
10375 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10376         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10377                                 cmd, "queue-region");
10378
10379 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10380         .f = cmd_show_queue_region_info_parsed,
10381         .data = NULL,
10382         .help_str = "show port <port_id> queue-region"
10383                 ": show all queue region related configuration info",
10384         .tokens = {
10385                 (void *)&cmd_show_queue_region_info_get,
10386                 (void *)&cmd_show_queue_region_info_port,
10387                 (void *)&cmd_show_queue_region_info_port_index,
10388                 (void *)&cmd_show_queue_region_info_cmd,
10389                 NULL,
10390         },
10391 };
10392
10393 /* *** Filters Control *** */
10394
10395 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10396 do { \
10397         if ((ip_addr).family == AF_INET) \
10398                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10399         else { \
10400                 fprintf(stderr, "invalid parameter.\n"); \
10401                 return; \
10402         } \
10403 } while (0)
10404
10405 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10406 do { \
10407         if ((ip_addr).family == AF_INET6) \
10408                 rte_memcpy(&(ip), \
10409                                  &((ip_addr).addr.ipv6), \
10410                                  sizeof(struct in6_addr)); \
10411         else { \
10412                 fprintf(stderr, "invalid parameter.\n"); \
10413                 return; \
10414         } \
10415 } while (0)
10416
10417 #ifdef RTE_NET_I40E
10418
10419 static uint16_t
10420 str2flowtype(char *string)
10421 {
10422         uint8_t i = 0;
10423         static const struct {
10424                 char str[32];
10425                 uint16_t type;
10426         } flowtype_str[] = {
10427                 {"raw", RTE_ETH_FLOW_RAW},
10428                 {"ipv4", RTE_ETH_FLOW_IPV4},
10429                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10430                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10431                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10432                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10433                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10434                 {"ipv6", RTE_ETH_FLOW_IPV6},
10435                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10436                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10437                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10438                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10439                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10440                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10441         };
10442
10443         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10444                 if (!strcmp(flowtype_str[i].str, string))
10445                         return flowtype_str[i].type;
10446         }
10447
10448         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10449                 return (uint16_t)atoi(string);
10450
10451         return RTE_ETH_FLOW_UNKNOWN;
10452 }
10453
10454 /* *** deal with flow director filter *** */
10455 struct cmd_flow_director_result {
10456         cmdline_fixed_string_t flow_director_filter;
10457         portid_t port_id;
10458         cmdline_fixed_string_t mode;
10459         cmdline_fixed_string_t mode_value;
10460         cmdline_fixed_string_t ops;
10461         cmdline_fixed_string_t flow;
10462         cmdline_fixed_string_t flow_type;
10463         cmdline_fixed_string_t drop;
10464         cmdline_fixed_string_t queue;
10465         uint16_t  queue_id;
10466         cmdline_fixed_string_t fd_id;
10467         uint32_t  fd_id_value;
10468         cmdline_fixed_string_t packet;
10469         char filepath[];
10470 };
10471
10472 static void
10473 cmd_flow_director_filter_parsed(void *parsed_result,
10474                           __rte_unused struct cmdline *cl,
10475                           __rte_unused void *data)
10476 {
10477         struct cmd_flow_director_result *res = parsed_result;
10478         int ret = 0;
10479         struct rte_pmd_i40e_flow_type_mapping
10480                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10481         struct rte_pmd_i40e_pkt_template_conf conf;
10482         uint16_t flow_type = str2flowtype(res->flow_type);
10483         uint16_t i, port = res->port_id;
10484         uint8_t add;
10485
10486         memset(&conf, 0, sizeof(conf));
10487
10488         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10489                 fprintf(stderr, "Invalid flow type specified.\n");
10490                 return;
10491         }
10492         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10493                                                  mapping);
10494         if (ret)
10495                 return;
10496         if (mapping[flow_type].pctype == 0ULL) {
10497                 fprintf(stderr, "Invalid flow type specified.\n");
10498                 return;
10499         }
10500         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10501                 if (mapping[flow_type].pctype & (1ULL << i)) {
10502                         conf.input.pctype = i;
10503                         break;
10504                 }
10505         }
10506
10507         conf.input.packet = open_file(res->filepath,
10508                                 &conf.input.length);
10509         if (!conf.input.packet)
10510                 return;
10511         if (!strcmp(res->drop, "drop"))
10512                 conf.action.behavior =
10513                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10514         else
10515                 conf.action.behavior =
10516                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10517         conf.action.report_status =
10518                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10519         conf.action.rx_queue = res->queue_id;
10520         conf.soft_id = res->fd_id_value;
10521         add  = strcmp(res->ops, "del") ? 1 : 0;
10522         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10523                                                         &conf,
10524                                                         add);
10525         if (ret < 0)
10526                 fprintf(stderr, "flow director config error: (%s)\n",
10527                         strerror(-ret));
10528         close_file(conf.input.packet);
10529 }
10530
10531 cmdline_parse_token_string_t cmd_flow_director_filter =
10532         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10533                                  flow_director_filter, "flow_director_filter");
10534 cmdline_parse_token_num_t cmd_flow_director_port_id =
10535         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10536                               port_id, RTE_UINT16);
10537 cmdline_parse_token_string_t cmd_flow_director_ops =
10538         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10539                                  ops, "add#del#update");
10540 cmdline_parse_token_string_t cmd_flow_director_flow =
10541         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10542                                  flow, "flow");
10543 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10544         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10545                 flow_type, NULL);
10546 cmdline_parse_token_string_t cmd_flow_director_drop =
10547         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10548                                  drop, "drop#fwd");
10549 cmdline_parse_token_string_t cmd_flow_director_queue =
10550         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10551                                  queue, "queue");
10552 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10553         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10554                               queue_id, RTE_UINT16);
10555 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10556         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10557                                  fd_id, "fd_id");
10558 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10559         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10560                               fd_id_value, RTE_UINT32);
10561
10562 cmdline_parse_token_string_t cmd_flow_director_mode =
10563         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10564                                  mode, "mode");
10565 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10566         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10567                                  mode_value, "raw");
10568 cmdline_parse_token_string_t cmd_flow_director_packet =
10569         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10570                                  packet, "packet");
10571 cmdline_parse_token_string_t cmd_flow_director_filepath =
10572         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10573                                  filepath, NULL);
10574
10575 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10576         .f = cmd_flow_director_filter_parsed,
10577         .data = NULL,
10578         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10579                 "director entry on NIC",
10580         .tokens = {
10581                 (void *)&cmd_flow_director_filter,
10582                 (void *)&cmd_flow_director_port_id,
10583                 (void *)&cmd_flow_director_mode,
10584                 (void *)&cmd_flow_director_mode_raw,
10585                 (void *)&cmd_flow_director_ops,
10586                 (void *)&cmd_flow_director_flow,
10587                 (void *)&cmd_flow_director_flow_type,
10588                 (void *)&cmd_flow_director_drop,
10589                 (void *)&cmd_flow_director_queue,
10590                 (void *)&cmd_flow_director_queue_id,
10591                 (void *)&cmd_flow_director_fd_id,
10592                 (void *)&cmd_flow_director_fd_id_value,
10593                 (void *)&cmd_flow_director_packet,
10594                 (void *)&cmd_flow_director_filepath,
10595                 NULL,
10596         },
10597 };
10598
10599 #endif /* RTE_NET_I40E */
10600
10601 /* *** deal with flow director mask *** */
10602 struct cmd_flow_director_mask_result {
10603         cmdline_fixed_string_t flow_director_mask;
10604         portid_t port_id;
10605         cmdline_fixed_string_t mode;
10606         cmdline_fixed_string_t mode_value;
10607         cmdline_fixed_string_t vlan;
10608         uint16_t vlan_mask;
10609         cmdline_fixed_string_t src_mask;
10610         cmdline_ipaddr_t ipv4_src;
10611         cmdline_ipaddr_t ipv6_src;
10612         uint16_t port_src;
10613         cmdline_fixed_string_t dst_mask;
10614         cmdline_ipaddr_t ipv4_dst;
10615         cmdline_ipaddr_t ipv6_dst;
10616         uint16_t port_dst;
10617         cmdline_fixed_string_t mac;
10618         uint8_t mac_addr_byte_mask;
10619         cmdline_fixed_string_t tunnel_id;
10620         uint32_t tunnel_id_mask;
10621         cmdline_fixed_string_t tunnel_type;
10622         uint8_t tunnel_type_mask;
10623 };
10624
10625 static void
10626 cmd_flow_director_mask_parsed(void *parsed_result,
10627                           __rte_unused struct cmdline *cl,
10628                           __rte_unused void *data)
10629 {
10630         struct cmd_flow_director_mask_result *res = parsed_result;
10631         struct rte_eth_fdir_masks *mask;
10632         struct rte_port *port;
10633
10634         port = &ports[res->port_id];
10635         /** Check if the port is not started **/
10636         if (port->port_status != RTE_PORT_STOPPED) {
10637                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10638                 return;
10639         }
10640
10641         mask = &port->dev_conf.fdir_conf.mask;
10642
10643         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10644                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10645                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10646                         return;
10647                 }
10648
10649                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10650         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10651                 if (strcmp(res->mode_value, "Tunnel")) {
10652                         fprintf(stderr, "Please set mode to Tunnel.\n");
10653                         return;
10654                 }
10655
10656                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10657                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10658                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10659                 mask->tunnel_type_mask = res->tunnel_type_mask;
10660         } else {
10661                 if (strcmp(res->mode_value, "IP")) {
10662                         fprintf(stderr, "Please set mode to IP.\n");
10663                         return;
10664                 }
10665
10666                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10667                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10668                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10669                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10670                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10671                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10672                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10673         }
10674
10675         cmd_reconfig_device_queue(res->port_id, 1, 1);
10676 }
10677
10678 cmdline_parse_token_string_t cmd_flow_director_mask =
10679         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10680                                  flow_director_mask, "flow_director_mask");
10681 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10682         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10683                               port_id, RTE_UINT16);
10684 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10685         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10686                                  vlan, "vlan");
10687 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10688         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10689                               vlan_mask, RTE_UINT16);
10690 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10692                                  src_mask, "src_mask");
10693 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10694         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10695                                  ipv4_src);
10696 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10697         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10698                                  ipv6_src);
10699 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10700         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10701                               port_src, RTE_UINT16);
10702 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10703         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10704                                  dst_mask, "dst_mask");
10705 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10706         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10707                                  ipv4_dst);
10708 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10709         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10710                                  ipv6_dst);
10711 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10712         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10713                               port_dst, RTE_UINT16);
10714
10715 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10716         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10717                                  mode, "mode");
10718 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10719         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10720                                  mode_value, "IP");
10721 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10722         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10723                                  mode_value, "MAC-VLAN");
10724 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10725         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10726                                  mode_value, "Tunnel");
10727 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10728         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10729                                  mac, "mac");
10730 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10731         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10732                               mac_addr_byte_mask, RTE_UINT8);
10733 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10734         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10735                                  tunnel_type, "tunnel-type");
10736 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10737         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10738                               tunnel_type_mask, RTE_UINT8);
10739 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10740         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10741                                  tunnel_id, "tunnel-id");
10742 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10743         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10744                               tunnel_id_mask, RTE_UINT32);
10745
10746 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10747         .f = cmd_flow_director_mask_parsed,
10748         .data = NULL,
10749         .help_str = "flow_director_mask ... : "
10750                 "Set IP mode flow director's mask on NIC",
10751         .tokens = {
10752                 (void *)&cmd_flow_director_mask,
10753                 (void *)&cmd_flow_director_mask_port_id,
10754                 (void *)&cmd_flow_director_mask_mode,
10755                 (void *)&cmd_flow_director_mask_mode_ip,
10756                 (void *)&cmd_flow_director_mask_vlan,
10757                 (void *)&cmd_flow_director_mask_vlan_value,
10758                 (void *)&cmd_flow_director_mask_src,
10759                 (void *)&cmd_flow_director_mask_ipv4_src,
10760                 (void *)&cmd_flow_director_mask_ipv6_src,
10761                 (void *)&cmd_flow_director_mask_port_src,
10762                 (void *)&cmd_flow_director_mask_dst,
10763                 (void *)&cmd_flow_director_mask_ipv4_dst,
10764                 (void *)&cmd_flow_director_mask_ipv6_dst,
10765                 (void *)&cmd_flow_director_mask_port_dst,
10766                 NULL,
10767         },
10768 };
10769
10770 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10771         .f = cmd_flow_director_mask_parsed,
10772         .data = NULL,
10773         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10774                 "flow director's mask on NIC",
10775         .tokens = {
10776                 (void *)&cmd_flow_director_mask,
10777                 (void *)&cmd_flow_director_mask_port_id,
10778                 (void *)&cmd_flow_director_mask_mode,
10779                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10780                 (void *)&cmd_flow_director_mask_vlan,
10781                 (void *)&cmd_flow_director_mask_vlan_value,
10782                 NULL,
10783         },
10784 };
10785
10786 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10787         .f = cmd_flow_director_mask_parsed,
10788         .data = NULL,
10789         .help_str = "flow_director_mask ... : Set tunnel mode "
10790                 "flow director's mask on NIC",
10791         .tokens = {
10792                 (void *)&cmd_flow_director_mask,
10793                 (void *)&cmd_flow_director_mask_port_id,
10794                 (void *)&cmd_flow_director_mask_mode,
10795                 (void *)&cmd_flow_director_mask_mode_tunnel,
10796                 (void *)&cmd_flow_director_mask_vlan,
10797                 (void *)&cmd_flow_director_mask_vlan_value,
10798                 (void *)&cmd_flow_director_mask_mac,
10799                 (void *)&cmd_flow_director_mask_mac_value,
10800                 (void *)&cmd_flow_director_mask_tunnel_type,
10801                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10802                 (void *)&cmd_flow_director_mask_tunnel_id,
10803                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10804                 NULL,
10805         },
10806 };
10807
10808 /* *** deal with flow director flexible payload configuration *** */
10809 struct cmd_flow_director_flexpayload_result {
10810         cmdline_fixed_string_t flow_director_flexpayload;
10811         portid_t port_id;
10812         cmdline_fixed_string_t payload_layer;
10813         cmdline_fixed_string_t payload_cfg;
10814 };
10815
10816 static inline int
10817 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10818 {
10819         char s[256];
10820         const char *p, *p0 = q_arg;
10821         char *end;
10822         unsigned long int_fld;
10823         char *str_fld[max_num];
10824         int i;
10825         unsigned size;
10826         int ret = -1;
10827
10828         p = strchr(p0, '(');
10829         if (p == NULL)
10830                 return -1;
10831         ++p;
10832         p0 = strchr(p, ')');
10833         if (p0 == NULL)
10834                 return -1;
10835
10836         size = p0 - p;
10837         if (size >= sizeof(s))
10838                 return -1;
10839
10840         snprintf(s, sizeof(s), "%.*s", size, p);
10841         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10842         if (ret < 0 || ret > max_num)
10843                 return -1;
10844         for (i = 0; i < ret; i++) {
10845                 errno = 0;
10846                 int_fld = strtoul(str_fld[i], &end, 0);
10847                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10848                         return -1;
10849                 offsets[i] = (uint16_t)int_fld;
10850         }
10851         return ret;
10852 }
10853
10854 static void
10855 cmd_flow_director_flxpld_parsed(void *parsed_result,
10856                           __rte_unused struct cmdline *cl,
10857                           __rte_unused void *data)
10858 {
10859         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10860         struct rte_eth_flex_payload_cfg flex_cfg;
10861         struct rte_port *port;
10862         int ret = 0;
10863
10864         port = &ports[res->port_id];
10865         /** Check if the port is not started **/
10866         if (port->port_status != RTE_PORT_STOPPED) {
10867                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10868                 return;
10869         }
10870
10871         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10872
10873         if (!strcmp(res->payload_layer, "raw"))
10874                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10875         else if (!strcmp(res->payload_layer, "l2"))
10876                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10877         else if (!strcmp(res->payload_layer, "l3"))
10878                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10879         else if (!strcmp(res->payload_layer, "l4"))
10880                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10881
10882         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10883                             RTE_ETH_FDIR_MAX_FLEXLEN);
10884         if (ret < 0) {
10885                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
10886                 return;
10887         }
10888
10889         fdir_set_flex_payload(res->port_id, &flex_cfg);
10890         cmd_reconfig_device_queue(res->port_id, 1, 1);
10891 }
10892
10893 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10894         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10895                                  flow_director_flexpayload,
10896                                  "flow_director_flex_payload");
10897 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10898         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10899                               port_id, RTE_UINT16);
10900 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10901         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10902                                  payload_layer, "raw#l2#l3#l4");
10903 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10904         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10905                                  payload_cfg, NULL);
10906
10907 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10908         .f = cmd_flow_director_flxpld_parsed,
10909         .data = NULL,
10910         .help_str = "flow_director_flexpayload ... : "
10911                 "Set flow director's flex payload on NIC",
10912         .tokens = {
10913                 (void *)&cmd_flow_director_flexpayload,
10914                 (void *)&cmd_flow_director_flexpayload_port_id,
10915                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10916                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10917                 NULL,
10918         },
10919 };
10920
10921 /* Generic flow interface command. */
10922 extern cmdline_parse_inst_t cmd_flow;
10923
10924 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10925 struct cmd_mcast_addr_result {
10926         cmdline_fixed_string_t mcast_addr_cmd;
10927         cmdline_fixed_string_t what;
10928         uint16_t port_num;
10929         struct rte_ether_addr mc_addr;
10930 };
10931
10932 static void cmd_mcast_addr_parsed(void *parsed_result,
10933                 __rte_unused struct cmdline *cl,
10934                 __rte_unused void *data)
10935 {
10936         struct cmd_mcast_addr_result *res = parsed_result;
10937
10938         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10939                 fprintf(stderr,
10940                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
10941                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
10942                 return;
10943         }
10944         if (strcmp(res->what, "add") == 0)
10945                 mcast_addr_add(res->port_num, &res->mc_addr);
10946         else
10947                 mcast_addr_remove(res->port_num, &res->mc_addr);
10948 }
10949
10950 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10951         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10952                                  mcast_addr_cmd, "mcast_addr");
10953 cmdline_parse_token_string_t cmd_mcast_addr_what =
10954         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10955                                  "add#remove");
10956 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10957         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10958                                  RTE_UINT16);
10959 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10960         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10961
10962 cmdline_parse_inst_t cmd_mcast_addr = {
10963         .f = cmd_mcast_addr_parsed,
10964         .data = (void *)0,
10965         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10966                 "Add/Remove multicast MAC address on port_id",
10967         .tokens = {
10968                 (void *)&cmd_mcast_addr_cmd,
10969                 (void *)&cmd_mcast_addr_what,
10970                 (void *)&cmd_mcast_addr_portnum,
10971                 (void *)&cmd_mcast_addr_addr,
10972                 NULL,
10973         },
10974 };
10975
10976 /* vf vlan anti spoof configuration */
10977
10978 /* Common result structure for vf vlan anti spoof */
10979 struct cmd_vf_vlan_anti_spoof_result {
10980         cmdline_fixed_string_t set;
10981         cmdline_fixed_string_t vf;
10982         cmdline_fixed_string_t vlan;
10983         cmdline_fixed_string_t antispoof;
10984         portid_t port_id;
10985         uint32_t vf_id;
10986         cmdline_fixed_string_t on_off;
10987 };
10988
10989 /* Common CLI fields for vf vlan anti spoof enable disable */
10990 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10991         TOKEN_STRING_INITIALIZER
10992                 (struct cmd_vf_vlan_anti_spoof_result,
10993                  set, "set");
10994 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10995         TOKEN_STRING_INITIALIZER
10996                 (struct cmd_vf_vlan_anti_spoof_result,
10997                  vf, "vf");
10998 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
10999         TOKEN_STRING_INITIALIZER
11000                 (struct cmd_vf_vlan_anti_spoof_result,
11001                  vlan, "vlan");
11002 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11003         TOKEN_STRING_INITIALIZER
11004                 (struct cmd_vf_vlan_anti_spoof_result,
11005                  antispoof, "antispoof");
11006 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11007         TOKEN_NUM_INITIALIZER
11008                 (struct cmd_vf_vlan_anti_spoof_result,
11009                  port_id, RTE_UINT16);
11010 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11011         TOKEN_NUM_INITIALIZER
11012                 (struct cmd_vf_vlan_anti_spoof_result,
11013                  vf_id, RTE_UINT32);
11014 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11015         TOKEN_STRING_INITIALIZER
11016                 (struct cmd_vf_vlan_anti_spoof_result,
11017                  on_off, "on#off");
11018
11019 static void
11020 cmd_set_vf_vlan_anti_spoof_parsed(
11021         void *parsed_result,
11022         __rte_unused struct cmdline *cl,
11023         __rte_unused void *data)
11024 {
11025         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11026         int ret = -ENOTSUP;
11027
11028         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11029
11030         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11031                 return;
11032
11033 #ifdef RTE_NET_IXGBE
11034         if (ret == -ENOTSUP)
11035                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11036                                 res->vf_id, is_on);
11037 #endif
11038 #ifdef RTE_NET_I40E
11039         if (ret == -ENOTSUP)
11040                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11041                                 res->vf_id, is_on);
11042 #endif
11043 #ifdef RTE_NET_BNXT
11044         if (ret == -ENOTSUP)
11045                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11046                                 res->vf_id, is_on);
11047 #endif
11048
11049         switch (ret) {
11050         case 0:
11051                 break;
11052         case -EINVAL:
11053                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11054                 break;
11055         case -ENODEV:
11056                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11057                 break;
11058         case -ENOTSUP:
11059                 fprintf(stderr, "function not implemented\n");
11060                 break;
11061         default:
11062                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11063         }
11064 }
11065
11066 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11067         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11068         .data = NULL,
11069         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11070         .tokens = {
11071                 (void *)&cmd_vf_vlan_anti_spoof_set,
11072                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11073                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11074                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11075                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11076                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11077                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11078                 NULL,
11079         },
11080 };
11081
11082 /* vf mac anti spoof configuration */
11083
11084 /* Common result structure for vf mac anti spoof */
11085 struct cmd_vf_mac_anti_spoof_result {
11086         cmdline_fixed_string_t set;
11087         cmdline_fixed_string_t vf;
11088         cmdline_fixed_string_t mac;
11089         cmdline_fixed_string_t antispoof;
11090         portid_t port_id;
11091         uint32_t vf_id;
11092         cmdline_fixed_string_t on_off;
11093 };
11094
11095 /* Common CLI fields for vf mac anti spoof enable disable */
11096 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11097         TOKEN_STRING_INITIALIZER
11098                 (struct cmd_vf_mac_anti_spoof_result,
11099                  set, "set");
11100 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11101         TOKEN_STRING_INITIALIZER
11102                 (struct cmd_vf_mac_anti_spoof_result,
11103                  vf, "vf");
11104 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11105         TOKEN_STRING_INITIALIZER
11106                 (struct cmd_vf_mac_anti_spoof_result,
11107                  mac, "mac");
11108 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11109         TOKEN_STRING_INITIALIZER
11110                 (struct cmd_vf_mac_anti_spoof_result,
11111                  antispoof, "antispoof");
11112 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11113         TOKEN_NUM_INITIALIZER
11114                 (struct cmd_vf_mac_anti_spoof_result,
11115                  port_id, RTE_UINT16);
11116 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11117         TOKEN_NUM_INITIALIZER
11118                 (struct cmd_vf_mac_anti_spoof_result,
11119                  vf_id, RTE_UINT32);
11120 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11121         TOKEN_STRING_INITIALIZER
11122                 (struct cmd_vf_mac_anti_spoof_result,
11123                  on_off, "on#off");
11124
11125 static void
11126 cmd_set_vf_mac_anti_spoof_parsed(
11127         void *parsed_result,
11128         __rte_unused struct cmdline *cl,
11129         __rte_unused void *data)
11130 {
11131         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11132         int ret = -ENOTSUP;
11133
11134         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11135
11136         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11137                 return;
11138
11139 #ifdef RTE_NET_IXGBE
11140         if (ret == -ENOTSUP)
11141                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11142                         res->vf_id, is_on);
11143 #endif
11144 #ifdef RTE_NET_I40E
11145         if (ret == -ENOTSUP)
11146                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11147                         res->vf_id, is_on);
11148 #endif
11149 #ifdef RTE_NET_BNXT
11150         if (ret == -ENOTSUP)
11151                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11152                         res->vf_id, is_on);
11153 #endif
11154
11155         switch (ret) {
11156         case 0:
11157                 break;
11158         case -EINVAL:
11159                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11160                         res->vf_id, is_on);
11161                 break;
11162         case -ENODEV:
11163                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11164                 break;
11165         case -ENOTSUP:
11166                 fprintf(stderr, "function not implemented\n");
11167                 break;
11168         default:
11169                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11170         }
11171 }
11172
11173 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11174         .f = cmd_set_vf_mac_anti_spoof_parsed,
11175         .data = NULL,
11176         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11177         .tokens = {
11178                 (void *)&cmd_vf_mac_anti_spoof_set,
11179                 (void *)&cmd_vf_mac_anti_spoof_vf,
11180                 (void *)&cmd_vf_mac_anti_spoof_mac,
11181                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11182                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11183                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11184                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11185                 NULL,
11186         },
11187 };
11188
11189 /* vf vlan strip queue configuration */
11190
11191 /* Common result structure for vf mac anti spoof */
11192 struct cmd_vf_vlan_stripq_result {
11193         cmdline_fixed_string_t set;
11194         cmdline_fixed_string_t vf;
11195         cmdline_fixed_string_t vlan;
11196         cmdline_fixed_string_t stripq;
11197         portid_t port_id;
11198         uint16_t vf_id;
11199         cmdline_fixed_string_t on_off;
11200 };
11201
11202 /* Common CLI fields for vf vlan strip enable disable */
11203 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11204         TOKEN_STRING_INITIALIZER
11205                 (struct cmd_vf_vlan_stripq_result,
11206                  set, "set");
11207 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11208         TOKEN_STRING_INITIALIZER
11209                 (struct cmd_vf_vlan_stripq_result,
11210                  vf, "vf");
11211 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11212         TOKEN_STRING_INITIALIZER
11213                 (struct cmd_vf_vlan_stripq_result,
11214                  vlan, "vlan");
11215 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11216         TOKEN_STRING_INITIALIZER
11217                 (struct cmd_vf_vlan_stripq_result,
11218                  stripq, "stripq");
11219 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11220         TOKEN_NUM_INITIALIZER
11221                 (struct cmd_vf_vlan_stripq_result,
11222                  port_id, RTE_UINT16);
11223 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11224         TOKEN_NUM_INITIALIZER
11225                 (struct cmd_vf_vlan_stripq_result,
11226                  vf_id, RTE_UINT16);
11227 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11228         TOKEN_STRING_INITIALIZER
11229                 (struct cmd_vf_vlan_stripq_result,
11230                  on_off, "on#off");
11231
11232 static void
11233 cmd_set_vf_vlan_stripq_parsed(
11234         void *parsed_result,
11235         __rte_unused struct cmdline *cl,
11236         __rte_unused void *data)
11237 {
11238         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11239         int ret = -ENOTSUP;
11240
11241         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11242
11243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11244                 return;
11245
11246 #ifdef RTE_NET_IXGBE
11247         if (ret == -ENOTSUP)
11248                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11249                         res->vf_id, is_on);
11250 #endif
11251 #ifdef RTE_NET_I40E
11252         if (ret == -ENOTSUP)
11253                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11254                         res->vf_id, is_on);
11255 #endif
11256 #ifdef RTE_NET_BNXT
11257         if (ret == -ENOTSUP)
11258                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11259                         res->vf_id, is_on);
11260 #endif
11261
11262         switch (ret) {
11263         case 0:
11264                 break;
11265         case -EINVAL:
11266                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11267                         res->vf_id, is_on);
11268                 break;
11269         case -ENODEV:
11270                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11271                 break;
11272         case -ENOTSUP:
11273                 fprintf(stderr, "function not implemented\n");
11274                 break;
11275         default:
11276                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11277         }
11278 }
11279
11280 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11281         .f = cmd_set_vf_vlan_stripq_parsed,
11282         .data = NULL,
11283         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11284         .tokens = {
11285                 (void *)&cmd_vf_vlan_stripq_set,
11286                 (void *)&cmd_vf_vlan_stripq_vf,
11287                 (void *)&cmd_vf_vlan_stripq_vlan,
11288                 (void *)&cmd_vf_vlan_stripq_stripq,
11289                 (void *)&cmd_vf_vlan_stripq_port_id,
11290                 (void *)&cmd_vf_vlan_stripq_vf_id,
11291                 (void *)&cmd_vf_vlan_stripq_on_off,
11292                 NULL,
11293         },
11294 };
11295
11296 /* vf vlan insert configuration */
11297
11298 /* Common result structure for vf vlan insert */
11299 struct cmd_vf_vlan_insert_result {
11300         cmdline_fixed_string_t set;
11301         cmdline_fixed_string_t vf;
11302         cmdline_fixed_string_t vlan;
11303         cmdline_fixed_string_t insert;
11304         portid_t port_id;
11305         uint16_t vf_id;
11306         uint16_t vlan_id;
11307 };
11308
11309 /* Common CLI fields for vf vlan insert enable disable */
11310 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11311         TOKEN_STRING_INITIALIZER
11312                 (struct cmd_vf_vlan_insert_result,
11313                  set, "set");
11314 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11315         TOKEN_STRING_INITIALIZER
11316                 (struct cmd_vf_vlan_insert_result,
11317                  vf, "vf");
11318 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11319         TOKEN_STRING_INITIALIZER
11320                 (struct cmd_vf_vlan_insert_result,
11321                  vlan, "vlan");
11322 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11323         TOKEN_STRING_INITIALIZER
11324                 (struct cmd_vf_vlan_insert_result,
11325                  insert, "insert");
11326 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11327         TOKEN_NUM_INITIALIZER
11328                 (struct cmd_vf_vlan_insert_result,
11329                  port_id, RTE_UINT16);
11330 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11331         TOKEN_NUM_INITIALIZER
11332                 (struct cmd_vf_vlan_insert_result,
11333                  vf_id, RTE_UINT16);
11334 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11335         TOKEN_NUM_INITIALIZER
11336                 (struct cmd_vf_vlan_insert_result,
11337                  vlan_id, RTE_UINT16);
11338
11339 static void
11340 cmd_set_vf_vlan_insert_parsed(
11341         void *parsed_result,
11342         __rte_unused struct cmdline *cl,
11343         __rte_unused void *data)
11344 {
11345         struct cmd_vf_vlan_insert_result *res = parsed_result;
11346         int ret = -ENOTSUP;
11347
11348         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11349                 return;
11350
11351 #ifdef RTE_NET_IXGBE
11352         if (ret == -ENOTSUP)
11353                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11354                         res->vlan_id);
11355 #endif
11356 #ifdef RTE_NET_I40E
11357         if (ret == -ENOTSUP)
11358                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11359                         res->vlan_id);
11360 #endif
11361 #ifdef RTE_NET_BNXT
11362         if (ret == -ENOTSUP)
11363                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11364                         res->vlan_id);
11365 #endif
11366
11367         switch (ret) {
11368         case 0:
11369                 break;
11370         case -EINVAL:
11371                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11372                         res->vf_id, res->vlan_id);
11373                 break;
11374         case -ENODEV:
11375                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11376                 break;
11377         case -ENOTSUP:
11378                 fprintf(stderr, "function not implemented\n");
11379                 break;
11380         default:
11381                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11382         }
11383 }
11384
11385 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11386         .f = cmd_set_vf_vlan_insert_parsed,
11387         .data = NULL,
11388         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11389         .tokens = {
11390                 (void *)&cmd_vf_vlan_insert_set,
11391                 (void *)&cmd_vf_vlan_insert_vf,
11392                 (void *)&cmd_vf_vlan_insert_vlan,
11393                 (void *)&cmd_vf_vlan_insert_insert,
11394                 (void *)&cmd_vf_vlan_insert_port_id,
11395                 (void *)&cmd_vf_vlan_insert_vf_id,
11396                 (void *)&cmd_vf_vlan_insert_vlan_id,
11397                 NULL,
11398         },
11399 };
11400
11401 /* tx loopback configuration */
11402
11403 /* Common result structure for tx loopback */
11404 struct cmd_tx_loopback_result {
11405         cmdline_fixed_string_t set;
11406         cmdline_fixed_string_t tx;
11407         cmdline_fixed_string_t loopback;
11408         portid_t port_id;
11409         cmdline_fixed_string_t on_off;
11410 };
11411
11412 /* Common CLI fields for tx loopback enable disable */
11413 cmdline_parse_token_string_t cmd_tx_loopback_set =
11414         TOKEN_STRING_INITIALIZER
11415                 (struct cmd_tx_loopback_result,
11416                  set, "set");
11417 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11418         TOKEN_STRING_INITIALIZER
11419                 (struct cmd_tx_loopback_result,
11420                  tx, "tx");
11421 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11422         TOKEN_STRING_INITIALIZER
11423                 (struct cmd_tx_loopback_result,
11424                  loopback, "loopback");
11425 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11426         TOKEN_NUM_INITIALIZER
11427                 (struct cmd_tx_loopback_result,
11428                  port_id, RTE_UINT16);
11429 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11430         TOKEN_STRING_INITIALIZER
11431                 (struct cmd_tx_loopback_result,
11432                  on_off, "on#off");
11433
11434 static void
11435 cmd_set_tx_loopback_parsed(
11436         void *parsed_result,
11437         __rte_unused struct cmdline *cl,
11438         __rte_unused void *data)
11439 {
11440         struct cmd_tx_loopback_result *res = parsed_result;
11441         int ret = -ENOTSUP;
11442
11443         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11444
11445         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11446                 return;
11447
11448 #ifdef RTE_NET_IXGBE
11449         if (ret == -ENOTSUP)
11450                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11451 #endif
11452 #ifdef RTE_NET_I40E
11453         if (ret == -ENOTSUP)
11454                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11455 #endif
11456 #ifdef RTE_NET_BNXT
11457         if (ret == -ENOTSUP)
11458                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11459 #endif
11460 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11461         if (ret == -ENOTSUP)
11462                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11463 #endif
11464
11465         switch (ret) {
11466         case 0:
11467                 break;
11468         case -EINVAL:
11469                 fprintf(stderr, "invalid is_on %d\n", is_on);
11470                 break;
11471         case -ENODEV:
11472                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11473                 break;
11474         case -ENOTSUP:
11475                 fprintf(stderr, "function not implemented\n");
11476                 break;
11477         default:
11478                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11479         }
11480 }
11481
11482 cmdline_parse_inst_t cmd_set_tx_loopback = {
11483         .f = cmd_set_tx_loopback_parsed,
11484         .data = NULL,
11485         .help_str = "set tx loopback <port_id> on|off",
11486         .tokens = {
11487                 (void *)&cmd_tx_loopback_set,
11488                 (void *)&cmd_tx_loopback_tx,
11489                 (void *)&cmd_tx_loopback_loopback,
11490                 (void *)&cmd_tx_loopback_port_id,
11491                 (void *)&cmd_tx_loopback_on_off,
11492                 NULL,
11493         },
11494 };
11495
11496 /* all queues drop enable configuration */
11497
11498 /* Common result structure for all queues drop enable */
11499 struct cmd_all_queues_drop_en_result {
11500         cmdline_fixed_string_t set;
11501         cmdline_fixed_string_t all;
11502         cmdline_fixed_string_t queues;
11503         cmdline_fixed_string_t drop;
11504         portid_t port_id;
11505         cmdline_fixed_string_t on_off;
11506 };
11507
11508 /* Common CLI fields for tx loopback enable disable */
11509 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11510         TOKEN_STRING_INITIALIZER
11511                 (struct cmd_all_queues_drop_en_result,
11512                  set, "set");
11513 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11514         TOKEN_STRING_INITIALIZER
11515                 (struct cmd_all_queues_drop_en_result,
11516                  all, "all");
11517 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11518         TOKEN_STRING_INITIALIZER
11519                 (struct cmd_all_queues_drop_en_result,
11520                  queues, "queues");
11521 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_all_queues_drop_en_result,
11524                  drop, "drop");
11525 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11526         TOKEN_NUM_INITIALIZER
11527                 (struct cmd_all_queues_drop_en_result,
11528                  port_id, RTE_UINT16);
11529 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11530         TOKEN_STRING_INITIALIZER
11531                 (struct cmd_all_queues_drop_en_result,
11532                  on_off, "on#off");
11533
11534 static void
11535 cmd_set_all_queues_drop_en_parsed(
11536         void *parsed_result,
11537         __rte_unused struct cmdline *cl,
11538         __rte_unused void *data)
11539 {
11540         struct cmd_all_queues_drop_en_result *res = parsed_result;
11541         int ret = -ENOTSUP;
11542         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11543
11544         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11545                 return;
11546
11547 #ifdef RTE_NET_IXGBE
11548         if (ret == -ENOTSUP)
11549                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11550 #endif
11551 #ifdef RTE_NET_BNXT
11552         if (ret == -ENOTSUP)
11553                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11554 #endif
11555         switch (ret) {
11556         case 0:
11557                 break;
11558         case -EINVAL:
11559                 fprintf(stderr, "invalid is_on %d\n", is_on);
11560                 break;
11561         case -ENODEV:
11562                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11563                 break;
11564         case -ENOTSUP:
11565                 fprintf(stderr, "function not implemented\n");
11566                 break;
11567         default:
11568                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11569         }
11570 }
11571
11572 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11573         .f = cmd_set_all_queues_drop_en_parsed,
11574         .data = NULL,
11575         .help_str = "set all queues drop <port_id> on|off",
11576         .tokens = {
11577                 (void *)&cmd_all_queues_drop_en_set,
11578                 (void *)&cmd_all_queues_drop_en_all,
11579                 (void *)&cmd_all_queues_drop_en_queues,
11580                 (void *)&cmd_all_queues_drop_en_drop,
11581                 (void *)&cmd_all_queues_drop_en_port_id,
11582                 (void *)&cmd_all_queues_drop_en_on_off,
11583                 NULL,
11584         },
11585 };
11586
11587 /* vf split drop enable configuration */
11588
11589 /* Common result structure for vf split drop enable */
11590 struct cmd_vf_split_drop_en_result {
11591         cmdline_fixed_string_t set;
11592         cmdline_fixed_string_t vf;
11593         cmdline_fixed_string_t split;
11594         cmdline_fixed_string_t drop;
11595         portid_t port_id;
11596         uint16_t vf_id;
11597         cmdline_fixed_string_t on_off;
11598 };
11599
11600 /* Common CLI fields for vf split drop enable disable */
11601 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11602         TOKEN_STRING_INITIALIZER
11603                 (struct cmd_vf_split_drop_en_result,
11604                  set, "set");
11605 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11606         TOKEN_STRING_INITIALIZER
11607                 (struct cmd_vf_split_drop_en_result,
11608                  vf, "vf");
11609 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11610         TOKEN_STRING_INITIALIZER
11611                 (struct cmd_vf_split_drop_en_result,
11612                  split, "split");
11613 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11614         TOKEN_STRING_INITIALIZER
11615                 (struct cmd_vf_split_drop_en_result,
11616                  drop, "drop");
11617 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11618         TOKEN_NUM_INITIALIZER
11619                 (struct cmd_vf_split_drop_en_result,
11620                  port_id, RTE_UINT16);
11621 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11622         TOKEN_NUM_INITIALIZER
11623                 (struct cmd_vf_split_drop_en_result,
11624                  vf_id, RTE_UINT16);
11625 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11626         TOKEN_STRING_INITIALIZER
11627                 (struct cmd_vf_split_drop_en_result,
11628                  on_off, "on#off");
11629
11630 static void
11631 cmd_set_vf_split_drop_en_parsed(
11632         void *parsed_result,
11633         __rte_unused struct cmdline *cl,
11634         __rte_unused void *data)
11635 {
11636         struct cmd_vf_split_drop_en_result *res = parsed_result;
11637         int ret = -ENOTSUP;
11638         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11639
11640         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11641                 return;
11642
11643 #ifdef RTE_NET_IXGBE
11644         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11645                         is_on);
11646 #endif
11647         switch (ret) {
11648         case 0:
11649                 break;
11650         case -EINVAL:
11651                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11652                         res->vf_id, is_on);
11653                 break;
11654         case -ENODEV:
11655                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11656                 break;
11657         case -ENOTSUP:
11658                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11659                 break;
11660         default:
11661                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11662         }
11663 }
11664
11665 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11666         .f = cmd_set_vf_split_drop_en_parsed,
11667         .data = NULL,
11668         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11669         .tokens = {
11670                 (void *)&cmd_vf_split_drop_en_set,
11671                 (void *)&cmd_vf_split_drop_en_vf,
11672                 (void *)&cmd_vf_split_drop_en_split,
11673                 (void *)&cmd_vf_split_drop_en_drop,
11674                 (void *)&cmd_vf_split_drop_en_port_id,
11675                 (void *)&cmd_vf_split_drop_en_vf_id,
11676                 (void *)&cmd_vf_split_drop_en_on_off,
11677                 NULL,
11678         },
11679 };
11680
11681 /* vf mac address configuration */
11682
11683 /* Common result structure for vf mac address */
11684 struct cmd_set_vf_mac_addr_result {
11685         cmdline_fixed_string_t set;
11686         cmdline_fixed_string_t vf;
11687         cmdline_fixed_string_t mac;
11688         cmdline_fixed_string_t addr;
11689         portid_t port_id;
11690         uint16_t vf_id;
11691         struct rte_ether_addr mac_addr;
11692
11693 };
11694
11695 /* Common CLI fields for vf split drop enable disable */
11696 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11697         TOKEN_STRING_INITIALIZER
11698                 (struct cmd_set_vf_mac_addr_result,
11699                  set, "set");
11700 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_set_vf_mac_addr_result,
11703                  vf, "vf");
11704 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11705         TOKEN_STRING_INITIALIZER
11706                 (struct cmd_set_vf_mac_addr_result,
11707                  mac, "mac");
11708 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11709         TOKEN_STRING_INITIALIZER
11710                 (struct cmd_set_vf_mac_addr_result,
11711                  addr, "addr");
11712 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11713         TOKEN_NUM_INITIALIZER
11714                 (struct cmd_set_vf_mac_addr_result,
11715                  port_id, RTE_UINT16);
11716 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11717         TOKEN_NUM_INITIALIZER
11718                 (struct cmd_set_vf_mac_addr_result,
11719                  vf_id, RTE_UINT16);
11720 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11721         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11722                  mac_addr);
11723
11724 static void
11725 cmd_set_vf_mac_addr_parsed(
11726         void *parsed_result,
11727         __rte_unused struct cmdline *cl,
11728         __rte_unused void *data)
11729 {
11730         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11731         int ret = -ENOTSUP;
11732
11733         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11734                 return;
11735
11736 #ifdef RTE_NET_IXGBE
11737         if (ret == -ENOTSUP)
11738                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11739                                 &res->mac_addr);
11740 #endif
11741 #ifdef RTE_NET_I40E
11742         if (ret == -ENOTSUP)
11743                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11744                                 &res->mac_addr);
11745 #endif
11746 #ifdef RTE_NET_BNXT
11747         if (ret == -ENOTSUP)
11748                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11749                                 &res->mac_addr);
11750 #endif
11751
11752         switch (ret) {
11753         case 0:
11754                 break;
11755         case -EINVAL:
11756                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11757                 break;
11758         case -ENODEV:
11759                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11760                 break;
11761         case -ENOTSUP:
11762                 fprintf(stderr, "function not implemented\n");
11763                 break;
11764         default:
11765                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11766         }
11767 }
11768
11769 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11770         .f = cmd_set_vf_mac_addr_parsed,
11771         .data = NULL,
11772         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11773         .tokens = {
11774                 (void *)&cmd_set_vf_mac_addr_set,
11775                 (void *)&cmd_set_vf_mac_addr_vf,
11776                 (void *)&cmd_set_vf_mac_addr_mac,
11777                 (void *)&cmd_set_vf_mac_addr_addr,
11778                 (void *)&cmd_set_vf_mac_addr_port_id,
11779                 (void *)&cmd_set_vf_mac_addr_vf_id,
11780                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11781                 NULL,
11782         },
11783 };
11784
11785 /* MACsec configuration */
11786
11787 /* Common result structure for MACsec offload enable */
11788 struct cmd_macsec_offload_on_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 on;
11794         cmdline_fixed_string_t encrypt;
11795         cmdline_fixed_string_t en_on_off;
11796         cmdline_fixed_string_t replay_protect;
11797         cmdline_fixed_string_t rp_on_off;
11798 };
11799
11800 /* Common CLI fields for MACsec offload disable */
11801 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_macsec_offload_on_result,
11804                  set, "set");
11805 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_macsec_offload_on_result,
11808                  macsec, "macsec");
11809 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_macsec_offload_on_result,
11812                  offload, "offload");
11813 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11814         TOKEN_NUM_INITIALIZER
11815                 (struct cmd_macsec_offload_on_result,
11816                  port_id, RTE_UINT16);
11817 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11818         TOKEN_STRING_INITIALIZER
11819                 (struct cmd_macsec_offload_on_result,
11820                  on, "on");
11821 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_macsec_offload_on_result,
11824                  encrypt, "encrypt");
11825 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11826         TOKEN_STRING_INITIALIZER
11827                 (struct cmd_macsec_offload_on_result,
11828                  en_on_off, "on#off");
11829 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11830         TOKEN_STRING_INITIALIZER
11831                 (struct cmd_macsec_offload_on_result,
11832                  replay_protect, "replay-protect");
11833 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11834         TOKEN_STRING_INITIALIZER
11835                 (struct cmd_macsec_offload_on_result,
11836                  rp_on_off, "on#off");
11837
11838 static void
11839 cmd_set_macsec_offload_on_parsed(
11840         void *parsed_result,
11841         __rte_unused struct cmdline *cl,
11842         __rte_unused void *data)
11843 {
11844         struct cmd_macsec_offload_on_result *res = parsed_result;
11845         int ret = -ENOTSUP;
11846         portid_t port_id = res->port_id;
11847         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11848         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11849         struct rte_eth_dev_info dev_info;
11850
11851         if (port_id_is_invalid(port_id, ENABLED_WARN))
11852                 return;
11853         if (!port_is_stopped(port_id)) {
11854                 fprintf(stderr, "Please stop port %d first\n", port_id);
11855                 return;
11856         }
11857
11858         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11859         if (ret != 0)
11860                 return;
11861
11862         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11863 #ifdef RTE_NET_IXGBE
11864                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11865 #endif
11866         }
11867         RTE_SET_USED(en);
11868         RTE_SET_USED(rp);
11869
11870         switch (ret) {
11871         case 0:
11872                 ports[port_id].dev_conf.txmode.offloads |=
11873                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
11874                 cmd_reconfig_device_queue(port_id, 1, 1);
11875                 break;
11876         case -ENODEV:
11877                 fprintf(stderr, "invalid port_id %d\n", port_id);
11878                 break;
11879         case -ENOTSUP:
11880                 fprintf(stderr, "not supported on port %d\n", port_id);
11881                 break;
11882         default:
11883                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11884         }
11885 }
11886
11887 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11888         .f = cmd_set_macsec_offload_on_parsed,
11889         .data = NULL,
11890         .help_str = "set macsec offload <port_id> on "
11891                 "encrypt on|off replay-protect on|off",
11892         .tokens = {
11893                 (void *)&cmd_macsec_offload_on_set,
11894                 (void *)&cmd_macsec_offload_on_macsec,
11895                 (void *)&cmd_macsec_offload_on_offload,
11896                 (void *)&cmd_macsec_offload_on_port_id,
11897                 (void *)&cmd_macsec_offload_on_on,
11898                 (void *)&cmd_macsec_offload_on_encrypt,
11899                 (void *)&cmd_macsec_offload_on_en_on_off,
11900                 (void *)&cmd_macsec_offload_on_replay_protect,
11901                 (void *)&cmd_macsec_offload_on_rp_on_off,
11902                 NULL,
11903         },
11904 };
11905
11906 /* Common result structure for MACsec offload disable */
11907 struct cmd_macsec_offload_off_result {
11908         cmdline_fixed_string_t set;
11909         cmdline_fixed_string_t macsec;
11910         cmdline_fixed_string_t offload;
11911         portid_t port_id;
11912         cmdline_fixed_string_t off;
11913 };
11914
11915 /* Common CLI fields for MACsec offload disable */
11916 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11917         TOKEN_STRING_INITIALIZER
11918                 (struct cmd_macsec_offload_off_result,
11919                  set, "set");
11920 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11921         TOKEN_STRING_INITIALIZER
11922                 (struct cmd_macsec_offload_off_result,
11923                  macsec, "macsec");
11924 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11925         TOKEN_STRING_INITIALIZER
11926                 (struct cmd_macsec_offload_off_result,
11927                  offload, "offload");
11928 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11929         TOKEN_NUM_INITIALIZER
11930                 (struct cmd_macsec_offload_off_result,
11931                  port_id, RTE_UINT16);
11932 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11933         TOKEN_STRING_INITIALIZER
11934                 (struct cmd_macsec_offload_off_result,
11935                  off, "off");
11936
11937 static void
11938 cmd_set_macsec_offload_off_parsed(
11939         void *parsed_result,
11940         __rte_unused struct cmdline *cl,
11941         __rte_unused void *data)
11942 {
11943         struct cmd_macsec_offload_off_result *res = parsed_result;
11944         int ret = -ENOTSUP;
11945         struct rte_eth_dev_info dev_info;
11946         portid_t port_id = res->port_id;
11947
11948         if (port_id_is_invalid(port_id, ENABLED_WARN))
11949                 return;
11950         if (!port_is_stopped(port_id)) {
11951                 fprintf(stderr, "Please stop port %d first\n", port_id);
11952                 return;
11953         }
11954
11955         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11956         if (ret != 0)
11957                 return;
11958
11959         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
11960 #ifdef RTE_NET_IXGBE
11961                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11962 #endif
11963         }
11964         switch (ret) {
11965         case 0:
11966                 ports[port_id].dev_conf.txmode.offloads &=
11967                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
11968                 cmd_reconfig_device_queue(port_id, 1, 1);
11969                 break;
11970         case -ENODEV:
11971                 fprintf(stderr, "invalid port_id %d\n", port_id);
11972                 break;
11973         case -ENOTSUP:
11974                 fprintf(stderr, "not supported on port %d\n", port_id);
11975                 break;
11976         default:
11977                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11978         }
11979 }
11980
11981 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11982         .f = cmd_set_macsec_offload_off_parsed,
11983         .data = NULL,
11984         .help_str = "set macsec offload <port_id> off",
11985         .tokens = {
11986                 (void *)&cmd_macsec_offload_off_set,
11987                 (void *)&cmd_macsec_offload_off_macsec,
11988                 (void *)&cmd_macsec_offload_off_offload,
11989                 (void *)&cmd_macsec_offload_off_port_id,
11990                 (void *)&cmd_macsec_offload_off_off,
11991                 NULL,
11992         },
11993 };
11994
11995 /* Common result structure for MACsec secure connection configure */
11996 struct cmd_macsec_sc_result {
11997         cmdline_fixed_string_t set;
11998         cmdline_fixed_string_t macsec;
11999         cmdline_fixed_string_t sc;
12000         cmdline_fixed_string_t tx_rx;
12001         portid_t port_id;
12002         struct rte_ether_addr mac;
12003         uint16_t pi;
12004 };
12005
12006 /* Common CLI fields for MACsec secure connection configure */
12007 cmdline_parse_token_string_t cmd_macsec_sc_set =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_macsec_sc_result,
12010                  set, "set");
12011 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_macsec_sc_result,
12014                  macsec, "macsec");
12015 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_macsec_sc_result,
12018                  sc, "sc");
12019 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12020         TOKEN_STRING_INITIALIZER
12021                 (struct cmd_macsec_sc_result,
12022                  tx_rx, "tx#rx");
12023 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12024         TOKEN_NUM_INITIALIZER
12025                 (struct cmd_macsec_sc_result,
12026                  port_id, RTE_UINT16);
12027 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12028         TOKEN_ETHERADDR_INITIALIZER
12029                 (struct cmd_macsec_sc_result,
12030                  mac);
12031 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12032         TOKEN_NUM_INITIALIZER
12033                 (struct cmd_macsec_sc_result,
12034                  pi, RTE_UINT16);
12035
12036 static void
12037 cmd_set_macsec_sc_parsed(
12038         void *parsed_result,
12039         __rte_unused struct cmdline *cl,
12040         __rte_unused void *data)
12041 {
12042         struct cmd_macsec_sc_result *res = parsed_result;
12043         int ret = -ENOTSUP;
12044         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12045
12046 #ifdef RTE_NET_IXGBE
12047         ret = is_tx ?
12048                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12049                                 res->mac.addr_bytes) :
12050                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12051                                 res->mac.addr_bytes, res->pi);
12052 #endif
12053         RTE_SET_USED(is_tx);
12054
12055         switch (ret) {
12056         case 0:
12057                 break;
12058         case -ENODEV:
12059                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12060                 break;
12061         case -ENOTSUP:
12062                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12063                 break;
12064         default:
12065                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12066         }
12067 }
12068
12069 cmdline_parse_inst_t cmd_set_macsec_sc = {
12070         .f = cmd_set_macsec_sc_parsed,
12071         .data = NULL,
12072         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12073         .tokens = {
12074                 (void *)&cmd_macsec_sc_set,
12075                 (void *)&cmd_macsec_sc_macsec,
12076                 (void *)&cmd_macsec_sc_sc,
12077                 (void *)&cmd_macsec_sc_tx_rx,
12078                 (void *)&cmd_macsec_sc_port_id,
12079                 (void *)&cmd_macsec_sc_mac,
12080                 (void *)&cmd_macsec_sc_pi,
12081                 NULL,
12082         },
12083 };
12084
12085 /* Common result structure for MACsec secure connection configure */
12086 struct cmd_macsec_sa_result {
12087         cmdline_fixed_string_t set;
12088         cmdline_fixed_string_t macsec;
12089         cmdline_fixed_string_t sa;
12090         cmdline_fixed_string_t tx_rx;
12091         portid_t port_id;
12092         uint8_t idx;
12093         uint8_t an;
12094         uint32_t pn;
12095         cmdline_fixed_string_t key;
12096 };
12097
12098 /* Common CLI fields for MACsec secure connection configure */
12099 cmdline_parse_token_string_t cmd_macsec_sa_set =
12100         TOKEN_STRING_INITIALIZER
12101                 (struct cmd_macsec_sa_result,
12102                  set, "set");
12103 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12104         TOKEN_STRING_INITIALIZER
12105                 (struct cmd_macsec_sa_result,
12106                  macsec, "macsec");
12107 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12108         TOKEN_STRING_INITIALIZER
12109                 (struct cmd_macsec_sa_result,
12110                  sa, "sa");
12111 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12112         TOKEN_STRING_INITIALIZER
12113                 (struct cmd_macsec_sa_result,
12114                  tx_rx, "tx#rx");
12115 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12116         TOKEN_NUM_INITIALIZER
12117                 (struct cmd_macsec_sa_result,
12118                  port_id, RTE_UINT16);
12119 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12120         TOKEN_NUM_INITIALIZER
12121                 (struct cmd_macsec_sa_result,
12122                  idx, RTE_UINT8);
12123 cmdline_parse_token_num_t cmd_macsec_sa_an =
12124         TOKEN_NUM_INITIALIZER
12125                 (struct cmd_macsec_sa_result,
12126                  an, RTE_UINT8);
12127 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12128         TOKEN_NUM_INITIALIZER
12129                 (struct cmd_macsec_sa_result,
12130                  pn, RTE_UINT32);
12131 cmdline_parse_token_string_t cmd_macsec_sa_key =
12132         TOKEN_STRING_INITIALIZER
12133                 (struct cmd_macsec_sa_result,
12134                  key, NULL);
12135
12136 static void
12137 cmd_set_macsec_sa_parsed(
12138         void *parsed_result,
12139         __rte_unused struct cmdline *cl,
12140         __rte_unused void *data)
12141 {
12142         struct cmd_macsec_sa_result *res = parsed_result;
12143         int ret = -ENOTSUP;
12144         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12145         uint8_t key[16] = { 0 };
12146         uint8_t xdgt0;
12147         uint8_t xdgt1;
12148         int key_len;
12149         int i;
12150
12151         key_len = strlen(res->key) / 2;
12152         if (key_len > 16)
12153                 key_len = 16;
12154
12155         for (i = 0; i < key_len; i++) {
12156                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12157                 if (xdgt0 == 0xFF)
12158                         return;
12159                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12160                 if (xdgt1 == 0xFF)
12161                         return;
12162                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12163         }
12164
12165 #ifdef RTE_NET_IXGBE
12166         ret = is_tx ?
12167                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12168                         res->idx, res->an, res->pn, key) :
12169                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12170                         res->idx, res->an, res->pn, key);
12171 #endif
12172         RTE_SET_USED(is_tx);
12173         RTE_SET_USED(key);
12174
12175         switch (ret) {
12176         case 0:
12177                 break;
12178         case -EINVAL:
12179                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12180                 break;
12181         case -ENODEV:
12182                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12183                 break;
12184         case -ENOTSUP:
12185                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12186                 break;
12187         default:
12188                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12189         }
12190 }
12191
12192 cmdline_parse_inst_t cmd_set_macsec_sa = {
12193         .f = cmd_set_macsec_sa_parsed,
12194         .data = NULL,
12195         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12196         .tokens = {
12197                 (void *)&cmd_macsec_sa_set,
12198                 (void *)&cmd_macsec_sa_macsec,
12199                 (void *)&cmd_macsec_sa_sa,
12200                 (void *)&cmd_macsec_sa_tx_rx,
12201                 (void *)&cmd_macsec_sa_port_id,
12202                 (void *)&cmd_macsec_sa_idx,
12203                 (void *)&cmd_macsec_sa_an,
12204                 (void *)&cmd_macsec_sa_pn,
12205                 (void *)&cmd_macsec_sa_key,
12206                 NULL,
12207         },
12208 };
12209
12210 /* VF unicast promiscuous mode configuration */
12211
12212 /* Common result structure for VF unicast promiscuous mode */
12213 struct cmd_vf_promisc_result {
12214         cmdline_fixed_string_t set;
12215         cmdline_fixed_string_t vf;
12216         cmdline_fixed_string_t promisc;
12217         portid_t port_id;
12218         uint32_t vf_id;
12219         cmdline_fixed_string_t on_off;
12220 };
12221
12222 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12223 cmdline_parse_token_string_t cmd_vf_promisc_set =
12224         TOKEN_STRING_INITIALIZER
12225                 (struct cmd_vf_promisc_result,
12226                  set, "set");
12227 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12228         TOKEN_STRING_INITIALIZER
12229                 (struct cmd_vf_promisc_result,
12230                  vf, "vf");
12231 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12232         TOKEN_STRING_INITIALIZER
12233                 (struct cmd_vf_promisc_result,
12234                  promisc, "promisc");
12235 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12236         TOKEN_NUM_INITIALIZER
12237                 (struct cmd_vf_promisc_result,
12238                  port_id, RTE_UINT16);
12239 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12240         TOKEN_NUM_INITIALIZER
12241                 (struct cmd_vf_promisc_result,
12242                  vf_id, RTE_UINT32);
12243 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12244         TOKEN_STRING_INITIALIZER
12245                 (struct cmd_vf_promisc_result,
12246                  on_off, "on#off");
12247
12248 static void
12249 cmd_set_vf_promisc_parsed(
12250         void *parsed_result,
12251         __rte_unused struct cmdline *cl,
12252         __rte_unused void *data)
12253 {
12254         struct cmd_vf_promisc_result *res = parsed_result;
12255         int ret = -ENOTSUP;
12256
12257         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12258
12259         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12260                 return;
12261
12262 #ifdef RTE_NET_I40E
12263         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12264                                                   res->vf_id, is_on);
12265 #endif
12266
12267         switch (ret) {
12268         case 0:
12269                 break;
12270         case -EINVAL:
12271                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12272                 break;
12273         case -ENODEV:
12274                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12275                 break;
12276         case -ENOTSUP:
12277                 fprintf(stderr, "function not implemented\n");
12278                 break;
12279         default:
12280                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12281         }
12282 }
12283
12284 cmdline_parse_inst_t cmd_set_vf_promisc = {
12285         .f = cmd_set_vf_promisc_parsed,
12286         .data = NULL,
12287         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12288                 "Set unicast promiscuous mode for a VF from the PF",
12289         .tokens = {
12290                 (void *)&cmd_vf_promisc_set,
12291                 (void *)&cmd_vf_promisc_vf,
12292                 (void *)&cmd_vf_promisc_promisc,
12293                 (void *)&cmd_vf_promisc_port_id,
12294                 (void *)&cmd_vf_promisc_vf_id,
12295                 (void *)&cmd_vf_promisc_on_off,
12296                 NULL,
12297         },
12298 };
12299
12300 /* VF multicast promiscuous mode configuration */
12301
12302 /* Common result structure for VF multicast promiscuous mode */
12303 struct cmd_vf_allmulti_result {
12304         cmdline_fixed_string_t set;
12305         cmdline_fixed_string_t vf;
12306         cmdline_fixed_string_t allmulti;
12307         portid_t port_id;
12308         uint32_t vf_id;
12309         cmdline_fixed_string_t on_off;
12310 };
12311
12312 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12313 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12314         TOKEN_STRING_INITIALIZER
12315                 (struct cmd_vf_allmulti_result,
12316                  set, "set");
12317 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12318         TOKEN_STRING_INITIALIZER
12319                 (struct cmd_vf_allmulti_result,
12320                  vf, "vf");
12321 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12322         TOKEN_STRING_INITIALIZER
12323                 (struct cmd_vf_allmulti_result,
12324                  allmulti, "allmulti");
12325 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12326         TOKEN_NUM_INITIALIZER
12327                 (struct cmd_vf_allmulti_result,
12328                  port_id, RTE_UINT16);
12329 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12330         TOKEN_NUM_INITIALIZER
12331                 (struct cmd_vf_allmulti_result,
12332                  vf_id, RTE_UINT32);
12333 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12334         TOKEN_STRING_INITIALIZER
12335                 (struct cmd_vf_allmulti_result,
12336                  on_off, "on#off");
12337
12338 static void
12339 cmd_set_vf_allmulti_parsed(
12340         void *parsed_result,
12341         __rte_unused struct cmdline *cl,
12342         __rte_unused void *data)
12343 {
12344         struct cmd_vf_allmulti_result *res = parsed_result;
12345         int ret = -ENOTSUP;
12346
12347         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12348
12349         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12350                 return;
12351
12352 #ifdef RTE_NET_I40E
12353         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12354                                                     res->vf_id, is_on);
12355 #endif
12356
12357         switch (ret) {
12358         case 0:
12359                 break;
12360         case -EINVAL:
12361                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12362                 break;
12363         case -ENODEV:
12364                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12365                 break;
12366         case -ENOTSUP:
12367                 fprintf(stderr, "function not implemented\n");
12368                 break;
12369         default:
12370                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12371         }
12372 }
12373
12374 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12375         .f = cmd_set_vf_allmulti_parsed,
12376         .data = NULL,
12377         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12378                 "Set multicast promiscuous mode for a VF from the PF",
12379         .tokens = {
12380                 (void *)&cmd_vf_allmulti_set,
12381                 (void *)&cmd_vf_allmulti_vf,
12382                 (void *)&cmd_vf_allmulti_allmulti,
12383                 (void *)&cmd_vf_allmulti_port_id,
12384                 (void *)&cmd_vf_allmulti_vf_id,
12385                 (void *)&cmd_vf_allmulti_on_off,
12386                 NULL,
12387         },
12388 };
12389
12390 /* vf broadcast mode configuration */
12391
12392 /* Common result structure for vf broadcast */
12393 struct cmd_set_vf_broadcast_result {
12394         cmdline_fixed_string_t set;
12395         cmdline_fixed_string_t vf;
12396         cmdline_fixed_string_t broadcast;
12397         portid_t port_id;
12398         uint16_t vf_id;
12399         cmdline_fixed_string_t on_off;
12400 };
12401
12402 /* Common CLI fields for vf broadcast enable disable */
12403 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12404         TOKEN_STRING_INITIALIZER
12405                 (struct cmd_set_vf_broadcast_result,
12406                  set, "set");
12407 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12408         TOKEN_STRING_INITIALIZER
12409                 (struct cmd_set_vf_broadcast_result,
12410                  vf, "vf");
12411 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12412         TOKEN_STRING_INITIALIZER
12413                 (struct cmd_set_vf_broadcast_result,
12414                  broadcast, "broadcast");
12415 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12416         TOKEN_NUM_INITIALIZER
12417                 (struct cmd_set_vf_broadcast_result,
12418                  port_id, RTE_UINT16);
12419 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12420         TOKEN_NUM_INITIALIZER
12421                 (struct cmd_set_vf_broadcast_result,
12422                  vf_id, RTE_UINT16);
12423 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12424         TOKEN_STRING_INITIALIZER
12425                 (struct cmd_set_vf_broadcast_result,
12426                  on_off, "on#off");
12427
12428 static void
12429 cmd_set_vf_broadcast_parsed(
12430         void *parsed_result,
12431         __rte_unused struct cmdline *cl,
12432         __rte_unused void *data)
12433 {
12434         struct cmd_set_vf_broadcast_result *res = parsed_result;
12435         int ret = -ENOTSUP;
12436
12437         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12438
12439         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12440                 return;
12441
12442 #ifdef RTE_NET_I40E
12443         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12444                                             res->vf_id, is_on);
12445 #endif
12446
12447         switch (ret) {
12448         case 0:
12449                 break;
12450         case -EINVAL:
12451                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12452                         res->vf_id, is_on);
12453                 break;
12454         case -ENODEV:
12455                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12456                 break;
12457         case -ENOTSUP:
12458                 fprintf(stderr, "function not implemented\n");
12459                 break;
12460         default:
12461                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12462         }
12463 }
12464
12465 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12466         .f = cmd_set_vf_broadcast_parsed,
12467         .data = NULL,
12468         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12469         .tokens = {
12470                 (void *)&cmd_set_vf_broadcast_set,
12471                 (void *)&cmd_set_vf_broadcast_vf,
12472                 (void *)&cmd_set_vf_broadcast_broadcast,
12473                 (void *)&cmd_set_vf_broadcast_port_id,
12474                 (void *)&cmd_set_vf_broadcast_vf_id,
12475                 (void *)&cmd_set_vf_broadcast_on_off,
12476                 NULL,
12477         },
12478 };
12479
12480 /* vf vlan tag configuration */
12481
12482 /* Common result structure for vf vlan tag */
12483 struct cmd_set_vf_vlan_tag_result {
12484         cmdline_fixed_string_t set;
12485         cmdline_fixed_string_t vf;
12486         cmdline_fixed_string_t vlan;
12487         cmdline_fixed_string_t tag;
12488         portid_t port_id;
12489         uint16_t vf_id;
12490         cmdline_fixed_string_t on_off;
12491 };
12492
12493 /* Common CLI fields for vf vlan tag enable disable */
12494 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12495         TOKEN_STRING_INITIALIZER
12496                 (struct cmd_set_vf_vlan_tag_result,
12497                  set, "set");
12498 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12499         TOKEN_STRING_INITIALIZER
12500                 (struct cmd_set_vf_vlan_tag_result,
12501                  vf, "vf");
12502 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12503         TOKEN_STRING_INITIALIZER
12504                 (struct cmd_set_vf_vlan_tag_result,
12505                  vlan, "vlan");
12506 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12507         TOKEN_STRING_INITIALIZER
12508                 (struct cmd_set_vf_vlan_tag_result,
12509                  tag, "tag");
12510 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12511         TOKEN_NUM_INITIALIZER
12512                 (struct cmd_set_vf_vlan_tag_result,
12513                  port_id, RTE_UINT16);
12514 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12515         TOKEN_NUM_INITIALIZER
12516                 (struct cmd_set_vf_vlan_tag_result,
12517                  vf_id, RTE_UINT16);
12518 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12519         TOKEN_STRING_INITIALIZER
12520                 (struct cmd_set_vf_vlan_tag_result,
12521                  on_off, "on#off");
12522
12523 static void
12524 cmd_set_vf_vlan_tag_parsed(
12525         void *parsed_result,
12526         __rte_unused struct cmdline *cl,
12527         __rte_unused void *data)
12528 {
12529         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12530         int ret = -ENOTSUP;
12531
12532         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12533
12534         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12535                 return;
12536
12537 #ifdef RTE_NET_I40E
12538         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12539                                            res->vf_id, is_on);
12540 #endif
12541
12542         switch (ret) {
12543         case 0:
12544                 break;
12545         case -EINVAL:
12546                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12547                         res->vf_id, is_on);
12548                 break;
12549         case -ENODEV:
12550                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12551                 break;
12552         case -ENOTSUP:
12553                 fprintf(stderr, "function not implemented\n");
12554                 break;
12555         default:
12556                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12557         }
12558 }
12559
12560 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12561         .f = cmd_set_vf_vlan_tag_parsed,
12562         .data = NULL,
12563         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12564         .tokens = {
12565                 (void *)&cmd_set_vf_vlan_tag_set,
12566                 (void *)&cmd_set_vf_vlan_tag_vf,
12567                 (void *)&cmd_set_vf_vlan_tag_vlan,
12568                 (void *)&cmd_set_vf_vlan_tag_tag,
12569                 (void *)&cmd_set_vf_vlan_tag_port_id,
12570                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12571                 (void *)&cmd_set_vf_vlan_tag_on_off,
12572                 NULL,
12573         },
12574 };
12575
12576 /* Common definition of VF and TC TX bandwidth configuration */
12577 struct cmd_vf_tc_bw_result {
12578         cmdline_fixed_string_t set;
12579         cmdline_fixed_string_t vf;
12580         cmdline_fixed_string_t tc;
12581         cmdline_fixed_string_t tx;
12582         cmdline_fixed_string_t min_bw;
12583         cmdline_fixed_string_t max_bw;
12584         cmdline_fixed_string_t strict_link_prio;
12585         portid_t port_id;
12586         uint16_t vf_id;
12587         uint8_t tc_no;
12588         uint32_t bw;
12589         cmdline_fixed_string_t bw_list;
12590         uint8_t tc_map;
12591 };
12592
12593 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12594         TOKEN_STRING_INITIALIZER
12595                 (struct cmd_vf_tc_bw_result,
12596                  set, "set");
12597 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12598         TOKEN_STRING_INITIALIZER
12599                 (struct cmd_vf_tc_bw_result,
12600                  vf, "vf");
12601 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12602         TOKEN_STRING_INITIALIZER
12603                 (struct cmd_vf_tc_bw_result,
12604                  tc, "tc");
12605 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12606         TOKEN_STRING_INITIALIZER
12607                 (struct cmd_vf_tc_bw_result,
12608                  tx, "tx");
12609 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12610         TOKEN_STRING_INITIALIZER
12611                 (struct cmd_vf_tc_bw_result,
12612                  strict_link_prio, "strict-link-priority");
12613 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12614         TOKEN_STRING_INITIALIZER
12615                 (struct cmd_vf_tc_bw_result,
12616                  min_bw, "min-bandwidth");
12617 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12618         TOKEN_STRING_INITIALIZER
12619                 (struct cmd_vf_tc_bw_result,
12620                  max_bw, "max-bandwidth");
12621 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12622         TOKEN_NUM_INITIALIZER
12623                 (struct cmd_vf_tc_bw_result,
12624                  port_id, RTE_UINT16);
12625 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12626         TOKEN_NUM_INITIALIZER
12627                 (struct cmd_vf_tc_bw_result,
12628                  vf_id, RTE_UINT16);
12629 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12630         TOKEN_NUM_INITIALIZER
12631                 (struct cmd_vf_tc_bw_result,
12632                  tc_no, RTE_UINT8);
12633 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12634         TOKEN_NUM_INITIALIZER
12635                 (struct cmd_vf_tc_bw_result,
12636                  bw, RTE_UINT32);
12637 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12638         TOKEN_STRING_INITIALIZER
12639                 (struct cmd_vf_tc_bw_result,
12640                  bw_list, NULL);
12641 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12642         TOKEN_NUM_INITIALIZER
12643                 (struct cmd_vf_tc_bw_result,
12644                  tc_map, RTE_UINT8);
12645
12646 /* VF max bandwidth setting */
12647 static void
12648 cmd_vf_max_bw_parsed(
12649         void *parsed_result,
12650         __rte_unused struct cmdline *cl,
12651         __rte_unused void *data)
12652 {
12653         struct cmd_vf_tc_bw_result *res = parsed_result;
12654         int ret = -ENOTSUP;
12655
12656         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12657                 return;
12658
12659 #ifdef RTE_NET_I40E
12660         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12661                                          res->vf_id, res->bw);
12662 #endif
12663
12664         switch (ret) {
12665         case 0:
12666                 break;
12667         case -EINVAL:
12668                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12669                         res->vf_id, res->bw);
12670                 break;
12671         case -ENODEV:
12672                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12673                 break;
12674         case -ENOTSUP:
12675                 fprintf(stderr, "function not implemented\n");
12676                 break;
12677         default:
12678                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12679         }
12680 }
12681
12682 cmdline_parse_inst_t cmd_vf_max_bw = {
12683         .f = cmd_vf_max_bw_parsed,
12684         .data = NULL,
12685         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12686         .tokens = {
12687                 (void *)&cmd_vf_tc_bw_set,
12688                 (void *)&cmd_vf_tc_bw_vf,
12689                 (void *)&cmd_vf_tc_bw_tx,
12690                 (void *)&cmd_vf_tc_bw_max_bw,
12691                 (void *)&cmd_vf_tc_bw_port_id,
12692                 (void *)&cmd_vf_tc_bw_vf_id,
12693                 (void *)&cmd_vf_tc_bw_bw,
12694                 NULL,
12695         },
12696 };
12697
12698 static int
12699 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12700                            uint8_t *tc_num,
12701                            char *str)
12702 {
12703         uint32_t size;
12704         const char *p, *p0 = str;
12705         char s[256];
12706         char *end;
12707         char *str_fld[16];
12708         uint16_t i;
12709         int ret;
12710
12711         p = strchr(p0, '(');
12712         if (p == NULL) {
12713                 fprintf(stderr,
12714                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12715                 return -1;
12716         }
12717         p++;
12718         p0 = strchr(p, ')');
12719         if (p0 == NULL) {
12720                 fprintf(stderr,
12721                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12722                 return -1;
12723         }
12724         size = p0 - p;
12725         if (size >= sizeof(s)) {
12726                 fprintf(stderr,
12727                         "The string size exceeds the internal buffer size\n");
12728                 return -1;
12729         }
12730         snprintf(s, sizeof(s), "%.*s", size, p);
12731         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12732         if (ret <= 0) {
12733                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12734                 return -1;
12735         }
12736         *tc_num = ret;
12737         for (i = 0; i < ret; i++)
12738                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12739
12740         return 0;
12741 }
12742
12743 /* TC min bandwidth setting */
12744 static void
12745 cmd_vf_tc_min_bw_parsed(
12746         void *parsed_result,
12747         __rte_unused struct cmdline *cl,
12748         __rte_unused void *data)
12749 {
12750         struct cmd_vf_tc_bw_result *res = parsed_result;
12751         uint8_t tc_num;
12752         uint8_t bw[16];
12753         int ret = -ENOTSUP;
12754
12755         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12756                 return;
12757
12758         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12759         if (ret)
12760                 return;
12761
12762 #ifdef RTE_NET_I40E
12763         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12764                                               tc_num, bw);
12765 #endif
12766
12767         switch (ret) {
12768         case 0:
12769                 break;
12770         case -EINVAL:
12771                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12772                 break;
12773         case -ENODEV:
12774                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12775                 break;
12776         case -ENOTSUP:
12777                 fprintf(stderr, "function not implemented\n");
12778                 break;
12779         default:
12780                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12781         }
12782 }
12783
12784 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12785         .f = cmd_vf_tc_min_bw_parsed,
12786         .data = NULL,
12787         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12788                     " <bw1, bw2, ...>",
12789         .tokens = {
12790                 (void *)&cmd_vf_tc_bw_set,
12791                 (void *)&cmd_vf_tc_bw_vf,
12792                 (void *)&cmd_vf_tc_bw_tc,
12793                 (void *)&cmd_vf_tc_bw_tx,
12794                 (void *)&cmd_vf_tc_bw_min_bw,
12795                 (void *)&cmd_vf_tc_bw_port_id,
12796                 (void *)&cmd_vf_tc_bw_vf_id,
12797                 (void *)&cmd_vf_tc_bw_bw_list,
12798                 NULL,
12799         },
12800 };
12801
12802 static void
12803 cmd_tc_min_bw_parsed(
12804         void *parsed_result,
12805         __rte_unused struct cmdline *cl,
12806         __rte_unused void *data)
12807 {
12808         struct cmd_vf_tc_bw_result *res = parsed_result;
12809         struct rte_port *port;
12810         uint8_t tc_num;
12811         uint8_t bw[16];
12812         int ret = -ENOTSUP;
12813
12814         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12815                 return;
12816
12817         port = &ports[res->port_id];
12818         /** Check if the port is not started **/
12819         if (port->port_status != RTE_PORT_STOPPED) {
12820                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
12821                 return;
12822         }
12823
12824         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12825         if (ret)
12826                 return;
12827
12828 #ifdef RTE_NET_IXGBE
12829         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12830 #endif
12831
12832         switch (ret) {
12833         case 0:
12834                 break;
12835         case -EINVAL:
12836                 fprintf(stderr, "invalid bandwidth\n");
12837                 break;
12838         case -ENODEV:
12839                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12840                 break;
12841         case -ENOTSUP:
12842                 fprintf(stderr, "function not implemented\n");
12843                 break;
12844         default:
12845                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12846         }
12847 }
12848
12849 cmdline_parse_inst_t cmd_tc_min_bw = {
12850         .f = cmd_tc_min_bw_parsed,
12851         .data = NULL,
12852         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12853         .tokens = {
12854                 (void *)&cmd_vf_tc_bw_set,
12855                 (void *)&cmd_vf_tc_bw_tc,
12856                 (void *)&cmd_vf_tc_bw_tx,
12857                 (void *)&cmd_vf_tc_bw_min_bw,
12858                 (void *)&cmd_vf_tc_bw_port_id,
12859                 (void *)&cmd_vf_tc_bw_bw_list,
12860                 NULL,
12861         },
12862 };
12863
12864 /* TC max bandwidth setting */
12865 static void
12866 cmd_vf_tc_max_bw_parsed(
12867         void *parsed_result,
12868         __rte_unused struct cmdline *cl,
12869         __rte_unused void *data)
12870 {
12871         struct cmd_vf_tc_bw_result *res = parsed_result;
12872         int ret = -ENOTSUP;
12873
12874         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12875                 return;
12876
12877 #ifdef RTE_NET_I40E
12878         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12879                                             res->tc_no, res->bw);
12880 #endif
12881
12882         switch (ret) {
12883         case 0:
12884                 break;
12885         case -EINVAL:
12886                 fprintf(stderr,
12887                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
12888                         res->vf_id, res->tc_no, res->bw);
12889                 break;
12890         case -ENODEV:
12891                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12892                 break;
12893         case -ENOTSUP:
12894                 fprintf(stderr, "function not implemented\n");
12895                 break;
12896         default:
12897                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12898         }
12899 }
12900
12901 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12902         .f = cmd_vf_tc_max_bw_parsed,
12903         .data = NULL,
12904         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12905                     " <bandwidth>",
12906         .tokens = {
12907                 (void *)&cmd_vf_tc_bw_set,
12908                 (void *)&cmd_vf_tc_bw_vf,
12909                 (void *)&cmd_vf_tc_bw_tc,
12910                 (void *)&cmd_vf_tc_bw_tx,
12911                 (void *)&cmd_vf_tc_bw_max_bw,
12912                 (void *)&cmd_vf_tc_bw_port_id,
12913                 (void *)&cmd_vf_tc_bw_vf_id,
12914                 (void *)&cmd_vf_tc_bw_tc_no,
12915                 (void *)&cmd_vf_tc_bw_bw,
12916                 NULL,
12917         },
12918 };
12919
12920 /** Set VXLAN encapsulation details */
12921 struct cmd_set_vxlan_result {
12922         cmdline_fixed_string_t set;
12923         cmdline_fixed_string_t vxlan;
12924         cmdline_fixed_string_t pos_token;
12925         cmdline_fixed_string_t ip_version;
12926         uint32_t vlan_present:1;
12927         uint32_t vni;
12928         uint16_t udp_src;
12929         uint16_t udp_dst;
12930         cmdline_ipaddr_t ip_src;
12931         cmdline_ipaddr_t ip_dst;
12932         uint16_t tci;
12933         uint8_t tos;
12934         uint8_t ttl;
12935         struct rte_ether_addr eth_src;
12936         struct rte_ether_addr eth_dst;
12937 };
12938
12939 cmdline_parse_token_string_t cmd_set_vxlan_set =
12940         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12941 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12942         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12943 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12944         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12945                                  "vxlan-tos-ttl");
12946 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12947         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12948                                  "vxlan-with-vlan");
12949 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12950         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12951                                  "ip-version");
12952 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12953         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12954                                  "ipv4#ipv6");
12955 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12956         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12957                                  "vni");
12958 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12959         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12960 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12961         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12962                                  "udp-src");
12963 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12964         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12965 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12966         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12967                                  "udp-dst");
12968 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12969         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12970 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12971         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12972                                  "ip-tos");
12973 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12974         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12975 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12976         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12977                                  "ip-ttl");
12978 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12979         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12980 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12981         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12982                                  "ip-src");
12983 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12984         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12985 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12986         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12987                                  "ip-dst");
12988 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12989         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12990 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12991         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12992                                  "vlan-tci");
12993 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12994         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12995 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
12996         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12997                                  "eth-src");
12998 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
12999         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13000 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13001         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13002                                  "eth-dst");
13003 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13004         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13005
13006 static void cmd_set_vxlan_parsed(void *parsed_result,
13007         __rte_unused struct cmdline *cl,
13008         __rte_unused void *data)
13009 {
13010         struct cmd_set_vxlan_result *res = parsed_result;
13011         union {
13012                 uint32_t vxlan_id;
13013                 uint8_t vni[4];
13014         } id = {
13015                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13016         };
13017
13018         vxlan_encap_conf.select_tos_ttl = 0;
13019         if (strcmp(res->vxlan, "vxlan") == 0)
13020                 vxlan_encap_conf.select_vlan = 0;
13021         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13022                 vxlan_encap_conf.select_vlan = 1;
13023         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13024                 vxlan_encap_conf.select_vlan = 0;
13025                 vxlan_encap_conf.select_tos_ttl = 1;
13026         }
13027         if (strcmp(res->ip_version, "ipv4") == 0)
13028                 vxlan_encap_conf.select_ipv4 = 1;
13029         else if (strcmp(res->ip_version, "ipv6") == 0)
13030                 vxlan_encap_conf.select_ipv4 = 0;
13031         else
13032                 return;
13033         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13034         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13035         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13036         vxlan_encap_conf.ip_tos = res->tos;
13037         vxlan_encap_conf.ip_ttl = res->ttl;
13038         if (vxlan_encap_conf.select_ipv4) {
13039                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13040                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13041         } else {
13042                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13043                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13044         }
13045         if (vxlan_encap_conf.select_vlan)
13046                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13047         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13048                    RTE_ETHER_ADDR_LEN);
13049         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13050                    RTE_ETHER_ADDR_LEN);
13051 }
13052
13053 cmdline_parse_inst_t cmd_set_vxlan = {
13054         .f = cmd_set_vxlan_parsed,
13055         .data = NULL,
13056         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13057                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13058                 " eth-src <eth-src> eth-dst <eth-dst>",
13059         .tokens = {
13060                 (void *)&cmd_set_vxlan_set,
13061                 (void *)&cmd_set_vxlan_vxlan,
13062                 (void *)&cmd_set_vxlan_ip_version,
13063                 (void *)&cmd_set_vxlan_ip_version_value,
13064                 (void *)&cmd_set_vxlan_vni,
13065                 (void *)&cmd_set_vxlan_vni_value,
13066                 (void *)&cmd_set_vxlan_udp_src,
13067                 (void *)&cmd_set_vxlan_udp_src_value,
13068                 (void *)&cmd_set_vxlan_udp_dst,
13069                 (void *)&cmd_set_vxlan_udp_dst_value,
13070                 (void *)&cmd_set_vxlan_ip_src,
13071                 (void *)&cmd_set_vxlan_ip_src_value,
13072                 (void *)&cmd_set_vxlan_ip_dst,
13073                 (void *)&cmd_set_vxlan_ip_dst_value,
13074                 (void *)&cmd_set_vxlan_eth_src,
13075                 (void *)&cmd_set_vxlan_eth_src_value,
13076                 (void *)&cmd_set_vxlan_eth_dst,
13077                 (void *)&cmd_set_vxlan_eth_dst_value,
13078                 NULL,
13079         },
13080 };
13081
13082 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13083         .f = cmd_set_vxlan_parsed,
13084         .data = NULL,
13085         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13086                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13087                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13088                 " eth-dst <eth-dst>",
13089         .tokens = {
13090                 (void *)&cmd_set_vxlan_set,
13091                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13092                 (void *)&cmd_set_vxlan_ip_version,
13093                 (void *)&cmd_set_vxlan_ip_version_value,
13094                 (void *)&cmd_set_vxlan_vni,
13095                 (void *)&cmd_set_vxlan_vni_value,
13096                 (void *)&cmd_set_vxlan_udp_src,
13097                 (void *)&cmd_set_vxlan_udp_src_value,
13098                 (void *)&cmd_set_vxlan_udp_dst,
13099                 (void *)&cmd_set_vxlan_udp_dst_value,
13100                 (void *)&cmd_set_vxlan_ip_tos,
13101                 (void *)&cmd_set_vxlan_ip_tos_value,
13102                 (void *)&cmd_set_vxlan_ip_ttl,
13103                 (void *)&cmd_set_vxlan_ip_ttl_value,
13104                 (void *)&cmd_set_vxlan_ip_src,
13105                 (void *)&cmd_set_vxlan_ip_src_value,
13106                 (void *)&cmd_set_vxlan_ip_dst,
13107                 (void *)&cmd_set_vxlan_ip_dst_value,
13108                 (void *)&cmd_set_vxlan_eth_src,
13109                 (void *)&cmd_set_vxlan_eth_src_value,
13110                 (void *)&cmd_set_vxlan_eth_dst,
13111                 (void *)&cmd_set_vxlan_eth_dst_value,
13112                 NULL,
13113         },
13114 };
13115
13116 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13117         .f = cmd_set_vxlan_parsed,
13118         .data = NULL,
13119         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13120                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13121                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13122                 " <eth-dst>",
13123         .tokens = {
13124                 (void *)&cmd_set_vxlan_set,
13125                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13126                 (void *)&cmd_set_vxlan_ip_version,
13127                 (void *)&cmd_set_vxlan_ip_version_value,
13128                 (void *)&cmd_set_vxlan_vni,
13129                 (void *)&cmd_set_vxlan_vni_value,
13130                 (void *)&cmd_set_vxlan_udp_src,
13131                 (void *)&cmd_set_vxlan_udp_src_value,
13132                 (void *)&cmd_set_vxlan_udp_dst,
13133                 (void *)&cmd_set_vxlan_udp_dst_value,
13134                 (void *)&cmd_set_vxlan_ip_src,
13135                 (void *)&cmd_set_vxlan_ip_src_value,
13136                 (void *)&cmd_set_vxlan_ip_dst,
13137                 (void *)&cmd_set_vxlan_ip_dst_value,
13138                 (void *)&cmd_set_vxlan_vlan,
13139                 (void *)&cmd_set_vxlan_vlan_value,
13140                 (void *)&cmd_set_vxlan_eth_src,
13141                 (void *)&cmd_set_vxlan_eth_src_value,
13142                 (void *)&cmd_set_vxlan_eth_dst,
13143                 (void *)&cmd_set_vxlan_eth_dst_value,
13144                 NULL,
13145         },
13146 };
13147
13148 /** Set NVGRE encapsulation details */
13149 struct cmd_set_nvgre_result {
13150         cmdline_fixed_string_t set;
13151         cmdline_fixed_string_t nvgre;
13152         cmdline_fixed_string_t pos_token;
13153         cmdline_fixed_string_t ip_version;
13154         uint32_t tni;
13155         cmdline_ipaddr_t ip_src;
13156         cmdline_ipaddr_t ip_dst;
13157         uint16_t tci;
13158         struct rte_ether_addr eth_src;
13159         struct rte_ether_addr eth_dst;
13160 };
13161
13162 cmdline_parse_token_string_t cmd_set_nvgre_set =
13163         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13164 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13165         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13166 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13167         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13168                                  "nvgre-with-vlan");
13169 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13170         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13171                                  "ip-version");
13172 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13173         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13174                                  "ipv4#ipv6");
13175 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13176         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13177                                  "tni");
13178 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13179         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13180 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13181         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13182                                  "ip-src");
13183 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13184         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13185 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13186         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13187                                  "ip-dst");
13188 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13189         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13190 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13191         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13192                                  "vlan-tci");
13193 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13194         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13195 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13196         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13197                                  "eth-src");
13198 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13199         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13200 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13201         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13202                                  "eth-dst");
13203 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13204         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13205
13206 static void cmd_set_nvgre_parsed(void *parsed_result,
13207         __rte_unused struct cmdline *cl,
13208         __rte_unused void *data)
13209 {
13210         struct cmd_set_nvgre_result *res = parsed_result;
13211         union {
13212                 uint32_t nvgre_tni;
13213                 uint8_t tni[4];
13214         } id = {
13215                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13216         };
13217
13218         if (strcmp(res->nvgre, "nvgre") == 0)
13219                 nvgre_encap_conf.select_vlan = 0;
13220         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13221                 nvgre_encap_conf.select_vlan = 1;
13222         if (strcmp(res->ip_version, "ipv4") == 0)
13223                 nvgre_encap_conf.select_ipv4 = 1;
13224         else if (strcmp(res->ip_version, "ipv6") == 0)
13225                 nvgre_encap_conf.select_ipv4 = 0;
13226         else
13227                 return;
13228         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13229         if (nvgre_encap_conf.select_ipv4) {
13230                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13231                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13232         } else {
13233                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13234                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13235         }
13236         if (nvgre_encap_conf.select_vlan)
13237                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13238         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13239                    RTE_ETHER_ADDR_LEN);
13240         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13241                    RTE_ETHER_ADDR_LEN);
13242 }
13243
13244 cmdline_parse_inst_t cmd_set_nvgre = {
13245         .f = cmd_set_nvgre_parsed,
13246         .data = NULL,
13247         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13248                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13249                 " eth-dst <eth-dst>",
13250         .tokens = {
13251                 (void *)&cmd_set_nvgre_set,
13252                 (void *)&cmd_set_nvgre_nvgre,
13253                 (void *)&cmd_set_nvgre_ip_version,
13254                 (void *)&cmd_set_nvgre_ip_version_value,
13255                 (void *)&cmd_set_nvgre_tni,
13256                 (void *)&cmd_set_nvgre_tni_value,
13257                 (void *)&cmd_set_nvgre_ip_src,
13258                 (void *)&cmd_set_nvgre_ip_src_value,
13259                 (void *)&cmd_set_nvgre_ip_dst,
13260                 (void *)&cmd_set_nvgre_ip_dst_value,
13261                 (void *)&cmd_set_nvgre_eth_src,
13262                 (void *)&cmd_set_nvgre_eth_src_value,
13263                 (void *)&cmd_set_nvgre_eth_dst,
13264                 (void *)&cmd_set_nvgre_eth_dst_value,
13265                 NULL,
13266         },
13267 };
13268
13269 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13270         .f = cmd_set_nvgre_parsed,
13271         .data = NULL,
13272         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13273                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13274                 " eth-src <eth-src> eth-dst <eth-dst>",
13275         .tokens = {
13276                 (void *)&cmd_set_nvgre_set,
13277                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13278                 (void *)&cmd_set_nvgre_ip_version,
13279                 (void *)&cmd_set_nvgre_ip_version_value,
13280                 (void *)&cmd_set_nvgre_tni,
13281                 (void *)&cmd_set_nvgre_tni_value,
13282                 (void *)&cmd_set_nvgre_ip_src,
13283                 (void *)&cmd_set_nvgre_ip_src_value,
13284                 (void *)&cmd_set_nvgre_ip_dst,
13285                 (void *)&cmd_set_nvgre_ip_dst_value,
13286                 (void *)&cmd_set_nvgre_vlan,
13287                 (void *)&cmd_set_nvgre_vlan_value,
13288                 (void *)&cmd_set_nvgre_eth_src,
13289                 (void *)&cmd_set_nvgre_eth_src_value,
13290                 (void *)&cmd_set_nvgre_eth_dst,
13291                 (void *)&cmd_set_nvgre_eth_dst_value,
13292                 NULL,
13293         },
13294 };
13295
13296 /** Set L2 encapsulation details */
13297 struct cmd_set_l2_encap_result {
13298         cmdline_fixed_string_t set;
13299         cmdline_fixed_string_t l2_encap;
13300         cmdline_fixed_string_t pos_token;
13301         cmdline_fixed_string_t ip_version;
13302         uint32_t vlan_present:1;
13303         uint16_t tci;
13304         struct rte_ether_addr eth_src;
13305         struct rte_ether_addr eth_dst;
13306 };
13307
13308 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13309         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13310 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13311         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13312 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13313         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13314                                  "l2_encap-with-vlan");
13315 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13316         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13317                                  "ip-version");
13318 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13319         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13320                                  "ipv4#ipv6");
13321 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13322         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13323                                  "vlan-tci");
13324 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13325         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13326 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13327         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13328                                  "eth-src");
13329 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13330         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13331 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13332         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13333                                  "eth-dst");
13334 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13335         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13336
13337 static void cmd_set_l2_encap_parsed(void *parsed_result,
13338         __rte_unused struct cmdline *cl,
13339         __rte_unused void *data)
13340 {
13341         struct cmd_set_l2_encap_result *res = parsed_result;
13342
13343         if (strcmp(res->l2_encap, "l2_encap") == 0)
13344                 l2_encap_conf.select_vlan = 0;
13345         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13346                 l2_encap_conf.select_vlan = 1;
13347         if (strcmp(res->ip_version, "ipv4") == 0)
13348                 l2_encap_conf.select_ipv4 = 1;
13349         else if (strcmp(res->ip_version, "ipv6") == 0)
13350                 l2_encap_conf.select_ipv4 = 0;
13351         else
13352                 return;
13353         if (l2_encap_conf.select_vlan)
13354                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13355         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13356                    RTE_ETHER_ADDR_LEN);
13357         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13358                    RTE_ETHER_ADDR_LEN);
13359 }
13360
13361 cmdline_parse_inst_t cmd_set_l2_encap = {
13362         .f = cmd_set_l2_encap_parsed,
13363         .data = NULL,
13364         .help_str = "set l2_encap ip-version ipv4|ipv6"
13365                 " eth-src <eth-src> eth-dst <eth-dst>",
13366         .tokens = {
13367                 (void *)&cmd_set_l2_encap_set,
13368                 (void *)&cmd_set_l2_encap_l2_encap,
13369                 (void *)&cmd_set_l2_encap_ip_version,
13370                 (void *)&cmd_set_l2_encap_ip_version_value,
13371                 (void *)&cmd_set_l2_encap_eth_src,
13372                 (void *)&cmd_set_l2_encap_eth_src_value,
13373                 (void *)&cmd_set_l2_encap_eth_dst,
13374                 (void *)&cmd_set_l2_encap_eth_dst_value,
13375                 NULL,
13376         },
13377 };
13378
13379 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13380         .f = cmd_set_l2_encap_parsed,
13381         .data = NULL,
13382         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13383                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13384         .tokens = {
13385                 (void *)&cmd_set_l2_encap_set,
13386                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13387                 (void *)&cmd_set_l2_encap_ip_version,
13388                 (void *)&cmd_set_l2_encap_ip_version_value,
13389                 (void *)&cmd_set_l2_encap_vlan,
13390                 (void *)&cmd_set_l2_encap_vlan_value,
13391                 (void *)&cmd_set_l2_encap_eth_src,
13392                 (void *)&cmd_set_l2_encap_eth_src_value,
13393                 (void *)&cmd_set_l2_encap_eth_dst,
13394                 (void *)&cmd_set_l2_encap_eth_dst_value,
13395                 NULL,
13396         },
13397 };
13398
13399 /** Set L2 decapsulation details */
13400 struct cmd_set_l2_decap_result {
13401         cmdline_fixed_string_t set;
13402         cmdline_fixed_string_t l2_decap;
13403         cmdline_fixed_string_t pos_token;
13404         uint32_t vlan_present:1;
13405 };
13406
13407 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13408         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13409 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13410         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13411                                  "l2_decap");
13412 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13413         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13414                                  "l2_decap-with-vlan");
13415
13416 static void cmd_set_l2_decap_parsed(void *parsed_result,
13417         __rte_unused struct cmdline *cl,
13418         __rte_unused void *data)
13419 {
13420         struct cmd_set_l2_decap_result *res = parsed_result;
13421
13422         if (strcmp(res->l2_decap, "l2_decap") == 0)
13423                 l2_decap_conf.select_vlan = 0;
13424         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13425                 l2_decap_conf.select_vlan = 1;
13426 }
13427
13428 cmdline_parse_inst_t cmd_set_l2_decap = {
13429         .f = cmd_set_l2_decap_parsed,
13430         .data = NULL,
13431         .help_str = "set l2_decap",
13432         .tokens = {
13433                 (void *)&cmd_set_l2_decap_set,
13434                 (void *)&cmd_set_l2_decap_l2_decap,
13435                 NULL,
13436         },
13437 };
13438
13439 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13440         .f = cmd_set_l2_decap_parsed,
13441         .data = NULL,
13442         .help_str = "set l2_decap-with-vlan",
13443         .tokens = {
13444                 (void *)&cmd_set_l2_decap_set,
13445                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13446                 NULL,
13447         },
13448 };
13449
13450 /** Set MPLSoGRE encapsulation details */
13451 struct cmd_set_mplsogre_encap_result {
13452         cmdline_fixed_string_t set;
13453         cmdline_fixed_string_t mplsogre;
13454         cmdline_fixed_string_t pos_token;
13455         cmdline_fixed_string_t ip_version;
13456         uint32_t vlan_present:1;
13457         uint32_t label;
13458         cmdline_ipaddr_t ip_src;
13459         cmdline_ipaddr_t ip_dst;
13460         uint16_t tci;
13461         struct rte_ether_addr eth_src;
13462         struct rte_ether_addr eth_dst;
13463 };
13464
13465 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13466         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13467                                  "set");
13468 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13469         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13470                                  "mplsogre_encap");
13471 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13472         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13473                                  mplsogre, "mplsogre_encap-with-vlan");
13474 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13475         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13476                                  pos_token, "ip-version");
13477 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13478         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13479                                  ip_version, "ipv4#ipv6");
13480 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13481         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13482                                  pos_token, "label");
13483 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13484         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13485                               RTE_UINT32);
13486 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13487         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13488                                  pos_token, "ip-src");
13489 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13490         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13491 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13492         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13493                                  pos_token, "ip-dst");
13494 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13495         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13496 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13497         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13498                                  pos_token, "vlan-tci");
13499 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13500         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13501                               RTE_UINT16);
13502 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13503         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13504                                  pos_token, "eth-src");
13505 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13506         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13507                                     eth_src);
13508 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13509         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13510                                  pos_token, "eth-dst");
13511 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13512         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13513                                     eth_dst);
13514
13515 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13516         __rte_unused struct cmdline *cl,
13517         __rte_unused void *data)
13518 {
13519         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13520         union {
13521                 uint32_t mplsogre_label;
13522                 uint8_t label[4];
13523         } id = {
13524                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13525         };
13526
13527         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13528                 mplsogre_encap_conf.select_vlan = 0;
13529         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13530                 mplsogre_encap_conf.select_vlan = 1;
13531         if (strcmp(res->ip_version, "ipv4") == 0)
13532                 mplsogre_encap_conf.select_ipv4 = 1;
13533         else if (strcmp(res->ip_version, "ipv6") == 0)
13534                 mplsogre_encap_conf.select_ipv4 = 0;
13535         else
13536                 return;
13537         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13538         if (mplsogre_encap_conf.select_ipv4) {
13539                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13540                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13541         } else {
13542                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13543                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13544         }
13545         if (mplsogre_encap_conf.select_vlan)
13546                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13547         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13548                    RTE_ETHER_ADDR_LEN);
13549         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13550                    RTE_ETHER_ADDR_LEN);
13551 }
13552
13553 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13554         .f = cmd_set_mplsogre_encap_parsed,
13555         .data = NULL,
13556         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13557                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13558                 " eth-dst <eth-dst>",
13559         .tokens = {
13560                 (void *)&cmd_set_mplsogre_encap_set,
13561                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13562                 (void *)&cmd_set_mplsogre_encap_ip_version,
13563                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13564                 (void *)&cmd_set_mplsogre_encap_label,
13565                 (void *)&cmd_set_mplsogre_encap_label_value,
13566                 (void *)&cmd_set_mplsogre_encap_ip_src,
13567                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13568                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13569                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13570                 (void *)&cmd_set_mplsogre_encap_eth_src,
13571                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13572                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13573                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13574                 NULL,
13575         },
13576 };
13577
13578 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13579         .f = cmd_set_mplsogre_encap_parsed,
13580         .data = NULL,
13581         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13582                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13583                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13584         .tokens = {
13585                 (void *)&cmd_set_mplsogre_encap_set,
13586                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13587                 (void *)&cmd_set_mplsogre_encap_ip_version,
13588                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13589                 (void *)&cmd_set_mplsogre_encap_label,
13590                 (void *)&cmd_set_mplsogre_encap_label_value,
13591                 (void *)&cmd_set_mplsogre_encap_ip_src,
13592                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13593                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13594                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13595                 (void *)&cmd_set_mplsogre_encap_vlan,
13596                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13597                 (void *)&cmd_set_mplsogre_encap_eth_src,
13598                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13599                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13600                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13601                 NULL,
13602         },
13603 };
13604
13605 /** Set MPLSoGRE decapsulation details */
13606 struct cmd_set_mplsogre_decap_result {
13607         cmdline_fixed_string_t set;
13608         cmdline_fixed_string_t mplsogre;
13609         cmdline_fixed_string_t pos_token;
13610         cmdline_fixed_string_t ip_version;
13611         uint32_t vlan_present:1;
13612 };
13613
13614 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13615         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13616                                  "set");
13617 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13618         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13619                                  "mplsogre_decap");
13620 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13621         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13622                                  mplsogre, "mplsogre_decap-with-vlan");
13623 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13624         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13625                                  pos_token, "ip-version");
13626 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13627         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13628                                  ip_version, "ipv4#ipv6");
13629
13630 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13631         __rte_unused struct cmdline *cl,
13632         __rte_unused void *data)
13633 {
13634         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13635
13636         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13637                 mplsogre_decap_conf.select_vlan = 0;
13638         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13639                 mplsogre_decap_conf.select_vlan = 1;
13640         if (strcmp(res->ip_version, "ipv4") == 0)
13641                 mplsogre_decap_conf.select_ipv4 = 1;
13642         else if (strcmp(res->ip_version, "ipv6") == 0)
13643                 mplsogre_decap_conf.select_ipv4 = 0;
13644 }
13645
13646 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13647         .f = cmd_set_mplsogre_decap_parsed,
13648         .data = NULL,
13649         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13650         .tokens = {
13651                 (void *)&cmd_set_mplsogre_decap_set,
13652                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13653                 (void *)&cmd_set_mplsogre_decap_ip_version,
13654                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13655                 NULL,
13656         },
13657 };
13658
13659 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13660         .f = cmd_set_mplsogre_decap_parsed,
13661         .data = NULL,
13662         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13663         .tokens = {
13664                 (void *)&cmd_set_mplsogre_decap_set,
13665                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13666                 (void *)&cmd_set_mplsogre_decap_ip_version,
13667                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13668                 NULL,
13669         },
13670 };
13671
13672 /** Set MPLSoUDP encapsulation details */
13673 struct cmd_set_mplsoudp_encap_result {
13674         cmdline_fixed_string_t set;
13675         cmdline_fixed_string_t mplsoudp;
13676         cmdline_fixed_string_t pos_token;
13677         cmdline_fixed_string_t ip_version;
13678         uint32_t vlan_present:1;
13679         uint32_t label;
13680         uint16_t udp_src;
13681         uint16_t udp_dst;
13682         cmdline_ipaddr_t ip_src;
13683         cmdline_ipaddr_t ip_dst;
13684         uint16_t tci;
13685         struct rte_ether_addr eth_src;
13686         struct rte_ether_addr eth_dst;
13687 };
13688
13689 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13690         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13691                                  "set");
13692 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13693         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13694                                  "mplsoudp_encap");
13695 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13696         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13697                                  mplsoudp, "mplsoudp_encap-with-vlan");
13698 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13699         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13700                                  pos_token, "ip-version");
13701 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13702         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13703                                  ip_version, "ipv4#ipv6");
13704 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13705         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13706                                  pos_token, "label");
13707 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13708         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13709                               RTE_UINT32);
13710 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13711         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13712                                  pos_token, "udp-src");
13713 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13714         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13715                               RTE_UINT16);
13716 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13717         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13718                                  pos_token, "udp-dst");
13719 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13720         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13721                               RTE_UINT16);
13722 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13723         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13724                                  pos_token, "ip-src");
13725 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13726         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13727 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13728         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13729                                  pos_token, "ip-dst");
13730 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13731         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13732 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13733         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13734                                  pos_token, "vlan-tci");
13735 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13736         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13737                               RTE_UINT16);
13738 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13739         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13740                                  pos_token, "eth-src");
13741 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13742         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13743                                     eth_src);
13744 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13745         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13746                                  pos_token, "eth-dst");
13747 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13748         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13749                                     eth_dst);
13750
13751 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13752         __rte_unused struct cmdline *cl,
13753         __rte_unused void *data)
13754 {
13755         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13756         union {
13757                 uint32_t mplsoudp_label;
13758                 uint8_t label[4];
13759         } id = {
13760                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13761         };
13762
13763         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13764                 mplsoudp_encap_conf.select_vlan = 0;
13765         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13766                 mplsoudp_encap_conf.select_vlan = 1;
13767         if (strcmp(res->ip_version, "ipv4") == 0)
13768                 mplsoudp_encap_conf.select_ipv4 = 1;
13769         else if (strcmp(res->ip_version, "ipv6") == 0)
13770                 mplsoudp_encap_conf.select_ipv4 = 0;
13771         else
13772                 return;
13773         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13774         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13775         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13776         if (mplsoudp_encap_conf.select_ipv4) {
13777                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13778                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13779         } else {
13780                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13781                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13782         }
13783         if (mplsoudp_encap_conf.select_vlan)
13784                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13785         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13786                    RTE_ETHER_ADDR_LEN);
13787         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13788                    RTE_ETHER_ADDR_LEN);
13789 }
13790
13791 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13792         .f = cmd_set_mplsoudp_encap_parsed,
13793         .data = NULL,
13794         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13795                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13796                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13797         .tokens = {
13798                 (void *)&cmd_set_mplsoudp_encap_set,
13799                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13800                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13801                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13802                 (void *)&cmd_set_mplsoudp_encap_label,
13803                 (void *)&cmd_set_mplsoudp_encap_label_value,
13804                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13805                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13806                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13807                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13808                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13809                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13810                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13811                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13812                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13813                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13814                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13815                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13816                 NULL,
13817         },
13818 };
13819
13820 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13821         .f = cmd_set_mplsoudp_encap_parsed,
13822         .data = NULL,
13823         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13824                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13825                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13826                 " eth-src <eth-src> eth-dst <eth-dst>",
13827         .tokens = {
13828                 (void *)&cmd_set_mplsoudp_encap_set,
13829                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13830                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13831                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13832                 (void *)&cmd_set_mplsoudp_encap_label,
13833                 (void *)&cmd_set_mplsoudp_encap_label_value,
13834                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13835                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13836                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13837                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13838                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13839                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13840                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13841                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13842                 (void *)&cmd_set_mplsoudp_encap_vlan,
13843                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13844                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13845                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13846                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13847                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13848                 NULL,
13849         },
13850 };
13851
13852 /** Set MPLSoUDP decapsulation details */
13853 struct cmd_set_mplsoudp_decap_result {
13854         cmdline_fixed_string_t set;
13855         cmdline_fixed_string_t mplsoudp;
13856         cmdline_fixed_string_t pos_token;
13857         cmdline_fixed_string_t ip_version;
13858         uint32_t vlan_present:1;
13859 };
13860
13861 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13862         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13863                                  "set");
13864 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13865         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13866                                  "mplsoudp_decap");
13867 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13868         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13869                                  mplsoudp, "mplsoudp_decap-with-vlan");
13870 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13871         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13872                                  pos_token, "ip-version");
13873 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13874         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13875                                  ip_version, "ipv4#ipv6");
13876
13877 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13878         __rte_unused struct cmdline *cl,
13879         __rte_unused void *data)
13880 {
13881         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13882
13883         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13884                 mplsoudp_decap_conf.select_vlan = 0;
13885         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13886                 mplsoudp_decap_conf.select_vlan = 1;
13887         if (strcmp(res->ip_version, "ipv4") == 0)
13888                 mplsoudp_decap_conf.select_ipv4 = 1;
13889         else if (strcmp(res->ip_version, "ipv6") == 0)
13890                 mplsoudp_decap_conf.select_ipv4 = 0;
13891 }
13892
13893 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13894         .f = cmd_set_mplsoudp_decap_parsed,
13895         .data = NULL,
13896         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13897         .tokens = {
13898                 (void *)&cmd_set_mplsoudp_decap_set,
13899                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13900                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13901                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13902                 NULL,
13903         },
13904 };
13905
13906 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13907         .f = cmd_set_mplsoudp_decap_parsed,
13908         .data = NULL,
13909         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13910         .tokens = {
13911                 (void *)&cmd_set_mplsoudp_decap_set,
13912                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13913                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13914                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13915                 NULL,
13916         },
13917 };
13918
13919 /** Set connection tracking object common details */
13920 struct cmd_set_conntrack_common_result {
13921         cmdline_fixed_string_t set;
13922         cmdline_fixed_string_t conntrack;
13923         cmdline_fixed_string_t common;
13924         cmdline_fixed_string_t peer;
13925         cmdline_fixed_string_t is_orig;
13926         cmdline_fixed_string_t enable;
13927         cmdline_fixed_string_t live;
13928         cmdline_fixed_string_t sack;
13929         cmdline_fixed_string_t cack;
13930         cmdline_fixed_string_t last_dir;
13931         cmdline_fixed_string_t liberal;
13932         cmdline_fixed_string_t state;
13933         cmdline_fixed_string_t max_ack_win;
13934         cmdline_fixed_string_t retrans;
13935         cmdline_fixed_string_t last_win;
13936         cmdline_fixed_string_t last_seq;
13937         cmdline_fixed_string_t last_ack;
13938         cmdline_fixed_string_t last_end;
13939         cmdline_fixed_string_t last_index;
13940         uint8_t stat;
13941         uint8_t factor;
13942         uint16_t peer_port;
13943         uint32_t is_original;
13944         uint32_t en;
13945         uint32_t is_live;
13946         uint32_t s_ack;
13947         uint32_t c_ack;
13948         uint32_t ld;
13949         uint32_t lb;
13950         uint8_t re_num;
13951         uint8_t li;
13952         uint16_t lw;
13953         uint32_t ls;
13954         uint32_t la;
13955         uint32_t le;
13956 };
13957
13958 cmdline_parse_token_string_t cmd_set_conntrack_set =
13959         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13960                                  set, "set");
13961 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13962         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13963                                  conntrack, "conntrack");
13964 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13965         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13966                                  common, "com");
13967 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13968         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13969                                  peer, "peer");
13970 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13971         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13972                               peer_port, RTE_UINT16);
13973 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13974         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13975                                  is_orig, "is_orig");
13976 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13977         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13978                               is_original, RTE_UINT32);
13979 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13980         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13981                                  enable, "enable");
13982 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13983         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13984                               en, RTE_UINT32);
13985 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
13986         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13987                                  live, "live");
13988 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
13989         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13990                               is_live, RTE_UINT32);
13991 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
13992         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13993                                  sack, "sack");
13994 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
13995         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13996                               s_ack, RTE_UINT32);
13997 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
13998         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13999                                  cack, "cack");
14000 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14001         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14002                               c_ack, RTE_UINT32);
14003 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14004         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14005                                  last_dir, "last_dir");
14006 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14007         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14008                               ld, RTE_UINT32);
14009 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14010         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14011                                  liberal, "liberal");
14012 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14013         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14014                               lb, RTE_UINT32);
14015 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14016         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14017                                  state, "state");
14018 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14019         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14020                               stat, RTE_UINT8);
14021 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14022         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14023                                  max_ack_win, "max_ack_win");
14024 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14025         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14026                               factor, RTE_UINT8);
14027 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14028         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14029                                  retrans, "r_lim");
14030 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14031         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14032                               re_num, RTE_UINT8);
14033 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14034         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14035                                  last_win, "last_win");
14036 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14037         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14038                               lw, RTE_UINT16);
14039 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14040         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14041                                  last_seq, "last_seq");
14042 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14043         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14044                               ls, RTE_UINT32);
14045 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14046         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14047                                  last_ack, "last_ack");
14048 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14049         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14050                               la, RTE_UINT32);
14051 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14052         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14053                                  last_end, "last_end");
14054 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14055         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14056                               le, RTE_UINT32);
14057 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14058         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14059                                  last_index, "last_index");
14060 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14061         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14062                               li, RTE_UINT8);
14063
14064 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14065         __rte_unused struct cmdline *cl,
14066         __rte_unused void *data)
14067 {
14068         struct cmd_set_conntrack_common_result *res = parsed_result;
14069
14070         /* No need to swap to big endian. */
14071         conntrack_context.peer_port = res->peer_port;
14072         conntrack_context.is_original_dir = res->is_original;
14073         conntrack_context.enable = res->en;
14074         conntrack_context.live_connection = res->is_live;
14075         conntrack_context.selective_ack = res->s_ack;
14076         conntrack_context.challenge_ack_passed = res->c_ack;
14077         conntrack_context.last_direction = res->ld;
14078         conntrack_context.liberal_mode = res->lb;
14079         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14080         conntrack_context.max_ack_window = res->factor;
14081         conntrack_context.retransmission_limit = res->re_num;
14082         conntrack_context.last_window = res->lw;
14083         conntrack_context.last_index =
14084                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14085         conntrack_context.last_seq = res->ls;
14086         conntrack_context.last_ack = res->la;
14087         conntrack_context.last_end = res->le;
14088 }
14089
14090 cmdline_parse_inst_t cmd_set_conntrack_common = {
14091         .f = cmd_set_conntrack_common_parsed,
14092         .data = NULL,
14093         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14094                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14095                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14096                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14097                 " last_index <flag>",
14098         .tokens = {
14099                 (void *)&cmd_set_conntrack_set,
14100                 (void *)&cmd_set_conntrack_conntrack,
14101                 (void *)&cmd_set_conntrack_common_com,
14102                 (void *)&cmd_set_conntrack_common_peer,
14103                 (void *)&cmd_set_conntrack_common_peer_value,
14104                 (void *)&cmd_set_conntrack_common_is_orig,
14105                 (void *)&cmd_set_conntrack_common_is_orig_value,
14106                 (void *)&cmd_set_conntrack_common_enable,
14107                 (void *)&cmd_set_conntrack_common_enable_value,
14108                 (void *)&cmd_set_conntrack_common_live,
14109                 (void *)&cmd_set_conntrack_common_live_value,
14110                 (void *)&cmd_set_conntrack_common_sack,
14111                 (void *)&cmd_set_conntrack_common_sack_value,
14112                 (void *)&cmd_set_conntrack_common_cack,
14113                 (void *)&cmd_set_conntrack_common_cack_value,
14114                 (void *)&cmd_set_conntrack_common_last_dir,
14115                 (void *)&cmd_set_conntrack_common_last_dir_value,
14116                 (void *)&cmd_set_conntrack_common_liberal,
14117                 (void *)&cmd_set_conntrack_common_liberal_value,
14118                 (void *)&cmd_set_conntrack_common_state,
14119                 (void *)&cmd_set_conntrack_common_state_value,
14120                 (void *)&cmd_set_conntrack_common_max_ackwin,
14121                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14122                 (void *)&cmd_set_conntrack_common_retrans,
14123                 (void *)&cmd_set_conntrack_common_retrans_value,
14124                 (void *)&cmd_set_conntrack_common_last_win,
14125                 (void *)&cmd_set_conntrack_common_last_win_value,
14126                 (void *)&cmd_set_conntrack_common_last_seq,
14127                 (void *)&cmd_set_conntrack_common_last_seq_value,
14128                 (void *)&cmd_set_conntrack_common_last_ack,
14129                 (void *)&cmd_set_conntrack_common_last_ack_value,
14130                 (void *)&cmd_set_conntrack_common_last_end,
14131                 (void *)&cmd_set_conntrack_common_last_end_value,
14132                 (void *)&cmd_set_conntrack_common_last_index,
14133                 (void *)&cmd_set_conntrack_common_last_index_value,
14134                 NULL,
14135         },
14136 };
14137
14138 /** Set connection tracking object both directions' details */
14139 struct cmd_set_conntrack_dir_result {
14140         cmdline_fixed_string_t set;
14141         cmdline_fixed_string_t conntrack;
14142         cmdline_fixed_string_t dir;
14143         cmdline_fixed_string_t scale;
14144         cmdline_fixed_string_t fin;
14145         cmdline_fixed_string_t ack_seen;
14146         cmdline_fixed_string_t unack;
14147         cmdline_fixed_string_t sent_end;
14148         cmdline_fixed_string_t reply_end;
14149         cmdline_fixed_string_t max_win;
14150         cmdline_fixed_string_t max_ack;
14151         uint32_t factor;
14152         uint32_t f;
14153         uint32_t as;
14154         uint32_t un;
14155         uint32_t se;
14156         uint32_t re;
14157         uint32_t mw;
14158         uint32_t ma;
14159 };
14160
14161 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14162         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14163                                  set, "set");
14164 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14165         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14166                                  conntrack, "conntrack");
14167 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14168         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14169                                  dir, "orig#rply");
14170 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14171         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14172                                  scale, "scale");
14173 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14174         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14175                               factor, RTE_UINT32);
14176 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14177         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14178                                  fin, "fin");
14179 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14180         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14181                               f, RTE_UINT32);
14182 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14183         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14184                                  ack_seen, "acked");
14185 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14186         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14187                               as, RTE_UINT32);
14188 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14189         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14190                                  unack, "unack_data");
14191 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14192         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14193                               un, RTE_UINT32);
14194 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14195         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14196                                  sent_end, "sent_end");
14197 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14198         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14199                               se, RTE_UINT32);
14200 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14201         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14202                                  reply_end, "reply_end");
14203 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14204         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14205                               re, RTE_UINT32);
14206 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14207         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14208                                  max_win, "max_win");
14209 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14210         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14211                               mw, RTE_UINT32);
14212 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14213         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14214                                  max_ack, "max_ack");
14215 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14216         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14217                               ma, RTE_UINT32);
14218
14219 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14220         __rte_unused struct cmdline *cl,
14221         __rte_unused void *data)
14222 {
14223         struct cmd_set_conntrack_dir_result *res = parsed_result;
14224         struct rte_flow_tcp_dir_param *dir = NULL;
14225
14226         if (strcmp(res->dir, "orig") == 0)
14227                 dir = &conntrack_context.original_dir;
14228         else if (strcmp(res->dir, "rply") == 0)
14229                 dir = &conntrack_context.reply_dir;
14230         else
14231                 return;
14232         dir->scale = res->factor;
14233         dir->close_initiated = res->f;
14234         dir->last_ack_seen = res->as;
14235         dir->data_unacked = res->un;
14236         dir->sent_end = res->se;
14237         dir->reply_end = res->re;
14238         dir->max_ack = res->ma;
14239         dir->max_win = res->mw;
14240 }
14241
14242 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14243         .f = cmd_set_conntrack_dir_parsed,
14244         .data = NULL,
14245         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14246                     " acked <seen> unack_data <unack> sent_end <sent>"
14247                     " reply_end <reply> max_win <win> max_ack <ack>",
14248         .tokens = {
14249                 (void *)&cmd_set_conntrack_set,
14250                 (void *)&cmd_set_conntrack_conntrack,
14251                 (void *)&cmd_set_conntrack_dir_dir,
14252                 (void *)&cmd_set_conntrack_dir_scale,
14253                 (void *)&cmd_set_conntrack_dir_scale_value,
14254                 (void *)&cmd_set_conntrack_dir_fin,
14255                 (void *)&cmd_set_conntrack_dir_fin_value,
14256                 (void *)&cmd_set_conntrack_dir_ack,
14257                 (void *)&cmd_set_conntrack_dir_ack_value,
14258                 (void *)&cmd_set_conntrack_dir_unack_data,
14259                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14260                 (void *)&cmd_set_conntrack_dir_sent_end,
14261                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14262                 (void *)&cmd_set_conntrack_dir_reply_end,
14263                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14264                 (void *)&cmd_set_conntrack_dir_max_win,
14265                 (void *)&cmd_set_conntrack_dir_max_win_value,
14266                 (void *)&cmd_set_conntrack_dir_max_ack,
14267                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14268                 NULL,
14269         },
14270 };
14271
14272 /* Strict link priority scheduling mode setting */
14273 static void
14274 cmd_strict_link_prio_parsed(
14275         void *parsed_result,
14276         __rte_unused struct cmdline *cl,
14277         __rte_unused void *data)
14278 {
14279         struct cmd_vf_tc_bw_result *res = parsed_result;
14280         int ret = -ENOTSUP;
14281
14282         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14283                 return;
14284
14285 #ifdef RTE_NET_I40E
14286         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14287 #endif
14288
14289         switch (ret) {
14290         case 0:
14291                 break;
14292         case -EINVAL:
14293                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14294                 break;
14295         case -ENODEV:
14296                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14297                 break;
14298         case -ENOTSUP:
14299                 fprintf(stderr, "function not implemented\n");
14300                 break;
14301         default:
14302                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14303         }
14304 }
14305
14306 cmdline_parse_inst_t cmd_strict_link_prio = {
14307         .f = cmd_strict_link_prio_parsed,
14308         .data = NULL,
14309         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14310         .tokens = {
14311                 (void *)&cmd_vf_tc_bw_set,
14312                 (void *)&cmd_vf_tc_bw_tx,
14313                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14314                 (void *)&cmd_vf_tc_bw_port_id,
14315                 (void *)&cmd_vf_tc_bw_tc_map,
14316                 NULL,
14317         },
14318 };
14319
14320 /* Load dynamic device personalization*/
14321 struct cmd_ddp_add_result {
14322         cmdline_fixed_string_t ddp;
14323         cmdline_fixed_string_t add;
14324         portid_t port_id;
14325         char filepath[];
14326 };
14327
14328 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14329         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14330 cmdline_parse_token_string_t cmd_ddp_add_add =
14331         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14332 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14333         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14334                 RTE_UINT16);
14335 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14336         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14337
14338 static void
14339 cmd_ddp_add_parsed(
14340         void *parsed_result,
14341         __rte_unused struct cmdline *cl,
14342         __rte_unused void *data)
14343 {
14344         struct cmd_ddp_add_result *res = parsed_result;
14345         uint8_t *buff;
14346         uint32_t size;
14347         char *filepath;
14348         char *file_fld[2];
14349         int file_num;
14350         int ret = -ENOTSUP;
14351
14352         if (!all_ports_stopped()) {
14353                 fprintf(stderr, "Please stop all ports first\n");
14354                 return;
14355         }
14356
14357         filepath = strdup(res->filepath);
14358         if (filepath == NULL) {
14359                 fprintf(stderr, "Failed to allocate memory\n");
14360                 return;
14361         }
14362         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14363
14364         buff = open_file(file_fld[0], &size);
14365         if (!buff) {
14366                 free((void *)filepath);
14367                 return;
14368         }
14369
14370 #ifdef RTE_NET_I40E
14371         if (ret == -ENOTSUP)
14372                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14373                                                buff, size,
14374                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14375 #endif
14376
14377         if (ret == -EEXIST)
14378                 fprintf(stderr, "Profile has already existed.\n");
14379         else if (ret < 0)
14380                 fprintf(stderr, "Failed to load profile.\n");
14381         else if (file_num == 2)
14382                 save_file(file_fld[1], buff, size);
14383
14384         close_file(buff);
14385         free((void *)filepath);
14386 }
14387
14388 cmdline_parse_inst_t cmd_ddp_add = {
14389         .f = cmd_ddp_add_parsed,
14390         .data = NULL,
14391         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14392         .tokens = {
14393                 (void *)&cmd_ddp_add_ddp,
14394                 (void *)&cmd_ddp_add_add,
14395                 (void *)&cmd_ddp_add_port_id,
14396                 (void *)&cmd_ddp_add_filepath,
14397                 NULL,
14398         },
14399 };
14400
14401 /* Delete dynamic device personalization*/
14402 struct cmd_ddp_del_result {
14403         cmdline_fixed_string_t ddp;
14404         cmdline_fixed_string_t del;
14405         portid_t port_id;
14406         char filepath[];
14407 };
14408
14409 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14410         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14411 cmdline_parse_token_string_t cmd_ddp_del_del =
14412         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14413 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14414         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14415 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14416         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14417
14418 static void
14419 cmd_ddp_del_parsed(
14420         void *parsed_result,
14421         __rte_unused struct cmdline *cl,
14422         __rte_unused void *data)
14423 {
14424         struct cmd_ddp_del_result *res = parsed_result;
14425         uint8_t *buff;
14426         uint32_t size;
14427         int ret = -ENOTSUP;
14428
14429         if (!all_ports_stopped()) {
14430                 fprintf(stderr, "Please stop all ports first\n");
14431                 return;
14432         }
14433
14434         buff = open_file(res->filepath, &size);
14435         if (!buff)
14436                 return;
14437
14438 #ifdef RTE_NET_I40E
14439         if (ret == -ENOTSUP)
14440                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14441                                                buff, size,
14442                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14443 #endif
14444
14445         if (ret == -EACCES)
14446                 fprintf(stderr, "Profile does not exist.\n");
14447         else if (ret < 0)
14448                 fprintf(stderr, "Failed to delete profile.\n");
14449
14450         close_file(buff);
14451 }
14452
14453 cmdline_parse_inst_t cmd_ddp_del = {
14454         .f = cmd_ddp_del_parsed,
14455         .data = NULL,
14456         .help_str = "ddp del <port_id> <backup_profile_path>",
14457         .tokens = {
14458                 (void *)&cmd_ddp_del_ddp,
14459                 (void *)&cmd_ddp_del_del,
14460                 (void *)&cmd_ddp_del_port_id,
14461                 (void *)&cmd_ddp_del_filepath,
14462                 NULL,
14463         },
14464 };
14465
14466 /* Get dynamic device personalization profile info */
14467 struct cmd_ddp_info_result {
14468         cmdline_fixed_string_t ddp;
14469         cmdline_fixed_string_t get;
14470         cmdline_fixed_string_t info;
14471         char filepath[];
14472 };
14473
14474 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14475         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14476 cmdline_parse_token_string_t cmd_ddp_info_get =
14477         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14478 cmdline_parse_token_string_t cmd_ddp_info_info =
14479         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14480 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14481         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14482
14483 static void
14484 cmd_ddp_info_parsed(
14485         void *parsed_result,
14486         __rte_unused struct cmdline *cl,
14487         __rte_unused void *data)
14488 {
14489         struct cmd_ddp_info_result *res = parsed_result;
14490         uint8_t *pkg;
14491         uint32_t pkg_size;
14492         int ret = -ENOTSUP;
14493 #ifdef RTE_NET_I40E
14494         uint32_t i, j, n;
14495         uint8_t *buff;
14496         uint32_t buff_size = 0;
14497         struct rte_pmd_i40e_profile_info info;
14498         uint32_t dev_num = 0;
14499         struct rte_pmd_i40e_ddp_device_id *devs;
14500         uint32_t proto_num = 0;
14501         struct rte_pmd_i40e_proto_info *proto = NULL;
14502         uint32_t pctype_num = 0;
14503         struct rte_pmd_i40e_ptype_info *pctype;
14504         uint32_t ptype_num = 0;
14505         struct rte_pmd_i40e_ptype_info *ptype;
14506         uint8_t proto_id;
14507
14508 #endif
14509
14510         pkg = open_file(res->filepath, &pkg_size);
14511         if (!pkg)
14512                 return;
14513
14514 #ifdef RTE_NET_I40E
14515         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14516                                 (uint8_t *)&info, sizeof(info),
14517                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14518         if (!ret) {
14519                 printf("Global Track id:       0x%x\n", info.track_id);
14520                 printf("Global Version:        %d.%d.%d.%d\n",
14521                         info.version.major,
14522                         info.version.minor,
14523                         info.version.update,
14524                         info.version.draft);
14525                 printf("Global Package name:   %s\n\n", info.name);
14526         }
14527
14528         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14529                                 (uint8_t *)&info, sizeof(info),
14530                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14531         if (!ret) {
14532                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14533                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14534                         info.version.major,
14535                         info.version.minor,
14536                         info.version.update,
14537                         info.version.draft);
14538                 printf("i40e Profile name:     %s\n\n", info.name);
14539         }
14540
14541         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14542                                 (uint8_t *)&buff_size, sizeof(buff_size),
14543                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14544         if (!ret && buff_size) {
14545                 buff = (uint8_t *)malloc(buff_size);
14546                 if (buff) {
14547                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14548                                                 buff, buff_size,
14549                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14550                         if (!ret)
14551                                 printf("Package Notes:\n%s\n\n", buff);
14552                         free(buff);
14553                 }
14554         }
14555
14556         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14557                                 (uint8_t *)&dev_num, sizeof(dev_num),
14558                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14559         if (!ret && dev_num) {
14560                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14561                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14562                 if (devs) {
14563                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14564                                                 (uint8_t *)devs, buff_size,
14565                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14566                         if (!ret) {
14567                                 printf("List of supported devices:\n");
14568                                 for (i = 0; i < dev_num; i++) {
14569                                         printf("  %04X:%04X %04X:%04X\n",
14570                                                 devs[i].vendor_dev_id >> 16,
14571                                                 devs[i].vendor_dev_id & 0xFFFF,
14572                                                 devs[i].sub_vendor_dev_id >> 16,
14573                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14574                                 }
14575                                 printf("\n");
14576                         }
14577                         free(devs);
14578                 }
14579         }
14580
14581         /* get information about protocols and packet types */
14582         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14583                 (uint8_t *)&proto_num, sizeof(proto_num),
14584                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14585         if (ret || !proto_num)
14586                 goto no_print_return;
14587
14588         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14589         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14590         if (!proto)
14591                 goto no_print_return;
14592
14593         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14594                                         buff_size,
14595                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14596         if (!ret) {
14597                 printf("List of used protocols:\n");
14598                 for (i = 0; i < proto_num; i++)
14599                         printf("  %2u: %s\n", proto[i].proto_id,
14600                                proto[i].name);
14601                 printf("\n");
14602         }
14603         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14604                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14605                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14606         if (ret || !pctype_num)
14607                 goto no_print_pctypes;
14608
14609         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14610         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14611         if (!pctype)
14612                 goto no_print_pctypes;
14613
14614         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14615                                         buff_size,
14616                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14617         if (ret) {
14618                 free(pctype);
14619                 goto no_print_pctypes;
14620         }
14621
14622         printf("List of defined packet classification types:\n");
14623         for (i = 0; i < pctype_num; i++) {
14624                 printf("  %2u:", pctype[i].ptype_id);
14625                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14626                         proto_id = pctype[i].protocols[j];
14627                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14628                                 for (n = 0; n < proto_num; n++) {
14629                                         if (proto[n].proto_id == proto_id) {
14630                                                 printf(" %s", proto[n].name);
14631                                                 break;
14632                                         }
14633                                 }
14634                         }
14635                 }
14636                 printf("\n");
14637         }
14638         printf("\n");
14639         free(pctype);
14640
14641 no_print_pctypes:
14642
14643         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14644                                         sizeof(ptype_num),
14645                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14646         if (ret || !ptype_num)
14647                 goto no_print_return;
14648
14649         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14650         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14651         if (!ptype)
14652                 goto no_print_return;
14653
14654         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14655                                         buff_size,
14656                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14657         if (ret) {
14658                 free(ptype);
14659                 goto no_print_return;
14660         }
14661         printf("List of defined packet types:\n");
14662         for (i = 0; i < ptype_num; i++) {
14663                 printf("  %2u:", ptype[i].ptype_id);
14664                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14665                         proto_id = ptype[i].protocols[j];
14666                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14667                                 for (n = 0; n < proto_num; n++) {
14668                                         if (proto[n].proto_id == proto_id) {
14669                                                 printf(" %s", proto[n].name);
14670                                                 break;
14671                                         }
14672                                 }
14673                         }
14674                 }
14675                 printf("\n");
14676         }
14677         free(ptype);
14678         printf("\n");
14679
14680         ret = 0;
14681 no_print_return:
14682         if (proto)
14683                 free(proto);
14684 #endif
14685         if (ret == -ENOTSUP)
14686                 fprintf(stderr, "Function not supported in PMD driver\n");
14687         close_file(pkg);
14688 }
14689
14690 cmdline_parse_inst_t cmd_ddp_get_info = {
14691         .f = cmd_ddp_info_parsed,
14692         .data = NULL,
14693         .help_str = "ddp get info <profile_path>",
14694         .tokens = {
14695                 (void *)&cmd_ddp_info_ddp,
14696                 (void *)&cmd_ddp_info_get,
14697                 (void *)&cmd_ddp_info_info,
14698                 (void *)&cmd_ddp_info_filepath,
14699                 NULL,
14700         },
14701 };
14702
14703 /* Get dynamic device personalization profile info list*/
14704 #define PROFILE_INFO_SIZE 48
14705 #define MAX_PROFILE_NUM 16
14706
14707 struct cmd_ddp_get_list_result {
14708         cmdline_fixed_string_t ddp;
14709         cmdline_fixed_string_t get;
14710         cmdline_fixed_string_t list;
14711         portid_t port_id;
14712 };
14713
14714 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14715         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14716 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14717         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14718 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14719         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14720 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14721         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14722                 RTE_UINT16);
14723
14724 static void
14725 cmd_ddp_get_list_parsed(
14726         __rte_unused void *parsed_result,
14727         __rte_unused struct cmdline *cl,
14728         __rte_unused void *data)
14729 {
14730 #ifdef RTE_NET_I40E
14731         struct cmd_ddp_get_list_result *res = parsed_result;
14732         struct rte_pmd_i40e_profile_list *p_list;
14733         struct rte_pmd_i40e_profile_info *p_info;
14734         uint32_t p_num;
14735         uint32_t size;
14736         uint32_t i;
14737 #endif
14738         int ret = -ENOTSUP;
14739
14740 #ifdef RTE_NET_I40E
14741         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14742         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14743         if (!p_list) {
14744                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14745                 return;
14746         }
14747
14748         if (ret == -ENOTSUP)
14749                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14750                                                 (uint8_t *)p_list, size);
14751
14752         if (!ret) {
14753                 p_num = p_list->p_count;
14754                 printf("Profile number is: %d\n\n", p_num);
14755
14756                 for (i = 0; i < p_num; i++) {
14757                         p_info = &p_list->p_info[i];
14758                         printf("Profile %d:\n", i);
14759                         printf("Track id:     0x%x\n", p_info->track_id);
14760                         printf("Version:      %d.%d.%d.%d\n",
14761                                p_info->version.major,
14762                                p_info->version.minor,
14763                                p_info->version.update,
14764                                p_info->version.draft);
14765                         printf("Profile name: %s\n\n", p_info->name);
14766                 }
14767         }
14768
14769         free(p_list);
14770 #endif
14771
14772         if (ret < 0)
14773                 fprintf(stderr, "Failed to get ddp list\n");
14774 }
14775
14776 cmdline_parse_inst_t cmd_ddp_get_list = {
14777         .f = cmd_ddp_get_list_parsed,
14778         .data = NULL,
14779         .help_str = "ddp get list <port_id>",
14780         .tokens = {
14781                 (void *)&cmd_ddp_get_list_ddp,
14782                 (void *)&cmd_ddp_get_list_get,
14783                 (void *)&cmd_ddp_get_list_list,
14784                 (void *)&cmd_ddp_get_list_port_id,
14785                 NULL,
14786         },
14787 };
14788
14789 /* Configure input set */
14790 struct cmd_cfg_input_set_result {
14791         cmdline_fixed_string_t port;
14792         cmdline_fixed_string_t cfg;
14793         portid_t port_id;
14794         cmdline_fixed_string_t pctype;
14795         uint8_t pctype_id;
14796         cmdline_fixed_string_t inset_type;
14797         cmdline_fixed_string_t opt;
14798         cmdline_fixed_string_t field;
14799         uint8_t field_idx;
14800 };
14801
14802 static void
14803 cmd_cfg_input_set_parsed(
14804         __rte_unused void *parsed_result,
14805         __rte_unused struct cmdline *cl,
14806         __rte_unused void *data)
14807 {
14808 #ifdef RTE_NET_I40E
14809         struct cmd_cfg_input_set_result *res = parsed_result;
14810         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14811         struct rte_pmd_i40e_inset inset;
14812 #endif
14813         int ret = -ENOTSUP;
14814
14815         if (!all_ports_stopped()) {
14816                 fprintf(stderr, "Please stop all ports first\n");
14817                 return;
14818         }
14819
14820 #ifdef RTE_NET_I40E
14821         if (!strcmp(res->inset_type, "hash_inset"))
14822                 inset_type = INSET_HASH;
14823         else if (!strcmp(res->inset_type, "fdir_inset"))
14824                 inset_type = INSET_FDIR;
14825         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14826                 inset_type = INSET_FDIR_FLX;
14827         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14828                                      &inset, inset_type);
14829         if (ret) {
14830                 fprintf(stderr, "Failed to get input set.\n");
14831                 return;
14832         }
14833
14834         if (!strcmp(res->opt, "get")) {
14835                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14836                                                    res->field_idx);
14837                 if (ret)
14838                         printf("Field index %d is enabled.\n", res->field_idx);
14839                 else
14840                         printf("Field index %d is disabled.\n", res->field_idx);
14841                 return;
14842         } else if (!strcmp(res->opt, "set"))
14843                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14844                                                    res->field_idx);
14845         else if (!strcmp(res->opt, "clear"))
14846                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14847                                                      res->field_idx);
14848         if (ret) {
14849                 fprintf(stderr, "Failed to configure input set field.\n");
14850                 return;
14851         }
14852
14853         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14854                                      &inset, inset_type);
14855         if (ret) {
14856                 fprintf(stderr, "Failed to set input set.\n");
14857                 return;
14858         }
14859 #endif
14860
14861         if (ret == -ENOTSUP)
14862                 fprintf(stderr, "Function not supported\n");
14863 }
14864
14865 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14866         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14867                                  port, "port");
14868 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14869         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14870                                  cfg, "config");
14871 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14872         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14873                               port_id, RTE_UINT16);
14874 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14875         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14876                                  pctype, "pctype");
14877 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14878         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14879                               pctype_id, RTE_UINT8);
14880 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14881         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14882                                  inset_type,
14883                                  "hash_inset#fdir_inset#fdir_flx_inset");
14884 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14885         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14886                                  opt, "get#set#clear");
14887 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14888         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14889                                  field, "field");
14890 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14891         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14892                               field_idx, RTE_UINT8);
14893
14894 cmdline_parse_inst_t cmd_cfg_input_set = {
14895         .f = cmd_cfg_input_set_parsed,
14896         .data = NULL,
14897         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14898                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14899         .tokens = {
14900                 (void *)&cmd_cfg_input_set_port,
14901                 (void *)&cmd_cfg_input_set_cfg,
14902                 (void *)&cmd_cfg_input_set_port_id,
14903                 (void *)&cmd_cfg_input_set_pctype,
14904                 (void *)&cmd_cfg_input_set_pctype_id,
14905                 (void *)&cmd_cfg_input_set_inset_type,
14906                 (void *)&cmd_cfg_input_set_opt,
14907                 (void *)&cmd_cfg_input_set_field,
14908                 (void *)&cmd_cfg_input_set_field_idx,
14909                 NULL,
14910         },
14911 };
14912
14913 /* Clear input set */
14914 struct cmd_clear_input_set_result {
14915         cmdline_fixed_string_t port;
14916         cmdline_fixed_string_t cfg;
14917         portid_t port_id;
14918         cmdline_fixed_string_t pctype;
14919         uint8_t pctype_id;
14920         cmdline_fixed_string_t inset_type;
14921         cmdline_fixed_string_t clear;
14922         cmdline_fixed_string_t all;
14923 };
14924
14925 static void
14926 cmd_clear_input_set_parsed(
14927         __rte_unused void *parsed_result,
14928         __rte_unused struct cmdline *cl,
14929         __rte_unused void *data)
14930 {
14931 #ifdef RTE_NET_I40E
14932         struct cmd_clear_input_set_result *res = parsed_result;
14933         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14934         struct rte_pmd_i40e_inset inset;
14935 #endif
14936         int ret = -ENOTSUP;
14937
14938         if (!all_ports_stopped()) {
14939                 fprintf(stderr, "Please stop all ports first\n");
14940                 return;
14941         }
14942
14943 #ifdef RTE_NET_I40E
14944         if (!strcmp(res->inset_type, "hash_inset"))
14945                 inset_type = INSET_HASH;
14946         else if (!strcmp(res->inset_type, "fdir_inset"))
14947                 inset_type = INSET_FDIR;
14948         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14949                 inset_type = INSET_FDIR_FLX;
14950
14951         memset(&inset, 0, sizeof(inset));
14952
14953         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14954                                      &inset, inset_type);
14955         if (ret) {
14956                 fprintf(stderr, "Failed to clear input set.\n");
14957                 return;
14958         }
14959
14960 #endif
14961
14962         if (ret == -ENOTSUP)
14963                 fprintf(stderr, "Function not supported\n");
14964 }
14965
14966 cmdline_parse_token_string_t cmd_clear_input_set_port =
14967         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14968                                  port, "port");
14969 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14970         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14971                                  cfg, "config");
14972 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14973         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14974                               port_id, RTE_UINT16);
14975 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14976         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14977                                  pctype, "pctype");
14978 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14979         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14980                               pctype_id, RTE_UINT8);
14981 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14982         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14983                                  inset_type,
14984                                  "hash_inset#fdir_inset#fdir_flx_inset");
14985 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14986         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14987                                  clear, "clear");
14988 cmdline_parse_token_string_t cmd_clear_input_set_all =
14989         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14990                                  all, "all");
14991
14992 cmdline_parse_inst_t cmd_clear_input_set = {
14993         .f = cmd_clear_input_set_parsed,
14994         .data = NULL,
14995         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14996                     "fdir_inset|fdir_flx_inset clear all",
14997         .tokens = {
14998                 (void *)&cmd_clear_input_set_port,
14999                 (void *)&cmd_clear_input_set_cfg,
15000                 (void *)&cmd_clear_input_set_port_id,
15001                 (void *)&cmd_clear_input_set_pctype,
15002                 (void *)&cmd_clear_input_set_pctype_id,
15003                 (void *)&cmd_clear_input_set_inset_type,
15004                 (void *)&cmd_clear_input_set_clear,
15005                 (void *)&cmd_clear_input_set_all,
15006                 NULL,
15007         },
15008 };
15009
15010 /* show vf stats */
15011
15012 /* Common result structure for show vf stats */
15013 struct cmd_show_vf_stats_result {
15014         cmdline_fixed_string_t show;
15015         cmdline_fixed_string_t vf;
15016         cmdline_fixed_string_t stats;
15017         portid_t port_id;
15018         uint16_t vf_id;
15019 };
15020
15021 /* Common CLI fields show vf stats*/
15022 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15023         TOKEN_STRING_INITIALIZER
15024                 (struct cmd_show_vf_stats_result,
15025                  show, "show");
15026 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15027         TOKEN_STRING_INITIALIZER
15028                 (struct cmd_show_vf_stats_result,
15029                  vf, "vf");
15030 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15031         TOKEN_STRING_INITIALIZER
15032                 (struct cmd_show_vf_stats_result,
15033                  stats, "stats");
15034 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15035         TOKEN_NUM_INITIALIZER
15036                 (struct cmd_show_vf_stats_result,
15037                  port_id, RTE_UINT16);
15038 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15039         TOKEN_NUM_INITIALIZER
15040                 (struct cmd_show_vf_stats_result,
15041                  vf_id, RTE_UINT16);
15042
15043 static void
15044 cmd_show_vf_stats_parsed(
15045         void *parsed_result,
15046         __rte_unused struct cmdline *cl,
15047         __rte_unused void *data)
15048 {
15049         struct cmd_show_vf_stats_result *res = parsed_result;
15050         struct rte_eth_stats stats;
15051         int ret = -ENOTSUP;
15052         static const char *nic_stats_border = "########################";
15053
15054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15055                 return;
15056
15057         memset(&stats, 0, sizeof(stats));
15058
15059 #ifdef RTE_NET_I40E
15060         if (ret == -ENOTSUP)
15061                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15062                                                 res->vf_id,
15063                                                 &stats);
15064 #endif
15065 #ifdef RTE_NET_BNXT
15066         if (ret == -ENOTSUP)
15067                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15068                                                 res->vf_id,
15069                                                 &stats);
15070 #endif
15071
15072         switch (ret) {
15073         case 0:
15074                 break;
15075         case -EINVAL:
15076                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15077                 break;
15078         case -ENODEV:
15079                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15080                 break;
15081         case -ENOTSUP:
15082                 fprintf(stderr, "function not implemented\n");
15083                 break;
15084         default:
15085                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15086         }
15087
15088         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15089                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15090
15091         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15092                "%-"PRIu64"\n",
15093                stats.ipackets, stats.imissed, stats.ibytes);
15094         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15095         printf("  RX-nombuf:  %-10"PRIu64"\n",
15096                stats.rx_nombuf);
15097         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15098                "%-"PRIu64"\n",
15099                stats.opackets, stats.oerrors, stats.obytes);
15100
15101         printf("  %s############################%s\n",
15102                                nic_stats_border, nic_stats_border);
15103 }
15104
15105 cmdline_parse_inst_t cmd_show_vf_stats = {
15106         .f = cmd_show_vf_stats_parsed,
15107         .data = NULL,
15108         .help_str = "show vf stats <port_id> <vf_id>",
15109         .tokens = {
15110                 (void *)&cmd_show_vf_stats_show,
15111                 (void *)&cmd_show_vf_stats_vf,
15112                 (void *)&cmd_show_vf_stats_stats,
15113                 (void *)&cmd_show_vf_stats_port_id,
15114                 (void *)&cmd_show_vf_stats_vf_id,
15115                 NULL,
15116         },
15117 };
15118
15119 /* clear vf stats */
15120
15121 /* Common result structure for clear vf stats */
15122 struct cmd_clear_vf_stats_result {
15123         cmdline_fixed_string_t clear;
15124         cmdline_fixed_string_t vf;
15125         cmdline_fixed_string_t stats;
15126         portid_t port_id;
15127         uint16_t vf_id;
15128 };
15129
15130 /* Common CLI fields clear vf stats*/
15131 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15132         TOKEN_STRING_INITIALIZER
15133                 (struct cmd_clear_vf_stats_result,
15134                  clear, "clear");
15135 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15136         TOKEN_STRING_INITIALIZER
15137                 (struct cmd_clear_vf_stats_result,
15138                  vf, "vf");
15139 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15140         TOKEN_STRING_INITIALIZER
15141                 (struct cmd_clear_vf_stats_result,
15142                  stats, "stats");
15143 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15144         TOKEN_NUM_INITIALIZER
15145                 (struct cmd_clear_vf_stats_result,
15146                  port_id, RTE_UINT16);
15147 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15148         TOKEN_NUM_INITIALIZER
15149                 (struct cmd_clear_vf_stats_result,
15150                  vf_id, RTE_UINT16);
15151
15152 static void
15153 cmd_clear_vf_stats_parsed(
15154         void *parsed_result,
15155         __rte_unused struct cmdline *cl,
15156         __rte_unused void *data)
15157 {
15158         struct cmd_clear_vf_stats_result *res = parsed_result;
15159         int ret = -ENOTSUP;
15160
15161         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15162                 return;
15163
15164 #ifdef RTE_NET_I40E
15165         if (ret == -ENOTSUP)
15166                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15167                                                   res->vf_id);
15168 #endif
15169 #ifdef RTE_NET_BNXT
15170         if (ret == -ENOTSUP)
15171                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15172                                                   res->vf_id);
15173 #endif
15174
15175         switch (ret) {
15176         case 0:
15177                 break;
15178         case -EINVAL:
15179                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15180                 break;
15181         case -ENODEV:
15182                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15183                 break;
15184         case -ENOTSUP:
15185                 fprintf(stderr, "function not implemented\n");
15186                 break;
15187         default:
15188                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15189         }
15190 }
15191
15192 cmdline_parse_inst_t cmd_clear_vf_stats = {
15193         .f = cmd_clear_vf_stats_parsed,
15194         .data = NULL,
15195         .help_str = "clear vf stats <port_id> <vf_id>",
15196         .tokens = {
15197                 (void *)&cmd_clear_vf_stats_clear,
15198                 (void *)&cmd_clear_vf_stats_vf,
15199                 (void *)&cmd_clear_vf_stats_stats,
15200                 (void *)&cmd_clear_vf_stats_port_id,
15201                 (void *)&cmd_clear_vf_stats_vf_id,
15202                 NULL,
15203         },
15204 };
15205
15206 /* port config pctype mapping reset */
15207
15208 /* Common result structure for port config pctype mapping reset */
15209 struct cmd_pctype_mapping_reset_result {
15210         cmdline_fixed_string_t port;
15211         cmdline_fixed_string_t config;
15212         portid_t port_id;
15213         cmdline_fixed_string_t pctype;
15214         cmdline_fixed_string_t mapping;
15215         cmdline_fixed_string_t reset;
15216 };
15217
15218 /* Common CLI fields for port config pctype mapping reset*/
15219 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15220         TOKEN_STRING_INITIALIZER
15221                 (struct cmd_pctype_mapping_reset_result,
15222                  port, "port");
15223 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15224         TOKEN_STRING_INITIALIZER
15225                 (struct cmd_pctype_mapping_reset_result,
15226                  config, "config");
15227 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15228         TOKEN_NUM_INITIALIZER
15229                 (struct cmd_pctype_mapping_reset_result,
15230                  port_id, RTE_UINT16);
15231 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15232         TOKEN_STRING_INITIALIZER
15233                 (struct cmd_pctype_mapping_reset_result,
15234                  pctype, "pctype");
15235 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15236         TOKEN_STRING_INITIALIZER
15237                 (struct cmd_pctype_mapping_reset_result,
15238                  mapping, "mapping");
15239 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15240         TOKEN_STRING_INITIALIZER
15241                 (struct cmd_pctype_mapping_reset_result,
15242                  reset, "reset");
15243
15244 static void
15245 cmd_pctype_mapping_reset_parsed(
15246         void *parsed_result,
15247         __rte_unused struct cmdline *cl,
15248         __rte_unused void *data)
15249 {
15250         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15251         int ret = -ENOTSUP;
15252
15253         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15254                 return;
15255
15256 #ifdef RTE_NET_I40E
15257         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15258 #endif
15259
15260         switch (ret) {
15261         case 0:
15262                 break;
15263         case -ENODEV:
15264                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15265                 break;
15266         case -ENOTSUP:
15267                 fprintf(stderr, "function not implemented\n");
15268                 break;
15269         default:
15270                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15271         }
15272 }
15273
15274 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15275         .f = cmd_pctype_mapping_reset_parsed,
15276         .data = NULL,
15277         .help_str = "port config <port_id> pctype mapping reset",
15278         .tokens = {
15279                 (void *)&cmd_pctype_mapping_reset_port,
15280                 (void *)&cmd_pctype_mapping_reset_config,
15281                 (void *)&cmd_pctype_mapping_reset_port_id,
15282                 (void *)&cmd_pctype_mapping_reset_pctype,
15283                 (void *)&cmd_pctype_mapping_reset_mapping,
15284                 (void *)&cmd_pctype_mapping_reset_reset,
15285                 NULL,
15286         },
15287 };
15288
15289 /* show port pctype mapping */
15290
15291 /* Common result structure for show port pctype mapping */
15292 struct cmd_pctype_mapping_get_result {
15293         cmdline_fixed_string_t show;
15294         cmdline_fixed_string_t port;
15295         portid_t port_id;
15296         cmdline_fixed_string_t pctype;
15297         cmdline_fixed_string_t mapping;
15298 };
15299
15300 /* Common CLI fields for pctype mapping get */
15301 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15302         TOKEN_STRING_INITIALIZER
15303                 (struct cmd_pctype_mapping_get_result,
15304                  show, "show");
15305 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15306         TOKEN_STRING_INITIALIZER
15307                 (struct cmd_pctype_mapping_get_result,
15308                  port, "port");
15309 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15310         TOKEN_NUM_INITIALIZER
15311                 (struct cmd_pctype_mapping_get_result,
15312                  port_id, RTE_UINT16);
15313 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15314         TOKEN_STRING_INITIALIZER
15315                 (struct cmd_pctype_mapping_get_result,
15316                  pctype, "pctype");
15317 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15318         TOKEN_STRING_INITIALIZER
15319                 (struct cmd_pctype_mapping_get_result,
15320                  mapping, "mapping");
15321
15322 static void
15323 cmd_pctype_mapping_get_parsed(
15324         void *parsed_result,
15325         __rte_unused struct cmdline *cl,
15326         __rte_unused void *data)
15327 {
15328         struct cmd_pctype_mapping_get_result *res = parsed_result;
15329         int ret = -ENOTSUP;
15330 #ifdef RTE_NET_I40E
15331         struct rte_pmd_i40e_flow_type_mapping
15332                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15333         int i, j, first_pctype;
15334 #endif
15335
15336         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15337                 return;
15338
15339 #ifdef RTE_NET_I40E
15340         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15341 #endif
15342
15343         switch (ret) {
15344         case 0:
15345                 break;
15346         case -ENODEV:
15347                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15348                 return;
15349         case -ENOTSUP:
15350                 fprintf(stderr, "function not implemented\n");
15351                 return;
15352         default:
15353                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15354                 return;
15355         }
15356
15357 #ifdef RTE_NET_I40E
15358         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15359                 if (mapping[i].pctype != 0ULL) {
15360                         first_pctype = 1;
15361
15362                         printf("pctype: ");
15363                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15364                                 if (mapping[i].pctype & (1ULL << j)) {
15365                                         printf(first_pctype ?
15366                                                "%02d" : ",%02d", j);
15367                                         first_pctype = 0;
15368                                 }
15369                         }
15370                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15371                 }
15372         }
15373 #endif
15374 }
15375
15376 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15377         .f = cmd_pctype_mapping_get_parsed,
15378         .data = NULL,
15379         .help_str = "show port <port_id> pctype mapping",
15380         .tokens = {
15381                 (void *)&cmd_pctype_mapping_get_show,
15382                 (void *)&cmd_pctype_mapping_get_port,
15383                 (void *)&cmd_pctype_mapping_get_port_id,
15384                 (void *)&cmd_pctype_mapping_get_pctype,
15385                 (void *)&cmd_pctype_mapping_get_mapping,
15386                 NULL,
15387         },
15388 };
15389
15390 /* port config pctype mapping update */
15391
15392 /* Common result structure for port config pctype mapping update */
15393 struct cmd_pctype_mapping_update_result {
15394         cmdline_fixed_string_t port;
15395         cmdline_fixed_string_t config;
15396         portid_t port_id;
15397         cmdline_fixed_string_t pctype;
15398         cmdline_fixed_string_t mapping;
15399         cmdline_fixed_string_t update;
15400         cmdline_fixed_string_t pctype_list;
15401         uint16_t flow_type;
15402 };
15403
15404 /* Common CLI fields for pctype mapping update*/
15405 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15406         TOKEN_STRING_INITIALIZER
15407                 (struct cmd_pctype_mapping_update_result,
15408                  port, "port");
15409 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15410         TOKEN_STRING_INITIALIZER
15411                 (struct cmd_pctype_mapping_update_result,
15412                  config, "config");
15413 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15414         TOKEN_NUM_INITIALIZER
15415                 (struct cmd_pctype_mapping_update_result,
15416                  port_id, RTE_UINT16);
15417 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15418         TOKEN_STRING_INITIALIZER
15419                 (struct cmd_pctype_mapping_update_result,
15420                  pctype, "pctype");
15421 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15422         TOKEN_STRING_INITIALIZER
15423                 (struct cmd_pctype_mapping_update_result,
15424                  mapping, "mapping");
15425 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15426         TOKEN_STRING_INITIALIZER
15427                 (struct cmd_pctype_mapping_update_result,
15428                  update, "update");
15429 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15430         TOKEN_STRING_INITIALIZER
15431                 (struct cmd_pctype_mapping_update_result,
15432                  pctype_list, NULL);
15433 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15434         TOKEN_NUM_INITIALIZER
15435                 (struct cmd_pctype_mapping_update_result,
15436                  flow_type, RTE_UINT16);
15437
15438 static void
15439 cmd_pctype_mapping_update_parsed(
15440         void *parsed_result,
15441         __rte_unused struct cmdline *cl,
15442         __rte_unused void *data)
15443 {
15444         struct cmd_pctype_mapping_update_result *res = parsed_result;
15445         int ret = -ENOTSUP;
15446 #ifdef RTE_NET_I40E
15447         struct rte_pmd_i40e_flow_type_mapping mapping;
15448         unsigned int i;
15449         unsigned int nb_item;
15450         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15451 #endif
15452
15453         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15454                 return;
15455
15456 #ifdef RTE_NET_I40E
15457         nb_item = parse_item_list(res->pctype_list, "pctypes",
15458                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15459         mapping.flow_type = res->flow_type;
15460         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15461                 mapping.pctype |= (1ULL << pctype_list[i]);
15462         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15463                                                 &mapping,
15464                                                 1,
15465                                                 0);
15466 #endif
15467
15468         switch (ret) {
15469         case 0:
15470                 break;
15471         case -EINVAL:
15472                 fprintf(stderr, "invalid pctype or flow type\n");
15473                 break;
15474         case -ENODEV:
15475                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15476                 break;
15477         case -ENOTSUP:
15478                 fprintf(stderr, "function not implemented\n");
15479                 break;
15480         default:
15481                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15482         }
15483 }
15484
15485 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15486         .f = cmd_pctype_mapping_update_parsed,
15487         .data = NULL,
15488         .help_str = "port config <port_id> pctype mapping update"
15489         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15490         .tokens = {
15491                 (void *)&cmd_pctype_mapping_update_port,
15492                 (void *)&cmd_pctype_mapping_update_config,
15493                 (void *)&cmd_pctype_mapping_update_port_id,
15494                 (void *)&cmd_pctype_mapping_update_pctype,
15495                 (void *)&cmd_pctype_mapping_update_mapping,
15496                 (void *)&cmd_pctype_mapping_update_update,
15497                 (void *)&cmd_pctype_mapping_update_pc_type,
15498                 (void *)&cmd_pctype_mapping_update_flow_type,
15499                 NULL,
15500         },
15501 };
15502
15503 /* ptype mapping get */
15504
15505 /* Common result structure for ptype mapping get */
15506 struct cmd_ptype_mapping_get_result {
15507         cmdline_fixed_string_t ptype;
15508         cmdline_fixed_string_t mapping;
15509         cmdline_fixed_string_t get;
15510         portid_t port_id;
15511         uint8_t valid_only;
15512 };
15513
15514 /* Common CLI fields for ptype mapping get */
15515 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15516         TOKEN_STRING_INITIALIZER
15517                 (struct cmd_ptype_mapping_get_result,
15518                  ptype, "ptype");
15519 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15520         TOKEN_STRING_INITIALIZER
15521                 (struct cmd_ptype_mapping_get_result,
15522                  mapping, "mapping");
15523 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15524         TOKEN_STRING_INITIALIZER
15525                 (struct cmd_ptype_mapping_get_result,
15526                  get, "get");
15527 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15528         TOKEN_NUM_INITIALIZER
15529                 (struct cmd_ptype_mapping_get_result,
15530                  port_id, RTE_UINT16);
15531 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15532         TOKEN_NUM_INITIALIZER
15533                 (struct cmd_ptype_mapping_get_result,
15534                  valid_only, RTE_UINT8);
15535
15536 static void
15537 cmd_ptype_mapping_get_parsed(
15538         void *parsed_result,
15539         __rte_unused struct cmdline *cl,
15540         __rte_unused void *data)
15541 {
15542         struct cmd_ptype_mapping_get_result *res = parsed_result;
15543         int ret = -ENOTSUP;
15544 #ifdef RTE_NET_I40E
15545         int max_ptype_num = 256;
15546         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15547         uint16_t count;
15548         int i;
15549 #endif
15550
15551         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15552                 return;
15553
15554 #ifdef RTE_NET_I40E
15555         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15556                                         mapping,
15557                                         max_ptype_num,
15558                                         &count,
15559                                         res->valid_only);
15560 #endif
15561
15562         switch (ret) {
15563         case 0:
15564                 break;
15565         case -ENODEV:
15566                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15567                 break;
15568         case -ENOTSUP:
15569                 fprintf(stderr, "function not implemented\n");
15570                 break;
15571         default:
15572                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15573         }
15574
15575 #ifdef RTE_NET_I40E
15576         if (!ret) {
15577                 for (i = 0; i < count; i++)
15578                         printf("%3d\t0x%08x\n",
15579                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15580         }
15581 #endif
15582 }
15583
15584 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15585         .f = cmd_ptype_mapping_get_parsed,
15586         .data = NULL,
15587         .help_str = "ptype mapping get <port_id> <valid_only>",
15588         .tokens = {
15589                 (void *)&cmd_ptype_mapping_get_ptype,
15590                 (void *)&cmd_ptype_mapping_get_mapping,
15591                 (void *)&cmd_ptype_mapping_get_get,
15592                 (void *)&cmd_ptype_mapping_get_port_id,
15593                 (void *)&cmd_ptype_mapping_get_valid_only,
15594                 NULL,
15595         },
15596 };
15597
15598 /* ptype mapping replace */
15599
15600 /* Common result structure for ptype mapping replace */
15601 struct cmd_ptype_mapping_replace_result {
15602         cmdline_fixed_string_t ptype;
15603         cmdline_fixed_string_t mapping;
15604         cmdline_fixed_string_t replace;
15605         portid_t port_id;
15606         uint32_t target;
15607         uint8_t mask;
15608         uint32_t pkt_type;
15609 };
15610
15611 /* Common CLI fields for ptype mapping replace */
15612 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15613         TOKEN_STRING_INITIALIZER
15614                 (struct cmd_ptype_mapping_replace_result,
15615                  ptype, "ptype");
15616 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15617         TOKEN_STRING_INITIALIZER
15618                 (struct cmd_ptype_mapping_replace_result,
15619                  mapping, "mapping");
15620 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15621         TOKEN_STRING_INITIALIZER
15622                 (struct cmd_ptype_mapping_replace_result,
15623                  replace, "replace");
15624 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15625         TOKEN_NUM_INITIALIZER
15626                 (struct cmd_ptype_mapping_replace_result,
15627                  port_id, RTE_UINT16);
15628 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15629         TOKEN_NUM_INITIALIZER
15630                 (struct cmd_ptype_mapping_replace_result,
15631                  target, RTE_UINT32);
15632 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15633         TOKEN_NUM_INITIALIZER
15634                 (struct cmd_ptype_mapping_replace_result,
15635                  mask, RTE_UINT8);
15636 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15637         TOKEN_NUM_INITIALIZER
15638                 (struct cmd_ptype_mapping_replace_result,
15639                  pkt_type, RTE_UINT32);
15640
15641 static void
15642 cmd_ptype_mapping_replace_parsed(
15643         void *parsed_result,
15644         __rte_unused struct cmdline *cl,
15645         __rte_unused void *data)
15646 {
15647         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15648         int ret = -ENOTSUP;
15649
15650         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15651                 return;
15652
15653 #ifdef RTE_NET_I40E
15654         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15655                                         res->target,
15656                                         res->mask,
15657                                         res->pkt_type);
15658 #endif
15659
15660         switch (ret) {
15661         case 0:
15662                 break;
15663         case -EINVAL:
15664                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15665                         res->target, res->pkt_type);
15666                 break;
15667         case -ENODEV:
15668                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15669                 break;
15670         case -ENOTSUP:
15671                 fprintf(stderr, "function not implemented\n");
15672                 break;
15673         default:
15674                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15675         }
15676 }
15677
15678 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15679         .f = cmd_ptype_mapping_replace_parsed,
15680         .data = NULL,
15681         .help_str =
15682                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15683         .tokens = {
15684                 (void *)&cmd_ptype_mapping_replace_ptype,
15685                 (void *)&cmd_ptype_mapping_replace_mapping,
15686                 (void *)&cmd_ptype_mapping_replace_replace,
15687                 (void *)&cmd_ptype_mapping_replace_port_id,
15688                 (void *)&cmd_ptype_mapping_replace_target,
15689                 (void *)&cmd_ptype_mapping_replace_mask,
15690                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15691                 NULL,
15692         },
15693 };
15694
15695 /* ptype mapping reset */
15696
15697 /* Common result structure for ptype mapping reset */
15698 struct cmd_ptype_mapping_reset_result {
15699         cmdline_fixed_string_t ptype;
15700         cmdline_fixed_string_t mapping;
15701         cmdline_fixed_string_t reset;
15702         portid_t port_id;
15703 };
15704
15705 /* Common CLI fields for ptype mapping reset*/
15706 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15707         TOKEN_STRING_INITIALIZER
15708                 (struct cmd_ptype_mapping_reset_result,
15709                  ptype, "ptype");
15710 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15711         TOKEN_STRING_INITIALIZER
15712                 (struct cmd_ptype_mapping_reset_result,
15713                  mapping, "mapping");
15714 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15715         TOKEN_STRING_INITIALIZER
15716                 (struct cmd_ptype_mapping_reset_result,
15717                  reset, "reset");
15718 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15719         TOKEN_NUM_INITIALIZER
15720                 (struct cmd_ptype_mapping_reset_result,
15721                  port_id, RTE_UINT16);
15722
15723 static void
15724 cmd_ptype_mapping_reset_parsed(
15725         void *parsed_result,
15726         __rte_unused struct cmdline *cl,
15727         __rte_unused void *data)
15728 {
15729         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15730         int ret = -ENOTSUP;
15731
15732         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15733                 return;
15734
15735 #ifdef RTE_NET_I40E
15736         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15737 #endif
15738
15739         switch (ret) {
15740         case 0:
15741                 break;
15742         case -ENODEV:
15743                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15744                 break;
15745         case -ENOTSUP:
15746                 fprintf(stderr, "function not implemented\n");
15747                 break;
15748         default:
15749                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15750         }
15751 }
15752
15753 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15754         .f = cmd_ptype_mapping_reset_parsed,
15755         .data = NULL,
15756         .help_str = "ptype mapping reset <port_id>",
15757         .tokens = {
15758                 (void *)&cmd_ptype_mapping_reset_ptype,
15759                 (void *)&cmd_ptype_mapping_reset_mapping,
15760                 (void *)&cmd_ptype_mapping_reset_reset,
15761                 (void *)&cmd_ptype_mapping_reset_port_id,
15762                 NULL,
15763         },
15764 };
15765
15766 /* ptype mapping update */
15767
15768 /* Common result structure for ptype mapping update */
15769 struct cmd_ptype_mapping_update_result {
15770         cmdline_fixed_string_t ptype;
15771         cmdline_fixed_string_t mapping;
15772         cmdline_fixed_string_t reset;
15773         portid_t port_id;
15774         uint8_t hw_ptype;
15775         uint32_t sw_ptype;
15776 };
15777
15778 /* Common CLI fields for ptype mapping update*/
15779 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15780         TOKEN_STRING_INITIALIZER
15781                 (struct cmd_ptype_mapping_update_result,
15782                  ptype, "ptype");
15783 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15784         TOKEN_STRING_INITIALIZER
15785                 (struct cmd_ptype_mapping_update_result,
15786                  mapping, "mapping");
15787 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15788         TOKEN_STRING_INITIALIZER
15789                 (struct cmd_ptype_mapping_update_result,
15790                  reset, "update");
15791 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15792         TOKEN_NUM_INITIALIZER
15793                 (struct cmd_ptype_mapping_update_result,
15794                  port_id, RTE_UINT16);
15795 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15796         TOKEN_NUM_INITIALIZER
15797                 (struct cmd_ptype_mapping_update_result,
15798                  hw_ptype, RTE_UINT8);
15799 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15800         TOKEN_NUM_INITIALIZER
15801                 (struct cmd_ptype_mapping_update_result,
15802                  sw_ptype, RTE_UINT32);
15803
15804 static void
15805 cmd_ptype_mapping_update_parsed(
15806         void *parsed_result,
15807         __rte_unused struct cmdline *cl,
15808         __rte_unused void *data)
15809 {
15810         struct cmd_ptype_mapping_update_result *res = parsed_result;
15811         int ret = -ENOTSUP;
15812 #ifdef RTE_NET_I40E
15813         struct rte_pmd_i40e_ptype_mapping mapping;
15814 #endif
15815         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15816                 return;
15817
15818 #ifdef RTE_NET_I40E
15819         mapping.hw_ptype = res->hw_ptype;
15820         mapping.sw_ptype = res->sw_ptype;
15821         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15822                                                 &mapping,
15823                                                 1,
15824                                                 0);
15825 #endif
15826
15827         switch (ret) {
15828         case 0:
15829                 break;
15830         case -EINVAL:
15831                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15832                 break;
15833         case -ENODEV:
15834                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15835                 break;
15836         case -ENOTSUP:
15837                 fprintf(stderr, "function not implemented\n");
15838                 break;
15839         default:
15840                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15841         }
15842 }
15843
15844 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15845         .f = cmd_ptype_mapping_update_parsed,
15846         .data = NULL,
15847         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15848         .tokens = {
15849                 (void *)&cmd_ptype_mapping_update_ptype,
15850                 (void *)&cmd_ptype_mapping_update_mapping,
15851                 (void *)&cmd_ptype_mapping_update_update,
15852                 (void *)&cmd_ptype_mapping_update_port_id,
15853                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15854                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15855                 NULL,
15856         },
15857 };
15858
15859 /* Common result structure for file commands */
15860 struct cmd_cmdfile_result {
15861         cmdline_fixed_string_t load;
15862         cmdline_fixed_string_t filename;
15863 };
15864
15865 /* Common CLI fields for file commands */
15866 cmdline_parse_token_string_t cmd_load_cmdfile =
15867         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15868 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15869         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15870
15871 static void
15872 cmd_load_from_file_parsed(
15873         void *parsed_result,
15874         __rte_unused struct cmdline *cl,
15875         __rte_unused void *data)
15876 {
15877         struct cmd_cmdfile_result *res = parsed_result;
15878
15879         cmdline_read_from_file(res->filename);
15880 }
15881
15882 cmdline_parse_inst_t cmd_load_from_file = {
15883         .f = cmd_load_from_file_parsed,
15884         .data = NULL,
15885         .help_str = "load <filename>",
15886         .tokens = {
15887                 (void *)&cmd_load_cmdfile,
15888                 (void *)&cmd_load_cmdfile_filename,
15889                 NULL,
15890         },
15891 };
15892
15893 /* Get Rx offloads capabilities */
15894 struct cmd_rx_offload_get_capa_result {
15895         cmdline_fixed_string_t show;
15896         cmdline_fixed_string_t port;
15897         portid_t port_id;
15898         cmdline_fixed_string_t rx_offload;
15899         cmdline_fixed_string_t capabilities;
15900 };
15901
15902 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15903         TOKEN_STRING_INITIALIZER
15904                 (struct cmd_rx_offload_get_capa_result,
15905                  show, "show");
15906 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15907         TOKEN_STRING_INITIALIZER
15908                 (struct cmd_rx_offload_get_capa_result,
15909                  port, "port");
15910 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15911         TOKEN_NUM_INITIALIZER
15912                 (struct cmd_rx_offload_get_capa_result,
15913                  port_id, RTE_UINT16);
15914 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15915         TOKEN_STRING_INITIALIZER
15916                 (struct cmd_rx_offload_get_capa_result,
15917                  rx_offload, "rx_offload");
15918 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15919         TOKEN_STRING_INITIALIZER
15920                 (struct cmd_rx_offload_get_capa_result,
15921                  capabilities, "capabilities");
15922
15923 static void
15924 print_rx_offloads(uint64_t offloads)
15925 {
15926         uint64_t single_offload;
15927         int begin;
15928         int end;
15929         int bit;
15930
15931         if (offloads == 0)
15932                 return;
15933
15934         begin = __builtin_ctzll(offloads);
15935         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15936
15937         single_offload = 1ULL << begin;
15938         for (bit = begin; bit < end; bit++) {
15939                 if (offloads & single_offload)
15940                         printf(" %s",
15941                                rte_eth_dev_rx_offload_name(single_offload));
15942                 single_offload <<= 1;
15943         }
15944 }
15945
15946 static void
15947 cmd_rx_offload_get_capa_parsed(
15948         void *parsed_result,
15949         __rte_unused struct cmdline *cl,
15950         __rte_unused void *data)
15951 {
15952         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15953         struct rte_eth_dev_info dev_info;
15954         portid_t port_id = res->port_id;
15955         uint64_t queue_offloads;
15956         uint64_t port_offloads;
15957         int ret;
15958
15959         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15960         if (ret != 0)
15961                 return;
15962
15963         queue_offloads = dev_info.rx_queue_offload_capa;
15964         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15965
15966         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15967         printf("  Per Queue :");
15968         print_rx_offloads(queue_offloads);
15969
15970         printf("\n");
15971         printf("  Per Port  :");
15972         print_rx_offloads(port_offloads);
15973         printf("\n\n");
15974 }
15975
15976 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15977         .f = cmd_rx_offload_get_capa_parsed,
15978         .data = NULL,
15979         .help_str = "show port <port_id> rx_offload capabilities",
15980         .tokens = {
15981                 (void *)&cmd_rx_offload_get_capa_show,
15982                 (void *)&cmd_rx_offload_get_capa_port,
15983                 (void *)&cmd_rx_offload_get_capa_port_id,
15984                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15985                 (void *)&cmd_rx_offload_get_capa_capabilities,
15986                 NULL,
15987         }
15988 };
15989
15990 /* Get Rx offloads configuration */
15991 struct cmd_rx_offload_get_configuration_result {
15992         cmdline_fixed_string_t show;
15993         cmdline_fixed_string_t port;
15994         portid_t port_id;
15995         cmdline_fixed_string_t rx_offload;
15996         cmdline_fixed_string_t configuration;
15997 };
15998
15999 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16000         TOKEN_STRING_INITIALIZER
16001                 (struct cmd_rx_offload_get_configuration_result,
16002                  show, "show");
16003 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16004         TOKEN_STRING_INITIALIZER
16005                 (struct cmd_rx_offload_get_configuration_result,
16006                  port, "port");
16007 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16008         TOKEN_NUM_INITIALIZER
16009                 (struct cmd_rx_offload_get_configuration_result,
16010                  port_id, RTE_UINT16);
16011 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16012         TOKEN_STRING_INITIALIZER
16013                 (struct cmd_rx_offload_get_configuration_result,
16014                  rx_offload, "rx_offload");
16015 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16016         TOKEN_STRING_INITIALIZER
16017                 (struct cmd_rx_offload_get_configuration_result,
16018                  configuration, "configuration");
16019
16020 static void
16021 cmd_rx_offload_get_configuration_parsed(
16022         void *parsed_result,
16023         __rte_unused struct cmdline *cl,
16024         __rte_unused void *data)
16025 {
16026         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16027         struct rte_eth_dev_info dev_info;
16028         portid_t port_id = res->port_id;
16029         struct rte_port *port = &ports[port_id];
16030         struct rte_eth_conf dev_conf;
16031         uint64_t port_offloads;
16032         uint64_t queue_offloads;
16033         uint16_t nb_rx_queues;
16034         int q;
16035         int ret;
16036
16037         printf("Rx Offloading Configuration of port %d :\n", port_id);
16038
16039         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16040         if (ret != 0)
16041                 return;
16042
16043         port_offloads = dev_conf.rxmode.offloads;
16044         printf("  Port :");
16045         print_rx_offloads(port_offloads);
16046         printf("\n");
16047
16048         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16049         if (ret != 0)
16050                 return;
16051
16052         nb_rx_queues = dev_info.nb_rx_queues;
16053         for (q = 0; q < nb_rx_queues; q++) {
16054                 queue_offloads = port->rx_conf[q].offloads;
16055                 printf("  Queue[%2d] :", q);
16056                 print_rx_offloads(queue_offloads);
16057                 printf("\n");
16058         }
16059         printf("\n");
16060 }
16061
16062 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16063         .f = cmd_rx_offload_get_configuration_parsed,
16064         .data = NULL,
16065         .help_str = "show port <port_id> rx_offload configuration",
16066         .tokens = {
16067                 (void *)&cmd_rx_offload_get_configuration_show,
16068                 (void *)&cmd_rx_offload_get_configuration_port,
16069                 (void *)&cmd_rx_offload_get_configuration_port_id,
16070                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16071                 (void *)&cmd_rx_offload_get_configuration_configuration,
16072                 NULL,
16073         }
16074 };
16075
16076 /* Enable/Disable a per port offloading */
16077 struct cmd_config_per_port_rx_offload_result {
16078         cmdline_fixed_string_t port;
16079         cmdline_fixed_string_t config;
16080         portid_t port_id;
16081         cmdline_fixed_string_t rx_offload;
16082         cmdline_fixed_string_t offload;
16083         cmdline_fixed_string_t on_off;
16084 };
16085
16086 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16087         TOKEN_STRING_INITIALIZER
16088                 (struct cmd_config_per_port_rx_offload_result,
16089                  port, "port");
16090 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16091         TOKEN_STRING_INITIALIZER
16092                 (struct cmd_config_per_port_rx_offload_result,
16093                  config, "config");
16094 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16095         TOKEN_NUM_INITIALIZER
16096                 (struct cmd_config_per_port_rx_offload_result,
16097                  port_id, RTE_UINT16);
16098 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16099         TOKEN_STRING_INITIALIZER
16100                 (struct cmd_config_per_port_rx_offload_result,
16101                  rx_offload, "rx_offload");
16102 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16103         TOKEN_STRING_INITIALIZER
16104                 (struct cmd_config_per_port_rx_offload_result,
16105                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16106                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16107                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16108                            "scatter#buffer_split#timestamp#security#"
16109                            "keep_crc#rss_hash");
16110 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16111         TOKEN_STRING_INITIALIZER
16112                 (struct cmd_config_per_port_rx_offload_result,
16113                  on_off, "on#off");
16114
16115 static uint64_t
16116 search_rx_offload(const char *name)
16117 {
16118         uint64_t single_offload;
16119         const char *single_name;
16120         int found = 0;
16121         unsigned int bit;
16122
16123         single_offload = 1;
16124         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16125                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16126                 if (!strcasecmp(single_name, name)) {
16127                         found = 1;
16128                         break;
16129                 }
16130                 single_offload <<= 1;
16131         }
16132
16133         if (found)
16134                 return single_offload;
16135
16136         return 0;
16137 }
16138
16139 static void
16140 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16141                                 __rte_unused struct cmdline *cl,
16142                                 __rte_unused void *data)
16143 {
16144         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16145         portid_t port_id = res->port_id;
16146         struct rte_eth_dev_info dev_info;
16147         struct rte_port *port = &ports[port_id];
16148         uint64_t single_offload;
16149         uint16_t nb_rx_queues;
16150         int q;
16151         int ret;
16152
16153         if (port->port_status != RTE_PORT_STOPPED) {
16154                 fprintf(stderr,
16155                         "Error: Can't config offload when Port %d is not stopped\n",
16156                         port_id);
16157                 return;
16158         }
16159
16160         single_offload = search_rx_offload(res->offload);
16161         if (single_offload == 0) {
16162                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16163                 return;
16164         }
16165
16166         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16167         if (ret != 0)
16168                 return;
16169
16170         nb_rx_queues = dev_info.nb_rx_queues;
16171         if (!strcmp(res->on_off, "on")) {
16172                 port->dev_conf.rxmode.offloads |= single_offload;
16173                 for (q = 0; q < nb_rx_queues; q++)
16174                         port->rx_conf[q].offloads |= single_offload;
16175         } else {
16176                 port->dev_conf.rxmode.offloads &= ~single_offload;
16177                 for (q = 0; q < nb_rx_queues; q++)
16178                         port->rx_conf[q].offloads &= ~single_offload;
16179         }
16180
16181         cmd_reconfig_device_queue(port_id, 1, 1);
16182 }
16183
16184 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16185         .f = cmd_config_per_port_rx_offload_parsed,
16186         .data = NULL,
16187         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16188                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16189                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16190                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16191                     "keep_crc|rss_hash on|off",
16192         .tokens = {
16193                 (void *)&cmd_config_per_port_rx_offload_result_port,
16194                 (void *)&cmd_config_per_port_rx_offload_result_config,
16195                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16196                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16197                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16198                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16199                 NULL,
16200         }
16201 };
16202
16203 /* Enable/Disable a per queue offloading */
16204 struct cmd_config_per_queue_rx_offload_result {
16205         cmdline_fixed_string_t port;
16206         portid_t port_id;
16207         cmdline_fixed_string_t rxq;
16208         uint16_t queue_id;
16209         cmdline_fixed_string_t rx_offload;
16210         cmdline_fixed_string_t offload;
16211         cmdline_fixed_string_t on_off;
16212 };
16213
16214 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16215         TOKEN_STRING_INITIALIZER
16216                 (struct cmd_config_per_queue_rx_offload_result,
16217                  port, "port");
16218 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16219         TOKEN_NUM_INITIALIZER
16220                 (struct cmd_config_per_queue_rx_offload_result,
16221                  port_id, RTE_UINT16);
16222 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16223         TOKEN_STRING_INITIALIZER
16224                 (struct cmd_config_per_queue_rx_offload_result,
16225                  rxq, "rxq");
16226 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16227         TOKEN_NUM_INITIALIZER
16228                 (struct cmd_config_per_queue_rx_offload_result,
16229                  queue_id, RTE_UINT16);
16230 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16231         TOKEN_STRING_INITIALIZER
16232                 (struct cmd_config_per_queue_rx_offload_result,
16233                  rx_offload, "rx_offload");
16234 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16235         TOKEN_STRING_INITIALIZER
16236                 (struct cmd_config_per_queue_rx_offload_result,
16237                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16238                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16239                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16240                            "scatter#buffer_split#timestamp#security#keep_crc");
16241 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16242         TOKEN_STRING_INITIALIZER
16243                 (struct cmd_config_per_queue_rx_offload_result,
16244                  on_off, "on#off");
16245
16246 static void
16247 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16248                                 __rte_unused struct cmdline *cl,
16249                                 __rte_unused void *data)
16250 {
16251         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16252         struct rte_eth_dev_info dev_info;
16253         portid_t port_id = res->port_id;
16254         uint16_t queue_id = res->queue_id;
16255         struct rte_port *port = &ports[port_id];
16256         uint64_t single_offload;
16257         int ret;
16258
16259         if (port->port_status != RTE_PORT_STOPPED) {
16260                 fprintf(stderr,
16261                         "Error: Can't config offload when Port %d is not stopped\n",
16262                         port_id);
16263                 return;
16264         }
16265
16266         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16267         if (ret != 0)
16268                 return;
16269
16270         if (queue_id >= dev_info.nb_rx_queues) {
16271                 fprintf(stderr,
16272                         "Error: input queue_id should be 0 ... %d\n",
16273                         dev_info.nb_rx_queues - 1);
16274                 return;
16275         }
16276
16277         single_offload = search_rx_offload(res->offload);
16278         if (single_offload == 0) {
16279                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16280                 return;
16281         }
16282
16283         if (!strcmp(res->on_off, "on"))
16284                 port->rx_conf[queue_id].offloads |= single_offload;
16285         else
16286                 port->rx_conf[queue_id].offloads &= ~single_offload;
16287
16288         cmd_reconfig_device_queue(port_id, 1, 1);
16289 }
16290
16291 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16292         .f = cmd_config_per_queue_rx_offload_parsed,
16293         .data = NULL,
16294         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16295                     "vlan_strip|ipv4_cksum|"
16296                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16297                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16298                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16299                     "keep_crc on|off",
16300         .tokens = {
16301                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16302                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16303                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16304                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16305                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16306                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16307                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16308                 NULL,
16309         }
16310 };
16311
16312 /* Get Tx offloads capabilities */
16313 struct cmd_tx_offload_get_capa_result {
16314         cmdline_fixed_string_t show;
16315         cmdline_fixed_string_t port;
16316         portid_t port_id;
16317         cmdline_fixed_string_t tx_offload;
16318         cmdline_fixed_string_t capabilities;
16319 };
16320
16321 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16322         TOKEN_STRING_INITIALIZER
16323                 (struct cmd_tx_offload_get_capa_result,
16324                  show, "show");
16325 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16326         TOKEN_STRING_INITIALIZER
16327                 (struct cmd_tx_offload_get_capa_result,
16328                  port, "port");
16329 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16330         TOKEN_NUM_INITIALIZER
16331                 (struct cmd_tx_offload_get_capa_result,
16332                  port_id, RTE_UINT16);
16333 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16334         TOKEN_STRING_INITIALIZER
16335                 (struct cmd_tx_offload_get_capa_result,
16336                  tx_offload, "tx_offload");
16337 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16338         TOKEN_STRING_INITIALIZER
16339                 (struct cmd_tx_offload_get_capa_result,
16340                  capabilities, "capabilities");
16341
16342 static void
16343 print_tx_offloads(uint64_t offloads)
16344 {
16345         uint64_t single_offload;
16346         int begin;
16347         int end;
16348         int bit;
16349
16350         if (offloads == 0)
16351                 return;
16352
16353         begin = __builtin_ctzll(offloads);
16354         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16355
16356         single_offload = 1ULL << begin;
16357         for (bit = begin; bit < end; bit++) {
16358                 if (offloads & single_offload)
16359                         printf(" %s",
16360                                rte_eth_dev_tx_offload_name(single_offload));
16361                 single_offload <<= 1;
16362         }
16363 }
16364
16365 static void
16366 cmd_tx_offload_get_capa_parsed(
16367         void *parsed_result,
16368         __rte_unused struct cmdline *cl,
16369         __rte_unused void *data)
16370 {
16371         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16372         struct rte_eth_dev_info dev_info;
16373         portid_t port_id = res->port_id;
16374         uint64_t queue_offloads;
16375         uint64_t port_offloads;
16376         int ret;
16377
16378         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16379         if (ret != 0)
16380                 return;
16381
16382         queue_offloads = dev_info.tx_queue_offload_capa;
16383         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16384
16385         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16386         printf("  Per Queue :");
16387         print_tx_offloads(queue_offloads);
16388
16389         printf("\n");
16390         printf("  Per Port  :");
16391         print_tx_offloads(port_offloads);
16392         printf("\n\n");
16393 }
16394
16395 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16396         .f = cmd_tx_offload_get_capa_parsed,
16397         .data = NULL,
16398         .help_str = "show port <port_id> tx_offload capabilities",
16399         .tokens = {
16400                 (void *)&cmd_tx_offload_get_capa_show,
16401                 (void *)&cmd_tx_offload_get_capa_port,
16402                 (void *)&cmd_tx_offload_get_capa_port_id,
16403                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16404                 (void *)&cmd_tx_offload_get_capa_capabilities,
16405                 NULL,
16406         }
16407 };
16408
16409 /* Get Tx offloads configuration */
16410 struct cmd_tx_offload_get_configuration_result {
16411         cmdline_fixed_string_t show;
16412         cmdline_fixed_string_t port;
16413         portid_t port_id;
16414         cmdline_fixed_string_t tx_offload;
16415         cmdline_fixed_string_t configuration;
16416 };
16417
16418 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16419         TOKEN_STRING_INITIALIZER
16420                 (struct cmd_tx_offload_get_configuration_result,
16421                  show, "show");
16422 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16423         TOKEN_STRING_INITIALIZER
16424                 (struct cmd_tx_offload_get_configuration_result,
16425                  port, "port");
16426 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16427         TOKEN_NUM_INITIALIZER
16428                 (struct cmd_tx_offload_get_configuration_result,
16429                  port_id, RTE_UINT16);
16430 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16431         TOKEN_STRING_INITIALIZER
16432                 (struct cmd_tx_offload_get_configuration_result,
16433                  tx_offload, "tx_offload");
16434 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16435         TOKEN_STRING_INITIALIZER
16436                 (struct cmd_tx_offload_get_configuration_result,
16437                  configuration, "configuration");
16438
16439 static void
16440 cmd_tx_offload_get_configuration_parsed(
16441         void *parsed_result,
16442         __rte_unused struct cmdline *cl,
16443         __rte_unused void *data)
16444 {
16445         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16446         struct rte_eth_dev_info dev_info;
16447         portid_t port_id = res->port_id;
16448         struct rte_port *port = &ports[port_id];
16449         struct rte_eth_conf dev_conf;
16450         uint64_t port_offloads;
16451         uint64_t queue_offloads;
16452         uint16_t nb_tx_queues;
16453         int q;
16454         int ret;
16455
16456         printf("Tx Offloading Configuration of port %d :\n", port_id);
16457
16458         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16459         if (ret != 0)
16460                 return;
16461
16462         port_offloads = dev_conf.txmode.offloads;
16463         printf("  Port :");
16464         print_tx_offloads(port_offloads);
16465         printf("\n");
16466
16467         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16468         if (ret != 0)
16469                 return;
16470
16471         nb_tx_queues = dev_info.nb_tx_queues;
16472         for (q = 0; q < nb_tx_queues; q++) {
16473                 queue_offloads = port->tx_conf[q].offloads;
16474                 printf("  Queue[%2d] :", q);
16475                 print_tx_offloads(queue_offloads);
16476                 printf("\n");
16477         }
16478         printf("\n");
16479 }
16480
16481 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16482         .f = cmd_tx_offload_get_configuration_parsed,
16483         .data = NULL,
16484         .help_str = "show port <port_id> tx_offload configuration",
16485         .tokens = {
16486                 (void *)&cmd_tx_offload_get_configuration_show,
16487                 (void *)&cmd_tx_offload_get_configuration_port,
16488                 (void *)&cmd_tx_offload_get_configuration_port_id,
16489                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16490                 (void *)&cmd_tx_offload_get_configuration_configuration,
16491                 NULL,
16492         }
16493 };
16494
16495 /* Enable/Disable a per port offloading */
16496 struct cmd_config_per_port_tx_offload_result {
16497         cmdline_fixed_string_t port;
16498         cmdline_fixed_string_t config;
16499         portid_t port_id;
16500         cmdline_fixed_string_t tx_offload;
16501         cmdline_fixed_string_t offload;
16502         cmdline_fixed_string_t on_off;
16503 };
16504
16505 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16506         TOKEN_STRING_INITIALIZER
16507                 (struct cmd_config_per_port_tx_offload_result,
16508                  port, "port");
16509 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16510         TOKEN_STRING_INITIALIZER
16511                 (struct cmd_config_per_port_tx_offload_result,
16512                  config, "config");
16513 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16514         TOKEN_NUM_INITIALIZER
16515                 (struct cmd_config_per_port_tx_offload_result,
16516                  port_id, RTE_UINT16);
16517 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16518         TOKEN_STRING_INITIALIZER
16519                 (struct cmd_config_per_port_tx_offload_result,
16520                  tx_offload, "tx_offload");
16521 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16522         TOKEN_STRING_INITIALIZER
16523                 (struct cmd_config_per_port_tx_offload_result,
16524                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16525                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16526                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16527                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16528                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16529                           "send_on_timestamp");
16530 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16531         TOKEN_STRING_INITIALIZER
16532                 (struct cmd_config_per_port_tx_offload_result,
16533                  on_off, "on#off");
16534
16535 static uint64_t
16536 search_tx_offload(const char *name)
16537 {
16538         uint64_t single_offload;
16539         const char *single_name;
16540         int found = 0;
16541         unsigned int bit;
16542
16543         single_offload = 1;
16544         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16545                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16546                 if (single_name == NULL)
16547                         break;
16548                 if (!strcasecmp(single_name, name)) {
16549                         found = 1;
16550                         break;
16551                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16552                         break;
16553                 single_offload <<= 1;
16554         }
16555
16556         if (found)
16557                 return single_offload;
16558
16559         return 0;
16560 }
16561
16562 static void
16563 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16564                                 __rte_unused struct cmdline *cl,
16565                                 __rte_unused void *data)
16566 {
16567         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16568         portid_t port_id = res->port_id;
16569         struct rte_eth_dev_info dev_info;
16570         struct rte_port *port = &ports[port_id];
16571         uint64_t single_offload;
16572         uint16_t nb_tx_queues;
16573         int q;
16574         int ret;
16575
16576         if (port->port_status != RTE_PORT_STOPPED) {
16577                 fprintf(stderr,
16578                         "Error: Can't config offload when Port %d is not stopped\n",
16579                         port_id);
16580                 return;
16581         }
16582
16583         single_offload = search_tx_offload(res->offload);
16584         if (single_offload == 0) {
16585                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16586                 return;
16587         }
16588
16589         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16590         if (ret != 0)
16591                 return;
16592
16593         nb_tx_queues = dev_info.nb_tx_queues;
16594         if (!strcmp(res->on_off, "on")) {
16595                 port->dev_conf.txmode.offloads |= single_offload;
16596                 for (q = 0; q < nb_tx_queues; q++)
16597                         port->tx_conf[q].offloads |= single_offload;
16598         } else {
16599                 port->dev_conf.txmode.offloads &= ~single_offload;
16600                 for (q = 0; q < nb_tx_queues; q++)
16601                         port->tx_conf[q].offloads &= ~single_offload;
16602         }
16603
16604         cmd_reconfig_device_queue(port_id, 1, 1);
16605 }
16606
16607 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16608         .f = cmd_config_per_port_tx_offload_parsed,
16609         .data = NULL,
16610         .help_str = "port config <port_id> tx_offload "
16611                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16612                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16613                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16614                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16615                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16616                     "send_on_timestamp on|off",
16617         .tokens = {
16618                 (void *)&cmd_config_per_port_tx_offload_result_port,
16619                 (void *)&cmd_config_per_port_tx_offload_result_config,
16620                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16621                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16622                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16623                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16624                 NULL,
16625         }
16626 };
16627
16628 /* Enable/Disable a per queue offloading */
16629 struct cmd_config_per_queue_tx_offload_result {
16630         cmdline_fixed_string_t port;
16631         portid_t port_id;
16632         cmdline_fixed_string_t txq;
16633         uint16_t queue_id;
16634         cmdline_fixed_string_t tx_offload;
16635         cmdline_fixed_string_t offload;
16636         cmdline_fixed_string_t on_off;
16637 };
16638
16639 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16640         TOKEN_STRING_INITIALIZER
16641                 (struct cmd_config_per_queue_tx_offload_result,
16642                  port, "port");
16643 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16644         TOKEN_NUM_INITIALIZER
16645                 (struct cmd_config_per_queue_tx_offload_result,
16646                  port_id, RTE_UINT16);
16647 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16648         TOKEN_STRING_INITIALIZER
16649                 (struct cmd_config_per_queue_tx_offload_result,
16650                  txq, "txq");
16651 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16652         TOKEN_NUM_INITIALIZER
16653                 (struct cmd_config_per_queue_tx_offload_result,
16654                  queue_id, RTE_UINT16);
16655 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16656         TOKEN_STRING_INITIALIZER
16657                 (struct cmd_config_per_queue_tx_offload_result,
16658                  tx_offload, "tx_offload");
16659 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16660         TOKEN_STRING_INITIALIZER
16661                 (struct cmd_config_per_queue_tx_offload_result,
16662                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16663                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16664                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16665                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16666                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16667 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16668         TOKEN_STRING_INITIALIZER
16669                 (struct cmd_config_per_queue_tx_offload_result,
16670                  on_off, "on#off");
16671
16672 static void
16673 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16674                                 __rte_unused struct cmdline *cl,
16675                                 __rte_unused void *data)
16676 {
16677         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16678         struct rte_eth_dev_info dev_info;
16679         portid_t port_id = res->port_id;
16680         uint16_t queue_id = res->queue_id;
16681         struct rte_port *port = &ports[port_id];
16682         uint64_t single_offload;
16683         int ret;
16684
16685         if (port->port_status != RTE_PORT_STOPPED) {
16686                 fprintf(stderr,
16687                         "Error: Can't config offload when Port %d is not stopped\n",
16688                         port_id);
16689                 return;
16690         }
16691
16692         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16693         if (ret != 0)
16694                 return;
16695
16696         if (queue_id >= dev_info.nb_tx_queues) {
16697                 fprintf(stderr,
16698                         "Error: input queue_id should be 0 ... %d\n",
16699                         dev_info.nb_tx_queues - 1);
16700                 return;
16701         }
16702
16703         single_offload = search_tx_offload(res->offload);
16704         if (single_offload == 0) {
16705                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16706                 return;
16707         }
16708
16709         if (!strcmp(res->on_off, "on"))
16710                 port->tx_conf[queue_id].offloads |= single_offload;
16711         else
16712                 port->tx_conf[queue_id].offloads &= ~single_offload;
16713
16714         cmd_reconfig_device_queue(port_id, 1, 1);
16715 }
16716
16717 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16718         .f = cmd_config_per_queue_tx_offload_parsed,
16719         .data = NULL,
16720         .help_str = "port <port_id> txq <queue_id> tx_offload "
16721                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16722                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16723                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16724                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16725                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16726                     "on|off",
16727         .tokens = {
16728                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16729                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16730                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16731                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16732                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16733                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16734                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16735                 NULL,
16736         }
16737 };
16738
16739 /* *** configure tx_metadata for specific port *** */
16740 struct cmd_config_tx_metadata_specific_result {
16741         cmdline_fixed_string_t port;
16742         cmdline_fixed_string_t keyword;
16743         uint16_t port_id;
16744         cmdline_fixed_string_t item;
16745         uint32_t value;
16746 };
16747
16748 static void
16749 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16750                                 __rte_unused struct cmdline *cl,
16751                                 __rte_unused void *data)
16752 {
16753         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16754
16755         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16756                 return;
16757         ports[res->port_id].tx_metadata = res->value;
16758         /* Add/remove callback to insert valid metadata in every Tx packet. */
16759         if (ports[res->port_id].tx_metadata)
16760                 add_tx_md_callback(res->port_id);
16761         else
16762                 remove_tx_md_callback(res->port_id);
16763         rte_flow_dynf_metadata_register();
16764 }
16765
16766 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16767         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16768                         port, "port");
16769 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16770         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16771                         keyword, "config");
16772 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16773         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16774                         port_id, RTE_UINT16);
16775 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16776         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16777                         item, "tx_metadata");
16778 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16779         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16780                         value, RTE_UINT32);
16781
16782 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16783         .f = cmd_config_tx_metadata_specific_parsed,
16784         .data = NULL,
16785         .help_str = "port config <port_id> tx_metadata <value>",
16786         .tokens = {
16787                 (void *)&cmd_config_tx_metadata_specific_port,
16788                 (void *)&cmd_config_tx_metadata_specific_keyword,
16789                 (void *)&cmd_config_tx_metadata_specific_id,
16790                 (void *)&cmd_config_tx_metadata_specific_item,
16791                 (void *)&cmd_config_tx_metadata_specific_value,
16792                 NULL,
16793         },
16794 };
16795
16796 /* *** set dynf *** */
16797 struct cmd_config_tx_dynf_specific_result {
16798         cmdline_fixed_string_t port;
16799         cmdline_fixed_string_t keyword;
16800         uint16_t port_id;
16801         cmdline_fixed_string_t item;
16802         cmdline_fixed_string_t name;
16803         cmdline_fixed_string_t value;
16804 };
16805
16806 static void
16807 cmd_config_dynf_specific_parsed(void *parsed_result,
16808                                 __rte_unused struct cmdline *cl,
16809                                 __rte_unused void *data)
16810 {
16811         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16812         struct rte_mbuf_dynflag desc_flag;
16813         int flag;
16814         uint64_t old_port_flags;
16815
16816         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16817                 return;
16818         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16819         if (flag <= 0) {
16820                 if (strlcpy(desc_flag.name, res->name,
16821                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16822                         fprintf(stderr, "Flag name too long\n");
16823                         return;
16824                 }
16825                 desc_flag.flags = 0;
16826                 flag = rte_mbuf_dynflag_register(&desc_flag);
16827                 if (flag < 0) {
16828                         fprintf(stderr, "Can't register flag\n");
16829                         return;
16830                 }
16831                 strcpy(dynf_names[flag], desc_flag.name);
16832         }
16833         old_port_flags = ports[res->port_id].mbuf_dynf;
16834         if (!strcmp(res->value, "set")) {
16835                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16836                 if (old_port_flags == 0)
16837                         add_tx_dynf_callback(res->port_id);
16838         } else {
16839                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16840                 if (ports[res->port_id].mbuf_dynf == 0)
16841                         remove_tx_dynf_callback(res->port_id);
16842         }
16843 }
16844
16845 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16846         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16847                         keyword, "port");
16848 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16849         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16850                         keyword, "config");
16851 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16852         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16853                         port_id, RTE_UINT16);
16854 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16855         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16856                         item, "dynf");
16857 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16858         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16859                         name, NULL);
16860 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16861         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16862                         value, "set#clear");
16863
16864 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16865         .f = cmd_config_dynf_specific_parsed,
16866         .data = NULL,
16867         .help_str = "port config <port id> dynf <name> set|clear",
16868         .tokens = {
16869                 (void *)&cmd_config_tx_dynf_specific_port,
16870                 (void *)&cmd_config_tx_dynf_specific_keyword,
16871                 (void *)&cmd_config_tx_dynf_specific_port_id,
16872                 (void *)&cmd_config_tx_dynf_specific_item,
16873                 (void *)&cmd_config_tx_dynf_specific_name,
16874                 (void *)&cmd_config_tx_dynf_specific_value,
16875                 NULL,
16876         },
16877 };
16878
16879 /* *** display tx_metadata per port configuration *** */
16880 struct cmd_show_tx_metadata_result {
16881         cmdline_fixed_string_t cmd_show;
16882         cmdline_fixed_string_t cmd_port;
16883         cmdline_fixed_string_t cmd_keyword;
16884         portid_t cmd_pid;
16885 };
16886
16887 static void
16888 cmd_show_tx_metadata_parsed(void *parsed_result,
16889                 __rte_unused struct cmdline *cl,
16890                 __rte_unused void *data)
16891 {
16892         struct cmd_show_tx_metadata_result *res = parsed_result;
16893
16894         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16895                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
16896                 return;
16897         }
16898         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16899                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16900                        ports[res->cmd_pid].tx_metadata);
16901         }
16902 }
16903
16904 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16905         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16906                         cmd_show, "show");
16907 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16908         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16909                         cmd_port, "port");
16910 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16911         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16912                         cmd_pid, RTE_UINT16);
16913 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16914         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16915                         cmd_keyword, "tx_metadata");
16916
16917 cmdline_parse_inst_t cmd_show_tx_metadata = {
16918         .f = cmd_show_tx_metadata_parsed,
16919         .data = NULL,
16920         .help_str = "show port <port_id> tx_metadata",
16921         .tokens = {
16922                 (void *)&cmd_show_tx_metadata_show,
16923                 (void *)&cmd_show_tx_metadata_port,
16924                 (void *)&cmd_show_tx_metadata_pid,
16925                 (void *)&cmd_show_tx_metadata_keyword,
16926                 NULL,
16927         },
16928 };
16929
16930 /* *** show fec capability per port configuration *** */
16931 struct cmd_show_fec_capability_result {
16932         cmdline_fixed_string_t cmd_show;
16933         cmdline_fixed_string_t cmd_port;
16934         cmdline_fixed_string_t cmd_fec;
16935         cmdline_fixed_string_t cmd_keyword;
16936         portid_t cmd_pid;
16937 };
16938
16939 static void
16940 cmd_show_fec_capability_parsed(void *parsed_result,
16941                 __rte_unused struct cmdline *cl,
16942                 __rte_unused void *data)
16943 {
16944         struct cmd_show_fec_capability_result *res = parsed_result;
16945         struct rte_eth_fec_capa *speed_fec_capa;
16946         unsigned int num;
16947         int ret;
16948
16949         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16950                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16951                 return;
16952         }
16953
16954         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16955         if (ret == -ENOTSUP) {
16956                 fprintf(stderr, "Function not implemented\n");
16957                 return;
16958         } else if (ret < 0) {
16959                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
16960                 return;
16961         }
16962
16963         num = (unsigned int)ret;
16964         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16965         if (speed_fec_capa == NULL) {
16966                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
16967                 return;
16968         }
16969
16970         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16971         if (ret < 0) {
16972                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
16973                 goto out;
16974         }
16975
16976         show_fec_capability(num, speed_fec_capa);
16977 out:
16978         free(speed_fec_capa);
16979 }
16980
16981 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16982         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16983                         cmd_show, "show");
16984 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16985         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16986                         cmd_port, "port");
16987 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16988         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16989                         cmd_pid, RTE_UINT16);
16990 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16991         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16992                         cmd_fec, "fec");
16993 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16994         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16995                         cmd_keyword, "capabilities");
16996
16997 cmdline_parse_inst_t cmd_show_capability = {
16998         .f = cmd_show_fec_capability_parsed,
16999         .data = NULL,
17000         .help_str = "show port <port_id> fec capabilities",
17001         .tokens = {
17002                 (void *)&cmd_show_fec_capability_show,
17003                 (void *)&cmd_show_fec_capability_port,
17004                 (void *)&cmd_show_fec_capability_pid,
17005                 (void *)&cmd_show_fec_capability_fec,
17006                 (void *)&cmd_show_fec_capability_keyword,
17007                 NULL,
17008         },
17009 };
17010
17011 /* *** show fec mode per port configuration *** */
17012 struct cmd_show_fec_metadata_result {
17013         cmdline_fixed_string_t cmd_show;
17014         cmdline_fixed_string_t cmd_port;
17015         cmdline_fixed_string_t cmd_keyword;
17016         portid_t cmd_pid;
17017 };
17018
17019 static void
17020 cmd_show_fec_mode_parsed(void *parsed_result,
17021                 __rte_unused struct cmdline *cl,
17022                 __rte_unused void *data)
17023 {
17024 #define FEC_NAME_SIZE 16
17025         struct cmd_show_fec_metadata_result *res = parsed_result;
17026         uint32_t mode;
17027         char buf[FEC_NAME_SIZE];
17028         int ret;
17029
17030         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17031                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17032                 return;
17033         }
17034         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17035         if (ret == -ENOTSUP) {
17036                 fprintf(stderr, "Function not implemented\n");
17037                 return;
17038         } else if (ret < 0) {
17039                 fprintf(stderr, "Get FEC mode failed\n");
17040                 return;
17041         }
17042
17043         switch (mode) {
17044         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17045                 strlcpy(buf, "off", sizeof(buf));
17046                 break;
17047         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17048                 strlcpy(buf, "auto", sizeof(buf));
17049                 break;
17050         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17051                 strlcpy(buf, "baser", sizeof(buf));
17052                 break;
17053         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17054                 strlcpy(buf, "rs", sizeof(buf));
17055                 break;
17056         default:
17057                 return;
17058         }
17059
17060         printf("%s\n", buf);
17061 }
17062
17063 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17064         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17065                         cmd_show, "show");
17066 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17067         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17068                         cmd_port, "port");
17069 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17070         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17071                         cmd_pid, RTE_UINT16);
17072 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17073         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17074                         cmd_keyword, "fec_mode");
17075
17076 cmdline_parse_inst_t cmd_show_fec_mode = {
17077         .f = cmd_show_fec_mode_parsed,
17078         .data = NULL,
17079         .help_str = "show port <port_id> fec_mode",
17080         .tokens = {
17081                 (void *)&cmd_show_fec_mode_show,
17082                 (void *)&cmd_show_fec_mode_port,
17083                 (void *)&cmd_show_fec_mode_pid,
17084                 (void *)&cmd_show_fec_mode_keyword,
17085                 NULL,
17086         },
17087 };
17088
17089 /* *** set fec mode per port configuration *** */
17090 struct cmd_set_port_fec_mode {
17091         cmdline_fixed_string_t set;
17092         cmdline_fixed_string_t port;
17093         portid_t port_id;
17094         cmdline_fixed_string_t fec_mode;
17095         cmdline_fixed_string_t fec_value;
17096 };
17097
17098 /* Common CLI fields for set fec mode */
17099 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17100         TOKEN_STRING_INITIALIZER
17101                 (struct cmd_set_port_fec_mode,
17102                  set, "set");
17103 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17104         TOKEN_STRING_INITIALIZER
17105                 (struct cmd_set_port_fec_mode,
17106                  port, "port");
17107 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17108         TOKEN_NUM_INITIALIZER
17109                 (struct cmd_set_port_fec_mode,
17110                  port_id, RTE_UINT16);
17111 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17112         TOKEN_STRING_INITIALIZER
17113                 (struct cmd_set_port_fec_mode,
17114                  fec_mode, "fec_mode");
17115 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17116         TOKEN_STRING_INITIALIZER
17117                 (struct cmd_set_port_fec_mode,
17118                  fec_value, NULL);
17119
17120 static void
17121 cmd_set_port_fec_mode_parsed(
17122         void *parsed_result,
17123         __rte_unused struct cmdline *cl,
17124         __rte_unused void *data)
17125 {
17126         struct cmd_set_port_fec_mode *res = parsed_result;
17127         uint16_t port_id = res->port_id;
17128         uint32_t fec_capa;
17129         int ret;
17130
17131         ret = parse_fec_mode(res->fec_value, &fec_capa);
17132         if (ret < 0) {
17133                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17134                                 res->fec_value, port_id);
17135                 return;
17136         }
17137
17138         ret = rte_eth_fec_set(port_id, fec_capa);
17139         if (ret == -ENOTSUP) {
17140                 fprintf(stderr, "Function not implemented\n");
17141                 return;
17142         } else if (ret < 0) {
17143                 fprintf(stderr, "Set FEC mode failed\n");
17144                 return;
17145         }
17146 }
17147
17148 cmdline_parse_inst_t cmd_set_fec_mode = {
17149         .f = cmd_set_port_fec_mode_parsed,
17150         .data = NULL,
17151         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17152         .tokens = {
17153                 (void *)&cmd_set_port_fec_mode_set,
17154                 (void *)&cmd_set_port_fec_mode_port,
17155                 (void *)&cmd_set_port_fec_mode_port_id,
17156                 (void *)&cmd_set_port_fec_mode_str,
17157                 (void *)&cmd_set_port_fec_mode_value,
17158                 NULL,
17159         },
17160 };
17161
17162 /* show port supported ptypes */
17163
17164 /* Common result structure for show port ptypes */
17165 struct cmd_show_port_supported_ptypes_result {
17166         cmdline_fixed_string_t show;
17167         cmdline_fixed_string_t port;
17168         portid_t port_id;
17169         cmdline_fixed_string_t ptypes;
17170 };
17171
17172 /* Common CLI fields for show port ptypes */
17173 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17174         TOKEN_STRING_INITIALIZER
17175                 (struct cmd_show_port_supported_ptypes_result,
17176                  show, "show");
17177 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17178         TOKEN_STRING_INITIALIZER
17179                 (struct cmd_show_port_supported_ptypes_result,
17180                  port, "port");
17181 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17182         TOKEN_NUM_INITIALIZER
17183                 (struct cmd_show_port_supported_ptypes_result,
17184                  port_id, RTE_UINT16);
17185 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17186         TOKEN_STRING_INITIALIZER
17187                 (struct cmd_show_port_supported_ptypes_result,
17188                  ptypes, "ptypes");
17189
17190 static void
17191 cmd_show_port_supported_ptypes_parsed(
17192         void *parsed_result,
17193         __rte_unused struct cmdline *cl,
17194         __rte_unused void *data)
17195 {
17196 #define RSVD_PTYPE_MASK       0xf0000000
17197 #define MAX_PTYPES_PER_LAYER  16
17198 #define LTYPE_NAMESIZE        32
17199 #define PTYPE_NAMESIZE        256
17200         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17201         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17202         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17203         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17204         uint16_t port_id = res->port_id;
17205         int ret, i;
17206
17207         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17208         if (ret < 0)
17209                 return;
17210
17211         while (ptype_mask != RSVD_PTYPE_MASK) {
17212
17213                 switch (ptype_mask) {
17214                 case RTE_PTYPE_L2_MASK:
17215                         strlcpy(ltype, "L2", sizeof(ltype));
17216                         break;
17217                 case RTE_PTYPE_L3_MASK:
17218                         strlcpy(ltype, "L3", sizeof(ltype));
17219                         break;
17220                 case RTE_PTYPE_L4_MASK:
17221                         strlcpy(ltype, "L4", sizeof(ltype));
17222                         break;
17223                 case RTE_PTYPE_TUNNEL_MASK:
17224                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17225                         break;
17226                 case RTE_PTYPE_INNER_L2_MASK:
17227                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17228                         break;
17229                 case RTE_PTYPE_INNER_L3_MASK:
17230                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17231                         break;
17232                 case RTE_PTYPE_INNER_L4_MASK:
17233                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17234                         break;
17235                 default:
17236                         return;
17237                 }
17238
17239                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17240                                                        ptype_mask, ptypes,
17241                                                        MAX_PTYPES_PER_LAYER);
17242
17243                 if (ret > 0)
17244                         printf("Supported %s ptypes:\n", ltype);
17245                 else
17246                         printf("%s ptypes unsupported\n", ltype);
17247
17248                 for (i = 0; i < ret; ++i) {
17249                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17250                         printf("%s\n", buf);
17251                 }
17252
17253                 ptype_mask <<= 4;
17254         }
17255 }
17256
17257 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17258         .f = cmd_show_port_supported_ptypes_parsed,
17259         .data = NULL,
17260         .help_str = "show port <port_id> ptypes",
17261         .tokens = {
17262                 (void *)&cmd_show_port_supported_ptypes_show,
17263                 (void *)&cmd_show_port_supported_ptypes_port,
17264                 (void *)&cmd_show_port_supported_ptypes_port_id,
17265                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17266                 NULL,
17267         },
17268 };
17269
17270 /* *** display rx/tx descriptor status *** */
17271 struct cmd_show_rx_tx_desc_status_result {
17272         cmdline_fixed_string_t cmd_show;
17273         cmdline_fixed_string_t cmd_port;
17274         cmdline_fixed_string_t cmd_keyword;
17275         cmdline_fixed_string_t cmd_desc;
17276         cmdline_fixed_string_t cmd_status;
17277         portid_t cmd_pid;
17278         portid_t cmd_qid;
17279         portid_t cmd_did;
17280 };
17281
17282 static void
17283 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17284                 __rte_unused struct cmdline *cl,
17285                 __rte_unused void *data)
17286 {
17287         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17288         int rc;
17289
17290         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17291                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17292                 return;
17293         }
17294
17295         if (!strcmp(res->cmd_keyword, "rxq")) {
17296                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17297                                              res->cmd_did);
17298                 if (rc < 0) {
17299                         fprintf(stderr,
17300                                 "Invalid input: queue id = %d, desc id = %d\n",
17301                                 res->cmd_qid, res->cmd_did);
17302                         return;
17303                 }
17304                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17305                         printf("Desc status = AVAILABLE\n");
17306                 else if (rc == RTE_ETH_RX_DESC_DONE)
17307                         printf("Desc status = DONE\n");
17308                 else
17309                         printf("Desc status = UNAVAILABLE\n");
17310         } else if (!strcmp(res->cmd_keyword, "txq")) {
17311                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17312                                              res->cmd_did);
17313                 if (rc < 0) {
17314                         fprintf(stderr,
17315                                 "Invalid input: queue id = %d, desc id = %d\n",
17316                                 res->cmd_qid, res->cmd_did);
17317                         return;
17318                 }
17319                 if (rc == RTE_ETH_TX_DESC_FULL)
17320                         printf("Desc status = FULL\n");
17321                 else if (rc == RTE_ETH_TX_DESC_DONE)
17322                         printf("Desc status = DONE\n");
17323                 else
17324                         printf("Desc status = UNAVAILABLE\n");
17325         }
17326 }
17327
17328 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17329         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17330                         cmd_show, "show");
17331 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17332         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17333                         cmd_port, "port");
17334 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17335         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17336                         cmd_pid, RTE_UINT16);
17337 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17338         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17339                         cmd_keyword, "rxq#txq");
17340 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17341         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17342                         cmd_qid, RTE_UINT16);
17343 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17344         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17345                         cmd_desc, "desc");
17346 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17347         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17348                         cmd_did, RTE_UINT16);
17349 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17350         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17351                         cmd_status, "status");
17352 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17353         .f = cmd_show_rx_tx_desc_status_parsed,
17354         .data = NULL,
17355         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17356                 "status",
17357         .tokens = {
17358                 (void *)&cmd_show_rx_tx_desc_status_show,
17359                 (void *)&cmd_show_rx_tx_desc_status_port,
17360                 (void *)&cmd_show_rx_tx_desc_status_pid,
17361                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17362                 (void *)&cmd_show_rx_tx_desc_status_qid,
17363                 (void *)&cmd_show_rx_tx_desc_status_desc,
17364                 (void *)&cmd_show_rx_tx_desc_status_did,
17365                 (void *)&cmd_show_rx_tx_desc_status_status,
17366                 NULL,
17367         },
17368 };
17369
17370 /* *** display rx queue desc used count *** */
17371 struct cmd_show_rx_queue_desc_used_count_result {
17372         cmdline_fixed_string_t cmd_show;
17373         cmdline_fixed_string_t cmd_port;
17374         cmdline_fixed_string_t cmd_rxq;
17375         cmdline_fixed_string_t cmd_desc;
17376         cmdline_fixed_string_t cmd_used;
17377         cmdline_fixed_string_t cmd_count;
17378         portid_t cmd_pid;
17379         portid_t cmd_qid;
17380 };
17381
17382 static void
17383 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17384                 __rte_unused struct cmdline *cl,
17385                 __rte_unused void *data)
17386 {
17387         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17388         int rc;
17389
17390         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17391                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17392                 return;
17393         }
17394
17395         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17396         if (rc < 0) {
17397                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17398                 return;
17399         }
17400         printf("Used desc count = %d\n", rc);
17401 }
17402
17403 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17404         TOKEN_STRING_INITIALIZER
17405                 (struct cmd_show_rx_queue_desc_used_count_result,
17406                  cmd_show, "show");
17407 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17408         TOKEN_STRING_INITIALIZER
17409                 (struct cmd_show_rx_queue_desc_used_count_result,
17410                  cmd_port, "port");
17411 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17412         TOKEN_NUM_INITIALIZER
17413                 (struct cmd_show_rx_queue_desc_used_count_result,
17414                  cmd_pid, RTE_UINT16);
17415 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17416         TOKEN_STRING_INITIALIZER
17417                 (struct cmd_show_rx_queue_desc_used_count_result,
17418                  cmd_rxq, "rxq");
17419 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17420         TOKEN_NUM_INITIALIZER
17421                 (struct cmd_show_rx_queue_desc_used_count_result,
17422                  cmd_qid, RTE_UINT16);
17423 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17424         TOKEN_STRING_INITIALIZER
17425                 (struct cmd_show_rx_queue_desc_used_count_result,
17426                  cmd_count, "desc");
17427 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17428         TOKEN_STRING_INITIALIZER
17429                 (struct cmd_show_rx_queue_desc_used_count_result,
17430                  cmd_count, "used");
17431 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17432         TOKEN_STRING_INITIALIZER
17433                 (struct cmd_show_rx_queue_desc_used_count_result,
17434                  cmd_count, "count");
17435 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17436         .f = cmd_show_rx_queue_desc_used_count_parsed,
17437         .data = NULL,
17438         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17439         .tokens = {
17440                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17441                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17442                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17443                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17444                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17445                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17446                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17447                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17448                 NULL,
17449         },
17450 };
17451
17452 /* Common result structure for set port ptypes */
17453 struct cmd_set_port_ptypes_result {
17454         cmdline_fixed_string_t set;
17455         cmdline_fixed_string_t port;
17456         portid_t port_id;
17457         cmdline_fixed_string_t ptype_mask;
17458         uint32_t mask;
17459 };
17460
17461 /* Common CLI fields for set port ptypes */
17462 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17463         TOKEN_STRING_INITIALIZER
17464                 (struct cmd_set_port_ptypes_result,
17465                  set, "set");
17466 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17467         TOKEN_STRING_INITIALIZER
17468                 (struct cmd_set_port_ptypes_result,
17469                  port, "port");
17470 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17471         TOKEN_NUM_INITIALIZER
17472                 (struct cmd_set_port_ptypes_result,
17473                  port_id, RTE_UINT16);
17474 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17475         TOKEN_STRING_INITIALIZER
17476                 (struct cmd_set_port_ptypes_result,
17477                  ptype_mask, "ptype_mask");
17478 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17479         TOKEN_NUM_INITIALIZER
17480                 (struct cmd_set_port_ptypes_result,
17481                  mask, RTE_UINT32);
17482
17483 static void
17484 cmd_set_port_ptypes_parsed(
17485         void *parsed_result,
17486         __rte_unused struct cmdline *cl,
17487         __rte_unused void *data)
17488 {
17489         struct cmd_set_port_ptypes_result *res = parsed_result;
17490 #define PTYPE_NAMESIZE        256
17491         char ptype_name[PTYPE_NAMESIZE];
17492         uint16_t port_id = res->port_id;
17493         uint32_t ptype_mask = res->mask;
17494         int ret, i;
17495
17496         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17497                                                NULL, 0);
17498         if (ret <= 0) {
17499                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17500                         port_id);
17501                 return;
17502         }
17503
17504         uint32_t ptypes[ret];
17505
17506         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17507         if (ret < 0) {
17508                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17509                         port_id);
17510                 return;
17511         }
17512
17513         printf("Successfully set following ptypes for Port %d\n", port_id);
17514         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17515                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17516                 printf("%s\n", ptype_name);
17517         }
17518
17519         clear_ptypes = false;
17520 }
17521
17522 cmdline_parse_inst_t cmd_set_port_ptypes = {
17523         .f = cmd_set_port_ptypes_parsed,
17524         .data = NULL,
17525         .help_str = "set port <port_id> ptype_mask <mask>",
17526         .tokens = {
17527                 (void *)&cmd_set_port_ptypes_set,
17528                 (void *)&cmd_set_port_ptypes_port,
17529                 (void *)&cmd_set_port_ptypes_port_id,
17530                 (void *)&cmd_set_port_ptypes_mask_str,
17531                 (void *)&cmd_set_port_ptypes_mask_u32,
17532                 NULL,
17533         },
17534 };
17535
17536 /* *** display mac addresses added to a port *** */
17537 struct cmd_showport_macs_result {
17538         cmdline_fixed_string_t cmd_show;
17539         cmdline_fixed_string_t cmd_port;
17540         cmdline_fixed_string_t cmd_keyword;
17541         portid_t cmd_pid;
17542 };
17543
17544 static void
17545 cmd_showport_macs_parsed(void *parsed_result,
17546                 __rte_unused struct cmdline *cl,
17547                 __rte_unused void *data)
17548 {
17549         struct cmd_showport_macs_result *res = parsed_result;
17550
17551         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17552                 return;
17553
17554         if (!strcmp(res->cmd_keyword, "macs"))
17555                 show_macs(res->cmd_pid);
17556         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17557                 show_mcast_macs(res->cmd_pid);
17558 }
17559
17560 cmdline_parse_token_string_t cmd_showport_macs_show =
17561         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17562                         cmd_show, "show");
17563 cmdline_parse_token_string_t cmd_showport_macs_port =
17564         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17565                         cmd_port, "port");
17566 cmdline_parse_token_num_t cmd_showport_macs_pid =
17567         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17568                         cmd_pid, RTE_UINT16);
17569 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17570         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17571                         cmd_keyword, "macs#mcast_macs");
17572
17573 cmdline_parse_inst_t cmd_showport_macs = {
17574         .f = cmd_showport_macs_parsed,
17575         .data = NULL,
17576         .help_str = "show port <port_id> macs|mcast_macs",
17577         .tokens = {
17578                 (void *)&cmd_showport_macs_show,
17579                 (void *)&cmd_showport_macs_port,
17580                 (void *)&cmd_showport_macs_pid,
17581                 (void *)&cmd_showport_macs_keyword,
17582                 NULL,
17583         },
17584 };
17585
17586 /* ******************************************************************************** */
17587
17588 /* list of instructions */
17589 cmdline_parse_ctx_t main_ctx[] = {
17590         (cmdline_parse_inst_t *)&cmd_help_brief,
17591         (cmdline_parse_inst_t *)&cmd_help_long,
17592         (cmdline_parse_inst_t *)&cmd_quit,
17593         (cmdline_parse_inst_t *)&cmd_load_from_file,
17594         (cmdline_parse_inst_t *)&cmd_showport,
17595         (cmdline_parse_inst_t *)&cmd_showqueue,
17596         (cmdline_parse_inst_t *)&cmd_showeeprom,
17597         (cmdline_parse_inst_t *)&cmd_showportall,
17598         (cmdline_parse_inst_t *)&cmd_representor_info,
17599         (cmdline_parse_inst_t *)&cmd_showdevice,
17600         (cmdline_parse_inst_t *)&cmd_showcfg,
17601         (cmdline_parse_inst_t *)&cmd_showfwdall,
17602         (cmdline_parse_inst_t *)&cmd_start,
17603         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17604         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17605         (cmdline_parse_inst_t *)&cmd_set_link_up,
17606         (cmdline_parse_inst_t *)&cmd_set_link_down,
17607         (cmdline_parse_inst_t *)&cmd_reset,
17608         (cmdline_parse_inst_t *)&cmd_set_numbers,
17609         (cmdline_parse_inst_t *)&cmd_set_log,
17610         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17611         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17612         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17613         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17614         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17615         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17616         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17617         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17618         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17619         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17620         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17621         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17622         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17623         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17624         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17625         (cmdline_parse_inst_t *)&cmd_set_link_check,
17626         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17627         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17628         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17629         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17630 #ifdef RTE_NET_BOND
17631         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17632         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17633         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17634         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17635         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17636         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17637         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17638         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17639         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17640         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17641         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17642         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17643 #endif
17644         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17645         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17646         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17647         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17648         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17649         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17650         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17651         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17652         (cmdline_parse_inst_t *)&cmd_csum_set,
17653         (cmdline_parse_inst_t *)&cmd_csum_show,
17654         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17655         (cmdline_parse_inst_t *)&cmd_tso_set,
17656         (cmdline_parse_inst_t *)&cmd_tso_show,
17657         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17658         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17659         (cmdline_parse_inst_t *)&cmd_gro_enable,
17660         (cmdline_parse_inst_t *)&cmd_gro_flush,
17661         (cmdline_parse_inst_t *)&cmd_gro_show,
17662         (cmdline_parse_inst_t *)&cmd_gso_enable,
17663         (cmdline_parse_inst_t *)&cmd_gso_size,
17664         (cmdline_parse_inst_t *)&cmd_gso_show,
17665         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17666         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17667         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17668         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17669         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17670         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17671         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17672         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17673         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17674         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17675         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17676         (cmdline_parse_inst_t *)&cmd_config_dcb,
17677         (cmdline_parse_inst_t *)&cmd_read_reg,
17678         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17679         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17680         (cmdline_parse_inst_t *)&cmd_write_reg,
17681         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17682         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17683         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17684         (cmdline_parse_inst_t *)&cmd_stop,
17685         (cmdline_parse_inst_t *)&cmd_mac_addr,
17686         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17687         (cmdline_parse_inst_t *)&cmd_set_qmap,
17688         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17689         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17690         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17691         (cmdline_parse_inst_t *)&cmd_operate_port,
17692         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17693         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17694         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17695         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17696         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17697         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17698         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17699         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17700         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17701         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17702         (cmdline_parse_inst_t *)&cmd_config_mtu,
17703         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17704         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17705         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17706         (cmdline_parse_inst_t *)&cmd_config_rss,
17707         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17708         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17709         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17710         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17711         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17712         (cmdline_parse_inst_t *)&cmd_showport_reta,
17713         (cmdline_parse_inst_t *)&cmd_showport_macs,
17714         (cmdline_parse_inst_t *)&cmd_config_burst,
17715         (cmdline_parse_inst_t *)&cmd_config_thresh,
17716         (cmdline_parse_inst_t *)&cmd_config_threshold,
17717         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17718         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17719         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17720         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17721         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17722         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17723         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17724         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17725         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17726         (cmdline_parse_inst_t *)&cmd_dump,
17727         (cmdline_parse_inst_t *)&cmd_dump_one,
17728 #ifdef RTE_NET_I40E
17729         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17730 #endif
17731         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17732         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17733         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17734         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17735         (cmdline_parse_inst_t *)&cmd_flow,
17736         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17737         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17738         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17739         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17740         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17741         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17742         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17743         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17744         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17745         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17746         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17747         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17748         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17749         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17750         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17751         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17752         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17753         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17754         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17755         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17756         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17757         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17758         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17759         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17760         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17761         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17762         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17763         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17764         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17765         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17766         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17767         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17768         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17769         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17770         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17771         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17772         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17773         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17774         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17775         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17776         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17777         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17778         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17779         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17780         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17781         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17782         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17783         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17784         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17785         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17786         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17787         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17788         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17789         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17790         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17791         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17792         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17793         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17794         (cmdline_parse_inst_t *)&cmd_ddp_add,
17795         (cmdline_parse_inst_t *)&cmd_ddp_del,
17796         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17797         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17798         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17799         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17800         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17801         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17802         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17803         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17804         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17805         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17806         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17807         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17808
17809         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17810         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17811         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17812         (cmdline_parse_inst_t *)&cmd_queue_region,
17813         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17814         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17815         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17816         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17817         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17818         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17819         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17820         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17821         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17822         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17823         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17824         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17825         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17826         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17827         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17828         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17829         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17830         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17831         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17832         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17833         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17834         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17835         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17836         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17837         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17838         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17839         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17840         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17841         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17842         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17843         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17844         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17845         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17846         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17847         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17848         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17849 #ifdef RTE_LIB_BPF
17850         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17851         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17852 #endif
17853         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17854         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17855         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17856         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17857         (cmdline_parse_inst_t *)&cmd_set_raw,
17858         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17859         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17860         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17861         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17862         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17863         (cmdline_parse_inst_t *)&cmd_show_capability,
17864         NULL,
17865 };
17866
17867 /* read cmdline commands from file */
17868 void
17869 cmdline_read_from_file(const char *filename)
17870 {
17871         struct cmdline *cl;
17872
17873         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17874         if (cl == NULL) {
17875                 fprintf(stderr,
17876                         "Failed to create file based cmdline context: %s\n",
17877                         filename);
17878                 return;
17879         }
17880
17881         cmdline_interact(cl);
17882         cmdline_quit(cl);
17883
17884         cmdline_free(cl);
17885
17886         printf("Read CLI commands from %s\n", filename);
17887 }
17888
17889 /* prompt function, called from main on MAIN lcore */
17890 void
17891 prompt(void)
17892 {
17893         int ret;
17894         /* initialize non-constant commands */
17895         cmd_set_fwd_mode_init();
17896         cmd_set_fwd_retry_mode_init();
17897
17898         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17899         if (testpmd_cl == NULL)
17900                 return;
17901
17902         ret = atexit(prompt_exit);
17903         if (ret != 0)
17904                 fprintf(stderr, "Cannot set exit function for cmdline\n");
17905
17906         cmdline_interact(testpmd_cl);
17907         if (ret != 0)
17908                 cmdline_stdin_exit(testpmd_cl);
17909 }
17910
17911 void
17912 prompt_exit(void)
17913 {
17914         if (testpmd_cl != NULL) {
17915                 cmdline_quit(testpmd_cl);
17916                 cmdline_stdin_exit(testpmd_cl);
17917         }
17918 }
17919
17920 static void
17921 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17922 {
17923         if (id == (portid_t)RTE_PORT_ALL) {
17924                 portid_t pid;
17925
17926                 RTE_ETH_FOREACH_DEV(pid) {
17927                         /* check if need_reconfig has been set to 1 */
17928                         if (ports[pid].need_reconfig == 0)
17929                                 ports[pid].need_reconfig = dev;
17930                         /* check if need_reconfig_queues has been set to 1 */
17931                         if (ports[pid].need_reconfig_queues == 0)
17932                                 ports[pid].need_reconfig_queues = queue;
17933                 }
17934         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17935                 /* check if need_reconfig has been set to 1 */
17936                 if (ports[id].need_reconfig == 0)
17937                         ports[id].need_reconfig = dev;
17938                 /* check if need_reconfig_queues has been set to 1 */
17939                 if (ports[id].need_reconfig_queues == 0)
17940                         ports[id].need_reconfig_queues = queue;
17941         }
17942 }