build: make GRO/GSO libraries optional
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <inttypes.h>
13 #include <sys/queue.h>
14
15 #include <rte_common.h>
16 #include <rte_byteorder.h>
17 #include <rte_log.h>
18 #include <rte_debug.h>
19 #include <rte_cycles.h>
20 #include <rte_memory.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_ring.h>
29 #include <rte_mempool.h>
30 #include <rte_interrupts.h>
31 #include <rte_pci.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_string_fns.h>
35 #include <rte_devargs.h>
36 #include <rte_flow.h>
37 #ifdef RTE_LIB_GRO
38 #include <rte_gro.h>
39 #endif
40 #include <rte_mbuf_dyn.h>
41
42 #include <cmdline_rdline.h>
43 #include <cmdline_parse.h>
44 #include <cmdline_parse_num.h>
45 #include <cmdline_parse_string.h>
46 #include <cmdline_parse_ipaddr.h>
47 #include <cmdline_parse_etheraddr.h>
48 #include <cmdline_socket.h>
49 #include <cmdline.h>
50 #ifdef RTE_NET_BOND
51 #include <rte_eth_bond.h>
52 #include <rte_eth_bond_8023ad.h>
53 #endif
54 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
55 #include <rte_pmd_dpaa.h>
56 #endif
57 #ifdef RTE_NET_IXGBE
58 #include <rte_pmd_ixgbe.h>
59 #endif
60 #ifdef RTE_NET_I40E
61 #include <rte_pmd_i40e.h>
62 #endif
63 #ifdef RTE_NET_BNXT
64 #include <rte_pmd_bnxt.h>
65 #endif
66 #include "testpmd.h"
67 #include "cmdline_mtr.h"
68 #include "cmdline_tm.h"
69 #include "bpf_cmd.h"
70
71 static struct cmdline *testpmd_cl;
72
73 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
74
75 /* *** Help command with introduction. *** */
76 struct cmd_help_brief_result {
77         cmdline_fixed_string_t help;
78 };
79
80 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
81                                   struct cmdline *cl,
82                                   __rte_unused void *data)
83 {
84         cmdline_printf(
85                 cl,
86                 "\n"
87                 "Help is available for the following sections:\n\n"
88                 "    help control                    : Start and stop forwarding.\n"
89                 "    help display                    : Displaying port, stats and config "
90                 "information.\n"
91                 "    help config                     : Configuration information.\n"
92                 "    help ports                      : Configuring ports.\n"
93                 "    help registers                  : Reading and setting port registers.\n"
94                 "    help filters                    : Filters configuration help.\n"
95                 "    help traffic_management         : Traffic Management commands.\n"
96                 "    help devices                    : Device related cmds.\n"
97                 "    help all                        : All of the above sections.\n\n"
98         );
99
100 }
101
102 cmdline_parse_token_string_t cmd_help_brief_help =
103         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
104
105 cmdline_parse_inst_t cmd_help_brief = {
106         .f = cmd_help_brief_parsed,
107         .data = NULL,
108         .help_str = "help: Show help",
109         .tokens = {
110                 (void *)&cmd_help_brief_help,
111                 NULL,
112         },
113 };
114
115 /* *** Help command with help sections. *** */
116 struct cmd_help_long_result {
117         cmdline_fixed_string_t help;
118         cmdline_fixed_string_t section;
119 };
120
121 static void cmd_help_long_parsed(void *parsed_result,
122                                  struct cmdline *cl,
123                                  __rte_unused void *data)
124 {
125         int show_all = 0;
126         struct cmd_help_long_result *res = parsed_result;
127
128         if (!strcmp(res->section, "all"))
129                 show_all = 1;
130
131         if (show_all || !strcmp(res->section, "control")) {
132
133                 cmdline_printf(
134                         cl,
135                         "\n"
136                         "Control forwarding:\n"
137                         "-------------------\n\n"
138
139                         "start\n"
140                         "    Start packet forwarding with current configuration.\n\n"
141
142                         "start tx_first\n"
143                         "    Start packet forwarding with current config"
144                         " after sending one burst of packets.\n\n"
145
146                         "stop\n"
147                         "    Stop packet forwarding, and display accumulated"
148                         " statistics.\n\n"
149
150                         "quit\n"
151                         "    Quit to prompt.\n\n"
152                 );
153         }
154
155         if (show_all || !strcmp(res->section, "display")) {
156
157                 cmdline_printf(
158                         cl,
159                         "\n"
160                         "Display:\n"
161                         "--------\n\n"
162
163                         "show port (info|stats|summary|xstats|fdir|dcb_tc) (port_id|all)\n"
164                         "    Display information for port_id, or all.\n\n"
165
166                         "show port info (port_id) representor\n"
167                         "    Show supported representors for a specific port\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) rxq (queue_id) desc used count\n"
250                         "    Show current number of filled receive"
251                         " packet descriptors.\n\n"
252
253                         "show port (port_id) macs|mcast_macs"
254                         "       Display list of mac addresses added to port.\n\n"
255
256                         "show port (port_id) fec capabilities"
257                         "       Show fec capabilities of a port.\n\n"
258
259                         "show port (port_id) fec_mode"
260                         "       Show fec mode of a port.\n\n"
261
262                         "show port (port_id) flow_ctrl"
263                         "       Show flow control info of a port.\n\n"
264                 );
265         }
266
267         if (show_all || !strcmp(res->section, "config")) {
268                 cmdline_printf(
269                         cl,
270                         "\n"
271                         "Configuration:\n"
272                         "--------------\n"
273                         "Configuration changes only become active when"
274                         " forwarding is started/restarted.\n\n"
275
276                         "set default\n"
277                         "    Reset forwarding to the default configuration.\n\n"
278
279                         "set verbose (level)\n"
280                         "    Set the debug verbosity level X.\n\n"
281
282                         "set log global|(type) (level)\n"
283                         "    Set the log level.\n\n"
284
285                         "set nbport (num)\n"
286                         "    Set number of ports.\n\n"
287
288                         "set nbcore (num)\n"
289                         "    Set number of cores.\n\n"
290
291                         "set coremask (mask)\n"
292                         "    Set the forwarding cores hexadecimal mask.\n\n"
293
294                         "set portmask (mask)\n"
295                         "    Set the forwarding ports hexadecimal mask.\n\n"
296
297                         "set burst (num)\n"
298                         "    Set number of packets per burst.\n\n"
299
300                         "set burst tx delay (microseconds) retry (num)\n"
301                         "    Set the transmit delay time and number of retries,"
302                         " effective when retry is enabled.\n\n"
303
304                         "set rxoffs (x[,y]*)\n"
305                         "    Set the offset of each packet segment on"
306                         " receiving if split feature is engaged."
307                         " Affects only the queues configured with split"
308                         " offloads.\n\n"
309
310                         "set rxpkts (x[,y]*)\n"
311                         "    Set the length of each segment to scatter"
312                         " packets on receiving if split feature is engaged."
313                         " Affects only the queues configured with split"
314                         " offloads.\n\n"
315
316                         "set txpkts (x[,y]*)\n"
317                         "    Set the length of each segment of TXONLY"
318                         " and optionally CSUM packets.\n\n"
319
320                         "set txsplit (off|on|rand)\n"
321                         "    Set the split policy for the TX packets."
322                         " Right now only applicable for CSUM and TXONLY"
323                         " modes\n\n"
324
325                         "set txtimes (x, y)\n"
326                         "    Set the scheduling on timestamps"
327                         " timings for the TXONLY mode\n\n"
328
329                         "set corelist (x[,y]*)\n"
330                         "    Set the list of forwarding cores.\n\n"
331
332                         "set portlist (x[,y]*)\n"
333                         "    Set the list of forwarding ports.\n\n"
334
335                         "set port setup on (iterator|event)\n"
336                         "    Select how attached port is retrieved for setup.\n\n"
337
338                         "set tx loopback (port_id) (on|off)\n"
339                         "    Enable or disable tx loopback.\n\n"
340
341                         "set all queues drop (port_id) (on|off)\n"
342                         "    Set drop enable bit for all queues.\n\n"
343
344                         "set vf split drop (port_id) (vf_id) (on|off)\n"
345                         "    Set split drop enable bit for a VF from the PF.\n\n"
346
347                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
348                         "    Set MAC antispoof for a VF from the PF.\n\n"
349
350                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
351                         "    Enable MACsec offload.\n\n"
352
353                         "set macsec offload (port_id) off\n"
354                         "    Disable MACsec offload.\n\n"
355
356                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
357                         "    Configure MACsec secure connection (SC).\n\n"
358
359                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
360                         "    Configure MACsec secure association (SA).\n\n"
361
362                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
363                         "    Set VF broadcast for a VF from the PF.\n\n"
364
365                         "vlan set stripq (on|off) (port_id,queue_id)\n"
366                         "    Set the VLAN strip for a queue on a port.\n\n"
367
368                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
369                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
370
371                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
372                         "    Set VLAN insert for a VF from the PF.\n\n"
373
374                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
375                         "    Set VLAN antispoof for a VF from the PF.\n\n"
376
377                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
378                         "    Set VLAN tag for a VF from the PF.\n\n"
379
380                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
381                         "    Set a VF's max bandwidth(Mbps).\n\n"
382
383                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
384                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
385
386                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
387                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
388
389                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
390                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
391
392                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
393                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
394
395                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
396                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
397
398                         "vlan set (inner|outer) tpid (value) (port_id)\n"
399                         "    Set the VLAN TPID for Packet Filtering on"
400                         " a port\n\n"
401
402                         "rx_vlan add (vlan_id|all) (port_id)\n"
403                         "    Add a vlan_id, or all identifiers, to the set"
404                         " of VLAN identifiers filtered by port_id.\n\n"
405
406                         "rx_vlan rm (vlan_id|all) (port_id)\n"
407                         "    Remove a vlan_id, or all identifiers, from the set"
408                         " of VLAN identifiers filtered by port_id.\n\n"
409
410                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
411                         "    Add a vlan_id, to the set of VLAN identifiers"
412                         "filtered for VF(s) from port_id.\n\n"
413
414                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
415                         "    Remove a vlan_id, to the set of VLAN identifiers"
416                         "filtered for VF(s) from port_id.\n\n"
417
418                         "rx_vxlan_port add (udp_port) (port_id)\n"
419                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
420
421                         "rx_vxlan_port rm (udp_port) (port_id)\n"
422                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
423
424                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
425                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
426                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
427
428                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
429                         "    Set port based TX VLAN insertion.\n\n"
430
431                         "tx_vlan reset (port_id)\n"
432                         "    Disable hardware insertion of a VLAN header in"
433                         " packets sent on a port.\n\n"
434
435                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
436                         "    Select hardware or software calculation of the"
437                         " checksum when transmitting a packet using the"
438                         " csum forward engine.\n"
439                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
440                         "    outer-ip concerns the outer IP layer in"
441                         "    outer-udp concerns the outer UDP layer in"
442                         " case the packet is recognized as a tunnel packet by"
443                         " the forward engine (vxlan, gre and ipip are supported)\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "csum parse-tunnel (on|off) (tx_port_id)\n"
447                         "    If disabled, treat tunnel packets as non-tunneled"
448                         " packets (treat inner headers as payload). The port\n"
449                         "    argument is the port used for TX in csum forward"
450                         " engine.\n\n"
451
452                         "csum show (port_id)\n"
453                         "    Display tx checksum offload configuration\n\n"
454
455                         "tso set (segsize) (portid)\n"
456                         "    Enable TCP Segmentation Offload in csum forward"
457                         " engine.\n"
458                         "    Please check the NIC datasheet for HW limits.\n\n"
459
460                         "tso show (portid)"
461                         "    Display the status of TCP Segmentation Offload.\n\n"
462
463 #ifdef RTE_LIB_GRO
464                         "set port (port_id) gro on|off\n"
465                         "    Enable or disable Generic Receive Offload in"
466                         " csum forwarding engine.\n\n"
467
468                         "show port (port_id) gro\n"
469                         "    Display GRO configuration.\n\n"
470
471                         "set gro flush (cycles)\n"
472                         "    Set the cycle to flush GROed packets from"
473                         " reassembly tables.\n\n"
474 #endif
475
476 #ifdef RTE_LIB_GSO
477                         "set port (port_id) gso (on|off)"
478                         "    Enable or disable Generic Segmentation Offload in"
479                         " csum forwarding engine.\n\n"
480
481                         "set gso segsz (length)\n"
482                         "    Set max packet length for output GSO segments,"
483                         " including packet header and payload.\n\n"
484
485                         "show port (port_id) gso\n"
486                         "    Show GSO configuration.\n\n"
487 #endif
488
489                         "set fwd (%s)\n"
490                         "    Set packet forwarding mode.\n\n"
491
492                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
493                         "    Add a MAC address on port_id.\n\n"
494
495                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
496                         "    Remove a MAC address from port_id.\n\n"
497
498                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
499                         "    Set the default MAC address for port_id.\n\n"
500
501                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
502                         "    Add a MAC address for a VF on the port.\n\n"
503
504                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
505                         "    Set the MAC address for a VF from the PF.\n\n"
506
507                         "set eth-peer (port_id) (peer_addr)\n"
508                         "    set the peer address for certain port.\n\n"
509
510                         "set port (port_id) uta (mac_address|all) (on|off)\n"
511                         "    Add/Remove a or all unicast hash filter(s)"
512                         "from port X.\n\n"
513
514                         "set promisc (port_id|all) (on|off)\n"
515                         "    Set the promiscuous mode on port_id, or all.\n\n"
516
517                         "set allmulti (port_id|all) (on|off)\n"
518                         "    Set the allmulti mode on port_id, or all.\n\n"
519
520                         "set vf promisc (port_id) (vf_id) (on|off)\n"
521                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
522
523                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
524                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
525
526                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
527                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
528                         " (on|off) autoneg (on|off) (port_id)\n"
529                         "set flow_ctrl rx (on|off) (portid)\n"
530                         "set flow_ctrl tx (on|off) (portid)\n"
531                         "set flow_ctrl high_water (high_water) (portid)\n"
532                         "set flow_ctrl low_water (low_water) (portid)\n"
533                         "set flow_ctrl pause_time (pause_time) (portid)\n"
534                         "set flow_ctrl send_xon (send_xon) (portid)\n"
535                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
536                         "set flow_ctrl autoneg (on|off) (port_id)\n"
537                         "    Set the link flow control parameter on a port.\n\n"
538
539                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
540                         " (low_water) (pause_time) (priority) (port_id)\n"
541                         "    Set the priority flow control parameter on a"
542                         " port.\n\n"
543
544                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
545                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
546                         " queue on port.\n"
547                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
548                         " on port 0 to mapping 5.\n\n"
549
550                         "set xstats-hide-zero on|off\n"
551                         "    Set the option to hide the zero values"
552                         " for xstats display.\n"
553
554                         "set record-core-cycles on|off\n"
555                         "    Set the option to enable measurement of CPU cycles.\n"
556
557                         "set record-burst-stats on|off\n"
558                         "    Set the option to enable display of RX and TX bursts.\n"
559
560                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
561                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
562
563                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
564                         "|MPE) (on|off)\n"
565                         "    AUPE:accepts untagged VLAN;"
566                         "ROPE:accept unicast hash\n\n"
567                         "    BAM:accepts broadcast packets;"
568                         "MPE:accepts all multicast packets\n\n"
569                         "    Enable/Disable a VF receive mode of a port\n\n"
570
571                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
572                         "    Set rate limit for a queue of a port\n\n"
573
574                         "set port (port_id) vf (vf_id) rate (rate_num) "
575                         "queue_mask (queue_mask_value)\n"
576                         "    Set rate limit for queues in VF of a port\n\n"
577
578                         "set flush_rx (on|off)\n"
579                         "   Flush (default) or don't flush RX streams before"
580                         " forwarding. Mainly used with PCAP drivers.\n\n"
581
582                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
583                         "   Set the bypass mode for the lowest port on bypass enabled"
584                         " NIC.\n\n"
585
586                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
587                         "mode (normal|bypass|isolate) (port_id)\n"
588                         "   Set the event required to initiate specified bypass mode for"
589                         " the lowest port on a bypass enabled NIC where:\n"
590                         "       timeout   = enable bypass after watchdog timeout.\n"
591                         "       os_on     = enable bypass when OS/board is powered on.\n"
592                         "       os_off    = enable bypass when OS/board is powered off.\n"
593                         "       power_on  = enable bypass when power supply is turned on.\n"
594                         "       power_off = enable bypass when power supply is turned off."
595                         "\n\n"
596
597                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
598                         "   Set the bypass watchdog timeout to 'n' seconds"
599                         " where 0 = instant.\n\n"
600
601                         "show bypass config (port_id)\n"
602                         "   Show the bypass configuration for a bypass enabled NIC"
603                         " using the lowest port on the NIC.\n\n"
604
605 #ifdef RTE_NET_BOND
606                         "create bonded device (mode) (socket)\n"
607                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
608
609                         "add bonding slave (slave_id) (port_id)\n"
610                         "       Add a slave device to a bonded device.\n\n"
611
612                         "remove bonding slave (slave_id) (port_id)\n"
613                         "       Remove a slave device from a bonded device.\n\n"
614
615                         "set bonding mode (value) (port_id)\n"
616                         "       Set the bonding mode on a bonded device.\n\n"
617
618                         "set bonding primary (slave_id) (port_id)\n"
619                         "       Set the primary slave for a bonded device.\n\n"
620
621                         "show bonding config (port_id)\n"
622                         "       Show the bonding config for port_id.\n\n"
623
624                         "show bonding lacp info (port_id)\n"
625                         "       Show the bonding lacp information for port_id.\n\n"
626
627                         "set bonding mac_addr (port_id) (address)\n"
628                         "       Set the MAC address of a bonded device.\n\n"
629
630                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
631                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
632
633                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
634                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
635
636                         "set bonding mon_period (port_id) (value)\n"
637                         "       Set the bonding link status monitoring polling period in ms.\n\n"
638
639                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
640                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
641
642 #endif
643                         "set link-up port (port_id)\n"
644                         "       Set link up for a port.\n\n"
645
646                         "set link-down port (port_id)\n"
647                         "       Set link down for a port.\n\n"
648
649                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
650                         "    Load a profile package on a port\n\n"
651
652                         "ddp del (port_id) (backup_profile_path)\n"
653                         "    Delete a profile package from a port\n\n"
654
655                         "ptype mapping get (port_id) (valid_only)\n"
656                         "    Get ptype mapping on a port\n\n"
657
658                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
659                         "    Replace target with the pkt_type in ptype mapping\n\n"
660
661                         "ptype mapping reset (port_id)\n"
662                         "    Reset ptype mapping on a port\n\n"
663
664                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
665                         "    Update a ptype mapping item on a port\n\n"
666
667                         "set port (port_id) ptype_mask (ptype_mask)\n"
668                         "    set packet types classification for a specific port\n\n"
669
670                         "set port (port_id) queue-region region_id (value) "
671                         "queue_start_index (value) queue_num (value)\n"
672                         "    Set a queue region on a port\n\n"
673
674                         "set port (port_id) queue-region region_id (value) "
675                         "flowtype (value)\n"
676                         "    Set a flowtype region index on a port\n\n"
677
678                         "set port (port_id) queue-region UP (value) region_id (value)\n"
679                         "    Set the mapping of User Priority to "
680                         "queue region on a port\n\n"
681
682                         "set port (port_id) queue-region flush (on|off)\n"
683                         "    flush all queue region related configuration\n\n"
684
685                         "show port meter cap (port_id)\n"
686                         "    Show port meter capability information\n\n"
687
688                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (packet_mode)\n"
689                         "    meter profile add - srtcm rfc 2697\n\n"
690
691                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs) (packet_mode)\n"
692                         "    meter profile add - trtcm rfc 2698\n\n"
693
694                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs) (packet_mode)\n"
695                         "    meter profile add - trtcm rfc 4115\n\n"
696
697                         "del port meter profile (port_id) (profile_id)\n"
698                         "    meter profile delete\n\n"
699
700                         "create port meter (port_id) (mtr_id) (profile_id) (policy_id) (meter_enable)\n"
701                         "(stats_mask) (shared) (use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
702                         "(dscp_tbl_entry63)]\n"
703                         "    meter create\n\n"
704
705                         "enable port meter (port_id) (mtr_id)\n"
706                         "    meter enable\n\n"
707
708                         "disable port meter (port_id) (mtr_id)\n"
709                         "    meter disable\n\n"
710
711                         "del port meter (port_id) (mtr_id)\n"
712                         "    meter delete\n\n"
713
714                         "add port meter policy (port_id) (policy_id) g_actions (actions)\n"
715                         "y_actions (actions) r_actions (actions)\n"
716                         "    meter policy add\n\n"
717
718                         "del port meter policy (port_id) (policy_id)\n"
719                         "    meter policy delete\n\n"
720
721                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
722                         "    meter update meter profile\n\n"
723
724                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
725                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
726                         "    update meter dscp table entries\n\n"
727
728                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
729                         "(action0) [(action1) (action2)]\n"
730                         "    meter update policer action\n\n"
731
732                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
733                         "    meter update stats\n\n"
734
735                         "show port (port_id) queue-region\n"
736                         "    show all queue region related configuration info\n\n"
737
738                         "set port (port_id) fec_mode auto|off|rs|baser\n"
739                         "    set fec mode for a specific port\n\n"
740
741                         , list_pkt_forwarding_modes()
742                 );
743         }
744
745         if (show_all || !strcmp(res->section, "ports")) {
746
747                 cmdline_printf(
748                         cl,
749                         "\n"
750                         "Port Operations:\n"
751                         "----------------\n\n"
752
753                         "port start (port_id|all)\n"
754                         "    Start all ports or port_id.\n\n"
755
756                         "port stop (port_id|all)\n"
757                         "    Stop all ports or port_id.\n\n"
758
759                         "port close (port_id|all)\n"
760                         "    Close all ports or port_id.\n\n"
761
762                         "port reset (port_id|all)\n"
763                         "    Reset all ports or port_id.\n\n"
764
765                         "port attach (ident)\n"
766                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
767
768                         "port detach (port_id)\n"
769                         "    Detach physical or virtual dev by port_id\n\n"
770
771                         "port config (port_id|all)"
772                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
773                         " duplex (half|full|auto)\n"
774                         "    Set speed and duplex for all ports or port_id\n\n"
775
776                         "port config (port_id|all) loopback (mode)\n"
777                         "    Set loopback mode for all ports or port_id\n\n"
778
779                         "port config all (rxq|txq|rxd|txd) (value)\n"
780                         "    Set number for rxq/txq/rxd/txd.\n\n"
781
782                         "port config all max-pkt-len (value)\n"
783                         "    Set the max packet length.\n\n"
784
785                         "port config all max-lro-pkt-size (value)\n"
786                         "    Set the max LRO aggregated packet size.\n\n"
787
788                         "port config all drop-en (on|off)\n"
789                         "    Enable or disable packet drop on all RX queues of all ports when no "
790                         "receive buffers available.\n\n"
791
792                         "port config all rss (all|default|ip|tcp|udp|sctp|"
793                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|none|level-default|"
794                         "level-outer|level-inner|<flowtype_id>)\n"
795                         "    Set the RSS mode.\n\n"
796
797                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
798                         "    Set the RSS redirection table.\n\n"
799
800                         "port config (port_id) dcb vt (on|off) (traffic_class)"
801                         " pfc (on|off)\n"
802                         "    Set the DCB mode.\n\n"
803
804                         "port config all burst (value)\n"
805                         "    Set the number of packets per burst.\n\n"
806
807                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
808                         " (value)\n"
809                         "    Set the ring prefetch/host/writeback threshold"
810                         " for tx/rx queue.\n\n"
811
812                         "port config all (txfreet|txrst|rxfreet) (value)\n"
813                         "    Set free threshold for rx/tx, or set"
814                         " tx rs bit threshold.\n\n"
815                         "port config mtu X value\n"
816                         "    Set the MTU of port X to a given value\n\n"
817
818                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
819                         "    Set a rx/tx queue's ring size configuration, the new"
820                         " value will take effect after command that (re-)start the port"
821                         " or command that setup the specific queue\n\n"
822
823                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
824                         "    Start/stop a rx/tx queue of port X. Only take effect"
825                         " when port X is started\n\n"
826
827                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
828                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
829                         " take effect when port X is stopped.\n\n"
830
831                         "port (port_id) (rxq|txq) (queue_id) setup\n"
832                         "    Setup a rx/tx queue of port X.\n\n"
833
834                         "port config (port_id) pctype mapping reset\n"
835                         "    Reset flow type to pctype mapping on a port\n\n"
836
837                         "port config (port_id) pctype mapping update"
838                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
839                         "    Update a flow type to pctype mapping item on a port\n\n"
840
841                         "port config (port_id) pctype (pctype_id) hash_inset|"
842                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
843                         " (field_idx)\n"
844                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
845
846                         "port config (port_id) pctype (pctype_id) hash_inset|"
847                         "fdir_inset|fdir_flx_inset clear all"
848                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
849
850                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve|ecpri (udp_port)\n\n"
851                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
852
853                         "port config <port_id> rx_offload vlan_strip|"
854                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
855                         "outer_ipv4_cksum|macsec_strip|header_split|"
856                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
857                         "buffer_split|timestamp|security|keep_crc on|off\n"
858                         "     Enable or disable a per port Rx offloading"
859                         " on all Rx queues of a port\n\n"
860
861                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
862                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
863                         "outer_ipv4_cksum|macsec_strip|header_split|"
864                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
865                         "buffer_split|timestamp|security|keep_crc on|off\n"
866                         "    Enable or disable a per queue Rx offloading"
867                         " only on a specific Rx queue\n\n"
868
869                         "port config (port_id) tx_offload vlan_insert|"
870                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
871                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
872                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
873                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
874                         "security on|off\n"
875                         "    Enable or disable a per port Tx offloading"
876                         " on all Tx queues of a port\n\n"
877
878                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
880                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
881                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
882                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
883                         " on|off\n"
884                         "    Enable or disable a per queue Tx offloading"
885                         " only on a specific Tx queue\n\n"
886
887                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
888                         "    Load an eBPF program as a callback"
889                         " for particular RX/TX queue\n\n"
890
891                         "bpf-unload rx|tx (port) (queue)\n"
892                         "    Unload previously loaded eBPF program"
893                         " for particular RX/TX queue\n\n"
894
895                         "port config (port_id) tx_metadata (value)\n"
896                         "    Set Tx metadata value per port. Testpmd will add this value"
897                         " to any Tx packet sent from this port\n\n"
898
899                         "port config (port_id) dynf (name) set|clear\n"
900                         "    Register a dynf and Set/clear this flag on Tx. "
901                         "Testpmd will set this value to any Tx packet "
902                         "sent from this port\n\n"
903
904                         "port cleanup (port_id) txq (queue_id) (free_cnt)\n"
905                         "    Cleanup txq mbufs for a specific Tx queue\n\n"
906                 );
907         }
908
909         if (show_all || !strcmp(res->section, "registers")) {
910
911                 cmdline_printf(
912                         cl,
913                         "\n"
914                         "Registers:\n"
915                         "----------\n\n"
916
917                         "read reg (port_id) (address)\n"
918                         "    Display value of a port register.\n\n"
919
920                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
921                         "    Display a port register bit field.\n\n"
922
923                         "read regbit (port_id) (address) (bit_x)\n"
924                         "    Display a single port register bit.\n\n"
925
926                         "write reg (port_id) (address) (value)\n"
927                         "    Set value of a port register.\n\n"
928
929                         "write regfield (port_id) (address) (bit_x) (bit_y)"
930                         " (value)\n"
931                         "    Set bit field of a port register.\n\n"
932
933                         "write regbit (port_id) (address) (bit_x) (value)\n"
934                         "    Set single bit value of a port register.\n\n"
935                 );
936         }
937         if (show_all || !strcmp(res->section, "filters")) {
938
939                 cmdline_printf(
940                         cl,
941                         "\n"
942                         "filters:\n"
943                         "--------\n\n"
944
945 #ifdef RTE_NET_I40E
946                         "flow_director_filter (port_id) mode raw (add|del|update)"
947                         " flow (flow_id) (drop|fwd) queue (queue_id)"
948                         " fd_id (fd_id_value) packet (packet file name)\n"
949                         "    Add/Del a raw type flow director filter.\n\n"
950 #endif
951
952                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
953                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
954                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
955                         "    Set flow director IP mask.\n\n"
956
957                         "flow_director_mask (port_id) mode MAC-VLAN"
958                         " vlan (vlan_value)\n"
959                         "    Set flow director MAC-VLAN mask.\n\n"
960
961                         "flow_director_mask (port_id) mode Tunnel"
962                         " vlan (vlan_value) mac (mac_value)"
963                         " tunnel-type (tunnel_type_value)"
964                         " tunnel-id (tunnel_id_value)\n"
965                         "    Set flow director Tunnel mask.\n\n"
966
967                         "flow_director_flex_payload (port_id)"
968                         " (raw|l2|l3|l4) (config)\n"
969                         "    Configure flex payload selection.\n\n"
970
971                         "flow validate {port_id}"
972                         " [group {group_id}] [priority {level}]"
973                         " [ingress] [egress]"
974                         " pattern {item} [/ {item} [...]] / end"
975                         " actions {action} [/ {action} [...]] / end\n"
976                         "    Check whether a flow rule can be created.\n\n"
977
978                         "flow create {port_id}"
979                         " [group {group_id}] [priority {level}]"
980                         " [ingress] [egress]"
981                         " pattern {item} [/ {item} [...]] / end"
982                         " actions {action} [/ {action} [...]] / end\n"
983                         "    Create a flow rule.\n\n"
984
985                         "flow destroy {port_id} rule {rule_id} [...]\n"
986                         "    Destroy specific flow rules.\n\n"
987
988                         "flow flush {port_id}\n"
989                         "    Destroy all flow rules.\n\n"
990
991                         "flow query {port_id} {rule_id} {action}\n"
992                         "    Query an existing flow rule.\n\n"
993
994                         "flow list {port_id} [group {group_id}] [...]\n"
995                         "    List existing flow rules sorted by priority,"
996                         " filtered by group identifiers.\n\n"
997
998                         "flow isolate {port_id} {boolean}\n"
999                         "    Restrict ingress traffic to the defined"
1000                         " flow rules\n\n"
1001
1002                         "flow aged {port_id} [destroy]\n"
1003                         "    List and destroy aged flows"
1004                         " flow rules\n\n"
1005
1006                         "flow indirect_action {port_id} create"
1007                         " [action_id {indirect_action_id}]"
1008                         " [ingress] [egress]"
1009                         " action {action} / end\n"
1010                         "    Create indirect action.\n\n"
1011
1012                         "flow indirect_action {port_id} update"
1013                         " {indirect_action_id} action {action} / end\n"
1014                         "    Update indirect action.\n\n"
1015
1016                         "flow indirect_action {port_id} destroy"
1017                         " action_id {indirect_action_id} [...]\n"
1018                         "    Destroy specific indirect actions.\n\n"
1019
1020                         "flow indirect_action {port_id} query"
1021                         " {indirect_action_id}\n"
1022                         "    Query an existing indirect action.\n\n"
1023
1024                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1025                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1026                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1027                         "       Configure the VXLAN encapsulation for flows.\n\n"
1028
1029                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1030                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1031                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1032                         " eth-dst (eth-dst)\n"
1033                         "       Configure the VXLAN encapsulation for flows.\n\n"
1034
1035                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1036                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1037                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1038                         " eth-dst (eth-dst)\n"
1039                         "       Configure the VXLAN encapsulation for flows.\n\n"
1040
1041                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1042                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1043                         " (eth-dst)\n"
1044                         "       Configure the NVGRE encapsulation for flows.\n\n"
1045
1046                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1047                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1048                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1049                         "       Configure the NVGRE encapsulation for flows.\n\n"
1050
1051                         "set raw_encap {flow items}\n"
1052                         "       Configure the encapsulation with raw data.\n\n"
1053
1054                         "set raw_decap {flow items}\n"
1055                         "       Configure the decapsulation with raw data.\n\n"
1056
1057                 );
1058         }
1059
1060         if (show_all || !strcmp(res->section, "traffic_management")) {
1061                 cmdline_printf(
1062                         cl,
1063                         "\n"
1064                         "Traffic Management:\n"
1065                         "--------------\n"
1066                         "show port tm cap (port_id)\n"
1067                         "       Display the port TM capability.\n\n"
1068
1069                         "show port tm level cap (port_id) (level_id)\n"
1070                         "       Display the port TM hierarchical level capability.\n\n"
1071
1072                         "show port tm node cap (port_id) (node_id)\n"
1073                         "       Display the port TM node capability.\n\n"
1074
1075                         "show port tm node type (port_id) (node_id)\n"
1076                         "       Display the port TM node type.\n\n"
1077
1078                         "show port tm node stats (port_id) (node_id) (clear)\n"
1079                         "       Display the port TM node stats.\n\n"
1080
1081                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1082                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1083                         " (packet_length_adjust) (packet_mode)\n"
1084                         "       Add port tm node private shaper profile.\n\n"
1085
1086                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1087                         "       Delete port tm node private shaper profile.\n\n"
1088
1089                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1090                         " (shaper_profile_id)\n"
1091                         "       Add/update port tm node shared shaper.\n\n"
1092
1093                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1094                         "       Delete port tm node shared shaper.\n\n"
1095
1096                         "set port tm node shaper profile (port_id) (node_id)"
1097                         " (shaper_profile_id)\n"
1098                         "       Set port tm node shaper profile.\n\n"
1099
1100                         "add port tm node wred profile (port_id) (wred_profile_id)"
1101                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1102                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1103                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1104                         "       Add port tm node wred profile.\n\n"
1105
1106                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1107                         "       Delete port tm node wred profile.\n\n"
1108
1109                         "add port tm nonleaf node (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.\n\n"
1114
1115                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1116                         " (priority) (weight) (level_id) (shaper_profile_id)"
1117                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1118                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1119                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1120
1121                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1122                         " (priority) (weight) (level_id) (shaper_profile_id)"
1123                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1124                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1125                         "       Add port tm leaf node.\n\n"
1126
1127                         "del port tm node (port_id) (node_id)\n"
1128                         "       Delete port tm node.\n\n"
1129
1130                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1131                         " (priority) (weight)\n"
1132                         "       Set port tm node parent.\n\n"
1133
1134                         "suspend port tm node (port_id) (node_id)"
1135                         "       Suspend tm node.\n\n"
1136
1137                         "resume port tm node (port_id) (node_id)"
1138                         "       Resume tm node.\n\n"
1139
1140                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1141                         "       Commit tm hierarchy.\n\n"
1142
1143                         "set port tm mark ip_ecn (port) (green) (yellow)"
1144                         " (red)\n"
1145                         "    Enables/Disables the traffic management marking"
1146                         " for IP ECN (Explicit Congestion Notification)"
1147                         " packets on a given port\n\n"
1148
1149                         "set port tm mark ip_dscp (port) (green) (yellow)"
1150                         " (red)\n"
1151                         "    Enables/Disables the traffic management marking"
1152                         " on the port for IP dscp packets\n\n"
1153
1154                         "set port tm mark vlan_dei (port) (green) (yellow)"
1155                         " (red)\n"
1156                         "    Enables/Disables the traffic management marking"
1157                         " on the port for VLAN packets with DEI enabled\n\n"
1158                 );
1159         }
1160
1161         if (show_all || !strcmp(res->section, "devices")) {
1162                 cmdline_printf(
1163                         cl,
1164                         "\n"
1165                         "Device Operations:\n"
1166                         "--------------\n"
1167                         "device detach (identifier)\n"
1168                         "       Detach device by identifier.\n\n"
1169                 );
1170         }
1171
1172 }
1173
1174 cmdline_parse_token_string_t cmd_help_long_help =
1175         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1176
1177 cmdline_parse_token_string_t cmd_help_long_section =
1178         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1179                         "all#control#display#config#"
1180                         "ports#registers#filters#traffic_management#devices");
1181
1182 cmdline_parse_inst_t cmd_help_long = {
1183         .f = cmd_help_long_parsed,
1184         .data = NULL,
1185         .help_str = "help all|control|display|config|ports|register|"
1186                 "filters|traffic_management|devices: "
1187                 "Show help",
1188         .tokens = {
1189                 (void *)&cmd_help_long_help,
1190                 (void *)&cmd_help_long_section,
1191                 NULL,
1192         },
1193 };
1194
1195
1196 /* *** start/stop/close all ports *** */
1197 struct cmd_operate_port_result {
1198         cmdline_fixed_string_t keyword;
1199         cmdline_fixed_string_t name;
1200         cmdline_fixed_string_t value;
1201 };
1202
1203 static void cmd_operate_port_parsed(void *parsed_result,
1204                                 __rte_unused struct cmdline *cl,
1205                                 __rte_unused void *data)
1206 {
1207         struct cmd_operate_port_result *res = parsed_result;
1208
1209         if (!strcmp(res->name, "start"))
1210                 start_port(RTE_PORT_ALL);
1211         else if (!strcmp(res->name, "stop"))
1212                 stop_port(RTE_PORT_ALL);
1213         else if (!strcmp(res->name, "close"))
1214                 close_port(RTE_PORT_ALL);
1215         else if (!strcmp(res->name, "reset"))
1216                 reset_port(RTE_PORT_ALL);
1217         else
1218                 fprintf(stderr, "Unknown parameter\n");
1219 }
1220
1221 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1222         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1223                                                                 "port");
1224 cmdline_parse_token_string_t cmd_operate_port_all_port =
1225         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1226                                                 "start#stop#close#reset");
1227 cmdline_parse_token_string_t cmd_operate_port_all_all =
1228         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1229
1230 cmdline_parse_inst_t cmd_operate_port = {
1231         .f = cmd_operate_port_parsed,
1232         .data = NULL,
1233         .help_str = "port start|stop|close|reset all: Start/Stop/Close/Reset all ports",
1234         .tokens = {
1235                 (void *)&cmd_operate_port_all_cmd,
1236                 (void *)&cmd_operate_port_all_port,
1237                 (void *)&cmd_operate_port_all_all,
1238                 NULL,
1239         },
1240 };
1241
1242 /* *** start/stop/close specific port *** */
1243 struct cmd_operate_specific_port_result {
1244         cmdline_fixed_string_t keyword;
1245         cmdline_fixed_string_t name;
1246         uint8_t value;
1247 };
1248
1249 static void cmd_operate_specific_port_parsed(void *parsed_result,
1250                         __rte_unused struct cmdline *cl,
1251                                 __rte_unused void *data)
1252 {
1253         struct cmd_operate_specific_port_result *res = parsed_result;
1254
1255         if (!strcmp(res->name, "start"))
1256                 start_port(res->value);
1257         else if (!strcmp(res->name, "stop"))
1258                 stop_port(res->value);
1259         else if (!strcmp(res->name, "close"))
1260                 close_port(res->value);
1261         else if (!strcmp(res->name, "reset"))
1262                 reset_port(res->value);
1263         else
1264                 fprintf(stderr, "Unknown parameter\n");
1265 }
1266
1267 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1268         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1269                                                         keyword, "port");
1270 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1271         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1272                                                 name, "start#stop#close#reset");
1273 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1274         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1275                                                         value, RTE_UINT8);
1276
1277 cmdline_parse_inst_t cmd_operate_specific_port = {
1278         .f = cmd_operate_specific_port_parsed,
1279         .data = NULL,
1280         .help_str = "port start|stop|close|reset <port_id>: Start/Stop/Close/Reset port_id",
1281         .tokens = {
1282                 (void *)&cmd_operate_specific_port_cmd,
1283                 (void *)&cmd_operate_specific_port_port,
1284                 (void *)&cmd_operate_specific_port_id,
1285                 NULL,
1286         },
1287 };
1288
1289 /* *** enable port setup (after attach) via iterator or event *** */
1290 struct cmd_set_port_setup_on_result {
1291         cmdline_fixed_string_t set;
1292         cmdline_fixed_string_t port;
1293         cmdline_fixed_string_t setup;
1294         cmdline_fixed_string_t on;
1295         cmdline_fixed_string_t mode;
1296 };
1297
1298 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1299                                 __rte_unused struct cmdline *cl,
1300                                 __rte_unused void *data)
1301 {
1302         struct cmd_set_port_setup_on_result *res = parsed_result;
1303
1304         if (strcmp(res->mode, "event") == 0)
1305                 setup_on_probe_event = true;
1306         else if (strcmp(res->mode, "iterator") == 0)
1307                 setup_on_probe_event = false;
1308         else
1309                 fprintf(stderr, "Unknown mode\n");
1310 }
1311
1312 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1313         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1314                         set, "set");
1315 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1316         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1317                         port, "port");
1318 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1319         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1320                         setup, "setup");
1321 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1322         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1323                         on, "on");
1324 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1325         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1326                         mode, "iterator#event");
1327
1328 cmdline_parse_inst_t cmd_set_port_setup_on = {
1329         .f = cmd_set_port_setup_on_parsed,
1330         .data = NULL,
1331         .help_str = "set port setup on iterator|event",
1332         .tokens = {
1333                 (void *)&cmd_set_port_setup_on_set,
1334                 (void *)&cmd_set_port_setup_on_port,
1335                 (void *)&cmd_set_port_setup_on_setup,
1336                 (void *)&cmd_set_port_setup_on_on,
1337                 (void *)&cmd_set_port_setup_on_mode,
1338                 NULL,
1339         },
1340 };
1341
1342 /* *** attach a specified port *** */
1343 struct cmd_operate_attach_port_result {
1344         cmdline_fixed_string_t port;
1345         cmdline_fixed_string_t keyword;
1346         cmdline_multi_string_t identifier;
1347 };
1348
1349 static void cmd_operate_attach_port_parsed(void *parsed_result,
1350                                 __rte_unused struct cmdline *cl,
1351                                 __rte_unused void *data)
1352 {
1353         struct cmd_operate_attach_port_result *res = parsed_result;
1354
1355         if (!strcmp(res->keyword, "attach"))
1356                 attach_port(res->identifier);
1357         else
1358                 fprintf(stderr, "Unknown parameter\n");
1359 }
1360
1361 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1363                         port, "port");
1364 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1365         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1366                         keyword, "attach");
1367 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1368         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1369                         identifier, TOKEN_STRING_MULTI);
1370
1371 cmdline_parse_inst_t cmd_operate_attach_port = {
1372         .f = cmd_operate_attach_port_parsed,
1373         .data = NULL,
1374         .help_str = "port attach <identifier>: "
1375                 "(identifier: pci address or virtual dev name)",
1376         .tokens = {
1377                 (void *)&cmd_operate_attach_port_port,
1378                 (void *)&cmd_operate_attach_port_keyword,
1379                 (void *)&cmd_operate_attach_port_identifier,
1380                 NULL,
1381         },
1382 };
1383
1384 /* *** detach a specified port *** */
1385 struct cmd_operate_detach_port_result {
1386         cmdline_fixed_string_t port;
1387         cmdline_fixed_string_t keyword;
1388         portid_t port_id;
1389 };
1390
1391 static void cmd_operate_detach_port_parsed(void *parsed_result,
1392                                 __rte_unused struct cmdline *cl,
1393                                 __rte_unused void *data)
1394 {
1395         struct cmd_operate_detach_port_result *res = parsed_result;
1396
1397         if (!strcmp(res->keyword, "detach")) {
1398                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1399                 detach_port_device(res->port_id);
1400         } else {
1401                 fprintf(stderr, "Unknown parameter\n");
1402         }
1403 }
1404
1405 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1406         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1407                         port, "port");
1408 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1409         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1410                         keyword, "detach");
1411 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1412         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1413                         port_id, RTE_UINT16);
1414
1415 cmdline_parse_inst_t cmd_operate_detach_port = {
1416         .f = cmd_operate_detach_port_parsed,
1417         .data = NULL,
1418         .help_str = "port detach <port_id>",
1419         .tokens = {
1420                 (void *)&cmd_operate_detach_port_port,
1421                 (void *)&cmd_operate_detach_port_keyword,
1422                 (void *)&cmd_operate_detach_port_port_id,
1423                 NULL,
1424         },
1425 };
1426
1427 /* *** detach device by identifier *** */
1428 struct cmd_operate_detach_device_result {
1429         cmdline_fixed_string_t device;
1430         cmdline_fixed_string_t keyword;
1431         cmdline_fixed_string_t identifier;
1432 };
1433
1434 static void cmd_operate_detach_device_parsed(void *parsed_result,
1435                                 __rte_unused struct cmdline *cl,
1436                                 __rte_unused void *data)
1437 {
1438         struct cmd_operate_detach_device_result *res = parsed_result;
1439
1440         if (!strcmp(res->keyword, "detach"))
1441                 detach_devargs(res->identifier);
1442         else
1443                 fprintf(stderr, "Unknown parameter\n");
1444 }
1445
1446 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1447         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1448                         device, "device");
1449 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1450         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1451                         keyword, "detach");
1452 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1453         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1454                         identifier, NULL);
1455
1456 cmdline_parse_inst_t cmd_operate_detach_device = {
1457         .f = cmd_operate_detach_device_parsed,
1458         .data = NULL,
1459         .help_str = "device detach <identifier>:"
1460                 "(identifier: pci address or virtual dev name)",
1461         .tokens = {
1462                 (void *)&cmd_operate_detach_device_device,
1463                 (void *)&cmd_operate_detach_device_keyword,
1464                 (void *)&cmd_operate_detach_device_identifier,
1465                 NULL,
1466         },
1467 };
1468 /* *** configure speed for all ports *** */
1469 struct cmd_config_speed_all {
1470         cmdline_fixed_string_t port;
1471         cmdline_fixed_string_t keyword;
1472         cmdline_fixed_string_t all;
1473         cmdline_fixed_string_t item1;
1474         cmdline_fixed_string_t item2;
1475         cmdline_fixed_string_t value1;
1476         cmdline_fixed_string_t value2;
1477 };
1478
1479 static int
1480 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1481 {
1482
1483         int duplex;
1484
1485         if (!strcmp(duplexstr, "half")) {
1486                 duplex = RTE_ETH_LINK_HALF_DUPLEX;
1487         } else if (!strcmp(duplexstr, "full")) {
1488                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1489         } else if (!strcmp(duplexstr, "auto")) {
1490                 duplex = RTE_ETH_LINK_FULL_DUPLEX;
1491         } else {
1492                 fprintf(stderr, "Unknown duplex parameter\n");
1493                 return -1;
1494         }
1495
1496         if (!strcmp(speedstr, "10")) {
1497                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1498                                 RTE_ETH_LINK_SPEED_10M_HD : RTE_ETH_LINK_SPEED_10M;
1499         } else if (!strcmp(speedstr, "100")) {
1500                 *speed = (duplex == RTE_ETH_LINK_HALF_DUPLEX) ?
1501                                 RTE_ETH_LINK_SPEED_100M_HD : RTE_ETH_LINK_SPEED_100M;
1502         } else {
1503                 if (duplex != RTE_ETH_LINK_FULL_DUPLEX) {
1504                         fprintf(stderr, "Invalid speed/duplex parameters\n");
1505                         return -1;
1506                 }
1507                 if (!strcmp(speedstr, "1000")) {
1508                         *speed = RTE_ETH_LINK_SPEED_1G;
1509                 } else if (!strcmp(speedstr, "10000")) {
1510                         *speed = RTE_ETH_LINK_SPEED_10G;
1511                 } else if (!strcmp(speedstr, "25000")) {
1512                         *speed = RTE_ETH_LINK_SPEED_25G;
1513                 } else if (!strcmp(speedstr, "40000")) {
1514                         *speed = RTE_ETH_LINK_SPEED_40G;
1515                 } else if (!strcmp(speedstr, "50000")) {
1516                         *speed = RTE_ETH_LINK_SPEED_50G;
1517                 } else if (!strcmp(speedstr, "100000")) {
1518                         *speed = RTE_ETH_LINK_SPEED_100G;
1519                 } else if (!strcmp(speedstr, "200000")) {
1520                         *speed = RTE_ETH_LINK_SPEED_200G;
1521                 } else if (!strcmp(speedstr, "auto")) {
1522                         *speed = RTE_ETH_LINK_SPEED_AUTONEG;
1523                 } else {
1524                         fprintf(stderr, "Unknown speed parameter\n");
1525                         return -1;
1526                 }
1527         }
1528
1529         if (*speed != RTE_ETH_LINK_SPEED_AUTONEG)
1530                 *speed |= RTE_ETH_LINK_SPEED_FIXED;
1531
1532         return 0;
1533 }
1534
1535 static void
1536 cmd_config_speed_all_parsed(void *parsed_result,
1537                         __rte_unused struct cmdline *cl,
1538                         __rte_unused void *data)
1539 {
1540         struct cmd_config_speed_all *res = parsed_result;
1541         uint32_t link_speed;
1542         portid_t pid;
1543
1544         if (!all_ports_stopped()) {
1545                 fprintf(stderr, "Please stop all ports first\n");
1546                 return;
1547         }
1548
1549         if (parse_and_check_speed_duplex(res->value1, res->value2,
1550                         &link_speed) < 0)
1551                 return;
1552
1553         RTE_ETH_FOREACH_DEV(pid) {
1554                 ports[pid].dev_conf.link_speeds = link_speed;
1555         }
1556
1557         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1558 }
1559
1560 cmdline_parse_token_string_t cmd_config_speed_all_port =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1562 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1564                                                         "config");
1565 cmdline_parse_token_string_t cmd_config_speed_all_all =
1566         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1567 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1568         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1569 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1570         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1571                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1572 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1573         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1574 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1575         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1576                                                 "half#full#auto");
1577
1578 cmdline_parse_inst_t cmd_config_speed_all = {
1579         .f = cmd_config_speed_all_parsed,
1580         .data = NULL,
1581         .help_str = "port config all speed "
1582                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1583                                                         "half|full|auto",
1584         .tokens = {
1585                 (void *)&cmd_config_speed_all_port,
1586                 (void *)&cmd_config_speed_all_keyword,
1587                 (void *)&cmd_config_speed_all_all,
1588                 (void *)&cmd_config_speed_all_item1,
1589                 (void *)&cmd_config_speed_all_value1,
1590                 (void *)&cmd_config_speed_all_item2,
1591                 (void *)&cmd_config_speed_all_value2,
1592                 NULL,
1593         },
1594 };
1595
1596 /* *** configure speed for specific port *** */
1597 struct cmd_config_speed_specific {
1598         cmdline_fixed_string_t port;
1599         cmdline_fixed_string_t keyword;
1600         portid_t id;
1601         cmdline_fixed_string_t item1;
1602         cmdline_fixed_string_t item2;
1603         cmdline_fixed_string_t value1;
1604         cmdline_fixed_string_t value2;
1605 };
1606
1607 static void
1608 cmd_config_speed_specific_parsed(void *parsed_result,
1609                                 __rte_unused struct cmdline *cl,
1610                                 __rte_unused void *data)
1611 {
1612         struct cmd_config_speed_specific *res = parsed_result;
1613         uint32_t link_speed;
1614
1615         if (port_id_is_invalid(res->id, ENABLED_WARN))
1616                 return;
1617
1618         if (!port_is_stopped(res->id)) {
1619                 fprintf(stderr, "Please stop port %d first\n", res->id);
1620                 return;
1621         }
1622
1623         if (parse_and_check_speed_duplex(res->value1, res->value2,
1624                         &link_speed) < 0)
1625                 return;
1626
1627         ports[res->id].dev_conf.link_speeds = link_speed;
1628
1629         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1630 }
1631
1632
1633 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1635                                                                 "port");
1636 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1638                                                                 "config");
1639 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1640         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, RTE_UINT16);
1641 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1642         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1643                                                                 "speed");
1644 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1645         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1646                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1647 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1648         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1649                                                                 "duplex");
1650 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1652                                                         "half#full#auto");
1653
1654 cmdline_parse_inst_t cmd_config_speed_specific = {
1655         .f = cmd_config_speed_specific_parsed,
1656         .data = NULL,
1657         .help_str = "port config <port_id> speed "
1658                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1659                                                         "half|full|auto",
1660         .tokens = {
1661                 (void *)&cmd_config_speed_specific_port,
1662                 (void *)&cmd_config_speed_specific_keyword,
1663                 (void *)&cmd_config_speed_specific_id,
1664                 (void *)&cmd_config_speed_specific_item1,
1665                 (void *)&cmd_config_speed_specific_value1,
1666                 (void *)&cmd_config_speed_specific_item2,
1667                 (void *)&cmd_config_speed_specific_value2,
1668                 NULL,
1669         },
1670 };
1671
1672 /* *** configure loopback for all ports *** */
1673 struct cmd_config_loopback_all {
1674         cmdline_fixed_string_t port;
1675         cmdline_fixed_string_t keyword;
1676         cmdline_fixed_string_t all;
1677         cmdline_fixed_string_t item;
1678         uint32_t mode;
1679 };
1680
1681 static void
1682 cmd_config_loopback_all_parsed(void *parsed_result,
1683                         __rte_unused struct cmdline *cl,
1684                         __rte_unused void *data)
1685 {
1686         struct cmd_config_loopback_all *res = parsed_result;
1687         portid_t pid;
1688
1689         if (!all_ports_stopped()) {
1690                 fprintf(stderr, "Please stop all ports first\n");
1691                 return;
1692         }
1693
1694         RTE_ETH_FOREACH_DEV(pid) {
1695                 ports[pid].dev_conf.lpbk_mode = res->mode;
1696         }
1697
1698         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1699 }
1700
1701 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1702         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1703 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1704         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1705                                                         "config");
1706 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1707         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1708 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1709         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1710                                                         "loopback");
1711 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1712         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, RTE_UINT32);
1713
1714 cmdline_parse_inst_t cmd_config_loopback_all = {
1715         .f = cmd_config_loopback_all_parsed,
1716         .data = NULL,
1717         .help_str = "port config all loopback <mode>",
1718         .tokens = {
1719                 (void *)&cmd_config_loopback_all_port,
1720                 (void *)&cmd_config_loopback_all_keyword,
1721                 (void *)&cmd_config_loopback_all_all,
1722                 (void *)&cmd_config_loopback_all_item,
1723                 (void *)&cmd_config_loopback_all_mode,
1724                 NULL,
1725         },
1726 };
1727
1728 /* *** configure loopback for specific port *** */
1729 struct cmd_config_loopback_specific {
1730         cmdline_fixed_string_t port;
1731         cmdline_fixed_string_t keyword;
1732         uint16_t port_id;
1733         cmdline_fixed_string_t item;
1734         uint32_t mode;
1735 };
1736
1737 static void
1738 cmd_config_loopback_specific_parsed(void *parsed_result,
1739                                 __rte_unused struct cmdline *cl,
1740                                 __rte_unused void *data)
1741 {
1742         struct cmd_config_loopback_specific *res = parsed_result;
1743
1744         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1745                 return;
1746
1747         if (!port_is_stopped(res->port_id)) {
1748                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
1749                 return;
1750         }
1751
1752         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1753
1754         cmd_reconfig_device_queue(res->port_id, 1, 1);
1755 }
1756
1757
1758 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1759         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1760                                                                 "port");
1761 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1762         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1763                                                                 "config");
1764 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1765         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1766                                                                 RTE_UINT16);
1767 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1768         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1769                                                                 "loopback");
1770 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1771         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1772                               RTE_UINT32);
1773
1774 cmdline_parse_inst_t cmd_config_loopback_specific = {
1775         .f = cmd_config_loopback_specific_parsed,
1776         .data = NULL,
1777         .help_str = "port config <port_id> loopback <mode>",
1778         .tokens = {
1779                 (void *)&cmd_config_loopback_specific_port,
1780                 (void *)&cmd_config_loopback_specific_keyword,
1781                 (void *)&cmd_config_loopback_specific_id,
1782                 (void *)&cmd_config_loopback_specific_item,
1783                 (void *)&cmd_config_loopback_specific_mode,
1784                 NULL,
1785         },
1786 };
1787
1788 /* *** configure txq/rxq, txd/rxd *** */
1789 struct cmd_config_rx_tx {
1790         cmdline_fixed_string_t port;
1791         cmdline_fixed_string_t keyword;
1792         cmdline_fixed_string_t all;
1793         cmdline_fixed_string_t name;
1794         uint16_t value;
1795 };
1796
1797 static void
1798 cmd_config_rx_tx_parsed(void *parsed_result,
1799                         __rte_unused struct cmdline *cl,
1800                         __rte_unused void *data)
1801 {
1802         struct cmd_config_rx_tx *res = parsed_result;
1803
1804         if (!all_ports_stopped()) {
1805                 fprintf(stderr, "Please stop all ports first\n");
1806                 return;
1807         }
1808         if (!strcmp(res->name, "rxq")) {
1809                 if (!res->value && !nb_txq) {
1810                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1811                         return;
1812                 }
1813                 if (check_nb_rxq(res->value) != 0)
1814                         return;
1815                 nb_rxq = res->value;
1816         }
1817         else if (!strcmp(res->name, "txq")) {
1818                 if (!res->value && !nb_rxq) {
1819                         fprintf(stderr, "Warning: Either rx or tx queues should be non zero\n");
1820                         return;
1821                 }
1822                 if (check_nb_txq(res->value) != 0)
1823                         return;
1824                 nb_txq = res->value;
1825         }
1826         else if (!strcmp(res->name, "rxd")) {
1827                 if (check_nb_rxd(res->value) != 0)
1828                         return;
1829                 nb_rxd = res->value;
1830         } else if (!strcmp(res->name, "txd")) {
1831                 if (check_nb_txd(res->value) != 0)
1832                         return;
1833
1834                 nb_txd = res->value;
1835         } else {
1836                 fprintf(stderr, "Unknown parameter\n");
1837                 return;
1838         }
1839
1840         fwd_config_setup();
1841
1842         init_port_config();
1843
1844         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1845 }
1846
1847 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1849 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1851 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1852         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1853 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1854         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1855                                                 "rxq#txq#rxd#txd");
1856 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1857         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, RTE_UINT16);
1858
1859 cmdline_parse_inst_t cmd_config_rx_tx = {
1860         .f = cmd_config_rx_tx_parsed,
1861         .data = NULL,
1862         .help_str = "port config all rxq|txq|rxd|txd <value>",
1863         .tokens = {
1864                 (void *)&cmd_config_rx_tx_port,
1865                 (void *)&cmd_config_rx_tx_keyword,
1866                 (void *)&cmd_config_rx_tx_all,
1867                 (void *)&cmd_config_rx_tx_name,
1868                 (void *)&cmd_config_rx_tx_value,
1869                 NULL,
1870         },
1871 };
1872
1873 /* *** config max packet length *** */
1874 struct cmd_config_max_pkt_len_result {
1875         cmdline_fixed_string_t port;
1876         cmdline_fixed_string_t keyword;
1877         cmdline_fixed_string_t all;
1878         cmdline_fixed_string_t name;
1879         uint32_t value;
1880 };
1881
1882 static void
1883 cmd_config_max_pkt_len_parsed(void *parsed_result,
1884                                 __rte_unused struct cmdline *cl,
1885                                 __rte_unused void *data)
1886 {
1887         struct cmd_config_max_pkt_len_result *res = parsed_result;
1888         portid_t port_id;
1889         int ret;
1890
1891         if (strcmp(res->name, "max-pkt-len") != 0) {
1892                 printf("Unknown parameter\n");
1893                 return;
1894         }
1895
1896         if (!all_ports_stopped()) {
1897                 fprintf(stderr, "Please stop all ports first\n");
1898                 return;
1899         }
1900
1901         RTE_ETH_FOREACH_DEV(port_id) {
1902                 struct rte_port *port = &ports[port_id];
1903
1904                 if (res->value < RTE_ETHER_MIN_LEN) {
1905                         fprintf(stderr,
1906                                 "max-pkt-len can not be less than %d\n",
1907                                 RTE_ETHER_MIN_LEN);
1908                         return;
1909                 }
1910
1911                 ret = eth_dev_info_get_print_err(port_id, &port->dev_info);
1912                 if (ret != 0) {
1913                         fprintf(stderr,
1914                                 "rte_eth_dev_info_get() failed for port %u\n",
1915                                 port_id);
1916                         return;
1917                 }
1918
1919                 update_mtu_from_frame_size(port_id, res->value);
1920         }
1921
1922         init_port_config();
1923
1924         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1925 }
1926
1927 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1928         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1929                                                                 "port");
1930 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1931         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1932                                                                 "config");
1933 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1934         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1935                                                                 "all");
1936 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1937         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1938                                                                 "max-pkt-len");
1939 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1940         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1941                                                                 RTE_UINT32);
1942
1943 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1944         .f = cmd_config_max_pkt_len_parsed,
1945         .data = NULL,
1946         .help_str = "port config all max-pkt-len <value>",
1947         .tokens = {
1948                 (void *)&cmd_config_max_pkt_len_port,
1949                 (void *)&cmd_config_max_pkt_len_keyword,
1950                 (void *)&cmd_config_max_pkt_len_all,
1951                 (void *)&cmd_config_max_pkt_len_name,
1952                 (void *)&cmd_config_max_pkt_len_value,
1953                 NULL,
1954         },
1955 };
1956
1957 /* *** config max LRO aggregated packet size *** */
1958 struct cmd_config_max_lro_pkt_size_result {
1959         cmdline_fixed_string_t port;
1960         cmdline_fixed_string_t keyword;
1961         cmdline_fixed_string_t all;
1962         cmdline_fixed_string_t name;
1963         uint32_t value;
1964 };
1965
1966 static void
1967 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
1968                                 __rte_unused struct cmdline *cl,
1969                                 __rte_unused void *data)
1970 {
1971         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
1972         portid_t pid;
1973
1974         if (!all_ports_stopped()) {
1975                 fprintf(stderr, "Please stop all ports first\n");
1976                 return;
1977         }
1978
1979         RTE_ETH_FOREACH_DEV(pid) {
1980                 struct rte_port *port = &ports[pid];
1981
1982                 if (!strcmp(res->name, "max-lro-pkt-size")) {
1983                         if (res->value ==
1984                                         port->dev_conf.rxmode.max_lro_pkt_size)
1985                                 return;
1986
1987                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
1988                 } else {
1989                         fprintf(stderr, "Unknown parameter\n");
1990                         return;
1991                 }
1992         }
1993
1994         init_port_config();
1995
1996         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1997 }
1998
1999 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2001                                  port, "port");
2002 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2003         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2004                                  keyword, "config");
2005 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2006         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2007                                  all, "all");
2008 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2009         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2010                                  name, "max-lro-pkt-size");
2011 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2012         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2013                               value, RTE_UINT32);
2014
2015 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2016         .f = cmd_config_max_lro_pkt_size_parsed,
2017         .data = NULL,
2018         .help_str = "port config all max-lro-pkt-size <value>",
2019         .tokens = {
2020                 (void *)&cmd_config_max_lro_pkt_size_port,
2021                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2022                 (void *)&cmd_config_max_lro_pkt_size_all,
2023                 (void *)&cmd_config_max_lro_pkt_size_name,
2024                 (void *)&cmd_config_max_lro_pkt_size_value,
2025                 NULL,
2026         },
2027 };
2028
2029 /* *** configure port MTU *** */
2030 struct cmd_config_mtu_result {
2031         cmdline_fixed_string_t port;
2032         cmdline_fixed_string_t keyword;
2033         cmdline_fixed_string_t mtu;
2034         portid_t port_id;
2035         uint16_t value;
2036 };
2037
2038 static void
2039 cmd_config_mtu_parsed(void *parsed_result,
2040                       __rte_unused struct cmdline *cl,
2041                       __rte_unused void *data)
2042 {
2043         struct cmd_config_mtu_result *res = parsed_result;
2044
2045         if (res->value < RTE_ETHER_MIN_LEN) {
2046                 fprintf(stderr, "mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2047                 return;
2048         }
2049         port_mtu_set(res->port_id, res->value);
2050 }
2051
2052 cmdline_parse_token_string_t cmd_config_mtu_port =
2053         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2054                                  "port");
2055 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2056         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2057                                  "config");
2058 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2059         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2060                                  "mtu");
2061 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2062         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id,
2063                                  RTE_UINT16);
2064 cmdline_parse_token_num_t cmd_config_mtu_value =
2065         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value,
2066                                  RTE_UINT16);
2067
2068 cmdline_parse_inst_t cmd_config_mtu = {
2069         .f = cmd_config_mtu_parsed,
2070         .data = NULL,
2071         .help_str = "port config mtu <port_id> <value>",
2072         .tokens = {
2073                 (void *)&cmd_config_mtu_port,
2074                 (void *)&cmd_config_mtu_keyword,
2075                 (void *)&cmd_config_mtu_mtu,
2076                 (void *)&cmd_config_mtu_port_id,
2077                 (void *)&cmd_config_mtu_value,
2078                 NULL,
2079         },
2080 };
2081
2082 /* *** configure rx mode *** */
2083 struct cmd_config_rx_mode_flag {
2084         cmdline_fixed_string_t port;
2085         cmdline_fixed_string_t keyword;
2086         cmdline_fixed_string_t all;
2087         cmdline_fixed_string_t name;
2088         cmdline_fixed_string_t value;
2089 };
2090
2091 static void
2092 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2093                                 __rte_unused struct cmdline *cl,
2094                                 __rte_unused void *data)
2095 {
2096         struct cmd_config_rx_mode_flag *res = parsed_result;
2097
2098         if (!all_ports_stopped()) {
2099                 fprintf(stderr, "Please stop all ports first\n");
2100                 return;
2101         }
2102
2103         if (!strcmp(res->name, "drop-en")) {
2104                 if (!strcmp(res->value, "on"))
2105                         rx_drop_en = 1;
2106                 else if (!strcmp(res->value, "off"))
2107                         rx_drop_en = 0;
2108                 else {
2109                         fprintf(stderr, "Unknown parameter\n");
2110                         return;
2111                 }
2112         } else {
2113                 fprintf(stderr, "Unknown parameter\n");
2114                 return;
2115         }
2116
2117         init_port_config();
2118
2119         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2120 }
2121
2122 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2123         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2124 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2125         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2126                                                                 "config");
2127 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2128         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2129 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2130         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2131                                         "drop-en");
2132 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2133         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2134                                                         "on#off");
2135
2136 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2137         .f = cmd_config_rx_mode_flag_parsed,
2138         .data = NULL,
2139         .help_str = "port config all drop-en on|off",
2140         .tokens = {
2141                 (void *)&cmd_config_rx_mode_flag_port,
2142                 (void *)&cmd_config_rx_mode_flag_keyword,
2143                 (void *)&cmd_config_rx_mode_flag_all,
2144                 (void *)&cmd_config_rx_mode_flag_name,
2145                 (void *)&cmd_config_rx_mode_flag_value,
2146                 NULL,
2147         },
2148 };
2149
2150 /* *** configure rss *** */
2151 struct cmd_config_rss {
2152         cmdline_fixed_string_t port;
2153         cmdline_fixed_string_t keyword;
2154         cmdline_fixed_string_t all;
2155         cmdline_fixed_string_t name;
2156         cmdline_fixed_string_t value;
2157 };
2158
2159 static void
2160 cmd_config_rss_parsed(void *parsed_result,
2161                         __rte_unused struct cmdline *cl,
2162                         __rte_unused void *data)
2163 {
2164         struct cmd_config_rss *res = parsed_result;
2165         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2166         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2167         int use_default = 0;
2168         int all_updated = 1;
2169         int diag;
2170         uint16_t i;
2171         int ret;
2172
2173         if (!strcmp(res->value, "all"))
2174                 rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
2175                         RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
2176                         RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
2177                         RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
2178                         RTE_ETH_RSS_ECPRI;
2179         else if (!strcmp(res->value, "eth"))
2180                 rss_conf.rss_hf = RTE_ETH_RSS_ETH;
2181         else if (!strcmp(res->value, "vlan"))
2182                 rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
2183         else if (!strcmp(res->value, "ip"))
2184                 rss_conf.rss_hf = RTE_ETH_RSS_IP;
2185         else if (!strcmp(res->value, "udp"))
2186                 rss_conf.rss_hf = RTE_ETH_RSS_UDP;
2187         else if (!strcmp(res->value, "tcp"))
2188                 rss_conf.rss_hf = RTE_ETH_RSS_TCP;
2189         else if (!strcmp(res->value, "sctp"))
2190                 rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
2191         else if (!strcmp(res->value, "ether"))
2192                 rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
2193         else if (!strcmp(res->value, "port"))
2194                 rss_conf.rss_hf = RTE_ETH_RSS_PORT;
2195         else if (!strcmp(res->value, "vxlan"))
2196                 rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
2197         else if (!strcmp(res->value, "geneve"))
2198                 rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
2199         else if (!strcmp(res->value, "nvgre"))
2200                 rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
2201         else if (!strcmp(res->value, "l3-pre32"))
2202                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2203         else if (!strcmp(res->value, "l3-pre40"))
2204                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2205         else if (!strcmp(res->value, "l3-pre48"))
2206                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2207         else if (!strcmp(res->value, "l3-pre56"))
2208                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2209         else if (!strcmp(res->value, "l3-pre64"))
2210                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2211         else if (!strcmp(res->value, "l3-pre96"))
2212                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2213         else if (!strcmp(res->value, "l3-src-only"))
2214                 rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
2215         else if (!strcmp(res->value, "l3-dst-only"))
2216                 rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
2217         else if (!strcmp(res->value, "l4-src-only"))
2218                 rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
2219         else if (!strcmp(res->value, "l4-dst-only"))
2220                 rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
2221         else if (!strcmp(res->value, "l2-src-only"))
2222                 rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
2223         else if (!strcmp(res->value, "l2-dst-only"))
2224                 rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
2225         else if (!strcmp(res->value, "l2tpv3"))
2226                 rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
2227         else if (!strcmp(res->value, "esp"))
2228                 rss_conf.rss_hf = RTE_ETH_RSS_ESP;
2229         else if (!strcmp(res->value, "ah"))
2230                 rss_conf.rss_hf = RTE_ETH_RSS_AH;
2231         else if (!strcmp(res->value, "pfcp"))
2232                 rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
2233         else if (!strcmp(res->value, "pppoe"))
2234                 rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
2235         else if (!strcmp(res->value, "gtpu"))
2236                 rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
2237         else if (!strcmp(res->value, "ecpri"))
2238                 rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
2239         else if (!strcmp(res->value, "mpls"))
2240                 rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
2241         else if (!strcmp(res->value, "ipv4-chksum"))
2242                 rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
2243         else if (!strcmp(res->value, "none"))
2244                 rss_conf.rss_hf = 0;
2245         else if (!strcmp(res->value, "level-default")) {
2246                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2247                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
2248         } else if (!strcmp(res->value, "level-outer")) {
2249                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2250                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_OUTERMOST);
2251         } else if (!strcmp(res->value, "level-inner")) {
2252                 rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
2253                 rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
2254         } else if (!strcmp(res->value, "default"))
2255                 use_default = 1;
2256         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2257                                                 atoi(res->value) < 64)
2258                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2259         else {
2260                 fprintf(stderr, "Unknown parameter\n");
2261                 return;
2262         }
2263         rss_conf.rss_key = NULL;
2264         /* Update global configuration for RSS types. */
2265         RTE_ETH_FOREACH_DEV(i) {
2266                 struct rte_eth_rss_conf local_rss_conf;
2267
2268                 ret = eth_dev_info_get_print_err(i, &dev_info);
2269                 if (ret != 0)
2270                         return;
2271
2272                 if (use_default)
2273                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2274
2275                 local_rss_conf = rss_conf;
2276                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2277                         dev_info.flow_type_rss_offloads;
2278                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2279                         printf("Port %u modified RSS hash function based on hardware support,"
2280                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2281                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2282                 }
2283                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2284                 if (diag < 0) {
2285                         all_updated = 0;
2286                         fprintf(stderr,
2287                                 "Configuration of RSS hash at ethernet port %d failed with error (%d): %s.\n",
2288                                 i, -diag, strerror(-diag));
2289                 }
2290         }
2291         if (all_updated && !use_default) {
2292                 rss_hf = rss_conf.rss_hf;
2293                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2294         }
2295 }
2296
2297 cmdline_parse_token_string_t cmd_config_rss_port =
2298         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2299 cmdline_parse_token_string_t cmd_config_rss_keyword =
2300         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2301 cmdline_parse_token_string_t cmd_config_rss_all =
2302         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2303 cmdline_parse_token_string_t cmd_config_rss_name =
2304         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2305 cmdline_parse_token_string_t cmd_config_rss_value =
2306         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2307
2308 cmdline_parse_inst_t cmd_config_rss = {
2309         .f = cmd_config_rss_parsed,
2310         .data = NULL,
2311         .help_str = "port config all rss "
2312                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2313                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|none|level-default|"
2314                 "level-outer|level-inner|ipv4-chksum|<flowtype_id>",
2315         .tokens = {
2316                 (void *)&cmd_config_rss_port,
2317                 (void *)&cmd_config_rss_keyword,
2318                 (void *)&cmd_config_rss_all,
2319                 (void *)&cmd_config_rss_name,
2320                 (void *)&cmd_config_rss_value,
2321                 NULL,
2322         },
2323 };
2324
2325 /* *** configure rss hash key *** */
2326 struct cmd_config_rss_hash_key {
2327         cmdline_fixed_string_t port;
2328         cmdline_fixed_string_t config;
2329         portid_t port_id;
2330         cmdline_fixed_string_t rss_hash_key;
2331         cmdline_fixed_string_t rss_type;
2332         cmdline_fixed_string_t key;
2333 };
2334
2335 static uint8_t
2336 hexa_digit_to_value(char hexa_digit)
2337 {
2338         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2339                 return (uint8_t) (hexa_digit - '0');
2340         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2341                 return (uint8_t) ((hexa_digit - 'a') + 10);
2342         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2343                 return (uint8_t) ((hexa_digit - 'A') + 10);
2344         /* Invalid hexa digit */
2345         return 0xFF;
2346 }
2347
2348 static uint8_t
2349 parse_and_check_key_hexa_digit(char *key, int idx)
2350 {
2351         uint8_t hexa_v;
2352
2353         hexa_v = hexa_digit_to_value(key[idx]);
2354         if (hexa_v == 0xFF)
2355                 fprintf(stderr,
2356                         "invalid key: character %c at position %d is not a valid hexa digit\n",
2357                         key[idx], idx);
2358         return hexa_v;
2359 }
2360
2361 static void
2362 cmd_config_rss_hash_key_parsed(void *parsed_result,
2363                                __rte_unused struct cmdline *cl,
2364                                __rte_unused void *data)
2365 {
2366         struct cmd_config_rss_hash_key *res = parsed_result;
2367         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2368         uint8_t xdgt0;
2369         uint8_t xdgt1;
2370         int i;
2371         struct rte_eth_dev_info dev_info;
2372         uint8_t hash_key_size;
2373         uint32_t key_len;
2374         int ret;
2375
2376         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2377         if (ret != 0)
2378                 return;
2379
2380         if (dev_info.hash_key_size > 0 &&
2381                         dev_info.hash_key_size <= sizeof(hash_key))
2382                 hash_key_size = dev_info.hash_key_size;
2383         else {
2384                 fprintf(stderr,
2385                         "dev_info did not provide a valid hash key size\n");
2386                 return;
2387         }
2388         /* Check the length of the RSS hash key */
2389         key_len = strlen(res->key);
2390         if (key_len != (hash_key_size * 2)) {
2391                 fprintf(stderr,
2392                         "key length: %d invalid - key must be a string of %d hexa-decimal numbers\n",
2393                         (int)key_len, hash_key_size * 2);
2394                 return;
2395         }
2396         /* Translate RSS hash key into binary representation */
2397         for (i = 0; i < hash_key_size; i++) {
2398                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2399                 if (xdgt0 == 0xFF)
2400                         return;
2401                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2402                 if (xdgt1 == 0xFF)
2403                         return;
2404                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2405         }
2406         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2407                         hash_key_size);
2408 }
2409
2410 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2411         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2412 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2413         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2414                                  "config");
2415 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2416         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id,
2417                                  RTE_UINT16);
2418 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2419         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2420                                  rss_hash_key, "rss-hash-key");
2421 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2422         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2423                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2424                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2425                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2426                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2427                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2428                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2429                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu#ecpri#mpls");
2430 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2431         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2432
2433 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2434         .f = cmd_config_rss_hash_key_parsed,
2435         .data = NULL,
2436         .help_str = "port config <port_id> rss-hash-key "
2437                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2438                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2439                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2440                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2441                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2442                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu|ecpri|mpls "
2443                 "<string of hex digits (variable length, NIC dependent)>",
2444         .tokens = {
2445                 (void *)&cmd_config_rss_hash_key_port,
2446                 (void *)&cmd_config_rss_hash_key_config,
2447                 (void *)&cmd_config_rss_hash_key_port_id,
2448                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2449                 (void *)&cmd_config_rss_hash_key_rss_type,
2450                 (void *)&cmd_config_rss_hash_key_value,
2451                 NULL,
2452         },
2453 };
2454
2455 /* *** cleanup txq mbufs *** */
2456 struct cmd_cleanup_txq_mbufs_result {
2457         cmdline_fixed_string_t port;
2458         cmdline_fixed_string_t keyword;
2459         cmdline_fixed_string_t name;
2460         uint16_t port_id;
2461         uint16_t queue_id;
2462         uint32_t free_cnt;
2463 };
2464
2465 static void
2466 cmd_cleanup_txq_mbufs_parsed(void *parsed_result,
2467                              __rte_unused struct cmdline *cl,
2468                              __rte_unused void *data)
2469 {
2470         struct cmd_cleanup_txq_mbufs_result *res = parsed_result;
2471         uint16_t port_id = res->port_id;
2472         uint16_t queue_id = res->queue_id;
2473         uint32_t free_cnt = res->free_cnt;
2474         struct rte_eth_txq_info qinfo;
2475         int ret;
2476
2477         if (test_done == 0) {
2478                 fprintf(stderr, "Please stop forwarding first\n");
2479                 return;
2480         }
2481
2482         if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) {
2483                 fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
2484                         port_id, queue_id);
2485                 return;
2486         }
2487
2488         if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
2489                 fprintf(stderr, "Tx queue %u not started\n", queue_id);
2490                 return;
2491         }
2492
2493         ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt);
2494         if (ret < 0) {
2495                 fprintf(stderr,
2496                         "Failed to cleanup mbuf for port %u Tx queue %u error desc: %s(%d)\n",
2497                         port_id, queue_id, strerror(-ret), ret);
2498                 return;
2499         }
2500
2501         printf("Cleanup port %u Tx queue %u mbuf nums: %u\n",
2502                port_id, queue_id, ret);
2503 }
2504
2505 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port =
2506         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port,
2507                                  "port");
2508 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup =
2509         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword,
2510                                  "cleanup");
2511 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id =
2512         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id,
2513                               RTE_UINT16);
2514 cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq =
2515         TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name,
2516                                  "txq");
2517 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id =
2518         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id,
2519                               RTE_UINT16);
2520 cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt =
2521         TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt,
2522                               RTE_UINT32);
2523
2524 cmdline_parse_inst_t cmd_cleanup_txq_mbufs = {
2525         .f = cmd_cleanup_txq_mbufs_parsed,
2526         .data = NULL,
2527         .help_str = "port cleanup <port_id> txq <queue_id> <free_cnt>",
2528         .tokens = {
2529                 (void *)&cmd_cleanup_txq_mbufs_port,
2530                 (void *)&cmd_cleanup_txq_mbufs_cleanup,
2531                 (void *)&cmd_cleanup_txq_mbufs_port_id,
2532                 (void *)&cmd_cleanup_txq_mbufs_txq,
2533                 (void *)&cmd_cleanup_txq_mbufs_queue_id,
2534                 (void *)&cmd_cleanup_txq_mbufs_free_cnt,
2535                 NULL,
2536         },
2537 };
2538
2539 /* *** configure port rxq/txq ring size *** */
2540 struct cmd_config_rxtx_ring_size {
2541         cmdline_fixed_string_t port;
2542         cmdline_fixed_string_t config;
2543         portid_t portid;
2544         cmdline_fixed_string_t rxtxq;
2545         uint16_t qid;
2546         cmdline_fixed_string_t rsize;
2547         uint16_t size;
2548 };
2549
2550 static void
2551 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2552                                  __rte_unused struct cmdline *cl,
2553                                  __rte_unused void *data)
2554 {
2555         struct cmd_config_rxtx_ring_size *res = parsed_result;
2556         struct rte_port *port;
2557         uint8_t isrx;
2558
2559         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2560                 return;
2561
2562         if (res->portid == (portid_t)RTE_PORT_ALL) {
2563                 fprintf(stderr, "Invalid port id\n");
2564                 return;
2565         }
2566
2567         port = &ports[res->portid];
2568
2569         if (!strcmp(res->rxtxq, "rxq"))
2570                 isrx = 1;
2571         else if (!strcmp(res->rxtxq, "txq"))
2572                 isrx = 0;
2573         else {
2574                 fprintf(stderr, "Unknown parameter\n");
2575                 return;
2576         }
2577
2578         if (isrx && rx_queue_id_is_invalid(res->qid))
2579                 return;
2580         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2581                 return;
2582
2583         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2584                 fprintf(stderr,
2585                         "Invalid rx ring_size, must > rx_free_thresh: %d\n",
2586                         rx_free_thresh);
2587                 return;
2588         }
2589
2590         if (isrx)
2591                 port->nb_rx_desc[res->qid] = res->size;
2592         else
2593                 port->nb_tx_desc[res->qid] = res->size;
2594
2595         cmd_reconfig_device_queue(res->portid, 0, 1);
2596 }
2597
2598 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2599         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2600                                  port, "port");
2601 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2602         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2603                                  config, "config");
2604 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2605         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606                                  portid, RTE_UINT16);
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609                                  rxtxq, "rxq#txq");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2611         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612                               qid, RTE_UINT16);
2613 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2614         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2615                                  rsize, "ring_size");
2616 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2617         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2618                               size, RTE_UINT16);
2619
2620 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2621         .f = cmd_config_rxtx_ring_size_parsed,
2622         .data = NULL,
2623         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2624         .tokens = {
2625                 (void *)&cmd_config_rxtx_ring_size_port,
2626                 (void *)&cmd_config_rxtx_ring_size_config,
2627                 (void *)&cmd_config_rxtx_ring_size_portid,
2628                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2629                 (void *)&cmd_config_rxtx_ring_size_qid,
2630                 (void *)&cmd_config_rxtx_ring_size_rsize,
2631                 (void *)&cmd_config_rxtx_ring_size_size,
2632                 NULL,
2633         },
2634 };
2635
2636 /* *** configure port rxq/txq start/stop *** */
2637 struct cmd_config_rxtx_queue {
2638         cmdline_fixed_string_t port;
2639         portid_t portid;
2640         cmdline_fixed_string_t rxtxq;
2641         uint16_t qid;
2642         cmdline_fixed_string_t opname;
2643 };
2644
2645 static void
2646 cmd_config_rxtx_queue_parsed(void *parsed_result,
2647                         __rte_unused struct cmdline *cl,
2648                         __rte_unused void *data)
2649 {
2650         struct cmd_config_rxtx_queue *res = parsed_result;
2651         uint8_t isrx;
2652         uint8_t isstart;
2653         int ret = 0;
2654
2655         if (test_done == 0) {
2656                 fprintf(stderr, "Please stop forwarding first\n");
2657                 return;
2658         }
2659
2660         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2661                 return;
2662
2663         if (port_is_started(res->portid) != 1) {
2664                 fprintf(stderr, "Please start port %u first\n", res->portid);
2665                 return;
2666         }
2667
2668         if (!strcmp(res->rxtxq, "rxq"))
2669                 isrx = 1;
2670         else if (!strcmp(res->rxtxq, "txq"))
2671                 isrx = 0;
2672         else {
2673                 fprintf(stderr, "Unknown parameter\n");
2674                 return;
2675         }
2676
2677         if (isrx && rx_queue_id_is_invalid(res->qid))
2678                 return;
2679         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2680                 return;
2681
2682         if (!strcmp(res->opname, "start"))
2683                 isstart = 1;
2684         else if (!strcmp(res->opname, "stop"))
2685                 isstart = 0;
2686         else {
2687                 fprintf(stderr, "Unknown parameter\n");
2688                 return;
2689         }
2690
2691         if (isstart && isrx)
2692                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2693         else if (!isstart && isrx)
2694                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2695         else if (isstart && !isrx)
2696                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2697         else
2698                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2699
2700         if (ret == -ENOTSUP)
2701                 fprintf(stderr, "Function not supported in PMD driver\n");
2702 }
2703
2704 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2705         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2706 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2707         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, RTE_UINT16);
2708 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2709         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2710 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2711         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, RTE_UINT16);
2712 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2713         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2714                                                 "start#stop");
2715
2716 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2717         .f = cmd_config_rxtx_queue_parsed,
2718         .data = NULL,
2719         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2720         .tokens = {
2721                 (void *)&cmd_config_rxtx_queue_port,
2722                 (void *)&cmd_config_rxtx_queue_portid,
2723                 (void *)&cmd_config_rxtx_queue_rxtxq,
2724                 (void *)&cmd_config_rxtx_queue_qid,
2725                 (void *)&cmd_config_rxtx_queue_opname,
2726                 NULL,
2727         },
2728 };
2729
2730 /* *** configure port rxq/txq deferred start on/off *** */
2731 struct cmd_config_deferred_start_rxtx_queue {
2732         cmdline_fixed_string_t port;
2733         portid_t port_id;
2734         cmdline_fixed_string_t rxtxq;
2735         uint16_t qid;
2736         cmdline_fixed_string_t opname;
2737         cmdline_fixed_string_t state;
2738 };
2739
2740 static void
2741 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2742                         __rte_unused struct cmdline *cl,
2743                         __rte_unused void *data)
2744 {
2745         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2746         struct rte_port *port;
2747         uint8_t isrx;
2748         uint8_t ison;
2749         uint8_t needreconfig = 0;
2750
2751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2752                 return;
2753
2754         if (port_is_started(res->port_id) != 0) {
2755                 fprintf(stderr, "Please stop port %u first\n", res->port_id);
2756                 return;
2757         }
2758
2759         port = &ports[res->port_id];
2760
2761         isrx = !strcmp(res->rxtxq, "rxq");
2762
2763         if (isrx && rx_queue_id_is_invalid(res->qid))
2764                 return;
2765         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2766                 return;
2767
2768         ison = !strcmp(res->state, "on");
2769
2770         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2771                 port->rx_conf[res->qid].rx_deferred_start = ison;
2772                 needreconfig = 1;
2773         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2774                 port->tx_conf[res->qid].tx_deferred_start = ison;
2775                 needreconfig = 1;
2776         }
2777
2778         if (needreconfig)
2779                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2780 }
2781
2782 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2783         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2784                                                 port, "port");
2785 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2786         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2787                                                 port_id, RTE_UINT16);
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2789         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790                                                 rxtxq, "rxq#txq");
2791 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2792         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793                                                 qid, RTE_UINT16);
2794 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2795         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2796                                                 opname, "deferred_start");
2797 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2798         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799                                                 state, "on#off");
2800
2801 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2802         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2803         .data = NULL,
2804         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2805         .tokens = {
2806                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2807                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2808                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2809                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2810                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2811                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2812                 NULL,
2813         },
2814 };
2815
2816 /* *** configure port rxq/txq setup *** */
2817 struct cmd_setup_rxtx_queue {
2818         cmdline_fixed_string_t port;
2819         portid_t portid;
2820         cmdline_fixed_string_t rxtxq;
2821         uint16_t qid;
2822         cmdline_fixed_string_t setup;
2823 };
2824
2825 /* Common CLI fields for queue setup */
2826 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2827         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2828 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2829         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, RTE_UINT16);
2830 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2831         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2832 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2833         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, RTE_UINT16);
2834 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2835         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2836
2837 static void
2838 cmd_setup_rxtx_queue_parsed(
2839         void *parsed_result,
2840         __rte_unused struct cmdline *cl,
2841         __rte_unused void *data)
2842 {
2843         struct cmd_setup_rxtx_queue *res = parsed_result;
2844         struct rte_port *port;
2845         struct rte_mempool *mp;
2846         unsigned int socket_id;
2847         uint8_t isrx = 0;
2848         int ret;
2849
2850         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2851                 return;
2852
2853         if (res->portid == (portid_t)RTE_PORT_ALL) {
2854                 fprintf(stderr, "Invalid port id\n");
2855                 return;
2856         }
2857
2858         if (!strcmp(res->rxtxq, "rxq"))
2859                 isrx = 1;
2860         else if (!strcmp(res->rxtxq, "txq"))
2861                 isrx = 0;
2862         else {
2863                 fprintf(stderr, "Unknown parameter\n");
2864                 return;
2865         }
2866
2867         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2868                 fprintf(stderr, "Invalid rx queue\n");
2869                 return;
2870         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2871                 fprintf(stderr, "Invalid tx queue\n");
2872                 return;
2873         }
2874
2875         port = &ports[res->portid];
2876         if (isrx) {
2877                 socket_id = rxring_numa[res->portid];
2878                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2879                         socket_id = port->socket_id;
2880
2881                 mp = mbuf_pool_find(socket_id, 0);
2882                 if (mp == NULL) {
2883                         fprintf(stderr,
2884                                 "Failed to setup RX queue: No mempool allocation on the socket %d\n",
2885                                 rxring_numa[res->portid]);
2886                         return;
2887                 }
2888                 ret = rx_queue_setup(res->portid,
2889                                      res->qid,
2890                                      port->nb_rx_desc[res->qid],
2891                                      socket_id,
2892                                      &port->rx_conf[res->qid],
2893                                      mp);
2894                 if (ret)
2895                         fprintf(stderr, "Failed to setup RX queue\n");
2896         } else {
2897                 socket_id = txring_numa[res->portid];
2898                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2899                         socket_id = port->socket_id;
2900
2901                 if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
2902                         fprintf(stderr,
2903                                 "Failed to setup TX queue: not enough descriptors\n");
2904                         return;
2905                 }
2906                 ret = rte_eth_tx_queue_setup(res->portid,
2907                                              res->qid,
2908                                              port->nb_tx_desc[res->qid],
2909                                              socket_id,
2910                                              &port->tx_conf[res->qid]);
2911                 if (ret)
2912                         fprintf(stderr, "Failed to setup TX queue\n");
2913         }
2914 }
2915
2916 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2917         .f = cmd_setup_rxtx_queue_parsed,
2918         .data = NULL,
2919         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2920         .tokens = {
2921                 (void *)&cmd_setup_rxtx_queue_port,
2922                 (void *)&cmd_setup_rxtx_queue_portid,
2923                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2924                 (void *)&cmd_setup_rxtx_queue_qid,
2925                 (void *)&cmd_setup_rxtx_queue_setup,
2926                 NULL,
2927         },
2928 };
2929
2930
2931 /* *** Configure RSS RETA *** */
2932 struct cmd_config_rss_reta {
2933         cmdline_fixed_string_t port;
2934         cmdline_fixed_string_t keyword;
2935         portid_t port_id;
2936         cmdline_fixed_string_t name;
2937         cmdline_fixed_string_t list_name;
2938         cmdline_fixed_string_t list_of_items;
2939 };
2940
2941 static int
2942 parse_reta_config(const char *str,
2943                   struct rte_eth_rss_reta_entry64 *reta_conf,
2944                   uint16_t nb_entries)
2945 {
2946         int i;
2947         unsigned size;
2948         uint16_t hash_index, idx, shift;
2949         uint16_t nb_queue;
2950         char s[256];
2951         const char *p, *p0 = str;
2952         char *end;
2953         enum fieldnames {
2954                 FLD_HASH_INDEX = 0,
2955                 FLD_QUEUE,
2956                 _NUM_FLD
2957         };
2958         unsigned long int_fld[_NUM_FLD];
2959         char *str_fld[_NUM_FLD];
2960
2961         while ((p = strchr(p0,'(')) != NULL) {
2962                 ++p;
2963                 if((p0 = strchr(p,')')) == NULL)
2964                         return -1;
2965
2966                 size = p0 - p;
2967                 if(size >= sizeof(s))
2968                         return -1;
2969
2970                 snprintf(s, sizeof(s), "%.*s", size, p);
2971                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2972                         return -1;
2973                 for (i = 0; i < _NUM_FLD; i++) {
2974                         errno = 0;
2975                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2976                         if (errno != 0 || end == str_fld[i] ||
2977                                         int_fld[i] > 65535)
2978                                 return -1;
2979                 }
2980
2981                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2982                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2983
2984                 if (hash_index >= nb_entries) {
2985                         fprintf(stderr, "Invalid RETA hash index=%d\n",
2986                                 hash_index);
2987                         return -1;
2988                 }
2989
2990                 idx = hash_index / RTE_ETH_RETA_GROUP_SIZE;
2991                 shift = hash_index % RTE_ETH_RETA_GROUP_SIZE;
2992                 reta_conf[idx].mask |= (1ULL << shift);
2993                 reta_conf[idx].reta[shift] = nb_queue;
2994         }
2995
2996         return 0;
2997 }
2998
2999 static void
3000 cmd_set_rss_reta_parsed(void *parsed_result,
3001                         __rte_unused struct cmdline *cl,
3002                         __rte_unused void *data)
3003 {
3004         int ret;
3005         struct rte_eth_dev_info dev_info;
3006         struct rte_eth_rss_reta_entry64 reta_conf[8];
3007         struct cmd_config_rss_reta *res = parsed_result;
3008
3009         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3010         if (ret != 0)
3011                 return;
3012
3013         if (dev_info.reta_size == 0) {
3014                 fprintf(stderr,
3015                         "Redirection table size is 0 which is invalid for RSS\n");
3016                 return;
3017         } else
3018                 printf("The reta size of port %d is %u\n",
3019                         res->port_id, dev_info.reta_size);
3020         if (dev_info.reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
3021                 fprintf(stderr,
3022                         "Currently do not support more than %u entries of redirection table\n",
3023                         RTE_ETH_RSS_RETA_SIZE_512);
3024                 return;
3025         }
3026
3027         memset(reta_conf, 0, sizeof(reta_conf));
3028         if (!strcmp(res->list_name, "reta")) {
3029                 if (parse_reta_config(res->list_of_items, reta_conf,
3030                                                 dev_info.reta_size)) {
3031                         fprintf(stderr,
3032                                 "Invalid RSS Redirection Table config entered\n");
3033                         return;
3034                 }
3035                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3036                                 reta_conf, dev_info.reta_size);
3037                 if (ret != 0)
3038                         fprintf(stderr,
3039                                 "Bad redirection table parameter, return code = %d\n",
3040                                 ret);
3041         }
3042 }
3043
3044 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3045         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3046 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3047         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3048 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3049         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, RTE_UINT16);
3050 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3051         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3052 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3053         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3054 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3055         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3056                                  NULL);
3057 cmdline_parse_inst_t cmd_config_rss_reta = {
3058         .f = cmd_set_rss_reta_parsed,
3059         .data = NULL,
3060         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3061         .tokens = {
3062                 (void *)&cmd_config_rss_reta_port,
3063                 (void *)&cmd_config_rss_reta_keyword,
3064                 (void *)&cmd_config_rss_reta_port_id,
3065                 (void *)&cmd_config_rss_reta_name,
3066                 (void *)&cmd_config_rss_reta_list_name,
3067                 (void *)&cmd_config_rss_reta_list_of_items,
3068                 NULL,
3069         },
3070 };
3071
3072 /* *** SHOW PORT RETA INFO *** */
3073 struct cmd_showport_reta {
3074         cmdline_fixed_string_t show;
3075         cmdline_fixed_string_t port;
3076         portid_t port_id;
3077         cmdline_fixed_string_t rss;
3078         cmdline_fixed_string_t reta;
3079         uint16_t size;
3080         cmdline_fixed_string_t list_of_items;
3081 };
3082
3083 static int
3084 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3085                            uint16_t nb_entries,
3086                            char *str)
3087 {
3088         uint32_t size;
3089         const char *p, *p0 = str;
3090         char s[256];
3091         char *end;
3092         char *str_fld[8];
3093         uint16_t i;
3094         uint16_t num = (nb_entries + RTE_ETH_RETA_GROUP_SIZE - 1) /
3095                         RTE_ETH_RETA_GROUP_SIZE;
3096         int ret;
3097
3098         p = strchr(p0, '(');
3099         if (p == NULL)
3100                 return -1;
3101         p++;
3102         p0 = strchr(p, ')');
3103         if (p0 == NULL)
3104                 return -1;
3105         size = p0 - p;
3106         if (size >= sizeof(s)) {
3107                 fprintf(stderr,
3108                         "The string size exceeds the internal buffer size\n");
3109                 return -1;
3110         }
3111         snprintf(s, sizeof(s), "%.*s", size, p);
3112         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3113         if (ret <= 0 || ret != num) {
3114                 fprintf(stderr,
3115                         "The bits of masks do not match the number of reta entries: %u\n",
3116                         num);
3117                 return -1;
3118         }
3119         for (i = 0; i < ret; i++)
3120                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3121
3122         return 0;
3123 }
3124
3125 static void
3126 cmd_showport_reta_parsed(void *parsed_result,
3127                          __rte_unused struct cmdline *cl,
3128                          __rte_unused void *data)
3129 {
3130         struct cmd_showport_reta *res = parsed_result;
3131         struct rte_eth_rss_reta_entry64 reta_conf[8];
3132         struct rte_eth_dev_info dev_info;
3133         uint16_t max_reta_size;
3134         int ret;
3135
3136         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3137         if (ret != 0)
3138                 return;
3139
3140         max_reta_size = RTE_MIN(dev_info.reta_size, RTE_ETH_RSS_RETA_SIZE_512);
3141         if (res->size == 0 || res->size > max_reta_size) {
3142                 fprintf(stderr, "Invalid redirection table size: %u (1-%u)\n",
3143                         res->size, max_reta_size);
3144                 return;
3145         }
3146
3147         memset(reta_conf, 0, sizeof(reta_conf));
3148         if (showport_parse_reta_config(reta_conf, res->size,
3149                                 res->list_of_items) < 0) {
3150                 fprintf(stderr, "Invalid string: %s for reta masks\n",
3151                         res->list_of_items);
3152                 return;
3153         }
3154         port_rss_reta_info(res->port_id, reta_conf, res->size);
3155 }
3156
3157 cmdline_parse_token_string_t cmd_showport_reta_show =
3158         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3159 cmdline_parse_token_string_t cmd_showport_reta_port =
3160         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3161 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3162         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, RTE_UINT16);
3163 cmdline_parse_token_string_t cmd_showport_reta_rss =
3164         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3165 cmdline_parse_token_string_t cmd_showport_reta_reta =
3166         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3167 cmdline_parse_token_num_t cmd_showport_reta_size =
3168         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, RTE_UINT16);
3169 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3170         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3171                                         list_of_items, NULL);
3172
3173 cmdline_parse_inst_t cmd_showport_reta = {
3174         .f = cmd_showport_reta_parsed,
3175         .data = NULL,
3176         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3177         .tokens = {
3178                 (void *)&cmd_showport_reta_show,
3179                 (void *)&cmd_showport_reta_port,
3180                 (void *)&cmd_showport_reta_port_id,
3181                 (void *)&cmd_showport_reta_rss,
3182                 (void *)&cmd_showport_reta_reta,
3183                 (void *)&cmd_showport_reta_size,
3184                 (void *)&cmd_showport_reta_list_of_items,
3185                 NULL,
3186         },
3187 };
3188
3189 /* *** Show RSS hash configuration *** */
3190 struct cmd_showport_rss_hash {
3191         cmdline_fixed_string_t show;
3192         cmdline_fixed_string_t port;
3193         portid_t port_id;
3194         cmdline_fixed_string_t rss_hash;
3195         cmdline_fixed_string_t rss_type;
3196         cmdline_fixed_string_t key; /* optional argument */
3197 };
3198
3199 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3200                                 __rte_unused struct cmdline *cl,
3201                                 void *show_rss_key)
3202 {
3203         struct cmd_showport_rss_hash *res = parsed_result;
3204
3205         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3206 }
3207
3208 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3209         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3210 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3211         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3212 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3213         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id,
3214                                  RTE_UINT16);
3215 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3216         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3217                                  "rss-hash");
3218 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3219         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3220
3221 cmdline_parse_inst_t cmd_showport_rss_hash = {
3222         .f = cmd_showport_rss_hash_parsed,
3223         .data = NULL,
3224         .help_str = "show port <port_id> rss-hash",
3225         .tokens = {
3226                 (void *)&cmd_showport_rss_hash_show,
3227                 (void *)&cmd_showport_rss_hash_port,
3228                 (void *)&cmd_showport_rss_hash_port_id,
3229                 (void *)&cmd_showport_rss_hash_rss_hash,
3230                 NULL,
3231         },
3232 };
3233
3234 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3235         .f = cmd_showport_rss_hash_parsed,
3236         .data = (void *)1,
3237         .help_str = "show port <port_id> rss-hash key",
3238         .tokens = {
3239                 (void *)&cmd_showport_rss_hash_show,
3240                 (void *)&cmd_showport_rss_hash_port,
3241                 (void *)&cmd_showport_rss_hash_port_id,
3242                 (void *)&cmd_showport_rss_hash_rss_hash,
3243                 (void *)&cmd_showport_rss_hash_rss_key,
3244                 NULL,
3245         },
3246 };
3247
3248 /* *** Configure DCB *** */
3249 struct cmd_config_dcb {
3250         cmdline_fixed_string_t port;
3251         cmdline_fixed_string_t config;
3252         portid_t port_id;
3253         cmdline_fixed_string_t dcb;
3254         cmdline_fixed_string_t vt;
3255         cmdline_fixed_string_t vt_en;
3256         uint8_t num_tcs;
3257         cmdline_fixed_string_t pfc;
3258         cmdline_fixed_string_t pfc_en;
3259 };
3260
3261 static void
3262 cmd_config_dcb_parsed(void *parsed_result,
3263                         __rte_unused struct cmdline *cl,
3264                         __rte_unused void *data)
3265 {
3266         struct cmd_config_dcb *res = parsed_result;
3267         struct rte_eth_dcb_info dcb_info;
3268         portid_t port_id = res->port_id;
3269         struct rte_port *port;
3270         uint8_t pfc_en;
3271         int ret;
3272
3273         port = &ports[port_id];
3274         /** Check if the port is not started **/
3275         if (port->port_status != RTE_PORT_STOPPED) {
3276                 fprintf(stderr, "Please stop port %d first\n", port_id);
3277                 return;
3278         }
3279
3280         if ((res->num_tcs != RTE_ETH_4_TCS) && (res->num_tcs != RTE_ETH_8_TCS)) {
3281                 fprintf(stderr,
3282                         "The invalid number of traffic class, only 4 or 8 allowed.\n");
3283                 return;
3284         }
3285
3286         if (nb_fwd_lcores < res->num_tcs) {
3287                 fprintf(stderr,
3288                         "nb_cores shouldn't be less than number of TCs.\n");
3289                 return;
3290         }
3291
3292         /* Check whether the port supports the report of DCB info. */
3293         ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
3294         if (ret == -ENOTSUP) {
3295                 fprintf(stderr, "rte_eth_dev_get_dcb_info not supported.\n");
3296                 return;
3297         }
3298
3299         if (!strncmp(res->pfc_en, "on", 2))
3300                 pfc_en = 1;
3301         else
3302                 pfc_en = 0;
3303
3304         /* DCB in VT mode */
3305         if (!strncmp(res->vt_en, "on", 2))
3306                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3307                                 (enum rte_eth_nb_tcs)res->num_tcs,
3308                                 pfc_en);
3309         else
3310                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3311                                 (enum rte_eth_nb_tcs)res->num_tcs,
3312                                 pfc_en);
3313         if (ret != 0) {
3314                 fprintf(stderr, "Cannot initialize network ports.\n");
3315                 return;
3316         }
3317
3318         fwd_config_setup();
3319
3320         cmd_reconfig_device_queue(port_id, 1, 1);
3321 }
3322
3323 cmdline_parse_token_string_t cmd_config_dcb_port =
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3325 cmdline_parse_token_string_t cmd_config_dcb_config =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3327 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3328         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, RTE_UINT16);
3329 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3330         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3331 cmdline_parse_token_string_t cmd_config_dcb_vt =
3332         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3333 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3334         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3335 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3336         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
3337 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3338         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3339 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3340         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3341
3342 cmdline_parse_inst_t cmd_config_dcb = {
3343         .f = cmd_config_dcb_parsed,
3344         .data = NULL,
3345         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3346         .tokens = {
3347                 (void *)&cmd_config_dcb_port,
3348                 (void *)&cmd_config_dcb_config,
3349                 (void *)&cmd_config_dcb_port_id,
3350                 (void *)&cmd_config_dcb_dcb,
3351                 (void *)&cmd_config_dcb_vt,
3352                 (void *)&cmd_config_dcb_vt_en,
3353                 (void *)&cmd_config_dcb_num_tcs,
3354                 (void *)&cmd_config_dcb_pfc,
3355                 (void *)&cmd_config_dcb_pfc_en,
3356                 NULL,
3357         },
3358 };
3359
3360 /* *** configure number of packets per burst *** */
3361 struct cmd_config_burst {
3362         cmdline_fixed_string_t port;
3363         cmdline_fixed_string_t keyword;
3364         cmdline_fixed_string_t all;
3365         cmdline_fixed_string_t name;
3366         uint16_t value;
3367 };
3368
3369 static void
3370 cmd_config_burst_parsed(void *parsed_result,
3371                         __rte_unused struct cmdline *cl,
3372                         __rte_unused void *data)
3373 {
3374         struct cmd_config_burst *res = parsed_result;
3375         struct rte_eth_dev_info dev_info;
3376         uint16_t rec_nb_pkts;
3377         int ret;
3378
3379         if (!all_ports_stopped()) {
3380                 fprintf(stderr, "Please stop all ports first\n");
3381                 return;
3382         }
3383
3384         if (!strcmp(res->name, "burst")) {
3385                 if (res->value == 0) {
3386                         /* If user gives a value of zero, query the PMD for
3387                          * its recommended Rx burst size. Testpmd uses a single
3388                          * size for all ports, so assume all ports are the same
3389                          * NIC model and use the values from Port 0.
3390                          */
3391                         ret = eth_dev_info_get_print_err(0, &dev_info);
3392                         if (ret != 0)
3393                                 return;
3394
3395                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3396
3397                         if (rec_nb_pkts == 0) {
3398                                 printf("PMD does not recommend a burst size.\n"
3399                                         "User provided value must be between"
3400                                         " 1 and %d\n", MAX_PKT_BURST);
3401                                 return;
3402                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3403                                 printf("PMD recommended burst size of %d"
3404                                         " exceeds maximum value of %d\n",
3405                                         rec_nb_pkts, MAX_PKT_BURST);
3406                                 return;
3407                         }
3408                         printf("Using PMD-provided burst value of %d\n",
3409                                 rec_nb_pkts);
3410                         nb_pkt_per_burst = rec_nb_pkts;
3411                 } else if (res->value > MAX_PKT_BURST) {
3412                         fprintf(stderr, "burst must be >= 1 && <= %d\n",
3413                                 MAX_PKT_BURST);
3414                         return;
3415                 } else
3416                         nb_pkt_per_burst = res->value;
3417         } else {
3418                 fprintf(stderr, "Unknown parameter\n");
3419                 return;
3420         }
3421
3422         init_port_config();
3423
3424         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3425 }
3426
3427 cmdline_parse_token_string_t cmd_config_burst_port =
3428         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3429 cmdline_parse_token_string_t cmd_config_burst_keyword =
3430         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3431 cmdline_parse_token_string_t cmd_config_burst_all =
3432         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3433 cmdline_parse_token_string_t cmd_config_burst_name =
3434         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3435 cmdline_parse_token_num_t cmd_config_burst_value =
3436         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, RTE_UINT16);
3437
3438 cmdline_parse_inst_t cmd_config_burst = {
3439         .f = cmd_config_burst_parsed,
3440         .data = NULL,
3441         .help_str = "port config all burst <value>",
3442         .tokens = {
3443                 (void *)&cmd_config_burst_port,
3444                 (void *)&cmd_config_burst_keyword,
3445                 (void *)&cmd_config_burst_all,
3446                 (void *)&cmd_config_burst_name,
3447                 (void *)&cmd_config_burst_value,
3448                 NULL,
3449         },
3450 };
3451
3452 /* *** configure rx/tx queues *** */
3453 struct cmd_config_thresh {
3454         cmdline_fixed_string_t port;
3455         cmdline_fixed_string_t keyword;
3456         cmdline_fixed_string_t all;
3457         cmdline_fixed_string_t name;
3458         uint8_t value;
3459 };
3460
3461 static void
3462 cmd_config_thresh_parsed(void *parsed_result,
3463                         __rte_unused struct cmdline *cl,
3464                         __rte_unused void *data)
3465 {
3466         struct cmd_config_thresh *res = parsed_result;
3467
3468         if (!all_ports_stopped()) {
3469                 fprintf(stderr, "Please stop all ports first\n");
3470                 return;
3471         }
3472
3473         if (!strcmp(res->name, "txpt"))
3474                 tx_pthresh = res->value;
3475         else if(!strcmp(res->name, "txht"))
3476                 tx_hthresh = res->value;
3477         else if(!strcmp(res->name, "txwt"))
3478                 tx_wthresh = res->value;
3479         else if(!strcmp(res->name, "rxpt"))
3480                 rx_pthresh = res->value;
3481         else if(!strcmp(res->name, "rxht"))
3482                 rx_hthresh = res->value;
3483         else if(!strcmp(res->name, "rxwt"))
3484                 rx_wthresh = res->value;
3485         else {
3486                 fprintf(stderr, "Unknown parameter\n");
3487                 return;
3488         }
3489
3490         init_port_config();
3491
3492         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3493 }
3494
3495 cmdline_parse_token_string_t cmd_config_thresh_port =
3496         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3497 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3498         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3499 cmdline_parse_token_string_t cmd_config_thresh_all =
3500         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3501 cmdline_parse_token_string_t cmd_config_thresh_name =
3502         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3503                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3504 cmdline_parse_token_num_t cmd_config_thresh_value =
3505         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, RTE_UINT8);
3506
3507 cmdline_parse_inst_t cmd_config_thresh = {
3508         .f = cmd_config_thresh_parsed,
3509         .data = NULL,
3510         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3511         .tokens = {
3512                 (void *)&cmd_config_thresh_port,
3513                 (void *)&cmd_config_thresh_keyword,
3514                 (void *)&cmd_config_thresh_all,
3515                 (void *)&cmd_config_thresh_name,
3516                 (void *)&cmd_config_thresh_value,
3517                 NULL,
3518         },
3519 };
3520
3521 /* *** configure free/rs threshold *** */
3522 struct cmd_config_threshold {
3523         cmdline_fixed_string_t port;
3524         cmdline_fixed_string_t keyword;
3525         cmdline_fixed_string_t all;
3526         cmdline_fixed_string_t name;
3527         uint16_t value;
3528 };
3529
3530 static void
3531 cmd_config_threshold_parsed(void *parsed_result,
3532                         __rte_unused struct cmdline *cl,
3533                         __rte_unused void *data)
3534 {
3535         struct cmd_config_threshold *res = parsed_result;
3536
3537         if (!all_ports_stopped()) {
3538                 fprintf(stderr, "Please stop all ports first\n");
3539                 return;
3540         }
3541
3542         if (!strcmp(res->name, "txfreet"))
3543                 tx_free_thresh = res->value;
3544         else if (!strcmp(res->name, "txrst"))
3545                 tx_rs_thresh = res->value;
3546         else if (!strcmp(res->name, "rxfreet"))
3547                 rx_free_thresh = res->value;
3548         else {
3549                 fprintf(stderr, "Unknown parameter\n");
3550                 return;
3551         }
3552
3553         init_port_config();
3554
3555         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3556 }
3557
3558 cmdline_parse_token_string_t cmd_config_threshold_port =
3559         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3560 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3561         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3562                                                                 "config");
3563 cmdline_parse_token_string_t cmd_config_threshold_all =
3564         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3565 cmdline_parse_token_string_t cmd_config_threshold_name =
3566         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3567                                                 "txfreet#txrst#rxfreet");
3568 cmdline_parse_token_num_t cmd_config_threshold_value =
3569         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, RTE_UINT16);
3570
3571 cmdline_parse_inst_t cmd_config_threshold = {
3572         .f = cmd_config_threshold_parsed,
3573         .data = NULL,
3574         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3575         .tokens = {
3576                 (void *)&cmd_config_threshold_port,
3577                 (void *)&cmd_config_threshold_keyword,
3578                 (void *)&cmd_config_threshold_all,
3579                 (void *)&cmd_config_threshold_name,
3580                 (void *)&cmd_config_threshold_value,
3581                 NULL,
3582         },
3583 };
3584
3585 /* *** stop *** */
3586 struct cmd_stop_result {
3587         cmdline_fixed_string_t stop;
3588 };
3589
3590 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3591                             __rte_unused struct cmdline *cl,
3592                             __rte_unused void *data)
3593 {
3594         stop_packet_forwarding();
3595 }
3596
3597 cmdline_parse_token_string_t cmd_stop_stop =
3598         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3599
3600 cmdline_parse_inst_t cmd_stop = {
3601         .f = cmd_stop_parsed,
3602         .data = NULL,
3603         .help_str = "stop: Stop packet forwarding",
3604         .tokens = {
3605                 (void *)&cmd_stop_stop,
3606                 NULL,
3607         },
3608 };
3609
3610 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3611
3612 unsigned int
3613 parse_item_list(const char *str, const char *item_name, unsigned int max_items,
3614                 unsigned int *parsed_items, int check_unique_values)
3615 {
3616         unsigned int nb_item;
3617         unsigned int value;
3618         unsigned int i;
3619         unsigned int j;
3620         int value_ok;
3621         char c;
3622
3623         /*
3624          * First parse all items in the list and store their value.
3625          */
3626         value = 0;
3627         nb_item = 0;
3628         value_ok = 0;
3629         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3630                 c = str[i];
3631                 if ((c >= '0') && (c <= '9')) {
3632                         value = (unsigned int) (value * 10 + (c - '0'));
3633                         value_ok = 1;
3634                         continue;
3635                 }
3636                 if (c != ',') {
3637                         fprintf(stderr, "character %c is not a decimal digit\n", c);
3638                         return 0;
3639                 }
3640                 if (! value_ok) {
3641                         fprintf(stderr, "No valid value before comma\n");
3642                         return 0;
3643                 }
3644                 if (nb_item < max_items) {
3645                         parsed_items[nb_item] = value;
3646                         value_ok = 0;
3647                         value = 0;
3648                 }
3649                 nb_item++;
3650         }
3651         if (nb_item >= max_items) {
3652                 fprintf(stderr, "Number of %s = %u > %u (maximum items)\n",
3653                         item_name, nb_item + 1, max_items);
3654                 return 0;
3655         }
3656         parsed_items[nb_item++] = value;
3657         if (! check_unique_values)
3658                 return nb_item;
3659
3660         /*
3661          * Then, check that all values in the list are different.
3662          * No optimization here...
3663          */
3664         for (i = 0; i < nb_item; i++) {
3665                 for (j = i + 1; j < nb_item; j++) {
3666                         if (parsed_items[j] == parsed_items[i]) {
3667                                 fprintf(stderr,
3668                                         "duplicated %s %u at index %u and %u\n",
3669                                         item_name, parsed_items[i], i, j);
3670                                 return 0;
3671                         }
3672                 }
3673         }
3674         return nb_item;
3675 }
3676
3677 struct cmd_set_list_result {
3678         cmdline_fixed_string_t cmd_keyword;
3679         cmdline_fixed_string_t list_name;
3680         cmdline_fixed_string_t list_of_items;
3681 };
3682
3683 static void cmd_set_list_parsed(void *parsed_result,
3684                                 __rte_unused struct cmdline *cl,
3685                                 __rte_unused void *data)
3686 {
3687         struct cmd_set_list_result *res;
3688         union {
3689                 unsigned int lcorelist[RTE_MAX_LCORE];
3690                 unsigned int portlist[RTE_MAX_ETHPORTS];
3691         } parsed_items;
3692         unsigned int nb_item;
3693
3694         if (test_done == 0) {
3695                 fprintf(stderr, "Please stop forwarding first\n");
3696                 return;
3697         }
3698
3699         res = parsed_result;
3700         if (!strcmp(res->list_name, "corelist")) {
3701                 nb_item = parse_item_list(res->list_of_items, "core",
3702                                           RTE_MAX_LCORE,
3703                                           parsed_items.lcorelist, 1);
3704                 if (nb_item > 0) {
3705                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3706                         fwd_config_setup();
3707                 }
3708                 return;
3709         }
3710         if (!strcmp(res->list_name, "portlist")) {
3711                 nb_item = parse_item_list(res->list_of_items, "port",
3712                                           RTE_MAX_ETHPORTS,
3713                                           parsed_items.portlist, 1);
3714                 if (nb_item > 0) {
3715                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3716                         fwd_config_setup();
3717                 }
3718         }
3719 }
3720
3721 cmdline_parse_token_string_t cmd_set_list_keyword =
3722         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3723                                  "set");
3724 cmdline_parse_token_string_t cmd_set_list_name =
3725         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3726                                  "corelist#portlist");
3727 cmdline_parse_token_string_t cmd_set_list_of_items =
3728         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3729                                  NULL);
3730
3731 cmdline_parse_inst_t cmd_set_fwd_list = {
3732         .f = cmd_set_list_parsed,
3733         .data = NULL,
3734         .help_str = "set corelist|portlist <list0[,list1]*>",
3735         .tokens = {
3736                 (void *)&cmd_set_list_keyword,
3737                 (void *)&cmd_set_list_name,
3738                 (void *)&cmd_set_list_of_items,
3739                 NULL,
3740         },
3741 };
3742
3743 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3744
3745 struct cmd_setmask_result {
3746         cmdline_fixed_string_t set;
3747         cmdline_fixed_string_t mask;
3748         uint64_t hexavalue;
3749 };
3750
3751 static void cmd_set_mask_parsed(void *parsed_result,
3752                                 __rte_unused struct cmdline *cl,
3753                                 __rte_unused void *data)
3754 {
3755         struct cmd_setmask_result *res = parsed_result;
3756
3757         if (test_done == 0) {
3758                 fprintf(stderr, "Please stop forwarding first\n");
3759                 return;
3760         }
3761         if (!strcmp(res->mask, "coremask")) {
3762                 set_fwd_lcores_mask(res->hexavalue);
3763                 fwd_config_setup();
3764         } else if (!strcmp(res->mask, "portmask")) {
3765                 set_fwd_ports_mask(res->hexavalue);
3766                 fwd_config_setup();
3767         }
3768 }
3769
3770 cmdline_parse_token_string_t cmd_setmask_set =
3771         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3772 cmdline_parse_token_string_t cmd_setmask_mask =
3773         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3774                                  "coremask#portmask");
3775 cmdline_parse_token_num_t cmd_setmask_value =
3776         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, RTE_UINT64);
3777
3778 cmdline_parse_inst_t cmd_set_fwd_mask = {
3779         .f = cmd_set_mask_parsed,
3780         .data = NULL,
3781         .help_str = "set coremask|portmask <hexadecimal value>",
3782         .tokens = {
3783                 (void *)&cmd_setmask_set,
3784                 (void *)&cmd_setmask_mask,
3785                 (void *)&cmd_setmask_value,
3786                 NULL,
3787         },
3788 };
3789
3790 /*
3791  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3792  */
3793 struct cmd_set_result {
3794         cmdline_fixed_string_t set;
3795         cmdline_fixed_string_t what;
3796         uint16_t value;
3797 };
3798
3799 static void cmd_set_parsed(void *parsed_result,
3800                            __rte_unused struct cmdline *cl,
3801                            __rte_unused void *data)
3802 {
3803         struct cmd_set_result *res = parsed_result;
3804         if (!strcmp(res->what, "nbport")) {
3805                 set_fwd_ports_number(res->value);
3806                 fwd_config_setup();
3807         } else if (!strcmp(res->what, "nbcore")) {
3808                 set_fwd_lcores_number(res->value);
3809                 fwd_config_setup();
3810         } else if (!strcmp(res->what, "burst"))
3811                 set_nb_pkt_per_burst(res->value);
3812         else if (!strcmp(res->what, "verbose"))
3813                 set_verbose_level(res->value);
3814 }
3815
3816 cmdline_parse_token_string_t cmd_set_set =
3817         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3818 cmdline_parse_token_string_t cmd_set_what =
3819         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3820                                  "nbport#nbcore#burst#verbose");
3821 cmdline_parse_token_num_t cmd_set_value =
3822         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, RTE_UINT16);
3823
3824 cmdline_parse_inst_t cmd_set_numbers = {
3825         .f = cmd_set_parsed,
3826         .data = NULL,
3827         .help_str = "set nbport|nbcore|burst|verbose <value>",
3828         .tokens = {
3829                 (void *)&cmd_set_set,
3830                 (void *)&cmd_set_what,
3831                 (void *)&cmd_set_value,
3832                 NULL,
3833         },
3834 };
3835
3836 /* *** SET LOG LEVEL CONFIGURATION *** */
3837
3838 struct cmd_set_log_result {
3839         cmdline_fixed_string_t set;
3840         cmdline_fixed_string_t log;
3841         cmdline_fixed_string_t type;
3842         uint32_t level;
3843 };
3844
3845 static void
3846 cmd_set_log_parsed(void *parsed_result,
3847                    __rte_unused struct cmdline *cl,
3848                    __rte_unused void *data)
3849 {
3850         struct cmd_set_log_result *res;
3851         int ret;
3852
3853         res = parsed_result;
3854         if (!strcmp(res->type, "global"))
3855                 rte_log_set_global_level(res->level);
3856         else {
3857                 ret = rte_log_set_level_regexp(res->type, res->level);
3858                 if (ret < 0)
3859                         fprintf(stderr, "Unable to set log level\n");
3860         }
3861 }
3862
3863 cmdline_parse_token_string_t cmd_set_log_set =
3864         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3865 cmdline_parse_token_string_t cmd_set_log_log =
3866         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3867 cmdline_parse_token_string_t cmd_set_log_type =
3868         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3869 cmdline_parse_token_num_t cmd_set_log_level =
3870         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, RTE_UINT32);
3871
3872 cmdline_parse_inst_t cmd_set_log = {
3873         .f = cmd_set_log_parsed,
3874         .data = NULL,
3875         .help_str = "set log global|<type> <level>",
3876         .tokens = {
3877                 (void *)&cmd_set_log_set,
3878                 (void *)&cmd_set_log_log,
3879                 (void *)&cmd_set_log_type,
3880                 (void *)&cmd_set_log_level,
3881                 NULL,
3882         },
3883 };
3884
3885 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3886
3887 struct cmd_set_rxoffs_result {
3888         cmdline_fixed_string_t cmd_keyword;
3889         cmdline_fixed_string_t rxoffs;
3890         cmdline_fixed_string_t seg_offsets;
3891 };
3892
3893 static void
3894 cmd_set_rxoffs_parsed(void *parsed_result,
3895                       __rte_unused struct cmdline *cl,
3896                       __rte_unused void *data)
3897 {
3898         struct cmd_set_rxoffs_result *res;
3899         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3900         unsigned int nb_segs;
3901
3902         res = parsed_result;
3903         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3904                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3905         if (nb_segs > 0)
3906                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3907         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3908 }
3909
3910 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3911         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3912                                  cmd_keyword, "set");
3913 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3914         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3915                                  rxoffs, "rxoffs");
3916 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3917         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3918                                  seg_offsets, NULL);
3919
3920 cmdline_parse_inst_t cmd_set_rxoffs = {
3921         .f = cmd_set_rxoffs_parsed,
3922         .data = NULL,
3923         .help_str = "set rxoffs <len0[,len1]*>",
3924         .tokens = {
3925                 (void *)&cmd_set_rxoffs_keyword,
3926                 (void *)&cmd_set_rxoffs_name,
3927                 (void *)&cmd_set_rxoffs_offsets,
3928                 NULL,
3929         },
3930 };
3931
3932 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3933
3934 struct cmd_set_rxpkts_result {
3935         cmdline_fixed_string_t cmd_keyword;
3936         cmdline_fixed_string_t rxpkts;
3937         cmdline_fixed_string_t seg_lengths;
3938 };
3939
3940 static void
3941 cmd_set_rxpkts_parsed(void *parsed_result,
3942                       __rte_unused struct cmdline *cl,
3943                       __rte_unused void *data)
3944 {
3945         struct cmd_set_rxpkts_result *res;
3946         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3947         unsigned int nb_segs;
3948
3949         res = parsed_result;
3950         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3951                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3952         if (nb_segs > 0)
3953                 set_rx_pkt_segments(seg_lengths, nb_segs);
3954         cmd_reconfig_device_queue(RTE_PORT_ALL, 0, 1);
3955 }
3956
3957 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3958         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3959                                  cmd_keyword, "set");
3960 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3961         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3962                                  rxpkts, "rxpkts");
3963 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3964         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3965                                  seg_lengths, NULL);
3966
3967 cmdline_parse_inst_t cmd_set_rxpkts = {
3968         .f = cmd_set_rxpkts_parsed,
3969         .data = NULL,
3970         .help_str = "set rxpkts <len0[,len1]*>",
3971         .tokens = {
3972                 (void *)&cmd_set_rxpkts_keyword,
3973                 (void *)&cmd_set_rxpkts_name,
3974                 (void *)&cmd_set_rxpkts_lengths,
3975                 NULL,
3976         },
3977 };
3978
3979 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3980
3981 struct cmd_set_txpkts_result {
3982         cmdline_fixed_string_t cmd_keyword;
3983         cmdline_fixed_string_t txpkts;
3984         cmdline_fixed_string_t seg_lengths;
3985 };
3986
3987 static void
3988 cmd_set_txpkts_parsed(void *parsed_result,
3989                       __rte_unused struct cmdline *cl,
3990                       __rte_unused void *data)
3991 {
3992         struct cmd_set_txpkts_result *res;
3993         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3994         unsigned int nb_segs;
3995
3996         res = parsed_result;
3997         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3998                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3999         if (nb_segs > 0)
4000                 set_tx_pkt_segments(seg_lengths, nb_segs);
4001 }
4002
4003 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4004         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4005                                  cmd_keyword, "set");
4006 cmdline_parse_token_string_t cmd_set_txpkts_name =
4007         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4008                                  txpkts, "txpkts");
4009 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4010         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4011                                  seg_lengths, NULL);
4012
4013 cmdline_parse_inst_t cmd_set_txpkts = {
4014         .f = cmd_set_txpkts_parsed,
4015         .data = NULL,
4016         .help_str = "set txpkts <len0[,len1]*>",
4017         .tokens = {
4018                 (void *)&cmd_set_txpkts_keyword,
4019                 (void *)&cmd_set_txpkts_name,
4020                 (void *)&cmd_set_txpkts_lengths,
4021                 NULL,
4022         },
4023 };
4024
4025 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4026
4027 struct cmd_set_txsplit_result {
4028         cmdline_fixed_string_t cmd_keyword;
4029         cmdline_fixed_string_t txsplit;
4030         cmdline_fixed_string_t mode;
4031 };
4032
4033 static void
4034 cmd_set_txsplit_parsed(void *parsed_result,
4035                       __rte_unused struct cmdline *cl,
4036                       __rte_unused void *data)
4037 {
4038         struct cmd_set_txsplit_result *res;
4039
4040         res = parsed_result;
4041         set_tx_pkt_split(res->mode);
4042 }
4043
4044 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4045         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4046                                  cmd_keyword, "set");
4047 cmdline_parse_token_string_t cmd_set_txsplit_name =
4048         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4049                                  txsplit, "txsplit");
4050 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4051         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4052                                  mode, NULL);
4053
4054 cmdline_parse_inst_t cmd_set_txsplit = {
4055         .f = cmd_set_txsplit_parsed,
4056         .data = NULL,
4057         .help_str = "set txsplit on|off|rand",
4058         .tokens = {
4059                 (void *)&cmd_set_txsplit_keyword,
4060                 (void *)&cmd_set_txsplit_name,
4061                 (void *)&cmd_set_txsplit_mode,
4062                 NULL,
4063         },
4064 };
4065
4066 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4067
4068 struct cmd_set_txtimes_result {
4069         cmdline_fixed_string_t cmd_keyword;
4070         cmdline_fixed_string_t txtimes;
4071         cmdline_fixed_string_t tx_times;
4072 };
4073
4074 static void
4075 cmd_set_txtimes_parsed(void *parsed_result,
4076                        __rte_unused struct cmdline *cl,
4077                        __rte_unused void *data)
4078 {
4079         struct cmd_set_txtimes_result *res;
4080         unsigned int tx_times[2] = {0, 0};
4081         unsigned int n_times;
4082
4083         res = parsed_result;
4084         n_times = parse_item_list(res->tx_times, "tx times",
4085                                   2, tx_times, 0);
4086         if (n_times == 2)
4087                 set_tx_pkt_times(tx_times);
4088 }
4089
4090 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4091         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4092                                  cmd_keyword, "set");
4093 cmdline_parse_token_string_t cmd_set_txtimes_name =
4094         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4095                                  txtimes, "txtimes");
4096 cmdline_parse_token_string_t cmd_set_txtimes_value =
4097         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4098                                  tx_times, NULL);
4099
4100 cmdline_parse_inst_t cmd_set_txtimes = {
4101         .f = cmd_set_txtimes_parsed,
4102         .data = NULL,
4103         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4104         .tokens = {
4105                 (void *)&cmd_set_txtimes_keyword,
4106                 (void *)&cmd_set_txtimes_name,
4107                 (void *)&cmd_set_txtimes_value,
4108                 NULL,
4109         },
4110 };
4111
4112 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4113 struct cmd_rx_vlan_filter_all_result {
4114         cmdline_fixed_string_t rx_vlan;
4115         cmdline_fixed_string_t what;
4116         cmdline_fixed_string_t all;
4117         portid_t port_id;
4118 };
4119
4120 static void
4121 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4122                               __rte_unused struct cmdline *cl,
4123                               __rte_unused void *data)
4124 {
4125         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4126
4127         if (!strcmp(res->what, "add"))
4128                 rx_vlan_all_filter_set(res->port_id, 1);
4129         else
4130                 rx_vlan_all_filter_set(res->port_id, 0);
4131 }
4132
4133 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4134         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4135                                  rx_vlan, "rx_vlan");
4136 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4137         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4138                                  what, "add#rm");
4139 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4140         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4141                                  all, "all");
4142 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4143         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4144                               port_id, RTE_UINT16);
4145
4146 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4147         .f = cmd_rx_vlan_filter_all_parsed,
4148         .data = NULL,
4149         .help_str = "rx_vlan add|rm all <port_id>: "
4150                 "Add/Remove all identifiers to/from the set of VLAN "
4151                 "identifiers filtered by a port",
4152         .tokens = {
4153                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4154                 (void *)&cmd_rx_vlan_filter_all_what,
4155                 (void *)&cmd_rx_vlan_filter_all_all,
4156                 (void *)&cmd_rx_vlan_filter_all_portid,
4157                 NULL,
4158         },
4159 };
4160
4161 /* *** VLAN OFFLOAD SET ON A PORT *** */
4162 struct cmd_vlan_offload_result {
4163         cmdline_fixed_string_t vlan;
4164         cmdline_fixed_string_t set;
4165         cmdline_fixed_string_t vlan_type;
4166         cmdline_fixed_string_t what;
4167         cmdline_fixed_string_t on;
4168         cmdline_fixed_string_t port_id;
4169 };
4170
4171 static void
4172 cmd_vlan_offload_parsed(void *parsed_result,
4173                           __rte_unused struct cmdline *cl,
4174                           __rte_unused void *data)
4175 {
4176         int on;
4177         struct cmd_vlan_offload_result *res = parsed_result;
4178         char *str;
4179         int i, len = 0;
4180         portid_t port_id = 0;
4181         unsigned int tmp;
4182
4183         str = res->port_id;
4184         len = strnlen(str, STR_TOKEN_SIZE);
4185         i = 0;
4186         /* Get port_id first */
4187         while(i < len){
4188                 if(str[i] == ',')
4189                         break;
4190
4191                 i++;
4192         }
4193         str[i]='\0';
4194         tmp = strtoul(str, NULL, 0);
4195         /* If port_id greater that what portid_t can represent, return */
4196         if(tmp >= RTE_MAX_ETHPORTS)
4197                 return;
4198         port_id = (portid_t)tmp;
4199
4200         if (!strcmp(res->on, "on"))
4201                 on = 1;
4202         else
4203                 on = 0;
4204
4205         if (!strcmp(res->what, "strip"))
4206                 rx_vlan_strip_set(port_id,  on);
4207         else if(!strcmp(res->what, "stripq")){
4208                 uint16_t queue_id = 0;
4209
4210                 /* No queue_id, return */
4211                 if(i + 1 >= len) {
4212                         fprintf(stderr, "must specify (port,queue_id)\n");
4213                         return;
4214                 }
4215                 tmp = strtoul(str + i + 1, NULL, 0);
4216                 /* If queue_id greater that what 16-bits can represent, return */
4217                 if(tmp > 0xffff)
4218                         return;
4219
4220                 queue_id = (uint16_t)tmp;
4221                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4222         }
4223         else if (!strcmp(res->what, "filter"))
4224                 rx_vlan_filter_set(port_id, on);
4225         else if (!strcmp(res->what, "qinq_strip"))
4226                 rx_vlan_qinq_strip_set(port_id, on);
4227         else
4228                 vlan_extend_set(port_id, on);
4229
4230         return;
4231 }
4232
4233 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4234         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4235                                  vlan, "vlan");
4236 cmdline_parse_token_string_t cmd_vlan_offload_set =
4237         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4238                                  set, "set");
4239 cmdline_parse_token_string_t cmd_vlan_offload_what =
4240         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4241                                 what, "strip#filter#qinq_strip#extend#stripq");
4242 cmdline_parse_token_string_t cmd_vlan_offload_on =
4243         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4244                               on, "on#off");
4245 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4246         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4247                               port_id, NULL);
4248
4249 cmdline_parse_inst_t cmd_vlan_offload = {
4250         .f = cmd_vlan_offload_parsed,
4251         .data = NULL,
4252         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4253                 "<port_id[,queue_id]>: "
4254                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4255         .tokens = {
4256                 (void *)&cmd_vlan_offload_vlan,
4257                 (void *)&cmd_vlan_offload_set,
4258                 (void *)&cmd_vlan_offload_what,
4259                 (void *)&cmd_vlan_offload_on,
4260                 (void *)&cmd_vlan_offload_portid,
4261                 NULL,
4262         },
4263 };
4264
4265 /* *** VLAN TPID SET ON A PORT *** */
4266 struct cmd_vlan_tpid_result {
4267         cmdline_fixed_string_t vlan;
4268         cmdline_fixed_string_t set;
4269         cmdline_fixed_string_t vlan_type;
4270         cmdline_fixed_string_t what;
4271         uint16_t tp_id;
4272         portid_t port_id;
4273 };
4274
4275 static void
4276 cmd_vlan_tpid_parsed(void *parsed_result,
4277                           __rte_unused struct cmdline *cl,
4278                           __rte_unused void *data)
4279 {
4280         struct cmd_vlan_tpid_result *res = parsed_result;
4281         enum rte_vlan_type vlan_type;
4282
4283         if (!strcmp(res->vlan_type, "inner"))
4284                 vlan_type = RTE_ETH_VLAN_TYPE_INNER;
4285         else if (!strcmp(res->vlan_type, "outer"))
4286                 vlan_type = RTE_ETH_VLAN_TYPE_OUTER;
4287         else {
4288                 fprintf(stderr, "Unknown vlan type\n");
4289                 return;
4290         }
4291         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4292 }
4293
4294 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4295         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4296                                  vlan, "vlan");
4297 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4298         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4299                                  set, "set");
4300 cmdline_parse_token_string_t cmd_vlan_type =
4301         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4302                                  vlan_type, "inner#outer");
4303 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4304         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4305                                  what, "tpid");
4306 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4307         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4308                               tp_id, RTE_UINT16);
4309 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4310         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4311                               port_id, RTE_UINT16);
4312
4313 cmdline_parse_inst_t cmd_vlan_tpid = {
4314         .f = cmd_vlan_tpid_parsed,
4315         .data = NULL,
4316         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4317                 "Set the VLAN Ether type",
4318         .tokens = {
4319                 (void *)&cmd_vlan_tpid_vlan,
4320                 (void *)&cmd_vlan_tpid_set,
4321                 (void *)&cmd_vlan_type,
4322                 (void *)&cmd_vlan_tpid_what,
4323                 (void *)&cmd_vlan_tpid_tpid,
4324                 (void *)&cmd_vlan_tpid_portid,
4325                 NULL,
4326         },
4327 };
4328
4329 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4330 struct cmd_rx_vlan_filter_result {
4331         cmdline_fixed_string_t rx_vlan;
4332         cmdline_fixed_string_t what;
4333         uint16_t vlan_id;
4334         portid_t port_id;
4335 };
4336
4337 static void
4338 cmd_rx_vlan_filter_parsed(void *parsed_result,
4339                           __rte_unused struct cmdline *cl,
4340                           __rte_unused void *data)
4341 {
4342         struct cmd_rx_vlan_filter_result *res = parsed_result;
4343
4344         if (!strcmp(res->what, "add"))
4345                 rx_vft_set(res->port_id, res->vlan_id, 1);
4346         else
4347                 rx_vft_set(res->port_id, res->vlan_id, 0);
4348 }
4349
4350 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4351         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4352                                  rx_vlan, "rx_vlan");
4353 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4354         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4355                                  what, "add#rm");
4356 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4357         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4358                               vlan_id, RTE_UINT16);
4359 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4360         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4361                               port_id, RTE_UINT16);
4362
4363 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4364         .f = cmd_rx_vlan_filter_parsed,
4365         .data = NULL,
4366         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4367                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4368                 "identifiers filtered by a port",
4369         .tokens = {
4370                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4371                 (void *)&cmd_rx_vlan_filter_what,
4372                 (void *)&cmd_rx_vlan_filter_vlanid,
4373                 (void *)&cmd_rx_vlan_filter_portid,
4374                 NULL,
4375         },
4376 };
4377
4378 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4379 struct cmd_tx_vlan_set_result {
4380         cmdline_fixed_string_t tx_vlan;
4381         cmdline_fixed_string_t set;
4382         portid_t port_id;
4383         uint16_t vlan_id;
4384 };
4385
4386 static void
4387 cmd_tx_vlan_set_parsed(void *parsed_result,
4388                        __rte_unused struct cmdline *cl,
4389                        __rte_unused void *data)
4390 {
4391         struct cmd_tx_vlan_set_result *res = parsed_result;
4392
4393         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4394                 return;
4395
4396         if (!port_is_stopped(res->port_id)) {
4397                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4398                 return;
4399         }
4400
4401         tx_vlan_set(res->port_id, res->vlan_id);
4402
4403         cmd_reconfig_device_queue(res->port_id, 1, 1);
4404 }
4405
4406 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4407         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4408                                  tx_vlan, "tx_vlan");
4409 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4410         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4411                                  set, "set");
4412 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4413         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4414                               port_id, RTE_UINT16);
4415 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4416         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4417                               vlan_id, RTE_UINT16);
4418
4419 cmdline_parse_inst_t cmd_tx_vlan_set = {
4420         .f = cmd_tx_vlan_set_parsed,
4421         .data = NULL,
4422         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4423                 "Enable hardware insertion of a single VLAN header "
4424                 "with a given TAG Identifier in packets sent on a port",
4425         .tokens = {
4426                 (void *)&cmd_tx_vlan_set_tx_vlan,
4427                 (void *)&cmd_tx_vlan_set_set,
4428                 (void *)&cmd_tx_vlan_set_portid,
4429                 (void *)&cmd_tx_vlan_set_vlanid,
4430                 NULL,
4431         },
4432 };
4433
4434 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4435 struct cmd_tx_vlan_set_qinq_result {
4436         cmdline_fixed_string_t tx_vlan;
4437         cmdline_fixed_string_t set;
4438         portid_t port_id;
4439         uint16_t vlan_id;
4440         uint16_t vlan_id_outer;
4441 };
4442
4443 static void
4444 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4445                             __rte_unused struct cmdline *cl,
4446                             __rte_unused void *data)
4447 {
4448         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4449
4450         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4451                 return;
4452
4453         if (!port_is_stopped(res->port_id)) {
4454                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4455                 return;
4456         }
4457
4458         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4459
4460         cmd_reconfig_device_queue(res->port_id, 1, 1);
4461 }
4462
4463 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4464         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4465                 tx_vlan, "tx_vlan");
4466 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4467         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4468                 set, "set");
4469 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4470         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4471                 port_id, RTE_UINT16);
4472 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4473         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4474                 vlan_id, RTE_UINT16);
4475 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4476         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4477                 vlan_id_outer, RTE_UINT16);
4478
4479 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4480         .f = cmd_tx_vlan_set_qinq_parsed,
4481         .data = NULL,
4482         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4483                 "Enable hardware insertion of double VLAN header "
4484                 "with given TAG Identifiers in packets sent on a port",
4485         .tokens = {
4486                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4487                 (void *)&cmd_tx_vlan_set_qinq_set,
4488                 (void *)&cmd_tx_vlan_set_qinq_portid,
4489                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4490                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4491                 NULL,
4492         },
4493 };
4494
4495 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4496 struct cmd_tx_vlan_set_pvid_result {
4497         cmdline_fixed_string_t tx_vlan;
4498         cmdline_fixed_string_t set;
4499         cmdline_fixed_string_t pvid;
4500         portid_t port_id;
4501         uint16_t vlan_id;
4502         cmdline_fixed_string_t mode;
4503 };
4504
4505 static void
4506 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4507                             __rte_unused struct cmdline *cl,
4508                             __rte_unused void *data)
4509 {
4510         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4511
4512         if (strcmp(res->mode, "on") == 0)
4513                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4514         else
4515                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4516 }
4517
4518 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4519         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4520                                  tx_vlan, "tx_vlan");
4521 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4522         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4523                                  set, "set");
4524 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4525         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4526                                  pvid, "pvid");
4527 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4528         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4529                              port_id, RTE_UINT16);
4530 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4531         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4532                               vlan_id, RTE_UINT16);
4533 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4534         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4535                                  mode, "on#off");
4536
4537 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4538         .f = cmd_tx_vlan_set_pvid_parsed,
4539         .data = NULL,
4540         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4541         .tokens = {
4542                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4543                 (void *)&cmd_tx_vlan_set_pvid_set,
4544                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4545                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4546                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4547                 (void *)&cmd_tx_vlan_set_pvid_mode,
4548                 NULL,
4549         },
4550 };
4551
4552 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4553 struct cmd_tx_vlan_reset_result {
4554         cmdline_fixed_string_t tx_vlan;
4555         cmdline_fixed_string_t reset;
4556         portid_t port_id;
4557 };
4558
4559 static void
4560 cmd_tx_vlan_reset_parsed(void *parsed_result,
4561                          __rte_unused struct cmdline *cl,
4562                          __rte_unused void *data)
4563 {
4564         struct cmd_tx_vlan_reset_result *res = parsed_result;
4565
4566         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4567                 return;
4568
4569         if (!port_is_stopped(res->port_id)) {
4570                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4571                 return;
4572         }
4573
4574         tx_vlan_reset(res->port_id);
4575
4576         cmd_reconfig_device_queue(res->port_id, 1, 1);
4577 }
4578
4579 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4580         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4581                                  tx_vlan, "tx_vlan");
4582 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4583         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4584                                  reset, "reset");
4585 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4586         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4587                               port_id, RTE_UINT16);
4588
4589 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4590         .f = cmd_tx_vlan_reset_parsed,
4591         .data = NULL,
4592         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4593                 "VLAN header in packets sent on a port",
4594         .tokens = {
4595                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4596                 (void *)&cmd_tx_vlan_reset_reset,
4597                 (void *)&cmd_tx_vlan_reset_portid,
4598                 NULL,
4599         },
4600 };
4601
4602
4603 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4604 struct cmd_csum_result {
4605         cmdline_fixed_string_t csum;
4606         cmdline_fixed_string_t mode;
4607         cmdline_fixed_string_t proto;
4608         cmdline_fixed_string_t hwsw;
4609         portid_t port_id;
4610 };
4611
4612 static void
4613 csum_show(int port_id)
4614 {
4615         struct rte_eth_dev_info dev_info;
4616         uint64_t tx_offloads;
4617         int ret;
4618
4619         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4620         printf("Parse tunnel is %s\n",
4621                 (ports[port_id].parse_tunnel) ? "on" : "off");
4622         printf("IP checksum offload is %s\n",
4623                 (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4624         printf("UDP checksum offload is %s\n",
4625                 (tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4626         printf("TCP checksum offload is %s\n",
4627                 (tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4628         printf("SCTP checksum offload is %s\n",
4629                 (tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4630         printf("Outer-Ip checksum offload is %s\n",
4631                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4632         printf("Outer-Udp checksum offload is %s\n",
4633                 (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4634
4635         /* display warnings if configuration is not supported by the NIC */
4636         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4637         if (ret != 0)
4638                 return;
4639
4640         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) &&
4641                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4642                 fprintf(stderr,
4643                         "Warning: hardware IP checksum enabled but not supported by port %d\n",
4644                         port_id);
4645         }
4646         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) &&
4647                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) == 0) {
4648                 fprintf(stderr,
4649                         "Warning: hardware UDP checksum enabled but not supported by port %d\n",
4650                         port_id);
4651         }
4652         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) &&
4653                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) == 0) {
4654                 fprintf(stderr,
4655                         "Warning: hardware TCP checksum enabled but not supported by port %d\n",
4656                         port_id);
4657         }
4658         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
4659                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4660                 fprintf(stderr,
4661                         "Warning: hardware SCTP checksum enabled but not supported by port %d\n",
4662                         port_id);
4663         }
4664         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4665                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4666                 fprintf(stderr,
4667                         "Warning: hardware outer IP checksum enabled but not supported by port %d\n",
4668                         port_id);
4669         }
4670         if ((tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4671                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
4672                         == 0) {
4673                 fprintf(stderr,
4674                         "Warning: hardware outer UDP checksum enabled but not supported by port %d\n",
4675                         port_id);
4676         }
4677 }
4678
4679 static void
4680 cmd_config_queue_tx_offloads(struct rte_port *port)
4681 {
4682         int k;
4683
4684         /* Apply queue tx offloads configuration */
4685         for (k = 0; k < port->dev_info.max_tx_queues; k++)
4686                 port->tx_conf[k].offloads =
4687                         port->dev_conf.txmode.offloads;
4688 }
4689
4690 static void
4691 cmd_csum_parsed(void *parsed_result,
4692                        __rte_unused struct cmdline *cl,
4693                        __rte_unused void *data)
4694 {
4695         struct cmd_csum_result *res = parsed_result;
4696         int hw = 0;
4697         uint64_t csum_offloads = 0;
4698         struct rte_eth_dev_info dev_info;
4699         int ret;
4700
4701         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4702                 fprintf(stderr, "invalid port %d\n", res->port_id);
4703                 return;
4704         }
4705         if (!port_is_stopped(res->port_id)) {
4706                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4707                 return;
4708         }
4709
4710         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4711         if (ret != 0)
4712                 return;
4713
4714         if (!strcmp(res->mode, "set")) {
4715
4716                 if (!strcmp(res->hwsw, "hw"))
4717                         hw = 1;
4718
4719                 if (!strcmp(res->proto, "ip")) {
4720                         if (hw == 0 || (dev_info.tx_offload_capa &
4721                                                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
4722                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
4723                         } else {
4724                                 fprintf(stderr,
4725                                         "IP checksum offload is not supported by port %u\n",
4726                                         res->port_id);
4727                         }
4728                 } else if (!strcmp(res->proto, "udp")) {
4729                         if (hw == 0 || (dev_info.tx_offload_capa &
4730                                                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM)) {
4731                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM;
4732                         } else {
4733                                 fprintf(stderr,
4734                                         "UDP checksum offload is not supported by port %u\n",
4735                                         res->port_id);
4736                         }
4737                 } else if (!strcmp(res->proto, "tcp")) {
4738                         if (hw == 0 || (dev_info.tx_offload_capa &
4739                                                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM)) {
4740                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
4741                         } else {
4742                                 fprintf(stderr,
4743                                         "TCP checksum offload is not supported by port %u\n",
4744                                         res->port_id);
4745                         }
4746                 } else if (!strcmp(res->proto, "sctp")) {
4747                         if (hw == 0 || (dev_info.tx_offload_capa &
4748                                                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)) {
4749                                 csum_offloads |= RTE_ETH_TX_OFFLOAD_SCTP_CKSUM;
4750                         } else {
4751                                 fprintf(stderr,
4752                                         "SCTP checksum offload is not supported by port %u\n",
4753                                         res->port_id);
4754                         }
4755                 } else if (!strcmp(res->proto, "outer-ip")) {
4756                         if (hw == 0 || (dev_info.tx_offload_capa &
4757                                         RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4758                                 csum_offloads |=
4759                                                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4760                         } else {
4761                                 fprintf(stderr,
4762                                         "Outer IP checksum offload is not supported by port %u\n",
4763                                         res->port_id);
4764                         }
4765                 } else if (!strcmp(res->proto, "outer-udp")) {
4766                         if (hw == 0 || (dev_info.tx_offload_capa &
4767                                         RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4768                                 csum_offloads |=
4769                                                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
4770                         } else {
4771                                 fprintf(stderr,
4772                                         "Outer UDP checksum offload is not supported by port %u\n",
4773                                         res->port_id);
4774                         }
4775                 }
4776
4777                 if (hw) {
4778                         ports[res->port_id].dev_conf.txmode.offloads |=
4779                                                         csum_offloads;
4780                 } else {
4781                         ports[res->port_id].dev_conf.txmode.offloads &=
4782                                                         (~csum_offloads);
4783                 }
4784                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4785         }
4786         csum_show(res->port_id);
4787
4788         cmd_reconfig_device_queue(res->port_id, 1, 1);
4789 }
4790
4791 cmdline_parse_token_string_t cmd_csum_csum =
4792         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4793                                 csum, "csum");
4794 cmdline_parse_token_string_t cmd_csum_mode =
4795         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4796                                 mode, "set");
4797 cmdline_parse_token_string_t cmd_csum_proto =
4798         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4799                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4800 cmdline_parse_token_string_t cmd_csum_hwsw =
4801         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4802                                 hwsw, "hw#sw");
4803 cmdline_parse_token_num_t cmd_csum_portid =
4804         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4805                                 port_id, RTE_UINT16);
4806
4807 cmdline_parse_inst_t cmd_csum_set = {
4808         .f = cmd_csum_parsed,
4809         .data = NULL,
4810         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4811                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4812                 "using csum forward engine",
4813         .tokens = {
4814                 (void *)&cmd_csum_csum,
4815                 (void *)&cmd_csum_mode,
4816                 (void *)&cmd_csum_proto,
4817                 (void *)&cmd_csum_hwsw,
4818                 (void *)&cmd_csum_portid,
4819                 NULL,
4820         },
4821 };
4822
4823 cmdline_parse_token_string_t cmd_csum_mode_show =
4824         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4825                                 mode, "show");
4826
4827 cmdline_parse_inst_t cmd_csum_show = {
4828         .f = cmd_csum_parsed,
4829         .data = NULL,
4830         .help_str = "csum show <port_id>: Show checksum offload configuration",
4831         .tokens = {
4832                 (void *)&cmd_csum_csum,
4833                 (void *)&cmd_csum_mode_show,
4834                 (void *)&cmd_csum_portid,
4835                 NULL,
4836         },
4837 };
4838
4839 /* Enable/disable tunnel parsing */
4840 struct cmd_csum_tunnel_result {
4841         cmdline_fixed_string_t csum;
4842         cmdline_fixed_string_t parse;
4843         cmdline_fixed_string_t onoff;
4844         portid_t port_id;
4845 };
4846
4847 static void
4848 cmd_csum_tunnel_parsed(void *parsed_result,
4849                        __rte_unused struct cmdline *cl,
4850                        __rte_unused void *data)
4851 {
4852         struct cmd_csum_tunnel_result *res = parsed_result;
4853
4854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4855                 return;
4856
4857         if (!strcmp(res->onoff, "on"))
4858                 ports[res->port_id].parse_tunnel = 1;
4859         else
4860                 ports[res->port_id].parse_tunnel = 0;
4861
4862         csum_show(res->port_id);
4863 }
4864
4865 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4866         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4867                                 csum, "csum");
4868 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4869         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4870                                 parse, "parse-tunnel");
4871 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4872         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4873                                 onoff, "on#off");
4874 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4875         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4876                                 port_id, RTE_UINT16);
4877
4878 cmdline_parse_inst_t cmd_csum_tunnel = {
4879         .f = cmd_csum_tunnel_parsed,
4880         .data = NULL,
4881         .help_str = "csum parse-tunnel on|off <port_id>: "
4882                 "Enable/Disable parsing of tunnels for csum engine",
4883         .tokens = {
4884                 (void *)&cmd_csum_tunnel_csum,
4885                 (void *)&cmd_csum_tunnel_parse,
4886                 (void *)&cmd_csum_tunnel_onoff,
4887                 (void *)&cmd_csum_tunnel_portid,
4888                 NULL,
4889         },
4890 };
4891
4892 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4893 struct cmd_tso_set_result {
4894         cmdline_fixed_string_t tso;
4895         cmdline_fixed_string_t mode;
4896         uint16_t tso_segsz;
4897         portid_t port_id;
4898 };
4899
4900 static void
4901 cmd_tso_set_parsed(void *parsed_result,
4902                        __rte_unused struct cmdline *cl,
4903                        __rte_unused void *data)
4904 {
4905         struct cmd_tso_set_result *res = parsed_result;
4906         struct rte_eth_dev_info dev_info;
4907         int ret;
4908
4909         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4910                 return;
4911         if (!port_is_stopped(res->port_id)) {
4912                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
4913                 return;
4914         }
4915
4916         if (!strcmp(res->mode, "set"))
4917                 ports[res->port_id].tso_segsz = res->tso_segsz;
4918
4919         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4920         if (ret != 0)
4921                 return;
4922
4923         if ((ports[res->port_id].tso_segsz != 0) &&
4924                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4925                 fprintf(stderr, "Error: TSO is not supported by port %d\n",
4926                         res->port_id);
4927                 return;
4928         }
4929
4930         if (ports[res->port_id].tso_segsz == 0) {
4931                 ports[res->port_id].dev_conf.txmode.offloads &=
4932                                                 ~RTE_ETH_TX_OFFLOAD_TCP_TSO;
4933                 printf("TSO for non-tunneled packets is disabled\n");
4934         } else {
4935                 ports[res->port_id].dev_conf.txmode.offloads |=
4936                                                 RTE_ETH_TX_OFFLOAD_TCP_TSO;
4937                 printf("TSO segment size for non-tunneled packets is %d\n",
4938                         ports[res->port_id].tso_segsz);
4939         }
4940         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4941
4942         /* display warnings if configuration is not supported by the NIC */
4943         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4944         if (ret != 0)
4945                 return;
4946
4947         if ((ports[res->port_id].tso_segsz != 0) &&
4948                 (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) == 0) {
4949                 fprintf(stderr,
4950                         "Warning: TSO enabled but not supported by port %d\n",
4951                         res->port_id);
4952         }
4953
4954         cmd_reconfig_device_queue(res->port_id, 1, 1);
4955 }
4956
4957 cmdline_parse_token_string_t cmd_tso_set_tso =
4958         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4959                                 tso, "tso");
4960 cmdline_parse_token_string_t cmd_tso_set_mode =
4961         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4962                                 mode, "set");
4963 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4964         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4965                                 tso_segsz, RTE_UINT16);
4966 cmdline_parse_token_num_t cmd_tso_set_portid =
4967         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4968                                 port_id, RTE_UINT16);
4969
4970 cmdline_parse_inst_t cmd_tso_set = {
4971         .f = cmd_tso_set_parsed,
4972         .data = NULL,
4973         .help_str = "tso set <tso_segsz> <port_id>: "
4974                 "Set TSO segment size of non-tunneled packets for csum engine "
4975                 "(0 to disable)",
4976         .tokens = {
4977                 (void *)&cmd_tso_set_tso,
4978                 (void *)&cmd_tso_set_mode,
4979                 (void *)&cmd_tso_set_tso_segsz,
4980                 (void *)&cmd_tso_set_portid,
4981                 NULL,
4982         },
4983 };
4984
4985 cmdline_parse_token_string_t cmd_tso_show_mode =
4986         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4987                                 mode, "show");
4988
4989
4990 cmdline_parse_inst_t cmd_tso_show = {
4991         .f = cmd_tso_set_parsed,
4992         .data = NULL,
4993         .help_str = "tso show <port_id>: "
4994                 "Show TSO segment size of non-tunneled packets for csum engine",
4995         .tokens = {
4996                 (void *)&cmd_tso_set_tso,
4997                 (void *)&cmd_tso_show_mode,
4998                 (void *)&cmd_tso_set_portid,
4999                 NULL,
5000         },
5001 };
5002
5003 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5004 struct cmd_tunnel_tso_set_result {
5005         cmdline_fixed_string_t tso;
5006         cmdline_fixed_string_t mode;
5007         uint16_t tso_segsz;
5008         portid_t port_id;
5009 };
5010
5011 static struct rte_eth_dev_info
5012 check_tunnel_tso_nic_support(portid_t port_id)
5013 {
5014         struct rte_eth_dev_info dev_info;
5015
5016         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5017                 return dev_info;
5018
5019         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO))
5020                 fprintf(stderr,
5021                         "Warning: VXLAN TUNNEL TSO not supported therefore not enabled for port %d\n",
5022                         port_id);
5023         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
5024                 fprintf(stderr,
5025                         "Warning: GRE TUNNEL TSO not supported therefore not enabled for port %d\n",
5026                         port_id);
5027         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO))
5028                 fprintf(stderr,
5029                         "Warning: IPIP TUNNEL TSO not supported therefore not enabled for port %d\n",
5030                         port_id);
5031         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO))
5032                 fprintf(stderr,
5033                         "Warning: GENEVE TUNNEL TSO not supported therefore not enabled for port %d\n",
5034                         port_id);
5035         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IP_TNL_TSO))
5036                 fprintf(stderr,
5037                         "Warning: IP TUNNEL TSO not supported therefore not enabled for port %d\n",
5038                         port_id);
5039         if (!(dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO))
5040                 fprintf(stderr,
5041                         "Warning: UDP TUNNEL TSO not supported therefore not enabled for port %d\n",
5042                         port_id);
5043         return dev_info;
5044 }
5045
5046 static void
5047 cmd_tunnel_tso_set_parsed(void *parsed_result,
5048                           __rte_unused struct cmdline *cl,
5049                           __rte_unused void *data)
5050 {
5051         struct cmd_tunnel_tso_set_result *res = parsed_result;
5052         struct rte_eth_dev_info dev_info;
5053
5054         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5055                 return;
5056         if (!port_is_stopped(res->port_id)) {
5057                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
5058                 return;
5059         }
5060
5061         if (!strcmp(res->mode, "set"))
5062                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5063
5064         dev_info = check_tunnel_tso_nic_support(res->port_id);
5065         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5066                 ports[res->port_id].dev_conf.txmode.offloads &=
5067                         ~(RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5068                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5069                           RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5070                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5071                           RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5072                           RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5073                 printf("TSO for tunneled packets is disabled\n");
5074         } else {
5075                 uint64_t tso_offloads = (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
5076                                          RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
5077                                          RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
5078                                          RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
5079                                          RTE_ETH_TX_OFFLOAD_IP_TNL_TSO |
5080                                          RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO);
5081
5082                 ports[res->port_id].dev_conf.txmode.offloads |=
5083                         (tso_offloads & dev_info.tx_offload_capa);
5084                 printf("TSO segment size for tunneled packets is %d\n",
5085                         ports[res->port_id].tunnel_tso_segsz);
5086
5087                 /* Below conditions are needed to make it work:
5088                  * (1) tunnel TSO is supported by the NIC;
5089                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5090                  * are recognized;
5091                  * (3) for tunneled pkts with outer L3 of IPv4,
5092                  * "csum set outer-ip" must be set to hw, because after tso,
5093                  * total_len of outer IP header is changed, and the checksum
5094                  * of outer IP header calculated by sw should be wrong; that
5095                  * is not necessary for IPv6 tunneled pkts because there's no
5096                  * checksum in IP header anymore.
5097                  */
5098
5099                 if (!ports[res->port_id].parse_tunnel)
5100                         fprintf(stderr,
5101                                 "Warning: csum parse_tunnel must be set so that tunneled packets are recognized\n");
5102                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5103                       RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5104                         fprintf(stderr,
5105                                 "Warning: csum set outer-ip must be set to hw if outer L3 is IPv4; not necessary for IPv6\n");
5106         }
5107
5108         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5109         cmd_reconfig_device_queue(res->port_id, 1, 1);
5110 }
5111
5112 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5113         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5114                                 tso, "tunnel_tso");
5115 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5116         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5117                                 mode, "set");
5118 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5119         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5120                                 tso_segsz, RTE_UINT16);
5121 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5122         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5123                                 port_id, RTE_UINT16);
5124
5125 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5126         .f = cmd_tunnel_tso_set_parsed,
5127         .data = NULL,
5128         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5129                 "Set TSO segment size of tunneled packets for csum engine "
5130                 "(0 to disable)",
5131         .tokens = {
5132                 (void *)&cmd_tunnel_tso_set_tso,
5133                 (void *)&cmd_tunnel_tso_set_mode,
5134                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5135                 (void *)&cmd_tunnel_tso_set_portid,
5136                 NULL,
5137         },
5138 };
5139
5140 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5141         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5142                                 mode, "show");
5143
5144
5145 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5146         .f = cmd_tunnel_tso_set_parsed,
5147         .data = NULL,
5148         .help_str = "tunnel_tso show <port_id> "
5149                 "Show TSO segment size of tunneled packets for csum engine",
5150         .tokens = {
5151                 (void *)&cmd_tunnel_tso_set_tso,
5152                 (void *)&cmd_tunnel_tso_show_mode,
5153                 (void *)&cmd_tunnel_tso_set_portid,
5154                 NULL,
5155         },
5156 };
5157
5158 #ifdef RTE_LIB_GRO
5159 /* *** SET GRO FOR A PORT *** */
5160 struct cmd_gro_enable_result {
5161         cmdline_fixed_string_t cmd_set;
5162         cmdline_fixed_string_t cmd_port;
5163         cmdline_fixed_string_t cmd_keyword;
5164         cmdline_fixed_string_t cmd_onoff;
5165         portid_t cmd_pid;
5166 };
5167
5168 static void
5169 cmd_gro_enable_parsed(void *parsed_result,
5170                 __rte_unused struct cmdline *cl,
5171                 __rte_unused void *data)
5172 {
5173         struct cmd_gro_enable_result *res;
5174
5175         res = parsed_result;
5176         if (!strcmp(res->cmd_keyword, "gro"))
5177                 setup_gro(res->cmd_onoff, res->cmd_pid);
5178 }
5179
5180 cmdline_parse_token_string_t cmd_gro_enable_set =
5181         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5182                         cmd_set, "set");
5183 cmdline_parse_token_string_t cmd_gro_enable_port =
5184         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5185                         cmd_keyword, "port");
5186 cmdline_parse_token_num_t cmd_gro_enable_pid =
5187         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5188                         cmd_pid, RTE_UINT16);
5189 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5190         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5191                         cmd_keyword, "gro");
5192 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5193         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5194                         cmd_onoff, "on#off");
5195
5196 cmdline_parse_inst_t cmd_gro_enable = {
5197         .f = cmd_gro_enable_parsed,
5198         .data = NULL,
5199         .help_str = "set port <port_id> gro on|off",
5200         .tokens = {
5201                 (void *)&cmd_gro_enable_set,
5202                 (void *)&cmd_gro_enable_port,
5203                 (void *)&cmd_gro_enable_pid,
5204                 (void *)&cmd_gro_enable_keyword,
5205                 (void *)&cmd_gro_enable_onoff,
5206                 NULL,
5207         },
5208 };
5209
5210 /* *** DISPLAY GRO CONFIGURATION *** */
5211 struct cmd_gro_show_result {
5212         cmdline_fixed_string_t cmd_show;
5213         cmdline_fixed_string_t cmd_port;
5214         cmdline_fixed_string_t cmd_keyword;
5215         portid_t cmd_pid;
5216 };
5217
5218 static void
5219 cmd_gro_show_parsed(void *parsed_result,
5220                 __rte_unused struct cmdline *cl,
5221                 __rte_unused void *data)
5222 {
5223         struct cmd_gro_show_result *res;
5224
5225         res = parsed_result;
5226         if (!strcmp(res->cmd_keyword, "gro"))
5227                 show_gro(res->cmd_pid);
5228 }
5229
5230 cmdline_parse_token_string_t cmd_gro_show_show =
5231         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5232                         cmd_show, "show");
5233 cmdline_parse_token_string_t cmd_gro_show_port =
5234         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5235                         cmd_port, "port");
5236 cmdline_parse_token_num_t cmd_gro_show_pid =
5237         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5238                         cmd_pid, RTE_UINT16);
5239 cmdline_parse_token_string_t cmd_gro_show_keyword =
5240         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5241                         cmd_keyword, "gro");
5242
5243 cmdline_parse_inst_t cmd_gro_show = {
5244         .f = cmd_gro_show_parsed,
5245         .data = NULL,
5246         .help_str = "show port <port_id> gro",
5247         .tokens = {
5248                 (void *)&cmd_gro_show_show,
5249                 (void *)&cmd_gro_show_port,
5250                 (void *)&cmd_gro_show_pid,
5251                 (void *)&cmd_gro_show_keyword,
5252                 NULL,
5253         },
5254 };
5255
5256 /* *** SET FLUSH CYCLES FOR GRO *** */
5257 struct cmd_gro_flush_result {
5258         cmdline_fixed_string_t cmd_set;
5259         cmdline_fixed_string_t cmd_keyword;
5260         cmdline_fixed_string_t cmd_flush;
5261         uint8_t cmd_cycles;
5262 };
5263
5264 static void
5265 cmd_gro_flush_parsed(void *parsed_result,
5266                 __rte_unused struct cmdline *cl,
5267                 __rte_unused void *data)
5268 {
5269         struct cmd_gro_flush_result *res;
5270
5271         res = parsed_result;
5272         if ((!strcmp(res->cmd_keyword, "gro")) &&
5273                         (!strcmp(res->cmd_flush, "flush")))
5274                 setup_gro_flush_cycles(res->cmd_cycles);
5275 }
5276
5277 cmdline_parse_token_string_t cmd_gro_flush_set =
5278         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5279                         cmd_set, "set");
5280 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5281         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5282                         cmd_keyword, "gro");
5283 cmdline_parse_token_string_t cmd_gro_flush_flush =
5284         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5285                         cmd_flush, "flush");
5286 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5287         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5288                         cmd_cycles, RTE_UINT8);
5289
5290 cmdline_parse_inst_t cmd_gro_flush = {
5291         .f = cmd_gro_flush_parsed,
5292         .data = NULL,
5293         .help_str = "set gro flush <cycles>",
5294         .tokens = {
5295                 (void *)&cmd_gro_flush_set,
5296                 (void *)&cmd_gro_flush_keyword,
5297                 (void *)&cmd_gro_flush_flush,
5298                 (void *)&cmd_gro_flush_cycles,
5299                 NULL,
5300         },
5301 };
5302 #endif /* RTE_LIB_GRO */
5303
5304 #ifdef RTE_LIB_GSO
5305 /* *** ENABLE/DISABLE GSO *** */
5306 struct cmd_gso_enable_result {
5307         cmdline_fixed_string_t cmd_set;
5308         cmdline_fixed_string_t cmd_port;
5309         cmdline_fixed_string_t cmd_keyword;
5310         cmdline_fixed_string_t cmd_mode;
5311         portid_t cmd_pid;
5312 };
5313
5314 static void
5315 cmd_gso_enable_parsed(void *parsed_result,
5316                 __rte_unused struct cmdline *cl,
5317                 __rte_unused void *data)
5318 {
5319         struct cmd_gso_enable_result *res;
5320
5321         res = parsed_result;
5322         if (!strcmp(res->cmd_keyword, "gso"))
5323                 setup_gso(res->cmd_mode, res->cmd_pid);
5324 }
5325
5326 cmdline_parse_token_string_t cmd_gso_enable_set =
5327         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5328                         cmd_set, "set");
5329 cmdline_parse_token_string_t cmd_gso_enable_port =
5330         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5331                         cmd_port, "port");
5332 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5333         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5334                         cmd_keyword, "gso");
5335 cmdline_parse_token_string_t cmd_gso_enable_mode =
5336         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5337                         cmd_mode, "on#off");
5338 cmdline_parse_token_num_t cmd_gso_enable_pid =
5339         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5340                         cmd_pid, RTE_UINT16);
5341
5342 cmdline_parse_inst_t cmd_gso_enable = {
5343         .f = cmd_gso_enable_parsed,
5344         .data = NULL,
5345         .help_str = "set port <port_id> gso on|off",
5346         .tokens = {
5347                 (void *)&cmd_gso_enable_set,
5348                 (void *)&cmd_gso_enable_port,
5349                 (void *)&cmd_gso_enable_pid,
5350                 (void *)&cmd_gso_enable_keyword,
5351                 (void *)&cmd_gso_enable_mode,
5352                 NULL,
5353         },
5354 };
5355
5356 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5357 struct cmd_gso_size_result {
5358         cmdline_fixed_string_t cmd_set;
5359         cmdline_fixed_string_t cmd_keyword;
5360         cmdline_fixed_string_t cmd_segsz;
5361         uint16_t cmd_size;
5362 };
5363
5364 static void
5365 cmd_gso_size_parsed(void *parsed_result,
5366                        __rte_unused struct cmdline *cl,
5367                        __rte_unused void *data)
5368 {
5369         struct cmd_gso_size_result *res = parsed_result;
5370
5371         if (test_done == 0) {
5372                 fprintf(stderr,
5373                         "Before setting GSO segsz, please first stop forwarding\n");
5374                 return;
5375         }
5376
5377         if (!strcmp(res->cmd_keyword, "gso") &&
5378                         !strcmp(res->cmd_segsz, "segsz")) {
5379                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5380                         fprintf(stderr,
5381                                 "gso_size should be larger than %zu. Please input a legal value\n",
5382                                 RTE_GSO_SEG_SIZE_MIN);
5383                 else
5384                         gso_max_segment_size = res->cmd_size;
5385         }
5386 }
5387
5388 cmdline_parse_token_string_t cmd_gso_size_set =
5389         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5390                                 cmd_set, "set");
5391 cmdline_parse_token_string_t cmd_gso_size_keyword =
5392         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5393                                 cmd_keyword, "gso");
5394 cmdline_parse_token_string_t cmd_gso_size_segsz =
5395         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5396                                 cmd_segsz, "segsz");
5397 cmdline_parse_token_num_t cmd_gso_size_size =
5398         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5399                                 cmd_size, RTE_UINT16);
5400
5401 cmdline_parse_inst_t cmd_gso_size = {
5402         .f = cmd_gso_size_parsed,
5403         .data = NULL,
5404         .help_str = "set gso segsz <length>",
5405         .tokens = {
5406                 (void *)&cmd_gso_size_set,
5407                 (void *)&cmd_gso_size_keyword,
5408                 (void *)&cmd_gso_size_segsz,
5409                 (void *)&cmd_gso_size_size,
5410                 NULL,
5411         },
5412 };
5413
5414 /* *** SHOW GSO CONFIGURATION *** */
5415 struct cmd_gso_show_result {
5416         cmdline_fixed_string_t cmd_show;
5417         cmdline_fixed_string_t cmd_port;
5418         cmdline_fixed_string_t cmd_keyword;
5419         portid_t cmd_pid;
5420 };
5421
5422 static void
5423 cmd_gso_show_parsed(void *parsed_result,
5424                        __rte_unused struct cmdline *cl,
5425                        __rte_unused void *data)
5426 {
5427         struct cmd_gso_show_result *res = parsed_result;
5428
5429         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5430                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
5431                 return;
5432         }
5433         if (!strcmp(res->cmd_keyword, "gso")) {
5434                 if (gso_ports[res->cmd_pid].enable) {
5435                         printf("Max GSO'd packet size: %uB\n"
5436                                         "Supported GSO types: TCP/IPv4, "
5437                                         "UDP/IPv4, VxLAN with inner "
5438                                         "TCP/IPv4 packet, GRE with inner "
5439                                         "TCP/IPv4 packet\n",
5440                                         gso_max_segment_size);
5441                 } else
5442                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5443         }
5444 }
5445
5446 cmdline_parse_token_string_t cmd_gso_show_show =
5447 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5448                 cmd_show, "show");
5449 cmdline_parse_token_string_t cmd_gso_show_port =
5450 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5451                 cmd_port, "port");
5452 cmdline_parse_token_string_t cmd_gso_show_keyword =
5453         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5454                                 cmd_keyword, "gso");
5455 cmdline_parse_token_num_t cmd_gso_show_pid =
5456         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5457                                 cmd_pid, RTE_UINT16);
5458
5459 cmdline_parse_inst_t cmd_gso_show = {
5460         .f = cmd_gso_show_parsed,
5461         .data = NULL,
5462         .help_str = "show port <port_id> gso",
5463         .tokens = {
5464                 (void *)&cmd_gso_show_show,
5465                 (void *)&cmd_gso_show_port,
5466                 (void *)&cmd_gso_show_pid,
5467                 (void *)&cmd_gso_show_keyword,
5468                 NULL,
5469         },
5470 };
5471 #endif /* RTE_LIB_GSO */
5472
5473 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5474 struct cmd_set_flush_rx {
5475         cmdline_fixed_string_t set;
5476         cmdline_fixed_string_t flush_rx;
5477         cmdline_fixed_string_t mode;
5478 };
5479
5480 static void
5481 cmd_set_flush_rx_parsed(void *parsed_result,
5482                 __rte_unused struct cmdline *cl,
5483                 __rte_unused void *data)
5484 {
5485         struct cmd_set_flush_rx *res = parsed_result;
5486
5487         if (num_procs > 1 && (strcmp(res->mode, "on") == 0)) {
5488                 printf("multi-process doesn't support to flush Rx queues.\n");
5489                 return;
5490         }
5491
5492         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5493 }
5494
5495 cmdline_parse_token_string_t cmd_setflushrx_set =
5496         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5497                         set, "set");
5498 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5499         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5500                         flush_rx, "flush_rx");
5501 cmdline_parse_token_string_t cmd_setflushrx_mode =
5502         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5503                         mode, "on#off");
5504
5505
5506 cmdline_parse_inst_t cmd_set_flush_rx = {
5507         .f = cmd_set_flush_rx_parsed,
5508         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5509         .data = NULL,
5510         .tokens = {
5511                 (void *)&cmd_setflushrx_set,
5512                 (void *)&cmd_setflushrx_flush_rx,
5513                 (void *)&cmd_setflushrx_mode,
5514                 NULL,
5515         },
5516 };
5517
5518 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5519 struct cmd_set_link_check {
5520         cmdline_fixed_string_t set;
5521         cmdline_fixed_string_t link_check;
5522         cmdline_fixed_string_t mode;
5523 };
5524
5525 static void
5526 cmd_set_link_check_parsed(void *parsed_result,
5527                 __rte_unused struct cmdline *cl,
5528                 __rte_unused void *data)
5529 {
5530         struct cmd_set_link_check *res = parsed_result;
5531         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5532 }
5533
5534 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5535         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5536                         set, "set");
5537 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5538         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5539                         link_check, "link_check");
5540 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5542                         mode, "on#off");
5543
5544
5545 cmdline_parse_inst_t cmd_set_link_check = {
5546         .f = cmd_set_link_check_parsed,
5547         .help_str = "set link_check on|off: Enable/Disable link status check "
5548                     "when starting/stopping a port",
5549         .data = NULL,
5550         .tokens = {
5551                 (void *)&cmd_setlinkcheck_set,
5552                 (void *)&cmd_setlinkcheck_link_check,
5553                 (void *)&cmd_setlinkcheck_mode,
5554                 NULL,
5555         },
5556 };
5557
5558 /* *** SET NIC BYPASS MODE *** */
5559 struct cmd_set_bypass_mode_result {
5560         cmdline_fixed_string_t set;
5561         cmdline_fixed_string_t bypass;
5562         cmdline_fixed_string_t mode;
5563         cmdline_fixed_string_t value;
5564         portid_t port_id;
5565 };
5566
5567 static void
5568 cmd_set_bypass_mode_parsed(void *parsed_result,
5569                 __rte_unused struct cmdline *cl,
5570                 __rte_unused void *data)
5571 {
5572         struct cmd_set_bypass_mode_result *res = parsed_result;
5573         portid_t port_id = res->port_id;
5574         int32_t rc = -EINVAL;
5575
5576 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5577         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5578
5579         if (!strcmp(res->value, "bypass"))
5580                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5581         else if (!strcmp(res->value, "isolate"))
5582                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5583         else
5584                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5585
5586         /* Set the bypass mode for the relevant port. */
5587         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5588 #endif
5589         if (rc != 0)
5590                 fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n",
5591                         port_id);
5592 }
5593
5594 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5595         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5596                         set, "set");
5597 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5598         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5599                         bypass, "bypass");
5600 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5601         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5602                         mode, "mode");
5603 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5604         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5605                         value, "normal#bypass#isolate");
5606 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5607         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5608                                 port_id, RTE_UINT16);
5609
5610 cmdline_parse_inst_t cmd_set_bypass_mode = {
5611         .f = cmd_set_bypass_mode_parsed,
5612         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5613                     "Set the NIC bypass mode for port_id",
5614         .data = NULL,
5615         .tokens = {
5616                 (void *)&cmd_setbypass_mode_set,
5617                 (void *)&cmd_setbypass_mode_bypass,
5618                 (void *)&cmd_setbypass_mode_mode,
5619                 (void *)&cmd_setbypass_mode_value,
5620                 (void *)&cmd_setbypass_mode_port,
5621                 NULL,
5622         },
5623 };
5624
5625 /* *** SET NIC BYPASS EVENT *** */
5626 struct cmd_set_bypass_event_result {
5627         cmdline_fixed_string_t set;
5628         cmdline_fixed_string_t bypass;
5629         cmdline_fixed_string_t event;
5630         cmdline_fixed_string_t event_value;
5631         cmdline_fixed_string_t mode;
5632         cmdline_fixed_string_t mode_value;
5633         portid_t port_id;
5634 };
5635
5636 static void
5637 cmd_set_bypass_event_parsed(void *parsed_result,
5638                 __rte_unused struct cmdline *cl,
5639                 __rte_unused void *data)
5640 {
5641         int32_t rc = -EINVAL;
5642         struct cmd_set_bypass_event_result *res = parsed_result;
5643         portid_t port_id = res->port_id;
5644
5645 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5646         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5647         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5648
5649         if (!strcmp(res->event_value, "timeout"))
5650                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5651         else if (!strcmp(res->event_value, "os_on"))
5652                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5653         else if (!strcmp(res->event_value, "os_off"))
5654                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5655         else if (!strcmp(res->event_value, "power_on"))
5656                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5657         else if (!strcmp(res->event_value, "power_off"))
5658                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5659         else
5660                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5661
5662         if (!strcmp(res->mode_value, "bypass"))
5663                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5664         else if (!strcmp(res->mode_value, "isolate"))
5665                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5666         else
5667                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5668
5669         /* Set the watchdog timeout. */
5670         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5671
5672                 rc = -EINVAL;
5673                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5674                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5675                                                            bypass_timeout);
5676                 }
5677                 if (rc != 0) {
5678                         fprintf(stderr,
5679                                 "Failed to set timeout value %u for port %d, errto code: %d.\n",
5680                                 bypass_timeout, port_id, rc);
5681                 }
5682         }
5683
5684         /* Set the bypass event to transition to bypass mode. */
5685         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5686                                               bypass_mode);
5687 #endif
5688
5689         if (rc != 0)
5690                 fprintf(stderr, "\t Failed to set bypass event for port = %d.\n",
5691                         port_id);
5692 }
5693
5694 cmdline_parse_token_string_t cmd_setbypass_event_set =
5695         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5696                         set, "set");
5697 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5698         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5699                         bypass, "bypass");
5700 cmdline_parse_token_string_t cmd_setbypass_event_event =
5701         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5702                         event, "event");
5703 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5704         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5705                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5706 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5707         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5708                         mode, "mode");
5709 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5710         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5711                         mode_value, "normal#bypass#isolate");
5712 cmdline_parse_token_num_t cmd_setbypass_event_port =
5713         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5714                                 port_id, RTE_UINT16);
5715
5716 cmdline_parse_inst_t cmd_set_bypass_event = {
5717         .f = cmd_set_bypass_event_parsed,
5718         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5719                 "power_off mode normal|bypass|isolate <port_id>: "
5720                 "Set the NIC bypass event mode for port_id",
5721         .data = NULL,
5722         .tokens = {
5723                 (void *)&cmd_setbypass_event_set,
5724                 (void *)&cmd_setbypass_event_bypass,
5725                 (void *)&cmd_setbypass_event_event,
5726                 (void *)&cmd_setbypass_event_event_value,
5727                 (void *)&cmd_setbypass_event_mode,
5728                 (void *)&cmd_setbypass_event_mode_value,
5729                 (void *)&cmd_setbypass_event_port,
5730                 NULL,
5731         },
5732 };
5733
5734
5735 /* *** SET NIC BYPASS TIMEOUT *** */
5736 struct cmd_set_bypass_timeout_result {
5737         cmdline_fixed_string_t set;
5738         cmdline_fixed_string_t bypass;
5739         cmdline_fixed_string_t timeout;
5740         cmdline_fixed_string_t value;
5741 };
5742
5743 static void
5744 cmd_set_bypass_timeout_parsed(void *parsed_result,
5745                 __rte_unused struct cmdline *cl,
5746                 __rte_unused void *data)
5747 {
5748         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5749
5750 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5751         if (!strcmp(res->value, "1.5"))
5752                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5753         else if (!strcmp(res->value, "2"))
5754                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5755         else if (!strcmp(res->value, "3"))
5756                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5757         else if (!strcmp(res->value, "4"))
5758                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5759         else if (!strcmp(res->value, "8"))
5760                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5761         else if (!strcmp(res->value, "16"))
5762                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5763         else if (!strcmp(res->value, "32"))
5764                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5765         else
5766                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5767 #endif
5768 }
5769
5770 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5771         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5772                         set, "set");
5773 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5774         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5775                         bypass, "bypass");
5776 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5777         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5778                         timeout, "timeout");
5779 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5780         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5781                         value, "0#1.5#2#3#4#8#16#32");
5782
5783 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5784         .f = cmd_set_bypass_timeout_parsed,
5785         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5786                 "Set the NIC bypass watchdog timeout in seconds",
5787         .data = NULL,
5788         .tokens = {
5789                 (void *)&cmd_setbypass_timeout_set,
5790                 (void *)&cmd_setbypass_timeout_bypass,
5791                 (void *)&cmd_setbypass_timeout_timeout,
5792                 (void *)&cmd_setbypass_timeout_value,
5793                 NULL,
5794         },
5795 };
5796
5797 /* *** SHOW NIC BYPASS MODE *** */
5798 struct cmd_show_bypass_config_result {
5799         cmdline_fixed_string_t show;
5800         cmdline_fixed_string_t bypass;
5801         cmdline_fixed_string_t config;
5802         portid_t port_id;
5803 };
5804
5805 static void
5806 cmd_show_bypass_config_parsed(void *parsed_result,
5807                 __rte_unused struct cmdline *cl,
5808                 __rte_unused void *data)
5809 {
5810         struct cmd_show_bypass_config_result *res = parsed_result;
5811         portid_t port_id = res->port_id;
5812         int rc = -EINVAL;
5813 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5814         uint32_t event_mode;
5815         uint32_t bypass_mode;
5816         uint32_t timeout = bypass_timeout;
5817         unsigned int i;
5818
5819         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5820                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5821         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5822                 {"UNKNOWN", "normal", "bypass", "isolate"};
5823         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5824                 "NONE",
5825                 "OS/board on",
5826                 "power supply on",
5827                 "OS/board off",
5828                 "power supply off",
5829                 "timeout"};
5830
5831         /* Display the bypass mode.*/
5832         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5833                 fprintf(stderr, "\tFailed to get bypass mode for port = %d\n",
5834                         port_id);
5835                 return;
5836         }
5837         else {
5838                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5839                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5840
5841                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5842         }
5843
5844         /* Display the bypass timeout.*/
5845         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5846                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5847
5848         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5849
5850         /* Display the bypass events and associated modes. */
5851         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5852
5853                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5854                         fprintf(stderr,
5855                                 "\tFailed to get bypass mode for event = %s\n",
5856                                 events[i]);
5857                 } else {
5858                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5859                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5860
5861                         printf("\tbypass event: %-16s = %s\n", events[i],
5862                                 modes[event_mode]);
5863                 }
5864         }
5865 #endif
5866         if (rc != 0)
5867                 fprintf(stderr,
5868                         "\tFailed to get bypass configuration for port = %d\n",
5869                        port_id);
5870 }
5871
5872 cmdline_parse_token_string_t cmd_showbypass_config_show =
5873         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5874                         show, "show");
5875 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5876         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5877                         bypass, "bypass");
5878 cmdline_parse_token_string_t cmd_showbypass_config_config =
5879         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5880                         config, "config");
5881 cmdline_parse_token_num_t cmd_showbypass_config_port =
5882         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5883                                 port_id, RTE_UINT16);
5884
5885 cmdline_parse_inst_t cmd_show_bypass_config = {
5886         .f = cmd_show_bypass_config_parsed,
5887         .help_str = "show bypass config <port_id>: "
5888                     "Show the NIC bypass config for port_id",
5889         .data = NULL,
5890         .tokens = {
5891                 (void *)&cmd_showbypass_config_show,
5892                 (void *)&cmd_showbypass_config_bypass,
5893                 (void *)&cmd_showbypass_config_config,
5894                 (void *)&cmd_showbypass_config_port,
5895                 NULL,
5896         },
5897 };
5898
5899 #ifdef RTE_NET_BOND
5900 /* *** SET BONDING MODE *** */
5901 struct cmd_set_bonding_mode_result {
5902         cmdline_fixed_string_t set;
5903         cmdline_fixed_string_t bonding;
5904         cmdline_fixed_string_t mode;
5905         uint8_t value;
5906         portid_t port_id;
5907 };
5908
5909 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5910                 __rte_unused  struct cmdline *cl,
5911                 __rte_unused void *data)
5912 {
5913         struct cmd_set_bonding_mode_result *res = parsed_result;
5914         portid_t port_id = res->port_id;
5915
5916         /* Set the bonding mode for the relevant port. */
5917         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5918                 fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
5919                         port_id);
5920 }
5921
5922 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5923 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5924                 set, "set");
5925 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5926 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5927                 bonding, "bonding");
5928 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5929 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5930                 mode, "mode");
5931 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5932 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5933                 value, RTE_UINT8);
5934 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5935 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5936                 port_id, RTE_UINT16);
5937
5938 cmdline_parse_inst_t cmd_set_bonding_mode = {
5939                 .f = cmd_set_bonding_mode_parsed,
5940                 .help_str = "set bonding mode <mode_value> <port_id>: "
5941                         "Set the bonding mode for port_id",
5942                 .data = NULL,
5943                 .tokens = {
5944                                 (void *) &cmd_setbonding_mode_set,
5945                                 (void *) &cmd_setbonding_mode_bonding,
5946                                 (void *) &cmd_setbonding_mode_mode,
5947                                 (void *) &cmd_setbonding_mode_value,
5948                                 (void *) &cmd_setbonding_mode_port,
5949                                 NULL
5950                 }
5951 };
5952
5953 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5954 struct cmd_set_bonding_lacp_dedicated_queues_result {
5955         cmdline_fixed_string_t set;
5956         cmdline_fixed_string_t bonding;
5957         cmdline_fixed_string_t lacp;
5958         cmdline_fixed_string_t dedicated_queues;
5959         portid_t port_id;
5960         cmdline_fixed_string_t mode;
5961 };
5962
5963 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5964                 __rte_unused  struct cmdline *cl,
5965                 __rte_unused void *data)
5966 {
5967         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5968         portid_t port_id = res->port_id;
5969         struct rte_port *port;
5970
5971         port = &ports[port_id];
5972
5973         /** Check if the port is not started **/
5974         if (port->port_status != RTE_PORT_STOPPED) {
5975                 fprintf(stderr, "Please stop port %d first\n", port_id);
5976                 return;
5977         }
5978
5979         if (!strcmp(res->mode, "enable")) {
5980                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5981                         printf("Dedicate queues for LACP control packets"
5982                                         " enabled\n");
5983                 else
5984                         printf("Enabling dedicate queues for LACP control "
5985                                         "packets on port %d failed\n", port_id);
5986         } else if (!strcmp(res->mode, "disable")) {
5987                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5988                         printf("Dedicated queues for LACP control packets "
5989                                         "disabled\n");
5990                 else
5991                         printf("Disabling dedicated queues for LACP control "
5992                                         "traffic on port %d failed\n", port_id);
5993         }
5994 }
5995
5996 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5997 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5998                 set, "set");
5999 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6000 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6001                 bonding, "bonding");
6002 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6003 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6004                 lacp, "lacp");
6005 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6006 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6007                 dedicated_queues, "dedicated_queues");
6008 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6009 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6010                 port_id, RTE_UINT16);
6011 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6012 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6013                 mode, "enable#disable");
6014
6015 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6016                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6017                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6018                         "enable|disable: "
6019                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6020                 .data = NULL,
6021                 .tokens = {
6022                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6023                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6024                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6025                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6026                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6027                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6028                         NULL
6029                 }
6030 };
6031
6032 /* *** SET BALANCE XMIT POLICY *** */
6033 struct cmd_set_bonding_balance_xmit_policy_result {
6034         cmdline_fixed_string_t set;
6035         cmdline_fixed_string_t bonding;
6036         cmdline_fixed_string_t balance_xmit_policy;
6037         portid_t port_id;
6038         cmdline_fixed_string_t policy;
6039 };
6040
6041 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6042                 __rte_unused  struct cmdline *cl,
6043                 __rte_unused void *data)
6044 {
6045         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6046         portid_t port_id = res->port_id;
6047         uint8_t policy;
6048
6049         if (!strcmp(res->policy, "l2")) {
6050                 policy = BALANCE_XMIT_POLICY_LAYER2;
6051         } else if (!strcmp(res->policy, "l23")) {
6052                 policy = BALANCE_XMIT_POLICY_LAYER23;
6053         } else if (!strcmp(res->policy, "l34")) {
6054                 policy = BALANCE_XMIT_POLICY_LAYER34;
6055         } else {
6056                 fprintf(stderr, "\t Invalid xmit policy selection");
6057                 return;
6058         }
6059
6060         /* Set the bonding mode for the relevant port. */
6061         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6062                 fprintf(stderr,
6063                         "\t Failed to set bonding balance xmit policy for port = %d.\n",
6064                         port_id);
6065         }
6066 }
6067
6068 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6069 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6070                 set, "set");
6071 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6072 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6073                 bonding, "bonding");
6074 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6075 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6076                 balance_xmit_policy, "balance_xmit_policy");
6077 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6078 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6079                 port_id, RTE_UINT16);
6080 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6081 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6082                 policy, "l2#l23#l34");
6083
6084 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6085                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6086                 .help_str = "set bonding balance_xmit_policy <port_id> "
6087                         "l2|l23|l34: "
6088                         "Set the bonding balance_xmit_policy for port_id",
6089                 .data = NULL,
6090                 .tokens = {
6091                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6092                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6093                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6094                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6095                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6096                                 NULL
6097                 }
6098 };
6099
6100 /* *** SHOW IEEE802.3 BONDING INFORMATION *** */
6101 struct cmd_show_bonding_lacp_info_result {
6102         cmdline_fixed_string_t show;
6103         cmdline_fixed_string_t bonding;
6104         cmdline_fixed_string_t lacp;
6105         cmdline_fixed_string_t info;
6106         portid_t port_id;
6107 };
6108
6109 static void port_param_show(struct port_params *params)
6110 {
6111         char buf[RTE_ETHER_ADDR_FMT_SIZE];
6112
6113         printf("\t\tsystem priority: %u\n", params->system_priority);
6114         rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &params->system);
6115         printf("\t\tsystem mac address: %s\n", buf);
6116         printf("\t\tport key: %u\n", params->key);
6117         printf("\t\tport priority: %u\n", params->port_priority);
6118         printf("\t\tport number: %u\n", params->port_number);
6119 }
6120
6121 static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info)
6122 {
6123         char a_state[256] = { 0 };
6124         char p_state[256] = { 0 };
6125         int a_len = 0;
6126         int p_len = 0;
6127         uint32_t i;
6128
6129         static const char * const state[] = {
6130                 "ACTIVE",
6131                 "TIMEOUT",
6132                 "AGGREGATION",
6133                 "SYNCHRONIZATION",
6134                 "COLLECTING",
6135                 "DISTRIBUTING",
6136                 "DEFAULTED",
6137                 "EXPIRED"
6138         };
6139         static const char * const selection[] = {
6140                 "UNSELECTED",
6141                 "STANDBY",
6142                 "SELECTED"
6143         };
6144
6145         for (i = 0; i < RTE_DIM(state); i++) {
6146                 if ((info->actor_state >> i) & 1)
6147                         a_len += snprintf(&a_state[a_len],
6148                                                 RTE_DIM(a_state) - a_len, "%s ",
6149                                                 state[i]);
6150
6151                 if ((info->partner_state >> i) & 1)
6152                         p_len += snprintf(&p_state[p_len],
6153                                                 RTE_DIM(p_state) - p_len, "%s ",
6154                                                 state[i]);
6155         }
6156         printf("\tAggregator port id: %u\n", info->agg_port_id);
6157         printf("\tselection: %s\n", selection[info->selected]);
6158         printf("\tActor detail info:\n");
6159         port_param_show(&info->actor);
6160         printf("\t\tport state: %s\n", a_state);
6161         printf("\tPartner detail info:\n");
6162         port_param_show(&info->partner);
6163         printf("\t\tport state: %s\n", p_state);
6164         printf("\n");
6165 }
6166
6167 static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf)
6168 {
6169         printf("\tfast period: %u ms\n", conf->fast_periodic_ms);
6170         printf("\tslow period: %u ms\n", conf->slow_periodic_ms);
6171         printf("\tshort timeout: %u ms\n", conf->short_timeout_ms);
6172         printf("\tlong timeout: %u ms\n", conf->long_timeout_ms);
6173         printf("\taggregate wait timeout: %u ms\n",
6174                         conf->aggregate_wait_timeout_ms);
6175         printf("\ttx period: %u ms\n", conf->tx_period_ms);
6176         printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms);
6177         printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms);
6178         switch (conf->agg_selection) {
6179         case AGG_BANDWIDTH:
6180                 printf("\taggregation mode: bandwidth\n");
6181                 break;
6182         case AGG_STABLE:
6183                 printf("\taggregation mode: stable\n");
6184                 break;
6185         case AGG_COUNT:
6186                 printf("\taggregation mode: count\n");
6187                 break;
6188         default:
6189                 printf("\taggregation mode: invalid\n");
6190                 break;
6191         }
6192
6193         printf("\n");
6194 }
6195
6196 static void cmd_show_bonding_lacp_info_parsed(void *parsed_result,
6197                 __rte_unused  struct cmdline *cl,
6198                 __rte_unused void *data)
6199 {
6200         struct cmd_show_bonding_lacp_info_result *res = parsed_result;
6201         struct rte_eth_bond_8023ad_slave_info slave_info;
6202         struct rte_eth_bond_8023ad_conf port_conf;
6203         portid_t slaves[RTE_MAX_ETHPORTS];
6204         portid_t port_id = res->port_id;
6205         int num_active_slaves;
6206         int bonding_mode;
6207         int i;
6208         int ret;
6209
6210         bonding_mode = rte_eth_bond_mode_get(port_id);
6211         if (bonding_mode != BONDING_MODE_8023AD) {
6212                 fprintf(stderr, "\tBonding mode is not mode 4\n");
6213                 return;
6214         }
6215
6216         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6217                         RTE_MAX_ETHPORTS);
6218         if (num_active_slaves < 0) {
6219                 fprintf(stderr, "\tFailed to get active slave list for port = %u\n",
6220                                 port_id);
6221                 return;
6222         }
6223         if (num_active_slaves == 0)
6224                 fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n",
6225                         port_id);
6226
6227         printf("\tIEEE802.3 port: %u\n", port_id);
6228         ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf);
6229         if (ret) {
6230                 fprintf(stderr, "\tGet bonded device %u info failed\n",
6231                         port_id);
6232                 return;
6233         }
6234         lacp_conf_show(&port_conf);
6235
6236         for (i = 0; i < num_active_slaves; i++) {
6237                 ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i],
6238                                 &slave_info);
6239                 if (ret) {
6240                         fprintf(stderr, "\tGet slave device %u info failed\n",
6241                                 slaves[i]);
6242                         return;
6243                 }
6244                 printf("\tSlave Port: %u\n", slaves[i]);
6245                 lacp_slave_info_show(&slave_info);
6246         }
6247 }
6248
6249 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show =
6250 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6251                 show, "show");
6252 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding =
6253 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6254                 bonding, "bonding");
6255 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp =
6256 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6257                 bonding, "lacp");
6258 cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info =
6259 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6260                 info, "info");
6261 cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id =
6262 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result,
6263                 port_id, RTE_UINT16);
6264
6265 cmdline_parse_inst_t cmd_show_bonding_lacp_info = {
6266                 .f = cmd_show_bonding_lacp_info_parsed,
6267                 .help_str = "show bonding lacp info <port_id> : "
6268                         "Show bonding IEEE802.3 information for port_id",
6269                 .data = NULL,
6270                 .tokens = {
6271                         (void *)&cmd_show_bonding_lacp_info_show,
6272                         (void *)&cmd_show_bonding_lacp_info_bonding,
6273                         (void *)&cmd_show_bonding_lacp_info_lacp,
6274                         (void *)&cmd_show_bonding_lacp_info_info,
6275                         (void *)&cmd_show_bonding_lacp_info_port_id,
6276                         NULL
6277                 }
6278 };
6279
6280 /* *** SHOW NIC BONDING CONFIGURATION *** */
6281 struct cmd_show_bonding_config_result {
6282         cmdline_fixed_string_t show;
6283         cmdline_fixed_string_t bonding;
6284         cmdline_fixed_string_t config;
6285         portid_t port_id;
6286 };
6287
6288 static void cmd_show_bonding_config_parsed(void *parsed_result,
6289                 __rte_unused  struct cmdline *cl,
6290                 __rte_unused void *data)
6291 {
6292         struct cmd_show_bonding_config_result *res = parsed_result;
6293         int bonding_mode, agg_mode;
6294         portid_t slaves[RTE_MAX_ETHPORTS];
6295         int num_slaves, num_active_slaves;
6296         int primary_id;
6297         int i;
6298         portid_t port_id = res->port_id;
6299
6300         /* Display the bonding mode.*/
6301         bonding_mode = rte_eth_bond_mode_get(port_id);
6302         if (bonding_mode < 0) {
6303                 fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
6304                         port_id);
6305                 return;
6306         } else
6307                 printf("\tBonding mode: %d\n", bonding_mode);
6308
6309         if (bonding_mode == BONDING_MODE_BALANCE ||
6310                 bonding_mode == BONDING_MODE_8023AD) {
6311                 int balance_xmit_policy;
6312
6313                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6314                 if (balance_xmit_policy < 0) {
6315                         fprintf(stderr,
6316                                 "\tFailed to get balance xmit policy for port = %d\n",
6317                                 port_id);
6318                         return;
6319                 } else {
6320                         printf("\tBalance Xmit Policy: ");
6321
6322                         switch (balance_xmit_policy) {
6323                         case BALANCE_XMIT_POLICY_LAYER2:
6324                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6325                                 break;
6326                         case BALANCE_XMIT_POLICY_LAYER23:
6327                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6328                                 break;
6329                         case BALANCE_XMIT_POLICY_LAYER34:
6330                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6331                                 break;
6332                         }
6333                         printf("\n");
6334                 }
6335         }
6336
6337         if (bonding_mode == BONDING_MODE_8023AD) {
6338                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6339                 printf("\tIEEE802.3AD Aggregator Mode: ");
6340                 switch (agg_mode) {
6341                 case AGG_BANDWIDTH:
6342                         printf("bandwidth");
6343                         break;
6344                 case AGG_STABLE:
6345                         printf("stable");
6346                         break;
6347                 case AGG_COUNT:
6348                         printf("count");
6349                         break;
6350                 }
6351                 printf("\n");
6352         }
6353
6354         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6355
6356         if (num_slaves < 0) {
6357                 fprintf(stderr, "\tFailed to get slave list for port = %d\n",
6358                         port_id);
6359                 return;
6360         }
6361         if (num_slaves > 0) {
6362                 printf("\tSlaves (%d): [", num_slaves);
6363                 for (i = 0; i < num_slaves - 1; i++)
6364                         printf("%d ", slaves[i]);
6365
6366                 printf("%d]\n", slaves[num_slaves - 1]);
6367         } else {
6368                 printf("\tSlaves: []\n");
6369
6370         }
6371
6372         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6373                         RTE_MAX_ETHPORTS);
6374
6375         if (num_active_slaves < 0) {
6376                 fprintf(stderr,
6377                         "\tFailed to get active slave list for port = %d\n",
6378                         port_id);
6379                 return;
6380         }
6381         if (num_active_slaves > 0) {
6382                 printf("\tActive Slaves (%d): [", num_active_slaves);
6383                 for (i = 0; i < num_active_slaves - 1; i++)
6384                         printf("%d ", slaves[i]);
6385
6386                 printf("%d]\n", slaves[num_active_slaves - 1]);
6387
6388         } else {
6389                 printf("\tActive Slaves: []\n");
6390
6391         }
6392
6393         primary_id = rte_eth_bond_primary_get(port_id);
6394         if (primary_id < 0) {
6395                 fprintf(stderr, "\tFailed to get primary slave for port = %d\n",
6396                         port_id);
6397                 return;
6398         } else
6399                 printf("\tPrimary: [%d]\n", primary_id);
6400
6401 }
6402
6403 cmdline_parse_token_string_t cmd_showbonding_config_show =
6404 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6405                 show, "show");
6406 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6407 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6408                 bonding, "bonding");
6409 cmdline_parse_token_string_t cmd_showbonding_config_config =
6410 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6411                 config, "config");
6412 cmdline_parse_token_num_t cmd_showbonding_config_port =
6413 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6414                 port_id, RTE_UINT16);
6415
6416 cmdline_parse_inst_t cmd_show_bonding_config = {
6417                 .f = cmd_show_bonding_config_parsed,
6418                 .help_str = "show bonding config <port_id>: "
6419                         "Show the bonding config for port_id",
6420                 .data = NULL,
6421                 .tokens = {
6422                                 (void *)&cmd_showbonding_config_show,
6423                                 (void *)&cmd_showbonding_config_bonding,
6424                                 (void *)&cmd_showbonding_config_config,
6425                                 (void *)&cmd_showbonding_config_port,
6426                                 NULL
6427                 }
6428 };
6429
6430 /* *** SET BONDING PRIMARY *** */
6431 struct cmd_set_bonding_primary_result {
6432         cmdline_fixed_string_t set;
6433         cmdline_fixed_string_t bonding;
6434         cmdline_fixed_string_t primary;
6435         portid_t slave_id;
6436         portid_t port_id;
6437 };
6438
6439 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6440                 __rte_unused  struct cmdline *cl,
6441                 __rte_unused void *data)
6442 {
6443         struct cmd_set_bonding_primary_result *res = parsed_result;
6444         portid_t master_port_id = res->port_id;
6445         portid_t slave_port_id = res->slave_id;
6446
6447         /* Set the primary slave for a bonded device. */
6448         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6449                 fprintf(stderr, "\t Failed to set primary slave for port = %d.\n",
6450                         master_port_id);
6451                 return;
6452         }
6453         init_port_config();
6454 }
6455
6456 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6457 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6458                 set, "set");
6459 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6460 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6461                 bonding, "bonding");
6462 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6463 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6464                 primary, "primary");
6465 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6466 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6467                 slave_id, RTE_UINT16);
6468 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6469 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6470                 port_id, RTE_UINT16);
6471
6472 cmdline_parse_inst_t cmd_set_bonding_primary = {
6473                 .f = cmd_set_bonding_primary_parsed,
6474                 .help_str = "set bonding primary <slave_id> <port_id>: "
6475                         "Set the primary slave for port_id",
6476                 .data = NULL,
6477                 .tokens = {
6478                                 (void *)&cmd_setbonding_primary_set,
6479                                 (void *)&cmd_setbonding_primary_bonding,
6480                                 (void *)&cmd_setbonding_primary_primary,
6481                                 (void *)&cmd_setbonding_primary_slave,
6482                                 (void *)&cmd_setbonding_primary_port,
6483                                 NULL
6484                 }
6485 };
6486
6487 /* *** ADD SLAVE *** */
6488 struct cmd_add_bonding_slave_result {
6489         cmdline_fixed_string_t add;
6490         cmdline_fixed_string_t bonding;
6491         cmdline_fixed_string_t slave;
6492         portid_t slave_id;
6493         portid_t port_id;
6494 };
6495
6496 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6497                 __rte_unused  struct cmdline *cl,
6498                 __rte_unused void *data)
6499 {
6500         struct cmd_add_bonding_slave_result *res = parsed_result;
6501         portid_t master_port_id = res->port_id;
6502         portid_t slave_port_id = res->slave_id;
6503
6504         /* add the slave for a bonded device. */
6505         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6506                 fprintf(stderr,
6507                         "\t Failed to add slave %d to master port = %d.\n",
6508                         slave_port_id, master_port_id);
6509                 return;
6510         }
6511         init_port_config();
6512         set_port_slave_flag(slave_port_id);
6513 }
6514
6515 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6516 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6517                 add, "add");
6518 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6519 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6520                 bonding, "bonding");
6521 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6522 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6523                 slave, "slave");
6524 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6525 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6526                 slave_id, RTE_UINT16);
6527 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6528 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6529                 port_id, RTE_UINT16);
6530
6531 cmdline_parse_inst_t cmd_add_bonding_slave = {
6532                 .f = cmd_add_bonding_slave_parsed,
6533                 .help_str = "add bonding slave <slave_id> <port_id>: "
6534                         "Add a slave device to a bonded device",
6535                 .data = NULL,
6536                 .tokens = {
6537                                 (void *)&cmd_addbonding_slave_add,
6538                                 (void *)&cmd_addbonding_slave_bonding,
6539                                 (void *)&cmd_addbonding_slave_slave,
6540                                 (void *)&cmd_addbonding_slave_slaveid,
6541                                 (void *)&cmd_addbonding_slave_port,
6542                                 NULL
6543                 }
6544 };
6545
6546 /* *** REMOVE SLAVE *** */
6547 struct cmd_remove_bonding_slave_result {
6548         cmdline_fixed_string_t remove;
6549         cmdline_fixed_string_t bonding;
6550         cmdline_fixed_string_t slave;
6551         portid_t slave_id;
6552         portid_t port_id;
6553 };
6554
6555 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6556                 __rte_unused  struct cmdline *cl,
6557                 __rte_unused void *data)
6558 {
6559         struct cmd_remove_bonding_slave_result *res = parsed_result;
6560         portid_t master_port_id = res->port_id;
6561         portid_t slave_port_id = res->slave_id;
6562
6563         /* remove the slave from a bonded device. */
6564         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6565                 fprintf(stderr,
6566                         "\t Failed to remove slave %d from master port = %d.\n",
6567                         slave_port_id, master_port_id);
6568                 return;
6569         }
6570         init_port_config();
6571         clear_port_slave_flag(slave_port_id);
6572 }
6573
6574 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6575                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6576                                 remove, "remove");
6577 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6578                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6579                                 bonding, "bonding");
6580 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6581                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6582                                 slave, "slave");
6583 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6584                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6585                                 slave_id, RTE_UINT16);
6586 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6587                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6588                                 port_id, RTE_UINT16);
6589
6590 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6591                 .f = cmd_remove_bonding_slave_parsed,
6592                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6593                         "Remove a slave device from a bonded device",
6594                 .data = NULL,
6595                 .tokens = {
6596                                 (void *)&cmd_removebonding_slave_remove,
6597                                 (void *)&cmd_removebonding_slave_bonding,
6598                                 (void *)&cmd_removebonding_slave_slave,
6599                                 (void *)&cmd_removebonding_slave_slaveid,
6600                                 (void *)&cmd_removebonding_slave_port,
6601                                 NULL
6602                 }
6603 };
6604
6605 /* *** CREATE BONDED DEVICE *** */
6606 struct cmd_create_bonded_device_result {
6607         cmdline_fixed_string_t create;
6608         cmdline_fixed_string_t bonded;
6609         cmdline_fixed_string_t device;
6610         uint8_t mode;
6611         uint8_t socket;
6612 };
6613
6614 static int bond_dev_num = 0;
6615
6616 static void cmd_create_bonded_device_parsed(void *parsed_result,
6617                 __rte_unused  struct cmdline *cl,
6618                 __rte_unused void *data)
6619 {
6620         struct cmd_create_bonded_device_result *res = parsed_result;
6621         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6622         int port_id;
6623         int ret;
6624
6625         if (test_done == 0) {
6626                 fprintf(stderr, "Please stop forwarding first\n");
6627                 return;
6628         }
6629
6630         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6631                         bond_dev_num++);
6632
6633         /* Create a new bonded device. */
6634         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6635         if (port_id < 0) {
6636                 fprintf(stderr, "\t Failed to create bonded device.\n");
6637                 return;
6638         } else {
6639                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6640                                 port_id);
6641
6642                 /* Update number of ports */
6643                 nb_ports = rte_eth_dev_count_avail();
6644                 reconfig(port_id, res->socket);
6645                 ret = rte_eth_promiscuous_enable(port_id);
6646                 if (ret != 0)
6647                         fprintf(stderr,
6648                                 "Failed to enable promiscuous mode for port %u: %s - ignore\n",
6649                                 port_id, rte_strerror(-ret));
6650
6651                 ports[port_id].need_setup = 0;
6652                 ports[port_id].port_status = RTE_PORT_STOPPED;
6653         }
6654
6655 }
6656
6657 cmdline_parse_token_string_t cmd_createbonded_device_create =
6658                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6659                                 create, "create");
6660 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6661                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6662                                 bonded, "bonded");
6663 cmdline_parse_token_string_t cmd_createbonded_device_device =
6664                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6665                                 device, "device");
6666 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6667                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6668                                 mode, RTE_UINT8);
6669 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6670                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6671                                 socket, RTE_UINT8);
6672
6673 cmdline_parse_inst_t cmd_create_bonded_device = {
6674                 .f = cmd_create_bonded_device_parsed,
6675                 .help_str = "create bonded device <mode> <socket>: "
6676                         "Create a new bonded device with specific bonding mode and socket",
6677                 .data = NULL,
6678                 .tokens = {
6679                                 (void *)&cmd_createbonded_device_create,
6680                                 (void *)&cmd_createbonded_device_bonded,
6681                                 (void *)&cmd_createbonded_device_device,
6682                                 (void *)&cmd_createbonded_device_mode,
6683                                 (void *)&cmd_createbonded_device_socket,
6684                                 NULL
6685                 }
6686 };
6687
6688 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6689 struct cmd_set_bond_mac_addr_result {
6690         cmdline_fixed_string_t set;
6691         cmdline_fixed_string_t bonding;
6692         cmdline_fixed_string_t mac_addr;
6693         uint16_t port_num;
6694         struct rte_ether_addr address;
6695 };
6696
6697 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6698                 __rte_unused  struct cmdline *cl,
6699                 __rte_unused void *data)
6700 {
6701         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6702         int ret;
6703
6704         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6705                 return;
6706
6707         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6708
6709         /* check the return value and print it if is < 0 */
6710         if (ret < 0)
6711                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6712                         strerror(-ret));
6713 }
6714
6715 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6716                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6717 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6718                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6719                                 "bonding");
6720 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6721                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6722                                 "mac_addr");
6723 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6724                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6725                                 port_num, RTE_UINT16);
6726 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6727                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6728
6729 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6730                 .f = cmd_set_bond_mac_addr_parsed,
6731                 .data = (void *) 0,
6732                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6733                 .tokens = {
6734                                 (void *)&cmd_set_bond_mac_addr_set,
6735                                 (void *)&cmd_set_bond_mac_addr_bonding,
6736                                 (void *)&cmd_set_bond_mac_addr_mac,
6737                                 (void *)&cmd_set_bond_mac_addr_portnum,
6738                                 (void *)&cmd_set_bond_mac_addr_addr,
6739                                 NULL
6740                 }
6741 };
6742
6743
6744 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6745 struct cmd_set_bond_mon_period_result {
6746         cmdline_fixed_string_t set;
6747         cmdline_fixed_string_t bonding;
6748         cmdline_fixed_string_t mon_period;
6749         uint16_t port_num;
6750         uint32_t period_ms;
6751 };
6752
6753 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6754                 __rte_unused  struct cmdline *cl,
6755                 __rte_unused void *data)
6756 {
6757         struct cmd_set_bond_mon_period_result *res = parsed_result;
6758         int ret;
6759
6760         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6761
6762         /* check the return value and print it if is < 0 */
6763         if (ret < 0)
6764                 fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
6765                         strerror(-ret));
6766 }
6767
6768 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6769                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6770                                 set, "set");
6771 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6772                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6773                                 bonding, "bonding");
6774 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6775                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6776                                 mon_period,     "mon_period");
6777 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6778                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6779                                 port_num, RTE_UINT16);
6780 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6781                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6782                                 period_ms, RTE_UINT32);
6783
6784 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6785                 .f = cmd_set_bond_mon_period_parsed,
6786                 .data = (void *) 0,
6787                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6788                 .tokens = {
6789                                 (void *)&cmd_set_bond_mon_period_set,
6790                                 (void *)&cmd_set_bond_mon_period_bonding,
6791                                 (void *)&cmd_set_bond_mon_period_mon_period,
6792                                 (void *)&cmd_set_bond_mon_period_portnum,
6793                                 (void *)&cmd_set_bond_mon_period_period_ms,
6794                                 NULL
6795                 }
6796 };
6797
6798
6799
6800 struct cmd_set_bonding_agg_mode_policy_result {
6801         cmdline_fixed_string_t set;
6802         cmdline_fixed_string_t bonding;
6803         cmdline_fixed_string_t agg_mode;
6804         uint16_t port_num;
6805         cmdline_fixed_string_t policy;
6806 };
6807
6808
6809 static void
6810 cmd_set_bonding_agg_mode(void *parsed_result,
6811                 __rte_unused struct cmdline *cl,
6812                 __rte_unused void *data)
6813 {
6814         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6815         uint8_t policy = AGG_BANDWIDTH;
6816
6817         if (!strcmp(res->policy, "bandwidth"))
6818                 policy = AGG_BANDWIDTH;
6819         else if (!strcmp(res->policy, "stable"))
6820                 policy = AGG_STABLE;
6821         else if (!strcmp(res->policy, "count"))
6822                 policy = AGG_COUNT;
6823
6824         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6825 }
6826
6827
6828 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6829         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6830                                 set, "set");
6831 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6832         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6833                                 bonding, "bonding");
6834
6835 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6836         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6837                                 agg_mode, "agg_mode");
6838
6839 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6840         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6841                                 port_num, RTE_UINT16);
6842
6843 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6844         TOKEN_STRING_INITIALIZER(
6845                         struct cmd_set_bonding_balance_xmit_policy_result,
6846                 policy, "stable#bandwidth#count");
6847
6848 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6849         .f = cmd_set_bonding_agg_mode,
6850         .data = (void *) 0,
6851         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6852         .tokens = {
6853                         (void *)&cmd_set_bonding_agg_mode_set,
6854                         (void *)&cmd_set_bonding_agg_mode_bonding,
6855                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6856                         (void *)&cmd_set_bonding_agg_mode_portnum,
6857                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6858                         NULL
6859                 }
6860 };
6861
6862
6863 #endif /* RTE_NET_BOND */
6864
6865 /* *** SET FORWARDING MODE *** */
6866 struct cmd_set_fwd_mode_result {
6867         cmdline_fixed_string_t set;
6868         cmdline_fixed_string_t fwd;
6869         cmdline_fixed_string_t mode;
6870 };
6871
6872 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6873                                     __rte_unused struct cmdline *cl,
6874                                     __rte_unused void *data)
6875 {
6876         struct cmd_set_fwd_mode_result *res = parsed_result;
6877
6878         retry_enabled = 0;
6879         set_pkt_forwarding_mode(res->mode);
6880 }
6881
6882 cmdline_parse_token_string_t cmd_setfwd_set =
6883         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6884 cmdline_parse_token_string_t cmd_setfwd_fwd =
6885         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6886 cmdline_parse_token_string_t cmd_setfwd_mode =
6887         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6888                 "" /* defined at init */);
6889
6890 cmdline_parse_inst_t cmd_set_fwd_mode = {
6891         .f = cmd_set_fwd_mode_parsed,
6892         .data = NULL,
6893         .help_str = NULL, /* defined at init */
6894         .tokens = {
6895                 (void *)&cmd_setfwd_set,
6896                 (void *)&cmd_setfwd_fwd,
6897                 (void *)&cmd_setfwd_mode,
6898                 NULL,
6899         },
6900 };
6901
6902 static void cmd_set_fwd_mode_init(void)
6903 {
6904         char *modes, *c;
6905         static char token[128];
6906         static char help[256];
6907         cmdline_parse_token_string_t *token_struct;
6908
6909         modes = list_pkt_forwarding_modes();
6910         snprintf(help, sizeof(help), "set fwd %s: "
6911                 "Set packet forwarding mode", modes);
6912         cmd_set_fwd_mode.help_str = help;
6913
6914         /* string token separator is # */
6915         for (c = token; *modes != '\0'; modes++)
6916                 if (*modes == '|')
6917                         *c++ = '#';
6918                 else
6919                         *c++ = *modes;
6920         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6921         token_struct->string_data.str = token;
6922 }
6923
6924 /* *** SET RETRY FORWARDING MODE *** */
6925 struct cmd_set_fwd_retry_mode_result {
6926         cmdline_fixed_string_t set;
6927         cmdline_fixed_string_t fwd;
6928         cmdline_fixed_string_t mode;
6929         cmdline_fixed_string_t retry;
6930 };
6931
6932 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6933                             __rte_unused struct cmdline *cl,
6934                             __rte_unused void *data)
6935 {
6936         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6937
6938         retry_enabled = 1;
6939         set_pkt_forwarding_mode(res->mode);
6940 }
6941
6942 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6943         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6944                         set, "set");
6945 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6946         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6947                         fwd, "fwd");
6948 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6949         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6950                         mode,
6951                 "" /* defined at init */);
6952 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6953         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6954                         retry, "retry");
6955
6956 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6957         .f = cmd_set_fwd_retry_mode_parsed,
6958         .data = NULL,
6959         .help_str = NULL, /* defined at init */
6960         .tokens = {
6961                 (void *)&cmd_setfwd_retry_set,
6962                 (void *)&cmd_setfwd_retry_fwd,
6963                 (void *)&cmd_setfwd_retry_mode,
6964                 (void *)&cmd_setfwd_retry_retry,
6965                 NULL,
6966         },
6967 };
6968
6969 static void cmd_set_fwd_retry_mode_init(void)
6970 {
6971         char *modes, *c;
6972         static char token[128];
6973         static char help[256];
6974         cmdline_parse_token_string_t *token_struct;
6975
6976         modes = list_pkt_forwarding_retry_modes();
6977         snprintf(help, sizeof(help), "set fwd %s retry: "
6978                 "Set packet forwarding mode with retry", modes);
6979         cmd_set_fwd_retry_mode.help_str = help;
6980
6981         /* string token separator is # */
6982         for (c = token; *modes != '\0'; modes++)
6983                 if (*modes == '|')
6984                         *c++ = '#';
6985                 else
6986                         *c++ = *modes;
6987         token_struct = (cmdline_parse_token_string_t *)
6988                 cmd_set_fwd_retry_mode.tokens[2];
6989         token_struct->string_data.str = token;
6990 }
6991
6992 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6993 struct cmd_set_burst_tx_retry_result {
6994         cmdline_fixed_string_t set;
6995         cmdline_fixed_string_t burst;
6996         cmdline_fixed_string_t tx;
6997         cmdline_fixed_string_t delay;
6998         uint32_t time;
6999         cmdline_fixed_string_t retry;
7000         uint32_t retry_num;
7001 };
7002
7003 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
7004                                         __rte_unused struct cmdline *cl,
7005                                         __rte_unused void *data)
7006 {
7007         struct cmd_set_burst_tx_retry_result *res = parsed_result;
7008
7009         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
7010                 && !strcmp(res->tx, "tx")) {
7011                 if (!strcmp(res->delay, "delay"))
7012                         burst_tx_delay_time = res->time;
7013                 if (!strcmp(res->retry, "retry"))
7014                         burst_tx_retry_num = res->retry_num;
7015         }
7016
7017 }
7018
7019 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
7020         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
7021 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
7022         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
7023                                  "burst");
7024 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
7025         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
7026 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
7027         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
7028 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
7029         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time,
7030                                  RTE_UINT32);
7031 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
7032         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
7033 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
7034         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num,
7035                                  RTE_UINT32);
7036
7037 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
7038         .f = cmd_set_burst_tx_retry_parsed,
7039         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
7040         .tokens = {
7041                 (void *)&cmd_set_burst_tx_retry_set,
7042                 (void *)&cmd_set_burst_tx_retry_burst,
7043                 (void *)&cmd_set_burst_tx_retry_tx,
7044                 (void *)&cmd_set_burst_tx_retry_delay,
7045                 (void *)&cmd_set_burst_tx_retry_time,
7046                 (void *)&cmd_set_burst_tx_retry_retry,
7047                 (void *)&cmd_set_burst_tx_retry_retry_num,
7048                 NULL,
7049         },
7050 };
7051
7052 /* *** SET PROMISC MODE *** */
7053 struct cmd_set_promisc_mode_result {
7054         cmdline_fixed_string_t set;
7055         cmdline_fixed_string_t promisc;
7056         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7057         uint16_t port_num;               /* valid if "allports" argument == 0 */
7058         cmdline_fixed_string_t mode;
7059 };
7060
7061 static void cmd_set_promisc_mode_parsed(void *parsed_result,
7062                                         __rte_unused struct cmdline *cl,
7063                                         void *allports)
7064 {
7065         struct cmd_set_promisc_mode_result *res = parsed_result;
7066         int enable;
7067         portid_t i;
7068
7069         if (!strcmp(res->mode, "on"))
7070                 enable = 1;
7071         else
7072                 enable = 0;
7073
7074         /* all ports */
7075         if (allports) {
7076                 RTE_ETH_FOREACH_DEV(i)
7077                         eth_set_promisc_mode(i, enable);
7078         } else {
7079                 eth_set_promisc_mode(res->port_num, enable);
7080         }
7081 }
7082
7083 cmdline_parse_token_string_t cmd_setpromisc_set =
7084         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
7085 cmdline_parse_token_string_t cmd_setpromisc_promisc =
7086         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
7087                                  "promisc");
7088 cmdline_parse_token_string_t cmd_setpromisc_portall =
7089         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
7090                                  "all");
7091 cmdline_parse_token_num_t cmd_setpromisc_portnum =
7092         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
7093                               RTE_UINT16);
7094 cmdline_parse_token_string_t cmd_setpromisc_mode =
7095         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
7096                                  "on#off");
7097
7098 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
7099         .f = cmd_set_promisc_mode_parsed,
7100         .data = (void *)1,
7101         .help_str = "set promisc all on|off: Set promisc mode for all ports",
7102         .tokens = {
7103                 (void *)&cmd_setpromisc_set,
7104                 (void *)&cmd_setpromisc_promisc,
7105                 (void *)&cmd_setpromisc_portall,
7106                 (void *)&cmd_setpromisc_mode,
7107                 NULL,
7108         },
7109 };
7110
7111 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
7112         .f = cmd_set_promisc_mode_parsed,
7113         .data = (void *)0,
7114         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
7115         .tokens = {
7116                 (void *)&cmd_setpromisc_set,
7117                 (void *)&cmd_setpromisc_promisc,
7118                 (void *)&cmd_setpromisc_portnum,
7119                 (void *)&cmd_setpromisc_mode,
7120                 NULL,
7121         },
7122 };
7123
7124 /* *** SET ALLMULTI MODE *** */
7125 struct cmd_set_allmulti_mode_result {
7126         cmdline_fixed_string_t set;
7127         cmdline_fixed_string_t allmulti;
7128         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
7129         uint16_t port_num;               /* valid if "allports" argument == 0 */
7130         cmdline_fixed_string_t mode;
7131 };
7132
7133 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
7134                                         __rte_unused struct cmdline *cl,
7135                                         void *allports)
7136 {
7137         struct cmd_set_allmulti_mode_result *res = parsed_result;
7138         int enable;
7139         portid_t i;
7140
7141         if (!strcmp(res->mode, "on"))
7142                 enable = 1;
7143         else
7144                 enable = 0;
7145
7146         /* all ports */
7147         if (allports) {
7148                 RTE_ETH_FOREACH_DEV(i) {
7149                         eth_set_allmulticast_mode(i, enable);
7150                 }
7151         }
7152         else {
7153                 eth_set_allmulticast_mode(res->port_num, enable);
7154         }
7155 }
7156
7157 cmdline_parse_token_string_t cmd_setallmulti_set =
7158         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
7159 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
7160         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
7161                                  "allmulti");
7162 cmdline_parse_token_string_t cmd_setallmulti_portall =
7163         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
7164                                  "all");
7165 cmdline_parse_token_num_t cmd_setallmulti_portnum =
7166         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
7167                               RTE_UINT16);
7168 cmdline_parse_token_string_t cmd_setallmulti_mode =
7169         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
7170                                  "on#off");
7171
7172 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
7173         .f = cmd_set_allmulti_mode_parsed,
7174         .data = (void *)1,
7175         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
7176         .tokens = {
7177                 (void *)&cmd_setallmulti_set,
7178                 (void *)&cmd_setallmulti_allmulti,
7179                 (void *)&cmd_setallmulti_portall,
7180                 (void *)&cmd_setallmulti_mode,
7181                 NULL,
7182         },
7183 };
7184
7185 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
7186         .f = cmd_set_allmulti_mode_parsed,
7187         .data = (void *)0,
7188         .help_str = "set allmulti <port_id> on|off: "
7189                 "Set allmulti mode on port_id",
7190         .tokens = {
7191                 (void *)&cmd_setallmulti_set,
7192                 (void *)&cmd_setallmulti_allmulti,
7193                 (void *)&cmd_setallmulti_portnum,
7194                 (void *)&cmd_setallmulti_mode,
7195                 NULL,
7196         },
7197 };
7198
7199 /* *** GET CURRENT ETHERNET LINK FLOW CONTROL *** */
7200 struct cmd_link_flow_ctrl_show {
7201         cmdline_fixed_string_t show;
7202         cmdline_fixed_string_t port;
7203         portid_t port_id;
7204         cmdline_fixed_string_t flow_ctrl;
7205 };
7206
7207 cmdline_parse_token_string_t cmd_lfc_show_show =
7208         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7209                                 show, "show");
7210 cmdline_parse_token_string_t cmd_lfc_show_port =
7211         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7212                                 port, "port");
7213 cmdline_parse_token_num_t cmd_lfc_show_portid =
7214         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_show,
7215                                 port_id, RTE_UINT16);
7216 cmdline_parse_token_string_t cmd_lfc_show_flow_ctrl =
7217         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_show,
7218                                 flow_ctrl, "flow_ctrl");
7219
7220 static void
7221 cmd_link_flow_ctrl_show_parsed(void *parsed_result,
7222                               __rte_unused struct cmdline *cl,
7223                               __rte_unused void *data)
7224 {
7225         struct cmd_link_flow_ctrl_show *res = parsed_result;
7226         static const char *info_border = "*********************";
7227         struct rte_eth_fc_conf fc_conf;
7228         bool rx_fc_en = false;
7229         bool tx_fc_en = false;
7230         int ret;
7231
7232         ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7233         if (ret != 0) {
7234                 fprintf(stderr,
7235                         "Failed to get current flow ctrl information: err = %d\n",
7236                         ret);
7237                 return;
7238         }
7239
7240         if (fc_conf.mode == RTE_ETH_FC_RX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7241                 rx_fc_en = true;
7242         if (fc_conf.mode == RTE_ETH_FC_TX_PAUSE || fc_conf.mode == RTE_ETH_FC_FULL)
7243                 tx_fc_en = true;
7244
7245         printf("\n%s Flow control infos for port %-2d %s\n",
7246                 info_border, res->port_id, info_border);
7247         printf("FC mode:\n");
7248         printf("   Rx pause: %s\n", rx_fc_en ? "on" : "off");
7249         printf("   Tx pause: %s\n", tx_fc_en ? "on" : "off");
7250         printf("Autoneg: %s\n", fc_conf.autoneg ? "on" : "off");
7251         printf("Pause time: 0x%x\n", fc_conf.pause_time);
7252         printf("High waterline: 0x%x\n", fc_conf.high_water);
7253         printf("Low waterline: 0x%x\n", fc_conf.low_water);
7254         printf("Send XON: %s\n", fc_conf.send_xon ? "on" : "off");
7255         printf("Forward MAC control frames: %s\n",
7256                 fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
7257         printf("\n%s**************   End  ***********%s\n",
7258                 info_border, info_border);
7259 }
7260
7261 cmdline_parse_inst_t cmd_link_flow_control_show = {
7262         .f = cmd_link_flow_ctrl_show_parsed,
7263         .data = NULL,
7264         .help_str = "show port <port_id> flow_ctrl",
7265         .tokens = {
7266                 (void *)&cmd_lfc_show_show,
7267                 (void *)&cmd_lfc_show_port,
7268                 (void *)&cmd_lfc_show_portid,
7269                 (void *)&cmd_lfc_show_flow_ctrl,
7270                 NULL,
7271         },
7272 };
7273
7274 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7275 struct cmd_link_flow_ctrl_set_result {
7276         cmdline_fixed_string_t set;
7277         cmdline_fixed_string_t flow_ctrl;
7278         cmdline_fixed_string_t rx;
7279         cmdline_fixed_string_t rx_lfc_mode;
7280         cmdline_fixed_string_t tx;
7281         cmdline_fixed_string_t tx_lfc_mode;
7282         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7283         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7284         cmdline_fixed_string_t autoneg_str;
7285         cmdline_fixed_string_t autoneg;
7286         cmdline_fixed_string_t hw_str;
7287         uint32_t high_water;
7288         cmdline_fixed_string_t lw_str;
7289         uint32_t low_water;
7290         cmdline_fixed_string_t pt_str;
7291         uint16_t pause_time;
7292         cmdline_fixed_string_t xon_str;
7293         uint16_t send_xon;
7294         portid_t port_id;
7295 };
7296
7297 cmdline_parse_token_string_t cmd_lfc_set_set =
7298         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7299                                 set, "set");
7300 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7301         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7302                                 flow_ctrl, "flow_ctrl");
7303 cmdline_parse_token_string_t cmd_lfc_set_rx =
7304         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7305                                 rx, "rx");
7306 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7307         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7308                                 rx_lfc_mode, "on#off");
7309 cmdline_parse_token_string_t cmd_lfc_set_tx =
7310         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7311                                 tx, "tx");
7312 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7313         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7314                                 tx_lfc_mode, "on#off");
7315 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7316         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7317                                 hw_str, "high_water");
7318 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7319         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7320                                 high_water, RTE_UINT32);
7321 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7322         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7323                                 lw_str, "low_water");
7324 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7325         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7326                                 low_water, RTE_UINT32);
7327 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7328         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7329                                 pt_str, "pause_time");
7330 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7331         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7332                                 pause_time, RTE_UINT16);
7333 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7334         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7335                                 xon_str, "send_xon");
7336 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7337         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7338                                 send_xon, RTE_UINT16);
7339 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7340         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7341                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7342 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7343         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7344                                 mac_ctrl_frame_fwd_mode, "on#off");
7345 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7346         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7347                                 autoneg_str, "autoneg");
7348 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7349         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7350                                 autoneg, "on#off");
7351 cmdline_parse_token_num_t cmd_lfc_set_portid =
7352         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7353                                 port_id, RTE_UINT16);
7354
7355 /* forward declaration */
7356 static void
7357 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7358                               void *data);
7359
7360 cmdline_parse_inst_t cmd_link_flow_control_set = {
7361         .f = cmd_link_flow_ctrl_set_parsed,
7362         .data = NULL,
7363         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7364                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7365                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7366         .tokens = {
7367                 (void *)&cmd_lfc_set_set,
7368                 (void *)&cmd_lfc_set_flow_ctrl,
7369                 (void *)&cmd_lfc_set_rx,
7370                 (void *)&cmd_lfc_set_rx_mode,
7371                 (void *)&cmd_lfc_set_tx,
7372                 (void *)&cmd_lfc_set_tx_mode,
7373                 (void *)&cmd_lfc_set_high_water,
7374                 (void *)&cmd_lfc_set_low_water,
7375                 (void *)&cmd_lfc_set_pause_time,
7376                 (void *)&cmd_lfc_set_send_xon,
7377                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7378                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7379                 (void *)&cmd_lfc_set_autoneg_str,
7380                 (void *)&cmd_lfc_set_autoneg,
7381                 (void *)&cmd_lfc_set_portid,
7382                 NULL,
7383         },
7384 };
7385
7386 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7387         .f = cmd_link_flow_ctrl_set_parsed,
7388         .data = (void *)&cmd_link_flow_control_set_rx,
7389         .help_str = "set flow_ctrl rx on|off <port_id>: "
7390                 "Change rx flow control parameter",
7391         .tokens = {
7392                 (void *)&cmd_lfc_set_set,
7393                 (void *)&cmd_lfc_set_flow_ctrl,
7394                 (void *)&cmd_lfc_set_rx,
7395                 (void *)&cmd_lfc_set_rx_mode,
7396                 (void *)&cmd_lfc_set_portid,
7397                 NULL,
7398         },
7399 };
7400
7401 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7402         .f = cmd_link_flow_ctrl_set_parsed,
7403         .data = (void *)&cmd_link_flow_control_set_tx,
7404         .help_str = "set flow_ctrl tx on|off <port_id>: "
7405                 "Change tx flow control parameter",
7406         .tokens = {
7407                 (void *)&cmd_lfc_set_set,
7408                 (void *)&cmd_lfc_set_flow_ctrl,
7409                 (void *)&cmd_lfc_set_tx,
7410                 (void *)&cmd_lfc_set_tx_mode,
7411                 (void *)&cmd_lfc_set_portid,
7412                 NULL,
7413         },
7414 };
7415
7416 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7417         .f = cmd_link_flow_ctrl_set_parsed,
7418         .data = (void *)&cmd_link_flow_control_set_hw,
7419         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7420                 "Change high water flow control parameter",
7421         .tokens = {
7422                 (void *)&cmd_lfc_set_set,
7423                 (void *)&cmd_lfc_set_flow_ctrl,
7424                 (void *)&cmd_lfc_set_high_water_str,
7425                 (void *)&cmd_lfc_set_high_water,
7426                 (void *)&cmd_lfc_set_portid,
7427                 NULL,
7428         },
7429 };
7430
7431 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7432         .f = cmd_link_flow_ctrl_set_parsed,
7433         .data = (void *)&cmd_link_flow_control_set_lw,
7434         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7435                 "Change low water flow control parameter",
7436         .tokens = {
7437                 (void *)&cmd_lfc_set_set,
7438                 (void *)&cmd_lfc_set_flow_ctrl,
7439                 (void *)&cmd_lfc_set_low_water_str,
7440                 (void *)&cmd_lfc_set_low_water,
7441                 (void *)&cmd_lfc_set_portid,
7442                 NULL,
7443         },
7444 };
7445
7446 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7447         .f = cmd_link_flow_ctrl_set_parsed,
7448         .data = (void *)&cmd_link_flow_control_set_pt,
7449         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7450                 "Change pause time flow control parameter",
7451         .tokens = {
7452                 (void *)&cmd_lfc_set_set,
7453                 (void *)&cmd_lfc_set_flow_ctrl,
7454                 (void *)&cmd_lfc_set_pause_time_str,
7455                 (void *)&cmd_lfc_set_pause_time,
7456                 (void *)&cmd_lfc_set_portid,
7457                 NULL,
7458         },
7459 };
7460
7461 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7462         .f = cmd_link_flow_ctrl_set_parsed,
7463         .data = (void *)&cmd_link_flow_control_set_xon,
7464         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7465                 "Change send_xon flow control parameter",
7466         .tokens = {
7467                 (void *)&cmd_lfc_set_set,
7468                 (void *)&cmd_lfc_set_flow_ctrl,
7469                 (void *)&cmd_lfc_set_send_xon_str,
7470                 (void *)&cmd_lfc_set_send_xon,
7471                 (void *)&cmd_lfc_set_portid,
7472                 NULL,
7473         },
7474 };
7475
7476 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7477         .f = cmd_link_flow_ctrl_set_parsed,
7478         .data = (void *)&cmd_link_flow_control_set_macfwd,
7479         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7480                 "Change mac ctrl fwd flow control parameter",
7481         .tokens = {
7482                 (void *)&cmd_lfc_set_set,
7483                 (void *)&cmd_lfc_set_flow_ctrl,
7484                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7485                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7486                 (void *)&cmd_lfc_set_portid,
7487                 NULL,
7488         },
7489 };
7490
7491 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7492         .f = cmd_link_flow_ctrl_set_parsed,
7493         .data = (void *)&cmd_link_flow_control_set_autoneg,
7494         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7495                 "Change autoneg flow control parameter",
7496         .tokens = {
7497                 (void *)&cmd_lfc_set_set,
7498                 (void *)&cmd_lfc_set_flow_ctrl,
7499                 (void *)&cmd_lfc_set_autoneg_str,
7500                 (void *)&cmd_lfc_set_autoneg,
7501                 (void *)&cmd_lfc_set_portid,
7502                 NULL,
7503         },
7504 };
7505
7506 static void
7507 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7508                               __rte_unused struct cmdline *cl,
7509                               void *data)
7510 {
7511         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7512         cmdline_parse_inst_t *cmd = data;
7513         struct rte_eth_fc_conf fc_conf;
7514         int rx_fc_en = 0;
7515         int tx_fc_en = 0;
7516         int ret;
7517
7518         /*
7519          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7520          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7521          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7522          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7523          */
7524         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7525                         {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7526         };
7527
7528         /* Partial command line, retrieve current configuration */
7529         if (cmd) {
7530                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7531                 if (ret != 0) {
7532                         fprintf(stderr,
7533                                 "cannot get current flow ctrl parameters, return code = %d\n",
7534                                 ret);
7535                         return;
7536                 }
7537
7538                 if ((fc_conf.mode == RTE_ETH_FC_RX_PAUSE) ||
7539                     (fc_conf.mode == RTE_ETH_FC_FULL))
7540                         rx_fc_en = 1;
7541                 if ((fc_conf.mode == RTE_ETH_FC_TX_PAUSE) ||
7542                     (fc_conf.mode == RTE_ETH_FC_FULL))
7543                         tx_fc_en = 1;
7544         }
7545
7546         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7547                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7548
7549         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7550                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7551
7552         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7553
7554         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7555                 fc_conf.high_water = res->high_water;
7556
7557         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7558                 fc_conf.low_water = res->low_water;
7559
7560         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7561                 fc_conf.pause_time = res->pause_time;
7562
7563         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7564                 fc_conf.send_xon = res->send_xon;
7565
7566         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7567                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7568                         fc_conf.mac_ctrl_frame_fwd = 1;
7569                 else
7570                         fc_conf.mac_ctrl_frame_fwd = 0;
7571         }
7572
7573         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7574                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7575
7576         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7577         if (ret != 0)
7578                 fprintf(stderr,
7579                         "bad flow control parameter, return code = %d\n",
7580                         ret);
7581 }
7582
7583 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7584 struct cmd_priority_flow_ctrl_set_result {
7585         cmdline_fixed_string_t set;
7586         cmdline_fixed_string_t pfc_ctrl;
7587         cmdline_fixed_string_t rx;
7588         cmdline_fixed_string_t rx_pfc_mode;
7589         cmdline_fixed_string_t tx;
7590         cmdline_fixed_string_t tx_pfc_mode;
7591         uint32_t high_water;
7592         uint32_t low_water;
7593         uint16_t pause_time;
7594         uint8_t  priority;
7595         portid_t port_id;
7596 };
7597
7598 static void
7599 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7600                        __rte_unused struct cmdline *cl,
7601                        __rte_unused void *data)
7602 {
7603         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7604         struct rte_eth_pfc_conf pfc_conf;
7605         int rx_fc_enable, tx_fc_enable;
7606         int ret;
7607
7608         /*
7609          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7610          * the RTE_ETH_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7611          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7612          * the RTE_ETH_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7613          */
7614         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7615                 {RTE_ETH_FC_NONE, RTE_ETH_FC_TX_PAUSE}, {RTE_ETH_FC_RX_PAUSE, RTE_ETH_FC_FULL}
7616         };
7617
7618         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7619         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7620         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7621         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7622         pfc_conf.fc.high_water = res->high_water;
7623         pfc_conf.fc.low_water  = res->low_water;
7624         pfc_conf.fc.pause_time = res->pause_time;
7625         pfc_conf.priority      = res->priority;
7626
7627         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7628         if (ret != 0)
7629                 fprintf(stderr,
7630                         "bad priority flow control parameter, return code = %d\n",
7631                         ret);
7632 }
7633
7634 cmdline_parse_token_string_t cmd_pfc_set_set =
7635         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7636                                 set, "set");
7637 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7638         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7639                                 pfc_ctrl, "pfc_ctrl");
7640 cmdline_parse_token_string_t cmd_pfc_set_rx =
7641         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7642                                 rx, "rx");
7643 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7644         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7645                                 rx_pfc_mode, "on#off");
7646 cmdline_parse_token_string_t cmd_pfc_set_tx =
7647         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7648                                 tx, "tx");
7649 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7650         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7651                                 tx_pfc_mode, "on#off");
7652 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7653         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7654                                 high_water, RTE_UINT32);
7655 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7656         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7657                                 low_water, RTE_UINT32);
7658 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7659         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7660                                 pause_time, RTE_UINT16);
7661 cmdline_parse_token_num_t cmd_pfc_set_priority =
7662         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7663                                 priority, RTE_UINT8);
7664 cmdline_parse_token_num_t cmd_pfc_set_portid =
7665         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7666                                 port_id, RTE_UINT16);
7667
7668 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7669         .f = cmd_priority_flow_ctrl_set_parsed,
7670         .data = NULL,
7671         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7672                 "<pause_time> <priority> <port_id>: "
7673                 "Configure the Ethernet priority flow control",
7674         .tokens = {
7675                 (void *)&cmd_pfc_set_set,
7676                 (void *)&cmd_pfc_set_flow_ctrl,
7677                 (void *)&cmd_pfc_set_rx,
7678                 (void *)&cmd_pfc_set_rx_mode,
7679                 (void *)&cmd_pfc_set_tx,
7680                 (void *)&cmd_pfc_set_tx_mode,
7681                 (void *)&cmd_pfc_set_high_water,
7682                 (void *)&cmd_pfc_set_low_water,
7683                 (void *)&cmd_pfc_set_pause_time,
7684                 (void *)&cmd_pfc_set_priority,
7685                 (void *)&cmd_pfc_set_portid,
7686                 NULL,
7687         },
7688 };
7689
7690 /* *** RESET CONFIGURATION *** */
7691 struct cmd_reset_result {
7692         cmdline_fixed_string_t reset;
7693         cmdline_fixed_string_t def;
7694 };
7695
7696 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7697                              struct cmdline *cl,
7698                              __rte_unused void *data)
7699 {
7700         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7701         set_def_fwd_config();
7702 }
7703
7704 cmdline_parse_token_string_t cmd_reset_set =
7705         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7706 cmdline_parse_token_string_t cmd_reset_def =
7707         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7708                                  "default");
7709
7710 cmdline_parse_inst_t cmd_reset = {
7711         .f = cmd_reset_parsed,
7712         .data = NULL,
7713         .help_str = "set default: Reset default forwarding configuration",
7714         .tokens = {
7715                 (void *)&cmd_reset_set,
7716                 (void *)&cmd_reset_def,
7717                 NULL,
7718         },
7719 };
7720
7721 /* *** START FORWARDING *** */
7722 struct cmd_start_result {
7723         cmdline_fixed_string_t start;
7724 };
7725
7726 cmdline_parse_token_string_t cmd_start_start =
7727         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7728
7729 static void cmd_start_parsed(__rte_unused void *parsed_result,
7730                              __rte_unused struct cmdline *cl,
7731                              __rte_unused void *data)
7732 {
7733         start_packet_forwarding(0);
7734 }
7735
7736 cmdline_parse_inst_t cmd_start = {
7737         .f = cmd_start_parsed,
7738         .data = NULL,
7739         .help_str = "start: Start packet forwarding",
7740         .tokens = {
7741                 (void *)&cmd_start_start,
7742                 NULL,
7743         },
7744 };
7745
7746 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7747 struct cmd_start_tx_first_result {
7748         cmdline_fixed_string_t start;
7749         cmdline_fixed_string_t tx_first;
7750 };
7751
7752 static void
7753 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7754                           __rte_unused struct cmdline *cl,
7755                           __rte_unused void *data)
7756 {
7757         start_packet_forwarding(1);
7758 }
7759
7760 cmdline_parse_token_string_t cmd_start_tx_first_start =
7761         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7762                                  "start");
7763 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7764         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7765                                  tx_first, "tx_first");
7766
7767 cmdline_parse_inst_t cmd_start_tx_first = {
7768         .f = cmd_start_tx_first_parsed,
7769         .data = NULL,
7770         .help_str = "start tx_first: Start packet forwarding, "
7771                 "after sending 1 burst of packets",
7772         .tokens = {
7773                 (void *)&cmd_start_tx_first_start,
7774                 (void *)&cmd_start_tx_first_tx_first,
7775                 NULL,
7776         },
7777 };
7778
7779 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7780 struct cmd_start_tx_first_n_result {
7781         cmdline_fixed_string_t start;
7782         cmdline_fixed_string_t tx_first;
7783         uint32_t tx_num;
7784 };
7785
7786 static void
7787 cmd_start_tx_first_n_parsed(void *parsed_result,
7788                           __rte_unused struct cmdline *cl,
7789                           __rte_unused void *data)
7790 {
7791         struct cmd_start_tx_first_n_result *res = parsed_result;
7792
7793         start_packet_forwarding(res->tx_num);
7794 }
7795
7796 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7797         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7798                         start, "start");
7799 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7800         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7801                         tx_first, "tx_first");
7802 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7803         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7804                         tx_num, RTE_UINT32);
7805
7806 cmdline_parse_inst_t cmd_start_tx_first_n = {
7807         .f = cmd_start_tx_first_n_parsed,
7808         .data = NULL,
7809         .help_str = "start tx_first <num>: "
7810                 "packet forwarding, after sending <num> bursts of packets",
7811         .tokens = {
7812                 (void *)&cmd_start_tx_first_n_start,
7813                 (void *)&cmd_start_tx_first_n_tx_first,
7814                 (void *)&cmd_start_tx_first_n_tx_num,
7815                 NULL,
7816         },
7817 };
7818
7819 /* *** SET LINK UP *** */
7820 struct cmd_set_link_up_result {
7821         cmdline_fixed_string_t set;
7822         cmdline_fixed_string_t link_up;
7823         cmdline_fixed_string_t port;
7824         portid_t port_id;
7825 };
7826
7827 cmdline_parse_token_string_t cmd_set_link_up_set =
7828         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7829 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7830         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7831                                 "link-up");
7832 cmdline_parse_token_string_t cmd_set_link_up_port =
7833         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7834 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7835         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id,
7836                                 RTE_UINT16);
7837
7838 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7839                              __rte_unused struct cmdline *cl,
7840                              __rte_unused void *data)
7841 {
7842         struct cmd_set_link_up_result *res = parsed_result;
7843         dev_set_link_up(res->port_id);
7844 }
7845
7846 cmdline_parse_inst_t cmd_set_link_up = {
7847         .f = cmd_set_link_up_parsed,
7848         .data = NULL,
7849         .help_str = "set link-up port <port id>",
7850         .tokens = {
7851                 (void *)&cmd_set_link_up_set,
7852                 (void *)&cmd_set_link_up_link_up,
7853                 (void *)&cmd_set_link_up_port,
7854                 (void *)&cmd_set_link_up_port_id,
7855                 NULL,
7856         },
7857 };
7858
7859 /* *** SET LINK DOWN *** */
7860 struct cmd_set_link_down_result {
7861         cmdline_fixed_string_t set;
7862         cmdline_fixed_string_t link_down;
7863         cmdline_fixed_string_t port;
7864         portid_t port_id;
7865 };
7866
7867 cmdline_parse_token_string_t cmd_set_link_down_set =
7868         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7869 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7870         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7871                                 "link-down");
7872 cmdline_parse_token_string_t cmd_set_link_down_port =
7873         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7874 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7875         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id,
7876                                 RTE_UINT16);
7877
7878 static void cmd_set_link_down_parsed(
7879                                 __rte_unused void *parsed_result,
7880                                 __rte_unused struct cmdline *cl,
7881                                 __rte_unused void *data)
7882 {
7883         struct cmd_set_link_down_result *res = parsed_result;
7884         dev_set_link_down(res->port_id);
7885 }
7886
7887 cmdline_parse_inst_t cmd_set_link_down = {
7888         .f = cmd_set_link_down_parsed,
7889         .data = NULL,
7890         .help_str = "set link-down port <port id>",
7891         .tokens = {
7892                 (void *)&cmd_set_link_down_set,
7893                 (void *)&cmd_set_link_down_link_down,
7894                 (void *)&cmd_set_link_down_port,
7895                 (void *)&cmd_set_link_down_port_id,
7896                 NULL,
7897         },
7898 };
7899
7900 /* *** SHOW CFG *** */
7901 struct cmd_showcfg_result {
7902         cmdline_fixed_string_t show;
7903         cmdline_fixed_string_t cfg;
7904         cmdline_fixed_string_t what;
7905 };
7906
7907 static void cmd_showcfg_parsed(void *parsed_result,
7908                                __rte_unused struct cmdline *cl,
7909                                __rte_unused void *data)
7910 {
7911         struct cmd_showcfg_result *res = parsed_result;
7912         if (!strcmp(res->what, "rxtx"))
7913                 rxtx_config_display();
7914         else if (!strcmp(res->what, "cores"))
7915                 fwd_lcores_config_display();
7916         else if (!strcmp(res->what, "fwd"))
7917                 pkt_fwd_config_display(&cur_fwd_config);
7918         else if (!strcmp(res->what, "rxoffs"))
7919                 show_rx_pkt_offsets();
7920         else if (!strcmp(res->what, "rxpkts"))
7921                 show_rx_pkt_segments();
7922         else if (!strcmp(res->what, "txpkts"))
7923                 show_tx_pkt_segments();
7924         else if (!strcmp(res->what, "txtimes"))
7925                 show_tx_pkt_times();
7926 }
7927
7928 cmdline_parse_token_string_t cmd_showcfg_show =
7929         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7930 cmdline_parse_token_string_t cmd_showcfg_port =
7931         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7932 cmdline_parse_token_string_t cmd_showcfg_what =
7933         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7934                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7935
7936 cmdline_parse_inst_t cmd_showcfg = {
7937         .f = cmd_showcfg_parsed,
7938         .data = NULL,
7939         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7940         .tokens = {
7941                 (void *)&cmd_showcfg_show,
7942                 (void *)&cmd_showcfg_port,
7943                 (void *)&cmd_showcfg_what,
7944                 NULL,
7945         },
7946 };
7947
7948 /* *** SHOW ALL PORT INFO *** */
7949 struct cmd_showportall_result {
7950         cmdline_fixed_string_t show;
7951         cmdline_fixed_string_t port;
7952         cmdline_fixed_string_t what;
7953         cmdline_fixed_string_t all;
7954 };
7955
7956 static void cmd_showportall_parsed(void *parsed_result,
7957                                 __rte_unused struct cmdline *cl,
7958                                 __rte_unused void *data)
7959 {
7960         portid_t i;
7961
7962         struct cmd_showportall_result *res = parsed_result;
7963         if (!strcmp(res->show, "clear")) {
7964                 if (!strcmp(res->what, "stats"))
7965                         RTE_ETH_FOREACH_DEV(i)
7966                                 nic_stats_clear(i);
7967                 else if (!strcmp(res->what, "xstats"))
7968                         RTE_ETH_FOREACH_DEV(i)
7969                                 nic_xstats_clear(i);
7970         } else if (!strcmp(res->what, "info"))
7971                 RTE_ETH_FOREACH_DEV(i)
7972                         port_infos_display(i);
7973         else if (!strcmp(res->what, "summary")) {
7974                 port_summary_header_display();
7975                 RTE_ETH_FOREACH_DEV(i)
7976                         port_summary_display(i);
7977         }
7978         else if (!strcmp(res->what, "stats"))
7979                 RTE_ETH_FOREACH_DEV(i)
7980                         nic_stats_display(i);
7981         else if (!strcmp(res->what, "xstats"))
7982                 RTE_ETH_FOREACH_DEV(i)
7983                         nic_xstats_display(i);
7984 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
7985         else if (!strcmp(res->what, "fdir"))
7986                 RTE_ETH_FOREACH_DEV(i)
7987                         fdir_get_infos(i);
7988 #endif
7989         else if (!strcmp(res->what, "dcb_tc"))
7990                 RTE_ETH_FOREACH_DEV(i)
7991                         port_dcb_info_display(i);
7992 }
7993
7994 cmdline_parse_token_string_t cmd_showportall_show =
7995         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7996                                  "show#clear");
7997 cmdline_parse_token_string_t cmd_showportall_port =
7998         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7999 cmdline_parse_token_string_t cmd_showportall_what =
8000         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
8001                                  "info#summary#stats#xstats#fdir#dcb_tc");
8002 cmdline_parse_token_string_t cmd_showportall_all =
8003         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
8004 cmdline_parse_inst_t cmd_showportall = {
8005         .f = cmd_showportall_parsed,
8006         .data = NULL,
8007         .help_str = "show|clear port "
8008                 "info|summary|stats|xstats|fdir|dcb_tc all",
8009         .tokens = {
8010                 (void *)&cmd_showportall_show,
8011                 (void *)&cmd_showportall_port,
8012                 (void *)&cmd_showportall_what,
8013                 (void *)&cmd_showportall_all,
8014                 NULL,
8015         },
8016 };
8017
8018 /* *** SHOW PORT INFO *** */
8019 struct cmd_showport_result {
8020         cmdline_fixed_string_t show;
8021         cmdline_fixed_string_t port;
8022         cmdline_fixed_string_t what;
8023         uint16_t portnum;
8024 };
8025
8026 static void cmd_showport_parsed(void *parsed_result,
8027                                 __rte_unused struct cmdline *cl,
8028                                 __rte_unused void *data)
8029 {
8030         struct cmd_showport_result *res = parsed_result;
8031         if (!strcmp(res->show, "clear")) {
8032                 if (!strcmp(res->what, "stats"))
8033                         nic_stats_clear(res->portnum);
8034                 else if (!strcmp(res->what, "xstats"))
8035                         nic_xstats_clear(res->portnum);
8036         } else if (!strcmp(res->what, "info"))
8037                 port_infos_display(res->portnum);
8038         else if (!strcmp(res->what, "summary")) {
8039                 port_summary_header_display();
8040                 port_summary_display(res->portnum);
8041         }
8042         else if (!strcmp(res->what, "stats"))
8043                 nic_stats_display(res->portnum);
8044         else if (!strcmp(res->what, "xstats"))
8045                 nic_xstats_display(res->portnum);
8046 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
8047         else if (!strcmp(res->what, "fdir"))
8048                  fdir_get_infos(res->portnum);
8049 #endif
8050         else if (!strcmp(res->what, "dcb_tc"))
8051                 port_dcb_info_display(res->portnum);
8052 }
8053
8054 cmdline_parse_token_string_t cmd_showport_show =
8055         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
8056                                  "show#clear");
8057 cmdline_parse_token_string_t cmd_showport_port =
8058         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
8059 cmdline_parse_token_string_t cmd_showport_what =
8060         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
8061                                  "info#summary#stats#xstats#fdir#dcb_tc");
8062 cmdline_parse_token_num_t cmd_showport_portnum =
8063         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, RTE_UINT16);
8064
8065 cmdline_parse_inst_t cmd_showport = {
8066         .f = cmd_showport_parsed,
8067         .data = NULL,
8068         .help_str = "show|clear port "
8069                 "info|summary|stats|xstats|fdir|dcb_tc "
8070                 "<port_id>",
8071         .tokens = {
8072                 (void *)&cmd_showport_show,
8073                 (void *)&cmd_showport_port,
8074                 (void *)&cmd_showport_what,
8075                 (void *)&cmd_showport_portnum,
8076                 NULL,
8077         },
8078 };
8079
8080 /* *** show port representors information *** */
8081 struct cmd_representor_info_result {
8082         cmdline_fixed_string_t cmd_show;
8083         cmdline_fixed_string_t cmd_port;
8084         cmdline_fixed_string_t cmd_info;
8085         cmdline_fixed_string_t cmd_keyword;
8086         portid_t cmd_pid;
8087 };
8088
8089 static void
8090 cmd_representor_info_parsed(void *parsed_result,
8091                 __rte_unused struct cmdline *cl,
8092                 __rte_unused void *data)
8093 {
8094         struct cmd_representor_info_result *res = parsed_result;
8095         struct rte_eth_representor_info *info;
8096         struct rte_eth_representor_range *range;
8097         uint32_t range_diff;
8098         uint32_t i;
8099         int ret;
8100         int num;
8101
8102         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
8103                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
8104                 return;
8105         }
8106
8107         ret = rte_eth_representor_info_get(res->cmd_pid, NULL);
8108         if (ret < 0) {
8109                 fprintf(stderr,
8110                         "Failed to get the number of representor info ranges for port %hu: %s\n",
8111                         res->cmd_pid, rte_strerror(-ret));
8112                 return;
8113         }
8114         num = ret;
8115
8116         info = calloc(1, sizeof(*info) + num * sizeof(info->ranges[0]));
8117         if (info == NULL) {
8118                 fprintf(stderr,
8119                         "Failed to allocate memory for representor info for port %hu\n",
8120                         res->cmd_pid);
8121                 return;
8122         }
8123         info->nb_ranges_alloc = num;
8124
8125         ret = rte_eth_representor_info_get(res->cmd_pid, info);
8126         if (ret < 0) {
8127                 fprintf(stderr,
8128                         "Failed to get the representor info for port %hu: %s\n",
8129                         res->cmd_pid, rte_strerror(-ret));
8130                 free(info);
8131                 return;
8132         }
8133
8134         printf("Port controller: %hu\n", info->controller);
8135         printf("Port PF: %hu\n", info->pf);
8136
8137         printf("Ranges: %u\n", info->nb_ranges);
8138         for (i = 0; i < info->nb_ranges; i++) {
8139                 range = &info->ranges[i];
8140                 range_diff = range->id_end - range->id_base;
8141
8142                 printf("%u. ", i + 1);
8143                 printf("'%s' ", range->name);
8144                 if (range_diff > 0)
8145                         printf("[%u-%u]: ", range->id_base, range->id_end);
8146                 else
8147                         printf("[%u]: ", range->id_base);
8148
8149                 printf("Controller %d, PF %d", range->controller, range->pf);
8150
8151                 switch (range->type) {
8152                 case RTE_ETH_REPRESENTOR_NONE:
8153                         printf(", NONE\n");
8154                         break;
8155                 case RTE_ETH_REPRESENTOR_VF:
8156                         if (range_diff > 0)
8157                                 printf(", VF %d..%d\n", range->vf,
8158                                        range->vf + range_diff);
8159                         else
8160                                 printf(", VF %d\n", range->vf);
8161                         break;
8162                 case RTE_ETH_REPRESENTOR_SF:
8163                         printf(", SF %d\n", range->sf);
8164                         break;
8165                 case RTE_ETH_REPRESENTOR_PF:
8166                         if (range_diff > 0)
8167                                 printf("..%d\n", range->pf + range_diff);
8168                         else
8169                                 printf("\n");
8170                         break;
8171                 default:
8172                         printf(", UNKNOWN TYPE %d\n", range->type);
8173                         break;
8174                 }
8175         }
8176
8177         free(info);
8178 }
8179
8180 cmdline_parse_token_string_t cmd_representor_info_show =
8181         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8182                         cmd_show, "show");
8183 cmdline_parse_token_string_t cmd_representor_info_port =
8184         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8185                         cmd_port, "port");
8186 cmdline_parse_token_string_t cmd_representor_info_info =
8187         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8188                         cmd_info, "info");
8189 cmdline_parse_token_num_t cmd_representor_info_pid =
8190         TOKEN_NUM_INITIALIZER(struct cmd_representor_info_result,
8191                         cmd_pid, RTE_UINT16);
8192 cmdline_parse_token_string_t cmd_representor_info_keyword =
8193         TOKEN_STRING_INITIALIZER(struct cmd_representor_info_result,
8194                         cmd_keyword, "representor");
8195
8196 cmdline_parse_inst_t cmd_representor_info = {
8197         .f = cmd_representor_info_parsed,
8198         .data = NULL,
8199         .help_str = "show port info <port_id> representor",
8200         .tokens = {
8201                 (void *)&cmd_representor_info_show,
8202                 (void *)&cmd_representor_info_port,
8203                 (void *)&cmd_representor_info_info,
8204                 (void *)&cmd_representor_info_pid,
8205                 (void *)&cmd_representor_info_keyword,
8206                 NULL,
8207         },
8208 };
8209
8210
8211 /* *** SHOW DEVICE INFO *** */
8212 struct cmd_showdevice_result {
8213         cmdline_fixed_string_t show;
8214         cmdline_fixed_string_t device;
8215         cmdline_fixed_string_t what;
8216         cmdline_fixed_string_t identifier;
8217 };
8218
8219 static void cmd_showdevice_parsed(void *parsed_result,
8220                                 __rte_unused struct cmdline *cl,
8221                                 __rte_unused void *data)
8222 {
8223         struct cmd_showdevice_result *res = parsed_result;
8224         if (!strcmp(res->what, "info")) {
8225                 if (!strcmp(res->identifier, "all"))
8226                         device_infos_display(NULL);
8227                 else
8228                         device_infos_display(res->identifier);
8229         }
8230 }
8231
8232 cmdline_parse_token_string_t cmd_showdevice_show =
8233         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
8234                                  "show");
8235 cmdline_parse_token_string_t cmd_showdevice_device =
8236         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
8237 cmdline_parse_token_string_t cmd_showdevice_what =
8238         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
8239                                  "info");
8240 cmdline_parse_token_string_t cmd_showdevice_identifier =
8241         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
8242                         identifier, NULL);
8243
8244 cmdline_parse_inst_t cmd_showdevice = {
8245         .f = cmd_showdevice_parsed,
8246         .data = NULL,
8247         .help_str = "show device info <identifier>|all",
8248         .tokens = {
8249                 (void *)&cmd_showdevice_show,
8250                 (void *)&cmd_showdevice_device,
8251                 (void *)&cmd_showdevice_what,
8252                 (void *)&cmd_showdevice_identifier,
8253                 NULL,
8254         },
8255 };
8256
8257 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
8258 struct cmd_showeeprom_result {
8259         cmdline_fixed_string_t show;
8260         cmdline_fixed_string_t port;
8261         uint16_t portnum;
8262         cmdline_fixed_string_t type;
8263 };
8264
8265 static void cmd_showeeprom_parsed(void *parsed_result,
8266                 __rte_unused struct cmdline *cl,
8267                 __rte_unused void *data)
8268 {
8269         struct cmd_showeeprom_result *res = parsed_result;
8270
8271         if (!strcmp(res->type, "eeprom"))
8272                 port_eeprom_display(res->portnum);
8273         else if (!strcmp(res->type, "module_eeprom"))
8274                 port_module_eeprom_display(res->portnum);
8275         else
8276                 fprintf(stderr, "Unknown argument\n");
8277 }
8278
8279 cmdline_parse_token_string_t cmd_showeeprom_show =
8280         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
8281 cmdline_parse_token_string_t cmd_showeeprom_port =
8282         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
8283 cmdline_parse_token_num_t cmd_showeeprom_portnum =
8284         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum,
8285                         RTE_UINT16);
8286 cmdline_parse_token_string_t cmd_showeeprom_type =
8287         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
8288
8289 cmdline_parse_inst_t cmd_showeeprom = {
8290         .f = cmd_showeeprom_parsed,
8291         .data = NULL,
8292         .help_str = "show port <port_id> module_eeprom|eeprom",
8293         .tokens = {
8294                 (void *)&cmd_showeeprom_show,
8295                 (void *)&cmd_showeeprom_port,
8296                 (void *)&cmd_showeeprom_portnum,
8297                 (void *)&cmd_showeeprom_type,
8298                 NULL,
8299         },
8300 };
8301
8302 /* *** SHOW QUEUE INFO *** */
8303 struct cmd_showqueue_result {
8304         cmdline_fixed_string_t show;
8305         cmdline_fixed_string_t type;
8306         cmdline_fixed_string_t what;
8307         uint16_t portnum;
8308         uint16_t queuenum;
8309 };
8310
8311 static void
8312 cmd_showqueue_parsed(void *parsed_result,
8313         __rte_unused struct cmdline *cl,
8314         __rte_unused void *data)
8315 {
8316         struct cmd_showqueue_result *res = parsed_result;
8317
8318         if (!strcmp(res->type, "rxq"))
8319                 rx_queue_infos_display(res->portnum, res->queuenum);
8320         else if (!strcmp(res->type, "txq"))
8321                 tx_queue_infos_display(res->portnum, res->queuenum);
8322 }
8323
8324 cmdline_parse_token_string_t cmd_showqueue_show =
8325         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
8326 cmdline_parse_token_string_t cmd_showqueue_type =
8327         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
8328 cmdline_parse_token_string_t cmd_showqueue_what =
8329         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
8330 cmdline_parse_token_num_t cmd_showqueue_portnum =
8331         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum,
8332                 RTE_UINT16);
8333 cmdline_parse_token_num_t cmd_showqueue_queuenum =
8334         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum,
8335                 RTE_UINT16);
8336
8337 cmdline_parse_inst_t cmd_showqueue = {
8338         .f = cmd_showqueue_parsed,
8339         .data = NULL,
8340         .help_str = "show rxq|txq info <port_id> <queue_id>",
8341         .tokens = {
8342                 (void *)&cmd_showqueue_show,
8343                 (void *)&cmd_showqueue_type,
8344                 (void *)&cmd_showqueue_what,
8345                 (void *)&cmd_showqueue_portnum,
8346                 (void *)&cmd_showqueue_queuenum,
8347                 NULL,
8348         },
8349 };
8350
8351 /* show/clear fwd engine statistics */
8352 struct fwd_result {
8353         cmdline_fixed_string_t action;
8354         cmdline_fixed_string_t fwd;
8355         cmdline_fixed_string_t stats;
8356         cmdline_fixed_string_t all;
8357 };
8358
8359 cmdline_parse_token_string_t cmd_fwd_action =
8360         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
8361 cmdline_parse_token_string_t cmd_fwd_fwd =
8362         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
8363 cmdline_parse_token_string_t cmd_fwd_stats =
8364         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
8365 cmdline_parse_token_string_t cmd_fwd_all =
8366         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
8367
8368 static void
8369 cmd_showfwdall_parsed(void *parsed_result,
8370                       __rte_unused struct cmdline *cl,
8371                       __rte_unused void *data)
8372 {
8373         struct fwd_result *res = parsed_result;
8374
8375         if (!strcmp(res->action, "show"))
8376                 fwd_stats_display();
8377         else
8378                 fwd_stats_reset();
8379 }
8380
8381 static cmdline_parse_inst_t cmd_showfwdall = {
8382         .f = cmd_showfwdall_parsed,
8383         .data = NULL,
8384         .help_str = "show|clear fwd stats all",
8385         .tokens = {
8386                 (void *)&cmd_fwd_action,
8387                 (void *)&cmd_fwd_fwd,
8388                 (void *)&cmd_fwd_stats,
8389                 (void *)&cmd_fwd_all,
8390                 NULL,
8391         },
8392 };
8393
8394 /* *** READ PORT REGISTER *** */
8395 struct cmd_read_reg_result {
8396         cmdline_fixed_string_t read;
8397         cmdline_fixed_string_t reg;
8398         portid_t port_id;
8399         uint32_t reg_off;
8400 };
8401
8402 static void
8403 cmd_read_reg_parsed(void *parsed_result,
8404                     __rte_unused struct cmdline *cl,
8405                     __rte_unused void *data)
8406 {
8407         struct cmd_read_reg_result *res = parsed_result;
8408         port_reg_display(res->port_id, res->reg_off);
8409 }
8410
8411 cmdline_parse_token_string_t cmd_read_reg_read =
8412         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8413 cmdline_parse_token_string_t cmd_read_reg_reg =
8414         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8415 cmdline_parse_token_num_t cmd_read_reg_port_id =
8416         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, RTE_UINT16);
8417 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8418         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, RTE_UINT32);
8419
8420 cmdline_parse_inst_t cmd_read_reg = {
8421         .f = cmd_read_reg_parsed,
8422         .data = NULL,
8423         .help_str = "read reg <port_id> <reg_off>",
8424         .tokens = {
8425                 (void *)&cmd_read_reg_read,
8426                 (void *)&cmd_read_reg_reg,
8427                 (void *)&cmd_read_reg_port_id,
8428                 (void *)&cmd_read_reg_reg_off,
8429                 NULL,
8430         },
8431 };
8432
8433 /* *** READ PORT REGISTER BIT FIELD *** */
8434 struct cmd_read_reg_bit_field_result {
8435         cmdline_fixed_string_t read;
8436         cmdline_fixed_string_t regfield;
8437         portid_t port_id;
8438         uint32_t reg_off;
8439         uint8_t bit1_pos;
8440         uint8_t bit2_pos;
8441 };
8442
8443 static void
8444 cmd_read_reg_bit_field_parsed(void *parsed_result,
8445                               __rte_unused struct cmdline *cl,
8446                               __rte_unused void *data)
8447 {
8448         struct cmd_read_reg_bit_field_result *res = parsed_result;
8449         port_reg_bit_field_display(res->port_id, res->reg_off,
8450                                    res->bit1_pos, res->bit2_pos);
8451 }
8452
8453 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8454         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8455                                  "read");
8456 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8457         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8458                                  regfield, "regfield");
8459 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8460         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8461                               RTE_UINT16);
8462 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8463         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8464                               RTE_UINT32);
8465 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8466         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8467                               RTE_UINT8);
8468 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8469         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8470                               RTE_UINT8);
8471
8472 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8473         .f = cmd_read_reg_bit_field_parsed,
8474         .data = NULL,
8475         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8476         "Read register bit field between bit_x and bit_y included",
8477         .tokens = {
8478                 (void *)&cmd_read_reg_bit_field_read,
8479                 (void *)&cmd_read_reg_bit_field_regfield,
8480                 (void *)&cmd_read_reg_bit_field_port_id,
8481                 (void *)&cmd_read_reg_bit_field_reg_off,
8482                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8483                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8484                 NULL,
8485         },
8486 };
8487
8488 /* *** READ PORT REGISTER BIT *** */
8489 struct cmd_read_reg_bit_result {
8490         cmdline_fixed_string_t read;
8491         cmdline_fixed_string_t regbit;
8492         portid_t port_id;
8493         uint32_t reg_off;
8494         uint8_t bit_pos;
8495 };
8496
8497 static void
8498 cmd_read_reg_bit_parsed(void *parsed_result,
8499                         __rte_unused struct cmdline *cl,
8500                         __rte_unused void *data)
8501 {
8502         struct cmd_read_reg_bit_result *res = parsed_result;
8503         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8504 }
8505
8506 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8507         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8508 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8509         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8510                                  regbit, "regbit");
8511 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8512         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id,
8513                                  RTE_UINT16);
8514 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8515         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off,
8516                                  RTE_UINT32);
8517 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8518         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos,
8519                                  RTE_UINT8);
8520
8521 cmdline_parse_inst_t cmd_read_reg_bit = {
8522         .f = cmd_read_reg_bit_parsed,
8523         .data = NULL,
8524         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8525         .tokens = {
8526                 (void *)&cmd_read_reg_bit_read,
8527                 (void *)&cmd_read_reg_bit_regbit,
8528                 (void *)&cmd_read_reg_bit_port_id,
8529                 (void *)&cmd_read_reg_bit_reg_off,
8530                 (void *)&cmd_read_reg_bit_bit_pos,
8531                 NULL,
8532         },
8533 };
8534
8535 /* *** WRITE PORT REGISTER *** */
8536 struct cmd_write_reg_result {
8537         cmdline_fixed_string_t write;
8538         cmdline_fixed_string_t reg;
8539         portid_t port_id;
8540         uint32_t reg_off;
8541         uint32_t value;
8542 };
8543
8544 static void
8545 cmd_write_reg_parsed(void *parsed_result,
8546                      __rte_unused struct cmdline *cl,
8547                      __rte_unused void *data)
8548 {
8549         struct cmd_write_reg_result *res = parsed_result;
8550         port_reg_set(res->port_id, res->reg_off, res->value);
8551 }
8552
8553 cmdline_parse_token_string_t cmd_write_reg_write =
8554         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8555 cmdline_parse_token_string_t cmd_write_reg_reg =
8556         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8557 cmdline_parse_token_num_t cmd_write_reg_port_id =
8558         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, RTE_UINT16);
8559 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8560         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, RTE_UINT32);
8561 cmdline_parse_token_num_t cmd_write_reg_value =
8562         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, RTE_UINT32);
8563
8564 cmdline_parse_inst_t cmd_write_reg = {
8565         .f = cmd_write_reg_parsed,
8566         .data = NULL,
8567         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8568         .tokens = {
8569                 (void *)&cmd_write_reg_write,
8570                 (void *)&cmd_write_reg_reg,
8571                 (void *)&cmd_write_reg_port_id,
8572                 (void *)&cmd_write_reg_reg_off,
8573                 (void *)&cmd_write_reg_value,
8574                 NULL,
8575         },
8576 };
8577
8578 /* *** WRITE PORT REGISTER BIT FIELD *** */
8579 struct cmd_write_reg_bit_field_result {
8580         cmdline_fixed_string_t write;
8581         cmdline_fixed_string_t regfield;
8582         portid_t port_id;
8583         uint32_t reg_off;
8584         uint8_t bit1_pos;
8585         uint8_t bit2_pos;
8586         uint32_t value;
8587 };
8588
8589 static void
8590 cmd_write_reg_bit_field_parsed(void *parsed_result,
8591                                __rte_unused struct cmdline *cl,
8592                                __rte_unused void *data)
8593 {
8594         struct cmd_write_reg_bit_field_result *res = parsed_result;
8595         port_reg_bit_field_set(res->port_id, res->reg_off,
8596                           res->bit1_pos, res->bit2_pos, res->value);
8597 }
8598
8599 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8600         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8601                                  "write");
8602 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8603         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8604                                  regfield, "regfield");
8605 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8606         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8607                               RTE_UINT16);
8608 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8609         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8610                               RTE_UINT32);
8611 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8612         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8613                               RTE_UINT8);
8614 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8615         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8616                               RTE_UINT8);
8617 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8618         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8619                               RTE_UINT32);
8620
8621 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8622         .f = cmd_write_reg_bit_field_parsed,
8623         .data = NULL,
8624         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8625                 "<reg_value>: "
8626                 "Set register bit field between bit_x and bit_y included",
8627         .tokens = {
8628                 (void *)&cmd_write_reg_bit_field_write,
8629                 (void *)&cmd_write_reg_bit_field_regfield,
8630                 (void *)&cmd_write_reg_bit_field_port_id,
8631                 (void *)&cmd_write_reg_bit_field_reg_off,
8632                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8633                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8634                 (void *)&cmd_write_reg_bit_field_value,
8635                 NULL,
8636         },
8637 };
8638
8639 /* *** WRITE PORT REGISTER BIT *** */
8640 struct cmd_write_reg_bit_result {
8641         cmdline_fixed_string_t write;
8642         cmdline_fixed_string_t regbit;
8643         portid_t port_id;
8644         uint32_t reg_off;
8645         uint8_t bit_pos;
8646         uint8_t value;
8647 };
8648
8649 static void
8650 cmd_write_reg_bit_parsed(void *parsed_result,
8651                          __rte_unused struct cmdline *cl,
8652                          __rte_unused void *data)
8653 {
8654         struct cmd_write_reg_bit_result *res = parsed_result;
8655         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8656 }
8657
8658 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8659         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8660                                  "write");
8661 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8662         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8663                                  regbit, "regbit");
8664 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8665         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id,
8666                                  RTE_UINT16);
8667 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8668         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off,
8669                                  RTE_UINT32);
8670 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8671         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos,
8672                                  RTE_UINT8);
8673 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8674         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value,
8675                                  RTE_UINT8);
8676
8677 cmdline_parse_inst_t cmd_write_reg_bit = {
8678         .f = cmd_write_reg_bit_parsed,
8679         .data = NULL,
8680         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8681                 "0 <= bit_x <= 31",
8682         .tokens = {
8683                 (void *)&cmd_write_reg_bit_write,
8684                 (void *)&cmd_write_reg_bit_regbit,
8685                 (void *)&cmd_write_reg_bit_port_id,
8686                 (void *)&cmd_write_reg_bit_reg_off,
8687                 (void *)&cmd_write_reg_bit_bit_pos,
8688                 (void *)&cmd_write_reg_bit_value,
8689                 NULL,
8690         },
8691 };
8692
8693 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8694 struct cmd_read_rxd_txd_result {
8695         cmdline_fixed_string_t read;
8696         cmdline_fixed_string_t rxd_txd;
8697         portid_t port_id;
8698         uint16_t queue_id;
8699         uint16_t desc_id;
8700 };
8701
8702 static void
8703 cmd_read_rxd_txd_parsed(void *parsed_result,
8704                         __rte_unused struct cmdline *cl,
8705                         __rte_unused void *data)
8706 {
8707         struct cmd_read_rxd_txd_result *res = parsed_result;
8708
8709         if (!strcmp(res->rxd_txd, "rxd"))
8710                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8711         else if (!strcmp(res->rxd_txd, "txd"))
8712                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8713 }
8714
8715 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8716         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8717 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8718         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8719                                  "rxd#txd");
8720 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8721         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id,
8722                                  RTE_UINT16);
8723 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8724         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id,
8725                                  RTE_UINT16);
8726 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8727         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id,
8728                                  RTE_UINT16);
8729
8730 cmdline_parse_inst_t cmd_read_rxd_txd = {
8731         .f = cmd_read_rxd_txd_parsed,
8732         .data = NULL,
8733         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8734         .tokens = {
8735                 (void *)&cmd_read_rxd_txd_read,
8736                 (void *)&cmd_read_rxd_txd_rxd_txd,
8737                 (void *)&cmd_read_rxd_txd_port_id,
8738                 (void *)&cmd_read_rxd_txd_queue_id,
8739                 (void *)&cmd_read_rxd_txd_desc_id,
8740                 NULL,
8741         },
8742 };
8743
8744 /* *** QUIT *** */
8745 struct cmd_quit_result {
8746         cmdline_fixed_string_t quit;
8747 };
8748
8749 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8750                             struct cmdline *cl,
8751                             __rte_unused void *data)
8752 {
8753         cmdline_quit(cl);
8754 }
8755
8756 cmdline_parse_token_string_t cmd_quit_quit =
8757         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8758
8759 cmdline_parse_inst_t cmd_quit = {
8760         .f = cmd_quit_parsed,
8761         .data = NULL,
8762         .help_str = "quit: Exit application",
8763         .tokens = {
8764                 (void *)&cmd_quit_quit,
8765                 NULL,
8766         },
8767 };
8768
8769 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8770 struct cmd_mac_addr_result {
8771         cmdline_fixed_string_t mac_addr_cmd;
8772         cmdline_fixed_string_t what;
8773         uint16_t port_num;
8774         struct rte_ether_addr address;
8775 };
8776
8777 static void cmd_mac_addr_parsed(void *parsed_result,
8778                 __rte_unused struct cmdline *cl,
8779                 __rte_unused void *data)
8780 {
8781         struct cmd_mac_addr_result *res = parsed_result;
8782         int ret;
8783
8784         if (strcmp(res->what, "add") == 0)
8785                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8786         else if (strcmp(res->what, "set") == 0)
8787                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8788                                                        &res->address);
8789         else
8790                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8791
8792         /* check the return value and print it if is < 0 */
8793         if(ret < 0)
8794                 fprintf(stderr, "mac_addr_cmd error: (%s)\n", strerror(-ret));
8795
8796 }
8797
8798 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8799         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8800                                 "mac_addr");
8801 cmdline_parse_token_string_t cmd_mac_addr_what =
8802         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8803                                 "add#remove#set");
8804 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8805                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8806                                         RTE_UINT16);
8807 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8808                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8809
8810 cmdline_parse_inst_t cmd_mac_addr = {
8811         .f = cmd_mac_addr_parsed,
8812         .data = (void *)0,
8813         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8814                         "Add/Remove/Set MAC address on port_id",
8815         .tokens = {
8816                 (void *)&cmd_mac_addr_cmd,
8817                 (void *)&cmd_mac_addr_what,
8818                 (void *)&cmd_mac_addr_portnum,
8819                 (void *)&cmd_mac_addr_addr,
8820                 NULL,
8821         },
8822 };
8823
8824 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8825 struct cmd_eth_peer_result {
8826         cmdline_fixed_string_t set;
8827         cmdline_fixed_string_t eth_peer;
8828         portid_t port_id;
8829         cmdline_fixed_string_t peer_addr;
8830 };
8831
8832 static void cmd_set_eth_peer_parsed(void *parsed_result,
8833                         __rte_unused struct cmdline *cl,
8834                         __rte_unused void *data)
8835 {
8836                 struct cmd_eth_peer_result *res = parsed_result;
8837
8838                 if (test_done == 0) {
8839                         fprintf(stderr, "Please stop forwarding first\n");
8840                         return;
8841                 }
8842                 if (!strcmp(res->eth_peer, "eth-peer")) {
8843                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8844                         fwd_config_setup();
8845                 }
8846 }
8847 cmdline_parse_token_string_t cmd_eth_peer_set =
8848         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8849 cmdline_parse_token_string_t cmd_eth_peer =
8850         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8851 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8852         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id,
8853                 RTE_UINT16);
8854 cmdline_parse_token_string_t cmd_eth_peer_addr =
8855         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8856
8857 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8858         .f = cmd_set_eth_peer_parsed,
8859         .data = NULL,
8860         .help_str = "set eth-peer <port_id> <peer_mac>",
8861         .tokens = {
8862                 (void *)&cmd_eth_peer_set,
8863                 (void *)&cmd_eth_peer,
8864                 (void *)&cmd_eth_peer_port_id,
8865                 (void *)&cmd_eth_peer_addr,
8866                 NULL,
8867         },
8868 };
8869
8870 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8871 struct cmd_set_qmap_result {
8872         cmdline_fixed_string_t set;
8873         cmdline_fixed_string_t qmap;
8874         cmdline_fixed_string_t what;
8875         portid_t port_id;
8876         uint16_t queue_id;
8877         uint8_t map_value;
8878 };
8879
8880 static void
8881 cmd_set_qmap_parsed(void *parsed_result,
8882                        __rte_unused struct cmdline *cl,
8883                        __rte_unused void *data)
8884 {
8885         struct cmd_set_qmap_result *res = parsed_result;
8886         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8887
8888         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8889 }
8890
8891 cmdline_parse_token_string_t cmd_setqmap_set =
8892         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8893                                  set, "set");
8894 cmdline_parse_token_string_t cmd_setqmap_qmap =
8895         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8896                                  qmap, "stat_qmap");
8897 cmdline_parse_token_string_t cmd_setqmap_what =
8898         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8899                                  what, "tx#rx");
8900 cmdline_parse_token_num_t cmd_setqmap_portid =
8901         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8902                               port_id, RTE_UINT16);
8903 cmdline_parse_token_num_t cmd_setqmap_queueid =
8904         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8905                               queue_id, RTE_UINT16);
8906 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8907         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8908                               map_value, RTE_UINT8);
8909
8910 cmdline_parse_inst_t cmd_set_qmap = {
8911         .f = cmd_set_qmap_parsed,
8912         .data = NULL,
8913         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8914                 "Set statistics mapping value on tx|rx queue_id of port_id",
8915         .tokens = {
8916                 (void *)&cmd_setqmap_set,
8917                 (void *)&cmd_setqmap_qmap,
8918                 (void *)&cmd_setqmap_what,
8919                 (void *)&cmd_setqmap_portid,
8920                 (void *)&cmd_setqmap_queueid,
8921                 (void *)&cmd_setqmap_mapvalue,
8922                 NULL,
8923         },
8924 };
8925
8926 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8927 struct cmd_set_xstats_hide_zero_result {
8928         cmdline_fixed_string_t keyword;
8929         cmdline_fixed_string_t name;
8930         cmdline_fixed_string_t on_off;
8931 };
8932
8933 static void
8934 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8935                         __rte_unused struct cmdline *cl,
8936                         __rte_unused void *data)
8937 {
8938         struct cmd_set_xstats_hide_zero_result *res;
8939         uint16_t on_off = 0;
8940
8941         res = parsed_result;
8942         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8943         set_xstats_hide_zero(on_off);
8944 }
8945
8946 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8947         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8948                                  keyword, "set");
8949 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8950         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8951                                  name, "xstats-hide-zero");
8952 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8953         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8954                                  on_off, "on#off");
8955
8956 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8957         .f = cmd_set_xstats_hide_zero_parsed,
8958         .data = NULL,
8959         .help_str = "set xstats-hide-zero on|off",
8960         .tokens = {
8961                 (void *)&cmd_set_xstats_hide_zero_keyword,
8962                 (void *)&cmd_set_xstats_hide_zero_name,
8963                 (void *)&cmd_set_xstats_hide_zero_on_off,
8964                 NULL,
8965         },
8966 };
8967
8968 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8969 struct cmd_set_record_core_cycles_result {
8970         cmdline_fixed_string_t keyword;
8971         cmdline_fixed_string_t name;
8972         cmdline_fixed_string_t on_off;
8973 };
8974
8975 static void
8976 cmd_set_record_core_cycles_parsed(void *parsed_result,
8977                         __rte_unused struct cmdline *cl,
8978                         __rte_unused void *data)
8979 {
8980         struct cmd_set_record_core_cycles_result *res;
8981         uint16_t on_off = 0;
8982
8983         res = parsed_result;
8984         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8985         set_record_core_cycles(on_off);
8986 }
8987
8988 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8989         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8990                                  keyword, "set");
8991 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8992         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8993                                  name, "record-core-cycles");
8994 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8995         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8996                                  on_off, "on#off");
8997
8998 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8999         .f = cmd_set_record_core_cycles_parsed,
9000         .data = NULL,
9001         .help_str = "set record-core-cycles on|off",
9002         .tokens = {
9003                 (void *)&cmd_set_record_core_cycles_keyword,
9004                 (void *)&cmd_set_record_core_cycles_name,
9005                 (void *)&cmd_set_record_core_cycles_on_off,
9006                 NULL,
9007         },
9008 };
9009
9010 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
9011 struct cmd_set_record_burst_stats_result {
9012         cmdline_fixed_string_t keyword;
9013         cmdline_fixed_string_t name;
9014         cmdline_fixed_string_t on_off;
9015 };
9016
9017 static void
9018 cmd_set_record_burst_stats_parsed(void *parsed_result,
9019                         __rte_unused struct cmdline *cl,
9020                         __rte_unused void *data)
9021 {
9022         struct cmd_set_record_burst_stats_result *res;
9023         uint16_t on_off = 0;
9024
9025         res = parsed_result;
9026         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
9027         set_record_burst_stats(on_off);
9028 }
9029
9030 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
9031         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9032                                  keyword, "set");
9033 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
9034         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9035                                  name, "record-burst-stats");
9036 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
9037         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
9038                                  on_off, "on#off");
9039
9040 cmdline_parse_inst_t cmd_set_record_burst_stats = {
9041         .f = cmd_set_record_burst_stats_parsed,
9042         .data = NULL,
9043         .help_str = "set record-burst-stats on|off",
9044         .tokens = {
9045                 (void *)&cmd_set_record_burst_stats_keyword,
9046                 (void *)&cmd_set_record_burst_stats_name,
9047                 (void *)&cmd_set_record_burst_stats_on_off,
9048                 NULL,
9049         },
9050 };
9051
9052 /* *** CONFIGURE UNICAST HASH TABLE *** */
9053 struct cmd_set_uc_hash_table {
9054         cmdline_fixed_string_t set;
9055         cmdline_fixed_string_t port;
9056         portid_t port_id;
9057         cmdline_fixed_string_t what;
9058         struct rte_ether_addr address;
9059         cmdline_fixed_string_t mode;
9060 };
9061
9062 static void
9063 cmd_set_uc_hash_parsed(void *parsed_result,
9064                        __rte_unused struct cmdline *cl,
9065                        __rte_unused void *data)
9066 {
9067         int ret=0;
9068         struct cmd_set_uc_hash_table *res = parsed_result;
9069
9070         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9071
9072         if (strcmp(res->what, "uta") == 0)
9073                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
9074                                                 &res->address,(uint8_t)is_on);
9075         if (ret < 0)
9076                 fprintf(stderr,
9077                         "bad unicast hash table parameter, return code = %d\n",
9078                         ret);
9079
9080 }
9081
9082 cmdline_parse_token_string_t cmd_set_uc_hash_set =
9083         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9084                                  set, "set");
9085 cmdline_parse_token_string_t cmd_set_uc_hash_port =
9086         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9087                                  port, "port");
9088 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
9089         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
9090                               port_id, RTE_UINT16);
9091 cmdline_parse_token_string_t cmd_set_uc_hash_what =
9092         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9093                                  what, "uta");
9094 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
9095         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
9096                                 address);
9097 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
9098         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
9099                                  mode, "on#off");
9100
9101 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
9102         .f = cmd_set_uc_hash_parsed,
9103         .data = NULL,
9104         .help_str = "set port <port_id> uta <mac_addr> on|off)",
9105         .tokens = {
9106                 (void *)&cmd_set_uc_hash_set,
9107                 (void *)&cmd_set_uc_hash_port,
9108                 (void *)&cmd_set_uc_hash_portid,
9109                 (void *)&cmd_set_uc_hash_what,
9110                 (void *)&cmd_set_uc_hash_mac,
9111                 (void *)&cmd_set_uc_hash_mode,
9112                 NULL,
9113         },
9114 };
9115
9116 struct cmd_set_uc_all_hash_table {
9117         cmdline_fixed_string_t set;
9118         cmdline_fixed_string_t port;
9119         portid_t port_id;
9120         cmdline_fixed_string_t what;
9121         cmdline_fixed_string_t value;
9122         cmdline_fixed_string_t mode;
9123 };
9124
9125 static void
9126 cmd_set_uc_all_hash_parsed(void *parsed_result,
9127                        __rte_unused struct cmdline *cl,
9128                        __rte_unused void *data)
9129 {
9130         int ret=0;
9131         struct cmd_set_uc_all_hash_table *res = parsed_result;
9132
9133         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9134
9135         if ((strcmp(res->what, "uta") == 0) &&
9136                 (strcmp(res->value, "all") == 0))
9137                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
9138         if (ret < 0)
9139                 fprintf(stderr,
9140                         "bad unicast hash table parameter, return code = %d\n",
9141                         ret);
9142 }
9143
9144 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
9145         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9146                                  set, "set");
9147 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
9148         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9149                                  port, "port");
9150 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
9151         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
9152                               port_id, RTE_UINT16);
9153 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
9154         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9155                                  what, "uta");
9156 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
9157         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9158                                 value,"all");
9159 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
9160         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
9161                                  mode, "on#off");
9162
9163 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
9164         .f = cmd_set_uc_all_hash_parsed,
9165         .data = NULL,
9166         .help_str = "set port <port_id> uta all on|off",
9167         .tokens = {
9168                 (void *)&cmd_set_uc_all_hash_set,
9169                 (void *)&cmd_set_uc_all_hash_port,
9170                 (void *)&cmd_set_uc_all_hash_portid,
9171                 (void *)&cmd_set_uc_all_hash_what,
9172                 (void *)&cmd_set_uc_all_hash_value,
9173                 (void *)&cmd_set_uc_all_hash_mode,
9174                 NULL,
9175         },
9176 };
9177
9178 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
9179 struct cmd_set_vf_traffic {
9180         cmdline_fixed_string_t set;
9181         cmdline_fixed_string_t port;
9182         portid_t port_id;
9183         cmdline_fixed_string_t vf;
9184         uint8_t vf_id;
9185         cmdline_fixed_string_t what;
9186         cmdline_fixed_string_t mode;
9187 };
9188
9189 static void
9190 cmd_set_vf_traffic_parsed(void *parsed_result,
9191                        __rte_unused struct cmdline *cl,
9192                        __rte_unused void *data)
9193 {
9194         struct cmd_set_vf_traffic *res = parsed_result;
9195         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
9196         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
9197
9198         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
9199 }
9200
9201 cmdline_parse_token_string_t cmd_setvf_traffic_set =
9202         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9203                                  set, "set");
9204 cmdline_parse_token_string_t cmd_setvf_traffic_port =
9205         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9206                                  port, "port");
9207 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
9208         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9209                               port_id, RTE_UINT16);
9210 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
9211         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9212                                  vf, "vf");
9213 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
9214         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
9215                               vf_id, RTE_UINT8);
9216 cmdline_parse_token_string_t cmd_setvf_traffic_what =
9217         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9218                                  what, "tx#rx");
9219 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
9220         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
9221                                  mode, "on#off");
9222
9223 cmdline_parse_inst_t cmd_set_vf_traffic = {
9224         .f = cmd_set_vf_traffic_parsed,
9225         .data = NULL,
9226         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
9227         .tokens = {
9228                 (void *)&cmd_setvf_traffic_set,
9229                 (void *)&cmd_setvf_traffic_port,
9230                 (void *)&cmd_setvf_traffic_portid,
9231                 (void *)&cmd_setvf_traffic_vf,
9232                 (void *)&cmd_setvf_traffic_vfid,
9233                 (void *)&cmd_setvf_traffic_what,
9234                 (void *)&cmd_setvf_traffic_mode,
9235                 NULL,
9236         },
9237 };
9238
9239 /* *** CONFIGURE VF RECEIVE MODE *** */
9240 struct cmd_set_vf_rxmode {
9241         cmdline_fixed_string_t set;
9242         cmdline_fixed_string_t port;
9243         portid_t port_id;
9244         cmdline_fixed_string_t vf;
9245         uint8_t vf_id;
9246         cmdline_fixed_string_t what;
9247         cmdline_fixed_string_t mode;
9248         cmdline_fixed_string_t on;
9249 };
9250
9251 static void
9252 cmd_set_vf_rxmode_parsed(void *parsed_result,
9253                        __rte_unused struct cmdline *cl,
9254                        __rte_unused void *data)
9255 {
9256         int ret = -ENOTSUP;
9257         uint16_t vf_rxmode = 0;
9258         struct cmd_set_vf_rxmode *res = parsed_result;
9259
9260         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
9261         if (!strcmp(res->what,"rxmode")) {
9262                 if (!strcmp(res->mode, "AUPE"))
9263                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_UNTAG;
9264                 else if (!strcmp(res->mode, "ROPE"))
9265                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_HASH_UC;
9266                 else if (!strcmp(res->mode, "BAM"))
9267                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_BROADCAST;
9268                 else if (!strncmp(res->mode, "MPE",3))
9269                         vf_rxmode |= RTE_ETH_VMDQ_ACCEPT_MULTICAST;
9270         }
9271
9272         RTE_SET_USED(is_on);
9273
9274 #ifdef RTE_NET_IXGBE
9275         if (ret == -ENOTSUP)
9276                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
9277                                                   vf_rxmode, (uint8_t)is_on);
9278 #endif
9279 #ifdef RTE_NET_BNXT
9280         if (ret == -ENOTSUP)
9281                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
9282                                                  vf_rxmode, (uint8_t)is_on);
9283 #endif
9284         if (ret < 0)
9285                 fprintf(stderr,
9286                         "bad VF receive mode parameter, return code = %d\n",
9287                         ret);
9288 }
9289
9290 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
9291         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9292                                  set, "set");
9293 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
9294         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9295                                  port, "port");
9296 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
9297         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9298                               port_id, RTE_UINT16);
9299 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
9300         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9301                                  vf, "vf");
9302 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
9303         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
9304                               vf_id, RTE_UINT8);
9305 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
9306         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9307                                  what, "rxmode");
9308 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
9309         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9310                                  mode, "AUPE#ROPE#BAM#MPE");
9311 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
9312         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
9313                                  on, "on#off");
9314
9315 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9316         .f = cmd_set_vf_rxmode_parsed,
9317         .data = NULL,
9318         .help_str = "set port <port_id> vf <vf_id> rxmode "
9319                 "AUPE|ROPE|BAM|MPE on|off",
9320         .tokens = {
9321                 (void *)&cmd_set_vf_rxmode_set,
9322                 (void *)&cmd_set_vf_rxmode_port,
9323                 (void *)&cmd_set_vf_rxmode_portid,
9324                 (void *)&cmd_set_vf_rxmode_vf,
9325                 (void *)&cmd_set_vf_rxmode_vfid,
9326                 (void *)&cmd_set_vf_rxmode_what,
9327                 (void *)&cmd_set_vf_rxmode_mode,
9328                 (void *)&cmd_set_vf_rxmode_on,
9329                 NULL,
9330         },
9331 };
9332
9333 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9334 struct cmd_vf_mac_addr_result {
9335         cmdline_fixed_string_t mac_addr_cmd;
9336         cmdline_fixed_string_t what;
9337         cmdline_fixed_string_t port;
9338         uint16_t port_num;
9339         cmdline_fixed_string_t vf;
9340         uint8_t vf_num;
9341         struct rte_ether_addr address;
9342 };
9343
9344 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9345                 __rte_unused struct cmdline *cl,
9346                 __rte_unused void *data)
9347 {
9348         struct cmd_vf_mac_addr_result *res = parsed_result;
9349         int ret = -ENOTSUP;
9350
9351         if (strcmp(res->what, "add") != 0)
9352                 return;
9353
9354 #ifdef RTE_NET_I40E
9355         if (ret == -ENOTSUP)
9356                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9357                                                    &res->address);
9358 #endif
9359 #ifdef RTE_NET_BNXT
9360         if (ret == -ENOTSUP)
9361                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9362                                                 res->vf_num);
9363 #endif
9364
9365         if(ret < 0)
9366                 fprintf(stderr, "vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9367
9368 }
9369
9370 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9371         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9372                                 mac_addr_cmd,"mac_addr");
9373 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9374         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9375                                 what,"add");
9376 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9377         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9378                                 port,"port");
9379 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9380         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9381                                 port_num, RTE_UINT16);
9382 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9383         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9384                                 vf,"vf");
9385 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9386         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9387                                 vf_num, RTE_UINT8);
9388 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9389         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9390                                 address);
9391
9392 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9393         .f = cmd_vf_mac_addr_parsed,
9394         .data = (void *)0,
9395         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9396                 "Add MAC address filtering for a VF on port_id",
9397         .tokens = {
9398                 (void *)&cmd_vf_mac_addr_cmd,
9399                 (void *)&cmd_vf_mac_addr_what,
9400                 (void *)&cmd_vf_mac_addr_port,
9401                 (void *)&cmd_vf_mac_addr_portnum,
9402                 (void *)&cmd_vf_mac_addr_vf,
9403                 (void *)&cmd_vf_mac_addr_vfnum,
9404                 (void *)&cmd_vf_mac_addr_addr,
9405                 NULL,
9406         },
9407 };
9408
9409 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9410 struct cmd_vf_rx_vlan_filter {
9411         cmdline_fixed_string_t rx_vlan;
9412         cmdline_fixed_string_t what;
9413         uint16_t vlan_id;
9414         cmdline_fixed_string_t port;
9415         portid_t port_id;
9416         cmdline_fixed_string_t vf;
9417         uint64_t vf_mask;
9418 };
9419
9420 static void
9421 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9422                           __rte_unused struct cmdline *cl,
9423                           __rte_unused void *data)
9424 {
9425         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9426         int ret = -ENOTSUP;
9427
9428         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9429
9430 #ifdef RTE_NET_IXGBE
9431         if (ret == -ENOTSUP)
9432                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9433                                 res->vlan_id, res->vf_mask, is_add);
9434 #endif
9435 #ifdef RTE_NET_I40E
9436         if (ret == -ENOTSUP)
9437                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9438                                 res->vlan_id, res->vf_mask, is_add);
9439 #endif
9440 #ifdef RTE_NET_BNXT
9441         if (ret == -ENOTSUP)
9442                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9443                                 res->vlan_id, res->vf_mask, is_add);
9444 #endif
9445
9446         switch (ret) {
9447         case 0:
9448                 break;
9449         case -EINVAL:
9450                 fprintf(stderr, "invalid vlan_id %d or vf_mask %"PRIu64"\n",
9451                         res->vlan_id, res->vf_mask);
9452                 break;
9453         case -ENODEV:
9454                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
9455                 break;
9456         case -ENOTSUP:
9457                 fprintf(stderr, "function not implemented or supported\n");
9458                 break;
9459         default:
9460                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
9461         }
9462 }
9463
9464 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9465         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9466                                  rx_vlan, "rx_vlan");
9467 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9468         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9469                                  what, "add#rm");
9470 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9471         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9472                               vlan_id, RTE_UINT16);
9473 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9474         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9475                                  port, "port");
9476 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9477         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9478                               port_id, RTE_UINT16);
9479 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9480         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9481                                  vf, "vf");
9482 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9483         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9484                               vf_mask, RTE_UINT64);
9485
9486 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9487         .f = cmd_vf_rx_vlan_filter_parsed,
9488         .data = NULL,
9489         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9490                 "(vf_mask = hexadecimal VF mask)",
9491         .tokens = {
9492                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9493                 (void *)&cmd_vf_rx_vlan_filter_what,
9494                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9495                 (void *)&cmd_vf_rx_vlan_filter_port,
9496                 (void *)&cmd_vf_rx_vlan_filter_portid,
9497                 (void *)&cmd_vf_rx_vlan_filter_vf,
9498                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9499                 NULL,
9500         },
9501 };
9502
9503 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9504 struct cmd_queue_rate_limit_result {
9505         cmdline_fixed_string_t set;
9506         cmdline_fixed_string_t port;
9507         uint16_t port_num;
9508         cmdline_fixed_string_t queue;
9509         uint8_t queue_num;
9510         cmdline_fixed_string_t rate;
9511         uint16_t rate_num;
9512 };
9513
9514 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9515                 __rte_unused struct cmdline *cl,
9516                 __rte_unused void *data)
9517 {
9518         struct cmd_queue_rate_limit_result *res = parsed_result;
9519         int ret = 0;
9520
9521         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9522                 && (strcmp(res->queue, "queue") == 0)
9523                 && (strcmp(res->rate, "rate") == 0))
9524                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9525                                         res->rate_num);
9526         if (ret < 0)
9527                 fprintf(stderr, "queue_rate_limit_cmd error: (%s)\n",
9528                         strerror(-ret));
9529
9530 }
9531
9532 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9533         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9534                                 set, "set");
9535 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9536         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9537                                 port, "port");
9538 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9539         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9540                                 port_num, RTE_UINT16);
9541 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9542         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9543                                 queue, "queue");
9544 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9545         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9546                                 queue_num, RTE_UINT8);
9547 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9548         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9549                                 rate, "rate");
9550 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9551         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9552                                 rate_num, RTE_UINT16);
9553
9554 cmdline_parse_inst_t cmd_queue_rate_limit = {
9555         .f = cmd_queue_rate_limit_parsed,
9556         .data = (void *)0,
9557         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9558                 "Set rate limit for a queue on port_id",
9559         .tokens = {
9560                 (void *)&cmd_queue_rate_limit_set,
9561                 (void *)&cmd_queue_rate_limit_port,
9562                 (void *)&cmd_queue_rate_limit_portnum,
9563                 (void *)&cmd_queue_rate_limit_queue,
9564                 (void *)&cmd_queue_rate_limit_queuenum,
9565                 (void *)&cmd_queue_rate_limit_rate,
9566                 (void *)&cmd_queue_rate_limit_ratenum,
9567                 NULL,
9568         },
9569 };
9570
9571 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9572 struct cmd_vf_rate_limit_result {
9573         cmdline_fixed_string_t set;
9574         cmdline_fixed_string_t port;
9575         uint16_t port_num;
9576         cmdline_fixed_string_t vf;
9577         uint8_t vf_num;
9578         cmdline_fixed_string_t rate;
9579         uint16_t rate_num;
9580         cmdline_fixed_string_t q_msk;
9581         uint64_t q_msk_val;
9582 };
9583
9584 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9585                 __rte_unused struct cmdline *cl,
9586                 __rte_unused void *data)
9587 {
9588         struct cmd_vf_rate_limit_result *res = parsed_result;
9589         int ret = 0;
9590
9591         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9592                 && (strcmp(res->vf, "vf") == 0)
9593                 && (strcmp(res->rate, "rate") == 0)
9594                 && (strcmp(res->q_msk, "queue_mask") == 0))
9595                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9596                                         res->rate_num, res->q_msk_val);
9597         if (ret < 0)
9598                 fprintf(stderr, "vf_rate_limit_cmd error: (%s)\n",
9599                         strerror(-ret));
9600
9601 }
9602
9603 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9604         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9605                                 set, "set");
9606 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9607         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9608                                 port, "port");
9609 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9610         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9611                                 port_num, RTE_UINT16);
9612 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9613         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9614                                 vf, "vf");
9615 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9616         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9617                                 vf_num, RTE_UINT8);
9618 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9619         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9620                                 rate, "rate");
9621 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9622         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9623                                 rate_num, RTE_UINT16);
9624 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9625         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9626                                 q_msk, "queue_mask");
9627 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9628         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9629                                 q_msk_val, RTE_UINT64);
9630
9631 cmdline_parse_inst_t cmd_vf_rate_limit = {
9632         .f = cmd_vf_rate_limit_parsed,
9633         .data = (void *)0,
9634         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9635                 "queue_mask <queue_mask_value>: "
9636                 "Set rate limit for queues of VF on port_id",
9637         .tokens = {
9638                 (void *)&cmd_vf_rate_limit_set,
9639                 (void *)&cmd_vf_rate_limit_port,
9640                 (void *)&cmd_vf_rate_limit_portnum,
9641                 (void *)&cmd_vf_rate_limit_vf,
9642                 (void *)&cmd_vf_rate_limit_vfnum,
9643                 (void *)&cmd_vf_rate_limit_rate,
9644                 (void *)&cmd_vf_rate_limit_ratenum,
9645                 (void *)&cmd_vf_rate_limit_q_msk,
9646                 (void *)&cmd_vf_rate_limit_q_msk_val,
9647                 NULL,
9648         },
9649 };
9650
9651 /* *** CONFIGURE TUNNEL UDP PORT *** */
9652 struct cmd_tunnel_udp_config {
9653         cmdline_fixed_string_t rx_vxlan_port;
9654         cmdline_fixed_string_t what;
9655         uint16_t udp_port;
9656         portid_t port_id;
9657 };
9658
9659 static void
9660 cmd_tunnel_udp_config_parsed(void *parsed_result,
9661                           __rte_unused struct cmdline *cl,
9662                           __rte_unused void *data)
9663 {
9664         struct cmd_tunnel_udp_config *res = parsed_result;
9665         struct rte_eth_udp_tunnel tunnel_udp;
9666         int ret;
9667
9668         tunnel_udp.udp_port = res->udp_port;
9669         tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9670
9671         if (!strcmp(res->what, "add"))
9672                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9673                                                       &tunnel_udp);
9674         else
9675                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9676                                                          &tunnel_udp);
9677
9678         if (ret < 0)
9679                 fprintf(stderr, "udp tunneling add error: (%s)\n",
9680                         strerror(-ret));
9681 }
9682
9683 cmdline_parse_token_string_t cmd_tunnel_udp_config_rx_vxlan_port =
9684         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9685                                 rx_vxlan_port, "rx_vxlan_port");
9686 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9687         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9688                                 what, "add#rm");
9689 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9690         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9691                                 udp_port, RTE_UINT16);
9692 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9693         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9694                                 port_id, RTE_UINT16);
9695
9696 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9697         .f = cmd_tunnel_udp_config_parsed,
9698         .data = (void *)0,
9699         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9700                 "Add/Remove a tunneling UDP port filter",
9701         .tokens = {
9702                 (void *)&cmd_tunnel_udp_config_rx_vxlan_port,
9703                 (void *)&cmd_tunnel_udp_config_what,
9704                 (void *)&cmd_tunnel_udp_config_udp_port,
9705                 (void *)&cmd_tunnel_udp_config_port_id,
9706                 NULL,
9707         },
9708 };
9709
9710 struct cmd_config_tunnel_udp_port {
9711         cmdline_fixed_string_t port;
9712         cmdline_fixed_string_t config;
9713         portid_t port_id;
9714         cmdline_fixed_string_t udp_tunnel_port;
9715         cmdline_fixed_string_t action;
9716         cmdline_fixed_string_t tunnel_type;
9717         uint16_t udp_port;
9718 };
9719
9720 static void
9721 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9722                                __rte_unused struct cmdline *cl,
9723                                __rte_unused void *data)
9724 {
9725         struct cmd_config_tunnel_udp_port *res = parsed_result;
9726         struct rte_eth_udp_tunnel tunnel_udp;
9727         int ret = 0;
9728
9729         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9730                 return;
9731
9732         tunnel_udp.udp_port = res->udp_port;
9733
9734         if (!strcmp(res->tunnel_type, "vxlan")) {
9735                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN;
9736         } else if (!strcmp(res->tunnel_type, "geneve")) {
9737                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_GENEVE;
9738         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9739                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_VXLAN_GPE;
9740         } else if (!strcmp(res->tunnel_type, "ecpri")) {
9741                 tunnel_udp.prot_type = RTE_ETH_TUNNEL_TYPE_ECPRI;
9742         } else {
9743                 fprintf(stderr, "Invalid tunnel type\n");
9744                 return;
9745         }
9746
9747         if (!strcmp(res->action, "add"))
9748                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9749                                                       &tunnel_udp);
9750         else
9751                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9752                                                          &tunnel_udp);
9753
9754         if (ret < 0)
9755                 fprintf(stderr, "udp tunneling port add error: (%s)\n",
9756                         strerror(-ret));
9757 }
9758
9759 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9760         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9761                                  "port");
9762 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9763         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9764                                  "config");
9765 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9766         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9767                               RTE_UINT16);
9768 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9769         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9770                                  udp_tunnel_port,
9771                                  "udp_tunnel_port");
9772 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9773         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9774                                  "add#rm");
9775 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9776         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9777                                  "vxlan#geneve#vxlan-gpe#ecpri");
9778 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9779         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9780                               RTE_UINT16);
9781
9782 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9783         .f = cmd_cfg_tunnel_udp_port_parsed,
9784         .data = NULL,
9785         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|"
9786                 "geneve|vxlan-gpe|ecpri <udp_port>",
9787         .tokens = {
9788                 (void *)&cmd_config_tunnel_udp_port_port,
9789                 (void *)&cmd_config_tunnel_udp_port_config,
9790                 (void *)&cmd_config_tunnel_udp_port_port_id,
9791                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9792                 (void *)&cmd_config_tunnel_udp_port_action,
9793                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9794                 (void *)&cmd_config_tunnel_udp_port_value,
9795                 NULL,
9796         },
9797 };
9798
9799 /* ******************************************************************************** */
9800
9801 struct cmd_dump_result {
9802         cmdline_fixed_string_t dump;
9803 };
9804
9805 static void
9806 dump_struct_sizes(void)
9807 {
9808 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9809         DUMP_SIZE(struct rte_mbuf);
9810         DUMP_SIZE(struct rte_mempool);
9811         DUMP_SIZE(struct rte_ring);
9812 #undef DUMP_SIZE
9813 }
9814
9815
9816 /* Dump the socket memory statistics on console */
9817 static void
9818 dump_socket_mem(FILE *f)
9819 {
9820         struct rte_malloc_socket_stats socket_stats;
9821         unsigned int i;
9822         size_t total = 0;
9823         size_t alloc = 0;
9824         size_t free = 0;
9825         unsigned int n_alloc = 0;
9826         unsigned int n_free = 0;
9827         static size_t last_allocs;
9828         static size_t last_total;
9829
9830
9831         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9832                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9833                     !socket_stats.heap_totalsz_bytes)
9834                         continue;
9835                 total += socket_stats.heap_totalsz_bytes;
9836                 alloc += socket_stats.heap_allocsz_bytes;
9837                 free += socket_stats.heap_freesz_bytes;
9838                 n_alloc += socket_stats.alloc_count;
9839                 n_free += socket_stats.free_count;
9840                 fprintf(f,
9841                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9842                         i,
9843                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9844                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9845                         (double)socket_stats.heap_allocsz_bytes * 100 /
9846                         (double)socket_stats.heap_totalsz_bytes,
9847                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9848                         socket_stats.alloc_count,
9849                         socket_stats.free_count);
9850         }
9851         fprintf(f,
9852                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9853                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9854                 total ? ((double)alloc * 100 / (double)total) : 0,
9855                 (double)free / (1024 * 1024),
9856                 n_alloc, n_free);
9857         if (last_allocs)
9858                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9859                         ((double)total - (double)last_total) / (1024 * 1024),
9860                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9861         last_allocs = alloc;
9862         last_total = total;
9863 }
9864
9865 static void cmd_dump_parsed(void *parsed_result,
9866                             __rte_unused struct cmdline *cl,
9867                             __rte_unused void *data)
9868 {
9869         struct cmd_dump_result *res = parsed_result;
9870
9871         if (!strcmp(res->dump, "dump_physmem"))
9872                 rte_dump_physmem_layout(stdout);
9873         else if (!strcmp(res->dump, "dump_socket_mem"))
9874                 dump_socket_mem(stdout);
9875         else if (!strcmp(res->dump, "dump_memzone"))
9876                 rte_memzone_dump(stdout);
9877         else if (!strcmp(res->dump, "dump_struct_sizes"))
9878                 dump_struct_sizes();
9879         else if (!strcmp(res->dump, "dump_ring"))
9880                 rte_ring_list_dump(stdout);
9881         else if (!strcmp(res->dump, "dump_mempool"))
9882                 rte_mempool_list_dump(stdout);
9883         else if (!strcmp(res->dump, "dump_devargs"))
9884                 rte_devargs_dump(stdout);
9885         else if (!strcmp(res->dump, "dump_log_types"))
9886                 rte_log_dump(stdout);
9887 }
9888
9889 cmdline_parse_token_string_t cmd_dump_dump =
9890         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9891                 "dump_physmem#"
9892                 "dump_memzone#"
9893                 "dump_socket_mem#"
9894                 "dump_struct_sizes#"
9895                 "dump_ring#"
9896                 "dump_mempool#"
9897                 "dump_devargs#"
9898                 "dump_log_types");
9899
9900 cmdline_parse_inst_t cmd_dump = {
9901         .f = cmd_dump_parsed,  /* function to call */
9902         .data = NULL,      /* 2nd arg of func */
9903         .help_str = "Dump status",
9904         .tokens = {        /* token list, NULL terminated */
9905                 (void *)&cmd_dump_dump,
9906                 NULL,
9907         },
9908 };
9909
9910 /* ******************************************************************************** */
9911
9912 struct cmd_dump_one_result {
9913         cmdline_fixed_string_t dump;
9914         cmdline_fixed_string_t name;
9915 };
9916
9917 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9918                                 __rte_unused void *data)
9919 {
9920         struct cmd_dump_one_result *res = parsed_result;
9921
9922         if (!strcmp(res->dump, "dump_ring")) {
9923                 struct rte_ring *r;
9924                 r = rte_ring_lookup(res->name);
9925                 if (r == NULL) {
9926                         cmdline_printf(cl, "Cannot find ring\n");
9927                         return;
9928                 }
9929                 rte_ring_dump(stdout, r);
9930         } else if (!strcmp(res->dump, "dump_mempool")) {
9931                 struct rte_mempool *mp;
9932                 mp = rte_mempool_lookup(res->name);
9933                 if (mp == NULL) {
9934                         cmdline_printf(cl, "Cannot find mempool\n");
9935                         return;
9936                 }
9937                 rte_mempool_dump(stdout, mp);
9938         }
9939 }
9940
9941 cmdline_parse_token_string_t cmd_dump_one_dump =
9942         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9943                                  "dump_ring#dump_mempool");
9944
9945 cmdline_parse_token_string_t cmd_dump_one_name =
9946         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9947
9948 cmdline_parse_inst_t cmd_dump_one = {
9949         .f = cmd_dump_one_parsed,  /* function to call */
9950         .data = NULL,      /* 2nd arg of func */
9951         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9952         .tokens = {        /* token list, NULL terminated */
9953                 (void *)&cmd_dump_one_dump,
9954                 (void *)&cmd_dump_one_name,
9955                 NULL,
9956         },
9957 };
9958
9959 /* *** queue region set *** */
9960 struct cmd_queue_region_result {
9961         cmdline_fixed_string_t set;
9962         cmdline_fixed_string_t port;
9963         portid_t port_id;
9964         cmdline_fixed_string_t cmd;
9965         cmdline_fixed_string_t region;
9966         uint8_t  region_id;
9967         cmdline_fixed_string_t queue_start_index;
9968         uint8_t  queue_id;
9969         cmdline_fixed_string_t queue_num;
9970         uint8_t  queue_num_value;
9971 };
9972
9973 static void
9974 cmd_queue_region_parsed(void *parsed_result,
9975                         __rte_unused struct cmdline *cl,
9976                         __rte_unused void *data)
9977 {
9978         struct cmd_queue_region_result *res = parsed_result;
9979         int ret = -ENOTSUP;
9980 #ifdef RTE_NET_I40E
9981         struct rte_pmd_i40e_queue_region_conf region_conf;
9982         enum rte_pmd_i40e_queue_region_op op_type;
9983 #endif
9984
9985         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9986                 return;
9987
9988 #ifdef RTE_NET_I40E
9989         memset(&region_conf, 0, sizeof(region_conf));
9990         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9991         region_conf.region_id = res->region_id;
9992         region_conf.queue_num = res->queue_num_value;
9993         region_conf.queue_start_index = res->queue_id;
9994
9995         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9996                                 op_type, &region_conf);
9997 #endif
9998
9999         switch (ret) {
10000         case 0:
10001                 break;
10002         case -ENOTSUP:
10003                 fprintf(stderr, "function not implemented or supported\n");
10004                 break;
10005         default:
10006                 fprintf(stderr, "queue region config error: (%s)\n",
10007                         strerror(-ret));
10008         }
10009 }
10010
10011 cmdline_parse_token_string_t cmd_queue_region_set =
10012 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10013                 set, "set");
10014 cmdline_parse_token_string_t cmd_queue_region_port =
10015         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10016 cmdline_parse_token_num_t cmd_queue_region_port_id =
10017         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10018                                 port_id, RTE_UINT16);
10019 cmdline_parse_token_string_t cmd_queue_region_cmd =
10020         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10021                                  cmd, "queue-region");
10022 cmdline_parse_token_string_t cmd_queue_region_id =
10023         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10024                                 region, "region_id");
10025 cmdline_parse_token_num_t cmd_queue_region_index =
10026         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10027                                 region_id, RTE_UINT8);
10028 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10029         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10030                                 queue_start_index, "queue_start_index");
10031 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10032         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10033                                 queue_id, RTE_UINT8);
10034 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10035         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10036                                 queue_num, "queue_num");
10037 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10038         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10039                                 queue_num_value, RTE_UINT8);
10040
10041 cmdline_parse_inst_t cmd_queue_region = {
10042         .f = cmd_queue_region_parsed,
10043         .data = NULL,
10044         .help_str = "set port <port_id> queue-region region_id <value> "
10045                 "queue_start_index <value> queue_num <value>: Set a queue region",
10046         .tokens = {
10047                 (void *)&cmd_queue_region_set,
10048                 (void *)&cmd_queue_region_port,
10049                 (void *)&cmd_queue_region_port_id,
10050                 (void *)&cmd_queue_region_cmd,
10051                 (void *)&cmd_queue_region_id,
10052                 (void *)&cmd_queue_region_index,
10053                 (void *)&cmd_queue_region_queue_start_index,
10054                 (void *)&cmd_queue_region_queue_id,
10055                 (void *)&cmd_queue_region_queue_num,
10056                 (void *)&cmd_queue_region_queue_num_value,
10057                 NULL,
10058         },
10059 };
10060
10061 /* *** queue region and flowtype set *** */
10062 struct cmd_region_flowtype_result {
10063         cmdline_fixed_string_t set;
10064         cmdline_fixed_string_t port;
10065         portid_t port_id;
10066         cmdline_fixed_string_t cmd;
10067         cmdline_fixed_string_t region;
10068         uint8_t  region_id;
10069         cmdline_fixed_string_t flowtype;
10070         uint8_t  flowtype_id;
10071 };
10072
10073 static void
10074 cmd_region_flowtype_parsed(void *parsed_result,
10075                         __rte_unused struct cmdline *cl,
10076                         __rte_unused void *data)
10077 {
10078         struct cmd_region_flowtype_result *res = parsed_result;
10079         int ret = -ENOTSUP;
10080 #ifdef RTE_NET_I40E
10081         struct rte_pmd_i40e_queue_region_conf region_conf;
10082         enum rte_pmd_i40e_queue_region_op op_type;
10083 #endif
10084
10085         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10086                 return;
10087
10088 #ifdef RTE_NET_I40E
10089         memset(&region_conf, 0, sizeof(region_conf));
10090
10091         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10092         region_conf.region_id = res->region_id;
10093         region_conf.hw_flowtype = res->flowtype_id;
10094
10095         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10096                         op_type, &region_conf);
10097 #endif
10098
10099         switch (ret) {
10100         case 0:
10101                 break;
10102         case -ENOTSUP:
10103                 fprintf(stderr, "function not implemented or supported\n");
10104                 break;
10105         default:
10106                 fprintf(stderr, "region flowtype config error: (%s)\n",
10107                         strerror(-ret));
10108         }
10109 }
10110
10111 cmdline_parse_token_string_t cmd_region_flowtype_set =
10112 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10113                                 set, "set");
10114 cmdline_parse_token_string_t cmd_region_flowtype_port =
10115         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10116                                 port, "port");
10117 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10118         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10119                                 port_id, RTE_UINT16);
10120 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10121         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10122                                 cmd, "queue-region");
10123 cmdline_parse_token_string_t cmd_region_flowtype_index =
10124         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10125                                 region, "region_id");
10126 cmdline_parse_token_num_t cmd_region_flowtype_id =
10127         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10128                                 region_id, RTE_UINT8);
10129 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10130         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10131                                 flowtype, "flowtype");
10132 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10133         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10134                                 flowtype_id, RTE_UINT8);
10135 cmdline_parse_inst_t cmd_region_flowtype = {
10136         .f = cmd_region_flowtype_parsed,
10137         .data = NULL,
10138         .help_str = "set port <port_id> queue-region region_id <value> "
10139                 "flowtype <value>: Set a flowtype region index",
10140         .tokens = {
10141                 (void *)&cmd_region_flowtype_set,
10142                 (void *)&cmd_region_flowtype_port,
10143                 (void *)&cmd_region_flowtype_port_index,
10144                 (void *)&cmd_region_flowtype_cmd,
10145                 (void *)&cmd_region_flowtype_index,
10146                 (void *)&cmd_region_flowtype_id,
10147                 (void *)&cmd_region_flowtype_flow_index,
10148                 (void *)&cmd_region_flowtype_flow_id,
10149                 NULL,
10150         },
10151 };
10152
10153 /* *** User Priority (UP) to queue region (region_id) set *** */
10154 struct cmd_user_priority_region_result {
10155         cmdline_fixed_string_t set;
10156         cmdline_fixed_string_t port;
10157         portid_t port_id;
10158         cmdline_fixed_string_t cmd;
10159         cmdline_fixed_string_t user_priority;
10160         uint8_t  user_priority_id;
10161         cmdline_fixed_string_t region;
10162         uint8_t  region_id;
10163 };
10164
10165 static void
10166 cmd_user_priority_region_parsed(void *parsed_result,
10167                         __rte_unused struct cmdline *cl,
10168                         __rte_unused void *data)
10169 {
10170         struct cmd_user_priority_region_result *res = parsed_result;
10171         int ret = -ENOTSUP;
10172 #ifdef RTE_NET_I40E
10173         struct rte_pmd_i40e_queue_region_conf region_conf;
10174         enum rte_pmd_i40e_queue_region_op op_type;
10175 #endif
10176
10177         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10178                 return;
10179
10180 #ifdef RTE_NET_I40E
10181         memset(&region_conf, 0, sizeof(region_conf));
10182         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10183         region_conf.user_priority = res->user_priority_id;
10184         region_conf.region_id = res->region_id;
10185
10186         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10187                                 op_type, &region_conf);
10188 #endif
10189
10190         switch (ret) {
10191         case 0:
10192                 break;
10193         case -ENOTSUP:
10194                 fprintf(stderr, "function not implemented or supported\n");
10195                 break;
10196         default:
10197                 fprintf(stderr, "user_priority region config error: (%s)\n",
10198                         strerror(-ret));
10199         }
10200 }
10201
10202 cmdline_parse_token_string_t cmd_user_priority_region_set =
10203         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10204                                 set, "set");
10205 cmdline_parse_token_string_t cmd_user_priority_region_port =
10206         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10207                                 port, "port");
10208 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10209         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10210                                 port_id, RTE_UINT16);
10211 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10212         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10213                                 cmd, "queue-region");
10214 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10215         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10216                                 user_priority, "UP");
10217 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10218         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10219                                 user_priority_id, RTE_UINT8);
10220 cmdline_parse_token_string_t cmd_user_priority_region_region =
10221         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10222                                 region, "region_id");
10223 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10224         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10225                                 region_id, RTE_UINT8);
10226
10227 cmdline_parse_inst_t cmd_user_priority_region = {
10228         .f = cmd_user_priority_region_parsed,
10229         .data = NULL,
10230         .help_str = "set port <port_id> queue-region UP <value> "
10231                 "region_id <value>: Set the mapping of User Priority (UP) "
10232                 "to queue region (region_id) ",
10233         .tokens = {
10234                 (void *)&cmd_user_priority_region_set,
10235                 (void *)&cmd_user_priority_region_port,
10236                 (void *)&cmd_user_priority_region_port_index,
10237                 (void *)&cmd_user_priority_region_cmd,
10238                 (void *)&cmd_user_priority_region_UP,
10239                 (void *)&cmd_user_priority_region_UP_id,
10240                 (void *)&cmd_user_priority_region_region,
10241                 (void *)&cmd_user_priority_region_region_id,
10242                 NULL,
10243         },
10244 };
10245
10246 /* *** flush all queue region related configuration *** */
10247 struct cmd_flush_queue_region_result {
10248         cmdline_fixed_string_t set;
10249         cmdline_fixed_string_t port;
10250         portid_t port_id;
10251         cmdline_fixed_string_t cmd;
10252         cmdline_fixed_string_t flush;
10253         cmdline_fixed_string_t what;
10254 };
10255
10256 static void
10257 cmd_flush_queue_region_parsed(void *parsed_result,
10258                         __rte_unused struct cmdline *cl,
10259                         __rte_unused void *data)
10260 {
10261         struct cmd_flush_queue_region_result *res = parsed_result;
10262         int ret = -ENOTSUP;
10263 #ifdef RTE_NET_I40E
10264         struct rte_pmd_i40e_queue_region_conf region_conf;
10265         enum rte_pmd_i40e_queue_region_op op_type;
10266 #endif
10267
10268         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10269                 return;
10270
10271 #ifdef RTE_NET_I40E
10272         memset(&region_conf, 0, sizeof(region_conf));
10273
10274         if (strcmp(res->what, "on") == 0)
10275                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10276         else
10277                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10278
10279         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10280                                 op_type, &region_conf);
10281 #endif
10282
10283         switch (ret) {
10284         case 0:
10285                 break;
10286         case -ENOTSUP:
10287                 fprintf(stderr, "function not implemented or supported\n");
10288                 break;
10289         default:
10290                 fprintf(stderr, "queue region config flush error: (%s)\n",
10291                         strerror(-ret));
10292         }
10293 }
10294
10295 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10296         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10297                                 set, "set");
10298 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10299         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10300                                 port, "port");
10301 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10302         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10303                                 port_id, RTE_UINT16);
10304 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10305         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10306                                 cmd, "queue-region");
10307 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10308         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10309                                 flush, "flush");
10310 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10311         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10312                                 what, "on#off");
10313
10314 cmdline_parse_inst_t cmd_flush_queue_region = {
10315         .f = cmd_flush_queue_region_parsed,
10316         .data = NULL,
10317         .help_str = "set port <port_id> queue-region flush on|off"
10318                 ": flush all queue region related configuration",
10319         .tokens = {
10320                 (void *)&cmd_flush_queue_region_set,
10321                 (void *)&cmd_flush_queue_region_port,
10322                 (void *)&cmd_flush_queue_region_port_index,
10323                 (void *)&cmd_flush_queue_region_cmd,
10324                 (void *)&cmd_flush_queue_region_flush,
10325                 (void *)&cmd_flush_queue_region_what,
10326                 NULL,
10327         },
10328 };
10329
10330 /* *** get all queue region related configuration info *** */
10331 struct cmd_show_queue_region_info {
10332         cmdline_fixed_string_t show;
10333         cmdline_fixed_string_t port;
10334         portid_t port_id;
10335         cmdline_fixed_string_t cmd;
10336 };
10337
10338 static void
10339 cmd_show_queue_region_info_parsed(void *parsed_result,
10340                         __rte_unused struct cmdline *cl,
10341                         __rte_unused void *data)
10342 {
10343         struct cmd_show_queue_region_info *res = parsed_result;
10344         int ret = -ENOTSUP;
10345 #ifdef RTE_NET_I40E
10346         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10347         enum rte_pmd_i40e_queue_region_op op_type;
10348 #endif
10349
10350         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10351                 return;
10352
10353 #ifdef RTE_NET_I40E
10354         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10355
10356         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10357
10358         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10359                                         op_type, &rte_pmd_regions);
10360
10361         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10362 #endif
10363
10364         switch (ret) {
10365         case 0:
10366                 break;
10367         case -ENOTSUP:
10368                 fprintf(stderr, "function not implemented or supported\n");
10369                 break;
10370         default:
10371                 fprintf(stderr, "queue region config info show error: (%s)\n",
10372                         strerror(-ret));
10373         }
10374 }
10375
10376 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10377 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10378                                 show, "show");
10379 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10380         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10381                                 port, "port");
10382 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10383         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10384                                 port_id, RTE_UINT16);
10385 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10386         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10387                                 cmd, "queue-region");
10388
10389 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10390         .f = cmd_show_queue_region_info_parsed,
10391         .data = NULL,
10392         .help_str = "show port <port_id> queue-region"
10393                 ": show all queue region related configuration info",
10394         .tokens = {
10395                 (void *)&cmd_show_queue_region_info_get,
10396                 (void *)&cmd_show_queue_region_info_port,
10397                 (void *)&cmd_show_queue_region_info_port_index,
10398                 (void *)&cmd_show_queue_region_info_cmd,
10399                 NULL,
10400         },
10401 };
10402
10403 /* *** Filters Control *** */
10404
10405 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10406 do { \
10407         if ((ip_addr).family == AF_INET) \
10408                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10409         else { \
10410                 fprintf(stderr, "invalid parameter.\n"); \
10411                 return; \
10412         } \
10413 } while (0)
10414
10415 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10416 do { \
10417         if ((ip_addr).family == AF_INET6) \
10418                 rte_memcpy(&(ip), \
10419                                  &((ip_addr).addr.ipv6), \
10420                                  sizeof(struct in6_addr)); \
10421         else { \
10422                 fprintf(stderr, "invalid parameter.\n"); \
10423                 return; \
10424         } \
10425 } while (0)
10426
10427 #ifdef RTE_NET_I40E
10428
10429 static uint16_t
10430 str2flowtype(char *string)
10431 {
10432         uint8_t i = 0;
10433         static const struct {
10434                 char str[32];
10435                 uint16_t type;
10436         } flowtype_str[] = {
10437                 {"raw", RTE_ETH_FLOW_RAW},
10438                 {"ipv4", RTE_ETH_FLOW_IPV4},
10439                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10440                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10441                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10442                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10443                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10444                 {"ipv6", RTE_ETH_FLOW_IPV6},
10445                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10446                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10447                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10448                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10449                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10450                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10451                 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
10452                 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
10453                 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
10454                 {"gtpu", RTE_ETH_FLOW_GTPU},
10455         };
10456
10457         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10458                 if (!strcmp(flowtype_str[i].str, string))
10459                         return flowtype_str[i].type;
10460         }
10461
10462         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10463                 return (uint16_t)atoi(string);
10464
10465         return RTE_ETH_FLOW_UNKNOWN;
10466 }
10467
10468 /* *** deal with flow director filter *** */
10469 struct cmd_flow_director_result {
10470         cmdline_fixed_string_t flow_director_filter;
10471         portid_t port_id;
10472         cmdline_fixed_string_t mode;
10473         cmdline_fixed_string_t mode_value;
10474         cmdline_fixed_string_t ops;
10475         cmdline_fixed_string_t flow;
10476         cmdline_fixed_string_t flow_type;
10477         cmdline_fixed_string_t drop;
10478         cmdline_fixed_string_t queue;
10479         uint16_t  queue_id;
10480         cmdline_fixed_string_t fd_id;
10481         uint32_t  fd_id_value;
10482         cmdline_fixed_string_t packet;
10483         char filepath[];
10484 };
10485
10486 static void
10487 cmd_flow_director_filter_parsed(void *parsed_result,
10488                           __rte_unused struct cmdline *cl,
10489                           __rte_unused void *data)
10490 {
10491         struct cmd_flow_director_result *res = parsed_result;
10492         int ret = 0;
10493         struct rte_pmd_i40e_flow_type_mapping
10494                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10495         struct rte_pmd_i40e_pkt_template_conf conf;
10496         uint16_t flow_type = str2flowtype(res->flow_type);
10497         uint16_t i, port = res->port_id;
10498         uint8_t add;
10499
10500         memset(&conf, 0, sizeof(conf));
10501
10502         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10503                 fprintf(stderr, "Invalid flow type specified.\n");
10504                 return;
10505         }
10506         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10507                                                  mapping);
10508         if (ret)
10509                 return;
10510         if (mapping[flow_type].pctype == 0ULL) {
10511                 fprintf(stderr, "Invalid flow type specified.\n");
10512                 return;
10513         }
10514         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10515                 if (mapping[flow_type].pctype & (1ULL << i)) {
10516                         conf.input.pctype = i;
10517                         break;
10518                 }
10519         }
10520
10521         conf.input.packet = open_file(res->filepath,
10522                                 &conf.input.length);
10523         if (!conf.input.packet)
10524                 return;
10525         if (!strcmp(res->drop, "drop"))
10526                 conf.action.behavior =
10527                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10528         else
10529                 conf.action.behavior =
10530                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10531         conf.action.report_status =
10532                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10533         conf.action.rx_queue = res->queue_id;
10534         conf.soft_id = res->fd_id_value;
10535         add  = strcmp(res->ops, "del") ? 1 : 0;
10536         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10537                                                         &conf,
10538                                                         add);
10539         if (ret < 0)
10540                 fprintf(stderr, "flow director config error: (%s)\n",
10541                         strerror(-ret));
10542         close_file(conf.input.packet);
10543 }
10544
10545 cmdline_parse_token_string_t cmd_flow_director_filter =
10546         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10547                                  flow_director_filter, "flow_director_filter");
10548 cmdline_parse_token_num_t cmd_flow_director_port_id =
10549         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10550                               port_id, RTE_UINT16);
10551 cmdline_parse_token_string_t cmd_flow_director_ops =
10552         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10553                                  ops, "add#del#update");
10554 cmdline_parse_token_string_t cmd_flow_director_flow =
10555         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10556                                  flow, "flow");
10557 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10558         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10559                 flow_type, NULL);
10560 cmdline_parse_token_string_t cmd_flow_director_drop =
10561         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10562                                  drop, "drop#fwd");
10563 cmdline_parse_token_string_t cmd_flow_director_queue =
10564         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10565                                  queue, "queue");
10566 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10567         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10568                               queue_id, RTE_UINT16);
10569 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10570         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10571                                  fd_id, "fd_id");
10572 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10573         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10574                               fd_id_value, RTE_UINT32);
10575
10576 cmdline_parse_token_string_t cmd_flow_director_mode =
10577         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10578                                  mode, "mode");
10579 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10580         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10581                                  mode_value, "raw");
10582 cmdline_parse_token_string_t cmd_flow_director_packet =
10583         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10584                                  packet, "packet");
10585 cmdline_parse_token_string_t cmd_flow_director_filepath =
10586         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10587                                  filepath, NULL);
10588
10589 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10590         .f = cmd_flow_director_filter_parsed,
10591         .data = NULL,
10592         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10593                 "director entry on NIC",
10594         .tokens = {
10595                 (void *)&cmd_flow_director_filter,
10596                 (void *)&cmd_flow_director_port_id,
10597                 (void *)&cmd_flow_director_mode,
10598                 (void *)&cmd_flow_director_mode_raw,
10599                 (void *)&cmd_flow_director_ops,
10600                 (void *)&cmd_flow_director_flow,
10601                 (void *)&cmd_flow_director_flow_type,
10602                 (void *)&cmd_flow_director_drop,
10603                 (void *)&cmd_flow_director_queue,
10604                 (void *)&cmd_flow_director_queue_id,
10605                 (void *)&cmd_flow_director_fd_id,
10606                 (void *)&cmd_flow_director_fd_id_value,
10607                 (void *)&cmd_flow_director_packet,
10608                 (void *)&cmd_flow_director_filepath,
10609                 NULL,
10610         },
10611 };
10612
10613 #endif /* RTE_NET_I40E */
10614
10615 /* *** deal with flow director mask *** */
10616 struct cmd_flow_director_mask_result {
10617         cmdline_fixed_string_t flow_director_mask;
10618         portid_t port_id;
10619         cmdline_fixed_string_t mode;
10620         cmdline_fixed_string_t mode_value;
10621         cmdline_fixed_string_t vlan;
10622         uint16_t vlan_mask;
10623         cmdline_fixed_string_t src_mask;
10624         cmdline_ipaddr_t ipv4_src;
10625         cmdline_ipaddr_t ipv6_src;
10626         uint16_t port_src;
10627         cmdline_fixed_string_t dst_mask;
10628         cmdline_ipaddr_t ipv4_dst;
10629         cmdline_ipaddr_t ipv6_dst;
10630         uint16_t port_dst;
10631         cmdline_fixed_string_t mac;
10632         uint8_t mac_addr_byte_mask;
10633         cmdline_fixed_string_t tunnel_id;
10634         uint32_t tunnel_id_mask;
10635         cmdline_fixed_string_t tunnel_type;
10636         uint8_t tunnel_type_mask;
10637 };
10638
10639 static void
10640 cmd_flow_director_mask_parsed(void *parsed_result,
10641                           __rte_unused struct cmdline *cl,
10642                           __rte_unused void *data)
10643 {
10644         struct cmd_flow_director_mask_result *res = parsed_result;
10645         struct rte_eth_fdir_masks *mask;
10646         struct rte_port *port;
10647
10648         port = &ports[res->port_id];
10649         /** Check if the port is not started **/
10650         if (port->port_status != RTE_PORT_STOPPED) {
10651                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10652                 return;
10653         }
10654
10655         mask = &port->dev_conf.fdir_conf.mask;
10656
10657         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10658                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10659                         fprintf(stderr, "Please set mode to MAC-VLAN.\n");
10660                         return;
10661                 }
10662
10663                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10664         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10665                 if (strcmp(res->mode_value, "Tunnel")) {
10666                         fprintf(stderr, "Please set mode to Tunnel.\n");
10667                         return;
10668                 }
10669
10670                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10671                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10672                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10673                 mask->tunnel_type_mask = res->tunnel_type_mask;
10674         } else {
10675                 if (strcmp(res->mode_value, "IP")) {
10676                         fprintf(stderr, "Please set mode to IP.\n");
10677                         return;
10678                 }
10679
10680                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10681                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10682                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10683                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10684                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10685                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10686                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10687         }
10688
10689         cmd_reconfig_device_queue(res->port_id, 1, 1);
10690 }
10691
10692 cmdline_parse_token_string_t cmd_flow_director_mask =
10693         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10694                                  flow_director_mask, "flow_director_mask");
10695 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10696         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10697                               port_id, RTE_UINT16);
10698 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10700                                  vlan, "vlan");
10701 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10702         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10703                               vlan_mask, RTE_UINT16);
10704 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10705         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10706                                  src_mask, "src_mask");
10707 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10708         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10709                                  ipv4_src);
10710 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10711         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10712                                  ipv6_src);
10713 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10714         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10715                               port_src, RTE_UINT16);
10716 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10718                                  dst_mask, "dst_mask");
10719 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10720         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10721                                  ipv4_dst);
10722 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10723         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10724                                  ipv6_dst);
10725 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10726         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10727                               port_dst, RTE_UINT16);
10728
10729 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10730         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10731                                  mode, "mode");
10732 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10733         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10734                                  mode_value, "IP");
10735 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10736         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10737                                  mode_value, "MAC-VLAN");
10738 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10739         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10740                                  mode_value, "Tunnel");
10741 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10743                                  mac, "mac");
10744 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10745         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10746                               mac_addr_byte_mask, RTE_UINT8);
10747 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10749                                  tunnel_type, "tunnel-type");
10750 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10751         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10752                               tunnel_type_mask, RTE_UINT8);
10753 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10755                                  tunnel_id, "tunnel-id");
10756 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10757         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10758                               tunnel_id_mask, RTE_UINT32);
10759
10760 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10761         .f = cmd_flow_director_mask_parsed,
10762         .data = NULL,
10763         .help_str = "flow_director_mask ... : "
10764                 "Set IP mode flow director's mask on NIC",
10765         .tokens = {
10766                 (void *)&cmd_flow_director_mask,
10767                 (void *)&cmd_flow_director_mask_port_id,
10768                 (void *)&cmd_flow_director_mask_mode,
10769                 (void *)&cmd_flow_director_mask_mode_ip,
10770                 (void *)&cmd_flow_director_mask_vlan,
10771                 (void *)&cmd_flow_director_mask_vlan_value,
10772                 (void *)&cmd_flow_director_mask_src,
10773                 (void *)&cmd_flow_director_mask_ipv4_src,
10774                 (void *)&cmd_flow_director_mask_ipv6_src,
10775                 (void *)&cmd_flow_director_mask_port_src,
10776                 (void *)&cmd_flow_director_mask_dst,
10777                 (void *)&cmd_flow_director_mask_ipv4_dst,
10778                 (void *)&cmd_flow_director_mask_ipv6_dst,
10779                 (void *)&cmd_flow_director_mask_port_dst,
10780                 NULL,
10781         },
10782 };
10783
10784 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10785         .f = cmd_flow_director_mask_parsed,
10786         .data = NULL,
10787         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10788                 "flow director's mask on NIC",
10789         .tokens = {
10790                 (void *)&cmd_flow_director_mask,
10791                 (void *)&cmd_flow_director_mask_port_id,
10792                 (void *)&cmd_flow_director_mask_mode,
10793                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10794                 (void *)&cmd_flow_director_mask_vlan,
10795                 (void *)&cmd_flow_director_mask_vlan_value,
10796                 NULL,
10797         },
10798 };
10799
10800 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10801         .f = cmd_flow_director_mask_parsed,
10802         .data = NULL,
10803         .help_str = "flow_director_mask ... : Set tunnel mode "
10804                 "flow director's mask on NIC",
10805         .tokens = {
10806                 (void *)&cmd_flow_director_mask,
10807                 (void *)&cmd_flow_director_mask_port_id,
10808                 (void *)&cmd_flow_director_mask_mode,
10809                 (void *)&cmd_flow_director_mask_mode_tunnel,
10810                 (void *)&cmd_flow_director_mask_vlan,
10811                 (void *)&cmd_flow_director_mask_vlan_value,
10812                 (void *)&cmd_flow_director_mask_mac,
10813                 (void *)&cmd_flow_director_mask_mac_value,
10814                 (void *)&cmd_flow_director_mask_tunnel_type,
10815                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10816                 (void *)&cmd_flow_director_mask_tunnel_id,
10817                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10818                 NULL,
10819         },
10820 };
10821
10822 /* *** deal with flow director flexible payload configuration *** */
10823 struct cmd_flow_director_flexpayload_result {
10824         cmdline_fixed_string_t flow_director_flexpayload;
10825         portid_t port_id;
10826         cmdline_fixed_string_t payload_layer;
10827         cmdline_fixed_string_t payload_cfg;
10828 };
10829
10830 static inline int
10831 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10832 {
10833         char s[256];
10834         const char *p, *p0 = q_arg;
10835         char *end;
10836         unsigned long int_fld;
10837         char *str_fld[max_num];
10838         int i;
10839         unsigned size;
10840         int ret = -1;
10841
10842         p = strchr(p0, '(');
10843         if (p == NULL)
10844                 return -1;
10845         ++p;
10846         p0 = strchr(p, ')');
10847         if (p0 == NULL)
10848                 return -1;
10849
10850         size = p0 - p;
10851         if (size >= sizeof(s))
10852                 return -1;
10853
10854         snprintf(s, sizeof(s), "%.*s", size, p);
10855         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10856         if (ret < 0 || ret > max_num)
10857                 return -1;
10858         for (i = 0; i < ret; i++) {
10859                 errno = 0;
10860                 int_fld = strtoul(str_fld[i], &end, 0);
10861                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10862                         return -1;
10863                 offsets[i] = (uint16_t)int_fld;
10864         }
10865         return ret;
10866 }
10867
10868 static void
10869 cmd_flow_director_flxpld_parsed(void *parsed_result,
10870                           __rte_unused struct cmdline *cl,
10871                           __rte_unused void *data)
10872 {
10873         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10874         struct rte_eth_flex_payload_cfg flex_cfg;
10875         struct rte_port *port;
10876         int ret = 0;
10877
10878         port = &ports[res->port_id];
10879         /** Check if the port is not started **/
10880         if (port->port_status != RTE_PORT_STOPPED) {
10881                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
10882                 return;
10883         }
10884
10885         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10886
10887         if (!strcmp(res->payload_layer, "raw"))
10888                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10889         else if (!strcmp(res->payload_layer, "l2"))
10890                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10891         else if (!strcmp(res->payload_layer, "l3"))
10892                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10893         else if (!strcmp(res->payload_layer, "l4"))
10894                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10895
10896         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10897                             RTE_ETH_FDIR_MAX_FLEXLEN);
10898         if (ret < 0) {
10899                 fprintf(stderr, "error: Cannot parse flex payload input.\n");
10900                 return;
10901         }
10902
10903         fdir_set_flex_payload(res->port_id, &flex_cfg);
10904         cmd_reconfig_device_queue(res->port_id, 1, 1);
10905 }
10906
10907 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10909                                  flow_director_flexpayload,
10910                                  "flow_director_flex_payload");
10911 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10912         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10913                               port_id, RTE_UINT16);
10914 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10915         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10916                                  payload_layer, "raw#l2#l3#l4");
10917 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10918         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10919                                  payload_cfg, NULL);
10920
10921 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10922         .f = cmd_flow_director_flxpld_parsed,
10923         .data = NULL,
10924         .help_str = "flow_director_flexpayload ... : "
10925                 "Set flow director's flex payload on NIC",
10926         .tokens = {
10927                 (void *)&cmd_flow_director_flexpayload,
10928                 (void *)&cmd_flow_director_flexpayload_port_id,
10929                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10930                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10931                 NULL,
10932         },
10933 };
10934
10935 /* Generic flow interface command. */
10936 extern cmdline_parse_inst_t cmd_flow;
10937
10938 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
10939 struct cmd_mcast_addr_result {
10940         cmdline_fixed_string_t mcast_addr_cmd;
10941         cmdline_fixed_string_t what;
10942         uint16_t port_num;
10943         struct rte_ether_addr mc_addr;
10944 };
10945
10946 static void cmd_mcast_addr_parsed(void *parsed_result,
10947                 __rte_unused struct cmdline *cl,
10948                 __rte_unused void *data)
10949 {
10950         struct cmd_mcast_addr_result *res = parsed_result;
10951
10952         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
10953                 fprintf(stderr,
10954                         "Invalid multicast addr " RTE_ETHER_ADDR_PRT_FMT "\n",
10955                         RTE_ETHER_ADDR_BYTES(&res->mc_addr));
10956                 return;
10957         }
10958         if (strcmp(res->what, "add") == 0)
10959                 mcast_addr_add(res->port_num, &res->mc_addr);
10960         else
10961                 mcast_addr_remove(res->port_num, &res->mc_addr);
10962 }
10963
10964 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
10965         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
10966                                  mcast_addr_cmd, "mcast_addr");
10967 cmdline_parse_token_string_t cmd_mcast_addr_what =
10968         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
10969                                  "add#remove");
10970 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
10971         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num,
10972                                  RTE_UINT16);
10973 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
10974         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
10975
10976 cmdline_parse_inst_t cmd_mcast_addr = {
10977         .f = cmd_mcast_addr_parsed,
10978         .data = (void *)0,
10979         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
10980                 "Add/Remove multicast MAC address on port_id",
10981         .tokens = {
10982                 (void *)&cmd_mcast_addr_cmd,
10983                 (void *)&cmd_mcast_addr_what,
10984                 (void *)&cmd_mcast_addr_portnum,
10985                 (void *)&cmd_mcast_addr_addr,
10986                 NULL,
10987         },
10988 };
10989
10990 /* vf vlan anti spoof configuration */
10991
10992 /* Common result structure for vf vlan anti spoof */
10993 struct cmd_vf_vlan_anti_spoof_result {
10994         cmdline_fixed_string_t set;
10995         cmdline_fixed_string_t vf;
10996         cmdline_fixed_string_t vlan;
10997         cmdline_fixed_string_t antispoof;
10998         portid_t port_id;
10999         uint32_t vf_id;
11000         cmdline_fixed_string_t on_off;
11001 };
11002
11003 /* Common CLI fields for vf vlan anti spoof enable disable */
11004 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
11005         TOKEN_STRING_INITIALIZER
11006                 (struct cmd_vf_vlan_anti_spoof_result,
11007                  set, "set");
11008 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
11009         TOKEN_STRING_INITIALIZER
11010                 (struct cmd_vf_vlan_anti_spoof_result,
11011                  vf, "vf");
11012 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
11013         TOKEN_STRING_INITIALIZER
11014                 (struct cmd_vf_vlan_anti_spoof_result,
11015                  vlan, "vlan");
11016 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
11017         TOKEN_STRING_INITIALIZER
11018                 (struct cmd_vf_vlan_anti_spoof_result,
11019                  antispoof, "antispoof");
11020 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
11021         TOKEN_NUM_INITIALIZER
11022                 (struct cmd_vf_vlan_anti_spoof_result,
11023                  port_id, RTE_UINT16);
11024 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
11025         TOKEN_NUM_INITIALIZER
11026                 (struct cmd_vf_vlan_anti_spoof_result,
11027                  vf_id, RTE_UINT32);
11028 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
11029         TOKEN_STRING_INITIALIZER
11030                 (struct cmd_vf_vlan_anti_spoof_result,
11031                  on_off, "on#off");
11032
11033 static void
11034 cmd_set_vf_vlan_anti_spoof_parsed(
11035         void *parsed_result,
11036         __rte_unused struct cmdline *cl,
11037         __rte_unused void *data)
11038 {
11039         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
11040         int ret = -ENOTSUP;
11041
11042         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11043
11044         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11045                 return;
11046
11047 #ifdef RTE_NET_IXGBE
11048         if (ret == -ENOTSUP)
11049                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
11050                                 res->vf_id, is_on);
11051 #endif
11052 #ifdef RTE_NET_I40E
11053         if (ret == -ENOTSUP)
11054                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
11055                                 res->vf_id, is_on);
11056 #endif
11057 #ifdef RTE_NET_BNXT
11058         if (ret == -ENOTSUP)
11059                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
11060                                 res->vf_id, is_on);
11061 #endif
11062
11063         switch (ret) {
11064         case 0:
11065                 break;
11066         case -EINVAL:
11067                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
11068                 break;
11069         case -ENODEV:
11070                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11071                 break;
11072         case -ENOTSUP:
11073                 fprintf(stderr, "function not implemented\n");
11074                 break;
11075         default:
11076                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11077         }
11078 }
11079
11080 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
11081         .f = cmd_set_vf_vlan_anti_spoof_parsed,
11082         .data = NULL,
11083         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
11084         .tokens = {
11085                 (void *)&cmd_vf_vlan_anti_spoof_set,
11086                 (void *)&cmd_vf_vlan_anti_spoof_vf,
11087                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
11088                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
11089                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
11090                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
11091                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
11092                 NULL,
11093         },
11094 };
11095
11096 /* vf mac anti spoof configuration */
11097
11098 /* Common result structure for vf mac anti spoof */
11099 struct cmd_vf_mac_anti_spoof_result {
11100         cmdline_fixed_string_t set;
11101         cmdline_fixed_string_t vf;
11102         cmdline_fixed_string_t mac;
11103         cmdline_fixed_string_t antispoof;
11104         portid_t port_id;
11105         uint32_t vf_id;
11106         cmdline_fixed_string_t on_off;
11107 };
11108
11109 /* Common CLI fields for vf mac anti spoof enable disable */
11110 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
11111         TOKEN_STRING_INITIALIZER
11112                 (struct cmd_vf_mac_anti_spoof_result,
11113                  set, "set");
11114 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
11115         TOKEN_STRING_INITIALIZER
11116                 (struct cmd_vf_mac_anti_spoof_result,
11117                  vf, "vf");
11118 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
11119         TOKEN_STRING_INITIALIZER
11120                 (struct cmd_vf_mac_anti_spoof_result,
11121                  mac, "mac");
11122 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
11123         TOKEN_STRING_INITIALIZER
11124                 (struct cmd_vf_mac_anti_spoof_result,
11125                  antispoof, "antispoof");
11126 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
11127         TOKEN_NUM_INITIALIZER
11128                 (struct cmd_vf_mac_anti_spoof_result,
11129                  port_id, RTE_UINT16);
11130 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
11131         TOKEN_NUM_INITIALIZER
11132                 (struct cmd_vf_mac_anti_spoof_result,
11133                  vf_id, RTE_UINT32);
11134 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
11135         TOKEN_STRING_INITIALIZER
11136                 (struct cmd_vf_mac_anti_spoof_result,
11137                  on_off, "on#off");
11138
11139 static void
11140 cmd_set_vf_mac_anti_spoof_parsed(
11141         void *parsed_result,
11142         __rte_unused struct cmdline *cl,
11143         __rte_unused void *data)
11144 {
11145         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
11146         int ret = -ENOTSUP;
11147
11148         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11149
11150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11151                 return;
11152
11153 #ifdef RTE_NET_IXGBE
11154         if (ret == -ENOTSUP)
11155                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
11156                         res->vf_id, is_on);
11157 #endif
11158 #ifdef RTE_NET_I40E
11159         if (ret == -ENOTSUP)
11160                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
11161                         res->vf_id, is_on);
11162 #endif
11163 #ifdef RTE_NET_BNXT
11164         if (ret == -ENOTSUP)
11165                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
11166                         res->vf_id, is_on);
11167 #endif
11168
11169         switch (ret) {
11170         case 0:
11171                 break;
11172         case -EINVAL:
11173                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11174                         res->vf_id, is_on);
11175                 break;
11176         case -ENODEV:
11177                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11178                 break;
11179         case -ENOTSUP:
11180                 fprintf(stderr, "function not implemented\n");
11181                 break;
11182         default:
11183                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11184         }
11185 }
11186
11187 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
11188         .f = cmd_set_vf_mac_anti_spoof_parsed,
11189         .data = NULL,
11190         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
11191         .tokens = {
11192                 (void *)&cmd_vf_mac_anti_spoof_set,
11193                 (void *)&cmd_vf_mac_anti_spoof_vf,
11194                 (void *)&cmd_vf_mac_anti_spoof_mac,
11195                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
11196                 (void *)&cmd_vf_mac_anti_spoof_port_id,
11197                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
11198                 (void *)&cmd_vf_mac_anti_spoof_on_off,
11199                 NULL,
11200         },
11201 };
11202
11203 /* vf vlan strip queue configuration */
11204
11205 /* Common result structure for vf mac anti spoof */
11206 struct cmd_vf_vlan_stripq_result {
11207         cmdline_fixed_string_t set;
11208         cmdline_fixed_string_t vf;
11209         cmdline_fixed_string_t vlan;
11210         cmdline_fixed_string_t stripq;
11211         portid_t port_id;
11212         uint16_t vf_id;
11213         cmdline_fixed_string_t on_off;
11214 };
11215
11216 /* Common CLI fields for vf vlan strip enable disable */
11217 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
11218         TOKEN_STRING_INITIALIZER
11219                 (struct cmd_vf_vlan_stripq_result,
11220                  set, "set");
11221 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
11222         TOKEN_STRING_INITIALIZER
11223                 (struct cmd_vf_vlan_stripq_result,
11224                  vf, "vf");
11225 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
11226         TOKEN_STRING_INITIALIZER
11227                 (struct cmd_vf_vlan_stripq_result,
11228                  vlan, "vlan");
11229 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
11230         TOKEN_STRING_INITIALIZER
11231                 (struct cmd_vf_vlan_stripq_result,
11232                  stripq, "stripq");
11233 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
11234         TOKEN_NUM_INITIALIZER
11235                 (struct cmd_vf_vlan_stripq_result,
11236                  port_id, RTE_UINT16);
11237 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
11238         TOKEN_NUM_INITIALIZER
11239                 (struct cmd_vf_vlan_stripq_result,
11240                  vf_id, RTE_UINT16);
11241 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
11242         TOKEN_STRING_INITIALIZER
11243                 (struct cmd_vf_vlan_stripq_result,
11244                  on_off, "on#off");
11245
11246 static void
11247 cmd_set_vf_vlan_stripq_parsed(
11248         void *parsed_result,
11249         __rte_unused struct cmdline *cl,
11250         __rte_unused void *data)
11251 {
11252         struct cmd_vf_vlan_stripq_result *res = parsed_result;
11253         int ret = -ENOTSUP;
11254
11255         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11256
11257         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11258                 return;
11259
11260 #ifdef RTE_NET_IXGBE
11261         if (ret == -ENOTSUP)
11262                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
11263                         res->vf_id, is_on);
11264 #endif
11265 #ifdef RTE_NET_I40E
11266         if (ret == -ENOTSUP)
11267                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
11268                         res->vf_id, is_on);
11269 #endif
11270 #ifdef RTE_NET_BNXT
11271         if (ret == -ENOTSUP)
11272                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
11273                         res->vf_id, is_on);
11274 #endif
11275
11276         switch (ret) {
11277         case 0:
11278                 break;
11279         case -EINVAL:
11280                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11281                         res->vf_id, is_on);
11282                 break;
11283         case -ENODEV:
11284                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11285                 break;
11286         case -ENOTSUP:
11287                 fprintf(stderr, "function not implemented\n");
11288                 break;
11289         default:
11290                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11291         }
11292 }
11293
11294 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
11295         .f = cmd_set_vf_vlan_stripq_parsed,
11296         .data = NULL,
11297         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
11298         .tokens = {
11299                 (void *)&cmd_vf_vlan_stripq_set,
11300                 (void *)&cmd_vf_vlan_stripq_vf,
11301                 (void *)&cmd_vf_vlan_stripq_vlan,
11302                 (void *)&cmd_vf_vlan_stripq_stripq,
11303                 (void *)&cmd_vf_vlan_stripq_port_id,
11304                 (void *)&cmd_vf_vlan_stripq_vf_id,
11305                 (void *)&cmd_vf_vlan_stripq_on_off,
11306                 NULL,
11307         },
11308 };
11309
11310 /* vf vlan insert configuration */
11311
11312 /* Common result structure for vf vlan insert */
11313 struct cmd_vf_vlan_insert_result {
11314         cmdline_fixed_string_t set;
11315         cmdline_fixed_string_t vf;
11316         cmdline_fixed_string_t vlan;
11317         cmdline_fixed_string_t insert;
11318         portid_t port_id;
11319         uint16_t vf_id;
11320         uint16_t vlan_id;
11321 };
11322
11323 /* Common CLI fields for vf vlan insert enable disable */
11324 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
11325         TOKEN_STRING_INITIALIZER
11326                 (struct cmd_vf_vlan_insert_result,
11327                  set, "set");
11328 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
11329         TOKEN_STRING_INITIALIZER
11330                 (struct cmd_vf_vlan_insert_result,
11331                  vf, "vf");
11332 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
11333         TOKEN_STRING_INITIALIZER
11334                 (struct cmd_vf_vlan_insert_result,
11335                  vlan, "vlan");
11336 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
11337         TOKEN_STRING_INITIALIZER
11338                 (struct cmd_vf_vlan_insert_result,
11339                  insert, "insert");
11340 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
11341         TOKEN_NUM_INITIALIZER
11342                 (struct cmd_vf_vlan_insert_result,
11343                  port_id, RTE_UINT16);
11344 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
11345         TOKEN_NUM_INITIALIZER
11346                 (struct cmd_vf_vlan_insert_result,
11347                  vf_id, RTE_UINT16);
11348 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
11349         TOKEN_NUM_INITIALIZER
11350                 (struct cmd_vf_vlan_insert_result,
11351                  vlan_id, RTE_UINT16);
11352
11353 static void
11354 cmd_set_vf_vlan_insert_parsed(
11355         void *parsed_result,
11356         __rte_unused struct cmdline *cl,
11357         __rte_unused void *data)
11358 {
11359         struct cmd_vf_vlan_insert_result *res = parsed_result;
11360         int ret = -ENOTSUP;
11361
11362         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11363                 return;
11364
11365 #ifdef RTE_NET_IXGBE
11366         if (ret == -ENOTSUP)
11367                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
11368                         res->vlan_id);
11369 #endif
11370 #ifdef RTE_NET_I40E
11371         if (ret == -ENOTSUP)
11372                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
11373                         res->vlan_id);
11374 #endif
11375 #ifdef RTE_NET_BNXT
11376         if (ret == -ENOTSUP)
11377                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
11378                         res->vlan_id);
11379 #endif
11380
11381         switch (ret) {
11382         case 0:
11383                 break;
11384         case -EINVAL:
11385                 fprintf(stderr, "invalid vf_id %d or vlan_id %d\n",
11386                         res->vf_id, res->vlan_id);
11387                 break;
11388         case -ENODEV:
11389                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11390                 break;
11391         case -ENOTSUP:
11392                 fprintf(stderr, "function not implemented\n");
11393                 break;
11394         default:
11395                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11396         }
11397 }
11398
11399 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
11400         .f = cmd_set_vf_vlan_insert_parsed,
11401         .data = NULL,
11402         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
11403         .tokens = {
11404                 (void *)&cmd_vf_vlan_insert_set,
11405                 (void *)&cmd_vf_vlan_insert_vf,
11406                 (void *)&cmd_vf_vlan_insert_vlan,
11407                 (void *)&cmd_vf_vlan_insert_insert,
11408                 (void *)&cmd_vf_vlan_insert_port_id,
11409                 (void *)&cmd_vf_vlan_insert_vf_id,
11410                 (void *)&cmd_vf_vlan_insert_vlan_id,
11411                 NULL,
11412         },
11413 };
11414
11415 /* tx loopback configuration */
11416
11417 /* Common result structure for tx loopback */
11418 struct cmd_tx_loopback_result {
11419         cmdline_fixed_string_t set;
11420         cmdline_fixed_string_t tx;
11421         cmdline_fixed_string_t loopback;
11422         portid_t port_id;
11423         cmdline_fixed_string_t on_off;
11424 };
11425
11426 /* Common CLI fields for tx loopback enable disable */
11427 cmdline_parse_token_string_t cmd_tx_loopback_set =
11428         TOKEN_STRING_INITIALIZER
11429                 (struct cmd_tx_loopback_result,
11430                  set, "set");
11431 cmdline_parse_token_string_t cmd_tx_loopback_tx =
11432         TOKEN_STRING_INITIALIZER
11433                 (struct cmd_tx_loopback_result,
11434                  tx, "tx");
11435 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
11436         TOKEN_STRING_INITIALIZER
11437                 (struct cmd_tx_loopback_result,
11438                  loopback, "loopback");
11439 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
11440         TOKEN_NUM_INITIALIZER
11441                 (struct cmd_tx_loopback_result,
11442                  port_id, RTE_UINT16);
11443 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
11444         TOKEN_STRING_INITIALIZER
11445                 (struct cmd_tx_loopback_result,
11446                  on_off, "on#off");
11447
11448 static void
11449 cmd_set_tx_loopback_parsed(
11450         void *parsed_result,
11451         __rte_unused struct cmdline *cl,
11452         __rte_unused void *data)
11453 {
11454         struct cmd_tx_loopback_result *res = parsed_result;
11455         int ret = -ENOTSUP;
11456
11457         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11458
11459         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11460                 return;
11461
11462 #ifdef RTE_NET_IXGBE
11463         if (ret == -ENOTSUP)
11464                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
11465 #endif
11466 #ifdef RTE_NET_I40E
11467         if (ret == -ENOTSUP)
11468                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
11469 #endif
11470 #ifdef RTE_NET_BNXT
11471         if (ret == -ENOTSUP)
11472                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
11473 #endif
11474 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
11475         if (ret == -ENOTSUP)
11476                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
11477 #endif
11478
11479         switch (ret) {
11480         case 0:
11481                 break;
11482         case -EINVAL:
11483                 fprintf(stderr, "invalid is_on %d\n", is_on);
11484                 break;
11485         case -ENODEV:
11486                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11487                 break;
11488         case -ENOTSUP:
11489                 fprintf(stderr, "function not implemented\n");
11490                 break;
11491         default:
11492                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11493         }
11494 }
11495
11496 cmdline_parse_inst_t cmd_set_tx_loopback = {
11497         .f = cmd_set_tx_loopback_parsed,
11498         .data = NULL,
11499         .help_str = "set tx loopback <port_id> on|off",
11500         .tokens = {
11501                 (void *)&cmd_tx_loopback_set,
11502                 (void *)&cmd_tx_loopback_tx,
11503                 (void *)&cmd_tx_loopback_loopback,
11504                 (void *)&cmd_tx_loopback_port_id,
11505                 (void *)&cmd_tx_loopback_on_off,
11506                 NULL,
11507         },
11508 };
11509
11510 /* all queues drop enable configuration */
11511
11512 /* Common result structure for all queues drop enable */
11513 struct cmd_all_queues_drop_en_result {
11514         cmdline_fixed_string_t set;
11515         cmdline_fixed_string_t all;
11516         cmdline_fixed_string_t queues;
11517         cmdline_fixed_string_t drop;
11518         portid_t port_id;
11519         cmdline_fixed_string_t on_off;
11520 };
11521
11522 /* Common CLI fields for tx loopback enable disable */
11523 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
11524         TOKEN_STRING_INITIALIZER
11525                 (struct cmd_all_queues_drop_en_result,
11526                  set, "set");
11527 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
11528         TOKEN_STRING_INITIALIZER
11529                 (struct cmd_all_queues_drop_en_result,
11530                  all, "all");
11531 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
11532         TOKEN_STRING_INITIALIZER
11533                 (struct cmd_all_queues_drop_en_result,
11534                  queues, "queues");
11535 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
11536         TOKEN_STRING_INITIALIZER
11537                 (struct cmd_all_queues_drop_en_result,
11538                  drop, "drop");
11539 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
11540         TOKEN_NUM_INITIALIZER
11541                 (struct cmd_all_queues_drop_en_result,
11542                  port_id, RTE_UINT16);
11543 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
11544         TOKEN_STRING_INITIALIZER
11545                 (struct cmd_all_queues_drop_en_result,
11546                  on_off, "on#off");
11547
11548 static void
11549 cmd_set_all_queues_drop_en_parsed(
11550         void *parsed_result,
11551         __rte_unused struct cmdline *cl,
11552         __rte_unused void *data)
11553 {
11554         struct cmd_all_queues_drop_en_result *res = parsed_result;
11555         int ret = -ENOTSUP;
11556         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11557
11558         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11559                 return;
11560
11561 #ifdef RTE_NET_IXGBE
11562         if (ret == -ENOTSUP)
11563                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
11564 #endif
11565 #ifdef RTE_NET_BNXT
11566         if (ret == -ENOTSUP)
11567                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
11568 #endif
11569         switch (ret) {
11570         case 0:
11571                 break;
11572         case -EINVAL:
11573                 fprintf(stderr, "invalid is_on %d\n", is_on);
11574                 break;
11575         case -ENODEV:
11576                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11577                 break;
11578         case -ENOTSUP:
11579                 fprintf(stderr, "function not implemented\n");
11580                 break;
11581         default:
11582                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11583         }
11584 }
11585
11586 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
11587         .f = cmd_set_all_queues_drop_en_parsed,
11588         .data = NULL,
11589         .help_str = "set all queues drop <port_id> on|off",
11590         .tokens = {
11591                 (void *)&cmd_all_queues_drop_en_set,
11592                 (void *)&cmd_all_queues_drop_en_all,
11593                 (void *)&cmd_all_queues_drop_en_queues,
11594                 (void *)&cmd_all_queues_drop_en_drop,
11595                 (void *)&cmd_all_queues_drop_en_port_id,
11596                 (void *)&cmd_all_queues_drop_en_on_off,
11597                 NULL,
11598         },
11599 };
11600
11601 /* vf split drop enable configuration */
11602
11603 /* Common result structure for vf split drop enable */
11604 struct cmd_vf_split_drop_en_result {
11605         cmdline_fixed_string_t set;
11606         cmdline_fixed_string_t vf;
11607         cmdline_fixed_string_t split;
11608         cmdline_fixed_string_t drop;
11609         portid_t port_id;
11610         uint16_t vf_id;
11611         cmdline_fixed_string_t on_off;
11612 };
11613
11614 /* Common CLI fields for vf split drop enable disable */
11615 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
11616         TOKEN_STRING_INITIALIZER
11617                 (struct cmd_vf_split_drop_en_result,
11618                  set, "set");
11619 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
11620         TOKEN_STRING_INITIALIZER
11621                 (struct cmd_vf_split_drop_en_result,
11622                  vf, "vf");
11623 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
11624         TOKEN_STRING_INITIALIZER
11625                 (struct cmd_vf_split_drop_en_result,
11626                  split, "split");
11627 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
11628         TOKEN_STRING_INITIALIZER
11629                 (struct cmd_vf_split_drop_en_result,
11630                  drop, "drop");
11631 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
11632         TOKEN_NUM_INITIALIZER
11633                 (struct cmd_vf_split_drop_en_result,
11634                  port_id, RTE_UINT16);
11635 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
11636         TOKEN_NUM_INITIALIZER
11637                 (struct cmd_vf_split_drop_en_result,
11638                  vf_id, RTE_UINT16);
11639 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_vf_split_drop_en_result,
11642                  on_off, "on#off");
11643
11644 static void
11645 cmd_set_vf_split_drop_en_parsed(
11646         void *parsed_result,
11647         __rte_unused struct cmdline *cl,
11648         __rte_unused void *data)
11649 {
11650         struct cmd_vf_split_drop_en_result *res = parsed_result;
11651         int ret = -ENOTSUP;
11652         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
11653
11654         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11655                 return;
11656
11657 #ifdef RTE_NET_IXGBE
11658         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
11659                         is_on);
11660 #endif
11661         switch (ret) {
11662         case 0:
11663                 break;
11664         case -EINVAL:
11665                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
11666                         res->vf_id, is_on);
11667                 break;
11668         case -ENODEV:
11669                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11670                 break;
11671         case -ENOTSUP:
11672                 fprintf(stderr, "not supported on port %d\n", res->port_id);
11673                 break;
11674         default:
11675                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11676         }
11677 }
11678
11679 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
11680         .f = cmd_set_vf_split_drop_en_parsed,
11681         .data = NULL,
11682         .help_str = "set vf split drop <port_id> <vf_id> on|off",
11683         .tokens = {
11684                 (void *)&cmd_vf_split_drop_en_set,
11685                 (void *)&cmd_vf_split_drop_en_vf,
11686                 (void *)&cmd_vf_split_drop_en_split,
11687                 (void *)&cmd_vf_split_drop_en_drop,
11688                 (void *)&cmd_vf_split_drop_en_port_id,
11689                 (void *)&cmd_vf_split_drop_en_vf_id,
11690                 (void *)&cmd_vf_split_drop_en_on_off,
11691                 NULL,
11692         },
11693 };
11694
11695 /* vf mac address configuration */
11696
11697 /* Common result structure for vf mac address */
11698 struct cmd_set_vf_mac_addr_result {
11699         cmdline_fixed_string_t set;
11700         cmdline_fixed_string_t vf;
11701         cmdline_fixed_string_t mac;
11702         cmdline_fixed_string_t addr;
11703         portid_t port_id;
11704         uint16_t vf_id;
11705         struct rte_ether_addr mac_addr;
11706
11707 };
11708
11709 /* Common CLI fields for vf split drop enable disable */
11710 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
11711         TOKEN_STRING_INITIALIZER
11712                 (struct cmd_set_vf_mac_addr_result,
11713                  set, "set");
11714 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
11715         TOKEN_STRING_INITIALIZER
11716                 (struct cmd_set_vf_mac_addr_result,
11717                  vf, "vf");
11718 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
11719         TOKEN_STRING_INITIALIZER
11720                 (struct cmd_set_vf_mac_addr_result,
11721                  mac, "mac");
11722 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
11723         TOKEN_STRING_INITIALIZER
11724                 (struct cmd_set_vf_mac_addr_result,
11725                  addr, "addr");
11726 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
11727         TOKEN_NUM_INITIALIZER
11728                 (struct cmd_set_vf_mac_addr_result,
11729                  port_id, RTE_UINT16);
11730 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
11731         TOKEN_NUM_INITIALIZER
11732                 (struct cmd_set_vf_mac_addr_result,
11733                  vf_id, RTE_UINT16);
11734 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
11735         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
11736                  mac_addr);
11737
11738 static void
11739 cmd_set_vf_mac_addr_parsed(
11740         void *parsed_result,
11741         __rte_unused struct cmdline *cl,
11742         __rte_unused void *data)
11743 {
11744         struct cmd_set_vf_mac_addr_result *res = parsed_result;
11745         int ret = -ENOTSUP;
11746
11747         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11748                 return;
11749
11750 #ifdef RTE_NET_IXGBE
11751         if (ret == -ENOTSUP)
11752                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
11753                                 &res->mac_addr);
11754 #endif
11755 #ifdef RTE_NET_I40E
11756         if (ret == -ENOTSUP)
11757                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
11758                                 &res->mac_addr);
11759 #endif
11760 #ifdef RTE_NET_BNXT
11761         if (ret == -ENOTSUP)
11762                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
11763                                 &res->mac_addr);
11764 #endif
11765
11766         switch (ret) {
11767         case 0:
11768                 break;
11769         case -EINVAL:
11770                 fprintf(stderr, "invalid vf_id %d or mac_addr\n", res->vf_id);
11771                 break;
11772         case -ENODEV:
11773                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
11774                 break;
11775         case -ENOTSUP:
11776                 fprintf(stderr, "function not implemented\n");
11777                 break;
11778         default:
11779                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11780         }
11781 }
11782
11783 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
11784         .f = cmd_set_vf_mac_addr_parsed,
11785         .data = NULL,
11786         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
11787         .tokens = {
11788                 (void *)&cmd_set_vf_mac_addr_set,
11789                 (void *)&cmd_set_vf_mac_addr_vf,
11790                 (void *)&cmd_set_vf_mac_addr_mac,
11791                 (void *)&cmd_set_vf_mac_addr_addr,
11792                 (void *)&cmd_set_vf_mac_addr_port_id,
11793                 (void *)&cmd_set_vf_mac_addr_vf_id,
11794                 (void *)&cmd_set_vf_mac_addr_mac_addr,
11795                 NULL,
11796         },
11797 };
11798
11799 /* MACsec configuration */
11800
11801 /* Common result structure for MACsec offload enable */
11802 struct cmd_macsec_offload_on_result {
11803         cmdline_fixed_string_t set;
11804         cmdline_fixed_string_t macsec;
11805         cmdline_fixed_string_t offload;
11806         portid_t port_id;
11807         cmdline_fixed_string_t on;
11808         cmdline_fixed_string_t encrypt;
11809         cmdline_fixed_string_t en_on_off;
11810         cmdline_fixed_string_t replay_protect;
11811         cmdline_fixed_string_t rp_on_off;
11812 };
11813
11814 /* Common CLI fields for MACsec offload disable */
11815 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
11816         TOKEN_STRING_INITIALIZER
11817                 (struct cmd_macsec_offload_on_result,
11818                  set, "set");
11819 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
11820         TOKEN_STRING_INITIALIZER
11821                 (struct cmd_macsec_offload_on_result,
11822                  macsec, "macsec");
11823 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
11824         TOKEN_STRING_INITIALIZER
11825                 (struct cmd_macsec_offload_on_result,
11826                  offload, "offload");
11827 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
11828         TOKEN_NUM_INITIALIZER
11829                 (struct cmd_macsec_offload_on_result,
11830                  port_id, RTE_UINT16);
11831 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
11832         TOKEN_STRING_INITIALIZER
11833                 (struct cmd_macsec_offload_on_result,
11834                  on, "on");
11835 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
11836         TOKEN_STRING_INITIALIZER
11837                 (struct cmd_macsec_offload_on_result,
11838                  encrypt, "encrypt");
11839 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
11840         TOKEN_STRING_INITIALIZER
11841                 (struct cmd_macsec_offload_on_result,
11842                  en_on_off, "on#off");
11843 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
11844         TOKEN_STRING_INITIALIZER
11845                 (struct cmd_macsec_offload_on_result,
11846                  replay_protect, "replay-protect");
11847 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
11848         TOKEN_STRING_INITIALIZER
11849                 (struct cmd_macsec_offload_on_result,
11850                  rp_on_off, "on#off");
11851
11852 static void
11853 cmd_set_macsec_offload_on_parsed(
11854         void *parsed_result,
11855         __rte_unused struct cmdline *cl,
11856         __rte_unused void *data)
11857 {
11858         struct cmd_macsec_offload_on_result *res = parsed_result;
11859         int ret = -ENOTSUP;
11860         portid_t port_id = res->port_id;
11861         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
11862         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
11863         struct rte_eth_dev_info dev_info;
11864
11865         if (port_id_is_invalid(port_id, ENABLED_WARN))
11866                 return;
11867         if (!port_is_stopped(port_id)) {
11868                 fprintf(stderr, "Please stop port %d first\n", port_id);
11869                 return;
11870         }
11871
11872         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11873         if (ret != 0)
11874                 return;
11875
11876         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
11877 #ifdef RTE_NET_IXGBE
11878                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
11879 #endif
11880         }
11881         RTE_SET_USED(en);
11882         RTE_SET_USED(rp);
11883
11884         switch (ret) {
11885         case 0:
11886                 ports[port_id].dev_conf.txmode.offloads |=
11887                                                 RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
11888                 cmd_reconfig_device_queue(port_id, 1, 1);
11889                 break;
11890         case -ENODEV:
11891                 fprintf(stderr, "invalid port_id %d\n", port_id);
11892                 break;
11893         case -ENOTSUP:
11894                 fprintf(stderr, "not supported on port %d\n", port_id);
11895                 break;
11896         default:
11897                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11898         }
11899 }
11900
11901 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
11902         .f = cmd_set_macsec_offload_on_parsed,
11903         .data = NULL,
11904         .help_str = "set macsec offload <port_id> on "
11905                 "encrypt on|off replay-protect on|off",
11906         .tokens = {
11907                 (void *)&cmd_macsec_offload_on_set,
11908                 (void *)&cmd_macsec_offload_on_macsec,
11909                 (void *)&cmd_macsec_offload_on_offload,
11910                 (void *)&cmd_macsec_offload_on_port_id,
11911                 (void *)&cmd_macsec_offload_on_on,
11912                 (void *)&cmd_macsec_offload_on_encrypt,
11913                 (void *)&cmd_macsec_offload_on_en_on_off,
11914                 (void *)&cmd_macsec_offload_on_replay_protect,
11915                 (void *)&cmd_macsec_offload_on_rp_on_off,
11916                 NULL,
11917         },
11918 };
11919
11920 /* Common result structure for MACsec offload disable */
11921 struct cmd_macsec_offload_off_result {
11922         cmdline_fixed_string_t set;
11923         cmdline_fixed_string_t macsec;
11924         cmdline_fixed_string_t offload;
11925         portid_t port_id;
11926         cmdline_fixed_string_t off;
11927 };
11928
11929 /* Common CLI fields for MACsec offload disable */
11930 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
11931         TOKEN_STRING_INITIALIZER
11932                 (struct cmd_macsec_offload_off_result,
11933                  set, "set");
11934 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
11935         TOKEN_STRING_INITIALIZER
11936                 (struct cmd_macsec_offload_off_result,
11937                  macsec, "macsec");
11938 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
11939         TOKEN_STRING_INITIALIZER
11940                 (struct cmd_macsec_offload_off_result,
11941                  offload, "offload");
11942 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
11943         TOKEN_NUM_INITIALIZER
11944                 (struct cmd_macsec_offload_off_result,
11945                  port_id, RTE_UINT16);
11946 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
11947         TOKEN_STRING_INITIALIZER
11948                 (struct cmd_macsec_offload_off_result,
11949                  off, "off");
11950
11951 static void
11952 cmd_set_macsec_offload_off_parsed(
11953         void *parsed_result,
11954         __rte_unused struct cmdline *cl,
11955         __rte_unused void *data)
11956 {
11957         struct cmd_macsec_offload_off_result *res = parsed_result;
11958         int ret = -ENOTSUP;
11959         struct rte_eth_dev_info dev_info;
11960         portid_t port_id = res->port_id;
11961
11962         if (port_id_is_invalid(port_id, ENABLED_WARN))
11963                 return;
11964         if (!port_is_stopped(port_id)) {
11965                 fprintf(stderr, "Please stop port %d first\n", port_id);
11966                 return;
11967         }
11968
11969         ret = eth_dev_info_get_print_err(port_id, &dev_info);
11970         if (ret != 0)
11971                 return;
11972
11973         if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) {
11974 #ifdef RTE_NET_IXGBE
11975                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
11976 #endif
11977         }
11978         switch (ret) {
11979         case 0:
11980                 ports[port_id].dev_conf.txmode.offloads &=
11981                                                 ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
11982                 cmd_reconfig_device_queue(port_id, 1, 1);
11983                 break;
11984         case -ENODEV:
11985                 fprintf(stderr, "invalid port_id %d\n", port_id);
11986                 break;
11987         case -ENOTSUP:
11988                 fprintf(stderr, "not supported on port %d\n", port_id);
11989                 break;
11990         default:
11991                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
11992         }
11993 }
11994
11995 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
11996         .f = cmd_set_macsec_offload_off_parsed,
11997         .data = NULL,
11998         .help_str = "set macsec offload <port_id> off",
11999         .tokens = {
12000                 (void *)&cmd_macsec_offload_off_set,
12001                 (void *)&cmd_macsec_offload_off_macsec,
12002                 (void *)&cmd_macsec_offload_off_offload,
12003                 (void *)&cmd_macsec_offload_off_port_id,
12004                 (void *)&cmd_macsec_offload_off_off,
12005                 NULL,
12006         },
12007 };
12008
12009 /* Common result structure for MACsec secure connection configure */
12010 struct cmd_macsec_sc_result {
12011         cmdline_fixed_string_t set;
12012         cmdline_fixed_string_t macsec;
12013         cmdline_fixed_string_t sc;
12014         cmdline_fixed_string_t tx_rx;
12015         portid_t port_id;
12016         struct rte_ether_addr mac;
12017         uint16_t pi;
12018 };
12019
12020 /* Common CLI fields for MACsec secure connection configure */
12021 cmdline_parse_token_string_t cmd_macsec_sc_set =
12022         TOKEN_STRING_INITIALIZER
12023                 (struct cmd_macsec_sc_result,
12024                  set, "set");
12025 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
12026         TOKEN_STRING_INITIALIZER
12027                 (struct cmd_macsec_sc_result,
12028                  macsec, "macsec");
12029 cmdline_parse_token_string_t cmd_macsec_sc_sc =
12030         TOKEN_STRING_INITIALIZER
12031                 (struct cmd_macsec_sc_result,
12032                  sc, "sc");
12033 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
12034         TOKEN_STRING_INITIALIZER
12035                 (struct cmd_macsec_sc_result,
12036                  tx_rx, "tx#rx");
12037 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
12038         TOKEN_NUM_INITIALIZER
12039                 (struct cmd_macsec_sc_result,
12040                  port_id, RTE_UINT16);
12041 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
12042         TOKEN_ETHERADDR_INITIALIZER
12043                 (struct cmd_macsec_sc_result,
12044                  mac);
12045 cmdline_parse_token_num_t cmd_macsec_sc_pi =
12046         TOKEN_NUM_INITIALIZER
12047                 (struct cmd_macsec_sc_result,
12048                  pi, RTE_UINT16);
12049
12050 static void
12051 cmd_set_macsec_sc_parsed(
12052         void *parsed_result,
12053         __rte_unused struct cmdline *cl,
12054         __rte_unused void *data)
12055 {
12056         struct cmd_macsec_sc_result *res = parsed_result;
12057         int ret = -ENOTSUP;
12058         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12059
12060 #ifdef RTE_NET_IXGBE
12061         ret = is_tx ?
12062                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
12063                                 res->mac.addr_bytes) :
12064                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
12065                                 res->mac.addr_bytes, res->pi);
12066 #endif
12067         RTE_SET_USED(is_tx);
12068
12069         switch (ret) {
12070         case 0:
12071                 break;
12072         case -ENODEV:
12073                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12074                 break;
12075         case -ENOTSUP:
12076                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12077                 break;
12078         default:
12079                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12080         }
12081 }
12082
12083 cmdline_parse_inst_t cmd_set_macsec_sc = {
12084         .f = cmd_set_macsec_sc_parsed,
12085         .data = NULL,
12086         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
12087         .tokens = {
12088                 (void *)&cmd_macsec_sc_set,
12089                 (void *)&cmd_macsec_sc_macsec,
12090                 (void *)&cmd_macsec_sc_sc,
12091                 (void *)&cmd_macsec_sc_tx_rx,
12092                 (void *)&cmd_macsec_sc_port_id,
12093                 (void *)&cmd_macsec_sc_mac,
12094                 (void *)&cmd_macsec_sc_pi,
12095                 NULL,
12096         },
12097 };
12098
12099 /* Common result structure for MACsec secure connection configure */
12100 struct cmd_macsec_sa_result {
12101         cmdline_fixed_string_t set;
12102         cmdline_fixed_string_t macsec;
12103         cmdline_fixed_string_t sa;
12104         cmdline_fixed_string_t tx_rx;
12105         portid_t port_id;
12106         uint8_t idx;
12107         uint8_t an;
12108         uint32_t pn;
12109         cmdline_fixed_string_t key;
12110 };
12111
12112 /* Common CLI fields for MACsec secure connection configure */
12113 cmdline_parse_token_string_t cmd_macsec_sa_set =
12114         TOKEN_STRING_INITIALIZER
12115                 (struct cmd_macsec_sa_result,
12116                  set, "set");
12117 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
12118         TOKEN_STRING_INITIALIZER
12119                 (struct cmd_macsec_sa_result,
12120                  macsec, "macsec");
12121 cmdline_parse_token_string_t cmd_macsec_sa_sa =
12122         TOKEN_STRING_INITIALIZER
12123                 (struct cmd_macsec_sa_result,
12124                  sa, "sa");
12125 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
12126         TOKEN_STRING_INITIALIZER
12127                 (struct cmd_macsec_sa_result,
12128                  tx_rx, "tx#rx");
12129 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
12130         TOKEN_NUM_INITIALIZER
12131                 (struct cmd_macsec_sa_result,
12132                  port_id, RTE_UINT16);
12133 cmdline_parse_token_num_t cmd_macsec_sa_idx =
12134         TOKEN_NUM_INITIALIZER
12135                 (struct cmd_macsec_sa_result,
12136                  idx, RTE_UINT8);
12137 cmdline_parse_token_num_t cmd_macsec_sa_an =
12138         TOKEN_NUM_INITIALIZER
12139                 (struct cmd_macsec_sa_result,
12140                  an, RTE_UINT8);
12141 cmdline_parse_token_num_t cmd_macsec_sa_pn =
12142         TOKEN_NUM_INITIALIZER
12143                 (struct cmd_macsec_sa_result,
12144                  pn, RTE_UINT32);
12145 cmdline_parse_token_string_t cmd_macsec_sa_key =
12146         TOKEN_STRING_INITIALIZER
12147                 (struct cmd_macsec_sa_result,
12148                  key, NULL);
12149
12150 static void
12151 cmd_set_macsec_sa_parsed(
12152         void *parsed_result,
12153         __rte_unused struct cmdline *cl,
12154         __rte_unused void *data)
12155 {
12156         struct cmd_macsec_sa_result *res = parsed_result;
12157         int ret = -ENOTSUP;
12158         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
12159         uint8_t key[16] = { 0 };
12160         uint8_t xdgt0;
12161         uint8_t xdgt1;
12162         int key_len;
12163         int i;
12164
12165         key_len = strlen(res->key) / 2;
12166         if (key_len > 16)
12167                 key_len = 16;
12168
12169         for (i = 0; i < key_len; i++) {
12170                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
12171                 if (xdgt0 == 0xFF)
12172                         return;
12173                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
12174                 if (xdgt1 == 0xFF)
12175                         return;
12176                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
12177         }
12178
12179 #ifdef RTE_NET_IXGBE
12180         ret = is_tx ?
12181                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
12182                         res->idx, res->an, res->pn, key) :
12183                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
12184                         res->idx, res->an, res->pn, key);
12185 #endif
12186         RTE_SET_USED(is_tx);
12187         RTE_SET_USED(key);
12188
12189         switch (ret) {
12190         case 0:
12191                 break;
12192         case -EINVAL:
12193                 fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an);
12194                 break;
12195         case -ENODEV:
12196                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12197                 break;
12198         case -ENOTSUP:
12199                 fprintf(stderr, "not supported on port %d\n", res->port_id);
12200                 break;
12201         default:
12202                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12203         }
12204 }
12205
12206 cmdline_parse_inst_t cmd_set_macsec_sa = {
12207         .f = cmd_set_macsec_sa_parsed,
12208         .data = NULL,
12209         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
12210         .tokens = {
12211                 (void *)&cmd_macsec_sa_set,
12212                 (void *)&cmd_macsec_sa_macsec,
12213                 (void *)&cmd_macsec_sa_sa,
12214                 (void *)&cmd_macsec_sa_tx_rx,
12215                 (void *)&cmd_macsec_sa_port_id,
12216                 (void *)&cmd_macsec_sa_idx,
12217                 (void *)&cmd_macsec_sa_an,
12218                 (void *)&cmd_macsec_sa_pn,
12219                 (void *)&cmd_macsec_sa_key,
12220                 NULL,
12221         },
12222 };
12223
12224 /* VF unicast promiscuous mode configuration */
12225
12226 /* Common result structure for VF unicast promiscuous mode */
12227 struct cmd_vf_promisc_result {
12228         cmdline_fixed_string_t set;
12229         cmdline_fixed_string_t vf;
12230         cmdline_fixed_string_t promisc;
12231         portid_t port_id;
12232         uint32_t vf_id;
12233         cmdline_fixed_string_t on_off;
12234 };
12235
12236 /* Common CLI fields for VF unicast promiscuous mode enable disable */
12237 cmdline_parse_token_string_t cmd_vf_promisc_set =
12238         TOKEN_STRING_INITIALIZER
12239                 (struct cmd_vf_promisc_result,
12240                  set, "set");
12241 cmdline_parse_token_string_t cmd_vf_promisc_vf =
12242         TOKEN_STRING_INITIALIZER
12243                 (struct cmd_vf_promisc_result,
12244                  vf, "vf");
12245 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
12246         TOKEN_STRING_INITIALIZER
12247                 (struct cmd_vf_promisc_result,
12248                  promisc, "promisc");
12249 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
12250         TOKEN_NUM_INITIALIZER
12251                 (struct cmd_vf_promisc_result,
12252                  port_id, RTE_UINT16);
12253 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
12254         TOKEN_NUM_INITIALIZER
12255                 (struct cmd_vf_promisc_result,
12256                  vf_id, RTE_UINT32);
12257 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
12258         TOKEN_STRING_INITIALIZER
12259                 (struct cmd_vf_promisc_result,
12260                  on_off, "on#off");
12261
12262 static void
12263 cmd_set_vf_promisc_parsed(
12264         void *parsed_result,
12265         __rte_unused struct cmdline *cl,
12266         __rte_unused void *data)
12267 {
12268         struct cmd_vf_promisc_result *res = parsed_result;
12269         int ret = -ENOTSUP;
12270
12271         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12272
12273         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12274                 return;
12275
12276 #ifdef RTE_NET_I40E
12277         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
12278                                                   res->vf_id, is_on);
12279 #endif
12280
12281         switch (ret) {
12282         case 0:
12283                 break;
12284         case -EINVAL:
12285                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12286                 break;
12287         case -ENODEV:
12288                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12289                 break;
12290         case -ENOTSUP:
12291                 fprintf(stderr, "function not implemented\n");
12292                 break;
12293         default:
12294                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12295         }
12296 }
12297
12298 cmdline_parse_inst_t cmd_set_vf_promisc = {
12299         .f = cmd_set_vf_promisc_parsed,
12300         .data = NULL,
12301         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
12302                 "Set unicast promiscuous mode for a VF from the PF",
12303         .tokens = {
12304                 (void *)&cmd_vf_promisc_set,
12305                 (void *)&cmd_vf_promisc_vf,
12306                 (void *)&cmd_vf_promisc_promisc,
12307                 (void *)&cmd_vf_promisc_port_id,
12308                 (void *)&cmd_vf_promisc_vf_id,
12309                 (void *)&cmd_vf_promisc_on_off,
12310                 NULL,
12311         },
12312 };
12313
12314 /* VF multicast promiscuous mode configuration */
12315
12316 /* Common result structure for VF multicast promiscuous mode */
12317 struct cmd_vf_allmulti_result {
12318         cmdline_fixed_string_t set;
12319         cmdline_fixed_string_t vf;
12320         cmdline_fixed_string_t allmulti;
12321         portid_t port_id;
12322         uint32_t vf_id;
12323         cmdline_fixed_string_t on_off;
12324 };
12325
12326 /* Common CLI fields for VF multicast promiscuous mode enable disable */
12327 cmdline_parse_token_string_t cmd_vf_allmulti_set =
12328         TOKEN_STRING_INITIALIZER
12329                 (struct cmd_vf_allmulti_result,
12330                  set, "set");
12331 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
12332         TOKEN_STRING_INITIALIZER
12333                 (struct cmd_vf_allmulti_result,
12334                  vf, "vf");
12335 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
12336         TOKEN_STRING_INITIALIZER
12337                 (struct cmd_vf_allmulti_result,
12338                  allmulti, "allmulti");
12339 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
12340         TOKEN_NUM_INITIALIZER
12341                 (struct cmd_vf_allmulti_result,
12342                  port_id, RTE_UINT16);
12343 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
12344         TOKEN_NUM_INITIALIZER
12345                 (struct cmd_vf_allmulti_result,
12346                  vf_id, RTE_UINT32);
12347 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
12348         TOKEN_STRING_INITIALIZER
12349                 (struct cmd_vf_allmulti_result,
12350                  on_off, "on#off");
12351
12352 static void
12353 cmd_set_vf_allmulti_parsed(
12354         void *parsed_result,
12355         __rte_unused struct cmdline *cl,
12356         __rte_unused void *data)
12357 {
12358         struct cmd_vf_allmulti_result *res = parsed_result;
12359         int ret = -ENOTSUP;
12360
12361         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12362
12363         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12364                 return;
12365
12366 #ifdef RTE_NET_I40E
12367         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
12368                                                     res->vf_id, is_on);
12369 #endif
12370
12371         switch (ret) {
12372         case 0:
12373                 break;
12374         case -EINVAL:
12375                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
12376                 break;
12377         case -ENODEV:
12378                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12379                 break;
12380         case -ENOTSUP:
12381                 fprintf(stderr, "function not implemented\n");
12382                 break;
12383         default:
12384                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12385         }
12386 }
12387
12388 cmdline_parse_inst_t cmd_set_vf_allmulti = {
12389         .f = cmd_set_vf_allmulti_parsed,
12390         .data = NULL,
12391         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
12392                 "Set multicast promiscuous mode for a VF from the PF",
12393         .tokens = {
12394                 (void *)&cmd_vf_allmulti_set,
12395                 (void *)&cmd_vf_allmulti_vf,
12396                 (void *)&cmd_vf_allmulti_allmulti,
12397                 (void *)&cmd_vf_allmulti_port_id,
12398                 (void *)&cmd_vf_allmulti_vf_id,
12399                 (void *)&cmd_vf_allmulti_on_off,
12400                 NULL,
12401         },
12402 };
12403
12404 /* vf broadcast mode configuration */
12405
12406 /* Common result structure for vf broadcast */
12407 struct cmd_set_vf_broadcast_result {
12408         cmdline_fixed_string_t set;
12409         cmdline_fixed_string_t vf;
12410         cmdline_fixed_string_t broadcast;
12411         portid_t port_id;
12412         uint16_t vf_id;
12413         cmdline_fixed_string_t on_off;
12414 };
12415
12416 /* Common CLI fields for vf broadcast enable disable */
12417 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
12418         TOKEN_STRING_INITIALIZER
12419                 (struct cmd_set_vf_broadcast_result,
12420                  set, "set");
12421 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
12422         TOKEN_STRING_INITIALIZER
12423                 (struct cmd_set_vf_broadcast_result,
12424                  vf, "vf");
12425 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
12426         TOKEN_STRING_INITIALIZER
12427                 (struct cmd_set_vf_broadcast_result,
12428                  broadcast, "broadcast");
12429 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
12430         TOKEN_NUM_INITIALIZER
12431                 (struct cmd_set_vf_broadcast_result,
12432                  port_id, RTE_UINT16);
12433 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
12434         TOKEN_NUM_INITIALIZER
12435                 (struct cmd_set_vf_broadcast_result,
12436                  vf_id, RTE_UINT16);
12437 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
12438         TOKEN_STRING_INITIALIZER
12439                 (struct cmd_set_vf_broadcast_result,
12440                  on_off, "on#off");
12441
12442 static void
12443 cmd_set_vf_broadcast_parsed(
12444         void *parsed_result,
12445         __rte_unused struct cmdline *cl,
12446         __rte_unused void *data)
12447 {
12448         struct cmd_set_vf_broadcast_result *res = parsed_result;
12449         int ret = -ENOTSUP;
12450
12451         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12452
12453         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12454                 return;
12455
12456 #ifdef RTE_NET_I40E
12457         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
12458                                             res->vf_id, is_on);
12459 #endif
12460
12461         switch (ret) {
12462         case 0:
12463                 break;
12464         case -EINVAL:
12465                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12466                         res->vf_id, is_on);
12467                 break;
12468         case -ENODEV:
12469                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12470                 break;
12471         case -ENOTSUP:
12472                 fprintf(stderr, "function not implemented\n");
12473                 break;
12474         default:
12475                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12476         }
12477 }
12478
12479 cmdline_parse_inst_t cmd_set_vf_broadcast = {
12480         .f = cmd_set_vf_broadcast_parsed,
12481         .data = NULL,
12482         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
12483         .tokens = {
12484                 (void *)&cmd_set_vf_broadcast_set,
12485                 (void *)&cmd_set_vf_broadcast_vf,
12486                 (void *)&cmd_set_vf_broadcast_broadcast,
12487                 (void *)&cmd_set_vf_broadcast_port_id,
12488                 (void *)&cmd_set_vf_broadcast_vf_id,
12489                 (void *)&cmd_set_vf_broadcast_on_off,
12490                 NULL,
12491         },
12492 };
12493
12494 /* vf vlan tag configuration */
12495
12496 /* Common result structure for vf vlan tag */
12497 struct cmd_set_vf_vlan_tag_result {
12498         cmdline_fixed_string_t set;
12499         cmdline_fixed_string_t vf;
12500         cmdline_fixed_string_t vlan;
12501         cmdline_fixed_string_t tag;
12502         portid_t port_id;
12503         uint16_t vf_id;
12504         cmdline_fixed_string_t on_off;
12505 };
12506
12507 /* Common CLI fields for vf vlan tag enable disable */
12508 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
12509         TOKEN_STRING_INITIALIZER
12510                 (struct cmd_set_vf_vlan_tag_result,
12511                  set, "set");
12512 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
12513         TOKEN_STRING_INITIALIZER
12514                 (struct cmd_set_vf_vlan_tag_result,
12515                  vf, "vf");
12516 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
12517         TOKEN_STRING_INITIALIZER
12518                 (struct cmd_set_vf_vlan_tag_result,
12519                  vlan, "vlan");
12520 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
12521         TOKEN_STRING_INITIALIZER
12522                 (struct cmd_set_vf_vlan_tag_result,
12523                  tag, "tag");
12524 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
12525         TOKEN_NUM_INITIALIZER
12526                 (struct cmd_set_vf_vlan_tag_result,
12527                  port_id, RTE_UINT16);
12528 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
12529         TOKEN_NUM_INITIALIZER
12530                 (struct cmd_set_vf_vlan_tag_result,
12531                  vf_id, RTE_UINT16);
12532 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
12533         TOKEN_STRING_INITIALIZER
12534                 (struct cmd_set_vf_vlan_tag_result,
12535                  on_off, "on#off");
12536
12537 static void
12538 cmd_set_vf_vlan_tag_parsed(
12539         void *parsed_result,
12540         __rte_unused struct cmdline *cl,
12541         __rte_unused void *data)
12542 {
12543         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
12544         int ret = -ENOTSUP;
12545
12546         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12547
12548         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12549                 return;
12550
12551 #ifdef RTE_NET_I40E
12552         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
12553                                            res->vf_id, is_on);
12554 #endif
12555
12556         switch (ret) {
12557         case 0:
12558                 break;
12559         case -EINVAL:
12560                 fprintf(stderr, "invalid vf_id %d or is_on %d\n",
12561                         res->vf_id, is_on);
12562                 break;
12563         case -ENODEV:
12564                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12565                 break;
12566         case -ENOTSUP:
12567                 fprintf(stderr, "function not implemented\n");
12568                 break;
12569         default:
12570                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12571         }
12572 }
12573
12574 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
12575         .f = cmd_set_vf_vlan_tag_parsed,
12576         .data = NULL,
12577         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
12578         .tokens = {
12579                 (void *)&cmd_set_vf_vlan_tag_set,
12580                 (void *)&cmd_set_vf_vlan_tag_vf,
12581                 (void *)&cmd_set_vf_vlan_tag_vlan,
12582                 (void *)&cmd_set_vf_vlan_tag_tag,
12583                 (void *)&cmd_set_vf_vlan_tag_port_id,
12584                 (void *)&cmd_set_vf_vlan_tag_vf_id,
12585                 (void *)&cmd_set_vf_vlan_tag_on_off,
12586                 NULL,
12587         },
12588 };
12589
12590 /* Common definition of VF and TC TX bandwidth configuration */
12591 struct cmd_vf_tc_bw_result {
12592         cmdline_fixed_string_t set;
12593         cmdline_fixed_string_t vf;
12594         cmdline_fixed_string_t tc;
12595         cmdline_fixed_string_t tx;
12596         cmdline_fixed_string_t min_bw;
12597         cmdline_fixed_string_t max_bw;
12598         cmdline_fixed_string_t strict_link_prio;
12599         portid_t port_id;
12600         uint16_t vf_id;
12601         uint8_t tc_no;
12602         uint32_t bw;
12603         cmdline_fixed_string_t bw_list;
12604         uint8_t tc_map;
12605 };
12606
12607 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
12608         TOKEN_STRING_INITIALIZER
12609                 (struct cmd_vf_tc_bw_result,
12610                  set, "set");
12611 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
12612         TOKEN_STRING_INITIALIZER
12613                 (struct cmd_vf_tc_bw_result,
12614                  vf, "vf");
12615 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
12616         TOKEN_STRING_INITIALIZER
12617                 (struct cmd_vf_tc_bw_result,
12618                  tc, "tc");
12619 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
12620         TOKEN_STRING_INITIALIZER
12621                 (struct cmd_vf_tc_bw_result,
12622                  tx, "tx");
12623 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
12624         TOKEN_STRING_INITIALIZER
12625                 (struct cmd_vf_tc_bw_result,
12626                  strict_link_prio, "strict-link-priority");
12627 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
12628         TOKEN_STRING_INITIALIZER
12629                 (struct cmd_vf_tc_bw_result,
12630                  min_bw, "min-bandwidth");
12631 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
12632         TOKEN_STRING_INITIALIZER
12633                 (struct cmd_vf_tc_bw_result,
12634                  max_bw, "max-bandwidth");
12635 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
12636         TOKEN_NUM_INITIALIZER
12637                 (struct cmd_vf_tc_bw_result,
12638                  port_id, RTE_UINT16);
12639 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
12640         TOKEN_NUM_INITIALIZER
12641                 (struct cmd_vf_tc_bw_result,
12642                  vf_id, RTE_UINT16);
12643 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
12644         TOKEN_NUM_INITIALIZER
12645                 (struct cmd_vf_tc_bw_result,
12646                  tc_no, RTE_UINT8);
12647 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
12648         TOKEN_NUM_INITIALIZER
12649                 (struct cmd_vf_tc_bw_result,
12650                  bw, RTE_UINT32);
12651 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
12652         TOKEN_STRING_INITIALIZER
12653                 (struct cmd_vf_tc_bw_result,
12654                  bw_list, NULL);
12655 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
12656         TOKEN_NUM_INITIALIZER
12657                 (struct cmd_vf_tc_bw_result,
12658                  tc_map, RTE_UINT8);
12659
12660 /* VF max bandwidth setting */
12661 static void
12662 cmd_vf_max_bw_parsed(
12663         void *parsed_result,
12664         __rte_unused struct cmdline *cl,
12665         __rte_unused void *data)
12666 {
12667         struct cmd_vf_tc_bw_result *res = parsed_result;
12668         int ret = -ENOTSUP;
12669
12670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12671                 return;
12672
12673 #ifdef RTE_NET_I40E
12674         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
12675                                          res->vf_id, res->bw);
12676 #endif
12677
12678         switch (ret) {
12679         case 0:
12680                 break;
12681         case -EINVAL:
12682                 fprintf(stderr, "invalid vf_id %d or bandwidth %d\n",
12683                         res->vf_id, res->bw);
12684                 break;
12685         case -ENODEV:
12686                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12687                 break;
12688         case -ENOTSUP:
12689                 fprintf(stderr, "function not implemented\n");
12690                 break;
12691         default:
12692                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12693         }
12694 }
12695
12696 cmdline_parse_inst_t cmd_vf_max_bw = {
12697         .f = cmd_vf_max_bw_parsed,
12698         .data = NULL,
12699         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
12700         .tokens = {
12701                 (void *)&cmd_vf_tc_bw_set,
12702                 (void *)&cmd_vf_tc_bw_vf,
12703                 (void *)&cmd_vf_tc_bw_tx,
12704                 (void *)&cmd_vf_tc_bw_max_bw,
12705                 (void *)&cmd_vf_tc_bw_port_id,
12706                 (void *)&cmd_vf_tc_bw_vf_id,
12707                 (void *)&cmd_vf_tc_bw_bw,
12708                 NULL,
12709         },
12710 };
12711
12712 static int
12713 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
12714                            uint8_t *tc_num,
12715                            char *str)
12716 {
12717         uint32_t size;
12718         const char *p, *p0 = str;
12719         char s[256];
12720         char *end;
12721         char *str_fld[16];
12722         uint16_t i;
12723         int ret;
12724
12725         p = strchr(p0, '(');
12726         if (p == NULL) {
12727                 fprintf(stderr,
12728                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12729                 return -1;
12730         }
12731         p++;
12732         p0 = strchr(p, ')');
12733         if (p0 == NULL) {
12734                 fprintf(stderr,
12735                         "The bandwidth-list should be '(bw1, bw2, ...)'\n");
12736                 return -1;
12737         }
12738         size = p0 - p;
12739         if (size >= sizeof(s)) {
12740                 fprintf(stderr,
12741                         "The string size exceeds the internal buffer size\n");
12742                 return -1;
12743         }
12744         snprintf(s, sizeof(s), "%.*s", size, p);
12745         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
12746         if (ret <= 0) {
12747                 fprintf(stderr, "Failed to get the bandwidth list.\n");
12748                 return -1;
12749         }
12750         *tc_num = ret;
12751         for (i = 0; i < ret; i++)
12752                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
12753
12754         return 0;
12755 }
12756
12757 /* TC min bandwidth setting */
12758 static void
12759 cmd_vf_tc_min_bw_parsed(
12760         void *parsed_result,
12761         __rte_unused struct cmdline *cl,
12762         __rte_unused void *data)
12763 {
12764         struct cmd_vf_tc_bw_result *res = parsed_result;
12765         uint8_t tc_num;
12766         uint8_t bw[16];
12767         int ret = -ENOTSUP;
12768
12769         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12770                 return;
12771
12772         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12773         if (ret)
12774                 return;
12775
12776 #ifdef RTE_NET_I40E
12777         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
12778                                               tc_num, bw);
12779 #endif
12780
12781         switch (ret) {
12782         case 0:
12783                 break;
12784         case -EINVAL:
12785                 fprintf(stderr, "invalid vf_id %d or bandwidth\n", res->vf_id);
12786                 break;
12787         case -ENODEV:
12788                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12789                 break;
12790         case -ENOTSUP:
12791                 fprintf(stderr, "function not implemented\n");
12792                 break;
12793         default:
12794                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12795         }
12796 }
12797
12798 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
12799         .f = cmd_vf_tc_min_bw_parsed,
12800         .data = NULL,
12801         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
12802                     " <bw1, bw2, ...>",
12803         .tokens = {
12804                 (void *)&cmd_vf_tc_bw_set,
12805                 (void *)&cmd_vf_tc_bw_vf,
12806                 (void *)&cmd_vf_tc_bw_tc,
12807                 (void *)&cmd_vf_tc_bw_tx,
12808                 (void *)&cmd_vf_tc_bw_min_bw,
12809                 (void *)&cmd_vf_tc_bw_port_id,
12810                 (void *)&cmd_vf_tc_bw_vf_id,
12811                 (void *)&cmd_vf_tc_bw_bw_list,
12812                 NULL,
12813         },
12814 };
12815
12816 static void
12817 cmd_tc_min_bw_parsed(
12818         void *parsed_result,
12819         __rte_unused struct cmdline *cl,
12820         __rte_unused void *data)
12821 {
12822         struct cmd_vf_tc_bw_result *res = parsed_result;
12823         struct rte_port *port;
12824         uint8_t tc_num;
12825         uint8_t bw[16];
12826         int ret = -ENOTSUP;
12827
12828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12829                 return;
12830
12831         port = &ports[res->port_id];
12832         /** Check if the port is not started **/
12833         if (port->port_status != RTE_PORT_STOPPED) {
12834                 fprintf(stderr, "Please stop port %d first\n", res->port_id);
12835                 return;
12836         }
12837
12838         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
12839         if (ret)
12840                 return;
12841
12842 #ifdef RTE_NET_IXGBE
12843         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
12844 #endif
12845
12846         switch (ret) {
12847         case 0:
12848                 break;
12849         case -EINVAL:
12850                 fprintf(stderr, "invalid bandwidth\n");
12851                 break;
12852         case -ENODEV:
12853                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12854                 break;
12855         case -ENOTSUP:
12856                 fprintf(stderr, "function not implemented\n");
12857                 break;
12858         default:
12859                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12860         }
12861 }
12862
12863 cmdline_parse_inst_t cmd_tc_min_bw = {
12864         .f = cmd_tc_min_bw_parsed,
12865         .data = NULL,
12866         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
12867         .tokens = {
12868                 (void *)&cmd_vf_tc_bw_set,
12869                 (void *)&cmd_vf_tc_bw_tc,
12870                 (void *)&cmd_vf_tc_bw_tx,
12871                 (void *)&cmd_vf_tc_bw_min_bw,
12872                 (void *)&cmd_vf_tc_bw_port_id,
12873                 (void *)&cmd_vf_tc_bw_bw_list,
12874                 NULL,
12875         },
12876 };
12877
12878 /* TC max bandwidth setting */
12879 static void
12880 cmd_vf_tc_max_bw_parsed(
12881         void *parsed_result,
12882         __rte_unused struct cmdline *cl,
12883         __rte_unused void *data)
12884 {
12885         struct cmd_vf_tc_bw_result *res = parsed_result;
12886         int ret = -ENOTSUP;
12887
12888         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12889                 return;
12890
12891 #ifdef RTE_NET_I40E
12892         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
12893                                             res->tc_no, res->bw);
12894 #endif
12895
12896         switch (ret) {
12897         case 0:
12898                 break;
12899         case -EINVAL:
12900                 fprintf(stderr,
12901                         "invalid vf_id %d, tc_no %d or bandwidth %d\n",
12902                         res->vf_id, res->tc_no, res->bw);
12903                 break;
12904         case -ENODEV:
12905                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
12906                 break;
12907         case -ENOTSUP:
12908                 fprintf(stderr, "function not implemented\n");
12909                 break;
12910         default:
12911                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
12912         }
12913 }
12914
12915 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
12916         .f = cmd_vf_tc_max_bw_parsed,
12917         .data = NULL,
12918         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
12919                     " <bandwidth>",
12920         .tokens = {
12921                 (void *)&cmd_vf_tc_bw_set,
12922                 (void *)&cmd_vf_tc_bw_vf,
12923                 (void *)&cmd_vf_tc_bw_tc,
12924                 (void *)&cmd_vf_tc_bw_tx,
12925                 (void *)&cmd_vf_tc_bw_max_bw,
12926                 (void *)&cmd_vf_tc_bw_port_id,
12927                 (void *)&cmd_vf_tc_bw_vf_id,
12928                 (void *)&cmd_vf_tc_bw_tc_no,
12929                 (void *)&cmd_vf_tc_bw_bw,
12930                 NULL,
12931         },
12932 };
12933
12934 /** Set VXLAN encapsulation details */
12935 struct cmd_set_vxlan_result {
12936         cmdline_fixed_string_t set;
12937         cmdline_fixed_string_t vxlan;
12938         cmdline_fixed_string_t pos_token;
12939         cmdline_fixed_string_t ip_version;
12940         uint32_t vlan_present:1;
12941         uint32_t vni;
12942         uint16_t udp_src;
12943         uint16_t udp_dst;
12944         cmdline_ipaddr_t ip_src;
12945         cmdline_ipaddr_t ip_dst;
12946         uint16_t tci;
12947         uint8_t tos;
12948         uint8_t ttl;
12949         struct rte_ether_addr eth_src;
12950         struct rte_ether_addr eth_dst;
12951 };
12952
12953 cmdline_parse_token_string_t cmd_set_vxlan_set =
12954         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
12955 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
12956         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
12957 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
12958         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12959                                  "vxlan-tos-ttl");
12960 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
12961         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
12962                                  "vxlan-with-vlan");
12963 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
12964         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12965                                  "ip-version");
12966 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
12967         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
12968                                  "ipv4#ipv6");
12969 cmdline_parse_token_string_t cmd_set_vxlan_vni =
12970         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12971                                  "vni");
12972 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
12973         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, RTE_UINT32);
12974 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
12975         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12976                                  "udp-src");
12977 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
12978         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, RTE_UINT16);
12979 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
12980         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12981                                  "udp-dst");
12982 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
12983         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, RTE_UINT16);
12984 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
12985         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12986                                  "ip-tos");
12987 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
12988         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, RTE_UINT8);
12989 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
12990         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12991                                  "ip-ttl");
12992 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
12993         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, RTE_UINT8);
12994 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
12995         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
12996                                  "ip-src");
12997 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
12998         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
12999 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
13000         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13001                                  "ip-dst");
13002 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
13003         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
13004 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
13005         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13006                                  "vlan-tci");
13007 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
13008         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, RTE_UINT16);
13009 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
13010         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13011                                  "eth-src");
13012 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
13013         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
13014 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
13015         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
13016                                  "eth-dst");
13017 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
13018         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
13019
13020 static void cmd_set_vxlan_parsed(void *parsed_result,
13021         __rte_unused struct cmdline *cl,
13022         __rte_unused void *data)
13023 {
13024         struct cmd_set_vxlan_result *res = parsed_result;
13025         union {
13026                 uint32_t vxlan_id;
13027                 uint8_t vni[4];
13028         } id = {
13029                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
13030         };
13031
13032         vxlan_encap_conf.select_tos_ttl = 0;
13033         if (strcmp(res->vxlan, "vxlan") == 0)
13034                 vxlan_encap_conf.select_vlan = 0;
13035         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
13036                 vxlan_encap_conf.select_vlan = 1;
13037         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
13038                 vxlan_encap_conf.select_vlan = 0;
13039                 vxlan_encap_conf.select_tos_ttl = 1;
13040         }
13041         if (strcmp(res->ip_version, "ipv4") == 0)
13042                 vxlan_encap_conf.select_ipv4 = 1;
13043         else if (strcmp(res->ip_version, "ipv6") == 0)
13044                 vxlan_encap_conf.select_ipv4 = 0;
13045         else
13046                 return;
13047         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
13048         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13049         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13050         vxlan_encap_conf.ip_tos = res->tos;
13051         vxlan_encap_conf.ip_ttl = res->ttl;
13052         if (vxlan_encap_conf.select_ipv4) {
13053                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
13054                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
13055         } else {
13056                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
13057                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
13058         }
13059         if (vxlan_encap_conf.select_vlan)
13060                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13061         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
13062                    RTE_ETHER_ADDR_LEN);
13063         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13064                    RTE_ETHER_ADDR_LEN);
13065 }
13066
13067 cmdline_parse_inst_t cmd_set_vxlan = {
13068         .f = cmd_set_vxlan_parsed,
13069         .data = NULL,
13070         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
13071                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
13072                 " eth-src <eth-src> eth-dst <eth-dst>",
13073         .tokens = {
13074                 (void *)&cmd_set_vxlan_set,
13075                 (void *)&cmd_set_vxlan_vxlan,
13076                 (void *)&cmd_set_vxlan_ip_version,
13077                 (void *)&cmd_set_vxlan_ip_version_value,
13078                 (void *)&cmd_set_vxlan_vni,
13079                 (void *)&cmd_set_vxlan_vni_value,
13080                 (void *)&cmd_set_vxlan_udp_src,
13081                 (void *)&cmd_set_vxlan_udp_src_value,
13082                 (void *)&cmd_set_vxlan_udp_dst,
13083                 (void *)&cmd_set_vxlan_udp_dst_value,
13084                 (void *)&cmd_set_vxlan_ip_src,
13085                 (void *)&cmd_set_vxlan_ip_src_value,
13086                 (void *)&cmd_set_vxlan_ip_dst,
13087                 (void *)&cmd_set_vxlan_ip_dst_value,
13088                 (void *)&cmd_set_vxlan_eth_src,
13089                 (void *)&cmd_set_vxlan_eth_src_value,
13090                 (void *)&cmd_set_vxlan_eth_dst,
13091                 (void *)&cmd_set_vxlan_eth_dst_value,
13092                 NULL,
13093         },
13094 };
13095
13096 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
13097         .f = cmd_set_vxlan_parsed,
13098         .data = NULL,
13099         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
13100                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
13101                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13102                 " eth-dst <eth-dst>",
13103         .tokens = {
13104                 (void *)&cmd_set_vxlan_set,
13105                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
13106                 (void *)&cmd_set_vxlan_ip_version,
13107                 (void *)&cmd_set_vxlan_ip_version_value,
13108                 (void *)&cmd_set_vxlan_vni,
13109                 (void *)&cmd_set_vxlan_vni_value,
13110                 (void *)&cmd_set_vxlan_udp_src,
13111                 (void *)&cmd_set_vxlan_udp_src_value,
13112                 (void *)&cmd_set_vxlan_udp_dst,
13113                 (void *)&cmd_set_vxlan_udp_dst_value,
13114                 (void *)&cmd_set_vxlan_ip_tos,
13115                 (void *)&cmd_set_vxlan_ip_tos_value,
13116                 (void *)&cmd_set_vxlan_ip_ttl,
13117                 (void *)&cmd_set_vxlan_ip_ttl_value,
13118                 (void *)&cmd_set_vxlan_ip_src,
13119                 (void *)&cmd_set_vxlan_ip_src_value,
13120                 (void *)&cmd_set_vxlan_ip_dst,
13121                 (void *)&cmd_set_vxlan_ip_dst_value,
13122                 (void *)&cmd_set_vxlan_eth_src,
13123                 (void *)&cmd_set_vxlan_eth_src_value,
13124                 (void *)&cmd_set_vxlan_eth_dst,
13125                 (void *)&cmd_set_vxlan_eth_dst_value,
13126                 NULL,
13127         },
13128 };
13129
13130 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
13131         .f = cmd_set_vxlan_parsed,
13132         .data = NULL,
13133         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
13134                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
13135                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
13136                 " <eth-dst>",
13137         .tokens = {
13138                 (void *)&cmd_set_vxlan_set,
13139                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
13140                 (void *)&cmd_set_vxlan_ip_version,
13141                 (void *)&cmd_set_vxlan_ip_version_value,
13142                 (void *)&cmd_set_vxlan_vni,
13143                 (void *)&cmd_set_vxlan_vni_value,
13144                 (void *)&cmd_set_vxlan_udp_src,
13145                 (void *)&cmd_set_vxlan_udp_src_value,
13146                 (void *)&cmd_set_vxlan_udp_dst,
13147                 (void *)&cmd_set_vxlan_udp_dst_value,
13148                 (void *)&cmd_set_vxlan_ip_src,
13149                 (void *)&cmd_set_vxlan_ip_src_value,
13150                 (void *)&cmd_set_vxlan_ip_dst,
13151                 (void *)&cmd_set_vxlan_ip_dst_value,
13152                 (void *)&cmd_set_vxlan_vlan,
13153                 (void *)&cmd_set_vxlan_vlan_value,
13154                 (void *)&cmd_set_vxlan_eth_src,
13155                 (void *)&cmd_set_vxlan_eth_src_value,
13156                 (void *)&cmd_set_vxlan_eth_dst,
13157                 (void *)&cmd_set_vxlan_eth_dst_value,
13158                 NULL,
13159         },
13160 };
13161
13162 /** Set NVGRE encapsulation details */
13163 struct cmd_set_nvgre_result {
13164         cmdline_fixed_string_t set;
13165         cmdline_fixed_string_t nvgre;
13166         cmdline_fixed_string_t pos_token;
13167         cmdline_fixed_string_t ip_version;
13168         uint32_t tni;
13169         cmdline_ipaddr_t ip_src;
13170         cmdline_ipaddr_t ip_dst;
13171         uint16_t tci;
13172         struct rte_ether_addr eth_src;
13173         struct rte_ether_addr eth_dst;
13174 };
13175
13176 cmdline_parse_token_string_t cmd_set_nvgre_set =
13177         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
13178 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
13179         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
13180 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
13181         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
13182                                  "nvgre-with-vlan");
13183 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
13184         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13185                                  "ip-version");
13186 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
13187         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
13188                                  "ipv4#ipv6");
13189 cmdline_parse_token_string_t cmd_set_nvgre_tni =
13190         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13191                                  "tni");
13192 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
13193         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, RTE_UINT32);
13194 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
13195         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13196                                  "ip-src");
13197 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
13198         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
13199 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
13200         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13201                                  "ip-dst");
13202 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
13203         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
13204 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
13205         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13206                                  "vlan-tci");
13207 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
13208         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, RTE_UINT16);
13209 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
13210         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13211                                  "eth-src");
13212 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
13213         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
13214 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
13215         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
13216                                  "eth-dst");
13217 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
13218         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
13219
13220 static void cmd_set_nvgre_parsed(void *parsed_result,
13221         __rte_unused struct cmdline *cl,
13222         __rte_unused void *data)
13223 {
13224         struct cmd_set_nvgre_result *res = parsed_result;
13225         union {
13226                 uint32_t nvgre_tni;
13227                 uint8_t tni[4];
13228         } id = {
13229                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
13230         };
13231
13232         if (strcmp(res->nvgre, "nvgre") == 0)
13233                 nvgre_encap_conf.select_vlan = 0;
13234         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
13235                 nvgre_encap_conf.select_vlan = 1;
13236         if (strcmp(res->ip_version, "ipv4") == 0)
13237                 nvgre_encap_conf.select_ipv4 = 1;
13238         else if (strcmp(res->ip_version, "ipv6") == 0)
13239                 nvgre_encap_conf.select_ipv4 = 0;
13240         else
13241                 return;
13242         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
13243         if (nvgre_encap_conf.select_ipv4) {
13244                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
13245                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
13246         } else {
13247                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
13248                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
13249         }
13250         if (nvgre_encap_conf.select_vlan)
13251                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13252         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
13253                    RTE_ETHER_ADDR_LEN);
13254         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13255                    RTE_ETHER_ADDR_LEN);
13256 }
13257
13258 cmdline_parse_inst_t cmd_set_nvgre = {
13259         .f = cmd_set_nvgre_parsed,
13260         .data = NULL,
13261         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
13262                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13263                 " eth-dst <eth-dst>",
13264         .tokens = {
13265                 (void *)&cmd_set_nvgre_set,
13266                 (void *)&cmd_set_nvgre_nvgre,
13267                 (void *)&cmd_set_nvgre_ip_version,
13268                 (void *)&cmd_set_nvgre_ip_version_value,
13269                 (void *)&cmd_set_nvgre_tni,
13270                 (void *)&cmd_set_nvgre_tni_value,
13271                 (void *)&cmd_set_nvgre_ip_src,
13272                 (void *)&cmd_set_nvgre_ip_src_value,
13273                 (void *)&cmd_set_nvgre_ip_dst,
13274                 (void *)&cmd_set_nvgre_ip_dst_value,
13275                 (void *)&cmd_set_nvgre_eth_src,
13276                 (void *)&cmd_set_nvgre_eth_src_value,
13277                 (void *)&cmd_set_nvgre_eth_dst,
13278                 (void *)&cmd_set_nvgre_eth_dst_value,
13279                 NULL,
13280         },
13281 };
13282
13283 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
13284         .f = cmd_set_nvgre_parsed,
13285         .data = NULL,
13286         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
13287                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13288                 " eth-src <eth-src> eth-dst <eth-dst>",
13289         .tokens = {
13290                 (void *)&cmd_set_nvgre_set,
13291                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
13292                 (void *)&cmd_set_nvgre_ip_version,
13293                 (void *)&cmd_set_nvgre_ip_version_value,
13294                 (void *)&cmd_set_nvgre_tni,
13295                 (void *)&cmd_set_nvgre_tni_value,
13296                 (void *)&cmd_set_nvgre_ip_src,
13297                 (void *)&cmd_set_nvgre_ip_src_value,
13298                 (void *)&cmd_set_nvgre_ip_dst,
13299                 (void *)&cmd_set_nvgre_ip_dst_value,
13300                 (void *)&cmd_set_nvgre_vlan,
13301                 (void *)&cmd_set_nvgre_vlan_value,
13302                 (void *)&cmd_set_nvgre_eth_src,
13303                 (void *)&cmd_set_nvgre_eth_src_value,
13304                 (void *)&cmd_set_nvgre_eth_dst,
13305                 (void *)&cmd_set_nvgre_eth_dst_value,
13306                 NULL,
13307         },
13308 };
13309
13310 /** Set L2 encapsulation details */
13311 struct cmd_set_l2_encap_result {
13312         cmdline_fixed_string_t set;
13313         cmdline_fixed_string_t l2_encap;
13314         cmdline_fixed_string_t pos_token;
13315         cmdline_fixed_string_t ip_version;
13316         uint32_t vlan_present:1;
13317         uint16_t tci;
13318         struct rte_ether_addr eth_src;
13319         struct rte_ether_addr eth_dst;
13320 };
13321
13322 cmdline_parse_token_string_t cmd_set_l2_encap_set =
13323         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
13324 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
13325         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
13326 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
13327         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
13328                                  "l2_encap-with-vlan");
13329 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
13330         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13331                                  "ip-version");
13332 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
13333         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
13334                                  "ipv4#ipv6");
13335 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
13336         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13337                                  "vlan-tci");
13338 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
13339         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, RTE_UINT16);
13340 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
13341         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13342                                  "eth-src");
13343 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
13344         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
13345 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
13346         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
13347                                  "eth-dst");
13348 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
13349         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
13350
13351 static void cmd_set_l2_encap_parsed(void *parsed_result,
13352         __rte_unused struct cmdline *cl,
13353         __rte_unused void *data)
13354 {
13355         struct cmd_set_l2_encap_result *res = parsed_result;
13356
13357         if (strcmp(res->l2_encap, "l2_encap") == 0)
13358                 l2_encap_conf.select_vlan = 0;
13359         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
13360                 l2_encap_conf.select_vlan = 1;
13361         if (strcmp(res->ip_version, "ipv4") == 0)
13362                 l2_encap_conf.select_ipv4 = 1;
13363         else if (strcmp(res->ip_version, "ipv6") == 0)
13364                 l2_encap_conf.select_ipv4 = 0;
13365         else
13366                 return;
13367         if (l2_encap_conf.select_vlan)
13368                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13369         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
13370                    RTE_ETHER_ADDR_LEN);
13371         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13372                    RTE_ETHER_ADDR_LEN);
13373 }
13374
13375 cmdline_parse_inst_t cmd_set_l2_encap = {
13376         .f = cmd_set_l2_encap_parsed,
13377         .data = NULL,
13378         .help_str = "set l2_encap ip-version ipv4|ipv6"
13379                 " eth-src <eth-src> eth-dst <eth-dst>",
13380         .tokens = {
13381                 (void *)&cmd_set_l2_encap_set,
13382                 (void *)&cmd_set_l2_encap_l2_encap,
13383                 (void *)&cmd_set_l2_encap_ip_version,
13384                 (void *)&cmd_set_l2_encap_ip_version_value,
13385                 (void *)&cmd_set_l2_encap_eth_src,
13386                 (void *)&cmd_set_l2_encap_eth_src_value,
13387                 (void *)&cmd_set_l2_encap_eth_dst,
13388                 (void *)&cmd_set_l2_encap_eth_dst_value,
13389                 NULL,
13390         },
13391 };
13392
13393 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
13394         .f = cmd_set_l2_encap_parsed,
13395         .data = NULL,
13396         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
13397                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13398         .tokens = {
13399                 (void *)&cmd_set_l2_encap_set,
13400                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
13401                 (void *)&cmd_set_l2_encap_ip_version,
13402                 (void *)&cmd_set_l2_encap_ip_version_value,
13403                 (void *)&cmd_set_l2_encap_vlan,
13404                 (void *)&cmd_set_l2_encap_vlan_value,
13405                 (void *)&cmd_set_l2_encap_eth_src,
13406                 (void *)&cmd_set_l2_encap_eth_src_value,
13407                 (void *)&cmd_set_l2_encap_eth_dst,
13408                 (void *)&cmd_set_l2_encap_eth_dst_value,
13409                 NULL,
13410         },
13411 };
13412
13413 /** Set L2 decapsulation details */
13414 struct cmd_set_l2_decap_result {
13415         cmdline_fixed_string_t set;
13416         cmdline_fixed_string_t l2_decap;
13417         cmdline_fixed_string_t pos_token;
13418         uint32_t vlan_present:1;
13419 };
13420
13421 cmdline_parse_token_string_t cmd_set_l2_decap_set =
13422         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
13423 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
13424         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13425                                  "l2_decap");
13426 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
13427         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
13428                                  "l2_decap-with-vlan");
13429
13430 static void cmd_set_l2_decap_parsed(void *parsed_result,
13431         __rte_unused struct cmdline *cl,
13432         __rte_unused void *data)
13433 {
13434         struct cmd_set_l2_decap_result *res = parsed_result;
13435
13436         if (strcmp(res->l2_decap, "l2_decap") == 0)
13437                 l2_decap_conf.select_vlan = 0;
13438         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
13439                 l2_decap_conf.select_vlan = 1;
13440 }
13441
13442 cmdline_parse_inst_t cmd_set_l2_decap = {
13443         .f = cmd_set_l2_decap_parsed,
13444         .data = NULL,
13445         .help_str = "set l2_decap",
13446         .tokens = {
13447                 (void *)&cmd_set_l2_decap_set,
13448                 (void *)&cmd_set_l2_decap_l2_decap,
13449                 NULL,
13450         },
13451 };
13452
13453 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
13454         .f = cmd_set_l2_decap_parsed,
13455         .data = NULL,
13456         .help_str = "set l2_decap-with-vlan",
13457         .tokens = {
13458                 (void *)&cmd_set_l2_decap_set,
13459                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
13460                 NULL,
13461         },
13462 };
13463
13464 /** Set MPLSoGRE encapsulation details */
13465 struct cmd_set_mplsogre_encap_result {
13466         cmdline_fixed_string_t set;
13467         cmdline_fixed_string_t mplsogre;
13468         cmdline_fixed_string_t pos_token;
13469         cmdline_fixed_string_t ip_version;
13470         uint32_t vlan_present:1;
13471         uint32_t label;
13472         cmdline_ipaddr_t ip_src;
13473         cmdline_ipaddr_t ip_dst;
13474         uint16_t tci;
13475         struct rte_ether_addr eth_src;
13476         struct rte_ether_addr eth_dst;
13477 };
13478
13479 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
13480         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
13481                                  "set");
13482 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
13483         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
13484                                  "mplsogre_encap");
13485 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
13486         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13487                                  mplsogre, "mplsogre_encap-with-vlan");
13488 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
13489         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13490                                  pos_token, "ip-version");
13491 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
13492         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13493                                  ip_version, "ipv4#ipv6");
13494 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
13495         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13496                                  pos_token, "label");
13497 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
13498         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
13499                               RTE_UINT32);
13500 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
13501         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13502                                  pos_token, "ip-src");
13503 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
13504         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
13505 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
13506         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13507                                  pos_token, "ip-dst");
13508 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
13509         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
13510 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
13511         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13512                                  pos_token, "vlan-tci");
13513 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
13514         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
13515                               RTE_UINT16);
13516 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
13517         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13518                                  pos_token, "eth-src");
13519 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
13520         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13521                                     eth_src);
13522 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
13523         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13524                                  pos_token, "eth-dst");
13525 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
13526         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
13527                                     eth_dst);
13528
13529 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
13530         __rte_unused struct cmdline *cl,
13531         __rte_unused void *data)
13532 {
13533         struct cmd_set_mplsogre_encap_result *res = parsed_result;
13534         union {
13535                 uint32_t mplsogre_label;
13536                 uint8_t label[4];
13537         } id = {
13538                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
13539         };
13540
13541         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
13542                 mplsogre_encap_conf.select_vlan = 0;
13543         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
13544                 mplsogre_encap_conf.select_vlan = 1;
13545         if (strcmp(res->ip_version, "ipv4") == 0)
13546                 mplsogre_encap_conf.select_ipv4 = 1;
13547         else if (strcmp(res->ip_version, "ipv6") == 0)
13548                 mplsogre_encap_conf.select_ipv4 = 0;
13549         else
13550                 return;
13551         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
13552         if (mplsogre_encap_conf.select_ipv4) {
13553                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
13554                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
13555         } else {
13556                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
13557                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
13558         }
13559         if (mplsogre_encap_conf.select_vlan)
13560                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13561         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
13562                    RTE_ETHER_ADDR_LEN);
13563         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13564                    RTE_ETHER_ADDR_LEN);
13565 }
13566
13567 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
13568         .f = cmd_set_mplsogre_encap_parsed,
13569         .data = NULL,
13570         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
13571                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
13572                 " eth-dst <eth-dst>",
13573         .tokens = {
13574                 (void *)&cmd_set_mplsogre_encap_set,
13575                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
13576                 (void *)&cmd_set_mplsogre_encap_ip_version,
13577                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13578                 (void *)&cmd_set_mplsogre_encap_label,
13579                 (void *)&cmd_set_mplsogre_encap_label_value,
13580                 (void *)&cmd_set_mplsogre_encap_ip_src,
13581                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13582                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13583                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13584                 (void *)&cmd_set_mplsogre_encap_eth_src,
13585                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13586                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13587                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13588                 NULL,
13589         },
13590 };
13591
13592 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
13593         .f = cmd_set_mplsogre_encap_parsed,
13594         .data = NULL,
13595         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
13596                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
13597                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
13598         .tokens = {
13599                 (void *)&cmd_set_mplsogre_encap_set,
13600                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
13601                 (void *)&cmd_set_mplsogre_encap_ip_version,
13602                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
13603                 (void *)&cmd_set_mplsogre_encap_label,
13604                 (void *)&cmd_set_mplsogre_encap_label_value,
13605                 (void *)&cmd_set_mplsogre_encap_ip_src,
13606                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
13607                 (void *)&cmd_set_mplsogre_encap_ip_dst,
13608                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
13609                 (void *)&cmd_set_mplsogre_encap_vlan,
13610                 (void *)&cmd_set_mplsogre_encap_vlan_value,
13611                 (void *)&cmd_set_mplsogre_encap_eth_src,
13612                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
13613                 (void *)&cmd_set_mplsogre_encap_eth_dst,
13614                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
13615                 NULL,
13616         },
13617 };
13618
13619 /** Set MPLSoGRE decapsulation details */
13620 struct cmd_set_mplsogre_decap_result {
13621         cmdline_fixed_string_t set;
13622         cmdline_fixed_string_t mplsogre;
13623         cmdline_fixed_string_t pos_token;
13624         cmdline_fixed_string_t ip_version;
13625         uint32_t vlan_present:1;
13626 };
13627
13628 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
13629         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
13630                                  "set");
13631 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
13632         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
13633                                  "mplsogre_decap");
13634 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
13635         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13636                                  mplsogre, "mplsogre_decap-with-vlan");
13637 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
13638         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13639                                  pos_token, "ip-version");
13640 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
13641         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
13642                                  ip_version, "ipv4#ipv6");
13643
13644 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
13645         __rte_unused struct cmdline *cl,
13646         __rte_unused void *data)
13647 {
13648         struct cmd_set_mplsogre_decap_result *res = parsed_result;
13649
13650         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
13651                 mplsogre_decap_conf.select_vlan = 0;
13652         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
13653                 mplsogre_decap_conf.select_vlan = 1;
13654         if (strcmp(res->ip_version, "ipv4") == 0)
13655                 mplsogre_decap_conf.select_ipv4 = 1;
13656         else if (strcmp(res->ip_version, "ipv6") == 0)
13657                 mplsogre_decap_conf.select_ipv4 = 0;
13658 }
13659
13660 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
13661         .f = cmd_set_mplsogre_decap_parsed,
13662         .data = NULL,
13663         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
13664         .tokens = {
13665                 (void *)&cmd_set_mplsogre_decap_set,
13666                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
13667                 (void *)&cmd_set_mplsogre_decap_ip_version,
13668                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13669                 NULL,
13670         },
13671 };
13672
13673 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
13674         .f = cmd_set_mplsogre_decap_parsed,
13675         .data = NULL,
13676         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
13677         .tokens = {
13678                 (void *)&cmd_set_mplsogre_decap_set,
13679                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
13680                 (void *)&cmd_set_mplsogre_decap_ip_version,
13681                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
13682                 NULL,
13683         },
13684 };
13685
13686 /** Set MPLSoUDP encapsulation details */
13687 struct cmd_set_mplsoudp_encap_result {
13688         cmdline_fixed_string_t set;
13689         cmdline_fixed_string_t mplsoudp;
13690         cmdline_fixed_string_t pos_token;
13691         cmdline_fixed_string_t ip_version;
13692         uint32_t vlan_present:1;
13693         uint32_t label;
13694         uint16_t udp_src;
13695         uint16_t udp_dst;
13696         cmdline_ipaddr_t ip_src;
13697         cmdline_ipaddr_t ip_dst;
13698         uint16_t tci;
13699         struct rte_ether_addr eth_src;
13700         struct rte_ether_addr eth_dst;
13701 };
13702
13703 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
13704         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
13705                                  "set");
13706 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
13707         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
13708                                  "mplsoudp_encap");
13709 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
13710         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13711                                  mplsoudp, "mplsoudp_encap-with-vlan");
13712 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
13713         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13714                                  pos_token, "ip-version");
13715 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
13716         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13717                                  ip_version, "ipv4#ipv6");
13718 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
13719         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13720                                  pos_token, "label");
13721 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
13722         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
13723                               RTE_UINT32);
13724 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
13725         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13726                                  pos_token, "udp-src");
13727 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
13728         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
13729                               RTE_UINT16);
13730 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
13731         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13732                                  pos_token, "udp-dst");
13733 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
13734         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
13735                               RTE_UINT16);
13736 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
13737         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13738                                  pos_token, "ip-src");
13739 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
13740         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
13741 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
13742         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13743                                  pos_token, "ip-dst");
13744 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
13745         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
13746 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
13747         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13748                                  pos_token, "vlan-tci");
13749 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
13750         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
13751                               RTE_UINT16);
13752 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
13753         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13754                                  pos_token, "eth-src");
13755 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
13756         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13757                                     eth_src);
13758 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
13759         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13760                                  pos_token, "eth-dst");
13761 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
13762         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
13763                                     eth_dst);
13764
13765 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
13766         __rte_unused struct cmdline *cl,
13767         __rte_unused void *data)
13768 {
13769         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
13770         union {
13771                 uint32_t mplsoudp_label;
13772                 uint8_t label[4];
13773         } id = {
13774                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
13775         };
13776
13777         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
13778                 mplsoudp_encap_conf.select_vlan = 0;
13779         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
13780                 mplsoudp_encap_conf.select_vlan = 1;
13781         if (strcmp(res->ip_version, "ipv4") == 0)
13782                 mplsoudp_encap_conf.select_ipv4 = 1;
13783         else if (strcmp(res->ip_version, "ipv6") == 0)
13784                 mplsoudp_encap_conf.select_ipv4 = 0;
13785         else
13786                 return;
13787         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
13788         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
13789         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
13790         if (mplsoudp_encap_conf.select_ipv4) {
13791                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
13792                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
13793         } else {
13794                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
13795                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
13796         }
13797         if (mplsoudp_encap_conf.select_vlan)
13798                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
13799         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
13800                    RTE_ETHER_ADDR_LEN);
13801         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
13802                    RTE_ETHER_ADDR_LEN);
13803 }
13804
13805 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
13806         .f = cmd_set_mplsoudp_encap_parsed,
13807         .data = NULL,
13808         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
13809                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
13810                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
13811         .tokens = {
13812                 (void *)&cmd_set_mplsoudp_encap_set,
13813                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
13814                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13815                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13816                 (void *)&cmd_set_mplsoudp_encap_label,
13817                 (void *)&cmd_set_mplsoudp_encap_label_value,
13818                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13819                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13820                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13821                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13822                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13823                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13824                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13825                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13826                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13827                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13828                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13829                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13830                 NULL,
13831         },
13832 };
13833
13834 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
13835         .f = cmd_set_mplsoudp_encap_parsed,
13836         .data = NULL,
13837         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
13838                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
13839                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
13840                 " eth-src <eth-src> eth-dst <eth-dst>",
13841         .tokens = {
13842                 (void *)&cmd_set_mplsoudp_encap_set,
13843                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
13844                 (void *)&cmd_set_mplsoudp_encap_ip_version,
13845                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
13846                 (void *)&cmd_set_mplsoudp_encap_label,
13847                 (void *)&cmd_set_mplsoudp_encap_label_value,
13848                 (void *)&cmd_set_mplsoudp_encap_udp_src,
13849                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
13850                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
13851                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
13852                 (void *)&cmd_set_mplsoudp_encap_ip_src,
13853                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
13854                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
13855                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
13856                 (void *)&cmd_set_mplsoudp_encap_vlan,
13857                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
13858                 (void *)&cmd_set_mplsoudp_encap_eth_src,
13859                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
13860                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
13861                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
13862                 NULL,
13863         },
13864 };
13865
13866 /** Set MPLSoUDP decapsulation details */
13867 struct cmd_set_mplsoudp_decap_result {
13868         cmdline_fixed_string_t set;
13869         cmdline_fixed_string_t mplsoudp;
13870         cmdline_fixed_string_t pos_token;
13871         cmdline_fixed_string_t ip_version;
13872         uint32_t vlan_present:1;
13873 };
13874
13875 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
13876         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
13877                                  "set");
13878 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
13879         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
13880                                  "mplsoudp_decap");
13881 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
13882         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13883                                  mplsoudp, "mplsoudp_decap-with-vlan");
13884 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
13885         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13886                                  pos_token, "ip-version");
13887 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
13888         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
13889                                  ip_version, "ipv4#ipv6");
13890
13891 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
13892         __rte_unused struct cmdline *cl,
13893         __rte_unused void *data)
13894 {
13895         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
13896
13897         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
13898                 mplsoudp_decap_conf.select_vlan = 0;
13899         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
13900                 mplsoudp_decap_conf.select_vlan = 1;
13901         if (strcmp(res->ip_version, "ipv4") == 0)
13902                 mplsoudp_decap_conf.select_ipv4 = 1;
13903         else if (strcmp(res->ip_version, "ipv6") == 0)
13904                 mplsoudp_decap_conf.select_ipv4 = 0;
13905 }
13906
13907 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
13908         .f = cmd_set_mplsoudp_decap_parsed,
13909         .data = NULL,
13910         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
13911         .tokens = {
13912                 (void *)&cmd_set_mplsoudp_decap_set,
13913                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
13914                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13915                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13916                 NULL,
13917         },
13918 };
13919
13920 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
13921         .f = cmd_set_mplsoudp_decap_parsed,
13922         .data = NULL,
13923         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
13924         .tokens = {
13925                 (void *)&cmd_set_mplsoudp_decap_set,
13926                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
13927                 (void *)&cmd_set_mplsoudp_decap_ip_version,
13928                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
13929                 NULL,
13930         },
13931 };
13932
13933 /** Set connection tracking object common details */
13934 struct cmd_set_conntrack_common_result {
13935         cmdline_fixed_string_t set;
13936         cmdline_fixed_string_t conntrack;
13937         cmdline_fixed_string_t common;
13938         cmdline_fixed_string_t peer;
13939         cmdline_fixed_string_t is_orig;
13940         cmdline_fixed_string_t enable;
13941         cmdline_fixed_string_t live;
13942         cmdline_fixed_string_t sack;
13943         cmdline_fixed_string_t cack;
13944         cmdline_fixed_string_t last_dir;
13945         cmdline_fixed_string_t liberal;
13946         cmdline_fixed_string_t state;
13947         cmdline_fixed_string_t max_ack_win;
13948         cmdline_fixed_string_t retrans;
13949         cmdline_fixed_string_t last_win;
13950         cmdline_fixed_string_t last_seq;
13951         cmdline_fixed_string_t last_ack;
13952         cmdline_fixed_string_t last_end;
13953         cmdline_fixed_string_t last_index;
13954         uint8_t stat;
13955         uint8_t factor;
13956         uint16_t peer_port;
13957         uint32_t is_original;
13958         uint32_t en;
13959         uint32_t is_live;
13960         uint32_t s_ack;
13961         uint32_t c_ack;
13962         uint32_t ld;
13963         uint32_t lb;
13964         uint8_t re_num;
13965         uint8_t li;
13966         uint16_t lw;
13967         uint32_t ls;
13968         uint32_t la;
13969         uint32_t le;
13970 };
13971
13972 cmdline_parse_token_string_t cmd_set_conntrack_set =
13973         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13974                                  set, "set");
13975 cmdline_parse_token_string_t cmd_set_conntrack_conntrack =
13976         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13977                                  conntrack, "conntrack");
13978 cmdline_parse_token_string_t cmd_set_conntrack_common_com =
13979         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13980                                  common, "com");
13981 cmdline_parse_token_string_t cmd_set_conntrack_common_peer =
13982         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13983                                  peer, "peer");
13984 cmdline_parse_token_num_t cmd_set_conntrack_common_peer_value =
13985         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13986                               peer_port, RTE_UINT16);
13987 cmdline_parse_token_string_t cmd_set_conntrack_common_is_orig =
13988         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13989                                  is_orig, "is_orig");
13990 cmdline_parse_token_num_t cmd_set_conntrack_common_is_orig_value =
13991         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13992                               is_original, RTE_UINT32);
13993 cmdline_parse_token_string_t cmd_set_conntrack_common_enable =
13994         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
13995                                  enable, "enable");
13996 cmdline_parse_token_num_t cmd_set_conntrack_common_enable_value =
13997         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
13998                               en, RTE_UINT32);
13999 cmdline_parse_token_string_t cmd_set_conntrack_common_live =
14000         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14001                                  live, "live");
14002 cmdline_parse_token_num_t cmd_set_conntrack_common_live_value =
14003         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14004                               is_live, RTE_UINT32);
14005 cmdline_parse_token_string_t cmd_set_conntrack_common_sack =
14006         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14007                                  sack, "sack");
14008 cmdline_parse_token_num_t cmd_set_conntrack_common_sack_value =
14009         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14010                               s_ack, RTE_UINT32);
14011 cmdline_parse_token_string_t cmd_set_conntrack_common_cack =
14012         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14013                                  cack, "cack");
14014 cmdline_parse_token_num_t cmd_set_conntrack_common_cack_value =
14015         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14016                               c_ack, RTE_UINT32);
14017 cmdline_parse_token_string_t cmd_set_conntrack_common_last_dir =
14018         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14019                                  last_dir, "last_dir");
14020 cmdline_parse_token_num_t cmd_set_conntrack_common_last_dir_value =
14021         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14022                               ld, RTE_UINT32);
14023 cmdline_parse_token_string_t cmd_set_conntrack_common_liberal =
14024         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14025                                  liberal, "liberal");
14026 cmdline_parse_token_num_t cmd_set_conntrack_common_liberal_value =
14027         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14028                               lb, RTE_UINT32);
14029 cmdline_parse_token_string_t cmd_set_conntrack_common_state =
14030         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14031                                  state, "state");
14032 cmdline_parse_token_num_t cmd_set_conntrack_common_state_value =
14033         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14034                               stat, RTE_UINT8);
14035 cmdline_parse_token_string_t cmd_set_conntrack_common_max_ackwin =
14036         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14037                                  max_ack_win, "max_ack_win");
14038 cmdline_parse_token_num_t cmd_set_conntrack_common_max_ackwin_value =
14039         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14040                               factor, RTE_UINT8);
14041 cmdline_parse_token_string_t cmd_set_conntrack_common_retrans =
14042         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14043                                  retrans, "r_lim");
14044 cmdline_parse_token_num_t cmd_set_conntrack_common_retrans_value =
14045         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14046                               re_num, RTE_UINT8);
14047 cmdline_parse_token_string_t cmd_set_conntrack_common_last_win =
14048         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14049                                  last_win, "last_win");
14050 cmdline_parse_token_num_t cmd_set_conntrack_common_last_win_value =
14051         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14052                               lw, RTE_UINT16);
14053 cmdline_parse_token_string_t cmd_set_conntrack_common_last_seq =
14054         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14055                                  last_seq, "last_seq");
14056 cmdline_parse_token_num_t cmd_set_conntrack_common_last_seq_value =
14057         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14058                               ls, RTE_UINT32);
14059 cmdline_parse_token_string_t cmd_set_conntrack_common_last_ack =
14060         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14061                                  last_ack, "last_ack");
14062 cmdline_parse_token_num_t cmd_set_conntrack_common_last_ack_value =
14063         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14064                               la, RTE_UINT32);
14065 cmdline_parse_token_string_t cmd_set_conntrack_common_last_end =
14066         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14067                                  last_end, "last_end");
14068 cmdline_parse_token_num_t cmd_set_conntrack_common_last_end_value =
14069         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14070                               le, RTE_UINT32);
14071 cmdline_parse_token_string_t cmd_set_conntrack_common_last_index =
14072         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_common_result,
14073                                  last_index, "last_index");
14074 cmdline_parse_token_num_t cmd_set_conntrack_common_last_index_value =
14075         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_common_result,
14076                               li, RTE_UINT8);
14077
14078 static void cmd_set_conntrack_common_parsed(void *parsed_result,
14079         __rte_unused struct cmdline *cl,
14080         __rte_unused void *data)
14081 {
14082         struct cmd_set_conntrack_common_result *res = parsed_result;
14083
14084         /* No need to swap to big endian. */
14085         conntrack_context.peer_port = res->peer_port;
14086         conntrack_context.is_original_dir = res->is_original;
14087         conntrack_context.enable = res->en;
14088         conntrack_context.live_connection = res->is_live;
14089         conntrack_context.selective_ack = res->s_ack;
14090         conntrack_context.challenge_ack_passed = res->c_ack;
14091         conntrack_context.last_direction = res->ld;
14092         conntrack_context.liberal_mode = res->lb;
14093         conntrack_context.state = (enum rte_flow_conntrack_state)res->stat;
14094         conntrack_context.max_ack_window = res->factor;
14095         conntrack_context.retransmission_limit = res->re_num;
14096         conntrack_context.last_window = res->lw;
14097         conntrack_context.last_index =
14098                 (enum rte_flow_conntrack_tcp_last_index)res->li;
14099         conntrack_context.last_seq = res->ls;
14100         conntrack_context.last_ack = res->la;
14101         conntrack_context.last_end = res->le;
14102 }
14103
14104 cmdline_parse_inst_t cmd_set_conntrack_common = {
14105         .f = cmd_set_conntrack_common_parsed,
14106         .data = NULL,
14107         .help_str = "set conntrack com peer <port_id> is_orig <dir> enable <en>"
14108                 " live <ack_seen> sack <en> cack <passed> last_dir <dir>"
14109                 " liberal <en> state <s> max_ack_win <factor> r_lim <num>"
14110                 " last_win <win> last_seq <seq> last_ack <ack> last_end <end>"
14111                 " last_index <flag>",
14112         .tokens = {
14113                 (void *)&cmd_set_conntrack_set,
14114                 (void *)&cmd_set_conntrack_conntrack,
14115                 (void *)&cmd_set_conntrack_common_com,
14116                 (void *)&cmd_set_conntrack_common_peer,
14117                 (void *)&cmd_set_conntrack_common_peer_value,
14118                 (void *)&cmd_set_conntrack_common_is_orig,
14119                 (void *)&cmd_set_conntrack_common_is_orig_value,
14120                 (void *)&cmd_set_conntrack_common_enable,
14121                 (void *)&cmd_set_conntrack_common_enable_value,
14122                 (void *)&cmd_set_conntrack_common_live,
14123                 (void *)&cmd_set_conntrack_common_live_value,
14124                 (void *)&cmd_set_conntrack_common_sack,
14125                 (void *)&cmd_set_conntrack_common_sack_value,
14126                 (void *)&cmd_set_conntrack_common_cack,
14127                 (void *)&cmd_set_conntrack_common_cack_value,
14128                 (void *)&cmd_set_conntrack_common_last_dir,
14129                 (void *)&cmd_set_conntrack_common_last_dir_value,
14130                 (void *)&cmd_set_conntrack_common_liberal,
14131                 (void *)&cmd_set_conntrack_common_liberal_value,
14132                 (void *)&cmd_set_conntrack_common_state,
14133                 (void *)&cmd_set_conntrack_common_state_value,
14134                 (void *)&cmd_set_conntrack_common_max_ackwin,
14135                 (void *)&cmd_set_conntrack_common_max_ackwin_value,
14136                 (void *)&cmd_set_conntrack_common_retrans,
14137                 (void *)&cmd_set_conntrack_common_retrans_value,
14138                 (void *)&cmd_set_conntrack_common_last_win,
14139                 (void *)&cmd_set_conntrack_common_last_win_value,
14140                 (void *)&cmd_set_conntrack_common_last_seq,
14141                 (void *)&cmd_set_conntrack_common_last_seq_value,
14142                 (void *)&cmd_set_conntrack_common_last_ack,
14143                 (void *)&cmd_set_conntrack_common_last_ack_value,
14144                 (void *)&cmd_set_conntrack_common_last_end,
14145                 (void *)&cmd_set_conntrack_common_last_end_value,
14146                 (void *)&cmd_set_conntrack_common_last_index,
14147                 (void *)&cmd_set_conntrack_common_last_index_value,
14148                 NULL,
14149         },
14150 };
14151
14152 /** Set connection tracking object both directions' details */
14153 struct cmd_set_conntrack_dir_result {
14154         cmdline_fixed_string_t set;
14155         cmdline_fixed_string_t conntrack;
14156         cmdline_fixed_string_t dir;
14157         cmdline_fixed_string_t scale;
14158         cmdline_fixed_string_t fin;
14159         cmdline_fixed_string_t ack_seen;
14160         cmdline_fixed_string_t unack;
14161         cmdline_fixed_string_t sent_end;
14162         cmdline_fixed_string_t reply_end;
14163         cmdline_fixed_string_t max_win;
14164         cmdline_fixed_string_t max_ack;
14165         uint32_t factor;
14166         uint32_t f;
14167         uint32_t as;
14168         uint32_t un;
14169         uint32_t se;
14170         uint32_t re;
14171         uint32_t mw;
14172         uint32_t ma;
14173 };
14174
14175 cmdline_parse_token_string_t cmd_set_conntrack_dir_set =
14176         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14177                                  set, "set");
14178 cmdline_parse_token_string_t cmd_set_conntrack_dir_conntrack =
14179         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14180                                  conntrack, "conntrack");
14181 cmdline_parse_token_string_t cmd_set_conntrack_dir_dir =
14182         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14183                                  dir, "orig#rply");
14184 cmdline_parse_token_string_t cmd_set_conntrack_dir_scale =
14185         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14186                                  scale, "scale");
14187 cmdline_parse_token_num_t cmd_set_conntrack_dir_scale_value =
14188         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14189                               factor, RTE_UINT32);
14190 cmdline_parse_token_string_t cmd_set_conntrack_dir_fin =
14191         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14192                                  fin, "fin");
14193 cmdline_parse_token_num_t cmd_set_conntrack_dir_fin_value =
14194         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14195                               f, RTE_UINT32);
14196 cmdline_parse_token_string_t cmd_set_conntrack_dir_ack =
14197         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14198                                  ack_seen, "acked");
14199 cmdline_parse_token_num_t cmd_set_conntrack_dir_ack_value =
14200         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14201                               as, RTE_UINT32);
14202 cmdline_parse_token_string_t cmd_set_conntrack_dir_unack_data =
14203         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14204                                  unack, "unack_data");
14205 cmdline_parse_token_num_t cmd_set_conntrack_dir_unack_data_value =
14206         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14207                               un, RTE_UINT32);
14208 cmdline_parse_token_string_t cmd_set_conntrack_dir_sent_end =
14209         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14210                                  sent_end, "sent_end");
14211 cmdline_parse_token_num_t cmd_set_conntrack_dir_sent_end_value =
14212         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14213                               se, RTE_UINT32);
14214 cmdline_parse_token_string_t cmd_set_conntrack_dir_reply_end =
14215         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14216                                  reply_end, "reply_end");
14217 cmdline_parse_token_num_t cmd_set_conntrack_dir_reply_end_value =
14218         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14219                               re, RTE_UINT32);
14220 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_win =
14221         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14222                                  max_win, "max_win");
14223 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_win_value =
14224         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14225                               mw, RTE_UINT32);
14226 cmdline_parse_token_string_t cmd_set_conntrack_dir_max_ack =
14227         TOKEN_STRING_INITIALIZER(struct cmd_set_conntrack_dir_result,
14228                                  max_ack, "max_ack");
14229 cmdline_parse_token_num_t cmd_set_conntrack_dir_max_ack_value =
14230         TOKEN_NUM_INITIALIZER(struct cmd_set_conntrack_dir_result,
14231                               ma, RTE_UINT32);
14232
14233 static void cmd_set_conntrack_dir_parsed(void *parsed_result,
14234         __rte_unused struct cmdline *cl,
14235         __rte_unused void *data)
14236 {
14237         struct cmd_set_conntrack_dir_result *res = parsed_result;
14238         struct rte_flow_tcp_dir_param *dir = NULL;
14239
14240         if (strcmp(res->dir, "orig") == 0)
14241                 dir = &conntrack_context.original_dir;
14242         else if (strcmp(res->dir, "rply") == 0)
14243                 dir = &conntrack_context.reply_dir;
14244         else
14245                 return;
14246         dir->scale = res->factor;
14247         dir->close_initiated = res->f;
14248         dir->last_ack_seen = res->as;
14249         dir->data_unacked = res->un;
14250         dir->sent_end = res->se;
14251         dir->reply_end = res->re;
14252         dir->max_ack = res->ma;
14253         dir->max_win = res->mw;
14254 }
14255
14256 cmdline_parse_inst_t cmd_set_conntrack_dir = {
14257         .f = cmd_set_conntrack_dir_parsed,
14258         .data = NULL,
14259         .help_str = "set conntrack orig|rply scale <factor> fin <sent>"
14260                     " acked <seen> unack_data <unack> sent_end <sent>"
14261                     " reply_end <reply> max_win <win> max_ack <ack>",
14262         .tokens = {
14263                 (void *)&cmd_set_conntrack_set,
14264                 (void *)&cmd_set_conntrack_conntrack,
14265                 (void *)&cmd_set_conntrack_dir_dir,
14266                 (void *)&cmd_set_conntrack_dir_scale,
14267                 (void *)&cmd_set_conntrack_dir_scale_value,
14268                 (void *)&cmd_set_conntrack_dir_fin,
14269                 (void *)&cmd_set_conntrack_dir_fin_value,
14270                 (void *)&cmd_set_conntrack_dir_ack,
14271                 (void *)&cmd_set_conntrack_dir_ack_value,
14272                 (void *)&cmd_set_conntrack_dir_unack_data,
14273                 (void *)&cmd_set_conntrack_dir_unack_data_value,
14274                 (void *)&cmd_set_conntrack_dir_sent_end,
14275                 (void *)&cmd_set_conntrack_dir_sent_end_value,
14276                 (void *)&cmd_set_conntrack_dir_reply_end,
14277                 (void *)&cmd_set_conntrack_dir_reply_end_value,
14278                 (void *)&cmd_set_conntrack_dir_max_win,
14279                 (void *)&cmd_set_conntrack_dir_max_win_value,
14280                 (void *)&cmd_set_conntrack_dir_max_ack,
14281                 (void *)&cmd_set_conntrack_dir_max_ack_value,
14282                 NULL,
14283         },
14284 };
14285
14286 /* Strict link priority scheduling mode setting */
14287 static void
14288 cmd_strict_link_prio_parsed(
14289         void *parsed_result,
14290         __rte_unused struct cmdline *cl,
14291         __rte_unused void *data)
14292 {
14293         struct cmd_vf_tc_bw_result *res = parsed_result;
14294         int ret = -ENOTSUP;
14295
14296         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14297                 return;
14298
14299 #ifdef RTE_NET_I40E
14300         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14301 #endif
14302
14303         switch (ret) {
14304         case 0:
14305                 break;
14306         case -EINVAL:
14307                 fprintf(stderr, "invalid tc_bitmap 0x%x\n", res->tc_map);
14308                 break;
14309         case -ENODEV:
14310                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
14311                 break;
14312         case -ENOTSUP:
14313                 fprintf(stderr, "function not implemented\n");
14314                 break;
14315         default:
14316                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
14317         }
14318 }
14319
14320 cmdline_parse_inst_t cmd_strict_link_prio = {
14321         .f = cmd_strict_link_prio_parsed,
14322         .data = NULL,
14323         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14324         .tokens = {
14325                 (void *)&cmd_vf_tc_bw_set,
14326                 (void *)&cmd_vf_tc_bw_tx,
14327                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14328                 (void *)&cmd_vf_tc_bw_port_id,
14329                 (void *)&cmd_vf_tc_bw_tc_map,
14330                 NULL,
14331         },
14332 };
14333
14334 /* Load dynamic device personalization*/
14335 struct cmd_ddp_add_result {
14336         cmdline_fixed_string_t ddp;
14337         cmdline_fixed_string_t add;
14338         portid_t port_id;
14339         char filepath[];
14340 };
14341
14342 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14344 cmdline_parse_token_string_t cmd_ddp_add_add =
14345         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14346 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14347         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id,
14348                 RTE_UINT16);
14349 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14350         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14351
14352 static void
14353 cmd_ddp_add_parsed(
14354         void *parsed_result,
14355         __rte_unused struct cmdline *cl,
14356         __rte_unused void *data)
14357 {
14358         struct cmd_ddp_add_result *res = parsed_result;
14359         uint8_t *buff;
14360         uint32_t size;
14361         char *filepath;
14362         char *file_fld[2];
14363         int file_num;
14364         int ret = -ENOTSUP;
14365
14366         if (!all_ports_stopped()) {
14367                 fprintf(stderr, "Please stop all ports first\n");
14368                 return;
14369         }
14370
14371         filepath = strdup(res->filepath);
14372         if (filepath == NULL) {
14373                 fprintf(stderr, "Failed to allocate memory\n");
14374                 return;
14375         }
14376         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14377
14378         buff = open_file(file_fld[0], &size);
14379         if (!buff) {
14380                 free((void *)filepath);
14381                 return;
14382         }
14383
14384 #ifdef RTE_NET_I40E
14385         if (ret == -ENOTSUP)
14386                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14387                                                buff, size,
14388                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14389 #endif
14390
14391         if (ret == -EEXIST)
14392                 fprintf(stderr, "Profile has already existed.\n");
14393         else if (ret < 0)
14394                 fprintf(stderr, "Failed to load profile.\n");
14395         else if (file_num == 2)
14396                 save_file(file_fld[1], buff, size);
14397
14398         close_file(buff);
14399         free((void *)filepath);
14400 }
14401
14402 cmdline_parse_inst_t cmd_ddp_add = {
14403         .f = cmd_ddp_add_parsed,
14404         .data = NULL,
14405         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
14406         .tokens = {
14407                 (void *)&cmd_ddp_add_ddp,
14408                 (void *)&cmd_ddp_add_add,
14409                 (void *)&cmd_ddp_add_port_id,
14410                 (void *)&cmd_ddp_add_filepath,
14411                 NULL,
14412         },
14413 };
14414
14415 /* Delete dynamic device personalization*/
14416 struct cmd_ddp_del_result {
14417         cmdline_fixed_string_t ddp;
14418         cmdline_fixed_string_t del;
14419         portid_t port_id;
14420         char filepath[];
14421 };
14422
14423 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14424         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14425 cmdline_parse_token_string_t cmd_ddp_del_del =
14426         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14427 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14428         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, RTE_UINT16);
14429 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14430         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14431
14432 static void
14433 cmd_ddp_del_parsed(
14434         void *parsed_result,
14435         __rte_unused struct cmdline *cl,
14436         __rte_unused void *data)
14437 {
14438         struct cmd_ddp_del_result *res = parsed_result;
14439         uint8_t *buff;
14440         uint32_t size;
14441         int ret = -ENOTSUP;
14442
14443         if (!all_ports_stopped()) {
14444                 fprintf(stderr, "Please stop all ports first\n");
14445                 return;
14446         }
14447
14448         buff = open_file(res->filepath, &size);
14449         if (!buff)
14450                 return;
14451
14452 #ifdef RTE_NET_I40E
14453         if (ret == -ENOTSUP)
14454                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14455                                                buff, size,
14456                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14457 #endif
14458
14459         if (ret == -EACCES)
14460                 fprintf(stderr, "Profile does not exist.\n");
14461         else if (ret < 0)
14462                 fprintf(stderr, "Failed to delete profile.\n");
14463
14464         close_file(buff);
14465 }
14466
14467 cmdline_parse_inst_t cmd_ddp_del = {
14468         .f = cmd_ddp_del_parsed,
14469         .data = NULL,
14470         .help_str = "ddp del <port_id> <backup_profile_path>",
14471         .tokens = {
14472                 (void *)&cmd_ddp_del_ddp,
14473                 (void *)&cmd_ddp_del_del,
14474                 (void *)&cmd_ddp_del_port_id,
14475                 (void *)&cmd_ddp_del_filepath,
14476                 NULL,
14477         },
14478 };
14479
14480 /* Get dynamic device personalization profile info */
14481 struct cmd_ddp_info_result {
14482         cmdline_fixed_string_t ddp;
14483         cmdline_fixed_string_t get;
14484         cmdline_fixed_string_t info;
14485         char filepath[];
14486 };
14487
14488 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14489         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14490 cmdline_parse_token_string_t cmd_ddp_info_get =
14491         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14492 cmdline_parse_token_string_t cmd_ddp_info_info =
14493         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14494 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14495         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14496
14497 static void
14498 cmd_ddp_info_parsed(
14499         void *parsed_result,
14500         __rte_unused struct cmdline *cl,
14501         __rte_unused void *data)
14502 {
14503         struct cmd_ddp_info_result *res = parsed_result;
14504         uint8_t *pkg;
14505         uint32_t pkg_size;
14506         int ret = -ENOTSUP;
14507 #ifdef RTE_NET_I40E
14508         uint32_t i, j, n;
14509         uint8_t *buff;
14510         uint32_t buff_size = 0;
14511         struct rte_pmd_i40e_profile_info info;
14512         uint32_t dev_num = 0;
14513         struct rte_pmd_i40e_ddp_device_id *devs;
14514         uint32_t proto_num = 0;
14515         struct rte_pmd_i40e_proto_info *proto = NULL;
14516         uint32_t pctype_num = 0;
14517         struct rte_pmd_i40e_ptype_info *pctype;
14518         uint32_t ptype_num = 0;
14519         struct rte_pmd_i40e_ptype_info *ptype;
14520         uint8_t proto_id;
14521
14522 #endif
14523
14524         pkg = open_file(res->filepath, &pkg_size);
14525         if (!pkg)
14526                 return;
14527
14528 #ifdef RTE_NET_I40E
14529         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14530                                 (uint8_t *)&info, sizeof(info),
14531                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14532         if (!ret) {
14533                 printf("Global Track id:       0x%x\n", info.track_id);
14534                 printf("Global Version:        %d.%d.%d.%d\n",
14535                         info.version.major,
14536                         info.version.minor,
14537                         info.version.update,
14538                         info.version.draft);
14539                 printf("Global Package name:   %s\n\n", info.name);
14540         }
14541
14542         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14543                                 (uint8_t *)&info, sizeof(info),
14544                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14545         if (!ret) {
14546                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14547                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14548                         info.version.major,
14549                         info.version.minor,
14550                         info.version.update,
14551                         info.version.draft);
14552                 printf("i40e Profile name:     %s\n\n", info.name);
14553         }
14554
14555         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14556                                 (uint8_t *)&buff_size, sizeof(buff_size),
14557                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14558         if (!ret && buff_size) {
14559                 buff = (uint8_t *)malloc(buff_size);
14560                 if (buff) {
14561                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14562                                                 buff, buff_size,
14563                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14564                         if (!ret)
14565                                 printf("Package Notes:\n%s\n\n", buff);
14566                         free(buff);
14567                 }
14568         }
14569
14570         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14571                                 (uint8_t *)&dev_num, sizeof(dev_num),
14572                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14573         if (!ret && dev_num) {
14574                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14575                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14576                 if (devs) {
14577                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14578                                                 (uint8_t *)devs, buff_size,
14579                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14580                         if (!ret) {
14581                                 printf("List of supported devices:\n");
14582                                 for (i = 0; i < dev_num; i++) {
14583                                         printf("  %04X:%04X %04X:%04X\n",
14584                                                 devs[i].vendor_dev_id >> 16,
14585                                                 devs[i].vendor_dev_id & 0xFFFF,
14586                                                 devs[i].sub_vendor_dev_id >> 16,
14587                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14588                                 }
14589                                 printf("\n");
14590                         }
14591                         free(devs);
14592                 }
14593         }
14594
14595         /* get information about protocols and packet types */
14596         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14597                 (uint8_t *)&proto_num, sizeof(proto_num),
14598                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14599         if (ret || !proto_num)
14600                 goto no_print_return;
14601
14602         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14603         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14604         if (!proto)
14605                 goto no_print_return;
14606
14607         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14608                                         buff_size,
14609                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14610         if (!ret) {
14611                 printf("List of used protocols:\n");
14612                 for (i = 0; i < proto_num; i++)
14613                         printf("  %2u: %s\n", proto[i].proto_id,
14614                                proto[i].name);
14615                 printf("\n");
14616         }
14617         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14618                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14619                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14620         if (ret || !pctype_num)
14621                 goto no_print_pctypes;
14622
14623         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14624         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14625         if (!pctype)
14626                 goto no_print_pctypes;
14627
14628         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14629                                         buff_size,
14630                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14631         if (ret) {
14632                 free(pctype);
14633                 goto no_print_pctypes;
14634         }
14635
14636         printf("List of defined packet classification types:\n");
14637         for (i = 0; i < pctype_num; i++) {
14638                 printf("  %2u:", pctype[i].ptype_id);
14639                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14640                         proto_id = pctype[i].protocols[j];
14641                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14642                                 for (n = 0; n < proto_num; n++) {
14643                                         if (proto[n].proto_id == proto_id) {
14644                                                 printf(" %s", proto[n].name);
14645                                                 break;
14646                                         }
14647                                 }
14648                         }
14649                 }
14650                 printf("\n");
14651         }
14652         printf("\n");
14653         free(pctype);
14654
14655 no_print_pctypes:
14656
14657         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14658                                         sizeof(ptype_num),
14659                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14660         if (ret || !ptype_num)
14661                 goto no_print_return;
14662
14663         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14664         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14665         if (!ptype)
14666                 goto no_print_return;
14667
14668         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14669                                         buff_size,
14670                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14671         if (ret) {
14672                 free(ptype);
14673                 goto no_print_return;
14674         }
14675         printf("List of defined packet types:\n");
14676         for (i = 0; i < ptype_num; i++) {
14677                 printf("  %2u:", ptype[i].ptype_id);
14678                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14679                         proto_id = ptype[i].protocols[j];
14680                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14681                                 for (n = 0; n < proto_num; n++) {
14682                                         if (proto[n].proto_id == proto_id) {
14683                                                 printf(" %s", proto[n].name);
14684                                                 break;
14685                                         }
14686                                 }
14687                         }
14688                 }
14689                 printf("\n");
14690         }
14691         free(ptype);
14692         printf("\n");
14693
14694         ret = 0;
14695 no_print_return:
14696         if (proto)
14697                 free(proto);
14698 #endif
14699         if (ret == -ENOTSUP)
14700                 fprintf(stderr, "Function not supported in PMD driver\n");
14701         close_file(pkg);
14702 }
14703
14704 cmdline_parse_inst_t cmd_ddp_get_info = {
14705         .f = cmd_ddp_info_parsed,
14706         .data = NULL,
14707         .help_str = "ddp get info <profile_path>",
14708         .tokens = {
14709                 (void *)&cmd_ddp_info_ddp,
14710                 (void *)&cmd_ddp_info_get,
14711                 (void *)&cmd_ddp_info_info,
14712                 (void *)&cmd_ddp_info_filepath,
14713                 NULL,
14714         },
14715 };
14716
14717 /* Get dynamic device personalization profile info list*/
14718 #define PROFILE_INFO_SIZE 48
14719 #define MAX_PROFILE_NUM 16
14720
14721 struct cmd_ddp_get_list_result {
14722         cmdline_fixed_string_t ddp;
14723         cmdline_fixed_string_t get;
14724         cmdline_fixed_string_t list;
14725         portid_t port_id;
14726 };
14727
14728 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14729         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14730 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14731         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14732 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14733         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14734 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14735         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id,
14736                 RTE_UINT16);
14737
14738 static void
14739 cmd_ddp_get_list_parsed(
14740         __rte_unused void *parsed_result,
14741         __rte_unused struct cmdline *cl,
14742         __rte_unused void *data)
14743 {
14744 #ifdef RTE_NET_I40E
14745         struct cmd_ddp_get_list_result *res = parsed_result;
14746         struct rte_pmd_i40e_profile_list *p_list;
14747         struct rte_pmd_i40e_profile_info *p_info;
14748         uint32_t p_num;
14749         uint32_t size;
14750         uint32_t i;
14751 #endif
14752         int ret = -ENOTSUP;
14753
14754 #ifdef RTE_NET_I40E
14755         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14756         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14757         if (!p_list) {
14758                 fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
14759                 return;
14760         }
14761
14762         if (ret == -ENOTSUP)
14763                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14764                                                 (uint8_t *)p_list, size);
14765
14766         if (!ret) {
14767                 p_num = p_list->p_count;
14768                 printf("Profile number is: %d\n\n", p_num);
14769
14770                 for (i = 0; i < p_num; i++) {
14771                         p_info = &p_list->p_info[i];
14772                         printf("Profile %d:\n", i);
14773                         printf("Track id:     0x%x\n", p_info->track_id);
14774                         printf("Version:      %d.%d.%d.%d\n",
14775                                p_info->version.major,
14776                                p_info->version.minor,
14777                                p_info->version.update,
14778                                p_info->version.draft);
14779                         printf("Profile name: %s\n\n", p_info->name);
14780                 }
14781         }
14782
14783         free(p_list);
14784 #endif
14785
14786         if (ret < 0)
14787                 fprintf(stderr, "Failed to get ddp list\n");
14788 }
14789
14790 cmdline_parse_inst_t cmd_ddp_get_list = {
14791         .f = cmd_ddp_get_list_parsed,
14792         .data = NULL,
14793         .help_str = "ddp get list <port_id>",
14794         .tokens = {
14795                 (void *)&cmd_ddp_get_list_ddp,
14796                 (void *)&cmd_ddp_get_list_get,
14797                 (void *)&cmd_ddp_get_list_list,
14798                 (void *)&cmd_ddp_get_list_port_id,
14799                 NULL,
14800         },
14801 };
14802
14803 /* Configure input set */
14804 struct cmd_cfg_input_set_result {
14805         cmdline_fixed_string_t port;
14806         cmdline_fixed_string_t cfg;
14807         portid_t port_id;
14808         cmdline_fixed_string_t pctype;
14809         uint8_t pctype_id;
14810         cmdline_fixed_string_t inset_type;
14811         cmdline_fixed_string_t opt;
14812         cmdline_fixed_string_t field;
14813         uint8_t field_idx;
14814 };
14815
14816 static void
14817 cmd_cfg_input_set_parsed(
14818         __rte_unused void *parsed_result,
14819         __rte_unused struct cmdline *cl,
14820         __rte_unused void *data)
14821 {
14822 #ifdef RTE_NET_I40E
14823         struct cmd_cfg_input_set_result *res = parsed_result;
14824         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14825         struct rte_pmd_i40e_inset inset;
14826 #endif
14827         int ret = -ENOTSUP;
14828
14829         if (!all_ports_stopped()) {
14830                 fprintf(stderr, "Please stop all ports first\n");
14831                 return;
14832         }
14833
14834 #ifdef RTE_NET_I40E
14835         if (!strcmp(res->inset_type, "hash_inset"))
14836                 inset_type = INSET_HASH;
14837         else if (!strcmp(res->inset_type, "fdir_inset"))
14838                 inset_type = INSET_FDIR;
14839         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14840                 inset_type = INSET_FDIR_FLX;
14841         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
14842                                      &inset, inset_type);
14843         if (ret) {
14844                 fprintf(stderr, "Failed to get input set.\n");
14845                 return;
14846         }
14847
14848         if (!strcmp(res->opt, "get")) {
14849                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
14850                                                    res->field_idx);
14851                 if (ret)
14852                         printf("Field index %d is enabled.\n", res->field_idx);
14853                 else
14854                         printf("Field index %d is disabled.\n", res->field_idx);
14855                 return;
14856         } else if (!strcmp(res->opt, "set"))
14857                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
14858                                                    res->field_idx);
14859         else if (!strcmp(res->opt, "clear"))
14860                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
14861                                                      res->field_idx);
14862         if (ret) {
14863                 fprintf(stderr, "Failed to configure input set field.\n");
14864                 return;
14865         }
14866
14867         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14868                                      &inset, inset_type);
14869         if (ret) {
14870                 fprintf(stderr, "Failed to set input set.\n");
14871                 return;
14872         }
14873 #endif
14874
14875         if (ret == -ENOTSUP)
14876                 fprintf(stderr, "Function not supported\n");
14877 }
14878
14879 cmdline_parse_token_string_t cmd_cfg_input_set_port =
14880         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14881                                  port, "port");
14882 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
14883         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14884                                  cfg, "config");
14885 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
14886         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14887                               port_id, RTE_UINT16);
14888 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
14889         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14890                                  pctype, "pctype");
14891 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
14892         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14893                               pctype_id, RTE_UINT8);
14894 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
14895         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14896                                  inset_type,
14897                                  "hash_inset#fdir_inset#fdir_flx_inset");
14898 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
14899         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14900                                  opt, "get#set#clear");
14901 cmdline_parse_token_string_t cmd_cfg_input_set_field =
14902         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
14903                                  field, "field");
14904 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
14905         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
14906                               field_idx, RTE_UINT8);
14907
14908 cmdline_parse_inst_t cmd_cfg_input_set = {
14909         .f = cmd_cfg_input_set_parsed,
14910         .data = NULL,
14911         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
14912                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
14913         .tokens = {
14914                 (void *)&cmd_cfg_input_set_port,
14915                 (void *)&cmd_cfg_input_set_cfg,
14916                 (void *)&cmd_cfg_input_set_port_id,
14917                 (void *)&cmd_cfg_input_set_pctype,
14918                 (void *)&cmd_cfg_input_set_pctype_id,
14919                 (void *)&cmd_cfg_input_set_inset_type,
14920                 (void *)&cmd_cfg_input_set_opt,
14921                 (void *)&cmd_cfg_input_set_field,
14922                 (void *)&cmd_cfg_input_set_field_idx,
14923                 NULL,
14924         },
14925 };
14926
14927 /* Clear input set */
14928 struct cmd_clear_input_set_result {
14929         cmdline_fixed_string_t port;
14930         cmdline_fixed_string_t cfg;
14931         portid_t port_id;
14932         cmdline_fixed_string_t pctype;
14933         uint8_t pctype_id;
14934         cmdline_fixed_string_t inset_type;
14935         cmdline_fixed_string_t clear;
14936         cmdline_fixed_string_t all;
14937 };
14938
14939 static void
14940 cmd_clear_input_set_parsed(
14941         __rte_unused void *parsed_result,
14942         __rte_unused struct cmdline *cl,
14943         __rte_unused void *data)
14944 {
14945 #ifdef RTE_NET_I40E
14946         struct cmd_clear_input_set_result *res = parsed_result;
14947         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
14948         struct rte_pmd_i40e_inset inset;
14949 #endif
14950         int ret = -ENOTSUP;
14951
14952         if (!all_ports_stopped()) {
14953                 fprintf(stderr, "Please stop all ports first\n");
14954                 return;
14955         }
14956
14957 #ifdef RTE_NET_I40E
14958         if (!strcmp(res->inset_type, "hash_inset"))
14959                 inset_type = INSET_HASH;
14960         else if (!strcmp(res->inset_type, "fdir_inset"))
14961                 inset_type = INSET_FDIR;
14962         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
14963                 inset_type = INSET_FDIR_FLX;
14964
14965         memset(&inset, 0, sizeof(inset));
14966
14967         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
14968                                      &inset, inset_type);
14969         if (ret) {
14970                 fprintf(stderr, "Failed to clear input set.\n");
14971                 return;
14972         }
14973
14974 #endif
14975
14976         if (ret == -ENOTSUP)
14977                 fprintf(stderr, "Function not supported\n");
14978 }
14979
14980 cmdline_parse_token_string_t cmd_clear_input_set_port =
14981         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14982                                  port, "port");
14983 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
14984         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14985                                  cfg, "config");
14986 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
14987         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14988                               port_id, RTE_UINT16);
14989 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
14990         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14991                                  pctype, "pctype");
14992 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
14993         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
14994                               pctype_id, RTE_UINT8);
14995 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
14996         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
14997                                  inset_type,
14998                                  "hash_inset#fdir_inset#fdir_flx_inset");
14999 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15000         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15001                                  clear, "clear");
15002 cmdline_parse_token_string_t cmd_clear_input_set_all =
15003         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15004                                  all, "all");
15005
15006 cmdline_parse_inst_t cmd_clear_input_set = {
15007         .f = cmd_clear_input_set_parsed,
15008         .data = NULL,
15009         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15010                     "fdir_inset|fdir_flx_inset clear all",
15011         .tokens = {
15012                 (void *)&cmd_clear_input_set_port,
15013                 (void *)&cmd_clear_input_set_cfg,
15014                 (void *)&cmd_clear_input_set_port_id,
15015                 (void *)&cmd_clear_input_set_pctype,
15016                 (void *)&cmd_clear_input_set_pctype_id,
15017                 (void *)&cmd_clear_input_set_inset_type,
15018                 (void *)&cmd_clear_input_set_clear,
15019                 (void *)&cmd_clear_input_set_all,
15020                 NULL,
15021         },
15022 };
15023
15024 /* show vf stats */
15025
15026 /* Common result structure for show vf stats */
15027 struct cmd_show_vf_stats_result {
15028         cmdline_fixed_string_t show;
15029         cmdline_fixed_string_t vf;
15030         cmdline_fixed_string_t stats;
15031         portid_t port_id;
15032         uint16_t vf_id;
15033 };
15034
15035 /* Common CLI fields show vf stats*/
15036 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15037         TOKEN_STRING_INITIALIZER
15038                 (struct cmd_show_vf_stats_result,
15039                  show, "show");
15040 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
15041         TOKEN_STRING_INITIALIZER
15042                 (struct cmd_show_vf_stats_result,
15043                  vf, "vf");
15044 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
15045         TOKEN_STRING_INITIALIZER
15046                 (struct cmd_show_vf_stats_result,
15047                  stats, "stats");
15048 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
15049         TOKEN_NUM_INITIALIZER
15050                 (struct cmd_show_vf_stats_result,
15051                  port_id, RTE_UINT16);
15052 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
15053         TOKEN_NUM_INITIALIZER
15054                 (struct cmd_show_vf_stats_result,
15055                  vf_id, RTE_UINT16);
15056
15057 static void
15058 cmd_show_vf_stats_parsed(
15059         void *parsed_result,
15060         __rte_unused struct cmdline *cl,
15061         __rte_unused void *data)
15062 {
15063         struct cmd_show_vf_stats_result *res = parsed_result;
15064         struct rte_eth_stats stats;
15065         int ret = -ENOTSUP;
15066         static const char *nic_stats_border = "########################";
15067
15068         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15069                 return;
15070
15071         memset(&stats, 0, sizeof(stats));
15072
15073 #ifdef RTE_NET_I40E
15074         if (ret == -ENOTSUP)
15075                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
15076                                                 res->vf_id,
15077                                                 &stats);
15078 #endif
15079 #ifdef RTE_NET_BNXT
15080         if (ret == -ENOTSUP)
15081                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
15082                                                 res->vf_id,
15083                                                 &stats);
15084 #endif
15085
15086         switch (ret) {
15087         case 0:
15088                 break;
15089         case -EINVAL:
15090                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15091                 break;
15092         case -ENODEV:
15093                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15094                 break;
15095         case -ENOTSUP:
15096                 fprintf(stderr, "function not implemented\n");
15097                 break;
15098         default:
15099                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15100         }
15101
15102         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
15103                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
15104
15105         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
15106                "%-"PRIu64"\n",
15107                stats.ipackets, stats.imissed, stats.ibytes);
15108         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
15109         printf("  RX-nombuf:  %-10"PRIu64"\n",
15110                stats.rx_nombuf);
15111         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
15112                "%-"PRIu64"\n",
15113                stats.opackets, stats.oerrors, stats.obytes);
15114
15115         printf("  %s############################%s\n",
15116                                nic_stats_border, nic_stats_border);
15117 }
15118
15119 cmdline_parse_inst_t cmd_show_vf_stats = {
15120         .f = cmd_show_vf_stats_parsed,
15121         .data = NULL,
15122         .help_str = "show vf stats <port_id> <vf_id>",
15123         .tokens = {
15124                 (void *)&cmd_show_vf_stats_show,
15125                 (void *)&cmd_show_vf_stats_vf,
15126                 (void *)&cmd_show_vf_stats_stats,
15127                 (void *)&cmd_show_vf_stats_port_id,
15128                 (void *)&cmd_show_vf_stats_vf_id,
15129                 NULL,
15130         },
15131 };
15132
15133 /* clear vf stats */
15134
15135 /* Common result structure for clear vf stats */
15136 struct cmd_clear_vf_stats_result {
15137         cmdline_fixed_string_t clear;
15138         cmdline_fixed_string_t vf;
15139         cmdline_fixed_string_t stats;
15140         portid_t port_id;
15141         uint16_t vf_id;
15142 };
15143
15144 /* Common CLI fields clear vf stats*/
15145 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
15146         TOKEN_STRING_INITIALIZER
15147                 (struct cmd_clear_vf_stats_result,
15148                  clear, "clear");
15149 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
15150         TOKEN_STRING_INITIALIZER
15151                 (struct cmd_clear_vf_stats_result,
15152                  vf, "vf");
15153 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
15154         TOKEN_STRING_INITIALIZER
15155                 (struct cmd_clear_vf_stats_result,
15156                  stats, "stats");
15157 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
15158         TOKEN_NUM_INITIALIZER
15159                 (struct cmd_clear_vf_stats_result,
15160                  port_id, RTE_UINT16);
15161 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
15162         TOKEN_NUM_INITIALIZER
15163                 (struct cmd_clear_vf_stats_result,
15164                  vf_id, RTE_UINT16);
15165
15166 static void
15167 cmd_clear_vf_stats_parsed(
15168         void *parsed_result,
15169         __rte_unused struct cmdline *cl,
15170         __rte_unused void *data)
15171 {
15172         struct cmd_clear_vf_stats_result *res = parsed_result;
15173         int ret = -ENOTSUP;
15174
15175         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15176                 return;
15177
15178 #ifdef RTE_NET_I40E
15179         if (ret == -ENOTSUP)
15180                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
15181                                                   res->vf_id);
15182 #endif
15183 #ifdef RTE_NET_BNXT
15184         if (ret == -ENOTSUP)
15185                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
15186                                                   res->vf_id);
15187 #endif
15188
15189         switch (ret) {
15190         case 0:
15191                 break;
15192         case -EINVAL:
15193                 fprintf(stderr, "invalid vf_id %d\n", res->vf_id);
15194                 break;
15195         case -ENODEV:
15196                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15197                 break;
15198         case -ENOTSUP:
15199                 fprintf(stderr, "function not implemented\n");
15200                 break;
15201         default:
15202                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15203         }
15204 }
15205
15206 cmdline_parse_inst_t cmd_clear_vf_stats = {
15207         .f = cmd_clear_vf_stats_parsed,
15208         .data = NULL,
15209         .help_str = "clear vf stats <port_id> <vf_id>",
15210         .tokens = {
15211                 (void *)&cmd_clear_vf_stats_clear,
15212                 (void *)&cmd_clear_vf_stats_vf,
15213                 (void *)&cmd_clear_vf_stats_stats,
15214                 (void *)&cmd_clear_vf_stats_port_id,
15215                 (void *)&cmd_clear_vf_stats_vf_id,
15216                 NULL,
15217         },
15218 };
15219
15220 /* port config pctype mapping reset */
15221
15222 /* Common result structure for port config pctype mapping reset */
15223 struct cmd_pctype_mapping_reset_result {
15224         cmdline_fixed_string_t port;
15225         cmdline_fixed_string_t config;
15226         portid_t port_id;
15227         cmdline_fixed_string_t pctype;
15228         cmdline_fixed_string_t mapping;
15229         cmdline_fixed_string_t reset;
15230 };
15231
15232 /* Common CLI fields for port config pctype mapping reset*/
15233 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
15234         TOKEN_STRING_INITIALIZER
15235                 (struct cmd_pctype_mapping_reset_result,
15236                  port, "port");
15237 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
15238         TOKEN_STRING_INITIALIZER
15239                 (struct cmd_pctype_mapping_reset_result,
15240                  config, "config");
15241 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
15242         TOKEN_NUM_INITIALIZER
15243                 (struct cmd_pctype_mapping_reset_result,
15244                  port_id, RTE_UINT16);
15245 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
15246         TOKEN_STRING_INITIALIZER
15247                 (struct cmd_pctype_mapping_reset_result,
15248                  pctype, "pctype");
15249 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
15250         TOKEN_STRING_INITIALIZER
15251                 (struct cmd_pctype_mapping_reset_result,
15252                  mapping, "mapping");
15253 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
15254         TOKEN_STRING_INITIALIZER
15255                 (struct cmd_pctype_mapping_reset_result,
15256                  reset, "reset");
15257
15258 static void
15259 cmd_pctype_mapping_reset_parsed(
15260         void *parsed_result,
15261         __rte_unused struct cmdline *cl,
15262         __rte_unused void *data)
15263 {
15264         struct cmd_pctype_mapping_reset_result *res = parsed_result;
15265         int ret = -ENOTSUP;
15266
15267         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15268                 return;
15269
15270 #ifdef RTE_NET_I40E
15271         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
15272 #endif
15273
15274         switch (ret) {
15275         case 0:
15276                 break;
15277         case -ENODEV:
15278                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15279                 break;
15280         case -ENOTSUP:
15281                 fprintf(stderr, "function not implemented\n");
15282                 break;
15283         default:
15284                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15285         }
15286 }
15287
15288 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
15289         .f = cmd_pctype_mapping_reset_parsed,
15290         .data = NULL,
15291         .help_str = "port config <port_id> pctype mapping reset",
15292         .tokens = {
15293                 (void *)&cmd_pctype_mapping_reset_port,
15294                 (void *)&cmd_pctype_mapping_reset_config,
15295                 (void *)&cmd_pctype_mapping_reset_port_id,
15296                 (void *)&cmd_pctype_mapping_reset_pctype,
15297                 (void *)&cmd_pctype_mapping_reset_mapping,
15298                 (void *)&cmd_pctype_mapping_reset_reset,
15299                 NULL,
15300         },
15301 };
15302
15303 /* show port pctype mapping */
15304
15305 /* Common result structure for show port pctype mapping */
15306 struct cmd_pctype_mapping_get_result {
15307         cmdline_fixed_string_t show;
15308         cmdline_fixed_string_t port;
15309         portid_t port_id;
15310         cmdline_fixed_string_t pctype;
15311         cmdline_fixed_string_t mapping;
15312 };
15313
15314 /* Common CLI fields for pctype mapping get */
15315 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
15316         TOKEN_STRING_INITIALIZER
15317                 (struct cmd_pctype_mapping_get_result,
15318                  show, "show");
15319 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
15320         TOKEN_STRING_INITIALIZER
15321                 (struct cmd_pctype_mapping_get_result,
15322                  port, "port");
15323 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
15324         TOKEN_NUM_INITIALIZER
15325                 (struct cmd_pctype_mapping_get_result,
15326                  port_id, RTE_UINT16);
15327 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
15328         TOKEN_STRING_INITIALIZER
15329                 (struct cmd_pctype_mapping_get_result,
15330                  pctype, "pctype");
15331 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
15332         TOKEN_STRING_INITIALIZER
15333                 (struct cmd_pctype_mapping_get_result,
15334                  mapping, "mapping");
15335
15336 static void
15337 cmd_pctype_mapping_get_parsed(
15338         void *parsed_result,
15339         __rte_unused struct cmdline *cl,
15340         __rte_unused void *data)
15341 {
15342         struct cmd_pctype_mapping_get_result *res = parsed_result;
15343         int ret = -ENOTSUP;
15344 #ifdef RTE_NET_I40E
15345         struct rte_pmd_i40e_flow_type_mapping
15346                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
15347         int i, j, first_pctype;
15348 #endif
15349
15350         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15351                 return;
15352
15353 #ifdef RTE_NET_I40E
15354         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15355 #endif
15356
15357         switch (ret) {
15358         case 0:
15359                 break;
15360         case -ENODEV:
15361                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15362                 return;
15363         case -ENOTSUP:
15364                 fprintf(stderr, "function not implemented\n");
15365                 return;
15366         default:
15367                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15368                 return;
15369         }
15370
15371 #ifdef RTE_NET_I40E
15372         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15373                 if (mapping[i].pctype != 0ULL) {
15374                         first_pctype = 1;
15375
15376                         printf("pctype: ");
15377                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15378                                 if (mapping[i].pctype & (1ULL << j)) {
15379                                         printf(first_pctype ?
15380                                                "%02d" : ",%02d", j);
15381                                         first_pctype = 0;
15382                                 }
15383                         }
15384                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15385                 }
15386         }
15387 #endif
15388 }
15389
15390 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15391         .f = cmd_pctype_mapping_get_parsed,
15392         .data = NULL,
15393         .help_str = "show port <port_id> pctype mapping",
15394         .tokens = {
15395                 (void *)&cmd_pctype_mapping_get_show,
15396                 (void *)&cmd_pctype_mapping_get_port,
15397                 (void *)&cmd_pctype_mapping_get_port_id,
15398                 (void *)&cmd_pctype_mapping_get_pctype,
15399                 (void *)&cmd_pctype_mapping_get_mapping,
15400                 NULL,
15401         },
15402 };
15403
15404 /* port config pctype mapping update */
15405
15406 /* Common result structure for port config pctype mapping update */
15407 struct cmd_pctype_mapping_update_result {
15408         cmdline_fixed_string_t port;
15409         cmdline_fixed_string_t config;
15410         portid_t port_id;
15411         cmdline_fixed_string_t pctype;
15412         cmdline_fixed_string_t mapping;
15413         cmdline_fixed_string_t update;
15414         cmdline_fixed_string_t pctype_list;
15415         uint16_t flow_type;
15416 };
15417
15418 /* Common CLI fields for pctype mapping update*/
15419 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15420         TOKEN_STRING_INITIALIZER
15421                 (struct cmd_pctype_mapping_update_result,
15422                  port, "port");
15423 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15424         TOKEN_STRING_INITIALIZER
15425                 (struct cmd_pctype_mapping_update_result,
15426                  config, "config");
15427 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15428         TOKEN_NUM_INITIALIZER
15429                 (struct cmd_pctype_mapping_update_result,
15430                  port_id, RTE_UINT16);
15431 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15432         TOKEN_STRING_INITIALIZER
15433                 (struct cmd_pctype_mapping_update_result,
15434                  pctype, "pctype");
15435 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15436         TOKEN_STRING_INITIALIZER
15437                 (struct cmd_pctype_mapping_update_result,
15438                  mapping, "mapping");
15439 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15440         TOKEN_STRING_INITIALIZER
15441                 (struct cmd_pctype_mapping_update_result,
15442                  update, "update");
15443 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15444         TOKEN_STRING_INITIALIZER
15445                 (struct cmd_pctype_mapping_update_result,
15446                  pctype_list, NULL);
15447 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15448         TOKEN_NUM_INITIALIZER
15449                 (struct cmd_pctype_mapping_update_result,
15450                  flow_type, RTE_UINT16);
15451
15452 static void
15453 cmd_pctype_mapping_update_parsed(
15454         void *parsed_result,
15455         __rte_unused struct cmdline *cl,
15456         __rte_unused void *data)
15457 {
15458         struct cmd_pctype_mapping_update_result *res = parsed_result;
15459         int ret = -ENOTSUP;
15460 #ifdef RTE_NET_I40E
15461         struct rte_pmd_i40e_flow_type_mapping mapping;
15462         unsigned int i;
15463         unsigned int nb_item;
15464         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15465 #endif
15466
15467         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15468                 return;
15469
15470 #ifdef RTE_NET_I40E
15471         nb_item = parse_item_list(res->pctype_list, "pctypes",
15472                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15473         mapping.flow_type = res->flow_type;
15474         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15475                 mapping.pctype |= (1ULL << pctype_list[i]);
15476         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15477                                                 &mapping,
15478                                                 1,
15479                                                 0);
15480 #endif
15481
15482         switch (ret) {
15483         case 0:
15484                 break;
15485         case -EINVAL:
15486                 fprintf(stderr, "invalid pctype or flow type\n");
15487                 break;
15488         case -ENODEV:
15489                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15490                 break;
15491         case -ENOTSUP:
15492                 fprintf(stderr, "function not implemented\n");
15493                 break;
15494         default:
15495                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15496         }
15497 }
15498
15499 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15500         .f = cmd_pctype_mapping_update_parsed,
15501         .data = NULL,
15502         .help_str = "port config <port_id> pctype mapping update"
15503         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15504         .tokens = {
15505                 (void *)&cmd_pctype_mapping_update_port,
15506                 (void *)&cmd_pctype_mapping_update_config,
15507                 (void *)&cmd_pctype_mapping_update_port_id,
15508                 (void *)&cmd_pctype_mapping_update_pctype,
15509                 (void *)&cmd_pctype_mapping_update_mapping,
15510                 (void *)&cmd_pctype_mapping_update_update,
15511                 (void *)&cmd_pctype_mapping_update_pc_type,
15512                 (void *)&cmd_pctype_mapping_update_flow_type,
15513                 NULL,
15514         },
15515 };
15516
15517 /* ptype mapping get */
15518
15519 /* Common result structure for ptype mapping get */
15520 struct cmd_ptype_mapping_get_result {
15521         cmdline_fixed_string_t ptype;
15522         cmdline_fixed_string_t mapping;
15523         cmdline_fixed_string_t get;
15524         portid_t port_id;
15525         uint8_t valid_only;
15526 };
15527
15528 /* Common CLI fields for ptype mapping get */
15529 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15530         TOKEN_STRING_INITIALIZER
15531                 (struct cmd_ptype_mapping_get_result,
15532                  ptype, "ptype");
15533 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15534         TOKEN_STRING_INITIALIZER
15535                 (struct cmd_ptype_mapping_get_result,
15536                  mapping, "mapping");
15537 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15538         TOKEN_STRING_INITIALIZER
15539                 (struct cmd_ptype_mapping_get_result,
15540                  get, "get");
15541 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15542         TOKEN_NUM_INITIALIZER
15543                 (struct cmd_ptype_mapping_get_result,
15544                  port_id, RTE_UINT16);
15545 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15546         TOKEN_NUM_INITIALIZER
15547                 (struct cmd_ptype_mapping_get_result,
15548                  valid_only, RTE_UINT8);
15549
15550 static void
15551 cmd_ptype_mapping_get_parsed(
15552         void *parsed_result,
15553         __rte_unused struct cmdline *cl,
15554         __rte_unused void *data)
15555 {
15556         struct cmd_ptype_mapping_get_result *res = parsed_result;
15557         int ret = -ENOTSUP;
15558 #ifdef RTE_NET_I40E
15559         int max_ptype_num = 256;
15560         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15561         uint16_t count;
15562         int i;
15563 #endif
15564
15565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15566                 return;
15567
15568 #ifdef RTE_NET_I40E
15569         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15570                                         mapping,
15571                                         max_ptype_num,
15572                                         &count,
15573                                         res->valid_only);
15574 #endif
15575
15576         switch (ret) {
15577         case 0:
15578                 break;
15579         case -ENODEV:
15580                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15581                 break;
15582         case -ENOTSUP:
15583                 fprintf(stderr, "function not implemented\n");
15584                 break;
15585         default:
15586                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15587         }
15588
15589 #ifdef RTE_NET_I40E
15590         if (!ret) {
15591                 for (i = 0; i < count; i++)
15592                         printf("%3d\t0x%08x\n",
15593                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15594         }
15595 #endif
15596 }
15597
15598 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15599         .f = cmd_ptype_mapping_get_parsed,
15600         .data = NULL,
15601         .help_str = "ptype mapping get <port_id> <valid_only>",
15602         .tokens = {
15603                 (void *)&cmd_ptype_mapping_get_ptype,
15604                 (void *)&cmd_ptype_mapping_get_mapping,
15605                 (void *)&cmd_ptype_mapping_get_get,
15606                 (void *)&cmd_ptype_mapping_get_port_id,
15607                 (void *)&cmd_ptype_mapping_get_valid_only,
15608                 NULL,
15609         },
15610 };
15611
15612 /* ptype mapping replace */
15613
15614 /* Common result structure for ptype mapping replace */
15615 struct cmd_ptype_mapping_replace_result {
15616         cmdline_fixed_string_t ptype;
15617         cmdline_fixed_string_t mapping;
15618         cmdline_fixed_string_t replace;
15619         portid_t port_id;
15620         uint32_t target;
15621         uint8_t mask;
15622         uint32_t pkt_type;
15623 };
15624
15625 /* Common CLI fields for ptype mapping replace */
15626 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15627         TOKEN_STRING_INITIALIZER
15628                 (struct cmd_ptype_mapping_replace_result,
15629                  ptype, "ptype");
15630 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15631         TOKEN_STRING_INITIALIZER
15632                 (struct cmd_ptype_mapping_replace_result,
15633                  mapping, "mapping");
15634 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15635         TOKEN_STRING_INITIALIZER
15636                 (struct cmd_ptype_mapping_replace_result,
15637                  replace, "replace");
15638 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15639         TOKEN_NUM_INITIALIZER
15640                 (struct cmd_ptype_mapping_replace_result,
15641                  port_id, RTE_UINT16);
15642 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15643         TOKEN_NUM_INITIALIZER
15644                 (struct cmd_ptype_mapping_replace_result,
15645                  target, RTE_UINT32);
15646 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15647         TOKEN_NUM_INITIALIZER
15648                 (struct cmd_ptype_mapping_replace_result,
15649                  mask, RTE_UINT8);
15650 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15651         TOKEN_NUM_INITIALIZER
15652                 (struct cmd_ptype_mapping_replace_result,
15653                  pkt_type, RTE_UINT32);
15654
15655 static void
15656 cmd_ptype_mapping_replace_parsed(
15657         void *parsed_result,
15658         __rte_unused struct cmdline *cl,
15659         __rte_unused void *data)
15660 {
15661         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15662         int ret = -ENOTSUP;
15663
15664         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15665                 return;
15666
15667 #ifdef RTE_NET_I40E
15668         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15669                                         res->target,
15670                                         res->mask,
15671                                         res->pkt_type);
15672 #endif
15673
15674         switch (ret) {
15675         case 0:
15676                 break;
15677         case -EINVAL:
15678                 fprintf(stderr, "invalid ptype 0x%8x or 0x%8x\n",
15679                         res->target, res->pkt_type);
15680                 break;
15681         case -ENODEV:
15682                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15683                 break;
15684         case -ENOTSUP:
15685                 fprintf(stderr, "function not implemented\n");
15686                 break;
15687         default:
15688                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15689         }
15690 }
15691
15692 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15693         .f = cmd_ptype_mapping_replace_parsed,
15694         .data = NULL,
15695         .help_str =
15696                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15697         .tokens = {
15698                 (void *)&cmd_ptype_mapping_replace_ptype,
15699                 (void *)&cmd_ptype_mapping_replace_mapping,
15700                 (void *)&cmd_ptype_mapping_replace_replace,
15701                 (void *)&cmd_ptype_mapping_replace_port_id,
15702                 (void *)&cmd_ptype_mapping_replace_target,
15703                 (void *)&cmd_ptype_mapping_replace_mask,
15704                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15705                 NULL,
15706         },
15707 };
15708
15709 /* ptype mapping reset */
15710
15711 /* Common result structure for ptype mapping reset */
15712 struct cmd_ptype_mapping_reset_result {
15713         cmdline_fixed_string_t ptype;
15714         cmdline_fixed_string_t mapping;
15715         cmdline_fixed_string_t reset;
15716         portid_t port_id;
15717 };
15718
15719 /* Common CLI fields for ptype mapping reset*/
15720 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15721         TOKEN_STRING_INITIALIZER
15722                 (struct cmd_ptype_mapping_reset_result,
15723                  ptype, "ptype");
15724 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15725         TOKEN_STRING_INITIALIZER
15726                 (struct cmd_ptype_mapping_reset_result,
15727                  mapping, "mapping");
15728 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15729         TOKEN_STRING_INITIALIZER
15730                 (struct cmd_ptype_mapping_reset_result,
15731                  reset, "reset");
15732 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15733         TOKEN_NUM_INITIALIZER
15734                 (struct cmd_ptype_mapping_reset_result,
15735                  port_id, RTE_UINT16);
15736
15737 static void
15738 cmd_ptype_mapping_reset_parsed(
15739         void *parsed_result,
15740         __rte_unused struct cmdline *cl,
15741         __rte_unused void *data)
15742 {
15743         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15744         int ret = -ENOTSUP;
15745
15746         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15747                 return;
15748
15749 #ifdef RTE_NET_I40E
15750         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15751 #endif
15752
15753         switch (ret) {
15754         case 0:
15755                 break;
15756         case -ENODEV:
15757                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15758                 break;
15759         case -ENOTSUP:
15760                 fprintf(stderr, "function not implemented\n");
15761                 break;
15762         default:
15763                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15764         }
15765 }
15766
15767 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15768         .f = cmd_ptype_mapping_reset_parsed,
15769         .data = NULL,
15770         .help_str = "ptype mapping reset <port_id>",
15771         .tokens = {
15772                 (void *)&cmd_ptype_mapping_reset_ptype,
15773                 (void *)&cmd_ptype_mapping_reset_mapping,
15774                 (void *)&cmd_ptype_mapping_reset_reset,
15775                 (void *)&cmd_ptype_mapping_reset_port_id,
15776                 NULL,
15777         },
15778 };
15779
15780 /* ptype mapping update */
15781
15782 /* Common result structure for ptype mapping update */
15783 struct cmd_ptype_mapping_update_result {
15784         cmdline_fixed_string_t ptype;
15785         cmdline_fixed_string_t mapping;
15786         cmdline_fixed_string_t reset;
15787         portid_t port_id;
15788         uint8_t hw_ptype;
15789         uint32_t sw_ptype;
15790 };
15791
15792 /* Common CLI fields for ptype mapping update*/
15793 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15794         TOKEN_STRING_INITIALIZER
15795                 (struct cmd_ptype_mapping_update_result,
15796                  ptype, "ptype");
15797 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15798         TOKEN_STRING_INITIALIZER
15799                 (struct cmd_ptype_mapping_update_result,
15800                  mapping, "mapping");
15801 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15802         TOKEN_STRING_INITIALIZER
15803                 (struct cmd_ptype_mapping_update_result,
15804                  reset, "update");
15805 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15806         TOKEN_NUM_INITIALIZER
15807                 (struct cmd_ptype_mapping_update_result,
15808                  port_id, RTE_UINT16);
15809 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15810         TOKEN_NUM_INITIALIZER
15811                 (struct cmd_ptype_mapping_update_result,
15812                  hw_ptype, RTE_UINT8);
15813 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15814         TOKEN_NUM_INITIALIZER
15815                 (struct cmd_ptype_mapping_update_result,
15816                  sw_ptype, RTE_UINT32);
15817
15818 static void
15819 cmd_ptype_mapping_update_parsed(
15820         void *parsed_result,
15821         __rte_unused struct cmdline *cl,
15822         __rte_unused void *data)
15823 {
15824         struct cmd_ptype_mapping_update_result *res = parsed_result;
15825         int ret = -ENOTSUP;
15826 #ifdef RTE_NET_I40E
15827         struct rte_pmd_i40e_ptype_mapping mapping;
15828 #endif
15829         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15830                 return;
15831
15832 #ifdef RTE_NET_I40E
15833         mapping.hw_ptype = res->hw_ptype;
15834         mapping.sw_ptype = res->sw_ptype;
15835         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15836                                                 &mapping,
15837                                                 1,
15838                                                 0);
15839 #endif
15840
15841         switch (ret) {
15842         case 0:
15843                 break;
15844         case -EINVAL:
15845                 fprintf(stderr, "invalid ptype 0x%8x\n", res->sw_ptype);
15846                 break;
15847         case -ENODEV:
15848                 fprintf(stderr, "invalid port_id %d\n", res->port_id);
15849                 break;
15850         case -ENOTSUP:
15851                 fprintf(stderr, "function not implemented\n");
15852                 break;
15853         default:
15854                 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
15855         }
15856 }
15857
15858 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15859         .f = cmd_ptype_mapping_update_parsed,
15860         .data = NULL,
15861         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15862         .tokens = {
15863                 (void *)&cmd_ptype_mapping_update_ptype,
15864                 (void *)&cmd_ptype_mapping_update_mapping,
15865                 (void *)&cmd_ptype_mapping_update_update,
15866                 (void *)&cmd_ptype_mapping_update_port_id,
15867                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15868                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15869                 NULL,
15870         },
15871 };
15872
15873 /* Common result structure for file commands */
15874 struct cmd_cmdfile_result {
15875         cmdline_fixed_string_t load;
15876         cmdline_fixed_string_t filename;
15877 };
15878
15879 /* Common CLI fields for file commands */
15880 cmdline_parse_token_string_t cmd_load_cmdfile =
15881         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15882 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15883         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15884
15885 static void
15886 cmd_load_from_file_parsed(
15887         void *parsed_result,
15888         __rte_unused struct cmdline *cl,
15889         __rte_unused void *data)
15890 {
15891         struct cmd_cmdfile_result *res = parsed_result;
15892
15893         cmdline_read_from_file(res->filename);
15894 }
15895
15896 cmdline_parse_inst_t cmd_load_from_file = {
15897         .f = cmd_load_from_file_parsed,
15898         .data = NULL,
15899         .help_str = "load <filename>",
15900         .tokens = {
15901                 (void *)&cmd_load_cmdfile,
15902                 (void *)&cmd_load_cmdfile_filename,
15903                 NULL,
15904         },
15905 };
15906
15907 /* Get Rx offloads capabilities */
15908 struct cmd_rx_offload_get_capa_result {
15909         cmdline_fixed_string_t show;
15910         cmdline_fixed_string_t port;
15911         portid_t port_id;
15912         cmdline_fixed_string_t rx_offload;
15913         cmdline_fixed_string_t capabilities;
15914 };
15915
15916 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
15917         TOKEN_STRING_INITIALIZER
15918                 (struct cmd_rx_offload_get_capa_result,
15919                  show, "show");
15920 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
15921         TOKEN_STRING_INITIALIZER
15922                 (struct cmd_rx_offload_get_capa_result,
15923                  port, "port");
15924 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
15925         TOKEN_NUM_INITIALIZER
15926                 (struct cmd_rx_offload_get_capa_result,
15927                  port_id, RTE_UINT16);
15928 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
15929         TOKEN_STRING_INITIALIZER
15930                 (struct cmd_rx_offload_get_capa_result,
15931                  rx_offload, "rx_offload");
15932 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
15933         TOKEN_STRING_INITIALIZER
15934                 (struct cmd_rx_offload_get_capa_result,
15935                  capabilities, "capabilities");
15936
15937 static void
15938 print_rx_offloads(uint64_t offloads)
15939 {
15940         uint64_t single_offload;
15941         int begin;
15942         int end;
15943         int bit;
15944
15945         if (offloads == 0)
15946                 return;
15947
15948         begin = __builtin_ctzll(offloads);
15949         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
15950
15951         single_offload = 1ULL << begin;
15952         for (bit = begin; bit < end; bit++) {
15953                 if (offloads & single_offload)
15954                         printf(" %s",
15955                                rte_eth_dev_rx_offload_name(single_offload));
15956                 single_offload <<= 1;
15957         }
15958 }
15959
15960 static void
15961 cmd_rx_offload_get_capa_parsed(
15962         void *parsed_result,
15963         __rte_unused struct cmdline *cl,
15964         __rte_unused void *data)
15965 {
15966         struct cmd_rx_offload_get_capa_result *res = parsed_result;
15967         struct rte_eth_dev_info dev_info;
15968         portid_t port_id = res->port_id;
15969         uint64_t queue_offloads;
15970         uint64_t port_offloads;
15971         int ret;
15972
15973         ret = eth_dev_info_get_print_err(port_id, &dev_info);
15974         if (ret != 0)
15975                 return;
15976
15977         queue_offloads = dev_info.rx_queue_offload_capa;
15978         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
15979
15980         printf("Rx Offloading Capabilities of port %d :\n", port_id);
15981         printf("  Per Queue :");
15982         print_rx_offloads(queue_offloads);
15983
15984         printf("\n");
15985         printf("  Per Port  :");
15986         print_rx_offloads(port_offloads);
15987         printf("\n\n");
15988 }
15989
15990 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
15991         .f = cmd_rx_offload_get_capa_parsed,
15992         .data = NULL,
15993         .help_str = "show port <port_id> rx_offload capabilities",
15994         .tokens = {
15995                 (void *)&cmd_rx_offload_get_capa_show,
15996                 (void *)&cmd_rx_offload_get_capa_port,
15997                 (void *)&cmd_rx_offload_get_capa_port_id,
15998                 (void *)&cmd_rx_offload_get_capa_rx_offload,
15999                 (void *)&cmd_rx_offload_get_capa_capabilities,
16000                 NULL,
16001         }
16002 };
16003
16004 /* Get Rx offloads configuration */
16005 struct cmd_rx_offload_get_configuration_result {
16006         cmdline_fixed_string_t show;
16007         cmdline_fixed_string_t port;
16008         portid_t port_id;
16009         cmdline_fixed_string_t rx_offload;
16010         cmdline_fixed_string_t configuration;
16011 };
16012
16013 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16014         TOKEN_STRING_INITIALIZER
16015                 (struct cmd_rx_offload_get_configuration_result,
16016                  show, "show");
16017 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16018         TOKEN_STRING_INITIALIZER
16019                 (struct cmd_rx_offload_get_configuration_result,
16020                  port, "port");
16021 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16022         TOKEN_NUM_INITIALIZER
16023                 (struct cmd_rx_offload_get_configuration_result,
16024                  port_id, RTE_UINT16);
16025 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16026         TOKEN_STRING_INITIALIZER
16027                 (struct cmd_rx_offload_get_configuration_result,
16028                  rx_offload, "rx_offload");
16029 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16030         TOKEN_STRING_INITIALIZER
16031                 (struct cmd_rx_offload_get_configuration_result,
16032                  configuration, "configuration");
16033
16034 static void
16035 cmd_rx_offload_get_configuration_parsed(
16036         void *parsed_result,
16037         __rte_unused struct cmdline *cl,
16038         __rte_unused void *data)
16039 {
16040         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
16041         struct rte_eth_dev_info dev_info;
16042         portid_t port_id = res->port_id;
16043         struct rte_port *port = &ports[port_id];
16044         struct rte_eth_conf dev_conf;
16045         uint64_t port_offloads;
16046         uint64_t queue_offloads;
16047         uint16_t nb_rx_queues;
16048         int q;
16049         int ret;
16050
16051         printf("Rx Offloading Configuration of port %d :\n", port_id);
16052
16053         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16054         if (ret != 0)
16055                 return;
16056
16057         port_offloads = dev_conf.rxmode.offloads;
16058         printf("  Port :");
16059         print_rx_offloads(port_offloads);
16060         printf("\n");
16061
16062         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16063         if (ret != 0)
16064                 return;
16065
16066         nb_rx_queues = dev_info.nb_rx_queues;
16067         for (q = 0; q < nb_rx_queues; q++) {
16068                 queue_offloads = port->rx_conf[q].offloads;
16069                 printf("  Queue[%2d] :", q);
16070                 print_rx_offloads(queue_offloads);
16071                 printf("\n");
16072         }
16073         printf("\n");
16074 }
16075
16076 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
16077         .f = cmd_rx_offload_get_configuration_parsed,
16078         .data = NULL,
16079         .help_str = "show port <port_id> rx_offload configuration",
16080         .tokens = {
16081                 (void *)&cmd_rx_offload_get_configuration_show,
16082                 (void *)&cmd_rx_offload_get_configuration_port,
16083                 (void *)&cmd_rx_offload_get_configuration_port_id,
16084                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
16085                 (void *)&cmd_rx_offload_get_configuration_configuration,
16086                 NULL,
16087         }
16088 };
16089
16090 /* Enable/Disable a per port offloading */
16091 struct cmd_config_per_port_rx_offload_result {
16092         cmdline_fixed_string_t port;
16093         cmdline_fixed_string_t config;
16094         portid_t port_id;
16095         cmdline_fixed_string_t rx_offload;
16096         cmdline_fixed_string_t offload;
16097         cmdline_fixed_string_t on_off;
16098 };
16099
16100 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
16101         TOKEN_STRING_INITIALIZER
16102                 (struct cmd_config_per_port_rx_offload_result,
16103                  port, "port");
16104 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
16105         TOKEN_STRING_INITIALIZER
16106                 (struct cmd_config_per_port_rx_offload_result,
16107                  config, "config");
16108 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
16109         TOKEN_NUM_INITIALIZER
16110                 (struct cmd_config_per_port_rx_offload_result,
16111                  port_id, RTE_UINT16);
16112 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
16113         TOKEN_STRING_INITIALIZER
16114                 (struct cmd_config_per_port_rx_offload_result,
16115                  rx_offload, "rx_offload");
16116 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
16117         TOKEN_STRING_INITIALIZER
16118                 (struct cmd_config_per_port_rx_offload_result,
16119                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16120                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16121                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16122                            "scatter#buffer_split#timestamp#security#"
16123                            "keep_crc#rss_hash");
16124 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
16125         TOKEN_STRING_INITIALIZER
16126                 (struct cmd_config_per_port_rx_offload_result,
16127                  on_off, "on#off");
16128
16129 static uint64_t
16130 search_rx_offload(const char *name)
16131 {
16132         uint64_t single_offload;
16133         const char *single_name;
16134         int found = 0;
16135         unsigned int bit;
16136
16137         single_offload = 1;
16138         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16139                 single_name = rte_eth_dev_rx_offload_name(single_offload);
16140                 if (!strcasecmp(single_name, name)) {
16141                         found = 1;
16142                         break;
16143                 }
16144                 single_offload <<= 1;
16145         }
16146
16147         if (found)
16148                 return single_offload;
16149
16150         return 0;
16151 }
16152
16153 static void
16154 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
16155                                 __rte_unused struct cmdline *cl,
16156                                 __rte_unused void *data)
16157 {
16158         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
16159         portid_t port_id = res->port_id;
16160         struct rte_eth_dev_info dev_info;
16161         struct rte_port *port = &ports[port_id];
16162         uint64_t single_offload;
16163         uint16_t nb_rx_queues;
16164         int q;
16165         int ret;
16166
16167         if (port->port_status != RTE_PORT_STOPPED) {
16168                 fprintf(stderr,
16169                         "Error: Can't config offload when Port %d is not stopped\n",
16170                         port_id);
16171                 return;
16172         }
16173
16174         single_offload = search_rx_offload(res->offload);
16175         if (single_offload == 0) {
16176                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16177                 return;
16178         }
16179
16180         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16181         if (ret != 0)
16182                 return;
16183
16184         nb_rx_queues = dev_info.nb_rx_queues;
16185         if (!strcmp(res->on_off, "on")) {
16186                 port->dev_conf.rxmode.offloads |= single_offload;
16187                 for (q = 0; q < nb_rx_queues; q++)
16188                         port->rx_conf[q].offloads |= single_offload;
16189         } else {
16190                 port->dev_conf.rxmode.offloads &= ~single_offload;
16191                 for (q = 0; q < nb_rx_queues; q++)
16192                         port->rx_conf[q].offloads &= ~single_offload;
16193         }
16194
16195         cmd_reconfig_device_queue(port_id, 1, 1);
16196 }
16197
16198 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
16199         .f = cmd_config_per_port_rx_offload_parsed,
16200         .data = NULL,
16201         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
16202                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16203                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16204                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16205                     "keep_crc|rss_hash on|off",
16206         .tokens = {
16207                 (void *)&cmd_config_per_port_rx_offload_result_port,
16208                 (void *)&cmd_config_per_port_rx_offload_result_config,
16209                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
16210                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
16211                 (void *)&cmd_config_per_port_rx_offload_result_offload,
16212                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
16213                 NULL,
16214         }
16215 };
16216
16217 /* Enable/Disable a per queue offloading */
16218 struct cmd_config_per_queue_rx_offload_result {
16219         cmdline_fixed_string_t port;
16220         portid_t port_id;
16221         cmdline_fixed_string_t rxq;
16222         uint16_t queue_id;
16223         cmdline_fixed_string_t rx_offload;
16224         cmdline_fixed_string_t offload;
16225         cmdline_fixed_string_t on_off;
16226 };
16227
16228 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
16229         TOKEN_STRING_INITIALIZER
16230                 (struct cmd_config_per_queue_rx_offload_result,
16231                  port, "port");
16232 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
16233         TOKEN_NUM_INITIALIZER
16234                 (struct cmd_config_per_queue_rx_offload_result,
16235                  port_id, RTE_UINT16);
16236 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
16237         TOKEN_STRING_INITIALIZER
16238                 (struct cmd_config_per_queue_rx_offload_result,
16239                  rxq, "rxq");
16240 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
16241         TOKEN_NUM_INITIALIZER
16242                 (struct cmd_config_per_queue_rx_offload_result,
16243                  queue_id, RTE_UINT16);
16244 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
16245         TOKEN_STRING_INITIALIZER
16246                 (struct cmd_config_per_queue_rx_offload_result,
16247                  rx_offload, "rx_offload");
16248 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
16249         TOKEN_STRING_INITIALIZER
16250                 (struct cmd_config_per_queue_rx_offload_result,
16251                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
16252                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
16253                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
16254                            "scatter#buffer_split#timestamp#security#keep_crc");
16255 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
16256         TOKEN_STRING_INITIALIZER
16257                 (struct cmd_config_per_queue_rx_offload_result,
16258                  on_off, "on#off");
16259
16260 static void
16261 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
16262                                 __rte_unused struct cmdline *cl,
16263                                 __rte_unused void *data)
16264 {
16265         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
16266         struct rte_eth_dev_info dev_info;
16267         portid_t port_id = res->port_id;
16268         uint16_t queue_id = res->queue_id;
16269         struct rte_port *port = &ports[port_id];
16270         uint64_t single_offload;
16271         int ret;
16272
16273         if (port->port_status != RTE_PORT_STOPPED) {
16274                 fprintf(stderr,
16275                         "Error: Can't config offload when Port %d is not stopped\n",
16276                         port_id);
16277                 return;
16278         }
16279
16280         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16281         if (ret != 0)
16282                 return;
16283
16284         if (queue_id >= dev_info.nb_rx_queues) {
16285                 fprintf(stderr,
16286                         "Error: input queue_id should be 0 ... %d\n",
16287                         dev_info.nb_rx_queues - 1);
16288                 return;
16289         }
16290
16291         single_offload = search_rx_offload(res->offload);
16292         if (single_offload == 0) {
16293                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16294                 return;
16295         }
16296
16297         if (!strcmp(res->on_off, "on"))
16298                 port->rx_conf[queue_id].offloads |= single_offload;
16299         else
16300                 port->rx_conf[queue_id].offloads &= ~single_offload;
16301
16302         cmd_reconfig_device_queue(port_id, 1, 1);
16303 }
16304
16305 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
16306         .f = cmd_config_per_queue_rx_offload_parsed,
16307         .data = NULL,
16308         .help_str = "port <port_id> rxq <queue_id> rx_offload "
16309                     "vlan_strip|ipv4_cksum|"
16310                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
16311                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
16312                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
16313                     "keep_crc on|off",
16314         .tokens = {
16315                 (void *)&cmd_config_per_queue_rx_offload_result_port,
16316                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
16317                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
16318                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
16319                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
16320                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
16321                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
16322                 NULL,
16323         }
16324 };
16325
16326 /* Get Tx offloads capabilities */
16327 struct cmd_tx_offload_get_capa_result {
16328         cmdline_fixed_string_t show;
16329         cmdline_fixed_string_t port;
16330         portid_t port_id;
16331         cmdline_fixed_string_t tx_offload;
16332         cmdline_fixed_string_t capabilities;
16333 };
16334
16335 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
16336         TOKEN_STRING_INITIALIZER
16337                 (struct cmd_tx_offload_get_capa_result,
16338                  show, "show");
16339 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
16340         TOKEN_STRING_INITIALIZER
16341                 (struct cmd_tx_offload_get_capa_result,
16342                  port, "port");
16343 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
16344         TOKEN_NUM_INITIALIZER
16345                 (struct cmd_tx_offload_get_capa_result,
16346                  port_id, RTE_UINT16);
16347 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
16348         TOKEN_STRING_INITIALIZER
16349                 (struct cmd_tx_offload_get_capa_result,
16350                  tx_offload, "tx_offload");
16351 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
16352         TOKEN_STRING_INITIALIZER
16353                 (struct cmd_tx_offload_get_capa_result,
16354                  capabilities, "capabilities");
16355
16356 static void
16357 print_tx_offloads(uint64_t offloads)
16358 {
16359         uint64_t single_offload;
16360         int begin;
16361         int end;
16362         int bit;
16363
16364         if (offloads == 0)
16365                 return;
16366
16367         begin = __builtin_ctzll(offloads);
16368         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16369
16370         single_offload = 1ULL << begin;
16371         for (bit = begin; bit < end; bit++) {
16372                 if (offloads & single_offload)
16373                         printf(" %s",
16374                                rte_eth_dev_tx_offload_name(single_offload));
16375                 single_offload <<= 1;
16376         }
16377 }
16378
16379 static void
16380 cmd_tx_offload_get_capa_parsed(
16381         void *parsed_result,
16382         __rte_unused struct cmdline *cl,
16383         __rte_unused void *data)
16384 {
16385         struct cmd_tx_offload_get_capa_result *res = parsed_result;
16386         struct rte_eth_dev_info dev_info;
16387         portid_t port_id = res->port_id;
16388         uint64_t queue_offloads;
16389         uint64_t port_offloads;
16390         int ret;
16391
16392         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16393         if (ret != 0)
16394                 return;
16395
16396         queue_offloads = dev_info.tx_queue_offload_capa;
16397         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
16398
16399         printf("Tx Offloading Capabilities of port %d :\n", port_id);
16400         printf("  Per Queue :");
16401         print_tx_offloads(queue_offloads);
16402
16403         printf("\n");
16404         printf("  Per Port  :");
16405         print_tx_offloads(port_offloads);
16406         printf("\n\n");
16407 }
16408
16409 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
16410         .f = cmd_tx_offload_get_capa_parsed,
16411         .data = NULL,
16412         .help_str = "show port <port_id> tx_offload capabilities",
16413         .tokens = {
16414                 (void *)&cmd_tx_offload_get_capa_show,
16415                 (void *)&cmd_tx_offload_get_capa_port,
16416                 (void *)&cmd_tx_offload_get_capa_port_id,
16417                 (void *)&cmd_tx_offload_get_capa_tx_offload,
16418                 (void *)&cmd_tx_offload_get_capa_capabilities,
16419                 NULL,
16420         }
16421 };
16422
16423 /* Get Tx offloads configuration */
16424 struct cmd_tx_offload_get_configuration_result {
16425         cmdline_fixed_string_t show;
16426         cmdline_fixed_string_t port;
16427         portid_t port_id;
16428         cmdline_fixed_string_t tx_offload;
16429         cmdline_fixed_string_t configuration;
16430 };
16431
16432 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
16433         TOKEN_STRING_INITIALIZER
16434                 (struct cmd_tx_offload_get_configuration_result,
16435                  show, "show");
16436 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
16437         TOKEN_STRING_INITIALIZER
16438                 (struct cmd_tx_offload_get_configuration_result,
16439                  port, "port");
16440 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
16441         TOKEN_NUM_INITIALIZER
16442                 (struct cmd_tx_offload_get_configuration_result,
16443                  port_id, RTE_UINT16);
16444 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
16445         TOKEN_STRING_INITIALIZER
16446                 (struct cmd_tx_offload_get_configuration_result,
16447                  tx_offload, "tx_offload");
16448 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
16449         TOKEN_STRING_INITIALIZER
16450                 (struct cmd_tx_offload_get_configuration_result,
16451                  configuration, "configuration");
16452
16453 static void
16454 cmd_tx_offload_get_configuration_parsed(
16455         void *parsed_result,
16456         __rte_unused struct cmdline *cl,
16457         __rte_unused void *data)
16458 {
16459         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
16460         struct rte_eth_dev_info dev_info;
16461         portid_t port_id = res->port_id;
16462         struct rte_port *port = &ports[port_id];
16463         struct rte_eth_conf dev_conf;
16464         uint64_t port_offloads;
16465         uint64_t queue_offloads;
16466         uint16_t nb_tx_queues;
16467         int q;
16468         int ret;
16469
16470         printf("Tx Offloading Configuration of port %d :\n", port_id);
16471
16472         ret = eth_dev_conf_get_print_err(port_id, &dev_conf);
16473         if (ret != 0)
16474                 return;
16475
16476         port_offloads = dev_conf.txmode.offloads;
16477         printf("  Port :");
16478         print_tx_offloads(port_offloads);
16479         printf("\n");
16480
16481         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16482         if (ret != 0)
16483                 return;
16484
16485         nb_tx_queues = dev_info.nb_tx_queues;
16486         for (q = 0; q < nb_tx_queues; q++) {
16487                 queue_offloads = port->tx_conf[q].offloads;
16488                 printf("  Queue[%2d] :", q);
16489                 print_tx_offloads(queue_offloads);
16490                 printf("\n");
16491         }
16492         printf("\n");
16493 }
16494
16495 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
16496         .f = cmd_tx_offload_get_configuration_parsed,
16497         .data = NULL,
16498         .help_str = "show port <port_id> tx_offload configuration",
16499         .tokens = {
16500                 (void *)&cmd_tx_offload_get_configuration_show,
16501                 (void *)&cmd_tx_offload_get_configuration_port,
16502                 (void *)&cmd_tx_offload_get_configuration_port_id,
16503                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
16504                 (void *)&cmd_tx_offload_get_configuration_configuration,
16505                 NULL,
16506         }
16507 };
16508
16509 /* Enable/Disable a per port offloading */
16510 struct cmd_config_per_port_tx_offload_result {
16511         cmdline_fixed_string_t port;
16512         cmdline_fixed_string_t config;
16513         portid_t port_id;
16514         cmdline_fixed_string_t tx_offload;
16515         cmdline_fixed_string_t offload;
16516         cmdline_fixed_string_t on_off;
16517 };
16518
16519 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
16520         TOKEN_STRING_INITIALIZER
16521                 (struct cmd_config_per_port_tx_offload_result,
16522                  port, "port");
16523 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
16524         TOKEN_STRING_INITIALIZER
16525                 (struct cmd_config_per_port_tx_offload_result,
16526                  config, "config");
16527 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
16528         TOKEN_NUM_INITIALIZER
16529                 (struct cmd_config_per_port_tx_offload_result,
16530                  port_id, RTE_UINT16);
16531 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
16532         TOKEN_STRING_INITIALIZER
16533                 (struct cmd_config_per_port_tx_offload_result,
16534                  tx_offload, "tx_offload");
16535 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
16536         TOKEN_STRING_INITIALIZER
16537                 (struct cmd_config_per_port_tx_offload_result,
16538                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16539                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16540                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16541                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16542                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
16543                           "send_on_timestamp");
16544 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
16545         TOKEN_STRING_INITIALIZER
16546                 (struct cmd_config_per_port_tx_offload_result,
16547                  on_off, "on#off");
16548
16549 static uint64_t
16550 search_tx_offload(const char *name)
16551 {
16552         uint64_t single_offload;
16553         const char *single_name;
16554         int found = 0;
16555         unsigned int bit;
16556
16557         single_offload = 1;
16558         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
16559                 single_name = rte_eth_dev_tx_offload_name(single_offload);
16560                 if (single_name == NULL)
16561                         break;
16562                 if (!strcasecmp(single_name, name)) {
16563                         found = 1;
16564                         break;
16565                 } else if (!strcasecmp(single_name, "UNKNOWN"))
16566                         break;
16567                 single_offload <<= 1;
16568         }
16569
16570         if (found)
16571                 return single_offload;
16572
16573         return 0;
16574 }
16575
16576 static void
16577 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
16578                                 __rte_unused struct cmdline *cl,
16579                                 __rte_unused void *data)
16580 {
16581         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
16582         portid_t port_id = res->port_id;
16583         struct rte_eth_dev_info dev_info;
16584         struct rte_port *port = &ports[port_id];
16585         uint64_t single_offload;
16586         uint16_t nb_tx_queues;
16587         int q;
16588         int ret;
16589
16590         if (port->port_status != RTE_PORT_STOPPED) {
16591                 fprintf(stderr,
16592                         "Error: Can't config offload when Port %d is not stopped\n",
16593                         port_id);
16594                 return;
16595         }
16596
16597         single_offload = search_tx_offload(res->offload);
16598         if (single_offload == 0) {
16599                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16600                 return;
16601         }
16602
16603         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16604         if (ret != 0)
16605                 return;
16606
16607         nb_tx_queues = dev_info.nb_tx_queues;
16608         if (!strcmp(res->on_off, "on")) {
16609                 port->dev_conf.txmode.offloads |= single_offload;
16610                 for (q = 0; q < nb_tx_queues; q++)
16611                         port->tx_conf[q].offloads |= single_offload;
16612         } else {
16613                 port->dev_conf.txmode.offloads &= ~single_offload;
16614                 for (q = 0; q < nb_tx_queues; q++)
16615                         port->tx_conf[q].offloads &= ~single_offload;
16616         }
16617
16618         cmd_reconfig_device_queue(port_id, 1, 1);
16619 }
16620
16621 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
16622         .f = cmd_config_per_port_tx_offload_parsed,
16623         .data = NULL,
16624         .help_str = "port config <port_id> tx_offload "
16625                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16626                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16627                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16628                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16629                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
16630                     "send_on_timestamp on|off",
16631         .tokens = {
16632                 (void *)&cmd_config_per_port_tx_offload_result_port,
16633                 (void *)&cmd_config_per_port_tx_offload_result_config,
16634                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
16635                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
16636                 (void *)&cmd_config_per_port_tx_offload_result_offload,
16637                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
16638                 NULL,
16639         }
16640 };
16641
16642 /* Enable/Disable a per queue offloading */
16643 struct cmd_config_per_queue_tx_offload_result {
16644         cmdline_fixed_string_t port;
16645         portid_t port_id;
16646         cmdline_fixed_string_t txq;
16647         uint16_t queue_id;
16648         cmdline_fixed_string_t tx_offload;
16649         cmdline_fixed_string_t offload;
16650         cmdline_fixed_string_t on_off;
16651 };
16652
16653 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
16654         TOKEN_STRING_INITIALIZER
16655                 (struct cmd_config_per_queue_tx_offload_result,
16656                  port, "port");
16657 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
16658         TOKEN_NUM_INITIALIZER
16659                 (struct cmd_config_per_queue_tx_offload_result,
16660                  port_id, RTE_UINT16);
16661 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
16662         TOKEN_STRING_INITIALIZER
16663                 (struct cmd_config_per_queue_tx_offload_result,
16664                  txq, "txq");
16665 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
16666         TOKEN_NUM_INITIALIZER
16667                 (struct cmd_config_per_queue_tx_offload_result,
16668                  queue_id, RTE_UINT16);
16669 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
16670         TOKEN_STRING_INITIALIZER
16671                 (struct cmd_config_per_queue_tx_offload_result,
16672                  tx_offload, "tx_offload");
16673 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
16674         TOKEN_STRING_INITIALIZER
16675                 (struct cmd_config_per_queue_tx_offload_result,
16676                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
16677                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
16678                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
16679                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
16680                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
16681 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
16682         TOKEN_STRING_INITIALIZER
16683                 (struct cmd_config_per_queue_tx_offload_result,
16684                  on_off, "on#off");
16685
16686 static void
16687 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
16688                                 __rte_unused struct cmdline *cl,
16689                                 __rte_unused void *data)
16690 {
16691         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
16692         struct rte_eth_dev_info dev_info;
16693         portid_t port_id = res->port_id;
16694         uint16_t queue_id = res->queue_id;
16695         struct rte_port *port = &ports[port_id];
16696         uint64_t single_offload;
16697         int ret;
16698
16699         if (port->port_status != RTE_PORT_STOPPED) {
16700                 fprintf(stderr,
16701                         "Error: Can't config offload when Port %d is not stopped\n",
16702                         port_id);
16703                 return;
16704         }
16705
16706         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16707         if (ret != 0)
16708                 return;
16709
16710         if (queue_id >= dev_info.nb_tx_queues) {
16711                 fprintf(stderr,
16712                         "Error: input queue_id should be 0 ... %d\n",
16713                         dev_info.nb_tx_queues - 1);
16714                 return;
16715         }
16716
16717         single_offload = search_tx_offload(res->offload);
16718         if (single_offload == 0) {
16719                 fprintf(stderr, "Unknown offload name: %s\n", res->offload);
16720                 return;
16721         }
16722
16723         if (!strcmp(res->on_off, "on"))
16724                 port->tx_conf[queue_id].offloads |= single_offload;
16725         else
16726                 port->tx_conf[queue_id].offloads &= ~single_offload;
16727
16728         cmd_reconfig_device_queue(port_id, 1, 1);
16729 }
16730
16731 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
16732         .f = cmd_config_per_queue_tx_offload_parsed,
16733         .data = NULL,
16734         .help_str = "port <port_id> txq <queue_id> tx_offload "
16735                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
16736                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
16737                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
16738                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
16739                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
16740                     "on|off",
16741         .tokens = {
16742                 (void *)&cmd_config_per_queue_tx_offload_result_port,
16743                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
16744                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
16745                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
16746                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
16747                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
16748                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
16749                 NULL,
16750         }
16751 };
16752
16753 /* *** configure tx_metadata for specific port *** */
16754 struct cmd_config_tx_metadata_specific_result {
16755         cmdline_fixed_string_t port;
16756         cmdline_fixed_string_t keyword;
16757         uint16_t port_id;
16758         cmdline_fixed_string_t item;
16759         uint32_t value;
16760 };
16761
16762 static void
16763 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
16764                                 __rte_unused struct cmdline *cl,
16765                                 __rte_unused void *data)
16766 {
16767         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
16768
16769         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16770                 return;
16771         ports[res->port_id].tx_metadata = res->value;
16772         /* Add/remove callback to insert valid metadata in every Tx packet. */
16773         if (ports[res->port_id].tx_metadata)
16774                 add_tx_md_callback(res->port_id);
16775         else
16776                 remove_tx_md_callback(res->port_id);
16777         rte_flow_dynf_metadata_register();
16778 }
16779
16780 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
16781         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16782                         port, "port");
16783 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
16784         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16785                         keyword, "config");
16786 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
16787         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16788                         port_id, RTE_UINT16);
16789 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
16790         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16791                         item, "tx_metadata");
16792 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
16793         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
16794                         value, RTE_UINT32);
16795
16796 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
16797         .f = cmd_config_tx_metadata_specific_parsed,
16798         .data = NULL,
16799         .help_str = "port config <port_id> tx_metadata <value>",
16800         .tokens = {
16801                 (void *)&cmd_config_tx_metadata_specific_port,
16802                 (void *)&cmd_config_tx_metadata_specific_keyword,
16803                 (void *)&cmd_config_tx_metadata_specific_id,
16804                 (void *)&cmd_config_tx_metadata_specific_item,
16805                 (void *)&cmd_config_tx_metadata_specific_value,
16806                 NULL,
16807         },
16808 };
16809
16810 /* *** set dynf *** */
16811 struct cmd_config_tx_dynf_specific_result {
16812         cmdline_fixed_string_t port;
16813         cmdline_fixed_string_t keyword;
16814         uint16_t port_id;
16815         cmdline_fixed_string_t item;
16816         cmdline_fixed_string_t name;
16817         cmdline_fixed_string_t value;
16818 };
16819
16820 static void
16821 cmd_config_dynf_specific_parsed(void *parsed_result,
16822                                 __rte_unused struct cmdline *cl,
16823                                 __rte_unused void *data)
16824 {
16825         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
16826         struct rte_mbuf_dynflag desc_flag;
16827         int flag;
16828         uint64_t old_port_flags;
16829
16830         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16831                 return;
16832         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
16833         if (flag <= 0) {
16834                 if (strlcpy(desc_flag.name, res->name,
16835                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
16836                         fprintf(stderr, "Flag name too long\n");
16837                         return;
16838                 }
16839                 desc_flag.flags = 0;
16840                 flag = rte_mbuf_dynflag_register(&desc_flag);
16841                 if (flag < 0) {
16842                         fprintf(stderr, "Can't register flag\n");
16843                         return;
16844                 }
16845                 strcpy(dynf_names[flag], desc_flag.name);
16846         }
16847         old_port_flags = ports[res->port_id].mbuf_dynf;
16848         if (!strcmp(res->value, "set")) {
16849                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
16850                 if (old_port_flags == 0)
16851                         add_tx_dynf_callback(res->port_id);
16852         } else {
16853                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
16854                 if (ports[res->port_id].mbuf_dynf == 0)
16855                         remove_tx_dynf_callback(res->port_id);
16856         }
16857 }
16858
16859 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
16860         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16861                         keyword, "port");
16862 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
16863         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16864                         keyword, "config");
16865 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
16866         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16867                         port_id, RTE_UINT16);
16868 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
16869         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16870                         item, "dynf");
16871 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
16872         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16873                         name, NULL);
16874 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
16875         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
16876                         value, "set#clear");
16877
16878 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
16879         .f = cmd_config_dynf_specific_parsed,
16880         .data = NULL,
16881         .help_str = "port config <port id> dynf <name> set|clear",
16882         .tokens = {
16883                 (void *)&cmd_config_tx_dynf_specific_port,
16884                 (void *)&cmd_config_tx_dynf_specific_keyword,
16885                 (void *)&cmd_config_tx_dynf_specific_port_id,
16886                 (void *)&cmd_config_tx_dynf_specific_item,
16887                 (void *)&cmd_config_tx_dynf_specific_name,
16888                 (void *)&cmd_config_tx_dynf_specific_value,
16889                 NULL,
16890         },
16891 };
16892
16893 /* *** display tx_metadata per port configuration *** */
16894 struct cmd_show_tx_metadata_result {
16895         cmdline_fixed_string_t cmd_show;
16896         cmdline_fixed_string_t cmd_port;
16897         cmdline_fixed_string_t cmd_keyword;
16898         portid_t cmd_pid;
16899 };
16900
16901 static void
16902 cmd_show_tx_metadata_parsed(void *parsed_result,
16903                 __rte_unused struct cmdline *cl,
16904                 __rte_unused void *data)
16905 {
16906         struct cmd_show_tx_metadata_result *res = parsed_result;
16907
16908         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16909                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
16910                 return;
16911         }
16912         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
16913                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
16914                        ports[res->cmd_pid].tx_metadata);
16915         }
16916 }
16917
16918 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
16919         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16920                         cmd_show, "show");
16921 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
16922         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16923                         cmd_port, "port");
16924 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
16925         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
16926                         cmd_pid, RTE_UINT16);
16927 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
16928         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
16929                         cmd_keyword, "tx_metadata");
16930
16931 cmdline_parse_inst_t cmd_show_tx_metadata = {
16932         .f = cmd_show_tx_metadata_parsed,
16933         .data = NULL,
16934         .help_str = "show port <port_id> tx_metadata",
16935         .tokens = {
16936                 (void *)&cmd_show_tx_metadata_show,
16937                 (void *)&cmd_show_tx_metadata_port,
16938                 (void *)&cmd_show_tx_metadata_pid,
16939                 (void *)&cmd_show_tx_metadata_keyword,
16940                 NULL,
16941         },
16942 };
16943
16944 /* *** show fec capability per port configuration *** */
16945 struct cmd_show_fec_capability_result {
16946         cmdline_fixed_string_t cmd_show;
16947         cmdline_fixed_string_t cmd_port;
16948         cmdline_fixed_string_t cmd_fec;
16949         cmdline_fixed_string_t cmd_keyword;
16950         portid_t cmd_pid;
16951 };
16952
16953 static void
16954 cmd_show_fec_capability_parsed(void *parsed_result,
16955                 __rte_unused struct cmdline *cl,
16956                 __rte_unused void *data)
16957 {
16958         struct cmd_show_fec_capability_result *res = parsed_result;
16959         struct rte_eth_fec_capa *speed_fec_capa;
16960         unsigned int num;
16961         int ret;
16962
16963         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
16964                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
16965                 return;
16966         }
16967
16968         ret = rte_eth_fec_get_capability(res->cmd_pid, NULL, 0);
16969         if (ret == -ENOTSUP) {
16970                 fprintf(stderr, "Function not implemented\n");
16971                 return;
16972         } else if (ret < 0) {
16973                 fprintf(stderr, "Get FEC capability failed: %d\n", ret);
16974                 return;
16975         }
16976
16977         num = (unsigned int)ret;
16978         speed_fec_capa = calloc(num, sizeof(*speed_fec_capa));
16979         if (speed_fec_capa == NULL) {
16980                 fprintf(stderr, "Failed to alloc FEC capability buffer\n");
16981                 return;
16982         }
16983
16984         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
16985         if (ret < 0) {
16986                 fprintf(stderr, "Error getting FEC capability: %d\n", ret);
16987                 goto out;
16988         }
16989
16990         show_fec_capability(num, speed_fec_capa);
16991 out:
16992         free(speed_fec_capa);
16993 }
16994
16995 cmdline_parse_token_string_t cmd_show_fec_capability_show =
16996         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
16997                         cmd_show, "show");
16998 cmdline_parse_token_string_t cmd_show_fec_capability_port =
16999         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17000                         cmd_port, "port");
17001 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17002         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17003                         cmd_pid, RTE_UINT16);
17004 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17005         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17006                         cmd_fec, "fec");
17007 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17008         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17009                         cmd_keyword, "capabilities");
17010
17011 cmdline_parse_inst_t cmd_show_capability = {
17012         .f = cmd_show_fec_capability_parsed,
17013         .data = NULL,
17014         .help_str = "show port <port_id> fec capabilities",
17015         .tokens = {
17016                 (void *)&cmd_show_fec_capability_show,
17017                 (void *)&cmd_show_fec_capability_port,
17018                 (void *)&cmd_show_fec_capability_pid,
17019                 (void *)&cmd_show_fec_capability_fec,
17020                 (void *)&cmd_show_fec_capability_keyword,
17021                 NULL,
17022         },
17023 };
17024
17025 /* *** show fec mode per port configuration *** */
17026 struct cmd_show_fec_metadata_result {
17027         cmdline_fixed_string_t cmd_show;
17028         cmdline_fixed_string_t cmd_port;
17029         cmdline_fixed_string_t cmd_keyword;
17030         portid_t cmd_pid;
17031 };
17032
17033 static void
17034 cmd_show_fec_mode_parsed(void *parsed_result,
17035                 __rte_unused struct cmdline *cl,
17036                 __rte_unused void *data)
17037 {
17038 #define FEC_NAME_SIZE 16
17039         struct cmd_show_fec_metadata_result *res = parsed_result;
17040         uint32_t mode;
17041         char buf[FEC_NAME_SIZE];
17042         int ret;
17043
17044         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17045                 fprintf(stderr, "Invalid port id %u\n", res->cmd_pid);
17046                 return;
17047         }
17048         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17049         if (ret == -ENOTSUP) {
17050                 fprintf(stderr, "Function not implemented\n");
17051                 return;
17052         } else if (ret < 0) {
17053                 fprintf(stderr, "Get FEC mode failed\n");
17054                 return;
17055         }
17056
17057         switch (mode) {
17058         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17059                 strlcpy(buf, "off", sizeof(buf));
17060                 break;
17061         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17062                 strlcpy(buf, "auto", sizeof(buf));
17063                 break;
17064         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17065                 strlcpy(buf, "baser", sizeof(buf));
17066                 break;
17067         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
17068                 strlcpy(buf, "rs", sizeof(buf));
17069                 break;
17070         default:
17071                 return;
17072         }
17073
17074         printf("%s\n", buf);
17075 }
17076
17077 cmdline_parse_token_string_t cmd_show_fec_mode_show =
17078         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17079                         cmd_show, "show");
17080 cmdline_parse_token_string_t cmd_show_fec_mode_port =
17081         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17082                         cmd_port, "port");
17083 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
17084         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
17085                         cmd_pid, RTE_UINT16);
17086 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
17087         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
17088                         cmd_keyword, "fec_mode");
17089
17090 cmdline_parse_inst_t cmd_show_fec_mode = {
17091         .f = cmd_show_fec_mode_parsed,
17092         .data = NULL,
17093         .help_str = "show port <port_id> fec_mode",
17094         .tokens = {
17095                 (void *)&cmd_show_fec_mode_show,
17096                 (void *)&cmd_show_fec_mode_port,
17097                 (void *)&cmd_show_fec_mode_pid,
17098                 (void *)&cmd_show_fec_mode_keyword,
17099                 NULL,
17100         },
17101 };
17102
17103 /* *** set fec mode per port configuration *** */
17104 struct cmd_set_port_fec_mode {
17105         cmdline_fixed_string_t set;
17106         cmdline_fixed_string_t port;
17107         portid_t port_id;
17108         cmdline_fixed_string_t fec_mode;
17109         cmdline_fixed_string_t fec_value;
17110 };
17111
17112 /* Common CLI fields for set fec mode */
17113 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
17114         TOKEN_STRING_INITIALIZER
17115                 (struct cmd_set_port_fec_mode,
17116                  set, "set");
17117 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
17118         TOKEN_STRING_INITIALIZER
17119                 (struct cmd_set_port_fec_mode,
17120                  port, "port");
17121 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
17122         TOKEN_NUM_INITIALIZER
17123                 (struct cmd_set_port_fec_mode,
17124                  port_id, RTE_UINT16);
17125 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
17126         TOKEN_STRING_INITIALIZER
17127                 (struct cmd_set_port_fec_mode,
17128                  fec_mode, "fec_mode");
17129 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
17130         TOKEN_STRING_INITIALIZER
17131                 (struct cmd_set_port_fec_mode,
17132                  fec_value, NULL);
17133
17134 static void
17135 cmd_set_port_fec_mode_parsed(
17136         void *parsed_result,
17137         __rte_unused struct cmdline *cl,
17138         __rte_unused void *data)
17139 {
17140         struct cmd_set_port_fec_mode *res = parsed_result;
17141         uint16_t port_id = res->port_id;
17142         uint32_t fec_capa;
17143         int ret;
17144
17145         ret = parse_fec_mode(res->fec_value, &fec_capa);
17146         if (ret < 0) {
17147                 fprintf(stderr, "Unknown fec mode: %s for port %d\n",
17148                                 res->fec_value, port_id);
17149                 return;
17150         }
17151
17152         ret = rte_eth_fec_set(port_id, fec_capa);
17153         if (ret == -ENOTSUP) {
17154                 fprintf(stderr, "Function not implemented\n");
17155                 return;
17156         } else if (ret < 0) {
17157                 fprintf(stderr, "Set FEC mode failed\n");
17158                 return;
17159         }
17160 }
17161
17162 cmdline_parse_inst_t cmd_set_fec_mode = {
17163         .f = cmd_set_port_fec_mode_parsed,
17164         .data = NULL,
17165         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
17166         .tokens = {
17167                 (void *)&cmd_set_port_fec_mode_set,
17168                 (void *)&cmd_set_port_fec_mode_port,
17169                 (void *)&cmd_set_port_fec_mode_port_id,
17170                 (void *)&cmd_set_port_fec_mode_str,
17171                 (void *)&cmd_set_port_fec_mode_value,
17172                 NULL,
17173         },
17174 };
17175
17176 /* show port supported ptypes */
17177
17178 /* Common result structure for show port ptypes */
17179 struct cmd_show_port_supported_ptypes_result {
17180         cmdline_fixed_string_t show;
17181         cmdline_fixed_string_t port;
17182         portid_t port_id;
17183         cmdline_fixed_string_t ptypes;
17184 };
17185
17186 /* Common CLI fields for show port ptypes */
17187 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
17188         TOKEN_STRING_INITIALIZER
17189                 (struct cmd_show_port_supported_ptypes_result,
17190                  show, "show");
17191 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
17192         TOKEN_STRING_INITIALIZER
17193                 (struct cmd_show_port_supported_ptypes_result,
17194                  port, "port");
17195 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
17196         TOKEN_NUM_INITIALIZER
17197                 (struct cmd_show_port_supported_ptypes_result,
17198                  port_id, RTE_UINT16);
17199 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
17200         TOKEN_STRING_INITIALIZER
17201                 (struct cmd_show_port_supported_ptypes_result,
17202                  ptypes, "ptypes");
17203
17204 static void
17205 cmd_show_port_supported_ptypes_parsed(
17206         void *parsed_result,
17207         __rte_unused struct cmdline *cl,
17208         __rte_unused void *data)
17209 {
17210 #define RSVD_PTYPE_MASK       0xf0000000
17211 #define MAX_PTYPES_PER_LAYER  16
17212 #define LTYPE_NAMESIZE        32
17213 #define PTYPE_NAMESIZE        256
17214         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
17215         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
17216         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
17217         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
17218         uint16_t port_id = res->port_id;
17219         int ret, i;
17220
17221         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
17222         if (ret < 0)
17223                 return;
17224
17225         while (ptype_mask != RSVD_PTYPE_MASK) {
17226
17227                 switch (ptype_mask) {
17228                 case RTE_PTYPE_L2_MASK:
17229                         strlcpy(ltype, "L2", sizeof(ltype));
17230                         break;
17231                 case RTE_PTYPE_L3_MASK:
17232                         strlcpy(ltype, "L3", sizeof(ltype));
17233                         break;
17234                 case RTE_PTYPE_L4_MASK:
17235                         strlcpy(ltype, "L4", sizeof(ltype));
17236                         break;
17237                 case RTE_PTYPE_TUNNEL_MASK:
17238                         strlcpy(ltype, "Tunnel", sizeof(ltype));
17239                         break;
17240                 case RTE_PTYPE_INNER_L2_MASK:
17241                         strlcpy(ltype, "Inner L2", sizeof(ltype));
17242                         break;
17243                 case RTE_PTYPE_INNER_L3_MASK:
17244                         strlcpy(ltype, "Inner L3", sizeof(ltype));
17245                         break;
17246                 case RTE_PTYPE_INNER_L4_MASK:
17247                         strlcpy(ltype, "Inner L4", sizeof(ltype));
17248                         break;
17249                 default:
17250                         return;
17251                 }
17252
17253                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
17254                                                        ptype_mask, ptypes,
17255                                                        MAX_PTYPES_PER_LAYER);
17256
17257                 if (ret > 0)
17258                         printf("Supported %s ptypes:\n", ltype);
17259                 else
17260                         printf("%s ptypes unsupported\n", ltype);
17261
17262                 for (i = 0; i < ret; ++i) {
17263                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
17264                         printf("%s\n", buf);
17265                 }
17266
17267                 ptype_mask <<= 4;
17268         }
17269 }
17270
17271 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
17272         .f = cmd_show_port_supported_ptypes_parsed,
17273         .data = NULL,
17274         .help_str = "show port <port_id> ptypes",
17275         .tokens = {
17276                 (void *)&cmd_show_port_supported_ptypes_show,
17277                 (void *)&cmd_show_port_supported_ptypes_port,
17278                 (void *)&cmd_show_port_supported_ptypes_port_id,
17279                 (void *)&cmd_show_port_supported_ptypes_ptypes,
17280                 NULL,
17281         },
17282 };
17283
17284 /* *** display rx/tx descriptor status *** */
17285 struct cmd_show_rx_tx_desc_status_result {
17286         cmdline_fixed_string_t cmd_show;
17287         cmdline_fixed_string_t cmd_port;
17288         cmdline_fixed_string_t cmd_keyword;
17289         cmdline_fixed_string_t cmd_desc;
17290         cmdline_fixed_string_t cmd_status;
17291         portid_t cmd_pid;
17292         portid_t cmd_qid;
17293         portid_t cmd_did;
17294 };
17295
17296 static void
17297 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
17298                 __rte_unused struct cmdline *cl,
17299                 __rte_unused void *data)
17300 {
17301         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
17302         int rc;
17303
17304         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17305                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17306                 return;
17307         }
17308
17309         if (!strcmp(res->cmd_keyword, "rxq")) {
17310                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
17311                                              res->cmd_did);
17312                 if (rc < 0) {
17313                         fprintf(stderr,
17314                                 "Invalid input: queue id = %d, desc id = %d\n",
17315                                 res->cmd_qid, res->cmd_did);
17316                         return;
17317                 }
17318                 if (rc == RTE_ETH_RX_DESC_AVAIL)
17319                         printf("Desc status = AVAILABLE\n");
17320                 else if (rc == RTE_ETH_RX_DESC_DONE)
17321                         printf("Desc status = DONE\n");
17322                 else
17323                         printf("Desc status = UNAVAILABLE\n");
17324         } else if (!strcmp(res->cmd_keyword, "txq")) {
17325                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
17326                                              res->cmd_did);
17327                 if (rc < 0) {
17328                         fprintf(stderr,
17329                                 "Invalid input: queue id = %d, desc id = %d\n",
17330                                 res->cmd_qid, res->cmd_did);
17331                         return;
17332                 }
17333                 if (rc == RTE_ETH_TX_DESC_FULL)
17334                         printf("Desc status = FULL\n");
17335                 else if (rc == RTE_ETH_TX_DESC_DONE)
17336                         printf("Desc status = DONE\n");
17337                 else
17338                         printf("Desc status = UNAVAILABLE\n");
17339         }
17340 }
17341
17342 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
17343         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17344                         cmd_show, "show");
17345 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
17346         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17347                         cmd_port, "port");
17348 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
17349         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17350                         cmd_pid, RTE_UINT16);
17351 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
17352         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17353                         cmd_keyword, "rxq#txq");
17354 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
17355         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17356                         cmd_qid, RTE_UINT16);
17357 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
17358         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17359                         cmd_desc, "desc");
17360 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
17361         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17362                         cmd_did, RTE_UINT16);
17363 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
17364         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
17365                         cmd_status, "status");
17366 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
17367         .f = cmd_show_rx_tx_desc_status_parsed,
17368         .data = NULL,
17369         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
17370                 "status",
17371         .tokens = {
17372                 (void *)&cmd_show_rx_tx_desc_status_show,
17373                 (void *)&cmd_show_rx_tx_desc_status_port,
17374                 (void *)&cmd_show_rx_tx_desc_status_pid,
17375                 (void *)&cmd_show_rx_tx_desc_status_keyword,
17376                 (void *)&cmd_show_rx_tx_desc_status_qid,
17377                 (void *)&cmd_show_rx_tx_desc_status_desc,
17378                 (void *)&cmd_show_rx_tx_desc_status_did,
17379                 (void *)&cmd_show_rx_tx_desc_status_status,
17380                 NULL,
17381         },
17382 };
17383
17384 /* *** display rx queue desc used count *** */
17385 struct cmd_show_rx_queue_desc_used_count_result {
17386         cmdline_fixed_string_t cmd_show;
17387         cmdline_fixed_string_t cmd_port;
17388         cmdline_fixed_string_t cmd_rxq;
17389         cmdline_fixed_string_t cmd_desc;
17390         cmdline_fixed_string_t cmd_used;
17391         cmdline_fixed_string_t cmd_count;
17392         portid_t cmd_pid;
17393         portid_t cmd_qid;
17394 };
17395
17396 static void
17397 cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
17398                 __rte_unused struct cmdline *cl,
17399                 __rte_unused void *data)
17400 {
17401         struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
17402         int rc;
17403
17404         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17405                 fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
17406                 return;
17407         }
17408
17409         rc = rte_eth_rx_queue_count(res->cmd_pid, res->cmd_qid);
17410         if (rc < 0) {
17411                 fprintf(stderr, "Invalid queueid = %d\n", res->cmd_qid);
17412                 return;
17413         }
17414         printf("Used desc count = %d\n", rc);
17415 }
17416
17417 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_show =
17418         TOKEN_STRING_INITIALIZER
17419                 (struct cmd_show_rx_queue_desc_used_count_result,
17420                  cmd_show, "show");
17421 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_port =
17422         TOKEN_STRING_INITIALIZER
17423                 (struct cmd_show_rx_queue_desc_used_count_result,
17424                  cmd_port, "port");
17425 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_pid =
17426         TOKEN_NUM_INITIALIZER
17427                 (struct cmd_show_rx_queue_desc_used_count_result,
17428                  cmd_pid, RTE_UINT16);
17429 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_rxq =
17430         TOKEN_STRING_INITIALIZER
17431                 (struct cmd_show_rx_queue_desc_used_count_result,
17432                  cmd_rxq, "rxq");
17433 cmdline_parse_token_num_t cmd_show_rx_queue_desc_used_count_qid =
17434         TOKEN_NUM_INITIALIZER
17435                 (struct cmd_show_rx_queue_desc_used_count_result,
17436                  cmd_qid, RTE_UINT16);
17437 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_desc =
17438         TOKEN_STRING_INITIALIZER
17439                 (struct cmd_show_rx_queue_desc_used_count_result,
17440                  cmd_count, "desc");
17441 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_used =
17442         TOKEN_STRING_INITIALIZER
17443                 (struct cmd_show_rx_queue_desc_used_count_result,
17444                  cmd_count, "used");
17445 cmdline_parse_token_string_t cmd_show_rx_queue_desc_used_count_count =
17446         TOKEN_STRING_INITIALIZER
17447                 (struct cmd_show_rx_queue_desc_used_count_result,
17448                  cmd_count, "count");
17449 cmdline_parse_inst_t cmd_show_rx_queue_desc_used_count = {
17450         .f = cmd_show_rx_queue_desc_used_count_parsed,
17451         .data = NULL,
17452         .help_str = "show port <port_id> rxq <queue_id> desc used count",
17453         .tokens = {
17454                 (void *)&cmd_show_rx_queue_desc_used_count_show,
17455                 (void *)&cmd_show_rx_queue_desc_used_count_port,
17456                 (void *)&cmd_show_rx_queue_desc_used_count_pid,
17457                 (void *)&cmd_show_rx_queue_desc_used_count_rxq,
17458                 (void *)&cmd_show_rx_queue_desc_used_count_qid,
17459                 (void *)&cmd_show_rx_queue_desc_used_count_desc,
17460                 (void *)&cmd_show_rx_queue_desc_used_count_used,
17461                 (void *)&cmd_show_rx_queue_desc_used_count_count,
17462                 NULL,
17463         },
17464 };
17465
17466 /* Common result structure for set port ptypes */
17467 struct cmd_set_port_ptypes_result {
17468         cmdline_fixed_string_t set;
17469         cmdline_fixed_string_t port;
17470         portid_t port_id;
17471         cmdline_fixed_string_t ptype_mask;
17472         uint32_t mask;
17473 };
17474
17475 /* Common CLI fields for set port ptypes */
17476 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
17477         TOKEN_STRING_INITIALIZER
17478                 (struct cmd_set_port_ptypes_result,
17479                  set, "set");
17480 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
17481         TOKEN_STRING_INITIALIZER
17482                 (struct cmd_set_port_ptypes_result,
17483                  port, "port");
17484 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
17485         TOKEN_NUM_INITIALIZER
17486                 (struct cmd_set_port_ptypes_result,
17487                  port_id, RTE_UINT16);
17488 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
17489         TOKEN_STRING_INITIALIZER
17490                 (struct cmd_set_port_ptypes_result,
17491                  ptype_mask, "ptype_mask");
17492 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
17493         TOKEN_NUM_INITIALIZER
17494                 (struct cmd_set_port_ptypes_result,
17495                  mask, RTE_UINT32);
17496
17497 static void
17498 cmd_set_port_ptypes_parsed(
17499         void *parsed_result,
17500         __rte_unused struct cmdline *cl,
17501         __rte_unused void *data)
17502 {
17503         struct cmd_set_port_ptypes_result *res = parsed_result;
17504 #define PTYPE_NAMESIZE        256
17505         char ptype_name[PTYPE_NAMESIZE];
17506         uint16_t port_id = res->port_id;
17507         uint32_t ptype_mask = res->mask;
17508         int ret, i;
17509
17510         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
17511                                                NULL, 0);
17512         if (ret <= 0) {
17513                 fprintf(stderr, "Port %d doesn't support any ptypes.\n",
17514                         port_id);
17515                 return;
17516         }
17517
17518         uint32_t ptypes[ret];
17519
17520         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
17521         if (ret < 0) {
17522                 fprintf(stderr, "Unable to set requested ptypes for Port %d\n",
17523                         port_id);
17524                 return;
17525         }
17526
17527         printf("Successfully set following ptypes for Port %d\n", port_id);
17528         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
17529                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
17530                 printf("%s\n", ptype_name);
17531         }
17532
17533         clear_ptypes = false;
17534 }
17535
17536 cmdline_parse_inst_t cmd_set_port_ptypes = {
17537         .f = cmd_set_port_ptypes_parsed,
17538         .data = NULL,
17539         .help_str = "set port <port_id> ptype_mask <mask>",
17540         .tokens = {
17541                 (void *)&cmd_set_port_ptypes_set,
17542                 (void *)&cmd_set_port_ptypes_port,
17543                 (void *)&cmd_set_port_ptypes_port_id,
17544                 (void *)&cmd_set_port_ptypes_mask_str,
17545                 (void *)&cmd_set_port_ptypes_mask_u32,
17546                 NULL,
17547         },
17548 };
17549
17550 /* *** display mac addresses added to a port *** */
17551 struct cmd_showport_macs_result {
17552         cmdline_fixed_string_t cmd_show;
17553         cmdline_fixed_string_t cmd_port;
17554         cmdline_fixed_string_t cmd_keyword;
17555         portid_t cmd_pid;
17556 };
17557
17558 static void
17559 cmd_showport_macs_parsed(void *parsed_result,
17560                 __rte_unused struct cmdline *cl,
17561                 __rte_unused void *data)
17562 {
17563         struct cmd_showport_macs_result *res = parsed_result;
17564
17565         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
17566                 return;
17567
17568         if (!strcmp(res->cmd_keyword, "macs"))
17569                 show_macs(res->cmd_pid);
17570         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
17571                 show_mcast_macs(res->cmd_pid);
17572 }
17573
17574 cmdline_parse_token_string_t cmd_showport_macs_show =
17575         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17576                         cmd_show, "show");
17577 cmdline_parse_token_string_t cmd_showport_macs_port =
17578         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17579                         cmd_port, "port");
17580 cmdline_parse_token_num_t cmd_showport_macs_pid =
17581         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
17582                         cmd_pid, RTE_UINT16);
17583 cmdline_parse_token_string_t cmd_showport_macs_keyword =
17584         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
17585                         cmd_keyword, "macs#mcast_macs");
17586
17587 cmdline_parse_inst_t cmd_showport_macs = {
17588         .f = cmd_showport_macs_parsed,
17589         .data = NULL,
17590         .help_str = "show port <port_id> macs|mcast_macs",
17591         .tokens = {
17592                 (void *)&cmd_showport_macs_show,
17593                 (void *)&cmd_showport_macs_port,
17594                 (void *)&cmd_showport_macs_pid,
17595                 (void *)&cmd_showport_macs_keyword,
17596                 NULL,
17597         },
17598 };
17599
17600 /* ******************************************************************************** */
17601
17602 /* list of instructions */
17603 cmdline_parse_ctx_t main_ctx[] = {
17604         (cmdline_parse_inst_t *)&cmd_help_brief,
17605         (cmdline_parse_inst_t *)&cmd_help_long,
17606         (cmdline_parse_inst_t *)&cmd_quit,
17607         (cmdline_parse_inst_t *)&cmd_load_from_file,
17608         (cmdline_parse_inst_t *)&cmd_showport,
17609         (cmdline_parse_inst_t *)&cmd_showqueue,
17610         (cmdline_parse_inst_t *)&cmd_showeeprom,
17611         (cmdline_parse_inst_t *)&cmd_showportall,
17612         (cmdline_parse_inst_t *)&cmd_representor_info,
17613         (cmdline_parse_inst_t *)&cmd_showdevice,
17614         (cmdline_parse_inst_t *)&cmd_showcfg,
17615         (cmdline_parse_inst_t *)&cmd_showfwdall,
17616         (cmdline_parse_inst_t *)&cmd_start,
17617         (cmdline_parse_inst_t *)&cmd_start_tx_first,
17618         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
17619         (cmdline_parse_inst_t *)&cmd_set_link_up,
17620         (cmdline_parse_inst_t *)&cmd_set_link_down,
17621         (cmdline_parse_inst_t *)&cmd_reset,
17622         (cmdline_parse_inst_t *)&cmd_set_numbers,
17623         (cmdline_parse_inst_t *)&cmd_set_log,
17624         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
17625         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
17626         (cmdline_parse_inst_t *)&cmd_set_txpkts,
17627         (cmdline_parse_inst_t *)&cmd_set_txsplit,
17628         (cmdline_parse_inst_t *)&cmd_set_txtimes,
17629         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
17630         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
17631         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
17632         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
17633         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
17634         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
17635         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
17636         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
17637         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
17638         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
17639         (cmdline_parse_inst_t *)&cmd_set_link_check,
17640         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
17641         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
17642         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
17643         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
17644 #ifdef RTE_NET_BOND
17645         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
17646         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
17647         (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info,
17648         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
17649         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
17650         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
17651         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
17652         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
17653         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
17654         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
17655         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
17656         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
17657 #endif
17658         (cmdline_parse_inst_t *)&cmd_vlan_offload,
17659         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
17660         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
17661         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
17662         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
17663         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
17664         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
17665         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
17666         (cmdline_parse_inst_t *)&cmd_csum_set,
17667         (cmdline_parse_inst_t *)&cmd_csum_show,
17668         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
17669         (cmdline_parse_inst_t *)&cmd_tso_set,
17670         (cmdline_parse_inst_t *)&cmd_tso_show,
17671         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
17672         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
17673 #ifdef RTE_LIB_GRO
17674         (cmdline_parse_inst_t *)&cmd_gro_enable,
17675         (cmdline_parse_inst_t *)&cmd_gro_flush,
17676         (cmdline_parse_inst_t *)&cmd_gro_show,
17677 #endif
17678 #ifdef RTE_LIB_GSO
17679         (cmdline_parse_inst_t *)&cmd_gso_enable,
17680         (cmdline_parse_inst_t *)&cmd_gso_size,
17681         (cmdline_parse_inst_t *)&cmd_gso_show,
17682 #endif
17683         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
17684         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
17685         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
17686         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
17687         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
17688         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
17689         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
17690         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
17691         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
17692         (cmdline_parse_inst_t *)&cmd_link_flow_control_show,
17693         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
17694         (cmdline_parse_inst_t *)&cmd_config_dcb,
17695         (cmdline_parse_inst_t *)&cmd_read_reg,
17696         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
17697         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
17698         (cmdline_parse_inst_t *)&cmd_write_reg,
17699         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
17700         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
17701         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
17702         (cmdline_parse_inst_t *)&cmd_stop,
17703         (cmdline_parse_inst_t *)&cmd_mac_addr,
17704         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
17705         (cmdline_parse_inst_t *)&cmd_set_qmap,
17706         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
17707         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
17708         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
17709         (cmdline_parse_inst_t *)&cmd_operate_port,
17710         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
17711         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
17712         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
17713         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
17714         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
17715         (cmdline_parse_inst_t *)&cmd_config_speed_all,
17716         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
17717         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
17718         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
17719         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
17720         (cmdline_parse_inst_t *)&cmd_config_mtu,
17721         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
17722         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
17723         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
17724         (cmdline_parse_inst_t *)&cmd_config_rss,
17725         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
17726         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
17727         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
17728         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
17729         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
17730         (cmdline_parse_inst_t *)&cmd_showport_reta,
17731         (cmdline_parse_inst_t *)&cmd_showport_macs,
17732         (cmdline_parse_inst_t *)&cmd_config_burst,
17733         (cmdline_parse_inst_t *)&cmd_config_thresh,
17734         (cmdline_parse_inst_t *)&cmd_config_threshold,
17735         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
17736         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
17737         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
17738         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
17739         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
17740         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
17741         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
17742         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
17743         (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs,
17744         (cmdline_parse_inst_t *)&cmd_dump,
17745         (cmdline_parse_inst_t *)&cmd_dump_one,
17746 #ifdef RTE_NET_I40E
17747         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
17748 #endif
17749         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
17750         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
17751         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
17752         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
17753         (cmdline_parse_inst_t *)&cmd_flow,
17754         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
17755         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
17756         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
17757         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
17758         (cmdline_parse_inst_t *)&cmd_create_port_meter,
17759         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
17760         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
17761         (cmdline_parse_inst_t *)&cmd_del_port_meter,
17762         (cmdline_parse_inst_t *)&cmd_del_port_meter_policy,
17763         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
17764         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
17765         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
17766         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
17767         (cmdline_parse_inst_t *)&cmd_mcast_addr,
17768         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
17769         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
17770         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
17771         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
17772         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
17773         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
17774         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
17775         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
17776         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
17777         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
17778         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
17779         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
17780         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
17781         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
17782         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
17783         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
17784         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
17785         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
17786         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
17787         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
17788         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
17789         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
17790         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
17791         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
17792         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
17793         (cmdline_parse_inst_t *)&cmd_set_vxlan,
17794         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
17795         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
17796         (cmdline_parse_inst_t *)&cmd_set_nvgre,
17797         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
17798         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
17799         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
17800         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
17801         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
17802         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
17803         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
17804         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
17805         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
17806         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
17807         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
17808         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
17809         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
17810         (cmdline_parse_inst_t *)&cmd_set_conntrack_common,
17811         (cmdline_parse_inst_t *)&cmd_set_conntrack_dir,
17812         (cmdline_parse_inst_t *)&cmd_ddp_add,
17813         (cmdline_parse_inst_t *)&cmd_ddp_del,
17814         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
17815         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
17816         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
17817         (cmdline_parse_inst_t *)&cmd_clear_input_set,
17818         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
17819         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
17820         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
17821         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
17822         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
17823         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
17824         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
17825         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
17826
17827         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
17828         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
17829         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
17830         (cmdline_parse_inst_t *)&cmd_queue_region,
17831         (cmdline_parse_inst_t *)&cmd_region_flowtype,
17832         (cmdline_parse_inst_t *)&cmd_user_priority_region,
17833         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
17834         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
17835         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
17836         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
17837         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
17838         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
17839         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
17840         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
17841         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
17842         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
17843         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
17844         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
17845         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
17846         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
17847         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
17848         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
17849         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
17850         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
17851         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
17852         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
17853         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
17854         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
17855         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
17856         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
17857         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
17858         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
17859         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
17860         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
17861         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
17862         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
17863         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
17864         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
17865         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
17866         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
17867 #ifdef RTE_LIB_BPF
17868         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
17869         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
17870 #endif
17871         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
17872         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
17873         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
17874         (cmdline_parse_inst_t *)&cmd_show_rx_queue_desc_used_count,
17875         (cmdline_parse_inst_t *)&cmd_set_raw,
17876         (cmdline_parse_inst_t *)&cmd_show_set_raw,
17877         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
17878         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
17879         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
17880         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
17881         (cmdline_parse_inst_t *)&cmd_show_capability,
17882         (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern,
17883         (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern,
17884         NULL,
17885 };
17886
17887 /* read cmdline commands from file */
17888 void
17889 cmdline_read_from_file(const char *filename)
17890 {
17891         struct cmdline *cl;
17892
17893         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
17894         if (cl == NULL) {
17895                 fprintf(stderr,
17896                         "Failed to create file based cmdline context: %s\n",
17897                         filename);
17898                 return;
17899         }
17900
17901         cmdline_interact(cl);
17902         cmdline_quit(cl);
17903
17904         cmdline_free(cl);
17905
17906         printf("Read CLI commands from %s\n", filename);
17907 }
17908
17909 /* prompt function, called from main on MAIN lcore */
17910 void
17911 prompt(void)
17912 {
17913         int ret;
17914         /* initialize non-constant commands */
17915         cmd_set_fwd_mode_init();
17916         cmd_set_fwd_retry_mode_init();
17917
17918         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
17919         if (testpmd_cl == NULL)
17920                 return;
17921
17922         ret = atexit(prompt_exit);
17923         if (ret != 0)
17924                 fprintf(stderr, "Cannot set exit function for cmdline\n");
17925
17926         cmdline_interact(testpmd_cl);
17927         if (ret != 0)
17928                 cmdline_stdin_exit(testpmd_cl);
17929 }
17930
17931 void
17932 prompt_exit(void)
17933 {
17934         if (testpmd_cl != NULL) {
17935                 cmdline_quit(testpmd_cl);
17936                 cmdline_stdin_exit(testpmd_cl);
17937         }
17938 }
17939
17940 static void
17941 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
17942 {
17943         if (id == (portid_t)RTE_PORT_ALL) {
17944                 portid_t pid;
17945
17946                 RTE_ETH_FOREACH_DEV(pid) {
17947                         /* check if need_reconfig has been set to 1 */
17948                         if (ports[pid].need_reconfig == 0)
17949                                 ports[pid].need_reconfig = dev;
17950                         /* check if need_reconfig_queues has been set to 1 */
17951                         if (ports[pid].need_reconfig_queues == 0)
17952                                 ports[pid].need_reconfig_queues = queue;
17953                 }
17954         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
17955                 /* check if need_reconfig has been set to 1 */
17956                 if (ports[id].need_reconfig == 0)
17957                         ports[id].need_reconfig = dev;
17958                 /* check if need_reconfig_queues has been set to 1 */
17959                 if (ports[id].need_reconfig_queues == 0)
17960                         ports[id].need_reconfig_queues = queue;
17961         }
17962 }