app: remove unneeded atomic header include
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <inttypes.h>
13 #include <sys/queue.h>
14
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_debug.h>
19 #include <rte_cycles.h>
20 #include <rte_memory.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_ring.h>
29 #include <rte_mempool.h>
30 #include <rte_interrupts.h>
31 #include <rte_pci.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_string_fns.h>
35 #include <rte_devargs.h>
36 #include <rte_flow.h>
37 #include <rte_gro.h>
38 #include <rte_mbuf_dyn.h>
39
40 #include <cmdline_rdline.h>
41 #include <cmdline_parse.h>
42 #include <cmdline_parse_num.h>
43 #include <cmdline_parse_string.h>
44 #include <cmdline_parse_ipaddr.h>
45 #include <cmdline_parse_etheraddr.h>
46 #include <cmdline_socket.h>
47 #include <cmdline.h>
48 #ifdef RTE_NET_BOND
49 #include <rte_eth_bond.h>
50 #include <rte_eth_bond_8023ad.h>
51 #endif
52 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
53 #include <rte_pmd_dpaa.h>
54 #endif
55 #ifdef RTE_NET_IXGBE
56 #include <rte_pmd_ixgbe.h>
57 #endif
58 #ifdef RTE_NET_I40E
59 #include <rte_pmd_i40e.h>
60 #endif
61 #ifdef RTE_NET_BNXT
62 #include <rte_pmd_bnxt.h>
63 #endif
64 #include "testpmd.h"
65 #include "cmdline_mtr.h"
66 #include "cmdline_tm.h"
67 #include "bpf_cmd.h"
68
69 static struct cmdline *testpmd_cl;
70
71 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
72
73 /* *** Help command with introduction. *** */
74 struct cmd_help_brief_result {
75         cmdline_fixed_string_t help;
76 };
77
78 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
79                                   struct cmdline *cl,
80                                   __rte_unused void *data)
81 {
82         cmdline_printf(
83                 cl,
84                 "\n"
85                 "Help is available for the following sections:\n\n"
86                 "    help control                    : Start and stop forwarding.\n"
87                 "    help display                    : Displaying port, stats and config "
88                 "information.\n"
89                 "    help config                     : Configuration information.\n"
90                 "    help ports                      : Configuring ports.\n"
91                 "    help registers                  : Reading and setting port registers.\n"
92                 "    help filters                    : Filters configuration help.\n"
93                 "    help traffic_management         : Traffic Management commands.\n"
94                 "    help devices                    : Device related cmds.\n"
95                 "    help all                        : All of the above sections.\n\n"
96         );
97
98 }
99
100 cmdline_parse_token_string_t cmd_help_brief_help =
101         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
102
103 cmdline_parse_inst_t cmd_help_brief = {
104         .f = cmd_help_brief_parsed,
105         .data = NULL,
106         .help_str = "help: Show help",
107         .tokens = {
108                 (void *)&cmd_help_brief_help,
109                 NULL,
110         },
111 };
112
113 /* *** Help command with help sections. *** */
114 struct cmd_help_long_result {
115         cmdline_fixed_string_t help;
116         cmdline_fixed_string_t section;
117 };
118
119 static void cmd_help_long_parsed(void *parsed_result,
120                                  struct cmdline *cl,
121                                  __rte_unused void *data)
122 {
123         int show_all = 0;
124         struct cmd_help_long_result *res = parsed_result;
125
126         if (!strcmp(res->section, "all"))
127                 show_all = 1;
128
129         if (show_all || !strcmp(res->section, "control")) {
130
131                 cmdline_printf(
132                         cl,
133                         "\n"
134                         "Control forwarding:\n"
135                         "-------------------\n\n"
136
137                         "start\n"
138                         "    Start packet forwarding with current configuration.\n\n"
139
140                         "start tx_first\n"
141                         "    Start packet forwarding with current config"
142                         " after sending one burst of packets.\n\n"
143
144                         "stop\n"
145                         "    Stop packet forwarding, and display accumulated"
146                         " statistics.\n\n"
147
148                         "quit\n"
149                         "    Quit to prompt.\n\n"
150                 );
151         }
152
153         if (show_all || !strcmp(res->section, "display")) {
154
155                 cmdline_printf(
156                         cl,
157                         "\n"
158                         "Display:\n"
159                         "--------\n\n"
160
161                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
162                         "    Display information for port_id, or all.\n\n"
163
164                         "show port info (port_id) representor\n"
165                         "    Show supported representors for a specific port\n\n"
166
167                         "show port port_id (module_eeprom|eeprom)\n"
168                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
169
170                         "show port X rss reta (size) (mask0,mask1,...)\n"
171                         "    Display the rss redirection table entry indicated"
172                         " by masks on port X. size is used to indicate the"
173                         " hardware supported reta size\n\n"
174
175                         "show port (port_id) rss-hash [key]\n"
176                         "    Display the RSS hash functions and RSS hash key of port\n\n"
177
178                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
179                         "    Clear information for port_id, or all.\n\n"
180
181                         "show (rxq|txq) info (port_id) (queue_id)\n"
182                         "    Display information for configured RX/TX queue.\n\n"
183
184                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
185                         "    Display the given configuration.\n\n"
186
187                         "read rxd (port_id) (queue_id) (rxd_id)\n"
188                         "    Display an RX descriptor of a port RX queue.\n\n"
189
190                         "read txd (port_id) (queue_id) (txd_id)\n"
191                         "    Display a TX descriptor of a port TX queue.\n\n"
192
193                         "ddp get list (port_id)\n"
194                         "    Get ddp profile info list\n\n"
195
196                         "ddp get info (profile_path)\n"
197                         "    Get ddp profile information.\n\n"
198
199                         "show vf stats (port_id) (vf_id)\n"
200                         "    Display a VF's statistics.\n\n"
201
202                         "clear vf stats (port_id) (vf_id)\n"
203                         "    Reset a VF's statistics.\n\n"
204
205                         "show port (port_id) pctype mapping\n"
206                         "    Get flow ptype to pctype mapping on a port\n\n"
207
208                         "show port meter stats (port_id) (meter_id) (clear)\n"
209                         "    Get meter stats on a port\n\n"
210
211                         "show fwd stats all\n"
212                         "    Display statistics for all fwd engines.\n\n"
213
214                         "clear fwd stats all\n"
215                         "    Clear statistics for all fwd engines.\n\n"
216
217                         "show port (port_id) rx_offload capabilities\n"
218                         "    List all per queue and per port Rx offloading"
219                         " capabilities of a port\n\n"
220
221                         "show port (port_id) rx_offload configuration\n"
222                         "    List port level and all queue level"
223                         " Rx offloading configuration\n\n"
224
225                         "show port (port_id) tx_offload capabilities\n"
226                         "    List all per queue and per port"
227                         " Tx offloading capabilities of a port\n\n"
228
229                         "show port (port_id) tx_offload configuration\n"
230                         "    List port level and all queue level"
231                         " Tx offloading configuration\n\n"
232
233                         "show port (port_id) tx_metadata\n"
234                         "    Show Tx metadata value set"
235                         " for a specific port\n\n"
236
237                         "show port (port_id) ptypes\n"
238                         "    Show port supported ptypes"
239                         " for a specific port\n\n"
240
241                         "show device info (<identifier>|all)"
242                         "       Show general information about devices probed.\n\n"
243
244                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
245                         "       Show status of rx|tx descriptor.\n\n"
246
247                         "show port (port_id) rxq (queue_id) desc used count\n"
248                         "    Show current number of filled receive"
249                         " packet descriptors.\n\n"
250
251                         "show port (port_id) macs|mcast_macs"
252                         "       Display list of mac addresses added to port.\n\n"
253
254                         "show port (port_id) fec capabilities"
255                         "       Show fec capabilities of a port.\n\n"
256
257                         "show port (port_id) fec_mode"
258                         "       Show fec mode of a port.\n\n"
259
260                         "show port (port_id) flow_ctrl"
261                         "       Show flow control info of a port.\n\n"
262                 );
263         }
264
265         if (show_all || !strcmp(res->section, "config")) {
266                 cmdline_printf(
267                         cl,
268                         "\n"
269                         "Configuration:\n"
270                         "--------------\n"
271                         "Configuration changes only become active when"
272                         " forwarding is started/restarted.\n\n"
273
274                         "set default\n"
275                         "    Reset forwarding to the default configuration.\n\n"
276
277                         "set verbose (level)\n"
278                         "    Set the debug verbosity level X.\n\n"
279
280                         "set log global|(type) (level)\n"
281                         "    Set the log level.\n\n"
282
283                         "set nbport (num)\n"
284                         "    Set number of ports.\n\n"
285
286                         "set nbcore (num)\n"
287                         "    Set number of cores.\n\n"
288
289                         "set coremask (mask)\n"
290                         "    Set the forwarding cores hexadecimal mask.\n\n"
291
292                         "set portmask (mask)\n"
293                         "    Set the forwarding ports hexadecimal mask.\n\n"
294
295                         "set burst (num)\n"
296                         "    Set number of packets per burst.\n\n"
297
298                         "set burst tx delay (microseconds) retry (num)\n"
299                         "    Set the transmit delay time and number of retries,"
300                         " effective when retry is enabled.\n\n"
301
302                         "set rxoffs (x[,y]*)\n"
303                         "    Set the offset of each packet segment on"
304                         " receiving if split feature is engaged."
305                         " Affects only the queues configured with split"
306                         " offloads.\n\n"
307
308                         "set rxpkts (x[,y]*)\n"
309                         "    Set the length of each segment to scatter"
310                         " packets on receiving if split feature is engaged."
311                         " Affects only the queues configured with split"
312                         " offloads.\n\n"
313
314                         "set txpkts (x[,y]*)\n"
315                         "    Set the length of each segment of TXONLY"
316                         " and optionally CSUM packets.\n\n"
317
318                         "set txsplit (off|on|rand)\n"
319                         "    Set the split policy for the TX packets."
320                         " Right now only applicable for CSUM and TXONLY"
321                         " modes\n\n"
322
323                         "set txtimes (x, y)\n"
324                         "    Set the scheduling on timestamps"
325                         " timings for the TXONLY mode\n\n"
326
327                         "set corelist (x[,y]*)\n"
328                         "    Set the list of forwarding cores.\n\n"
329
330                         "set portlist (x[,y]*)\n"
331                         "    Set the list of forwarding ports.\n\n"
332
333                         "set port setup on (iterator|event)\n"
334                         "    Select how attached port is retrieved for setup.\n\n"
335
336                         "set tx loopback (port_id) (on|off)\n"
337                         "    Enable or disable tx loopback.\n\n"
338
339                         "set all queues drop (port_id) (on|off)\n"
340                         "    Set drop enable bit for all queues.\n\n"
341
342                         "set vf split drop (port_id) (vf_id) (on|off)\n"
343                         "    Set split drop enable bit for a VF from the PF.\n\n"
344
345                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
346                         "    Set MAC antispoof for a VF from the PF.\n\n"
347
348                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
349                         "    Enable MACsec offload.\n\n"
350
351                         "set macsec offload (port_id) off\n"
352                         "    Disable MACsec offload.\n\n"
353
354                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
355                         "    Configure MACsec secure connection (SC).\n\n"
356
357                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
358                         "    Configure MACsec secure association (SA).\n\n"
359
360                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
361                         "    Set VF broadcast for a VF from the PF.\n\n"
362
363                         "vlan set stripq (on|off) (port_id,queue_id)\n"
364                         "    Set the VLAN strip for a queue on a port.\n\n"
365
366                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
367                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
368
369                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
370                         "    Set VLAN insert for a VF from the PF.\n\n"
371
372                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
373                         "    Set VLAN antispoof for a VF from the PF.\n\n"
374
375                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
376                         "    Set VLAN tag for a VF from the PF.\n\n"
377
378                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
379                         "    Set a VF's max bandwidth(Mbps).\n\n"
380
381                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
382                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
383
384                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
385                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
386
387                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
388                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
389
390                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
391                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
392
393                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
394                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
395
396                         "vlan set (inner|outer) tpid (value) (port_id)\n"
397                         "    Set the VLAN TPID for Packet Filtering on"
398                         " a port\n\n"
399
400                         "rx_vlan add (vlan_id|all) (port_id)\n"
401                         "    Add a vlan_id, or all identifiers, to the set"
402                         " of VLAN identifiers filtered by port_id.\n\n"
403
404                         "rx_vlan rm (vlan_id|all) (port_id)\n"
405                         "    Remove a vlan_id, or all identifiers, from the set"
406                         " of VLAN identifiers filtered by port_id.\n\n"
407
408                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
409                         "    Add a vlan_id, to the set of VLAN identifiers"
410                         "filtered for VF(s) from port_id.\n\n"
411
412                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
413                         "    Remove a vlan_id, to the set of VLAN identifiers"
414                         "filtered for VF(s) from port_id.\n\n"
415
416                         "rx_vxlan_port add (udp_port) (port_id)\n"
417                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
418
419                         "rx_vxlan_port rm (udp_port) (port_id)\n"
420                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
421
422                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
423                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
424                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
425
426                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
427                         "    Set port based TX VLAN insertion.\n\n"
428
429                         "tx_vlan reset (port_id)\n"
430                         "    Disable hardware insertion of a VLAN header in"
431                         " packets sent on a port.\n\n"
432
433                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
434                         "    Select hardware or software calculation of the"
435                         " checksum when transmitting a packet using the"
436                         " csum forward engine.\n"
437                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
438                         "    outer-ip concerns the outer IP layer in"
439                         "    outer-udp concerns the outer UDP layer in"
440                         " case the packet is recognized as a tunnel packet by"
441                         " the forward engine (vxlan, gre and ipip are supported)\n"
442                         "    Please check the NIC datasheet for HW limits.\n\n"
443
444                         "csum parse-tunnel (on|off) (tx_port_id)\n"
445                         "    If disabled, treat tunnel packets as non-tunneled"
446                         " packets (treat inner headers as payload). The port\n"
447                         "    argument is the port used for TX in csum forward"
448                         " engine.\n\n"
449
450                         "csum show (port_id)\n"
451                         "    Display tx checksum offload configuration\n\n"
452
453                         "tso set (segsize) (portid)\n"
454                         "    Enable TCP Segmentation Offload in csum forward"
455                         " engine.\n"
456                         "    Please check the NIC datasheet for HW limits.\n\n"
457
458                         "tso show (portid)"
459                         "    Display the status of TCP Segmentation Offload.\n\n"
460
461                         "set port (port_id) gro on|off\n"
462                         "    Enable or disable Generic Receive Offload in"
463                         " csum forwarding engine.\n\n"
464
465                         "show port (port_id) gro\n"
466                         "    Display GRO configuration.\n\n"
467
468                         "set gro flush (cycles)\n"
469                         "    Set the cycle to flush GROed packets from"
470                         " reassembly tables.\n\n"
471
472                         "set port (port_id) gso (on|off)"
473                         "    Enable or disable Generic Segmentation Offload in"
474                         " csum forwarding engine.\n\n"
475
476                         "set gso segsz (length)\n"
477                         "    Set max packet length for output GSO segments,"
478                         " including packet header and payload.\n\n"
479
480                         "show port (port_id) gso\n"
481                         "    Show GSO configuration.\n\n"
482
483                         "set fwd (%s)\n"
484                         "    Set packet forwarding mode.\n\n"
485
486                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Add a MAC address on port_id.\n\n"
488
489                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
490                         "    Remove a MAC address from port_id.\n\n"
491
492                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
493                         "    Set the default MAC address for port_id.\n\n"
494
495                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
496                         "    Add a MAC address for a VF on the port.\n\n"
497
498                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
499                         "    Set the MAC address for a VF from the PF.\n\n"
500
501                         "set eth-peer (port_id) (peer_addr)\n"
502                         "    set the peer address for certain port.\n\n"
503
504                         "set port (port_id) uta (mac_address|all) (on|off)\n"
505                         "    Add/Remove a or all unicast hash filter(s)"
506                         "from port X.\n\n"
507
508                         "set promisc (port_id|all) (on|off)\n"
509                         "    Set the promiscuous mode on port_id, or all.\n\n"
510
511                         "set allmulti (port_id|all) (on|off)\n"
512                         "    Set the allmulti mode on port_id, or all.\n\n"
513
514                         "set vf promisc (port_id) (vf_id) (on|off)\n"
515                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
516
517                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
518                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
519
520                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
521                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
522                         " (on|off) autoneg (on|off) (port_id)\n"
523                         "set flow_ctrl rx (on|off) (portid)\n"
524                         "set flow_ctrl tx (on|off) (portid)\n"
525                         "set flow_ctrl high_water (high_water) (portid)\n"
526                         "set flow_ctrl low_water (low_water) (portid)\n"
527                         "set flow_ctrl pause_time (pause_time) (portid)\n"
528                         "set flow_ctrl send_xon (send_xon) (portid)\n"
529                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
530                         "set flow_ctrl autoneg (on|off) (port_id)\n"
531                         "    Set the link flow control parameter on a port.\n\n"
532
533                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
534                         " (low_water) (pause_time) (priority) (port_id)\n"
535                         "    Set the priority flow control parameter on a"
536                         " port.\n\n"
537
538                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
539                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
540                         " queue on port.\n"
541                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
542                         " on port 0 to mapping 5.\n\n"
543
544                         "set xstats-hide-zero on|off\n"
545                         "    Set the option to hide the zero values"
546                         " for xstats display.\n"
547
548                         "set record-core-cycles on|off\n"
549                         "    Set the option to enable measurement of CPU cycles.\n"
550
551                         "set record-burst-stats on|off\n"
552                         "    Set the option to enable display of RX and TX bursts.\n"
553
554                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
555                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
556
557                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
558                         "|MPE) (on|off)\n"
559                         "    AUPE:accepts untagged VLAN;"
560                         "ROPE:accept unicast hash\n\n"
561                         "    BAM:accepts broadcast packets;"
562                         "MPE:accepts all multicast packets\n\n"
563                         "    Enable/Disable a VF receive mode of a port\n\n"
564
565                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
566                         "    Set rate limit for a queue of a port\n\n"
567
568                         "set port (port_id) vf (vf_id) rate (rate_num) "
569                         "queue_mask (queue_mask_value)\n"
570                         "    Set rate limit for queues in VF of a port\n\n"
571
572                         "set flush_rx (on|off)\n"
573                         "   Flush (default) or don't flush RX streams before"
574                         " forwarding. Mainly used with PCAP drivers.\n\n"
575
576                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
577                         "   Set the bypass mode for the lowest port on bypass enabled"
578                         " NIC.\n\n"
579
580                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
581                         "mode (normal|bypass|isolate) (port_id)\n"
582                         "   Set the event required to initiate specified bypass mode for"
583                         " the lowest port on a bypass enabled NIC where:\n"
584                         "       timeout   = enable bypass after watchdog timeout.\n"
585                         "       os_on     = enable bypass when OS/board is powered on.\n"
586                         "       os_off    = enable bypass when OS/board is powered off.\n"
587                         "       power_on  = enable bypass when power supply is turned on.\n"
588                         "       power_off = enable bypass when power supply is turned off."
589                         "\n\n"
590
591                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
592                         "   Set the bypass watchdog timeout to 'n' seconds"
593                         " where 0 = instant.\n\n"
594
595                         "show bypass config (port_id)\n"
596                         "   Show the bypass configuration for a bypass enabled NIC"
597                         " using the lowest port on the NIC.\n\n"
598
599 #ifdef RTE_NET_BOND
600                         "create bonded device (mode) (socket)\n"
601                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
602
603                         "add bonding slave (slave_id) (port_id)\n"
604                         "       Add a slave device to a bonded device.\n\n"
605
606                         "remove bonding slave (slave_id) (port_id)\n"
607                         "       Remove a slave device from a bonded device.\n\n"
608
609                         "set bonding mode (value) (port_id)\n"
610                         "       Set the bonding mode on a bonded device.\n\n"
611
612                         "set bonding primary (slave_id) (port_id)\n"
613                         "       Set the primary slave for a bonded device.\n\n"
614
615                         "show bonding config (port_id)\n"
616                         "       Show the bonding config for port_id.\n\n"
617
618                         "show bonding lacp info (port_id)\n"
619                         "       Show the bonding lacp information for port_id.\n\n"
620
621                         "set bonding mac_addr (port_id) (address)\n"
622                         "       Set the MAC address of a bonded device.\n\n"
623
624                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
625                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
626
627                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
628                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
629
630                         "set bonding mon_period (port_id) (value)\n"
631                         "       Set the bonding link status monitoring polling period in ms.\n\n"
632
633                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
634                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
635
636 #endif
637                         "set link-up port (port_id)\n"
638                         "       Set link up for a port.\n\n"
639
640                         "set link-down port (port_id)\n"
641                         "       Set link down for a port.\n\n"
642
643                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
644                         "    Load a profile package on a port\n\n"
645
646                         "ddp del (port_id) (backup_profile_path)\n"
647                         "    Delete a profile package from a port\n\n"
648
649                         "ptype mapping get (port_id) (valid_only)\n"
650                         "    Get ptype mapping on a port\n\n"
651
652                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
653                         "    Replace target with the pkt_type in ptype mapping\n\n"
654
655                         "ptype mapping reset (port_id)\n"
656                         "    Reset ptype mapping on a port\n\n"
657
658                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
659                         "    Update a ptype mapping item on a port\n\n"
660
661                         "set port (port_id) ptype_mask (ptype_mask)\n"
662                         "    set packet types classification for a specific port\n\n"
663
664                         "set port (port_id) queue-region region_id (value) "
665                         "queue_start_index (value) queue_num (value)\n"
666                         "    Set a queue region on a port\n\n"
667
668                         "set port (port_id) queue-region region_id (value) "
669                         "flowtype (value)\n"
670                         "    Set a flowtype region index on a port\n\n"
671
672                         "set port (port_id) queue-region UP (value) region_id (value)\n"
673                         "    Set the mapping of User Priority to "
674                         "queue region on a port\n\n"
675
676                         "set port (port_id) queue-region flush (on|off)\n"
677                         "    flush all queue region related configuration\n\n"
678
679                         "show port meter cap (port_id)\n"
680                         "    Show port meter capability information\n\n"
681
682                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
683                         "    meter profile add - srtcm rfc 2697\n\n"
684
685                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
686                         "    meter profile add - trtcm rfc 2698\n\n"
687
688                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
689                         "    meter profile add - trtcm rfc 4115\n\n"
690
691                         "del port meter profile (port_id) (profile_id)\n"
692                         "    meter profile delete\n\n"
693
694                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
695                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
696                         "(dscp_tbl_entry63)]\n"
697                         "    meter create\n\n"
698
699                         "enable port meter (port_id) (mtr_id)\n"
700                         "    meter enable\n\n"
701
702                         "disable port meter (port_id) (mtr_id)\n"
703                         "    meter disable\n\n"
704
705                         "del port meter (port_id) (mtr_id)\n"
706                         "    meter delete\n\n"
707
708                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
709                         "y_actions (actions) r_actions (actions)\n"
710                         "    meter policy add\n\n"
711
712                         "del port meter policy (port_id) (policy_id)\n"
713                         "    meter policy delete\n\n"
714
715                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
716                         "    meter update meter profile\n\n"
717
718                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
719                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
720                         "    update meter dscp table entries\n\n"
721
722                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
723                         "(action0) [(action1) (action2)]\n"
724                         "    meter update policer action\n\n"
725
726                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
727                         "    meter update stats\n\n"
728
729                         "show port (port_id) queue-region\n"
730                         "    show all queue region related configuration info\n\n"
731
732                         "set port (port_id) fec_mode auto|off|rs|baser\n"
733                         "    set fec mode for a specific port\n\n"
734
735                         , list_pkt_forwarding_modes()
736                 );
737         }
738
739         if (show_all || !strcmp(res->section, "ports")) {
740
741                 cmdline_printf(
742                         cl,
743                         "\n"
744                         "Port Operations:\n"
745                         "----------------\n\n"
746
747                         "port start (port_id|all)\n"
748                         "    Start all ports or port_id.\n\n"
749
750                         "port stop (port_id|all)\n"
751                         "    Stop all ports or port_id.\n\n"
752
753                         "port close (port_id|all)\n"
754                         "    Close all ports or port_id.\n\n"
755
756                         "port reset (port_id|all)\n"
757                         "    Reset all ports or port_id.\n\n"
758
759                         "port attach (ident)\n"
760                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
761
762                         "port detach (port_id)\n"
763                         "    Detach physical or virtual dev by port_id\n\n"
764
765                         "port config (port_id|all)"
766                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
767                         " duplex (half|full|auto)\n"
768                         "    Set speed and duplex for all ports or port_id\n\n"
769
770                         "port config (port_id|all) loopback (mode)\n"
771                         "    Set loopback mode for all ports or port_id\n\n"
772
773                         "port config all (rxq|txq|rxd|txd) (value)\n"
774                         "    Set number for rxq/txq/rxd/txd.\n\n"
775
776                         "port config all max-pkt-len (value)\n"
777                         "    Set the max packet length.\n\n"
778
779                         "port config all max-lro-pkt-size (value)\n"
780                         "    Set the max LRO aggregated packet size.\n\n"
781
782                         "port config all drop-en (on|off)\n"
783                         "    Enable or disable packet drop on all RX queues of all ports when no "
784                         "receive buffers available.\n\n"
785
786                         "port config all rss (all|default|ip|tcp|udp|sctp|"
787                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
788                         "level-outer|level-inner|<flowtype_id>)\n"
789                         "    Set the RSS mode.\n\n"
790
791                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
792                         "    Set the RSS redirection table.\n\n"
793
794                         "port config (port_id) dcb vt (on|off) (traffic_class)"
795                         " pfc (on|off)\n"
796                         "    Set the DCB mode.\n\n"
797
798                         "port config all burst (value)\n"
799                         "    Set the number of packets per burst.\n\n"
800
801                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
802                         " (value)\n"
803                         "    Set the ring prefetch/host/writeback threshold"
804                         " for tx/rx queue.\n\n"
805
806                         "port config all (txfreet|txrst|rxfreet) (value)\n"
807                         "    Set free threshold for rx/tx, or set"
808                         " tx rs bit threshold.\n\n"
809                         "port config mtu X value\n"
810                         "    Set the MTU of port X to a given value\n\n"
811
812                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
813                         "    Set a rx/tx queue's ring size configuration, the new"
814                         " value will take effect after command that (re-)start the port"
815                         " or command that setup the specific queue\n\n"
816
817                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
818                         "    Start/stop a rx/tx queue of port X. Only take effect"
819                         " when port X is started\n\n"
820
821                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
822                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
823                         " take effect when port X is stopped.\n\n"
824
825                         "port (port_id) (rxq|txq) (queue_id) setup\n"
826                         "    Setup a rx/tx queue of port X.\n\n"
827
828                         "port config (port_id) pctype mapping reset\n"
829                         "    Reset flow type to pctype mapping on a port\n\n"
830
831                         "port config (port_id) pctype mapping update"
832                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
833                         "    Update a flow type to pctype mapping item on a port\n\n"
834
835                         "port config (port_id) pctype (pctype_id) hash_inset|"
836                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
837                         " (field_idx)\n"
838                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
839
840                         "port config (port_id) pctype (pctype_id) hash_inset|"
841                         "fdir_inset|fdir_flx_inset clear all"
842                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
843
844                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
845                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
846
847                         "port config <port_id> rx_offload vlan_strip|"
848                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
849                         "outer_ipv4_cksum|macsec_strip|header_split|"
850                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
851                         "buffer_split|timestamp|security|keep_crc on|off\n"
852                         "     Enable or disable a per port Rx offloading"
853                         " on all Rx queues of a port\n\n"
854
855                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
856                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
857                         "outer_ipv4_cksum|macsec_strip|header_split|"
858                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
859                         "buffer_split|timestamp|security|keep_crc on|off\n"
860                         "    Enable or disable a per queue Rx offloading"
861                         " only on a specific Rx queue\n\n"
862
863                         "port config (port_id) tx_offload vlan_insert|"
864                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
865                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
866                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
867                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
868                         "security on|off\n"
869                         "    Enable or disable a per port Tx offloading"
870                         " on all Tx queues of a port\n\n"
871
872                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
873                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
874                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
875                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
876                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
877                         " on|off\n"
878                         "    Enable or disable a per queue Tx offloading"
879                         " only on a specific Tx queue\n\n"
880
881                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
882                         "    Load an eBPF program as a callback"
883                         " for particular RX/TX queue\n\n"
884
885                         "bpf-unload rx|tx (port) (queue)\n"
886                         "    Unload previously loaded eBPF program"
887                         " for particular RX/TX queue\n\n"
888
889                         "port config (port_id) tx_metadata (value)\n"
890                         "    Set Tx metadata value per port. Testpmd will add this value"
891                         " to any Tx packet sent from this port\n\n"
892
893                         "port config (port_id) dynf (name) set|clear\n"
894                         "    Register a dynf and Set/clear this flag on Tx. "
895                         "Testpmd will set this value to any Tx packet "
896                         "sent from this port\n\n"
897
898                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
899                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
900                 );
901         }
902
903         if (show_all || !strcmp(res->section, "registers")) {
904
905                 cmdline_printf(
906                         cl,
907                         "\n"
908                         "Registers:\n"
909                         "----------\n\n"
910
911                         "read reg (port_id) (address)\n"
912                         "    Display value of a port register.\n\n"
913
914                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
915                         "    Display a port register bit field.\n\n"
916
917                         "read regbit (port_id) (address) (bit_x)\n"
918                         "    Display a single port register bit.\n\n"
919
920                         "write reg (port_id) (address) (value)\n"
921                         "    Set value of a port register.\n\n"
922
923                         "write regfield (port_id) (address) (bit_x) (bit_y)"
924                         " (value)\n"
925                         "    Set bit field of a port register.\n\n"
926
927                         "write regbit (port_id) (address) (bit_x) (value)\n"
928                         "    Set single bit value of a port register.\n\n"
929                 );
930         }
931         if (show_all || !strcmp(res->section, "filters")) {
932
933                 cmdline_printf(
934                         cl,
935                         "\n"
936                         "filters:\n"
937                         "--------\n\n"
938
939 #ifdef RTE_NET_I40E
940                         "flow_director_filter (port_id) mode raw (add|del|update)"
941                         " flow (flow_id) (drop|fwd) queue (queue_id)"
942                         " fd_id (fd_id_value) packet (packet file name)\n"
943                         "    Add/Del a raw type flow director filter.\n\n"
944 #endif
945
946                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
947                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
948                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
949                         "    Set flow director IP mask.\n\n"
950
951                         "flow_director_mask (port_id) mode MAC-VLAN"
952                         " vlan (vlan_value)\n"
953                         "    Set flow director MAC-VLAN mask.\n\n"
954
955                         "flow_director_mask (port_id) mode Tunnel"
956                         " vlan (vlan_value) mac (mac_value)"
957                         " tunnel-type (tunnel_type_value)"
958                         " tunnel-id (tunnel_id_value)\n"
959                         "    Set flow director Tunnel mask.\n\n"
960
961                         "flow_director_flex_payload (port_id)"
962                         " (raw|l2|l3|l4) (config)\n"
963                         "    Configure flex payload selection.\n\n"
964
965                         "flow validate {port_id}"
966                         " [group {group_id}] [priority {level}]"
967                         " [ingress] [egress]"
968                         " pattern {item} [/ {item} [...]] / end"
969                         " actions {action} [/ {action} [...]] / end\n"
970                         "    Check whether a flow rule can be created.\n\n"
971
972                         "flow create {port_id}"
973                         " [group {group_id}] [priority {level}]"
974                         " [ingress] [egress]"
975                         " pattern {item} [/ {item} [...]] / end"
976                         " actions {action} [/ {action} [...]] / end\n"
977                         "    Create a flow rule.\n\n"
978
979                         "flow destroy {port_id} rule {rule_id} [...]\n"
980                         "    Destroy specific flow rules.\n\n"
981
982                         "flow flush {port_id}\n"
983                         "    Destroy all flow rules.\n\n"
984
985                         "flow query {port_id} {rule_id} {action}\n"
986                         "    Query an existing flow rule.\n\n"
987
988                         "flow list {port_id} [group {group_id}] [...]\n"
989                         "    List existing flow rules sorted by priority,"
990                         " filtered by group identifiers.\n\n"
991
992                         "flow isolate {port_id} {boolean}\n"
993                         "    Restrict ingress traffic to the defined"
994                         " flow rules\n\n"
995
996                         "flow aged {port_id} [destroy]\n"
997                         "    List and destroy aged flows"
998                         " flow rules\n\n"
999
1000                         "flow indirect_action {port_id} create"
1001                         " [action_id {indirect_action_id}]"
1002                         " [ingress] [egress]"
1003                         " action {action} / end\n"
1004                         "    Create indirect action.\n\n"
1005
1006                         "flow indirect_action {port_id} update"
1007                         " {indirect_action_id} action {action} / end\n"
1008                         "    Update indirect action.\n\n"
1009
1010                         "flow indirect_action {port_id} destroy"
1011                         " action_id {indirect_action_id} [...]\n"
1012                         "    Destroy specific indirect actions.\n\n"
1013
1014                         "flow indirect_action {port_id} query"
1015                         " {indirect_action_id}\n"
1016                         "    Query an existing indirect action.\n\n"
1017
1018                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1019                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1020                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1021                         "       Configure the VXLAN encapsulation for flows.\n\n"
1022
1023                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1024                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1025                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1026                         " eth-dst (eth-dst)\n"
1027                         "       Configure the VXLAN encapsulation for flows.\n\n"
1028
1029                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1030                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1031                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1032                         " eth-dst (eth-dst)\n"
1033                         "       Configure the VXLAN encapsulation for flows.\n\n"
1034
1035                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1036                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1037                         " (eth-dst)\n"
1038                         "       Configure the NVGRE encapsulation for flows.\n\n"
1039
1040                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1041                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1042                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1043                         "       Configure the NVGRE encapsulation for flows.\n\n"
1044
1045                         "set raw_encap {flow items}\n"
1046                         "       Configure the encapsulation with raw data.\n\n"
1047
1048                         "set raw_decap {flow items}\n"
1049                         "       Configure the decapsulation with raw data.\n\n"
1050
1051                 );
1052         }
1053
1054         if (show_all || !strcmp(res->section, "traffic_management")) {
1055                 cmdline_printf(
1056                         cl,
1057                         "\n"
1058                         "Traffic Management:\n"
1059                         "--------------\n"
1060                         "show port tm cap (port_id)\n"
1061                         "       Display the port TM capability.\n\n"
1062
1063                         "show port tm level cap (port_id) (level_id)\n"
1064                         "       Display the port TM hierarchical level capability.\n\n"
1065
1066                         "show port tm node cap (port_id) (node_id)\n"
1067                         "       Display the port TM node capability.\n\n"
1068
1069                         "show port tm node type (port_id) (node_id)\n"
1070                         "       Display the port TM node type.\n\n"
1071
1072                         "show port tm node stats (port_id) (node_id) (clear)\n"
1073                         "       Display the port TM node stats.\n\n"
1074
1075                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1076                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1077                         " (packet_length_adjust) (packet_mode)\n"
1078                         "       Add port tm node private shaper profile.\n\n"
1079
1080                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1081                         "       Delete port tm node private shaper profile.\n\n"
1082
1083                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1084                         " (shaper_profile_id)\n"
1085                         "       Add/update port tm node shared shaper.\n\n"
1086
1087                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1088                         "       Delete port tm node shared shaper.\n\n"
1089
1090                         "set port tm node shaper profile (port_id) (node_id)"
1091                         " (shaper_profile_id)\n"
1092                         "       Set port tm node shaper profile.\n\n"
1093
1094                         "add port tm node wred profile (port_id) (wred_profile_id)"
1095                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1096                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1097                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1098                         "       Add port tm node wred profile.\n\n"
1099
1100                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1101                         "       Delete port tm node wred profile.\n\n"
1102
1103                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1104                         " (priority) (weight) (level_id) (shaper_profile_id)"
1105                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1106                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1107                         "       Add port tm nonleaf node.\n\n"
1108
1109                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1110                         " (priority) (weight) (level_id) (shaper_profile_id)"
1111                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1112                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1113                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1114
1115                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1116                         " (priority) (weight) (level_id) (shaper_profile_id)"
1117                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1118                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1119                         "       Add port tm leaf node.\n\n"
1120
1121                         "del port tm node (port_id) (node_id)\n"
1122                         "       Delete port tm node.\n\n"
1123
1124                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1125                         " (priority) (weight)\n"
1126                         "       Set port tm node parent.\n\n"
1127
1128                         "suspend port tm node (port_id) (node_id)"
1129                         "       Suspend tm node.\n\n"
1130
1131                         "resume port tm node (port_id) (node_id)"
1132                         "       Resume tm node.\n\n"
1133
1134                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1135                         "       Commit tm hierarchy.\n\n"
1136
1137                         "set port tm mark ip_ecn (port) (green) (yellow)"
1138                         " (red)\n"
1139                         "    Enables/Disables the traffic management marking"
1140                         " for IP ECN (Explicit Congestion Notification)"
1141                         " packets on a given port\n\n"
1142
1143                         "set port tm mark ip_dscp (port) (green) (yellow)"
1144                         " (red)\n"
1145                         "    Enables/Disables the traffic management marking"
1146                         " on the port for IP dscp packets\n\n"
1147
1148                         "set port tm mark vlan_dei (port) (green) (yellow)"
1149                         " (red)\n"
1150                         "    Enables/Disables the traffic management marking"
1151                         " on the port for VLAN packets with DEI enabled\n\n"
1152                 );
1153         }
1154
1155         if (show_all || !strcmp(res->section, "devices")) {
1156                 cmdline_printf(
1157                         cl,
1158                         "\n"
1159                         "Device Operations:\n"
1160                         "--------------\n"
1161                         "device detach (identifier)\n"
1162                         "       Detach device by identifier.\n\n"
1163                 );
1164         }
1165
1166 }
1167
1168 cmdline_parse_token_string_t cmd_help_long_help =
1169         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1170
1171 cmdline_parse_token_string_t cmd_help_long_section =
1172         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1173                         "all#control#display#config#"
1174                         "ports#registers#filters#traffic_management#devices");
1175
1176 cmdline_parse_inst_t cmd_help_long = {
1177         .f = cmd_help_long_parsed,
1178         .data = NULL,
1179         .help_str = "help all|control|display|config|ports|register|"
1180                 "filters|traffic_management|devices: "
1181                 "Show help",
1182         .tokens = {
1183                 (void *)&cmd_help_long_help,
1184                 (void *)&cmd_help_long_section,
1185                 NULL,
1186         },
1187 };
1188
1189
1190 /* *** start/stop/close all ports *** */
1191 struct cmd_operate_port_result {
1192         cmdline_fixed_string_t keyword;
1193         cmdline_fixed_string_t name;
1194         cmdline_fixed_string_t value;
1195 };
1196
1197 static void cmd_operate_port_parsed(void *parsed_result,
1198                                 __rte_unused struct cmdline *cl,
1199                                 __rte_unused void *data)
1200 {
1201         struct cmd_operate_port_result *res = parsed_result;
1202
1203         if (!strcmp(res->name, "start"))
1204                 start_port(RTE_PORT_ALL);
1205         else if (!strcmp(res->name, "stop"))
1206                 stop_port(RTE_PORT_ALL);
1207         else if (!strcmp(res->name, "close"))
1208                 close_port(RTE_PORT_ALL);
1209         else if (!strcmp(res->name, "reset"))
1210                 reset_port(RTE_PORT_ALL);
1211         else
1212                 fprintf(stderr, "Unknown parameter\n");
1213 }
1214
1215 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1216         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1217                                                                 "port");
1218 cmdline_parse_token_string_t cmd_operate_port_all_port =
1219         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1220                                                 "start#stop#close#reset");
1221 cmdline_parse_token_string_t cmd_operate_port_all_all =
1222         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1223
1224 cmdline_parse_inst_t cmd_operate_port = {
1225         .f = cmd_operate_port_parsed,
1226         .data = NULL,
1227         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1228         .tokens = {
1229                 (void *)&cmd_operate_port_all_cmd,
1230                 (void *)&cmd_operate_port_all_port,
1231                 (void *)&cmd_operate_port_all_all,
1232                 NULL,
1233         },
1234 };
1235
1236 /* *** start/stop/close specific port *** */
1237 struct cmd_operate_specific_port_result {
1238         cmdline_fixed_string_t keyword;
1239         cmdline_fixed_string_t name;
1240         uint8_t value;
1241 };
1242
1243 static void cmd_operate_specific_port_parsed(void *parsed_result,
1244                         __rte_unused struct cmdline *cl,
1245                                 __rte_unused void *data)
1246 {
1247         struct cmd_operate_specific_port_result *res = parsed_result;
1248
1249         if (!strcmp(res->name, "start"))
1250                 start_port(res->value);
1251         else if (!strcmp(res->name, "stop"))
1252                 stop_port(res->value);
1253         else if (!strcmp(res->name, "close"))
1254                 close_port(res->value);
1255         else if (!strcmp(res->name, "reset"))
1256                 reset_port(res->value);
1257         else
1258                 fprintf(stderr, "Unknown parameter\n");
1259 }
1260
1261 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1262         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1263                                                         keyword, "port");
1264 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1265         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1266                                                 name, "start#stop#close#reset");
1267 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1268         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1269                                                         value, RTE_UINT8);
1270
1271 cmdline_parse_inst_t cmd_operate_specific_port = {
1272         .f = cmd_operate_specific_port_parsed,
1273         .data = NULL,
1274         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1275         .tokens = {
1276                 (void *)&cmd_operate_specific_port_cmd,
1277                 (void *)&cmd_operate_specific_port_port,
1278                 (void *)&cmd_operate_specific_port_id,
1279                 NULL,
1280         },
1281 };
1282
1283 /* *** enable port setup (after attach) via iterator or event *** */
1284 struct cmd_set_port_setup_on_result {
1285         cmdline_fixed_string_t set;
1286         cmdline_fixed_string_t port;
1287         cmdline_fixed_string_t setup;
1288         cmdline_fixed_string_t on;
1289         cmdline_fixed_string_t mode;
1290 };
1291
1292 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1293                                 __rte_unused struct cmdline *cl,
1294                                 __rte_unused void *data)
1295 {
1296         struct cmd_set_port_setup_on_result *res = parsed_result;
1297
1298         if (strcmp(res->mode, "event") == 0)
1299                 setup_on_probe_event = true;
1300         else if (strcmp(res->mode, "iterator") == 0)
1301                 setup_on_probe_event = false;
1302         else
1303                 fprintf(stderr, "Unknown mode\n");
1304 }
1305
1306 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1307         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1308                         set, "set");
1309 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1310         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1311                         port, "port");
1312 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1313         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1314                         setup, "setup");
1315 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1316         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1317                         on, "on");
1318 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1319         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1320                         mode, "iterator#event");
1321
1322 cmdline_parse_inst_t cmd_set_port_setup_on = {
1323         .f = cmd_set_port_setup_on_parsed,
1324         .data = NULL,
1325         .help_str = "set port setup on iterator|event",
1326         .tokens = {
1327                 (void *)&cmd_set_port_setup_on_set,
1328                 (void *)&cmd_set_port_setup_on_port,
1329                 (void *)&cmd_set_port_setup_on_setup,
1330                 (void *)&cmd_set_port_setup_on_on,
1331                 (void *)&cmd_set_port_setup_on_mode,
1332                 NULL,
1333         },
1334 };
1335
1336 /* *** attach a specified port *** */
1337 struct cmd_operate_attach_port_result {
1338         cmdline_fixed_string_t port;
1339         cmdline_fixed_string_t keyword;
1340         cmdline_multi_string_t identifier;
1341 };
1342
1343 static void cmd_operate_attach_port_parsed(void *parsed_result,
1344                                 __rte_unused struct cmdline *cl,
1345                                 __rte_unused void *data)
1346 {
1347         struct cmd_operate_attach_port_result *res = parsed_result;
1348
1349         if (!strcmp(res->keyword, "attach"))
1350                 attach_port(res->identifier);
1351         else
1352                 fprintf(stderr, "Unknown parameter\n");
1353 }
1354
1355 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1356         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1357                         port, "port");
1358 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1359         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1360                         keyword, "attach");
1361 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1363                         identifier, TOKEN_STRING_MULTI);
1364
1365 cmdline_parse_inst_t cmd_operate_attach_port = {
1366         .f = cmd_operate_attach_port_parsed,
1367         .data = NULL,
1368         .help_str = "port attach <identifier>: "
1369                 "(identifier: pci address or virtual dev name)",
1370         .tokens = {
1371                 (void *)&cmd_operate_attach_port_port,
1372                 (void *)&cmd_operate_attach_port_keyword,
1373                 (void *)&cmd_operate_attach_port_identifier,
1374                 NULL,
1375         },
1376 };
1377
1378 /* *** detach a specified port *** */
1379 struct cmd_operate_detach_port_result {
1380         cmdline_fixed_string_t port;
1381         cmdline_fixed_string_t keyword;
1382         portid_t port_id;
1383 };
1384
1385 static void cmd_operate_detach_port_parsed(void *parsed_result,
1386                                 __rte_unused struct cmdline *cl,
1387                                 __rte_unused void *data)
1388 {
1389         struct cmd_operate_detach_port_result *res = parsed_result;
1390
1391         if (!strcmp(res->keyword, "detach")) {
1392                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1393                 detach_port_device(res->port_id);
1394         } else {
1395                 fprintf(stderr, "Unknown parameter\n");
1396         }
1397 }
1398
1399 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1400         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1401                         port, "port");
1402 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1403         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1404                         keyword, "detach");
1405 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1406         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1407                         port_id, RTE_UINT16);
1408
1409 cmdline_parse_inst_t cmd_operate_detach_port = {
1410         .f = cmd_operate_detach_port_parsed,
1411         .data = NULL,
1412         .help_str = "port detach <port_id>",
1413         .tokens = {
1414                 (void *)&cmd_operate_detach_port_port,
1415                 (void *)&cmd_operate_detach_port_keyword,
1416                 (void *)&cmd_operate_detach_port_port_id,
1417                 NULL,
1418         },
1419 };
1420
1421 /* *** detach device by identifier *** */
1422 struct cmd_operate_detach_device_result {
1423         cmdline_fixed_string_t device;
1424         cmdline_fixed_string_t keyword;
1425         cmdline_fixed_string_t identifier;
1426 };
1427
1428 static void cmd_operate_detach_device_parsed(void *parsed_result,
1429                                 __rte_unused struct cmdline *cl,
1430                                 __rte_unused void *data)
1431 {
1432         struct cmd_operate_detach_device_result *res = parsed_result;
1433
1434         if (!strcmp(res->keyword, "detach"))
1435                 detach_devargs(res->identifier);
1436         else
1437                 fprintf(stderr, "Unknown parameter\n");
1438 }
1439
1440 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1441         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1442                         device, "device");
1443 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1444         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1445                         keyword, "detach");
1446 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1447         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1448                         identifier, NULL);
1449
1450 cmdline_parse_inst_t cmd_operate_detach_device = {
1451         .f = cmd_operate_detach_device_parsed,
1452         .data = NULL,
1453         .help_str = "device detach <identifier>:"
1454                 "(identifier: pci address or virtual dev name)",
1455         .tokens = {
1456                 (void *)&cmd_operate_detach_device_device,
1457                 (void *)&cmd_operate_detach_device_keyword,
1458                 (void *)&cmd_operate_detach_device_identifier,
1459                 NULL,
1460         },
1461 };
1462 /* *** configure speed for all ports *** */
1463 struct cmd_config_speed_all {
1464         cmdline_fixed_string_t port;
1465         cmdline_fixed_string_t keyword;
1466         cmdline_fixed_string_t all;
1467         cmdline_fixed_string_t item1;
1468         cmdline_fixed_string_t item2;
1469         cmdline_fixed_string_t value1;
1470         cmdline_fixed_string_t value2;
1471 };
1472
1473 static int
1474 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1475 {
1476
1477         int duplex;
1478
1479         if (!strcmp(duplexstr, "half")) {
1480                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
1481         } else if (!strcmp(duplexstr, "full")) {
1482                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1483         } else if (!strcmp(duplexstr, "auto")) {
1484                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1485         } else {
1486                 fprintf(stderr, "Unknown duplex parameter\n");
1487                 return -1;
1488         }
1489
1490         if (!strcmp(speedstr, "10")) {
1491                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1492                                 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1493         } else if (!strcmp(speedstr, "100")) {
1494                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1495                                 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1496         } else {
1497                 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1498                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1499                         return -1;
1500                 }
1501                 if (!strcmp(speedstr, "1000")) {
1502                         *speed = RTE_ETH_LINK_SPEED_1G;
1503                 } else if (!strcmp(speedstr, "10000")) {
1504                         *speed = RTE_ETH_LINK_SPEED_10G;
1505                 } else if (!strcmp(speedstr, "25000")) {
1506                         *speed = RTE_ETH_LINK_SPEED_25G;
1507                 } else if (!strcmp(speedstr, "40000")) {
1508                         *speed = RTE_ETH_LINK_SPEED_40G;
1509                 } else if (!strcmp(speedstr, "50000")) {
1510                         *speed = RTE_ETH_LINK_SPEED_50G;
1511                 } else if (!strcmp(speedstr, "100000")) {
1512                         *speed = RTE_ETH_LINK_SPEED_100G;
1513                 } else if (!strcmp(speedstr, "200000")) {
1514                         *speed = RTE_ETH_LINK_SPEED_200G;
1515                 } else if (!strcmp(speedstr, "auto")) {
1516                         *speed = RTE_ETH_LINK_SPEED_AUTONEG;
1517                 } else {
1518                         fprintf(stderr, "Unknown speed parameter\n");
1519                         return -1;
1520                 }
1521         }
1522
1523         if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1524                 *speed |= RTE_ETH_LINK_SPEED_FIXED;
1525
1526         return 0;
1527 }
1528
1529 static void
1530 cmd_config_speed_all_parsed(void *parsed_result,
1531                         __rte_unused struct cmdline *cl,
1532                         __rte_unused void *data)
1533 {
1534         struct cmd_config_speed_all *res = parsed_result;
1535         uint32_t link_speed;
1536         portid_t pid;
1537
1538         if (!all_ports_stopped()) {
1539                 fprintf(stderr, "Please stop all ports first\n");
1540                 return;
1541         }
1542
1543         if (parse_and_check_speed_duplex(res->value1, res->value2,
1544                         &link_speed) < 0)
1545                 return;
1546
1547         RTE_ETH_FOREACH_DEV(pid) {
1548                 ports[pid].dev_conf.link_speeds = link_speed;
1549         }
1550
1551         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1552 }
1553
1554 cmdline_parse_token_string_t cmd_config_speed_all_port =
1555         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1556 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1558                                                         "config");
1559 cmdline_parse_token_string_t cmd_config_speed_all_all =
1560         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1561 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1562         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1563 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1564         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1565                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1566 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1567         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1568 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1569         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1570                                                 "half#full#auto");
1571
1572 cmdline_parse_inst_t cmd_config_speed_all = {
1573         .f = cmd_config_speed_all_parsed,
1574         .data = NULL,
1575         .help_str = "port config all speed "
1576                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1577                                                         "half|full|auto",
1578         .tokens = {
1579                 (void *)&cmd_config_speed_all_port,
1580                 (void *)&cmd_config_speed_all_keyword,
1581                 (void *)&cmd_config_speed_all_all,
1582                 (void *)&cmd_config_speed_all_item1,
1583                 (void *)&cmd_config_speed_all_value1,
1584                 (void *)&cmd_config_speed_all_item2,
1585                 (void *)&cmd_config_speed_all_value2,
1586                 NULL,
1587         },
1588 };
1589
1590 /* *** configure speed for specific port *** */
1591 struct cmd_config_speed_specific {
1592         cmdline_fixed_string_t port;
1593         cmdline_fixed_string_t keyword;
1594         portid_t id;
1595         cmdline_fixed_string_t item1;
1596         cmdline_fixed_string_t item2;
1597         cmdline_fixed_string_t value1;
1598         cmdline_fixed_string_t value2;
1599 };
1600
1601 static void
1602 cmd_config_speed_specific_parsed(void *parsed_result,
1603                                 __rte_unused struct cmdline *cl,
1604                                 __rte_unused void *data)
1605 {
1606         struct cmd_config_speed_specific *res = parsed_result;
1607         uint32_t link_speed;
1608
1609         if (port_id_is_invalid(res->id, ENABLED_WARN))
1610                 return;
1611
1612         if (!port_is_stopped(res->id)) {
1613                 fprintf(stderr, "Please stop port %d first\n", res->id);
1614                 return;
1615         }
1616
1617         if (parse_and_check_speed_duplex(res->value1, res->value2,
1618                         &link_speed) < 0)
1619                 return;
1620
1621         ports[res->id].dev_conf.link_speeds = link_speed;
1622
1623         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1624 }
1625
1626
1627 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1628         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1629                                                                 "port");
1630 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1632                                                                 "config");
1633 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1634         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1635 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1636         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1637                                                                 "speed");
1638 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1639         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1640                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1641 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1642         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1643                                                                 "duplex");
1644 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1646                                                         "half#full#auto");
1647
1648 cmdline_parse_inst_t cmd_config_speed_specific = {
1649         .f = cmd_config_speed_specific_parsed,
1650         .data = NULL,
1651         .help_str = "port config <port_id> speed "
1652                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1653                                                         "half|full|auto",
1654         .tokens = {
1655                 (void *)&cmd_config_speed_specific_port,
1656                 (void *)&cmd_config_speed_specific_keyword,
1657                 (void *)&cmd_config_speed_specific_id,
1658                 (void *)&cmd_config_speed_specific_item1,
1659                 (void *)&cmd_config_speed_specific_value1,
1660                 (void *)&cmd_config_speed_specific_item2,
1661                 (void *)&cmd_config_speed_specific_value2,
1662                 NULL,
1663         },
1664 };
1665
1666 /* *** configure loopback for all ports *** */
1667 struct cmd_config_loopback_all {
1668         cmdline_fixed_string_t port;
1669         cmdline_fixed_string_t keyword;
1670         cmdline_fixed_string_t all;
1671         cmdline_fixed_string_t item;
1672         uint32_t mode;
1673 };
1674
1675 static void
1676 cmd_config_loopback_all_parsed(void *parsed_result,
1677                         __rte_unused struct cmdline *cl,
1678                         __rte_unused void *data)
1679 {
1680         struct cmd_config_loopback_all *res = parsed_result;
1681         portid_t pid;
1682
1683         if (!all_ports_stopped()) {
1684                 fprintf(stderr, "Please stop all ports first\n");
1685                 return;
1686         }
1687
1688         RTE_ETH_FOREACH_DEV(pid) {
1689                 ports[pid].dev_conf.lpbk_mode = res->mode;
1690         }
1691
1692         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1693 }
1694
1695 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1696         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1697 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1698         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1699                                                         "config");
1700 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1701         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1702 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1703         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1704                                                         "loopback");
1705 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1706         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1707
1708 cmdline_parse_inst_t cmd_config_loopback_all = {
1709         .f = cmd_config_loopback_all_parsed,
1710         .data = NULL,
1711         .help_str = "port config all loopback <mode>",
1712         .tokens = {
1713                 (void *)&cmd_config_loopback_all_port,
1714                 (void *)&cmd_config_loopback_all_keyword,
1715                 (void *)&cmd_config_loopback_all_all,
1716                 (void *)&cmd_config_loopback_all_item,
1717                 (void *)&cmd_config_loopback_all_mode,
1718                 NULL,
1719         },
1720 };
1721
1722 /* *** configure loopback for specific port *** */
1723 struct cmd_config_loopback_specific {
1724         cmdline_fixed_string_t port;
1725         cmdline_fixed_string_t keyword;
1726         uint16_t port_id;
1727         cmdline_fixed_string_t item;
1728         uint32_t mode;
1729 };
1730
1731 static void
1732 cmd_config_loopback_specific_parsed(void *parsed_result,
1733                                 __rte_unused struct cmdline *cl,
1734                                 __rte_unused void *data)
1735 {
1736         struct cmd_config_loopback_specific *res = parsed_result;
1737
1738         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1739                 return;
1740
1741         if (!port_is_stopped(res->port_id)) {
1742                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1743                 return;
1744         }
1745
1746         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1747
1748         cmd_reconfig_device_queue(res->port_id, 1, 1);
1749 }
1750
1751
1752 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1753         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1754                                                                 "port");
1755 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1756         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1757                                                                 "config");
1758 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1759         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1760                                                                 RTE_UINT16);
1761 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1762         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1763                                                                 "loopback");
1764 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1765         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1766                               RTE_UINT32);
1767
1768 cmdline_parse_inst_t cmd_config_loopback_specific = {
1769         .f = cmd_config_loopback_specific_parsed,
1770         .data = NULL,
1771         .help_str = "port config <port_id> loopback <mode>",
1772         .tokens = {
1773                 (void *)&cmd_config_loopback_specific_port,
1774                 (void *)&cmd_config_loopback_specific_keyword,
1775                 (void *)&cmd_config_loopback_specific_id,
1776                 (void *)&cmd_config_loopback_specific_item,
1777                 (void *)&cmd_config_loopback_specific_mode,
1778                 NULL,
1779         },
1780 };
1781
1782 /* *** configure txq/rxq, txd/rxd *** */
1783 struct cmd_config_rx_tx {
1784         cmdline_fixed_string_t port;
1785         cmdline_fixed_string_t keyword;
1786         cmdline_fixed_string_t all;
1787         cmdline_fixed_string_t name;
1788         uint16_t value;
1789 };
1790
1791 static void
1792 cmd_config_rx_tx_parsed(void *parsed_result,
1793                         __rte_unused struct cmdline *cl,
1794                         __rte_unused void *data)
1795 {
1796         struct cmd_config_rx_tx *res = parsed_result;
1797
1798         if (!all_ports_stopped()) {
1799                 fprintf(stderr, "Please stop all ports first\n");
1800                 return;
1801         }
1802         if (!strcmp(res->name, "rxq")) {
1803                 if (!res->value && !nb_txq) {
1804                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1805                         return;
1806                 }
1807                 if (check_nb_rxq(res->value) != 0)
1808                         return;
1809                 nb_rxq = res->value;
1810         }
1811         else if (!strcmp(res->name, "txq")) {
1812                 if (!res->value && !nb_rxq) {
1813                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1814                         return;
1815                 }
1816                 if (check_nb_txq(res->value) != 0)
1817                         return;
1818                 nb_txq = res->value;
1819         }
1820         else if (!strcmp(res->name, "rxd")) {
1821                 if (check_nb_rxd(res->value) != 0)
1822                         return;
1823                 nb_rxd = res->value;
1824         } else if (!strcmp(res->name, "txd")) {
1825                 if (check_nb_txd(res->value) != 0)
1826                         return;
1827
1828                 nb_txd = res->value;
1829         } else {
1830                 fprintf(stderr, "Unknown parameter\n");
1831                 return;
1832         }
1833
1834         fwd_config_setup();
1835
1836         init_port_config();
1837
1838         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1839 }
1840
1841 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1842         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1843 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1844         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1845 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1846         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1847 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1849                                                 "rxq#txq#rxd#txd");
1850 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1851         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1852
1853 cmdline_parse_inst_t cmd_config_rx_tx = {
1854         .f = cmd_config_rx_tx_parsed,
1855         .data = NULL,
1856         .help_str = "port config all rxq|txq|rxd|txd <value>",
1857         .tokens = {
1858                 (void *)&cmd_config_rx_tx_port,
1859                 (void *)&cmd_config_rx_tx_keyword,
1860                 (void *)&cmd_config_rx_tx_all,
1861                 (void *)&cmd_config_rx_tx_name,
1862                 (void *)&cmd_config_rx_tx_value,
1863                 NULL,
1864         },
1865 };
1866
1867 /* *** config max packet length *** */
1868 struct cmd_config_max_pkt_len_result {
1869         cmdline_fixed_string_t port;
1870         cmdline_fixed_string_t keyword;
1871         cmdline_fixed_string_t all;
1872         cmdline_fixed_string_t name;
1873         uint32_t value;
1874 };
1875
1876 static void
1877 cmd_config_max_pkt_len_parsed(void *parsed_result,
1878                                 __rte_unused struct cmdline *cl,
1879                                 __rte_unused void *data)
1880 {
1881         struct cmd_config_max_pkt_len_result *res = parsed_result;
1882         portid_t port_id;
1883         int ret;
1884
1885         if (strcmp(res->name, "max-pkt-len") != 0) {
1886                 printf("Unknown parameter\n");
1887                 return;
1888         }
1889
1890         if (!all_ports_stopped()) {
1891                 fprintf(stderr, "Please stop all ports first\n");
1892                 return;
1893         }
1894
1895         RTE_ETH_FOREACH_DEV(port_id) {
1896                 struct rte_port *port = &ports[port_id];
1897
1898                 if (res->value < RTE_ETHER_MIN_LEN) {
1899                         fprintf(stderr,
1900                                 "max-pkt-len can not be less than %d\n",
1901                                 RTE_ETHER_MIN_LEN);
1902                         return;
1903                 }
1904
1905                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1906                 if (ret != 0) {
1907                         fprintf(stderr,
1908                                 "rte_eth_dev_info_get() failed for port %u\n",
1909                                 port_id);
1910                         return;
1911                 }
1912
1913                 update_mtu_from_frame_size(port_id, res->value);
1914         }
1915
1916         init_port_config();
1917
1918         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1919 }
1920
1921 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1922         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1923                                                                 "port");
1924 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1925         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1926                                                                 "config");
1927 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1929                                                                 "all");
1930 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1931         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1932                                                                 "max-pkt-len");
1933 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1934         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1935                                                                 RTE_UINT32);
1936
1937 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1938         .f = cmd_config_max_pkt_len_parsed,
1939         .data = NULL,
1940         .help_str = "port config all max-pkt-len <value>",
1941         .tokens = {
1942                 (void *)&cmd_config_max_pkt_len_port,
1943                 (void *)&cmd_config_max_pkt_len_keyword,
1944                 (void *)&cmd_config_max_pkt_len_all,
1945                 (void *)&cmd_config_max_pkt_len_name,
1946                 (void *)&cmd_config_max_pkt_len_value,
1947                 NULL,
1948         },
1949 };
1950
1951 /* *** config max LRO aggregated packet size *** */
1952 struct cmd_config_max_lro_pkt_size_result {
1953         cmdline_fixed_string_t port;
1954         cmdline_fixed_string_t keyword;
1955         cmdline_fixed_string_t all;
1956         cmdline_fixed_string_t name;
1957         uint32_t value;
1958 };
1959
1960 static void
1961 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1962                                 __rte_unused struct cmdline *cl,
1963                                 __rte_unused void *data)
1964 {
1965         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1966         portid_t pid;
1967
1968         if (!all_ports_stopped()) {
1969                 fprintf(stderr, "Please stop all ports first\n");
1970                 return;
1971         }
1972
1973         RTE_ETH_FOREACH_DEV(pid) {
1974                 struct rte_port *port = &ports[pid];
1975
1976                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1977                         if (res->value ==
1978                                         port->dev_conf.rxmode.max_lro_pkt_size)
1979                                 return;
1980
1981                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1982                 } else {
1983                         fprintf(stderr, "Unknown parameter\n");
1984                         return;
1985                 }
1986         }
1987
1988         init_port_config();
1989
1990         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1991 }
1992
1993 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
1994         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1995                                  port, "port");
1996 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
1997         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
1998                                  keyword, "config");
1999 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2001                                  all, "all");
2002 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2003         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2004                                  name, "max-lro-pkt-size");
2005 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2006         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2007                               value, RTE_UINT32);
2008
2009 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2010         .f = cmd_config_max_lro_pkt_size_parsed,
2011         .data = NULL,
2012         .help_str = "port config all max-lro-pkt-size <value>",
2013         .tokens = {
2014                 (void *)&cmd_config_max_lro_pkt_size_port,
2015                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2016                 (void *)&cmd_config_max_lro_pkt_size_all,
2017                 (void *)&cmd_config_max_lro_pkt_size_name,
2018                 (void *)&cmd_config_max_lro_pkt_size_value,
2019                 NULL,
2020         },
2021 };
2022
2023 /* *** configure port MTU *** */
2024 struct cmd_config_mtu_result {
2025         cmdline_fixed_string_t port;
2026         cmdline_fixed_string_t keyword;
2027         cmdline_fixed_string_t mtu;
2028         portid_t port_id;
2029         uint16_t value;
2030 };
2031
2032 static void
2033 cmd_config_mtu_parsed(void *parsed_result,
2034                       __rte_unused struct cmdline *cl,
2035                       __rte_unused void *data)
2036 {
2037         struct cmd_config_mtu_result *res = parsed_result;
2038
2039         if (res->value < RTE_ETHER_MIN_LEN) {
2040                 fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2041                 return;
2042         }
2043         port_mtu_set(res->port_id, res->value);
2044 }
2045
2046 cmdline_parse_token_string_t cmd_config_mtu_port =
2047         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2048                                  "port");
2049 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2050         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2051                                  "config");
2052 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2053         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2054                                  "mtu");
2055 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2056         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2057                                  RTE_UINT16);
2058 cmdline_parse_token_num_t cmd_config_mtu_value =
2059         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2060                                  RTE_UINT16);
2061
2062 cmdline_parse_inst_t cmd_config_mtu = {
2063         .f = cmd_config_mtu_parsed,
2064         .data = NULL,
2065         .help_str = "port config mtu <port_id> <value>",
2066         .tokens = {
2067                 (void *)&cmd_config_mtu_port,
2068                 (void *)&cmd_config_mtu_keyword,
2069                 (void *)&cmd_config_mtu_mtu,
2070                 (void *)&cmd_config_mtu_port_id,
2071                 (void *)&cmd_config_mtu_value,
2072                 NULL,
2073         },
2074 };
2075
2076 /* *** configure rx mode *** */
2077 struct cmd_config_rx_mode_flag {
2078         cmdline_fixed_string_t port;
2079         cmdline_fixed_string_t keyword;
2080         cmdline_fixed_string_t all;
2081         cmdline_fixed_string_t name;
2082         cmdline_fixed_string_t value;
2083 };
2084
2085 static void
2086 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2087                                 __rte_unused struct cmdline *cl,
2088                                 __rte_unused void *data)
2089 {
2090         struct cmd_config_rx_mode_flag *res = parsed_result;
2091
2092         if (!all_ports_stopped()) {
2093                 fprintf(stderr, "Please stop all ports first\n");
2094                 return;
2095         }
2096
2097         if (!strcmp(res->name, "drop-en")) {
2098                 if (!strcmp(res->value, "on"))
2099                         rx_drop_en = 1;
2100                 else if (!strcmp(res->value, "off"))
2101                         rx_drop_en = 0;
2102                 else {
2103                         fprintf(stderr, "Unknown parameter\n");
2104                         return;
2105                 }
2106         } else {
2107                 fprintf(stderr, "Unknown parameter\n");
2108                 return;
2109         }
2110
2111         init_port_config();
2112
2113         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2114 }
2115
2116 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2117         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2118 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2119         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2120                                                                 "config");
2121 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2122         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2123 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2124         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2125                                         "drop-en");
2126 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2127         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2128                                                         "on#off");
2129
2130 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2131         .f = cmd_config_rx_mode_flag_parsed,
2132         .data = NULL,
2133         .help_str = "port config all drop-en on|off",
2134         .tokens = {
2135                 (void *)&cmd_config_rx_mode_flag_port,
2136                 (void *)&cmd_config_rx_mode_flag_keyword,
2137                 (void *)&cmd_config_rx_mode_flag_all,
2138                 (void *)&cmd_config_rx_mode_flag_name,
2139                 (void *)&cmd_config_rx_mode_flag_value,
2140                 NULL,
2141         },
2142 };
2143
2144 /* *** configure rss *** */
2145 struct cmd_config_rss {
2146         cmdline_fixed_string_t port;
2147         cmdline_fixed_string_t keyword;
2148         cmdline_fixed_string_t all;
2149         cmdline_fixed_string_t name;
2150         cmdline_fixed_string_t value;
2151 };
2152
2153 static void
2154 cmd_config_rss_parsed(void *parsed_result,
2155                         __rte_unused struct cmdline *cl,
2156                         __rte_unused void *data)
2157 {
2158         struct cmd_config_rss *res = parsed_result;
2159         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2160         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2161         int use_default = 0;
2162         int all_updated = 1;
2163         int diag;
2164         uint16_t i;
2165         int ret;
2166
2167         if (!strcmp(res->value, "all"))
2168                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2169                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2170                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2171                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2172                         RTE_ETH_RSS_ECPRI;
2173         else if (!strcmp(res->value, "eth"))
2174                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2175         else if (!strcmp(res->value, "vlan"))
2176                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2177         else if (!strcmp(res->value, "ip"))
2178                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2179         else if (!strcmp(res->value, "udp"))
2180                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2181         else if (!strcmp(res->value, "tcp"))
2182                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2183         else if (!strcmp(res->value, "sctp"))
2184                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2185         else if (!strcmp(res->value, "ether"))
2186                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2187         else if (!strcmp(res->value, "port"))
2188                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2189         else if (!strcmp(res->value, "vxlan"))
2190                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2191         else if (!strcmp(res->value, "geneve"))
2192                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2193         else if (!strcmp(res->value, "nvgre"))
2194                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2195         else if (!strcmp(res->value, "l3-pre32"))
2196                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2197         else if (!strcmp(res->value, "l3-pre40"))
2198                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2199         else if (!strcmp(res->value, "l3-pre48"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2201         else if (!strcmp(res->value, "l3-pre56"))
2202                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2203         else if (!strcmp(res->value, "l3-pre64"))
2204                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2205         else if (!strcmp(res->value, "l3-pre96"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2207         else if (!strcmp(res->value, "l3-src-only"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2209         else if (!strcmp(res->value, "l3-dst-only"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2211         else if (!strcmp(res->value, "l4-src-only"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2213         else if (!strcmp(res->value, "l4-dst-only"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2215         else if (!strcmp(res->value, "l2-src-only"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2217         else if (!strcmp(res->value, "l2-dst-only"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2219         else if (!strcmp(res->value, "l2tpv3"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2221         else if (!strcmp(res->value, "esp"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2223         else if (!strcmp(res->value, "ah"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2225         else if (!strcmp(res->value, "pfcp"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2227         else if (!strcmp(res->value, "pppoe"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2229         else if (!strcmp(res->value, "gtpu"))
2230                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2231         else if (!strcmp(res->value, "ecpri"))
2232                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2233         else if (!strcmp(res->value, "mpls"))
2234                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2235         else if (!strcmp(res->value, "ipv4-chksum"))
2236                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2237         else if (!strcmp(res->value, "none"))
2238                 rss_conf.rss_hf = 0;
2239         else if (!strcmp(res->value, "level-default")) {
2240                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2241                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2242         } else if (!strcmp(res->value, "level-outer")) {
2243                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2244                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2245         } else if (!strcmp(res->value, "level-inner")) {
2246                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2247                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2248         } else if (!strcmp(res->value, "default"))
2249                 use_default = 1;
2250         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2251                                                 atoi(res->value) < 64)
2252                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2253         else {
2254                 fprintf(stderr, "Unknown parameter\n");
2255                 return;
2256         }
2257         rss_conf.rss_key = NULL;
2258         /* Update global configuration for RSS types. */
2259         RTE_ETH_FOREACH_DEV(i) {
2260                 struct rte_eth_rss_conf local_rss_conf;
2261
2262                 ret = eth_dev_info_get_print_err(i, &dev_info);
2263                 if (ret != 0)
2264                         return;
2265
2266                 if (use_default)
2267                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2268
2269                 local_rss_conf = rss_conf;
2270                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2271                         dev_info.flow_type_rss_offloads;
2272                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2273                         printf("Port %u modified RSS hash function based on hardware support,"
2274                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2275                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2276                 }
2277                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2278                 if (diag < 0) {
2279                         all_updated = 0;
2280                         fprintf(stderr,
2281                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2282                                 i, -diag, strerror(-diag));
2283                 }
2284         }
2285         if (all_updated && !use_default) {
2286                 rss_hf = rss_conf.rss_hf;
2287                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2288         }
2289 }
2290
2291 cmdline_parse_token_string_t cmd_config_rss_port =
2292         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2293 cmdline_parse_token_string_t cmd_config_rss_keyword =
2294         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2295 cmdline_parse_token_string_t cmd_config_rss_all =
2296         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2297 cmdline_parse_token_string_t cmd_config_rss_name =
2298         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2299 cmdline_parse_token_string_t cmd_config_rss_value =
2300         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2301
2302 cmdline_parse_inst_t cmd_config_rss = {
2303         .f = cmd_config_rss_parsed,
2304         .data = NULL,
2305         .help_str = "port config all rss "
2306                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2307                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2308                 "level-outer|level-inner|ipv4-chksum|<flowtype_id>",
2309         .tokens = {
2310                 (void *)&cmd_config_rss_port,
2311                 (void *)&cmd_config_rss_keyword,
2312                 (void *)&cmd_config_rss_all,
2313                 (void *)&cmd_config_rss_name,
2314                 (void *)&cmd_config_rss_value,
2315                 NULL,
2316         },
2317 };
2318
2319 /* *** configure rss hash key *** */
2320 struct cmd_config_rss_hash_key {
2321         cmdline_fixed_string_t port;
2322         cmdline_fixed_string_t config;
2323         portid_t port_id;
2324         cmdline_fixed_string_t rss_hash_key;
2325         cmdline_fixed_string_t rss_type;
2326         cmdline_fixed_string_t key;
2327 };
2328
2329 static uint8_t
2330 hexa_digit_to_value(char hexa_digit)
2331 {
2332         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2333                 return (uint8_t) (hexa_digit - '0');
2334         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2335                 return (uint8_t) ((hexa_digit - 'a') + 10);
2336         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2337                 return (uint8_t) ((hexa_digit - 'A') + 10);
2338         /* Invalid hexa digit */
2339         return 0xFF;
2340 }
2341
2342 static uint8_t
2343 parse_and_check_key_hexa_digit(char *key, int idx)
2344 {
2345         uint8_t hexa_v;
2346
2347         hexa_v = hexa_digit_to_value(key[idx]);
2348         if (hexa_v == 0xFF)
2349                 fprintf(stderr,
2350                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2351                         key[idx], idx);
2352         return hexa_v;
2353 }
2354
2355 static void
2356 cmd_config_rss_hash_key_parsed(void *parsed_result,
2357                                __rte_unused struct cmdline *cl,
2358                                __rte_unused void *data)
2359 {
2360         struct cmd_config_rss_hash_key *res = parsed_result;
2361         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2362         uint8_t xdgt0;
2363         uint8_t xdgt1;
2364         int i;
2365         struct rte_eth_dev_info dev_info;
2366         uint8_t hash_key_size;
2367         uint32_t key_len;
2368         int ret;
2369
2370         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2371         if (ret != 0)
2372                 return;
2373
2374         if (dev_info.hash_key_size > 0 &&
2375                         dev_info.hash_key_size <= sizeof(hash_key))
2376                 hash_key_size = dev_info.hash_key_size;
2377         else {
2378                 fprintf(stderr,
2379                         "dev_info did not provide a valid hash key size\n");
2380                 return;
2381         }
2382         /* Check the length of the RSS hash key */
2383         key_len = strlen(res->key);
2384         if (key_len != (hash_key_size * 2)) {
2385                 fprintf(stderr,
2386                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2387                         (int)key_len, hash_key_size * 2);
2388                 return;
2389         }
2390         /* Translate RSS hash key into binary representation */
2391         for (i = 0; i < hash_key_size; i++) {
2392                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2393                 if (xdgt0 == 0xFF)
2394                         return;
2395                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2396                 if (xdgt1 == 0xFF)
2397                         return;
2398                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2399         }
2400         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2401                         hash_key_size);
2402 }
2403
2404 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2405         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2406 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2407         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2408                                  "config");
2409 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2410         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2411                                  RTE_UINT16);
2412 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2413         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2414                                  rss_hash_key, "rss-hash-key");
2415 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2416         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2417                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2418                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2419                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2420                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2421                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2422                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2423                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2424 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2425         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2426
2427 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2428         .f = cmd_config_rss_hash_key_parsed,
2429         .data = NULL,
2430         .help_str = "port config <port_id> rss-hash-key "
2431                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2432                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2433                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2434                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2435                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2436                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2437                 "<string of hex digits (variable length, NIC dependent)>",
2438         .tokens = {
2439                 (void *)&cmd_config_rss_hash_key_port,
2440                 (void *)&cmd_config_rss_hash_key_config,
2441                 (void *)&cmd_config_rss_hash_key_port_id,
2442                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2443                 (void *)&cmd_config_rss_hash_key_rss_type,
2444                 (void *)&cmd_config_rss_hash_key_value,
2445                 NULL,
2446         },
2447 };
2448
2449 /* *** cleanup txq mbufs *** */
2450 struct cmd_cleanup_txq_mbufs_result {
2451         cmdline_fixed_string_t port;
2452         cmdline_fixed_string_t keyword;
2453         cmdline_fixed_string_t name;
2454         uint16_t port_id;
2455         uint16_t queue_id;
2456         uint32_t free_cnt;
2457 };
2458
2459 static void
2460 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2461                              __rte_unused struct cmdline *cl,
2462                              __rte_unused void *data)
2463 {
2464         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2465         uint16_t port_id = res->port_id;
2466         uint16_t queue_id = res->queue_id;
2467         uint32_t free_cnt = res->free_cnt;
2468         struct rte_eth_txq_info qinfo;
2469         int ret;
2470
2471         if (test_done == 0) {
2472                 fprintf(stderr, "Please stop forwarding first\n");
2473                 return;
2474         }
2475
2476         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2477                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2478                         port_id, queue_id);
2479                 return;
2480         }
2481
2482         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2483                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2484                 return;
2485         }
2486
2487         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2488         if (ret < 0) {
2489                 fprintf(stderr,
2490                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2491                         port_id, queue_id, strerror(-ret), ret);
2492                 return;
2493         }
2494
2495         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2496                port_id, queue_id, ret);
2497 }
2498
2499 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2500         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2501                                  "port");
2502 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2503         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2504                                  "cleanup");
2505 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2506         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2507                               RTE_UINT16);
2508 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2509         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2510                                  "txq");
2511 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2512         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2513                               RTE_UINT16);
2514 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2515         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2516                               RTE_UINT32);
2517
2518 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2519         .f = cmd_cleanup_txq_mbufs_parsed,
2520         .data = NULL,
2521         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2522         .tokens = {
2523                 (void *)&cmd_cleanup_txq_mbufs_port,
2524                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2525                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2526                 (void *)&cmd_cleanup_txq_mbufs_txq,
2527                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2528                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2529                 NULL,
2530         },
2531 };
2532
2533 /* *** configure port rxq/txq ring size *** */
2534 struct cmd_config_rxtx_ring_size {
2535         cmdline_fixed_string_t port;
2536         cmdline_fixed_string_t config;
2537         portid_t portid;
2538         cmdline_fixed_string_t rxtxq;
2539         uint16_t qid;
2540         cmdline_fixed_string_t rsize;
2541         uint16_t size;
2542 };
2543
2544 static void
2545 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2546                                  __rte_unused struct cmdline *cl,
2547                                  __rte_unused void *data)
2548 {
2549         struct cmd_config_rxtx_ring_size *res = parsed_result;
2550         struct rte_port *port;
2551         uint8_t isrx;
2552
2553         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2554                 return;
2555
2556         if (res->portid == (portid_t)RTE_PORT_ALL) {
2557                 fprintf(stderr, "Invalid port id\n");
2558                 return;
2559         }
2560
2561         port = &ports[res->portid];
2562
2563         if (!strcmp(res->rxtxq, "rxq"))
2564                 isrx = 1;
2565         else if (!strcmp(res->rxtxq, "txq"))
2566                 isrx = 0;
2567         else {
2568                 fprintf(stderr, "Unknown parameter\n");
2569                 return;
2570         }
2571
2572         if (isrx && rx_queue_id_is_invalid(res->qid))
2573                 return;
2574         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2575                 return;
2576
2577         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2578                 fprintf(stderr,
2579                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2580                         rx_free_thresh);
2581                 return;
2582         }
2583
2584         if (isrx)
2585                 port->nb_rx_desc[res->qid] = res->size;
2586         else
2587                 port->nb_tx_desc[res->qid] = res->size;
2588
2589         cmd_reconfig_device_queue(res->portid, 0, 1);
2590 }
2591
2592 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2593         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2594                                  port, "port");
2595 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2596         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2597                                  config, "config");
2598 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2599         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2600                                  portid, RTE_UINT16);
2601 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2602         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2603                                  rxtxq, "rxq#txq");
2604 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2605         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606                               qid, RTE_UINT16);
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609                                  rsize, "ring_size");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2611         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612                               size, RTE_UINT16);
2613
2614 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2615         .f = cmd_config_rxtx_ring_size_parsed,
2616         .data = NULL,
2617         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2618         .tokens = {
2619                 (void *)&cmd_config_rxtx_ring_size_port,
2620                 (void *)&cmd_config_rxtx_ring_size_config,
2621                 (void *)&cmd_config_rxtx_ring_size_portid,
2622                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2623                 (void *)&cmd_config_rxtx_ring_size_qid,
2624                 (void *)&cmd_config_rxtx_ring_size_rsize,
2625                 (void *)&cmd_config_rxtx_ring_size_size,
2626                 NULL,
2627         },
2628 };
2629
2630 /* *** configure port rxq/txq start/stop *** */
2631 struct cmd_config_rxtx_queue {
2632         cmdline_fixed_string_t port;
2633         portid_t portid;
2634         cmdline_fixed_string_t rxtxq;
2635         uint16_t qid;
2636         cmdline_fixed_string_t opname;
2637 };
2638
2639 static void
2640 cmd_config_rxtx_queue_parsed(void *parsed_result,
2641                         __rte_unused struct cmdline *cl,
2642                         __rte_unused void *data)
2643 {
2644         struct cmd_config_rxtx_queue *res = parsed_result;
2645         uint8_t isrx;
2646         uint8_t isstart;
2647         int ret = 0;
2648
2649         if (test_done == 0) {
2650                 fprintf(stderr, "Please stop forwarding first\n");
2651                 return;
2652         }
2653
2654         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2655                 return;
2656
2657         if (port_is_started(res->portid) != 1) {
2658                 fprintf(stderr, "Please start port %u first\n", res->portid);
2659                 return;
2660         }
2661
2662         if (!strcmp(res->rxtxq, "rxq"))
2663                 isrx = 1;
2664         else if (!strcmp(res->rxtxq, "txq"))
2665                 isrx = 0;
2666         else {
2667                 fprintf(stderr, "Unknown parameter\n");
2668                 return;
2669         }
2670
2671         if (isrx && rx_queue_id_is_invalid(res->qid))
2672                 return;
2673         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2674                 return;
2675
2676         if (!strcmp(res->opname, "start"))
2677                 isstart = 1;
2678         else if (!strcmp(res->opname, "stop"))
2679                 isstart = 0;
2680         else {
2681                 fprintf(stderr, "Unknown parameter\n");
2682                 return;
2683         }
2684
2685         if (isstart && isrx)
2686                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2687         else if (!isstart && isrx)
2688                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2689         else if (isstart && !isrx)
2690                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2691         else
2692                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2693
2694         if (ret == -ENOTSUP)
2695                 fprintf(stderr, "Function not supported in PMD driver\n");
2696 }
2697
2698 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2699         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2700 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2701         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2702 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2703         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2704 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2705         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2706 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2707         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2708                                                 "start#stop");
2709
2710 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2711         .f = cmd_config_rxtx_queue_parsed,
2712         .data = NULL,
2713         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2714         .tokens = {
2715                 (void *)&cmd_config_rxtx_queue_port,
2716                 (void *)&cmd_config_rxtx_queue_portid,
2717                 (void *)&cmd_config_rxtx_queue_rxtxq,
2718                 (void *)&cmd_config_rxtx_queue_qid,
2719                 (void *)&cmd_config_rxtx_queue_opname,
2720                 NULL,
2721         },
2722 };
2723
2724 /* *** configure port rxq/txq deferred start on/off *** */
2725 struct cmd_config_deferred_start_rxtx_queue {
2726         cmdline_fixed_string_t port;
2727         portid_t port_id;
2728         cmdline_fixed_string_t rxtxq;
2729         uint16_t qid;
2730         cmdline_fixed_string_t opname;
2731         cmdline_fixed_string_t state;
2732 };
2733
2734 static void
2735 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2736                         __rte_unused struct cmdline *cl,
2737                         __rte_unused void *data)
2738 {
2739         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2740         struct rte_port *port;
2741         uint8_t isrx;
2742         uint8_t ison;
2743         uint8_t needreconfig = 0;
2744
2745         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2746                 return;
2747
2748         if (port_is_started(res->port_id) != 0) {
2749                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2750                 return;
2751         }
2752
2753         port = &ports[res->port_id];
2754
2755         isrx = !strcmp(res->rxtxq, "rxq");
2756
2757         if (isrx && rx_queue_id_is_invalid(res->qid))
2758                 return;
2759         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2760                 return;
2761
2762         ison = !strcmp(res->state, "on");
2763
2764         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2765                 port->rx_conf[res->qid].rx_deferred_start = ison;
2766                 needreconfig = 1;
2767         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2768                 port->tx_conf[res->qid].tx_deferred_start = ison;
2769                 needreconfig = 1;
2770         }
2771
2772         if (needreconfig)
2773                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2774 }
2775
2776 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2777         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2778                                                 port, "port");
2779 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2780         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2781                                                 port_id, RTE_UINT16);
2782 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2783         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2784                                                 rxtxq, "rxq#txq");
2785 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2786         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2787                                                 qid, RTE_UINT16);
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2789         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790                                                 opname, "deferred_start");
2791 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2792         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793                                                 state, "on#off");
2794
2795 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2796         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2797         .data = NULL,
2798         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2799         .tokens = {
2800                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2801                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2802                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2803                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2804                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2805                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2806                 NULL,
2807         },
2808 };
2809
2810 /* *** configure port rxq/txq setup *** */
2811 struct cmd_setup_rxtx_queue {
2812         cmdline_fixed_string_t port;
2813         portid_t portid;
2814         cmdline_fixed_string_t rxtxq;
2815         uint16_t qid;
2816         cmdline_fixed_string_t setup;
2817 };
2818
2819 /* Common CLI fields for queue setup */
2820 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2821         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2822 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2823         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2824 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2825         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2826 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2827         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2828 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2829         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2830
2831 static void
2832 cmd_setup_rxtx_queue_parsed(
2833         void *parsed_result,
2834         __rte_unused struct cmdline *cl,
2835         __rte_unused void *data)
2836 {
2837         struct cmd_setup_rxtx_queue *res = parsed_result;
2838         struct rte_port *port;
2839         struct rte_mempool *mp;
2840         unsigned int socket_id;
2841         uint8_t isrx = 0;
2842         int ret;
2843
2844         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2845                 return;
2846
2847         if (res->portid == (portid_t)RTE_PORT_ALL) {
2848                 fprintf(stderr, "Invalid port id\n");
2849                 return;
2850         }
2851
2852         if (!strcmp(res->rxtxq, "rxq"))
2853                 isrx = 1;
2854         else if (!strcmp(res->rxtxq, "txq"))
2855                 isrx = 0;
2856         else {
2857                 fprintf(stderr, "Unknown parameter\n");
2858                 return;
2859         }
2860
2861         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2862                 fprintf(stderr, "Invalid rx queue\n");
2863                 return;
2864         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2865                 fprintf(stderr, "Invalid tx queue\n");
2866                 return;
2867         }
2868
2869         port = &ports[res->portid];
2870         if (isrx) {
2871                 socket_id = rxring_numa[res->portid];
2872                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2873                         socket_id = port->socket_id;
2874
2875                 mp = mbuf_pool_find(socket_id, 0);
2876                 if (mp == NULL) {
2877                         fprintf(stderr,
2878                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2879                                 rxring_numa[res->portid]);
2880                         return;
2881                 }
2882                 ret = rx_queue_setup(res->portid,
2883                                      res->qid,
2884                                      port->nb_rx_desc[res->qid],
2885                                      socket_id,
2886                                      &port->rx_conf[res->qid],
2887                                      mp);
2888                 if (ret)
2889                         fprintf(stderr, "Failed to setup RX queue\n");
2890         } else {
2891                 socket_id = txring_numa[res->portid];
2892                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2893                         socket_id = port->socket_id;
2894
2895                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2896                         fprintf(stderr,
2897                                 "Failed to setup TX queue: not enough descriptors\n");
2898                         return;
2899                 }
2900                 ret = rte_eth_tx_queue_setup(res->portid,
2901                                              res->qid,
2902                                              port->nb_tx_desc[res->qid],
2903                                              socket_id,
2904                                              &port->tx_conf[res->qid]);
2905                 if (ret)
2906                         fprintf(stderr, "Failed to setup TX queue\n");
2907         }
2908 }
2909
2910 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2911         .f = cmd_setup_rxtx_queue_parsed,
2912         .data = NULL,
2913         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2914         .tokens = {
2915                 (void *)&cmd_setup_rxtx_queue_port,
2916                 (void *)&cmd_setup_rxtx_queue_portid,
2917                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2918                 (void *)&cmd_setup_rxtx_queue_qid,
2919                 (void *)&cmd_setup_rxtx_queue_setup,
2920                 NULL,
2921         },
2922 };
2923
2924
2925 /* *** Configure RSS RETA *** */
2926 struct cmd_config_rss_reta {
2927         cmdline_fixed_string_t port;
2928         cmdline_fixed_string_t keyword;
2929         portid_t port_id;
2930         cmdline_fixed_string_t name;
2931         cmdline_fixed_string_t list_name;
2932         cmdline_fixed_string_t list_of_items;
2933 };
2934
2935 static int
2936 parse_reta_config(const char *str,
2937                   struct rte_eth_rss_reta_entry64 *reta_conf,
2938                   uint16_t nb_entries)
2939 {
2940         int i;
2941         unsigned size;
2942         uint16_t hash_index, idx, shift;
2943         uint16_t nb_queue;
2944         char s[256];
2945         const char *p, *p0 = str;
2946         char *end;
2947         enum fieldnames {
2948                 FLD_HASH_INDEX = 0,
2949                 FLD_QUEUE,
2950                 _NUM_FLD
2951         };
2952         unsigned long int_fld[_NUM_FLD];
2953         char *str_fld[_NUM_FLD];
2954
2955         while ((p = strchr(p0,'(')) != NULL) {
2956                 ++p;
2957                 if((p0 = strchr(p,')')) == NULL)
2958                         return -1;
2959
2960                 size = p0 - p;
2961                 if(size >= sizeof(s))
2962                         return -1;
2963
2964                 snprintf(s, sizeof(s), "%.*s", size, p);
2965                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2966                         return -1;
2967                 for (i = 0; i < _NUM_FLD; i++) {
2968                         errno = 0;
2969                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2970                         if (errno != 0 || end == str_fld[i] ||
2971                                         int_fld[i] > 65535)
2972                                 return -1;
2973                 }
2974
2975                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2976                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2977
2978                 if (hash_index >= nb_entries) {
2979                         fprintf(stderr, "Invalid RETA hash index=%d\n",
2980                                 hash_index);
2981                         return -1;
2982                 }
2983
2984                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
2985                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
2986                 reta_conf[idx].mask |= (1ULL << shift);
2987                 reta_conf[idx].reta[shift] = nb_queue;
2988         }
2989
2990         return 0;
2991 }
2992
2993 static void
2994 cmd_set_rss_reta_parsed(void *parsed_result,
2995                         __rte_unused struct cmdline *cl,
2996                         __rte_unused void *data)
2997 {
2998         int ret;
2999         struct rte_eth_dev_info dev_info;
3000         struct rte_eth_rss_reta_entry64 reta_conf[8];
3001         struct cmd_config_rss_reta *res = parsed_result;
3002
3003         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3004         if (ret != 0)
3005                 return;
3006
3007         if (dev_info.reta_size == 0) {
3008                 fprintf(stderr,
3009                         "Redirection table size is 0 which is invalid for RSS\n");
3010                 return;
3011         } else
3012                 printf("The reta size of port %d is %u\n",
3013                         res->port_id, dev_info.reta_size);
3014         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3015                 fprintf(stderr,
3016                         "Currently do not support more than %u entries of redirection table\n",
3017                         RTE_ETH_RSS_RETA_SIZE_512);
3018                 return;
3019         }
3020
3021         memset(reta_conf, 0, sizeof(reta_conf));
3022         if (!strcmp(res->list_name, "reta")) {
3023                 if (parse_reta_config(res->list_of_items, reta_conf,
3024                                                 dev_info.reta_size)) {
3025                         fprintf(stderr,
3026                                 "Invalid RSS Redirection Table config entered\n");
3027                         return;
3028                 }
3029                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3030                                 reta_conf, dev_info.reta_size);
3031                 if (ret != 0)
3032                         fprintf(stderr,
3033                                 "Bad redirection table parameter, return code = %d\n",
3034                                 ret);
3035         }
3036 }
3037
3038 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3039         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3040 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3041         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3042 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3043         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3044 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3045         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3046 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3047         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3048 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3049         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3050                                  NULL);
3051 cmdline_parse_inst_t cmd_config_rss_reta = {
3052         .f = cmd_set_rss_reta_parsed,
3053         .data = NULL,
3054         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3055         .tokens = {
3056                 (void *)&cmd_config_rss_reta_port,
3057                 (void *)&cmd_config_rss_reta_keyword,
3058                 (void *)&cmd_config_rss_reta_port_id,
3059                 (void *)&cmd_config_rss_reta_name,
3060                 (void *)&cmd_config_rss_reta_list_name,
3061                 (void *)&cmd_config_rss_reta_list_of_items,
3062                 NULL,
3063         },
3064 };
3065
3066 /* *** SHOW PORT RETA INFO *** */
3067 struct cmd_showport_reta {
3068         cmdline_fixed_string_t show;
3069         cmdline_fixed_string_t port;
3070         portid_t port_id;
3071         cmdline_fixed_string_t rss;
3072         cmdline_fixed_string_t reta;
3073         uint16_t size;
3074         cmdline_fixed_string_t list_of_items;
3075 };
3076
3077 static int
3078 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3079                            uint16_t nb_entries,
3080                            char *str)
3081 {
3082         uint32_t size;
3083         const char *p, *p0 = str;
3084         char s[256];
3085         char *end;
3086         char *str_fld[8];
3087         uint16_t i;
3088         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3089                         RTE_ETH_RETA_GROUP_SIZE;
3090         int ret;
3091
3092         p = strchr(p0, '(');
3093         if (p == NULL)
3094                 return -1;
3095         p++;
3096         p0 = strchr(p, ')');
3097         if (p0 == NULL)
3098                 return -1;
3099         size = p0 - p;
3100         if (size >= sizeof(s)) {
3101                 fprintf(stderr,
3102                         "The string size exceeds the internal buffer size\n");
3103                 return -1;
3104         }
3105         snprintf(s, sizeof(s), "%.*s", size, p);
3106         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3107         if (ret <= 0 || ret != num) {
3108                 fprintf(stderr,
3109                         "The bits of masks do not match the number of reta entries: %u\n",
3110                         num);
3111                 return -1;
3112         }
3113         for (i = 0; i < ret; i++)
3114                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3115
3116         return 0;
3117 }
3118
3119 static void
3120 cmd_showport_reta_parsed(void *parsed_result,
3121                          __rte_unused struct cmdline *cl,
3122                          __rte_unused void *data)
3123 {
3124         struct cmd_showport_reta *res = parsed_result;
3125         struct rte_eth_rss_reta_entry64 reta_conf[8];
3126         struct rte_eth_dev_info dev_info;
3127         uint16_t max_reta_size;
3128         int ret;
3129
3130         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3131         if (ret != 0)
3132                 return;
3133
3134         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3135         if (res->size == 0 || res->size > max_reta_size) {
3136                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3137                         res->size, max_reta_size);
3138                 return;
3139         }
3140
3141         memset(reta_conf, 0, sizeof(reta_conf));
3142         if (showport_parse_reta_config(reta_conf, res->size,
3143                                 res->list_of_items) < 0) {
3144                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3145                         res->list_of_items);
3146                 return;
3147         }
3148         port_rss_reta_info(res->port_id, reta_conf, res->size);
3149 }
3150
3151 cmdline_parse_token_string_t cmd_showport_reta_show =
3152         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3153 cmdline_parse_token_string_t cmd_showport_reta_port =
3154         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3155 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3156         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3157 cmdline_parse_token_string_t cmd_showport_reta_rss =
3158         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3159 cmdline_parse_token_string_t cmd_showport_reta_reta =
3160         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3161 cmdline_parse_token_num_t cmd_showport_reta_size =
3162         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3163 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3164         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3165                                         list_of_items, NULL);
3166
3167 cmdline_parse_inst_t cmd_showport_reta = {
3168         .f = cmd_showport_reta_parsed,
3169         .data = NULL,
3170         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3171         .tokens = {
3172                 (void *)&cmd_showport_reta_show,
3173                 (void *)&cmd_showport_reta_port,
3174                 (void *)&cmd_showport_reta_port_id,
3175                 (void *)&cmd_showport_reta_rss,
3176                 (void *)&cmd_showport_reta_reta,
3177                 (void *)&cmd_showport_reta_size,
3178                 (void *)&cmd_showport_reta_list_of_items,
3179                 NULL,
3180         },
3181 };
3182
3183 /* *** Show RSS hash configuration *** */
3184 struct cmd_showport_rss_hash {
3185         cmdline_fixed_string_t show;
3186         cmdline_fixed_string_t port;
3187         portid_t port_id;
3188         cmdline_fixed_string_t rss_hash;
3189         cmdline_fixed_string_t rss_type;
3190         cmdline_fixed_string_t key; /* optional argument */
3191 };
3192
3193 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3194                                 __rte_unused struct cmdline *cl,
3195                                 void *show_rss_key)
3196 {
3197         struct cmd_showport_rss_hash *res = parsed_result;
3198
3199         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3200 }
3201
3202 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3203         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3204 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3205         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3206 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3207         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3208                                  RTE_UINT16);
3209 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3210         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3211                                  "rss-hash");
3212 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3213         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3214
3215 cmdline_parse_inst_t cmd_showport_rss_hash = {
3216         .f = cmd_showport_rss_hash_parsed,
3217         .data = NULL,
3218         .help_str = "show port <port_id> rss-hash",
3219         .tokens = {
3220                 (void *)&cmd_showport_rss_hash_show,
3221                 (void *)&cmd_showport_rss_hash_port,
3222                 (void *)&cmd_showport_rss_hash_port_id,
3223                 (void *)&cmd_showport_rss_hash_rss_hash,
3224                 NULL,
3225         },
3226 };
3227
3228 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3229         .f = cmd_showport_rss_hash_parsed,
3230         .data = (void *)1,
3231         .help_str = "show port <port_id> rss-hash key",
3232         .tokens = {
3233                 (void *)&cmd_showport_rss_hash_show,
3234                 (void *)&cmd_showport_rss_hash_port,
3235                 (void *)&cmd_showport_rss_hash_port_id,
3236                 (void *)&cmd_showport_rss_hash_rss_hash,
3237                 (void *)&cmd_showport_rss_hash_rss_key,
3238                 NULL,
3239         },
3240 };
3241
3242 /* *** Configure DCB *** */
3243 struct cmd_config_dcb {
3244         cmdline_fixed_string_t port;
3245         cmdline_fixed_string_t config;
3246         portid_t port_id;
3247         cmdline_fixed_string_t dcb;
3248         cmdline_fixed_string_t vt;
3249         cmdline_fixed_string_t vt_en;
3250         uint8_t num_tcs;
3251         cmdline_fixed_string_t pfc;
3252         cmdline_fixed_string_t pfc_en;
3253 };
3254
3255 static void
3256 cmd_config_dcb_parsed(void *parsed_result,
3257                         __rte_unused struct cmdline *cl,
3258                         __rte_unused void *data)
3259 {
3260         struct cmd_config_dcb *res = parsed_result;
3261         struct rte_eth_dcb_info dcb_info;
3262         portid_t port_id = res->port_id;
3263         struct rte_port *port;
3264         uint8_t pfc_en;
3265         int ret;
3266
3267         port = &ports[port_id];
3268         /** Check if the port is not started **/
3269         if (port->port_status != RTE_PORT_STOPPED) {
3270                 fprintf(stderr, "Please stop port %d first\n", port_id);
3271                 return;
3272         }
3273
3274         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3275                 fprintf(stderr,
3276                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3277                 return;
3278         }
3279
3280         if (nb_fwd_lcores < res->num_tcs) {
3281                 fprintf(stderr,
3282                         "nb_cores shouldn't be less than number of TCs.\n");
3283                 return;
3284         }
3285
3286         /* Check whether the port supports the report of DCB info. */
3287         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3288         if (ret == -ENOTSUP) {
3289                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3290                 return;
3291         }
3292
3293         if (!strncmp(res->pfc_en, "on", 2))
3294                 pfc_en = 1;
3295         else
3296                 pfc_en = 0;
3297
3298         /* DCB in VT mode */
3299         if (!strncmp(res->vt_en, "on", 2))
3300                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3301                                 (enum rte_eth_nb_tcs)res->num_tcs,
3302                                 pfc_en);
3303         else
3304                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3305                                 (enum rte_eth_nb_tcs)res->num_tcs,
3306                                 pfc_en);
3307         if (ret != 0) {
3308                 fprintf(stderr, "Cannot initialize network ports.\n");
3309                 return;
3310         }
3311
3312         fwd_config_setup();
3313
3314         cmd_reconfig_device_queue(port_id, 1, 1);
3315 }
3316
3317 cmdline_parse_token_string_t cmd_config_dcb_port =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3319 cmdline_parse_token_string_t cmd_config_dcb_config =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3321 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3322         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3323 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3325 cmdline_parse_token_string_t cmd_config_dcb_vt =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3327 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3328         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3329 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3330         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3331 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3333 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3334         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3335
3336 cmdline_parse_inst_t cmd_config_dcb = {
3337         .f = cmd_config_dcb_parsed,
3338         .data = NULL,
3339         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3340         .tokens = {
3341                 (void *)&cmd_config_dcb_port,
3342                 (void *)&cmd_config_dcb_config,
3343                 (void *)&cmd_config_dcb_port_id,
3344                 (void *)&cmd_config_dcb_dcb,
3345                 (void *)&cmd_config_dcb_vt,
3346                 (void *)&cmd_config_dcb_vt_en,
3347                 (void *)&cmd_config_dcb_num_tcs,
3348                 (void *)&cmd_config_dcb_pfc,
3349                 (void *)&cmd_config_dcb_pfc_en,
3350                 NULL,
3351         },
3352 };
3353
3354 /* *** configure number of packets per burst *** */
3355 struct cmd_config_burst {
3356         cmdline_fixed_string_t port;
3357         cmdline_fixed_string_t keyword;
3358         cmdline_fixed_string_t all;
3359         cmdline_fixed_string_t name;
3360         uint16_t value;
3361 };
3362
3363 static void
3364 cmd_config_burst_parsed(void *parsed_result,
3365                         __rte_unused struct cmdline *cl,
3366                         __rte_unused void *data)
3367 {
3368         struct cmd_config_burst *res = parsed_result;
3369         struct rte_eth_dev_info dev_info;
3370         uint16_t rec_nb_pkts;
3371         int ret;
3372
3373         if (!all_ports_stopped()) {
3374                 fprintf(stderr, "Please stop all ports first\n");
3375                 return;
3376         }
3377
3378         if (!strcmp(res->name, "burst")) {
3379                 if (res->value == 0) {
3380                         /* If user gives a value of zero, query the PMD for
3381                          * its recommended Rx burst size. Testpmd uses a single
3382                          * size for all ports, so assume all ports are the same
3383                          * NIC model and use the values from Port 0.
3384                          */
3385                         ret = eth_dev_info_get_print_err(0, &dev_info);
3386                         if (ret != 0)
3387                                 return;
3388
3389                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3390
3391                         if (rec_nb_pkts == 0) {
3392                                 printf("PMD does not recommend a burst size.\n"
3393                                         "User provided value must be between"
3394                                         " 1 and %d\n", MAX_PKT_BURST);
3395                                 return;
3396                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3397                                 printf("PMD recommended burst size of %d"
3398                                         " exceeds maximum value of %d\n",
3399                                         rec_nb_pkts, MAX_PKT_BURST);
3400                                 return;
3401                         }
3402                         printf("Using PMD-provided burst value of %d\n",
3403                                 rec_nb_pkts);
3404                         nb_pkt_per_burst = rec_nb_pkts;
3405                 } else if (res->value > MAX_PKT_BURST) {
3406                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3407                                 MAX_PKT_BURST);
3408                         return;
3409                 } else
3410                         nb_pkt_per_burst = res->value;
3411         } else {
3412                 fprintf(stderr, "Unknown parameter\n");
3413                 return;
3414         }
3415
3416         init_port_config();
3417
3418         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3419 }
3420
3421 cmdline_parse_token_string_t cmd_config_burst_port =
3422         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3423 cmdline_parse_token_string_t cmd_config_burst_keyword =
3424         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3425 cmdline_parse_token_string_t cmd_config_burst_all =
3426         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3427 cmdline_parse_token_string_t cmd_config_burst_name =
3428         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3429 cmdline_parse_token_num_t cmd_config_burst_value =
3430         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3431
3432 cmdline_parse_inst_t cmd_config_burst = {
3433         .f = cmd_config_burst_parsed,
3434         .data = NULL,
3435         .help_str = "port config all burst <value>",
3436         .tokens = {
3437                 (void *)&cmd_config_burst_port,
3438                 (void *)&cmd_config_burst_keyword,
3439                 (void *)&cmd_config_burst_all,
3440                 (void *)&cmd_config_burst_name,
3441                 (void *)&cmd_config_burst_value,
3442                 NULL,
3443         },
3444 };
3445
3446 /* *** configure rx/tx queues *** */
3447 struct cmd_config_thresh {
3448         cmdline_fixed_string_t port;
3449         cmdline_fixed_string_t keyword;
3450         cmdline_fixed_string_t all;
3451         cmdline_fixed_string_t name;
3452         uint8_t value;
3453 };
3454
3455 static void
3456 cmd_config_thresh_parsed(void *parsed_result,
3457                         __rte_unused struct cmdline *cl,
3458                         __rte_unused void *data)
3459 {
3460         struct cmd_config_thresh *res = parsed_result;
3461
3462         if (!all_ports_stopped()) {
3463                 fprintf(stderr, "Please stop all ports first\n");
3464                 return;
3465         }
3466
3467         if (!strcmp(res->name, "txpt"))
3468                 tx_pthresh = res->value;
3469         else if(!strcmp(res->name, "txht"))
3470                 tx_hthresh = res->value;
3471         else if(!strcmp(res->name, "txwt"))
3472                 tx_wthresh = res->value;
3473         else if(!strcmp(res->name, "rxpt"))
3474                 rx_pthresh = res->value;
3475         else if(!strcmp(res->name, "rxht"))
3476                 rx_hthresh = res->value;
3477         else if(!strcmp(res->name, "rxwt"))
3478                 rx_wthresh = res->value;
3479         else {
3480                 fprintf(stderr, "Unknown parameter\n");
3481                 return;
3482         }
3483
3484         init_port_config();
3485
3486         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3487 }
3488
3489 cmdline_parse_token_string_t cmd_config_thresh_port =
3490         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3491 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3492         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3493 cmdline_parse_token_string_t cmd_config_thresh_all =
3494         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3495 cmdline_parse_token_string_t cmd_config_thresh_name =
3496         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3497                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3498 cmdline_parse_token_num_t cmd_config_thresh_value =
3499         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3500
3501 cmdline_parse_inst_t cmd_config_thresh = {
3502         .f = cmd_config_thresh_parsed,
3503         .data = NULL,
3504         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3505         .tokens = {
3506                 (void *)&cmd_config_thresh_port,
3507                 (void *)&cmd_config_thresh_keyword,
3508                 (void *)&cmd_config_thresh_all,
3509                 (void *)&cmd_config_thresh_name,
3510                 (void *)&cmd_config_thresh_value,
3511                 NULL,
3512         },
3513 };
3514
3515 /* *** configure free/rs threshold *** */
3516 struct cmd_config_threshold {
3517         cmdline_fixed_string_t port;
3518         cmdline_fixed_string_t keyword;
3519         cmdline_fixed_string_t all;
3520         cmdline_fixed_string_t name;
3521         uint16_t value;
3522 };
3523
3524 static void
3525 cmd_config_threshold_parsed(void *parsed_result,
3526                         __rte_unused struct cmdline *cl,
3527                         __rte_unused void *data)
3528 {
3529         struct cmd_config_threshold *res = parsed_result;
3530
3531         if (!all_ports_stopped()) {
3532                 fprintf(stderr, "Please stop all ports first\n");
3533                 return;
3534         }
3535
3536         if (!strcmp(res->name, "txfreet"))
3537                 tx_free_thresh = res->value;
3538         else if (!strcmp(res->name, "txrst"))
3539                 tx_rs_thresh = res->value;
3540         else if (!strcmp(res->name, "rxfreet"))
3541                 rx_free_thresh = res->value;
3542         else {
3543                 fprintf(stderr, "Unknown parameter\n");
3544                 return;
3545         }
3546
3547         init_port_config();
3548
3549         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3550 }
3551
3552 cmdline_parse_token_string_t cmd_config_threshold_port =
3553         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3554 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3555         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3556                                                                 "config");
3557 cmdline_parse_token_string_t cmd_config_threshold_all =
3558         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3559 cmdline_parse_token_string_t cmd_config_threshold_name =
3560         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3561                                                 "txfreet#txrst#rxfreet");
3562 cmdline_parse_token_num_t cmd_config_threshold_value =
3563         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3564
3565 cmdline_parse_inst_t cmd_config_threshold = {
3566         .f = cmd_config_threshold_parsed,
3567         .data = NULL,
3568         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3569         .tokens = {
3570                 (void *)&cmd_config_threshold_port,
3571                 (void *)&cmd_config_threshold_keyword,
3572                 (void *)&cmd_config_threshold_all,
3573                 (void *)&cmd_config_threshold_name,
3574                 (void *)&cmd_config_threshold_value,
3575                 NULL,
3576         },
3577 };
3578
3579 /* *** stop *** */
3580 struct cmd_stop_result {
3581         cmdline_fixed_string_t stop;
3582 };
3583
3584 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3585                             __rte_unused struct cmdline *cl,
3586                             __rte_unused void *data)
3587 {
3588         stop_packet_forwarding();
3589 }
3590
3591 cmdline_parse_token_string_t cmd_stop_stop =
3592         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3593
3594 cmdline_parse_inst_t cmd_stop = {
3595         .f = cmd_stop_parsed,
3596         .data = NULL,
3597         .help_str = "stop: Stop packet forwarding",
3598         .tokens = {
3599                 (void *)&cmd_stop_stop,
3600                 NULL,
3601         },
3602 };
3603
3604 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3605
3606 unsigned int
3607 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3608                 unsigned int *parsed_items, int check_unique_values)
3609 {
3610         unsigned int nb_item;
3611         unsigned int value;
3612         unsigned int i;
3613         unsigned int j;
3614         int value_ok;
3615         char c;
3616
3617         /*
3618          * First parse all items in the list and store their value.
3619          */
3620         value = 0;
3621         nb_item = 0;
3622         value_ok = 0;
3623         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3624                 c = str[i];
3625                 if ((c >= '0') && (c <= '9')) {
3626                         value = (unsigned int) (value * 10 + (c - '0'));
3627                         value_ok = 1;
3628                         continue;
3629                 }
3630                 if (c != ',') {
3631                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3632                         return 0;
3633                 }
3634                 if (! value_ok) {
3635                         fprintf(stderr, "No valid value before comma\n");
3636                         return 0;
3637                 }
3638                 if (nb_item < max_items) {
3639                         parsed_items[nb_item] = value;
3640                         value_ok = 0;
3641                         value = 0;
3642                 }
3643                 nb_item++;
3644         }
3645         if (nb_item >= max_items) {
3646                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3647                         item_name, nb_item + 1, max_items);
3648                 return 0;
3649         }
3650         parsed_items[nb_item++] = value;
3651         if (! check_unique_values)
3652                 return nb_item;
3653
3654         /*
3655          * Then, check that all values in the list are different.
3656          * No optimization here...
3657          */
3658         for (i = 0; i < nb_item; i++) {
3659                 for (j = i + 1; j < nb_item; j++) {
3660                         if (parsed_items[j] == parsed_items[i]) {
3661                                 fprintf(stderr,
3662                                         "duplicated %s %u at index %u and %u\n",
3663                                         item_name, parsed_items[i], i, j);
3664                                 return 0;
3665                         }
3666                 }
3667         }
3668         return nb_item;
3669 }
3670
3671 struct cmd_set_list_result {
3672         cmdline_fixed_string_t cmd_keyword;
3673         cmdline_fixed_string_t list_name;
3674         cmdline_fixed_string_t list_of_items;
3675 };
3676
3677 static void cmd_set_list_parsed(void *parsed_result,
3678                                 __rte_unused struct cmdline *cl,
3679                                 __rte_unused void *data)
3680 {
3681         struct cmd_set_list_result *res;
3682         union {
3683                 unsigned int lcorelist[RTE_MAX_LCORE];
3684                 unsigned int portlist[RTE_MAX_ETHPORTS];
3685         } parsed_items;
3686         unsigned int nb_item;
3687
3688         if (test_done == 0) {
3689                 fprintf(stderr, "Please stop forwarding first\n");
3690                 return;
3691         }
3692
3693         res = parsed_result;
3694         if (!strcmp(res->list_name, "corelist")) {
3695                 nb_item = parse_item_list(res->list_of_items, "core",
3696                                           RTE_MAX_LCORE,
3697                                           parsed_items.lcorelist, 1);
3698                 if (nb_item > 0) {
3699                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3700                         fwd_config_setup();
3701                 }
3702                 return;
3703         }
3704         if (!strcmp(res->list_name, "portlist")) {
3705                 nb_item = parse_item_list(res->list_of_items, "port",
3706                                           RTE_MAX_ETHPORTS,
3707                                           parsed_items.portlist, 1);
3708                 if (nb_item > 0) {
3709                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3710                         fwd_config_setup();
3711                 }
3712         }
3713 }
3714
3715 cmdline_parse_token_string_t cmd_set_list_keyword =
3716         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3717                                  "set");
3718 cmdline_parse_token_string_t cmd_set_list_name =
3719         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3720                                  "corelist#portlist");
3721 cmdline_parse_token_string_t cmd_set_list_of_items =
3722         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3723                                  NULL);
3724
3725 cmdline_parse_inst_t cmd_set_fwd_list = {
3726         .f = cmd_set_list_parsed,
3727         .data = NULL,
3728         .help_str = "set corelist|portlist <list0[,list1]*>",
3729         .tokens = {
3730                 (void *)&cmd_set_list_keyword,
3731                 (void *)&cmd_set_list_name,
3732                 (void *)&cmd_set_list_of_items,
3733                 NULL,
3734         },
3735 };
3736
3737 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3738
3739 struct cmd_setmask_result {
3740         cmdline_fixed_string_t set;
3741         cmdline_fixed_string_t mask;
3742         uint64_t hexavalue;
3743 };
3744
3745 static void cmd_set_mask_parsed(void *parsed_result,
3746                                 __rte_unused struct cmdline *cl,
3747                                 __rte_unused void *data)
3748 {
3749         struct cmd_setmask_result *res = parsed_result;
3750
3751         if (test_done == 0) {
3752                 fprintf(stderr, "Please stop forwarding first\n");
3753                 return;
3754         }
3755         if (!strcmp(res->mask, "coremask")) {
3756                 set_fwd_lcores_mask(res->hexavalue);
3757                 fwd_config_setup();
3758         } else if (!strcmp(res->mask, "portmask")) {
3759                 set_fwd_ports_mask(res->hexavalue);
3760                 fwd_config_setup();
3761         }
3762 }
3763
3764 cmdline_parse_token_string_t cmd_setmask_set =
3765         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3766 cmdline_parse_token_string_t cmd_setmask_mask =
3767         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3768                                  "coremask#portmask");
3769 cmdline_parse_token_num_t cmd_setmask_value =
3770         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3771
3772 cmdline_parse_inst_t cmd_set_fwd_mask = {
3773         .f = cmd_set_mask_parsed,
3774         .data = NULL,
3775         .help_str = "set coremask|portmask <hexadecimal value>",
3776         .tokens = {
3777                 (void *)&cmd_setmask_set,
3778                 (void *)&cmd_setmask_mask,
3779                 (void *)&cmd_setmask_value,
3780                 NULL,
3781         },
3782 };
3783
3784 /*
3785  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3786  */
3787 struct cmd_set_result {
3788         cmdline_fixed_string_t set;
3789         cmdline_fixed_string_t what;
3790         uint16_t value;
3791 };
3792
3793 static void cmd_set_parsed(void *parsed_result,
3794                            __rte_unused struct cmdline *cl,
3795                            __rte_unused void *data)
3796 {
3797         struct cmd_set_result *res = parsed_result;
3798         if (!strcmp(res->what, "nbport")) {
3799                 set_fwd_ports_number(res->value);
3800                 fwd_config_setup();
3801         } else if (!strcmp(res->what, "nbcore")) {
3802                 set_fwd_lcores_number(res->value);
3803                 fwd_config_setup();
3804         } else if (!strcmp(res->what, "burst"))
3805                 set_nb_pkt_per_burst(res->value);
3806         else if (!strcmp(res->what, "verbose"))
3807                 set_verbose_level(res->value);
3808 }
3809
3810 cmdline_parse_token_string_t cmd_set_set =
3811         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3812 cmdline_parse_token_string_t cmd_set_what =
3813         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3814                                  "nbport#nbcore#burst#verbose");
3815 cmdline_parse_token_num_t cmd_set_value =
3816         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3817
3818 cmdline_parse_inst_t cmd_set_numbers = {
3819         .f = cmd_set_parsed,
3820         .data = NULL,
3821         .help_str = "set nbport|nbcore|burst|verbose <value>",
3822         .tokens = {
3823                 (void *)&cmd_set_set,
3824                 (void *)&cmd_set_what,
3825                 (void *)&cmd_set_value,
3826                 NULL,
3827         },
3828 };
3829
3830 /* *** SET LOG LEVEL CONFIGURATION *** */
3831
3832 struct cmd_set_log_result {
3833         cmdline_fixed_string_t set;
3834         cmdline_fixed_string_t log;
3835         cmdline_fixed_string_t type;
3836         uint32_t level;
3837 };
3838
3839 static void
3840 cmd_set_log_parsed(void *parsed_result,
3841                    __rte_unused struct cmdline *cl,
3842                    __rte_unused void *data)
3843 {
3844         struct cmd_set_log_result *res;
3845         int ret;
3846
3847         res = parsed_result;
3848         if (!strcmp(res->type, "global"))
3849                 rte_log_set_global_level(res->level);
3850         else {
3851                 ret = rte_log_set_level_regexp(res->type, res->level);
3852                 if (ret < 0)
3853                         fprintf(stderr, "Unable to set log level\n");
3854         }
3855 }
3856
3857 cmdline_parse_token_string_t cmd_set_log_set =
3858         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3859 cmdline_parse_token_string_t cmd_set_log_log =
3860         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3861 cmdline_parse_token_string_t cmd_set_log_type =
3862         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3863 cmdline_parse_token_num_t cmd_set_log_level =
3864         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3865
3866 cmdline_parse_inst_t cmd_set_log = {
3867         .f = cmd_set_log_parsed,
3868         .data = NULL,
3869         .help_str = "set log global|<type> <level>",
3870         .tokens = {
3871                 (void *)&cmd_set_log_set,
3872                 (void *)&cmd_set_log_log,
3873                 (void *)&cmd_set_log_type,
3874                 (void *)&cmd_set_log_level,
3875                 NULL,
3876         },
3877 };
3878
3879 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3880
3881 struct cmd_set_rxoffs_result {
3882         cmdline_fixed_string_t cmd_keyword;
3883         cmdline_fixed_string_t rxoffs;
3884         cmdline_fixed_string_t seg_offsets;
3885 };
3886
3887 static void
3888 cmd_set_rxoffs_parsed(void *parsed_result,
3889                       __rte_unused struct cmdline *cl,
3890                       __rte_unused void *data)
3891 {
3892         struct cmd_set_rxoffs_result *res;
3893         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3894         unsigned int nb_segs;
3895
3896         res = parsed_result;
3897         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3898                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3899         if (nb_segs > 0)
3900                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3901         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3902 }
3903
3904 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3905         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3906                                  cmd_keyword, "set");
3907 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3908         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3909                                  rxoffs, "rxoffs");
3910 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3911         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3912                                  seg_offsets, NULL);
3913
3914 cmdline_parse_inst_t cmd_set_rxoffs = {
3915         .f = cmd_set_rxoffs_parsed,
3916         .data = NULL,
3917         .help_str = "set rxoffs <len0[,len1]*>",
3918         .tokens = {
3919                 (void *)&cmd_set_rxoffs_keyword,
3920                 (void *)&cmd_set_rxoffs_name,
3921                 (void *)&cmd_set_rxoffs_offsets,
3922                 NULL,
3923         },
3924 };
3925
3926 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3927
3928 struct cmd_set_rxpkts_result {
3929         cmdline_fixed_string_t cmd_keyword;
3930         cmdline_fixed_string_t rxpkts;
3931         cmdline_fixed_string_t seg_lengths;
3932 };
3933
3934 static void
3935 cmd_set_rxpkts_parsed(void *parsed_result,
3936                       __rte_unused struct cmdline *cl,
3937                       __rte_unused void *data)
3938 {
3939         struct cmd_set_rxpkts_result *res;
3940         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3941         unsigned int nb_segs;
3942
3943         res = parsed_result;
3944         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3945                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3946         if (nb_segs > 0)
3947                 set_rx_pkt_segments(seg_lengths, nb_segs);
3948         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3949 }
3950
3951 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3952         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3953                                  cmd_keyword, "set");
3954 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3955         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3956                                  rxpkts, "rxpkts");
3957 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3958         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3959                                  seg_lengths, NULL);
3960
3961 cmdline_parse_inst_t cmd_set_rxpkts = {
3962         .f = cmd_set_rxpkts_parsed,
3963         .data = NULL,
3964         .help_str = "set rxpkts <len0[,len1]*>",
3965         .tokens = {
3966                 (void *)&cmd_set_rxpkts_keyword,
3967                 (void *)&cmd_set_rxpkts_name,
3968                 (void *)&cmd_set_rxpkts_lengths,
3969                 NULL,
3970         },
3971 };
3972
3973 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3974
3975 struct cmd_set_txpkts_result {
3976         cmdline_fixed_string_t cmd_keyword;
3977         cmdline_fixed_string_t txpkts;
3978         cmdline_fixed_string_t seg_lengths;
3979 };
3980
3981 static void
3982 cmd_set_txpkts_parsed(void *parsed_result,
3983                       __rte_unused struct cmdline *cl,
3984                       __rte_unused void *data)
3985 {
3986         struct cmd_set_txpkts_result *res;
3987         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3988         unsigned int nb_segs;
3989
3990         res = parsed_result;
3991         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3992                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3993         if (nb_segs > 0)
3994                 set_tx_pkt_segments(seg_lengths, nb_segs);
3995 }
3996
3997 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3998         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3999                                  cmd_keyword, "set");
4000 cmdline_parse_token_string_t cmd_set_txpkts_name =
4001         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4002                                  txpkts, "txpkts");
4003 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4004         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4005                                  seg_lengths, NULL);
4006
4007 cmdline_parse_inst_t cmd_set_txpkts = {
4008         .f = cmd_set_txpkts_parsed,
4009         .data = NULL,
4010         .help_str = "set txpkts <len0[,len1]*>",
4011         .tokens = {
4012                 (void *)&cmd_set_txpkts_keyword,
4013                 (void *)&cmd_set_txpkts_name,
4014                 (void *)&cmd_set_txpkts_lengths,
4015                 NULL,
4016         },
4017 };
4018
4019 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4020
4021 struct cmd_set_txsplit_result {
4022         cmdline_fixed_string_t cmd_keyword;
4023         cmdline_fixed_string_t txsplit;
4024         cmdline_fixed_string_t mode;
4025 };
4026
4027 static void
4028 cmd_set_txsplit_parsed(void *parsed_result,
4029                       __rte_unused struct cmdline *cl,
4030                       __rte_unused void *data)
4031 {
4032         struct cmd_set_txsplit_result *res;
4033
4034         res = parsed_result;
4035         set_tx_pkt_split(res->mode);
4036 }
4037
4038 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4039         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4040                                  cmd_keyword, "set");
4041 cmdline_parse_token_string_t cmd_set_txsplit_name =
4042         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4043                                  txsplit, "txsplit");
4044 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4045         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4046                                  mode, NULL);
4047
4048 cmdline_parse_inst_t cmd_set_txsplit = {
4049         .f = cmd_set_txsplit_parsed,
4050         .data = NULL,
4051         .help_str = "set txsplit on|off|rand",
4052         .tokens = {
4053                 (void *)&cmd_set_txsplit_keyword,
4054                 (void *)&cmd_set_txsplit_name,
4055                 (void *)&cmd_set_txsplit_mode,
4056                 NULL,
4057         },
4058 };
4059
4060 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4061
4062 struct cmd_set_txtimes_result {
4063         cmdline_fixed_string_t cmd_keyword;
4064         cmdline_fixed_string_t txtimes;
4065         cmdline_fixed_string_t tx_times;
4066 };
4067
4068 static void
4069 cmd_set_txtimes_parsed(void *parsed_result,
4070                        __rte_unused struct cmdline *cl,
4071                        __rte_unused void *data)
4072 {
4073         struct cmd_set_txtimes_result *res;
4074         unsigned int tx_times[2] = {0, 0};
4075         unsigned int n_times;
4076
4077         res = parsed_result;
4078         n_times = parse_item_list(res->tx_times, "tx times",
4079                                   2, tx_times, 0);
4080         if (n_times == 2)
4081                 set_tx_pkt_times(tx_times);
4082 }
4083
4084 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4085         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4086                                  cmd_keyword, "set");
4087 cmdline_parse_token_string_t cmd_set_txtimes_name =
4088         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4089                                  txtimes, "txtimes");
4090 cmdline_parse_token_string_t cmd_set_txtimes_value =
4091         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4092                                  tx_times, NULL);
4093
4094 cmdline_parse_inst_t cmd_set_txtimes = {
4095         .f = cmd_set_txtimes_parsed,
4096         .data = NULL,
4097         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4098         .tokens = {
4099                 (void *)&cmd_set_txtimes_keyword,
4100                 (void *)&cmd_set_txtimes_name,
4101                 (void *)&cmd_set_txtimes_value,
4102                 NULL,
4103         },
4104 };
4105
4106 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4107 struct cmd_rx_vlan_filter_all_result {
4108         cmdline_fixed_string_t rx_vlan;
4109         cmdline_fixed_string_t what;
4110         cmdline_fixed_string_t all;
4111         portid_t port_id;
4112 };
4113
4114 static void
4115 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4116                               __rte_unused struct cmdline *cl,
4117                               __rte_unused void *data)
4118 {
4119         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4120
4121         if (!strcmp(res->what, "add"))
4122                 rx_vlan_all_filter_set(res->port_id, 1);
4123         else
4124                 rx_vlan_all_filter_set(res->port_id, 0);
4125 }
4126
4127 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4128         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4129                                  rx_vlan, "rx_vlan");
4130 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4131         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4132                                  what, "add#rm");
4133 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4134         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4135                                  all, "all");
4136 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4137         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4138                               port_id, RTE_UINT16);
4139
4140 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4141         .f = cmd_rx_vlan_filter_all_parsed,
4142         .data = NULL,
4143         .help_str = "rx_vlan add|rm all <port_id>: "
4144                 "Add/Remove all identifiers to/from the set of VLAN "
4145                 "identifiers filtered by a port",
4146         .tokens = {
4147                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4148                 (void *)&cmd_rx_vlan_filter_all_what,
4149                 (void *)&cmd_rx_vlan_filter_all_all,
4150                 (void *)&cmd_rx_vlan_filter_all_portid,
4151                 NULL,
4152         },
4153 };
4154
4155 /* *** VLAN OFFLOAD SET ON A PORT *** */
4156 struct cmd_vlan_offload_result {
4157         cmdline_fixed_string_t vlan;
4158         cmdline_fixed_string_t set;
4159         cmdline_fixed_string_t vlan_type;
4160         cmdline_fixed_string_t what;
4161         cmdline_fixed_string_t on;
4162         cmdline_fixed_string_t port_id;
4163 };
4164
4165 static void
4166 cmd_vlan_offload_parsed(void *parsed_result,
4167                           __rte_unused struct cmdline *cl,
4168                           __rte_unused void *data)
4169 {
4170         int on;
4171         struct cmd_vlan_offload_result *res = parsed_result;
4172         char *str;
4173         int i, len = 0;
4174         portid_t port_id = 0;
4175         unsigned int tmp;
4176
4177         str = res->port_id;
4178         len = strnlen(str, STR_TOKEN_SIZE);
4179         i = 0;
4180         /* Get port_id first */
4181         while(i < len){
4182                 if(str[i] == ',')
4183                         break;
4184
4185                 i++;
4186         }
4187         str[i]='\0';
4188         tmp = strtoul(str, NULL, 0);
4189         /* If port_id greater that what portid_t can represent, return */
4190         if(tmp >= RTE_MAX_ETHPORTS)
4191                 return;
4192         port_id = (portid_t)tmp;
4193
4194         if (!strcmp(res->on, "on"))
4195                 on = 1;
4196         else
4197                 on = 0;
4198
4199         if (!strcmp(res->what, "strip"))
4200                 rx_vlan_strip_set(port_id,  on);
4201         else if(!strcmp(res->what, "stripq")){
4202                 uint16_t queue_id = 0;
4203
4204                 /* No queue_id, return */
4205                 if(i + 1 >= len) {
4206                         fprintf(stderr, "must specify (port,queue_id)\n");
4207                         return;
4208                 }
4209                 tmp = strtoul(str + i + 1, NULL, 0);
4210                 /* If queue_id greater that what 16-bits can represent, return */
4211                 if(tmp > 0xffff)
4212                         return;
4213
4214                 queue_id = (uint16_t)tmp;
4215                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4216         }
4217         else if (!strcmp(res->what, "filter"))
4218                 rx_vlan_filter_set(port_id, on);
4219         else if (!strcmp(res->what, "qinq_strip"))
4220                 rx_vlan_qinq_strip_set(port_id, on);
4221         else
4222                 vlan_extend_set(port_id, on);
4223
4224         return;
4225 }
4226
4227 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4228         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4229                                  vlan, "vlan");
4230 cmdline_parse_token_string_t cmd_vlan_offload_set =
4231         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4232                                  set, "set");
4233 cmdline_parse_token_string_t cmd_vlan_offload_what =
4234         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4235                                 what, "strip#filter#qinq_strip#extend#stripq");
4236 cmdline_parse_token_string_t cmd_vlan_offload_on =
4237         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4238                               on, "on#off");
4239 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4240         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4241                               port_id, NULL);
4242
4243 cmdline_parse_inst_t cmd_vlan_offload = {
4244         .f = cmd_vlan_offload_parsed,
4245         .data = NULL,
4246         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4247                 "<port_id[,queue_id]>: "
4248                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4249         .tokens = {
4250                 (void *)&cmd_vlan_offload_vlan,
4251                 (void *)&cmd_vlan_offload_set,
4252                 (void *)&cmd_vlan_offload_what,
4253                 (void *)&cmd_vlan_offload_on,
4254                 (void *)&cmd_vlan_offload_portid,
4255                 NULL,
4256         },
4257 };
4258
4259 /* *** VLAN TPID SET ON A PORT *** */
4260 struct cmd_vlan_tpid_result {
4261         cmdline_fixed_string_t vlan;
4262         cmdline_fixed_string_t set;
4263         cmdline_fixed_string_t vlan_type;
4264         cmdline_fixed_string_t what;
4265         uint16_t tp_id;
4266         portid_t port_id;
4267 };
4268
4269 static void
4270 cmd_vlan_tpid_parsed(void *parsed_result,
4271                           __rte_unused struct cmdline *cl,
4272                           __rte_unused void *data)
4273 {
4274         struct cmd_vlan_tpid_result *res = parsed_result;
4275         enum rte_vlan_type vlan_type;
4276
4277         if (!strcmp(res->vlan_type, "inner"))
4278                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4279         else if (!strcmp(res->vlan_type, "outer"))
4280                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4281         else {
4282                 fprintf(stderr, "Unknown vlan type\n");
4283                 return;
4284         }
4285         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4286 }
4287
4288 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4289         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4290                                  vlan, "vlan");
4291 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4292         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4293                                  set, "set");
4294 cmdline_parse_token_string_t cmd_vlan_type =
4295         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4296                                  vlan_type, "inner#outer");
4297 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4298         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4299                                  what, "tpid");
4300 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4301         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4302                               tp_id, RTE_UINT16);
4303 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4304         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4305                               port_id, RTE_UINT16);
4306
4307 cmdline_parse_inst_t cmd_vlan_tpid = {
4308         .f = cmd_vlan_tpid_parsed,
4309         .data = NULL,
4310         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4311                 "Set the VLAN Ether type",
4312         .tokens = {
4313                 (void *)&cmd_vlan_tpid_vlan,
4314                 (void *)&cmd_vlan_tpid_set,
4315                 (void *)&cmd_vlan_type,
4316                 (void *)&cmd_vlan_tpid_what,
4317                 (void *)&cmd_vlan_tpid_tpid,
4318                 (void *)&cmd_vlan_tpid_portid,
4319                 NULL,
4320         },
4321 };
4322
4323 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4324 struct cmd_rx_vlan_filter_result {
4325         cmdline_fixed_string_t rx_vlan;
4326         cmdline_fixed_string_t what;
4327         uint16_t vlan_id;
4328         portid_t port_id;
4329 };
4330
4331 static void
4332 cmd_rx_vlan_filter_parsed(void *parsed_result,
4333                           __rte_unused struct cmdline *cl,
4334                           __rte_unused void *data)
4335 {
4336         struct cmd_rx_vlan_filter_result *res = parsed_result;
4337
4338         if (!strcmp(res->what, "add"))
4339                 rx_vft_set(res->port_id, res->vlan_id, 1);
4340         else
4341                 rx_vft_set(res->port_id, res->vlan_id, 0);
4342 }
4343
4344 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4345         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4346                                  rx_vlan, "rx_vlan");
4347 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4348         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4349                                  what, "add#rm");
4350 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4351         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4352                               vlan_id, RTE_UINT16);
4353 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4354         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4355                               port_id, RTE_UINT16);
4356
4357 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4358         .f = cmd_rx_vlan_filter_parsed,
4359         .data = NULL,
4360         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4361                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4362                 "identifiers filtered by a port",
4363         .tokens = {
4364                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4365                 (void *)&cmd_rx_vlan_filter_what,
4366                 (void *)&cmd_rx_vlan_filter_vlanid,
4367                 (void *)&cmd_rx_vlan_filter_portid,
4368                 NULL,
4369         },
4370 };
4371
4372 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4373 struct cmd_tx_vlan_set_result {
4374         cmdline_fixed_string_t tx_vlan;
4375         cmdline_fixed_string_t set;
4376         portid_t port_id;
4377         uint16_t vlan_id;
4378 };
4379
4380 static void
4381 cmd_tx_vlan_set_parsed(void *parsed_result,
4382                        __rte_unused struct cmdline *cl,
4383                        __rte_unused void *data)
4384 {
4385         struct cmd_tx_vlan_set_result *res = parsed_result;
4386
4387         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4388                 return;
4389
4390         if (!port_is_stopped(res->port_id)) {
4391                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4392                 return;
4393         }
4394
4395         tx_vlan_set(res->port_id, res->vlan_id);
4396
4397         cmd_reconfig_device_queue(res->port_id, 1, 1);
4398 }
4399
4400 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4401         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4402                                  tx_vlan, "tx_vlan");
4403 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4404         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4405                                  set, "set");
4406 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4407         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4408                               port_id, RTE_UINT16);
4409 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4410         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4411                               vlan_id, RTE_UINT16);
4412
4413 cmdline_parse_inst_t cmd_tx_vlan_set = {
4414         .f = cmd_tx_vlan_set_parsed,
4415         .data = NULL,
4416         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4417                 "Enable hardware insertion of a single VLAN header "
4418                 "with a given TAG Identifier in packets sent on a port",
4419         .tokens = {
4420                 (void *)&cmd_tx_vlan_set_tx_vlan,
4421                 (void *)&cmd_tx_vlan_set_set,
4422                 (void *)&cmd_tx_vlan_set_portid,
4423                 (void *)&cmd_tx_vlan_set_vlanid,
4424                 NULL,
4425         },
4426 };
4427
4428 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4429 struct cmd_tx_vlan_set_qinq_result {
4430         cmdline_fixed_string_t tx_vlan;
4431         cmdline_fixed_string_t set;
4432         portid_t port_id;
4433         uint16_t vlan_id;
4434         uint16_t vlan_id_outer;
4435 };
4436
4437 static void
4438 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4439                             __rte_unused struct cmdline *cl,
4440                             __rte_unused void *data)
4441 {
4442         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4443
4444         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4445                 return;
4446
4447         if (!port_is_stopped(res->port_id)) {
4448                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4449                 return;
4450         }
4451
4452         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4453
4454         cmd_reconfig_device_queue(res->port_id, 1, 1);
4455 }
4456
4457 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4458         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4459                 tx_vlan, "tx_vlan");
4460 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4461         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4462                 set, "set");
4463 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4464         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4465                 port_id, RTE_UINT16);
4466 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4467         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4468                 vlan_id, RTE_UINT16);
4469 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4470         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4471                 vlan_id_outer, RTE_UINT16);
4472
4473 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4474         .f = cmd_tx_vlan_set_qinq_parsed,
4475         .data = NULL,
4476         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4477                 "Enable hardware insertion of double VLAN header "
4478                 "with given TAG Identifiers in packets sent on a port",
4479         .tokens = {
4480                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4481                 (void *)&cmd_tx_vlan_set_qinq_set,
4482                 (void *)&cmd_tx_vlan_set_qinq_portid,
4483                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4484                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4485                 NULL,
4486         },
4487 };
4488
4489 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4490 struct cmd_tx_vlan_set_pvid_result {
4491         cmdline_fixed_string_t tx_vlan;
4492         cmdline_fixed_string_t set;
4493         cmdline_fixed_string_t pvid;
4494         portid_t port_id;
4495         uint16_t vlan_id;
4496         cmdline_fixed_string_t mode;
4497 };
4498
4499 static void
4500 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4501                             __rte_unused struct cmdline *cl,
4502                             __rte_unused void *data)
4503 {
4504         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4505
4506         if (strcmp(res->mode, "on") == 0)
4507                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4508         else
4509                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4510 }
4511
4512 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4513         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4514                                  tx_vlan, "tx_vlan");
4515 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4516         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4517                                  set, "set");
4518 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4519         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4520                                  pvid, "pvid");
4521 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4522         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4523                              port_id, RTE_UINT16);
4524 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4525         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4526                               vlan_id, RTE_UINT16);
4527 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4528         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4529                                  mode, "on#off");
4530
4531 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4532         .f = cmd_tx_vlan_set_pvid_parsed,
4533         .data = NULL,
4534         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4535         .tokens = {
4536                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4537                 (void *)&cmd_tx_vlan_set_pvid_set,
4538                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4539                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4540                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4541                 (void *)&cmd_tx_vlan_set_pvid_mode,
4542                 NULL,
4543         },
4544 };
4545
4546 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4547 struct cmd_tx_vlan_reset_result {
4548         cmdline_fixed_string_t tx_vlan;
4549         cmdline_fixed_string_t reset;
4550         portid_t port_id;
4551 };
4552
4553 static void
4554 cmd_tx_vlan_reset_parsed(void *parsed_result,
4555                          __rte_unused struct cmdline *cl,
4556                          __rte_unused void *data)
4557 {
4558         struct cmd_tx_vlan_reset_result *res = parsed_result;
4559
4560         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4561                 return;
4562
4563         if (!port_is_stopped(res->port_id)) {
4564                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4565                 return;
4566         }
4567
4568         tx_vlan_reset(res->port_id);
4569
4570         cmd_reconfig_device_queue(res->port_id, 1, 1);
4571 }
4572
4573 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4574         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4575                                  tx_vlan, "tx_vlan");
4576 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4577         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4578                                  reset, "reset");
4579 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4580         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4581                               port_id, RTE_UINT16);
4582
4583 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4584         .f = cmd_tx_vlan_reset_parsed,
4585         .data = NULL,
4586         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4587                 "VLAN header in packets sent on a port",
4588         .tokens = {
4589                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4590                 (void *)&cmd_tx_vlan_reset_reset,
4591                 (void *)&cmd_tx_vlan_reset_portid,
4592                 NULL,
4593         },
4594 };
4595
4596
4597 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4598 struct cmd_csum_result {
4599         cmdline_fixed_string_t csum;
4600         cmdline_fixed_string_t mode;
4601         cmdline_fixed_string_t proto;
4602         cmdline_fixed_string_t hwsw;
4603         portid_t port_id;
4604 };
4605
4606 static void
4607 csum_show(int port_id)
4608 {
4609         struct rte_eth_dev_info dev_info;
4610         uint64_t tx_offloads;
4611         int ret;
4612
4613         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4614         printf("Parse tunnel is %s\n",
4615                 (ports[port_id].parse_tunnel) ? "on" : "off");
4616         printf("IP checksum offload is %s\n",
4617                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4618         printf("UDP checksum offload is %s\n",
4619                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4620         printf("TCP checksum offload is %s\n",
4621                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4622         printf("SCTP checksum offload is %s\n",
4623                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4624         printf("Outer-Ip checksum offload is %s\n",
4625                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4626         printf("Outer-Udp checksum offload is %s\n",
4627                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4628
4629         /* display warnings if configuration is not supported by the NIC */
4630         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4631         if (ret != 0)
4632                 return;
4633
4634         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4635                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4636                 fprintf(stderr,
4637                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4638                         port_id);
4639         }
4640         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4641                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4642                 fprintf(stderr,
4643                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4644                         port_id);
4645         }
4646         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4647                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4648                 fprintf(stderr,
4649                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4650                         port_id);
4651         }
4652         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4653                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4654                 fprintf(stderr,
4655                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4656                         port_id);
4657         }
4658         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4659                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4660                 fprintf(stderr,
4661                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4662                         port_id);
4663         }
4664         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4665                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4666                         == 0) {
4667                 fprintf(stderr,
4668                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4669                         port_id);
4670         }
4671 }
4672
4673 static void
4674 cmd_config_queue_tx_offloads(struct rte_port *port)
4675 {
4676         int k;
4677
4678         /* Apply queue tx offloads configuration */
4679         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4680                 port->tx_conf[k].offloads =
4681                         port->dev_conf.txmode.offloads;
4682 }
4683
4684 static void
4685 cmd_csum_parsed(void *parsed_result,
4686                        __rte_unused struct cmdline *cl,
4687                        __rte_unused void *data)
4688 {
4689         struct cmd_csum_result *res = parsed_result;
4690         int hw = 0;
4691         uint64_t csum_offloads = 0;
4692         struct rte_eth_dev_info dev_info;
4693         int ret;
4694
4695         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4696                 fprintf(stderr, "invalid port %d\n", res->port_id);
4697                 return;
4698         }
4699         if (!port_is_stopped(res->port_id)) {
4700                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4701                 return;
4702         }
4703
4704         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4705         if (ret != 0)
4706                 return;
4707
4708         if (!strcmp(res->mode, "set")) {
4709
4710                 if (!strcmp(res->hwsw, "hw"))
4711                         hw = 1;
4712
4713                 if (!strcmp(res->proto, "ip")) {
4714                         if (hw == 0 || (dev_info.tx_offload_capa &
4715                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4716                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4717                         } else {
4718                                 fprintf(stderr,
4719                                         "IP checksum offload is not supported by port %u\n",
4720                                         res->port_id);
4721                         }
4722                 } else if (!strcmp(res->proto, "udp")) {
4723                         if (hw == 0 || (dev_info.tx_offload_capa &
4724                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4725                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4726                         } else {
4727                                 fprintf(stderr,
4728                                         "UDP checksum offload is not supported by port %u\n",
4729                                         res->port_id);
4730                         }
4731                 } else if (!strcmp(res->proto, "tcp")) {
4732                         if (hw == 0 || (dev_info.tx_offload_capa &
4733                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4734                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4735                         } else {
4736                                 fprintf(stderr,
4737                                         "TCP checksum offload is not supported by port %u\n",
4738                                         res->port_id);
4739                         }
4740                 } else if (!strcmp(res->proto, "sctp")) {
4741                         if (hw == 0 || (dev_info.tx_offload_capa &
4742                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4743                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4744                         } else {
4745                                 fprintf(stderr,
4746                                         "SCTP checksum offload is not supported by port %u\n",
4747                                         res->port_id);
4748                         }
4749                 } else if (!strcmp(res->proto, "outer-ip")) {
4750                         if (hw == 0 || (dev_info.tx_offload_capa &
4751                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4752                                 csum_offloads |=
4753                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4754                         } else {
4755                                 fprintf(stderr,
4756                                         "Outer IP checksum offload is not supported by port %u\n",
4757                                         res->port_id);
4758                         }
4759                 } else if (!strcmp(res->proto, "outer-udp")) {
4760                         if (hw == 0 || (dev_info.tx_offload_capa &
4761                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4762                                 csum_offloads |=
4763                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4764                         } else {
4765                                 fprintf(stderr,
4766                                         "Outer UDP checksum offload is not supported by port %u\n",
4767                                         res->port_id);
4768                         }
4769                 }
4770
4771                 if (hw) {
4772                         ports[res->port_id].dev_conf.txmode.offloads |=
4773                                                         csum_offloads;
4774                 } else {
4775                         ports[res->port_id].dev_conf.txmode.offloads &=
4776                                                         (~csum_offloads);
4777                 }
4778                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4779         }
4780         csum_show(res->port_id);
4781
4782         cmd_reconfig_device_queue(res->port_id, 1, 1);
4783 }
4784
4785 cmdline_parse_token_string_t cmd_csum_csum =
4786         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4787                                 csum, "csum");
4788 cmdline_parse_token_string_t cmd_csum_mode =
4789         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4790                                 mode, "set");
4791 cmdline_parse_token_string_t cmd_csum_proto =
4792         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4793                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4794 cmdline_parse_token_string_t cmd_csum_hwsw =
4795         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4796                                 hwsw, "hw#sw");
4797 cmdline_parse_token_num_t cmd_csum_portid =
4798         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4799                                 port_id, RTE_UINT16);
4800
4801 cmdline_parse_inst_t cmd_csum_set = {
4802         .f = cmd_csum_parsed,
4803         .data = NULL,
4804         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4805                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4806                 "using csum forward engine",
4807         .tokens = {
4808                 (void *)&cmd_csum_csum,
4809                 (void *)&cmd_csum_mode,
4810                 (void *)&cmd_csum_proto,
4811                 (void *)&cmd_csum_hwsw,
4812                 (void *)&cmd_csum_portid,
4813                 NULL,
4814         },
4815 };
4816
4817 cmdline_parse_token_string_t cmd_csum_mode_show =
4818         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4819                                 mode, "show");
4820
4821 cmdline_parse_inst_t cmd_csum_show = {
4822         .f = cmd_csum_parsed,
4823         .data = NULL,
4824         .help_str = "csum show <port_id>: Show checksum offload configuration",
4825         .tokens = {
4826                 (void *)&cmd_csum_csum,
4827                 (void *)&cmd_csum_mode_show,
4828                 (void *)&cmd_csum_portid,
4829                 NULL,
4830         },
4831 };
4832
4833 /* Enable/disable tunnel parsing */
4834 struct cmd_csum_tunnel_result {
4835         cmdline_fixed_string_t csum;
4836         cmdline_fixed_string_t parse;
4837         cmdline_fixed_string_t onoff;
4838         portid_t port_id;
4839 };
4840
4841 static void
4842 cmd_csum_tunnel_parsed(void *parsed_result,
4843                        __rte_unused struct cmdline *cl,
4844                        __rte_unused void *data)
4845 {
4846         struct cmd_csum_tunnel_result *res = parsed_result;
4847
4848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4849                 return;
4850
4851         if (!strcmp(res->onoff, "on"))
4852                 ports[res->port_id].parse_tunnel = 1;
4853         else
4854                 ports[res->port_id].parse_tunnel = 0;
4855
4856         csum_show(res->port_id);
4857 }
4858
4859 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4860         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4861                                 csum, "csum");
4862 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4863         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4864                                 parse, "parse-tunnel");
4865 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4866         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4867                                 onoff, "on#off");
4868 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4869         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4870                                 port_id, RTE_UINT16);
4871
4872 cmdline_parse_inst_t cmd_csum_tunnel = {
4873         .f = cmd_csum_tunnel_parsed,
4874         .data = NULL,
4875         .help_str = "csum parse-tunnel on|off <port_id>: "
4876                 "Enable/Disable parsing of tunnels for csum engine",
4877         .tokens = {
4878                 (void *)&cmd_csum_tunnel_csum,
4879                 (void *)&cmd_csum_tunnel_parse,
4880                 (void *)&cmd_csum_tunnel_onoff,
4881                 (void *)&cmd_csum_tunnel_portid,
4882                 NULL,
4883         },
4884 };
4885
4886 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4887 struct cmd_tso_set_result {
4888         cmdline_fixed_string_t tso;
4889         cmdline_fixed_string_t mode;
4890         uint16_t tso_segsz;
4891         portid_t port_id;
4892 };
4893
4894 static void
4895 cmd_tso_set_parsed(void *parsed_result,
4896                        __rte_unused struct cmdline *cl,
4897                        __rte_unused void *data)
4898 {
4899         struct cmd_tso_set_result *res = parsed_result;
4900         struct rte_eth_dev_info dev_info;
4901         int ret;
4902
4903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4904                 return;
4905         if (!port_is_stopped(res->port_id)) {
4906                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4907                 return;
4908         }
4909
4910         if (!strcmp(res->mode, "set"))
4911                 ports[res->port_id].tso_segsz = res->tso_segsz;
4912
4913         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4914         if (ret != 0)
4915                 return;
4916
4917         if ((ports[res->port_id].tso_segsz != 0) &&
4918                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4919                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4920                         res->port_id);
4921                 return;
4922         }
4923
4924         if (ports[res->port_id].tso_segsz == 0) {
4925                 ports[res->port_id].dev_conf.txmode.offloads &=
4926                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4927                 printf("TSO for non-tunneled packets is disabled\n");
4928         } else {
4929                 ports[res->port_id].dev_conf.txmode.offloads |=
4930                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4931                 printf("TSO segment size for non-tunneled packets is %d\n",
4932                         ports[res->port_id].tso_segsz);
4933         }
4934         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4935
4936         /* display warnings if configuration is not supported by the NIC */
4937         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4938         if (ret != 0)
4939                 return;
4940
4941         if ((ports[res->port_id].tso_segsz != 0) &&
4942                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4943                 fprintf(stderr,
4944                         "Warning: TSO enabled but not supported by port %d\n",
4945                         res->port_id);
4946         }
4947
4948         cmd_reconfig_device_queue(res->port_id, 1, 1);
4949 }
4950
4951 cmdline_parse_token_string_t cmd_tso_set_tso =
4952         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4953                                 tso, "tso");
4954 cmdline_parse_token_string_t cmd_tso_set_mode =
4955         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4956                                 mode, "set");
4957 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4958         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4959                                 tso_segsz, RTE_UINT16);
4960 cmdline_parse_token_num_t cmd_tso_set_portid =
4961         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4962                                 port_id, RTE_UINT16);
4963
4964 cmdline_parse_inst_t cmd_tso_set = {
4965         .f = cmd_tso_set_parsed,
4966         .data = NULL,
4967         .help_str = "tso set <tso_segsz> <port_id>: "
4968                 "Set TSO segment size of non-tunneled packets for csum engine "
4969                 "(0 to disable)",
4970         .tokens = {
4971                 (void *)&cmd_tso_set_tso,
4972                 (void *)&cmd_tso_set_mode,
4973                 (void *)&cmd_tso_set_tso_segsz,
4974                 (void *)&cmd_tso_set_portid,
4975                 NULL,
4976         },
4977 };
4978
4979 cmdline_parse_token_string_t cmd_tso_show_mode =
4980         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4981                                 mode, "show");
4982
4983
4984 cmdline_parse_inst_t cmd_tso_show = {
4985         .f = cmd_tso_set_parsed,
4986         .data = NULL,
4987         .help_str = "tso show <port_id>: "
4988                 "Show TSO segment size of non-tunneled packets for csum engine",
4989         .tokens = {
4990                 (void *)&cmd_tso_set_tso,
4991                 (void *)&cmd_tso_show_mode,
4992                 (void *)&cmd_tso_set_portid,
4993                 NULL,
4994         },
4995 };
4996
4997 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4998 struct cmd_tunnel_tso_set_result {
4999         cmdline_fixed_string_t tso;
5000         cmdline_fixed_string_t mode;
5001         uint16_t tso_segsz;
5002         portid_t port_id;
5003 };
5004
5005 static struct rte_eth_dev_info
5006 check_tunnel_tso_nic_support(portid_t port_id)
5007 {
5008         struct rte_eth_dev_info dev_info;
5009
5010         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5011                 return dev_info;
5012
5013         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5014                 fprintf(stderr,
5015                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5016                         port_id);
5017         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5018                 fprintf(stderr,
5019                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5020                         port_id);
5021         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5022                 fprintf(stderr,
5023                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5024                         port_id);
5025         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5026                 fprintf(stderr,
5027                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5028                         port_id);
5029         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5030                 fprintf(stderr,
5031                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5032                         port_id);
5033         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5034                 fprintf(stderr,
5035                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5036                         port_id);
5037         return dev_info;
5038 }
5039
5040 static void
5041 cmd_tunnel_tso_set_parsed(void *parsed_result,
5042                           __rte_unused struct cmdline *cl,
5043                           __rte_unused void *data)
5044 {
5045         struct cmd_tunnel_tso_set_result *res = parsed_result;
5046         struct rte_eth_dev_info dev_info;
5047
5048         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5049                 return;
5050         if (!port_is_stopped(res->port_id)) {
5051                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5052                 return;
5053         }
5054
5055         if (!strcmp(res->mode, "set"))
5056                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5057
5058         dev_info = check_tunnel_tso_nic_support(res->port_id);
5059         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5060                 ports[res->port_id].dev_conf.txmode.offloads &=
5061                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5062                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5063                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5064                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5065                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5066                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5067                 printf("TSO for tunneled packets is disabled\n");
5068         } else {
5069                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5070                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5071                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5072                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5073                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5074                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5075
5076                 ports[res->port_id].dev_conf.txmode.offloads |=
5077                         (tso_offloads & dev_info.tx_offload_capa);
5078                 printf("TSO segment size for tunneled packets is %d\n",
5079                         ports[res->port_id].tunnel_tso_segsz);
5080
5081                 /* Below conditions are needed to make it work:
5082                  * (1) tunnel TSO is supported by the NIC;
5083                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5084                  * are recognized;
5085                  * (3) for tunneled pkts with outer L3 of IPv4,
5086                  * "csum set outer-ip" must be set to hw, because after tso,
5087                  * total_len of outer IP header is changed, and the checksum
5088                  * of outer IP header calculated by sw should be wrong; that
5089                  * is not necessary for IPv6 tunneled pkts because there's no
5090                  * checksum in IP header anymore.
5091                  */
5092
5093                 if (!ports[res->port_id].parse_tunnel)
5094                         fprintf(stderr,
5095                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5096                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5097                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5098                         fprintf(stderr,
5099                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5100         }
5101
5102         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5103         cmd_reconfig_device_queue(res->port_id, 1, 1);
5104 }
5105
5106 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5107         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5108                                 tso, "tunnel_tso");
5109 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5110         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5111                                 mode, "set");
5112 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5113         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5114                                 tso_segsz, RTE_UINT16);
5115 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5116         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5117                                 port_id, RTE_UINT16);
5118
5119 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5120         .f = cmd_tunnel_tso_set_parsed,
5121         .data = NULL,
5122         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5123                 "Set TSO segment size of tunneled packets for csum engine "
5124                 "(0 to disable)",
5125         .tokens = {
5126                 (void *)&cmd_tunnel_tso_set_tso,
5127                 (void *)&cmd_tunnel_tso_set_mode,
5128                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5129                 (void *)&cmd_tunnel_tso_set_portid,
5130                 NULL,
5131         },
5132 };
5133
5134 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5135         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5136                                 mode, "show");
5137
5138
5139 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5140         .f = cmd_tunnel_tso_set_parsed,
5141         .data = NULL,
5142         .help_str = "tunnel_tso show <port_id> "
5143                 "Show TSO segment size of tunneled packets for csum engine",
5144         .tokens = {
5145                 (void *)&cmd_tunnel_tso_set_tso,
5146                 (void *)&cmd_tunnel_tso_show_mode,
5147                 (void *)&cmd_tunnel_tso_set_portid,
5148                 NULL,
5149         },
5150 };
5151
5152 /* *** SET GRO FOR A PORT *** */
5153 struct cmd_gro_enable_result {
5154         cmdline_fixed_string_t cmd_set;
5155         cmdline_fixed_string_t cmd_port;
5156         cmdline_fixed_string_t cmd_keyword;
5157         cmdline_fixed_string_t cmd_onoff;
5158         portid_t cmd_pid;
5159 };
5160
5161 static void
5162 cmd_gro_enable_parsed(void *parsed_result,
5163                 __rte_unused struct cmdline *cl,
5164                 __rte_unused void *data)
5165 {
5166         struct cmd_gro_enable_result *res;
5167
5168         res = parsed_result;
5169         if (!strcmp(res->cmd_keyword, "gro"))
5170                 setup_gro(res->cmd_onoff, res->cmd_pid);
5171 }
5172
5173 cmdline_parse_token_string_t cmd_gro_enable_set =
5174         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5175                         cmd_set, "set");
5176 cmdline_parse_token_string_t cmd_gro_enable_port =
5177         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5178                         cmd_keyword, "port");
5179 cmdline_parse_token_num_t cmd_gro_enable_pid =
5180         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5181                         cmd_pid, RTE_UINT16);
5182 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5183         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5184                         cmd_keyword, "gro");
5185 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5186         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5187                         cmd_onoff, "on#off");
5188
5189 cmdline_parse_inst_t cmd_gro_enable = {
5190         .f = cmd_gro_enable_parsed,
5191         .data = NULL,
5192         .help_str = "set port <port_id> gro on|off",
5193         .tokens = {
5194                 (void *)&cmd_gro_enable_set,
5195                 (void *)&cmd_gro_enable_port,
5196                 (void *)&cmd_gro_enable_pid,
5197                 (void *)&cmd_gro_enable_keyword,
5198                 (void *)&cmd_gro_enable_onoff,
5199                 NULL,
5200         },
5201 };
5202
5203 /* *** DISPLAY GRO CONFIGURATION *** */
5204 struct cmd_gro_show_result {
5205         cmdline_fixed_string_t cmd_show;
5206         cmdline_fixed_string_t cmd_port;
5207         cmdline_fixed_string_t cmd_keyword;
5208         portid_t cmd_pid;
5209 };
5210
5211 static void
5212 cmd_gro_show_parsed(void *parsed_result,
5213                 __rte_unused struct cmdline *cl,
5214                 __rte_unused void *data)
5215 {
5216         struct cmd_gro_show_result *res;
5217
5218         res = parsed_result;
5219         if (!strcmp(res->cmd_keyword, "gro"))
5220                 show_gro(res->cmd_pid);
5221 }
5222
5223 cmdline_parse_token_string_t cmd_gro_show_show =
5224         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5225                         cmd_show, "show");
5226 cmdline_parse_token_string_t cmd_gro_show_port =
5227         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5228                         cmd_port, "port");
5229 cmdline_parse_token_num_t cmd_gro_show_pid =
5230         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5231                         cmd_pid, RTE_UINT16);
5232 cmdline_parse_token_string_t cmd_gro_show_keyword =
5233         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5234                         cmd_keyword, "gro");
5235
5236 cmdline_parse_inst_t cmd_gro_show = {
5237         .f = cmd_gro_show_parsed,
5238         .data = NULL,
5239         .help_str = "show port <port_id> gro",
5240         .tokens = {
5241                 (void *)&cmd_gro_show_show,
5242                 (void *)&cmd_gro_show_port,
5243                 (void *)&cmd_gro_show_pid,
5244                 (void *)&cmd_gro_show_keyword,
5245                 NULL,
5246         },
5247 };
5248
5249 /* *** SET FLUSH CYCLES FOR GRO *** */
5250 struct cmd_gro_flush_result {
5251         cmdline_fixed_string_t cmd_set;
5252         cmdline_fixed_string_t cmd_keyword;
5253         cmdline_fixed_string_t cmd_flush;
5254         uint8_t cmd_cycles;
5255 };
5256
5257 static void
5258 cmd_gro_flush_parsed(void *parsed_result,
5259                 __rte_unused struct cmdline *cl,
5260                 __rte_unused void *data)
5261 {
5262         struct cmd_gro_flush_result *res;
5263
5264         res = parsed_result;
5265         if ((!strcmp(res->cmd_keyword, "gro")) &&
5266                         (!strcmp(res->cmd_flush, "flush")))
5267                 setup_gro_flush_cycles(res->cmd_cycles);
5268 }
5269
5270 cmdline_parse_token_string_t cmd_gro_flush_set =
5271         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5272                         cmd_set, "set");
5273 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5274         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5275                         cmd_keyword, "gro");
5276 cmdline_parse_token_string_t cmd_gro_flush_flush =
5277         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5278                         cmd_flush, "flush");
5279 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5280         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5281                         cmd_cycles, RTE_UINT8);
5282
5283 cmdline_parse_inst_t cmd_gro_flush = {
5284         .f = cmd_gro_flush_parsed,
5285         .data = NULL,
5286         .help_str = "set gro flush <cycles>",
5287         .tokens = {
5288                 (void *)&cmd_gro_flush_set,
5289                 (void *)&cmd_gro_flush_keyword,
5290                 (void *)&cmd_gro_flush_flush,
5291                 (void *)&cmd_gro_flush_cycles,
5292                 NULL,
5293         },
5294 };
5295
5296 /* *** ENABLE/DISABLE GSO *** */
5297 struct cmd_gso_enable_result {
5298         cmdline_fixed_string_t cmd_set;
5299         cmdline_fixed_string_t cmd_port;
5300         cmdline_fixed_string_t cmd_keyword;
5301         cmdline_fixed_string_t cmd_mode;
5302         portid_t cmd_pid;
5303 };
5304
5305 static void
5306 cmd_gso_enable_parsed(void *parsed_result,
5307                 __rte_unused struct cmdline *cl,
5308                 __rte_unused void *data)
5309 {
5310         struct cmd_gso_enable_result *res;
5311
5312         res = parsed_result;
5313         if (!strcmp(res->cmd_keyword, "gso"))
5314                 setup_gso(res->cmd_mode, res->cmd_pid);
5315 }
5316
5317 cmdline_parse_token_string_t cmd_gso_enable_set =
5318         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5319                         cmd_set, "set");
5320 cmdline_parse_token_string_t cmd_gso_enable_port =
5321         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5322                         cmd_port, "port");
5323 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5324         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5325                         cmd_keyword, "gso");
5326 cmdline_parse_token_string_t cmd_gso_enable_mode =
5327         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5328                         cmd_mode, "on#off");
5329 cmdline_parse_token_num_t cmd_gso_enable_pid =
5330         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5331                         cmd_pid, RTE_UINT16);
5332
5333 cmdline_parse_inst_t cmd_gso_enable = {
5334         .f = cmd_gso_enable_parsed,
5335         .data = NULL,
5336         .help_str = "set port <port_id> gso on|off",
5337         .tokens = {
5338                 (void *)&cmd_gso_enable_set,
5339                 (void *)&cmd_gso_enable_port,
5340                 (void *)&cmd_gso_enable_pid,
5341                 (void *)&cmd_gso_enable_keyword,
5342                 (void *)&cmd_gso_enable_mode,
5343                 NULL,
5344         },
5345 };
5346
5347 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5348 struct cmd_gso_size_result {
5349         cmdline_fixed_string_t cmd_set;
5350         cmdline_fixed_string_t cmd_keyword;
5351         cmdline_fixed_string_t cmd_segsz;
5352         uint16_t cmd_size;
5353 };
5354
5355 static void
5356 cmd_gso_size_parsed(void *parsed_result,
5357                        __rte_unused struct cmdline *cl,
5358                        __rte_unused void *data)
5359 {
5360         struct cmd_gso_size_result *res = parsed_result;
5361
5362         if (test_done == 0) {
5363                 fprintf(stderr,
5364                         "Before setting GSO segsz, please first stop forwarding\n");
5365                 return;
5366         }
5367
5368         if (!strcmp(res->cmd_keyword, "gso") &&
5369                         !strcmp(res->cmd_segsz, "segsz")) {
5370                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5371                         fprintf(stderr,
5372                                 "gso_size should be larger than %zu. Please input a legal value\n",
5373                                 RTE_GSO_SEG_SIZE_MIN);
5374                 else
5375                         gso_max_segment_size = res->cmd_size;
5376         }
5377 }
5378
5379 cmdline_parse_token_string_t cmd_gso_size_set =
5380         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5381                                 cmd_set, "set");
5382 cmdline_parse_token_string_t cmd_gso_size_keyword =
5383         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5384                                 cmd_keyword, "gso");
5385 cmdline_parse_token_string_t cmd_gso_size_segsz =
5386         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5387                                 cmd_segsz, "segsz");
5388 cmdline_parse_token_num_t cmd_gso_size_size =
5389         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5390                                 cmd_size, RTE_UINT16);
5391
5392 cmdline_parse_inst_t cmd_gso_size = {
5393         .f = cmd_gso_size_parsed,
5394         .data = NULL,
5395         .help_str = "set gso segsz <length>",
5396         .tokens = {
5397                 (void *)&cmd_gso_size_set,
5398                 (void *)&cmd_gso_size_keyword,
5399                 (void *)&cmd_gso_size_segsz,
5400                 (void *)&cmd_gso_size_size,
5401                 NULL,
5402         },
5403 };
5404
5405 /* *** SHOW GSO CONFIGURATION *** */
5406 struct cmd_gso_show_result {
5407         cmdline_fixed_string_t cmd_show;
5408         cmdline_fixed_string_t cmd_port;
5409         cmdline_fixed_string_t cmd_keyword;
5410         portid_t cmd_pid;
5411 };
5412
5413 static void
5414 cmd_gso_show_parsed(void *parsed_result,
5415                        __rte_unused struct cmdline *cl,
5416                        __rte_unused void *data)
5417 {
5418         struct cmd_gso_show_result *res = parsed_result;
5419
5420         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5421                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5422                 return;
5423         }
5424         if (!strcmp(res->cmd_keyword, "gso")) {
5425                 if (gso_ports[res->cmd_pid].enable) {
5426                         printf("Max GSO'd packet size: %uB\n"
5427                                         "Supported GSO types: TCP/IPv4, "
5428                                         "UDP/IPv4, VxLAN with inner "
5429                                         "TCP/IPv4 packet, GRE with inner "
5430                                         "TCP/IPv4 packet\n",
5431                                         gso_max_segment_size);
5432                 } else
5433                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5434         }
5435 }
5436
5437 cmdline_parse_token_string_t cmd_gso_show_show =
5438 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5439                 cmd_show, "show");
5440 cmdline_parse_token_string_t cmd_gso_show_port =
5441 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5442                 cmd_port, "port");
5443 cmdline_parse_token_string_t cmd_gso_show_keyword =
5444         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5445                                 cmd_keyword, "gso");
5446 cmdline_parse_token_num_t cmd_gso_show_pid =
5447         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5448                                 cmd_pid, RTE_UINT16);
5449
5450 cmdline_parse_inst_t cmd_gso_show = {
5451         .f = cmd_gso_show_parsed,
5452         .data = NULL,
5453         .help_str = "show port <port_id> gso",
5454         .tokens = {
5455                 (void *)&cmd_gso_show_show,
5456                 (void *)&cmd_gso_show_port,
5457                 (void *)&cmd_gso_show_pid,
5458                 (void *)&cmd_gso_show_keyword,
5459                 NULL,
5460         },
5461 };
5462
5463 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5464 struct cmd_set_flush_rx {
5465         cmdline_fixed_string_t set;
5466         cmdline_fixed_string_t flush_rx;
5467         cmdline_fixed_string_t mode;
5468 };
5469
5470 static void
5471 cmd_set_flush_rx_parsed(void *parsed_result,
5472                 __rte_unused struct cmdline *cl,
5473                 __rte_unused void *data)
5474 {
5475         struct cmd_set_flush_rx *res = parsed_result;
5476
5477         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5478                 printf("multi-process doesn't support to flush Rx queues.\n");
5479                 return;
5480         }
5481
5482         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5483 }
5484
5485 cmdline_parse_token_string_t cmd_setflushrx_set =
5486         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5487                         set, "set");
5488 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5489         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5490                         flush_rx, "flush_rx");
5491 cmdline_parse_token_string_t cmd_setflushrx_mode =
5492         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5493                         mode, "on#off");
5494
5495
5496 cmdline_parse_inst_t cmd_set_flush_rx = {
5497         .f = cmd_set_flush_rx_parsed,
5498         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5499         .data = NULL,
5500         .tokens = {
5501                 (void *)&cmd_setflushrx_set,
5502                 (void *)&cmd_setflushrx_flush_rx,
5503                 (void *)&cmd_setflushrx_mode,
5504                 NULL,
5505         },
5506 };
5507
5508 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5509 struct cmd_set_link_check {
5510         cmdline_fixed_string_t set;
5511         cmdline_fixed_string_t link_check;
5512         cmdline_fixed_string_t mode;
5513 };
5514
5515 static void
5516 cmd_set_link_check_parsed(void *parsed_result,
5517                 __rte_unused struct cmdline *cl,
5518                 __rte_unused void *data)
5519 {
5520         struct cmd_set_link_check *res = parsed_result;
5521         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5522 }
5523
5524 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5525         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5526                         set, "set");
5527 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5528         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5529                         link_check, "link_check");
5530 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5531         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5532                         mode, "on#off");
5533
5534
5535 cmdline_parse_inst_t cmd_set_link_check = {
5536         .f = cmd_set_link_check_parsed,
5537         .help_str = "set link_check on|off: Enable/Disable link status check "
5538                     "when starting/stopping a port",
5539         .data = NULL,
5540         .tokens = {
5541                 (void *)&cmd_setlinkcheck_set,
5542                 (void *)&cmd_setlinkcheck_link_check,
5543                 (void *)&cmd_setlinkcheck_mode,
5544                 NULL,
5545         },
5546 };
5547
5548 /* *** SET NIC BYPASS MODE *** */
5549 struct cmd_set_bypass_mode_result {
5550         cmdline_fixed_string_t set;
5551         cmdline_fixed_string_t bypass;
5552         cmdline_fixed_string_t mode;
5553         cmdline_fixed_string_t value;
5554         portid_t port_id;
5555 };
5556
5557 static void
5558 cmd_set_bypass_mode_parsed(void *parsed_result,
5559                 __rte_unused struct cmdline *cl,
5560                 __rte_unused void *data)
5561 {
5562         struct cmd_set_bypass_mode_result *res = parsed_result;
5563         portid_t port_id = res->port_id;
5564         int32_t rc = -EINVAL;
5565
5566 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5567         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5568
5569         if (!strcmp(res->value, "bypass"))
5570                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5571         else if (!strcmp(res->value, "isolate"))
5572                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5573         else
5574                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5575
5576         /* Set the bypass mode for the relevant port. */
5577         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5578 #endif
5579         if (rc != 0)
5580                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5581                         port_id);
5582 }
5583
5584 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5585         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5586                         set, "set");
5587 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5588         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5589                         bypass, "bypass");
5590 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5591         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5592                         mode, "mode");
5593 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5594         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5595                         value, "normal#bypass#isolate");
5596 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5597         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5598                                 port_id, RTE_UINT16);
5599
5600 cmdline_parse_inst_t cmd_set_bypass_mode = {
5601         .f = cmd_set_bypass_mode_parsed,
5602         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5603                     "Set the NIC bypass mode for port_id",
5604         .data = NULL,
5605         .tokens = {
5606                 (void *)&cmd_setbypass_mode_set,
5607                 (void *)&cmd_setbypass_mode_bypass,
5608                 (void *)&cmd_setbypass_mode_mode,
5609                 (void *)&cmd_setbypass_mode_value,
5610                 (void *)&cmd_setbypass_mode_port,
5611                 NULL,
5612         },
5613 };
5614
5615 /* *** SET NIC BYPASS EVENT *** */
5616 struct cmd_set_bypass_event_result {
5617         cmdline_fixed_string_t set;
5618         cmdline_fixed_string_t bypass;
5619         cmdline_fixed_string_t event;
5620         cmdline_fixed_string_t event_value;
5621         cmdline_fixed_string_t mode;
5622         cmdline_fixed_string_t mode_value;
5623         portid_t port_id;
5624 };
5625
5626 static void
5627 cmd_set_bypass_event_parsed(void *parsed_result,
5628                 __rte_unused struct cmdline *cl,
5629                 __rte_unused void *data)
5630 {
5631         int32_t rc = -EINVAL;
5632         struct cmd_set_bypass_event_result *res = parsed_result;
5633         portid_t port_id = res->port_id;
5634
5635 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5636         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5637         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5638
5639         if (!strcmp(res->event_value, "timeout"))
5640                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5641         else if (!strcmp(res->event_value, "os_on"))
5642                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5643         else if (!strcmp(res->event_value, "os_off"))
5644                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5645         else if (!strcmp(res->event_value, "power_on"))
5646                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5647         else if (!strcmp(res->event_value, "power_off"))
5648                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5649         else
5650                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5651
5652         if (!strcmp(res->mode_value, "bypass"))
5653                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5654         else if (!strcmp(res->mode_value, "isolate"))
5655                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5656         else
5657                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5658
5659         /* Set the watchdog timeout. */
5660         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5661
5662                 rc = -EINVAL;
5663                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5664                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5665                                                            bypass_timeout);
5666                 }
5667                 if (rc != 0) {
5668                         fprintf(stderr,
5669                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5670                                 bypass_timeout, port_id, rc);
5671                 }
5672         }
5673
5674         /* Set the bypass event to transition to bypass mode. */
5675         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5676                                               bypass_mode);
5677 #endif
5678
5679         if (rc != 0)
5680                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5681                         port_id);
5682 }
5683
5684 cmdline_parse_token_string_t cmd_setbypass_event_set =
5685         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5686                         set, "set");
5687 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5688         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5689                         bypass, "bypass");
5690 cmdline_parse_token_string_t cmd_setbypass_event_event =
5691         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5692                         event, "event");
5693 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5695                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5696 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5697         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5698                         mode, "mode");
5699 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5700         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5701                         mode_value, "normal#bypass#isolate");
5702 cmdline_parse_token_num_t cmd_setbypass_event_port =
5703         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5704                                 port_id, RTE_UINT16);
5705
5706 cmdline_parse_inst_t cmd_set_bypass_event = {
5707         .f = cmd_set_bypass_event_parsed,
5708         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5709                 "power_off mode normal|bypass|isolate <port_id>: "
5710                 "Set the NIC bypass event mode for port_id",
5711         .data = NULL,
5712         .tokens = {
5713                 (void *)&cmd_setbypass_event_set,
5714                 (void *)&cmd_setbypass_event_bypass,
5715                 (void *)&cmd_setbypass_event_event,
5716                 (void *)&cmd_setbypass_event_event_value,
5717                 (void *)&cmd_setbypass_event_mode,
5718                 (void *)&cmd_setbypass_event_mode_value,
5719                 (void *)&cmd_setbypass_event_port,
5720                 NULL,
5721         },
5722 };
5723
5724
5725 /* *** SET NIC BYPASS TIMEOUT *** */
5726 struct cmd_set_bypass_timeout_result {
5727         cmdline_fixed_string_t set;
5728         cmdline_fixed_string_t bypass;
5729         cmdline_fixed_string_t timeout;
5730         cmdline_fixed_string_t value;
5731 };
5732
5733 static void
5734 cmd_set_bypass_timeout_parsed(void *parsed_result,
5735                 __rte_unused struct cmdline *cl,
5736                 __rte_unused void *data)
5737 {
5738         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5739
5740 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5741         if (!strcmp(res->value, "1.5"))
5742                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5743         else if (!strcmp(res->value, "2"))
5744                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5745         else if (!strcmp(res->value, "3"))
5746                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5747         else if (!strcmp(res->value, "4"))
5748                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5749         else if (!strcmp(res->value, "8"))
5750                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5751         else if (!strcmp(res->value, "16"))
5752                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5753         else if (!strcmp(res->value, "32"))
5754                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5755         else
5756                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5757 #endif
5758 }
5759
5760 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5761         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5762                         set, "set");
5763 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5765                         bypass, "bypass");
5766 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5768                         timeout, "timeout");
5769 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5770         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5771                         value, "0#1.5#2#3#4#8#16#32");
5772
5773 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5774         .f = cmd_set_bypass_timeout_parsed,
5775         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5776                 "Set the NIC bypass watchdog timeout in seconds",
5777         .data = NULL,
5778         .tokens = {
5779                 (void *)&cmd_setbypass_timeout_set,
5780                 (void *)&cmd_setbypass_timeout_bypass,
5781                 (void *)&cmd_setbypass_timeout_timeout,
5782                 (void *)&cmd_setbypass_timeout_value,
5783                 NULL,
5784         },
5785 };
5786
5787 /* *** SHOW NIC BYPASS MODE *** */
5788 struct cmd_show_bypass_config_result {
5789         cmdline_fixed_string_t show;
5790         cmdline_fixed_string_t bypass;
5791         cmdline_fixed_string_t config;
5792         portid_t port_id;
5793 };
5794
5795 static void
5796 cmd_show_bypass_config_parsed(void *parsed_result,
5797                 __rte_unused struct cmdline *cl,
5798                 __rte_unused void *data)
5799 {
5800         struct cmd_show_bypass_config_result *res = parsed_result;
5801         portid_t port_id = res->port_id;
5802         int rc = -EINVAL;
5803 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5804         uint32_t event_mode;
5805         uint32_t bypass_mode;
5806         uint32_t timeout = bypass_timeout;
5807         unsigned int i;
5808
5809         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5810                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5811         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5812                 {"UNKNOWN", "normal", "bypass", "isolate"};
5813         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5814                 "NONE",
5815                 "OS/board on",
5816                 "power supply on",
5817                 "OS/board off",
5818                 "power supply off",
5819                 "timeout"};
5820
5821         /* Display the bypass mode.*/
5822         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5823                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5824                         port_id);
5825                 return;
5826         }
5827         else {
5828                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5829                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5830
5831                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5832         }
5833
5834         /* Display the bypass timeout.*/
5835         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5836                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5837
5838         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5839
5840         /* Display the bypass events and associated modes. */
5841         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5842
5843                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5844                         fprintf(stderr,
5845                                 "\tFailed to get bypass mode for event = %s\n",
5846                                 events[i]);
5847                 } else {
5848                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5849                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5850
5851                         printf("\tbypass event: %-16s = %s\n", events[i],
5852                                 modes[event_mode]);
5853                 }
5854         }
5855 #endif
5856         if (rc != 0)
5857                 fprintf(stderr,
5858                         "\tFailed to get bypass configuration for port = %d\n",
5859                        port_id);
5860 }
5861
5862 cmdline_parse_token_string_t cmd_showbypass_config_show =
5863         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5864                         show, "show");
5865 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5866         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5867                         bypass, "bypass");
5868 cmdline_parse_token_string_t cmd_showbypass_config_config =
5869         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5870                         config, "config");
5871 cmdline_parse_token_num_t cmd_showbypass_config_port =
5872         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5873                                 port_id, RTE_UINT16);
5874
5875 cmdline_parse_inst_t cmd_show_bypass_config = {
5876         .f = cmd_show_bypass_config_parsed,
5877         .help_str = "show bypass config <port_id>: "
5878                     "Show the NIC bypass config for port_id",
5879         .data = NULL,
5880         .tokens = {
5881                 (void *)&cmd_showbypass_config_show,
5882                 (void *)&cmd_showbypass_config_bypass,
5883                 (void *)&cmd_showbypass_config_config,
5884                 (void *)&cmd_showbypass_config_port,
5885                 NULL,
5886         },
5887 };
5888
5889 #ifdef RTE_NET_BOND
5890 /* *** SET BONDING MODE *** */
5891 struct cmd_set_bonding_mode_result {
5892         cmdline_fixed_string_t set;
5893         cmdline_fixed_string_t bonding;
5894         cmdline_fixed_string_t mode;
5895         uint8_t value;
5896         portid_t port_id;
5897 };
5898
5899 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5900                 __rte_unused  struct cmdline *cl,
5901                 __rte_unused void *data)
5902 {
5903         struct cmd_set_bonding_mode_result *res = parsed_result;
5904         portid_t port_id = res->port_id;
5905
5906         /* Set the bonding mode for the relevant port. */
5907         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5908                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5909                         port_id);
5910 }
5911
5912 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5913 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5914                 set, "set");
5915 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5916 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5917                 bonding, "bonding");
5918 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5919 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5920                 mode, "mode");
5921 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5922 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5923                 value, RTE_UINT8);
5924 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5925 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5926                 port_id, RTE_UINT16);
5927
5928 cmdline_parse_inst_t cmd_set_bonding_mode = {
5929                 .f = cmd_set_bonding_mode_parsed,
5930                 .help_str = "set bonding mode <mode_value> <port_id>: "
5931                         "Set the bonding mode for port_id",
5932                 .data = NULL,
5933                 .tokens = {
5934                                 (void *) &cmd_setbonding_mode_set,
5935                                 (void *) &cmd_setbonding_mode_bonding,
5936                                 (void *) &cmd_setbonding_mode_mode,
5937                                 (void *) &cmd_setbonding_mode_value,
5938                                 (void *) &cmd_setbonding_mode_port,
5939                                 NULL
5940                 }
5941 };
5942
5943 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5944 struct cmd_set_bonding_lacp_dedicated_queues_result {
5945         cmdline_fixed_string_t set;
5946         cmdline_fixed_string_t bonding;
5947         cmdline_fixed_string_t lacp;
5948         cmdline_fixed_string_t dedicated_queues;
5949         portid_t port_id;
5950         cmdline_fixed_string_t mode;
5951 };
5952
5953 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5954                 __rte_unused  struct cmdline *cl,
5955                 __rte_unused void *data)
5956 {
5957         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5958         portid_t port_id = res->port_id;
5959         struct rte_port *port;
5960
5961         port = &ports[port_id];
5962
5963         /** Check if the port is not started **/
5964         if (port->port_status != RTE_PORT_STOPPED) {
5965                 fprintf(stderr, "Please stop port %d first\n", port_id);
5966                 return;
5967         }
5968
5969         if (!strcmp(res->mode, "enable")) {
5970                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5971                         printf("Dedicate queues for LACP control packets"
5972                                         " enabled\n");
5973                 else
5974                         printf("Enabling dedicate queues for LACP control "
5975                                         "packets on port %d failed\n", port_id);
5976         } else if (!strcmp(res->mode, "disable")) {
5977                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5978                         printf("Dedicated queues for LACP control packets "
5979                                         "disabled\n");
5980                 else
5981                         printf("Disabling dedicated queues for LACP control "
5982                                         "traffic on port %d failed\n", port_id);
5983         }
5984 }
5985
5986 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5987 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5988                 set, "set");
5989 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5990 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5991                 bonding, "bonding");
5992 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5993 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5994                 lacp, "lacp");
5995 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5996 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5997                 dedicated_queues, "dedicated_queues");
5998 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5999 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6000                 port_id, RTE_UINT16);
6001 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6002 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6003                 mode, "enable#disable");
6004
6005 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6006                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6007                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6008                         "enable|disable: "
6009                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6010                 .data = NULL,
6011                 .tokens = {
6012                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6013                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6014                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6015                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6016                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6017                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6018                         NULL
6019                 }
6020 };
6021
6022 /* *** SET BALANCE XMIT POLICY *** */
6023 struct cmd_set_bonding_balance_xmit_policy_result {
6024         cmdline_fixed_string_t set;
6025         cmdline_fixed_string_t bonding;
6026         cmdline_fixed_string_t balance_xmit_policy;
6027         portid_t port_id;
6028         cmdline_fixed_string_t policy;
6029 };
6030
6031 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6032                 __rte_unused  struct cmdline *cl,
6033                 __rte_unused void *data)
6034 {
6035         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6036         portid_t port_id = res->port_id;
6037         uint8_t policy;
6038
6039         if (!strcmp(res->policy, "l2")) {
6040                 policy = BALANCE_XMIT_POLICY_LAYER2;
6041         } else if (!strcmp(res->policy, "l23")) {
6042                 policy = BALANCE_XMIT_POLICY_LAYER23;
6043         } else if (!strcmp(res->policy, "l34")) {
6044                 policy = BALANCE_XMIT_POLICY_LAYER34;
6045         } else {
6046                 fprintf(stderr, "\t Invalid xmit policy selection");
6047                 return;
6048         }
6049
6050         /* Set the bonding mode for the relevant port. */
6051         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6052                 fprintf(stderr,
6053                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6054                         port_id);
6055         }
6056 }
6057
6058 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6059 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6060                 set, "set");
6061 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6062 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6063                 bonding, "bonding");
6064 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6065 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6066                 balance_xmit_policy, "balance_xmit_policy");
6067 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6068 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6069                 port_id, RTE_UINT16);
6070 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6071 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6072                 policy, "l2#l23#l34");
6073
6074 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6075                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6076                 .help_str = "set bonding balance_xmit_policy <port_id> "
6077                         "l2|l23|l34: "
6078                         "Set the bonding balance_xmit_policy for port_id",
6079                 .data = NULL,
6080                 .tokens = {
6081                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6082                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6083                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6084                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6085                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6086                                 NULL
6087                 }
6088 };
6089
6090 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6091 struct cmd_show_bonding_lacp_info_result {
6092         cmdline_fixed_string_t show;
6093         cmdline_fixed_string_t bonding;
6094         cmdline_fixed_string_t lacp;
6095         cmdline_fixed_string_t info;
6096         portid_t port_id;
6097 };
6098
6099 static void port_param_show(struct port_params *params)
6100 {
6101         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6102
6103         printf("\t\tsystem priority: %u\n", params->system_priority);
6104         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6105         printf("\t\tsystem mac address: %s\n", buf);
6106         printf("\t\tport key: %u\n", params->key);
6107         printf("\t\tport priority: %u\n", params->port_priority);
6108         printf("\t\tport number: %u\n", params->port_number);
6109 }
6110
6111 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6112 {
6113         char a_state[256] = { 0 };
6114         char p_state[256] = { 0 };
6115         int a_len = 0;
6116         int p_len = 0;
6117         uint32_t i;
6118
6119         static const char * const state[] = {
6120                 "ACTIVE",
6121                 "TIMEOUT",
6122                 "AGGREGATION",
6123                 "SYNCHRONIZATION",
6124                 "COLLECTING",
6125                 "DISTRIBUTING",
6126                 "DEFAULTED",
6127                 "EXPIRED"
6128         };
6129         static const char * const selection[] = {
6130                 "UNSELECTED",
6131                 "STANDBY",
6132                 "SELECTED"
6133         };
6134
6135         for (i = 0; i < RTE_DIM(state); i++) {
6136                 if ((info->actor_state >> i) & 1)
6137                         a_len += snprintf(&a_state[a_len],
6138                                                 RTE_DIM(a_state) - a_len, "%s ",
6139                                                 state[i]);
6140
6141                 if ((info->partner_state >> i) & 1)
6142                         p_len += snprintf(&p_state[p_len],
6143                                                 RTE_DIM(p_state) - p_len, "%s ",
6144                                                 state[i]);
6145         }
6146         printf("\tAggregator port id: %u\n", info->agg_port_id);
6147         printf("\tselection: %s\n", selection[info->selected]);
6148         printf("\tActor detail info:\n");
6149         port_param_show(&info->actor);
6150         printf("\t\tport state: %s\n", a_state);
6151         printf("\tPartner detail info:\n");
6152         port_param_show(&info->partner);
6153         printf("\t\tport state: %s\n", p_state);
6154         printf("\n");
6155 }
6156
6157 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6158 {
6159         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6160         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6161         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6162         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6163         printf("\taggregate wait timeout: %u ms\n",
6164                         conf->aggregate_wait_timeout_ms);
6165         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6166         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6167         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6168         switch (conf->agg_selection) {
6169         case AGG_BANDWIDTH:
6170                 printf("\taggregation mode: bandwidth\n");
6171                 break;
6172         case AGG_STABLE:
6173                 printf("\taggregation mode: stable\n");
6174                 break;
6175         case AGG_COUNT:
6176                 printf("\taggregation mode: count\n");
6177                 break;
6178         default:
6179                 printf("\taggregation mode: invalid\n");
6180                 break;
6181         }
6182
6183         printf("\n");
6184 }
6185
6186 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6187                 __rte_unused  struct cmdline *cl,
6188                 __rte_unused void *data)
6189 {
6190         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6191         struct rte_eth_bond_8023ad_slave_info slave_info;
6192         struct rte_eth_bond_8023ad_conf port_conf;
6193         portid_t slaves[RTE_MAX_ETHPORTS];
6194         portid_t port_id = res->port_id;
6195         int num_active_slaves;
6196         int bonding_mode;
6197         int i;
6198         int ret;
6199
6200         bonding_mode = rte_eth_bond_mode_get(port_id);
6201         if (bonding_mode != BONDING_MODE_8023AD) {
6202                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6203                 return;
6204         }
6205
6206         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6207                         RTE_MAX_ETHPORTS);
6208         if (num_active_slaves < 0) {
6209                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6210                                 port_id);
6211                 return;
6212         }
6213         if (num_active_slaves == 0)
6214                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6215                         port_id);
6216
6217         printf("\tIEEE802.3 port: %u\n", port_id);
6218         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6219         if (ret) {
6220                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6221                         port_id);
6222                 return;
6223         }
6224         lacp_conf_show(&port_conf);
6225
6226         for (i = 0; i < num_active_slaves; i++) {
6227                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6228                                 &slave_info);
6229                 if (ret) {
6230                         fprintf(stderr, "\tGet slave device %u info failed\n",
6231                                 slaves[i]);
6232                         return;
6233                 }
6234                 printf("\tSlave Port: %u\n", slaves[i]);
6235                 lacp_slave_info_show(&slave_info);
6236         }
6237 }
6238
6239 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6240 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6241                 show, "show");
6242 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6243 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6244                 bonding, "bonding");
6245 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6246 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6247                 bonding, "lacp");
6248 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6249 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6250                 info, "info");
6251 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6252 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6253                 port_id, RTE_UINT16);
6254
6255 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6256                 .f = cmd_show_bonding_lacp_info_parsed,
6257                 .help_str = "show bonding lacp info <port_id> : "
6258                         "Show bonding IEEE802.3 information for port_id",
6259                 .data = NULL,
6260                 .tokens = {
6261                         (void *)&cmd_show_bonding_lacp_info_show,
6262                         (void *)&cmd_show_bonding_lacp_info_bonding,
6263                         (void *)&cmd_show_bonding_lacp_info_lacp,
6264                         (void *)&cmd_show_bonding_lacp_info_info,
6265                         (void *)&cmd_show_bonding_lacp_info_port_id,
6266                         NULL
6267                 }
6268 };
6269
6270 /* *** SHOW NIC BONDING CONFIGURATION *** */
6271 struct cmd_show_bonding_config_result {
6272         cmdline_fixed_string_t show;
6273         cmdline_fixed_string_t bonding;
6274         cmdline_fixed_string_t config;
6275         portid_t port_id;
6276 };
6277
6278 static void cmd_show_bonding_config_parsed(void *parsed_result,
6279                 __rte_unused  struct cmdline *cl,
6280                 __rte_unused void *data)
6281 {
6282         struct cmd_show_bonding_config_result *res = parsed_result;
6283         int bonding_mode, agg_mode;
6284         portid_t slaves[RTE_MAX_ETHPORTS];
6285         int num_slaves, num_active_slaves;
6286         int primary_id;
6287         int i;
6288         portid_t port_id = res->port_id;
6289
6290         /* Display the bonding mode.*/
6291         bonding_mode = rte_eth_bond_mode_get(port_id);
6292         if (bonding_mode < 0) {
6293                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6294                         port_id);
6295                 return;
6296         } else
6297                 printf("\tBonding mode: %d\n", bonding_mode);
6298
6299         if (bonding_mode == BONDING_MODE_BALANCE ||
6300                 bonding_mode == BONDING_MODE_8023AD) {
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_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7231                 rx_fc_en = true;
7232         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_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_ETH_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_ETH_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_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_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_ETH_FC_RX_PAUSE) ||
7529                     (fc_conf.mode == RTE_ETH_FC_FULL))
7530                         rx_fc_en = 1;
7531                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7532                     (fc_conf.mode == RTE_ETH_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_ETH_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_ETH_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_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_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 |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9254                 else if (!strcmp(res->mode, "ROPE"))
9255                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9256                 else if (!strcmp(res->mode, "BAM"))
9257                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9258                 else if (!strncmp(res->mode, "MPE",3))
9259                         vf_rxmode |= RTE_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_ETH_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_ETH_TUNNEL_TYPE_VXLAN;
9726         } else if (!strcmp(res->tunnel_type, "geneve")) {
9727                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9728         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9729                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9730         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9731                 tunnel_udp.prot_type = RTE_ETH_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                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10442                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10443                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10444                 {"gtpu", RTE_ETH_FLOW_GTPU},
10445         };
10446
10447         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10448                 if (!strcmp(flowtype_str[i].str, string))
10449                         return flowtype_str[i].type;
10450         }
10451
10452         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10453                 return (uint16_t)atoi(string);
10454
10455         return RTE_ETH_FLOW_UNKNOWN;
10456 }
10457
10458 /* *** deal with flow director filter *** */
10459 struct cmd_flow_director_result {
10460         cmdline_fixed_string_t flow_director_filter;
10461         portid_t port_id;
10462         cmdline_fixed_string_t mode;
10463         cmdline_fixed_string_t mode_value;
10464         cmdline_fixed_string_t ops;
10465         cmdline_fixed_string_t flow;
10466         cmdline_fixed_string_t flow_type;
10467         cmdline_fixed_string_t drop;
10468         cmdline_fixed_string_t queue;
10469         uint16_t  queue_id;
10470         cmdline_fixed_string_t fd_id;
10471         uint32_t  fd_id_value;
10472         cmdline_fixed_string_t packet;
10473         char filepath[];
10474 };
10475
10476 static void
10477 cmd_flow_director_filter_parsed(void *parsed_result,
10478                           __rte_unused struct cmdline *cl,
10479                           __rte_unused void *data)
10480 {
10481         struct cmd_flow_director_result *res = parsed_result;
10482         int ret = 0;
10483         struct rte_pmd_i40e_flow_type_mapping
10484                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10485         struct rte_pmd_i40e_pkt_template_conf conf;
10486         uint16_t flow_type = str2flowtype(res->flow_type);
10487         uint16_t i, port = res->port_id;
10488         uint8_t add;
10489
10490         memset(&conf, 0, sizeof(conf));
10491
10492         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10493                 fprintf(stderr, "Invalid flow type specified.\n");
10494                 return;
10495         }
10496         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10497                                                  mapping);
10498         if (ret)
10499                 return;
10500         if (mapping[flow_type].pctype == 0ULL) {
10501                 fprintf(stderr, "Invalid flow type specified.\n");
10502                 return;
10503         }
10504         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10505                 if (mapping[flow_type].pctype & (1ULL << i)) {
10506                         conf.input.pctype = i;
10507                         break;
10508                 }
10509         }
10510
10511         conf.input.packet = open_file(res->filepath,
10512                                 &conf.input.length);
10513         if (!conf.input.packet)
10514                 return;
10515         if (!strcmp(res->drop, "drop"))
10516                 conf.action.behavior =
10517                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10518         else
10519                 conf.action.behavior =
10520                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10521         conf.action.report_status =
10522                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10523         conf.action.rx_queue = res->queue_id;
10524         conf.soft_id = res->fd_id_value;
10525         add  = strcmp(res->ops, "del") ? 1 : 0;
10526         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10527                                                         &conf,
10528                                                         add);
10529         if (ret < 0)
10530                 fprintf(stderr, "flow director config error: (%s)\n",
10531                         strerror(-ret));
10532         close_file(conf.input.packet);
10533 }
10534
10535 cmdline_parse_token_string_t cmd_flow_director_filter =
10536         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10537                                  flow_director_filter, "flow_director_filter");
10538 cmdline_parse_token_num_t cmd_flow_director_port_id =
10539         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10540                               port_id, RTE_UINT16);
10541 cmdline_parse_token_string_t cmd_flow_director_ops =
10542         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10543                                  ops, "add#del#update");
10544 cmdline_parse_token_string_t cmd_flow_director_flow =
10545         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10546                                  flow, "flow");
10547 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10548         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10549                 flow_type, NULL);
10550 cmdline_parse_token_string_t cmd_flow_director_drop =
10551         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10552                                  drop, "drop#fwd");
10553 cmdline_parse_token_string_t cmd_flow_director_queue =
10554         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10555                                  queue, "queue");
10556 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10557         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10558                               queue_id, RTE_UINT16);
10559 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10560         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10561                                  fd_id, "fd_id");
10562 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10563         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10564                               fd_id_value, RTE_UINT32);
10565
10566 cmdline_parse_token_string_t cmd_flow_director_mode =
10567         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10568                                  mode, "mode");
10569 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10571                                  mode_value, "raw");
10572 cmdline_parse_token_string_t cmd_flow_director_packet =
10573         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10574                                  packet, "packet");
10575 cmdline_parse_token_string_t cmd_flow_director_filepath =
10576         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10577                                  filepath, NULL);
10578
10579 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10580         .f = cmd_flow_director_filter_parsed,
10581         .data = NULL,
10582         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10583                 "director entry on NIC",
10584         .tokens = {
10585                 (void *)&cmd_flow_director_filter,
10586                 (void *)&cmd_flow_director_port_id,
10587                 (void *)&cmd_flow_director_mode,
10588                 (void *)&cmd_flow_director_mode_raw,
10589                 (void *)&cmd_flow_director_ops,
10590                 (void *)&cmd_flow_director_flow,
10591                 (void *)&cmd_flow_director_flow_type,
10592                 (void *)&cmd_flow_director_drop,
10593                 (void *)&cmd_flow_director_queue,
10594                 (void *)&cmd_flow_director_queue_id,
10595                 (void *)&cmd_flow_director_fd_id,
10596                 (void *)&cmd_flow_director_fd_id_value,
10597                 (void *)&cmd_flow_director_packet,
10598                 (void *)&cmd_flow_director_filepath,
10599                 NULL,
10600         },
10601 };
10602
10603 #endif /* RTE_NET_I40E */
10604
10605 /* *** deal with flow director mask *** */
10606 struct cmd_flow_director_mask_result {
10607         cmdline_fixed_string_t flow_director_mask;
10608         portid_t port_id;
10609         cmdline_fixed_string_t mode;
10610         cmdline_fixed_string_t mode_value;
10611         cmdline_fixed_string_t vlan;
10612         uint16_t vlan_mask;
10613         cmdline_fixed_string_t src_mask;
10614         cmdline_ipaddr_t ipv4_src;
10615         cmdline_ipaddr_t ipv6_src;
10616         uint16_t port_src;
10617         cmdline_fixed_string_t dst_mask;
10618         cmdline_ipaddr_t ipv4_dst;
10619         cmdline_ipaddr_t ipv6_dst;
10620         uint16_t port_dst;
10621         cmdline_fixed_string_t mac;
10622         uint8_t mac_addr_byte_mask;
10623         cmdline_fixed_string_t tunnel_id;
10624         uint32_t tunnel_id_mask;
10625         cmdline_fixed_string_t tunnel_type;
10626         uint8_t tunnel_type_mask;
10627 };
10628
10629 static void
10630 cmd_flow_director_mask_parsed(void *parsed_result,
10631                           __rte_unused struct cmdline *cl,
10632                           __rte_unused void *data)
10633 {
10634         struct cmd_flow_director_mask_result *res = parsed_result;
10635         struct rte_eth_fdir_masks *mask;
10636         struct rte_port *port;
10637
10638         port = &ports[res->port_id];
10639         /** Check if the port is not started **/
10640         if (port->port_status != RTE_PORT_STOPPED) {
10641                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10642                 return;
10643         }
10644
10645         mask = &port->dev_conf.fdir_conf.mask;
10646
10647         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10648                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10649                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10650                         return;
10651                 }
10652
10653                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10654         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10655                 if (strcmp(res->mode_value, "Tunnel")) {
10656                         fprintf(stderr, "Please set mode to Tunnel.\n");
10657                         return;
10658                 }
10659
10660                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10661                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10662                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10663                 mask->tunnel_type_mask = res->tunnel_type_mask;
10664         } else {
10665                 if (strcmp(res->mode_value, "IP")) {
10666                         fprintf(stderr, "Please set mode to IP.\n");
10667                         return;
10668                 }
10669
10670                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10671                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10672                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10673                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10674                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10675                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10676                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10677         }
10678
10679         cmd_reconfig_device_queue(res->port_id, 1, 1);
10680 }
10681
10682 cmdline_parse_token_string_t cmd_flow_director_mask =
10683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10684                                  flow_director_mask, "flow_director_mask");
10685 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10686         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10687                               port_id, RTE_UINT16);
10688 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10690                                  vlan, "vlan");
10691 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10692         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10693                               vlan_mask, RTE_UINT16);
10694 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10696                                  src_mask, "src_mask");
10697 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10698         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10699                                  ipv4_src);
10700 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10701         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10702                                  ipv6_src);
10703 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10704         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10705                               port_src, RTE_UINT16);
10706 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10707         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10708                                  dst_mask, "dst_mask");
10709 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10710         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10711                                  ipv4_dst);
10712 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10713         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10714                                  ipv6_dst);
10715 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10716         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10717                               port_dst, RTE_UINT16);
10718
10719 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10721                                  mode, "mode");
10722 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10723         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10724                                  mode_value, "IP");
10725 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10727                                  mode_value, "MAC-VLAN");
10728 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10730                                  mode_value, "Tunnel");
10731 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10732         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10733                                  mac, "mac");
10734 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10735         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10736                               mac_addr_byte_mask, RTE_UINT8);
10737 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10738         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10739                                  tunnel_type, "tunnel-type");
10740 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10741         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10742                               tunnel_type_mask, RTE_UINT8);
10743 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10744         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10745                                  tunnel_id, "tunnel-id");
10746 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10747         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10748                               tunnel_id_mask, RTE_UINT32);
10749
10750 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10751         .f = cmd_flow_director_mask_parsed,
10752         .data = NULL,
10753         .help_str = "flow_director_mask ... : "
10754                 "Set IP mode flow director's mask on NIC",
10755         .tokens = {
10756                 (void *)&cmd_flow_director_mask,
10757                 (void *)&cmd_flow_director_mask_port_id,
10758                 (void *)&cmd_flow_director_mask_mode,
10759                 (void *)&cmd_flow_director_mask_mode_ip,
10760                 (void *)&cmd_flow_director_mask_vlan,
10761                 (void *)&cmd_flow_director_mask_vlan_value,
10762                 (void *)&cmd_flow_director_mask_src,
10763                 (void *)&cmd_flow_director_mask_ipv4_src,
10764                 (void *)&cmd_flow_director_mask_ipv6_src,
10765                 (void *)&cmd_flow_director_mask_port_src,
10766                 (void *)&cmd_flow_director_mask_dst,
10767                 (void *)&cmd_flow_director_mask_ipv4_dst,
10768                 (void *)&cmd_flow_director_mask_ipv6_dst,
10769                 (void *)&cmd_flow_director_mask_port_dst,
10770                 NULL,
10771         },
10772 };
10773
10774 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10775         .f = cmd_flow_director_mask_parsed,
10776         .data = NULL,
10777         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10778                 "flow director's mask on NIC",
10779         .tokens = {
10780                 (void *)&cmd_flow_director_mask,
10781                 (void *)&cmd_flow_director_mask_port_id,
10782                 (void *)&cmd_flow_director_mask_mode,
10783                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10784                 (void *)&cmd_flow_director_mask_vlan,
10785                 (void *)&cmd_flow_director_mask_vlan_value,
10786                 NULL,
10787         },
10788 };
10789
10790 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10791         .f = cmd_flow_director_mask_parsed,
10792         .data = NULL,
10793         .help_str = "flow_director_mask ... : Set tunnel mode "
10794                 "flow director's mask on NIC",
10795         .tokens = {
10796                 (void *)&cmd_flow_director_mask,
10797                 (void *)&cmd_flow_director_mask_port_id,
10798                 (void *)&cmd_flow_director_mask_mode,
10799                 (void *)&cmd_flow_director_mask_mode_tunnel,
10800                 (void *)&cmd_flow_director_mask_vlan,
10801                 (void *)&cmd_flow_director_mask_vlan_value,
10802                 (void *)&cmd_flow_director_mask_mac,
10803                 (void *)&cmd_flow_director_mask_mac_value,
10804                 (void *)&cmd_flow_director_mask_tunnel_type,
10805                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10806                 (void *)&cmd_flow_director_mask_tunnel_id,
10807                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10808                 NULL,
10809         },
10810 };
10811
10812 /* *** deal with flow director flexible payload configuration *** */
10813 struct cmd_flow_director_flexpayload_result {
10814         cmdline_fixed_string_t flow_director_flexpayload;
10815         portid_t port_id;
10816         cmdline_fixed_string_t payload_layer;
10817         cmdline_fixed_string_t payload_cfg;
10818 };
10819
10820 static inline int
10821 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10822 {
10823         char s[256];
10824         const char *p, *p0 = q_arg;
10825         char *end;
10826         unsigned long int_fld;
10827         char *str_fld[max_num];
10828         int i;
10829         unsigned size;
10830         int ret = -1;
10831
10832         p = strchr(p0, '(');
10833         if (p == NULL)
10834                 return -1;
10835         ++p;
10836         p0 = strchr(p, ')');
10837         if (p0 == NULL)
10838                 return -1;
10839
10840         size = p0 - p;
10841         if (size >= sizeof(s))
10842                 return -1;
10843
10844         snprintf(s, sizeof(s), "%.*s", size, p);
10845         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10846         if (ret < 0 || ret > max_num)
10847                 return -1;
10848         for (i = 0; i < ret; i++) {
10849                 errno = 0;
10850                 int_fld = strtoul(str_fld[i], &end, 0);
10851                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10852                         return -1;
10853                 offsets[i] = (uint16_t)int_fld;
10854         }
10855         return ret;
10856 }
10857
10858 static void
10859 cmd_flow_director_flxpld_parsed(void *parsed_result,
10860                           __rte_unused struct cmdline *cl,
10861                           __rte_unused void *data)
10862 {
10863         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10864         struct rte_eth_flex_payload_cfg flex_cfg;
10865         struct rte_port *port;
10866         int ret = 0;
10867
10868         port = &ports[res->port_id];
10869         /** Check if the port is not started **/
10870         if (port->port_status != RTE_PORT_STOPPED) {
10871                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10872                 return;
10873         }
10874
10875         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10876
10877         if (!strcmp(res->payload_layer, "raw"))
10878                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10879         else if (!strcmp(res->payload_layer, "l2"))
10880                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10881         else if (!strcmp(res->payload_layer, "l3"))
10882                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10883         else if (!strcmp(res->payload_layer, "l4"))
10884                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10885
10886         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10887                             RTE_ETH_FDIR_MAX_FLEXLEN);
10888         if (ret < 0) {
10889                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
10890                 return;
10891         }
10892
10893         fdir_set_flex_payload(res->port_id, &flex_cfg);
10894         cmd_reconfig_device_queue(res->port_id, 1, 1);
10895 }
10896
10897 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10898         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10899                                  flow_director_flexpayload,
10900                                  "flow_director_flex_payload");
10901 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10902         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10903                               port_id, RTE_UINT16);
10904 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10905         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10906                                  payload_layer, "raw#l2#l3#l4");
10907 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10909                                  payload_cfg, NULL);
10910
10911 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10912         .f = cmd_flow_director_flxpld_parsed,
10913         .data = NULL,
10914         .help_str = "flow_director_flexpayload ... : "
10915                 "Set flow director's flex payload on NIC",
10916         .tokens = {
10917                 (void *)&cmd_flow_director_flexpayload,
10918                 (void *)&cmd_flow_director_flexpayload_port_id,
10919                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10920                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10921                 NULL,
10922         },
10923 };
10924
10925 /* Generic flow interface command. */
10926 extern cmdline_parse_inst_t cmd_flow;
10927
10928 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10929 struct cmd_mcast_addr_result {
10930         cmdline_fixed_string_t mcast_addr_cmd;
10931         cmdline_fixed_string_t what;
10932         uint16_t port_num;
10933         struct rte_ether_addr mc_addr;
10934 };
10935
10936 static void cmd_mcast_addr_parsed(void *parsed_result,
10937                 __rte_unused struct cmdline *cl,
10938                 __rte_unused void *data)
10939 {
10940         struct cmd_mcast_addr_result *res = parsed_result;
10941
10942         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10943                 fprintf(stderr,
10944                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
10945                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
10946                 return;
10947         }
10948         if (strcmp(res->what, "add") == 0)
10949                 mcast_addr_add(res->port_num, &res->mc_addr);
10950         else
10951                 mcast_addr_remove(res->port_num, &res->mc_addr);
10952 }
10953
10954 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10955         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10956                                  mcast_addr_cmd, "mcast_addr");
10957 cmdline_parse_token_string_t cmd_mcast_addr_what =
10958         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10959                                  "add#remove");
10960 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10961         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10962                                  RTE_UINT16);
10963 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10964         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10965
10966 cmdline_parse_inst_t cmd_mcast_addr = {
10967         .f = cmd_mcast_addr_parsed,
10968         .data = (void *)0,
10969         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10970                 "Add/Remove multicast MAC address on port_id",
10971         .tokens = {
10972                 (void *)&cmd_mcast_addr_cmd,
10973                 (void *)&cmd_mcast_addr_what,
10974                 (void *)&cmd_mcast_addr_portnum,
10975                 (void *)&cmd_mcast_addr_addr,
10976                 NULL,
10977         },
10978 };
10979
10980 /* vf vlan anti spoof configuration */
10981
10982 /* Common result structure for vf vlan anti spoof */
10983 struct cmd_vf_vlan_anti_spoof_result {
10984         cmdline_fixed_string_t set;
10985         cmdline_fixed_string_t vf;
10986         cmdline_fixed_string_t vlan;
10987         cmdline_fixed_string_t antispoof;
10988         portid_t port_id;
10989         uint32_t vf_id;
10990         cmdline_fixed_string_t on_off;
10991 };
10992
10993 /* Common CLI fields for vf vlan anti spoof enable disable */
10994 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
10995         TOKEN_STRING_INITIALIZER
10996                 (struct cmd_vf_vlan_anti_spoof_result,
10997                  set, "set");
10998 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
10999         TOKEN_STRING_INITIALIZER
11000                 (struct cmd_vf_vlan_anti_spoof_result,
11001                  vf, "vf");
11002 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11003         TOKEN_STRING_INITIALIZER
11004                 (struct cmd_vf_vlan_anti_spoof_result,
11005                  vlan, "vlan");
11006 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11007         TOKEN_STRING_INITIALIZER
11008                 (struct cmd_vf_vlan_anti_spoof_result,
11009                  antispoof, "antispoof");
11010 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11011         TOKEN_NUM_INITIALIZER
11012                 (struct cmd_vf_vlan_anti_spoof_result,
11013                  port_id, RTE_UINT16);
11014 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11015         TOKEN_NUM_INITIALIZER
11016                 (struct cmd_vf_vlan_anti_spoof_result,
11017                  vf_id, RTE_UINT32);
11018 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11019         TOKEN_STRING_INITIALIZER
11020                 (struct cmd_vf_vlan_anti_spoof_result,
11021                  on_off, "on#off");
11022
11023 static void
11024 cmd_set_vf_vlan_anti_spoof_parsed(
11025         void *parsed_result,
11026         __rte_unused struct cmdline *cl,
11027         __rte_unused void *data)
11028 {
11029         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11030         int ret = -ENOTSUP;
11031
11032         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11033
11034         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11035                 return;
11036
11037 #ifdef RTE_NET_IXGBE
11038         if (ret == -ENOTSUP)
11039                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11040                                 res->vf_id, is_on);
11041 #endif
11042 #ifdef RTE_NET_I40E
11043         if (ret == -ENOTSUP)
11044                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11045                                 res->vf_id, is_on);
11046 #endif
11047 #ifdef RTE_NET_BNXT
11048         if (ret == -ENOTSUP)
11049                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11050                                 res->vf_id, is_on);
11051 #endif
11052
11053         switch (ret) {
11054         case 0:
11055                 break;
11056         case -EINVAL:
11057                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11058                 break;
11059         case -ENODEV:
11060                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11061                 break;
11062         case -ENOTSUP:
11063                 fprintf(stderr, "function not implemented\n");
11064                 break;
11065         default:
11066                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11067         }
11068 }
11069
11070 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11071         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11072         .data = NULL,
11073         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11074         .tokens = {
11075                 (void *)&cmd_vf_vlan_anti_spoof_set,
11076                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11077                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11078                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11079                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11080                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11081                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11082                 NULL,
11083         },
11084 };
11085
11086 /* vf mac anti spoof configuration */
11087
11088 /* Common result structure for vf mac anti spoof */
11089 struct cmd_vf_mac_anti_spoof_result {
11090         cmdline_fixed_string_t set;
11091         cmdline_fixed_string_t vf;
11092         cmdline_fixed_string_t mac;
11093         cmdline_fixed_string_t antispoof;
11094         portid_t port_id;
11095         uint32_t vf_id;
11096         cmdline_fixed_string_t on_off;
11097 };
11098
11099 /* Common CLI fields for vf mac anti spoof enable disable */
11100 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11101         TOKEN_STRING_INITIALIZER
11102                 (struct cmd_vf_mac_anti_spoof_result,
11103                  set, "set");
11104 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11105         TOKEN_STRING_INITIALIZER
11106                 (struct cmd_vf_mac_anti_spoof_result,
11107                  vf, "vf");
11108 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11109         TOKEN_STRING_INITIALIZER
11110                 (struct cmd_vf_mac_anti_spoof_result,
11111                  mac, "mac");
11112 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11113         TOKEN_STRING_INITIALIZER
11114                 (struct cmd_vf_mac_anti_spoof_result,
11115                  antispoof, "antispoof");
11116 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11117         TOKEN_NUM_INITIALIZER
11118                 (struct cmd_vf_mac_anti_spoof_result,
11119                  port_id, RTE_UINT16);
11120 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11121         TOKEN_NUM_INITIALIZER
11122                 (struct cmd_vf_mac_anti_spoof_result,
11123                  vf_id, RTE_UINT32);
11124 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11125         TOKEN_STRING_INITIALIZER
11126                 (struct cmd_vf_mac_anti_spoof_result,
11127                  on_off, "on#off");
11128
11129 static void
11130 cmd_set_vf_mac_anti_spoof_parsed(
11131         void *parsed_result,
11132         __rte_unused struct cmdline *cl,
11133         __rte_unused void *data)
11134 {
11135         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11136         int ret = -ENOTSUP;
11137
11138         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11139
11140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11141                 return;
11142
11143 #ifdef RTE_NET_IXGBE
11144         if (ret == -ENOTSUP)
11145                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11146                         res->vf_id, is_on);
11147 #endif
11148 #ifdef RTE_NET_I40E
11149         if (ret == -ENOTSUP)
11150                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11151                         res->vf_id, is_on);
11152 #endif
11153 #ifdef RTE_NET_BNXT
11154         if (ret == -ENOTSUP)
11155                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11156                         res->vf_id, is_on);
11157 #endif
11158
11159         switch (ret) {
11160         case 0:
11161                 break;
11162         case -EINVAL:
11163                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11164                         res->vf_id, is_on);
11165                 break;
11166         case -ENODEV:
11167                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11168                 break;
11169         case -ENOTSUP:
11170                 fprintf(stderr, "function not implemented\n");
11171                 break;
11172         default:
11173                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11174         }
11175 }
11176
11177 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11178         .f = cmd_set_vf_mac_anti_spoof_parsed,
11179         .data = NULL,
11180         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11181         .tokens = {
11182                 (void *)&cmd_vf_mac_anti_spoof_set,
11183                 (void *)&cmd_vf_mac_anti_spoof_vf,
11184                 (void *)&cmd_vf_mac_anti_spoof_mac,
11185                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11186                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11187                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11188                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11189                 NULL,
11190         },
11191 };
11192
11193 /* vf vlan strip queue configuration */
11194
11195 /* Common result structure for vf mac anti spoof */
11196 struct cmd_vf_vlan_stripq_result {
11197         cmdline_fixed_string_t set;
11198         cmdline_fixed_string_t vf;
11199         cmdline_fixed_string_t vlan;
11200         cmdline_fixed_string_t stripq;
11201         portid_t port_id;
11202         uint16_t vf_id;
11203         cmdline_fixed_string_t on_off;
11204 };
11205
11206 /* Common CLI fields for vf vlan strip enable disable */
11207 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11208         TOKEN_STRING_INITIALIZER
11209                 (struct cmd_vf_vlan_stripq_result,
11210                  set, "set");
11211 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11212         TOKEN_STRING_INITIALIZER
11213                 (struct cmd_vf_vlan_stripq_result,
11214                  vf, "vf");
11215 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11216         TOKEN_STRING_INITIALIZER
11217                 (struct cmd_vf_vlan_stripq_result,
11218                  vlan, "vlan");
11219 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11220         TOKEN_STRING_INITIALIZER
11221                 (struct cmd_vf_vlan_stripq_result,
11222                  stripq, "stripq");
11223 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11224         TOKEN_NUM_INITIALIZER
11225                 (struct cmd_vf_vlan_stripq_result,
11226                  port_id, RTE_UINT16);
11227 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11228         TOKEN_NUM_INITIALIZER
11229                 (struct cmd_vf_vlan_stripq_result,
11230                  vf_id, RTE_UINT16);
11231 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11232         TOKEN_STRING_INITIALIZER
11233                 (struct cmd_vf_vlan_stripq_result,
11234                  on_off, "on#off");
11235
11236 static void
11237 cmd_set_vf_vlan_stripq_parsed(
11238         void *parsed_result,
11239         __rte_unused struct cmdline *cl,
11240         __rte_unused void *data)
11241 {
11242         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11243         int ret = -ENOTSUP;
11244
11245         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11246
11247         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11248                 return;
11249
11250 #ifdef RTE_NET_IXGBE
11251         if (ret == -ENOTSUP)
11252                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11253                         res->vf_id, is_on);
11254 #endif
11255 #ifdef RTE_NET_I40E
11256         if (ret == -ENOTSUP)
11257                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11258                         res->vf_id, is_on);
11259 #endif
11260 #ifdef RTE_NET_BNXT
11261         if (ret == -ENOTSUP)
11262                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11263                         res->vf_id, is_on);
11264 #endif
11265
11266         switch (ret) {
11267         case 0:
11268                 break;
11269         case -EINVAL:
11270                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11271                         res->vf_id, is_on);
11272                 break;
11273         case -ENODEV:
11274                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11275                 break;
11276         case -ENOTSUP:
11277                 fprintf(stderr, "function not implemented\n");
11278                 break;
11279         default:
11280                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11281         }
11282 }
11283
11284 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11285         .f = cmd_set_vf_vlan_stripq_parsed,
11286         .data = NULL,
11287         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11288         .tokens = {
11289                 (void *)&cmd_vf_vlan_stripq_set,
11290                 (void *)&cmd_vf_vlan_stripq_vf,
11291                 (void *)&cmd_vf_vlan_stripq_vlan,
11292                 (void *)&cmd_vf_vlan_stripq_stripq,
11293                 (void *)&cmd_vf_vlan_stripq_port_id,
11294                 (void *)&cmd_vf_vlan_stripq_vf_id,
11295                 (void *)&cmd_vf_vlan_stripq_on_off,
11296                 NULL,
11297         },
11298 };
11299
11300 /* vf vlan insert configuration */
11301
11302 /* Common result structure for vf vlan insert */
11303 struct cmd_vf_vlan_insert_result {
11304         cmdline_fixed_string_t set;
11305         cmdline_fixed_string_t vf;
11306         cmdline_fixed_string_t vlan;
11307         cmdline_fixed_string_t insert;
11308         portid_t port_id;
11309         uint16_t vf_id;
11310         uint16_t vlan_id;
11311 };
11312
11313 /* Common CLI fields for vf vlan insert enable disable */
11314 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11315         TOKEN_STRING_INITIALIZER
11316                 (struct cmd_vf_vlan_insert_result,
11317                  set, "set");
11318 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11319         TOKEN_STRING_INITIALIZER
11320                 (struct cmd_vf_vlan_insert_result,
11321                  vf, "vf");
11322 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11323         TOKEN_STRING_INITIALIZER
11324                 (struct cmd_vf_vlan_insert_result,
11325                  vlan, "vlan");
11326 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11327         TOKEN_STRING_INITIALIZER
11328                 (struct cmd_vf_vlan_insert_result,
11329                  insert, "insert");
11330 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11331         TOKEN_NUM_INITIALIZER
11332                 (struct cmd_vf_vlan_insert_result,
11333                  port_id, RTE_UINT16);
11334 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11335         TOKEN_NUM_INITIALIZER
11336                 (struct cmd_vf_vlan_insert_result,
11337                  vf_id, RTE_UINT16);
11338 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11339         TOKEN_NUM_INITIALIZER
11340                 (struct cmd_vf_vlan_insert_result,
11341                  vlan_id, RTE_UINT16);
11342
11343 static void
11344 cmd_set_vf_vlan_insert_parsed(
11345         void *parsed_result,
11346         __rte_unused struct cmdline *cl,
11347         __rte_unused void *data)
11348 {
11349         struct cmd_vf_vlan_insert_result *res = parsed_result;
11350         int ret = -ENOTSUP;
11351
11352         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11353                 return;
11354
11355 #ifdef RTE_NET_IXGBE
11356         if (ret == -ENOTSUP)
11357                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11358                         res->vlan_id);
11359 #endif
11360 #ifdef RTE_NET_I40E
11361         if (ret == -ENOTSUP)
11362                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11363                         res->vlan_id);
11364 #endif
11365 #ifdef RTE_NET_BNXT
11366         if (ret == -ENOTSUP)
11367                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11368                         res->vlan_id);
11369 #endif
11370
11371         switch (ret) {
11372         case 0:
11373                 break;
11374         case -EINVAL:
11375                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11376                         res->vf_id, res->vlan_id);
11377                 break;
11378         case -ENODEV:
11379                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11380                 break;
11381         case -ENOTSUP:
11382                 fprintf(stderr, "function not implemented\n");
11383                 break;
11384         default:
11385                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11386         }
11387 }
11388
11389 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11390         .f = cmd_set_vf_vlan_insert_parsed,
11391         .data = NULL,
11392         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11393         .tokens = {
11394                 (void *)&cmd_vf_vlan_insert_set,
11395                 (void *)&cmd_vf_vlan_insert_vf,
11396                 (void *)&cmd_vf_vlan_insert_vlan,
11397                 (void *)&cmd_vf_vlan_insert_insert,
11398                 (void *)&cmd_vf_vlan_insert_port_id,
11399                 (void *)&cmd_vf_vlan_insert_vf_id,
11400                 (void *)&cmd_vf_vlan_insert_vlan_id,
11401                 NULL,
11402         },
11403 };
11404
11405 /* tx loopback configuration */
11406
11407 /* Common result structure for tx loopback */
11408 struct cmd_tx_loopback_result {
11409         cmdline_fixed_string_t set;
11410         cmdline_fixed_string_t tx;
11411         cmdline_fixed_string_t loopback;
11412         portid_t port_id;
11413         cmdline_fixed_string_t on_off;
11414 };
11415
11416 /* Common CLI fields for tx loopback enable disable */
11417 cmdline_parse_token_string_t cmd_tx_loopback_set =
11418         TOKEN_STRING_INITIALIZER
11419                 (struct cmd_tx_loopback_result,
11420                  set, "set");
11421 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11422         TOKEN_STRING_INITIALIZER
11423                 (struct cmd_tx_loopback_result,
11424                  tx, "tx");
11425 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11426         TOKEN_STRING_INITIALIZER
11427                 (struct cmd_tx_loopback_result,
11428                  loopback, "loopback");
11429 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11430         TOKEN_NUM_INITIALIZER
11431                 (struct cmd_tx_loopback_result,
11432                  port_id, RTE_UINT16);
11433 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11434         TOKEN_STRING_INITIALIZER
11435                 (struct cmd_tx_loopback_result,
11436                  on_off, "on#off");
11437
11438 static void
11439 cmd_set_tx_loopback_parsed(
11440         void *parsed_result,
11441         __rte_unused struct cmdline *cl,
11442         __rte_unused void *data)
11443 {
11444         struct cmd_tx_loopback_result *res = parsed_result;
11445         int ret = -ENOTSUP;
11446
11447         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11448
11449         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11450                 return;
11451
11452 #ifdef RTE_NET_IXGBE
11453         if (ret == -ENOTSUP)
11454                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11455 #endif
11456 #ifdef RTE_NET_I40E
11457         if (ret == -ENOTSUP)
11458                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11459 #endif
11460 #ifdef RTE_NET_BNXT
11461         if (ret == -ENOTSUP)
11462                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11463 #endif
11464 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11465         if (ret == -ENOTSUP)
11466                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11467 #endif
11468
11469         switch (ret) {
11470         case 0:
11471                 break;
11472         case -EINVAL:
11473                 fprintf(stderr, "invalid is_on %d\n", is_on);
11474                 break;
11475         case -ENODEV:
11476                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11477                 break;
11478         case -ENOTSUP:
11479                 fprintf(stderr, "function not implemented\n");
11480                 break;
11481         default:
11482                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11483         }
11484 }
11485
11486 cmdline_parse_inst_t cmd_set_tx_loopback = {
11487         .f = cmd_set_tx_loopback_parsed,
11488         .data = NULL,
11489         .help_str = "set tx loopback <port_id> on|off",
11490         .tokens = {
11491                 (void *)&cmd_tx_loopback_set,
11492                 (void *)&cmd_tx_loopback_tx,
11493                 (void *)&cmd_tx_loopback_loopback,
11494                 (void *)&cmd_tx_loopback_port_id,
11495                 (void *)&cmd_tx_loopback_on_off,
11496                 NULL,
11497         },
11498 };
11499
11500 /* all queues drop enable configuration */
11501
11502 /* Common result structure for all queues drop enable */
11503 struct cmd_all_queues_drop_en_result {
11504         cmdline_fixed_string_t set;
11505         cmdline_fixed_string_t all;
11506         cmdline_fixed_string_t queues;
11507         cmdline_fixed_string_t drop;
11508         portid_t port_id;
11509         cmdline_fixed_string_t on_off;
11510 };
11511
11512 /* Common CLI fields for tx loopback enable disable */
11513 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11514         TOKEN_STRING_INITIALIZER
11515                 (struct cmd_all_queues_drop_en_result,
11516                  set, "set");
11517 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11518         TOKEN_STRING_INITIALIZER
11519                 (struct cmd_all_queues_drop_en_result,
11520                  all, "all");
11521 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_all_queues_drop_en_result,
11524                  queues, "queues");
11525 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11526         TOKEN_STRING_INITIALIZER
11527                 (struct cmd_all_queues_drop_en_result,
11528                  drop, "drop");
11529 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11530         TOKEN_NUM_INITIALIZER
11531                 (struct cmd_all_queues_drop_en_result,
11532                  port_id, RTE_UINT16);
11533 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11534         TOKEN_STRING_INITIALIZER
11535                 (struct cmd_all_queues_drop_en_result,
11536                  on_off, "on#off");
11537
11538 static void
11539 cmd_set_all_queues_drop_en_parsed(
11540         void *parsed_result,
11541         __rte_unused struct cmdline *cl,
11542         __rte_unused void *data)
11543 {
11544         struct cmd_all_queues_drop_en_result *res = parsed_result;
11545         int ret = -ENOTSUP;
11546         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11547
11548         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11549                 return;
11550
11551 #ifdef RTE_NET_IXGBE
11552         if (ret == -ENOTSUP)
11553                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11554 #endif
11555 #ifdef RTE_NET_BNXT
11556         if (ret == -ENOTSUP)
11557                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11558 #endif
11559         switch (ret) {
11560         case 0:
11561                 break;
11562         case -EINVAL:
11563                 fprintf(stderr, "invalid is_on %d\n", is_on);
11564                 break;
11565         case -ENODEV:
11566                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11567                 break;
11568         case -ENOTSUP:
11569                 fprintf(stderr, "function not implemented\n");
11570                 break;
11571         default:
11572                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11573         }
11574 }
11575
11576 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11577         .f = cmd_set_all_queues_drop_en_parsed,
11578         .data = NULL,
11579         .help_str = "set all queues drop <port_id> on|off",
11580         .tokens = {
11581                 (void *)&cmd_all_queues_drop_en_set,
11582                 (void *)&cmd_all_queues_drop_en_all,
11583                 (void *)&cmd_all_queues_drop_en_queues,
11584                 (void *)&cmd_all_queues_drop_en_drop,
11585                 (void *)&cmd_all_queues_drop_en_port_id,
11586                 (void *)&cmd_all_queues_drop_en_on_off,
11587                 NULL,
11588         },
11589 };
11590
11591 /* vf split drop enable configuration */
11592
11593 /* Common result structure for vf split drop enable */
11594 struct cmd_vf_split_drop_en_result {
11595         cmdline_fixed_string_t set;
11596         cmdline_fixed_string_t vf;
11597         cmdline_fixed_string_t split;
11598         cmdline_fixed_string_t drop;
11599         portid_t port_id;
11600         uint16_t vf_id;
11601         cmdline_fixed_string_t on_off;
11602 };
11603
11604 /* Common CLI fields for vf split drop enable disable */
11605 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11606         TOKEN_STRING_INITIALIZER
11607                 (struct cmd_vf_split_drop_en_result,
11608                  set, "set");
11609 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11610         TOKEN_STRING_INITIALIZER
11611                 (struct cmd_vf_split_drop_en_result,
11612                  vf, "vf");
11613 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11614         TOKEN_STRING_INITIALIZER
11615                 (struct cmd_vf_split_drop_en_result,
11616                  split, "split");
11617 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11618         TOKEN_STRING_INITIALIZER
11619                 (struct cmd_vf_split_drop_en_result,
11620                  drop, "drop");
11621 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11622         TOKEN_NUM_INITIALIZER
11623                 (struct cmd_vf_split_drop_en_result,
11624                  port_id, RTE_UINT16);
11625 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11626         TOKEN_NUM_INITIALIZER
11627                 (struct cmd_vf_split_drop_en_result,
11628                  vf_id, RTE_UINT16);
11629 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11630         TOKEN_STRING_INITIALIZER
11631                 (struct cmd_vf_split_drop_en_result,
11632                  on_off, "on#off");
11633
11634 static void
11635 cmd_set_vf_split_drop_en_parsed(
11636         void *parsed_result,
11637         __rte_unused struct cmdline *cl,
11638         __rte_unused void *data)
11639 {
11640         struct cmd_vf_split_drop_en_result *res = parsed_result;
11641         int ret = -ENOTSUP;
11642         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11643
11644         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11645                 return;
11646
11647 #ifdef RTE_NET_IXGBE
11648         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11649                         is_on);
11650 #endif
11651         switch (ret) {
11652         case 0:
11653                 break;
11654         case -EINVAL:
11655                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11656                         res->vf_id, is_on);
11657                 break;
11658         case -ENODEV:
11659                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11660                 break;
11661         case -ENOTSUP:
11662                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11663                 break;
11664         default:
11665                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11666         }
11667 }
11668
11669 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11670         .f = cmd_set_vf_split_drop_en_parsed,
11671         .data = NULL,
11672         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11673         .tokens = {
11674                 (void *)&cmd_vf_split_drop_en_set,
11675                 (void *)&cmd_vf_split_drop_en_vf,
11676                 (void *)&cmd_vf_split_drop_en_split,
11677                 (void *)&cmd_vf_split_drop_en_drop,
11678                 (void *)&cmd_vf_split_drop_en_port_id,
11679                 (void *)&cmd_vf_split_drop_en_vf_id,
11680                 (void *)&cmd_vf_split_drop_en_on_off,
11681                 NULL,
11682         },
11683 };
11684
11685 /* vf mac address configuration */
11686
11687 /* Common result structure for vf mac address */
11688 struct cmd_set_vf_mac_addr_result {
11689         cmdline_fixed_string_t set;
11690         cmdline_fixed_string_t vf;
11691         cmdline_fixed_string_t mac;
11692         cmdline_fixed_string_t addr;
11693         portid_t port_id;
11694         uint16_t vf_id;
11695         struct rte_ether_addr mac_addr;
11696
11697 };
11698
11699 /* Common CLI fields for vf split drop enable disable */
11700 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11701         TOKEN_STRING_INITIALIZER
11702                 (struct cmd_set_vf_mac_addr_result,
11703                  set, "set");
11704 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11705         TOKEN_STRING_INITIALIZER
11706                 (struct cmd_set_vf_mac_addr_result,
11707                  vf, "vf");
11708 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11709         TOKEN_STRING_INITIALIZER
11710                 (struct cmd_set_vf_mac_addr_result,
11711                  mac, "mac");
11712 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11713         TOKEN_STRING_INITIALIZER
11714                 (struct cmd_set_vf_mac_addr_result,
11715                  addr, "addr");
11716 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11717         TOKEN_NUM_INITIALIZER
11718                 (struct cmd_set_vf_mac_addr_result,
11719                  port_id, RTE_UINT16);
11720 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11721         TOKEN_NUM_INITIALIZER
11722                 (struct cmd_set_vf_mac_addr_result,
11723                  vf_id, RTE_UINT16);
11724 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11725         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11726                  mac_addr);
11727
11728 static void
11729 cmd_set_vf_mac_addr_parsed(
11730         void *parsed_result,
11731         __rte_unused struct cmdline *cl,
11732         __rte_unused void *data)
11733 {
11734         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11735         int ret = -ENOTSUP;
11736
11737         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11738                 return;
11739
11740 #ifdef RTE_NET_IXGBE
11741         if (ret == -ENOTSUP)
11742                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11743                                 &res->mac_addr);
11744 #endif
11745 #ifdef RTE_NET_I40E
11746         if (ret == -ENOTSUP)
11747                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11748                                 &res->mac_addr);
11749 #endif
11750 #ifdef RTE_NET_BNXT
11751         if (ret == -ENOTSUP)
11752                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11753                                 &res->mac_addr);
11754 #endif
11755
11756         switch (ret) {
11757         case 0:
11758                 break;
11759         case -EINVAL:
11760                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11761                 break;
11762         case -ENODEV:
11763                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11764                 break;
11765         case -ENOTSUP:
11766                 fprintf(stderr, "function not implemented\n");
11767                 break;
11768         default:
11769                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11770         }
11771 }
11772
11773 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11774         .f = cmd_set_vf_mac_addr_parsed,
11775         .data = NULL,
11776         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11777         .tokens = {
11778                 (void *)&cmd_set_vf_mac_addr_set,
11779                 (void *)&cmd_set_vf_mac_addr_vf,
11780                 (void *)&cmd_set_vf_mac_addr_mac,
11781                 (void *)&cmd_set_vf_mac_addr_addr,
11782                 (void *)&cmd_set_vf_mac_addr_port_id,
11783                 (void *)&cmd_set_vf_mac_addr_vf_id,
11784                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11785                 NULL,
11786         },
11787 };
11788
11789 /* MACsec configuration */
11790
11791 /* Common result structure for MACsec offload enable */
11792 struct cmd_macsec_offload_on_result {
11793         cmdline_fixed_string_t set;
11794         cmdline_fixed_string_t macsec;
11795         cmdline_fixed_string_t offload;
11796         portid_t port_id;
11797         cmdline_fixed_string_t on;
11798         cmdline_fixed_string_t encrypt;
11799         cmdline_fixed_string_t en_on_off;
11800         cmdline_fixed_string_t replay_protect;
11801         cmdline_fixed_string_t rp_on_off;
11802 };
11803
11804 /* Common CLI fields for MACsec offload disable */
11805 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_macsec_offload_on_result,
11808                  set, "set");
11809 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_macsec_offload_on_result,
11812                  macsec, "macsec");
11813 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_macsec_offload_on_result,
11816                  offload, "offload");
11817 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11818         TOKEN_NUM_INITIALIZER
11819                 (struct cmd_macsec_offload_on_result,
11820                  port_id, RTE_UINT16);
11821 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_macsec_offload_on_result,
11824                  on, "on");
11825 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11826         TOKEN_STRING_INITIALIZER
11827                 (struct cmd_macsec_offload_on_result,
11828                  encrypt, "encrypt");
11829 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11830         TOKEN_STRING_INITIALIZER
11831                 (struct cmd_macsec_offload_on_result,
11832                  en_on_off, "on#off");
11833 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11834         TOKEN_STRING_INITIALIZER
11835                 (struct cmd_macsec_offload_on_result,
11836                  replay_protect, "replay-protect");
11837 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11838         TOKEN_STRING_INITIALIZER
11839                 (struct cmd_macsec_offload_on_result,
11840                  rp_on_off, "on#off");
11841
11842 static void
11843 cmd_set_macsec_offload_on_parsed(
11844         void *parsed_result,
11845         __rte_unused struct cmdline *cl,
11846         __rte_unused void *data)
11847 {
11848         struct cmd_macsec_offload_on_result *res = parsed_result;
11849         int ret = -ENOTSUP;
11850         portid_t port_id = res->port_id;
11851         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11852         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11853         struct rte_eth_dev_info dev_info;
11854
11855         if (port_id_is_invalid(port_id, ENABLED_WARN))
11856                 return;
11857         if (!port_is_stopped(port_id)) {
11858                 fprintf(stderr, "Please stop port %d first\n", port_id);
11859                 return;
11860         }
11861
11862         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11863         if (ret != 0)
11864                 return;
11865
11866         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
11867 #ifdef RTE_NET_IXGBE
11868                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11869 #endif
11870         }
11871         RTE_SET_USED(en);
11872         RTE_SET_USED(rp);
11873
11874         switch (ret) {
11875         case 0:
11876                 ports[port_id].dev_conf.txmode.offloads |=
11877                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
11878                 cmd_reconfig_device_queue(port_id, 1, 1);
11879                 break;
11880         case -ENODEV:
11881                 fprintf(stderr, "invalid port_id %d\n", port_id);
11882                 break;
11883         case -ENOTSUP:
11884                 fprintf(stderr, "not supported on port %d\n", port_id);
11885                 break;
11886         default:
11887                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11888         }
11889 }
11890
11891 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11892         .f = cmd_set_macsec_offload_on_parsed,
11893         .data = NULL,
11894         .help_str = "set macsec offload <port_id> on "
11895                 "encrypt on|off replay-protect on|off",
11896         .tokens = {
11897                 (void *)&cmd_macsec_offload_on_set,
11898                 (void *)&cmd_macsec_offload_on_macsec,
11899                 (void *)&cmd_macsec_offload_on_offload,
11900                 (void *)&cmd_macsec_offload_on_port_id,
11901                 (void *)&cmd_macsec_offload_on_on,
11902                 (void *)&cmd_macsec_offload_on_encrypt,
11903                 (void *)&cmd_macsec_offload_on_en_on_off,
11904                 (void *)&cmd_macsec_offload_on_replay_protect,
11905                 (void *)&cmd_macsec_offload_on_rp_on_off,
11906                 NULL,
11907         },
11908 };
11909
11910 /* Common result structure for MACsec offload disable */
11911 struct cmd_macsec_offload_off_result {
11912         cmdline_fixed_string_t set;
11913         cmdline_fixed_string_t macsec;
11914         cmdline_fixed_string_t offload;
11915         portid_t port_id;
11916         cmdline_fixed_string_t off;
11917 };
11918
11919 /* Common CLI fields for MACsec offload disable */
11920 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11921         TOKEN_STRING_INITIALIZER
11922                 (struct cmd_macsec_offload_off_result,
11923                  set, "set");
11924 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11925         TOKEN_STRING_INITIALIZER
11926                 (struct cmd_macsec_offload_off_result,
11927                  macsec, "macsec");
11928 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11929         TOKEN_STRING_INITIALIZER
11930                 (struct cmd_macsec_offload_off_result,
11931                  offload, "offload");
11932 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11933         TOKEN_NUM_INITIALIZER
11934                 (struct cmd_macsec_offload_off_result,
11935                  port_id, RTE_UINT16);
11936 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11937         TOKEN_STRING_INITIALIZER
11938                 (struct cmd_macsec_offload_off_result,
11939                  off, "off");
11940
11941 static void
11942 cmd_set_macsec_offload_off_parsed(
11943         void *parsed_result,
11944         __rte_unused struct cmdline *cl,
11945         __rte_unused void *data)
11946 {
11947         struct cmd_macsec_offload_off_result *res = parsed_result;
11948         int ret = -ENOTSUP;
11949         struct rte_eth_dev_info dev_info;
11950         portid_t port_id = res->port_id;
11951
11952         if (port_id_is_invalid(port_id, ENABLED_WARN))
11953                 return;
11954         if (!port_is_stopped(port_id)) {
11955                 fprintf(stderr, "Please stop port %d first\n", port_id);
11956                 return;
11957         }
11958
11959         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11960         if (ret != 0)
11961                 return;
11962
11963         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
11964 #ifdef RTE_NET_IXGBE
11965                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11966 #endif
11967         }
11968         switch (ret) {
11969         case 0:
11970                 ports[port_id].dev_conf.txmode.offloads &=
11971                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
11972                 cmd_reconfig_device_queue(port_id, 1, 1);
11973                 break;
11974         case -ENODEV:
11975                 fprintf(stderr, "invalid port_id %d\n", port_id);
11976                 break;
11977         case -ENOTSUP:
11978                 fprintf(stderr, "not supported on port %d\n", port_id);
11979                 break;
11980         default:
11981                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11982         }
11983 }
11984
11985 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11986         .f = cmd_set_macsec_offload_off_parsed,
11987         .data = NULL,
11988         .help_str = "set macsec offload <port_id> off",
11989         .tokens = {
11990                 (void *)&cmd_macsec_offload_off_set,
11991                 (void *)&cmd_macsec_offload_off_macsec,
11992                 (void *)&cmd_macsec_offload_off_offload,
11993                 (void *)&cmd_macsec_offload_off_port_id,
11994                 (void *)&cmd_macsec_offload_off_off,
11995                 NULL,
11996         },
11997 };
11998
11999 /* Common result structure for MACsec secure connection configure */
12000 struct cmd_macsec_sc_result {
12001         cmdline_fixed_string_t set;
12002         cmdline_fixed_string_t macsec;
12003         cmdline_fixed_string_t sc;
12004         cmdline_fixed_string_t tx_rx;
12005         portid_t port_id;
12006         struct rte_ether_addr mac;
12007         uint16_t pi;
12008 };
12009
12010 /* Common CLI fields for MACsec secure connection configure */
12011 cmdline_parse_token_string_t cmd_macsec_sc_set =
12012         TOKEN_STRING_INITIALIZER
12013                 (struct cmd_macsec_sc_result,
12014                  set, "set");
12015 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_macsec_sc_result,
12018                  macsec, "macsec");
12019 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12020         TOKEN_STRING_INITIALIZER
12021                 (struct cmd_macsec_sc_result,
12022                  sc, "sc");
12023 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12024         TOKEN_STRING_INITIALIZER
12025                 (struct cmd_macsec_sc_result,
12026                  tx_rx, "tx#rx");
12027 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12028         TOKEN_NUM_INITIALIZER
12029                 (struct cmd_macsec_sc_result,
12030                  port_id, RTE_UINT16);
12031 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12032         TOKEN_ETHERADDR_INITIALIZER
12033                 (struct cmd_macsec_sc_result,
12034                  mac);
12035 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12036         TOKEN_NUM_INITIALIZER
12037                 (struct cmd_macsec_sc_result,
12038                  pi, RTE_UINT16);
12039
12040 static void
12041 cmd_set_macsec_sc_parsed(
12042         void *parsed_result,
12043         __rte_unused struct cmdline *cl,
12044         __rte_unused void *data)
12045 {
12046         struct cmd_macsec_sc_result *res = parsed_result;
12047         int ret = -ENOTSUP;
12048         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12049
12050 #ifdef RTE_NET_IXGBE
12051         ret = is_tx ?
12052                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12053                                 res->mac.addr_bytes) :
12054                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12055                                 res->mac.addr_bytes, res->pi);
12056 #endif
12057         RTE_SET_USED(is_tx);
12058
12059         switch (ret) {
12060         case 0:
12061                 break;
12062         case -ENODEV:
12063                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12064                 break;
12065         case -ENOTSUP:
12066                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12067                 break;
12068         default:
12069                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12070         }
12071 }
12072
12073 cmdline_parse_inst_t cmd_set_macsec_sc = {
12074         .f = cmd_set_macsec_sc_parsed,
12075         .data = NULL,
12076         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12077         .tokens = {
12078                 (void *)&cmd_macsec_sc_set,
12079                 (void *)&cmd_macsec_sc_macsec,
12080                 (void *)&cmd_macsec_sc_sc,
12081                 (void *)&cmd_macsec_sc_tx_rx,
12082                 (void *)&cmd_macsec_sc_port_id,
12083                 (void *)&cmd_macsec_sc_mac,
12084                 (void *)&cmd_macsec_sc_pi,
12085                 NULL,
12086         },
12087 };
12088
12089 /* Common result structure for MACsec secure connection configure */
12090 struct cmd_macsec_sa_result {
12091         cmdline_fixed_string_t set;
12092         cmdline_fixed_string_t macsec;
12093         cmdline_fixed_string_t sa;
12094         cmdline_fixed_string_t tx_rx;
12095         portid_t port_id;
12096         uint8_t idx;
12097         uint8_t an;
12098         uint32_t pn;
12099         cmdline_fixed_string_t key;
12100 };
12101
12102 /* Common CLI fields for MACsec secure connection configure */
12103 cmdline_parse_token_string_t cmd_macsec_sa_set =
12104         TOKEN_STRING_INITIALIZER
12105                 (struct cmd_macsec_sa_result,
12106                  set, "set");
12107 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12108         TOKEN_STRING_INITIALIZER
12109                 (struct cmd_macsec_sa_result,
12110                  macsec, "macsec");
12111 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12112         TOKEN_STRING_INITIALIZER
12113                 (struct cmd_macsec_sa_result,
12114                  sa, "sa");
12115 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12116         TOKEN_STRING_INITIALIZER
12117                 (struct cmd_macsec_sa_result,
12118                  tx_rx, "tx#rx");
12119 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12120         TOKEN_NUM_INITIALIZER
12121                 (struct cmd_macsec_sa_result,
12122                  port_id, RTE_UINT16);
12123 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12124         TOKEN_NUM_INITIALIZER
12125                 (struct cmd_macsec_sa_result,
12126                  idx, RTE_UINT8);
12127 cmdline_parse_token_num_t cmd_macsec_sa_an =
12128         TOKEN_NUM_INITIALIZER
12129                 (struct cmd_macsec_sa_result,
12130                  an, RTE_UINT8);
12131 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12132         TOKEN_NUM_INITIALIZER
12133                 (struct cmd_macsec_sa_result,
12134                  pn, RTE_UINT32);
12135 cmdline_parse_token_string_t cmd_macsec_sa_key =
12136         TOKEN_STRING_INITIALIZER
12137                 (struct cmd_macsec_sa_result,
12138                  key, NULL);
12139
12140 static void
12141 cmd_set_macsec_sa_parsed(
12142         void *parsed_result,
12143         __rte_unused struct cmdline *cl,
12144         __rte_unused void *data)
12145 {
12146         struct cmd_macsec_sa_result *res = parsed_result;
12147         int ret = -ENOTSUP;
12148         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12149         uint8_t key[16] = { 0 };
12150         uint8_t xdgt0;
12151         uint8_t xdgt1;
12152         int key_len;
12153         int i;
12154
12155         key_len = strlen(res->key) / 2;
12156         if (key_len > 16)
12157                 key_len = 16;
12158
12159         for (i = 0; i < key_len; i++) {
12160                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12161                 if (xdgt0 == 0xFF)
12162                         return;
12163                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12164                 if (xdgt1 == 0xFF)
12165                         return;
12166                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12167         }
12168
12169 #ifdef RTE_NET_IXGBE
12170         ret = is_tx ?
12171                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12172                         res->idx, res->an, res->pn, key) :
12173                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12174                         res->idx, res->an, res->pn, key);
12175 #endif
12176         RTE_SET_USED(is_tx);
12177         RTE_SET_USED(key);
12178
12179         switch (ret) {
12180         case 0:
12181                 break;
12182         case -EINVAL:
12183                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12184                 break;
12185         case -ENODEV:
12186                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12187                 break;
12188         case -ENOTSUP:
12189                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12190                 break;
12191         default:
12192                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12193         }
12194 }
12195
12196 cmdline_parse_inst_t cmd_set_macsec_sa = {
12197         .f = cmd_set_macsec_sa_parsed,
12198         .data = NULL,
12199         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12200         .tokens = {
12201                 (void *)&cmd_macsec_sa_set,
12202                 (void *)&cmd_macsec_sa_macsec,
12203                 (void *)&cmd_macsec_sa_sa,
12204                 (void *)&cmd_macsec_sa_tx_rx,
12205                 (void *)&cmd_macsec_sa_port_id,
12206                 (void *)&cmd_macsec_sa_idx,
12207                 (void *)&cmd_macsec_sa_an,
12208                 (void *)&cmd_macsec_sa_pn,
12209                 (void *)&cmd_macsec_sa_key,
12210                 NULL,
12211         },
12212 };
12213
12214 /* VF unicast promiscuous mode configuration */
12215
12216 /* Common result structure for VF unicast promiscuous mode */
12217 struct cmd_vf_promisc_result {
12218         cmdline_fixed_string_t set;
12219         cmdline_fixed_string_t vf;
12220         cmdline_fixed_string_t promisc;
12221         portid_t port_id;
12222         uint32_t vf_id;
12223         cmdline_fixed_string_t on_off;
12224 };
12225
12226 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12227 cmdline_parse_token_string_t cmd_vf_promisc_set =
12228         TOKEN_STRING_INITIALIZER
12229                 (struct cmd_vf_promisc_result,
12230                  set, "set");
12231 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12232         TOKEN_STRING_INITIALIZER
12233                 (struct cmd_vf_promisc_result,
12234                  vf, "vf");
12235 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12236         TOKEN_STRING_INITIALIZER
12237                 (struct cmd_vf_promisc_result,
12238                  promisc, "promisc");
12239 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12240         TOKEN_NUM_INITIALIZER
12241                 (struct cmd_vf_promisc_result,
12242                  port_id, RTE_UINT16);
12243 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12244         TOKEN_NUM_INITIALIZER
12245                 (struct cmd_vf_promisc_result,
12246                  vf_id, RTE_UINT32);
12247 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12248         TOKEN_STRING_INITIALIZER
12249                 (struct cmd_vf_promisc_result,
12250                  on_off, "on#off");
12251
12252 static void
12253 cmd_set_vf_promisc_parsed(
12254         void *parsed_result,
12255         __rte_unused struct cmdline *cl,
12256         __rte_unused void *data)
12257 {
12258         struct cmd_vf_promisc_result *res = parsed_result;
12259         int ret = -ENOTSUP;
12260
12261         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12262
12263         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12264                 return;
12265
12266 #ifdef RTE_NET_I40E
12267         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12268                                                   res->vf_id, is_on);
12269 #endif
12270
12271         switch (ret) {
12272         case 0:
12273                 break;
12274         case -EINVAL:
12275                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12276                 break;
12277         case -ENODEV:
12278                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12279                 break;
12280         case -ENOTSUP:
12281                 fprintf(stderr, "function not implemented\n");
12282                 break;
12283         default:
12284                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12285         }
12286 }
12287
12288 cmdline_parse_inst_t cmd_set_vf_promisc = {
12289         .f = cmd_set_vf_promisc_parsed,
12290         .data = NULL,
12291         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12292                 "Set unicast promiscuous mode for a VF from the PF",
12293         .tokens = {
12294                 (void *)&cmd_vf_promisc_set,
12295                 (void *)&cmd_vf_promisc_vf,
12296                 (void *)&cmd_vf_promisc_promisc,
12297                 (void *)&cmd_vf_promisc_port_id,
12298                 (void *)&cmd_vf_promisc_vf_id,
12299                 (void *)&cmd_vf_promisc_on_off,
12300                 NULL,
12301         },
12302 };
12303
12304 /* VF multicast promiscuous mode configuration */
12305
12306 /* Common result structure for VF multicast promiscuous mode */
12307 struct cmd_vf_allmulti_result {
12308         cmdline_fixed_string_t set;
12309         cmdline_fixed_string_t vf;
12310         cmdline_fixed_string_t allmulti;
12311         portid_t port_id;
12312         uint32_t vf_id;
12313         cmdline_fixed_string_t on_off;
12314 };
12315
12316 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12317 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12318         TOKEN_STRING_INITIALIZER
12319                 (struct cmd_vf_allmulti_result,
12320                  set, "set");
12321 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12322         TOKEN_STRING_INITIALIZER
12323                 (struct cmd_vf_allmulti_result,
12324                  vf, "vf");
12325 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12326         TOKEN_STRING_INITIALIZER
12327                 (struct cmd_vf_allmulti_result,
12328                  allmulti, "allmulti");
12329 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12330         TOKEN_NUM_INITIALIZER
12331                 (struct cmd_vf_allmulti_result,
12332                  port_id, RTE_UINT16);
12333 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12334         TOKEN_NUM_INITIALIZER
12335                 (struct cmd_vf_allmulti_result,
12336                  vf_id, RTE_UINT32);
12337 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12338         TOKEN_STRING_INITIALIZER
12339                 (struct cmd_vf_allmulti_result,
12340                  on_off, "on#off");
12341
12342 static void
12343 cmd_set_vf_allmulti_parsed(
12344         void *parsed_result,
12345         __rte_unused struct cmdline *cl,
12346         __rte_unused void *data)
12347 {
12348         struct cmd_vf_allmulti_result *res = parsed_result;
12349         int ret = -ENOTSUP;
12350
12351         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12352
12353         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12354                 return;
12355
12356 #ifdef RTE_NET_I40E
12357         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12358                                                     res->vf_id, is_on);
12359 #endif
12360
12361         switch (ret) {
12362         case 0:
12363                 break;
12364         case -EINVAL:
12365                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12366                 break;
12367         case -ENODEV:
12368                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12369                 break;
12370         case -ENOTSUP:
12371                 fprintf(stderr, "function not implemented\n");
12372                 break;
12373         default:
12374                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12375         }
12376 }
12377
12378 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12379         .f = cmd_set_vf_allmulti_parsed,
12380         .data = NULL,
12381         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12382                 "Set multicast promiscuous mode for a VF from the PF",
12383         .tokens = {
12384                 (void *)&cmd_vf_allmulti_set,
12385                 (void *)&cmd_vf_allmulti_vf,
12386                 (void *)&cmd_vf_allmulti_allmulti,
12387                 (void *)&cmd_vf_allmulti_port_id,
12388                 (void *)&cmd_vf_allmulti_vf_id,
12389                 (void *)&cmd_vf_allmulti_on_off,
12390                 NULL,
12391         },
12392 };
12393
12394 /* vf broadcast mode configuration */
12395
12396 /* Common result structure for vf broadcast */
12397 struct cmd_set_vf_broadcast_result {
12398         cmdline_fixed_string_t set;
12399         cmdline_fixed_string_t vf;
12400         cmdline_fixed_string_t broadcast;
12401         portid_t port_id;
12402         uint16_t vf_id;
12403         cmdline_fixed_string_t on_off;
12404 };
12405
12406 /* Common CLI fields for vf broadcast enable disable */
12407 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12408         TOKEN_STRING_INITIALIZER
12409                 (struct cmd_set_vf_broadcast_result,
12410                  set, "set");
12411 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12412         TOKEN_STRING_INITIALIZER
12413                 (struct cmd_set_vf_broadcast_result,
12414                  vf, "vf");
12415 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12416         TOKEN_STRING_INITIALIZER
12417                 (struct cmd_set_vf_broadcast_result,
12418                  broadcast, "broadcast");
12419 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12420         TOKEN_NUM_INITIALIZER
12421                 (struct cmd_set_vf_broadcast_result,
12422                  port_id, RTE_UINT16);
12423 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12424         TOKEN_NUM_INITIALIZER
12425                 (struct cmd_set_vf_broadcast_result,
12426                  vf_id, RTE_UINT16);
12427 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12428         TOKEN_STRING_INITIALIZER
12429                 (struct cmd_set_vf_broadcast_result,
12430                  on_off, "on#off");
12431
12432 static void
12433 cmd_set_vf_broadcast_parsed(
12434         void *parsed_result,
12435         __rte_unused struct cmdline *cl,
12436         __rte_unused void *data)
12437 {
12438         struct cmd_set_vf_broadcast_result *res = parsed_result;
12439         int ret = -ENOTSUP;
12440
12441         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12442
12443         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12444                 return;
12445
12446 #ifdef RTE_NET_I40E
12447         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12448                                             res->vf_id, is_on);
12449 #endif
12450
12451         switch (ret) {
12452         case 0:
12453                 break;
12454         case -EINVAL:
12455                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12456                         res->vf_id, is_on);
12457                 break;
12458         case -ENODEV:
12459                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12460                 break;
12461         case -ENOTSUP:
12462                 fprintf(stderr, "function not implemented\n");
12463                 break;
12464         default:
12465                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12466         }
12467 }
12468
12469 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12470         .f = cmd_set_vf_broadcast_parsed,
12471         .data = NULL,
12472         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12473         .tokens = {
12474                 (void *)&cmd_set_vf_broadcast_set,
12475                 (void *)&cmd_set_vf_broadcast_vf,
12476                 (void *)&cmd_set_vf_broadcast_broadcast,
12477                 (void *)&cmd_set_vf_broadcast_port_id,
12478                 (void *)&cmd_set_vf_broadcast_vf_id,
12479                 (void *)&cmd_set_vf_broadcast_on_off,
12480                 NULL,
12481         },
12482 };
12483
12484 /* vf vlan tag configuration */
12485
12486 /* Common result structure for vf vlan tag */
12487 struct cmd_set_vf_vlan_tag_result {
12488         cmdline_fixed_string_t set;
12489         cmdline_fixed_string_t vf;
12490         cmdline_fixed_string_t vlan;
12491         cmdline_fixed_string_t tag;
12492         portid_t port_id;
12493         uint16_t vf_id;
12494         cmdline_fixed_string_t on_off;
12495 };
12496
12497 /* Common CLI fields for vf vlan tag enable disable */
12498 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12499         TOKEN_STRING_INITIALIZER
12500                 (struct cmd_set_vf_vlan_tag_result,
12501                  set, "set");
12502 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12503         TOKEN_STRING_INITIALIZER
12504                 (struct cmd_set_vf_vlan_tag_result,
12505                  vf, "vf");
12506 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12507         TOKEN_STRING_INITIALIZER
12508                 (struct cmd_set_vf_vlan_tag_result,
12509                  vlan, "vlan");
12510 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12511         TOKEN_STRING_INITIALIZER
12512                 (struct cmd_set_vf_vlan_tag_result,
12513                  tag, "tag");
12514 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12515         TOKEN_NUM_INITIALIZER
12516                 (struct cmd_set_vf_vlan_tag_result,
12517                  port_id, RTE_UINT16);
12518 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12519         TOKEN_NUM_INITIALIZER
12520                 (struct cmd_set_vf_vlan_tag_result,
12521                  vf_id, RTE_UINT16);
12522 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12523         TOKEN_STRING_INITIALIZER
12524                 (struct cmd_set_vf_vlan_tag_result,
12525                  on_off, "on#off");
12526
12527 static void
12528 cmd_set_vf_vlan_tag_parsed(
12529         void *parsed_result,
12530         __rte_unused struct cmdline *cl,
12531         __rte_unused void *data)
12532 {
12533         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12534         int ret = -ENOTSUP;
12535
12536         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12537
12538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12539                 return;
12540
12541 #ifdef RTE_NET_I40E
12542         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12543                                            res->vf_id, is_on);
12544 #endif
12545
12546         switch (ret) {
12547         case 0:
12548                 break;
12549         case -EINVAL:
12550                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12551                         res->vf_id, is_on);
12552                 break;
12553         case -ENODEV:
12554                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12555                 break;
12556         case -ENOTSUP:
12557                 fprintf(stderr, "function not implemented\n");
12558                 break;
12559         default:
12560                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12561         }
12562 }
12563
12564 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12565         .f = cmd_set_vf_vlan_tag_parsed,
12566         .data = NULL,
12567         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12568         .tokens = {
12569                 (void *)&cmd_set_vf_vlan_tag_set,
12570                 (void *)&cmd_set_vf_vlan_tag_vf,
12571                 (void *)&cmd_set_vf_vlan_tag_vlan,
12572                 (void *)&cmd_set_vf_vlan_tag_tag,
12573                 (void *)&cmd_set_vf_vlan_tag_port_id,
12574                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12575                 (void *)&cmd_set_vf_vlan_tag_on_off,
12576                 NULL,
12577         },
12578 };
12579
12580 /* Common definition of VF and TC TX bandwidth configuration */
12581 struct cmd_vf_tc_bw_result {
12582         cmdline_fixed_string_t set;
12583         cmdline_fixed_string_t vf;
12584         cmdline_fixed_string_t tc;
12585         cmdline_fixed_string_t tx;
12586         cmdline_fixed_string_t min_bw;
12587         cmdline_fixed_string_t max_bw;
12588         cmdline_fixed_string_t strict_link_prio;
12589         portid_t port_id;
12590         uint16_t vf_id;
12591         uint8_t tc_no;
12592         uint32_t bw;
12593         cmdline_fixed_string_t bw_list;
12594         uint8_t tc_map;
12595 };
12596
12597 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12598         TOKEN_STRING_INITIALIZER
12599                 (struct cmd_vf_tc_bw_result,
12600                  set, "set");
12601 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12602         TOKEN_STRING_INITIALIZER
12603                 (struct cmd_vf_tc_bw_result,
12604                  vf, "vf");
12605 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12606         TOKEN_STRING_INITIALIZER
12607                 (struct cmd_vf_tc_bw_result,
12608                  tc, "tc");
12609 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12610         TOKEN_STRING_INITIALIZER
12611                 (struct cmd_vf_tc_bw_result,
12612                  tx, "tx");
12613 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12614         TOKEN_STRING_INITIALIZER
12615                 (struct cmd_vf_tc_bw_result,
12616                  strict_link_prio, "strict-link-priority");
12617 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12618         TOKEN_STRING_INITIALIZER
12619                 (struct cmd_vf_tc_bw_result,
12620                  min_bw, "min-bandwidth");
12621 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12622         TOKEN_STRING_INITIALIZER
12623                 (struct cmd_vf_tc_bw_result,
12624                  max_bw, "max-bandwidth");
12625 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12626         TOKEN_NUM_INITIALIZER
12627                 (struct cmd_vf_tc_bw_result,
12628                  port_id, RTE_UINT16);
12629 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12630         TOKEN_NUM_INITIALIZER
12631                 (struct cmd_vf_tc_bw_result,
12632                  vf_id, RTE_UINT16);
12633 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12634         TOKEN_NUM_INITIALIZER
12635                 (struct cmd_vf_tc_bw_result,
12636                  tc_no, RTE_UINT8);
12637 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12638         TOKEN_NUM_INITIALIZER
12639                 (struct cmd_vf_tc_bw_result,
12640                  bw, RTE_UINT32);
12641 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12642         TOKEN_STRING_INITIALIZER
12643                 (struct cmd_vf_tc_bw_result,
12644                  bw_list, NULL);
12645 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12646         TOKEN_NUM_INITIALIZER
12647                 (struct cmd_vf_tc_bw_result,
12648                  tc_map, RTE_UINT8);
12649
12650 /* VF max bandwidth setting */
12651 static void
12652 cmd_vf_max_bw_parsed(
12653         void *parsed_result,
12654         __rte_unused struct cmdline *cl,
12655         __rte_unused void *data)
12656 {
12657         struct cmd_vf_tc_bw_result *res = parsed_result;
12658         int ret = -ENOTSUP;
12659
12660         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12661                 return;
12662
12663 #ifdef RTE_NET_I40E
12664         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12665                                          res->vf_id, res->bw);
12666 #endif
12667
12668         switch (ret) {
12669         case 0:
12670                 break;
12671         case -EINVAL:
12672                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12673                         res->vf_id, res->bw);
12674                 break;
12675         case -ENODEV:
12676                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12677                 break;
12678         case -ENOTSUP:
12679                 fprintf(stderr, "function not implemented\n");
12680                 break;
12681         default:
12682                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12683         }
12684 }
12685
12686 cmdline_parse_inst_t cmd_vf_max_bw = {
12687         .f = cmd_vf_max_bw_parsed,
12688         .data = NULL,
12689         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12690         .tokens = {
12691                 (void *)&cmd_vf_tc_bw_set,
12692                 (void *)&cmd_vf_tc_bw_vf,
12693                 (void *)&cmd_vf_tc_bw_tx,
12694                 (void *)&cmd_vf_tc_bw_max_bw,
12695                 (void *)&cmd_vf_tc_bw_port_id,
12696                 (void *)&cmd_vf_tc_bw_vf_id,
12697                 (void *)&cmd_vf_tc_bw_bw,
12698                 NULL,
12699         },
12700 };
12701
12702 static int
12703 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12704                            uint8_t *tc_num,
12705                            char *str)
12706 {
12707         uint32_t size;
12708         const char *p, *p0 = str;
12709         char s[256];
12710         char *end;
12711         char *str_fld[16];
12712         uint16_t i;
12713         int ret;
12714
12715         p = strchr(p0, '(');
12716         if (p == NULL) {
12717                 fprintf(stderr,
12718                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12719                 return -1;
12720         }
12721         p++;
12722         p0 = strchr(p, ')');
12723         if (p0 == NULL) {
12724                 fprintf(stderr,
12725                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12726                 return -1;
12727         }
12728         size = p0 - p;
12729         if (size >= sizeof(s)) {
12730                 fprintf(stderr,
12731                         "The string size exceeds the internal buffer size\n");
12732                 return -1;
12733         }
12734         snprintf(s, sizeof(s), "%.*s", size, p);
12735         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12736         if (ret <= 0) {
12737                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12738                 return -1;
12739         }
12740         *tc_num = ret;
12741         for (i = 0; i < ret; i++)
12742                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12743
12744         return 0;
12745 }
12746
12747 /* TC min bandwidth setting */
12748 static void
12749 cmd_vf_tc_min_bw_parsed(
12750         void *parsed_result,
12751         __rte_unused struct cmdline *cl,
12752         __rte_unused void *data)
12753 {
12754         struct cmd_vf_tc_bw_result *res = parsed_result;
12755         uint8_t tc_num;
12756         uint8_t bw[16];
12757         int ret = -ENOTSUP;
12758
12759         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12760                 return;
12761
12762         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12763         if (ret)
12764                 return;
12765
12766 #ifdef RTE_NET_I40E
12767         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12768                                               tc_num, bw);
12769 #endif
12770
12771         switch (ret) {
12772         case 0:
12773                 break;
12774         case -EINVAL:
12775                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12776                 break;
12777         case -ENODEV:
12778                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12779                 break;
12780         case -ENOTSUP:
12781                 fprintf(stderr, "function not implemented\n");
12782                 break;
12783         default:
12784                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12785         }
12786 }
12787
12788 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12789         .f = cmd_vf_tc_min_bw_parsed,
12790         .data = NULL,
12791         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12792                     " <bw1, bw2, ...>",
12793         .tokens = {
12794                 (void *)&cmd_vf_tc_bw_set,
12795                 (void *)&cmd_vf_tc_bw_vf,
12796                 (void *)&cmd_vf_tc_bw_tc,
12797                 (void *)&cmd_vf_tc_bw_tx,
12798                 (void *)&cmd_vf_tc_bw_min_bw,
12799                 (void *)&cmd_vf_tc_bw_port_id,
12800                 (void *)&cmd_vf_tc_bw_vf_id,
12801                 (void *)&cmd_vf_tc_bw_bw_list,
12802                 NULL,
12803         },
12804 };
12805
12806 static void
12807 cmd_tc_min_bw_parsed(
12808         void *parsed_result,
12809         __rte_unused struct cmdline *cl,
12810         __rte_unused void *data)
12811 {
12812         struct cmd_vf_tc_bw_result *res = parsed_result;
12813         struct rte_port *port;
12814         uint8_t tc_num;
12815         uint8_t bw[16];
12816         int ret = -ENOTSUP;
12817
12818         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12819                 return;
12820
12821         port = &ports[res->port_id];
12822         /** Check if the port is not started **/
12823         if (port->port_status != RTE_PORT_STOPPED) {
12824                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
12825                 return;
12826         }
12827
12828         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12829         if (ret)
12830                 return;
12831
12832 #ifdef RTE_NET_IXGBE
12833         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12834 #endif
12835
12836         switch (ret) {
12837         case 0:
12838                 break;
12839         case -EINVAL:
12840                 fprintf(stderr, "invalid bandwidth\n");
12841                 break;
12842         case -ENODEV:
12843                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12844                 break;
12845         case -ENOTSUP:
12846                 fprintf(stderr, "function not implemented\n");
12847                 break;
12848         default:
12849                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12850         }
12851 }
12852
12853 cmdline_parse_inst_t cmd_tc_min_bw = {
12854         .f = cmd_tc_min_bw_parsed,
12855         .data = NULL,
12856         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12857         .tokens = {
12858                 (void *)&cmd_vf_tc_bw_set,
12859                 (void *)&cmd_vf_tc_bw_tc,
12860                 (void *)&cmd_vf_tc_bw_tx,
12861                 (void *)&cmd_vf_tc_bw_min_bw,
12862                 (void *)&cmd_vf_tc_bw_port_id,
12863                 (void *)&cmd_vf_tc_bw_bw_list,
12864                 NULL,
12865         },
12866 };
12867
12868 /* TC max bandwidth setting */
12869 static void
12870 cmd_vf_tc_max_bw_parsed(
12871         void *parsed_result,
12872         __rte_unused struct cmdline *cl,
12873         __rte_unused void *data)
12874 {
12875         struct cmd_vf_tc_bw_result *res = parsed_result;
12876         int ret = -ENOTSUP;
12877
12878         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12879                 return;
12880
12881 #ifdef RTE_NET_I40E
12882         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12883                                             res->tc_no, res->bw);
12884 #endif
12885
12886         switch (ret) {
12887         case 0:
12888                 break;
12889         case -EINVAL:
12890                 fprintf(stderr,
12891                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
12892                         res->vf_id, res->tc_no, res->bw);
12893                 break;
12894         case -ENODEV:
12895                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12896                 break;
12897         case -ENOTSUP:
12898                 fprintf(stderr, "function not implemented\n");
12899                 break;
12900         default:
12901                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12902         }
12903 }
12904
12905 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12906         .f = cmd_vf_tc_max_bw_parsed,
12907         .data = NULL,
12908         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12909                     " <bandwidth>",
12910         .tokens = {
12911                 (void *)&cmd_vf_tc_bw_set,
12912                 (void *)&cmd_vf_tc_bw_vf,
12913                 (void *)&cmd_vf_tc_bw_tc,
12914                 (void *)&cmd_vf_tc_bw_tx,
12915                 (void *)&cmd_vf_tc_bw_max_bw,
12916                 (void *)&cmd_vf_tc_bw_port_id,
12917                 (void *)&cmd_vf_tc_bw_vf_id,
12918                 (void *)&cmd_vf_tc_bw_tc_no,
12919                 (void *)&cmd_vf_tc_bw_bw,
12920                 NULL,
12921         },
12922 };
12923
12924 /** Set VXLAN encapsulation details */
12925 struct cmd_set_vxlan_result {
12926         cmdline_fixed_string_t set;
12927         cmdline_fixed_string_t vxlan;
12928         cmdline_fixed_string_t pos_token;
12929         cmdline_fixed_string_t ip_version;
12930         uint32_t vlan_present:1;
12931         uint32_t vni;
12932         uint16_t udp_src;
12933         uint16_t udp_dst;
12934         cmdline_ipaddr_t ip_src;
12935         cmdline_ipaddr_t ip_dst;
12936         uint16_t tci;
12937         uint8_t tos;
12938         uint8_t ttl;
12939         struct rte_ether_addr eth_src;
12940         struct rte_ether_addr eth_dst;
12941 };
12942
12943 cmdline_parse_token_string_t cmd_set_vxlan_set =
12944         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12945 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12946         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12947 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12948         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12949                                  "vxlan-tos-ttl");
12950 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12951         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12952                                  "vxlan-with-vlan");
12953 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12954         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12955                                  "ip-version");
12956 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12957         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12958                                  "ipv4#ipv6");
12959 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12960         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12961                                  "vni");
12962 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12963         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12964 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12965         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12966                                  "udp-src");
12967 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12968         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12969 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12970         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12971                                  "udp-dst");
12972 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12973         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12974 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12975         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12976                                  "ip-tos");
12977 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12978         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12979 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12980         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12981                                  "ip-ttl");
12982 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12983         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12984 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12985         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12986                                  "ip-src");
12987 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12988         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12989 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
12990         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12991                                  "ip-dst");
12992 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
12993         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
12994 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
12995         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12996                                  "vlan-tci");
12997 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
12998         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
12999 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13000         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13001                                  "eth-src");
13002 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13003         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13004 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13005         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13006                                  "eth-dst");
13007 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13008         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13009
13010 static void cmd_set_vxlan_parsed(void *parsed_result,
13011         __rte_unused struct cmdline *cl,
13012         __rte_unused void *data)
13013 {
13014         struct cmd_set_vxlan_result *res = parsed_result;
13015         union {
13016                 uint32_t vxlan_id;
13017                 uint8_t vni[4];
13018         } id = {
13019                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13020         };
13021
13022         vxlan_encap_conf.select_tos_ttl = 0;
13023         if (strcmp(res->vxlan, "vxlan") == 0)
13024                 vxlan_encap_conf.select_vlan = 0;
13025         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13026                 vxlan_encap_conf.select_vlan = 1;
13027         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13028                 vxlan_encap_conf.select_vlan = 0;
13029                 vxlan_encap_conf.select_tos_ttl = 1;
13030         }
13031         if (strcmp(res->ip_version, "ipv4") == 0)
13032                 vxlan_encap_conf.select_ipv4 = 1;
13033         else if (strcmp(res->ip_version, "ipv6") == 0)
13034                 vxlan_encap_conf.select_ipv4 = 0;
13035         else
13036                 return;
13037         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13038         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13039         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13040         vxlan_encap_conf.ip_tos = res->tos;
13041         vxlan_encap_conf.ip_ttl = res->ttl;
13042         if (vxlan_encap_conf.select_ipv4) {
13043                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13044                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13045         } else {
13046                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13047                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13048         }
13049         if (vxlan_encap_conf.select_vlan)
13050                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13051         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13052                    RTE_ETHER_ADDR_LEN);
13053         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13054                    RTE_ETHER_ADDR_LEN);
13055 }
13056
13057 cmdline_parse_inst_t cmd_set_vxlan = {
13058         .f = cmd_set_vxlan_parsed,
13059         .data = NULL,
13060         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13061                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13062                 " eth-src <eth-src> eth-dst <eth-dst>",
13063         .tokens = {
13064                 (void *)&cmd_set_vxlan_set,
13065                 (void *)&cmd_set_vxlan_vxlan,
13066                 (void *)&cmd_set_vxlan_ip_version,
13067                 (void *)&cmd_set_vxlan_ip_version_value,
13068                 (void *)&cmd_set_vxlan_vni,
13069                 (void *)&cmd_set_vxlan_vni_value,
13070                 (void *)&cmd_set_vxlan_udp_src,
13071                 (void *)&cmd_set_vxlan_udp_src_value,
13072                 (void *)&cmd_set_vxlan_udp_dst,
13073                 (void *)&cmd_set_vxlan_udp_dst_value,
13074                 (void *)&cmd_set_vxlan_ip_src,
13075                 (void *)&cmd_set_vxlan_ip_src_value,
13076                 (void *)&cmd_set_vxlan_ip_dst,
13077                 (void *)&cmd_set_vxlan_ip_dst_value,
13078                 (void *)&cmd_set_vxlan_eth_src,
13079                 (void *)&cmd_set_vxlan_eth_src_value,
13080                 (void *)&cmd_set_vxlan_eth_dst,
13081                 (void *)&cmd_set_vxlan_eth_dst_value,
13082                 NULL,
13083         },
13084 };
13085
13086 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13087         .f = cmd_set_vxlan_parsed,
13088         .data = NULL,
13089         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13090                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13091                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13092                 " eth-dst <eth-dst>",
13093         .tokens = {
13094                 (void *)&cmd_set_vxlan_set,
13095                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13096                 (void *)&cmd_set_vxlan_ip_version,
13097                 (void *)&cmd_set_vxlan_ip_version_value,
13098                 (void *)&cmd_set_vxlan_vni,
13099                 (void *)&cmd_set_vxlan_vni_value,
13100                 (void *)&cmd_set_vxlan_udp_src,
13101                 (void *)&cmd_set_vxlan_udp_src_value,
13102                 (void *)&cmd_set_vxlan_udp_dst,
13103                 (void *)&cmd_set_vxlan_udp_dst_value,
13104                 (void *)&cmd_set_vxlan_ip_tos,
13105                 (void *)&cmd_set_vxlan_ip_tos_value,
13106                 (void *)&cmd_set_vxlan_ip_ttl,
13107                 (void *)&cmd_set_vxlan_ip_ttl_value,
13108                 (void *)&cmd_set_vxlan_ip_src,
13109                 (void *)&cmd_set_vxlan_ip_src_value,
13110                 (void *)&cmd_set_vxlan_ip_dst,
13111                 (void *)&cmd_set_vxlan_ip_dst_value,
13112                 (void *)&cmd_set_vxlan_eth_src,
13113                 (void *)&cmd_set_vxlan_eth_src_value,
13114                 (void *)&cmd_set_vxlan_eth_dst,
13115                 (void *)&cmd_set_vxlan_eth_dst_value,
13116                 NULL,
13117         },
13118 };
13119
13120 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13121         .f = cmd_set_vxlan_parsed,
13122         .data = NULL,
13123         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13124                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13125                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13126                 " <eth-dst>",
13127         .tokens = {
13128                 (void *)&cmd_set_vxlan_set,
13129                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13130                 (void *)&cmd_set_vxlan_ip_version,
13131                 (void *)&cmd_set_vxlan_ip_version_value,
13132                 (void *)&cmd_set_vxlan_vni,
13133                 (void *)&cmd_set_vxlan_vni_value,
13134                 (void *)&cmd_set_vxlan_udp_src,
13135                 (void *)&cmd_set_vxlan_udp_src_value,
13136                 (void *)&cmd_set_vxlan_udp_dst,
13137                 (void *)&cmd_set_vxlan_udp_dst_value,
13138                 (void *)&cmd_set_vxlan_ip_src,
13139                 (void *)&cmd_set_vxlan_ip_src_value,
13140                 (void *)&cmd_set_vxlan_ip_dst,
13141                 (void *)&cmd_set_vxlan_ip_dst_value,
13142                 (void *)&cmd_set_vxlan_vlan,
13143                 (void *)&cmd_set_vxlan_vlan_value,
13144                 (void *)&cmd_set_vxlan_eth_src,
13145                 (void *)&cmd_set_vxlan_eth_src_value,
13146                 (void *)&cmd_set_vxlan_eth_dst,
13147                 (void *)&cmd_set_vxlan_eth_dst_value,
13148                 NULL,
13149         },
13150 };
13151
13152 /** Set NVGRE encapsulation details */
13153 struct cmd_set_nvgre_result {
13154         cmdline_fixed_string_t set;
13155         cmdline_fixed_string_t nvgre;
13156         cmdline_fixed_string_t pos_token;
13157         cmdline_fixed_string_t ip_version;
13158         uint32_t tni;
13159         cmdline_ipaddr_t ip_src;
13160         cmdline_ipaddr_t ip_dst;
13161         uint16_t tci;
13162         struct rte_ether_addr eth_src;
13163         struct rte_ether_addr eth_dst;
13164 };
13165
13166 cmdline_parse_token_string_t cmd_set_nvgre_set =
13167         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13168 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13169         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13170 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13171         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13172                                  "nvgre-with-vlan");
13173 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13174         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13175                                  "ip-version");
13176 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13177         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13178                                  "ipv4#ipv6");
13179 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13180         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13181                                  "tni");
13182 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13183         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13184 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13185         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13186                                  "ip-src");
13187 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13188         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13189 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13190         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13191                                  "ip-dst");
13192 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13193         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13194 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13195         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13196                                  "vlan-tci");
13197 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13198         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13199 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13200         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13201                                  "eth-src");
13202 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13203         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13204 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13205         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13206                                  "eth-dst");
13207 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13209
13210 static void cmd_set_nvgre_parsed(void *parsed_result,
13211         __rte_unused struct cmdline *cl,
13212         __rte_unused void *data)
13213 {
13214         struct cmd_set_nvgre_result *res = parsed_result;
13215         union {
13216                 uint32_t nvgre_tni;
13217                 uint8_t tni[4];
13218         } id = {
13219                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13220         };
13221
13222         if (strcmp(res->nvgre, "nvgre") == 0)
13223                 nvgre_encap_conf.select_vlan = 0;
13224         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13225                 nvgre_encap_conf.select_vlan = 1;
13226         if (strcmp(res->ip_version, "ipv4") == 0)
13227                 nvgre_encap_conf.select_ipv4 = 1;
13228         else if (strcmp(res->ip_version, "ipv6") == 0)
13229                 nvgre_encap_conf.select_ipv4 = 0;
13230         else
13231                 return;
13232         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13233         if (nvgre_encap_conf.select_ipv4) {
13234                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13235                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13236         } else {
13237                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13238                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13239         }
13240         if (nvgre_encap_conf.select_vlan)
13241                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13242         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13243                    RTE_ETHER_ADDR_LEN);
13244         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13245                    RTE_ETHER_ADDR_LEN);
13246 }
13247
13248 cmdline_parse_inst_t cmd_set_nvgre = {
13249         .f = cmd_set_nvgre_parsed,
13250         .data = NULL,
13251         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13252                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13253                 " eth-dst <eth-dst>",
13254         .tokens = {
13255                 (void *)&cmd_set_nvgre_set,
13256                 (void *)&cmd_set_nvgre_nvgre,
13257                 (void *)&cmd_set_nvgre_ip_version,
13258                 (void *)&cmd_set_nvgre_ip_version_value,
13259                 (void *)&cmd_set_nvgre_tni,
13260                 (void *)&cmd_set_nvgre_tni_value,
13261                 (void *)&cmd_set_nvgre_ip_src,
13262                 (void *)&cmd_set_nvgre_ip_src_value,
13263                 (void *)&cmd_set_nvgre_ip_dst,
13264                 (void *)&cmd_set_nvgre_ip_dst_value,
13265                 (void *)&cmd_set_nvgre_eth_src,
13266                 (void *)&cmd_set_nvgre_eth_src_value,
13267                 (void *)&cmd_set_nvgre_eth_dst,
13268                 (void *)&cmd_set_nvgre_eth_dst_value,
13269                 NULL,
13270         },
13271 };
13272
13273 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13274         .f = cmd_set_nvgre_parsed,
13275         .data = NULL,
13276         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13277                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13278                 " eth-src <eth-src> eth-dst <eth-dst>",
13279         .tokens = {
13280                 (void *)&cmd_set_nvgre_set,
13281                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13282                 (void *)&cmd_set_nvgre_ip_version,
13283                 (void *)&cmd_set_nvgre_ip_version_value,
13284                 (void *)&cmd_set_nvgre_tni,
13285                 (void *)&cmd_set_nvgre_tni_value,
13286                 (void *)&cmd_set_nvgre_ip_src,
13287                 (void *)&cmd_set_nvgre_ip_src_value,
13288                 (void *)&cmd_set_nvgre_ip_dst,
13289                 (void *)&cmd_set_nvgre_ip_dst_value,
13290                 (void *)&cmd_set_nvgre_vlan,
13291                 (void *)&cmd_set_nvgre_vlan_value,
13292                 (void *)&cmd_set_nvgre_eth_src,
13293                 (void *)&cmd_set_nvgre_eth_src_value,
13294                 (void *)&cmd_set_nvgre_eth_dst,
13295                 (void *)&cmd_set_nvgre_eth_dst_value,
13296                 NULL,
13297         },
13298 };
13299
13300 /** Set L2 encapsulation details */
13301 struct cmd_set_l2_encap_result {
13302         cmdline_fixed_string_t set;
13303         cmdline_fixed_string_t l2_encap;
13304         cmdline_fixed_string_t pos_token;
13305         cmdline_fixed_string_t ip_version;
13306         uint32_t vlan_present:1;
13307         uint16_t tci;
13308         struct rte_ether_addr eth_src;
13309         struct rte_ether_addr eth_dst;
13310 };
13311
13312 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13313         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13314 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13315         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13316 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13317         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13318                                  "l2_encap-with-vlan");
13319 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13320         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13321                                  "ip-version");
13322 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13323         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13324                                  "ipv4#ipv6");
13325 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13326         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13327                                  "vlan-tci");
13328 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13329         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13330 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13331         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13332                                  "eth-src");
13333 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13334         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13335 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13336         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13337                                  "eth-dst");
13338 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13339         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13340
13341 static void cmd_set_l2_encap_parsed(void *parsed_result,
13342         __rte_unused struct cmdline *cl,
13343         __rte_unused void *data)
13344 {
13345         struct cmd_set_l2_encap_result *res = parsed_result;
13346
13347         if (strcmp(res->l2_encap, "l2_encap") == 0)
13348                 l2_encap_conf.select_vlan = 0;
13349         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13350                 l2_encap_conf.select_vlan = 1;
13351         if (strcmp(res->ip_version, "ipv4") == 0)
13352                 l2_encap_conf.select_ipv4 = 1;
13353         else if (strcmp(res->ip_version, "ipv6") == 0)
13354                 l2_encap_conf.select_ipv4 = 0;
13355         else
13356                 return;
13357         if (l2_encap_conf.select_vlan)
13358                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13359         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13360                    RTE_ETHER_ADDR_LEN);
13361         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13362                    RTE_ETHER_ADDR_LEN);
13363 }
13364
13365 cmdline_parse_inst_t cmd_set_l2_encap = {
13366         .f = cmd_set_l2_encap_parsed,
13367         .data = NULL,
13368         .help_str = "set l2_encap ip-version ipv4|ipv6"
13369                 " eth-src <eth-src> eth-dst <eth-dst>",
13370         .tokens = {
13371                 (void *)&cmd_set_l2_encap_set,
13372                 (void *)&cmd_set_l2_encap_l2_encap,
13373                 (void *)&cmd_set_l2_encap_ip_version,
13374                 (void *)&cmd_set_l2_encap_ip_version_value,
13375                 (void *)&cmd_set_l2_encap_eth_src,
13376                 (void *)&cmd_set_l2_encap_eth_src_value,
13377                 (void *)&cmd_set_l2_encap_eth_dst,
13378                 (void *)&cmd_set_l2_encap_eth_dst_value,
13379                 NULL,
13380         },
13381 };
13382
13383 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13384         .f = cmd_set_l2_encap_parsed,
13385         .data = NULL,
13386         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13387                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13388         .tokens = {
13389                 (void *)&cmd_set_l2_encap_set,
13390                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13391                 (void *)&cmd_set_l2_encap_ip_version,
13392                 (void *)&cmd_set_l2_encap_ip_version_value,
13393                 (void *)&cmd_set_l2_encap_vlan,
13394                 (void *)&cmd_set_l2_encap_vlan_value,
13395                 (void *)&cmd_set_l2_encap_eth_src,
13396                 (void *)&cmd_set_l2_encap_eth_src_value,
13397                 (void *)&cmd_set_l2_encap_eth_dst,
13398                 (void *)&cmd_set_l2_encap_eth_dst_value,
13399                 NULL,
13400         },
13401 };
13402
13403 /** Set L2 decapsulation details */
13404 struct cmd_set_l2_decap_result {
13405         cmdline_fixed_string_t set;
13406         cmdline_fixed_string_t l2_decap;
13407         cmdline_fixed_string_t pos_token;
13408         uint32_t vlan_present:1;
13409 };
13410
13411 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13412         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13413 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13414         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13415                                  "l2_decap");
13416 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13417         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13418                                  "l2_decap-with-vlan");
13419
13420 static void cmd_set_l2_decap_parsed(void *parsed_result,
13421         __rte_unused struct cmdline *cl,
13422         __rte_unused void *data)
13423 {
13424         struct cmd_set_l2_decap_result *res = parsed_result;
13425
13426         if (strcmp(res->l2_decap, "l2_decap") == 0)
13427                 l2_decap_conf.select_vlan = 0;
13428         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13429                 l2_decap_conf.select_vlan = 1;
13430 }
13431
13432 cmdline_parse_inst_t cmd_set_l2_decap = {
13433         .f = cmd_set_l2_decap_parsed,
13434         .data = NULL,
13435         .help_str = "set l2_decap",
13436         .tokens = {
13437                 (void *)&cmd_set_l2_decap_set,
13438                 (void *)&cmd_set_l2_decap_l2_decap,
13439                 NULL,
13440         },
13441 };
13442
13443 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13444         .f = cmd_set_l2_decap_parsed,
13445         .data = NULL,
13446         .help_str = "set l2_decap-with-vlan",
13447         .tokens = {
13448                 (void *)&cmd_set_l2_decap_set,
13449                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13450                 NULL,
13451         },
13452 };
13453
13454 /** Set MPLSoGRE encapsulation details */
13455 struct cmd_set_mplsogre_encap_result {
13456         cmdline_fixed_string_t set;
13457         cmdline_fixed_string_t mplsogre;
13458         cmdline_fixed_string_t pos_token;
13459         cmdline_fixed_string_t ip_version;
13460         uint32_t vlan_present:1;
13461         uint32_t label;
13462         cmdline_ipaddr_t ip_src;
13463         cmdline_ipaddr_t ip_dst;
13464         uint16_t tci;
13465         struct rte_ether_addr eth_src;
13466         struct rte_ether_addr eth_dst;
13467 };
13468
13469 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13470         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13471                                  "set");
13472 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13473         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13474                                  "mplsogre_encap");
13475 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13476         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13477                                  mplsogre, "mplsogre_encap-with-vlan");
13478 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13479         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13480                                  pos_token, "ip-version");
13481 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13482         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13483                                  ip_version, "ipv4#ipv6");
13484 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13485         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13486                                  pos_token, "label");
13487 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13488         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13489                               RTE_UINT32);
13490 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13491         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13492                                  pos_token, "ip-src");
13493 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13494         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13495 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13496         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13497                                  pos_token, "ip-dst");
13498 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13499         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13500 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13501         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13502                                  pos_token, "vlan-tci");
13503 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13504         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13505                               RTE_UINT16);
13506 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13507         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13508                                  pos_token, "eth-src");
13509 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13510         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13511                                     eth_src);
13512 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13513         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13514                                  pos_token, "eth-dst");
13515 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13516         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13517                                     eth_dst);
13518
13519 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13520         __rte_unused struct cmdline *cl,
13521         __rte_unused void *data)
13522 {
13523         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13524         union {
13525                 uint32_t mplsogre_label;
13526                 uint8_t label[4];
13527         } id = {
13528                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13529         };
13530
13531         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13532                 mplsogre_encap_conf.select_vlan = 0;
13533         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13534                 mplsogre_encap_conf.select_vlan = 1;
13535         if (strcmp(res->ip_version, "ipv4") == 0)
13536                 mplsogre_encap_conf.select_ipv4 = 1;
13537         else if (strcmp(res->ip_version, "ipv6") == 0)
13538                 mplsogre_encap_conf.select_ipv4 = 0;
13539         else
13540                 return;
13541         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13542         if (mplsogre_encap_conf.select_ipv4) {
13543                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13544                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13545         } else {
13546                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13547                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13548         }
13549         if (mplsogre_encap_conf.select_vlan)
13550                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13551         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13552                    RTE_ETHER_ADDR_LEN);
13553         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13554                    RTE_ETHER_ADDR_LEN);
13555 }
13556
13557 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13558         .f = cmd_set_mplsogre_encap_parsed,
13559         .data = NULL,
13560         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13561                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13562                 " eth-dst <eth-dst>",
13563         .tokens = {
13564                 (void *)&cmd_set_mplsogre_encap_set,
13565                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13566                 (void *)&cmd_set_mplsogre_encap_ip_version,
13567                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13568                 (void *)&cmd_set_mplsogre_encap_label,
13569                 (void *)&cmd_set_mplsogre_encap_label_value,
13570                 (void *)&cmd_set_mplsogre_encap_ip_src,
13571                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13572                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13573                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13574                 (void *)&cmd_set_mplsogre_encap_eth_src,
13575                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13576                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13577                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13578                 NULL,
13579         },
13580 };
13581
13582 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13583         .f = cmd_set_mplsogre_encap_parsed,
13584         .data = NULL,
13585         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13586                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13587                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13588         .tokens = {
13589                 (void *)&cmd_set_mplsogre_encap_set,
13590                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13591                 (void *)&cmd_set_mplsogre_encap_ip_version,
13592                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13593                 (void *)&cmd_set_mplsogre_encap_label,
13594                 (void *)&cmd_set_mplsogre_encap_label_value,
13595                 (void *)&cmd_set_mplsogre_encap_ip_src,
13596                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13597                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13598                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13599                 (void *)&cmd_set_mplsogre_encap_vlan,
13600                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13601                 (void *)&cmd_set_mplsogre_encap_eth_src,
13602                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13603                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13604                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13605                 NULL,
13606         },
13607 };
13608
13609 /** Set MPLSoGRE decapsulation details */
13610 struct cmd_set_mplsogre_decap_result {
13611         cmdline_fixed_string_t set;
13612         cmdline_fixed_string_t mplsogre;
13613         cmdline_fixed_string_t pos_token;
13614         cmdline_fixed_string_t ip_version;
13615         uint32_t vlan_present:1;
13616 };
13617
13618 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13619         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13620                                  "set");
13621 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13622         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13623                                  "mplsogre_decap");
13624 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13625         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13626                                  mplsogre, "mplsogre_decap-with-vlan");
13627 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13628         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13629                                  pos_token, "ip-version");
13630 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13631         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13632                                  ip_version, "ipv4#ipv6");
13633
13634 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13635         __rte_unused struct cmdline *cl,
13636         __rte_unused void *data)
13637 {
13638         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13639
13640         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13641                 mplsogre_decap_conf.select_vlan = 0;
13642         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13643                 mplsogre_decap_conf.select_vlan = 1;
13644         if (strcmp(res->ip_version, "ipv4") == 0)
13645                 mplsogre_decap_conf.select_ipv4 = 1;
13646         else if (strcmp(res->ip_version, "ipv6") == 0)
13647                 mplsogre_decap_conf.select_ipv4 = 0;
13648 }
13649
13650 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13651         .f = cmd_set_mplsogre_decap_parsed,
13652         .data = NULL,
13653         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13654         .tokens = {
13655                 (void *)&cmd_set_mplsogre_decap_set,
13656                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13657                 (void *)&cmd_set_mplsogre_decap_ip_version,
13658                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13659                 NULL,
13660         },
13661 };
13662
13663 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13664         .f = cmd_set_mplsogre_decap_parsed,
13665         .data = NULL,
13666         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13667         .tokens = {
13668                 (void *)&cmd_set_mplsogre_decap_set,
13669                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13670                 (void *)&cmd_set_mplsogre_decap_ip_version,
13671                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13672                 NULL,
13673         },
13674 };
13675
13676 /** Set MPLSoUDP encapsulation details */
13677 struct cmd_set_mplsoudp_encap_result {
13678         cmdline_fixed_string_t set;
13679         cmdline_fixed_string_t mplsoudp;
13680         cmdline_fixed_string_t pos_token;
13681         cmdline_fixed_string_t ip_version;
13682         uint32_t vlan_present:1;
13683         uint32_t label;
13684         uint16_t udp_src;
13685         uint16_t udp_dst;
13686         cmdline_ipaddr_t ip_src;
13687         cmdline_ipaddr_t ip_dst;
13688         uint16_t tci;
13689         struct rte_ether_addr eth_src;
13690         struct rte_ether_addr eth_dst;
13691 };
13692
13693 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13694         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13695                                  "set");
13696 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13697         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13698                                  "mplsoudp_encap");
13699 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13700         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13701                                  mplsoudp, "mplsoudp_encap-with-vlan");
13702 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13703         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13704                                  pos_token, "ip-version");
13705 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13706         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13707                                  ip_version, "ipv4#ipv6");
13708 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13709         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13710                                  pos_token, "label");
13711 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13712         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13713                               RTE_UINT32);
13714 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13715         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13716                                  pos_token, "udp-src");
13717 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13718         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13719                               RTE_UINT16);
13720 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13721         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13722                                  pos_token, "udp-dst");
13723 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13724         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13725                               RTE_UINT16);
13726 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13727         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13728                                  pos_token, "ip-src");
13729 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13730         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13731 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13732         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13733                                  pos_token, "ip-dst");
13734 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13735         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13736 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13737         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13738                                  pos_token, "vlan-tci");
13739 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13740         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13741                               RTE_UINT16);
13742 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13743         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13744                                  pos_token, "eth-src");
13745 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13746         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13747                                     eth_src);
13748 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13749         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13750                                  pos_token, "eth-dst");
13751 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13752         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13753                                     eth_dst);
13754
13755 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13756         __rte_unused struct cmdline *cl,
13757         __rte_unused void *data)
13758 {
13759         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13760         union {
13761                 uint32_t mplsoudp_label;
13762                 uint8_t label[4];
13763         } id = {
13764                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13765         };
13766
13767         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13768                 mplsoudp_encap_conf.select_vlan = 0;
13769         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13770                 mplsoudp_encap_conf.select_vlan = 1;
13771         if (strcmp(res->ip_version, "ipv4") == 0)
13772                 mplsoudp_encap_conf.select_ipv4 = 1;
13773         else if (strcmp(res->ip_version, "ipv6") == 0)
13774                 mplsoudp_encap_conf.select_ipv4 = 0;
13775         else
13776                 return;
13777         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13778         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13779         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13780         if (mplsoudp_encap_conf.select_ipv4) {
13781                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13782                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13783         } else {
13784                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13785                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13786         }
13787         if (mplsoudp_encap_conf.select_vlan)
13788                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13789         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13790                    RTE_ETHER_ADDR_LEN);
13791         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13792                    RTE_ETHER_ADDR_LEN);
13793 }
13794
13795 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13796         .f = cmd_set_mplsoudp_encap_parsed,
13797         .data = NULL,
13798         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13799                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13800                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13801         .tokens = {
13802                 (void *)&cmd_set_mplsoudp_encap_set,
13803                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13804                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13805                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13806                 (void *)&cmd_set_mplsoudp_encap_label,
13807                 (void *)&cmd_set_mplsoudp_encap_label_value,
13808                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13809                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13810                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13811                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13812                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13813                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13814                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13815                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13816                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13817                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13818                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13819                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13820                 NULL,
13821         },
13822 };
13823
13824 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13825         .f = cmd_set_mplsoudp_encap_parsed,
13826         .data = NULL,
13827         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13828                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13829                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13830                 " eth-src <eth-src> eth-dst <eth-dst>",
13831         .tokens = {
13832                 (void *)&cmd_set_mplsoudp_encap_set,
13833                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13834                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13835                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13836                 (void *)&cmd_set_mplsoudp_encap_label,
13837                 (void *)&cmd_set_mplsoudp_encap_label_value,
13838                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13839                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13840                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13841                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13842                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13843                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13844                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13845                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13846                 (void *)&cmd_set_mplsoudp_encap_vlan,
13847                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13848                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13849                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13850                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13851                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13852                 NULL,
13853         },
13854 };
13855
13856 /** Set MPLSoUDP decapsulation details */
13857 struct cmd_set_mplsoudp_decap_result {
13858         cmdline_fixed_string_t set;
13859         cmdline_fixed_string_t mplsoudp;
13860         cmdline_fixed_string_t pos_token;
13861         cmdline_fixed_string_t ip_version;
13862         uint32_t vlan_present:1;
13863 };
13864
13865 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13866         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13867                                  "set");
13868 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13869         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13870                                  "mplsoudp_decap");
13871 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13872         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13873                                  mplsoudp, "mplsoudp_decap-with-vlan");
13874 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13875         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13876                                  pos_token, "ip-version");
13877 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13878         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13879                                  ip_version, "ipv4#ipv6");
13880
13881 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13882         __rte_unused struct cmdline *cl,
13883         __rte_unused void *data)
13884 {
13885         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13886
13887         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13888                 mplsoudp_decap_conf.select_vlan = 0;
13889         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13890                 mplsoudp_decap_conf.select_vlan = 1;
13891         if (strcmp(res->ip_version, "ipv4") == 0)
13892                 mplsoudp_decap_conf.select_ipv4 = 1;
13893         else if (strcmp(res->ip_version, "ipv6") == 0)
13894                 mplsoudp_decap_conf.select_ipv4 = 0;
13895 }
13896
13897 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13898         .f = cmd_set_mplsoudp_decap_parsed,
13899         .data = NULL,
13900         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13901         .tokens = {
13902                 (void *)&cmd_set_mplsoudp_decap_set,
13903                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13904                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13905                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13906                 NULL,
13907         },
13908 };
13909
13910 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13911         .f = cmd_set_mplsoudp_decap_parsed,
13912         .data = NULL,
13913         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13914         .tokens = {
13915                 (void *)&cmd_set_mplsoudp_decap_set,
13916                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13917                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13918                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13919                 NULL,
13920         },
13921 };
13922
13923 /** Set connection tracking object common details */
13924 struct cmd_set_conntrack_common_result {
13925         cmdline_fixed_string_t set;
13926         cmdline_fixed_string_t conntrack;
13927         cmdline_fixed_string_t common;
13928         cmdline_fixed_string_t peer;
13929         cmdline_fixed_string_t is_orig;
13930         cmdline_fixed_string_t enable;
13931         cmdline_fixed_string_t live;
13932         cmdline_fixed_string_t sack;
13933         cmdline_fixed_string_t cack;
13934         cmdline_fixed_string_t last_dir;
13935         cmdline_fixed_string_t liberal;
13936         cmdline_fixed_string_t state;
13937         cmdline_fixed_string_t max_ack_win;
13938         cmdline_fixed_string_t retrans;
13939         cmdline_fixed_string_t last_win;
13940         cmdline_fixed_string_t last_seq;
13941         cmdline_fixed_string_t last_ack;
13942         cmdline_fixed_string_t last_end;
13943         cmdline_fixed_string_t last_index;
13944         uint8_t stat;
13945         uint8_t factor;
13946         uint16_t peer_port;
13947         uint32_t is_original;
13948         uint32_t en;
13949         uint32_t is_live;
13950         uint32_t s_ack;
13951         uint32_t c_ack;
13952         uint32_t ld;
13953         uint32_t lb;
13954         uint8_t re_num;
13955         uint8_t li;
13956         uint16_t lw;
13957         uint32_t ls;
13958         uint32_t la;
13959         uint32_t le;
13960 };
13961
13962 cmdline_parse_token_string_t cmd_set_conntrack_set =
13963         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13964                                  set, "set");
13965 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13966         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13967                                  conntrack, "conntrack");
13968 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13969         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13970                                  common, "com");
13971 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13972         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13973                                  peer, "peer");
13974 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13975         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13976                               peer_port, RTE_UINT16);
13977 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13978         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13979                                  is_orig, "is_orig");
13980 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13981         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13982                               is_original, RTE_UINT32);
13983 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13984         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13985                                  enable, "enable");
13986 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13987         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13988                               en, RTE_UINT32);
13989 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
13990         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13991                                  live, "live");
13992 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
13993         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13994                               is_live, RTE_UINT32);
13995 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
13996         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13997                                  sack, "sack");
13998 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
13999         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14000                               s_ack, RTE_UINT32);
14001 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14002         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14003                                  cack, "cack");
14004 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14005         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14006                               c_ack, RTE_UINT32);
14007 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14008         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14009                                  last_dir, "last_dir");
14010 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14011         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14012                               ld, RTE_UINT32);
14013 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14014         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14015                                  liberal, "liberal");
14016 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14017         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14018                               lb, RTE_UINT32);
14019 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14020         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14021                                  state, "state");
14022 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14023         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14024                               stat, RTE_UINT8);
14025 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14026         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14027                                  max_ack_win, "max_ack_win");
14028 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14029         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14030                               factor, RTE_UINT8);
14031 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14032         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14033                                  retrans, "r_lim");
14034 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14035         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14036                               re_num, RTE_UINT8);
14037 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14038         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14039                                  last_win, "last_win");
14040 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14041         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14042                               lw, RTE_UINT16);
14043 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14044         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14045                                  last_seq, "last_seq");
14046 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14047         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14048                               ls, RTE_UINT32);
14049 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14050         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14051                                  last_ack, "last_ack");
14052 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14053         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14054                               la, RTE_UINT32);
14055 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14056         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14057                                  last_end, "last_end");
14058 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14059         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14060                               le, RTE_UINT32);
14061 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14062         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14063                                  last_index, "last_index");
14064 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14065         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14066                               li, RTE_UINT8);
14067
14068 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14069         __rte_unused struct cmdline *cl,
14070         __rte_unused void *data)
14071 {
14072         struct cmd_set_conntrack_common_result *res = parsed_result;
14073
14074         /* No need to swap to big endian. */
14075         conntrack_context.peer_port = res->peer_port;
14076         conntrack_context.is_original_dir = res->is_original;
14077         conntrack_context.enable = res->en;
14078         conntrack_context.live_connection = res->is_live;
14079         conntrack_context.selective_ack = res->s_ack;
14080         conntrack_context.challenge_ack_passed = res->c_ack;
14081         conntrack_context.last_direction = res->ld;
14082         conntrack_context.liberal_mode = res->lb;
14083         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14084         conntrack_context.max_ack_window = res->factor;
14085         conntrack_context.retransmission_limit = res->re_num;
14086         conntrack_context.last_window = res->lw;
14087         conntrack_context.last_index =
14088                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14089         conntrack_context.last_seq = res->ls;
14090         conntrack_context.last_ack = res->la;
14091         conntrack_context.last_end = res->le;
14092 }
14093
14094 cmdline_parse_inst_t cmd_set_conntrack_common = {
14095         .f = cmd_set_conntrack_common_parsed,
14096         .data = NULL,
14097         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14098                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14099                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14100                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14101                 " last_index <flag>",
14102         .tokens = {
14103                 (void *)&cmd_set_conntrack_set,
14104                 (void *)&cmd_set_conntrack_conntrack,
14105                 (void *)&cmd_set_conntrack_common_com,
14106                 (void *)&cmd_set_conntrack_common_peer,
14107                 (void *)&cmd_set_conntrack_common_peer_value,
14108                 (void *)&cmd_set_conntrack_common_is_orig,
14109                 (void *)&cmd_set_conntrack_common_is_orig_value,
14110                 (void *)&cmd_set_conntrack_common_enable,
14111                 (void *)&cmd_set_conntrack_common_enable_value,
14112                 (void *)&cmd_set_conntrack_common_live,
14113                 (void *)&cmd_set_conntrack_common_live_value,
14114                 (void *)&cmd_set_conntrack_common_sack,
14115                 (void *)&cmd_set_conntrack_common_sack_value,
14116                 (void *)&cmd_set_conntrack_common_cack,
14117                 (void *)&cmd_set_conntrack_common_cack_value,
14118                 (void *)&cmd_set_conntrack_common_last_dir,
14119                 (void *)&cmd_set_conntrack_common_last_dir_value,
14120                 (void *)&cmd_set_conntrack_common_liberal,
14121                 (void *)&cmd_set_conntrack_common_liberal_value,
14122                 (void *)&cmd_set_conntrack_common_state,
14123                 (void *)&cmd_set_conntrack_common_state_value,
14124                 (void *)&cmd_set_conntrack_common_max_ackwin,
14125                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14126                 (void *)&cmd_set_conntrack_common_retrans,
14127                 (void *)&cmd_set_conntrack_common_retrans_value,
14128                 (void *)&cmd_set_conntrack_common_last_win,
14129                 (void *)&cmd_set_conntrack_common_last_win_value,
14130                 (void *)&cmd_set_conntrack_common_last_seq,
14131                 (void *)&cmd_set_conntrack_common_last_seq_value,
14132                 (void *)&cmd_set_conntrack_common_last_ack,
14133                 (void *)&cmd_set_conntrack_common_last_ack_value,
14134                 (void *)&cmd_set_conntrack_common_last_end,
14135                 (void *)&cmd_set_conntrack_common_last_end_value,
14136                 (void *)&cmd_set_conntrack_common_last_index,
14137                 (void *)&cmd_set_conntrack_common_last_index_value,
14138                 NULL,
14139         },
14140 };
14141
14142 /** Set connection tracking object both directions' details */
14143 struct cmd_set_conntrack_dir_result {
14144         cmdline_fixed_string_t set;
14145         cmdline_fixed_string_t conntrack;
14146         cmdline_fixed_string_t dir;
14147         cmdline_fixed_string_t scale;
14148         cmdline_fixed_string_t fin;
14149         cmdline_fixed_string_t ack_seen;
14150         cmdline_fixed_string_t unack;
14151         cmdline_fixed_string_t sent_end;
14152         cmdline_fixed_string_t reply_end;
14153         cmdline_fixed_string_t max_win;
14154         cmdline_fixed_string_t max_ack;
14155         uint32_t factor;
14156         uint32_t f;
14157         uint32_t as;
14158         uint32_t un;
14159         uint32_t se;
14160         uint32_t re;
14161         uint32_t mw;
14162         uint32_t ma;
14163 };
14164
14165 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14166         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14167                                  set, "set");
14168 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14169         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14170                                  conntrack, "conntrack");
14171 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14172         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14173                                  dir, "orig#rply");
14174 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14175         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14176                                  scale, "scale");
14177 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14178         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14179                               factor, RTE_UINT32);
14180 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14181         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14182                                  fin, "fin");
14183 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14184         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14185                               f, RTE_UINT32);
14186 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14187         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14188                                  ack_seen, "acked");
14189 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14190         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14191                               as, RTE_UINT32);
14192 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14193         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14194                                  unack, "unack_data");
14195 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14196         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14197                               un, RTE_UINT32);
14198 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14199         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14200                                  sent_end, "sent_end");
14201 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14202         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14203                               se, RTE_UINT32);
14204 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14205         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14206                                  reply_end, "reply_end");
14207 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14208         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14209                               re, RTE_UINT32);
14210 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14211         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14212                                  max_win, "max_win");
14213 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14214         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14215                               mw, RTE_UINT32);
14216 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14217         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14218                                  max_ack, "max_ack");
14219 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14220         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14221                               ma, RTE_UINT32);
14222
14223 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14224         __rte_unused struct cmdline *cl,
14225         __rte_unused void *data)
14226 {
14227         struct cmd_set_conntrack_dir_result *res = parsed_result;
14228         struct rte_flow_tcp_dir_param *dir = NULL;
14229
14230         if (strcmp(res->dir, "orig") == 0)
14231                 dir = &conntrack_context.original_dir;
14232         else if (strcmp(res->dir, "rply") == 0)
14233                 dir = &conntrack_context.reply_dir;
14234         else
14235                 return;
14236         dir->scale = res->factor;
14237         dir->close_initiated = res->f;
14238         dir->last_ack_seen = res->as;
14239         dir->data_unacked = res->un;
14240         dir->sent_end = res->se;
14241         dir->reply_end = res->re;
14242         dir->max_ack = res->ma;
14243         dir->max_win = res->mw;
14244 }
14245
14246 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14247         .f = cmd_set_conntrack_dir_parsed,
14248         .data = NULL,
14249         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14250                     " acked <seen> unack_data <unack> sent_end <sent>"
14251                     " reply_end <reply> max_win <win> max_ack <ack>",
14252         .tokens = {
14253                 (void *)&cmd_set_conntrack_set,
14254                 (void *)&cmd_set_conntrack_conntrack,
14255                 (void *)&cmd_set_conntrack_dir_dir,
14256                 (void *)&cmd_set_conntrack_dir_scale,
14257                 (void *)&cmd_set_conntrack_dir_scale_value,
14258                 (void *)&cmd_set_conntrack_dir_fin,
14259                 (void *)&cmd_set_conntrack_dir_fin_value,
14260                 (void *)&cmd_set_conntrack_dir_ack,
14261                 (void *)&cmd_set_conntrack_dir_ack_value,
14262                 (void *)&cmd_set_conntrack_dir_unack_data,
14263                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14264                 (void *)&cmd_set_conntrack_dir_sent_end,
14265                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14266                 (void *)&cmd_set_conntrack_dir_reply_end,
14267                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14268                 (void *)&cmd_set_conntrack_dir_max_win,
14269                 (void *)&cmd_set_conntrack_dir_max_win_value,
14270                 (void *)&cmd_set_conntrack_dir_max_ack,
14271                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14272                 NULL,
14273         },
14274 };
14275
14276 /* Strict link priority scheduling mode setting */
14277 static void
14278 cmd_strict_link_prio_parsed(
14279         void *parsed_result,
14280         __rte_unused struct cmdline *cl,
14281         __rte_unused void *data)
14282 {
14283         struct cmd_vf_tc_bw_result *res = parsed_result;
14284         int ret = -ENOTSUP;
14285
14286         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14287                 return;
14288
14289 #ifdef RTE_NET_I40E
14290         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14291 #endif
14292
14293         switch (ret) {
14294         case 0:
14295                 break;
14296         case -EINVAL:
14297                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14298                 break;
14299         case -ENODEV:
14300                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14301                 break;
14302         case -ENOTSUP:
14303                 fprintf(stderr, "function not implemented\n");
14304                 break;
14305         default:
14306                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14307         }
14308 }
14309
14310 cmdline_parse_inst_t cmd_strict_link_prio = {
14311         .f = cmd_strict_link_prio_parsed,
14312         .data = NULL,
14313         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14314         .tokens = {
14315                 (void *)&cmd_vf_tc_bw_set,
14316                 (void *)&cmd_vf_tc_bw_tx,
14317                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14318                 (void *)&cmd_vf_tc_bw_port_id,
14319                 (void *)&cmd_vf_tc_bw_tc_map,
14320                 NULL,
14321         },
14322 };
14323
14324 /* Load dynamic device personalization*/
14325 struct cmd_ddp_add_result {
14326         cmdline_fixed_string_t ddp;
14327         cmdline_fixed_string_t add;
14328         portid_t port_id;
14329         char filepath[];
14330 };
14331
14332 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14333         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14334 cmdline_parse_token_string_t cmd_ddp_add_add =
14335         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14336 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14337         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14338                 RTE_UINT16);
14339 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14340         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14341
14342 static void
14343 cmd_ddp_add_parsed(
14344         void *parsed_result,
14345         __rte_unused struct cmdline *cl,
14346         __rte_unused void *data)
14347 {
14348         struct cmd_ddp_add_result *res = parsed_result;
14349         uint8_t *buff;
14350         uint32_t size;
14351         char *filepath;
14352         char *file_fld[2];
14353         int file_num;
14354         int ret = -ENOTSUP;
14355
14356         if (!all_ports_stopped()) {
14357                 fprintf(stderr, "Please stop all ports first\n");
14358                 return;
14359         }
14360
14361         filepath = strdup(res->filepath);
14362         if (filepath == NULL) {
14363                 fprintf(stderr, "Failed to allocate memory\n");
14364                 return;
14365         }
14366         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14367
14368         buff = open_file(file_fld[0], &size);
14369         if (!buff) {
14370                 free((void *)filepath);
14371                 return;
14372         }
14373
14374 #ifdef RTE_NET_I40E
14375         if (ret == -ENOTSUP)
14376                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14377                                                buff, size,
14378                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14379 #endif
14380
14381         if (ret == -EEXIST)
14382                 fprintf(stderr, "Profile has already existed.\n");
14383         else if (ret < 0)
14384                 fprintf(stderr, "Failed to load profile.\n");
14385         else if (file_num == 2)
14386                 save_file(file_fld[1], buff, size);
14387
14388         close_file(buff);
14389         free((void *)filepath);
14390 }
14391
14392 cmdline_parse_inst_t cmd_ddp_add = {
14393         .f = cmd_ddp_add_parsed,
14394         .data = NULL,
14395         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14396         .tokens = {
14397                 (void *)&cmd_ddp_add_ddp,
14398                 (void *)&cmd_ddp_add_add,
14399                 (void *)&cmd_ddp_add_port_id,
14400                 (void *)&cmd_ddp_add_filepath,
14401                 NULL,
14402         },
14403 };
14404
14405 /* Delete dynamic device personalization*/
14406 struct cmd_ddp_del_result {
14407         cmdline_fixed_string_t ddp;
14408         cmdline_fixed_string_t del;
14409         portid_t port_id;
14410         char filepath[];
14411 };
14412
14413 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14414         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14415 cmdline_parse_token_string_t cmd_ddp_del_del =
14416         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14417 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14418         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14419 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14420         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14421
14422 static void
14423 cmd_ddp_del_parsed(
14424         void *parsed_result,
14425         __rte_unused struct cmdline *cl,
14426         __rte_unused void *data)
14427 {
14428         struct cmd_ddp_del_result *res = parsed_result;
14429         uint8_t *buff;
14430         uint32_t size;
14431         int ret = -ENOTSUP;
14432
14433         if (!all_ports_stopped()) {
14434                 fprintf(stderr, "Please stop all ports first\n");
14435                 return;
14436         }
14437
14438         buff = open_file(res->filepath, &size);
14439         if (!buff)
14440                 return;
14441
14442 #ifdef RTE_NET_I40E
14443         if (ret == -ENOTSUP)
14444                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14445                                                buff, size,
14446                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14447 #endif
14448
14449         if (ret == -EACCES)
14450                 fprintf(stderr, "Profile does not exist.\n");
14451         else if (ret < 0)
14452                 fprintf(stderr, "Failed to delete profile.\n");
14453
14454         close_file(buff);
14455 }
14456
14457 cmdline_parse_inst_t cmd_ddp_del = {
14458         .f = cmd_ddp_del_parsed,
14459         .data = NULL,
14460         .help_str = "ddp del <port_id> <backup_profile_path>",
14461         .tokens = {
14462                 (void *)&cmd_ddp_del_ddp,
14463                 (void *)&cmd_ddp_del_del,
14464                 (void *)&cmd_ddp_del_port_id,
14465                 (void *)&cmd_ddp_del_filepath,
14466                 NULL,
14467         },
14468 };
14469
14470 /* Get dynamic device personalization profile info */
14471 struct cmd_ddp_info_result {
14472         cmdline_fixed_string_t ddp;
14473         cmdline_fixed_string_t get;
14474         cmdline_fixed_string_t info;
14475         char filepath[];
14476 };
14477
14478 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14479         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14480 cmdline_parse_token_string_t cmd_ddp_info_get =
14481         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14482 cmdline_parse_token_string_t cmd_ddp_info_info =
14483         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14484 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14485         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14486
14487 static void
14488 cmd_ddp_info_parsed(
14489         void *parsed_result,
14490         __rte_unused struct cmdline *cl,
14491         __rte_unused void *data)
14492 {
14493         struct cmd_ddp_info_result *res = parsed_result;
14494         uint8_t *pkg;
14495         uint32_t pkg_size;
14496         int ret = -ENOTSUP;
14497 #ifdef RTE_NET_I40E
14498         uint32_t i, j, n;
14499         uint8_t *buff;
14500         uint32_t buff_size = 0;
14501         struct rte_pmd_i40e_profile_info info;
14502         uint32_t dev_num = 0;
14503         struct rte_pmd_i40e_ddp_device_id *devs;
14504         uint32_t proto_num = 0;
14505         struct rte_pmd_i40e_proto_info *proto = NULL;
14506         uint32_t pctype_num = 0;
14507         struct rte_pmd_i40e_ptype_info *pctype;
14508         uint32_t ptype_num = 0;
14509         struct rte_pmd_i40e_ptype_info *ptype;
14510         uint8_t proto_id;
14511
14512 #endif
14513
14514         pkg = open_file(res->filepath, &pkg_size);
14515         if (!pkg)
14516                 return;
14517
14518 #ifdef RTE_NET_I40E
14519         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14520                                 (uint8_t *)&info, sizeof(info),
14521                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14522         if (!ret) {
14523                 printf("Global Track id:       0x%x\n", info.track_id);
14524                 printf("Global Version:        %d.%d.%d.%d\n",
14525                         info.version.major,
14526                         info.version.minor,
14527                         info.version.update,
14528                         info.version.draft);
14529                 printf("Global Package name:   %s\n\n", info.name);
14530         }
14531
14532         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14533                                 (uint8_t *)&info, sizeof(info),
14534                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14535         if (!ret) {
14536                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14537                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14538                         info.version.major,
14539                         info.version.minor,
14540                         info.version.update,
14541                         info.version.draft);
14542                 printf("i40e Profile name:     %s\n\n", info.name);
14543         }
14544
14545         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14546                                 (uint8_t *)&buff_size, sizeof(buff_size),
14547                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14548         if (!ret && buff_size) {
14549                 buff = (uint8_t *)malloc(buff_size);
14550                 if (buff) {
14551                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14552                                                 buff, buff_size,
14553                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14554                         if (!ret)
14555                                 printf("Package Notes:\n%s\n\n", buff);
14556                         free(buff);
14557                 }
14558         }
14559
14560         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14561                                 (uint8_t *)&dev_num, sizeof(dev_num),
14562                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14563         if (!ret && dev_num) {
14564                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14565                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14566                 if (devs) {
14567                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14568                                                 (uint8_t *)devs, buff_size,
14569                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14570                         if (!ret) {
14571                                 printf("List of supported devices:\n");
14572                                 for (i = 0; i < dev_num; i++) {
14573                                         printf("  %04X:%04X %04X:%04X\n",
14574                                                 devs[i].vendor_dev_id >> 16,
14575                                                 devs[i].vendor_dev_id & 0xFFFF,
14576                                                 devs[i].sub_vendor_dev_id >> 16,
14577                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14578                                 }
14579                                 printf("\n");
14580                         }
14581                         free(devs);
14582                 }
14583         }
14584
14585         /* get information about protocols and packet types */
14586         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14587                 (uint8_t *)&proto_num, sizeof(proto_num),
14588                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14589         if (ret || !proto_num)
14590                 goto no_print_return;
14591
14592         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14593         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14594         if (!proto)
14595                 goto no_print_return;
14596
14597         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14598                                         buff_size,
14599                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14600         if (!ret) {
14601                 printf("List of used protocols:\n");
14602                 for (i = 0; i < proto_num; i++)
14603                         printf("  %2u: %s\n", proto[i].proto_id,
14604                                proto[i].name);
14605                 printf("\n");
14606         }
14607         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14608                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14609                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14610         if (ret || !pctype_num)
14611                 goto no_print_pctypes;
14612
14613         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14614         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14615         if (!pctype)
14616                 goto no_print_pctypes;
14617
14618         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14619                                         buff_size,
14620                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14621         if (ret) {
14622                 free(pctype);
14623                 goto no_print_pctypes;
14624         }
14625
14626         printf("List of defined packet classification types:\n");
14627         for (i = 0; i < pctype_num; i++) {
14628                 printf("  %2u:", pctype[i].ptype_id);
14629                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14630                         proto_id = pctype[i].protocols[j];
14631                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14632                                 for (n = 0; n < proto_num; n++) {
14633                                         if (proto[n].proto_id == proto_id) {
14634                                                 printf(" %s", proto[n].name);
14635                                                 break;
14636                                         }
14637                                 }
14638                         }
14639                 }
14640                 printf("\n");
14641         }
14642         printf("\n");
14643         free(pctype);
14644
14645 no_print_pctypes:
14646
14647         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14648                                         sizeof(ptype_num),
14649                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14650         if (ret || !ptype_num)
14651                 goto no_print_return;
14652
14653         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14654         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14655         if (!ptype)
14656                 goto no_print_return;
14657
14658         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14659                                         buff_size,
14660                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14661         if (ret) {
14662                 free(ptype);
14663                 goto no_print_return;
14664         }
14665         printf("List of defined packet types:\n");
14666         for (i = 0; i < ptype_num; i++) {
14667                 printf("  %2u:", ptype[i].ptype_id);
14668                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14669                         proto_id = ptype[i].protocols[j];
14670                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14671                                 for (n = 0; n < proto_num; n++) {
14672                                         if (proto[n].proto_id == proto_id) {
14673                                                 printf(" %s", proto[n].name);
14674                                                 break;
14675                                         }
14676                                 }
14677                         }
14678                 }
14679                 printf("\n");
14680         }
14681         free(ptype);
14682         printf("\n");
14683
14684         ret = 0;
14685 no_print_return:
14686         if (proto)
14687                 free(proto);
14688 #endif
14689         if (ret == -ENOTSUP)
14690                 fprintf(stderr, "Function not supported in PMD driver\n");
14691         close_file(pkg);
14692 }
14693
14694 cmdline_parse_inst_t cmd_ddp_get_info = {
14695         .f = cmd_ddp_info_parsed,
14696         .data = NULL,
14697         .help_str = "ddp get info <profile_path>",
14698         .tokens = {
14699                 (void *)&cmd_ddp_info_ddp,
14700                 (void *)&cmd_ddp_info_get,
14701                 (void *)&cmd_ddp_info_info,
14702                 (void *)&cmd_ddp_info_filepath,
14703                 NULL,
14704         },
14705 };
14706
14707 /* Get dynamic device personalization profile info list*/
14708 #define PROFILE_INFO_SIZE 48
14709 #define MAX_PROFILE_NUM 16
14710
14711 struct cmd_ddp_get_list_result {
14712         cmdline_fixed_string_t ddp;
14713         cmdline_fixed_string_t get;
14714         cmdline_fixed_string_t list;
14715         portid_t port_id;
14716 };
14717
14718 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14719         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14720 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14721         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14722 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14723         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14724 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14725         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14726                 RTE_UINT16);
14727
14728 static void
14729 cmd_ddp_get_list_parsed(
14730         __rte_unused void *parsed_result,
14731         __rte_unused struct cmdline *cl,
14732         __rte_unused void *data)
14733 {
14734 #ifdef RTE_NET_I40E
14735         struct cmd_ddp_get_list_result *res = parsed_result;
14736         struct rte_pmd_i40e_profile_list *p_list;
14737         struct rte_pmd_i40e_profile_info *p_info;
14738         uint32_t p_num;
14739         uint32_t size;
14740         uint32_t i;
14741 #endif
14742         int ret = -ENOTSUP;
14743
14744 #ifdef RTE_NET_I40E
14745         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14746         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14747         if (!p_list) {
14748                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14749                 return;
14750         }
14751
14752         if (ret == -ENOTSUP)
14753                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14754                                                 (uint8_t *)p_list, size);
14755
14756         if (!ret) {
14757                 p_num = p_list->p_count;
14758                 printf("Profile number is: %d\n\n", p_num);
14759
14760                 for (i = 0; i < p_num; i++) {
14761                         p_info = &p_list->p_info[i];
14762                         printf("Profile %d:\n", i);
14763                         printf("Track id:     0x%x\n", p_info->track_id);
14764                         printf("Version:      %d.%d.%d.%d\n",
14765                                p_info->version.major,
14766                                p_info->version.minor,
14767                                p_info->version.update,
14768                                p_info->version.draft);
14769                         printf("Profile name: %s\n\n", p_info->name);
14770                 }
14771         }
14772
14773         free(p_list);
14774 #endif
14775
14776         if (ret < 0)
14777                 fprintf(stderr, "Failed to get ddp list\n");
14778 }
14779
14780 cmdline_parse_inst_t cmd_ddp_get_list = {
14781         .f = cmd_ddp_get_list_parsed,
14782         .data = NULL,
14783         .help_str = "ddp get list <port_id>",
14784         .tokens = {
14785                 (void *)&cmd_ddp_get_list_ddp,
14786                 (void *)&cmd_ddp_get_list_get,
14787                 (void *)&cmd_ddp_get_list_list,
14788                 (void *)&cmd_ddp_get_list_port_id,
14789                 NULL,
14790         },
14791 };
14792
14793 /* Configure input set */
14794 struct cmd_cfg_input_set_result {
14795         cmdline_fixed_string_t port;
14796         cmdline_fixed_string_t cfg;
14797         portid_t port_id;
14798         cmdline_fixed_string_t pctype;
14799         uint8_t pctype_id;
14800         cmdline_fixed_string_t inset_type;
14801         cmdline_fixed_string_t opt;
14802         cmdline_fixed_string_t field;
14803         uint8_t field_idx;
14804 };
14805
14806 static void
14807 cmd_cfg_input_set_parsed(
14808         __rte_unused void *parsed_result,
14809         __rte_unused struct cmdline *cl,
14810         __rte_unused void *data)
14811 {
14812 #ifdef RTE_NET_I40E
14813         struct cmd_cfg_input_set_result *res = parsed_result;
14814         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14815         struct rte_pmd_i40e_inset inset;
14816 #endif
14817         int ret = -ENOTSUP;
14818
14819         if (!all_ports_stopped()) {
14820                 fprintf(stderr, "Please stop all ports first\n");
14821                 return;
14822         }
14823
14824 #ifdef RTE_NET_I40E
14825         if (!strcmp(res->inset_type, "hash_inset"))
14826                 inset_type = INSET_HASH;
14827         else if (!strcmp(res->inset_type, "fdir_inset"))
14828                 inset_type = INSET_FDIR;
14829         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14830                 inset_type = INSET_FDIR_FLX;
14831         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14832                                      &inset, inset_type);
14833         if (ret) {
14834                 fprintf(stderr, "Failed to get input set.\n");
14835                 return;
14836         }
14837
14838         if (!strcmp(res->opt, "get")) {
14839                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14840                                                    res->field_idx);
14841                 if (ret)
14842                         printf("Field index %d is enabled.\n", res->field_idx);
14843                 else
14844                         printf("Field index %d is disabled.\n", res->field_idx);
14845                 return;
14846         } else if (!strcmp(res->opt, "set"))
14847                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14848                                                    res->field_idx);
14849         else if (!strcmp(res->opt, "clear"))
14850                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14851                                                      res->field_idx);
14852         if (ret) {
14853                 fprintf(stderr, "Failed to configure input set field.\n");
14854                 return;
14855         }
14856
14857         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14858                                      &inset, inset_type);
14859         if (ret) {
14860                 fprintf(stderr, "Failed to set input set.\n");
14861                 return;
14862         }
14863 #endif
14864
14865         if (ret == -ENOTSUP)
14866                 fprintf(stderr, "Function not supported\n");
14867 }
14868
14869 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14870         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14871                                  port, "port");
14872 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14873         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14874                                  cfg, "config");
14875 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14876         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14877                               port_id, RTE_UINT16);
14878 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14879         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14880                                  pctype, "pctype");
14881 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14882         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14883                               pctype_id, RTE_UINT8);
14884 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14885         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14886                                  inset_type,
14887                                  "hash_inset#fdir_inset#fdir_flx_inset");
14888 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14889         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14890                                  opt, "get#set#clear");
14891 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14892         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14893                                  field, "field");
14894 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14895         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14896                               field_idx, RTE_UINT8);
14897
14898 cmdline_parse_inst_t cmd_cfg_input_set = {
14899         .f = cmd_cfg_input_set_parsed,
14900         .data = NULL,
14901         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14902                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14903         .tokens = {
14904                 (void *)&cmd_cfg_input_set_port,
14905                 (void *)&cmd_cfg_input_set_cfg,
14906                 (void *)&cmd_cfg_input_set_port_id,
14907                 (void *)&cmd_cfg_input_set_pctype,
14908                 (void *)&cmd_cfg_input_set_pctype_id,
14909                 (void *)&cmd_cfg_input_set_inset_type,
14910                 (void *)&cmd_cfg_input_set_opt,
14911                 (void *)&cmd_cfg_input_set_field,
14912                 (void *)&cmd_cfg_input_set_field_idx,
14913                 NULL,
14914         },
14915 };
14916
14917 /* Clear input set */
14918 struct cmd_clear_input_set_result {
14919         cmdline_fixed_string_t port;
14920         cmdline_fixed_string_t cfg;
14921         portid_t port_id;
14922         cmdline_fixed_string_t pctype;
14923         uint8_t pctype_id;
14924         cmdline_fixed_string_t inset_type;
14925         cmdline_fixed_string_t clear;
14926         cmdline_fixed_string_t all;
14927 };
14928
14929 static void
14930 cmd_clear_input_set_parsed(
14931         __rte_unused void *parsed_result,
14932         __rte_unused struct cmdline *cl,
14933         __rte_unused void *data)
14934 {
14935 #ifdef RTE_NET_I40E
14936         struct cmd_clear_input_set_result *res = parsed_result;
14937         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14938         struct rte_pmd_i40e_inset inset;
14939 #endif
14940         int ret = -ENOTSUP;
14941
14942         if (!all_ports_stopped()) {
14943                 fprintf(stderr, "Please stop all ports first\n");
14944                 return;
14945         }
14946
14947 #ifdef RTE_NET_I40E
14948         if (!strcmp(res->inset_type, "hash_inset"))
14949                 inset_type = INSET_HASH;
14950         else if (!strcmp(res->inset_type, "fdir_inset"))
14951                 inset_type = INSET_FDIR;
14952         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14953                 inset_type = INSET_FDIR_FLX;
14954
14955         memset(&inset, 0, sizeof(inset));
14956
14957         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14958                                      &inset, inset_type);
14959         if (ret) {
14960                 fprintf(stderr, "Failed to clear input set.\n");
14961                 return;
14962         }
14963
14964 #endif
14965
14966         if (ret == -ENOTSUP)
14967                 fprintf(stderr, "Function not supported\n");
14968 }
14969
14970 cmdline_parse_token_string_t cmd_clear_input_set_port =
14971         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14972                                  port, "port");
14973 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14974         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14975                                  cfg, "config");
14976 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14977         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14978                               port_id, RTE_UINT16);
14979 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14980         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14981                                  pctype, "pctype");
14982 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14983         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14984                               pctype_id, RTE_UINT8);
14985 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14986         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14987                                  inset_type,
14988                                  "hash_inset#fdir_inset#fdir_flx_inset");
14989 cmdline_parse_token_string_t cmd_clear_input_set_clear =
14990         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14991                                  clear, "clear");
14992 cmdline_parse_token_string_t cmd_clear_input_set_all =
14993         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14994                                  all, "all");
14995
14996 cmdline_parse_inst_t cmd_clear_input_set = {
14997         .f = cmd_clear_input_set_parsed,
14998         .data = NULL,
14999         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15000                     "fdir_inset|fdir_flx_inset clear all",
15001         .tokens = {
15002                 (void *)&cmd_clear_input_set_port,
15003                 (void *)&cmd_clear_input_set_cfg,
15004                 (void *)&cmd_clear_input_set_port_id,
15005                 (void *)&cmd_clear_input_set_pctype,
15006                 (void *)&cmd_clear_input_set_pctype_id,
15007                 (void *)&cmd_clear_input_set_inset_type,
15008                 (void *)&cmd_clear_input_set_clear,
15009                 (void *)&cmd_clear_input_set_all,
15010                 NULL,
15011         },
15012 };
15013
15014 /* show vf stats */
15015
15016 /* Common result structure for show vf stats */
15017 struct cmd_show_vf_stats_result {
15018         cmdline_fixed_string_t show;
15019         cmdline_fixed_string_t vf;
15020         cmdline_fixed_string_t stats;
15021         portid_t port_id;
15022         uint16_t vf_id;
15023 };
15024
15025 /* Common CLI fields show vf stats*/
15026 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15027         TOKEN_STRING_INITIALIZER
15028                 (struct cmd_show_vf_stats_result,
15029                  show, "show");
15030 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15031         TOKEN_STRING_INITIALIZER
15032                 (struct cmd_show_vf_stats_result,
15033                  vf, "vf");
15034 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15035         TOKEN_STRING_INITIALIZER
15036                 (struct cmd_show_vf_stats_result,
15037                  stats, "stats");
15038 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15039         TOKEN_NUM_INITIALIZER
15040                 (struct cmd_show_vf_stats_result,
15041                  port_id, RTE_UINT16);
15042 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15043         TOKEN_NUM_INITIALIZER
15044                 (struct cmd_show_vf_stats_result,
15045                  vf_id, RTE_UINT16);
15046
15047 static void
15048 cmd_show_vf_stats_parsed(
15049         void *parsed_result,
15050         __rte_unused struct cmdline *cl,
15051         __rte_unused void *data)
15052 {
15053         struct cmd_show_vf_stats_result *res = parsed_result;
15054         struct rte_eth_stats stats;
15055         int ret = -ENOTSUP;
15056         static const char *nic_stats_border = "########################";
15057
15058         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15059                 return;
15060
15061         memset(&stats, 0, sizeof(stats));
15062
15063 #ifdef RTE_NET_I40E
15064         if (ret == -ENOTSUP)
15065                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15066                                                 res->vf_id,
15067                                                 &stats);
15068 #endif
15069 #ifdef RTE_NET_BNXT
15070         if (ret == -ENOTSUP)
15071                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15072                                                 res->vf_id,
15073                                                 &stats);
15074 #endif
15075
15076         switch (ret) {
15077         case 0:
15078                 break;
15079         case -EINVAL:
15080                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15081                 break;
15082         case -ENODEV:
15083                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15084                 break;
15085         case -ENOTSUP:
15086                 fprintf(stderr, "function not implemented\n");
15087                 break;
15088         default:
15089                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15090         }
15091
15092         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15093                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15094
15095         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15096                "%-"PRIu64"\n",
15097                stats.ipackets, stats.imissed, stats.ibytes);
15098         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15099         printf("  RX-nombuf:  %-10"PRIu64"\n",
15100                stats.rx_nombuf);
15101         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15102                "%-"PRIu64"\n",
15103                stats.opackets, stats.oerrors, stats.obytes);
15104
15105         printf("  %s############################%s\n",
15106                                nic_stats_border, nic_stats_border);
15107 }
15108
15109 cmdline_parse_inst_t cmd_show_vf_stats = {
15110         .f = cmd_show_vf_stats_parsed,
15111         .data = NULL,
15112         .help_str = "show vf stats <port_id> <vf_id>",
15113         .tokens = {
15114                 (void *)&cmd_show_vf_stats_show,
15115                 (void *)&cmd_show_vf_stats_vf,
15116                 (void *)&cmd_show_vf_stats_stats,
15117                 (void *)&cmd_show_vf_stats_port_id,
15118                 (void *)&cmd_show_vf_stats_vf_id,
15119                 NULL,
15120         },
15121 };
15122
15123 /* clear vf stats */
15124
15125 /* Common result structure for clear vf stats */
15126 struct cmd_clear_vf_stats_result {
15127         cmdline_fixed_string_t clear;
15128         cmdline_fixed_string_t vf;
15129         cmdline_fixed_string_t stats;
15130         portid_t port_id;
15131         uint16_t vf_id;
15132 };
15133
15134 /* Common CLI fields clear vf stats*/
15135 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15136         TOKEN_STRING_INITIALIZER
15137                 (struct cmd_clear_vf_stats_result,
15138                  clear, "clear");
15139 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15140         TOKEN_STRING_INITIALIZER
15141                 (struct cmd_clear_vf_stats_result,
15142                  vf, "vf");
15143 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15144         TOKEN_STRING_INITIALIZER
15145                 (struct cmd_clear_vf_stats_result,
15146                  stats, "stats");
15147 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15148         TOKEN_NUM_INITIALIZER
15149                 (struct cmd_clear_vf_stats_result,
15150                  port_id, RTE_UINT16);
15151 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15152         TOKEN_NUM_INITIALIZER
15153                 (struct cmd_clear_vf_stats_result,
15154                  vf_id, RTE_UINT16);
15155
15156 static void
15157 cmd_clear_vf_stats_parsed(
15158         void *parsed_result,
15159         __rte_unused struct cmdline *cl,
15160         __rte_unused void *data)
15161 {
15162         struct cmd_clear_vf_stats_result *res = parsed_result;
15163         int ret = -ENOTSUP;
15164
15165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15166                 return;
15167
15168 #ifdef RTE_NET_I40E
15169         if (ret == -ENOTSUP)
15170                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15171                                                   res->vf_id);
15172 #endif
15173 #ifdef RTE_NET_BNXT
15174         if (ret == -ENOTSUP)
15175                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15176                                                   res->vf_id);
15177 #endif
15178
15179         switch (ret) {
15180         case 0:
15181                 break;
15182         case -EINVAL:
15183                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15184                 break;
15185         case -ENODEV:
15186                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15187                 break;
15188         case -ENOTSUP:
15189                 fprintf(stderr, "function not implemented\n");
15190                 break;
15191         default:
15192                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15193         }
15194 }
15195
15196 cmdline_parse_inst_t cmd_clear_vf_stats = {
15197         .f = cmd_clear_vf_stats_parsed,
15198         .data = NULL,
15199         .help_str = "clear vf stats <port_id> <vf_id>",
15200         .tokens = {
15201                 (void *)&cmd_clear_vf_stats_clear,
15202                 (void *)&cmd_clear_vf_stats_vf,
15203                 (void *)&cmd_clear_vf_stats_stats,
15204                 (void *)&cmd_clear_vf_stats_port_id,
15205                 (void *)&cmd_clear_vf_stats_vf_id,
15206                 NULL,
15207         },
15208 };
15209
15210 /* port config pctype mapping reset */
15211
15212 /* Common result structure for port config pctype mapping reset */
15213 struct cmd_pctype_mapping_reset_result {
15214         cmdline_fixed_string_t port;
15215         cmdline_fixed_string_t config;
15216         portid_t port_id;
15217         cmdline_fixed_string_t pctype;
15218         cmdline_fixed_string_t mapping;
15219         cmdline_fixed_string_t reset;
15220 };
15221
15222 /* Common CLI fields for port config pctype mapping reset*/
15223 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15224         TOKEN_STRING_INITIALIZER
15225                 (struct cmd_pctype_mapping_reset_result,
15226                  port, "port");
15227 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15228         TOKEN_STRING_INITIALIZER
15229                 (struct cmd_pctype_mapping_reset_result,
15230                  config, "config");
15231 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15232         TOKEN_NUM_INITIALIZER
15233                 (struct cmd_pctype_mapping_reset_result,
15234                  port_id, RTE_UINT16);
15235 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15236         TOKEN_STRING_INITIALIZER
15237                 (struct cmd_pctype_mapping_reset_result,
15238                  pctype, "pctype");
15239 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15240         TOKEN_STRING_INITIALIZER
15241                 (struct cmd_pctype_mapping_reset_result,
15242                  mapping, "mapping");
15243 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15244         TOKEN_STRING_INITIALIZER
15245                 (struct cmd_pctype_mapping_reset_result,
15246                  reset, "reset");
15247
15248 static void
15249 cmd_pctype_mapping_reset_parsed(
15250         void *parsed_result,
15251         __rte_unused struct cmdline *cl,
15252         __rte_unused void *data)
15253 {
15254         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15255         int ret = -ENOTSUP;
15256
15257         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15258                 return;
15259
15260 #ifdef RTE_NET_I40E
15261         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15262 #endif
15263
15264         switch (ret) {
15265         case 0:
15266                 break;
15267         case -ENODEV:
15268                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15269                 break;
15270         case -ENOTSUP:
15271                 fprintf(stderr, "function not implemented\n");
15272                 break;
15273         default:
15274                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15275         }
15276 }
15277
15278 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15279         .f = cmd_pctype_mapping_reset_parsed,
15280         .data = NULL,
15281         .help_str = "port config <port_id> pctype mapping reset",
15282         .tokens = {
15283                 (void *)&cmd_pctype_mapping_reset_port,
15284                 (void *)&cmd_pctype_mapping_reset_config,
15285                 (void *)&cmd_pctype_mapping_reset_port_id,
15286                 (void *)&cmd_pctype_mapping_reset_pctype,
15287                 (void *)&cmd_pctype_mapping_reset_mapping,
15288                 (void *)&cmd_pctype_mapping_reset_reset,
15289                 NULL,
15290         },
15291 };
15292
15293 /* show port pctype mapping */
15294
15295 /* Common result structure for show port pctype mapping */
15296 struct cmd_pctype_mapping_get_result {
15297         cmdline_fixed_string_t show;
15298         cmdline_fixed_string_t port;
15299         portid_t port_id;
15300         cmdline_fixed_string_t pctype;
15301         cmdline_fixed_string_t mapping;
15302 };
15303
15304 /* Common CLI fields for pctype mapping get */
15305 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15306         TOKEN_STRING_INITIALIZER
15307                 (struct cmd_pctype_mapping_get_result,
15308                  show, "show");
15309 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15310         TOKEN_STRING_INITIALIZER
15311                 (struct cmd_pctype_mapping_get_result,
15312                  port, "port");
15313 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15314         TOKEN_NUM_INITIALIZER
15315                 (struct cmd_pctype_mapping_get_result,
15316                  port_id, RTE_UINT16);
15317 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15318         TOKEN_STRING_INITIALIZER
15319                 (struct cmd_pctype_mapping_get_result,
15320                  pctype, "pctype");
15321 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15322         TOKEN_STRING_INITIALIZER
15323                 (struct cmd_pctype_mapping_get_result,
15324                  mapping, "mapping");
15325
15326 static void
15327 cmd_pctype_mapping_get_parsed(
15328         void *parsed_result,
15329         __rte_unused struct cmdline *cl,
15330         __rte_unused void *data)
15331 {
15332         struct cmd_pctype_mapping_get_result *res = parsed_result;
15333         int ret = -ENOTSUP;
15334 #ifdef RTE_NET_I40E
15335         struct rte_pmd_i40e_flow_type_mapping
15336                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15337         int i, j, first_pctype;
15338 #endif
15339
15340         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15341                 return;
15342
15343 #ifdef RTE_NET_I40E
15344         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15345 #endif
15346
15347         switch (ret) {
15348         case 0:
15349                 break;
15350         case -ENODEV:
15351                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15352                 return;
15353         case -ENOTSUP:
15354                 fprintf(stderr, "function not implemented\n");
15355                 return;
15356         default:
15357                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15358                 return;
15359         }
15360
15361 #ifdef RTE_NET_I40E
15362         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15363                 if (mapping[i].pctype != 0ULL) {
15364                         first_pctype = 1;
15365
15366                         printf("pctype: ");
15367                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15368                                 if (mapping[i].pctype & (1ULL << j)) {
15369                                         printf(first_pctype ?
15370                                                "%02d" : ",%02d", j);
15371                                         first_pctype = 0;
15372                                 }
15373                         }
15374                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15375                 }
15376         }
15377 #endif
15378 }
15379
15380 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15381         .f = cmd_pctype_mapping_get_parsed,
15382         .data = NULL,
15383         .help_str = "show port <port_id> pctype mapping",
15384         .tokens = {
15385                 (void *)&cmd_pctype_mapping_get_show,
15386                 (void *)&cmd_pctype_mapping_get_port,
15387                 (void *)&cmd_pctype_mapping_get_port_id,
15388                 (void *)&cmd_pctype_mapping_get_pctype,
15389                 (void *)&cmd_pctype_mapping_get_mapping,
15390                 NULL,
15391         },
15392 };
15393
15394 /* port config pctype mapping update */
15395
15396 /* Common result structure for port config pctype mapping update */
15397 struct cmd_pctype_mapping_update_result {
15398         cmdline_fixed_string_t port;
15399         cmdline_fixed_string_t config;
15400         portid_t port_id;
15401         cmdline_fixed_string_t pctype;
15402         cmdline_fixed_string_t mapping;
15403         cmdline_fixed_string_t update;
15404         cmdline_fixed_string_t pctype_list;
15405         uint16_t flow_type;
15406 };
15407
15408 /* Common CLI fields for pctype mapping update*/
15409 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15410         TOKEN_STRING_INITIALIZER
15411                 (struct cmd_pctype_mapping_update_result,
15412                  port, "port");
15413 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15414         TOKEN_STRING_INITIALIZER
15415                 (struct cmd_pctype_mapping_update_result,
15416                  config, "config");
15417 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15418         TOKEN_NUM_INITIALIZER
15419                 (struct cmd_pctype_mapping_update_result,
15420                  port_id, RTE_UINT16);
15421 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15422         TOKEN_STRING_INITIALIZER
15423                 (struct cmd_pctype_mapping_update_result,
15424                  pctype, "pctype");
15425 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15426         TOKEN_STRING_INITIALIZER
15427                 (struct cmd_pctype_mapping_update_result,
15428                  mapping, "mapping");
15429 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15430         TOKEN_STRING_INITIALIZER
15431                 (struct cmd_pctype_mapping_update_result,
15432                  update, "update");
15433 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15434         TOKEN_STRING_INITIALIZER
15435                 (struct cmd_pctype_mapping_update_result,
15436                  pctype_list, NULL);
15437 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15438         TOKEN_NUM_INITIALIZER
15439                 (struct cmd_pctype_mapping_update_result,
15440                  flow_type, RTE_UINT16);
15441
15442 static void
15443 cmd_pctype_mapping_update_parsed(
15444         void *parsed_result,
15445         __rte_unused struct cmdline *cl,
15446         __rte_unused void *data)
15447 {
15448         struct cmd_pctype_mapping_update_result *res = parsed_result;
15449         int ret = -ENOTSUP;
15450 #ifdef RTE_NET_I40E
15451         struct rte_pmd_i40e_flow_type_mapping mapping;
15452         unsigned int i;
15453         unsigned int nb_item;
15454         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15455 #endif
15456
15457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15458                 return;
15459
15460 #ifdef RTE_NET_I40E
15461         nb_item = parse_item_list(res->pctype_list, "pctypes",
15462                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15463         mapping.flow_type = res->flow_type;
15464         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15465                 mapping.pctype |= (1ULL << pctype_list[i]);
15466         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15467                                                 &mapping,
15468                                                 1,
15469                                                 0);
15470 #endif
15471
15472         switch (ret) {
15473         case 0:
15474                 break;
15475         case -EINVAL:
15476                 fprintf(stderr, "invalid pctype or flow type\n");
15477                 break;
15478         case -ENODEV:
15479                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15480                 break;
15481         case -ENOTSUP:
15482                 fprintf(stderr, "function not implemented\n");
15483                 break;
15484         default:
15485                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15486         }
15487 }
15488
15489 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15490         .f = cmd_pctype_mapping_update_parsed,
15491         .data = NULL,
15492         .help_str = "port config <port_id> pctype mapping update"
15493         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15494         .tokens = {
15495                 (void *)&cmd_pctype_mapping_update_port,
15496                 (void *)&cmd_pctype_mapping_update_config,
15497                 (void *)&cmd_pctype_mapping_update_port_id,
15498                 (void *)&cmd_pctype_mapping_update_pctype,
15499                 (void *)&cmd_pctype_mapping_update_mapping,
15500                 (void *)&cmd_pctype_mapping_update_update,
15501                 (void *)&cmd_pctype_mapping_update_pc_type,
15502                 (void *)&cmd_pctype_mapping_update_flow_type,
15503                 NULL,
15504         },
15505 };
15506
15507 /* ptype mapping get */
15508
15509 /* Common result structure for ptype mapping get */
15510 struct cmd_ptype_mapping_get_result {
15511         cmdline_fixed_string_t ptype;
15512         cmdline_fixed_string_t mapping;
15513         cmdline_fixed_string_t get;
15514         portid_t port_id;
15515         uint8_t valid_only;
15516 };
15517
15518 /* Common CLI fields for ptype mapping get */
15519 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15520         TOKEN_STRING_INITIALIZER
15521                 (struct cmd_ptype_mapping_get_result,
15522                  ptype, "ptype");
15523 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15524         TOKEN_STRING_INITIALIZER
15525                 (struct cmd_ptype_mapping_get_result,
15526                  mapping, "mapping");
15527 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15528         TOKEN_STRING_INITIALIZER
15529                 (struct cmd_ptype_mapping_get_result,
15530                  get, "get");
15531 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15532         TOKEN_NUM_INITIALIZER
15533                 (struct cmd_ptype_mapping_get_result,
15534                  port_id, RTE_UINT16);
15535 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15536         TOKEN_NUM_INITIALIZER
15537                 (struct cmd_ptype_mapping_get_result,
15538                  valid_only, RTE_UINT8);
15539
15540 static void
15541 cmd_ptype_mapping_get_parsed(
15542         void *parsed_result,
15543         __rte_unused struct cmdline *cl,
15544         __rte_unused void *data)
15545 {
15546         struct cmd_ptype_mapping_get_result *res = parsed_result;
15547         int ret = -ENOTSUP;
15548 #ifdef RTE_NET_I40E
15549         int max_ptype_num = 256;
15550         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15551         uint16_t count;
15552         int i;
15553 #endif
15554
15555         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15556                 return;
15557
15558 #ifdef RTE_NET_I40E
15559         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15560                                         mapping,
15561                                         max_ptype_num,
15562                                         &count,
15563                                         res->valid_only);
15564 #endif
15565
15566         switch (ret) {
15567         case 0:
15568                 break;
15569         case -ENODEV:
15570                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15571                 break;
15572         case -ENOTSUP:
15573                 fprintf(stderr, "function not implemented\n");
15574                 break;
15575         default:
15576                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15577         }
15578
15579 #ifdef RTE_NET_I40E
15580         if (!ret) {
15581                 for (i = 0; i < count; i++)
15582                         printf("%3d\t0x%08x\n",
15583                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15584         }
15585 #endif
15586 }
15587
15588 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15589         .f = cmd_ptype_mapping_get_parsed,
15590         .data = NULL,
15591         .help_str = "ptype mapping get <port_id> <valid_only>",
15592         .tokens = {
15593                 (void *)&cmd_ptype_mapping_get_ptype,
15594                 (void *)&cmd_ptype_mapping_get_mapping,
15595                 (void *)&cmd_ptype_mapping_get_get,
15596                 (void *)&cmd_ptype_mapping_get_port_id,
15597                 (void *)&cmd_ptype_mapping_get_valid_only,
15598                 NULL,
15599         },
15600 };
15601
15602 /* ptype mapping replace */
15603
15604 /* Common result structure for ptype mapping replace */
15605 struct cmd_ptype_mapping_replace_result {
15606         cmdline_fixed_string_t ptype;
15607         cmdline_fixed_string_t mapping;
15608         cmdline_fixed_string_t replace;
15609         portid_t port_id;
15610         uint32_t target;
15611         uint8_t mask;
15612         uint32_t pkt_type;
15613 };
15614
15615 /* Common CLI fields for ptype mapping replace */
15616 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15617         TOKEN_STRING_INITIALIZER
15618                 (struct cmd_ptype_mapping_replace_result,
15619                  ptype, "ptype");
15620 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15621         TOKEN_STRING_INITIALIZER
15622                 (struct cmd_ptype_mapping_replace_result,
15623                  mapping, "mapping");
15624 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15625         TOKEN_STRING_INITIALIZER
15626                 (struct cmd_ptype_mapping_replace_result,
15627                  replace, "replace");
15628 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15629         TOKEN_NUM_INITIALIZER
15630                 (struct cmd_ptype_mapping_replace_result,
15631                  port_id, RTE_UINT16);
15632 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15633         TOKEN_NUM_INITIALIZER
15634                 (struct cmd_ptype_mapping_replace_result,
15635                  target, RTE_UINT32);
15636 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15637         TOKEN_NUM_INITIALIZER
15638                 (struct cmd_ptype_mapping_replace_result,
15639                  mask, RTE_UINT8);
15640 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15641         TOKEN_NUM_INITIALIZER
15642                 (struct cmd_ptype_mapping_replace_result,
15643                  pkt_type, RTE_UINT32);
15644
15645 static void
15646 cmd_ptype_mapping_replace_parsed(
15647         void *parsed_result,
15648         __rte_unused struct cmdline *cl,
15649         __rte_unused void *data)
15650 {
15651         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15652         int ret = -ENOTSUP;
15653
15654         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15655                 return;
15656
15657 #ifdef RTE_NET_I40E
15658         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15659                                         res->target,
15660                                         res->mask,
15661                                         res->pkt_type);
15662 #endif
15663
15664         switch (ret) {
15665         case 0:
15666                 break;
15667         case -EINVAL:
15668                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15669                         res->target, res->pkt_type);
15670                 break;
15671         case -ENODEV:
15672                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15673                 break;
15674         case -ENOTSUP:
15675                 fprintf(stderr, "function not implemented\n");
15676                 break;
15677         default:
15678                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15679         }
15680 }
15681
15682 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15683         .f = cmd_ptype_mapping_replace_parsed,
15684         .data = NULL,
15685         .help_str =
15686                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15687         .tokens = {
15688                 (void *)&cmd_ptype_mapping_replace_ptype,
15689                 (void *)&cmd_ptype_mapping_replace_mapping,
15690                 (void *)&cmd_ptype_mapping_replace_replace,
15691                 (void *)&cmd_ptype_mapping_replace_port_id,
15692                 (void *)&cmd_ptype_mapping_replace_target,
15693                 (void *)&cmd_ptype_mapping_replace_mask,
15694                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15695                 NULL,
15696         },
15697 };
15698
15699 /* ptype mapping reset */
15700
15701 /* Common result structure for ptype mapping reset */
15702 struct cmd_ptype_mapping_reset_result {
15703         cmdline_fixed_string_t ptype;
15704         cmdline_fixed_string_t mapping;
15705         cmdline_fixed_string_t reset;
15706         portid_t port_id;
15707 };
15708
15709 /* Common CLI fields for ptype mapping reset*/
15710 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15711         TOKEN_STRING_INITIALIZER
15712                 (struct cmd_ptype_mapping_reset_result,
15713                  ptype, "ptype");
15714 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15715         TOKEN_STRING_INITIALIZER
15716                 (struct cmd_ptype_mapping_reset_result,
15717                  mapping, "mapping");
15718 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15719         TOKEN_STRING_INITIALIZER
15720                 (struct cmd_ptype_mapping_reset_result,
15721                  reset, "reset");
15722 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15723         TOKEN_NUM_INITIALIZER
15724                 (struct cmd_ptype_mapping_reset_result,
15725                  port_id, RTE_UINT16);
15726
15727 static void
15728 cmd_ptype_mapping_reset_parsed(
15729         void *parsed_result,
15730         __rte_unused struct cmdline *cl,
15731         __rte_unused void *data)
15732 {
15733         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15734         int ret = -ENOTSUP;
15735
15736         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15737                 return;
15738
15739 #ifdef RTE_NET_I40E
15740         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15741 #endif
15742
15743         switch (ret) {
15744         case 0:
15745                 break;
15746         case -ENODEV:
15747                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15748                 break;
15749         case -ENOTSUP:
15750                 fprintf(stderr, "function not implemented\n");
15751                 break;
15752         default:
15753                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15754         }
15755 }
15756
15757 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15758         .f = cmd_ptype_mapping_reset_parsed,
15759         .data = NULL,
15760         .help_str = "ptype mapping reset <port_id>",
15761         .tokens = {
15762                 (void *)&cmd_ptype_mapping_reset_ptype,
15763                 (void *)&cmd_ptype_mapping_reset_mapping,
15764                 (void *)&cmd_ptype_mapping_reset_reset,
15765                 (void *)&cmd_ptype_mapping_reset_port_id,
15766                 NULL,
15767         },
15768 };
15769
15770 /* ptype mapping update */
15771
15772 /* Common result structure for ptype mapping update */
15773 struct cmd_ptype_mapping_update_result {
15774         cmdline_fixed_string_t ptype;
15775         cmdline_fixed_string_t mapping;
15776         cmdline_fixed_string_t reset;
15777         portid_t port_id;
15778         uint8_t hw_ptype;
15779         uint32_t sw_ptype;
15780 };
15781
15782 /* Common CLI fields for ptype mapping update*/
15783 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15784         TOKEN_STRING_INITIALIZER
15785                 (struct cmd_ptype_mapping_update_result,
15786                  ptype, "ptype");
15787 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15788         TOKEN_STRING_INITIALIZER
15789                 (struct cmd_ptype_mapping_update_result,
15790                  mapping, "mapping");
15791 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15792         TOKEN_STRING_INITIALIZER
15793                 (struct cmd_ptype_mapping_update_result,
15794                  reset, "update");
15795 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15796         TOKEN_NUM_INITIALIZER
15797                 (struct cmd_ptype_mapping_update_result,
15798                  port_id, RTE_UINT16);
15799 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15800         TOKEN_NUM_INITIALIZER
15801                 (struct cmd_ptype_mapping_update_result,
15802                  hw_ptype, RTE_UINT8);
15803 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15804         TOKEN_NUM_INITIALIZER
15805                 (struct cmd_ptype_mapping_update_result,
15806                  sw_ptype, RTE_UINT32);
15807
15808 static void
15809 cmd_ptype_mapping_update_parsed(
15810         void *parsed_result,
15811         __rte_unused struct cmdline *cl,
15812         __rte_unused void *data)
15813 {
15814         struct cmd_ptype_mapping_update_result *res = parsed_result;
15815         int ret = -ENOTSUP;
15816 #ifdef RTE_NET_I40E
15817         struct rte_pmd_i40e_ptype_mapping mapping;
15818 #endif
15819         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15820                 return;
15821
15822 #ifdef RTE_NET_I40E
15823         mapping.hw_ptype = res->hw_ptype;
15824         mapping.sw_ptype = res->sw_ptype;
15825         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15826                                                 &mapping,
15827                                                 1,
15828                                                 0);
15829 #endif
15830
15831         switch (ret) {
15832         case 0:
15833                 break;
15834         case -EINVAL:
15835                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15836                 break;
15837         case -ENODEV:
15838                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15839                 break;
15840         case -ENOTSUP:
15841                 fprintf(stderr, "function not implemented\n");
15842                 break;
15843         default:
15844                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15845         }
15846 }
15847
15848 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15849         .f = cmd_ptype_mapping_update_parsed,
15850         .data = NULL,
15851         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15852         .tokens = {
15853                 (void *)&cmd_ptype_mapping_update_ptype,
15854                 (void *)&cmd_ptype_mapping_update_mapping,
15855                 (void *)&cmd_ptype_mapping_update_update,
15856                 (void *)&cmd_ptype_mapping_update_port_id,
15857                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15858                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15859                 NULL,
15860         },
15861 };
15862
15863 /* Common result structure for file commands */
15864 struct cmd_cmdfile_result {
15865         cmdline_fixed_string_t load;
15866         cmdline_fixed_string_t filename;
15867 };
15868
15869 /* Common CLI fields for file commands */
15870 cmdline_parse_token_string_t cmd_load_cmdfile =
15871         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15872 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15873         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15874
15875 static void
15876 cmd_load_from_file_parsed(
15877         void *parsed_result,
15878         __rte_unused struct cmdline *cl,
15879         __rte_unused void *data)
15880 {
15881         struct cmd_cmdfile_result *res = parsed_result;
15882
15883         cmdline_read_from_file(res->filename);
15884 }
15885
15886 cmdline_parse_inst_t cmd_load_from_file = {
15887         .f = cmd_load_from_file_parsed,
15888         .data = NULL,
15889         .help_str = "load <filename>",
15890         .tokens = {
15891                 (void *)&cmd_load_cmdfile,
15892                 (void *)&cmd_load_cmdfile_filename,
15893                 NULL,
15894         },
15895 };
15896
15897 /* Get Rx offloads capabilities */
15898 struct cmd_rx_offload_get_capa_result {
15899         cmdline_fixed_string_t show;
15900         cmdline_fixed_string_t port;
15901         portid_t port_id;
15902         cmdline_fixed_string_t rx_offload;
15903         cmdline_fixed_string_t capabilities;
15904 };
15905
15906 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15907         TOKEN_STRING_INITIALIZER
15908                 (struct cmd_rx_offload_get_capa_result,
15909                  show, "show");
15910 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15911         TOKEN_STRING_INITIALIZER
15912                 (struct cmd_rx_offload_get_capa_result,
15913                  port, "port");
15914 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15915         TOKEN_NUM_INITIALIZER
15916                 (struct cmd_rx_offload_get_capa_result,
15917                  port_id, RTE_UINT16);
15918 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15919         TOKEN_STRING_INITIALIZER
15920                 (struct cmd_rx_offload_get_capa_result,
15921                  rx_offload, "rx_offload");
15922 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15923         TOKEN_STRING_INITIALIZER
15924                 (struct cmd_rx_offload_get_capa_result,
15925                  capabilities, "capabilities");
15926
15927 static void
15928 print_rx_offloads(uint64_t offloads)
15929 {
15930         uint64_t single_offload;
15931         int begin;
15932         int end;
15933         int bit;
15934
15935         if (offloads == 0)
15936                 return;
15937
15938         begin = __builtin_ctzll(offloads);
15939         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15940
15941         single_offload = 1ULL << begin;
15942         for (bit = begin; bit < end; bit++) {
15943                 if (offloads & single_offload)
15944                         printf(" %s",
15945                                rte_eth_dev_rx_offload_name(single_offload));
15946                 single_offload <<= 1;
15947         }
15948 }
15949
15950 static void
15951 cmd_rx_offload_get_capa_parsed(
15952         void *parsed_result,
15953         __rte_unused struct cmdline *cl,
15954         __rte_unused void *data)
15955 {
15956         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15957         struct rte_eth_dev_info dev_info;
15958         portid_t port_id = res->port_id;
15959         uint64_t queue_offloads;
15960         uint64_t port_offloads;
15961         int ret;
15962
15963         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15964         if (ret != 0)
15965                 return;
15966
15967         queue_offloads = dev_info.rx_queue_offload_capa;
15968         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15969
15970         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15971         printf("  Per Queue :");
15972         print_rx_offloads(queue_offloads);
15973
15974         printf("\n");
15975         printf("  Per Port  :");
15976         print_rx_offloads(port_offloads);
15977         printf("\n\n");
15978 }
15979
15980 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15981         .f = cmd_rx_offload_get_capa_parsed,
15982         .data = NULL,
15983         .help_str = "show port <port_id> rx_offload capabilities",
15984         .tokens = {
15985                 (void *)&cmd_rx_offload_get_capa_show,
15986                 (void *)&cmd_rx_offload_get_capa_port,
15987                 (void *)&cmd_rx_offload_get_capa_port_id,
15988                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15989                 (void *)&cmd_rx_offload_get_capa_capabilities,
15990                 NULL,
15991         }
15992 };
15993
15994 /* Get Rx offloads configuration */
15995 struct cmd_rx_offload_get_configuration_result {
15996         cmdline_fixed_string_t show;
15997         cmdline_fixed_string_t port;
15998         portid_t port_id;
15999         cmdline_fixed_string_t rx_offload;
16000         cmdline_fixed_string_t configuration;
16001 };
16002
16003 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16004         TOKEN_STRING_INITIALIZER
16005                 (struct cmd_rx_offload_get_configuration_result,
16006                  show, "show");
16007 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16008         TOKEN_STRING_INITIALIZER
16009                 (struct cmd_rx_offload_get_configuration_result,
16010                  port, "port");
16011 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16012         TOKEN_NUM_INITIALIZER
16013                 (struct cmd_rx_offload_get_configuration_result,
16014                  port_id, RTE_UINT16);
16015 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16016         TOKEN_STRING_INITIALIZER
16017                 (struct cmd_rx_offload_get_configuration_result,
16018                  rx_offload, "rx_offload");
16019 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16020         TOKEN_STRING_INITIALIZER
16021                 (struct cmd_rx_offload_get_configuration_result,
16022                  configuration, "configuration");
16023
16024 static void
16025 cmd_rx_offload_get_configuration_parsed(
16026         void *parsed_result,
16027         __rte_unused struct cmdline *cl,
16028         __rte_unused void *data)
16029 {
16030         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16031         struct rte_eth_dev_info dev_info;
16032         portid_t port_id = res->port_id;
16033         struct rte_port *port = &ports[port_id];
16034         struct rte_eth_conf dev_conf;
16035         uint64_t port_offloads;
16036         uint64_t queue_offloads;
16037         uint16_t nb_rx_queues;
16038         int q;
16039         int ret;
16040
16041         printf("Rx Offloading Configuration of port %d :\n", port_id);
16042
16043         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16044         if (ret != 0)
16045                 return;
16046
16047         port_offloads = dev_conf.rxmode.offloads;
16048         printf("  Port :");
16049         print_rx_offloads(port_offloads);
16050         printf("\n");
16051
16052         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16053         if (ret != 0)
16054                 return;
16055
16056         nb_rx_queues = dev_info.nb_rx_queues;
16057         for (q = 0; q < nb_rx_queues; q++) {
16058                 queue_offloads = port->rx_conf[q].offloads;
16059                 printf("  Queue[%2d] :", q);
16060                 print_rx_offloads(queue_offloads);
16061                 printf("\n");
16062         }
16063         printf("\n");
16064 }
16065
16066 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16067         .f = cmd_rx_offload_get_configuration_parsed,
16068         .data = NULL,
16069         .help_str = "show port <port_id> rx_offload configuration",
16070         .tokens = {
16071                 (void *)&cmd_rx_offload_get_configuration_show,
16072                 (void *)&cmd_rx_offload_get_configuration_port,
16073                 (void *)&cmd_rx_offload_get_configuration_port_id,
16074                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16075                 (void *)&cmd_rx_offload_get_configuration_configuration,
16076                 NULL,
16077         }
16078 };
16079
16080 /* Enable/Disable a per port offloading */
16081 struct cmd_config_per_port_rx_offload_result {
16082         cmdline_fixed_string_t port;
16083         cmdline_fixed_string_t config;
16084         portid_t port_id;
16085         cmdline_fixed_string_t rx_offload;
16086         cmdline_fixed_string_t offload;
16087         cmdline_fixed_string_t on_off;
16088 };
16089
16090 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16091         TOKEN_STRING_INITIALIZER
16092                 (struct cmd_config_per_port_rx_offload_result,
16093                  port, "port");
16094 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16095         TOKEN_STRING_INITIALIZER
16096                 (struct cmd_config_per_port_rx_offload_result,
16097                  config, "config");
16098 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16099         TOKEN_NUM_INITIALIZER
16100                 (struct cmd_config_per_port_rx_offload_result,
16101                  port_id, RTE_UINT16);
16102 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16103         TOKEN_STRING_INITIALIZER
16104                 (struct cmd_config_per_port_rx_offload_result,
16105                  rx_offload, "rx_offload");
16106 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16107         TOKEN_STRING_INITIALIZER
16108                 (struct cmd_config_per_port_rx_offload_result,
16109                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16110                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16111                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16112                            "scatter#buffer_split#timestamp#security#"
16113                            "keep_crc#rss_hash");
16114 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16115         TOKEN_STRING_INITIALIZER
16116                 (struct cmd_config_per_port_rx_offload_result,
16117                  on_off, "on#off");
16118
16119 static uint64_t
16120 search_rx_offload(const char *name)
16121 {
16122         uint64_t single_offload;
16123         const char *single_name;
16124         int found = 0;
16125         unsigned int bit;
16126
16127         single_offload = 1;
16128         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16129                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16130                 if (!strcasecmp(single_name, name)) {
16131                         found = 1;
16132                         break;
16133                 }
16134                 single_offload <<= 1;
16135         }
16136
16137         if (found)
16138                 return single_offload;
16139
16140         return 0;
16141 }
16142
16143 static void
16144 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16145                                 __rte_unused struct cmdline *cl,
16146                                 __rte_unused void *data)
16147 {
16148         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16149         portid_t port_id = res->port_id;
16150         struct rte_eth_dev_info dev_info;
16151         struct rte_port *port = &ports[port_id];
16152         uint64_t single_offload;
16153         uint16_t nb_rx_queues;
16154         int q;
16155         int ret;
16156
16157         if (port->port_status != RTE_PORT_STOPPED) {
16158                 fprintf(stderr,
16159                         "Error: Can't config offload when Port %d is not stopped\n",
16160                         port_id);
16161                 return;
16162         }
16163
16164         single_offload = search_rx_offload(res->offload);
16165         if (single_offload == 0) {
16166                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16167                 return;
16168         }
16169
16170         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16171         if (ret != 0)
16172                 return;
16173
16174         nb_rx_queues = dev_info.nb_rx_queues;
16175         if (!strcmp(res->on_off, "on")) {
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         } else {
16180                 port->dev_conf.rxmode.offloads &= ~single_offload;
16181                 for (q = 0; q < nb_rx_queues; q++)
16182                         port->rx_conf[q].offloads &= ~single_offload;
16183         }
16184
16185         cmd_reconfig_device_queue(port_id, 1, 1);
16186 }
16187
16188 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16189         .f = cmd_config_per_port_rx_offload_parsed,
16190         .data = NULL,
16191         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16192                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16193                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16194                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16195                     "keep_crc|rss_hash on|off",
16196         .tokens = {
16197                 (void *)&cmd_config_per_port_rx_offload_result_port,
16198                 (void *)&cmd_config_per_port_rx_offload_result_config,
16199                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16200                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16201                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16202                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16203                 NULL,
16204         }
16205 };
16206
16207 /* Enable/Disable a per queue offloading */
16208 struct cmd_config_per_queue_rx_offload_result {
16209         cmdline_fixed_string_t port;
16210         portid_t port_id;
16211         cmdline_fixed_string_t rxq;
16212         uint16_t queue_id;
16213         cmdline_fixed_string_t rx_offload;
16214         cmdline_fixed_string_t offload;
16215         cmdline_fixed_string_t on_off;
16216 };
16217
16218 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16219         TOKEN_STRING_INITIALIZER
16220                 (struct cmd_config_per_queue_rx_offload_result,
16221                  port, "port");
16222 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16223         TOKEN_NUM_INITIALIZER
16224                 (struct cmd_config_per_queue_rx_offload_result,
16225                  port_id, RTE_UINT16);
16226 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16227         TOKEN_STRING_INITIALIZER
16228                 (struct cmd_config_per_queue_rx_offload_result,
16229                  rxq, "rxq");
16230 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16231         TOKEN_NUM_INITIALIZER
16232                 (struct cmd_config_per_queue_rx_offload_result,
16233                  queue_id, RTE_UINT16);
16234 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16235         TOKEN_STRING_INITIALIZER
16236                 (struct cmd_config_per_queue_rx_offload_result,
16237                  rx_offload, "rx_offload");
16238 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16239         TOKEN_STRING_INITIALIZER
16240                 (struct cmd_config_per_queue_rx_offload_result,
16241                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16242                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16243                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16244                            "scatter#buffer_split#timestamp#security#keep_crc");
16245 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16246         TOKEN_STRING_INITIALIZER
16247                 (struct cmd_config_per_queue_rx_offload_result,
16248                  on_off, "on#off");
16249
16250 static void
16251 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16252                                 __rte_unused struct cmdline *cl,
16253                                 __rte_unused void *data)
16254 {
16255         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16256         struct rte_eth_dev_info dev_info;
16257         portid_t port_id = res->port_id;
16258         uint16_t queue_id = res->queue_id;
16259         struct rte_port *port = &ports[port_id];
16260         uint64_t single_offload;
16261         int ret;
16262
16263         if (port->port_status != RTE_PORT_STOPPED) {
16264                 fprintf(stderr,
16265                         "Error: Can't config offload when Port %d is not stopped\n",
16266                         port_id);
16267                 return;
16268         }
16269
16270         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16271         if (ret != 0)
16272                 return;
16273
16274         if (queue_id >= dev_info.nb_rx_queues) {
16275                 fprintf(stderr,
16276                         "Error: input queue_id should be 0 ... %d\n",
16277                         dev_info.nb_rx_queues - 1);
16278                 return;
16279         }
16280
16281         single_offload = search_rx_offload(res->offload);
16282         if (single_offload == 0) {
16283                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16284                 return;
16285         }
16286
16287         if (!strcmp(res->on_off, "on"))
16288                 port->rx_conf[queue_id].offloads |= single_offload;
16289         else
16290                 port->rx_conf[queue_id].offloads &= ~single_offload;
16291
16292         cmd_reconfig_device_queue(port_id, 1, 1);
16293 }
16294
16295 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16296         .f = cmd_config_per_queue_rx_offload_parsed,
16297         .data = NULL,
16298         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16299                     "vlan_strip|ipv4_cksum|"
16300                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16301                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16302                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16303                     "keep_crc on|off",
16304         .tokens = {
16305                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16306                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16307                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16308                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16309                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16310                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16311                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16312                 NULL,
16313         }
16314 };
16315
16316 /* Get Tx offloads capabilities */
16317 struct cmd_tx_offload_get_capa_result {
16318         cmdline_fixed_string_t show;
16319         cmdline_fixed_string_t port;
16320         portid_t port_id;
16321         cmdline_fixed_string_t tx_offload;
16322         cmdline_fixed_string_t capabilities;
16323 };
16324
16325 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16326         TOKEN_STRING_INITIALIZER
16327                 (struct cmd_tx_offload_get_capa_result,
16328                  show, "show");
16329 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16330         TOKEN_STRING_INITIALIZER
16331                 (struct cmd_tx_offload_get_capa_result,
16332                  port, "port");
16333 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16334         TOKEN_NUM_INITIALIZER
16335                 (struct cmd_tx_offload_get_capa_result,
16336                  port_id, RTE_UINT16);
16337 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16338         TOKEN_STRING_INITIALIZER
16339                 (struct cmd_tx_offload_get_capa_result,
16340                  tx_offload, "tx_offload");
16341 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16342         TOKEN_STRING_INITIALIZER
16343                 (struct cmd_tx_offload_get_capa_result,
16344                  capabilities, "capabilities");
16345
16346 static void
16347 print_tx_offloads(uint64_t offloads)
16348 {
16349         uint64_t single_offload;
16350         int begin;
16351         int end;
16352         int bit;
16353
16354         if (offloads == 0)
16355                 return;
16356
16357         begin = __builtin_ctzll(offloads);
16358         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16359
16360         single_offload = 1ULL << begin;
16361         for (bit = begin; bit < end; bit++) {
16362                 if (offloads & single_offload)
16363                         printf(" %s",
16364                                rte_eth_dev_tx_offload_name(single_offload));
16365                 single_offload <<= 1;
16366         }
16367 }
16368
16369 static void
16370 cmd_tx_offload_get_capa_parsed(
16371         void *parsed_result,
16372         __rte_unused struct cmdline *cl,
16373         __rte_unused void *data)
16374 {
16375         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16376         struct rte_eth_dev_info dev_info;
16377         portid_t port_id = res->port_id;
16378         uint64_t queue_offloads;
16379         uint64_t port_offloads;
16380         int ret;
16381
16382         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16383         if (ret != 0)
16384                 return;
16385
16386         queue_offloads = dev_info.tx_queue_offload_capa;
16387         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16388
16389         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16390         printf("  Per Queue :");
16391         print_tx_offloads(queue_offloads);
16392
16393         printf("\n");
16394         printf("  Per Port  :");
16395         print_tx_offloads(port_offloads);
16396         printf("\n\n");
16397 }
16398
16399 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16400         .f = cmd_tx_offload_get_capa_parsed,
16401         .data = NULL,
16402         .help_str = "show port <port_id> tx_offload capabilities",
16403         .tokens = {
16404                 (void *)&cmd_tx_offload_get_capa_show,
16405                 (void *)&cmd_tx_offload_get_capa_port,
16406                 (void *)&cmd_tx_offload_get_capa_port_id,
16407                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16408                 (void *)&cmd_tx_offload_get_capa_capabilities,
16409                 NULL,
16410         }
16411 };
16412
16413 /* Get Tx offloads configuration */
16414 struct cmd_tx_offload_get_configuration_result {
16415         cmdline_fixed_string_t show;
16416         cmdline_fixed_string_t port;
16417         portid_t port_id;
16418         cmdline_fixed_string_t tx_offload;
16419         cmdline_fixed_string_t configuration;
16420 };
16421
16422 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16423         TOKEN_STRING_INITIALIZER
16424                 (struct cmd_tx_offload_get_configuration_result,
16425                  show, "show");
16426 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16427         TOKEN_STRING_INITIALIZER
16428                 (struct cmd_tx_offload_get_configuration_result,
16429                  port, "port");
16430 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16431         TOKEN_NUM_INITIALIZER
16432                 (struct cmd_tx_offload_get_configuration_result,
16433                  port_id, RTE_UINT16);
16434 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16435         TOKEN_STRING_INITIALIZER
16436                 (struct cmd_tx_offload_get_configuration_result,
16437                  tx_offload, "tx_offload");
16438 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16439         TOKEN_STRING_INITIALIZER
16440                 (struct cmd_tx_offload_get_configuration_result,
16441                  configuration, "configuration");
16442
16443 static void
16444 cmd_tx_offload_get_configuration_parsed(
16445         void *parsed_result,
16446         __rte_unused struct cmdline *cl,
16447         __rte_unused void *data)
16448 {
16449         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16450         struct rte_eth_dev_info dev_info;
16451         portid_t port_id = res->port_id;
16452         struct rte_port *port = &ports[port_id];
16453         struct rte_eth_conf dev_conf;
16454         uint64_t port_offloads;
16455         uint64_t queue_offloads;
16456         uint16_t nb_tx_queues;
16457         int q;
16458         int ret;
16459
16460         printf("Tx Offloading Configuration of port %d :\n", port_id);
16461
16462         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16463         if (ret != 0)
16464                 return;
16465
16466         port_offloads = dev_conf.txmode.offloads;
16467         printf("  Port :");
16468         print_tx_offloads(port_offloads);
16469         printf("\n");
16470
16471         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16472         if (ret != 0)
16473                 return;
16474
16475         nb_tx_queues = dev_info.nb_tx_queues;
16476         for (q = 0; q < nb_tx_queues; q++) {
16477                 queue_offloads = port->tx_conf[q].offloads;
16478                 printf("  Queue[%2d] :", q);
16479                 print_tx_offloads(queue_offloads);
16480                 printf("\n");
16481         }
16482         printf("\n");
16483 }
16484
16485 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16486         .f = cmd_tx_offload_get_configuration_parsed,
16487         .data = NULL,
16488         .help_str = "show port <port_id> tx_offload configuration",
16489         .tokens = {
16490                 (void *)&cmd_tx_offload_get_configuration_show,
16491                 (void *)&cmd_tx_offload_get_configuration_port,
16492                 (void *)&cmd_tx_offload_get_configuration_port_id,
16493                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16494                 (void *)&cmd_tx_offload_get_configuration_configuration,
16495                 NULL,
16496         }
16497 };
16498
16499 /* Enable/Disable a per port offloading */
16500 struct cmd_config_per_port_tx_offload_result {
16501         cmdline_fixed_string_t port;
16502         cmdline_fixed_string_t config;
16503         portid_t port_id;
16504         cmdline_fixed_string_t tx_offload;
16505         cmdline_fixed_string_t offload;
16506         cmdline_fixed_string_t on_off;
16507 };
16508
16509 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16510         TOKEN_STRING_INITIALIZER
16511                 (struct cmd_config_per_port_tx_offload_result,
16512                  port, "port");
16513 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16514         TOKEN_STRING_INITIALIZER
16515                 (struct cmd_config_per_port_tx_offload_result,
16516                  config, "config");
16517 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16518         TOKEN_NUM_INITIALIZER
16519                 (struct cmd_config_per_port_tx_offload_result,
16520                  port_id, RTE_UINT16);
16521 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16522         TOKEN_STRING_INITIALIZER
16523                 (struct cmd_config_per_port_tx_offload_result,
16524                  tx_offload, "tx_offload");
16525 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16526         TOKEN_STRING_INITIALIZER
16527                 (struct cmd_config_per_port_tx_offload_result,
16528                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16529                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16530                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16531                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16532                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16533                           "send_on_timestamp");
16534 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16535         TOKEN_STRING_INITIALIZER
16536                 (struct cmd_config_per_port_tx_offload_result,
16537                  on_off, "on#off");
16538
16539 static uint64_t
16540 search_tx_offload(const char *name)
16541 {
16542         uint64_t single_offload;
16543         const char *single_name;
16544         int found = 0;
16545         unsigned int bit;
16546
16547         single_offload = 1;
16548         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16549                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16550                 if (single_name == NULL)
16551                         break;
16552                 if (!strcasecmp(single_name, name)) {
16553                         found = 1;
16554                         break;
16555                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16556                         break;
16557                 single_offload <<= 1;
16558         }
16559
16560         if (found)
16561                 return single_offload;
16562
16563         return 0;
16564 }
16565
16566 static void
16567 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16568                                 __rte_unused struct cmdline *cl,
16569                                 __rte_unused void *data)
16570 {
16571         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16572         portid_t port_id = res->port_id;
16573         struct rte_eth_dev_info dev_info;
16574         struct rte_port *port = &ports[port_id];
16575         uint64_t single_offload;
16576         uint16_t nb_tx_queues;
16577         int q;
16578         int ret;
16579
16580         if (port->port_status != RTE_PORT_STOPPED) {
16581                 fprintf(stderr,
16582                         "Error: Can't config offload when Port %d is not stopped\n",
16583                         port_id);
16584                 return;
16585         }
16586
16587         single_offload = search_tx_offload(res->offload);
16588         if (single_offload == 0) {
16589                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16590                 return;
16591         }
16592
16593         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16594         if (ret != 0)
16595                 return;
16596
16597         nb_tx_queues = dev_info.nb_tx_queues;
16598         if (!strcmp(res->on_off, "on")) {
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         } else {
16603                 port->dev_conf.txmode.offloads &= ~single_offload;
16604                 for (q = 0; q < nb_tx_queues; q++)
16605                         port->tx_conf[q].offloads &= ~single_offload;
16606         }
16607
16608         cmd_reconfig_device_queue(port_id, 1, 1);
16609 }
16610
16611 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16612         .f = cmd_config_per_port_tx_offload_parsed,
16613         .data = NULL,
16614         .help_str = "port config <port_id> tx_offload "
16615                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16616                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16617                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16618                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16619                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16620                     "send_on_timestamp on|off",
16621         .tokens = {
16622                 (void *)&cmd_config_per_port_tx_offload_result_port,
16623                 (void *)&cmd_config_per_port_tx_offload_result_config,
16624                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16625                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16626                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16627                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16628                 NULL,
16629         }
16630 };
16631
16632 /* Enable/Disable a per queue offloading */
16633 struct cmd_config_per_queue_tx_offload_result {
16634         cmdline_fixed_string_t port;
16635         portid_t port_id;
16636         cmdline_fixed_string_t txq;
16637         uint16_t queue_id;
16638         cmdline_fixed_string_t tx_offload;
16639         cmdline_fixed_string_t offload;
16640         cmdline_fixed_string_t on_off;
16641 };
16642
16643 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16644         TOKEN_STRING_INITIALIZER
16645                 (struct cmd_config_per_queue_tx_offload_result,
16646                  port, "port");
16647 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16648         TOKEN_NUM_INITIALIZER
16649                 (struct cmd_config_per_queue_tx_offload_result,
16650                  port_id, RTE_UINT16);
16651 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16652         TOKEN_STRING_INITIALIZER
16653                 (struct cmd_config_per_queue_tx_offload_result,
16654                  txq, "txq");
16655 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16656         TOKEN_NUM_INITIALIZER
16657                 (struct cmd_config_per_queue_tx_offload_result,
16658                  queue_id, RTE_UINT16);
16659 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16660         TOKEN_STRING_INITIALIZER
16661                 (struct cmd_config_per_queue_tx_offload_result,
16662                  tx_offload, "tx_offload");
16663 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16664         TOKEN_STRING_INITIALIZER
16665                 (struct cmd_config_per_queue_tx_offload_result,
16666                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16667                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16668                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16669                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16670                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16671 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16672         TOKEN_STRING_INITIALIZER
16673                 (struct cmd_config_per_queue_tx_offload_result,
16674                  on_off, "on#off");
16675
16676 static void
16677 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16678                                 __rte_unused struct cmdline *cl,
16679                                 __rte_unused void *data)
16680 {
16681         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16682         struct rte_eth_dev_info dev_info;
16683         portid_t port_id = res->port_id;
16684         uint16_t queue_id = res->queue_id;
16685         struct rte_port *port = &ports[port_id];
16686         uint64_t single_offload;
16687         int ret;
16688
16689         if (port->port_status != RTE_PORT_STOPPED) {
16690                 fprintf(stderr,
16691                         "Error: Can't config offload when Port %d is not stopped\n",
16692                         port_id);
16693                 return;
16694         }
16695
16696         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16697         if (ret != 0)
16698                 return;
16699
16700         if (queue_id >= dev_info.nb_tx_queues) {
16701                 fprintf(stderr,
16702                         "Error: input queue_id should be 0 ... %d\n",
16703                         dev_info.nb_tx_queues - 1);
16704                 return;
16705         }
16706
16707         single_offload = search_tx_offload(res->offload);
16708         if (single_offload == 0) {
16709                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16710                 return;
16711         }
16712
16713         if (!strcmp(res->on_off, "on"))
16714                 port->tx_conf[queue_id].offloads |= single_offload;
16715         else
16716                 port->tx_conf[queue_id].offloads &= ~single_offload;
16717
16718         cmd_reconfig_device_queue(port_id, 1, 1);
16719 }
16720
16721 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16722         .f = cmd_config_per_queue_tx_offload_parsed,
16723         .data = NULL,
16724         .help_str = "port <port_id> txq <queue_id> tx_offload "
16725                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16726                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16727                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16728                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16729                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16730                     "on|off",
16731         .tokens = {
16732                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16733                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16734                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16735                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16736                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16737                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16738                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16739                 NULL,
16740         }
16741 };
16742
16743 /* *** configure tx_metadata for specific port *** */
16744 struct cmd_config_tx_metadata_specific_result {
16745         cmdline_fixed_string_t port;
16746         cmdline_fixed_string_t keyword;
16747         uint16_t port_id;
16748         cmdline_fixed_string_t item;
16749         uint32_t value;
16750 };
16751
16752 static void
16753 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16754                                 __rte_unused struct cmdline *cl,
16755                                 __rte_unused void *data)
16756 {
16757         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16758
16759         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16760                 return;
16761         ports[res->port_id].tx_metadata = res->value;
16762         /* Add/remove callback to insert valid metadata in every Tx packet. */
16763         if (ports[res->port_id].tx_metadata)
16764                 add_tx_md_callback(res->port_id);
16765         else
16766                 remove_tx_md_callback(res->port_id);
16767         rte_flow_dynf_metadata_register();
16768 }
16769
16770 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16771         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16772                         port, "port");
16773 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16774         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16775                         keyword, "config");
16776 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16777         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16778                         port_id, RTE_UINT16);
16779 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16780         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16781                         item, "tx_metadata");
16782 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16783         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16784                         value, RTE_UINT32);
16785
16786 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16787         .f = cmd_config_tx_metadata_specific_parsed,
16788         .data = NULL,
16789         .help_str = "port config <port_id> tx_metadata <value>",
16790         .tokens = {
16791                 (void *)&cmd_config_tx_metadata_specific_port,
16792                 (void *)&cmd_config_tx_metadata_specific_keyword,
16793                 (void *)&cmd_config_tx_metadata_specific_id,
16794                 (void *)&cmd_config_tx_metadata_specific_item,
16795                 (void *)&cmd_config_tx_metadata_specific_value,
16796                 NULL,
16797         },
16798 };
16799
16800 /* *** set dynf *** */
16801 struct cmd_config_tx_dynf_specific_result {
16802         cmdline_fixed_string_t port;
16803         cmdline_fixed_string_t keyword;
16804         uint16_t port_id;
16805         cmdline_fixed_string_t item;
16806         cmdline_fixed_string_t name;
16807         cmdline_fixed_string_t value;
16808 };
16809
16810 static void
16811 cmd_config_dynf_specific_parsed(void *parsed_result,
16812                                 __rte_unused struct cmdline *cl,
16813                                 __rte_unused void *data)
16814 {
16815         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16816         struct rte_mbuf_dynflag desc_flag;
16817         int flag;
16818         uint64_t old_port_flags;
16819
16820         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16821                 return;
16822         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16823         if (flag <= 0) {
16824                 if (strlcpy(desc_flag.name, res->name,
16825                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16826                         fprintf(stderr, "Flag name too long\n");
16827                         return;
16828                 }
16829                 desc_flag.flags = 0;
16830                 flag = rte_mbuf_dynflag_register(&desc_flag);
16831                 if (flag < 0) {
16832                         fprintf(stderr, "Can't register flag\n");
16833                         return;
16834                 }
16835                 strcpy(dynf_names[flag], desc_flag.name);
16836         }
16837         old_port_flags = ports[res->port_id].mbuf_dynf;
16838         if (!strcmp(res->value, "set")) {
16839                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16840                 if (old_port_flags == 0)
16841                         add_tx_dynf_callback(res->port_id);
16842         } else {
16843                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16844                 if (ports[res->port_id].mbuf_dynf == 0)
16845                         remove_tx_dynf_callback(res->port_id);
16846         }
16847 }
16848
16849 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16850         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16851                         keyword, "port");
16852 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16853         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16854                         keyword, "config");
16855 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16856         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16857                         port_id, RTE_UINT16);
16858 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16859         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16860                         item, "dynf");
16861 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16862         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16863                         name, NULL);
16864 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16865         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16866                         value, "set#clear");
16867
16868 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16869         .f = cmd_config_dynf_specific_parsed,
16870         .data = NULL,
16871         .help_str = "port config <port id> dynf <name> set|clear",
16872         .tokens = {
16873                 (void *)&cmd_config_tx_dynf_specific_port,
16874                 (void *)&cmd_config_tx_dynf_specific_keyword,
16875                 (void *)&cmd_config_tx_dynf_specific_port_id,
16876                 (void *)&cmd_config_tx_dynf_specific_item,
16877                 (void *)&cmd_config_tx_dynf_specific_name,
16878                 (void *)&cmd_config_tx_dynf_specific_value,
16879                 NULL,
16880         },
16881 };
16882
16883 /* *** display tx_metadata per port configuration *** */
16884 struct cmd_show_tx_metadata_result {
16885         cmdline_fixed_string_t cmd_show;
16886         cmdline_fixed_string_t cmd_port;
16887         cmdline_fixed_string_t cmd_keyword;
16888         portid_t cmd_pid;
16889 };
16890
16891 static void
16892 cmd_show_tx_metadata_parsed(void *parsed_result,
16893                 __rte_unused struct cmdline *cl,
16894                 __rte_unused void *data)
16895 {
16896         struct cmd_show_tx_metadata_result *res = parsed_result;
16897
16898         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16899                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
16900                 return;
16901         }
16902         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16903                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16904                        ports[res->cmd_pid].tx_metadata);
16905         }
16906 }
16907
16908 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16909         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16910                         cmd_show, "show");
16911 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16912         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16913                         cmd_port, "port");
16914 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16915         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16916                         cmd_pid, RTE_UINT16);
16917 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16918         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16919                         cmd_keyword, "tx_metadata");
16920
16921 cmdline_parse_inst_t cmd_show_tx_metadata = {
16922         .f = cmd_show_tx_metadata_parsed,
16923         .data = NULL,
16924         .help_str = "show port <port_id> tx_metadata",
16925         .tokens = {
16926                 (void *)&cmd_show_tx_metadata_show,
16927                 (void *)&cmd_show_tx_metadata_port,
16928                 (void *)&cmd_show_tx_metadata_pid,
16929                 (void *)&cmd_show_tx_metadata_keyword,
16930                 NULL,
16931         },
16932 };
16933
16934 /* *** show fec capability per port configuration *** */
16935 struct cmd_show_fec_capability_result {
16936         cmdline_fixed_string_t cmd_show;
16937         cmdline_fixed_string_t cmd_port;
16938         cmdline_fixed_string_t cmd_fec;
16939         cmdline_fixed_string_t cmd_keyword;
16940         portid_t cmd_pid;
16941 };
16942
16943 static void
16944 cmd_show_fec_capability_parsed(void *parsed_result,
16945                 __rte_unused struct cmdline *cl,
16946                 __rte_unused void *data)
16947 {
16948         struct cmd_show_fec_capability_result *res = parsed_result;
16949         struct rte_eth_fec_capa *speed_fec_capa;
16950         unsigned int num;
16951         int ret;
16952
16953         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16954                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16955                 return;
16956         }
16957
16958         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16959         if (ret == -ENOTSUP) {
16960                 fprintf(stderr, "Function not implemented\n");
16961                 return;
16962         } else if (ret < 0) {
16963                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
16964                 return;
16965         }
16966
16967         num = (unsigned int)ret;
16968         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16969         if (speed_fec_capa == NULL) {
16970                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
16971                 return;
16972         }
16973
16974         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16975         if (ret < 0) {
16976                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
16977                 goto out;
16978         }
16979
16980         show_fec_capability(num, speed_fec_capa);
16981 out:
16982         free(speed_fec_capa);
16983 }
16984
16985 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16986         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16987                         cmd_show, "show");
16988 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16989         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16990                         cmd_port, "port");
16991 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
16992         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
16993                         cmd_pid, RTE_UINT16);
16994 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
16995         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16996                         cmd_fec, "fec");
16997 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
16998         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16999                         cmd_keyword, "capabilities");
17000
17001 cmdline_parse_inst_t cmd_show_capability = {
17002         .f = cmd_show_fec_capability_parsed,
17003         .data = NULL,
17004         .help_str = "show port <port_id> fec capabilities",
17005         .tokens = {
17006                 (void *)&cmd_show_fec_capability_show,
17007                 (void *)&cmd_show_fec_capability_port,
17008                 (void *)&cmd_show_fec_capability_pid,
17009                 (void *)&cmd_show_fec_capability_fec,
17010                 (void *)&cmd_show_fec_capability_keyword,
17011                 NULL,
17012         },
17013 };
17014
17015 /* *** show fec mode per port configuration *** */
17016 struct cmd_show_fec_metadata_result {
17017         cmdline_fixed_string_t cmd_show;
17018         cmdline_fixed_string_t cmd_port;
17019         cmdline_fixed_string_t cmd_keyword;
17020         portid_t cmd_pid;
17021 };
17022
17023 static void
17024 cmd_show_fec_mode_parsed(void *parsed_result,
17025                 __rte_unused struct cmdline *cl,
17026                 __rte_unused void *data)
17027 {
17028 #define FEC_NAME_SIZE 16
17029         struct cmd_show_fec_metadata_result *res = parsed_result;
17030         uint32_t mode;
17031         char buf[FEC_NAME_SIZE];
17032         int ret;
17033
17034         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17035                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17036                 return;
17037         }
17038         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17039         if (ret == -ENOTSUP) {
17040                 fprintf(stderr, "Function not implemented\n");
17041                 return;
17042         } else if (ret < 0) {
17043                 fprintf(stderr, "Get FEC mode failed\n");
17044                 return;
17045         }
17046
17047         switch (mode) {
17048         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17049                 strlcpy(buf, "off", sizeof(buf));
17050                 break;
17051         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17052                 strlcpy(buf, "auto", sizeof(buf));
17053                 break;
17054         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17055                 strlcpy(buf, "baser", sizeof(buf));
17056                 break;
17057         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17058                 strlcpy(buf, "rs", sizeof(buf));
17059                 break;
17060         default:
17061                 return;
17062         }
17063
17064         printf("%s\n", buf);
17065 }
17066
17067 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17068         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17069                         cmd_show, "show");
17070 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17071         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17072                         cmd_port, "port");
17073 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17074         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17075                         cmd_pid, RTE_UINT16);
17076 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17077         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17078                         cmd_keyword, "fec_mode");
17079
17080 cmdline_parse_inst_t cmd_show_fec_mode = {
17081         .f = cmd_show_fec_mode_parsed,
17082         .data = NULL,
17083         .help_str = "show port <port_id> fec_mode",
17084         .tokens = {
17085                 (void *)&cmd_show_fec_mode_show,
17086                 (void *)&cmd_show_fec_mode_port,
17087                 (void *)&cmd_show_fec_mode_pid,
17088                 (void *)&cmd_show_fec_mode_keyword,
17089                 NULL,
17090         },
17091 };
17092
17093 /* *** set fec mode per port configuration *** */
17094 struct cmd_set_port_fec_mode {
17095         cmdline_fixed_string_t set;
17096         cmdline_fixed_string_t port;
17097         portid_t port_id;
17098         cmdline_fixed_string_t fec_mode;
17099         cmdline_fixed_string_t fec_value;
17100 };
17101
17102 /* Common CLI fields for set fec mode */
17103 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17104         TOKEN_STRING_INITIALIZER
17105                 (struct cmd_set_port_fec_mode,
17106                  set, "set");
17107 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17108         TOKEN_STRING_INITIALIZER
17109                 (struct cmd_set_port_fec_mode,
17110                  port, "port");
17111 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17112         TOKEN_NUM_INITIALIZER
17113                 (struct cmd_set_port_fec_mode,
17114                  port_id, RTE_UINT16);
17115 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17116         TOKEN_STRING_INITIALIZER
17117                 (struct cmd_set_port_fec_mode,
17118                  fec_mode, "fec_mode");
17119 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17120         TOKEN_STRING_INITIALIZER
17121                 (struct cmd_set_port_fec_mode,
17122                  fec_value, NULL);
17123
17124 static void
17125 cmd_set_port_fec_mode_parsed(
17126         void *parsed_result,
17127         __rte_unused struct cmdline *cl,
17128         __rte_unused void *data)
17129 {
17130         struct cmd_set_port_fec_mode *res = parsed_result;
17131         uint16_t port_id = res->port_id;
17132         uint32_t fec_capa;
17133         int ret;
17134
17135         ret = parse_fec_mode(res->fec_value, &fec_capa);
17136         if (ret < 0) {
17137                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17138                                 res->fec_value, port_id);
17139                 return;
17140         }
17141
17142         ret = rte_eth_fec_set(port_id, fec_capa);
17143         if (ret == -ENOTSUP) {
17144                 fprintf(stderr, "Function not implemented\n");
17145                 return;
17146         } else if (ret < 0) {
17147                 fprintf(stderr, "Set FEC mode failed\n");
17148                 return;
17149         }
17150 }
17151
17152 cmdline_parse_inst_t cmd_set_fec_mode = {
17153         .f = cmd_set_port_fec_mode_parsed,
17154         .data = NULL,
17155         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17156         .tokens = {
17157                 (void *)&cmd_set_port_fec_mode_set,
17158                 (void *)&cmd_set_port_fec_mode_port,
17159                 (void *)&cmd_set_port_fec_mode_port_id,
17160                 (void *)&cmd_set_port_fec_mode_str,
17161                 (void *)&cmd_set_port_fec_mode_value,
17162                 NULL,
17163         },
17164 };
17165
17166 /* show port supported ptypes */
17167
17168 /* Common result structure for show port ptypes */
17169 struct cmd_show_port_supported_ptypes_result {
17170         cmdline_fixed_string_t show;
17171         cmdline_fixed_string_t port;
17172         portid_t port_id;
17173         cmdline_fixed_string_t ptypes;
17174 };
17175
17176 /* Common CLI fields for show port ptypes */
17177 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17178         TOKEN_STRING_INITIALIZER
17179                 (struct cmd_show_port_supported_ptypes_result,
17180                  show, "show");
17181 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17182         TOKEN_STRING_INITIALIZER
17183                 (struct cmd_show_port_supported_ptypes_result,
17184                  port, "port");
17185 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17186         TOKEN_NUM_INITIALIZER
17187                 (struct cmd_show_port_supported_ptypes_result,
17188                  port_id, RTE_UINT16);
17189 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17190         TOKEN_STRING_INITIALIZER
17191                 (struct cmd_show_port_supported_ptypes_result,
17192                  ptypes, "ptypes");
17193
17194 static void
17195 cmd_show_port_supported_ptypes_parsed(
17196         void *parsed_result,
17197         __rte_unused struct cmdline *cl,
17198         __rte_unused void *data)
17199 {
17200 #define RSVD_PTYPE_MASK       0xf0000000
17201 #define MAX_PTYPES_PER_LAYER  16
17202 #define LTYPE_NAMESIZE        32
17203 #define PTYPE_NAMESIZE        256
17204         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17205         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17206         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17207         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17208         uint16_t port_id = res->port_id;
17209         int ret, i;
17210
17211         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17212         if (ret < 0)
17213                 return;
17214
17215         while (ptype_mask != RSVD_PTYPE_MASK) {
17216
17217                 switch (ptype_mask) {
17218                 case RTE_PTYPE_L2_MASK:
17219                         strlcpy(ltype, "L2", sizeof(ltype));
17220                         break;
17221                 case RTE_PTYPE_L3_MASK:
17222                         strlcpy(ltype, "L3", sizeof(ltype));
17223                         break;
17224                 case RTE_PTYPE_L4_MASK:
17225                         strlcpy(ltype, "L4", sizeof(ltype));
17226                         break;
17227                 case RTE_PTYPE_TUNNEL_MASK:
17228                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17229                         break;
17230                 case RTE_PTYPE_INNER_L2_MASK:
17231                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17232                         break;
17233                 case RTE_PTYPE_INNER_L3_MASK:
17234                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17235                         break;
17236                 case RTE_PTYPE_INNER_L4_MASK:
17237                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17238                         break;
17239                 default:
17240                         return;
17241                 }
17242
17243                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17244                                                        ptype_mask, ptypes,
17245                                                        MAX_PTYPES_PER_LAYER);
17246
17247                 if (ret > 0)
17248                         printf("Supported %s ptypes:\n", ltype);
17249                 else
17250                         printf("%s ptypes unsupported\n", ltype);
17251
17252                 for (i = 0; i < ret; ++i) {
17253                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17254                         printf("%s\n", buf);
17255                 }
17256
17257                 ptype_mask <<= 4;
17258         }
17259 }
17260
17261 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17262         .f = cmd_show_port_supported_ptypes_parsed,
17263         .data = NULL,
17264         .help_str = "show port <port_id> ptypes",
17265         .tokens = {
17266                 (void *)&cmd_show_port_supported_ptypes_show,
17267                 (void *)&cmd_show_port_supported_ptypes_port,
17268                 (void *)&cmd_show_port_supported_ptypes_port_id,
17269                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17270                 NULL,
17271         },
17272 };
17273
17274 /* *** display rx/tx descriptor status *** */
17275 struct cmd_show_rx_tx_desc_status_result {
17276         cmdline_fixed_string_t cmd_show;
17277         cmdline_fixed_string_t cmd_port;
17278         cmdline_fixed_string_t cmd_keyword;
17279         cmdline_fixed_string_t cmd_desc;
17280         cmdline_fixed_string_t cmd_status;
17281         portid_t cmd_pid;
17282         portid_t cmd_qid;
17283         portid_t cmd_did;
17284 };
17285
17286 static void
17287 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17288                 __rte_unused struct cmdline *cl,
17289                 __rte_unused void *data)
17290 {
17291         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17292         int rc;
17293
17294         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17295                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17296                 return;
17297         }
17298
17299         if (!strcmp(res->cmd_keyword, "rxq")) {
17300                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17301                                              res->cmd_did);
17302                 if (rc < 0) {
17303                         fprintf(stderr,
17304                                 "Invalid input: queue id = %d, desc id = %d\n",
17305                                 res->cmd_qid, res->cmd_did);
17306                         return;
17307                 }
17308                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17309                         printf("Desc status = AVAILABLE\n");
17310                 else if (rc == RTE_ETH_RX_DESC_DONE)
17311                         printf("Desc status = DONE\n");
17312                 else
17313                         printf("Desc status = UNAVAILABLE\n");
17314         } else if (!strcmp(res->cmd_keyword, "txq")) {
17315                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17316                                              res->cmd_did);
17317                 if (rc < 0) {
17318                         fprintf(stderr,
17319                                 "Invalid input: queue id = %d, desc id = %d\n",
17320                                 res->cmd_qid, res->cmd_did);
17321                         return;
17322                 }
17323                 if (rc == RTE_ETH_TX_DESC_FULL)
17324                         printf("Desc status = FULL\n");
17325                 else if (rc == RTE_ETH_TX_DESC_DONE)
17326                         printf("Desc status = DONE\n");
17327                 else
17328                         printf("Desc status = UNAVAILABLE\n");
17329         }
17330 }
17331
17332 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17333         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17334                         cmd_show, "show");
17335 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17336         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17337                         cmd_port, "port");
17338 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17339         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17340                         cmd_pid, RTE_UINT16);
17341 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17342         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17343                         cmd_keyword, "rxq#txq");
17344 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17345         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17346                         cmd_qid, RTE_UINT16);
17347 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17348         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17349                         cmd_desc, "desc");
17350 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17351         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17352                         cmd_did, RTE_UINT16);
17353 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17354         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17355                         cmd_status, "status");
17356 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17357         .f = cmd_show_rx_tx_desc_status_parsed,
17358         .data = NULL,
17359         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17360                 "status",
17361         .tokens = {
17362                 (void *)&cmd_show_rx_tx_desc_status_show,
17363                 (void *)&cmd_show_rx_tx_desc_status_port,
17364                 (void *)&cmd_show_rx_tx_desc_status_pid,
17365                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17366                 (void *)&cmd_show_rx_tx_desc_status_qid,
17367                 (void *)&cmd_show_rx_tx_desc_status_desc,
17368                 (void *)&cmd_show_rx_tx_desc_status_did,
17369                 (void *)&cmd_show_rx_tx_desc_status_status,
17370                 NULL,
17371         },
17372 };
17373
17374 /* *** display rx queue desc used count *** */
17375 struct cmd_show_rx_queue_desc_used_count_result {
17376         cmdline_fixed_string_t cmd_show;
17377         cmdline_fixed_string_t cmd_port;
17378         cmdline_fixed_string_t cmd_rxq;
17379         cmdline_fixed_string_t cmd_desc;
17380         cmdline_fixed_string_t cmd_used;
17381         cmdline_fixed_string_t cmd_count;
17382         portid_t cmd_pid;
17383         portid_t cmd_qid;
17384 };
17385
17386 static void
17387 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17388                 __rte_unused struct cmdline *cl,
17389                 __rte_unused void *data)
17390 {
17391         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17392         int rc;
17393
17394         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17395                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17396                 return;
17397         }
17398
17399         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17400         if (rc < 0) {
17401                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17402                 return;
17403         }
17404         printf("Used desc count = %d\n", rc);
17405 }
17406
17407 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17408         TOKEN_STRING_INITIALIZER
17409                 (struct cmd_show_rx_queue_desc_used_count_result,
17410                  cmd_show, "show");
17411 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17412         TOKEN_STRING_INITIALIZER
17413                 (struct cmd_show_rx_queue_desc_used_count_result,
17414                  cmd_port, "port");
17415 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17416         TOKEN_NUM_INITIALIZER
17417                 (struct cmd_show_rx_queue_desc_used_count_result,
17418                  cmd_pid, RTE_UINT16);
17419 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17420         TOKEN_STRING_INITIALIZER
17421                 (struct cmd_show_rx_queue_desc_used_count_result,
17422                  cmd_rxq, "rxq");
17423 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17424         TOKEN_NUM_INITIALIZER
17425                 (struct cmd_show_rx_queue_desc_used_count_result,
17426                  cmd_qid, RTE_UINT16);
17427 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17428         TOKEN_STRING_INITIALIZER
17429                 (struct cmd_show_rx_queue_desc_used_count_result,
17430                  cmd_count, "desc");
17431 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17432         TOKEN_STRING_INITIALIZER
17433                 (struct cmd_show_rx_queue_desc_used_count_result,
17434                  cmd_count, "used");
17435 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17436         TOKEN_STRING_INITIALIZER
17437                 (struct cmd_show_rx_queue_desc_used_count_result,
17438                  cmd_count, "count");
17439 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17440         .f = cmd_show_rx_queue_desc_used_count_parsed,
17441         .data = NULL,
17442         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17443         .tokens = {
17444                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17445                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17446                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17447                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17448                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17449                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17450                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17451                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17452                 NULL,
17453         },
17454 };
17455
17456 /* Common result structure for set port ptypes */
17457 struct cmd_set_port_ptypes_result {
17458         cmdline_fixed_string_t set;
17459         cmdline_fixed_string_t port;
17460         portid_t port_id;
17461         cmdline_fixed_string_t ptype_mask;
17462         uint32_t mask;
17463 };
17464
17465 /* Common CLI fields for set port ptypes */
17466 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17467         TOKEN_STRING_INITIALIZER
17468                 (struct cmd_set_port_ptypes_result,
17469                  set, "set");
17470 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17471         TOKEN_STRING_INITIALIZER
17472                 (struct cmd_set_port_ptypes_result,
17473                  port, "port");
17474 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17475         TOKEN_NUM_INITIALIZER
17476                 (struct cmd_set_port_ptypes_result,
17477                  port_id, RTE_UINT16);
17478 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17479         TOKEN_STRING_INITIALIZER
17480                 (struct cmd_set_port_ptypes_result,
17481                  ptype_mask, "ptype_mask");
17482 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17483         TOKEN_NUM_INITIALIZER
17484                 (struct cmd_set_port_ptypes_result,
17485                  mask, RTE_UINT32);
17486
17487 static void
17488 cmd_set_port_ptypes_parsed(
17489         void *parsed_result,
17490         __rte_unused struct cmdline *cl,
17491         __rte_unused void *data)
17492 {
17493         struct cmd_set_port_ptypes_result *res = parsed_result;
17494 #define PTYPE_NAMESIZE        256
17495         char ptype_name[PTYPE_NAMESIZE];
17496         uint16_t port_id = res->port_id;
17497         uint32_t ptype_mask = res->mask;
17498         int ret, i;
17499
17500         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17501                                                NULL, 0);
17502         if (ret <= 0) {
17503                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17504                         port_id);
17505                 return;
17506         }
17507
17508         uint32_t ptypes[ret];
17509
17510         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17511         if (ret < 0) {
17512                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17513                         port_id);
17514                 return;
17515         }
17516
17517         printf("Successfully set following ptypes for Port %d\n", port_id);
17518         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17519                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17520                 printf("%s\n", ptype_name);
17521         }
17522
17523         clear_ptypes = false;
17524 }
17525
17526 cmdline_parse_inst_t cmd_set_port_ptypes = {
17527         .f = cmd_set_port_ptypes_parsed,
17528         .data = NULL,
17529         .help_str = "set port <port_id> ptype_mask <mask>",
17530         .tokens = {
17531                 (void *)&cmd_set_port_ptypes_set,
17532                 (void *)&cmd_set_port_ptypes_port,
17533                 (void *)&cmd_set_port_ptypes_port_id,
17534                 (void *)&cmd_set_port_ptypes_mask_str,
17535                 (void *)&cmd_set_port_ptypes_mask_u32,
17536                 NULL,
17537         },
17538 };
17539
17540 /* *** display mac addresses added to a port *** */
17541 struct cmd_showport_macs_result {
17542         cmdline_fixed_string_t cmd_show;
17543         cmdline_fixed_string_t cmd_port;
17544         cmdline_fixed_string_t cmd_keyword;
17545         portid_t cmd_pid;
17546 };
17547
17548 static void
17549 cmd_showport_macs_parsed(void *parsed_result,
17550                 __rte_unused struct cmdline *cl,
17551                 __rte_unused void *data)
17552 {
17553         struct cmd_showport_macs_result *res = parsed_result;
17554
17555         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17556                 return;
17557
17558         if (!strcmp(res->cmd_keyword, "macs"))
17559                 show_macs(res->cmd_pid);
17560         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17561                 show_mcast_macs(res->cmd_pid);
17562 }
17563
17564 cmdline_parse_token_string_t cmd_showport_macs_show =
17565         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17566                         cmd_show, "show");
17567 cmdline_parse_token_string_t cmd_showport_macs_port =
17568         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17569                         cmd_port, "port");
17570 cmdline_parse_token_num_t cmd_showport_macs_pid =
17571         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17572                         cmd_pid, RTE_UINT16);
17573 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17574         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17575                         cmd_keyword, "macs#mcast_macs");
17576
17577 cmdline_parse_inst_t cmd_showport_macs = {
17578         .f = cmd_showport_macs_parsed,
17579         .data = NULL,
17580         .help_str = "show port <port_id> macs|mcast_macs",
17581         .tokens = {
17582                 (void *)&cmd_showport_macs_show,
17583                 (void *)&cmd_showport_macs_port,
17584                 (void *)&cmd_showport_macs_pid,
17585                 (void *)&cmd_showport_macs_keyword,
17586                 NULL,
17587         },
17588 };
17589
17590 /* ******************************************************************************** */
17591
17592 /* list of instructions */
17593 cmdline_parse_ctx_t main_ctx[] = {
17594         (cmdline_parse_inst_t *)&cmd_help_brief,
17595         (cmdline_parse_inst_t *)&cmd_help_long,
17596         (cmdline_parse_inst_t *)&cmd_quit,
17597         (cmdline_parse_inst_t *)&cmd_load_from_file,
17598         (cmdline_parse_inst_t *)&cmd_showport,
17599         (cmdline_parse_inst_t *)&cmd_showqueue,
17600         (cmdline_parse_inst_t *)&cmd_showeeprom,
17601         (cmdline_parse_inst_t *)&cmd_showportall,
17602         (cmdline_parse_inst_t *)&cmd_representor_info,
17603         (cmdline_parse_inst_t *)&cmd_showdevice,
17604         (cmdline_parse_inst_t *)&cmd_showcfg,
17605         (cmdline_parse_inst_t *)&cmd_showfwdall,
17606         (cmdline_parse_inst_t *)&cmd_start,
17607         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17608         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17609         (cmdline_parse_inst_t *)&cmd_set_link_up,
17610         (cmdline_parse_inst_t *)&cmd_set_link_down,
17611         (cmdline_parse_inst_t *)&cmd_reset,
17612         (cmdline_parse_inst_t *)&cmd_set_numbers,
17613         (cmdline_parse_inst_t *)&cmd_set_log,
17614         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17615         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17616         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17617         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17618         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17619         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17620         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17621         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17622         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17623         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17624         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17625         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17626         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17627         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17628         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17629         (cmdline_parse_inst_t *)&cmd_set_link_check,
17630         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17631         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17632         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17633         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17634 #ifdef RTE_NET_BOND
17635         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17636         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17637         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17638         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17639         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17640         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17641         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17642         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17643         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17644         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17645         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17646         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17647 #endif
17648         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17649         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17650         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17651         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17652         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17653         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17654         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17655         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17656         (cmdline_parse_inst_t *)&cmd_csum_set,
17657         (cmdline_parse_inst_t *)&cmd_csum_show,
17658         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17659         (cmdline_parse_inst_t *)&cmd_tso_set,
17660         (cmdline_parse_inst_t *)&cmd_tso_show,
17661         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17662         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17663         (cmdline_parse_inst_t *)&cmd_gro_enable,
17664         (cmdline_parse_inst_t *)&cmd_gro_flush,
17665         (cmdline_parse_inst_t *)&cmd_gro_show,
17666         (cmdline_parse_inst_t *)&cmd_gso_enable,
17667         (cmdline_parse_inst_t *)&cmd_gso_size,
17668         (cmdline_parse_inst_t *)&cmd_gso_show,
17669         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17670         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17671         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17672         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17673         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17674         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17675         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17676         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17677         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17678         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17679         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17680         (cmdline_parse_inst_t *)&cmd_config_dcb,
17681         (cmdline_parse_inst_t *)&cmd_read_reg,
17682         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17683         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17684         (cmdline_parse_inst_t *)&cmd_write_reg,
17685         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17686         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17687         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17688         (cmdline_parse_inst_t *)&cmd_stop,
17689         (cmdline_parse_inst_t *)&cmd_mac_addr,
17690         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17691         (cmdline_parse_inst_t *)&cmd_set_qmap,
17692         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17693         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17694         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17695         (cmdline_parse_inst_t *)&cmd_operate_port,
17696         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17697         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17698         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17699         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17700         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17701         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17702         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17703         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17704         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17705         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17706         (cmdline_parse_inst_t *)&cmd_config_mtu,
17707         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17708         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17709         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17710         (cmdline_parse_inst_t *)&cmd_config_rss,
17711         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17712         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17713         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17714         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17715         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17716         (cmdline_parse_inst_t *)&cmd_showport_reta,
17717         (cmdline_parse_inst_t *)&cmd_showport_macs,
17718         (cmdline_parse_inst_t *)&cmd_config_burst,
17719         (cmdline_parse_inst_t *)&cmd_config_thresh,
17720         (cmdline_parse_inst_t *)&cmd_config_threshold,
17721         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17722         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17723         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17724         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17725         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17726         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17727         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17728         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17729         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17730         (cmdline_parse_inst_t *)&cmd_dump,
17731         (cmdline_parse_inst_t *)&cmd_dump_one,
17732 #ifdef RTE_NET_I40E
17733         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17734 #endif
17735         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17736         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17737         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17738         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17739         (cmdline_parse_inst_t *)&cmd_flow,
17740         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17741         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17742         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17743         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17744         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17745         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17746         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17747         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17748         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17749         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17750         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17751         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17752         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17753         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17754         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17755         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17756         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17757         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17758         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17759         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17760         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17761         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17762         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17763         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17764         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17765         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17766         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17767         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17768         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17769         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17770         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17771         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17772         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17773         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17774         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17775         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17776         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17777         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17778         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17779         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17780         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17781         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17782         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17783         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17784         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17785         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17786         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17787         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17788         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17789         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17790         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17791         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17792         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17793         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17794         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17795         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17796         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17797         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17798         (cmdline_parse_inst_t *)&cmd_ddp_add,
17799         (cmdline_parse_inst_t *)&cmd_ddp_del,
17800         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17801         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17802         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17803         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17804         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17805         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17806         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17807         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17808         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17809         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17810         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17811         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17812
17813         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17814         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17815         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17816         (cmdline_parse_inst_t *)&cmd_queue_region,
17817         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17818         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17819         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17820         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17821         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17822         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17823         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17824         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17825         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17826         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17827         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17828         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17829         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17830         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17831         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17832         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17833         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17834         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17835         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17836         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17837         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17838         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17839         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17840         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17841         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17842         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17843         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17844         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17845         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17846         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17847         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17848         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17849         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17850         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17851         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17852         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17853 #ifdef RTE_LIB_BPF
17854         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17855         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17856 #endif
17857         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17858         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17859         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17860         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17861         (cmdline_parse_inst_t *)&cmd_set_raw,
17862         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17863         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17864         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17865         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17866         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17867         (cmdline_parse_inst_t *)&cmd_show_capability,
17868         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
17869         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
17870         NULL,
17871 };
17872
17873 /* read cmdline commands from file */
17874 void
17875 cmdline_read_from_file(const char *filename)
17876 {
17877         struct cmdline *cl;
17878
17879         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17880         if (cl == NULL) {
17881                 fprintf(stderr,
17882                         "Failed to create file based cmdline context: %s\n",
17883                         filename);
17884                 return;
17885         }
17886
17887         cmdline_interact(cl);
17888         cmdline_quit(cl);
17889
17890         cmdline_free(cl);
17891
17892         printf("Read CLI commands from %s\n", filename);
17893 }
17894
17895 /* prompt function, called from main on MAIN lcore */
17896 void
17897 prompt(void)
17898 {
17899         int ret;
17900         /* initialize non-constant commands */
17901         cmd_set_fwd_mode_init();
17902         cmd_set_fwd_retry_mode_init();
17903
17904         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17905         if (testpmd_cl == NULL)
17906                 return;
17907
17908         ret = atexit(prompt_exit);
17909         if (ret != 0)
17910                 fprintf(stderr, "Cannot set exit function for cmdline\n");
17911
17912         cmdline_interact(testpmd_cl);
17913         if (ret != 0)
17914                 cmdline_stdin_exit(testpmd_cl);
17915 }
17916
17917 void
17918 prompt_exit(void)
17919 {
17920         if (testpmd_cl != NULL) {
17921                 cmdline_quit(testpmd_cl);
17922                 cmdline_stdin_exit(testpmd_cl);
17923         }
17924 }
17925
17926 static void
17927 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17928 {
17929         if (id == (portid_t)RTE_PORT_ALL) {
17930                 portid_t pid;
17931
17932                 RTE_ETH_FOREACH_DEV(pid) {
17933                         /* check if need_reconfig has been set to 1 */
17934                         if (ports[pid].need_reconfig == 0)
17935                                 ports[pid].need_reconfig = dev;
17936                         /* check if need_reconfig_queues has been set to 1 */
17937                         if (ports[pid].need_reconfig_queues == 0)
17938                                 ports[pid].need_reconfig_queues = queue;
17939                 }
17940         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17941                 /* check if need_reconfig has been set to 1 */
17942                 if (ports[id].need_reconfig == 0)
17943                         ports[id].need_reconfig = dev;
17944                 /* check if need_reconfig_queues has been set to 1 */
17945                 if (ports[id].need_reconfig_queues == 0)
17946                         ports[id].need_reconfig_queues = queue;
17947         }
17948 }